URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-01 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Rename dirbrowsing and improve it.
* mln/canvas/dirbrowsing.hh: Rename as ...
* mln/canvas/browsing/directional.hh: ...this.
* mln/level/median.hh: Update.
* tests/canvas_browsing_fwd.cc: Update.
---
mln/canvas/browsing/directional.hh | 118 +++++++++++++++++++++++++++++++++++++
mln/level/median.hh | 20 ++++--
tests/canvas_browsing_fwd.cc | 31 ++++++---
3 files changed, 153 insertions(+), 16 deletions(-)
Index: trunk/milena/tests/canvas_browsing_fwd.cc
===================================================================
--- trunk/milena/tests/canvas_browsing_fwd.cc (revision 1205)
+++ trunk/milena/tests/canvas_browsing_fwd.cc (revision 1206)
@@ -31,11 +31,14 @@
*/
#include <mln/core/image2d_b.hh>
+#include <mln/core/image3d_b.hh>
#include <mln/canvas/browsing/fwd.hh>
#include <mln/canvas/browsing/snake_fwd.hh>
+#include <mln/canvas/browsing/directional.hh>
#include <mln/fun/p2v/iota.hh>
#include <mln/pw/image.hh>
#include <mln/debug/println.hh>
+#include <mln/level/fill.hh>
@@ -46,13 +49,17 @@
struct assign_browsing_functor
{
typedef I_ I;
+ enum { dim = I::point::dim };
+
I input;
F f;
+ int dir;
- assign_browsing_functor(I& input, F f = F())
+ assign_browsing_functor(I& input, F f = F(), int dir_ = 0)
: input(input),
- f(f)
+ f(f),
+ dir(dir_)
{}
mln_psite(I) p;
@@ -74,13 +81,14 @@
template <typename I, typename F, typename B>
void my_test(Image<I>& ima_,
const Function_p2v<F>& f_,
- const Browsing<B>& browse_)
+ 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);
+ assign_browsing_functor<I, F> fun(ima, f, dir);
browse(fun);
}
@@ -90,11 +98,16 @@
int main()
{
using namespace mln;
- image2d_b<unsigned> ima(3, 3);
+ image2d_b<unsigned> ima2(3, 3);
+ image3d_b<unsigned> ima3(3, 3, 3);
+
+ my_test(ima2, fun::p2v::iota, canvas::browsing::fwd);
+ debug::println(ima2);
- my_test(ima, fun::p2v::iota, canvas::browsing::fwd);
- debug::println(ima);
+ my_test(ima2, fun::p2v::iota, canvas::browsing::snake_fwd);
+ debug::println(ima2);
- my_test(ima, fun::p2v::iota, canvas::browsing::snake_fwd);
- debug::println(ima);
+ level::fill(ima3, 0);
+ my_test(ima3, fun::p2v::iota, canvas::browsing::directional, 1);
+ debug::println(ima3);
}
Index: trunk/milena/mln/level/median.hh
===================================================================
--- trunk/milena/mln/level/median.hh (revision 1205)
+++ trunk/milena/mln/level/median.hh (revision 1206)
@@ -41,7 +41,7 @@
# include <mln/set/diff.hh>
# include <mln/canvas/browsing/snake_fwd.hh>
-# include <mln/canvas/dirbrowsing.hh>
+# include <mln/canvas/browsing/directional.hh>
# include <mln/accu/median.hh>
@@ -176,11 +176,11 @@
- template <typename I, typename O>
+ template <typename I_, typename O>
struct median_dir_t
{
- typedef mln_point(I) point;
- enum { dim = point::dim };
+ typedef I_ I;
+ enum { dim = I::point::dim };
// i/o
const I& input;
@@ -189,6 +189,7 @@
O& output;
// aux data
+ mln_point(I) p;
const mln_point(I)
pmin, pmax;
const mln_coord(I)
@@ -204,6 +205,7 @@
length(length),
output(exact(output)),
// aux data
+ p(),
pmin(input.domain().pmin()),
pmax(input.domain().pmax()),
pmin_dir(pmin[dir]),
@@ -218,10 +220,10 @@
{
}
- void process(const mln_point(I)& p_)
+ void next()
{
mln_point(I)
- p = p_,
+ p = this->p,
pt = p,
pu = p;
@@ -268,6 +270,10 @@
}
}
+ void final()
+ {
+ }
+
}; // end of median_dir_t
@@ -276,7 +282,7 @@
void median_dir_(const Image<I>& input, unsigned dir, unsigned length,
O& output)
{
median_dir_t<I,O> f(exact(input), dir, length, output);
- canvas::dirbrowsing(f);
+ canvas::browsing::directional(f);
}
Index: trunk/milena/mln/canvas/dirbrowsing.hh (deleted)
===================================================================
Index: trunk/milena/mln/canvas/browsing/directional.hh
===================================================================
--- trunk/milena/mln/canvas/browsing/directional.hh (revision 0)
+++ trunk/milena/mln/canvas/browsing/directional.hh (revision 1206)
@@ -0,0 +1,118 @@
+// 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_DIRBROWSING_HH
+# define MLN_CANVAS_DIRBROWSING_HH
+
+/*! \file mln/canvas/dirbrowsing.hh
+ *
+ * \brief Directional browsing of an image.
+ */
+
+# include <mln/core/concept/browsing.hh>
+# include <mln/core/concept/image.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace browsing
+ {
+
+ /*! FIXME : DOC
+ * 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 directional_t : public Browsing< directional_t >
+ {
+ template <typename F>
+ void operator()(F& f) const;
+ }
+
+ directional;
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename F>
+ void
+ directional_t::operator()(F& f) const
+ {
+ mln_precondition(f.dir < f.dim);
+ typedef typename F::I I;
+
+ mln_point(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();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::browsing
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+#endif // ! MLN_CANVAS_DIRBROWSING_HH