milena r2534: Add hyper_directional browsing

URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena ChangeLog: 2008-10-09 Matthieu Garrigues <garrigues@lrde.epita.fr> Add hyper_directional browsing. This is the old directional browsing. hyper_directional browse an hyper plan of a n dimensional box (It browse all the dimensions except the given one. The given dimension is browsed by the "next()" method of the argument functor defined by the user). * mln/canvas/browsing/hyper_directional.hh: New. * tests/canvas/browsing/Makefile.am: . * tests/canvas/browsing/directional.cc: Remove. * tests/canvas/browsing/hyper_directional.cc: New. --- mln/canvas/browsing/hyper_directional.hh | 134 +++++++++++++++++++++++++++++ tests/canvas/browsing/Makefile.am | 4 tests/canvas/browsing/hyper_directional.cc | 121 ++++++++++++++++++++++++++ 3 files changed, 257 insertions(+), 2 deletions(-) Index: branches/cleanup-2008/milena/tests/canvas/browsing/directional.cc (deleted) =================================================================== Index: branches/cleanup-2008/milena/tests/canvas/browsing/hyper_directional.cc =================================================================== --- branches/cleanup-2008/milena/tests/canvas/browsing/hyper_directional.cc (revision 0) +++ branches/cleanup-2008/milena/tests/canvas/browsing/hyper_directional.cc (revision 2534) @@ -0,0 +1,121 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/*! \file tests/canvas/browsing/hyper_directional.cc + * + * \brief Tests on mln::canvas::browsing::hyper_directional. + */ + +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/canvas/browsing/hyper_directional.hh> +#include <mln/fun/p2v/iota.hh> +#include <mln/debug/println.hh> +#include <mln/level/fill.hh> + +// FIXME: Move code below into mln/canvas/browsing/iota.hh. + + +template <typename I_, typename F> +struct assign_browsing_functor +{ + typedef I_ I; + enum { dim = I::site::dim }; + + + I input; + F f; + int dir; + + assign_browsing_functor(I& input, F f = F(), int dir_ = 0) + : input(input), + f(f), + dir(dir_) + {} + + mln_psite(I) p; + + void init() {} + void final() {} + void next() + { + input(p) = f(p); + //FIXME: Try to make more relevant test. + mln_assertion(p[dir] == 0); + } + void fwd() { next(); } + void bkd() { next(); } + void down() { next(); } +}; + +namespace mln +{ + + template <typename I, typename F, typename B> + void my_test(Image<I>& ima_, + const Function_p2v<F>& f_, + const Browsing<B>& browse_, + int dir = 0) + { + I& ima = exact(ima_); + const F& f = exact(f_); + const B& browse = exact(browse_); + + assign_browsing_functor<I, F> fun(ima, f, dir); + browse(fun); + } + +} + + +int main() +{ + using namespace mln; + image2d<unsigned> ima2(3, 3); + image3d<unsigned> ima3(3, 3, 3); + + level::fill(ima2, 0); + my_test(ima2, fun::p2v::iota, canvas::browsing::hyper_directional, 0); + debug::println(ima2); + + level::fill(ima2, 0); + my_test(ima2, fun::p2v::iota, canvas::browsing::hyper_directional, 1); + debug::println(ima2); + + + level::fill(ima3, 0); + my_test(ima3, fun::p2v::iota, canvas::browsing::hyper_directional, 0); + debug::println(ima3); + + level::fill(ima3, 0); + my_test(ima3, fun::p2v::iota, canvas::browsing::hyper_directional, 1); + debug::println(ima3); + + level::fill(ima3, 0); + my_test(ima3, fun::p2v::iota, canvas::browsing::hyper_directional, 2); + debug::println(ima3); +} Index: branches/cleanup-2008/milena/tests/canvas/browsing/Makefile.am =================================================================== --- branches/cleanup-2008/milena/tests/canvas/browsing/Makefile.am (revision 2533) +++ branches/cleanup-2008/milena/tests/canvas/browsing/Makefile.am (revision 2534) @@ -6,13 +6,13 @@ fwd \ snake_fwd \ snake_vert \ - directional \ + hyper_directional \ dir_struct_elt_incr_update fwd_SOURCES = fwd.cc snake_fwd_SOURCES = snake_fwd.cc snake_vert_SOURCES = snake_vert.cc -directional_SOURCES = directional.cc +hyper_directional_SOURCES = hyper_directional.cc dir_struct_elt_incr_update_SOURCES = dir_struct_elt_incr_update.cc TESTS = $(check_PROGRAMS) Index: branches/cleanup-2008/milena/mln/canvas/browsing/hyper_directional.hh =================================================================== --- branches/cleanup-2008/milena/mln/canvas/browsing/hyper_directional.hh (revision 0) +++ branches/cleanup-2008/milena/mln/canvas/browsing/hyper_directional.hh (revision 2534) @@ -0,0 +1,134 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_CANVAS_BROWSING_HYPER_DIRECTIONAL_HH +# define MLN_CANVAS_BROWSING_HYPER_DIRECTIONAL_HH + +/*! \file mln/canvas/browsing/hyper_directional.hh + * + * \brief Hyper_Directional browsing of an image. + */ + +# include <mln/core/concept/browsing.hh> +# include <mln/core/concept/image.hh> + +namespace mln +{ + + namespace canvas + { + + namespace browsing + { + + /*! + * \brief Browsing in a certain direction. + * + * This canvas browse all the point of an image 'input' of type + * 'I' and of dimension 'dim' in the direction 'dir'. + * + * The functor should provide (In addition to 'input', 'I', + * 'dim' and 'dir') three methods : + * + * - init() : Will be called at the beginning. + * - next() : Will be called at each point 'p' (also provided by + * the fonctor). + * - final(): Will be called at the end. + * + * F shall features : \n + * { \n + * --- as types: \n + * I; \n + * --- as attributes: \n + * dim; \n + * dir; // and test dir < dim \n + * input; \n + * p; \n + * --- as methods: \n + * void init(); \n + * void next(); \n + * void final(); \n + * } \n + * + */ + struct hyper_directional_t : public Browsing< hyper_directional_t > + { + template <typename F> + void operator()(F& f) const; + } + + hyper_directional; + +# ifndef MLN_INCLUDE_ONLY + + template <typename F> + inline + void + hyper_directional_t::operator()(F& f) const + { + trace::entering("canvas::browsing::hyper_directional"); + mln_precondition(f.dir < f.dim); + typedef typename F::I I; + + mln_psite(I) + pmin = f.input.domain().pmin(), + pmax = f.input.domain().pmax(); + + f.p = pmin; + + f.init(); + + do + { + f.next(); + + for (int c = F::dim - 1; c >= 0; --c) + { + if (c == int(f.dir)) + continue; + if (f.p[c] != pmax[c]) + { + ++f.p[c]; + break; + } + f.p[c] = pmin[c]; + } + } while (f.p != pmin); + + f.final(); + trace::exiting("canvas::browsing::hyper_directional"); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::canvas::browsing + + } // end of namespace mln::canvas + +} // end of namespace mln + +#endif // ! MLN_CANVAS_BROWSING_HYPER_DIRECTIONAL_HH
participants (1)
-
Matthieu Garrigues