https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a canvas to milena.
* mln/level/median.hh (impl::median): Rename as...
(impl::median_as_procedure): ...this.
(impl::median_functor, impl::median): New.
* mln/canvas: New.
* mln/canvas/sbrowsing.hh: New.
canvas/sbrowsing.hh | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
level/median.hh | 89 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 198 insertions(+), 1 deletion(-)
Index: mln/level/median.hh
--- mln/level/median.hh (revision 1011)
+++ mln/level/median.hh (working copy)
@@ -37,6 +37,8 @@
# include <mln/core/window2d.hh>
# include <mln/accu/median.hh>
+# include <mln/canvas/sbrowsing.hh>
+
namespace mln
{
@@ -65,7 +67,7 @@
{
template <typename I, typename W, typename O>
- void median(const I& input,
+ void median_as_procedure(const I& input,
const W& win,
O& output)
{
@@ -146,6 +148,91 @@
}
}
+
+ template <typename I, typename W, typename O>
+ struct median_functor
+ {
+ // i/o
+
+ const I& input;
+ const W& win;
+ O& output;
+
+ // aux data
+
+ mln_point(I) p;
+ window2d win_fp, win_fm, win_bp, win_bm, win_dp, win_dm;
+ mln_qiter(W) q_fp, q_fm, q_bp, q_bm, q_dp, q_dm;
+ accu::median_on<mln_value(I)> med;
+
+ // ctor
+
+ median_functor(I& input_, const W& win_, O& output_)
+ :
+ // i/o
+ input(exact(input_)),
+ win(exact(win_)),
+ output(exact(output_)),
+ // aux data
+ p(),
+ win_fp(win - (win + left)), win_fm((win + left) - win),
+ win_bp(win - (win + right)), win_bm((win + right) - win),
+ win_dp(win - (win + up)), win_dm((win + up) - win),
+ q_fp(win_fp, p), q_fm(win_fm, p),
+ q_bp(win_bp, p), q_bm(win_bm, p),
+ q_dp(win_dp, p), q_dm(win_dm, p)
+ {
+ }
+
+ // parts
+
+ void init()
+ {
+ med.init();
+ mln_qiter(W) q(win, p);
+ for_all(q) if (input.has(q))
+ med.take(input(q));
+ }
+
+ void down()
+ {
+ for_all(q_dm) if (input.has(q_dm))
+ med.untake(input(q_dm));
+ for_all(q_dp) if (input.has(q_dp))
+ med.take(input(q_dp));
+ output(p) = med;
+ }
+
+ void fwd()
+ {
+ for_all(q_fm) if (input.has(q_fm))
+ med.untake(input(q_fm));
+ for_all(q_fp) if (input.has(q_fp))
+ med.take(input(q_fp));
+ output(p) = med;
+ }
+
+ void bkd()
+ {
+ for_all(q_bm) if (input.has(q_bm))
+ med.untake(input(q_bm));
+ for_all(q_bp) if (input.has(q_bp))
+ med.take(input(q_bp));
+ output(p) = med;
+ }
+
+ }; // end of median_functor
+
+
+ template <typename I, typename W, typename O>
+ void median(I& input, const W& win, O& output)
+ {
+ // FIXME: resize border!
+ impl::median_functor<I,W,O> f(input, win, output);
+ canvas::sbrowsing(f);
+ }
+
+
} // end of namespace mln::level::impl
Index: mln/canvas/sbrowsing.hh
--- mln/canvas/sbrowsing.hh (revision 0)
+++ mln/canvas/sbrowsing.hh (revision 0)
@@ -0,0 +1,110 @@
+// 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_SBROWSING_HH
+# define MLN_CANVAS_SBROWSING_HH
+
+/*! \file mln/canvas/sbrowsing.hh
+ *
+ * \brief Sbrowsing of an image.
+ */
+
+# include <mln/core/dpoint2d.hh> // for "up"
+
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ /*! FIXME: Doc!
+ *
+ *
+ * F should be
+ * {
+ * input; p; --- attributes
+ * void init();
+ * void down(); void fwd(); void bkd(); --- methods
+ * }
+ */
+ template <typename F>
+ void sbrowsing(F& f);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename F>
+ void sbrowsing(F& f)
+ {
+ mln_precondition(f.input.has_data());
+ int
+ min_row = f.input.min_row(), max_row = f.input.max_row(),
+ min_col = f.input.min_col(), max_col = f.input.max_col();
+
+ // p
+ f.p = f.input.domain().pmin() + up;
+ int& row = f.p.row();
+ int& col = f.p.col();
+
+ // initialization
+ f.init();
+
+ bool fwd = true;
+ for (row = min_row; row <= max_row; ++row)
+ {
+ // go down
+ f.down();
+
+ if (fwd)
+ // browse line fwd
+ while (col < max_col)
+ {
+ ++col;
+ f.fwd();
+ }
+ else
+ // browse line bkd
+ while (col > min_col)
+ {
+ --col;
+ f.bkd();
+ }
+
+ // change browsing
+ fwd = ! fwd;
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_SBROWSING_HH