3232: Activate fastest version of algebraic union-find.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Activate fastest version of algebraic union-find. * mln/morpho/closing_attribute.hh (closing_attribute_dispatch): Activate for fastest images. * mln/canvas/morpho/algebraic_union_find.hh: Likewise. * mln/canvas/labeling.hh: Remove dead code. canvas/labeling.hh | 155 ---------------------------------- canvas/morpho/algebraic_union_find.hh | 30 +++--- morpho/closing_attribute.hh | 28 +++--- 3 files changed, 35 insertions(+), 178 deletions(-) Index: mln/morpho/closing_attribute.hh --- mln/morpho/closing_attribute.hh (revision 3231) +++ mln/morpho/closing_attribute.hh (working copy) @@ -209,22 +209,22 @@ template <typename A, typename I, typename N> inline mln_concrete(I) - closing_attribute_dispatch(trait::image::speed::any, + closing_attribute_dispatch(metal::false_, const Image<I>& input, const Neighborhood<N>& nbh, mln_result(A) lambda) { return impl::generic::closing_attribute<A>(input, nbh, lambda); } -// template <typename A, typename I, typename N> -// inline -// mln_concrete(I) -// closing_attribute_dispatch(trait::image::speed::fastest, -// const Image<I>& input, const Neighborhood<N>& nbh, -// mln_result(A) lambda) -// { -// return impl::closing_attribute_fastest<A>(input, nbh, lambda); -// } + template <typename A, typename I, typename N> + inline + mln_concrete(I) + closing_attribute_dispatch(metal::true_, + const Image<I>& input, const Neighborhood<N>& nbh, + mln_result(A) lambda) + { + return impl::closing_attribute_fastest<A>(input, nbh, lambda); + } template <typename A, typename I, typename N> inline @@ -232,7 +232,13 @@ closing_attribute_dispatch(const Image<I>& input, const Neighborhood<N>& nbh, mln_result(A) lambda) { - return closing_attribute_dispatch<A>(mln_trait_image_speed(I)(), + enum { + test = mlc_equal(mln_trait_image_speed(I), + trait::image::speed::fastest)::value + && + mln_is_simple_neighborhood(N)::value + }; + return closing_attribute_dispatch<A>(metal::bool_<test>(), input, nbh, lambda); } Index: mln/canvas/morpho/algebraic_union_find.hh --- mln/canvas/morpho/algebraic_union_find.hh (revision 3231) +++ mln/canvas/morpho/algebraic_union_find.hh (working copy) @@ -336,7 +336,7 @@ template <typename I, typename N, typename F> inline mln_concrete(I) - algebraic_union_find_dispatch(trait::image::speed::any, + algebraic_union_find_dispatch(metal::false_, const Image<I>& input, const Neighborhood<N>& nbh, F& f) @@ -344,16 +344,16 @@ return impl::generic::algebraic_union_find(input, nbh, f); } - // template <typename I, typename N, typename F> - // inline - // mln_concrete(I) - // algebraic_union_find_dispatch(trait::image::speed::fastest, - // const Image<I>& input, - // const Neighborhood<N>& nbh, - // F& f) - // { - // return impl::algebraic_union_find_fastest(input, nbh, f); - // } + template <typename I, typename N, typename F> + inline + mln_concrete(I) + algebraic_union_find_dispatch(metal::true_, + const Image<I>& input, + const Neighborhood<N>& nbh, + F& f) + { + return impl::algebraic_union_find_fastest(input, nbh, f); + } template <typename I, typename N, typename F> inline @@ -362,7 +362,13 @@ const Neighborhood<N>& nbh, F& f) { - return algebraic_union_find_dispatch(mln_trait_image_speed(I)(), + enum { + test = mlc_equal(mln_trait_image_speed(I), + trait::image::speed::fastest)::value + && + mln_is_simple_neighborhood(N)::value + }; + return algebraic_union_find_dispatch(metal::bool_<test>(), input, nbh, f); } Index: mln/canvas/labeling.hh --- mln/canvas/labeling.hh (revision 3231) +++ mln/canvas/labeling.hh (working copy) @@ -203,161 +203,6 @@ - - - - - // ----------------------------------------------------------- - // Old code below. - - - /* - - // Fastest version. - - template <typename F> - struct labeling_fastest - { - // Functor. - F& f; - - typedef typename F::I I; - typedef typename F::N N; - typedef typename F::L L; - - // Auxiliary data. - mln_ch_value(I, unsigned) parent; - - // Output. - mln_ch_value(I, L) output; - L nlabels; - bool status; - - // Ctor. - labeling_fastest(F& f); - - void init(); - - void pass_1(); - - void pass_2(); - - // Auxiliary methods. - - bool is_root(unsigned p) const; - - unsigned find_root(unsigned x); - - void do_union(unsigned n, unsigned p); - - }; - - template <typename F> - labeling_fastest<F>::labeling_fastest(F& f) - : f(f) - { - trace::entering("canvas::labeling_fastest"); - - init(); - f.init(); // Client initialization. - pass_1(); - pass_2(); - - trace::exiting("canvas::labeling_fastest"); - } - - template <typename F> - void - labeling_fastest<F>::init() - { - initialize(parent, f.input); - for (unsigned p = 0; p < parent.nelements(); ++p) - parent.element(p) = p; // make_set - initialize(output, f.input); - mln::data::fill(output, 0); // FIXME: Use literal::zero. - nlabels = 0; - } - - template <typename F> - void - labeling_fastest<F>::pass_1() - { - mln_bkd_pixter(const I) p(f.input); - - typedef window<mln_dpsite(I)> W; - W win = mln::convert::to_upper_window(f.nbh); - mln_qixter(const I, W) n(p, win); - - for_all(p) if (f.handles(p)) - { - f.init_attr(p); - for_all(n) - if (f.equiv(n, p)) - do_union(n, p); - else - f.do_no_union(n, p); - } - } - - template <typename F> - void - labeling_fastest<F>::pass_2() - { - mln_fwd_pixter(const I) p(f.input); - - for_all(p) if (f.handles(p)) - { - if (is_root(p)) - { - if (f.labels(p)) - { - if (nlabels == mln_max(L)) - { - status = false; - return; - } - output(p) = ++nlabels; - } - } - else - output(p) = output(parent.element(p)); - } - status = true; - } - - template <typename F> - bool - labeling_fastest<F>::is_root(unsigned p) const - { - return parent.element(p) == p; - } - - template <typename F> - unsigned - labeling_fastest<F>::find_root(unsigned x) - { - if (parent.element(x) == x) - return x; - else - return parent.element(x) = find_root(parent.element(x)); - } - - template <typename F> - void - labeling_fastest<F>::do_union(unsigned n, unsigned p) - { - unsigned r = find_root(n); - if (r != p) - { - parent.element(r) = p; - f.merge_attr(r, p); - } - } - - */ - - - // Dispatch. namespace internal
participants (1)
-
Thierry Geraud