
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add accu transform stop and make erosion rely on it. * mln/accu/land_basic.hh: New. * mln/accu/transform_stop.hh: New. * mln/accu/all.hh: Update. * mln/morpho/erosion.hh (erosion_on_set): Rely on accu::transform_stop. * mln/morpho/includes.hh: Update. accu/all.hh | 8 ++++- accu/land_basic.hh | 74 +++++++++++++++++++++++-------------------------- accu/transform_stop.hh | 66 +++++++++++++++++++++++-------------------- morpho/erosion.hh | 19 +----------- morpho/includes.hh | 14 +++++---- 5 files changed, 88 insertions(+), 93 deletions(-) Index: mln/accu/all.hh --- mln/accu/all.hh (revision 2878) +++ mln/accu/all.hh (working copy) @@ -58,7 +58,6 @@ # include <mln/accu/bbox.hh> # include <mln/accu/count.hh> -# include <mln/accu/convolve.hh> //# include <mln/accu/count_adjacent_vertices.hh> # include <mln/accu/height.hh> # include <mln/accu/histo.hh> @@ -78,5 +77,12 @@ # include <mln/accu/tuple.hh> # include <mln/accu/volume.hh> +// Routines. + +# include <mln/accu/convolve.hh> +# include <mln/accu/snake_2d.hh> +# include <mln/accu/transform.hh> +# include <mln/accu/transform_stop.hh> + #endif // ! MLN_ACCU_ALL_HH Index: mln/accu/land_basic.hh --- mln/accu/land_basic.hh (revision 2878) +++ mln/accu/land_basic.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,13 +26,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_ACCU_LAND_HH -# define MLN_ACCU_LAND_HH +#ifndef MLN_ACCU_LAND_BASIC_HH +# define MLN_ACCU_LAND_BASIC_HH -/// \file mln/accu/land.hh -/// -/// Define a 'logical-and' accumulator. +/// \file mln/accu/land_basic.hh /// +/// Define a basic 'logical-and' accumulator. # include <mln/accu/internal/base.hh> @@ -42,12 +42,14 @@ namespace accu { - /// "Logical-and" accumulator class. - struct land : public mln::accu::internal::base< bool, land > + /// "Logical-and" accumulator class. Conversely to accu::lands, + /// this version does not have the 'untake' method but features + /// the 'can_stop' method. + struct land_basic : public mln::accu::internal::base< bool, land_basic > { typedef bool argument; - land(); + land_basic(); /// Manipulators. /// \{ @@ -55,10 +57,7 @@ void take_as_init(const argument& t); void take(const argument& t); - void take(const land& other); - - void untake(const argument& t); - void untake(const land& other); + void take(const land_basic& other); /// \} /// Get the value of the accumulator. @@ -68,73 +67,70 @@ /// Always true here. bool is_valid() const; + /// Test if it is worth for this accumulator to take extra data. + /// If the result is already 'false' (because this accumulator + /// has already taken a 'false' value), can_stop returns true. + bool can_stop() const; + protected: - unsigned nfalse_; + bool res_; }; # ifndef MLN_INCLUDE_ONLY inline - land::land() + land_basic::land_basic() { init(); } inline void - land::init() + land_basic::init() { - nfalse_ = 0; + res_ = true; } inline - void land::take_as_init(const argument& t) + void land_basic::take_as_init(const argument& t) { - nfalse_ = t ? 0 : 1; + res_ = t; } inline - void land::take(const argument& t) + void land_basic::take(const argument& t) { - if (t == false) - ++nfalse_; + if (res_ == true && t == false) + res_ = false; } inline void - land::take(const land& other) + land_basic::take(const land_basic& other) { - nfalse_ += other.nfalse_; + res_ = res_ && other.res_; } inline - void land::untake(const argument& t) - { - if (t == false) - --nfalse_; - } - - inline - void - land::untake(const land& other) + bool + land_basic::to_result() const { - mln_precondition(other.nfalse_ <= nfalse_); - nfalse_ -= other.nfalse_; + return res_; } inline bool - land::to_result() const + land_basic::is_valid() const { - return nfalse_ == 0; + return true; } inline bool - land::is_valid() const + land_basic::can_stop() const { - return true; + return res_ == false; } # endif // ! MLN_INCLUDE_ONLY Property changes on: mln/accu/land_basic.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/accu/transform_stop.hh --- mln/accu/transform_stop.hh (revision 2878) +++ mln/accu/transform_stop.hh (working copy) @@ -25,12 +25,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_ACCU_TRANSFORM_HH -# define MLN_ACCU_TRANSFORM_HH +#ifndef MLN_ACCU_TRANSFORM_STOP_HH +# define MLN_ACCU_TRANSFORM_STOP_HH -/// \file mln/accu/transform.hh +/// \file mln/accu/transform_stop.hh /// -/// Transform an image by applying locally an accumulator on its +/// Transform_Stop an image by applying locally an accumulator on its /// values. # include <mln/core/concept/meta_accumulator.hh> @@ -47,15 +47,11 @@ template <typename I, typename A, typename W> mln_ch_value(I, mln_result(A)) - transform(const Image<I>& input, - const Accumulator<A>& a, - const Window<W>& win); + transform_stop(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win); template <typename I, typename A, typename W> mln_ch_value(I, mln_accu_with(A, mln_value(I))::result) - transform(const Image<I>& input, - const Meta_Accumulator<A>& a, - const Window<W>& win); + transform_stop(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win); @@ -72,11 +68,11 @@ template <typename I, typename A, typename W> mln_ch_value(I, mln_result(A)) - transform(const Image<I>& input_, + transform_stop(const Image<I>& input_, const Accumulator<A>& a_, const Window<W>& win_) { - trace::entering("accu::impl::generic::transform"); + trace::entering("accu::impl::generic::transform_stop"); const I& input = exact(input_); const W& win = exact(win_); @@ -96,11 +92,15 @@ { a.init(); for_all(q) + { a.take(input(q)); + if (a.can_stop()) + break; + } output(p) = a.to_result(); } - trace::exiting("accu::impl::generic::transform"); + trace::exiting("accu::impl::generic::transform_stop"); return output; } @@ -111,9 +111,9 @@ template <typename I, typename A, typename W> mln_ch_value(I, mln_result(A)) - transform_fastest(const Image<I>& input_, const Accumulator<A>& a_, const Window<W>& win_) + transform_stop_fastest(const Image<I>& input_, const Accumulator<A>& a_, const Window<W>& win_) { - trace::entering("accu::impl::transform_fastest"); + trace::entering("accu::impl::transform_stop_fastest"); const I& input = exact(input_); const W& win = exact(win_); @@ -135,11 +135,15 @@ { a.init(); for_all(q) + { a.take(q.val()); + if (a.can_stop()) + break; + } o.val() = a.to_result(); } - trace::exiting("accu::impl::transform_fastest"); + trace::exiting("accu::impl::transform_stop_fastest"); return output; } @@ -154,25 +158,25 @@ template <typename I, typename A, typename W> mln_ch_value(I, mln_result(A)) - transform_dispatch(trait::image::speed::any, + transform_stop_dispatch(trait::image::speed::any, const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) { - return impl::generic::transform(input, a, win); + return impl::generic::transform_stop(input, a, win); } template <typename I, typename A, typename W> mln_ch_value(I, mln_result(A)) - transform_dispatch(trait::image::speed::fastest, + transform_stop_dispatch(trait::image::speed::fastest, const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) { - return impl::transform_fastest(input, a, win); + return impl::transform_stop_fastest(input, a, win); } template <typename I, typename A, typename W> mln_ch_value(I, mln_result(A)) - transform_dispatch(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) + transform_stop_dispatch(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) { - return transform_dispatch(mln_trait_image_speed(I)(), + return transform_stop_dispatch(mln_trait_image_speed(I)(), input, a, win); } @@ -184,25 +188,25 @@ template <typename I, typename A, typename W> inline mln_ch_value(I, mln_result(A)) - transform(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) + transform_stop(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win) { - trace::entering("accu::transform"); + trace::entering("accu::transform_stop"); mln_precondition(exact(input).has_data()); // mln_precondition(exact(win).is_valid()); mln_ch_value(I, mln_result(A)) output; - output = internal::transform_dispatch(input, a, win); + output = internal::transform_stop_dispatch(input, a, win); - trace::exiting("accu::transform"); + trace::exiting("accu::transform_stop"); return output; } template <typename I, typename A, typename W> mln_ch_value(I, mln_accu_with(A, mln_value(I))::result) - transform(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win) + transform_stop(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win) { - trace::entering("accu::transform"); + trace::entering("accu::transform_stop"); mln_precondition(exact(input).has_data()); // mln_precondition(exact(win).is_valid()); @@ -211,9 +215,9 @@ A_ a_ = accu::unmeta(exact(a), mln_value(I)()); mln_ch_value(I, mln_result(A_)) output; - output = internal::transform_dispatch(input, a_, win); + output = internal::transform_stop_dispatch(input, a_, win); - trace::exiting("accu::transform"); + trace::exiting("accu::transform_stop"); return output; } @@ -224,4 +228,4 @@ } // end of namespace mln -#endif // ! MLN_ACCU_TRANSFORM_HH +#endif // ! MLN_ACCU_TRANSFORM_STOP_HH Property changes on: mln/accu/transform_stop.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/morpho/erosion.hh --- mln/morpho/erosion.hh (revision 2878) +++ mln/morpho/erosion.hh (working copy) @@ -34,7 +34,6 @@ /// \brief Morphological erosion. # include <mln/morpho/includes.hh> -# include <mln/accu/transform.hh> // Specializations are in: # include <mln/morpho/erosion.spe.hh> @@ -109,27 +108,15 @@ template <typename I, typename W> inline mln_concrete(I) - erosion_on_set(const Image<I>& input_, const Window<W>& win_) + erosion_on_set(const Image<I>& input, const Window<W>& win) { trace::entering("morpho::impl::generic::erosion_on_set"); - const I& input = exact(input_); - const W& win = exact(win_); + internal::erosion_tests(input, win); extension::adjust_fill(input, win, true); - mln_concrete(I) output; - initialize(output, input); - - mln_piter(I) p(input.domain()); - mln_qiter(W) q(win, p); - for_all(p) - { - for_all(q) if (input.has(q)) - if (input(q) == false) - break; - output(p) = ! q.is_valid(); - } + output = accu::transform_stop(input, accu::land_basic(), win); trace::exiting("morpho::impl::generic::erosion_on_set"); return output; Index: mln/morpho/includes.hh --- mln/morpho/includes.hh (revision 2878) +++ mln/morpho/includes.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,12 +29,9 @@ #ifndef MLN_MORPHO_INCLUDES_HH # define MLN_MORPHO_INCLUDES_HH -/*! \file mln/morpho/includes.hh - * - * \brief Basic list of includes for all files in mln/morpho/. - * - * \todo Re-activate the border/all include when ready. - */ +/// \file mln/morpho/includes.hh +/// +/// Basic list of includes for all files in mln/morpho/. # include <mln/core/concept/image.hh> @@ -45,6 +43,7 @@ # include <mln/value/ops.hh> # include <mln/accu/land.hh> +# include <mln/accu/land_basic.hh> // # include <mln/accu/lor.hh> # include <mln/accu/min.hh> # include <mln/accu/max.hh> @@ -52,6 +51,9 @@ # include <mln/accu/max_h.hh> # include <mln/accu/rank.hh> +# include <mln/accu/transform.hh> +# include <mln/accu/transform_stop.hh> + # include <mln/fun/v2v/saturate.hh> # include <mln/level/compare.hh>