URL:
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-09-22 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add snake_vert browsing canvas.
* mln/canvas/browsing/snake_vert.hh: New, snake vert browsing
canvas. This canvas browse all the point of an image 'input' like
this :
1 4 5
|| /\ ||
|| || ||
\/ || \/
2 3 6
* tests/canvas/browsing/Makefile.am: Add snake_vert test.
* tests/canvas/browsing/snake_vert.cc: New. The test.
* mln/canvas/browsing/snake_fwd.hh: Desactivate check
of dimension.
---
mln/canvas/browsing/snake_fwd.hh | 8 +
mln/canvas/browsing/snake_vert.hh | 166 ++++++++++++++++++++++++++++++++++++
tests/canvas/browsing/Makefile.am | 2
tests/canvas/browsing/snake_vert.cc | 96 ++++++++++++++++++++
4 files changed, 269 insertions(+), 3 deletions(-)
Index: branches/cleanup-2008/milena/tests/canvas/browsing/snake_vert.cc
===================================================================
--- branches/cleanup-2008/milena/tests/canvas/browsing/snake_vert.cc (revision 0)
+++ branches/cleanup-2008/milena/tests/canvas/browsing/snake_vert.cc (revision 2344)
@@ -0,0 +1,96 @@
+// 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/snake_vert.cc
+ *
+ * \brief Tests on mln::canvas::browsing::snake_vert.
+ */
+
+#include <mln/core/image/image2d.hh>
+#include <mln/canvas/browsing/snake_vert.hh>
+#include <mln/fun/p2v/iota.hh>
+#include <mln/debug/println.hh>
+
+// FIXME: Move code below into mln/canvas/browsing/iota.hh.
+
+
+template <typename I, typename F>
+struct assign_browsing_functor
+{
+ enum { dim = I::site::dim };
+
+
+ I input;
+ F f;
+
+ assign_browsing_functor(I& input, F f = F())
+ : input(input),
+ f(f)
+ {}
+
+ mln_psite(I) p;
+
+ void init() {}
+ void final() {}
+ void next()
+ {
+ input(p) = f(p);
+// mln_assertion(input(p) - 1 == p[0] * input.domain().ncols()
+// + ( (p[0] % 2) ? input.domain().ncols() - 1 - p[1] : p[1]));
+ }
+ void fwd() { next(); }
+ void up() { 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_)
+ {
+ I& ima = exact(ima_);
+ const F& f = exact(f_);
+ const B& browse = exact(browse_);
+
+ assign_browsing_functor<I, F> fun(ima, f);
+ browse(fun);
+ }
+
+}
+
+
+int main()
+{
+ using namespace mln;
+ image2d<unsigned> ima2(2, 7);
+
+ my_test(ima2, fun::p2v::iota, canvas::browsing::snake_vert);
+ debug::println(ima2);
+}
Index: branches/cleanup-2008/milena/tests/canvas/browsing/Makefile.am
===================================================================
--- branches/cleanup-2008/milena/tests/canvas/browsing/Makefile.am (revision 2343)
+++ branches/cleanup-2008/milena/tests/canvas/browsing/Makefile.am (revision 2344)
@@ -5,11 +5,13 @@
check_PROGRAMS = \
fwd \
snake_fwd \
+ snake_vert \
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
dir_struct_elt_incr_update_SOURCES = dir_struct_elt_incr_update.cc
Index: branches/cleanup-2008/milena/mln/canvas/browsing/snake_fwd.hh
===================================================================
--- branches/cleanup-2008/milena/mln/canvas/browsing/snake_fwd.hh (revision 2343)
+++ branches/cleanup-2008/milena/mln/canvas/browsing/snake_fwd.hh (revision 2344)
@@ -101,7 +101,9 @@
void
snake_fwd_t::operator()(F& f) const
{
- // FIXME: Check the dimension (2D) or generalize.
+ // Fixme: check the dimension of the input
+// mlc_equal(mln_trait_image_dimension(I)(),
+// trait::image::dimension::two_d)::check();
trace::entering("canvas::browsing::snake_fwd");
mln_precondition(f.input.has_data());
int
@@ -141,9 +143,9 @@
while (col > min_col)
{
--col;
- trace::entering("canvas::browsing::snake_fwd");
+ trace::entering("canvas::browsing::snake_fwd::bkd");
f.bkd();
- trace::exiting("canvas::browsing::snake_fwd");
+ trace::exiting("canvas::browsing::snake_fwd::bkd");
}
// change browsing
Index: branches/cleanup-2008/milena/mln/canvas/browsing/snake_vert.hh
===================================================================
--- branches/cleanup-2008/milena/mln/canvas/browsing/snake_vert.hh (revision 0)
+++ branches/cleanup-2008/milena/mln/canvas/browsing/snake_vert.hh (revision 2344)
@@ -0,0 +1,166 @@
+// 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_SNAKE_VERT_HH
+# define MLN_CANVAS_BROWSING_SNAKE_VERT_HH
+
+/*! \file mln/canvas/browsing/snake_vert.hh
+ *
+ * \brief Browsing in a snake-way, forward.
+ */
+
+# include <mln/core/concept/browsing.hh>
+# include <mln/geom/size2d.hh>
+
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace browsing
+ {
+
+ /*!
+ * \brief Browsing in a snake-way, forward.
+ *
+ * This canvas browse all the point of an image 'input' like
+ * this :
+ *
+ * | /\ |
+ * | | |
+ * \/ | \/
+ *
+ * The fonctor should provide (In addition to 'input') four
+ * methods :
+ *
+ * - init() : Will be called at the beginning.
+ * - down() : Will be called after each moving down.
+ * - up() : Will ba called after each moving up.
+ * - fwd() : Will be called after each moving right. (will
+ * also be called once at the first point).
+ *
+ * This methods should acces to the current working point 'p'
+ * also provided by the functor.
+ *
+ * Warning: This canvas works only on 2D.
+ *
+ * F shall feature: \n
+ * { \n
+ * --- as attributes: \n
+ * input; \n
+ * p; \n
+ * --- as methods: \n
+ * void init(); \n
+ * void down(); \n
+ * void up(); \n
+ * void fwd(); \n
+ * } \n
+ *
+ */
+
+ struct snake_vert_t : public Browsing< snake_vert_t >
+ {
+ template <typename F>
+ void operator()(F& f) const;
+ }
+
+ snake_vert;
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename F>
+ inline
+ void
+ snake_vert_t::operator()(F& f) const
+ {
+ // Fixme: check the dimension of the input
+// mlc_equal(mln_trait_image_dimension(I)(),
+// trait::image::dimension::two_d)::check();
+ trace::entering("canvas::browsing::snake_vert");
+ mln_precondition(f.input.has_data());
+ int
+ min_row = geom::min_row(f.input), max_row = geom::max_row(f.input),
+ min_col = geom::min_col(f.input), max_col = geom::max_col(f.input);
+
+ // p
+ f.p = f.input.bbox().pmin();
+ def::coord& row = f.p.row();
+ def::coord& col = f.p.col();
+
+ // initialization
+ trace::entering("canvas::browsing::snake_vert::init");
+ f.init();
+ trace::exiting("canvas::browsing::snake_vert::init");
+
+ bool down = true;
+ for (col = min_col; col <= max_col; ++col)
+ // FIXME: Add "if (f.input.has(p))"?
+ {
+ // go fwd
+ trace::entering("canvas::browsing::snake_vert::init");
+ f.fwd();
+ trace::exiting("canvas::browsing::snake_vert::init");
+
+ if (down)
+ // browse col down.
+ while (row < max_row)
+ {
+ ++row;
+ trace::entering("canvas::browsing::snake_vert::down");
+ f.down();
+ trace::exiting("canvas::browsing::snake_vert::down");
+ }
+ else
+ // browse col up.
+ while (row > min_row)
+ {
+ --row;
+ trace::entering("canvas::browsing::snake_vert::up");
+ f.up();
+ trace::exiting("canvas::browsing::snake_vert::up");
+ }
+
+ // change browsing
+ down = ! down;
+ }
+ trace::exiting("canvas::browsing::snake_vert");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::browsing
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_BROWSING_SNAKE_VERT_HH