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
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Handle const promotion for morphers.
* mln/core/internal/image_adaptor.hh (operator I): New.
(pset_): Remove; uncompatible with temporary pset.
(domain): Change sig.
* mln/core/inplace.hh: New.
* tests/line2d.cc: Augment; use inplace.
* mln/core/sub_image.hh: New.
* tests/sub_image.cc: New.
* mln/core/safe.hh (safe): New overload; const version.
(safe_image): Update.
(default_value): New.
(operator safe_image<const I>): New.
* tests/safe_image.cc: Augment.
* mln/core/queue_p.hh (push): Fix missing return.
* mln/core/internal/image_base.hh: Add doc.
* mln/core/pset_if_piter.hh (fixme): Remove include; useless.
* mln/core/vec_p_piter.hh: Likewise.
* mln/make/box2d: Change arg list (all min first).
* tests/to_image.cc: Update.
mln/core/image_if.hh | 10 ++
mln/core/inplace.hh | 63 ++++++++++++++++++
mln/core/internal/image_adaptor.hh | 19 +++--
mln/core/internal/image_base.hh | 27 +++++--
mln/core/pset_if_piter.hh | 1
mln/core/queue_p.hh | 1
mln/core/safe.hh | 62 +++++++++++++----
mln/core/sub_image.hh | 129 +++++++++++++++++++++++++++++++++++++
mln/core/vec_p_piter.hh | 1
mln/make/box2d.hh | 10 +-
tests/line2d.cc | 9 ++
tests/safe_image.cc | 30 +++++++-
tests/sub_image.cc | 53 +++++++++++++++
tests/to_image.cc | 4 -
14 files changed, 378 insertions(+), 41 deletions(-)
Index: tests/sub_image.cc
--- tests/sub_image.cc (revision 0)
+++ tests/sub_image.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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/sub_image.cc
+ *
+ * \brief Tests on mln::sub_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/level/fill.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(8, 8);
+ level::fill(ima, 0);
+ debug::println(ima);
+
+ level::fill(inplace(ima | make::box2d(1,1, 3,3)), 5);
+ level::fill(inplace(ima | make::box2d(4,4, 6,6)), 1);
+
+ debug::println(ima);
+}
Index: tests/line2d.cc
--- tests/line2d.cc (revision 1048)
+++ tests/line2d.cc (working copy)
@@ -33,10 +33,13 @@
#include <iterator>
#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/inplace.hh>
#include <mln/level/fill.hh>
#include <mln/level/compare.hh>
#include <mln/draw/line.hh>
+#include <mln/debug/println.hh>
int main()
@@ -56,4 +59,10 @@
level::paste(pw::cst(true) | l, ima2);
mln_assertion(ima2 = ima);
+
+ image2d_b<bool> ima3(10,10);
+ level::fill(ima3, false);
+ level::fill(inplace(ima3 | l), true);
+
+ mln_assertion(ima3 = ima);
}
Index: tests/to_image.cc
--- tests/to_image.cc (revision 1048)
+++ tests/to_image.cc (working copy)
@@ -47,9 +47,9 @@
{
using namespace mln;
- box2d box_3x3 = make::box2d(-1,+1, -1,+1);
+ box2d box_3x3 = make::box2d(-1,-1, +1,+1);
// ^^^^^ ^^^^^
- // rows cols
+ // from to
// center point
// V
Index: tests/safe_image.cc
--- tests/safe_image.cc (revision 1048)
+++ tests/safe_image.cc (working copy)
@@ -32,7 +32,6 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/safe.hh>
-#include <mln/level/paste.hh>
int main()
@@ -41,9 +40,30 @@
typedef image2d_b<int> I;
I ima(1, 1);
- safe_image<I> ima_ = safe(ima);
+ point2d
+ in = make::point2d(0, 0),
+ out = make::point2d(-999, -999);
+
+ {
+ safe_image<I> ima_ = safe(ima, 7);
+
+ ima_(in) = 51;
+ mln_assertion(ima_(in) = 51);
+
+ ima_(out) = 0;
+ mln_assertion(ima_(out) = 7);
+
+ // test "image_adaptor_<..>::operator I() const"
+ I ima2 = ima_;
+ const I ima3 = ima_;
+ }
+
+ {
+ safe_image<const I> ima_ = safe(ima, 7);
+
+ ima(in) = 51;
+ mln_assertion(ima_(in) = 51);
+ mln_assertion(ima_(out) = 7);
+ }
- point2d p = make::point2d(-5, -1);
- ima_(p) = 0;
- level::paste(ima, ima_);
}
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 1048)
+++ mln/core/image_if.hh (working copy)
@@ -66,6 +66,9 @@
typedef image_if<mln_ch_value(I,T), F> ret;
};
+ /// Const promotion via convertion.
+ operator image_if<const I, F>() const;
+
protected:
pset pset_;
@@ -110,6 +113,13 @@
return pset_;
}
+ template <typename I, typename F>
+ image_if<I,F>::operator image_if<const I, F>() const
+ {
+ image_if<const I, F> tmp(this->adaptee_, this->f_);
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/queue_p.hh
--- mln/core/queue_p.hh (revision 1048)
+++ mln/core/queue_p.hh (working copy)
@@ -196,6 +196,7 @@
vect_needs_update_ = true;
bb_needs_update_ = true;
}
+ return *this;
}
template <typename P>
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1048)
+++ mln/core/safe.hh (working copy)
@@ -37,14 +37,17 @@
// FIXME: Doc!
template <typename I>
- struct safe_image : public internal::image_adaptor_< I, safe_image<I> >
+ class safe_image : public internal::image_adaptor_< I, safe_image<I> >
{
- typedef internal::image_adaptor_< I, safe_image<I> > super;
+ typedef internal::image_adaptor_< I, safe_image<I> > super_;
+ public:
- safe_image(Image<I>& ima);
+ safe_image(I& ima, const mln_value(I)& default_value);
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
- mln_lvalue(I) operator()(const mln_psite(I)& p);
+
+ typedef typename super_::lvalue lvalue;
+ lvalue operator()(const mln_psite(I)& p);
template <typename U>
struct change_value
@@ -52,20 +55,33 @@
typedef safe_image<mln_ch_value(I, U)> ret;
};
+ /// Const promotion via convertion.
+ operator safe_image<const I>() const;
+
+ protected:
+ mln_value(I) default_value_;
};
template <typename I>
- safe_image<I> safe(Image<I>& ima);
+ safe_image<I> safe(Image<I>& ima,
+ mln_value(I) default_value = mln_value(I)());
+
+ template <typename I>
+ safe_image<const I> safe(const Image<I>& ima,
+ mln_value(I) default_value = mln_value(I)());
# ifndef MLN_INCLUDE_ONLY
+ // safe_image<I>
+
template <typename I>
- safe_image<I>::safe_image(Image<I>& ima)
- : super(exact(ima))
+ safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
+ : super_(exact(ima)),
+ default_value_(default_value)
{
}
@@ -73,26 +89,44 @@
mln_rvalue(I)
safe_image<I>::operator()(const mln_psite(I)& p) const
{
- static mln_value(I) tmp;
if (! this->owns_(p))
- return tmp;
+ return default_value_;
return this->adaptee_(p);
}
template <typename I>
- mln_lvalue(I)
+ typename safe_image<I>::lvalue
safe_image<I>::operator()(const mln_psite(I)& p)
{
- static mln_value(I) tmp;
+ static mln_value(I) forget_it_;
if (! this->owns_(p))
- return tmp;
+ // so default_value_ is returned but cannot be modified
+ return forget_it_ = default_value_;
return this->adaptee_(p);
}
template <typename I>
- safe_image<I> safe(Image<I>& ima)
+ safe_image<I>::operator safe_image<const I>() const
+ {
+ safe_image<const I> tmp(this->adaptee_, default_value_);
+ return tmp;
+ }
+
+ // safe
+
+ template <typename I>
+ safe_image<I> safe(Image<I>& ima,
+ mln_value(I) default_value)
+ {
+ safe_image<I> tmp(exact(ima), default_value);
+ return tmp;
+ }
+
+ template <typename I>
+ safe_image<const I> safe(const Image<I>& ima,
+ mln_value(I) default_value)
{
- safe_image<I> tmp(ima);
+ safe_image<const I> tmp(exact(ima), default_value);
return tmp;
}
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1048)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -78,7 +78,7 @@
bool owns_(const psite& p) const;
/// Give the definition domain.
- const S& domain() const;
+ const mln_pset(I)& domain() const;
/// Give the set of values.
const vset& values() const;
@@ -89,6 +89,8 @@
/// Read-write access of pixel value at point site \p p.
lvalue operator()(const psite& p);
+ /// Convertion to the underlying (adapted) image.
+ operator I() const;
protected:
I& adaptee_;
@@ -97,13 +99,17 @@
image_adaptor_(I& adaptee);
};
- // FIXME: image_const_adaptor_
-
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename E, typename S>
+ image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
+ : adaptee_(adaptee)
+ {
+ }
+
+ template <typename I, typename E, typename S>
bool image_adaptor_<I,E,S>::has_data() const
{
return adaptee_.has_data();
@@ -117,7 +123,7 @@
}
template <typename I, typename E, typename S>
- const S&
+ const mln_pset(I)&
image_adaptor_<I,E,S>::domain() const
{
mln_precondition(exact(this)->has_data());
@@ -148,9 +154,10 @@
}
template <typename I, typename E, typename S>
- image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
- : adaptee_(adaptee)
+ image_adaptor_<I,E,S>::operator I() const
{
+ mln_precondition(exact(this)->has_data());
+ return adaptee_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1048)
+++ mln/core/internal/image_base.hh (working copy)
@@ -43,6 +43,11 @@
{
+ /*! \brief Return the lvalue type when an image with type \c I is
+ * morphed.
+ *
+ * \internal
+ */
template <typename I>
struct morpher_lvalue_
{
@@ -56,7 +61,10 @@
};
-
+ /*! \brief Selector for image inheritance (fast or regular).
+ *
+ * \internal
+ */
template <typename Is_fast, typename E>
struct select_image_concept_;
@@ -77,7 +85,9 @@
* \internal
*/
template <typename S, typename E>
- struct image_base_ : public select_image_concept_< typename trait::is_fast<E>::ret,
+ struct image_base_
+
+ : public select_image_concept_< typename trait::is_fast<E>::ret,
E >
{
/// Point_Set associated type.
@@ -113,6 +123,9 @@
/// Give the number of points of the image domain.
std::size_t npoints() const;
+
+ // FIXME: Add owns_(p) based on has(p)?
+
protected:
image_base_();
};
@@ -121,6 +134,11 @@
# ifndef MLN_INCLUDE_ONLY
template <typename S, typename E>
+ image_base_<S,E>::image_base_()
+ {
+ }
+
+ template <typename S, typename E>
bool
image_base_<S,E>::has(const psite& p) const
{
@@ -144,11 +162,6 @@
return exact(this)->domain().npoints();
}
- template <typename S, typename E>
- image_base_<S,E>::image_base_()
- {
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
Index: mln/core/sub_image.hh
--- mln/core/sub_image.hh (revision 0)
+++ mln/core/sub_image.hh (revision 0)
@@ -0,0 +1,129 @@
+// 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_SUB_IMAGE_HH
+# define MLN_CORE_SUB_IMAGE_HH
+
+# include <mln/core/internal/image_adaptor.hh>
+
+
+namespace mln
+{
+
+ // FIXME: Doc!
+
+ template <typename I, typename S>
+ class sub_image : public internal::image_adaptor_< I,
+ sub_image<I,S>,
+ S >
+ {
+ typedef internal::image_adaptor_<I, sub_image<I,S>, S> super_;
+ public:
+
+ sub_image(I& ima, const S& pset);
+
+ bool owns_(const mln_psite(I)& p) const;
+
+ template <typename U>
+ struct change_value
+ {
+ typedef internal::fixme ret;
+ };
+
+ const S& domain() const;
+
+ /// Const promotion via convertion.
+ operator sub_image<const I, S>() const;
+
+ protected:
+ const S& pset_;
+ };
+
+
+
+ template <typename I, typename S>
+ sub_image<const I, S> operator|(const Image<I>& ima, const Point_Set<S>& pset);
+
+ template <typename I, typename S>
+ sub_image<I, S> operator|(Image<I>& ima, const Point_Set<S>& pset);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename S>
+ sub_image<I,S>::sub_image(I& ima, const S& pset)
+ : super_(ima),
+ pset_(pset)
+ {
+ }
+
+ template <typename I, typename S>
+ bool
+ sub_image<I,S>::owns_(const mln_psite(I)& p) const
+ {
+ return this->domain().has(p);
+ }
+
+ template <typename I, typename S>
+ const S&
+ sub_image<I,S>::domain() const
+ {
+ return pset_;
+ }
+
+ template <typename I, typename S>
+ sub_image<I,S>::operator sub_image<const I, S>() const
+ {
+ sub_image<const I, S> tmp(this->adaptee_, this->pset_);
+ return tmp;
+ }
+
+ // operator
+
+ template <typename I, typename S>
+ sub_image<const I, S>
+ operator|(const Image<I>& ima, const Point_Set<S>& pset)
+ {
+ sub_image<const I, S> tmp(exact(ima), exact(pset));
+ return tmp;
+ }
+
+ template <typename I, typename S>
+ sub_image<I, S>
+ operator|(Image<I>& ima, const Point_Set<S>& pset)
+ {
+ sub_image<I, S> tmp(exact(ima), exact(pset));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SUB_IMAGE_HH
Index: mln/core/pset_if_piter.hh
--- mln/core/pset_if_piter.hh (revision 1048)
+++ mln/core/pset_if_piter.hh (working copy)
@@ -35,7 +35,6 @@
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/internal/piter_adaptor.hh>
-# include <mln/core/internal/fixme.hh>
# include <mln/core/pset_if.hh>
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1048)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -34,7 +34,6 @@
*/
# include <mln/core/vec_p.hh>
-# include <mln/core/internal/fixme.hh>
namespace mln
Index: mln/core/inplace.hh
--- mln/core/inplace.hh (revision 0)
+++ mln/core/inplace.hh (revision 0)
@@ -0,0 +1,63 @@
+// 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_INPLACE_HH
+# define MLN_CORE_INPLACE_HH
+
+/*! \file mln/core/inplace.hh
+ * \brief Definition of the mln::inplace routine.
+ */
+
+# include <mln/core/exact.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Routine to make temporary objects become mutable.
+ *
+ * \warning This routine is not safe! FIXME: Explain.
+ */
+ template <typename E>
+ E& inplace(const Object<E>& temp);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ E& inplace(const Object<E>& temp)
+ {
+ return const_cast<E&>( exact(temp) );
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INPLACE_HH
Index: mln/make/box2d.hh
--- mln/make/box2d.hh (revision 1048)
+++ mln/make/box2d.hh (working copy)
@@ -60,16 +60,16 @@
* \overload
*
* \param[in] min_row Index of the top most row.
- * \param[in] max_row Index of the botton most row.
* \param[in] min_col Index of the left most column.
+ * \param[in] max_row Index of the botton most row.
* \param[in] max_col Index of the right most column.
*
* \pre \p max_row >= \p min_row and \p max_col >= \p min_col.
*
* \return A 2D box.
*/
- mln::box2d box2d(int min_row, int max_row,
- int min_col, int max_col);
+ mln::box2d box2d(int min_row, int min_col,
+ int max_row, int max_col);
# ifndef MLN_INCLUDE_ONLY
@@ -82,8 +82,8 @@
return tmp;
}
- mln::box2d box2d(int min_row, int max_row,
- int min_col, int max_col)
+ mln::box2d box2d(int min_row, int min_col,
+ int max_row, int max_col)
{
mln_precondition(max_row >= min_row && max_col >= min_col);
mln::box2d tmp(make::point2d(min_row, min_col),
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Renaming.
* mln/core/fimage.hh,
* tests/fimage.cc: Rename as...
* mln/pw/image.hh,
* tests/pw_image.cc: ...these.
* mln/pw/all.hh,
* mln/draw/line.hh,
* tests/line2d.cc: Update.
* mln/core/pqueue.hh,
* mln/core/pvec.hh,
* mln/core/pvec_piter.hh,
* mln/core/pset.hh,
* tests/pqueue.cc,
* tests/pset.cc: Rename as...
* mln/core/queue_p.hh,
* mln/core/vec_p.hh,
* mln/core/vec_p_piter.hh,
* mln/core/set_p.hh,
* tests/queue_p.cc,
* tests/set_p.cc: ...these.
* mln/core/line2d.hh: Update.
* mln/core/psubset.hh,
* mln/core/psubset_piter.hh,
* mln/core/subimage.hh,
* tests/psubset.cc,
* tests/subimage.cc: Rename as...
* mln/core/pset_if.hh,
* mln/core/pset_if_piter.hh,
* mln/core/image_if.hh,
* tests/pset_if.cc,
* tests/image_if.cc: ...these.
* tests/to_image.cc: Update.
* mln/accu/counter.hh: Rename as...
* mln/accu/count.hh: ...this.
* mln/accu/count.hh,
* mln/accu/mean.hh,
* mln/accu/sum.hh (operator+=): New.
* mln/value/props.hh (mln_sum, sum): New.
* mln/accu/mean.hh,
* mln/accu/sum.hh,
* mln/value/int_u.hh,
* mln/value/int_s.hh: Update.
* mln/level/apply.hh: Move accumulator version into...
* mln/level/take.hh: ...this new file.
* mln/level/run.hh: New.
* mln/estim/mean.hh: Update.
* mln/core/internal/set_of.hh (operator=): Remove;
too error-prone.
* mln/core/concept/window.hh (operator=): New.
* tests/rectangle2d.cc: Fix.
mln/accu/count.hh | 119 ++++++++++++++++++++
mln/accu/mean.hh | 26 +++-
mln/accu/sum.hh | 19 ++-
mln/core/concept/window.hh | 28 ++++
mln/core/image_if.hh | 118 ++++++++++++++++++++
mln/core/internal/set_of.hh | 22 ---
mln/core/line2d.hh | 6 -
mln/core/pset_if.hh | 191 +++++++++++++++++++++++++++++++++
mln/core/pset_if_piter.hh | 125 +++++++++++++++++++++
mln/core/queue_p.hh | 253 ++++++++++++++++++++++++++++++++++++++++++++
mln/core/set_p.hh | 162 ++++++++++++++++++++++++++++
mln/core/vec_p.hh | 208 ++++++++++++++++++++++++++++++++++++
mln/core/vec_p_piter.hh | 172 +++++++++++++++++++++++++++++
mln/draw/line.hh | 30 +----
mln/estim/mean.hh | 28 +---
mln/level/apply.hh | 51 ++++----
mln/level/run.hh | 79 +++++++++++++
mln/level/take.hh | 102 +++++++++++++++++
mln/pw/all.hh | 1
mln/pw/image.hh | 192 +++++++++++++++++++++++++++++++++
mln/value/int_s.hh | 1
mln/value/int_u.hh | 1
mln/value/props.hh | 13 ++
tests/image_if.cc | 46 ++++++++
tests/line2d.cc | 7 -
tests/mean.cc | 53 +++++++++
tests/pset_if.cc | 45 +++++++
tests/pw_image.cc | 44 +++++++
tests/queue_p.cc | 57 +++++++++
tests/rectangle2d.cc | 2
tests/set_p.cc | 59 ++++++++++
tests/to_image.cc | 2
32 files changed, 2152 insertions(+), 110 deletions(-)
Index: tests/set_p.cc
--- tests/set_p.cc (revision 0)
+++ tests/set_p.cc (revision 0)
@@ -0,0 +1,59 @@
+// 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/set_p.cc
+ *
+ * \brief Tests on mln::set_p.
+ */
+
+#include <iterator>
+
+#include <mln/core/point2d.hh>
+#include <mln/core/set_p.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ set_p<point2d> ps;
+ ps
+ .insert(make::point2d(6, 9))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(5, 1));
+ mln_assertion(ps.npoints() = 3);
+
+ std::cout << ps.bbox() << std::endl;
+
+ std::copy(ps.vect().begin(), ps.vect().end(),
+ std::ostream_iterator<point2d>(std::cout, " "));
+ std::cout << std::endl;
+
+
+}
Index: tests/line2d.cc
--- tests/line2d.cc (revision 1047)
+++ tests/line2d.cc (working copy)
@@ -35,13 +35,8 @@
#include <mln/core/image2d_b.hh>
#include <mln/level/fill.hh>
-#include <mln/draw/line.hh>
-#include <mln/debug/println.hh>
-
-#include <mln/core/fimage.hh>
-#include <mln/pw/cst.hh>
-#include <mln/level/paste.hh>
#include <mln/level/compare.hh>
+#include <mln/draw/line.hh>
int main()
Index: tests/mean.cc
--- tests/mean.cc (revision 0)
+++ tests/mean.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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/assign.cc
+ *
+ * \brief Tests on mln::level::assign.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/estim/mean.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d_b<int_u8> ima(3, 3);
+ debug::iota(ima);
+ // 1 2 3
+ // 4 5 6
+ // 7 8 9
+ mln_assertion(estim::mean(ima) = 5);
+
+ // FIXME: Add example on accu::mean used several times.
+}
Index: tests/to_image.cc
--- tests/to_image.cc (revision 1047)
+++ tests/to_image.cc (working copy)
@@ -32,7 +32,7 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/window2d.hh>
-#include <mln/core/psubset.hh>
+#include <mln/core/pset_if.hh>
#include <mln/fun/p2b/chess.hh>
#include <mln/level/compare.hh>
Index: tests/pw_image.cc
--- tests/pw_image.cc (revision 0)
+++ tests/pw_image.cc (revision 0)
@@ -0,0 +1,44 @@
+// 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/fimage.cc
+ *
+ * \brief Tests on mln::fimage.
+ */
+
+#include <mln/fun/p2b/chess.hh>
+#include <mln/core/box2d.hh>
+#include <mln/pw/image.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ debug::println( fun::p2b::chess | make::box2d(8, 8) );
+}
Index: tests/rectangle2d.cc
--- tests/rectangle2d.cc (revision 1047)
+++ tests/rectangle2d.cc (working copy)
@@ -44,6 +44,6 @@
mln_assertion(rec.is_centered());
mln_assertion(rec.is_symmetric());
mln_assertion(rec = -rec);
- mln_assertion(rec.nelements() = h * w);
+ mln_assertion(rec.ndpoints() = h * w);
}
Index: tests/image_if.cc
--- tests/image_if.cc (revision 0)
+++ tests/image_if.cc (revision 0)
@@ -0,0 +1,46 @@
+// 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/image_if.cc
+ *
+ * \brief Tests on mln::image_if.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(8, 8);
+ // debug::println(ima | fun::p2b::chess);
+ mln_assertion((ima | fun::p2b::chess).npoints() = 32);
+}
Index: tests/queue_p.cc
--- tests/queue_p.cc (revision 0)
+++ tests/queue_p.cc (revision 0)
@@ -0,0 +1,57 @@
+// 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/queue_p.cc
+ *
+ * \brief Tests on mln::queue_p.
+ */
+
+#include <mln/core/point2d.hh>
+#include <mln/core/queue_p.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ queue_p<point2d> q;
+ q
+ .push(make::point2d(6, 9))
+ .push(make::point2d(5, 1))
+ .push(make::point2d(4, 2));
+ mln_assertion(q.npoints() = 3);
+
+ std::cout << q.bbox() << std::endl;
+ std::cout << q << std::endl;
+
+ q.pop();
+ mln_assertion(q.npoints() = 2);
+ point2d p = q.front();
+ mln_assertion(q.npoints() = 2);
+ mln_assertion(p = make::point2d(5, 1));
+}
Index: tests/pset_if.cc
--- tests/pset_if.cc (revision 0)
+++ tests/pset_if.cc (revision 0)
@@ -0,0 +1,45 @@
+// 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/pset_if.cc
+ *
+ * \brief Tests on mln::pset_if.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/pset_if.hh>
+#include <mln/fun/p2b/chess.hh>
+#include <mln/convert/to_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d box_8x8 = make::box2d(8, 8);
+ mln_assertion((box_8x8 | fun::p2b::chess).npoints() = 32);
+}
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1047)
+++ mln/estim/mean.hh (working copy)
@@ -33,8 +33,8 @@
* \brief Compute the mean pixel value.
*/
-# include <mln/core/concept/image.hh>
# include <mln/accu/mean.hh>
+# include <mln/level/run.hh>
namespace mln
@@ -43,32 +43,22 @@
namespace estim
{
-
/*! \brief Compute the mean value of the pixels of image \p input.
*
- * Parameter \c S is the type of the mean value.
+ * \param[in] input The image.
*/
- template <typename S, typename I>
- S mean(const Image<I>& input);
-
+ template <typename I>
+ mln_sum(mln_value(I)) mean(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
- template <typename S, typename I>
- S
- mean(const Image<I>& input_)
+ template <typename I>
+ mln_sum(mln_value(I)) mean(const Image<I>& input)
{
- const I& input = exact(input_);
- mln_precondition(input.has_data());
-
- accu::mean<mln_value(I), S> m;
-
- mln_piter(I) p(input.domain());
- for_all(p)
- m.take(input(p));
-
- return m;
+ typedef mln_value(I) V;
+ typedef mln_sum(V) S;
+ return level::run(input, accu::mean<V, S>());
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/pw/image.hh
--- mln/pw/image.hh (revision 0)
+++ mln/pw/image.hh (revision 0)
@@ -0,0 +1,192 @@
+// 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_PW_IMAGE_HH
+# define MLN_PW_IMAGE_HH
+
+/*! \file mln/pw/image.hh
+ *
+ * \brief Definition of an image class FIXME
+ */
+
+# include <mln/core/internal/image_base.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ namespace pw { template <typename F, typename S> struct image; }
+
+
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename F, typename S>
+ pw::image<F,S>
+ operator | (const Function_p2v<F>& f, const Point_Set<S>& ps);
+
+
+
+ namespace pw
+ {
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename F, typename S>
+ struct image : public internal::image_base_< S, image<F,S> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point_Set associated type.
+ typedef S pset;
+
+ /// Value associated type.
+ typedef mln_result(F) value;
+
+ /// Return type of read-only access.
+ typedef mln_result(F) rvalue;
+
+ /// Return type of read-write access.
+ typedef void lvalue; // FIXME
+
+ /// Value set associated type.
+ typedef mln::value::set<mln_result(F)> vset;
+
+
+ /// Constructor.
+ image(const Function_p2v<F>& f, const Point_Set<S>& ps);
+
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const psite& p) const;
+
+ /// Give the definition domain.
+ const S& domain() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_result(F) operator()(const psite& p) const;
+
+ /// Read-write access is present but disabled.
+ void operator()(const psite&);
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Change value type. FIXME!
+ template <typename U>
+ struct change_value
+ {
+ typedef void ret;
+ };
+
+ protected:
+ F f_;
+ S pset_;
+ };
+
+ } // end of namespace mln::pw
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename F, typename S>
+ pw::image<F,S>
+ operator | (const Function_p2v<F>& f, const Point_Set<S>& ps)
+ {
+ pw::image<F,S> tmp(f, ps);
+ return tmp;
+ }
+
+ namespace pw
+ {
+
+ template <typename F, typename S>
+ image<F,S>::image(const Function_p2v<F>& f, const Point_Set<S>& ps)
+ : f_(exact(f)),
+ pset_(exact(ps))
+ {
+ }
+
+ template <typename F, typename S>
+ bool image<F,S>::has_data() const
+ {
+ return true;
+ }
+
+ template <typename F, typename S>
+ bool image<F,S>::owns_(const psite& p) const
+ {
+ return pset_.has(p);
+ }
+
+ template <typename F, typename S>
+ const S&
+ image<F,S>::domain() const
+ {
+ return pset_;
+ }
+
+ template <typename F, typename S>
+ mln_result(F)
+ image<F,S>::operator()(const psite& p) const
+ {
+ mln_precondition(pset_.has(p));
+ return f_(p);
+ }
+
+ template <typename F, typename S>
+ void
+ image<F,S>::operator()(const psite&)
+ {
+ mln_invariant(0); // FIXME: Turn into a compile-time error...
+ }
+
+ template <typename F, typename S>
+ const mln::value::set<mln_result(F)>&
+ image<F,S>::values() const
+ {
+ return vset::the();
+ }
+
+ } // end of namespace mln::pw
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_PW_IMAGE_HH
Index: mln/pw/all.hh
--- mln/pw/all.hh (revision 1047)
+++ mln/pw/all.hh (working copy)
@@ -47,6 +47,7 @@
# include <mln/pw/value.hh>
# include <mln/pw/cst.hh>
# include <mln/pw/var.hh>
+# include <mln/pw/image.hh>
# include <mln/fun/ops.hh>
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 0)
+++ mln/core/image_if.hh (revision 0)
@@ -0,0 +1,118 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_IMAGE_IF_HH
+# define MLN_CORE_IMAGE_IF_HH
+
+/*! \file mln/core/image_if.hh
+ *
+ * \brief Definition of a base class for image adaptors.
+ */
+
+# include <mln/core/internal/image_adaptor.hh>
+# include <mln/core/pset_if.hh>
+
+
+namespace mln
+{
+
+ /*! \brief A base class for image adaptors.
+ *
+ */
+ template <typename I, typename F>
+ struct image_if : public internal::image_adaptor_< I,
+ image_if<I,F>,
+ pset_if<mln_pset(I),F> >
+ {
+ /// Point_Set associated type.
+ typedef pset_if<mln_pset(I), F> pset;
+
+ /// Constructor from an \p adaptee image.
+ image_if(I& adaptee, const F& f);
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_psite(I)& p) const;
+
+ /// Give the definition domain.
+ const pset& domain() const;
+
+ template <typename T>
+ struct change_value
+ {
+ typedef image_if<mln_ch_value(I,T), F> ret;
+ };
+
+ protected:
+
+ pset pset_;
+ F f_;
+
+ typedef image_if<I,F> self_;
+ typedef internal::image_adaptor_< I, self_, pset > super_;
+ };
+
+
+
+ template <typename I, typename F>
+ image_if<I, F>
+ operator | (Image<I>& ima, const Function_p2b<F>& f)
+ {
+ image_if<I, F> tmp(exact(ima), exact(f));
+ return tmp;
+ }
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename F>
+ image_if<I,F>::image_if(I& adaptee, const F& f)
+ : super_(adaptee),
+ pset_(adaptee.domain() | f),
+ f_(f)
+ {
+ }
+
+ template <typename I, typename F>
+ bool
+ image_if<I,F>::owns_(const mln_psite(I)& p) const
+ {
+ return pset_.has(p);
+ }
+
+ template <typename I, typename F>
+ const pset_if<mln_pset(I), F>&
+ image_if<I,F>::domain() const
+ {
+ return pset_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_IF_HH
Index: mln/core/queue_p.hh
--- mln/core/queue_p.hh (revision 0)
+++ mln/core/queue_p.hh (revision 0)
@@ -0,0 +1,253 @@
+// 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_QUEUE_P_HH
+# define MLN_CORE_QUEUE_P_HH
+
+/*! \file mln/core/queue_p.hh
+ *
+ * \brief Definition of a point set class based on std::deque.
+ */
+
+# include <vector>
+# include <deque>
+# include <algorithm>
+# include <iterator>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/vec_p_piter.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct vec_p_fwd_piter_;
+ template <typename P> struct vec_p_bkd_piter_;
+
+
+ /*! \brief Point queue class (based on std::deque).
+ *
+ * This is a mathematical set of points (unique insertion).
+ *
+ * \todo Make it work with P being a Point_Site.
+ * \todo Add a parameter flag to choose another policy for "push"
+ * (i.e., no-op if multiple or allow multiple insertions).
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints() when this container is multiple.
+ */
+ template <typename P>
+ class queue_p : public Point_Set< queue_p<P> >
+ {
+ public:
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ queue_p();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Push a point \p p in the queue.
+ queue_p<P>& push(const P& p);
+
+ /// Pop (remove) the front point \p p from the queue; \p p is the
+ /// least recently inserted point.
+ void pop();
+
+ /// Give the front point \p p of the queue; \p p is the least
+ /// recently inserted point.
+ const P& front() const;
+
+ /// Clear the queue.
+ void clear();
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<P>& vect() const;
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ protected:
+
+ std::deque<P> q_;
+
+ mutable std::vector<P> vect_;
+ mutable bool vect_needs_update_;
+ void vect_update_() const;
+
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+ void bb_update_() const;
+
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ queue_p<P>::queue_p()
+ {
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::vect_update_() const
+ {
+ vect_.clear();
+ vect_.reserve(q_.size());
+ std::copy(q_.begin(), q_.end(),
+ std::back_inserter(vect_));
+ vect_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::bb_update_() const
+ {
+ bb_.init();
+ for (unsigned i = 0; i < q_.size(); ++i)
+ bb_.take(q_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ queue_p<P>::has(const P& p) const
+ {
+ for (unsigned i = 0; i < q_.size(); ++i)
+ if (q_[i] = p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ std::size_t
+ queue_p<P>::npoints() const
+ {
+ return q_.size();
+ }
+
+ template <typename P>
+ const box_<P>&
+ queue_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ bb_update_();
+ return bb_.to_value();
+ }
+
+ template <typename P>
+ queue_p<P>&
+ queue_p<P>::push(const P& p)
+ {
+ mln_precondition(! has(p));
+ // FIXME: Our choice is "error if multiple insertions"
+ q_.push_back(p);
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::pop()
+ {
+ q_.pop_front();
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ const P&
+ queue_p<P>::front() const
+ {
+ mln_precondition(! q_.empty());
+ return q_.front();
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::clear()
+ {
+ q_.clear();
+ vect_.clear();
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ queue_p<P>::vect() const
+ {
+ if (vect_needs_update_)
+ vect_update_();
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ queue_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return q_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_QUEUE_P_HH
Index: mln/core/internal/set_of.hh
--- mln/core/internal/set_of.hh (revision 1047)
+++ mln/core/internal/set_of.hh (working copy)
@@ -173,16 +173,6 @@
std::ostream& operator<<(std::ostream& ostr, const set_of_<E>& s);
- /*! \brief Test if both sets \p lhs and \p rhs are equal.
- *
- * \param[in] lhs A set.
- * \param[in] rhs Another set.
- *
- * \relates mln::internal::set_of_
- */
- template <typename E>
- bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs);
-
# ifndef MLN_INCLUDE_ONLY
@@ -279,18 +269,6 @@
return ostr;
}
- template <typename E>
- bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs)
- {
- if (lhs.nelements() != rhs.nelements())
- return false;
- const unsigned n = lhs.nelements();
- for (unsigned i = 0; i < n; ++i)
- if (rhs.element(i) != lhs.element(i))
- return false;
- return true;
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
Index: mln/core/pset_if.hh
--- mln/core/pset_if.hh (revision 0)
+++ mln/core/pset_if.hh (revision 0)
@@ -0,0 +1,191 @@
+// 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_PSET_IF_HH
+# define MLN_CORE_PSET_IF_HH
+
+/*! \file mln/core/pset_if.hh
+ *
+ * \brief Definition of the restriction of a point set w.r.t. a predicate.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename S, typename F> struct pset_if;
+ template <typename S, typename F> struct pset_if_fwd_piter_;
+ template <typename S, typename F> struct pset_if_bkd_piter_;
+
+
+
+ /*! \brief Restrict a point set \p pset to points that verify \p f.
+ *
+ * \param[in] pset A point set.
+ * \param[in] f A function from point to Boolean.
+ * \return A subset of points.
+ */
+ template <typename S, typename F>
+ pset_if<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f);
+
+
+
+ /*! \brief Generic subset class.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ */
+ template <typename S, typename F>
+ struct pset_if : public Point_Set< pset_if<S,F> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point associated type.
+ typedef mln_point(S) point;
+
+
+ /// Forward Point_Iterator associated type.
+ typedef pset_if_fwd_piter_<S,F> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef internal::fixme bkd_piter;
+
+
+ /// Constructor without argument.
+ pset_if(const S& pset, const F& f);
+
+
+ /// Test if \p p belongs to the subset.
+ bool has(const psite& p) const;
+
+ /// Give a bounding box of the subset.
+ const box_<point>& bbox() const;
+
+ /// Give the number of points of the subset.
+ std::size_t npoints() const;
+
+ /// Give the primary overset.
+ const S& overset() const;
+
+ /// Test predicate on point site \p p.
+ bool pred(const psite& p) const;
+
+ protected:
+
+ const S& pset_;
+ F f_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename S, typename F>
+ pset_if<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f)
+ {
+ pset_if<S, F> tmp(exact(pset), exact(f));
+ return tmp;
+ }
+
+
+ // pset_if<S,F>
+
+ template <typename S, typename F>
+ bool
+ pset_if<S,F>::has(const psite& p) const
+ {
+ return pset_.has(p) && f_(p);
+ }
+
+ template <typename S, typename F>
+ const box_<mln_point(S)>&
+ pset_if<S,F>::bbox() const
+ {
+ return pset_.bbox();
+ }
+
+ template <typename S, typename F>
+ const S&
+ pset_if<S,F>::overset() const
+ {
+ return pset_;
+ }
+
+ template <typename S, typename F>
+ bool
+ pset_if<S,F>::pred(const psite& p) const
+ {
+ return f_(p);
+ }
+
+ template <typename S, typename F>
+ pset_if<S,F>::pset_if(const S& pset, const F& f)
+ : pset_(pset),
+ f_(f)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+# include <mln/core/pset_if_piter.hh>
+
+
+
+namespace mln
+{
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ std::size_t
+ pset_if<S,F>::npoints() const
+ {
+ std::size_t n = 0;
+ fwd_piter p(*this);
+ for_all(p)
+ ++n;
+ return n;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSET_IF_HH
Index: mln/core/pset_if_piter.hh
--- mln/core/pset_if_piter.hh (revision 0)
+++ mln/core/pset_if_piter.hh (revision 0)
@@ -0,0 +1,125 @@
+// 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_PSET_IF_PITER_HH
+# define MLN_CORE_PSET_IF_PITER_HH
+
+/*! \file mln/core/pset_if_piter.hh
+ *
+ * \brief Definition of iterators on points of pset_ifes.
+ */
+
+# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/piter_adaptor.hh>
+# include <mln/core/internal/fixme.hh>
+# include <mln/core/pset_if.hh>
+
+
+namespace mln
+{
+
+ /*! \brief A generic forward iterator on points of subsets.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ *
+ * \see mln::pset_if
+ */
+ template <typename S, typename F>
+ class pset_if_fwd_piter_
+ : public internal::piter_adaptor_< mln_fwd_piter(S),
+ pset_if_fwd_piter_<S,F> >
+ {
+ typedef mln_fwd_piter(S) adaptee_;
+ typedef pset_if_fwd_piter_<S,F> self_;
+ typedef internal::piter_adaptor_<adaptee_, self_> super_;
+
+ public:
+
+ /// Constructor from a subset of points.
+ pset_if_fwd_piter_(const pset_if<S,F>& subset);
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ private:
+
+ const pset_if<S,F>& subset_;
+ };
+
+
+ // FIXME:
+ template <typename S, typename F>
+ class pset_if_bkd_piter_
+ : public internal::fixme
+ {};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // pset_if_fwd_piter_<S,F>
+
+ template <typename S, typename F>
+ pset_if_fwd_piter_<S,F>::pset_if_fwd_piter_(const pset_if<S,F>& subset)
+ : super_(adaptee_(subset.overset())),
+ subset_(subset)
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ pset_if_fwd_piter_<S,F>::start()
+ {
+ this->piter_.start();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_))
+ this->piter_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ pset_if_fwd_piter_<S,F>::next_()
+ {
+ do
+ this->piter_.next();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_));
+ }
+
+
+ // FIXME: pset_if_bkd_piter_<S,F>
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSET_IF_PITER_HH
Index: mln/core/vec_p.hh
--- mln/core/vec_p.hh (revision 0)
+++ mln/core/vec_p.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_VEC_P_HH
+# define MLN_CORE_VEC_P_HH
+
+/*! \file mln/core/vec_p.hh
+ *
+ * \brief Definition of a point set class based on std::vector.
+ */
+
+# include <vector>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct vec_p_fwd_piter_;
+ template <typename P> struct vec_p_bkd_piter_;
+
+
+ /*! \brief Point set class based on std::vector.
+ *
+ * This is a multi-set of points.
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints(). FIXME: Explain!
+ *
+ * \todo Make it work with P being a Point_Site.
+ */
+ template <typename P>
+ class vec_p : public Point_Set< vec_p<P> >
+ {
+ public:
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ vec_p();
+
+ /// Constructor from a vector \p vect.
+ vec_p(const std::vector<P>& vect);
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Append a point \p p.
+ vec_p<P>& append(const P& p);
+
+ /// Clear this set.
+ void clear();
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<P>& vect() const;
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ protected:
+
+ std::vector<P> vect_;
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+
+ void update_bb_() const;
+ // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ vec_p<P>::vec_p()
+ {
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ vec_p<P>::vec_p(const std::vector<P>& vect)
+ : vect_(vect)
+ {
+ bb_needs_update_ = true;
+ }
+
+ template <typename P>
+ void
+ vec_p<P>::update_bb_() const
+ {
+ bb_.init();
+ for (unsigned i = 0; i < vect_.size(); ++i)
+ bb_.take(vect_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ vec_p<P>::has(const P& p) const
+ {
+ for (unsigned i = 0; i < vect_.size(); ++i)
+ if (vect_[i] = p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ std::size_t
+ vec_p<P>::npoints() const
+ {
+ return vect_.size();
+ }
+
+ template <typename P>
+ const box_<P>&
+ vec_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ update_bb_();
+ return bb_.to_value();
+ }
+
+ template <typename P>
+ vec_p<P>&
+ vec_p<P>::append(const P& p)
+ {
+ vect_.push_back(p);
+ if (! bb_needs_update_)
+ bb_needs_update_ = true;
+ return *this;
+ }
+
+ template <typename P>
+ void
+ vec_p<P>::clear()
+ {
+ vect_.clear();
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ vec_p<P>::vect() const
+ {
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ vec_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return vect_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+# include <mln/core/vec_p_piter.hh>
+
+
+#endif // ! MLN_CORE_VEC_P_HH
Index: mln/core/concept/window.hh
--- mln/core/concept/window.hh (revision 1047)
+++ mln/core/concept/window.hh (working copy)
@@ -77,6 +77,14 @@
W operator-(const Window<W>& rhs);
+ /*! \brief Equality comparison between windows \p lhs and \p rhs.
+ *
+ * \relates mln::Window
+ */
+ template <typename Wl, typename Wr>
+ bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
@@ -107,6 +115,26 @@
return exact(rhs).sym_();
}
+ template <typename Wl, typename Wr>
+ bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs)
+ {
+ // FIXME: Same grid!
+ typedef mln_point(Wl) P;
+
+ mln_fwd_qiter(Wl) ql(exact(lhs), P::zero);
+ mln_fwd_qiter(Wr) qr(exact(rhs), P::zero);
+
+ for (ql.start(), qr.start();
+ ql.is_valid() && qr.is_valid();
+ ql.next(), qr.next())
+ if (ql != qr)
+ return false; // difference found
+
+ // both windows are equal only if both browsings are completed at
+ // the same time:
+ return ! ql.is_valid() && ! qr.is_valid();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 0)
+++ mln/core/vec_p_piter.hh (revision 0)
@@ -0,0 +1,172 @@
+// 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_VEC_P_PITER_HH
+# define MLN_CORE_VEC_P_PITER_HH
+
+/*! \file mln/core/vec_p_piter.hh
+ *
+ * \brief Definition of point iterators on mln::vec_p.
+ */
+
+# include <mln/core/vec_p.hh>
+# include <mln/core/internal/fixme.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Forward iterator on points of a vec_p<P>.
+ *
+ */
+ template <typename P>
+ struct vec_p_fwd_piter_ : public Point_Iterator< vec_p_fwd_piter_<P> >
+ {
+ enum { dim = P::dim };
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(P) dpoint;
+
+ /// Coordinate associated type.
+ typedef mln_coord(P) coord;
+
+ /// Coordinate associated type.
+ template <typename S>
+ vec_p_fwd_piter_(const Point_Set<S>& s);
+
+ /// Give a hook to the point address.
+ const P* pointer_() const;
+
+ /// Read-only access to the \p i-th coordinate.
+ coord operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convert the iterator into a point.
+ operator P() const;
+
+ protected:
+ const std::vector<P>& vect_;
+ unsigned i_;
+ P p_;
+ };
+
+
+
+ // FIXME:
+ template <typename P>
+ struct vec_p_bkd_piter_ : internal::fixme
+ {};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ template <typename S>
+ vec_p_fwd_piter_<P>::vec_p_fwd_piter_(const Point_Set<S>& s)
+ : vect_(exact(s).vect())
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ const P*
+ vec_p_fwd_piter_<P>::pointer_() const
+ {
+ return & p_;
+ }
+
+ template <typename P>
+ mln_coord(P)
+ vec_p_fwd_piter_<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ mln_precondition(is_valid());
+ return p_[i];
+ }
+
+ template <typename P>
+ bool
+ vec_p_fwd_piter_<P>::is_valid() const
+ {
+ return i_ < vect_.size();
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::invalidate()
+ {
+ i_ = vect_.size();
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::start()
+ {
+ i_ = 0;
+ if (is_valid())
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::next_()
+ {
+ ++i_;
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ vec_p_fwd_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_VEC_P_PITER_HH
Index: mln/core/set_p.hh
--- mln/core/set_p.hh (revision 0)
+++ mln/core/set_p.hh (revision 0)
@@ -0,0 +1,162 @@
+// 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_SET_P_HH
+# define MLN_CORE_SET_P_HH
+
+/*! \file mln/core/set_p.hh
+ *
+ * \brief Definition of a point set class based on std::set.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/set_of.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/core/vec_p.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Point set class based on std::set.
+ *
+ * This is a mathematical set of points (not a multi-set). The
+ * parameter \p P shall be a Point type.
+ *
+ * \todo Test if \p P being a Point_Site is ok.
+ */
+ template <typename P>
+ class set_p : public Point_Set< set_p<P> >,
+ private internal::set_of_<P>
+ {
+ typedef internal::set_of_<P> super_;
+
+ public:
+
+ /// Point associated type.
+ typedef mln_point(P) point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ set_p();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Return the corresponding std::vector of points.
+ using super_::vect;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Insert a point \p p.
+ set_p<P>& insert(const P& p);
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ /// Clear this set.
+ void clear();
+
+ /// Give the exact bounding box.
+ const box_<point>& bbox() const;
+
+ protected:
+
+ accu::bbox<P> bb_;
+ // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ set_p<P>::set_p()
+ {
+ }
+
+ template <typename P>
+ bool
+ set_p<P>::has(const P& p) const
+ {
+ return this->super_::has(p);
+ }
+
+ template <typename P>
+ std::size_t
+ set_p<P>::npoints() const
+ {
+ return this->super_::nelements();
+ }
+
+ template <typename P>
+ set_p<P>&
+ set_p<P>::insert(const P& p)
+ {
+ this->super_::insert(p);
+ bb_.take(p);
+ return *this;
+ }
+
+ template <typename P>
+ const P&
+ set_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return this->super_::element(i);
+ }
+
+ template <typename P>
+ void
+ set_p<P>::clear()
+ {
+ this->super_::clear();
+ bb_.init();
+ }
+
+ template <typename P>
+ const box_<mln_point(P)>&
+ set_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ return bb_.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SET_P_HH
Index: mln/core/line2d.hh
--- mln/core/line2d.hh (revision 1047)
+++ mln/core/line2d.hh (working copy)
@@ -36,7 +36,7 @@
# include <vector>
# include <mln/core/concept/point_set.hh>
-# include <mln/core/pvec_piter.hh>
+# include <mln/core/vec_p_piter.hh>
# include <mln/core/box2d.hh>
# include <mln/math/all.hh>
@@ -58,10 +58,10 @@
typedef point2d psite;
/// Forward Point_Iterator associated type.
- typedef pvec_fwd_piter_<point2d> fwd_piter;
+ typedef vec_p_fwd_piter_<point2d> fwd_piter;
/// Backward Point_Iterator associated type.
- typedef pvec_bkd_piter_<point2d> bkd_piter;
+ typedef vec_p_bkd_piter_<point2d> bkd_piter;
/// Constructor from point \p beg to point \p end.
Index: mln/draw/line.hh
--- mln/draw/line.hh (revision 1047)
+++ mln/draw/line.hh (working copy)
@@ -35,6 +35,9 @@
# include <mln/core/concept/image.hh>
# include <mln/core/line2d.hh>
+# include <mln/level/paste.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
namespace mln
@@ -43,7 +46,8 @@
namespace draw
{
- /// Draw a line at level \p v in image \p ima between the points \p beg and \p end.
+ /// Draw a line at level \p v in image \p ima between the points
+ /// \p beg and \p end.
template <typename I>
void line(Image<I>& ima,
const mln_point(I)& beg, const mln_point(I)& end,
@@ -52,27 +56,6 @@
# ifndef MLN_INCLUDE_ONLY
- namespace impl
- {
-
- template <typename I>
- void line(I& ima,
- const point2d& beg, const point2d& end,
- const mln_value(I)& v)
- {
- line2d l(beg, end);
- mln_piter(line2d) p(l);
- for_all(p)
- ima(p) = v;
- }
-
- // FIXME: Overload.
-
- } // end of namespace mln::draw::impl
-
-
- // Facade.
-
template <typename I>
void line(Image<I>& ima,
const mln_point(I)& beg, const mln_point(I)& end,
@@ -80,7 +63,8 @@
{
mln_precondition(exact(ima).has_data());
mln_precondition(exact(ima).has(beg) && exact(ima).has(end));
- impl::line(exact(ima), beg, end, v);
+ level::paste(pw::cst(v) | line2d(beg, end),
+ ima);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/take.hh
--- mln/level/take.hh (revision 0)
+++ mln/level/take.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_LEVEL_TAKE_HH
+# define MLN_LEVEL_TAKE_HH
+
+/*! \file mln/level/take.hh
+ *
+ * \brief Make an accumulator take image pixel values.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Make an accumulator take the values of the image \p input.
+ *
+ * \param[in,out] a The accumulator.
+ * \param[in] input The input image.
+ *
+ * This routine runs: \n
+ * for all p of \p input, \p a.take( \p input(p) ) \n
+ *
+ * \warning This routine does not perform a.init().
+ */
+ template <typename A, typename I>
+ void take(Accumulator<A>& a, const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename A, typename I>
+ void take(A& a, const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ a.take(input(p));
+ }
+
+ template <typename A, typename I>
+ void take(A& a, const Fast_Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_pixter(const I) pxl(input);
+ for_all(pxl)
+ a.take(*pxl);
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facade.
+
+ template <typename A, typename I>
+ void take(Accumulator<A>& a, const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ impl::take(exact(a), exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_TAKE_HH
Index: mln/level/apply.hh
--- mln/level/apply.hh (revision 1047)
+++ mln/level/apply.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/level/apply.hh
*
- * \brief Apply some function-objects on an image.
+ * \brief Apply a function-object onto image pixel values.
*/
# include <mln/core/concept/image.hh>
@@ -52,34 +52,25 @@
* This routine runs: \n
* for all p of \p input, \p f( \p input(p) ) \n
* return \p f
+ *
+ * \todo Find a meaning for this routine! (Clue: f is mutable
+ * and/or same for input?)
*/
template <typename I, typename F>
F apply(const Image<I>& input, const Function<F>& f);
- /*! Apply an accumulator to the image \p input.
- *
- * \param[in] input The input image.
- * \param[in] a The accumulator.
- * \result A copy of the accumulator.
- *
- * This routine runs: \n
- * a.init() \n
- * for all p of \p input, \p a.take( \p input(p) ) \n
- * return \p a
- */
- template <typename I, typename A>
- A apply(const Image<I>& input, const Accumulator<A>& a);
-
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename I, typename F>
F apply(const Image<I>& input_, const Function<F>& f_)
{
const I& input = exact(input_);
F f = exact(f_);
- mln_precondition(input.has_data());
mln_piter(I) p(input.domain());
for_all(p)
@@ -87,18 +78,28 @@
return f;
}
- template <typename I, typename A>
- A apply(const Image<I>& input_, const Accumulator<A>& a_)
+ template <typename I, typename F>
+ F apply(const Fast_Image<I>& input_, const Function<F>& f_)
{
const I& input = exact(input_);
- A a = exact(a_);
- mln_precondition(input.has_data());
+ F f = exact(f_);
- a.init();
- mln_piter(I) p(input.domain());
- for_all(p)
- a.take(input(p));
- return a;
+ mln_pixter(const I) pxl(input);
+ for_all(pxl)
+ f(input(*pxl));
+ return f;
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facades.
+
+ template <typename I, typename F>
+ F apply(const Image<I>& input, const Function<F>& f)
+ {
+ mln_precondition(exact(input).has_data());
+ return impl::apply(exact(input), f);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/run.hh
--- mln/level/run.hh (revision 0)
+++ mln/level/run.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_LEVEL_RUN_HH
+# define MLN_LEVEL_RUN_HH
+
+/*! \file mln/level/run.hh
+ *
+ * \brief Run an accumulator onto image pixel values.
+ */
+
+# include <mln/level/take.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Run 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
+ * 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);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename A>
+ A run(const Image<I>& input, const Accumulator<A>& a)
+ {
+ A res = exact(a);
+ res.init();
+ level::take(res, input);
+ return res;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_RUN_HH
Index: mln/accu/sum.hh
--- mln/accu/sum.hh (revision 1047)
+++ mln/accu/sum.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/accumulator.hh>
+# include <mln/value/props.hh>
namespace mln
@@ -46,10 +47,10 @@
/*! Generic sum accumulator class.
*
* Parameter \c V is the type of values that we sum. Parameter \c
- * S is the type to store the sum value; the default type of
- * \c S is \c V.
+ * S is the type to store the value sum; the default type of
+ * \c S is the summation type (property) of \c V.
*/
- template <typename V, typename S = V>
+ template <typename V, typename S = mln_sum(V)>
struct sum : public Accumulator< sum<V,S> >
{
typedef V value;
@@ -61,6 +62,8 @@
operator S() const;
S to_value() const;
+ sum<V,S>& operator+=(const sum<V,S>& rhs);
+
protected:
S sum_;
@@ -99,7 +102,15 @@
S
sum<V,S>::to_value() const
{
- return sum_ / count_;
+ return sum_;
+ }
+
+ template <typename V, typename S>
+ sum<V,S>&
+ sum<V,S>::operator+=(const sum<V,S>& rhs)
+ {
+ sum_ += rhs.sum_;
+ return *this;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/accu/count.hh
--- mln/accu/count.hh (revision 0)
+++ mln/accu/count.hh (revision 0)
@@ -0,0 +1,119 @@
+// 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_COUNT_HH
+# define MLN_ACCU_COUNT_HH
+
+/*! \file mln/accu/count.hh
+ *
+ * \brief Define an accumulator that counts.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! Generic counter accumulator class.
+ */
+ template <typename V>
+ struct count : public Accumulator< count<V> >
+ {
+ typedef V value;
+
+ count();
+ void take(const value&);
+ void init();
+
+ operator std::size_t() const;
+ std::size_t to_value() const;
+
+ count<V>& operator+=(const count<V>& rhs);
+
+ protected:
+
+ std::size_t count_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ count<V>::count()
+ {
+ init();
+ }
+
+ template <typename V>
+ void
+ count<V>::take(const value&)
+ {
+ ++count_;
+ }
+
+ template <typename V>
+ void
+ count<V>::init()
+ {
+ count_ = 0;
+ }
+
+ template <typename V>
+ count<V>::operator std::size_t() const
+ {
+ return to_value();
+ }
+
+ template <typename V>
+ std::size_t
+ count<V>::to_value() const
+ {
+ 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
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_COUNT_HH
Index: mln/accu/mean.hh
--- mln/accu/mean.hh (revision 1047)
+++ mln/accu/mean.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Define an accumulator that computes a mean.
*/
-# include <mln/accu/counter.hh>
+# include <mln/accu/count.hh>
# include <mln/accu/sum.hh>
@@ -48,10 +48,13 @@
*
* Parameter \c V is the type of values that we sum. Parameter \c
* S is the type to store the sum of values; the default type of
- * \c S is \c V. Parameter \c M is the type of the mean value;
- * the default type of \c M is \c S.
+ * \c S is the summation type (property) of \c V. Parameter \c M
+ * is the type of the mean value; the default type of \c M is \c
+ * S.
*/
- template <typename V, typename S = V, typename M = S>
+ template <typename V,
+ typename S = mln_sum(V),
+ typename M = S>
struct mean : public Accumulator< mean<V,S,M> >
{
typedef V value;
@@ -63,9 +66,11 @@
operator M() const;
M to_value() const;
+ mean<V,S,M>& operator+=(const mean<V,S,M>& rhs);
+
protected:
- accu::counter<V> count_;
+ accu::count<V> count_;
accu::sum<V,S> sum_;
};
@@ -97,7 +102,7 @@
template <typename V, typename S, typename M>
mean<V,S,M>::operator M() const
{
- return to_value;
+ return to_value();
}
template <typename V, typename S, typename M>
@@ -107,6 +112,15 @@
return sum_.to_value() / count_.to_value();
}
+ template <typename V, typename S, typename M>
+ mean<V,S,M>&
+ mean<V,S,M>::operator+=(const mean<V,S,M>& rhs)
+ {
+ count_ += rhs.count_;
+ sum_ += rhs.sum_;
+ return *this;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1047)
+++ mln/value/props.hh (working copy)
@@ -61,6 +61,9 @@
# define mln_is_lowq(T) typename metal::bool_<( mln_card_(T) != 0 )>::type
+/// Give the summation type for values of type \c T.
+# define mln_sum(T) typename mln::value::props< T >::sum
+
namespace mln
@@ -121,6 +124,7 @@
static const unsigned char max = 255;
static const std::size_t card_ = 256;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -130,6 +134,7 @@
static const signed char max = 127;
static const std::size_t card_ = 256;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -139,6 +144,7 @@
static const unsigned short max = 65535;
static const std::size_t card_ = 65536;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -148,6 +154,7 @@
static const signed short max = 32767;
static const std::size_t card_ = 655356;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -157,6 +164,7 @@
static const unsigned int max = UINT_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -166,6 +174,7 @@
static const signed int max = INT_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -175,6 +184,7 @@
static const unsigned long int max = ULONG_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -184,6 +194,7 @@
static const signed long int max = LONG_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
@@ -196,6 +207,7 @@
static const float max() { return FLT_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -205,6 +217,7 @@
static const double max() { return DBL_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef double sum;
};
} // end of namespace mln::value
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1047)
+++ mln/value/int_s.hh (working copy)
@@ -97,6 +97,7 @@
static const std::size_t card_ = metal::pow<2, n>::value;
static const unsigned nbits = n;
typedef data_kind kind;
+ typedef float sum;
};
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1047)
+++ mln/value/int_u.hh (working copy)
@@ -99,6 +99,7 @@
static const int_u<n> max; // = card_ - 1
static const unsigned nbits = n;
typedef data_kind kind;
+ typedef float sum;
};