https://svn.lrde.epita.fr/svn/oln/trunk/olena
Users need yet to `typedef` their image type in order to use
Olena's Canvas.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix wrong type in cc_tarjan versions.
* oln/core/gen/neighb.hh: .
* oln/morpho/cc_tarjan_v0.hh: .
* oln/morpho/cc_tarjan_v2.hh: .
* oln/morpho/cc_tarjan_v4.hh: .
* oln/morpho/cc_tarjan_v1.hh: .
* oln/morpho/cc_tarjan_v3.hh: .
* oln/canvas/queue_based.hh: .
* oln/canvas/sequential.hh: .
* oln/canvas/parallel.hh: .
* oln/canvas/two_pass_until_stability.hh: .
* oln/canvas/two_pass.hh: .
canvas/parallel.hh | 9 +++--
canvas/queue_based.hh | 9 +++--
canvas/sequential.hh | 9 +++--
canvas/two_pass.hh | 7 ++--
canvas/two_pass_until_stability.hh | 9 +++--
core/gen/neighb.hh | 1
morpho/cc_tarjan_v0.hh | 60 +++++++++++++++++++------------------
morpho/cc_tarjan_v1.hh | 30 +++++++++++-------
morpho/cc_tarjan_v2.hh | 18 ++++++-----
morpho/cc_tarjan_v3.hh | 24 ++++++++------
morpho/cc_tarjan_v4.hh | 22 +++++++------
11 files changed, 115 insertions(+), 83 deletions(-)
Index: oln/core/gen/neighb.hh
--- oln/core/gen/neighb.hh (revision 978)
+++ oln/core/gen/neighb.hh (working copy)
@@ -33,7 +33,6 @@
# include <oln/core/internal/neighborhood_base.hh>
# include <oln/core/gen/dpoints_piter.hh>
-
namespace oln
{
Index: oln/morpho/cc_tarjan_v0.hh
--- oln/morpho/cc_tarjan_v0.hh (revision 978)
+++ oln/morpho/cc_tarjan_v0.hh (working copy)
@@ -47,45 +47,46 @@
namespace impl
{
template <typename I>
- oln_point(I) find_root(I& ima,
+ oln_point(I) find_root(const I& f,
const oln_point(I)& x,
oln_plain_value(I, oln_point(I))& parent)
{
if (parent(x) != x)
{
- parent(x) = find_root(ima, parent(x), parent);
+ parent(x) = find_root(f, parent(x), parent);
return parent(x);
}
return x;
}
template <typename I>
- void do_union(I& ima,
+ void do_union(const I& f,
const oln_point(I)& n,
const oln_point(I)& p,
oln_plain_value(I, oln_point(I))& parent)
{
- oln_point(I) r = find_root(ima, n, parent);
+ oln_point(I) r = find_root(f, n, parent);
if (r != p)
parent(r) = p;
}
- template <typename I>
- void first_pass(const I& input,
+ template <typename I, typename N>
+ void first_pass(const I& f,
oln_plain_value(I, oln_point(I))& parent,
- oln_plain(I)& is_processed)
+ oln_plain(I)& is_processed,
+ const N& nhb)
{
- oln_bkd_piter(I) p(input.points());
+ oln_bkd_piter(I) p(f.points());
for_all(p)
{
parent(p) = p;
- if ( input(p) )
+ if ( f(p) )
{
- oln_niter(I) n(input, p);
- for_all(n)
+ oln_niter(N) n(nhb, p);
+ for_all(n) if ( f.has(n) )
{
- if ( input(n) == true and is_processed(n) )
- do_union(input, n, p, parent);
+ if ( f(n) == true and is_processed(n) )
+ do_union(f, n, p, parent);
}
is_processed(p) = true;
}
@@ -93,38 +94,40 @@
}
template <typename I>
- void second_pass(const I& input,
+ void second_pass(const I& f,
oln_plain_value(I, oln_point(I))& parent,
oln_plain_value(I, unsigned)& output)
{
unsigned current_label = 0;
- oln_fwd_piter(I) p(input.points());
+ oln_fwd_piter(I) p(f.points());
for_all(p)
{
- if ( input(p) == true and parent(p) == p )
+ if ( f(p) == true and parent(p) == p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
}
}
- template <typename I>
+ template <typename I, typename N>
oln_plain_value(I, unsigned)
- cc_tarjan_(const Image_with_Nbh<I>& input)
+ cc_tarjan_(const I& f,
+ const N& nhb)
{
oln_plain_value(I, unsigned) output;
- prepare(output, with, input);
-
+ prepare(output, with, f);
oln_plain_value(I, oln_point(I)) parent;
- prepare(parent, with, input);
+ prepare(parent, with, f);
- // init.
+ // Init
oln_plain_value(I, bool) is_processed;
- prepare(is_processed, with, input);
+ prepare(is_processed, with, f);
level::fill(inplace(is_processed), false);
+ // First pass
+ first_pass(f, parent, is_processed, nhb);
+ // Second pass
+ second_pass(f, parent, output);
- first_pass(input, parent, is_processed);
- second_pass(input, parent, output);
return output;
}
@@ -132,11 +135,12 @@
// Facades.
- template <typename I>
+ template <typename I, typename N>
oln_plain_value(I, unsigned)
- cc_tarjan(const Binary_Image<I>& input)
+ cc_tarjan(const Binary_Image<I>& f,
+ const Neighborhood<N>& nhb)
{
- return impl::cc_tarjan_(exact(input));
+ return impl::cc_tarjan_(exact(f), exact(nhb));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/cc_tarjan_v2.hh
--- oln/morpho/cc_tarjan_v2.hh (revision 978)
+++ oln/morpho/cc_tarjan_v2.hh (working copy)
@@ -49,16 +49,19 @@
namespace impl
{
- template <typename I>
+ template <typename I, typename N>
struct cc_tarjan_
{
typedef oln_point(I) point;
+ const N& nbh;
oln_plain_value(I, unsigned) output;
oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
- cc_tarjan_() {}
+ cc_tarjan_(const N& nbh)
+ : nbh(nbh)
+ { }
void init(I f)
{
@@ -73,8 +76,8 @@
parent(p) = p;
if ( f(p) )
{
- oln_niter(I) n(f, p);
- for_all(n)
+ oln_niter(N) n(nbh, p);
+ for_all(n) if ( f.has(n) )
{
if ( f(n) == true and is_processed(n) )
do_union(f, n, p);
@@ -124,11 +127,12 @@
// Facades.
- template <typename I>
+ template <typename I, typename N>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& f)
+ cc_tarjan(const Binary_Image<I>& f,
+ const Neighborhood<N>& nbh)
{
- impl::cc_tarjan_<I> run;
+ impl::cc_tarjan_<I,N> run(exact(nbh));
canvas::v2::two_pass(run, exact(f));
return run.output;
}
Index: oln/morpho/cc_tarjan_v4.hh
--- oln/morpho/cc_tarjan_v4.hh (revision 978)
+++ oln/morpho/cc_tarjan_v4.hh (working copy)
@@ -47,21 +47,22 @@
namespace impl
{
- template <typename I>
- struct cc_tarjan_ : public canvas::v4::two_pass<I, cc_tarjan_<I> >
+ template <typename I, typename N>
+ struct cc_tarjan_ : public canvas::v4::two_pass<I, cc_tarjan_<I, N> >
{
typedef oln_point(I) point;
const I& f;
+ const N& nbh;
oln_plain_value(I, unsigned) output;
oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
unsigned nlabels;
- cc_tarjan_(const I& f)
- : canvas::v4::two_pass<I, cc_tarjan_<I> >(f),
- f(f)
+ cc_tarjan_(const I& f, const N& nbh)
+ : canvas::v4::two_pass<I, cc_tarjan_<I, N> >(f),
+ f(f), nbh(nbh)
{
}
@@ -79,8 +80,8 @@
parent(p) = p;
if (f(p) == true)
{
- oln_niter(I) n(f, p);
- for_all(n)
+ oln_niter(N) n(nbh, p);
+ for_all(n) if ( f.has(n) )
{
if ( f(n) == true and is_processed(n) )
do_union(n, p);
@@ -127,11 +128,12 @@
} // end of namespace oln::morpho::impl
- template <typename I>
+ template <typename I, typename N>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& f)
+ cc_tarjan(const Image<I>& f,
+ const Neighborhood<N>& nbh)
{
- impl::cc_tarjan_<I> cc(exact(f));
+ impl::cc_tarjan_<I, N> cc(exact(f), exact(nbh));
cc.run();
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 978)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -53,20 +53,23 @@
namespace impl
{
- template <typename I>
+ template <typename I, typename N>
struct cc_tarjan_
{
typedef oln_point(I) point;
+ typedef I image;
const I& f;
+ const N& nbh;
oln_plain_value(I, unsigned) output;
oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
unsigned nlabels;
- cc_tarjan_(const I& f)
- : f(f)
+ cc_tarjan_(const I& f,
+ const N& nbh)
+ : f(f), nbh(nbh)
{
}
@@ -84,8 +87,8 @@
parent(p) = p;
if (f(p) == true)
{
- oln_niter(I) n(f, p);
- for_all(n)
+ oln_niter(N) n(nbh, p);
+ for_all(n) if ( f.has(n) )
{
if ( f(n) == true and is_processed(n) )
do_union(n, p);
@@ -137,23 +140,26 @@
// Facades.
- template <typename I>
+ template <typename I, typename N>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& f, unsigned& nlabels)
+ cc_tarjan(const Image<I>& f,
+ const Neighborhood<N>& nbh,
+ unsigned& nlabels)
{
- impl::cc_tarjan_<I> run(exact(f));
+ impl::cc_tarjan_<I, N> run(exact(f), exact(nbh));
canvas::v1::two_pass(run);
nlabels = run.nlabels;
oln_plain_value(I, unsigned) tmp = run.output;
return tmp;
}
- template <typename I>
+ template <typename I, typename N>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& f)
+ cc_tarjan(const Image<I>& f,
+ const Neighborhood<N>& nbh)
{
- unsigned nlabels;
- return cc_tarjan(f, nlabels);
+ unsigned nlabels = 0;
+ return cc_tarjan(f, nbh, nlabels);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/cc_tarjan_v3.hh
--- oln/morpho/cc_tarjan_v3.hh (revision 978)
+++ oln/morpho/cc_tarjan_v3.hh (working copy)
@@ -48,18 +48,21 @@
namespace impl
{
- template <typename T>
+ template <typename T, typename U>
struct data_
{
typedef T I;
+ typedef U N;
const I& f;
+ const N& nbh;
+
oln_plain_value(I, unsigned) output;
oln_plain(I) is_processed;
oln_plain_value(I, oln_point(I)) parent;
- data_(const I& f)
- : f(f)
+ data_(const I& f, const N& nbh)
+ : f(f), nbh(nbh)
{
}
};
@@ -107,8 +110,8 @@
data.parent(p) = p;
if ( data.f(p) )
{
- oln_niter(Data::I) n(data.f, p);
- for_all(n)
+ oln_niter(Data::N) n(data.nbh, p);
+ for_all(n) if ( data.f.has(n) )
{
if ( data.f(n) == true and data.is_processed(n) )
do_union(data, n, p);
@@ -137,14 +140,15 @@
// Facades.
- template <typename I>
+ template <typename I, typename N>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& input)
+ cc_tarjan(const Binary_Image<I>& input,
+ const Neighborhood<N>& nbh)
{
- typedef impl::data_<I> data_t;
+ typedef impl::data_<I, N> data_t;
- data_t data(exact(input));
- impl::cc_tarjan_< impl::data_<I> > f;
+ data_t data(exact(input), exact(nbh));
+ impl::cc_tarjan_< data_t > f;
canvas::v3::two_pass(f, data);
return data.output;
}
Index: oln/canvas/queue_based.hh
--- oln/canvas/queue_based.hh (revision 978)
+++ oln/canvas/queue_based.hh (working copy)
@@ -34,10 +34,13 @@
namespace canvas
{
- template <template <class> class F,
- typename I, typename Queue>
- void queue_based(F<I>& fun)
+ template <typename F, typename Queue>
+ void queue_based(F& fun)
{
+
+ typedef typename F::image I;
+ mlc::assert_< mlc_is_a(I, Image) >::check();
+
Queue q;
fun.init();
Index: oln/canvas/sequential.hh
--- oln/canvas/sequential.hh (revision 978)
+++ oln/canvas/sequential.hh (working copy)
@@ -36,10 +36,13 @@
namespace canvas
{
- template <template <class> class F,
- typename I>
- void sequential(F<I>& fun)
+ template <typename F>
+ void sequential(F& fun)
{
+
+ typedef typename F::image I;
+ mlc::assert_< mlc_is_a(I, Image) >::check();
+
bool stability;
fun.init();
Index: oln/canvas/parallel.hh
--- oln/canvas/parallel.hh (revision 978)
+++ oln/canvas/parallel.hh (working copy)
@@ -36,10 +36,13 @@
namespace canvas
{
- template <template <class> class F,
- typename I>
- void parallel(F<I>& fun)
+ template <typename F>
+ void parallel(F& fun)
{
+
+ typedef typename F::image I;
+ mlc::assert_< mlc_is_a(I, Image) >::check();
+
fun.init();
oln_piter(I) p(fun.f.points());
Index: oln/canvas/two_pass_until_stability.hh
--- oln/canvas/two_pass_until_stability.hh (revision 978)
+++ oln/canvas/two_pass_until_stability.hh (working copy)
@@ -34,10 +34,13 @@
namespace canvas
{
- template <template <class> class F,
- typename I>
- void two_pass_until_stability(F<I>& fun)
+ template <typename F>
+ void two_pass_until_stability(F& fun)
{
+
+ typedef typename F::image I;
+ mlc::assert_< mlc_is_a(I, Image) >::check();
+
bool stability;
fun.init();
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 978)
+++ oln/canvas/two_pass.hh (working copy)
@@ -39,10 +39,11 @@
namespace v1
{
- template <template <class> class F,
- typename I> // Data owned by f.
- void two_pass(F<I>& fun)
+ template <typename F> // Data owned by f.
+ void two_pass(F& fun)
{
+
+ typedef typename F::image I;
mlc::assert_< mlc_is_a(I, Image) >::check();
fun.init();