
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update directional erosion so that it can now be used on sets. * mln/accu/rank.hh (todo): New. * mln/accu/rank_bool.hh (todo): New. Fix doc. (rank): Fix ctor. (take_as_init): Fix. * mln/accu/land.hh: New. * mln/morpho/erosion.spe.hh (erosion_directional_nd_functor), (erosion_directional_nd_fastest_functor): Add accumulator type as parameter and rename min as accu. (erosion_directional_nd), (erosion_directional_nd_fastest): Update; compute A. (erosion_dispatch_wrt_win): Update overload for hline2d and vline2d. * mln/morpho/includes.hh: Update. accu/land.hh | 81 ++++++++++++++++++++++++-------------------------- accu/rank.hh | 3 + accu/rank_bool.hh | 18 +++++------ morpho/erosion.spe.hh | 58 ++++++++++++++++++----------------- morpho/includes.hh | 2 + 5 files changed, 83 insertions(+), 79 deletions(-) Index: mln/accu/rank.hh --- mln/accu/rank.hh (revision 2667) +++ mln/accu/rank.hh (working copy) @@ -31,6 +31,9 @@ /*! \file mln/accu/rank.hh * * \brief Define an rank accumulator. + * + * \todo It should be renamed as rank_h since it relies on histogram + * (thus low quantization). */ # include <vector> Index: mln/accu/rank_bool.hh --- mln/accu/rank_bool.hh (revision 2667) +++ mln/accu/rank_bool.hh (working copy) @@ -28,16 +28,17 @@ #ifndef MLN_ACCU_RANK_BOOL_HH # define MLN_ACCU_RANK_BOOL_HH -/*! \file mln/accu/rankbool.hh +/*! \file mln/accu/rank_bool.hh * * \brief Define an rank accumulator. + * + * \todo There is no-arg-ctor so this accumulator does not support + * deferred initialization! + * + * \todo Add untake routines... */ -# include <vector> # include <mln/accu/internal/base.hh> -# include <mln/core/concept/meta_accumulator.hh> -# include <mln/trait/value_.hh> -# include <mln/util/pix.hh> namespace mln @@ -49,7 +50,7 @@ // Fwd declaration. template <typename T> struct rank; - /*! \brief rank accumulator class for boolean. + /*! \brief rank accumulator class for Boolean. * */ template <> @@ -85,8 +86,7 @@ inline rank<bool>::rank(unsigned k, unsigned n) - : nfalse_(0), - k_(k), + : k_(k), n_(n) { mln_assertion(k_ < n_); @@ -105,7 +105,7 @@ inline void rank<bool>::take_as_init(const argument& t) { - nfalse_ += !t; + nfalse_ = t ? 0 : 1; } Index: mln/accu/land.hh --- mln/accu/land.hh (revision 2667) +++ mln/accu/land.hh (working copy) @@ -25,19 +25,15 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_ACCU_RANK_BOOL_HH -# define MLN_ACCU_RANK_BOOL_HH +#ifndef MLN_ACCU_LAND_HH +# define MLN_ACCU_LAND_HH -/*! \file mln/accu/rankbool.hh +/*! \file mln/accu/land.hh * - * \brief Define an rank accumulator. + * \brief Define a 'logical-and' accumulator. */ -# include <vector> # include <mln/accu/internal/base.hh> -# include <mln/core/concept/meta_accumulator.hh> -# include <mln/trait/value_.hh> -# include <mln/util/pix.hh> namespace mln @@ -46,25 +42,23 @@ namespace accu { - // Fwd declaration. - template <typename T> struct rank; - - /*! \brief rank accumulator class for boolean. - * - */ - template <> - struct rank<bool> : public mln::accu::internal::base< bool, rank<bool> > + /// "Logical-and" accumulator class. + struct land : public mln::accu::internal::base< bool, land > { typedef bool argument; - rank(unsigned k, unsigned n); + land(); /// Manipulators. /// \{ void init(); void take_as_init(const argument& t); + void take(const argument& t); - void take(const rank<bool>& other); + void take(const land& other); + + void untake(const argument& t); + void untake(const land& other); /// \} /// Get the value of the accumulator. @@ -76,67 +70,71 @@ protected: unsigned nfalse_; - unsigned k_; // 0 <= k_ < n - unsigned n_; }; # ifndef MLN_INCLUDE_ONLY inline - rank<bool>::rank(unsigned k, unsigned n) - : nfalse_(0), - k_(k), - n_(n) + land::land() { - mln_assertion(k_ < n_); init(); } - inline void - rank<bool>::init() + land::init() { nfalse_ = 0; } - inline - void rank<bool>::take_as_init(const argument& t) + void land::take_as_init(const argument& t) { - nfalse_ += !t; + nfalse_ = t ? 0 : 1; } - inline - void rank<bool>::take(const argument& t) + void land::take(const argument& t) { - nfalse_ += !t; + if (t == false) + ++nfalse_; } - inline void - rank<bool>::take(const rank<bool>& other) + land::take(const land& other) { nfalse_ += other.nfalse_; } + inline + void land::untake(const argument& t) + { + if (t == false) + --nfalse_; + } + + inline + void + land::untake(const land& other) + { + mln_precondition(other.nfalse_ <= nfalse_); + nfalse_ -= other.nfalse_; + } inline bool - rank<bool>::to_result() const + land::to_result() const { - mln_assertion(nfalse_ <= n_); - return k_ >= nfalse_; + return nfalse_ == 0; } inline bool - rank<bool>::is_valid() const + land::is_valid() const { - return nfalse_ <= n_; + return true; } # endif // ! MLN_INCLUDE_ONLY @@ -145,5 +143,4 @@ } // end of namespace mln - -#endif // ! MLN_ACCU_RANK_BOOL_HH +#endif // ! MLN_ACCU_AND_HH Index: mln/morpho/erosion.spe.hh --- mln/morpho/erosion.spe.hh (revision 2667) +++ mln/morpho/erosion.spe.hh (working copy) @@ -636,7 +636,7 @@ return dp; } - template <typename I_, typename W> + template <typename I_, typename W, typename A> struct erosion_directional_nd_functor { typedef I_ I; @@ -645,7 +645,7 @@ const I& input; const W& win; mln_concrete(I) output; - accu::min_h<mln_value(I)> min; + A accu; enum { dim = I::site::dim }; mln_psite(I) p; @@ -662,7 +662,7 @@ erosion_directional_nd_functor(const I& input, const W& win, int dir) : input(input), win(win), - min(), + accu(), dir(dir), win_left(win::shift(win, -dp_directional<dpsite>(dir)) - win), win_right(win - win::shift(win, -dp_directional<dpsite>(dir))), @@ -675,27 +675,27 @@ void init() { // FIXME: border::adjust(input, win.delta()); - extension::fill(input, mln_max(mln_value(I))); + extension::fill(input, accu); initialize(output, input); } void init_run() { - min.init(); + accu.init(); p[dir]--; mln_qiter(W) q(win, p); for_all(q) if (input.has(q)) - min.take(input(q)); + accu.take(input(q)); p[dir]++; } void next() { for_all(q_l) if (input.has(q_l)) - min.untake(input(q_l)); + accu.untake(input(q_l)); for_all(q_r) if (input.has(q_r)) - min.take(input(q_r)); - output(p) = min; + accu.take(input(q_r)); + output(p) = accu; } void final() @@ -711,7 +711,11 @@ { trace::entering("morpho::impl:erosion_directional_nd"); - typedef erosion_directional_nd_functor<I, W> F; + typedef mlc_is(mln_trait_image_kind(I), + trait::image::kind::binary) is_binary; + typedef mlc_if(is_binary, accu::land, accu::min_h<mln_value(I)>) A; + + typedef erosion_directional_nd_functor<I, W, A> F; F f(exact(input), exact(win), dir); canvas::browsing::directional(f); @@ -721,7 +725,7 @@ } - template <typename I_, typename W> + template <typename I_, typename W, typename A> struct erosion_directional_nd_fastest_functor { typedef I_ I; @@ -730,7 +734,7 @@ const I& input; const W& win; mln_concrete(I) output; - accu::min_h<mln_value(I)> min; + A accu; mln_psite(I) p; enum { dim = I::site::dim }; @@ -743,7 +747,7 @@ erosion_directional_nd_fastest_functor(const I& input, const W& win, unsigned dir) : input(input), win(win), - min(), + accu(), dir(dir), win_left(win::shift(win, -dp_directional<dpsite>(dir)) - win), win_right(win - win::shift(win, -dp_directional<dpsite>(dir))), @@ -755,27 +759,27 @@ void init() { // FIXME: border::adjust(input, win.delta()); - extension::fill(input, mln_max(mln_value(I))); + extension::fill(input, accu); initialize(output, input); } void next() { for_all(q_l) - min.untake(q_l.val()); + accu.untake(q_l.val()); for_all(q_r) - min.take(q_r.val()); - output(p) = min; + accu.take(q_r.val()); + output(p) = accu; } void init_run() { - min.init(); + accu.init(); p[dir]--; mln_qixter(const I, W) q(input, win, p); for_all(q) - min.take(q.val()); + accu.take(q.val()); p[dir]++; } @@ -793,7 +797,11 @@ { trace::entering("morpho::impl:erosion_directional_nd_fastest"); - typedef erosion_directional_nd_fastest_functor<I, W> F; + typedef mlc_is(mln_trait_image_kind(I), + trait::image::kind::binary) is_binary; + typedef mlc_if(is_binary, accu::land, accu::min_h<mln_value(I)>) A; + + typedef erosion_directional_nd_fastest_functor<I, W, A> F; F f(exact(input), exact(win), dir); canvas::browsing::directional(f); @@ -1400,13 +1408,10 @@ return erosion_dispatch_for_generic(input, win); else { - typedef mlc_is_not(mln_trait_image_kind(I), - mln::trait::image::kind::logic) test_not_logic; typedef mlc_is_a(mln_pset(I), Box) test_box; typedef mlc_equal(mln_trait_image_quant(I), mln::trait::image::quant::low) test_lowq; - typedef mlc_and(test_not_logic, test_box) temp; - typedef mlc_and(temp, test_lowq) tests; + typedef mlc_and(test_box, test_lowq) tests; return erosion_dispatch_wrt_win(typename tests::eval (), input, win); } @@ -1445,13 +1450,10 @@ return erosion_dispatch_for_generic(input, win); else { - typedef mlc_is_not(mln_trait_image_kind(I), - mln::trait::image::kind::logic) test_not_logic; typedef mlc_is_a(mln_pset(I), Box) test_box; typedef mlc_equal(mln_trait_image_quant(I), mln::trait::image::quant::low) test_lowq; - typedef mlc_and(test_not_logic, test_box) temp; - typedef mlc_and(temp, test_lowq) tests; + typedef mlc_and(test_box, test_lowq) tests; return erosion_dispatch_wrt_win(typename tests::eval (), input, win); } Index: mln/morpho/includes.hh --- mln/morpho/includes.hh (revision 2667) +++ mln/morpho/includes.hh (working copy) @@ -44,6 +44,8 @@ # include <mln/value/ops.hh> +# include <mln/accu/land.hh> +// # include <mln/accu/lor.hh> # include <mln/accu/min.hh> # include <mln/accu/max.hh> # include <mln/accu/min_h.hh>