cleanup-2008 2832: Rely on a canvas to compute iz and distance transforms.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Rely on a canvas to compute iz and distance transforms. * tests/transform/influence_zone_geodesic.cc: Slight change. * mln/debug/println.hh: New overload to display a message. * mln/canvas/distance_geodesic.hh: New. * mln/transform/influence_zone_geodesic.hh: Update. * mln/transform/distance_geodesic.hh: Update. mln/canvas/distance_geodesic.hh | 81 ++++++++---------------- mln/debug/println.hh | 28 ++++++-- mln/transform/distance_geodesic.hh | 84 +++++-------------------- mln/transform/influence_zone_geodesic.hh | 96 ++++++----------------------- tests/transform/influence_zone_geodesic.cc | 2 5 files changed, 91 insertions(+), 200 deletions(-) Index: tests/transform/influence_zone_geodesic.cc --- tests/transform/influence_zone_geodesic.cc (revision 2831) +++ tests/transform/influence_zone_geodesic.cc (working copy) @@ -53,6 +53,6 @@ 0, 0, 0, 0, 0, 0, 0 }; image2d<int_u8> input = make::image2d(vals); - image2d<int_u8> output = transform::influence_zone_geodesic(input, c4(), int_u8(1)); + image2d<int_u8> output = transform::influence_zone_geodesic(input, c4(), int_u8(2)); debug::println(output); } Index: mln/debug/println.hh --- mln/debug/println.hh (revision 2831) +++ mln/debug/println.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,11 @@ #ifndef MLN_DEBUG_PRINTLN_HH # define MLN_DEBUG_PRINTLN_HH -/*! \file mln/debug/println.hh - * - * \brief Print an image on the standard output. - * - * \todo Revamp. - */ +/// \file mln/debug/println.hh +/// +/// Print an image on the standard output. +/// +/// \todo Revamp. # include <mln/core/concept/image.hh> # include <mln/core/concept/window.hh> @@ -43,6 +43,7 @@ // Specializations are in: # include <mln/debug/println.spe.hh> + namespace mln { @@ -53,6 +54,11 @@ template <typename I> void println(const Image<I>& input); + /// Print the message \p msg and the image \p input on the + /// standard output. + template <typename I> + void println(const std::string& msg, const Image<I>& input); + # ifndef MLN_INCLUDE_ONLY @@ -75,7 +81,8 @@ } // end of namespace mln::debug::impl - // Facade. + // Facades. + template <typename I> inline void @@ -87,6 +94,13 @@ trace::exiting("debug::println"); } + template <typename I> + void println(const std::string& msg, const Image<I>& input) + { + std::cout << msg << std::endl; + println(input); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::debug Index: mln/transform/influence_zone_geodesic.hh --- mln/transform/influence_zone_geodesic.hh (revision 2831) +++ mln/transform/influence_zone_geodesic.hh (working copy) @@ -32,13 +32,8 @@ /// /// Discrete geodesic distance transform. -# include <mln/core/concept/image.hh> -# include <mln/core/concept/neighborhood.hh> -# include <mln/core/site_set/p_queue_fast.hh> -# include <mln/core/routine/clone.hh> -# include <mln/level/fill.hh> - -# include <mln/debug/println.hh> +# include <mln/canvas/distance_geodesic.hh> +# include <mln/literal/zero.hh> namespace mln @@ -55,99 +50,54 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - namespace generic + namespace internal { - template <typename I, typename N, typename D> - mln_concrete(I) - influence_zone_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_, - D max) + template <typename I> + struct iz_functor { - trace::entering("transform::impl::generic::influence_zone_geodesic"); - - const I& input = exact(input_); - const N& nbh = exact(nbh_); - - mln_precondition(input.has_data()); - - mln_ch_value(I, D) dmap; // Distance map is aux data. - initialize(dmap, input); - + typedef mln_value(I) V; typedef mln_site(I) P; - p_queue_fast<P> q; - mln_concrete(I) output = clone(input); + mln_concrete(I) output; - // Initialization. - { - level::fill(dmap, max); - mln_piter(I) p(input.domain()); - mln_niter(N) n(nbh, p); - for_all(p) - if (input(p) != 0) // p in a component - { - dmap(p) = 0; - for_all(n) - if (input.domain().has(n) && input(n) == 0) // n in background + void init(const I& input) { - q.push(p); - break; - } + output = clone(input); } + bool inqueue_p_wrt_input_p(const V& input_p) + { + return input_p != 0u; } - - // Propagation. + bool inqueue_p_wrt_input_n(const V& input_n) { - P p; - mln_niter(N) n(nbh, p); - while (! q.is_empty()) - { - p = q.pop_front(); - if (dmap(p) == max) - { - // Saturation so stop. - q.clear(); - break; + return input_n == 0u; } - for_all(n) - if (input.domain().has(n) && dmap(n) == max) + void process(const P& p, const P& n) { - dmap(n) = dmap(p) + 1; output(n) = output(p); - q.push(n); - } - } } + }; - trace::exiting("transform::impl::generic::influence_zone_geodesic"); - return output; - } + } // end of namespace mln::transform::internal - } // end of namespace mln::transform::impl::generic - - } // end of namespace mln::transform::impl - - - // Facade. template <typename I, typename N, typename D> - inline mln_concrete(I) influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, - D distance_max) + D max) { trace::entering("transform::influence_zone_geodesic"); - // FIXME: tests. + mln_precondition(exact(input).has_data()); + // mln_precondition(exact(nbh).is_valid()); - mln_concrete(I) output; - output = impl::generic::influence_zone_geodesic(input, nbh, distance_max); + internal::iz_functor<I> f; + (void) mln::canvas::distance_geodesic(input, nbh, max, f); trace::exiting("transform::influence_zone_geodesic"); - return output; + return f.output; } # endif // ! MLN_INCLUDE_ONLY Index: mln/transform/distance_geodesic.hh --- mln/transform/distance_geodesic.hh (revision 2831) +++ mln/transform/distance_geodesic.hh (working copy) @@ -32,10 +32,7 @@ /// /// Discrete geodesic distance transform. -# include <mln/core/concept/image.hh> -# include <mln/core/concept/neighborhood.hh> -# include <mln/core/site_set/p_queue_fast.hh> -# include <mln/level/fill.hh> +# include <mln/canvas/distance_geodesic.hh> @@ -53,79 +50,34 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - namespace generic + namespace internal { - template <typename I, typename N, typename D> - mln_ch_value(I, D) - distance_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_, D max) + template <typename I> + struct distance_functor { - trace::entering("transform::impl::generic::distance_geodesic"); - - const I& input = exact(input_); - const N& nbh = exact(nbh_); - - mln_precondition(input.has_data()); - - mln_ch_value(I, D) output; - initialize(output, input); - + typedef mln_value(I) V; typedef mln_site(I) P; - p_queue_fast<P> q; - // Initialization. + void init(const I&) { - level::fill(output, max); - mln_piter(I) p(input.domain()); - mln_niter(N) n(nbh, p); - for_all(p) - if (input(p) == true) // p in object - { - output(p) = 0; - for_all(n) - if (input.domain().has(n) && input(n) == false) // n in background - { - q.push(p); - break; - } } - } - - // Propagation. + bool inqueue_p_wrt_input_p(const V& input_p) { - P p; - mln_niter(N) n(nbh, p); - while (! q.is_empty()) - { - p = q.pop_front(); - for_all(n) - if (input.domain().has(n) && output(n) == max) - { - output(n) = output(p) + 1; - if (output(n) == max) - { - // Saturation so stop. - q.clear(); - break; - } - q.push(n); - } + return input_p == true; } + bool inqueue_p_wrt_input_n(const V& input_n) + { + return input_n == false; } - - trace::exiting("transform::impl::generic::distance_geodesic"); - return output; + void process(const P&, const P&) + { } + }; - } // end of namespace mln::transform::impl::generic - - } // end of namespace mln::transform::impl - + } // end of namespace mln::transform::internal - // Facade. template <typename I, typename N, typename D> inline @@ -134,10 +86,12 @@ { trace::entering("transform::distance_geodesic"); - // FIXME: tests. + mln_precondition(exact(input).has_data()); + // mln_precondition(exact(nbh).is_valid()); mln_ch_value(I, D) output; - output = impl::generic::distance_geodesic(input, nbh, max); + internal::distance_functor<I> f; + output = mln::canvas::distance_geodesic(input, nbh, max, f); trace::exiting("transform::distance_geodesic"); return output; Index: mln/canvas/distance_geodesic.hh --- mln/canvas/distance_geodesic.hh (revision 2830) +++ mln/canvas/distance_geodesic.hh (working copy) @@ -25,12 +25,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH -# define MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH +#ifndef MLN_CANVAS_DISTANCE_GEODESIC_HH +# define MLN_CANVAS_DISTANCE_GEODESIC_HH -/// \file mln/transform/influence_zone_geodesic.hh +/// \file mln/canvas/distance_geodesic.hh /// -/// Discrete geodesic distance transform. +/// Discrete geodesic distance canvas. # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> @@ -38,40 +38,37 @@ # include <mln/core/routine/clone.hh> # include <mln/level/fill.hh> -# include <mln/debug/println.hh> - namespace mln { - namespace transform + namespace canvas { - /// Discrete geodesic distance transform. - template <typename I, typename N, typename D> - mln_concrete(I) - influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max); + /// Discrete geodesic distance canvas. + template <typename I, typename N, typename D, + typename F> + mln_ch_value(I, D) + distance_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max, + F& functor); # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - namespace generic - { - template <typename I, typename N, typename D> - mln_concrete(I) - influence_zone_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_, - D max) + template <typename I, typename N, typename D, + typename F> + mln_ch_value(I, D) + distance_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_, D max, + F& functor) { - trace::entering("transform::impl::generic::influence_zone_geodesic"); + trace::entering("canvas::distance_geodesic"); const I& input = exact(input_); const N& nbh = exact(nbh_); mln_precondition(input.has_data()); + // mln_precondition(nbh.is_valid()); mln_ch_value(I, D) dmap; // Distance map is aux data. initialize(dmap, input); @@ -79,19 +76,19 @@ typedef mln_site(I) P; p_queue_fast<P> q; - mln_concrete(I) output = clone(input); - // Initialization. { + functor.init(input); // <-- init level::fill(dmap, max); mln_piter(I) p(input.domain()); mln_niter(N) n(nbh, p); for_all(p) - if (input(p) != 0) // p in a component + if (functor.inqueue_p_wrt_input_p(input(p))) // <-- inqueue_p_wrt_input_p { dmap(p) = 0; for_all(n) - if (input.domain().has(n) && input(n) == 0) // n in background + if (input.domain().has(n) && + functor.inqueue_p_wrt_input_n(input(n))) // <-- inqueue_p_wrt_input_n { q.push(p); break; @@ -116,45 +113,21 @@ if (input.domain().has(n) && dmap(n) == max) { dmap(n) = dmap(p) + 1; - output(n) = output(p); + functor.process(p, n); // <- process q.push(n); } } } - trace::exiting("transform::impl::generic::influence_zone_geodesic"); - return output; - } - - } // end of namespace mln::transform::impl::generic - - } // end of namespace mln::transform::impl - - - // Facade. - - template <typename I, typename N, typename D> - inline - mln_concrete(I) - influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, - D distance_max) - { - trace::entering("transform::influence_zone_geodesic"); - - // FIXME: tests. - - mln_concrete(I) output; - output = impl::generic::influence_zone_geodesic(input, nbh, distance_max); - - trace::exiting("transform::influence_zone_geodesic"); - return output; + trace::exiting("canvas::distance_geodesic"); + return dmap; } # endif // ! MLN_INCLUDE_ONLY - } // end of namespace mln::transform + } // end of namespace mln::canvas } // end of namespace mln -#endif // ! MLN_TRANSFORM_DISTANCE_HH +#endif // ! MLN_CANVAS_DISTANCE_GEODESIC_HH Property changes on: mln/canvas/distance_geodesic.hh ___________________________________________________________________ Added: svn:mergeinfo
participants (1)
-
Thierry Geraud