3479: Complete Etienne's work.

https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Complete Etienne's work. * folio/distance_front.cc: New. * folio/distance_front_new.hh: Make it compile. Fix missing work. distance_front.cc | 38 ++++++++++++++++++++++++------ distance_front_new.hh | 63 ++++++++++++++++++++++++++------------------------ 2 files changed, 65 insertions(+), 36 deletions(-) Index: folio/distance_front.cc --- folio/distance_front.cc (revision 3478) +++ folio/distance_front.cc (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009 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 @@ -29,6 +30,7 @@ /// /// Test on mln::transform::distance_front. +#include <mln/core/var.hh> #include <mln/core/image/image2d.hh> #include <mln/core/alias/neighb2d.hh> #include <mln/make/w_window2d_int.hh> @@ -37,7 +39,8 @@ #include <mln/debug/println.hh> #include <mln/opt/at.hh> -#include <mln/transform/distance_front.hh> +# include <mln/transform/internal/distance_functor.hh> +# include "distance_front_new.hh" int main() @@ -45,18 +48,39 @@ using namespace mln; using value::int_u8; - image2d<bool> input(9, 9); + typedef image2d<bool> I; + + I input(9, 9); data::fill(input, false); opt::at(input, 4, 4) = true; + + int_u8 dmax = 18; + mln_VAR(nbh, c4()); + int ws[] = { 0, 9, 0, 9, 0, 9, 6, 4, 6, 9, 0, 4, 0, 4, 0, 9, 6, 4, 6, 9, 0, 9, 0, 9, 0 }; + mln_VAR(w_win, make::w_window2d_int(ws)); + + + transform::internal::distance_functor<I> f; + image2d<int_u8> ref, output; + + ref = canvas::impl::generic::distance_front(input, + nbh, + w_win, + dmax, + f); + debug::println("ref", ref); + + output = canvas::impl::distance_front_fastest(input, + nbh, + w_win, + dmax, + f); + debug::println("output", output); - image2d<int_u8> output = transform::distance_front(input, - c4(), make::w_window2d_int(ws), - int_u8(18)); - debug::println(output); } Index: folio/distance_front_new.hh --- folio/distance_front_new.hh (revision 3478) +++ folio/distance_front_new.hh (working copy) @@ -38,11 +38,7 @@ # include <mln/core/concept/weighted_window.hh> # include <mln/data/fill.hh> # include <mln/accu/max.hh> - -//# include <mln/core/routine/duplicate.hh> -//# include <mln/core/site_set/p_queue_fast.hh> -//# include <queue> -//# include <mln/extension/adjust_fill.hh> +# include <mln/extension/adjust_fill.hh> namespace mln @@ -75,11 +71,14 @@ typename F> void distance_front_tests(const Image<I>& input_, - const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D max, + const Neighborhood<N>& nbh_, + const Weighted_Window<W>& w_win_, + D max, F& functor) { const I& input = exact(input_); const N& nbh = exact(nbh_); + const W& w_win = exact(w_win_); mln_precondition(input.is_valid()); mln_precondition(nbh.is_valid()); @@ -108,7 +107,9 @@ typename F> mln_ch_value(I, D) distance_front(const Image<I>& input_, - const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, D max, + const Neighborhood<N>& nbh_, + const Weighted_Window<W>& w_win_, + D max, F& functor) { trace::entering("canvas::impl::generic::distance_front"); @@ -159,7 +160,7 @@ break; } } - } + } // end of Initialization. // Propagation. { @@ -199,11 +200,11 @@ bucket_size -= bucket_d.size(); bucket_d.clear(); } + } // end of Propagation. trace::exiting("canvas::impl::generic::distance_front"); return dmap; } - } } // of namespace mln::canvas::impl::generic @@ -216,7 +217,8 @@ typename F> mln_ch_value(I, D) distance_front_fastest(const Image<I>& input_, - const Neighborhood<N>& nbh, const Weighted_Window<W>& w_win, + const Neighborhood<N>& nbh_, + const Weighted_Window<W>& w_win_, D max, F& functor) { trace::entering("canvas::impl::distance_front_fastest"); @@ -225,12 +227,14 @@ const N& nbh = exact(nbh_); const W& w_win = exact(w_win_); -// mln_precondition(input.is_valid()); // ?x -// mln_precondition(w_win.is_valid()); // ?x - extension::adjust(input, w_win); // ? + mln_precondition(input.is_valid()); + mln_precondition(w_win.is_valid()); -// typedef mln_site(I) P; - typedef std::vector<unsigned> bucket_t; + // Handling w_win. + extension::adjust(input, w_win); + const unsigned n_ws = w_win.size(); + util::array<int> dp = offsets_wrt(input, w_win.win()); + mln_invariant(dp.nelements() == n_ws); // Distance map. mln_ch_value(I, D) dmap; @@ -247,6 +251,7 @@ } // Aux data. + typedef std::vector<unsigned> bucket_t; std::vector<bucket_t> bucket(mod); unsigned bucket_size = 0; @@ -254,14 +259,14 @@ { functor.init_(input); // <-- init - // For the extension to be ignored: // ? - extension::fill(input, true); // ? - extension::fill(dmap, D(0)); // ? + // For the extension to be ignored: + extension::fill(input, true); + extension::fill(dmap, D(0)); mln_pixter(const I) p(input); mln_nixter(const I, N) n(p, nbh); for_all(p) - if (functor.inqueue_p_wrt_input_p_(input(p))) // <-- inqueue_p_wrt_input_p + if (functor.inqueue_p_wrt_input_p_(p.val())) // <-- inqueue_p_wrt_input_p { dmap.element(p.offset()) = 0; for_all(n) @@ -272,14 +277,12 @@ break; } } - } + } // end of Initialization. // Propagation. { unsigned p; - mln_qiter(W) q(w_win, p); // ?x- - for (unsigned d = 0; bucket_size != 0; ++d) { bucket_t& bucket_d = bucket[d % mod]; @@ -298,15 +301,16 @@ // p has already been processed, having a distance less than d. continue; - for_all(q) + for (unsigned i = 0; i < n_ws; ++i) { - if (dmap.domain().has(q) && dmap(q) > d) + unsigned q = p + dp[i]; + if (dmap.element(q) > d) { - unsigned d_ = d + q.w(); - if (d_ < dmap(q)) + unsigned d_ = d + w_win.w(i); + if (d_ < dmap.element(q)) { - dmap(q) = d_; - functor.process_(dmap.element(p), q); // <- process + dmap.element(q) = d_; + functor.process_(p, q); // <- process bucket[d_ % mod].push_back(q); ++bucket_size; } @@ -315,11 +319,12 @@ bucket_size -= bucket_d.size(); bucket_d.clear(); } + } + } // end of Propagation. trace::exiting("canvas::impl::distance_front_fastest"); return dmap; } - } } // of namespace mln::canvas::impl
participants (1)
-
Thierry Geraud