Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add morphological top-hats and contrast.
* tests/morpho_gradient.cc: Fix doc.
* mln/geom/pmin_pmax.hh (pmin_pmax): Overload for point set.
* mln/geom/bbox.hh: Update.
* mln/morpho/includes.hh (include): Add mln/test/positive.hh
and mln/arith/plus.hh.
* mln/morpho/gradient.hh: Add commentaries.
* tests/morpho_contrast.cc: New.
* mln/morpho/contrast.hh: New.
* mln/morpho/top_hat.hh: New.
mln/geom/bbox.hh | 3 -
mln/geom/pmin_pmax.hh | 91 ++++++++++++++++++++++++++----
mln/morpho/contrast.hh | 82 +++++++++++++++++++++++++++
mln/morpho/gradient.hh | 21 +++----
mln/morpho/includes.hh | 3 +
mln/morpho/top_hat.hh | 138 +++++++++++++++++++++++++++++++++++++++++++++++
tests/morpho_contrast.cc | 61 ++++++++++++++++++++
tests/morpho_gradient.cc | 4 -
8 files changed, 373 insertions(+), 30 deletions(-)
Index: tests/morpho_gradient.cc
--- tests/morpho_gradient.cc (revision 1058)
+++ tests/morpho_gradient.cc (working copy)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/erosion.cc
+/*! \file tests/morpho_gradient.cc
*
- * \brief Test on mln::morpho::erosion.
+ * \brief Test on mln::morpho::gradient.
*/
#include <mln/core/image2d_b.hh>
Index: tests/morpho_contrast.cc
--- tests/morpho_contrast.cc (revision 0)
+++ tests/morpho_contrast.cc (revision 0)
@@ -0,0 +1,61 @@
+// 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/morpho_contrast.cc
+ *
+ * \brief Test on mln::morpho::contrast.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/win/rectangle2d.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/morpho/contrast.hh>
+#include <mln/level/saturate.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ win::rectangle2d rect(5, 5);
+ border::thickness = 2;
+
+ image2d_b<int_u8>
+ lena = io::load_pgm("../img/tiny.pgm"),
+ out(lena.domain());
+
+ image2d_b<int> tmp(lena.domain());
+ morpho::contrast(lena, rect, tmp);
+
+ level::saturate(tmp, out);
+ io::save_pgm(out, "out.pgm");
+}
Index: mln/geom/pmin_pmax.hh
--- mln/geom/pmin_pmax.hh (revision 1058)
+++ mln/geom/pmin_pmax.hh (working copy)
@@ -36,6 +36,10 @@
# include <utility>
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/box.hh>
+
+
namespace mln
{
@@ -44,6 +48,19 @@
{
+ /// Compute the minimum and maximum points of point set \p s.
+ template <typename S>
+ std::pair<mln_point(S), mln_point(S)>
+ pmin_pmax(const Point_Set<S>& s);
+
+
+ /// Compute the minimum and maximum points, \p pmin and \p max,
+ /// of point set \p s.
+ template <typename S>
+ void
+ pmin_pmax(const Point_Set<S>& s, mln_point(S)& pmin, mln_point(S)& pmax);
+
+
/// Compute the minimum and maximum points when browsing with
/// iterator \p p.
template <typename I>
@@ -61,40 +78,86 @@
# ifndef MLN_INCLUDE_ONLY
+
+ // Versions with point iterator.
+
template <typename I>
- std::pair<mln_point(I), mln_point(I)>
- pmin_pmax(Point_Iterator<I>& p_)
+ void
+ pmin_pmax(const Point_Iterator<I>& p_, mln_point(I)& pmin, mln_point(I)& pmax)
{
- I& p = exact(p_);
-
- typedef mln_point(I) P;
- std::pair<P, P> tmp;
- P& pmin = tmp.first;
- P& pmax = tmp.second;
+ I p = exact(p_); // a copy of p_
// init with first point
p.start();
+ mln_precondition(p.is_valid());
pmin = pmax = p;
// update with remaining points
+ typedef mln_point(I) P;
for_all_remaining(p)
for (unsigned i = 0; i < P::dim; ++i)
if (p[i] < pmin[i])
pmin[i] = p[i];
else if (p[i] > pmax[i])
pmax[i] = p[i];
+ }
+ template <typename I>
+ std::pair<mln_point(I), mln_point(I)>
+ pmin_pmax(const Point_Iterator<I>& p)
+ {
+ typedef mln_point(I) P;
+ std::pair<P, P> tmp;
+ pmin_pmax(p, tmp.first, tmp.second); // calls the previous version
return tmp;
}
- template <typename I>
+
+ // Versions with point set.
+
+ namespace impl
+ {
+
+ // General case.
+
+ template <typename S>
void
- pmin_pmax(const Point_Iterator<I>& p, mln_point(I)& pmin, mln_point(I)& pmax)
+ pmin_pmax_(const Point_Set<S>& s, mln_point(S)& pmin, mln_point(S)& pmax)
{
- typedef mln_point(I) P;
- std::pair<P, P> tmp = pmin_pmax(p);
- pmin = tmp.first;
- pmax = tmp.second;
+ mln_piter(S) it(exact(s));
+ pmin_pmax(it, pmin, pmax);
+ }
+
+ // Box.
+
+ template <typename B>
+ void
+ pmin_pmax_(const Box<B>& b, mln_point(B)& pmin, mln_point(B)& pmax)
+ {
+ pmin = exact(b).pmin();
+ pmax = exact(b).pmax();
+ }
+
+ } // end of namespace mln::geom::impl
+
+
+ template <typename S>
+ void
+ pmin_pmax(const Point_Set<S>& s, mln_point(S)& pmin, mln_point(S)& pmax)
+ {
+ mln_precondition(exact(s).npoints() != 0);
+ impl::pmin_pmax_(exact(s), pmin, pmax);
+ }
+
+ template <typename S>
+ std::pair<mln_point(S), mln_point(S)>
+ pmin_pmax(const Point_Set<S>& s)
+ {
+ mln_precondition(exact(s).npoints() != 0);
+ typedef mln_point(S) P;
+ std::pair<P, P> tmp;
+ pmin_pmax(p_, tmp.first, tmp.second); // calls the previous version
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/geom/bbox.hh
--- mln/geom/bbox.hh (revision 1058)
+++ mln/geom/bbox.hh (working copy)
@@ -100,8 +100,7 @@
mln_precondition(pset.npoints() != 0);
typedef mln_point(S) P;
- mln_piter(S) p(pset);
- std::pair<P, P> pp = geom::pmin_pmax(p);
+ std::pair<P, P> pp = geom::pmin_pmax(pset);
box_<P> tmp(pp.first, pp.second);
// FIXME: mln_postcondition(tmp <= pset.bbox());
Index: mln/morpho/includes.hh
--- mln/morpho/includes.hh (revision 1058)
+++ mln/morpho/includes.hh (working copy)
@@ -40,11 +40,14 @@
# include <mln/accu/min.hh>
# include <mln/accu/max.hh>
+# include <mln/arith/plus.hh>
# include <mln/arith/minus.hh>
# include <mln/level/compare.hh>
# include <mln/level/fill.hh>
+# include <mln/test/positive.hh>
+
# include <mln/border/resize.hh>
# include <mln/border/fill.hh>
Index: mln/morpho/gradient.hh
--- mln/morpho/gradient.hh (revision 1058)
+++ mln/morpho/gradient.hh (working copy)
@@ -31,10 +31,11 @@
/*! \file mln/morpho/gradient.hh
*
* \brief Morphological gradient.
+ *
+ * \todo Save memory.
*/
# include <mln/morpho/includes.hh>
-# include <mln/test/positive.hh>
namespace mln
@@ -82,11 +83,10 @@
mln_precondition(output.domain() = input.domain());
mln_precondition(! win.is_empty());
+ dilation(input, win, output); // output = dilation
O temp(input.domain());
- erosion(input, win, temp);
-
- dilation(input, win, output);
- arith::minus_inplace(output, temp);
+ erosion(input, win, temp); // temp = erosion
+ arith::minus_inplace(output, temp); // now output = dilation - erosion
mln_postcondition(test::positive(output));
}
@@ -103,9 +103,8 @@
mln_precondition(! win.is_empty());
O temp(input.domain());
- erosion(input, win, temp);
-
- arith::minus(input, temp, output);
+ erosion(input, win, temp); // temp = erosion
+ arith::minus(input, temp, output); // output = input - erosion
mln_postcondition(test::positive(output));
}
@@ -121,10 +120,8 @@
mln_precondition(output.domain() = input.domain());
mln_precondition(! win.is_empty());
- O temp(input.domain());
- dilation(input, win, temp);
-
- arith::minus(temp, input, output);
+ dilation(input, win, output); // output = dilation
+ arith::minus_inplace(output, input); // now output = dilation - input
mln_postcondition(test::positive(output));
}
Index: mln/morpho/contrast.hh
--- mln/morpho/contrast.hh (revision 0)
+++ mln/morpho/contrast.hh (revision 0)
@@ -0,0 +1,82 @@
+// 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_MORPHO_CONTRAST_HH
+# define MLN_MORPHO_CONTRAST_HH
+
+/*! \file mln/morpho/contrast.hh
+ *
+ * \brief Morphological contrast operator (based on top-hats).
+ *
+ * \todo Save memory.
+ */
+
+# include <mln/morpho/top_hat.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /*! Morphological contrast operator (based on top-hats).
+ *
+ * This operator is Id + wth_B - bth_B.
+ */
+ template <typename I, typename W, typename O>
+ void contrast(const Image<I>& input, const Window<W>& win,
+ Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename W, typename O>
+ void contrast(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ top_hat_white(input, win, output); // output = wth
+ arith::plus_inplace(output, input); // now output = wth + input
+ O temp(input.domain());
+ top_hat_black(input, win, temp); // temp = bth
+ arith::minus_inplace(output, temp); // now output = wth + input - bth
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_CONTRAST_HH
Index: mln/morpho/top_hat.hh
--- mln/morpho/top_hat.hh (revision 0)
+++ mln/morpho/top_hat.hh (revision 0)
@@ -0,0 +1,138 @@
+// 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_MORPHO_TOP_HAT_HH
+# define MLN_MORPHO_TOP_HAT_HH
+
+/*! \file mln/morpho/top_hat.hh
+ *
+ * \brief Morphological top-hats.
+ *
+ * \todo Save memory.
+ */
+
+# include <mln/morpho/opening.hh>
+# include <mln/morpho/closing.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /*! Morphological white top-hat (for object / light objects).
+ *
+ * This operator is Id - ope_B.
+ */
+ template <typename I, typename W, typename O>
+ void top_hat_white(const Image<I>& input, const Window<W>& win,
+ Image<O>& output);
+
+
+ /*! Morphological black top-hat (for background / dark objects).
+ *
+ * This operator is clo_B - Id.
+ */
+ template <typename I, typename W, typename O>
+ void top_hat_black(const Image<I>& input, const Window<W>& win,
+ Image<O>& output);
+
+
+ /*! Morphological self-complementary top-hat.
+ *
+ * This operator is \n
+ * = top_hat_white + top_hat_black \n
+ * = (input - opening) + (closing - input) \n
+ * = closing - opening. \n
+ */
+ template <typename I, typename W, typename O>
+ void top_hat_self_complementary(const Image<I>& input, const Window<W>& win,
+ Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename W, typename O>
+ void top_hat_white(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ O temp(input.domain());
+ opening(input, win, temp); // temp = opening
+ arith::minus(input, temp, output); // output = input - opening
+
+ mln_postcondition(test::positive(output));
+ }
+
+ template <typename I, typename W, typename O>
+ void top_hat_black(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ closing(input, win, output); // output = closing
+ arith::minus_inplace(output, input); // now output = closing - input
+
+ mln_postcondition(test::positive(output));
+ }
+
+ template <typename I, typename W, typename O>
+ void top_hat_self_complementary(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ closing(input, win, output); // output = closing
+ O temp(input.domain());
+ opening(input, win, temp); // temp = opening
+ arith::minus_inplace(output, temp); // now output = closing - opening
+
+ mln_postcondition(test::positive(output));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_TOP_HAT_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Replace 2D specific methods in 2D images by routines.
* mln/geom/max_col.hh: New.
* mln/geom/nrows.hh: New.
* mln/geom/min_row.hh: New.
* mln/geom/max_row.hh: New.
* mln/geom/ncols.hh: New.
* mln/geom/size2d.hh: New.
* mln/geom/min_col.hh: New.
* mln/core/image2d_b.hh (image2d_b): Remove inheritance to
box_impl.
* tests/image2d_b.cc,
* mln/core/pixter2d_b.hh,
* mln/io/save_pgm.hh,
* mln/io/load_pgm.hh,
* mln/level/was.median.hh,
* mln/level/median.hh,
* mln/level/fast_median.hh,
* mln/canvas/sbrowsing.hh: Update.
mln/canvas/sbrowsing.hh | 7 ++--
mln/core/image2d_b.hh | 4 --
mln/core/pixter2d_b.hh | 5 ++-
mln/geom/max_col.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++
mln/geom/max_row.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++
mln/geom/min_col.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++
mln/geom/min_row.hh | 66 ++++++++++++++++++++++++++++++++++++++++++++++
mln/geom/ncols.hh | 67 +++++++++++++++++++++++++++++++++++++++++++++++
mln/geom/nrows.hh | 67 +++++++++++++++++++++++++++++++++++++++++++++++
mln/geom/size2d.hh | 40 ++++++++++++++++++++++++++++
mln/io/load_pgm.hh | 10 +++----
mln/io/save_pgm.hh | 17 +++++------
mln/level/fast_median.hh | 4 +-
mln/level/median.hh | 10 ++++---
mln/level/was.median.hh | 13 ++++-----
tests/image2d_b.cc | 3 +-
16 files changed, 475 insertions(+), 36 deletions(-)
Index: tests/image2d_b.cc
--- tests/image2d_b.cc (revision 1057)
+++ tests/image2d_b.cc (working copy)
@@ -31,6 +31,7 @@
*/
#include <mln/core/image2d_b.hh>
+#include <mln/geom/size2d.hh>
int main()
@@ -43,6 +44,6 @@
image2d_b<int> f(nrows, ncols, border);
- mln_assertion(f.npoints() = f.nrows() * f.ncols());
+ mln_assertion(f.npoints() = geom::nrows(f) * geom::ncols(f));
mln_assertion(f.ncells() = (nrows + 2 * border) * (ncols + 2 * border));
}
Index: mln/geom/max_col.hh
--- mln/geom/max_col.hh (revision 0)
+++ mln/geom/max_col.hh (revision 0)
@@ -0,0 +1,66 @@
+// 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_GEOM_MAX_COL_HH
+# define MLN_GEOM_MAX_COL_HH
+
+/*! \file mln/geom/max_col.hh
+ *
+ * \brief Give the maximum column of an image.
+ */
+
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /// Give the maximum column of an image.
+ template <typename I>
+ mln_coord(I) max_col(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_coord(I) max_col(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ return exact(ima).bbox().pmax().col();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_MAX_COL_HH
Index: mln/geom/nrows.hh
--- mln/geom/nrows.hh (revision 0)
+++ mln/geom/nrows.hh (revision 0)
@@ -0,0 +1,67 @@
+// 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_GEOM_NROWS_HH
+# define MLN_GEOM_NROWS_HH
+
+/*! \file mln/geom/nrows.hh
+ *
+ * \brief Give the number of rows of an image.
+ */
+
+# include <mln/geom/min_row.hh>
+# include <mln/geom/max_row.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /// Give the number of rows of an image.
+ template <typename I>
+ unsigned nrows(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ unsigned nrows(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ return geom::max_row(ima) - geom::min_row(ima) + 1;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_NROWS_HH
Index: mln/geom/min_row.hh
--- mln/geom/min_row.hh (revision 0)
+++ mln/geom/min_row.hh (revision 0)
@@ -0,0 +1,66 @@
+// 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_GEOM_MIN_ROW_HH
+# define MLN_GEOM_MIN_ROW_HH
+
+/*! \file mln/geom/min_row.hh
+ *
+ * \brief Give the minimum row of an image.
+ */
+
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /// Give the minimum row of an image.
+ template <typename I>
+ mln_coord(I) min_row(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_coord(I) min_row(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ return exact(ima).bbox().pmin().row();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_MIN_ROW_HH
Index: mln/geom/max_row.hh
--- mln/geom/max_row.hh (revision 0)
+++ mln/geom/max_row.hh (revision 0)
@@ -0,0 +1,66 @@
+// 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_GEOM_MAX_ROW_HH
+# define MLN_GEOM_MAX_ROW_HH
+
+/*! \file mln/geom/max_row.hh
+ *
+ * \brief Give the maximum row of an image.
+ */
+
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /// Give the maximum row of an image.
+ template <typename I>
+ mln_coord(I) max_row(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_coord(I) max_row(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ return exact(ima).bbox().pmax().row();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_MAX_ROW_HH
Index: mln/geom/ncols.hh
--- mln/geom/ncols.hh (revision 0)
+++ mln/geom/ncols.hh (revision 0)
@@ -0,0 +1,67 @@
+// 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_GEOM_NCOLS_HH
+# define MLN_GEOM_NCOLS_HH
+
+/*! \file mln/geom/ncols.hh
+ *
+ * \brief Give the number of columns of an image.
+ */
+
+# include <mln/geom/min_col.hh>
+# include <mln/geom/max_col.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /// Give the number of columns of an image.
+ template <typename I>
+ unsigned ncols(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ unsigned ncols(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ return geom::max_col(ima) - geom::min_col(ima) + 1;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_NCOLS_HH
Index: mln/geom/size2d.hh
--- mln/geom/size2d.hh (revision 0)
+++ mln/geom/size2d.hh (revision 0)
@@ -0,0 +1,40 @@
+// 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_GEOM_SIZE2D_HH
+# define MLN_GEOM_SIZE2D_HH
+
+/*! \file mln/geom/size2d.hh
+ *
+ * \brief Facade to include 2D size access routines.
+ */
+
+# include <mln/geom/nrows.hh>
+# include <mln/geom/ncols.hh>
+
+
+#endif // ! MLN_GEOM_SIZE2D_HH
Index: mln/geom/min_col.hh
--- mln/geom/min_col.hh (revision 0)
+++ mln/geom/min_col.hh (revision 0)
@@ -0,0 +1,66 @@
+// 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_GEOM_MIN_COL_HH
+# define MLN_GEOM_MIN_COL_HH
+
+/*! \file mln/geom/min_col.hh
+ *
+ * \brief Give the minimum column of an image.
+ */
+
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /// Give the minimum column of an image.
+ template <typename I>
+ mln_coord(I) min_col(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_coord(I) min_col(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ return exact(ima).bbox().pmin().col();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_MIN_COL_HH
Index: mln/core/pixter2d_b.hh
--- mln/core/pixter2d_b.hh (revision 1057)
+++ mln/core/pixter2d_b.hh (working copy)
@@ -35,6 +35,7 @@
# include <mln/core/internal/pixel_iterator_base.hh>
# include <mln/core/point2d.hh>
+# include <mln/geom/size2d.hh>
@@ -84,8 +85,8 @@
{
mln_precondition(image.has_data());
border_x2_ = 2 * image.border();
- row_offset_ = image.max_col() - image.min_col() + 1 + border_x2_;
- eor_ = & image.at(image.min_row(), image.max_col()) + 1;
+ row_offset_ = geom::max_col(image) - geom::min_col(image) + 1 + border_x2_;
+ eor_ = & image.at(geom::min_row(image), geom::max_col(image)) + 1;
}
template <typename I>
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1057)
+++ mln/core/image2d_b.hh (working copy)
@@ -34,7 +34,6 @@
*/
# include <mln/core/internal/image_base.hh>
-# include <mln/core/internal/box_impl.hh>
# include <mln/core/box2d.hh>
# include <mln/border/thickness.hh>
@@ -75,8 +74,7 @@
* thickness around data.
*/
template <typename T>
- struct image2d_b : public internal::image_base_< box2d, image2d_b<T> >,
- public internal::box_impl_< 2, int, image2d_b<T> >
+ struct image2d_b : public internal::image_base_< box2d, image2d_b<T> >
{
// Warning: just to make effective types appear in Doxygen:
typedef box2d pset;
Index: mln/io/save_pgm.hh
--- mln/io/save_pgm.hh (revision 1057)
+++ mln/io/save_pgm.hh (working copy)
@@ -33,6 +33,7 @@
# include <fstream>
# include <mln/core/image2d_b.hh>
+# include <mln/geom/size2d.hh>
# include <mln/value/int_u8.hh>
@@ -53,16 +54,16 @@
}
file << "P5" << std::endl;
file << "# olena" << std::endl;
- file << ima.ncols() << ' ' << ima.nrows() << std::endl;
+ file << geom::ncols(ima) << ' ' << geom::nrows(ima) << std::endl;
file << "255" << std::endl;
const int
- min_row = ima.domain().pmin().row(),
- max_row = ima.domain().pmax().row();
+ min_row = geom::min_row(ima),
+ max_row = geom::max_row(ima);
point2d p;
if (sizeof(value::int_u8) = 1)
{
- p.col() = ima.domain().pmin().col();
- size_t len = ima.ncols();
+ p.col() = geom::min_col(ima);
+ size_t len = geom::ncols(ima);
for (p.row() = min_row; p.row() <= max_row; ++p.row())
file.write((char*)(& ima(p)), len);
}
@@ -70,10 +71,8 @@
{
// FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!!
const int
- min_col = ima.domain().pmin().col(),
- max_col = ima.domain().pmax().col();
- std::cout << min_row << ' ' << max_row << std::endl;
- std::cout << min_col << ' ' << max_col << std::endl;
+ min_col = geom::min_col(ima),
+ max_col = geom::max_col(ima);
for (p.row() = min_row; p.row() <= max_row; ++p.row())
for (p.col() = min_col; p.col() <= max_col; ++p.col())
{
Index: mln/io/load_pgm.hh
--- mln/io/load_pgm.hh (revision 1057)
+++ mln/io/load_pgm.hh (working copy)
@@ -137,11 +137,11 @@
point2d p = make::point2d(0, ima.domain().pmin().col());
typedef mln_value(I) V;
const mln_coord(I)
- min_row = ima.domain().pmin().row(),
- max_row = ima.domain().pmax().row();
+ min_row = geom::min_row(ima),
+ max_row = geom::max_row(ima);
if (sizeof(V) = 1)
{
- size_t len = ima.ncols() * sizeof(mln_enc(V));
+ size_t len = geom::ncols(ima) * sizeof(mln_enc(V));
for (p.row() = min_row; p.row() <= max_row; ++p.row())
file.read((char*)(& ima(p)), len);
}
@@ -149,8 +149,8 @@
{
// FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!!
const mln_coord(I)
- min_col = ima.domain().pmin().col(),
- max_col = ima.domain().pmax().col();
+ min_col = geom::min_col(ima),
+ max_col = geom::max_col(ima);
for (p.row() = min_row; p.row() <= max_row; ++p.row())
for (p.col() = min_col; p.col() <= max_col; ++p.col())
{
Index: mln/level/was.median.hh
--- mln/level/was.median.hh (revision 1057)
+++ mln/level/was.median.hh (working copy)
@@ -55,8 +55,8 @@
mln_precondition(output.has_data());
int
- min_row = input.min_row(), max_row = input.max_row(),
- min_col = input.min_col(), max_col = input.max_col();
+ min_row = geom::min_row(input), max_row = geom::max_row(input),
+ min_col = geom::min_col(input), max_col = geom::max_col(input);
window2d
win_fwd_plus = win - (win + left),
@@ -76,7 +76,7 @@
// initialization
- p = input.domain().pmin() + up;
+ p = input.bbox().pmin() + up;
med.init();
{
mln_qiter(W) q(win, p);
@@ -137,9 +137,8 @@
{
const int
- max_row = input.max_row(),
- min_col = input.min_col(),
- max_col = input.max_col();
+ min_row = geom::min_row(input), max_row = geom::max_row(input),
+ min_col = geom::min_col(input), max_col = geom::max_col(input);
const unsigned half = win.length() / 2;
point2d p;
@@ -148,7 +147,7 @@
accu::median<mln_vset(I)> med(input.values());
- for (row = input.min_row(); row <= max_row; ++row)
+ for (row = min_row; row <= max_row; ++row)
{
int ct, cu;
Index: mln/level/median.hh
--- mln/level/median.hh (revision 1057)
+++ mln/level/median.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/geom/size2d.hh>
# include <mln/core/window2d.hh>
# include <mln/core/win/hline2d.hh>
@@ -162,9 +163,10 @@
{
typedef mln_coord(I) coord;
const coord
- max_row = input.bbox().max_row(),
- min_col = input.bbox().min_col(),
- max_col = input.bbox().max_col();
+ min_row = geom::min_row(input),
+ max_row = geom::max_row(input),
+ min_col = geom::min_col(input),
+ max_col = geom::max_col(input);
const coord half = win.length() / 2;
point2d p;
@@ -179,7 +181,7 @@
accu::median<mln_vset(I)> med(input.values());
- for (row = input.bbox().min_row(); row <= max_row; ++row)
+ for (row = min_row; row <= max_row; ++row)
{
pt.row() = pu.row() = row;
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 1057)
+++ mln/level/fast_median.hh (working copy)
@@ -73,8 +73,8 @@
mln_precondition(output.has_data());
int
- min_row = input.min_row(), max_row = input.max_row(),
- min_col = input.min_col(), max_col = input.max_col();
+ min_row = geom::min_row(input), max_row = geom::max_row(input),
+ min_col = geom::min_col(input), max_col = geom::max_col(input);
window2d
win_fwd_plus = win - (win + left),
Index: mln/canvas/sbrowsing.hh
--- mln/canvas/sbrowsing.hh (revision 1057)
+++ mln/canvas/sbrowsing.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/dpoint2d.hh> // for "up"
+# include <mln/geom/size2d.hh>
namespace mln
@@ -69,11 +70,11 @@
{
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();
+ 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.domain().pmin() + up;
+ f.p = f.input.bbox().pmin() + up;
int& row = f.p.row();
int& col = f.p.col();
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix compilation errors.
* tests/run_pset.cc: Fix and clean.
* tests/README: Augment.
* tests/erosion.cc: Clean.
* mln/core/internal/run_pset.hh: Fix.
* mln/core/concept/function.hh: Add explicit calls to cpy
ctors.
mln/core/concept/function.hh | 23 ++++++++----
mln/core/internal/run_pset.hh | 2 -
tests/README | 16 ++++++++
tests/erosion.cc | 7 ++-
tests/run_pset.cc | 77 ++++++++++++++++++++++++++----------------
5 files changed, 85 insertions(+), 40 deletions(-)
Index: tests/run_pset.cc
--- tests/run_pset.cc (revision 1056)
+++ tests/run_pset.cc (working copy)
@@ -1,58 +1,79 @@
-#include <mln/core/internal/run_pset.hh>
+// 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/run_pset.cc
+ *
+ * \brief Test on mln::internal::run_pset_ and related tools.
+ */
+
#include <mln/core/image2d_b.hh>
-#include <iostream>
+#include <mln/core/internal/run_pset.hh>
-using namespace mln;
template <typename Pset>
-void
-parc(const Pset& pset)
+void parc(const Pset& pset)
{
- typename Pset::fwd_piter it_(pset);
-
+ mln_fwd_piter(Pset) it_(pset);
for_all(it_)
- {
- std::cout << (typename Pset::point) it_ << std::endl;
- }
-
- typename Pset::bkd_piter rit_(pset);
+ std::cout << it_ << std::endl;
+ mln_bkd_piter(Pset) rit_(pset);
for_all(rit_)
- {
- std::cout << (typename Pset::point) rit_ << std::endl;
- }
+ std::cout << rit_ << std::endl;
}
-int
-main()
+int main()
{
+ using namespace mln;
+
point2d p, q, r;
p = make::point2d(2, 4);
q = make::point2d(18, 42);
r = make::point2d(50, 76);
// Psite declaration
- run_psite<point2d> site(p, 5, 0);
- run_psite<point2d> site2(r, 40, 0);
+ internal::run_psite<point2d> site(p, 5, 0);
+ internal::run_psite<point2d> site2(r, 40, 0);
// Pset test
internal::run_pset_<point2d> ps;
ps.insert(p, 7);
- assert(ps.npoints() = 7);
+ mln_assertion(ps.npoints() = 7);
ps.insert(q, 42);
- assert(ps.npoints() = 49);
+ mln_assertion(ps.npoints() = 49);
- assert(ps.has(site));
- assert(!ps.has(site2));
+ mln_assertion(ps.has(site));
+ mln_assertion(!ps.has(site2));
ps.insert(r, 14);
- assert(!ps.has(site2));
-
- // FIXME bbox test
+ mln_assertion(!ps.has(site2));
- parc(ps);
- return 0;
+ // parc(ps);
}
Index: tests/README
--- tests/README (revision 1056)
+++ tests/README (working copy)
@@ -4,14 +4,28 @@
* compilation
+** g++-4.1
+*** options
+-ansi -pedantic -W -Wall -Wextra -Wconversion
+*** sample
g++-4.1 -ansi -pedantic -W -Wall -Wextra -Wconversion -I.. sample.cc
+** g++-2.95
+*** options
+-ansi -pedantic -W -Wall -Wconversion -ftemplate-depth-51
+*** sample
g++-2.95 -ansi -pedantic -W -Wall -Wconversion -ftemplate-depth-51 -I.. sample.cc
+** icpc-9.1
+*** options
+-w1 -Wcheck -Werror -ansi
+*** sample
+icpc-9.1 -w1 -Wcheck -Werror -ansi -I.. sample.cc
+
* bench
+** median
naive: 18s
median: 1s
approx: 0.05s
-
Index: tests/erosion.cc
--- tests/erosion.cc (revision 1056)
+++ tests/erosion.cc (working copy)
@@ -54,12 +54,13 @@
win::rectangle2d rec(21, 21);
border::thickness = 66;
- image2d_b<int_u8>
- lena = io::load_pgm("../img/lena.pgm"),
- out(lena.domain());
+ image2d_b<int_u8> lena = io::load_pgm("../img/lena.pgm");
+ {
+ image2d_b<int_u8> out(lena.domain());
morpho::erosion(lena, rec, out);
io::save_pgm(out, "out.pgm");
+ }
{
image2d_b<bool> bin(lena.domain()), out(lena.domain());
Index: mln/core/internal/run_pset.hh
--- mln/core/internal/run_pset.hh (revision 1056)
+++ mln/core/internal/run_pset.hh (working copy)
@@ -217,7 +217,7 @@
}
template <typename P, typename E>
- run_piter_<P, E>::operator typename run_piter_<P, E>::psite () const
+ run_piter_<P, E>::operator internal::run_psite<P> () const
{
return site_;
}
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1056)
+++ mln/core/concept/function.hh (working copy)
@@ -148,7 +148,8 @@
}
template <typename E>
- Function<E>::Function(const Function<E>&)
+ Function<E>::Function(const Function<E>& rhs)
+ : Object<E>(rhs)
{
}
@@ -158,7 +159,8 @@
}
template <typename E>
- Function_v2v<E>::Function_v2v(const Function_v2v<E>&)
+ Function_v2v<E>::Function_v2v(const Function_v2v<E>& rhs)
+ : Function<E>(rhs)
{
}
@@ -168,7 +170,8 @@
}
template <typename E>
- Function_i2v<E>::Function_i2v(const Function_i2v<E>&)
+ Function_i2v<E>::Function_i2v(const Function_i2v<E>& rhs)
+ : Function_v2v<E>(rhs)
{
}
@@ -178,7 +181,8 @@
}
template <typename E>
- Function_p2v<E>::Function_p2v(const Function_p2v<E>&)
+ Function_p2v<E>::Function_p2v(const Function_p2v<E>& rhs)
+ : Function_v2v<E>(rhs)
{
}
@@ -188,7 +192,8 @@
}
template <typename E>
- Function_v2b<E>::Function_v2b(const Function_v2b<E>&)
+ Function_v2b<E>::Function_v2b(const Function_v2b<E>& rhs)
+ : Function_v2v<E>(rhs)
{
}
@@ -198,7 +203,10 @@
}
template <typename E>
- Function_p2b<E>::Function_p2b(const Function_p2b<E>&)
+ Function_p2b<E>::Function_p2b(const Function_p2b<E>& rhs)
+ : Function_v2v<E>(rhs),
+ Function_p2v<E>(rhs),
+ Function_v2b<E>(rhs)
{
}
@@ -208,7 +216,8 @@
}
template <typename E>
- Function_p2p<E>::Function_p2p(const Function_p2p<E>&)
+ Function_p2p<E>::Function_p2p(const Function_p2p<E>& rhs)
+ : Function_p2v<E>(rhs)
{
}
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment morpho and add saturation for int-like types.
* mln/arith/minus.hh (minus_inplace): New.
* mln/arith/plus.hh (plus_inplace): New.
* mln/fun/v2v/saturate.hh: New.
* mln/level/abs.hh: New.
* mln/level/saturate.hh: New.
* mln/linear/sobel.hh: Update.
* mln/math/round.hh (round_): Rename as...
(round): ...this.
* tests/convolve.cc,
* tests/line_convolve.cc,
* tests/sobel.cc: Update.
* mln/linear/line_convolve.hh,
* mln/linear/line_x2_convolve.hh,
* mln/make/w_window_line.hh: Unconst array literals to help
g++-2.95.
* mln/core/concept/function.hh (Function_v2b): New.
* mln/core/macros.hh (mln_value_): New.
* mln/fun/ops.hh (l_, r_, f_): Add const.
(mln_decl_binary_expr_): Use 'Out' part of fun type name.
(mln_decl_unary_expr_): Likewise.
New overload for "v2v -> v2b" operators.
* mln/fun/v2v/id.hh: New.
* mln/level/assign.hh,
* mln/level/fill.hh: Add todo.
* mln/morpho/erosion.hh: Update.
* mln/morpho/includes.hh,
* mln/morpho/closing.hh,
* mln/morpho/dilation.hh
* mln/morpho/gradient.hh
* mln/morpho/opening.hh: New.
* mln/test: New directory.
* mln/test/positive.hh,
* mln/test/predicate.hh,
* tests/morpho_gradient.cc: New.
mln/arith/minus.hh | 72 +++++++++++++++++++--
mln/arith/plus.hh | 42 ++++++++++++
mln/core/concept/function.hh | 70 ++++++++++++++++++++
mln/core/macros.hh | 1
mln/fun/internal/selector.hh | 22 +++---
mln/fun/ops.hh | 42 +++++++++---
mln/fun/v2v/id.hh | 77 ++++++++++++++++++++++
mln/fun/v2v/saturate.hh | 105 ++++++++++++++++++++++++++++++
mln/level/abs.hh | 89 ++++++++++++++++++++++++++
mln/level/assign.hh | 2
mln/level/fill.hh | 2
mln/level/saturate.hh | 121 +++++++++++++++++++++++++++++++++++
mln/linear/line_convolve.hh | 4 -
mln/linear/line_x2_convolve.hh | 4 -
mln/linear/sobel.hh | 16 ++--
mln/make/w_window_line.hh | 4 -
mln/math/round.hh | 4 -
mln/morpho/closing.hh | 79 +++++++++++++++++++++++
mln/morpho/dilation.hh | 102 ++++++++++++++++++++++++++++++
mln/morpho/erosion.hh | 32 ++++-----
mln/morpho/gradient.hh | 139 +++++++++++++++++++++++++++++++++++++++++
mln/morpho/includes.hh | 56 ++++++++++++++++
mln/morpho/opening.hh | 79 +++++++++++++++++++++++
mln/test/positive.hh | 73 +++++++++++++++++++++
mln/test/predicate.hh | 128 +++++++++++++++++++++++++++++++++++++
tests/convolve.cc | 2
tests/line_convolve.cc | 3
tests/morpho_gradient.cc | 58 +++++++++++++++++
tests/sobel.cc | 6 -
tests/test_positive.cc | 64 ++++++++++++++++++
30 files changed, 1431 insertions(+), 67 deletions(-)
Index: tests/convolve.cc
--- tests/convolve.cc (revision 1055)
+++ tests/convolve.cc (working copy)
@@ -63,7 +63,7 @@
image2d_b<float> tmp(lena.domain());
linear::convolve(lena, w, tmp);
- level::transform(tmp, math::round_<int_u8>(), out);
+ level::transform(tmp, math::round<int_u8>(), out);
io::save_pgm(out, "out.pgm");
}
Index: tests/sobel.cc
--- tests/sobel.cc (revision 1055)
+++ tests/sobel.cc (working copy)
@@ -32,13 +32,11 @@
#include <mln/core/image2d_b.hh>
#include <mln/value/int_u8.hh>
+#include <mln/level/saturate.hh>
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/math/round_sat.hh>
-#include <mln/level/transform.hh>
-
#include <mln/border/thickness.hh>
#include <mln/linear/sobel.hh>
@@ -57,6 +55,6 @@
image2d_b<int> tmp(lena.domain());
linear::sobel(lena, tmp);
- level::transform(tmp, math::round_sat_<int_u8>(), out);
+ level::saturate(tmp, out);
io::save_pgm(out, "out.pgm");
}
Index: tests/test_positive.cc
--- tests/test_positive.cc (revision 0)
+++ tests/test_positive.cc (revision 0)
@@ -0,0 +1,64 @@
+// 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/test_positive.cc
+ *
+ * \brief Tests on mln::test::positive.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/level/fill.hh>
+#include <mln/test/positive.hh>
+
+
+// both test routines can be called with a p2b function
+
+template <typename F>
+void test_p2v(const mln::Function_p2v<F>&)
+{
+}
+
+template <typename F>
+void test_v2b(const mln::Function_v2b<F>&)
+{
+}
+
+
+
+int main()
+{
+ using namespace mln;
+ typedef image2d_b<int> I;
+
+ I ima(1,1);
+ level::fill(ima, 0);
+
+ test_v2b(fun::v2v::id<mln_value_(I)>() >= pw::cst(0));
+
+ // test2(fun::v2v::id<mln_value_(I)>() >= pw::cst(0));
+ // test::positive(ima);
+}
Index: tests/line_convolve.cc
--- tests/line_convolve.cc (revision 1055)
+++ tests/line_convolve.cc (working copy)
@@ -36,7 +36,6 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
#include <mln/math/round.hh>
-#include <mln/math/round_sat.hh>
#include <mln/level/transform.hh>
#include <mln/core/w_window2d_float.hh>
@@ -59,6 +58,6 @@
float ws[] = { .11, .11, .11, .11, .11, .11, .11, .11, .11 };
linear::line_convolve(lena, ws, tmp);
- level::transform(tmp, math::round_<int_u8>(), out);
+ level::transform(tmp, math::round<int_u8>(), out);
io::save_pgm(out, "out.pgm");
}
Index: tests/morpho_gradient.cc
--- tests/morpho_gradient.cc (revision 0)
+++ tests/morpho_gradient.cc (revision 0)
@@ -0,0 +1,58 @@
+// 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/erosion.cc
+ *
+ * \brief Test on mln::morpho::erosion.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/win/rectangle2d.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/morpho/gradient.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ win::rectangle2d rect(5, 5);
+ border::thickness = 2;
+
+ image2d_b<int_u8>
+ lena = io::load_pgm("../img/tiny.pgm"),
+ out(lena.domain());
+
+ morpho::gradient(lena, rect, out);
+ io::save_pgm(out, "out.pgm");
+}
Index: mln/test/positive.hh
--- mln/test/positive.hh (revision 0)
+++ mln/test/positive.hh (revision 0)
@@ -0,0 +1,73 @@
+// 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_TEST_POSITIVE_HH
+# define MLN_TEST_POSITIVE_HH
+
+/*! \file mln/test/positive.hh
+ *
+ * \brief Test if an image only contains positive values.
+ */
+
+# include <mln/test/predicate.hh>
+# include <mln/pw/all.hh>
+# include <mln/fun/v2v/id.hh>
+
+
+namespace mln
+{
+
+ namespace test
+ {
+
+ /// Test if an image only contains positive values.
+ template <typename I>
+ bool positive(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ bool positive(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_precondition(input.has_data());
+ return test::predicate(input.domain(),
+ pw::value(input) >= pw::cst(0));
+ // FIXME: test the version below.
+// return test::predicate(input,
+// fun::v2v::id<mln_value(I)>() >= pw::cst(0));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::test
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TEST_POSITIVE_HH
Index: mln/test/predicate.hh
--- mln/test/predicate.hh (revision 0)
+++ mln/test/predicate.hh (revision 0)
@@ -0,0 +1,128 @@
+// 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_TEST_PREDICATE_HH
+# define MLN_TEST_PREDICATE_HH
+
+/*! \file mln/test/predicate.hh
+ *
+ * \brief Test a predicate on the pixel values of an image.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/core/concept/point_set.hh>
+
+
+namespace mln
+{
+
+ namespace test
+ {
+
+ /*! Test if all pixel values of \p ima verify the predicate \p
+ * f.
+ *
+ * \param[in] ima The image.
+ * \param[in] f The predicate.
+ */
+ template <typename I, typename F>
+ bool predicate(const Image<I>& ima, const Function_v2b<F>& f);
+
+
+ /*! Test if all points of \p pset verify the predicate \p f.
+ *
+ * \param[in] pset The point set.
+ * \param[in] f The predicate.
+ */
+ template <typename S, typename F>
+ bool predicate(const Point_Set<S>& pset, const Function_p2b<F>& f);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename F>
+ bool predicate_(const Image<I>& ima_, const F& f)
+ {
+ const I& ima = exact(ima_);
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ if (! f(ima(p)))
+ return false;
+ return true;
+ }
+
+ template <typename I, typename F>
+ bool predicate_(const Fast_Image<I>& ima_, const F& f)
+ {
+ const I& ima = exact(ima_);
+ mln_pixter(const I) pxl(ima);
+ for_all(pxl)
+ if (! f(pxl.val()))
+ return false;
+ return true;
+ }
+
+ template <typename S, typename F>
+ bool predicate_(const Point_Set<S>& pset, const F& f)
+ {
+ mln_piter(S) p(exact(pset));
+ for_all(p)
+ if (! f(p))
+ return false;
+ return true;
+ }
+
+ } // end of namespace mln::test::impl
+
+
+ // Facades.
+
+ template <typename I, typename F>
+ bool predicate(const Image<I>& ima, const Function_v2b<F>& f)
+ {
+ mln_precondition(exact(ima).has_data());
+ return impl::predicate_(exact(ima), exact(f));
+ }
+
+ template <typename S, typename F>
+ bool predicate(const Point_Set<S>& pset, const Function_p2b<F>& f)
+ {
+ return impl::predicate_(exact(pset), exact(f));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::test
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TEST_PREDICATE_HH
Index: mln/pw/value.hh
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1055)
+++ mln/core/macros.hh (working copy)
@@ -148,6 +148,7 @@
/// Shortcut to access the value type associated to T.
# define mln_value(T) typename T::value
+# define mln_value_(T) T::value
/// Shortcut to the kind of values for an image with type \c I.
# define mln_value_kind(I) typename mln::value::props< mln_value(I) >::kind
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1055)
+++ mln/core/concept/function.hh (working copy)
@@ -53,6 +53,7 @@
*/
protected:
Function();
+ Function(const Function&);
};
@@ -65,6 +66,7 @@
{
protected:
Function_v2v();
+ Function_v2v(const Function_v2v&);
};
@@ -77,6 +79,7 @@
{
protected:
Function_i2v();
+ Function_i2v(const Function_i2v&);
};
@@ -85,10 +88,25 @@
/// Base class for implementation of function-objects from point to
/// value.
template <typename E>
- struct Function_p2v : public Function_v2v<E>
+ struct Function_p2v : public virtual Function_v2v<E>
{
protected:
Function_p2v();
+ Function_p2v(const Function_p2v&);
+ };
+
+
+ // Value -> bool.
+
+ /// Base class for implementation of function-objects from value to
+ /// bool.
+ template <typename E>
+ struct Function_v2b : public virtual Function_v2v<E>
+ {
+ typedef bool result;
+ protected:
+ Function_v2b();
+ Function_v2b(const Function_v2b&);
};
@@ -97,11 +115,13 @@
/// Base class for implementation of function-objects from point to
/// bool.
template <typename E>
- struct Function_p2b : public Function_p2v<E>
+ struct Function_p2b : public Function_p2v<E>,
+ public Function_v2b<E>
{
typedef bool result;
protected:
Function_p2b();
+ Function_p2b(const Function_p2b&);
};
@@ -114,6 +134,7 @@
{
protected:
Function_p2p();
+ Function_p2p(const Function_p2p&);
};
@@ -127,25 +148,70 @@
}
template <typename E>
+ Function<E>::Function(const Function<E>&)
+ {
+ }
+
+ template <typename E>
Function_v2v<E>::Function_v2v()
{
}
template <typename E>
+ Function_v2v<E>::Function_v2v(const Function_v2v<E>&)
+ {
+ }
+
+ template <typename E>
Function_i2v<E>::Function_i2v()
{
}
template <typename E>
+ Function_i2v<E>::Function_i2v(const Function_i2v<E>&)
+ {
+ }
+
+ template <typename E>
Function_p2v<E>::Function_p2v()
{
}
template <typename E>
+ Function_p2v<E>::Function_p2v(const Function_p2v<E>&)
+ {
+ }
+
+ template <typename E>
+ Function_v2b<E>::Function_v2b()
+ {
+ }
+
+ template <typename E>
+ Function_v2b<E>::Function_v2b(const Function_v2b<E>&)
+ {
+ }
+
+ template <typename E>
Function_p2b<E>::Function_p2b()
{
}
+ template <typename E>
+ Function_p2b<E>::Function_p2b(const Function_p2b<E>&)
+ {
+ }
+
+ template <typename E>
+ Function_p2p<E>::Function_p2p()
+ {
+ }
+
+ template <typename E>
+ Function_p2p<E>::Function_p2p(const Function_p2p<E>&)
+ {
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/fun/ops.hh
--- mln/fun/ops.hh (revision 1055)
+++ mln/fun/ops.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/selector.hh>
@@ -43,11 +44,12 @@
{ \
\
template <typename L, typename R> \
- struct Name##_expr_ : public Function_##Out < Name##_expr_<L,R> > \
+ struct Name##_##Out##_expr_ \
+ : public Function_##Out < Name##_##Out##_expr_<L,R> > \
{ \
typedef mln_result(L) result; \
\
- Name##_expr_(const L& l, const R& r) \
+ Name##_##Out##_expr_(const L& l, const R& r) \
: l_(l), r_(r) \
{ \
} \
@@ -59,17 +61,17 @@
} \
\
protected: \
- L l_; \
- R r_; \
+ const L l_; \
+ const R r_; \
}; \
\
} \
\
template <typename L, typename R> \
- fun::Name##_expr_<L,R> \
+ fun::Name##_##Out##_expr_<L,R> \
operator Symbol (const Function_##In<L>& lhs, const Function_##In<R>& rhs) \
{ \
- fun::Name##_expr_<L,R> tmp(exact(lhs), exact(rhs)); \
+ fun::Name##_##Out##_expr_<L,R> tmp(exact(lhs), exact(rhs)); \
return tmp; \
} \
\
@@ -82,11 +84,12 @@
{ \
\
template <typename F> \
- struct Name##_expr_ : public Function_##Out< Name##_expr_<F> > \
+ struct Name##_##Out##_expr_ \
+ : public Function_##Out< Name##_##Out##_expr_<F> > \
{ \
typedef mln_result(F) result; \
\
- Name##_expr_(const F& f) \
+ Name##_##Out##_expr_(const F& f) \
: f_(f) \
{ \
} \
@@ -98,16 +101,16 @@
} \
\
protected: \
- F f_; \
+ const F f_; \
}; \
\
} \
\
template <typename F> \
- fun::Name##_expr_<F> \
+ fun::Name##_##Out##_expr_<F> \
operator Symbol (const Function_##In<F>& f) \
{ \
- fun::Name##_expr_<F> tmp(exact(f)); \
+ fun::Name##_##Out##_expr_<F> tmp(exact(f)); \
return tmp; \
} \
\
@@ -117,6 +120,7 @@
namespace mln
{
+ // -> p2v
mln_decl_binary_expr_(p2v, p2b, equal, =);
mln_decl_binary_expr_(p2v, p2b, not_equal, !=);
@@ -141,6 +145,22 @@
mln_decl_unary_expr_(p2v, p2v, uplus, +);
mln_decl_unary_expr_(p2v, p2v, uminus, -);
+ // -> v2b
+
+ mln_decl_binary_expr_(v2v, v2b, equal, =);
+ mln_decl_binary_expr_(v2v, v2b, not_equal, !=);
+
+ mln_decl_binary_expr_(v2v, v2b, less, <);
+ mln_decl_binary_expr_(v2v, v2b, less_or_equal, <=);
+ mln_decl_binary_expr_(v2v, v2b, greater_or_equal, >=);
+ mln_decl_binary_expr_(v2v, v2b, greater, >);
+
+ mln_decl_binary_expr_(v2b, v2b, and, &&);
+ mln_decl_binary_expr_(v2b, v2b, or, ||);
+ mln_decl_binary_expr_(v2b, v2b, xor, ^);
+
+ mln_decl_unary_expr_(v2b, v2b, not, !);
+
} // end of namespace mln
Index: mln/fun/internal/selector.hh
--- mln/fun/internal/selector.hh (revision 1055)
+++ mln/fun/internal/selector.hh (working copy)
@@ -51,11 +51,13 @@
// Function_v2v
// |
- // + -- Function_i2v
- // |
- // + -- Function_p2v
- // |
- // + -- Function_p2b
+ // + ---------------------- Function_v2b
+ // | |
+ // + -- Function_i2v |
+ // | |
+ // + -- Function_p2v |
+ // | |
+ // + -- Function_p2b -- +
// |
// + -- Function_p2p
@@ -69,9 +71,9 @@
template <int arg, int res, typename E> struct helper_selector_;
- // no b2* type => v2v type
+ // b2* => v2v type, except for v2b
template <typename E>
- struct helper_selector_< b_, b_, E > { typedef Function_v2v<E> ret; };
+ struct helper_selector_< b_, b_, E > { typedef Function_v2b<E> ret; };
template <typename E>
struct helper_selector_< b_, i_, E > { typedef Function_v2v<E> ret; };
template <typename E>
@@ -79,7 +81,7 @@
template <typename E>
struct helper_selector_< b_, v_, E > { typedef Function_v2v<E> ret; };
- // i2* => only i2v type
+ // i2* => i2v type
template <typename E>
struct helper_selector_< i_, b_, E > { typedef Function_i2v<E> ret; };
template <typename E>
@@ -99,9 +101,9 @@
template <typename E>
struct helper_selector_< p_, v_, E > { typedef Function_p2v<E> ret; };
- // v2* => only v2v type
+ // v2* => v2v type, except for v2b
template <typename E>
- struct helper_selector_< v_, b_, E > { typedef Function_v2v<E> ret; };
+ struct helper_selector_< v_, b_, E > { typedef Function_v2b<E> ret; };
template <typename E>
struct helper_selector_< v_, i_, E > { typedef Function_v2v<E> ret; };
template <typename E>
Index: mln/fun/v2v/saturate.hh
--- mln/fun/v2v/saturate.hh (revision 0)
+++ mln/fun/v2v/saturate.hh (revision 0)
@@ -0,0 +1,105 @@
+// 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_FUN_V2V_SATURATE_HH
+# define MLN_FUN_V2V_SATURATE_HH
+
+/*! \file mln/fun/v2v/saturate.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/value/props.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ // FIXME: Doc!
+
+ template <typename V>
+ struct saturate : public Function_v2v< saturate<V> >
+ {
+ saturate();
+ saturate(const V& min, const V& max);
+
+ typedef V result;
+
+ template <typename W>
+ V operator()(const W& v) const;
+
+ protected:
+ V min_, max_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ saturate<V>::saturate()
+ : min_(mln_min(V)),
+ max_(mln_max(V))
+ {
+ }
+
+ template <typename V>
+ saturate<V>::saturate(const V& min, const V& max)
+ : min_(min),
+ max_(max)
+ {
+ mln_precondition(max > min);
+ }
+
+ template <typename V>
+ template <typename W>
+ V
+ saturate<V>::operator()(const W& v) const
+ {
+ if (v < min_)
+ return min_;
+ if (v > max_)
+ return max_;
+ return v;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2V_SATURATE_HH
Index: mln/fun/v2v/id.hh
--- mln/fun/v2v/id.hh (revision 0)
+++ mln/fun/v2v/id.hh (revision 0)
@@ -0,0 +1,77 @@
+// 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_FUN_V2V_ID_HH
+# define MLN_FUN_V2V_ID_HH
+
+/*! \file mln/fun/id.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/fun/internal/selector.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ // FIXME: Doc!
+
+ template <typename T>
+ struct id
+ : fun::internal::selector_<T, T, id<T> >::ret
+ {
+ typedef T result;
+ T operator()(const T& t) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ T
+ id<T>::operator()(const T& t) const
+ {
+ return t;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2V_ID_HH
Index: mln/math/round.hh
--- mln/math/round.hh (revision 1055)
+++ mln/math/round.hh (working copy)
@@ -47,7 +47,7 @@
template <typename R>
- struct round_ : public Function_v2v< round_<R> >
+ struct round : public Function_v2v< round<R> >
{
typedef R result;
@@ -61,7 +61,7 @@
template <typename R>
template <typename T>
- R round_<R>::operator()(const T& v) const
+ R round<R>::operator()(const T& v) const
{
return (long int)(v + 0.49999); // FIXME: !!!
}
Index: mln/morpho/dilation.hh
--- mln/morpho/dilation.hh (revision 0)
+++ mln/morpho/dilation.hh (revision 0)
@@ -0,0 +1,102 @@
+// 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_MORPHO_DILATION_HH
+# define MLN_MORPHO_DILATION_HH
+
+/*! \file mln/morpho/dilation.hh
+ *
+ * \brief Morphological dilation.
+ *
+ * \todo Mimic erosion.hh when completed.
+ */
+
+# include <mln/morpho/includes.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /*! Morphological dilation.
+ */
+ template <typename I, typename W, typename O>
+ void dilation(const Image<I>& input, const Window<W>& win, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename W, typename O>
+ void dilation_on_function(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ accu::max<mln_value(I)> max;
+
+ mln_piter(I) p(input.domain());
+ mln_qiter(W) q(win, p);
+ for_all(p)
+ {
+ max.init();
+ for_all(q) if (input.has(q))
+ max.take(input(q));
+ output(p) = max.to_value();
+ }
+ }
+
+ } // end of namespace mln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W, typename O>
+ void dilation(const Image<I>& input, const Window<W>& win, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ mln_precondition(! exact(win).is_empty());
+
+ impl::dilation_on_function(input, win, output);
+
+ if (exact(win).is_centered())
+ mln_postcondition(output >= input);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_DILATION_HH
Index: mln/morpho/includes.hh
--- mln/morpho/includes.hh (revision 0)
+++ mln/morpho/includes.hh (revision 0)
@@ -0,0 +1,56 @@
+// 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_MORPHO_INCLUDES_HH
+# define MLN_MORPHO_INCLUDES_HH
+
+/*! \file mln/morpho/includes.hh
+ *
+ * \brief Basic list of includes for all files in mln/morpho/.
+ */
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/window.hh>
+
+# include <mln/accu/min.hh>
+# include <mln/accu/max.hh>
+
+# include <mln/arith/minus.hh>
+
+# include <mln/level/compare.hh>
+# include <mln/level/fill.hh>
+
+# include <mln/border/resize.hh>
+# include <mln/border/fill.hh>
+
+# include <mln/morpho/dilation.hh>
+# include <mln/morpho/erosion.hh>
+
+
+
+#endif // ! MLN_MORPHO_INCLUDES_HH
Index: mln/morpho/gradient.hh
--- mln/morpho/gradient.hh (revision 0)
+++ mln/morpho/gradient.hh (revision 0)
@@ -0,0 +1,139 @@
+// 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_MORPHO_GRADIENT_HH
+# define MLN_MORPHO_GRADIENT_HH
+
+/*! \file mln/morpho/gradient.hh
+ *
+ * \brief Morphological gradient.
+ */
+
+# include <mln/morpho/includes.hh>
+# include <mln/test/positive.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /*! Morphological gradient.
+ *
+ * This operator is d_B - e_B.
+ */
+ template <typename I, typename W, typename O>
+ void gradient(const Image<I>& input, const Window<W>& win,
+ Image<O>& output);
+
+
+ /*! Morphological internal gradient.
+ *
+ * This operator is Id - e_B.
+ */
+ template <typename I, typename W, typename O>
+ void gradient_internal(const Image<I>& input, const Window<W>& win,
+ Image<O>& output);
+
+
+ /*! Morphological external gradient.
+ *
+ * This operator is d_B - Id.
+ */
+ template <typename I, typename W, typename O>
+ void gradient_external(const Image<I>& input, const Window<W>& win,
+ Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename W, typename O>
+ void gradient(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ O temp(input.domain());
+ erosion(input, win, temp);
+
+ dilation(input, win, output);
+ arith::minus_inplace(output, temp);
+
+ mln_postcondition(test::positive(output));
+ }
+
+ template <typename I, typename W, typename O>
+ void gradient_internal(const Image<I>& input_, const Window<W>& win_,
+ Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ O temp(input.domain());
+ erosion(input, win, temp);
+
+ arith::minus(input, temp, output);
+
+ mln_postcondition(test::positive(output));
+ }
+
+ template <typename I, typename W, typename O>
+ void gradient_external(const Image<I>& input_, const Window<W>& win_,
+ Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ O temp(input.domain());
+ dilation(input, win, temp);
+
+ arith::minus(temp, input, output);
+
+ mln_postcondition(test::positive(output));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_GRADIENT_HH
Index: mln/morpho/erosion.hh
--- mln/morpho/erosion.hh (revision 1055)
+++ mln/morpho/erosion.hh (working copy)
@@ -28,13 +28,7 @@
#ifndef MLN_MORPHO_EROSION_HH
# define MLN_MORPHO_EROSION_HH
-# include <mln/core/concept/image.hh>
-# include <mln/core/concept/window.hh>
-# include <mln/accu/min.hh>
-# include <mln/value/props.hh>
-# include <mln/level/compare.hh>
-# include <mln/level/fill.hh>
-// FIXME: # include <mln/border/assign.hh>
+# include <mln/morpho/includes.hh>
namespace mln
@@ -43,6 +37,11 @@
namespace morpho
{
+ /*! Morphological erosion.
+ *
+ * \todo Overload erosion_wrt_win for hline and vline and for fast
+ * images.
+ */
template <typename I, typename W, typename O>
void erosion(const Image<I>& input, const Window<W>& win, Image<O>& output);
@@ -52,7 +51,7 @@
namespace impl
{
- // on function
+ // On function.
template <typename I, typename W, typename O>
void erosion_on_function(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
@@ -75,7 +74,7 @@
}
- // on set
+ // On set.
template <typename I, typename W, typename O>
void erosion_on_set(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
@@ -104,10 +103,10 @@
- // FIXME: stage 3: dispatch w.r.t. fast property
+ // FIXME: Stage 3: dispatch w.r.t. fast property
- // stage 2: dispatch w.r.t. the value kind
+ // Stage 2: dispatch w.r.t. the value kind.
template <typename I, typename W, typename O>
void erosion_wrt_value(value::binary_kind, // binary => morphology on sets
@@ -125,7 +124,7 @@
- // stage 1: dispatch w.r.t. the window type
+ // Stage 1: dispatch w.r.t. the window type.
// |
// V
@@ -142,9 +141,9 @@
template <typename I, typename O>
void erosion_wrt_win(const Image<I>& input, const win::rectangle2d& win, Image<O>& output)
{
- O tmp(exact(output).domain());
- morpho::erosion(input, win::hline2d(win.width()), tmp);
- morpho::erosion(tmp, win::vline2d(win.height()), output);
+ O temp(exact(output).domain());
+ morpho::erosion(input, win::hline2d(win.width()), temp);
+ morpho::erosion(temp, win::vline2d(win.height()), output);
}
# endif // MLN_CORE_WIN_RECTANGLE2D_HH
@@ -157,7 +156,7 @@
} // end of namespace mln::morpho::impl
- // facade
+ // Facade.
template <typename I, typename W, typename O>
void erosion(const Image<I>& input, const Window<W>& win, Image<O>& output)
@@ -166,6 +165,7 @@
mln_precondition(! exact(win).is_empty());
impl::erosion_wrt_win(input, exact(win), output);
+
if (exact(win).is_centered())
mln_postcondition(output <= input);
}
Index: mln/morpho/closing.hh
--- mln/morpho/closing.hh (revision 0)
+++ mln/morpho/closing.hh (revision 0)
@@ -0,0 +1,79 @@
+// 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_MORPHO_CLOSING_HH
+# define MLN_MORPHO_CLOSING_HH
+
+/*! \file mln/morpho/closing.hh
+ *
+ * \brief Morphological closing.
+ */
+
+# include <mln/morpho/includes.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /*! Morphological closing.
+ *
+ * This operator is e_{-B} o d_B.
+ */
+ template <typename I, typename W, typename O>
+ void closing(const Image<I>& input, const Window<W>& win, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename W, typename O>
+ void closing(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ O temp(input.domain());
+ dilation(input, win, temp);
+ erosion(temp, -win, output);
+
+ mln_postcondition(output >= input);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_CLOSING_HH
Index: mln/morpho/opening.hh
--- mln/morpho/opening.hh (revision 0)
+++ mln/morpho/opening.hh (revision 0)
@@ -0,0 +1,79 @@
+// 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_MORPHO_OPENING_HH
+# define MLN_MORPHO_OPENING_HH
+
+/*! \file mln/morpho/opening.hh
+ *
+ * \brief Morphological opening.
+ */
+
+# include <mln/morpho/includes.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /*! Morphological opening.
+ *
+ * This operator is d_{-B} o e_B.
+ */
+ template <typename I, typename W, typename O>
+ void opening(const Image<I>& input, const Window<W>& win, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename W, typename O>
+ void opening(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() = input.domain());
+ mln_precondition(! win.is_empty());
+
+ O temp(input.domain());
+ erosion(input, win, temp);
+ dilation(temp, -win, output);
+
+ mln_postcondition(output <= input);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_OPENING_HH
Index: mln/level/assign.hh
--- mln/level/assign.hh (revision 1055)
+++ mln/level/assign.hh (working copy)
@@ -31,6 +31,8 @@
/*! \file mln/level/assign.hh
*
* \brief Assignment between a couple of images.
+ *
+ * \todo Assign should be a precondition then a call to level::fill.
*/
# include <mln/core/concept/image.hh>
Index: mln/level/fill.hh
--- mln/level/fill.hh (revision 1055)
+++ mln/level/fill.hh (working copy)
@@ -31,6 +31,8 @@
/*! \file mln/level/fill.hh
*
* \brief Fill an image, that is, set pixel values.
+ *
+ * \todo Overload for fast images.
*/
# include <cstring>
Index: mln/level/saturate.hh
--- mln/level/saturate.hh (revision 0)
+++ mln/level/saturate.hh (revision 0)
@@ -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.
+
+#ifndef MLN_LEVEL_SATURATE_HH
+# define MLN_LEVEL_SATURATE_HH
+
+/*! \file mln/level/saturate.hh
+ *
+ * \brief Apply a saturation function to image pixel values.
+ */
+
+# include <mln/fun/v2v/saturate.hh>
+# include <mln/level/apply.hh>
+# include <mln/level/transform.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+
+ /*! Apply the saturate function to image pixel values.
+ *
+ * \param[in] input The input image.
+ * \param[out] output The output image.
+ *
+ * The saturation is based on the min and max values of the output
+ * value type. This assumes that the range of values in the input
+ * image is larger than the one of the output image.
+ */
+ template <typename I, typename O>
+ void saturate(const Image<I>& input, Image<O>& output);
+
+
+ /*! Apply the saturate function to image pixel values.
+ *
+ * \param[in] input The input image.
+ * \param[in] min The minimum output value.
+ * \param[in] max The maximum output value.
+ * \param[out] output The output image.
+ */
+ template <typename I, typename O>
+ void saturate(const Image<I>& input,
+ const mln_value(O)& min, const mln_value(O)& max,
+ Image<O>& output);
+
+
+ /*! Apply the saturate function to image pixel values.
+ *
+ * \param[in,out] input The input image.
+ * \param[in] min The minimum output value.
+ * \param[in] max The maximum output value.
+ */
+ template <typename I>
+ void saturate_inplace(Image<I>& input,
+ const mln_value(I)& min, const mln_value(I)& max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename O>
+ void saturate(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(input).domain() = exact(output).domain());
+ fun::v2v::saturate<mln_value(O)> f;
+ level::transform(input, f, output);
+ }
+
+ template <typename I, typename O>
+ void saturate(const Image<I>& input,
+ const mln_value(O)& min, const mln_value(O)& max,
+ Image<O>& output)
+ {
+ mln_precondition(exact(input).domain() = exact(output).domain());
+ fun::v2v::saturate<mln_value(O)> f(min, max);
+ level::transform(input, f, output);
+ }
+
+ template <typename I>
+ void saturate_inplace(Image<I>& input,
+ const mln_value(I)& min, const mln_value(I)& max)
+ {
+ mln_precondition(exact(input).has_data());
+ fun::v2v::saturate<mln_value(I)> f(min, max);
+ level::apply(input, f);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_SATURATE_HH
Index: mln/level/abs.hh
--- mln/level/abs.hh (revision 0)
+++ mln/level/abs.hh (revision 0)
@@ -0,0 +1,89 @@
+// 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_LEVEL_ABS_HH
+# define MLN_LEVEL_ABS_HH
+
+/*! \file mln/level/abs.hh
+ *
+ * \brief Apply the absolute value (abs) function to image pixel
+ * values.
+ */
+
+# include <mln/fun/v2v/abs.hh>
+# include <mln/level/apply.hh>
+# include <mln/level/transform.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+
+ /*! Apply the absolute value (abs) function to image pixel values.
+ *
+ * \param[in] input The input image.
+ * \param[out] output The output image.
+ */
+ template <typename I, typename O>
+ void abs(const Image<I>& input, Image<O>& output);
+
+
+ /*! Apply the absolute value (abs) function to image pixel values.
+ *
+ * \param[in,out] input The input image.
+ */
+ template <typename I>
+ void abs_inplace(Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename O>
+ void abs(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(input).domain() = exact(output).domain());
+ level::transform(input, fun::v2v::abs<mln_value(I)>(), output);
+ }
+
+ template <typename I>
+ void abs_inplace(Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ level::apply(input, fun::v2v::abs<mln_value(I)>());
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_ABS_HH
Index: mln/arith/plus.hh
--- mln/arith/plus.hh (revision 1055)
+++ mln/arith/plus.hh (working copy)
@@ -54,6 +54,20 @@
void plus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
+ /*! Point-wise addition of image \p rhs in image \p lhs.
+ *
+ * \param[in] lhs First operand image (subject to addition).
+ * \param[in,out] rhs Second operand image (to be added to \p lhs).
+ *
+ * This addition performs: \n
+ * for all p of rhs.domain \n
+ * lhs(p) += rhs(p)
+ *
+ * \pre \p rhs.domain <= \p lhs.domain
+ */
+ template <typename L, typename R>
+ void plus_inplace(Image<L>& lhs, const Image<R>& rhs);
+
# ifndef MLN_INCLUDE_ONLY
@@ -81,10 +95,29 @@
op.val() = lp.val() + rp.val();
}
+ template <typename L, typename R>
+ void plus_inplace_(Image<L>& lhs_, const Image<R>& rhs_)
+ {
+ L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_piter(R) p(rhs.domain());
+ for_all(p)
+ lhs(p) += rhs(p);
+ }
+
+ template <typename L, typename R>
+ void plus_inplace_(Fast_Image<L>& lhs, const Fast_Image<R>& rhs)
+ {
+ mln_pixter(L) lp(exact(lhs));
+ mln_pixter(const R) rp(exact(rhs));
+ for_all_2(rp, lp)
+ lp.val() += rp.val();
+ }
+
} // end of namespace mln::arith::impl
- // Facade.
+ // Facades.
template <typename L, typename R, typename O>
void plus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
@@ -94,6 +127,13 @@
impl::plus_(exact(lhs), exact(rhs), exact(output));
}
+ template <typename L, typename R>
+ void plus_inplace(Image<L>& lhs, const Image<R>& rhs)
+ {
+ mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
+ impl::plus_inplace_(exact(lhs), exact(rhs));
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::arith
Index: mln/arith/minus.hh
--- mln/arith/minus.hh (revision 1055)
+++ mln/arith/minus.hh (working copy)
@@ -54,22 +54,84 @@
void minus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
+ /*! Point-wise substraction of image \p lhs in image \p rhs.
+ *
+ * \param[in,out] lhs First operand image (subject to substraction).
+ * \param[in] rhs Second operand image (to be substracted to \p lhs).
+ *
+ * This substraction performs: \n
+ * for all p of rhs.domain \n
+ * lhs(p) -= rhs(p)
+ *
+ * \pre \p rhs.domain <= \p lhs.domain
+ */
+ template <typename L, typename R>
+ void minus_inplace(Image<L>& lhs, const Image<R>& rhs);
+
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename L, typename R, typename O>
- void minus(const Image<L>& lhs_, const Image<R>& rhs_, Image<O>& output_)
+ void minus_(const Image<L>& lhs_, const Image<R>& rhs_, Image<O>& output_)
{
const L& lhs = exact(lhs_);
const R& rhs = exact(rhs_);
O& output = exact(output_);
+ mln_piter(L) p(lhs.domain());
+ for_all(p)
+ output(p) = lhs(p) - rhs(p);
+ }
- mln_precondition(rhs.domain() = lhs.domain());
- mln_precondition(output.domain() = lhs.domain());
+ template <typename L, typename R, typename O>
+ void minus_(const Fast_Image<L>& lhs, const Fast_Image<R>& rhs, Fast_Image<O>& output)
+ {
+ mln_pixter(const L) lp(exact(lhs));
+ mln_pixter(const R) rp(exact(rhs));
+ mln_pixter(O) op(exact(output));
+ for_all_3(lp, rp, op)
+ op.val() = lp.val() - rp.val();
+ }
- mln_piter(I) p(output.domain());
+ template <typename L, typename R>
+ void minus_inplace_(Image<L>& lhs_, const Image<R>& rhs_)
+ {
+ L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ mln_piter(R) p(rhs.domain());
for_all(p)
- output(p) = lhs(p) - rhs(p);
+ lhs(p) -= rhs(p);
+ }
+
+ template <typename L, typename R>
+ void minus_inplace_(Fast_Image<L>& lhs, const Fast_Image<R>& rhs)
+ {
+ mln_pixter(L) lp(exact(lhs));
+ mln_pixter(const R) rp(exact(rhs));
+ for_all_2(rp, lp)
+ lp.val() -= rp.val();
+ }
+
+ } // end of namespace mln::arith::impl
+
+
+ // Facades.
+
+ template <typename L, typename R, typename O>
+ void minus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
+ {
+ mln_precondition(exact(rhs).domain() = exact(lhs).domain());
+ mln_precondition(exact(output).domain() = exact(lhs).domain());
+ impl::minus_(exact(lhs), exact(rhs), exact(output));
+ }
+
+ template <typename L, typename R>
+ void minus_inplace(Image<L>& lhs, const Image<R>& rhs)
+ {
+ mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
+ impl::minus_inplace_(exact(lhs), exact(rhs));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/linear/line_convolve.hh
--- mln/linear/line_convolve.hh (revision 1055)
+++ mln/linear/line_convolve.hh (working copy)
@@ -56,14 +56,14 @@
* \pre output.domain = input.domain
*/
template <typename I, typename W, unsigned N, typename O>
- void line_convolve(const Image<I>& input, const W (&weights)[N],
+ void line_convolve(const Image<I>& input, W (&weights)[N],
Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename W, unsigned N, typename O>
- void line_convolve(const Image<I>& input, const W (&weights)[N],
+ void line_convolve(const Image<I>& input, W (&weights)[N],
Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
Index: mln/linear/sobel.hh
--- mln/linear/sobel.hh (revision 1055)
+++ mln/linear/sobel.hh (working copy)
@@ -34,8 +34,7 @@
*/
# include <mln/arith/plus.hh>
-# include <mln/fun/v2v/abs.hh>
-# include <mln/level/apply.hh>
+# include <mln/level/abs.hh>
# include <mln/linear/line_x2_convolve.hh>
@@ -97,11 +96,14 @@
template <typename I, typename O>
void sobel_(const Image<I>& input, Image<O>& output)
{
- O temp_h(exact(input).domain()), temp_v(exact(input).domain());
- sobel_h(input, temp_h);
- sobel_v(input, temp_v);
- arith::plus(temp_h, temp_v, output);
- level::apply(exact(output), fun::v2v::abs<mln_value(O)>());
+ // h
+ sobel_h(input, output);
+ // v
+ O temp(exact(input).domain());
+ sobel_v(input, temp);
+ // output
+ arith::plus_inplace(output, temp);
+ level::abs_inplace(output);
}
} // end of namespace mln::linear::impl
Index: mln/linear/line_x2_convolve.hh
--- mln/linear/line_x2_convolve.hh (revision 1055)
+++ mln/linear/line_x2_convolve.hh (working copy)
@@ -59,7 +59,7 @@
typename W, unsigned Nr, unsigned Nc,
typename O>
void line_x2_convolve(const Image<I>& input,
- const W (&row_weights)[Nr], const W (&col_weights)[Nc],
+ W (&row_weights)[Nr], W (&col_weights)[Nc],
Image<O>& output);
@@ -69,7 +69,7 @@
typename W, unsigned Nr, unsigned Nc,
typename O>
void line_x2_convolve(const Image<I>& input,
- const W (&row_weights)[Nr], const W (&col_weights)[Nc],
+ W (&row_weights)[Nr], W (&col_weights)[Nc],
Image<O>& output)
{
// FIXME: Check 2D.
Index: mln/make/w_window_line.hh
--- mln/make/w_window_line.hh (revision 1055)
+++ mln/make/w_window_line.hh (working copy)
@@ -52,13 +52,13 @@
* \return A window.
*/
template <typename D, typename W, unsigned L>
- mln::w_window<D,W> w_window_line(const W (&w)[L]);
+ mln::w_window<D,W> w_window_line(W (&w)[L]);
# ifndef MLN_INCLUDE_ONLY
template <typename D, typename W, unsigned L>
- mln::w_window<D,W> w_window_line(const W (&w)[L])
+ mln::w_window<D,W> w_window_line(W (&w)[L])
{
mln_precondition(L % 2 = 1);
mln::w_window<D,W> w_win;
1
0
27 Aug '07
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment tools for linear filtering; add sobel.
* mln/core/decorated_image.hh
(helper_decorated_image_write_): Replace by...
(decorated_image_impl_): ...this.
(impl_): New.
(lvalue): Update.
(write_): Remove; now in impl_.
* mln/value/all.hh: Update.
* mln/value/props.hh,
* mln/value/int_u.hh,
* mln/value/int_s.hh (min, max): Change to proc.
* mln/value/props.hh (mln_min, mln_max): Update.
(epsilon): Change to proc.
* mln/value/aliases.hh: New.
* mln/level/stretch.hh: Update.
* mln/arith/abs.hh: New.
* mln/arith/plus.hh: Overload.
* mln/fun/v2v/abs.hh: New.
* mln/level/apply.hh: Fix meaning; add todo.
* mln/math/abs.hh: Overload.
* mln/core/concept/iterator.hh (for_all_3): New.
* mln/math/round_sat.hh: New.
* mln/make/w_window_line.hh: New.
* mln/metal/abort.hh: New.
* mln/linear/line_convolve.hh: New.
* mln/linear/line_x2_convolve.hh: New.
* mln/linear/sobel.hh: New.
* tests/line_convolve.cc: New.
* tests/sobel.cc: New.
mln/arith/plus.hh | 34 ++++++++-
mln/core/concept/iterator.hh | 9 ++
mln/core/decorated_image.hh | 55 +++++++++-------
mln/fun/v2v/abs.hh | 77 ++++++++++++++++++++++
mln/level/apply.hh | 42 +++++-------
mln/level/stretch.hh | 2
mln/linear/convolve.hh | 8 +-
mln/linear/hconvolve.hh | 109 +++++++++++++++++++++++++++++++
mln/linear/line_convolve.hh | 82 ++++++++++++++++++++++++
mln/linear/line_x2_convolve.hh | 92 ++++++++++++++++++++++++++
mln/linear/sobel.hh | 140 +++++++++++++++++++++++++++++++++++++++++
mln/make/w_window_line.hh | 81 +++++++++++++++++++++++
mln/math/abs.hh | 13 +++
mln/math/round_sat.hh | 83 ++++++++++++++++++++++++
mln/metal/abort.hh | 50 ++++++++++++++
mln/value/aliases.hh | 43 ++++++++++++
mln/value/all.hh | 9 ++
mln/value/int_s.hh | 23 ++----
mln/value/int_u.hh | 13 ---
mln/value/props.hh | 52 +++++++--------
tests/line_convolve.cc | 64 ++++++++++++++++++
tests/sobel.cc | 62 ++++++++++++++++++
22 files changed, 1034 insertions(+), 109 deletions(-)
Index: tests/sobel.cc
--- tests/sobel.cc (revision 0)
+++ tests/sobel.cc (revision 0)
@@ -0,0 +1,62 @@
+// 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/sobel.cc
+ *
+ * \brief Tests on mln::linear::sobel.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/math/round_sat.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/border/thickness.hh>
+#include <mln/linear/sobel.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ border::thickness = 1;
+
+ image2d_b<int_u8>
+ lena = io::load_pgm("../img/lena.pgm"),
+ out(lena.domain());
+
+ image2d_b<int> tmp(lena.domain());
+ linear::sobel(lena, tmp);
+
+ level::transform(tmp, math::round_sat_<int_u8>(), out);
+ io::save_pgm(out, "out.pgm");
+}
Index: tests/line_convolve.cc
--- tests/line_convolve.cc (revision 0)
+++ tests/line_convolve.cc (revision 0)
@@ -0,0 +1,64 @@
+// 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/line_convolve.cc
+ *
+ * \brief Tests on mln::linear::line_convolve.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+#include <mln/math/round.hh>
+#include <mln/math/round_sat.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/core/w_window2d_float.hh>
+#include <mln/border/thickness.hh>
+#include <mln/linear/line_convolve.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ border::thickness = 4;
+
+ image2d_b<int_u8>
+ lena = io::load_pgm("../img/lena.pgm"),
+ out(lena.domain());
+
+ image2d_b<float> tmp(lena.domain());
+ float ws[] = { .11, .11, .11, .11, .11, .11, .11, .11, .11 };
+ linear::line_convolve(lena, ws, tmp);
+
+ level::transform(tmp, math::round_<int_u8>(), out);
+ io::save_pgm(out, "out.pgm");
+}
Index: mln/core/decorated_image.hh
--- mln/core/decorated_image.hh (revision 1054)
+++ mln/core/decorated_image.hh (working copy)
@@ -35,13 +35,39 @@
namespace mln
{
+ // Fwd decl.
+ template <typename I, typename D> class decorated_image;
+
+
+ namespace internal
+ {
+
+ template <typename I, typename E>
+ struct decorated_image_impl_
+ {
+ typedef mln::value::proxy<E> lvalue;
+ void write_(const mln_psite(I)& p, const mln_value(I)& v);
+ };
+
+ template <typename I, typename E>
+ struct decorated_image_impl_< const I, E >
+ {
+ typedef mln::value::proxy<const E> lvalue;
+ };
+
+ } // end of namespace::internal
+
+
+
// FIXME: Doc!
template <typename I, typename D>
- class decorated_image : public internal::image_adaptor_< I, decorated_image<I,D> >
+ class decorated_image : public internal::image_adaptor_< I, decorated_image<I,D> >,
+ public internal::decorated_image_impl_< I, decorated_image<I,D> >
{
typedef decorated_image<I, D> self_;
typedef internal::image_adaptor_< I, self_ > super_;
+ typedef internal::decorated_image_impl_< I, self_ > impl_;
public:
decorated_image(I& ima, const D& deco);
@@ -49,13 +75,12 @@
typedef mln_value(I) value;
typedef mln::value::proxy<const self_> rvalue;
- typedef mln::value::proxy<self_> lvalue;
+ typedef typename impl_::lvalue lvalue;
rvalue operator()(const mln_psite(I)& p) const;
lvalue operator()(const mln_psite(I)& p);
mln_value(I) read_(const mln_psite(I)& p) const;
- void write_(const mln_psite(I)& p, const mln_value(I)& v);
template <typename V>
struct change_value
@@ -110,7 +135,7 @@
}
template <typename I, typename D>
- mln::value::proxy< const decorated_image<I,D> >
+ typename decorated_image<I,D>::rvalue
decorated_image<I,D>::operator()(const mln_psite(I)& p) const
{
rvalue tmp(*this, p);
@@ -118,7 +143,7 @@
}
template <typename I, typename D>
- mln::value::proxy< decorated_image<I,D> >
+ typename decorated_image<I,D>::lvalue
decorated_image<I,D>::operator()(const mln_psite(I)& p)
{
lvalue tmp(*this, p);
@@ -128,32 +153,18 @@
namespace internal
{
- template <typename I, typename D>
+ template <typename I, typename E>
void
- helper_decorated_image_write_(decorated_image<I,D>& ima,
- const mln_psite(I)& p, const mln_value(I)& v)
+ decorated_image_impl_<I,E>::write_(const mln_psite(I)& p, const mln_value(I)& v)
{
+ E& ima = internal::force_exact<E>(*this);
ima.decoration().writing(ima.adaptee(), p, v);
ima.adaptee()(p) = v;
}
- template <typename I, typename D>
- void
- helper_decorated_image_write_(decorated_image<const I,D>&,
- const mln_psite(I)&, const mln_value(I)&)
- // FIXME: Static assertion instead.
- ;
-
} // end of namespace mln::internal
template <typename I, typename D>
- void
- decorated_image<I,D>::write_(const mln_psite(I)& p, const mln_value(I)& v)
- {
- internal::helper_decorated_image_write_(*this, p, v);
- }
-
- template <typename I, typename D>
mln_value(I)
decorated_image<I,D>::read_(const mln_psite(I)& p) const
{
Index: mln/core/concept/iterator.hh
--- mln/core/concept/iterator.hh (revision 1054)
+++ mln/core/concept/iterator.hh (working copy)
@@ -46,6 +46,15 @@
# define for_all_2(x1, x2) for(x1.start(),x2.start(); x1.is_valid(); x1.next(),x2.next())
+/*! \brief Loop to browse all the elements targetted by the triplet of
+ * iterators \p x1, \p x2, and \p x3.
+ */
+# define for_all_3(x1, x2, x3) \
+ for(x1.start(), x2.start(), x3.start(); \
+ x1.is_valid(); \
+ x1.next(), x2.next(), x3.next())
+
+
/*! \brief Loop to browse all the remaining elements targetted by the
* iterator \p x.
*/
Index: mln/fun/v2v/abs.hh
--- mln/fun/v2v/abs.hh (revision 0)
+++ mln/fun/v2v/abs.hh (revision 0)
@@ -0,0 +1,77 @@
+// 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_FUN_V2V_ABS_HH
+# define MLN_FUN_V2V_ABS_HH
+
+/*! \file mln/fun/v2v/abs.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/math/abs.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ // FIXME: Doc!
+
+ template <typename V>
+ struct abs : public Function_v2v< abs<V> >
+ {
+ typedef V result;
+ V operator()(const V& v) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ V
+ abs<V>::operator()(const V& v) const
+ {
+ return mln::math::abs(v);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2V_ABS_HH
Index: mln/math/abs.hh
--- mln/math/abs.hh (revision 1054)
+++ mln/math/abs.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <cmath>
+# include <mln/value/all.hh>
@@ -55,6 +56,18 @@
return std::abs(v);
}
+ template <unsigned n>
+ value::int_u<n> abs(const value::int_u<n>& v)
+ {
+ return v;
+ }
+
+ template <unsigned n>
+ value::int_s<n> abs(const value::int_s<n>& v)
+ {
+ return std::abs(v.to_enc());
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::math
Index: mln/math/round_sat.hh
--- mln/math/round_sat.hh (revision 0)
+++ mln/math/round_sat.hh (revision 0)
@@ -0,0 +1,83 @@
+// 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_MATH_ROUND_SAT_HH
+# define MLN_MATH_ROUND_SAT_HH
+
+/*! \file mln/math/round_sat.hh
+ *
+ * \brief Define round_sat routine.
+ */
+
+# include <cmath>
+
+# include <mln/core/concept/function.hh>
+# include <mln/value/props.hh>
+
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+
+ template <typename R>
+ struct round_sat_ : public Function_v2v< round_sat_<R> >
+ {
+ typedef R result;
+
+ template <typename T>
+ result operator()(const T& v) const;
+
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename R>
+ template <typename T>
+ R round_sat_<R>::operator()(const T& v) const
+ {
+ long int l = (long int)(v + 0.49999); // FIXME: !!!
+ return
+ l < mln_min(R)
+ ? mln_min(R)
+ : (l > mln_max(R)
+ ? mln_max(R)
+ : R(l));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::math
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_ROUND_SAT_HH
Index: mln/metal/abort.hh
--- mln/metal/abort.hh (revision 0)
+++ mln/metal/abort.hh (revision 0)
@@ -0,0 +1,50 @@
+// 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_METAL_ABORT_HH
+# define MLN_METAL_ABORT_HH
+
+# include <mln/metal/bool.hh>
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct abort : false_
+ {};
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_ABORT_HH
Index: mln/level/apply.hh
--- mln/level/apply.hh (revision 1054)
+++ mln/level/apply.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/function.hh>
namespace mln
@@ -45,19 +45,19 @@
/*! Apply a function-object to the image \p input.
*
- * \param[in] input The input image.
+ * \param[in,out] input The input image.
* \param[in] f The function-object.
- * \result A copy of the function-object.
*
* This routine runs: \n
- * for all p of \p input, \p f( \p input(p) ) \n
- * return \p f
+ * for all p of \p input, \p input(p) = \p f( \p input(p) ) \n
*
- * \todo Find a meaning for this routine! (Clue: f is mutable
- * and/or same for input?)
+ * This routine is equivalent to level::tranform(input, f, input)
+ * but it is faster since a single iterator is required.
+ *
+ * \todo Add versions for lowq images.
*/
template <typename I, typename F>
- F apply(const Image<I>& input, const Function<F>& f);
+ void apply(Image<I>& input, const Function_v2v<F>& f);
@@ -67,39 +67,33 @@
{
template <typename I, typename F>
- F apply(const Image<I>& input_, const Function<F>& f_)
+ void apply_(Image<I>& input_, const F& f)
{
- const I& input = exact(input_);
- F f = exact(f_);
-
+ I& input = exact(input_);
mln_piter(I) p(input.domain());
for_all(p)
- f(input(p));
- return f;
+ input(p) = f(input(p));
}
template <typename I, typename F>
- F apply(const Fast_Image<I>& input_, const Function<F>& f_)
+ void apply_(Fast_Image<I>& input_, const F& f)
{
- const I& input = exact(input_);
- F f = exact(f_);
-
- mln_pixter(const I) pxl(input);
+ I& input = exact(input_);
+ mln_pixter(I) pxl(input);
for_all(pxl)
- f(pxl.val());
- return f;
+ pxl.val() = f(pxl.val());
}
} // end of namespace mln::level::impl
- // Facades.
+ // Facade.
template <typename I, typename F>
- F apply(const Image<I>& input, const Function<F>& f)
+ void apply(Image<I>& input, const Function_v2v<F>& f)
{
mln_precondition(exact(input).has_data());
- return impl::apply(exact(input), f);
+ impl::apply_(exact(input), exact(f));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/stretch.hh
--- mln/level/stretch.hh (revision 1054)
+++ mln/level/stretch.hh (working copy)
@@ -71,7 +71,7 @@
if (max_ = min_)
return; // FIXME
float min = float(min_), max = float(max_);
- const float epsilon = value::props<float>::epsilon;
+ const float epsilon = value::props<float>::epsilon();
float m = 0.0f - 0.5f + epsilon;
float M = mln_max(value::int_u<n>) + 0.5f - epsilon;
float a = (M - m) / (max - min);
Index: mln/arith/plus.hh
--- mln/arith/plus.hh (revision 1054)
+++ mln/arith/plus.hh (working copy)
@@ -57,21 +57,43 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename L, typename R, typename O>
- void plus(const Image<L>& lhs_, const Image<R>& rhs_, Image<O>& output_)
+ void plus_(const Image<L>& lhs_, const Image<R>& rhs_, Image<O>& output_)
{
const L& lhs = exact(lhs_);
const R& rhs = exact(rhs_);
O& output = exact(output_);
-
- mln_precondition(rhs.domain() = lhs.domain());
- mln_precondition(output.domain() = lhs.domain());
-
- mln_piter(I) p(output.domain());
+ mln_piter(L) p(lhs.domain());
for_all(p)
output(p) = lhs(p) + rhs(p);
}
+ template <typename L, typename R, typename O>
+ void plus_(const Fast_Image<L>& lhs, const Fast_Image<R>& rhs, Fast_Image<O>& output)
+ {
+ mln_pixter(const L) lp(exact(lhs));
+ mln_pixter(const R) rp(exact(rhs));
+ mln_pixter(O) op(exact(output));
+ for_all_3(lp, rp, op)
+ op.val() = lp.val() + rp.val();
+ }
+
+ } // end of namespace mln::arith::impl
+
+
+ // Facade.
+
+ template <typename L, typename R, typename O>
+ void plus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
+ {
+ mln_precondition(exact(rhs).domain() = exact(lhs).domain());
+ mln_precondition(exact(output).domain() = exact(lhs).domain());
+ impl::plus_(exact(lhs), exact(rhs), exact(output));
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::arith
Index: mln/linear/line_convolve.hh
--- mln/linear/line_convolve.hh (revision 0)
+++ mln/linear/line_convolve.hh (revision 0)
@@ -0,0 +1,82 @@
+// 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_LINEAR_LINE_CONVOLVE_HH
+# define MLN_LINEAR_LINE_CONVOLVE_HH
+
+/*! \file mln/linear/line_convolve.hh
+ *
+ * \brief Convolution by a line-shaped kernel.
+ */
+
+# include <mln/linear/convolve.hh>
+# include <mln/make/w_window_line.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ /*! Convolution of an image \p input by a line-shaped weighted
+ * window defined by the array of \p weights.
+ *
+ * \warning Computation of \p output(p) is performed with the
+ * value type of \p output.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ *
+ * \pre output.domain = input.domain
+ */
+ template <typename I, typename W, unsigned N, typename O>
+ void line_convolve(const Image<I>& input, const W (&weights)[N],
+ Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename W, unsigned N, typename O>
+ void line_convolve(const Image<I>& input, const W (&weights)[N],
+ Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ linear::convolve(input,
+ make::w_window_line<mln_dpoint(I)>(weights),
+ output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_LINE_CONVOLVE_HH
Index: mln/linear/hconvolve.hh
--- mln/linear/hconvolve.hh (revision 0)
+++ mln/linear/hconvolve.hh (revision 0)
@@ -0,0 +1,109 @@
+// 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_LINEAR_LINE_CONVOLVE_HH
+# define MLN_LINEAR_LINE_CONVOLVE_HH
+
+/*! \file mln/linear/line_convolve.hh
+ *
+ * \brief Convolution by an horizontal kernel.
+ */
+
+# include <vector>
+
+# include <mln/linear/convolve.hh>
+# include <mln/make/w_window_line.hh>
+# include <mln/core/t_image.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ /*! Convolution of an image \p input by an horizontal weighted
+ * window defined by the array of \p weights.
+ *
+ * \warning Computation of \p output(p) is performed with the
+ * value type of \p output.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ *
+ * \pre output.domain = input.domain
+ */
+ template <typename I, typename W, unsigned N, typename O>
+ void line_convolve(const Image<I>& input, const W (&weights)[N],
+ Image<O>& output);
+
+ // FIXME: Doc!
+ template <typename I, typename W, unsigned Nr, unsigned Nc, typename O>
+ void line_convolve(const Image<I>& input,
+ const W (&row_weights)[Nr], const W (&col_weights)[Nc],
+ Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename W, unsigned N, typename O>
+ void line_convolve(const Image<I>& input, const W (&weights)[N],
+ Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ linear::convolve(input,
+ make::w_window_line<mln_dpoint(I)>(weights),
+ output);
+ }
+
+
+ template <typename I, typename W, unsigned Nr, unsigned Nc, typename O>
+ void line_convolve(const Image<I>& input,
+ const W (&row_weights)[Nr], const W (&col_weights)[Nc],
+ Image<O>& output)
+ {
+ // FIXME: Check 2D.
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ O tmp(exact(output).domain());
+ linear::convolve(input,
+ make::w_window_line<mln_dpoint(I)>(row_weights),
+ tmp);
+ t_image<O> swap_output = swap_coords(output, 0, 1);
+ linear::convolve(swap_coords(tmp, 0, 1),
+ make::w_window_line<mln_dpoint(I)>(col_weights),
+ swap_output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_LINE_CONVOLVE_HH
Index: mln/linear/sobel.hh
--- mln/linear/sobel.hh (revision 0)
+++ mln/linear/sobel.hh (revision 0)
@@ -0,0 +1,140 @@
+// 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_LINEAR_SOBEL_HH
+# define MLN_LINEAR_SOBEL_HH
+
+/*! \file mln/linear/sobel.hh
+ *
+ * \brief Sobel filter.
+ */
+
+# include <mln/arith/plus.hh>
+# include <mln/fun/v2v/abs.hh>
+# include <mln/level/apply.hh>
+# include <mln/linear/line_x2_convolve.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ /*! Convolution of an image \p input by the weighted window \p w_win.
+ *
+ * \warning Computation of \p output(p) is performed with the
+ * value type of \p output.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ *
+ * \pre output.domain = input.domain
+ *
+ * \todo Only for 2D so check + generalize.
+ *
+ * \todo Suboptimal since it is not point-wise and it costs temp
+ * images.
+ */
+ template <typename I, typename O>
+ void sobel_v(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void sobel_h(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void sobel(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename O>
+ void sobel_h_(const Image<I>& input, Image<O>& output)
+ {
+ int wrow[] = { -1, 0, 1 }, wcol[] = { 1,
+ 2,
+ 1 };
+ linear::line_x2_convolve(input, wrow, wcol, output);
+ }
+
+ template <typename I, typename O>
+ void sobel_v_(const Image<I>& input, Image<O>& output)
+ {
+ int wrow[] = { 1, 2, 1 }, wcol[] = { -1,
+ 0,
+ +1 };
+ linear::line_x2_convolve(input, wrow, wcol, output);
+ }
+
+ template <typename I, typename O>
+ void sobel_(const Image<I>& input, Image<O>& output)
+ {
+ O temp_h(exact(input).domain()), temp_v(exact(input).domain());
+ sobel_h(input, temp_h);
+ sobel_v(input, temp_v);
+ arith::plus(temp_h, temp_v, output);
+ level::apply(exact(output), fun::v2v::abs<mln_value(O)>());
+ }
+
+ } // end of namespace mln::linear::impl
+
+
+ // Facades.
+
+ template <typename I, typename O>
+ void sobel_h(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ impl::sobel_h_(exact(input), exact(output));
+ }
+
+ template <typename I, typename O>
+ void sobel_v(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ impl::sobel_v_(exact(input), exact(output));
+ }
+
+ template <typename I, typename O>
+ void sobel(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ impl::sobel_(exact(input), exact(output));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_SOBEL_HH
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 1054)
+++ mln/linear/convolve.hh (working copy)
@@ -46,7 +46,7 @@
namespace linear
{
- /*! Convolution of image \p input by the weighted window \p w_win.
+ /*! Convolution of an image \p input by the weighted window \p w_win.
*
* \warning Computation of \p output(p) is performed with the
* value type of \p output.
@@ -67,7 +67,7 @@
{
template <typename I, typename W, typename O>
- void convolve(const Image<I>& input_, const Weighted_Window<W>& w_win_,
+ void convolve_(const Image<I>& input_, const Weighted_Window<W>& w_win_,
Image<O>& output_)
{
const I& input = exact(input_);
@@ -87,7 +87,7 @@
}
template <typename I, typename W, typename O>
- void convolve(const Fast_Image<I>& input_, const Weighted_Window<W>& w_win_,
+ void convolve_(const Fast_Image<I>& input_, const Weighted_Window<W>& w_win_,
Fast_Image<O>& output_)
{
const I& input = exact(input_);
@@ -122,7 +122,7 @@
Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- impl::convolve(exact(input), exact(w_win), exact(output));
+ impl::convolve_(exact(input), exact(w_win), exact(output));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/linear/line_x2_convolve.hh
--- mln/linear/line_x2_convolve.hh (revision 0)
+++ mln/linear/line_x2_convolve.hh (revision 0)
@@ -0,0 +1,92 @@
+// 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_LINEAR_LINE_X2_CONVOLVE_HH
+# define MLN_LINEAR_LINE_X2_CONVOLVE_HH
+
+/*! \file mln/linear/line_x2_convolve.hh
+ *
+ * \brief 2D convolution by a couple of line kernels.
+ */
+
+# include <mln/linear/line_convolve.hh>
+# include <mln/core/t_image.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ /*! Convolution of an image \p input by two weighted line-shapes
+ * windows.
+ *
+ * \warning Computation of \p output(p) is performed with the
+ * value type of \p output.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ *
+ * \pre output.domain = input.domain
+ */
+ template <typename I,
+ typename W, unsigned Nr, unsigned Nc,
+ typename O>
+ void line_x2_convolve(const Image<I>& input,
+ const W (&row_weights)[Nr], const W (&col_weights)[Nc],
+ Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I,
+ typename W, unsigned Nr, unsigned Nc,
+ typename O>
+ void line_x2_convolve(const Image<I>& input,
+ const W (&row_weights)[Nr], const W (&col_weights)[Nc],
+ Image<O>& output)
+ {
+ // FIXME: Check 2D.
+ mln_precondition(exact(output).domain() = exact(input).domain());
+
+ O tmp(exact(output).domain());
+ linear::line_convolve(input, row_weights, tmp);
+
+ t_image<O> swap_output = swap_coords(output, 0, 1);
+ linear::line_convolve(swap_coords(tmp, 0, 1), col_weights, swap_output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_LINE_X2_CONVOLVE_HH
Index: mln/value/aliases.hh
--- mln/value/aliases.hh (revision 0)
+++ mln/value/aliases.hh (revision 0)
@@ -0,0 +1,43 @@
+// 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_VALUE_ALIASES_HH
+# define MLN_VALUE_ALIASES_HH
+
+/*! \file mln/value/aliases.hh
+ *
+ * \brief File that includes all aliases of value types.
+ */
+
+
+# include <mln/value/int_u8.hh>
+# include <mln/value/int_u16.hh>
+
+# include <mln/value/int_s8.hh>
+
+
+#endif // ! MLN_VALUE_ALIASES_HH
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1054)
+++ mln/value/props.hh (working copy)
@@ -42,11 +42,11 @@
/// Get the minimum value of type \c T.
-# define mln_min(T) mln::value::props< T >::min
+# define mln_min(T) mln::value::props< T >::min()
/// Get the maximum value of type \c T.
-# define mln_max(T) mln::value::props< T >::max
+# define mln_max(T) mln::value::props< T >::max()
/// Get the number of values for value type \c T.
@@ -108,8 +108,8 @@
template <>
struct props<bool>
{
- static const bool min = false;
- static const bool max = true;
+ static const bool min() { return false; }
+ static const bool max() { return true; }
static const std::size_t card_ = 2;
typedef binary_kind kind;
};
@@ -120,8 +120,8 @@
template <>
struct props<unsigned char>
{
- static const unsigned char min = 0;
- static const unsigned char max = 255;
+ static const unsigned char min() { return 0; }
+ static const unsigned char max() { return 255; }
static const std::size_t card_ = 256;
typedef data_kind kind;
typedef float sum;
@@ -130,8 +130,8 @@
template <>
struct props<signed char>
{
- static const signed char min = -128;
- static const signed char max = 127;
+ static const signed char min() { return -128; }
+ static const signed char max() { return 127; }
static const std::size_t card_ = 256;
typedef data_kind kind;
typedef float sum;
@@ -140,8 +140,8 @@
template <>
struct props<unsigned short>
{
- static const unsigned short min = 0;
- static const unsigned short max = 65535;
+ static const unsigned short min() { return 0; }
+ static const unsigned short max() { return 65535; }
static const std::size_t card_ = 65536;
typedef data_kind kind;
typedef float sum;
@@ -150,8 +150,8 @@
template <>
struct props<signed short>
{
- static const signed short min = -32768;
- static const signed short max = 32767;
+ static const signed short min() { return -32768; }
+ static const signed short max() { return 32767; }
static const std::size_t card_ = 655356;
typedef data_kind kind;
typedef float sum;
@@ -160,8 +160,8 @@
template <>
struct props<unsigned int>
{
- static const unsigned int min = 0;
- static const unsigned int max = UINT_MAX;
+ static const unsigned int min() { return 0; }
+ static const unsigned int max() { return UINT_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef float sum;
@@ -170,8 +170,8 @@
template <>
struct props<signed int>
{
- static const signed int min = INT_MIN;
- static const signed int max = INT_MAX;
+ static const signed int min() { return INT_MIN; }
+ static const signed int max() { return INT_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef float sum;
@@ -180,8 +180,8 @@
template <>
struct props<unsigned long int>
{
- static const unsigned long int min = 0;
- static const unsigned long int max = ULONG_MAX;
+ static const unsigned long int min() { return 0; }
+ static const unsigned long int max() { return ULONG_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef float sum;
@@ -190,8 +190,8 @@
template <>
struct props<signed long int>
{
- static const signed long int min = LONG_MIN;
- static const signed long int max = LONG_MAX;
+ static const signed long int min() { return LONG_MIN; }
+ static const signed long int max() { return LONG_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef float sum;
@@ -203,9 +203,9 @@
template <>
struct props<float>
{
- static const float min = FLT_MIN;
- static const float max = FLT_MAX;
- static const float epsilon = 0.00001f;
+ static const float min() { return FLT_MIN; }
+ static const float max() { return FLT_MAX; }
+ static const float epsilon() { return 0.00001f; }
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef float sum;
@@ -214,9 +214,9 @@
template <>
struct props<double>
{
- static const double min = DBL_MIN;
- static const double max = DBL_MAX;
- static const double epsilon = 0.0000001;
+ static const double min() { return DBL_MIN; }
+ static const double max() { return DBL_MAX; }
+ static const double epsilon() { return 0.0000001; }
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef double sum;
Index: mln/value/all.hh
--- mln/value/all.hh (revision 1054)
+++ mln/value/all.hh (working copy)
@@ -44,7 +44,16 @@
}
+# include <mln/value/aliases.hh>
+# include <mln/value/label.hh>
# include <mln/value/props.hh>
+# include <mln/value/proxy.hh>
+
+
+// FIXME: that includes concept/image.hh!
+
+// # include <mln/value/cast.hh>
+// # include <mln/value/stack.hh>
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1054)
+++ mln/value/int_s.hh (working copy)
@@ -89,23 +89,24 @@
+ // Safety.
+ template <> struct int_s<0>;
+ template <> struct int_s<1>;
+
+
+
template <unsigned n>
struct props< int_s<n> >
{
- static const int_s<n> max; // = 2^(n-1) - 1
- static const int_s<n> min; // = - max
static const std::size_t card_ = metal::pow<2, n>::value;
+ static const int_s<n> max() { return metal::pow<2, n-1>::value - 1; }
+ static const int_s<n> min() { return - max(); }
static const unsigned nbits = n;
typedef data_kind kind;
typedef float sum;
};
- // Safety.
- template <> struct int_s<0>;
- template <> struct int_s<1>;
-
-
/*! \brief Print an signed integer \p i into the output stream \p ostr.
*
@@ -167,14 +168,6 @@
const int_s<n> int_s<n>::one = 1;
template <unsigned n>
- const int_s<n>
- props< int_s<n> >::min = 1 - metal::pow<2, n - 1>::value;
-
- template <unsigned n>
- const int_s<n>
- props< int_s<n> >::max = metal::pow<2, n - 1>::value - 1;
-
- template <unsigned n>
std::ostream& operator<<(std::ostream& ostr, const int_s<n>& i)
{
return ostr << debug::format(i.to_equiv());
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1054)
+++ mln/value/int_u.hh (working copy)
@@ -95,8 +95,8 @@
struct props< int_u<n> >
{
static const std::size_t card_ = metal::pow<2, n>::value;
- static const int_u<n> min; // = 0
- static const int_u<n> max; // = card_ - 1
+ static const int_u<n> min() { return 0; }
+ static const int_u<n> max() { return card_ - 1; }
static const unsigned nbits = n;
typedef data_kind kind;
typedef float sum;
@@ -156,15 +156,6 @@
template <unsigned n>
const int_u<n> int_u<n>::one = 1;
-
- template <unsigned n>
- const int_u<n>
- props< int_u<n> >::min = 0;
-
- template <unsigned n>
- const int_u<n>
- props< int_u<n> >::max = metal::pow<2, n>::value - 1;
-
template <unsigned n>
std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i)
{
Index: mln/make/w_window_line.hh
--- mln/make/w_window_line.hh (revision 0)
+++ mln/make/w_window_line.hh (revision 0)
@@ -0,0 +1,81 @@
+// 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_MAKE_W_WINDOW_LINE_HH
+# define MLN_MAKE_W_WINDOW_LINE_HH
+
+/*! \file mln/make/w_window_line.hh
+ *
+ * \brief Routine to create an horizontal mln::w_window.
+ */
+
+# include <mln/core/w_window.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an horizontal centered and symmetrical
+ * mln::w_window.
+ *
+ * The free parameter \c D is a type of delta-point.
+ *
+ * \pre The window length \c L has to be odd.
+ *
+ * \return A window.
+ */
+ template <typename D, typename W, unsigned L>
+ mln::w_window<D,W> w_window_line(const W (&w)[L]);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename D, typename W, unsigned L>
+ mln::w_window<D,W> w_window_line(const W (&w)[L])
+ {
+ mln_precondition(L % 2 = 1);
+ mln::w_window<D,W> w_win;
+ D dp = D::zero;
+ for (unsigned i = 0; i < L; ++i)
+ {
+ dp[D::dim - 1] = i - L / 2;
+ w_win.insert(w[i], dp);
+ }
+ return w_win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_W_WINDOW_LINE_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add local convolution.
* mln/core/concept/doc/generalized_pixel.hh,
* mln/core/concept/generalized_pixel.hh,
* mln/core/internal/pixel_impl.hh (ima): New.
* mln/core/concept/doc/generalized_pixel.hh,
* mln/core/concept/doc/pixel_iterator.hh
* mln/core/concept/generalized_pixel.hh,
* mln/core/concept/pixel_iterator.hh,
* mln/core/dpoints_pixter.hh (ctor): Better sig.
(center_value): Rename as...
(center_val): ...this.
* mln/core/internal/pixel_impl.hh (operator*): Rename as...
(val): ...this.
* mln/debug/iota.hh,
* mln/histo/compute.hh,
* mln/level/apply.hh,
* mln/level/assign.hh,
* mln/level/fast_median.hh,
* mln/level/take.hh,
* mln/level/transform.hh,
* mln/linear/convolve.hh,
: Update.
* mln/core/pixel.hh (is_valid): Disambiguate.
(include): Fix.
* mln/linear/local: New directory.
* mln/linear/local/convolve.hh: New.
* mln/make/pixel.hh: New.
* mln/metal/const.hh: New.
* tests/decorated_image.cc: Fix warning.
* tests/local_convolve.cc: New.
* tests/pixel.cc: Update and augment.
* tests/pixter_point2d.cc: Rename as...
* tests/pixter2d_b.cc: ...this.
Clean, update, and augment.
* tests/pixter_dpoint2d.cc: Rename as...
* tests/dpoints_pixter.cc: ...this.
Clean, update, and augment.
mln/core/concept/doc/generalized_pixel.hh | 9 +
mln/core/concept/doc/pixel_iterator.hh | 4
mln/core/concept/generalized_pixel.hh | 14 +-
mln/core/concept/pixel_iterator.hh | 4
mln/core/dpoints_pixter.hh | 26 ++--
mln/core/internal/pixel_impl.hh | 35 +++++-
mln/core/macros.hh | 1
mln/core/pixel.hh | 12 +-
mln/debug/iota.hh | 2
mln/histo/compute.hh | 2
mln/level/apply.hh | 2
mln/level/assign.hh | 2
mln/level/fast_median.hh | 14 +-
mln/level/take.hh | 2
mln/level/transform.hh | 4
mln/linear/convolve.hh | 16 +-
mln/linear/local/convolve.hh | 174 ++++++++++++++++++++++++++++++
mln/make/pixel.hh | 78 +++++++++++++
mln/metal/const.hh | 58 ++++++++++
tests/decorated_image.cc | 2
tests/dpoints_pixter.cc | 67 ++++++-----
tests/fast_median.cc | 8 -
tests/local_convolve.cc | 78 +++++++++++++
tests/pixel.cc | 13 +-
tests/pixter2d_b.cc | 76 +++++++++----
25 files changed, 589 insertions(+), 114 deletions(-)
Index: tests/local_convolve.cc
--- tests/local_convolve.cc (revision 0)
+++ tests/local_convolve.cc (revision 0)
@@ -0,0 +1,78 @@
+// 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/convolve.cc
+ *
+ * \brief Tests on mln::linear::convolve.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/core/w_window2d_int.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/core/pixel.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/pw/cst.hh>
+#include <mln/border/thickness.hh>
+#include <mln/linear/local/convolve.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ const unsigned size = 3;
+ border::thickness = size - 1;
+
+ image2d_b<int_u8> ima(size, size);
+ debug::iota(ima);
+
+ point2d p = make::point2d(1,1);
+ w_window2d_int w_win = make::w_window(win::rectangle2d(size, size),
+ pw::cst(1));
+
+ int res;
+ {
+ linear::local::convolve(ima, p, w_win, res);
+ mln_assertion(res = size*size * (size*size + 1) / 2);
+ }
+
+ {
+ typedef image2d_b<int_u8> I;
+ linear::local::convolve(pixel<const I>(ima, p), w_win, res);
+ linear::local::convolve(pixel<I>(ima, p), w_win, res);
+ }
+ {
+ linear::local::convolve(make::pixel(ima, p), w_win, res);
+ mln_assertion(res = size*size * (size*size + 1) / 2);
+ }
+
+ res = 0;
+}
Index: tests/fast_median.cc
--- tests/fast_median.cc (revision 1053)
+++ tests/fast_median.cc (working copy)
@@ -57,16 +57,16 @@
{
mln_qixter(I, W) qix(input, win, p);
for_all(qix)
- std::cout << *qix << ' ';
- std::cout << " : " << qix.center_value() << std::endl;
+ std::cout << qix.val() << ' ';
+ std::cout << " : " << qix.center_val() << std::endl;
}
{
pixel<I> pix(input, p);
mln_qixter(I, W) qix(input, win, pix);
for_all(qix)
- std::cout << *qix << ' ';
- std::cout << " : " << qix.center_value() << std::endl;
+ std::cout << qix.val() << ' ';
+ std::cout << " : " << qix.center_val() << std::endl;
}
}
Index: tests/decorated_image.cc
--- tests/decorated_image.cc (revision 1053)
+++ tests/decorated_image.cc (working copy)
@@ -39,7 +39,7 @@
template <typename I>
struct counter
{
- void reading(const I& ima, const mln_psite(I)& p) const
+ void reading(const I&, const mln_psite(I)&) const
{
++count_read;
}
Index: tests/pixter2d_b.cc
--- tests/pixter2d_b.cc (revision 1053)
+++ tests/pixter2d_b.cc (working copy)
@@ -25,38 +25,70 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#include <cassert>
-#include <mln/core/image2d_b.hh>
+/*! \file tests/pixter2d_b.cc
+ *
+ * \brief Tests on mln::fwd_pixter2d_b.
+ */
+#include <mln/core/image2d_b.hh>
-int
-main()
-{
- using namespace mln;
- typedef image2d_b<int> I;
- I ima(20, 20);
+const unsigned size = 20;
+const int v = 51;
- mln_piter_(I) p(ima.domain());
- mln_pixter_(I) pix(ima);
- int i = 0;
+template <typename I>
+void test_fill(I& ima)
+{
+ mln_pixter(I) pxl(ima);
+ unsigned i = 0;
+ for_all(pxl)
+ {
+ ++i;
+ pxl.val() = v;
+ }
+ mln_assertion(i = size * size);
+ mln_assertion(! pxl.is_valid());
+ mln_piter(I) p(ima.domain());
for_all(p)
- ima(p) = i++;
- i = 0;
+ mln_assertion(ima(p) = v);
+}
- for_all(pix)
+
+template <typename I>
+void test_const(const I& imac, I& ima)
+{
{
- mln_assertion(*pix = i ++);
- *pix = 5;
+ mln_pixter(const I) pxl(imac); // const is mandatory
+ pxl.start();
+ mln_assertion(pxl.val() = v);
+ // pxl.val() = v; // error is OK since pixter on 'const I'
+ }
+ {
+ // mln_pixter(I) pxl_(imac); // error is OK since mutable I but const imac
+ mln_pixter(I) pxl(ima);
+ pxl.start();
+ pxl.val() = 2 * pxl.val();
+ mln_assertion(pxl.val() = 2 * v);
+ }
+ {
+ mln_pixter(const I) pxl(ima); // const promotion is OK
+ pxl.start();
+ mln_assertion(pxl.val() = 2 * v);
+ // pxl.val() = v; // error is OK since pixter on 'const I'
+ }
}
- for_all(p)
- mln_assertion(ima(p) = 5);
- pix.start();
- mln_assertion(pix.is_valid());
- pix.invalidate();
- mln_assertion(! pix.is_valid());
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(size, size);
+
+ test_fill(ima);
+ test_const(ima, ima);
}
Index: tests/dpoints_pixter.cc
--- tests/dpoints_pixter.cc (revision 1053)
+++ tests/dpoints_pixter.cc (working copy)
@@ -25,49 +25,56 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/pixter_dpoint2d.cc
+/*! \file tests/dpoints_pixter.cc
*
* \brief Test on mln::dpoints_fwd_pixter.
*/
-#include <cassert>
-#include <iostream>
-
#include <mln/core/image2d_b.hh>
-#include <mln/core/window.hh>
-#include <mln/core/dpoints_pixter.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/make/pixel.hh>
-#include <mln/level/fill.hh>
-int main()
+template <typename I, typename W>
+void test_fill(I& ima, const W& win)
{
- using namespace mln;
+ mln_piter(I) p(ima.domain());
+ mln_qixter(I, W) q(ima, win, p);
+ for_all(p)
+ {
+ unsigned i = 0;
+ for_all(q)
+ ++i, q.val() = 51;
+ mln_assertion(i = 9);
+ }
+}
- typedef image2d_b<int> I;
- typedef I::dpoint D;
- typedef window<D> W;
- typedef dpoints_fwd_pixter<I> qixter;
+// FIXME: test promotion and other constructions
- const unsigned size = 20;
- I ima(size, size);
- const int value = 51;
- level::fill(ima, value);
-
- W win;
- win
- .insert(make::dpoint2d(0, -1))
- .insert(make::dpoint2d(0, -1))
- .insert(make::dpoint2d(1, 0))
- .insert(make::dpoint2d(1, 0));
+template <typename P, typename W>
+void test_pixel(const P& pxl, const W& win)
+{
+ mln_qixter(mln_image(P), W) q(pxl, win);
+ for_all(q)
+ q.val() = 2 * q.val();
+}
- mln_piter_(I) p(ima.domain());
- qixter qix(ima, win, p);
- for_all(p)
- if (p[0] > 0 && p[1] > 0 && p[0] < int(size - 1) && p[1] < int(size - 1))
- for_all(qix)
- mln_assertion(*qix = value);
+
+int main()
+{
+ using namespace mln;
+
+ border::thickness = 1;
+ typedef image2d_b<int> I;
+ I ima(5, 5);
+
+ win::rectangle2d rect(3, 3);
+ point2d p = make::point2d(1, 1);
+
+ test_fill(ima, rect);
+ test_pixel(make::pixel(ima, p), rect);
}
Index: tests/pixel.cc
--- tests/pixel.cc (revision 1053)
+++ tests/pixel.cc (working copy)
@@ -30,8 +30,9 @@
* \brief Tests on mln::pixel.
*/
-#include <mln/core/pixel.hh>
#include <mln/core/image2d_b.hh>
+#include <mln/core/pixel.hh>
+#include <mln/metal/equal.hh>
int main()
@@ -43,18 +44,22 @@
{
pixel<I> pxl(ima, make::point2d(1, 1));
- *pxl = 51;
+ pxl.val() = 51;
mln_assertion(ima.at(1, 1) = 51);
}
{
pixel<const I> pxl(ima, make::point2d(1, 1));
ima.at(1, 1) = 51;
- mln_assertion(*pxl = 51);
+ mln_assertion(pxl.val() = 51);
// hopefully the code below does not compile:
- // *pxl = 0;
+ // pxl.val() = 0;
// assignment of read-only location
}
+ {
+ mln::metal::equal< mln_image_(pixel<I>), I >::check();
+ mln::metal::equal< mln_image_(pixel<const I>), const I >::check();
+ }
}
Index: mln/histo/compute.hh
--- mln/histo/compute.hh (revision 1053)
+++ mln/histo/compute.hh (working copy)
@@ -71,7 +71,7 @@
data<mln_vset(I)> h(input.values());
mln_pixter(const I) p(input);
for_all(p)
- ++h(*p);
+ ++h(p.val());
return h;
}
Index: mln/debug/iota.hh
--- mln/debug/iota.hh (revision 1053)
+++ mln/debug/iota.hh (working copy)
@@ -69,7 +69,7 @@
I& input = exact(input_);
mln_pixter(I) p(input);
for_all(p)
- *p = ++i;
+ p.val() = ++i;
}
} // end of namespace mln::debug::impl
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1053)
+++ mln/core/macros.hh (working copy)
@@ -94,6 +94,7 @@
/// Shortcut to access the image type associated to T.
# define mln_image(T) typename T::image
+# define mln_image_(T) T::image
// l
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 1053)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -71,14 +71,12 @@
/*! \brief Constructor.
*
- * \param[in] image Image subject to iteration.
+ * \param[in] pxl_ref Center (generalized) pixel to iterate around.
* \param[in] dps Object that can provide a set of delta-points.
- * \param[in] p_ref Center (generalized) pixel to iterate around.
*/
template <typename Dps, typename Pref>
- dpoints_fwd_pixter(I& image,
- const Dps& dps,
- const Generalized_Pixel<Pref>& p_ref);
+ dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
+ const Dps& dps);
/// Start an iteration.
void start();
@@ -97,7 +95,7 @@
void update();
/// The value around which this iterator moves.
- const mln_value(I)& center_value() const;
+ const mln_value(I)& center_val() const;
private:
@@ -140,23 +138,23 @@
init_(dps);
}
-
template <typename I>
template <typename Dps, typename Pref>
- dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
- const Dps& dps,
- const Generalized_Pixel<Pref>& p_ref)
- : super_(image)
+ dpoints_fwd_pixter<I>::dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
+ const Dps& dps)
+ : super_(internal::force_exact<Pref>(pxl_ref_).ima())
{
- mln_precondition(image.has_data());
+ const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
+ mln_precondition(pxl_ref.ima().has_data());
p_ref_ = 0;
- value_ref_ = internal::force_exact<Pref>(p_ref).address_();
+ // potential promotion from (T**) to (const T**) shall be forced:
+ value_ref_ = (mln_qlf_value(I)**)(void*)(pxl_ref.address_());
init_(dps);
}
template <typename I>
const mln_value(I)&
- dpoints_fwd_pixter<I>::center_value() const
+ dpoints_fwd_pixter<I>::center_val() const
{
mln_invariant(value_ref_ != 0 || p_ref_ != 0);
if (p_ref_)
Index: mln/core/internal/pixel_impl.hh
--- mln/core/internal/pixel_impl.hh (revision 1053)
+++ mln/core/internal/pixel_impl.hh (working copy)
@@ -67,10 +67,14 @@
/// pixel iterator value.
- lvalue operator*();
+ lvalue val();
/// Get the pixel iterator value.
- rvalue operator*() const;
+ rvalue val() const;
+
+
+ /// Give the pixel image.
+ I& ima() const;
/// Address of the current iterator value/pixel.
@@ -113,7 +117,11 @@
/// Get the pixel iterator value.
- rvalue operator*() const;
+ rvalue val() const;
+
+
+ /// Give the pixel image.
+ const I& ima() const;
/// Address of the current iterator value/pixel.
@@ -155,7 +163,7 @@
template <typename I, typename E>
mln_lvalue(I)
- pixel_impl_<I, E>::operator*()
+ pixel_impl_<I, E>::val()
{
mln_precondition(is_valid_());
return *value_ptr_;
@@ -163,13 +171,21 @@
template <typename I, typename E>
mln_rvalue(I)
- pixel_impl_<I, E>::operator*() const
+ pixel_impl_<I, E>::val() const
{
mln_precondition(is_valid_());
return *value_ptr_;
}
template <typename I, typename E>
+ I&
+ pixel_impl_<I, E>::ima() const
+ {
+ // a const pixel, yet a mutable image
+ return const_cast<I&>(image_);
+ }
+
+ template <typename I, typename E>
mln_value(I) **
pixel_impl_<I, E>::address_() const
{
@@ -195,13 +211,20 @@
template <typename I, typename E>
mln_rvalue(I)
- pixel_impl_<const I, E>::operator*() const
+ pixel_impl_<const I, E>::val() const
{
mln_precondition(is_valid_());
return *value_ptr_;
}
template <typename I, typename E>
+ const I&
+ pixel_impl_<const I, E>::ima() const
+ {
+ return image_;
+ }
+
+ template <typename I, typename E>
const mln_value(I) **
pixel_impl_<const I, E>::address_() const
{
Index: mln/core/pixel.hh
--- mln/core/pixel.hh (revision 1053)
+++ mln/core/pixel.hh (working copy)
@@ -96,12 +96,11 @@
bool
pixel<I>::is_valid() const
{
- I& ima = this->image_;
- if (this->value_ptr_ = 0 || ! ima.has_data())
+ if (this->value_ptr_ = 0 || ! this->image_.has_data())
return false;
- int o = this->value_ptr_ - ima.buffer();
- mln_point(I) p = ima.point_at_offset(o);
- return ima.owns_(p);
+ int o = this->value_ptr_ - this->image_.buffer();
+ mln_point(I) p = this->image_.point_at_offset(o);
+ return this->image_.owns_(p);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -109,4 +108,7 @@
} // end of namespace mln
+# include <mln/make/pixel.hh>
+
+
#endif // ! MLN_CORE_PIXEL_HH
Index: mln/core/concept/pixel_iterator.hh
--- mln/core/concept/pixel_iterator.hh (revision 1053)
+++ mln/core/concept/pixel_iterator.hh (working copy)
@@ -57,7 +57,7 @@
only if the iterator is constructed on a mutable image:
typedef lvalue;
- lvalue operator*();
+ lvalue val();
*/
protected:
Pixel_Iterator();
@@ -70,7 +70,7 @@
Pixel_Iterator<E>::Pixel_Iterator()
{
// typedef mln_lvalue(E) lvalue;
-// lvalue (E::*m)() = & E::operator*;
+// lvalue (E::*m)() = & E::val;
// m = 0;
}
Index: mln/core/concept/generalized_pixel.hh
--- mln/core/concept/generalized_pixel.hh (revision 1053)
+++ mln/core/concept/generalized_pixel.hh (working copy)
@@ -62,9 +62,10 @@
/*
typedef value;
typedef rvalue;
- typedef image;
+ typedef image; // is const or not
- rvalue operator*() const;
+ rvalue val() const;
+ image& ima() const;
mln_qlf_value(image)** address_() const;
*/
protected:
@@ -80,13 +81,16 @@
typedef mln_value(E) value;
typedef mln_rvalue(E) rvalue;
- rvalue (E::*m1)() const = & E::operator*;
+ rvalue (E::*m1)() const = & E::val;
m1 = 0;
typedef mln_image(E) image;
-
- mln_qlf_value(image)** (E::*m2)() const = & E::address_;
+ // FIXME: check "without &"
+ image& (E::*m2)() const = & E::ima;
m2 = 0;
+
+ mln_qlf_value(image)** (E::*m3)() const = & E::address_;
+ m3 = 0;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/pixel_iterator.hh
--- mln/core/concept/doc/pixel_iterator.hh (revision 1053)
+++ mln/core/concept/doc/pixel_iterator.hh (working copy)
@@ -47,12 +47,12 @@
*/
typedef void lvalue;
- /*! \brief Dereference operator.
+ /*! \brief Give the pixel value.
*
* \return The current pixel value; this value cannot be
* modified.
*/
- lvalue operator*() const;
+ lvalue val() const;
protected:
Pixel_Iterator();
Index: mln/core/concept/doc/generalized_pixel.hh
--- mln/core/concept/doc/generalized_pixel.hh (revision 1053)
+++ mln/core/concept/doc/generalized_pixel.hh (working copy)
@@ -61,7 +61,14 @@
*
* \return A read-only value.
*/
- rvalue operator*() const;
+ rvalue val() const;
+
+ /*! \brief Give the image of this generalized pixel.
+ *
+ * The constness of a pixel object is not transmitted to the
+ * underlying image.
+ */
+ image& ima() const;
/*! \brief Give a hook to the value address.
*
Index: mln/metal/const.hh
--- mln/metal/const.hh (revision 0)
+++ mln/metal/const.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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_METAL_CONST_HH
+# define MLN_METAL_CONST_HH
+
+
+# define mlc_const(T) typename mln::metal::const_< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct const_
+ {
+ typedef const T ret;
+ };
+
+ template <typename T>
+ struct const_< const T >
+ {
+ typedef const T ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_CONST_HH
Index: mln/level/take.hh
--- mln/level/take.hh (revision 1053)
+++ mln/level/take.hh (working copy)
@@ -77,7 +77,7 @@
const I& input = exact(input_);
mln_pixter(const I) pxl(input);
for_all(pxl)
- a.take(*pxl);
+ a.take(pxl.val());
}
} // end of namespace mln::level::impl
Index: mln/level/assign.hh
--- mln/level/assign.hh (revision 1053)
+++ mln/level/assign.hh (working copy)
@@ -80,7 +80,7 @@
mln_pixter(L) lhs(target);
mln_pixter(const R) rhs(data);
for_all_2(lhs, rhs)
- *lhs = *rhs;
+ lhs.val() = rhs.val();
}
} // end of namespace mln::level::impl
Index: mln/level/apply.hh
--- mln/level/apply.hh (revision 1053)
+++ mln/level/apply.hh (working copy)
@@ -86,7 +86,7 @@
mln_pixter(const I) pxl(input);
for_all(pxl)
- f(input(*pxl));
+ f(pxl.val());
return f;
}
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 1053)
+++ mln/level/fast_median.hh (working copy)
@@ -99,7 +99,7 @@
{
mln_qixter(const I, W) q(input, win, p);
for_all(q)
- med.take(*q);
+ med.take(q.val());
}
int& row = p.row();
@@ -114,10 +114,10 @@
// "go down"
for_all(q_top)
- med.untake(*q_top);
+ med.untake(q_top.val());
for_all(q_bot)
- med.take(*q_bot);
+ med.take(q_bot.val());
output(p) = med.to_value();
@@ -127,9 +127,9 @@
{
++col;
for_all(q_fm)
- med.untake(*q_fm);
+ med.untake(q_fm.val());
for_all(q_fp)
- med.take(*q_fp);
+ med.take(q_fp.val());
output(p) = med.to_value();
}
else
@@ -138,9 +138,9 @@
{
--col;
for_all(q_bm)
- med.untake(*q_bm);
+ med.untake(q_bm.val());
for_all(q_bp)
- med.take(*q_bp);
+ med.take(q_bp.val());
output(p) = med.to_value();
}
// change browsing
Index: mln/level/transform.hh
--- mln/level/transform.hh (revision 1053)
+++ mln/level/transform.hh (working copy)
@@ -31,6 +31,8 @@
/*! \file mln/level/transform.hh
*
* \brief Transform the contents of an image into another one.
+ *
+ * \todo Clean this file + overload with pixel iterators.
*/
# include <mln/core/concept/image.hh>
@@ -110,7 +112,7 @@
// po.start();
// for_all(pi)
// {
-// *po = lut(*pi);
+// po.val() = lut(pi.val());
// po.next();
// }
// }
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 1053)
+++ mln/linear/convolve.hh (working copy)
@@ -46,11 +46,14 @@
namespace linear
{
- /*! Convolution of image \p input by the weighted window \p win.
+ /*! Convolution of image \p input by the weighted window \p w_win.
*
* \warning Computation of \p output(p) is performed with the
* value type of \p output.
*
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ *
* \pre output.domain = input.domain
*/
template <typename I, typename W, typename O>
@@ -97,26 +100,29 @@
mln_pixter(O) p_out(output);
mln_pixter(const I) p(input);
- mln_qixter(const I, W) q(input, w_win, p);
+ mln_qixter(const I, W) q(p, w_win);
for_all_2(p, p_out)
{
mln_value(O) v = 0;
unsigned i = 0;
for_all(q)
- v += w_win.w(i++) * *q;
- *p_out = v;
+ v += w_win.w(i++) * q.val();
+ p_out.val() = v;
}
}
} // end of namespace mln::linear::impl
+
+ // Facade.
+
template <typename I, typename W, typename O>
void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- impl::convolve(exact(input), - exact(w_win), exact(output));
+ impl::convolve(exact(input), exact(w_win), exact(output));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/linear/local/convolve.hh
--- mln/linear/local/convolve.hh (revision 0)
+++ mln/linear/local/convolve.hh (revision 0)
@@ -0,0 +1,174 @@
+// 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_LINEAR_LOCAL_CONVOLVE_HH
+# define MLN_LINEAR_LOCAL_CONVOLVE_HH
+
+/*! \file mln/linear/local/convolve.hh
+ *
+ * \brief Local convolution at a point.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/generalized_pixel.hh>
+# include <mln/core/concept/weighted_window.hh>
+# include <mln/metal/const.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ namespace local
+ {
+
+ /*! Local convolution of image \p input at point \p p by the
+ * weighted window \p w_win.
+ *
+ * \warning Computation of the \p result is performed with the
+ * type \c R.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ */
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Image<I>& input,
+ const Generalized_Point<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result);
+
+
+ /*! Local convolution around (generalized) pixel \p by the
+ * weighted window \p w_win.
+ *
+ * \warning Computation of the \p result is performed with the
+ * type \c R.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ */
+ template <typename P, typename W, typename R>
+ void convolve(const Generalized_Pixel<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Image<I>& input_,
+ const Generalized_Point<P>& p_,
+ const W& w_win,
+ R& result)
+ {
+ const I& input = exact(input_);
+ const P& p = internal::force_exact<P>(p_);
+
+ R tmp = 0; // FIXME: zero?
+ mln_qiter(W) q(w_win, p);
+ for_all(q) if (input.has(q))
+ tmp += input(q) * q.w();
+ result = tmp;
+ }
+
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Fast_Image<I>& input_,
+ const Generalized_Point<P>& p_,
+ const W& w_win,
+ R& result)
+ {
+ const I& input = exact(input_);
+ const P& p = internal::force_exact<P>(p_);
+
+ mln_precondition(input.border() >= w_win.delta());
+
+ R tmp = 0;
+ unsigned i = 0;
+ mln_qixter(const I, W) q(input, w_win, p);
+ for_all(q)
+ tmp += w_win.w(i++) * q.val();
+ result = tmp;
+ }
+
+ template <typename P, typename W, typename R>
+ void convolve(const Generalized_Pixel<P>& p_,
+ const W& w_win,
+ R& result)
+ {
+ const P& p = internal::force_exact<P>(p_);
+ mln_precondition(p.ima().border() >= w_win.delta());
+
+ R tmp = 0;
+ unsigned i = 0;
+ // FIXME: mln_qixter(const P, W) should work
+ // FIXME: so make the trait make this job...
+ mln_qixter(mlc_const(mln_image(P)), W) q(p, w_win);
+ for_all(q)
+ tmp += w_win.w(i++) * q.val();
+ result = tmp;
+ }
+
+ } // end of namespace mln::linear::impl
+
+
+ // Facades.
+
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Image<I>& input,
+ const Generalized_Point<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result)
+ {
+ mln_precondition(exact(input).has_data());
+ impl::convolve(exact(input), p, exact(w_win), result);
+ }
+
+ template <typename P, typename W, typename R>
+ void convolve(const Generalized_Pixel<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result)
+ {
+ impl::convolve(p, exact(w_win), result);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear::local
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_LOCAL_CONVOLVE_HH
Index: mln/make/pixel.hh
--- mln/make/pixel.hh (revision 0)
+++ mln/make/pixel.hh (revision 0)
@@ -0,0 +1,78 @@
+// 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_MAKE_PIXEL_HH
+# define MLN_MAKE_PIXEL_HH
+
+/*! \file mln/make/pixel.hh
+ *
+ * \brief Routine to construct an mln::pixel.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/pixel.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /// Create an mln::pixel from a constant image \p ima and a point \p p.
+ template <typename I>
+ mln::pixel<const I> pixel(const Image<I>& ima, const mln_point(I)& p);
+
+ /// Create an mln::pixel from a mutable image \p ima and a point \p p.
+ template <typename I>
+ mln::pixel<I> pixel(Image<I>& ima, const mln_point(I)& p);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln::pixel<const I> pixel(const Image<I>& ima, const mln_point(I)& p)
+ {
+ mln::pixel<const I> tmp(exact(ima), p);
+ return tmp;
+ }
+
+ template <typename I>
+ mln::pixel<I> pixel(Image<I>& ima, const mln_point(I)& p)
+ {
+ mln::pixel<I> tmp(exact(ima), p);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_PIXEL_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add proper inheritance to functions.
* mln/core/concept/doc/neighborhood.hh,
* mln/core/concept/neighborhood.hh,
* mln/core/neighb.hh (point): New.
* mln/convert/to_image.hh
(helper_dim_, helper_image_from_): New in mln::internal.
(image_from_): New in mln.
(mln_image_from): New macro.
(to_image): Fix; now generalized.
* mln/metal/all.hh: New.
* mln/metal/equal.hh: Update.
(mlc_equal): New.
* mln/metal/if.hh: New.
* mln/metal/is_a.hh: New.
* mln/metal/unptr.hh: New.
* mln/metal/unqualif.hh: New.
* mln/metal/unref.hh: New.
* mln/core/concept/function.hh (result): New in Function_p2b.
* mln/fun/internal: New directory.
* mln/pw/cst.hh: Precise inheritance.
* mln/pw/value.hh: Likewise.
(select_function_): Move to...
* mln/fun/internal/selector.hh: ...this new file.
(select_function_): Rename as...
(selector_): ...this.
* mln/fun/c.hh: New.
* mln/convert/to_fun.hh: New.
* mln/convert/to_window.hh (to_window): New overload.
* mln/estim/mean.hh (mean): New overload.
* mln/estim/sum.hh: New.
* mln/level/run.hh: Rename as...
* mln/level/compute.hh: ...this.
(run): Rename as...
(compute): ...this.
* tests/w_window2d_int.cc: Augment.
mln/convert/to_fun.hh | 77 ++++++++++++++++
mln/convert/to_image.hh | 59 ++++++++++--
mln/convert/to_window.hh | 29 ++++--
mln/core/concept/doc/neighborhood.hh | 3
mln/core/concept/function.hh | 1
mln/core/concept/neighborhood.hh | 2
mln/core/neighb.hh | 3
mln/estim/mean.hh | 28 +++++
mln/estim/sum.hh | 88 ++++++++++++++++++
mln/fun/c.hh | 85 +++++++++++++++++
mln/fun/internal/selector.hh | 168 +++++++++++++++++++++++++++++++++++
mln/level/compute.hh | 18 +--
mln/metal/all.hh | 58 ++++++++++++
mln/metal/equal.hh | 16 +--
mln/metal/if.hh | 85 +++++++++++++++++
mln/metal/is_a.hh | 88 ++++++++++++++++++
mln/metal/unptr.hh | 58 ++++++++++++
mln/metal/unqualif.hh | 58 ++++++++++++
mln/metal/unref.hh | 58 ++++++++++++
mln/pw/cst.hh | 13 +-
mln/pw/value.hh | 21 ----
tests/pw_value.cc | 1
tests/w_window2d_int.cc | 24 +++--
23 files changed, 968 insertions(+), 73 deletions(-)
Index: tests/w_window2d_int.cc
--- tests/w_window2d_int.cc (revision 1052)
+++ tests/w_window2d_int.cc (working copy)
@@ -35,23 +35,22 @@
#include <mln/convert/to_image.hh>
#include <mln/convert/to_w_window.hh>
-#include <mln/debug/println.hh>
+#include <mln/convert/to_fun.hh>
+#include <mln/estim/sum.hh>
-struct my_f : mln::Function_p2v< my_f >
-{
- typedef int result;
- int operator()(const mln::point2d& p) const
+
+int f(mln::point2d p)
{
return p.row() + p.col();
}
-};
int main()
{
using namespace mln;
+ {
int ws[] = { -1, 0, 1,
-2, 0, 2,
-1, 0, 1 };
@@ -60,7 +59,16 @@
image2d_b<int> ima = convert::to_image(w_win);
w_window2d_int w_win_2 = convert::to_w_window(ima);
mln_assertion(w_win_2 = w_win);
+ }
+
+ {
+ w_window2d_int w_win = make::w_window(win::rectangle2d(3, 5),
+ convert::to_fun(f));
+ // -3 -2 -1 0 +1
+ // -2 -1 0 +1 +2
+ // -1 0 +1 +2 +3
+ image2d_b<int> ima = convert::to_image(w_win);
+ mln_assertion(estim::sum(ima) = 0);
+ }
- w_window2d_int tmp = make::w_window(win::rectangle2d(3, 5), my_f());
- debug::println(convert::to_image(tmp));
}
Index: tests/pw_value.cc
--- tests/pw_value.cc (revision 1052)
+++ tests/pw_value.cc (working copy)
@@ -43,6 +43,5 @@
image2d_b<int> ima(3, 3);
point2d p = make::point2d(1, 1);
ima(p) = 51;
-
mln_assertion( (pw::value(ima) = pw::cst(51))(p) = true );
}
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 1052)
+++ mln/convert/to_image.hh (working copy)
@@ -45,36 +45,73 @@
# include <mln/level/fill.hh>
+# define mln_image_from(Src, Value) typename mln::image_from_< Src, Value >::ret
+
+
+
namespace mln
{
+ // FIXME: Move elsewhere.
+ namespace internal
+ {
+
+ template <typename T>
+ struct helper_dim_
+ {
+ typedef mln_point(T) P;
+ enum { value = P::dim };
+ };
+
+ template <unsigned dim, typename V> struct helper_image_from_;
+
+ template <typename V>
+ struct helper_image_from_< 2, V >
+ {
+ typedef image2d_b<V> ret;
+ };
+
+ } // end of namespace mln::internal
+
+
+ // FIXME: Doc + move elsewhere!
+ template <typename T, typename V>
+ struct image_from_
+ {
+ enum { dim = internal::helper_dim_<T>::value };
+ typedef typename internal::helper_image_from_< dim, V >::ret ret;
+ };
+
+
+
namespace convert
{
+
/// Convert a point set \p pset into a binary image.
template <typename S>
- image2d_b<bool> to_image(const Point_Set<S>& pset);
+ mln_image_from(S, bool) to_image(const Point_Set<S>& pset);
/// Convert a window \p win into a binary image.
template <typename W>
- image2d_b<bool> to_image(const Window<W>& win);
+ mln_image_from(W, bool) to_image(const Window<W>& win);
/// Convert a neighborhood \p nbh into a binary image.
template <typename N>
- image2d_b<bool> to_image(const Neighborhood<N>& nbh);
+ mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh);
/// Convert a weighted window \p w_win into an image.
template <typename W>
- image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win);
+ mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win);
# ifndef MLN_INCLUDE_ONLY
template <typename S>
- image2d_b<bool> to_image(const Point_Set<S>& pset_)
+ mln_image_from(S, bool) to_image(const Point_Set<S>& pset_)
{
const S& pset = exact(pset_);
- image2d_b<bool> ima(pset.bbox());
+ mln_image_from(S, bool) ima(pset.bbox());
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
@@ -83,14 +120,14 @@
}
template <typename W>
- image2d_b<bool> to_image(const Window<W>& win_)
+ mln_image_from(W, bool) to_image(const Window<W>& win_)
{
const W& win = exact(win_);
mln_precondition(! win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(win);
- image2d_b<bool> ima(b);
+ mln_image_from(W, bool) ima(b);
level::fill(ima, false);
mln_qiter(W) q(win, P::zero);
for_all(q)
@@ -99,20 +136,20 @@
}
template <typename N>
- image2d_b<bool> to_image(const Neighborhood<N>& nbh)
+ mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh)
{
return to_image(convert::to_window(nbh));
}
template <typename W>
- image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win_)
+ mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
{
const W& w_win = exact(w_win_);
mln_precondition(! w_win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(w_win);
- image2d_b<mln_weight(W)> ima(b);
+ mln_image_from(W, mln_weight(W)) ima(b);
mln_qiter(W) q(w_win, P::zero);
for_all(q)
ima(q) = q.w();
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1052)
+++ mln/convert/to_window.hh (working copy)
@@ -33,9 +33,10 @@
* \brief Conversions to mln::window.
*/
-# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
namespace mln
@@ -48,9 +49,13 @@
template <typename N>
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
- /// Convert a binary image \p input into a window.
+ /// Convert a binary image \p ima into a window.
template <typename I>
- window<mln_dpoint(I)> to_window(const Image<I>& input);
+ window<mln_dpoint(I)> to_window(const Image<I>& ima);
+
+ /// Convert a point set \p pset into a window.
+ template <typename S, typename F>
+ window<mln_dpoint(S)> to_window(const Point_Set<S>& pset);
# ifndef MLN_INCLUDE_ONLY
@@ -69,21 +74,27 @@
}
template <typename I>
- window<mln_dpoint(I)> to_window(const Image<I>& input_)
+ window<mln_dpoint(I)> to_window(const Image<I>& ima_)
{
- const I& input = exact(input_);
- mln_precondition(input.has_data());
- // FIXME: Check that input is binary!
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ // FIXME: Check that ima is binary!
typedef mln_dpoint(I) D;
typedef mln_point(D) P;
window<D> win;
- mln_piter(I) p(input.domain());
+ mln_piter(I) p(ima.domain());
for_all(p)
- if (input(p))
+ if (ima(p))
win.insert(p - P::zero);
return win;
}
+ template <typename S, typename F>
+ window<mln_dpoint(S)> to_window(const Point_Set<S>& pset)
+ {
+ return to_window(pw::cst(true) | pset);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
Index: mln/convert/to_fun.hh
--- mln/convert/to_fun.hh (revision 0)
+++ mln/convert/to_fun.hh (revision 0)
@@ -0,0 +1,77 @@
+// 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_CONVERT_TO_FUN_HH
+# define MLN_CONVERT_TO_FUN_HH
+
+/*! \file mln/convert/to_fun.hh
+ *
+ * \brief Conversions towards some mln::Function.
+ */
+
+# include <mln/pw/value.hh>
+# include <mln/fun/c.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a C unary function into an mln::fun::C.
+ template <typename R, typename A>
+ fun::C<R(*)(A)> to_fun(R (*f)(A));
+
+ /// Convert an image into a function.
+ template <typename I>
+ pw::value_<I> to_fun(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename R, typename A>
+ fun::C<R(*)(A)> to_fun(R (*f_)(A))
+ {
+ fun::C<R(*)(A)> f(f_);
+ return f;
+ }
+
+ template <typename I>
+ pw::value_<I> to_fun(const Image<I>& ima)
+ {
+ return pw::value(ima);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_FUN_HH
Index: mln/estim/sum.hh
--- mln/estim/sum.hh (revision 0)
+++ mln/estim/sum.hh (revision 0)
@@ -0,0 +1,88 @@
+// 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_ESTIM_SUM_HH
+# define MLN_ESTIM_SUM_HH
+
+/*! \file mln/estim/sum.hh
+ *
+ * \brief Compute the sum pixel value.
+ */
+
+# include <mln/accu/sum.hh>
+# include <mln/level/compute.hh>
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+ /*! \brief Compute the sum value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \return The sum value.
+ */
+ template <typename I>
+ mln_sum(mln_value(I)) sum(const Image<I>& input);
+
+
+ /*! \brief Compute the sum value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] result The sum value.
+ */
+ template <typename I, typename S>
+ void sum(const Image<I>& input, S& result);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_sum(mln_value(I)) sum(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ return level::compute(input, accu::sum<mln_value(I)>()).to_value();
+ }
+
+ template <typename I, typename S>
+ void sum(const Image<I>& input, S& result)
+ {
+ mln_precondition(exact(input).has_data());
+ result = level::compute(input,
+ accu::sum<mln_value(I), S>()).to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_SUM_HH
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1052)
+++ mln/estim/mean.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/accu/mean.hh>
-# include <mln/level/run.hh>
+# include <mln/level/compute.hh>
namespace mln
@@ -46,20 +46,40 @@
/*! \brief Compute the mean value of the pixels of image \p input.
*
* \param[in] input The image.
+ * \return The mean value.
*/
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input);
+ /*! \brief Compute the mean value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] result The mean value.
+ *
+ * The free parameter \c S is the type used to compute the
+ * summation.
+ */
+ template <typename S, typename I, typename M>
+ void mean(const Image<I>& input, M& result);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input)
{
mln_precondition(exact(input).has_data());
- typedef mln_value(I) V;
- typedef mln_sum(V) S;
- return level::run(input, accu::mean<V, S>()).to_value();
+ return level::compute(input,
+ accu::mean<mln_value(I)>()).to_value();
+ }
+
+ template <typename S, typename I, typename M>
+ void mean(const Image<I>& input, M& result)
+ {
+ mln_precondition(exact(input).has_data());
+ result = level::compute(input,
+ accu::mean<mln_value(I), S, M>()).to_value();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/pw/cst.hh
--- mln/pw/cst.hh (revision 1052)
+++ mln/pw/cst.hh (working copy)
@@ -33,7 +33,7 @@
* \brief FIXME.
*/
-# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/selector.hh>
namespace mln
@@ -45,11 +45,12 @@
// FIXME: Doc!
template <typename T>
- struct cst_ : public Function_p2v< cst_<T> >
+ struct cst_
+ : fun::internal::selector_p2_<T, cst_<T> >::ret
{
typedef T result;
- cst_(T t);
+ cst_(const T& t);
template <typename P>
T operator()(const P&) const;
@@ -62,7 +63,7 @@
// FIXME: Doc!
template <typename T>
- cst_<T> cst(T t);
+ cst_<T> cst(const T& t);
# ifndef MLN_INCLUDE_ONLY
@@ -70,7 +71,7 @@
// pw::cst_<T>
template <typename T>
- cst_<T>::cst_(T t)
+ cst_<T>::cst_(const T& t)
: t_(t)
{
}
@@ -86,7 +87,7 @@
// pw::cst(t)
template <typename T>
- cst_<T> cst(T t)
+ cst_<T> cst(const T& t)
{
cst_<T> tmp(t);
return tmp;
Index: mln/pw/value.hh
--- mln/pw/value.hh (revision 1052)
+++ mln/pw/value.hh (working copy)
@@ -33,9 +33,8 @@
* \brief FIXME.
*/
-# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/selector.hh>
# include <mln/core/concept/image.hh>
-# include <mln/value/props.hh>
@@ -45,26 +44,12 @@
namespace pw
{
- // FIXME: Move!
-
- namespace internal
- {
-
- template <typename K, typename E>
- struct select_function_ : Function_p2v<E>
- {};
-
- template <typename E>
- struct select_function_< value::binary_kind, E > : Function_p2b<E>
- {};
-
- } // end of namespace mln::pw::internal
-
// FIXME: Doc!
template <typename I>
- struct value_ : public internal::select_function_< mln_value_kind(I), value_<I> >
+ struct value_
+ : fun::internal::selector_p2_< mln_value(I), value_<I> >::ret
{
typedef mln_value(I) result;
value_(const I& ima);
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 1052)
+++ mln/core/neighb.hh (working copy)
@@ -58,6 +58,9 @@
/// Dpoint associated type.
typedef D dpoint;
+ /// Point associated type.
+ typedef mln_point(D) point;
+
/*! \brief Point_Iterator type to browse the points of a generic
* neighborhood w.r.t. the ordering of delta-points.
*/
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1052)
+++ mln/core/concept/function.hh (working copy)
@@ -99,6 +99,7 @@
template <typename E>
struct Function_p2b : public Function_p2v<E>
{
+ typedef bool result;
protected:
Function_p2b();
};
Index: mln/core/concept/neighborhood.hh
--- mln/core/concept/neighborhood.hh (revision 1052)
+++ mln/core/concept/neighborhood.hh (working copy)
@@ -52,6 +52,7 @@
typedef bkd_niter;
typedef dpoint;
+ typedef point;
*/
protected:
@@ -68,6 +69,7 @@
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
typedef mln_dpoint(E) dpoint;
+ typedef mln_point(E) point;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/neighborhood.hh
--- mln/core/concept/doc/neighborhood.hh (revision 1052)
+++ mln/core/concept/doc/neighborhood.hh (working copy)
@@ -59,6 +59,9 @@
/// Dpoint associated type.
typedef void dpoint;
+
+ /// Point associated type.
+ typedef void point;
};
} // end of namespace mln::doc
Index: mln/fun/c.hh
--- mln/fun/c.hh (revision 0)
+++ mln/fun/c.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_FUN_C_HH
+# define MLN_FUN_C_HH
+
+/*! \file mln/fun/c.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/fun/internal/selector.hh>
+# include <mln/metal/unqualif.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ template <typename F> struct C;
+
+
+ // FIXME: Doc!
+ template <typename R, typename A>
+ struct C< R (*)(A) >
+ :
+ fun::internal::selector_< R, A, C<R(*)(A)> >::ret
+ {
+ C(R (*f)(A));
+ typedef R result;
+ R operator()(const mlc_unqualif(A)& a) const;
+ protected:
+ R (*f_)(A);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename R, typename A>
+ C<R(*)(A)>::C(R (*f)(A))
+ : f_(f)
+ {
+ }
+
+ template <typename R, typename A>
+ R
+ C<R(*)(A)>::operator()(const mlc_unqualif(A)& a) const
+ {
+ return f_(a);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_P2B_C_HH
Index: mln/fun/internal/selector.hh
--- mln/fun/internal/selector.hh (revision 0)
+++ mln/fun/internal/selector.hh (revision 0)
@@ -0,0 +1,168 @@
+// 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_FUN_INTERNAL_SELECTOR_HH
+# define MLN_FUN_INTERNAL_SELECTOR_HH
+
+/*! \file mln/fun/internal/selector.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/core/concept/point.hh>
+# include <mln/metal/unqualif.hh>
+# include <mln/metal/if.hh>
+# include <mln/metal/is_a.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace internal
+ {
+
+ // Function_v2v
+ // |
+ // + -- Function_i2v
+ // |
+ // + -- Function_p2v
+ // |
+ // + -- Function_p2b
+ // |
+ // + -- Function_p2p
+
+ enum
+ {
+ b_,
+ i_,
+ p_,
+ v_
+ };
+
+ template <int arg, int res, typename E> struct helper_selector_;
+
+ // no b2* type => v2v type
+ template <typename E>
+ struct helper_selector_< b_, b_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, i_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, p_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, v_, E > { typedef Function_v2v<E> ret; };
+
+ // i2* => only i2v type
+ template <typename E>
+ struct helper_selector_< i_, b_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, i_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, p_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, v_, E > { typedef Function_i2v<E> ret; };
+
+ // p2*
+ template <typename E>
+ struct helper_selector_< p_, b_, E > { typedef Function_p2b<E> ret; };
+ template <typename E>
+ struct helper_selector_< p_, i_, E > { typedef Function_p2v<E> ret; }; // no p2i type => p2v
+ template <typename E>
+ struct helper_selector_< p_, p_, E > { typedef Function_p2p<E> ret; };
+ template <typename E>
+ struct helper_selector_< p_, v_, E > { typedef Function_p2v<E> ret; };
+
+ // v2* => only v2v type
+ template <typename E>
+ struct helper_selector_< v_, b_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, i_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, p_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, v_, E > { typedef Function_v2v<E> ret; };
+
+
+ // tag_
+
+ template <typename T> struct tag_;
+
+ template <>
+ struct tag_< bool >
+ {
+ enum { value = b_ };
+ };
+
+ template <>
+ struct tag_< unsigned >
+ {
+ enum { value = i_ };
+ };
+
+ template <typename T>
+ struct tag_
+ {
+ enum { value = mlc_is_a(T, Point)::to_bool
+ ? p_
+ : v_ };
+ };
+
+
+ template <typename R_, typename A_, typename E>
+ struct selector_
+ {
+ typedef mlc_unqualif(R_) R;
+ typedef mlc_unqualif(A_) A;
+ enum { arg = tag_<A>::value,
+ res = tag_<R>::value };
+ typedef typename helper_selector_<arg, res, E>::ret ret;
+ private:
+ selector_();
+ };
+
+
+ template <typename R_, typename E>
+ struct selector_p2_
+ {
+ typedef mlc_unqualif(R_) R;
+ enum { res = tag_<R>::value };
+ typedef typename helper_selector_<p_, res, E>::ret ret;
+ private:
+ selector_p2_();
+ };
+
+ } // end of namespace mln::fun::internal
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_INTERNAL_SELECTOR_HH
Index: mln/metal/unqualif.hh
--- mln/metal/unqualif.hh (revision 0)
+++ mln/metal/unqualif.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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_METAL_UNQUALIF_HH
+# define MLN_METAL_UNQUALIF_HH
+
+# include <mln/metal/unconst.hh>
+# include <mln/metal/unptr.hh>
+# include <mln/metal/unref.hh>
+
+
+# define mlc_unqualif(T) typename mln::metal::unqualif< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unqualif
+ {
+ typedef mlc_unref(T) tmp1;
+ typedef mlc_unconst(tmp1) tmp2;
+ typedef mlc_unptr(tmp2) ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNQUALIF_HH
Index: mln/metal/if.hh
--- mln/metal/if.hh (revision 0)
+++ mln/metal/if.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_CORE_METAL_IF_HH
+# define MLN_CORE_METAL_IF_HH
+
+/*! \file mln/metal/if.hh
+ *
+ * \brief Definition of an "if-then-else" expression type.
+ */
+
+# include <mln/metal/bool.hh>
+
+# define mlc_if(Cond, Then, Else) typename mln::metal::if_< Cond, Then, Else >::ret
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace internal
+ {
+
+ template <bool cond, typename Then, typename Else>
+ struct helper_if_;
+
+ template <typename Then, typename Else>
+ struct helper_if_< true, Then, Else >
+ {
+ typedef Then ret;
+ };
+
+ template <typename Then, typename Else>
+ struct helper_if_< false, Then, Else >
+ {
+ typedef Else ret;
+ };
+
+ } // end of namespace mln::metal::internal
+
+
+ /*! \brief "if-then-else" expression.
+ *
+ * FIXME: Doc!
+ */
+ template <typename Cond, typename Then, typename Else>
+ struct if_ : internal::helper_if_< Cond::value, Then, Else >
+ {
+ // ret is inherited.
+ };
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_METAL_IF_HH
Index: mln/metal/equal.hh
--- mln/metal/equal.hh (revision 1052)
+++ mln/metal/equal.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_METAL_EQUAL_HH
# define MLN_METAL_EQUAL_HH
+# include <mln/metal/bool.hh>
+
+
+# define mlc_equal(T1, T2) mln::metal::equal< T1, T2 >
+
namespace mln
{
@@ -36,15 +41,12 @@
{
template <typename T1, typename T2>
- struct equal
- {
- };
+ struct equal : false_
+ {};
template <typename T>
- struct equal< T, T >
- {
- static void check() {}
- };
+ struct equal< T, T > : true_
+ {};
} // end of namespace mln::metal
Index: mln/metal/unptr.hh
--- mln/metal/unptr.hh (revision 0)
+++ mln/metal/unptr.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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_METAL_UNPTR_HH
+# define MLN_METAL_UNPTR_HH
+
+
+# define mlc_unptr(T) typename mln::metal::unptr< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unptr
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unptr< T* >
+ {
+ typedef mlc_unptr(T) ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNPTR_HH
Index: mln/metal/all.hh
--- mln/metal/all.hh (revision 0)
+++ mln/metal/all.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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_METAL_ALL_HH
+# define MLN_METAL_ALL_HH
+
+/*! \file mln/metal/all.hh
+ *
+ * \brief File that includes all meta-programming tools.
+ */
+
+namespace mln
+{
+
+ /// Namespace of meta-programming tools.
+ namespace metal {}
+
+} // end of namespace mln
+
+
+# include <mln/metal/bexpr.hh> // <- bool.hh
+# include <mln/metal/equal.hh>
+# include <mln/metal/if.hh>
+# include <mln/metal/is_a.hh>
+# include <mln/metal/math.hh>
+# include <mln/metal/none.hh>
+# include <mln/metal/unqualif.hh> // <- unconst.hh, unptr.hh, unref.hh
+# include <mln/metal/vec.hh>
+
+# include <mln/metal/same_coord.hh>
+# include <mln/metal/same_point.hh>
+
+
+#endif // ! MLN_METAL_ALL_HH
Index: mln/metal/is_a.hh
--- mln/metal/is_a.hh (revision 0)
+++ mln/metal/is_a.hh (revision 0)
@@ -0,0 +1,88 @@
+// 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_CORE_METAL_IS_A_HH
+# define MLN_CORE_METAL_IS_A_HH
+
+/*! \file mln/metal/is_a.hh
+ *
+ * \brief Definition of a type that means "is_a".
+ */
+
+
+# define mlc_is_a(T, U) mln::metal::is_a< T, U >
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace internal
+ {
+
+ typedef char yes_;
+ struct no_ { char dummy[2]; };
+
+ template <typename T>
+ struct make_
+ {
+ static T* ptr();
+ };
+
+ template <typename T, template <class> class U>
+ struct helper_is_a_
+ {
+
+ template<class V>
+ static yes_ selector(U<V>*);
+ static no_ selector(...);
+ };
+
+ } // end of namespace mln::metal::internal
+
+
+
+ /*! \brief "is_a" check.
+ *
+ * FIXME: Doc!
+ */
+ template <typename T, template <class> class U>
+ struct is_a : bool_<( sizeof( internal::helper_is_a_<T,U>::selector(internal::make_<T>::ptr()) )
+ =
+ sizeof( internal::yes_ ) )>::type
+ {};
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_METAL_IS_A_HH
Index: mln/metal/unref.hh
--- mln/metal/unref.hh (revision 0)
+++ mln/metal/unref.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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_METAL_UNREF_HH
+# define MLN_METAL_UNREF_HH
+
+
+# define mlc_unref(T) typename mln::metal::unref< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unref
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unref< T& >
+ {
+ typedef T ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNREF_HH
Index: mln/level/compute.hh
--- mln/level/compute.hh (revision 1052)
+++ mln/level/compute.hh (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_LEVEL_RUN_HH
-# define MLN_LEVEL_RUN_HH
+#ifndef MLN_LEVEL_COMPUTE_HH
+# define MLN_LEVEL_COMPUTE_HH
-/*! \file mln/level/run.hh
+/*! \file mln/level/compute.hh
*
- * \brief Run an accumulator onto image pixel values.
+ * \brief Compute an accumulator onto image pixel values.
*/
# include <mln/level/take.hh>
@@ -42,26 +42,26 @@
namespace level
{
- /*! Run an accumulator onto the pixel values of the image \p input.
+ /*! Compute an accumulator onto the pixel values of the image \p input.
*
* \param[in] input The input image.
* \param[in] a The accumulator.
* \return A resulting accumulator.
*
- * This routine runs: \n
+ * This routine computes: \n
* res = \p a \n
* res.init() \n
* level::take(res, \p input) \n
* return res \n
*/
template <typename I, typename A>
- A run(const Image<I>& input, const Accumulator<A>& a);
+ A compute(const Image<I>& input, const Accumulator<A>& a);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename A>
- A run(const Image<I>& input, const Accumulator<A>& a)
+ A compute(const Image<I>& input, const Accumulator<A>& a)
{
A res = exact(a);
res.init();
@@ -76,4 +76,4 @@
} // end of namespace mln
-#endif // ! MLN_LEVEL_RUN_HH
+#endif // ! MLN_LEVEL_COMPUTE_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some linear filters and augment related tools.
* mln/linear/convolve.hh: Add doc.
* mln/linear/log.hh (LoG_7x7, LoG_13x13, LoG_17x17): New.
* mln/linear/lap.hh: New.
* tests/linear_lap.cc: New.
* mln/convert/to_dpoint.hh: Add postcondition.
* mln/convert/to_w_window.hh: New.
* mln/core/w_window2d_float.hh: New.
* mln/make/w_window.hh: New.
* mln/make/w_window2d_int.hh: Remove; useless.
* mln/core/concept/doc/weighted_window.hh: Augment doc.
(weight, window): Rename as...
(w, win): ...these.
(weight, window): New associated types.
* mln/core/concept/weighted_window.hh: Update.
* mln/core/window.hh (window_): Rename as...
(window): ...this.
* mln/core/w_window.hh (w_window_): Rename as...
(w_window): ...this.
(insert): Swap args; add precondition.
Update.
* mln/convert/to_image.hh,
* mln/convert/to_window.hh,
* mln/geom/pmin_pmax.hh,
* mln/geom/bbox.hh: New overload.
* mln/core/window2d.hh,
* mln/core/w_window2d_int.hh,
* mln/linear/convolve.hh,
* mln/make/w_window2d.hh,
* tests/convolve.cc,
* tests/pixter_dpoint2d.cc,
* tests/w_window2d_int.cc: Update.
mln/convert/to_dpoint.hh | 8 +-
mln/convert/to_image.hh | 21 +++++
mln/convert/to_w_window.hh | 76 +++++++++++++++++++++
mln/convert/to_window.hh | 29 +++++++-
mln/core/concept/doc/weighted_window.hh | 16 ++++
mln/core/concept/weighted_window.hh | 17 +++-
mln/core/macros.hh | 10 ++
mln/core/w_window.hh | 114 +++++++++++++++++++++-----------
mln/core/w_window2d_float.hh | 56 +++++++++++++++
mln/core/w_window2d_int.hh | 4 -
mln/core/window.hh | 46 ++++++------
mln/core/window2d.hh | 2
mln/estim/min_max.hh | 2
mln/geom/bbox.hh | 17 ++++
mln/geom/pmin_pmax.hh | 17 ++++
mln/linear/convolve.hh | 27 ++++---
mln/linear/lap.hh | 113 +++++++++++++++++++++++++++++++
mln/linear/log.hh | 89 +++++++++++++++++++++++-
mln/make/w_window.hh | 86 ++++++++++++++++++++++++
mln/make/w_window2d.hh | 15 ++--
tests/convolve.cc | 5 -
tests/linear_lap.cc | 51 ++++++++++++++
tests/pixter_dpoint2d.cc | 2
tests/w_window2d_int.cc | 27 ++++---
24 files changed, 730 insertions(+), 120 deletions(-)
Index: tests/convolve.cc
--- tests/convolve.cc (revision 1051)
+++ tests/convolve.cc (working copy)
@@ -38,8 +38,7 @@
#include <mln/math/round.hh>
#include <mln/level/transform.hh>
-#include <mln/core/w_window.hh>
-#include <mln/make/w_window2d.hh>
+#include <mln/core/w_window2d_float.hh>
#include <mln/border/thickness.hh>
#include <mln/linear/convolve.hh>
@@ -60,7 +59,7 @@
.04, .04, .04, .04, .04,
.04, .04, .04, .04, .04,
.04, .04, .04, .04, .04 };
- w_window_<dpoint2d,float> w = make::w_window2d(ws);
+ w_window2d_float w = make::w_window2d(ws);
image2d_b<float> tmp(lena.domain());
linear::convolve(lena, w, tmp);
Index: tests/w_window2d_int.cc
--- tests/w_window2d_int.cc (revision 1051)
+++ tests/w_window2d_int.cc (working copy)
@@ -31,18 +31,21 @@
*/
#include <mln/core/w_window2d_int.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/convert/to_image.hh>
+#include <mln/convert/to_w_window.hh>
+#include <mln/debug/println.hh>
-template <typename W, typename P>
-void test(const W& w, const P& p)
+struct my_f : mln::Function_p2v< my_f >
{
- mln_qiter(W) q(w, p);
- for_all(q)
- std::cout << q << ':' << q.weight() << ' ';
- std::cout << std::endl;
+ typedef int result;
+ int operator()(const mln::point2d& p) const
+ {
+ return p.row() + p.col();
}
-
+};
int main()
@@ -52,8 +55,12 @@
int ws[] = { -1, 0, 1,
-2, 0, 2,
-1, 0, 1 };
- w_window2d_int ww = make::w_window2d_int(ws);
- std::cout << ww << std::endl;
+ w_window2d_int w_win = make::w_window2d(ws);
+
+ image2d_b<int> ima = convert::to_image(w_win);
+ w_window2d_int w_win_2 = convert::to_w_window(ima);
+ mln_assertion(w_win_2 = w_win);
- test(ww, make::point2d(0,0));
+ w_window2d_int tmp = make::w_window(win::rectangle2d(3, 5), my_f());
+ debug::println(convert::to_image(tmp));
}
Index: tests/pixter_dpoint2d.cc
--- tests/pixter_dpoint2d.cc (revision 1051)
+++ tests/pixter_dpoint2d.cc (working copy)
@@ -46,7 +46,7 @@
typedef image2d_b<int> I;
typedef I::dpoint D;
- typedef window_<D> W;
+ typedef window<D> W;
typedef dpoints_fwd_pixter<I> qixter;
Index: tests/linear_lap.cc
--- tests/linear_lap.cc (revision 0)
+++ tests/linear_lap.cc (revision 0)
@@ -0,0 +1,51 @@
+// 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/linear_lAP.cc
+ *
+ * \brief Tests on mln::linear::lap_4.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/load_pgm.hh>
+
+#include <mln/border/thickness.hh>
+#include <mln/linear/lap.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ border::thickness = 1;
+
+ image2d_b<int_u8> lena = io::load_pgm("../img/lena.pgm");
+ image2d_b<int> tmp(lena.domain());
+ linear::lap_4(lena, tmp);
+}
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 1051)
+++ mln/convert/to_image.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/concept/point_set.hh>
# include <mln/core/concept/window.hh>
+# include <mln/core/concept/weighted_window.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/convert/to_window.hh>
@@ -62,6 +63,10 @@
template <typename N>
image2d_b<bool> to_image(const Neighborhood<N>& nbh);
+ /// Convert a weighted window \p w_win into an image.
+ template <typename W>
+ image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win);
+
# ifndef MLN_INCLUDE_ONLY
@@ -99,6 +104,22 @@
return to_image(convert::to_window(nbh));
}
+ template <typename W>
+ image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win_)
+ {
+ const W& w_win = exact(w_win_);
+ mln_precondition(! w_win.is_empty());
+
+ typedef mln_point(W) P;
+ box2d b = geom::bbox(w_win);
+ image2d_b<mln_weight(W)> ima(b);
+ mln_qiter(W) q(w_win, P::zero);
+ for_all(q)
+ ima(q) = q.w();
+ return ima;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1051)
+++ mln/convert/to_window.hh (working copy)
@@ -30,9 +30,10 @@
/*! \file mln/convert/to_window.hh
*
- * \brief Convertions to mln::Window.
+ * \brief Conversions to mln::window.
*/
+# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
@@ -45,24 +46,44 @@
/// Convert a neighborhood \p nbh into a window.
template <typename N>
- window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
+ window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
+
+ /// Convert a binary image \p input into a window.
+ template <typename I>
+ window<mln_dpoint(I)> to_window(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
template <typename N>
- window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
+ window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
typedef mln_dpoint(N) D;
typedef mln_point(D) P;
- window_<D> win;
+ window<D> win;
mln_niter(N) n(nbh, P::zero);
for_all(n)
win.insert(n - P::zero);
return win;
}
+ template <typename I>
+ window<mln_dpoint(I)> to_window(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_precondition(input.has_data());
+ // FIXME: Check that input is binary!
+ typedef mln_dpoint(I) D;
+ typedef mln_point(D) P;
+ window<D> win;
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p))
+ win.insert(p - P::zero);
+ return win;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
Index: mln/convert/to_dpoint.hh
--- mln/convert/to_dpoint.hh (revision 1051)
+++ mln/convert/to_dpoint.hh (working copy)
@@ -53,10 +53,12 @@
mln_dpoint(P) to_dpoint(const Generalized_Point<P>& p_)
{
const P& p = internal::force_exact<P>(p_);
- mln_dpoint(P) tmp;
+ mln_dpoint(P) dp;
for (unsigned i = 0; i < P::dim; ++i)
- tmp[i] = p[i];
- return tmp;
+ dp[i] = p[i];
+ typedef mln_point(P) P_;
+ mln_postcondition(dp = p - P_::zero);
+ return dp;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/convert/to_w_window.hh
--- mln/convert/to_w_window.hh (revision 0)
+++ mln/convert/to_w_window.hh (revision 0)
@@ -0,0 +1,76 @@
+// 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_CONVERT_TO_W_WINDOW_HH
+# define MLN_CONVERT_TO_W_WINDOW_HH
+
+/*! \file mln/convert/to_w_window.hh
+ *
+ * \brief Conversions to mln::w_window.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/window.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert an image \p input into a weighted window.
+ template <typename I>
+ w_window<mln_dpoint(I), mln_value(I)> to_w_window(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ w_window<mln_dpoint(I), mln_value(I)> to_w_window(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_precondition(input.has_data());
+ // FIXME: Check that input is scalar?
+ typedef mln_dpoint(I) D;
+ typedef mln_point(D) P;
+ w_window<D, mln_value(I)> w_win;
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p) != 0)
+ w_win.insert(input(p), p - P::zero);
+ return w_win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_W_WINDOW_HH
Index: mln/estim/min_max.hh
--- mln/estim/min_max.hh (revision 1051)
+++ mln/estim/min_max.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/estim/min_max.hh
*
- * \brief Compute the min_max pixel value.
+ * \brief Compute the min and max pixel values of an image.
*/
# include <mln/accu/min_max.hh>
Index: mln/geom/pmin_pmax.hh
--- mln/geom/pmin_pmax.hh (revision 1051)
+++ mln/geom/pmin_pmax.hh (working copy)
@@ -51,6 +51,13 @@
pmin_pmax(const Point_Iterator<I>& p);
+ /// Compute the minimum and maximum points, \p pmin and \p max,
+ /// when browsing with iterator \p p.
+ template <typename I>
+ void
+ pmin_pmax(const Point_Iterator<I>& p, mln_point(I)& pmin, mln_point(I)& pmax);
+
+
# ifndef MLN_INCLUDE_ONLY
@@ -80,6 +87,16 @@
return tmp;
}
+ template <typename I>
+ void
+ pmin_pmax(const Point_Iterator<I>& p, mln_point(I)& pmin, mln_point(I)& pmax)
+ {
+ typedef mln_point(I) P;
+ std::pair<P, P> tmp = pmin_pmax(p);
+ pmin = tmp.first;
+ pmax = tmp.second;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::geom
Index: mln/geom/bbox.hh
--- mln/geom/bbox.hh (revision 1051)
+++ mln/geom/bbox.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/point_set.hh>
# include <mln/core/concept/window.hh>
+# include <mln/core/concept/weighted_window.hh>
# include <mln/geom/pmin_pmax.hh>
@@ -47,12 +48,18 @@
{
- /// Compute the precise bounding box of a window \p win centered
- /// at the origin.
+ /// Compute the precise bounding box of a window \p win when
+ /// centered at the origin.
template <typename W>
box_<mln_point(W)> bbox(const Window<W>& win);
+ /// Compute the precise bounding box of a weighted window \p w_win
+ /// when centered at the origin.
+ template <typename W>
+ box_<mln_point(W)> bbox(const Weighted_Window<W>& w_win);
+
+
/// Compute the precise bounding box of a point set \p pset.
template <typename S>
box_<mln_point(S)> bbox(const Point_Set<S>& pset);
@@ -80,6 +87,12 @@
return tmp;
}
+ template <typename W>
+ box_<mln_point(W)> bbox(const Weighted_Window<W>& w_win)
+ {
+ return bbox(exact(w_win).win());
+ }
+
template <typename S>
box_<mln_point(S)> bbox(const Point_Set<S>& pset_)
{
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1051)
+++ mln/core/macros.hh (working copy)
@@ -161,6 +161,16 @@
# define mln_viter(T) typename T::fwd_viter
+// w
+
+/// Shortcut to access the weight type associated to T.
+# define mln_weight(T) typename T::weight
+
+/// Shortcut to access the window type associated to T.
+# define mln_window(T) typename T::window
+
+
+
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 1051)
+++ mln/core/w_window.hh (working copy)
@@ -30,13 +30,13 @@
/*! \file mln/core/w_window.hh
*
- * \brief Definition of the generic weighted window class mln::w_window_.
+ * \brief Definition of the generic weighted window class mln::w_window.
*/
# include <map>
-# include <mln/core/concept/weighted_window.hh>
# include <mln/core/window.hh>
+# include <mln/core/concept/weighted_window.hh>
namespace mln
@@ -54,7 +54,7 @@
* the type of weights.
*/
template <typename D, typename W>
- struct w_window_ : public Weighted_Window< w_window_<D,W> >
+ struct w_window : public Weighted_Window< w_window<D,W> >
{
/// Point associated type.
typedef mln_point(D) point;
@@ -62,6 +62,12 @@
/// Dpoint associated type.
typedef D dpoint;
+ /// Weight associated type.
+ typedef W weight;
+
+ /// Window associated type.
+ typedef mln::window<D> window;
+
/// Point_Iterator type to browse (forward) the points of a generic w_window.
typedef with_w_< dpoints_fwd_piter<D>, W > fwd_qiter;
@@ -71,15 +77,15 @@
/// Constructor without argument.
- w_window_();
+ w_window();
- /// Insert a delta-point \p d and its associated weight \p w.
- w_window_<D,W>& insert(const D& d, const W& w);
+ /// Insert a couple of weight \p w and delta-point \p d.
+ w_window<D,W>& insert(const W& w, const D& d);
/// Give the \p i-th weight.
- W weight(unsigned i) const;
+ W w(unsigned i) const;
/// Give access to the vector of weights.
const std::vector<W>& weights() const;
@@ -95,22 +101,31 @@
const std::vector<D>& vect() const;
/// Give the corresponding window.
- const window_<D>& window() const;
+ const mln::window<D>& win() const;
/// Give the symmetrical w_window.
- w_window_<D,W> sym_() const;
+ w_window<D,W> sym_() const;
protected:
- window_<D> win_;
+ mln::window<D> win_;
std::vector<W> wei_;
};
- /// Print a weighted window \p wwin into an output stream \p ostr.
+ /* \brief Print a weighted window \p w_win into an output stream \p ostr.
+ * \relates mln::w_window
+ */
template <typename D, typename W>
- std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin);
+ std::ostream& operator<<(std::ostream& ostr, const w_window<D,W>& w_win);
+
+
+ /* \brief Equality test between two weighted windows \p lhs and \p rhs.
+ * \relates mln::w_window
+ */
+ template <typename D, typename Wl, typename Wr>
+ bool operator=(const w_window<D,Wl>& lhs, const w_window<D,Wr>& rhs);
@@ -122,7 +137,7 @@
template <typename Ds, typename P>
with_w_(const Ds& ds, const P& p);
- W weight() const;
+ W w() const;
protected:
const std::vector<W> wei_;
@@ -146,39 +161,30 @@
template <typename It, typename W>
W
- with_w_<It,W>::weight() const
+ with_w_<It,W>::w() const
{
mln_precondition(this->i_ < wei_.size());
return wei_[this->i_];
}
- // w_window_<D,W>
-
- template <typename D, typename W>
- std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin)
- {
- ostr << '[';
- for (unsigned i = 0; i < wwin.window().ndpoints(); ++i)
- ostr << wwin.vect()[i] << ':' << wwin.weight(i) << ' ';
- return ostr << ']';
- }
+ // w_window<D,W>
template <typename D, typename W>
- w_window_<D,W>::w_window_()
+ w_window<D,W>::w_window()
{
}
template <typename D, typename W>
- const window_<D>&
- w_window_<D,W>::window() const
+ const mln::window<D>&
+ w_window<D,W>::win() const
{
return win_;
}
template <typename D, typename W>
const D&
- w_window_<D,W>::dp(unsigned i) const
+ w_window<D,W>::dp(unsigned i) const
{
mln_precondition(i < win_.ndpoints());
mln_invariant(wei_.size() = win_.ndpoints());
@@ -187,7 +193,7 @@
template <typename D, typename W>
unsigned
- w_window_<D,W>::ndpoints() const
+ w_window<D,W>::ndpoints() const
{
mln_invariant(wei_.size() = win_.ndpoints());
return win_.ndpoints();
@@ -195,21 +201,21 @@
template <typename D, typename W>
const std::vector<D>&
- w_window_<D,W>::vect() const
+ w_window<D,W>::vect() const
{
return win_.vect();
}
template <typename D, typename W>
const std::vector<W>&
- w_window_<D,W>::weights() const
+ w_window<D,W>::weights() const
{
return wei_;
}
template <typename D, typename W>
W
- w_window_<D,W>::weight(unsigned i) const
+ w_window<D,W>::w(unsigned i) const
{
mln_precondition(i < wei_.size());
mln_invariant(wei_.size() = win_.ndpoints());
@@ -217,12 +223,13 @@
}
template <typename D, typename W>
- w_window_<D,W>&
- w_window_<D,W>::insert(const D& d, const W& w)
+ w_window<D,W>&
+ w_window<D,W>::insert(const W& w, const D& d)
{
mln_invariant(wei_.size() = win_.ndpoints());
+ mln_precondition(! win_.has(d));
- if (win_.has(d))
+ if (w = W(0)) // FIXME: Implicit restriction "W scalar"...
// no-op
return *this;
@@ -244,19 +251,48 @@
return *this;
}
-
template <typename D, typename W>
- w_window_<D,W>
- w_window_<D,W>::sym_() const
+ w_window<D,W>
+ w_window<D,W>::sym_() const
{
- w_window_<D,W> tmp(*this);
+ w_window<D,W> tmp(*this);
tmp.win_ = - this->win_;
return *this;
}
+ // operators
+
+ template <typename D, typename W>
+ std::ostream& operator<<(std::ostream& ostr, const w_window<D,W>& w_win)
+ {
+ ostr << '[';
+ for (unsigned i = 0; i < w_win.win().ndpoints(); ++i)
+ ostr << w_win.vect()[i] << ':' << w_win.w(i) << ' ';
+ return ostr << ']';
+ }
+
+ template <typename D, typename Wl, typename Wr>
+ bool operator=(const w_window<D,Wl>& lhs, const w_window<D,Wr>& rhs)
+ {
+ if (lhs.ndpoints() != rhs.ndpoints())
+ return false;
+ if (lhs.win() != rhs.win())
+ return false;
+ const std::vector<Wl>& wl = lhs.weights();
+ const std::vector<Wr>& wr = rhs.weights();
+ mln_assertion(wl.size() = wr.size());
+ for (unsigned i = 0; i < wl.size(); ++i)
+ if (wr[i] != wl[i])
+ return false;
+ return true;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
+# include <mln/make/w_window.hh>
+
+
#endif // ! MLN_CORE_W_WINDOW_HH
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1051)
+++ mln/core/window.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/core/window.hh
*
- * \brief Definition of the generic window class mln::window_.
+ * \brief Definition of the generic window class mln::window.
*/
# include <mln/core/concept/window.hh>
@@ -56,10 +56,10 @@
* parameter is \c D, type of delta-point.
*/
template <typename D>
- class window_ : public Window< window_<D> >,
- public internal::dpoints_base_<D, window_<D> >
+ class window : public Window< window<D> >,
+ public internal::dpoints_base_<D, window<D> >
{
- typedef internal::dpoints_base_<D, window_<D> > super_;
+ typedef internal::dpoints_base_<D, window<D> > super_;
public:
/*! \brief Point_Iterator type to browse the points of a generic window
@@ -77,7 +77,7 @@
*
* The constructed window is empty.
*/
- window_();
+ window();
/*! \brief Test if the window is symmetric.
@@ -85,10 +85,10 @@
bool is_symmetric() const;
/// Insert a delta-point \p dp.
- window_<D>& insert(const D& dp);
+ window<D>& insert(const D& dp);
/// Give the symmetrical window.
- window_<D> sym_() const;
+ window<D> sym_() const;
protected:
@@ -100,40 +100,40 @@
/// Shift a window \p win with a delta-point \p dp.
template <typename W>
- window_<mln_dpoint(W)> operator+(const Window<W>& win,
+ window<mln_dpoint(W)> operator+(const Window<W>& win,
const mln_dpoint(W)& dp);
/// Shift a window \p win with the delta-point (-\p dp).
template <typename W>
- window_<mln_dpoint(W)> operator-(const Window<W>& win,
+ window<mln_dpoint(W)> operator-(const Window<W>& win,
const mln_dpoint(W)& dp);
/// Substract \p rhs from \p lhs.
// FIXME: Give details!
template <typename Wl, typename Wr>
- window_<mln_dpoint(Wl)> operator-(const Window<Wl>& lhs,
+ window<mln_dpoint(Wl)> operator-(const Window<Wl>& lhs,
const Window<Wr>& rhs);
# ifndef MLN_INCLUDE_ONLY
- // window_<D>
+ // window<D>
template <typename D>
- window_<D>::window_()
+ window<D>::window()
{
}
template <typename D>
- bool window_<D>::is_symmetric() const
+ bool window<D>::is_symmetric() const
{
return this->sym_() = *this;
}
template <typename D>
- window_<D>&
- window_<D>::insert(const D& dp)
+ window<D>&
+ window<D>::insert(const D& dp)
{
mln_precondition(! has(dp));
this->super_::insert(dp);
@@ -141,10 +141,10 @@
}
template <typename D>
- window_<D>
- window_<D>::sym_() const
+ window<D>
+ window<D>::sym_() const
{
- window_<D> tmp;
+ window<D> tmp;
const unsigned n = this->ndpoints();
for (unsigned i = 0; i < n; ++i)
tmp.insert(- this->dp(i));
@@ -155,11 +155,11 @@
// operators
template <typename W>
- window_<mln_dpoint(W)> operator+(const Window<W>& win,
+ window<mln_dpoint(W)> operator+(const Window<W>& win,
const mln_dpoint(W)& dp)
{
typedef mln_point(W) P;
- window_<mln_dpoint(W)> tmp;
+ window<mln_dpoint(W)> tmp;
mln_qiter(W) q(win, P::zero);
for_all(q)
tmp.insert(convert::to_dpoint(q) + dp);
@@ -167,18 +167,18 @@
}
template <typename W>
- window_<mln_dpoint(W)> operator-(const Window<W>& win,
+ window<mln_dpoint(W)> operator-(const Window<W>& win,
const mln_dpoint(W)& dp)
{
return win + (-dp);
}
template <typename W, typename Wr>
- window_<mln_dpoint(W)> operator-(const Window<W>& lhs,
+ window<mln_dpoint(W)> operator-(const Window<W>& lhs,
const Window<Wr>& rhs)
{
typedef mln_point(W) P;
- window_<mln_dpoint(W)> tmp;
+ window<mln_dpoint(W)> tmp;
mln_qiter(W) q(lhs, P::zero);
for_all(q)
{
Index: mln/core/window2d.hh
--- mln/core/window2d.hh (revision 1051)
+++ mln/core/window2d.hh (working copy)
@@ -44,7 +44,7 @@
/*! \brief Type alias for a window with arbitrary shape, defined on
* the 2D square grid with integer coordinates.
*/
- typedef window_<dpoint2d> window2d;
+ typedef window<dpoint2d> window2d;
} // end of namespace mln
Index: mln/core/concept/weighted_window.hh
--- mln/core/concept/weighted_window.hh (revision 1051)
+++ mln/core/concept/weighted_window.hh (working copy)
@@ -55,6 +55,8 @@
typedef point;
typedef dpoint;
+ typedef weight;
+ typedef window;
E sym_() const;
*/
@@ -62,13 +64,13 @@
/// Test if the weighted window is empty; final method.
bool is_empty() const
{
- return exact(this)->window().is_empty();
+ return exact(this)->win().is_empty();
}
/// Test if the weighted window is centered; final method.
bool is_centered() const
{
- return exact(this)->window().is_centered();
+ return exact(this)->win().is_centered();
}
// FIXME: Remove because too ambiguous: bool is_symmetric() const
@@ -76,7 +78,7 @@
/// Give the maximum coordinate gap.
unsigned delta() const
{
- return exact(this)->window().delta();
+ return exact(this)->win().delta();
}
protected:
@@ -99,12 +101,17 @@
{
typedef mln_point(E) point;
typedef mln_dpoint(E) dpoint;
+ typedef mln_weight(E) weight;
+ typedef mln_window(E) window;
typedef mln_fwd_qiter(E) fwd_qiter;
typedef mln_bkd_qiter(E) bkd_qiter;
- E (E::*m_)() const = & E::sym_;
- m_ = 0;
+ E (E::*m1)() const = & E::sym_;
+ m1 = 0;
+
+ const window& (E::*m2)() const = & E::win;
+ m2 = 0;
}
template <typename W>
Index: mln/core/concept/doc/weighted_window.hh
--- mln/core/concept/doc/weighted_window.hh (revision 1051)
+++ mln/core/concept/doc/weighted_window.hh (working copy)
@@ -56,6 +56,18 @@
*/
typedef void bkd_qiter;
+ /// Point associated type.
+ typedef void point;
+
+ /// Dpoint associated type.
+ typedef void dpoint;
+
+ /// Weight associated type.
+ typedef void weight;
+
+ /// Window associated type.
+ typedef void window;
+
/*! \brief Test if the weighted window is empty.
*
* A weighted_window of null size is empty.
@@ -73,6 +85,10 @@
*/
unsigned delta() const;
+ /*! \brief Give the corresponding window.
+ */
+ const window& win() const;
+
/*! \brief Give the symmetrical weighted_window.
*/
E sym_() const;
Index: mln/core/w_window2d_int.hh
--- mln/core/w_window2d_int.hh (revision 1051)
+++ mln/core/w_window2d_int.hh (working copy)
@@ -44,13 +44,13 @@
* on the 2D square grid (with integer coordinates) and whose
* weights are integers.
*/
- typedef w_window_<dpoint2d, int> w_window2d_int;
+ typedef w_window<dpoint2d, int> w_window2d_int;
} // end of namespace mln
-# include <mln/make/w_window2d_int.hh>
+# include <mln/make/w_window2d.hh>
#endif // ! MLN_CORE_W_WINDOW2D_INT_HH
Index: mln/core/w_window2d_float.hh
--- mln/core/w_window2d_float.hh (revision 0)
+++ mln/core/w_window2d_float.hh (revision 0)
@@ -0,0 +1,56 @@
+// 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_CORE_W_WINDOW2D_FLOAT_HH
+# define MLN_CORE_W_WINDOW2D_FLOAT_HH
+
+/*! \file mln/core/w_window2d_float.hh
+ *
+ * \brief Definition of the mln::w_window2d_float alias.
+ */
+
+# include <mln/core/w_window.hh>
+# include <mln/core/dpoint2d.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Type alias for a w_window with arbitrary shape, defined
+ * on the 2D square grid (with integer coordinates) and whose
+ * weights are floating values.
+ */
+ typedef w_window<dpoint2d, float> w_window2d_float;
+
+
+} // end of namespace mln
+
+
+# include <mln/make/w_window2d.hh>
+
+
+#endif // ! MLN_CORE_W_WINDOW2D_FLOAT_HH
Index: mln/linear/log.hh
--- mln/linear/log.hh (revision 1051)
+++ mln/linear/log.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/linear/convolve.hh>
-# include <mln/make/w_window2d_int.hh>
+# include <mln/make/w_window2d.hh>
@@ -47,21 +47,96 @@
template <typename I, typename O>
void LoG_5x5(const Image<I>& input, Image<O>& output);
+ template <typename I, typename O>
+ void LoG_7x7(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void LoG_13x13(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void LoG_17x17(const Image<I>& input, Image<O>& output);
+
# ifndef MLN_INCLUDE_ONLY
// LoG_5x5 (Cf. Sonka et al., pages 85-86)
+ // This is also a "mexican hat".
template <typename I, typename O>
void LoG_5x5(const Image<I>& input, Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- int ws[] = { 0, 0, -1, 0, 0,
- 0, -1, -2, -1, 0,
+ int ws[] = { +0, 0, -1, 0, 0,
+ +0, -1, -2, -1, 0,
-1, -2, 16, -2, -1,
- 0, -1, -2, -1, 0,
- 0, 0, -1, 0, 0 };
- convolve(input, make::w_window2d_int(ws), output);
+ +0, -1, -2, -1, 0,
+ +0, 0, -1, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ // LoG 7x7 (Cf. Russ, p. 250)
+
+ template <typename I, typename O>
+ void LoG_7x7(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +0, 0, -1, -1, -1, 0, 0,
+ +0, -1, -3, -3, -3, -1, 0,
+ -1, -3, 0, 7, 0, -3, -1,
+ -1, -3, 7, 24, 7, -3, -1,
+ -1, -3, 0, 7, 0, -3, -1,
+ +0, -1, -3, -3, -3, -1, 0,
+ +0, 0, -1, -1, -1, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ // LoG 13x13 (Cf. Russ, p. 250)
+
+ template <typename I, typename O>
+ void LoG_13x13(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0,
+ +0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+ +0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
+ +0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
+ +0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
+ -1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
+ -1, -2, -4, -2, 6, 19, 24, 19, 6, -2, -4, -2, -1,
+ -1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
+ +0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
+ +0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
+ +0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
+ +0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+ +0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+
+ // LoG 17x17 (Cf. Sonka et al., pages 85-86)
+
+ template <typename I, typename O>
+ void LoG_17x17(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0,
+ +0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
+ +0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
+ +0, 0,-1,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1,-1, 0, 0,
+ +0,-1,-1,-2,-3,-3,-3,-2,-3,-2,-3,-3,-3,-2,-1,-1, 0,
+ +0,-1,-2,-3,-3,-3, 0, 2, 4, 2, 0,-3,-3,-3,-2,-1, 0,
+ -1,-1,-3,-3,-3, 0, 4,10,12,10, 4, 0,-3,-3,-3,-1,-1,
+ -1,-1,-3,-3,-2, 2,10,18,21,18,10, 2,-2,-3,-3,-1,-1,
+ -1,-1,-3,-3,-3, 4,12,21,24,21,12, 4,-3,-3,-3,-1,-1,
+ -1,-1,-3,-3,-2, 2,10,18,21,18,10, 2,-2,-3,-3,-1,-1,
+ -1,-1,-3,-3,-3, 0, 4,10,12,10, 4, 0,-3,-3,-3,-1,-1,
+ +0,-1,-2,-3,-3,-3, 0, 2, 4, 2, 0,-3,-3,-3,-2,-1, 0,
+ +0,-1,-1,-2,-3,-3,-3,-2,-3,-2,-3,-3,-3,-2,-1,-1, 0,
+ +0, 0,-1,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1,-1, 0, 0,
+ +0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
+ +0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
+ +0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -71,4 +146,4 @@
} // end of namespace mln
-#endif // ! MLN_LINEAR_CONVOLVE_HH
+#endif // ! MLN_LINEAR_LOG_HH
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 1051)
+++ mln/linear/convolve.hh (working copy)
@@ -48,10 +48,13 @@
/*! Convolution of image \p input by the weighted window \p win.
*
+ * \warning Computation of \p output(p) is performed with the
+ * value type of \p output.
+ *
* \pre output.domain = input.domain
*/
template <typename I, typename W, typename O>
- void convolve(const Image<I>& input, const Weighted_Window<W>& win,
+ void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
Image<O>& output);
@@ -61,47 +64,47 @@
{
template <typename I, typename W, typename O>
- void convolve(const Image<I>& input_, const Weighted_Window<W>& win_,
+ void convolve(const Image<I>& input_, const Weighted_Window<W>& w_win_,
Image<O>& output_)
{
const I& input = exact(input_);
- const W& win = exact(win_);
+ const W& w_win = exact(w_win_);
O& output = exact(output_);
mln_piter(I) p(input.domain());
- mln_qiter(W) q(win, p);
+ mln_qiter(W) q(w_win, p);
for_all(p)
{
mln_value(O) v = 0;
for_all(q) if (input.has(q))
- v += input(q) * q.weight();
+ v += input(q) * q.w();
output(p) = v;
}
}
template <typename I, typename W, typename O>
- void convolve(const Fast_Image<I>& input_, const Weighted_Window<W>& win_,
+ void convolve(const Fast_Image<I>& input_, const Weighted_Window<W>& w_win_,
Fast_Image<O>& output_)
{
const I& input = exact(input_);
- const W& win = exact(win_);
+ const W& w_win = exact(w_win_);
O& output = exact(output_);
- border::resize(input, win.delta());
+ border::resize(input, w_win.delta());
border::duplicate(input);
mln_pixter(O) p_out(output);
mln_pixter(const I) p(input);
- mln_qixter(const I, W) q(input, win, p);
+ mln_qixter(const I, W) q(input, w_win, p);
for_all_2(p, p_out)
{
mln_value(O) v = 0;
unsigned i = 0;
for_all(q)
- v += win.weight(i++) * *q;
+ v += w_win.w(i++) * *q;
*p_out = v;
}
}
@@ -109,11 +112,11 @@
} // end of namespace mln::linear::impl
template <typename I, typename W, typename O>
- void convolve(const Image<I>& input, const Weighted_Window<W>& win,
+ void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- impl::convolve(exact(input), exact(win), exact(output));
+ impl::convolve(exact(input), - exact(w_win), exact(output));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/linear/lap.hh
--- mln/linear/lap.hh (revision 0)
+++ mln/linear/lap.hh (revision 0)
@@ -0,0 +1,113 @@
+// 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_LINEAR_LAP_HH
+# define MLN_LINEAR_LAP_HH
+
+/*! \file mln/linear/lap.hh
+ *
+ * \brief Laplacian.
+ */
+
+# include <mln/linear/convolve.hh>
+# include <mln/make/w_window2d.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ // FIXME: Doc!
+
+ template <typename I, typename O>
+ void lap_4(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void lap_8(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void lap_x(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void lap_o(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // Laplacian operators (Cf. Sonka et al., p. 81)
+
+ template <typename I, typename O>
+ void lap_4(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { 0, 1, 0,
+ 1, -4, 1,
+ 0, 1, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ template <typename I, typename O>
+ void lap_8(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { 1, 1, 1,
+ 1, -8, 1,
+ 1, 1, 1 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ template <typename I, typename O>
+ void lap_x(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +2, -1, +2,
+ -1, -4, -1,
+ +2, -1, +2 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ template <typename I, typename O>
+ void lap_o(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { -1, +2, -1,
+ +2, -4, +2,
+ -1, +2, -1 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_LAP_HH
Index: mln/make/w_window2d.hh
--- mln/make/w_window2d.hh (revision 1051)
+++ mln/make/w_window2d.hh (working copy)
@@ -30,12 +30,13 @@
/*! \file mln/make/w_window2d.hh
*
- * \brief Routine to create an mln::w_window_ in the 2D case.
+ * \brief Routine to create an mln::w_window in the 2D case.
*/
# include <cmath>
+
# include <mln/core/w_window.hh>
-# include <mln/make/dpoint2d.hh>
+# include <mln/core/dpoint2d.hh>
namespace mln
@@ -44,7 +45,7 @@
namespace make
{
- /*! \brief Create a mln::w_window_ in the 2D case.
+ /*! \brief Create a 2D mln::w_window from an array of weights.
*
* \param[in] weights Array.
*
@@ -53,24 +54,24 @@
* \return A 2D weighted window.
*/
template <typename W, unsigned M>
- mln::w_window_<mln::dpoint2d, W> w_window2d(W (&weights)[M]);
+ mln::w_window<mln::dpoint2d, W> w_window2d(W (&weights)[M]);
# ifndef MLN_INCLUDE_ONLY
template <typename W, unsigned M>
- mln::w_window_<mln::dpoint2d, W>
+ mln::w_window<mln::dpoint2d, W>
w_window2d(W (&weights)[M])
{
int h = unsigned(std::sqrt(float(M))) / 2;
mln_precondition((2 * h + 1) * (2 * h + 1) = M);
- mln::w_window_<mln::dpoint2d, W> tmp;
+ mln::w_window<mln::dpoint2d, W> tmp;
unsigned i = 0;
for (int row = - h; row <= h; ++row)
for (int col = - h; col <= h; ++col)
{
if (weights[i] != 0)
- tmp.insert(make::dpoint2d(row, col), weights[i]);
+ tmp.insert(weights[i], make::dpoint2d(row, col));
i++;
}
return tmp;
Index: mln/make/w_window.hh
--- mln/make/w_window.hh (revision 0)
+++ mln/make/w_window.hh (revision 0)
@@ -0,0 +1,86 @@
+// 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_MAKE_W_WINDOW_HH
+# define MLN_MAKE_W_WINDOW_HH
+
+/*! \file mln/make/w_window.hh
+ *
+ * \brief Routine to create a mln::w_window.
+ */
+
+# include <mln/core/concept/window.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/core/w_window.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create a mln::w_window from a window and a weight
+ * function.
+ *
+ * \param[in] weights Array.
+ *
+ * \pre The array size, \c M, has to be a square of an odd integer.
+ *
+ * \return A weighted window.
+ */
+ template <typename W, typename F>
+ mln::w_window<mln_dpoint(W), mln_result(F)> w_window(const Window<W>& win,
+ const Function_p2v<F>& wei);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename W, typename F>
+ mln::w_window<mln_dpoint(W), mln_result(F)> w_window(const Window<W>& win_,
+ const Function_p2v<F>& wei_)
+ {
+ const W& win = exact(win_);
+ const F& wei = exact(wei_);
+ mln_precondition(! win.is_empty());
+ typedef mln_dpoint(W) D;
+ typedef mln_point(D) P;
+ mln::w_window<D, mln_result(F)> w_win;
+ mln_qiter(W) q(win, P::zero);
+ for_all(q)
+ w_win.insert(wei(q), q - P::zero);
+ return w_win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_W_WINDOW_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update accus and add LoG filter.
* mln/core/concept/accumulator.hh (merge): New.
* mln/core/concept/doc/accumulator.hh
(take): New; overload.
* mln/accu/bbox.hh,
* mln/accu/count.hh,
* mln/accu/histo.hh,
* mln/accu/max.hh,
* mln/accu/mean.hh,
* mln/accu/min.hh,
* mln/accu/sum.hh (operator+=): Rename as...
(take): ...this.
(conversion): Remove operator; too risky.
Update.
* mln/estim/mean.hh: Update.
* mln/level/fast_median.hh: Update.
* mln/level/median.hh: Update.
* mln/level/naive/median.hh: Update.
* mln/morpho/erosion.hh: Update.
* mln/border/duplicate.hh,
* mln/border/fill.hh,
* mln/border/mirror.hh,
* mln/border/resize.hh: Add fixme.
* mln/io/load_pgm,
* mln/io/save_pgm: Fix for g++-2.95.
* mln/linear/convolve.hh: Use border.
* tests/convolve.cc: Update.
* mln/accu/min_max.hh: New.
* mln/estim/min_max.hh: New.
* mln/fun/v2v/linear.hh: New.
* mln/level/stretch.hh: New.
* mln/linear/log.hh: New.
* mln/value/props.hh (epsilon): New.
* tests/linear_log.cc: New.
mln/accu/bbox.hh | 33 ++++++--
mln/accu/count.hh | 28 ++----
mln/accu/histo.hh | 10 ++
mln/accu/max.hh | 16 ++-
mln/accu/mean.hh | 34 +++-----
mln/accu/median.hh | 29 +++++--
mln/accu/min.hh | 21 ++---
mln/accu/min_max.hh | 147 ++++++++++++++++++++++++++++++++++++
mln/accu/sum.hh | 30 ++-----
mln/border/duplicate.hh | 5 -
mln/border/fill.hh | 5 -
mln/border/mirror.hh | 5 -
mln/border/resize.hh | 7 +
mln/core/concept/accumulator.hh | 25 ++++++
mln/core/concept/doc/accumulator.hh | 3
mln/estim/mean.hh | 3
mln/estim/min_max.hh | 78 +++++++++++++++++++
mln/fun/v2v/linear.hh | 93 ++++++++++++++++++++++
mln/io/load_pgm.hh | 26 +++++-
mln/io/save_pgm.hh | 29 +++++--
mln/level/fast_median.hh | 6 -
mln/level/median.hh | 12 +-
mln/level/naive/median.hh | 2
mln/level/stretch.hh | 100 ++++++++++++++++++++++++
mln/level/to_enc.hh | 4
mln/linear/convolve.hh | 5 +
mln/linear/log.hh | 74 ++++++++++++++++++
mln/morpho/erosion.hh | 2
mln/value/props.hh | 10 +-
mln/value/stack.hh | 2
tests/convolve.cc | 3
tests/linear_log.cc | 71 +++++++++++++++++
32 files changed, 794 insertions(+), 124 deletions(-)
Index: tests/convolve.cc
--- tests/convolve.cc (revision 1050)
+++ tests/convolve.cc (working copy)
@@ -40,6 +40,7 @@
#include <mln/core/w_window.hh>
#include <mln/make/w_window2d.hh>
+#include <mln/border/thickness.hh>
#include <mln/linear/convolve.hh>
@@ -48,6 +49,8 @@
using namespace mln;
using value::int_u8;
+ border::thickness = 2;
+
image2d_b<int_u8>
lena = io::load_pgm("../img/lena.pgm"),
out(lena.domain());
Index: tests/linear_log.cc
--- tests/linear_log.cc (revision 0)
+++ tests/linear_log.cc (revision 0)
@@ -0,0 +1,71 @@
+// 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/linear_log.cc
+ *
+ * \brief Tests on mln::linear::log.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/border/thickness.hh>
+#include <mln/linear/log.hh>
+
+#include <mln/estim/min_max.hh>
+#include <mln/level/stretch.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ border::thickness = 2;
+
+ image2d_b<int_u8> lena = io::load_pgm("../img/lena.pgm");
+
+ image2d_b<int> tmp(lena.domain());
+ linear::LoG_5x5(lena, tmp);
+ {
+ int min, max;
+ estim::min_max(tmp, min, max);
+ mln_assertion(min = -929 && max = 1458);
+ }
+
+ image2d_b<int_u8> out(lena.domain());
+ level::stretch(tmp, out);
+ io::save_pgm(out, "out.pgm");
+ {
+ int_u8 min, max;
+ estim::min_max(out, min, max);
+ mln_assertion(min = 0 && max = 255);
+ }
+}
Index: mln/estim/min_max.hh
--- mln/estim/min_max.hh (revision 0)
+++ mln/estim/min_max.hh (revision 0)
@@ -0,0 +1,78 @@
+// 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_ESTIM_MIN_MAX_HH
+# define MLN_ESTIM_MIN_MAX_HH
+
+/*! \file mln/estim/min_max.hh
+ *
+ * \brief Compute the min_max pixel value.
+ */
+
+# include <mln/accu/min_max.hh>
+# include <mln/level/take.hh>
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+ /*! \brief Compute the min and max values of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] min The minimum pixel value of \p input.
+ * \param[out] max The maximum pixel value of \p input.
+ */
+ template <typename I>
+ void min_max(const Image<I>& input,
+ mln_value(I)& min, mln_value(I)& max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ void min_max(const Image<I>& input,
+ mln_value(I)& min, mln_value(I)& max)
+ {
+ mln_precondition(exact(input).has_data());
+ accu::min_max<mln_value(I)> a;
+ a.init();
+ level::take(a, input);
+ min = a.min();
+ max = a.max();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_MIN_MAX_HH
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1050)
+++ mln/estim/mean.hh (working copy)
@@ -56,9 +56,10 @@
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input)
{
+ mln_precondition(exact(input).has_data());
typedef mln_value(I) V;
typedef mln_sum(V) S;
- return level::run(input, accu::mean<V, S>());
+ return level::run(input, accu::mean<V, S>()).to_value();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/accumulator.hh
--- mln/core/concept/doc/accumulator.hh (revision 1050)
+++ mln/core/concept/doc/accumulator.hh (working copy)
@@ -49,6 +49,9 @@
/// Take into account a value \p v (an element).
void take(const value& v);
+
+ /// Take into account another accumulator \p other.
+ void take(const E& other);
};
} // end of namespace mln::doc
Index: mln/core/concept/accumulator.hh
--- mln/core/concept/accumulator.hh (revision 1050)
+++ mln/core/concept/accumulator.hh (working copy)
@@ -54,12 +54,27 @@
typedef value;
void init();
void take(const value& v);
+ void take(const E& other);
*/
protected:
Accumulator();
};
+ /*! \brief Merge two accumulators.
+ *
+ * The parameter \a E is the accumulator exact type.
+ *
+ * \param[in] lhs An accumulator.
+ * \param[in] rhs Another accumulator.
+ * \result A temporary accumulator.
+ *
+ * \see relates mln::Accumulator
+ */
+ template <typename E>
+ E merge(const Accumulator<E>& lhs, const Accumulator<E>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
@@ -70,6 +85,16 @@
m1 = 0;
void (E::*m2)(const value&) = & E::take;
m2 = 0;
+ void (E::*m3)(const E&) = & E::take;
+ m3 = 0;
+ }
+
+ template <typename E>
+ E merge(const Accumulator<E>& lhs, const Accumulator<E>& rhs)
+ {
+ E tmp(exact(lhs));
+ tmp.take(exact(rhs));
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/fun/v2v/linear.hh
--- mln/fun/v2v/linear.hh (revision 0)
+++ mln/fun/v2v/linear.hh (revision 0)
@@ -0,0 +1,93 @@
+// 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_FUN_V2V_LINEAR_HH
+# define MLN_FUN_V2V_LINEAR_HH
+
+/*! \file mln/fun/v2v/linear.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ /*! Linear function.
+ *
+ * f(v) = a * v + b.
+ *
+ * \c V is the type of input values; \c T is the type used to
+ * compute the result; \c R is the result type.
+ *
+ * By defaut, \c T is \c V and \c R is \c T.
+ */
+ template <typename V, typename T = V, typename R = T>
+ struct linear : public Function_v2v< linear<V,T,R> >
+ {
+ typedef R result;
+ R operator()(const V& v) const;
+
+ linear(T a, T b);
+ T a, b;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, typename T, typename R>
+ linear<V,T,R>::linear(T a, T b)
+ : a(a),
+ b(b)
+ {
+ }
+
+ template <typename V, typename T, typename R>
+ R
+ linear<V,T,R>::operator()(const V& v) const
+ {
+ return R(a * T(v) + b);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2V_LINEAR_HH
Index: mln/morpho/erosion.hh
--- mln/morpho/erosion.hh (revision 1050)
+++ mln/morpho/erosion.hh (working copy)
@@ -70,7 +70,7 @@
min.init();
for_all(q) if (input.has(q))
min.take(input(q));
- output(p) = min;
+ output(p) = min.to_value();
}
}
Index: mln/level/median.hh
--- mln/level/median.hh (revision 1050)
+++ mln/level/median.hh (working copy)
@@ -122,7 +122,7 @@
med.untake(input(q_dm));
for_all(q_dp) if (input.has(q_dp))
med.take(input(q_dp));
- output(p) = med;
+ output(p) = med.to_value();
}
void fwd()
@@ -131,7 +131,7 @@
med.untake(input(q_fm));
for_all(q_fp) if (input.has(q_fp))
med.take(input(q_fp));
- output(p) = med;
+ output(p) = med.to_value();
}
void bkd()
@@ -140,7 +140,7 @@
med.untake(input(q_bm));
for_all(q_bp) if (input.has(q_bp))
med.take(input(q_bp));
- output(p) = med;
+ output(p) = med.to_value();
}
}; // end of median_functor
@@ -192,7 +192,7 @@
for (col = min_col; col <= min_col + half; ++col, ++ct)
{
med.take(input(pt));
- output(p) = med;
+ output(p) = med.to_value();
}
// middle columns (both take and untake)
@@ -201,14 +201,14 @@
{
med.take(input(pt));
med.untake(input(pu));
- output(p) = med;
+ output(p) = med.to_value();
}
// right columns (now just untake old points)
for (; col <= max_col; ++cu, ++col)
{
med.untake(input(pu));
- output(p) = med;
+ output(p) = med.to_value();
}
}
}
Index: mln/level/naive/median.hh
--- mln/level/naive/median.hh (revision 1050)
+++ mln/level/naive/median.hh (working copy)
@@ -85,7 +85,7 @@
med.init();
for_all(q) if (input.has(q))
med.take(input(q));
- output(p) = med;
+ output(p) = med.to_value();
}
}
Index: mln/level/to_enc.hh
--- mln/level/to_enc.hh (revision 1050)
+++ mln/level/to_enc.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/level/to_enc.hh
*
- * \brief Transform with fun::to_enc the contents of an image into
+ * \brief Transform with fun::v2v::enc the contents of an image into
* another one.
*/
@@ -60,7 +60,7 @@
template <typename I, typename O>
void to_enc(const Image<I>& input, Image<O>& output)
{
- mln_precondition(exact(output).domain() >= exact(input).domain());
+ mln_precondition(exact(output).domain() = exact(input).domain());
level::transform(input, fun::v2v::enc< mln_value(I) >(), output);
}
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 1050)
+++ mln/level/fast_median.hh (working copy)
@@ -119,7 +119,7 @@
for_all(q_bot)
med.take(*q_bot);
- output(p) = med;
+ output(p) = med.to_value();
if (fwd)
// browse line fwd
@@ -130,7 +130,7 @@
med.untake(*q_fm);
for_all(q_fp)
med.take(*q_fp);
- output(p) = med;
+ output(p) = med.to_value();
}
else
// browse line bkd
@@ -141,7 +141,7 @@
med.untake(*q_bm);
for_all(q_bp)
med.take(*q_bp);
- output(p) = med;
+ output(p) = med.to_value();
}
// change browsing
fwd = ! fwd;
Index: mln/level/stretch.hh
--- mln/level/stretch.hh (revision 0)
+++ mln/level/stretch.hh (revision 0)
@@ -0,0 +1,100 @@
+// 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_LEVEL_STRETCH_HH
+# define MLN_LEVEL_STRETCH_HH
+
+/*! \file mln/level/stretch.hh
+ *
+ * \brief Transform with fun::stretch the contents of an image into
+ * another one.
+ */
+
+# include <mln/estim/min_max.hh>
+# include <mln/value/int_u.hh>
+# include <mln/fun/v2v/linear.hh>
+# include <mln/level/transform.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Stretch the values of \p input so that they can be stored in \p output.
+ *
+ * \param[in] input The input image.
+ * \param[out] output The result image.
+ *
+ * \pre \p output.domain = \p input.domain
+ */
+ template <typename I, typename O>
+ void stretch(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <unsigned n, typename I, typename O>
+ void stretch(value::int_u<n>,
+ const Image<I>& input, Image<O>& output)
+ {
+ mln_value(I) min_, max_;
+ estim::min_max(input, min_, max_);
+ if (max_ = min_)
+ return; // FIXME
+ float min = float(min_), max = float(max_);
+ const float epsilon = value::props<float>::epsilon;
+ float m = 0.0f - 0.5f + epsilon;
+ float M = mln_max(value::int_u<n>) + 0.5f - epsilon;
+ float a = (M - m) / (max - min);
+ float b = (m * max - M * min) / (max - min);
+ fun::v2v::linear<float, float, int> f(a, b);
+ level::transform(input, f, output);
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ template <typename I, typename O>
+ void stretch(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ impl::stretch(mln_value(O)(), input, output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_STRETCH_HH
Index: mln/io/save_pgm.hh
--- mln/io/save_pgm.hh (revision 1050)
+++ mln/io/save_pgm.hh (working copy)
@@ -55,15 +55,32 @@
file << "# olena" << std::endl;
file << ima.ncols() << ' ' << ima.nrows() << std::endl;
file << "255" << std::endl;
- point2d p = make::point2d(ima.domain().pmin().row(),
- ima.domain().pmin().col());
- size_t len = ima.ncols() * sizeof(unsigned char);
- for (;
- p.row() <= ima.domain().pmax().row();
- ++p.row())
+ const int
+ min_row = ima.domain().pmin().row(),
+ max_row = ima.domain().pmax().row();
+ point2d p;
+ if (sizeof(value::int_u8) = 1)
{
+ p.col() = ima.domain().pmin().col();
+ size_t len = ima.ncols();
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
file.write((char*)(& ima(p)), len);
}
+ else
+ {
+ // FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!!
+ const int
+ min_col = ima.domain().pmin().col(),
+ max_col = ima.domain().pmax().col();
+ std::cout << min_row << ' ' << max_row << std::endl;
+ std::cout << min_col << ' ' << max_col << std::endl;
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
+ for (p.col() = min_col; p.col() <= max_col; ++p.col())
+ {
+ unsigned char c = ima(p);
+ file.write((char*)(&c), 1);
+ }
+ }
}
} // end of namespace mln::io
Index: mln/io/load_pgm.hh
--- mln/io/load_pgm.hh (revision 1050)
+++ mln/io/load_pgm.hh (working copy)
@@ -135,13 +135,30 @@
void load_pgm_raw_2d(std::ifstream& file, I& ima)
{
point2d p = make::point2d(0, ima.domain().pmin().col());
- size_t len = ima.ncols() * sizeof(mln_value(I));
- for (p.row() = ima.domain().pmin().row();
- p.row() <= ima.domain().pmax().row();
- ++p.row())
+ typedef mln_value(I) V;
+ const mln_coord(I)
+ min_row = ima.domain().pmin().row(),
+ max_row = ima.domain().pmax().row();
+ if (sizeof(V) = 1)
{
+ size_t len = ima.ncols() * sizeof(mln_enc(V));
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
file.read((char*)(& ima(p)), len);
}
+ else
+ {
+ // FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!!
+ const mln_coord(I)
+ min_col = ima.domain().pmin().col(),
+ max_col = ima.domain().pmax().col();
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
+ for (p.col() = min_col; p.col() <= max_col; ++p.col())
+ {
+ unsigned char c;
+ file.read((char*)(&c), 1);
+ ima(p) = c;
+ }
+ }
}
@@ -160,6 +177,7 @@
char type;
int nrows, ncols;
internal::read_pnm_header('2', '5', file, type, nrows, ncols);
+
image2d_b<value::int_u8> ima(nrows, ncols);
if (type = '5')
internal::load_pgm_raw_2d(file, ima);
Index: mln/linear/log.hh
--- mln/linear/log.hh (revision 0)
+++ mln/linear/log.hh (revision 0)
@@ -0,0 +1,74 @@
+// 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_LINEAR_LOG_HH
+# define MLN_LINEAR_LOG_HH
+
+/*! \file mln/linear/log.hh
+ *
+ * \brief Laplacian of Gaussian.
+ */
+
+# include <mln/linear/convolve.hh>
+# include <mln/make/w_window2d_int.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ template <typename I, typename O>
+ void LoG_5x5(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // LoG_5x5 (Cf. Sonka et al., pages 85-86)
+
+ template <typename I, typename O>
+ void LoG_5x5(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { 0, 0, -1, 0, 0,
+ 0, -1, -2, -1, 0,
+ -1, -2, 16, -2, -1,
+ 0, -1, -2, -1, 0,
+ 0, 0, -1, 0, 0 };
+ convolve(input, make::w_window2d_int(ws), output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_CONVOLVE_HH
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 1050)
+++ mln/linear/convolve.hh (working copy)
@@ -35,6 +35,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/weighted_window.hh>
+# include <mln/border/resize.hh>
+# include <mln/border/duplicate.hh>
@@ -86,6 +88,9 @@
const W& win = exact(win_);
O& output = exact(output_);
+ border::resize(input, win.delta());
+ border::duplicate(input);
+
mln_pixter(O) p_out(output);
mln_pixter(const I) p(input);
Index: mln/accu/min.hh
--- mln/accu/min.hh (revision 1050)
+++ mln/accu/min.hh (working copy)
@@ -54,10 +54,11 @@
typedef V value;
min();
+
void take(const value& v);
+ void take(const min<V>& other);
void init();
- operator V() const;
V to_value() const;
protected:
@@ -76,23 +77,25 @@
}
template <typename V>
- void min<V>::take(const value& v)
+ void
+ min<V>::init()
{
- if (v < v_)
- v_ = v;
+ v_ = mln_max(V);
}
template <typename V>
- void
- min<V>::init()
+ void min<V>::take(const value& v)
{
- v_ = mln_max(V);
+ if (v < v_)
+ v_ = v;
}
template <typename V>
- min<V>::operator V() const
+ void
+ min<V>::take(const min<V>& other)
{
- return v_;
+ if (other.v_ < v_)
+ v_ = other.v_;
}
template <typename V>
Index: mln/accu/sum.hh
--- mln/accu/sum.hh (revision 1050)
+++ mln/accu/sum.hh (working copy)
@@ -56,14 +56,13 @@
typedef V value;
sum();
- void take(const value& v);
+
void init();
+ void take(const value& v);
+ void take(const sum<V,S>& other);
- operator S() const;
S to_value() const;
- sum<V,S>& operator+=(const sum<V,S>& rhs);
-
protected:
S sum_;
@@ -80,12 +79,6 @@
}
template <typename V, typename S>
- void sum<V,S>::take(const value& v)
- {
- sum_ += v;
- }
-
- template <typename V, typename S>
void
sum<V,S>::init()
{
@@ -93,24 +86,23 @@
}
template <typename V, typename S>
- sum<V,S>::operator S() const
+ void sum<V,S>::take(const value& v)
{
- return to_value;
+ sum_ += v;
}
template <typename V, typename S>
- S
- sum<V,S>::to_value() const
+ void
+ sum<V,S>::take(const sum<V,S>& other)
{
- return sum_;
+ sum_ += other.sum_;
}
template <typename V, typename S>
- sum<V,S>&
- sum<V,S>::operator+=(const sum<V,S>& rhs)
+ S
+ sum<V,S>::to_value() const
{
- sum_ += rhs.sum_;
- return *this;
+ return sum_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/accu/max.hh
--- mln/accu/max.hh (revision 1050)
+++ mln/accu/max.hh (working copy)
@@ -54,10 +54,11 @@
typedef V value;
max();
+
void take(const value& v);
+ void take(const max<V>& other);
void init();
- operator V() const;
V to_value() const;
protected:
@@ -76,7 +77,8 @@
}
template <typename V>
- void max<V>::take(const value& v)
+ void
+ max<V>::take(const value& v)
{
if (v > v_)
v_ = v;
@@ -84,15 +86,17 @@
template <typename V>
void
- max<V>::init()
+ max<V>::take(const max<V>& other)
{
- v_ = mln_min(V);
+ if (other.v_ > v_)
+ v_ = other.v_;
}
template <typename V>
- max<V>::operator V() const
+ void
+ max<V>::init()
{
- return v_;
+ v_ = mln_min(V);
}
template <typename V>
Index: mln/accu/histo.hh
--- mln/accu/histo.hh (revision 1050)
+++ mln/accu/histo.hh (working copy)
@@ -59,6 +59,7 @@
typedef mln_value(S) value;
void take(const value& v);
+ void take(const histo<S>& other);
void untake(const value& v);
void init();
@@ -113,6 +114,15 @@
template <typename S>
void
+ histo<S>::take(const histo<S>& other)
+ {
+ for (unsigned i = 0; i < h_.size(); ++i)
+ h_[i] += other.h_[i];
+ sum_ += other.sum_;
+ }
+
+ template <typename S>
+ void
histo<S>::untake(const value& v)
{
mln_precondition(h_[s_.index_of(v)] > 0);
Index: mln/accu/count.hh
--- mln/accu/count.hh (revision 1050)
+++ mln/accu/count.hh (working copy)
@@ -51,14 +51,13 @@
typedef V value;
count();
- void take(const value&);
+
void init();
+ void take(const value&);
+ void take(const count<V>& other);
- operator std::size_t() const;
std::size_t to_value() const;
- count<V>& operator+=(const count<V>& rhs);
-
protected:
std::size_t count_;
@@ -76,22 +75,23 @@
template <typename V>
void
- count<V>::take(const value&)
+ count<V>::init()
{
- ++count_;
+ count_ = 0;
}
template <typename V>
void
- count<V>::init()
+ count<V>::take(const value&)
{
- count_ = 0;
+ ++count_;
}
template <typename V>
- count<V>::operator std::size_t() const
+ void
+ count<V>::take(const count<V>& other)
{
- return to_value();
+ count_ += other.count_;
}
template <typename V>
@@ -101,14 +101,6 @@
return count_;
}
- template <typename V>
- count<V>&
- count<V>::operator+=(const count<V>& rhs)
- {
- count_ += rhs.count_;
- return *this;
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
Index: mln/accu/min_max.hh
--- mln/accu/min_max.hh (revision 0)
+++ mln/accu/min_max.hh (revision 0)
@@ -0,0 +1,147 @@
+// 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_ACCU_MIN_MAX_HH
+# define MLN_ACCU_MIN_MAX_HH
+
+/*! \file mln/accu/min_max.hh
+ *
+ * \brief Define an accumulator that computes a min and a max.
+ */
+
+# include <utility>
+
+# include <mln/accu/min.hh>
+# include <mln/accu/max.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! Generic min and max accumulator class.
+ *
+ * The parameter \c V is the type of values.
+ */
+ template <typename V>
+ struct min_max : public Accumulator< min_max<V> >
+ {
+ typedef V value;
+
+ min_max();
+
+ void take(const value& v);
+ void take(const min_max<V>& other);
+ void init();
+
+ V min() const;
+ V max() const;
+
+ std::pair<V,V> to_value() const;
+ void values(V& min, V& max) const;
+
+ protected:
+
+ accu::min<V> min_;
+ accu::max<V> max_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ min_max<V>::min_max()
+ {
+ init();
+ }
+
+ template <typename V>
+ void
+ min_max<V>::init()
+ {
+ min_.init();
+ max_.init();
+ }
+
+ template <typename V>
+ void min_max<V>::take(const value& v)
+ {
+ min_.take(v);
+ max_.take(v);
+ }
+
+ template <typename V>
+ void
+ min_max<V>::take(const min_max<V>& other)
+ {
+ min_.take(other.min_);
+ max_.take(other.max_);
+ }
+
+ template <typename V>
+ V
+ min_max<V>::min() const
+ {
+ return min_.to_value();
+ }
+
+ template <typename V>
+ V
+ min_max<V>::max() const
+ {
+ return max_.to_value();
+ }
+
+ template <typename V>
+ std::pair<V,V>
+ min_max<V>::to_value() const
+ {
+ std::pair<V,V> tmp(min_.to_value(),
+ max_.to_value());
+ return tmp;
+ }
+
+ template <typename V>
+ void
+ min_max<V>::values(V& min, V& max) const
+ {
+ min = min_.to_value();
+ max = max_.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_MIN_MAX_HH
Index: mln/accu/bbox.hh
--- mln/accu/bbox.hh (revision 1050)
+++ mln/accu/bbox.hh (working copy)
@@ -54,10 +54,11 @@
typedef P value;
bbox();
+
void take(const P& p);
+ void take(const bbox<P>& other);
void init();
- operator box_<P>() const;
const box_<P>& to_value() const;
bool is_valid() const;
@@ -79,7 +80,8 @@
}
template <typename P>
- void bbox<P>::take(const P& p)
+ void
+ bbox<P>::take(const P& p)
{
if (! is_valid_)
{
@@ -97,16 +99,33 @@
template <typename P>
void
- bbox<P>::init()
+ bbox<P>::take(const bbox<P>& other)
{
- is_valid_ = false;
+ if (! other.is_valid_)
+ {
+ // no-op
+ return;
+ }
+ if (! this->is_valid_)
+ {
+ // 'other' makes '*this' valid
+ *this = other;
+ return;
+ }
+ // both are valids so:
+ const box_<P>& o_b = other.b_;
+ for (unsigned i = 0; i < P::dim; ++i)
+ if (o_b.pmin()[i] < b_.pmin()[i])
+ b_.pmin()[i] = o_b.pmin()[i];
+ else if (o_b.pmax()[i] > b_.pmax()[i])
+ b_.pmax()[i] = o_b.pmax()[i];
}
template <typename P>
- bbox<P>::operator box_<P>() const
+ void
+ bbox<P>::init()
{
- mln_precondition(is_valid_);
- return b_;
+ is_valid_ = false;
}
template <typename P>
Index: mln/accu/median.hh
--- mln/accu/median.hh (revision 1050)
+++ mln/accu/median.hh (working copy)
@@ -55,13 +55,13 @@
median(const Value_Set<S>& s);
median();
+ void init();
void take(const value& v);
+ void take(const median<S>& other);
void untake(const value& v);
- void init();
unsigned card() const { return h_.sum(); }
- operator mln_value(S) () const;
value to_value() const;
const accu::histo<S>& histo() const;
@@ -119,6 +119,25 @@
template <typename S>
void
+ median<S>::take(const median<S>& other)
+ {
+ // h_
+ h_.take(other.h_);
+
+ // sum_minus_
+ for (unsigned i = 0; i < i_; ++i)
+ sum_minus_ += other.h_[i];
+
+ // sum_plus_
+ for (unsigned i = i_ + 1; i < h_.nvalues(); ++i)
+ sum_plus_ += other.h_[i];
+
+ if (valid_)
+ valid_ = false;
+ }
+
+ template <typename S>
+ void
median<S>::untake(const value& v)
{
mln_precondition(h_(v) != 0);
@@ -203,12 +222,6 @@
}
template <typename S>
- median<S>::operator mln_value(S) () const
- {
- return to_value();
- }
-
- template <typename S>
typename median<S>::value
median<S>::to_value() const
{
Index: mln/accu/mean.hh
--- mln/accu/mean.hh (revision 1050)
+++ mln/accu/mean.hh (working copy)
@@ -60,14 +60,13 @@
typedef V value;
mean();
- void take(const value& v);
+
void init();
+ void take(const value& v);
+ void take(const mean<V,S,M>& other);
- operator M() const;
M to_value() const;
- mean<V,S,M>& operator+=(const mean<V,S,M>& rhs);
-
protected:
accu::count<V> count_;
@@ -85,13 +84,6 @@
}
template <typename V, typename S, typename M>
- void mean<V,S,M>::take(const value& v)
- {
- count_.take(v);
- sum_.take(v);
- }
-
- template <typename V, typename S, typename M>
void
mean<V,S,M>::init()
{
@@ -100,25 +92,25 @@
}
template <typename V, typename S, typename M>
- mean<V,S,M>::operator M() const
+ void mean<V,S,M>::take(const value& v)
{
- return to_value();
+ count_.take(v);
+ sum_.take(v);
}
template <typename V, typename S, typename M>
- M
- mean<V,S,M>::to_value() const
+ void
+ mean<V,S,M>::take(const mean<V,S,M>& other)
{
- return sum_.to_value() / count_.to_value();
+ count_.take(other.count_);
+ sum_.take(other.sum_);
}
template <typename V, typename S, typename M>
- mean<V,S,M>&
- mean<V,S,M>::operator+=(const mean<V,S,M>& rhs)
+ M
+ mean<V,S,M>::to_value() const
{
- count_ += rhs.count_;
- sum_ += rhs.sum_;
- return *this;
+ return sum_.to_value() / count_.to_value();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1050)
+++ mln/value/props.hh (working copy)
@@ -203,8 +203,9 @@
template <>
struct props<float>
{
- static const float min() { return FLT_MIN; }
- static const float max() { return FLT_MAX; }
+ static const float min = FLT_MIN;
+ static const float max = FLT_MAX;
+ static const float epsilon = 0.00001f;
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef float sum;
@@ -213,8 +214,9 @@
template <>
struct props<double>
{
- static const double min() { return DBL_MIN; }
- static const double max() { return DBL_MAX; }
+ static const double min = DBL_MIN;
+ static const double max = DBL_MAX;
+ static const double epsilon = 0.0000001;
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef double sum;
Index: mln/value/stack.hh
--- mln/value/stack.hh (revision 1050)
+++ mln/value/stack.hh (working copy)
@@ -143,11 +143,13 @@
stack_image<2, const I>
stack(const Image<I>& ima1, const Image<I>& ima2);
+
template <typename I>
stack_image<2, I>
stack(Image<I>& ima1, Image<I>& ima2);
+
# ifndef MLN_INCLUDE_ONLY
// stack_image<n, I>
Index: mln/border/resize.hh
--- mln/border/resize.hh (revision 1050)
+++ mln/border/resize.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -65,10 +66,12 @@
void resize(const Fast_Image<I>& ima_, unsigned thickness)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
+ mln_precondition(ima.has_data());
if (ima.border() >= thickness)
return;
- mln_invariant(0); // FIXME: NYI
+ internal::fixme();
+ mln_postcondition(ima.border() >= thickness);
+ return;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/border/fill.hh
--- mln/border/fill.hh (revision 1050)
+++ mln/border/fill.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -62,8 +63,8 @@
void fill(const Fast_Image<I>& ima_, const mln_value(I)& v)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
- mln_invariant(0); // FIXME: NYI
+ mln_precondition(ima.has_data());
+ internal::fixme();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/border/duplicate.hh
--- mln/border/duplicate.hh (revision 1050)
+++ mln/border/duplicate.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -61,8 +62,8 @@
void duplicate(const Fast_Image<I>& ima_)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
- mln_invariant(0); // FIXME: NYI
+ mln_precondition(ima.has_data());
+ internal::fixme();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/border/mirror.hh
--- mln/border/mirror.hh (revision 1050)
+++ mln/border/mirror.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -61,8 +62,8 @@
void mirror(const Fast_Image<I>& ima_)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
- mln_invariant(0); // FIXME: NYI
+ mln_precondition(ima.has_data());
+ internal::fixme();
}
# endif // ! MLN_INCLUDE_ONLY
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add 'decorated image' morpher.
* mln/core/decorated_image.hh: New.
* mln/core/internal/image_adaptor.hh (adaptee): New.
* mln/metal/unconst.hh: New.
* mln/metal/vec.hh (vec): New ctors.
(operator=): New.
* mln/metal/make: New directory.
* mln/metal/make/vec.hh: New.
* mln/value/proxy: New.
* mln/value/stack.hh (helper_stack_image_lvalue_): New.
(read_, write_): New.
(operator()): Fix.
(stack): New overload for n=2 and I mutable.
* tests/decorated_image.cc: New.
* tests/stack.cc: Augment.
mln/core/decorated_image.hh | 208 ++++++++++++++++++++++
mln/core/internal/image_adaptor.hh | 20 ++
mln/core/safe.hh | 2
mln/metal/make/vec.hh | 108 +++++++++++
mln/metal/unconst.hh | 58 ++++++
mln/metal/vec.hh | 33 +++
mln/value/proxy.hh | 335 +++++++++++++++++++++++++++++++++++++
mln/value/stack.hh | 102 +++++++++--
tests/decorated_image.cc | 67 +++++++
tests/stack.cc | 13 -
10 files changed, 927 insertions(+), 19 deletions(-)
Index: tests/stack.cc
--- tests/stack.cc (revision 1049)
+++ tests/stack.cc (working copy)
@@ -42,8 +42,13 @@
typedef image2d_b<int> I;
- I ima(2, 3);
- debug::iota(ima);
- debug::println(ima);
- debug::println(value::stack(ima, ima));
+ box2d b = make::box2d(1, 1);
+ image2d_b<int> ima5(b), ima1(b);
+
+ point2d p = make::point2d(0, 0);
+ metal::vec<2, int> v = metal::make::vec(5, 1);
+
+ value::stack(ima5, ima1)(p) = v;
+ mln_assertion(value::stack(ima5, ima1)(p) = v);
+ mln_assertion(ima5(p) = 5 && ima1(p) = 1);
}
Index: tests/decorated_image.cc
--- tests/decorated_image.cc (revision 0)
+++ tests/decorated_image.cc (revision 0)
@@ -0,0 +1,67 @@
+// 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/decorated_image.cc
+ *
+ * \brief Tests on mln::decorated_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/decorated_image.hh>
+
+
+unsigned count_read = 0, count_write = 0;
+
+template <typename I>
+struct counter
+{
+ void reading(const I& ima, const mln_psite(I)& p) const
+ {
+ ++count_read;
+ }
+ void writing(I&, const mln_psite(I)&, const mln_value(I)&)
+ {
+ ++count_write;
+ }
+};
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(1, 1);
+ point2d p = make::point2d(0, 0);
+
+ decorated_image< I, counter<I> > ima_ = decorate(ima, counter<I>());
+ ima_(p) = ima_(p) = 51;
+ mln_assertion(count_read = 1 && count_write = 2);
+
+ const I& imac = ima;
+ decorated_image< const I, counter<I> > cima_ = decorate(imac, counter<I>());
+}
Index: mln/core/decorated_image.hh
--- mln/core/decorated_image.hh (revision 0)
+++ mln/core/decorated_image.hh (revision 0)
@@ -0,0 +1,208 @@
+// 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_CORE_DECORATED_IMAGE_HH
+# define MLN_CORE_DECORATED_IMAGE_HH
+
+# include <mln/core/internal/image_adaptor.hh>
+# include <mln/value/proxy.hh>
+
+
+namespace mln
+{
+
+ // FIXME: Doc!
+
+ template <typename I, typename D>
+ class decorated_image : public internal::image_adaptor_< I, decorated_image<I,D> >
+ {
+ typedef decorated_image<I, D> self_;
+ typedef internal::image_adaptor_< I, self_ > super_;
+ public:
+
+ decorated_image(I& ima, const D& deco);
+ ~decorated_image();
+
+ typedef mln_value(I) value;
+ typedef mln::value::proxy<const self_> rvalue;
+ typedef mln::value::proxy<self_> lvalue;
+
+ rvalue operator()(const mln_psite(I)& p) const;
+ lvalue operator()(const mln_psite(I)& p);
+
+ mln_value(I) read_(const mln_psite(I)& p) const;
+ void write_(const mln_psite(I)& p, const mln_value(I)& v);
+
+ template <typename V>
+ struct change_value
+ {
+ typedef decorated_image<mln_ch_value(I, V), D> ret;
+ };
+
+ /// Const promotion via convertion.
+ operator decorated_image<const I, D>() const;
+
+ /// Give the decoration.
+ const D& decoration() const;
+
+ /// Give the decoration.
+ D& decoration();
+
+ protected:
+ D deco_;
+ };
+
+
+
+ template <typename I, typename D>
+ decorated_image<I,D> decorate(Image<I>& ima,
+ const D& decoration);
+
+ template <typename I, typename D>
+ decorated_image<const I, D> decorate(const Image<I>& ima,
+ const D& decoration);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // decorated_image<I,D>
+
+ template <typename I, typename D>
+ decorated_image<I,D>::decorated_image(I& ima, const D& deco)
+ : super_(ima),
+ deco_(deco)
+ {
+ }
+
+ template <typename I, typename D>
+ decorated_image<I,D>::~decorated_image()
+ {
+ void (D::*mr)(const I&, const mln_psite(I)&) const = & D::reading;
+ mr = 0;
+ typedef mlc_unconst(I) I_;
+ void (D::*mw)(I_&, const mln_psite(I_)&, const mln_value(I_)&) = & D::writing;
+ mw = 0;
+ }
+
+ template <typename I, typename D>
+ mln::value::proxy< const decorated_image<I,D> >
+ decorated_image<I,D>::operator()(const mln_psite(I)& p) const
+ {
+ rvalue tmp(*this, p);
+ return tmp;
+ }
+
+ template <typename I, typename D>
+ mln::value::proxy< decorated_image<I,D> >
+ decorated_image<I,D>::operator()(const mln_psite(I)& p)
+ {
+ lvalue tmp(*this, p);
+ return tmp;
+ }
+
+ namespace internal
+ {
+
+ template <typename I, typename D>
+ void
+ helper_decorated_image_write_(decorated_image<I,D>& ima,
+ const mln_psite(I)& p, const mln_value(I)& v)
+ {
+ ima.decoration().writing(ima.adaptee(), p, v);
+ ima.adaptee()(p) = v;
+ }
+
+ template <typename I, typename D>
+ void
+ helper_decorated_image_write_(decorated_image<const I,D>&,
+ const mln_psite(I)&, const mln_value(I)&)
+ // FIXME: Static assertion instead.
+ ;
+
+ } // end of namespace mln::internal
+
+ template <typename I, typename D>
+ void
+ decorated_image<I,D>::write_(const mln_psite(I)& p, const mln_value(I)& v)
+ {
+ internal::helper_decorated_image_write_(*this, p, v);
+ }
+
+ template <typename I, typename D>
+ mln_value(I)
+ decorated_image<I,D>::read_(const mln_psite(I)& p) const
+ {
+ deco_.reading(this->adaptee_, p);
+ return this->adaptee_(p);
+ }
+
+ template <typename I, typename D>
+ decorated_image<I,D>::operator decorated_image<const I, D>() const
+ {
+ decorated_image<const I, D> tmp(this->adaptee_, deco_);
+ return tmp;
+ }
+
+ template <typename I, typename D>
+ const D&
+ decorated_image<I,D>::decoration() const
+ {
+ return deco_;
+ }
+
+ template <typename I, typename D>
+ D&
+ decorated_image<I,D>::decoration()
+ {
+ return deco_;
+ }
+
+ // decorate
+
+ template <typename I, typename D>
+ decorated_image<I, D> decorate(Image<I>& ima,
+ const D& decoration)
+ {
+ decorated_image<I, D> tmp(exact(ima), decoration);
+ return tmp;
+ }
+
+ template <typename I, typename D>
+ decorated_image<const I, D> decorate(const Image<I>& ima,
+ const D& decoration)
+ {
+ decorated_image<const I, D> tmp(exact(ima), decoration);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_DECORATED_IMAGE_HH
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1049)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -92,6 +92,12 @@
/// Convertion to the underlying (adapted) image.
operator I() const;
+ /// Give the adaptee (underlying adapted) image.
+ const I& adaptee() const;
+
+ /// Give the adaptee (underlying adapted) image.
+ I& adaptee();
+
protected:
I& adaptee_;
@@ -104,6 +110,20 @@
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename E, typename S>
+ const I&
+ image_adaptor_<I,E,S>::adaptee() const
+ {
+ return adaptee_;
+ }
+
+ template <typename I, typename E, typename S>
+ I&
+ image_adaptor_<I,E,S>::adaptee()
+ {
+ return adaptee_;
+ }
+
+ template <typename I, typename E, typename S>
image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
: adaptee_(adaptee)
{
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1049)
+++ mln/core/safe.hh (working copy)
@@ -80,7 +80,7 @@
template <typename I>
safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
- : super_(exact(ima)),
+ : super_(ima),
default_value_(default_value)
{
}
Index: mln/metal/unconst.hh
--- mln/metal/unconst.hh (revision 0)
+++ mln/metal/unconst.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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_METAL_UNCONST_HH
+# define MLN_METAL_UNCONST_HH
+
+
+# define mlc_unconst(T) typename mln::metal::unconst< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unconst
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unconst< const T >
+ {
+ typedef T ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNCONST_HH
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1049)
+++ mln/metal/vec.hh (working copy)
@@ -47,6 +47,9 @@
enum { dim = n };
typedef T coord;
+ vec();
+ vec(T (&values)[n]);
+
T& operator[](unsigned i);
T operator[](unsigned i) const;
@@ -59,9 +62,25 @@
std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v);
+ template <unsigned n, typename T>
+ bool operator=(const vec<n,T>& lhs, const vec<n,T>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
template <unsigned n, typename T>
+ vec<n,T>::vec()
+ {
+ }
+
+ template <unsigned n, typename T>
+ vec<n,T>::vec(T (&values)[n])
+ {
+ for (unsigned i = 0; i < n; ++i)
+ coord_[i] = values[i];
+ }
+
+ template <unsigned n, typename T>
T&
vec<n,T>::operator[](unsigned i)
{
@@ -77,6 +96,8 @@
return coord_[i];
}
+ // operators
+
template <unsigned n, typename T>
std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v)
{
@@ -86,6 +107,15 @@
return ostr << ']';
}
+ template <unsigned n, typename T>
+ bool operator=(const vec<n,T>& lhs, const vec<n,T>& rhs)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
@@ -94,4 +124,7 @@
} // end of namespace mln
+# include <mln/metal/make/vec.hh>
+
+
#endif // ! MLN_CORE_METAL_VEC_HH
Index: mln/metal/make/vec.hh
--- mln/metal/make/vec.hh (revision 0)
+++ mln/metal/make/vec.hh (revision 0)
@@ -0,0 +1,108 @@
+// 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_CORE_METAL_MAKE_VEC_HH
+# define MLN_CORE_METAL_MAKE_VEC_HH
+
+# include <mln/metal/vec.hh>
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace make
+ {
+
+ template <typename T>
+ mln::metal::vec<1,T> vec(T c0);
+
+ template <typename T>
+ mln::metal::vec<2,T> vec(T c0, T c1);
+
+ template <typename T>
+ mln::metal::vec<3,T> vec(T c0, T c1, T c2);
+
+ template <typename T>
+ mln::metal::vec<4,T> vec(T c0, T c1, T c2, T c3);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ mln::metal::vec<1,T> vec(T c0)
+ {
+ mln::metal::vec<1,T> tmp;
+ tmp[0] = c0;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<2,T> vec(T c0, T c1)
+ {
+ mln::metal::vec<2,T> tmp;
+ tmp[0] = c0;
+ tmp[1] = c1;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<3,T> vec(T c0, T c1, T c2)
+ {
+ mln::metal::vec<3,T> tmp;
+ tmp[0] = c0;
+ tmp[1] = c1;
+ tmp[2] = c2;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<4,T> vec(T c0, T c1, T c2, T c3)
+ {
+ mln::metal::vec<4,T> tmp;
+ tmp[0] = c0;
+ tmp[1] = c1;
+ tmp[2] = c2;
+ tmp[3] = c3;
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::metal::make
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+# include <mln/metal/make/vec.hh>
+
+
+#endif // ! MLN_CORE_METAL_MAKE_VEC_HH
Index: mln/value/proxy.hh
--- mln/value/proxy.hh (revision 0)
+++ mln/value/proxy.hh (revision 0)
@@ -0,0 +1,335 @@
+// 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_VALUE_PROXY_HH
+# define MLN_VALUE_PROXY_HH
+
+/*! \file mln/value/proxy.hh
+ *
+ * \brief Define a generic proxy class for an image pixel value.
+ */
+
+# include <mln/core/concept/value.hh>
+# include <mln/value/props.hh>
+# include <mln/metal/unconst.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! \brief Generic proxy class for an image pixel value.
+ *
+ * The parameter \c I is an image type.
+ */
+ template <typename I>
+ class proxy : public Value< proxy<I> >
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef void enc; // FIXME
+
+ /// Equivalent associated type.
+ typedef mln_value(I) equiv;
+
+ /// Constructor.
+ proxy(I& ima, const mln_psite(I)& p);
+
+ /// Destructor.
+ ~proxy();
+
+ /// Assignment (write access); general version.
+ template <typename V>
+ proxy<I>& operator=(const V& v);
+
+ /// Assignment (write access); replacement for default op.
+ proxy<I>& operator=(const proxy<I>& rhs);
+
+ /// Assignment (write access); with other proxy.
+ template <typename II>
+ proxy<I>& operator=(const proxy<II>& rhs);
+
+ /// Convertion (read access); general version.
+ template <typename V>
+ operator V() const;
+
+ /// Convertion (read access); precise version.
+ operator mln_value(I)() const;
+
+ /// Explicit read access.
+ mln_value(I) to_value() const;
+
+ protected:
+ I& ima_;
+ mln_psite(I) p_;
+ };
+
+
+
+ /*! \brief Generic proxy class for an image pixel value.
+ *
+ * The parameter \c I is an image type.
+ */
+ template <typename I>
+ class proxy< const I > : public Value< proxy<const I> >
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef void enc; // FIXME
+
+ /// Equivalent associated type.
+ typedef mln_value(I) equiv;
+
+ /// Constructor.
+ proxy(const I& ima, const mln_psite(I)& p);
+
+ /// Destructor.
+ ~proxy();
+
+ /// Convertion (read access); general version.
+ template <typename V>
+ operator V() const;
+
+ /// Convertion (read access); precise version.
+ operator mln_value(I)() const;
+
+ /// Explicit read access.
+ mln_value(I) to_value() const;
+
+ protected:
+ const I& ima_;
+ mln_psite(I) p_;
+ };
+
+
+
+ template <typename I>
+ bool operator=(const proxy<I>& lhs, const mln_value(I)& rhs);
+
+ template <typename I>
+ bool operator=(const mln_value(I)& lhs, const proxy<I>& rhs);
+
+ template <typename I, typename J>
+ bool operator=(const proxy<I>& lhs, const proxy<J>& rhs);
+
+
+ template <typename I>
+ bool operator<(const proxy<I>& lhs, const mln_value(I)& rhs);
+
+ template <typename I>
+ bool operator<(const mln_value(I)& lhs, const proxy<I>& rhs);
+
+ template <typename I, typename J>
+ bool operator<(const proxy<I>& lhs, const proxy<J>& rhs);
+
+
+ // FIXME: Ops such as +=, etc.
+
+
+
+ template <typename I>
+ struct props< proxy<I> > : public props< mln_value(I) >
+ {
+ // Contents is inherited.
+ };
+
+
+
+ /*! \brief Print a value proxy \p x into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] x A value proxy.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const proxy<I>& x);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // proxy<I>
+
+ template <typename I>
+ proxy<I>::proxy(I& ima, const mln_psite(I)& p)
+ : ima_(ima),
+ p_(p)
+ {
+ }
+
+ template <typename I>
+ proxy<I>::~proxy()
+ {
+ mln_value(I) (I::*mr)(const mln_psite(I)&) const = & I::read_;
+ mr = 0;
+ void (I::*mw)(const mln_psite(I)&, const mln_value(I)&) = & I::write_;
+ mw = 0;
+ }
+
+ template <typename I>
+ template <typename V>
+ proxy<I>&
+ proxy<I>::operator=(const V& v)
+ {
+ ima_.write_(p_, v);
+ return *this;
+ }
+
+ template <typename I>
+ proxy<I>&
+ proxy<I>::operator=(const proxy<I>& rhs)
+ {
+ this->operator=(rhs.to_value());
+ return *this;
+ }
+
+ template <typename I>
+ template <typename II>
+ proxy<I>&
+ proxy<I>::operator=(const proxy<II>& rhs)
+ {
+ this->operator=(rhs.to_value());
+ return *this;
+ }
+
+ template <typename I>
+ template <typename V>
+ proxy<I>::operator V() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ proxy<I>::operator mln_value(I)() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ mln_value(I)
+ proxy<I>::to_value() const
+ {
+ return ima_.read_(p_);
+ }
+
+ // proxy<const I>
+
+ template <typename I>
+ proxy<const I>::proxy(const I& ima, const mln_psite(I)& p)
+ : ima_(ima),
+ p_(p)
+ {
+ }
+
+ template <typename I>
+ proxy<const I>::~proxy()
+ {
+ mln_value(I) (I::*mr)(const mln_psite(I)&) const = & I::read_;
+ mr = 0;
+ }
+
+ template <typename I>
+ template <typename V>
+ proxy<const I>::operator V() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ proxy<const I>::operator mln_value(I)() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ mln_value(I)
+ proxy<const I>::to_value() const
+ {
+ return ima_.read_(p_);
+ }
+
+ // operator <<
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const proxy<I>& x)
+ {
+ return ostr << x.to_value();
+ }
+
+ // operator =
+
+ template <typename I>
+ bool operator=(const proxy<I>& lhs, const mln_value(I)& rhs)
+ {
+ return lhs.to_value() = rhs;
+ }
+
+ template <typename I>
+ bool operator=(const mln_value(I)& lhs, const proxy<I>& rhs)
+ {
+ return lhs = rhs.to_value();
+ }
+
+ template <typename I, typename J>
+ bool operator=(const proxy<I>& lhs, const proxy<J>& rhs)
+ {
+ return lhs.to_value() = rhs.to_value();
+ }
+
+ // operator <
+
+ template <typename I>
+ bool operator<(const proxy<I>& lhs, const mln_value(I)& rhs)
+ {
+ return lhs.to_value() < rhs;
+ }
+
+ template <typename I>
+ bool operator<(const mln_value(I)& lhs, const proxy<I>& rhs)
+ {
+ return lhs < rhs.to_value();
+ }
+
+ template <typename I, typename J>
+ bool operator<(const proxy<I>& lhs, const proxy<J>& rhs)
+ {
+ return lhs.to_value() < rhs.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U_HH
Index: mln/value/stack.hh
--- mln/value/stack.hh (revision 1049)
+++ mln/value/stack.hh (working copy)
@@ -36,6 +36,7 @@
# include <mln/core/internal/image_base.hh>
# include <mln/metal/vec.hh>
# include <mln/value/set.hh>
+# include <mln/value/proxy.hh>
namespace mln
@@ -44,6 +45,37 @@
namespace value
{
+ // Fwd decl.
+ template <unsigned n, typename I> struct stack_image;
+
+
+ namespace internal
+ {
+
+ template <unsigned n, typename I>
+ struct helper_stack_image_lvalue_
+ {
+ typedef value::proxy< stack_image<n,I> > ret;
+ static ret make(stack_image<n,I>& ima, const mln_psite(I)& p)
+ {
+ ret tmp(ima, p);
+ return tmp;
+ }
+ };
+
+ template <unsigned n, typename I>
+ struct helper_stack_image_lvalue_< n, const I >
+ {
+ typedef metal::vec<n, mln_value(I)> ret;
+ static ret make(stack_image<n, const I>& ima, const mln_psite(I)& p)
+ {
+ return ima.read_(p);
+ }
+ };
+
+ } // end of namespace mln::value::internal
+
+
/*! \brief FIXME
*
*/
@@ -63,7 +95,7 @@
typedef value rvalue;
/// Return type of read-write access.
- typedef void lvalue; // FIXME
+ typedef typename internal::helper_stack_image_lvalue_<n,I>::ret lvalue;
/// Value set associated type.
typedef mln::value::set<value> vset;
@@ -84,9 +116,11 @@
/// Read-only access of pixel value at point site \p p.
rvalue operator()(const psite& p) const;
+ value read_(const psite& p) const;
/// Read-write access of pixel value at point site \p p.
- void operator()(const psite&);
+ lvalue operator()(const psite&);
+ void write_(const psite& p, const value& v);
/// Give the set of values of the image.
const vset& values() const;
@@ -107,20 +141,17 @@
template <typename I>
stack_image<2,const I>
- stack(const Image<I>& ima1, const Image<I>& ima2)
- {
- mln_precondition(exact(ima1).domain() = exact(ima2).domain());
- metal::vec<2, const I*> imas;
- imas[0] = & exact(ima1);
- imas[1] = & exact(ima2);
- stack_image<2, const I> tmp(imas);
- return tmp;
- }
+ stack(const Image<I>& ima1, const Image<I>& ima2);
+ template <typename I>
+ stack_image<2, I>
+ stack(Image<I>& ima1, Image<I>& ima2);
# ifndef MLN_INCLUDE_ONLY
+ // stack_image<n, I>
+
template <unsigned n, typename I>
stack_image<n,I>::stack_image(const metal::vec<n,I*>& imas)
: imas_(imas)
@@ -158,7 +189,7 @@
template <unsigned n, typename I>
metal::vec<n, mln_value(I)>
- stack_image<n,I>::operator()(const psite& p) const
+ stack_image<n,I>::read_(const psite& p) const
{
mln_precondition(this->owns_(p));
metal::vec<n, mln_value(I)> tmp;
@@ -168,10 +199,27 @@
}
template <unsigned n, typename I>
+ metal::vec<n, mln_value(I)>
+ stack_image<n,I>::operator()(const psite& p) const
+ {
+ return read_(p);
+ }
+
+ template <unsigned n, typename I>
void
- stack_image<n,I>::operator()(const psite&)
+ stack_image<n,I>::write_(const psite& p, const value& v)
+ {
+ mln_precondition(this->owns_(p));
+ // FIXME!!!
+ for (unsigned i = 0; i < n; ++i)
+ imas_[i]->operator()(p) = v[i];
+ }
+
+ template <unsigned n, typename I>
+ typename stack_image<n,I>::lvalue
+ stack_image<n,I>::operator()(const psite& p)
{
- mln_invariant(0); // FIXME: Turn into a compile-time error...
+ return internal::helper_stack_image_lvalue_<n,I>::make(*this, p);
}
template <unsigned n, typename I>
@@ -181,6 +229,32 @@
return vset::the();
}
+ // stack(..)
+
+ template <typename I>
+ stack_image<2, const I>
+ stack(const Image<I>& ima1, const Image<I>& ima2)
+ {
+ mln_precondition(exact(ima1).domain() = exact(ima2).domain());
+ metal::vec<2, const I*> imas;
+ imas[0] = & exact(ima1);
+ imas[1] = & exact(ima2);
+ stack_image<2, const I> tmp(imas);
+ return tmp;
+ }
+
+ template <typename I>
+ stack_image<2, I>
+ stack(Image<I>& ima1, Image<I>& ima2)
+ {
+ mln_precondition(exact(ima1).domain() = exact(ima2).domain());
+ metal::vec<2, I*> imas;
+ imas[0] = & exact(ima1);
+ imas[1] = & exact(ima2);
+ stack_image<2, I> tmp(imas);
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::value
1
0