cleanup-2008 2842: Update labeling routines to modern conventions.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update labeling routines to modern conventions. * mln/morpho/erosion.spe.hh (erosion_dispatch_wrt_win): Add check over win simplicity. * mln/labeling/flat_zones.hh, * mln/labeling/level.hh, * mln/labeling/foreground.hh, * mln/labeling/regional_minima.hh, * mln/labeling/regional_maxima.hh, * mln/labeling/compute.hh, * mln/labeling/level.spe.hh, * mln/labeling/background.hh: Partial update w.r.t. routine naming and style. * mln/labeling/all.hh (todo): New. labeling/all.hh | 13 ++++---- labeling/background.hh | 26 ++++++++--------- labeling/compute.hh | 11 +++---- labeling/flat_zones.hh | 21 ++++++------- labeling/foreground.hh | 26 ++++++++--------- labeling/level.hh | 67 ++++++++++++++++++++++++++++++++++++-------- labeling/level.spe.hh | 42 +++++++-------------------- labeling/regional_maxima.hh | 14 ++++----- labeling/regional_minima.hh | 14 ++++----- morpho/erosion.spe.hh | 4 ++ 10 files changed, 133 insertions(+), 105 deletions(-) Index: mln/morpho/erosion.spe.hh --- mln/morpho/erosion.spe.hh (revision 2841) +++ mln/morpho/erosion.spe.hh (working copy) @@ -58,6 +58,8 @@ /// /// \todo Warning: we should also have the "arbitrary" versions working /// on sets (not only on functions!) +/// +/// \todo HERE Factor dispatch for lines... # ifndef MLN_INCLUDE_ONLY @@ -1384,6 +1386,8 @@ && mlc_is_a(mln_site(I), Gpoint)::value && + mln_is_simple_window(W)::value + && mlc_not_equal(mln_trait_image_value_storage(I), trait::image::value_storage::disrupted)::value }; return erosion_dispatch_wrt_arbitrary_win(metal::bool_<test>(), Index: mln/labeling/flat_zones.hh --- mln/labeling/flat_zones.hh (revision 2841) +++ mln/labeling/flat_zones.hh (working copy) @@ -29,10 +29,9 @@ #ifndef MLN_LABELING_FLAT_ZONES_HH # define MLN_LABELING_FLAT_ZONES_HH -/*! \file mln/labeling/flat_zones.hh - * - * \brief Connected component labeling of the flat zones of an image. - */ +/// \file mln/labeling/flat_zones.hh +/// +/// Connected component labeling of the flat zones of an image. # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> @@ -93,7 +92,7 @@ // end of requirements - flat_zones_functor(const I_& input, const N_& nbh) + flat_zones_functor(const I& input, const N& nbh) : input(input), nbh(nbh), s(input.domain()) @@ -108,16 +107,16 @@ template <typename I, typename N, typename L> mln_ch_value(I, L) - flat_zones_(const I& input, const N& nbh, L& nlabels) + flat_zones(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels) { - trace::entering("labeling::impl::generic::flat_zones_"); + trace::entering("labeling::impl::generic::flat_zones"); typedef flat_zones_functor<I,N,L> F; - F f(input, nbh); + F f(exact(input), exact(nbh)); canvas::labeling<F> run(f); nlabels = run.nlabels; - trace::exiting("labeling::impl::generic::flat_zones_"); + trace::exiting("labeling::impl::generic::flat_zones"); return run.output; } @@ -136,13 +135,13 @@ L& nlabels) { trace::entering("labeling::flat_zones"); + const I& input = exact(input_); const N& nbh = exact(nbh_); mln_precondition(input.has_data()); // Calls the only (generic) impl. - mln_ch_value(I, L) output = - impl::generic::flat_zones_(input, nbh, nlabels); + mln_ch_value(I, L) output = impl::generic::flat_zones(input, nbh, nlabels); trace::exiting("labeling::flat_zones"); return output; Index: mln/labeling/level.hh --- mln/labeling/level.hh (revision 2841) +++ mln/labeling/level.hh (working copy) @@ -67,6 +67,32 @@ # ifndef MLN_INCLUDE_ONLY + + // Tests. + + namespace internal + { + + template <typename I, typename N, typename L> + void + level_tests(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh, + L& nlabels) + { + mln_precondition(exact(input).has_data()); + // mln_precondition(exact(nbh).is_valid()); + + (void) input; + (void) val; + (void) nbh; + (void) nlabels; + } + + } // end of namespace mln::labeling::internal + + + + // Generic implementation. + namespace impl { @@ -101,7 +127,7 @@ const mln_value(I_)& val; - level_functor(const I_& input, const mln_value(I_)& val, const N_& nbh) + level_functor(const I& input, const mln_value(I)& val, const N& nbh) : input(input), nbh(nbh), s(input.domain()), @@ -117,19 +143,22 @@ template <typename I, typename N, typename L> mln_ch_value(I, L) - level_(const I& input, const mln_value(I)& val, const N& nbh, + level(const Image<I>& input, const mln_value(I)& val, + const Neighborhood<N>& nbh, L& nlabels) { - trace::entering("labeling::impl::generic::level_"); + trace::entering("labeling::impl::generic::level"); + + internal::level_tests(input, val, nbh, nlabels); typedef level_functor<I,N,L> F; - F f(input, val, nbh); + F f(exact(input), val, exact(nbh)); canvas::labeling<F> run(f); nlabels = run.nlabels; // FIXME: Handle run.status - trace::exiting("labeling::impl::generic::level_"); + trace::exiting("labeling::impl::generic::level"); return run.output; } @@ -139,20 +168,36 @@ } // end of namespace mln::labeling::impl + // Dispatch. + + namespace internal + { + + template <typename I, typename N, typename L> + mln_ch_value(I, L) + level_dispatch(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh, + L& nlabels) + { + return impl::generic::level(input, val, nbh, nlabels); + } + + } // end of namespace mln::labeling::internal + + // Facade. template <typename I, typename N, typename L> mln_ch_value(I, L) - level(const Image<I>& input, const mln_value(I)& val, - const Neighborhood<N>& nbh, L& nlabels) + level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh, + L& nlabels) { trace::entering("labeling::level"); - mln_precondition(exact(input).has_data()); - mln_ch_value(I, L) output = - impl::level_(mln_trait_image_speed(I)(), - exact(input), val, exact(nbh), nlabels); + internal::level_tests(input, val, nbh, nlabels); + + mln_ch_value(I, L) output; + output = internal::level_dispatch(input, val, nbh, nlabels); trace::exiting("labeling::level"); return output; Index: mln/labeling/all.hh --- mln/labeling/all.hh (revision 2841) +++ mln/labeling/all.hh (working copy) @@ -28,10 +28,12 @@ #ifndef MLN_LABELING_ALL_HH # define MLN_LABELING_ALL_HH -/*! \file mln/labeling/all.hh - * - * \brief File that includes all labeling routines. - */ +/// \file mln/labeling/all.hh +/// +/// File that includes all labeling routines. +/// +/// \todo Many files in this directory have to be updated with the +/// test and dispatch mechanisms. namespace mln @@ -47,9 +49,7 @@ namespace generic {} } - } - } # include <mln/labeling/background.hh> @@ -61,4 +61,5 @@ # include <mln/labeling/regional_maxima.hh> # include <mln/labeling/regional_minima.hh> + #endif // ! MLN_LABELING_ALL_HH Index: mln/labeling/foreground.hh --- mln/labeling/foreground.hh (revision 2841) +++ mln/labeling/foreground.hh (working copy) @@ -29,11 +29,10 @@ #ifndef MLN_LABELING_FOREGROUND_HH # define MLN_LABELING_FOREGROUND_HH -/*! \file mln/labeling/foreground.hh - * - * \brief Connected component labeling of the object part in a binary - * image. - */ +/// \file mln/labeling/foreground.hh +/// +/// Connected component labeling of the object part in a binary +/// image. # include <mln/labeling/level.hh> @@ -59,27 +58,28 @@ * * \see mln::labeling::level */ - template <typename I, typename N> - mln_ch_value(I, unsigned) + template <typename I, typename N, typename L> + mln_ch_value(I, L) foreground(const Image<I>& input, const Neighborhood<N>& nbh, - unsigned& nlabels); + L& nlabels); # ifndef MLN_INCLUDE_ONLY - template <typename I, typename N> + template <typename I, typename N, typename L> inline - mln_ch_value(I, unsigned) + mln_ch_value(I, L) foreground(const Image<I>& input, const Neighborhood<N>& nbh, - unsigned& nlabels) + L& nlabels) { trace::entering("labeling::foreground"); + mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check(); mln_precondition(exact(input).has_data()); + // mln_precondition(exact(nbh).is_valid()); - mln_ch_value(I, unsigned) output = - labeling::level(input, true, nbh, nlabels); + mln_ch_value(I, L) output = labeling::level(input, true, nbh, nlabels); trace::exiting("labeling::foreground"); return output; Index: mln/labeling/regional_minima.hh --- mln/labeling/regional_minima.hh (revision 2841) +++ mln/labeling/regional_minima.hh (working copy) @@ -30,8 +30,8 @@ # define MLN_LABELING_REGIONAL_MINIMA_HH /// \file mln/labeling/regional_minima.hh -/// \brief Connected component labeling of the regional minima of an -/// image. +/// +/// Connected component labeling of the regional minima of an image. # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> @@ -124,9 +124,9 @@ template <typename I, typename N, typename L> mln_ch_value(I, L) - regional_minima_(const I& input, const N& nbh, L& nlabels) + regional_minima(const I& input, const N& nbh, L& nlabels) { - trace::entering("labeling::impl::generic::regional_minima_"); + trace::entering("labeling::impl::generic::regional_minima"); // FIXME: abort if L is not wide enough to encode the set of // minima. @@ -136,7 +136,7 @@ canvas::labeling<F> run(f); nlabels = run.nlabels; - trace::exiting("labeling::impl::generic::regional_minima_"); + trace::exiting("labeling::impl::generic::regional_minima"); return run.output; } @@ -155,13 +155,13 @@ L& nlabels) { trace::entering("labeling::regional_minima"); + const I& input = exact(input_); const N& nbh = exact(nbh_); mln_precondition(input.has_data()); // Calls the only (generic) impl. - mln_ch_value(I, L) output = - impl::generic::regional_minima_(input, nbh, nlabels); + mln_ch_value(I, L) output = impl::generic::regional_minima(input, nbh, nlabels); trace::exiting("labeling::regional_minima"); return output; Index: mln/labeling/regional_maxima.hh --- mln/labeling/regional_maxima.hh (revision 2841) +++ mln/labeling/regional_maxima.hh (working copy) @@ -30,8 +30,8 @@ # define MLN_LABELING_REGIONAL_MAXIMA_HH /// \file mln/labeling/regional_maxima.hh -/// \brief Connected component labeling of the regional maxima of an -/// image. +/// +/// Connected component labeling of the regional maxima of an image. # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> @@ -118,10 +118,10 @@ template <typename I, typename N, typename L> mln_ch_value(I, L) - regional_maxima_(const I& input, const N& nbh, + regional_maxima(const I& input, const N& nbh, L& nlabels) { - trace::entering("labeling::impl::generic::regional_maxima_"); + trace::entering("labeling::impl::generic::regional_maxima"); // FIXME: abort if L is not wide enough to encode the set of // maxima. @@ -131,7 +131,7 @@ canvas::labeling<F> run(f); nlabels = run.nlabels; - trace::exiting("labeling::impl::generic::regional_maxima_"); + trace::exiting("labeling::impl::generic::regional_maxima"); return run.output; } @@ -150,13 +150,13 @@ L& nlabels) { trace::entering("labeling::regional_maxima"); + const I& input = exact(input_); const N& nbh = exact(nbh_); mln_precondition(input.has_data()); // Calls the only (generic) impl. - mln_ch_value(I, L) output = - impl::generic::regional_maxima_(input, nbh, nlabels); + mln_ch_value(I, L) output = impl::generic::regional_maxima(input, nbh, nlabels); trace::exiting("labeling::regional_maxima"); return output; Index: mln/labeling/compute.hh --- mln/labeling/compute.hh (revision 2841) +++ mln/labeling/compute.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 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,11 +28,10 @@ #ifndef MLN_LABELING_COMPUTE_HH # define MLN_LABELING_COMPUTE_HH -/*! \file mln/labeling/compute.hh - * - * \brief Compute accumulators onto sites/values of each labeled component - * of an image. - */ +/// \file mln/labeling/compute.hh +/// +/// Compute accumulators onto sites/values of each labeled component +/// of an image. # include <mln/core/concept/meta_accumulator.hh> # include <mln/util/array.hh> Index: mln/labeling/level.spe.hh --- mln/labeling/level.spe.hh (revision 2841) +++ mln/labeling/level.spe.hh (working copy) @@ -39,8 +39,7 @@ # error "Forbidden inclusion of *.spe.hh" # endif // ! MLN_LABELING_LEVEL_HH -# include <mln/border/adjust.hh> -# include <mln/border/fill.hh> +# include <mln/extension/adjust_fill.hh> # include <mln/value/other.hh> @@ -78,7 +77,8 @@ template <typename I, typename N, typename L> mln_ch_value(I, L) - level_(const I& input, const mln_value(I)& val, const N& nbh, + level(const Image<I>& input, const mln_value(I)& val, + const Neighborhood<N>& nbh, L& nlabels); } // end of namespace mln::labeling::impl::generic @@ -124,17 +124,19 @@ }; - // Fastest routine. + // Fastest implementation. template <typename I, typename N, typename L> mln_ch_value(I, L) - level_fastest_(const I& input, const mln_value(I)& val, const N& nbh, + level_fastest(const Image<I>& input, const mln_value(I)& val, + const Neighborhood<N>& nbh, L& nlabels) { - trace::entering("labeling::impl::level_fastest_"); + trace::entering("labeling::impl::level_fastest"); + + // FIXME: HERE - border::adjust(input, nbh.delta()); - border::fill(input, value::other(val)); + extension::adjust_fill(input, nbh.delta(), value::other(val)); typedef level_fastest_functor<I,N,L> F; F f(input, val, nbh); @@ -143,32 +145,10 @@ nlabels = run.nlabels; // FIXME: Handle run.status - trace::exiting("labeling::impl::level_fastest_"); + trace::exiting("labeling::impl::level_fastest"); return run.output; } - - // Disjunction between "fastest" and "not fastest". - - template <typename I, typename N, typename L> - mln_ch_value(I, L) - level_(trait::image::speed::any, - const I& input, const mln_value(I)& val, const N& nbh, - L& nlabels) - { - return generic::level_(input, val, nbh, nlabels); - } - -// template <typename I, typename N, typename L> -// mln_ch_value(I, L) -// level_(trait::image::speed::fastest, -// const I& input, const mln_value(I)& val, const N& nbh, -// L& nlabels) -// { -// return level_fastest_(input, val, nbh, nlabels); -// } - - } // end of namespace mln::labeling::impl Index: mln/labeling/background.hh --- mln/labeling/background.hh (revision 2841) +++ mln/labeling/background.hh (working copy) @@ -29,11 +29,10 @@ #ifndef MLN_LABELING_BACKGROUND_HH # define MLN_LABELING_BACKGROUND_HH -/*! \file mln/labeling/background.hh - * - * \brief Connected component labeling of the background in a binary - * image. - */ +/// \file mln/labeling/background.hh +/// +/// Connected component labeling of the background in a binary +/// image. # include <mln/labeling/level.hh> @@ -59,27 +58,28 @@ * * \see mln::labeling::level */ - template <typename I, typename N> - mln_ch_value(I, unsigned) + template <typename I, typename N, typename L> + mln_ch_value(I, L) background(const Image<I>& input, const Neighborhood<N>& nbh, - unsigned& nlabels); + L& nlabels); # ifndef MLN_INCLUDE_ONLY - template <typename I, typename N> + template <typename I, typename N, typename L> inline - mln_ch_value(I, unsigned) + mln_ch_value(I, L) background(const Image<I>& input, const Neighborhood<N>& nbh, - unsigned& nlabels) + L& nlabels) { trace::entering("labeling::background"); + mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check(); mln_precondition(exact(input).has_data()); + // mln_precondition(exact(nbh).is_valid()); - mln_ch_value(I, unsigned) output = - labeling::level(input, false, nbh, nlabels); + mln_ch_value(I, L) output = labeling::level(input, false, nbh, nlabels); trace::exiting("labeling::background"); return output;
participants (1)
-
Thierry Geraud