https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Introduce accumulators and point-wise operations in mln.
* tests/pw_value.cc: New.
* mln/estim/mean.hh: New.
* mln/fun/chess.hh (result): New.
* mln/fun/ops.hh: New.
* mln/fun/val.hh: New.
* mln/fun/pw_value.hh: New.
* mln/fun/var.hh: New.
* mln/core/concept/doc/accumulator.hh: New.
* mln/core/concept/accumulator.hh: New.
* mln/core/concept/function.hh (Function_i2v): New.
* mln/core/macros.hh (mln_result): New.
* mln/arith: New.
* mln/arith/plus.hh: New.
* mln/level/apply.hh: New.
* mln/level/transform.hh: New.
* mln/accu/counter.hh: New.
* mln/accu/mean.hh: New.
* mln/value/kind.hh: New.
* mln/value/props.hh (mln_kind, kind): New.
* mln/estim/count.hh: Remove; useless.
* mln/fun/all.hh (all): Change inheritance.
* mln/core/point.hh (point_): Strenghten sigs.
* mln/core/dpoint.hh (dpoint_): Likewise.
* mln/accu/histo.hh: Add inheritance.
* mln/accu/median.hh: Likewise.
mln/accu/counter.hh | 109 ++++++++++++++++++++++++++
mln/accu/histo.hh | 6 +
mln/accu/mean.hh | 116 ++++++++++++++++++++++++++++
mln/accu/median.hh | 8 +
mln/arith/plus.hh | 82 ++++++++++++++++++++
mln/core/concept/accumulator.hh | 80 +++++++++++++++++++
mln/core/concept/doc/accumulator.hh | 56 +++++++++++++
mln/core/concept/function.hh | 18 ++++
mln/core/dpoint.hh | 4
mln/core/macros.hh | 3
mln/core/point.hh | 4
mln/estim/mean.hh | 55 ++++++-------
mln/fun/all.hh | 3
mln/fun/chess.hh | 1
mln/fun/ops.hh | 147 ++++++++++++++++++++++++++++++++++++
mln/fun/pw_value.hh | 130 +++++++++++++++++++++++++++++++
mln/fun/val.hh | 97 +++++++++++++++++++++++
mln/fun/var.hh | 98 ++++++++++++++++++++++++
mln/level/apply.hh | 111 +++++++++++++++++++++++++++
mln/level/transform.hh | 85 ++++++++++++++++++++
mln/value/kind.hh | 60 ++++++++++++++
mln/value/props.hh | 20 ++++
tests/pw_value.cc | 48 +++++++++++
23 files changed, 1304 insertions(+), 37 deletions(-)
Index: tests/pw_value.cc
--- tests/pw_value.cc (revision 0)
+++ tests/pw_value.cc (revision 0)
@@ -0,0 +1,48 @@
+// 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/pw_value.cc
+ *
+ * \brief Test on mln::fun::pw_value_.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/fun/pw_value.hh>
+#include <mln/fun/ops.hh>
+#include <mln/fun/val.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(3, 3);
+ point2d p = make::point2d(1, 1);
+ ima(p) = 51;
+
+ std::cout << (pw_value(ima) = val(51))(p) << std::endl;
+}
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1014)
+++ mln/estim/mean.hh (working copy)
@@ -25,14 +25,17 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_ESTIM_COUNT_HH
-# define MLN_ESTIM_COUNT_HH
+#ifndef MLN_ESTIM_MEAN_HH
+# define MLN_ESTIM_MEAN_HH
-/*! \file mln/estim/count.hh
+/*! \file mln/estim/mean.hh
*
- * \brief Several routines to count the number of points.
+ * \brief Compute the mean pixel value.
*/
+# include <mln/core/concept/image.hh>
+# include <mln/accu/mean.hh>
+
namespace mln
{
@@ -41,39 +44,31 @@
{
- /// Compute the number FIXME minimum and maximum points when browsing with
- /// iterator \p p.
- template <typename S>
- std::size_t count(const Point_Set<S>& pset);
+ /*! \brief Compute the mean value of the pixels of image \p input.
+ *
+ * Parameter \c S is the type of the mean value.
+ */
+ template <typename S, typename I>
+ S mean(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
- std::pair<mln_point(I), mln_point(I)>
- count(const Piter<I>& p_)
+ template <typename S, typename I>
+ S
+ mean(const Image<I>& input_)
{
- const I& p = exact(p_);
+ const I& input = exact(input_);
+ mln_precondition(input.has_data());
+
+ accu::mean<mln_value(I), S> m;
- typedef mln_point(I) P;
- std::pair<P, P> tmp;
- P& pmin = tmp.first;
- P& pmax = tmp.second;
-
- // init with first point
- p.start();
- pmin = pmax = p;
-
- // update with remaining points
- for_all_remaining(p)
- for (unsigned i = 0; i < P::dim; ++i)
- if (p[i] < pmin[i])
- pmin()[i] = p[i];
- else if (p[i] > pmax[i])
- pmax[i] = p[i];
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ m.take(input(p));
- return tmp;
+ return m;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -83,4 +78,4 @@
} // end of namespace mln
-#endif // ! MLN_ESTIM_COUNT_HH
+#endif // ! MLN_ESTIM_MEAN_HH
Index: mln/fun/ops.hh
--- mln/fun/ops.hh (revision 0)
+++ mln/fun/ops.hh (revision 0)
@@ -0,0 +1,147 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_FUN_OPS_HH
+# define MLN_FUN_OPS_HH
+
+/*! \file mln/fun/ops.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+
+
+
+# define mln_decl_binary_expr_(In, Out, Name, Symbol) \
+ \
+ namespace fun \
+ { \
+ \
+ template <typename L, typename R> \
+ struct Name##_expr_ : public Function_##Out < Name##_expr_<L,R> > \
+ { \
+ typedef mln_result(L) result; \
+ \
+ Name##_expr_(const L& l, const R& r) \
+ : l_(l), r_(r) \
+ { \
+ } \
+ \
+ template <typename P> \
+ result operator()(const P& p) const \
+ { \
+ return l_(p) Symbol r_(p); \
+ } \
+ \
+ protected: \
+ L l_; \
+ R r_; \
+ }; \
+ \
+ } \
+ \
+ template <typename L, typename R> \
+ fun::Name##_expr_<L,R> \
+ operator Symbol (const Function_##In<L>& lhs, const Function_##In<R>& rhs) \
+ { \
+ fun::Name##_expr_<L,R> tmp(exact(lhs), exact(rhs)); \
+ return tmp; \
+ } \
+ \
+ struct dummy
+
+
+# define mln_decl_unary_expr_(In, Out, Name, Symbol) \
+ \
+ namespace fun \
+ { \
+ \
+ template <typename F> \
+ struct Name##_expr_ : public Function_##Out< Name##_expr_<F> > \
+ { \
+ typedef mln_result(F) result; \
+ \
+ Name##_expr_(const F& f) \
+ : f_(f) \
+ { \
+ } \
+ \
+ template <typename P> \
+ result operator()(const P& p) const \
+ { \
+ return Symbol f_(p); \
+ } \
+ \
+ protected: \
+ F f_; \
+ }; \
+ \
+ } \
+ \
+ template <typename F> \
+ fun::Name##_expr_<F> \
+ operator Symbol (const Function_##In<F>& f) \
+ { \
+ fun::Name##_expr_<F> tmp(exact(f)); \
+ return tmp; \
+ } \
+ \
+ struct dummy
+
+
+
+namespace mln
+{
+
+ mln_decl_binary_expr_(p2v, p2b, equal, =);
+ mln_decl_binary_expr_(p2v, p2b, not_equal, !=);
+
+ mln_decl_binary_expr_(p2v, p2b, less, <);
+ mln_decl_binary_expr_(p2v, p2b, less_or_equal, <=);
+ mln_decl_binary_expr_(p2v, p2b, greater_or_equal, >=);
+ mln_decl_binary_expr_(p2v, p2b, greater, >);
+
+ mln_decl_binary_expr_(p2b, p2b, and, &&);
+ mln_decl_binary_expr_(p2b, p2b, or, ||);
+ mln_decl_binary_expr_(p2b, p2b, xor, ^);
+
+ mln_decl_unary_expr_(p2b, p2b, not, !);
+
+ mln_decl_binary_expr_(p2v, p2v, plus, +);
+ mln_decl_binary_expr_(p2v, p2v, minus, -);
+ mln_decl_binary_expr_(p2v, p2v, times, *);
+ mln_decl_binary_expr_(p2v, p2v, div, /);
+ mln_decl_binary_expr_(p2v, p2v, mod, %);
+
+ mln_decl_unary_expr_(p2v, p2v, uplus, +);
+ mln_decl_unary_expr_(p2v, p2v, uminus, -);
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_OPS_HH
Index: mln/fun/val.hh
--- mln/fun/val.hh (revision 0)
+++ mln/fun/val.hh (revision 0)
@@ -0,0 +1,97 @@
+// 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_VAL_HH
+# define MLN_FUN_VAL_HH
+
+/*! \file mln/fun/val.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // FIXME: Doc!
+
+ namespace fun
+ {
+
+ template <typename T>
+ struct val_ : public Function_p2v< val_<T> >
+ {
+ typedef T result;
+ val_(T t);
+ template <typename P>
+ T operator()(const P&) const;
+ private:
+ T t_;
+ };
+
+ } // end of namespace mln::fun
+
+ template <typename T>
+ fun::val_<T> val(T t);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace fun
+ {
+
+ template <typename T>
+ val_<T>::val_(T t)
+ : t_(t)
+ {
+ }
+
+ template <typename T>
+ template <typename P>
+ T
+ val_<T>::operator()(const P&) const
+ {
+ return t_;
+ }
+
+ } // end of namespace mln::fun
+
+ template <typename T>
+ fun::val_<T> val(T t)
+ {
+ fun::val_<T> tmp(t);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VAL_HH
Index: mln/fun/pw_value.hh
--- mln/fun/pw_value.hh (revision 0)
+++ mln/fun/pw_value.hh (revision 0)
@@ -0,0 +1,130 @@
+// 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_PW_VALUE_HH
+# define MLN_FUN_PW_VALUE_HH
+
+/*! \file mln/fun/pw_value.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/value/props.hh>
+
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ namespace fun { template <typename I> struct pw_value; }
+
+
+
+ // FIXME: Doc!
+
+ template <typename I>
+ fun::pw_value<I> pw_value(const Image<I>& ima);
+
+
+
+ namespace fun
+ {
+
+ // FIXME: Move!
+
+ namespace internal
+ {
+
+ template <typename K, typename E>
+ struct function_ : Function_p2v<E>
+ {};
+
+ template <typename E>
+ struct function_< value::binary_kind, E > : Function_p2b<E>
+ {};
+
+ } // end of namespace mln::fun::internal
+
+
+ // FIXME: Doc!
+
+ template <typename I>
+ struct pw_value : public internal::function_< mln_kind(I), pw_value<I> >
+ {
+ typedef mln_value(I) result;
+ pw_value(const I& ima);
+ mln_rvalue(I) operator()(const mln_psite(I)& p) const;
+ protected:
+ const I& ima_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // fun::pw_value<I>
+
+ template <typename I>
+ pw_value<I>::pw_value(const I& ima)
+ : ima_(ima)
+ {
+ }
+
+ template <typename I>
+ mln_rvalue(I)
+ pw_value<I>::operator()(const mln_psite(I)& p) const
+ {
+ mln_precondition(ima_.owns_(p));
+ return ima_(p);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // pw_value
+
+ template <typename I>
+ fun::pw_value<I>
+ pw_value(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ fun::pw_value<I> tmp(exact(ima));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_PW_VALUE_HH
Index: mln/fun/chess.hh
--- mln/fun/chess.hh (revision 1014)
+++ mln/fun/chess.hh (working copy)
@@ -47,6 +47,7 @@
struct chess_t : public Function_p2b< chess_t >
{
+ typedef bool result;
bool operator()(const point2d& p) const;
}
Index: mln/fun/all.hh
--- mln/fun/all.hh (revision 1014)
+++ mln/fun/all.hh (working copy)
@@ -45,8 +45,9 @@
{
template <typename T>
- struct all : public Function< all<T> >
+ struct all : public Function_i2v< all<T> >
{
+ typedef T result;
all(T t);
template <typename U>
T operator()(const U&) const;
Index: mln/fun/var.hh
--- mln/fun/var.hh (revision 0)
+++ mln/fun/var.hh (revision 0)
@@ -0,0 +1,98 @@
+// 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_VAR_HH
+# define MLN_FUN_VAR_HH
+
+/*! \file mln/fun/var.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // FIXME: Doc!
+
+ namespace fun
+ {
+
+ template <typename V>
+ struct var_ : public Function_p2v< var_<V> >
+ {
+ typedef V result;
+ var_(const V& v);
+ template <typename P>
+ const V& operator()(const P&) const;
+ private:
+ const V& v_;
+ };
+
+ } // end of namespace mln::fun
+
+
+ template <typename V>
+ fun::var_<V> var(const V& v);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace fun
+ {
+
+ template <typename V>
+ var_<V>::var_(const V& v)
+ : v_(v)
+ {
+ }
+
+ template <typename V>
+ template <typename P>
+ const V&
+ var_<V>::operator()(const P&) const
+ {
+ return v_;
+ }
+
+ } // end of namespace mln::fun
+
+ template <typename V>
+ fun::var_<V> var(const V& v)
+ {
+ fun::var_<V> tmp(v);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VAR_HH
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1014)
+++ mln/core/macros.hh (working copy)
@@ -138,6 +138,9 @@
// r
+/// Shortcut to access the result type associated to T.
+# define mln_result(T) typename T::result
+
/// Shortcut to access the rvalue type associated to T.
# define mln_rvalue(T) typename T::rvalue
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1014)
+++ mln/core/point.hh (working copy)
@@ -87,7 +87,7 @@
/*! \brief Constructor; coordinates are set by function \p f.
*/
template <typename F>
- point_(const Function<F>& f);
+ point_(const Function_i2v<F>& f);
/*! \brief Set all coordinates to the value \p c.
*/
@@ -124,7 +124,7 @@
template <unsigned n, typename C>
template <typename F>
- point_<n,C>::point_(const Function<F>& f_)
+ point_<n,C>::point_(const Function_i2v<F>& f_)
{
const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1014)
+++ mln/core/dpoint.hh (working copy)
@@ -87,7 +87,7 @@
/*! \brief Constructor; coordinates are set by function \p f.
*/
template <typename F>
- dpoint_(const Function<F>& f);
+ dpoint_(const Function_i2v<F>& f);
/*! \brief Set all coordinates to the value \p c.
*/
@@ -124,7 +124,7 @@
template <unsigned n, typename C>
template <typename F>
- dpoint_<n,C>::dpoint_(const Function<F>& f_)
+ dpoint_<n,C>::dpoint_(const Function_i2v<F>& f_)
{
const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1014)
+++ mln/core/concept/function.hh (working copy)
@@ -68,6 +68,18 @@
};
+ // Index -> Value.
+
+ /// Base class for implementation of function-objects from index to
+ /// value.
+ template <typename E>
+ struct Function_i2v : public Function_v2v<E>
+ {
+ protected:
+ Function_i2v();
+ };
+
+
// Point -> Value.
/// Base class for implementation of function-objects from point to
@@ -110,6 +122,7 @@
template <typename E>
Function<E>::Function()
{
+ typedef mln_result(E) result;
}
template <typename E>
@@ -118,6 +131,11 @@
}
template <typename E>
+ Function_i2v<E>::Function_i2v()
+ {
+ }
+
+ template <typename E>
Function_p2v<E>::Function_p2v()
{
}
Index: mln/core/concept/doc/accumulator.hh
--- mln/core/concept/doc/accumulator.hh (revision 0)
+++ mln/core/concept/doc/accumulator.hh (revision 0)
@@ -0,0 +1,56 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file mln/core/concept/doc/accumulator.hh
+ * \brief This file documents the concept of mln::Accumulator.
+ */
+
+namespace mln
+{
+
+ namespace doc
+ {
+
+ /*! \brief Documentation class for mln::Accumulator.
+ * \see mln::Accumulator
+ */
+ template <typename E>
+ struct Accumulator
+ {
+ /// The value type of elements to accumulate.
+ typedef void value;
+
+ /// Initialize the accumulator.
+ void init();
+
+ /// Take into account a value \p v (an element).
+ void take(const value& v);
+ };
+
+ } // end of namespace mln::doc
+
+} // end of namespace mln
Index: mln/core/concept/accumulator.hh
--- mln/core/concept/accumulator.hh (revision 0)
+++ mln/core/concept/accumulator.hh (revision 0)
@@ -0,0 +1,80 @@
+// 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_CONCEPT_ACCUMULATOR_HH
+# define MLN_CORE_CONCEPT_ACCUMULATOR_HH
+
+/*! \file mln/core/concept/accumulator.hh
+ *
+ * \brief Definition of the concept of mln::Accumulator.
+ */
+
+# include <mln/core/concept/object.hh>
+
+
+namespace mln
+{
+
+
+ /*! \brief Base class for implementation of accumulators.
+ *
+ * The parameter \a E is the exact type.
+ *
+ * \see mln::doc::Accumulator for a complete documentation of this
+ * class contents.
+ */
+ template <typename E>
+ struct Accumulator : public Object<E>
+ {
+ /*
+ typedef value;
+ void init();
+ void take(const value& v);
+ */
+ protected:
+ Accumulator();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Accumulator<E>::Accumulator()
+ {
+ typedef mln_value(E) value;
+ void (E::*m1)() = & E::init;
+ m1 = 0;
+ void (E::*m2)(const value&) = & E::take;
+ m2 = 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_ACCUMULATOR_HH
Index: mln/arith/plus.hh
--- mln/arith/plus.hh (revision 0)
+++ mln/arith/plus.hh (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ARITH_PLUS_HH
+# define MLN_ARITH_PLUS_HH
+
+/*! \file mln/arith/plus.hh
+ *
+ * \brief Point-wise addition between images.
+ */
+
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace arith
+ {
+
+ /*! Point-wise addition of images \p lhs and \p rhs.
+ *
+ * \param[in] lhs First operand image.
+ * \param[in] rhs Second operand image.
+ * \param[out] output The result image.
+ *
+ * \pre \p output.domain = \p lhs.domain = \p rhs.domain
+ */
+ template <typename L, typename R, typename O>
+ void plus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L, typename R, typename O>
+ void plus(const Image<L>& lhs_, const Image<R>& rhs_, Image<O>& output_)
+ {
+ const L& lhs = exact(lhs_);
+ const R& rhs = exact(rhs_);
+ O& output = exact(output_);
+
+ mln_precondition(rhs.domain() = lhs.domain());
+ mln_precondition(output.domain() = lhs.domain());
+
+ mln_piter(I) p(output.domain());
+ for_all(p)
+ output(p) = lhs(p) + rhs(p);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::arith
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ARITH_PLUS_HH
Index: mln/level/apply.hh
--- mln/level/apply.hh (revision 0)
+++ mln/level/apply.hh (revision 0)
@@ -0,0 +1,111 @@
+// 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_APPLY_HH
+# define MLN_LEVEL_APPLY_HH
+
+/*! \file mln/level/apply.hh
+ *
+ * \brief Apply some function-objects on an image.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/accumulator.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Apply a function-object to the image \p input.
+ *
+ * \param[in] input The input image.
+ * \param[in] f The function-object.
+ * \result A copy of the function-object.
+ *
+ * This routine runs: \n
+ * for all p of \p input, \p f( \p input(p) ) \n
+ * return \p f
+ */
+ 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
+
+ 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)
+ f(input(p));
+ return f;
+ }
+
+ template <typename I, typename A>
+ A apply(const Image<I>& input_, const Accumulator<A>& a_)
+ {
+ const I& input = exact(input_);
+ A a = exact(a_);
+ mln_precondition(input.has_data());
+
+ a.init();
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ a.take(input(p));
+ return a;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_APPLY_HH
Index: mln/level/transform.hh
--- mln/level/transform.hh (revision 0)
+++ mln/level/transform.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_LEVEL_TRANSFORM_HH
+# define MLN_LEVEL_TRANSFORM_HH
+
+/*! \file mln/level/transform.hh
+ *
+ * \brief Transform the contents of an image into another one.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Transform the image \p input through a function \p f to set
+ * the \p output image.
+ *
+ * \param[in] input The input image.
+ * \param[in] f The function.
+ * \param[out] output The result image.
+ *
+ * This routine runs: \n
+ * for all p of \p input, \p output(p) = \p f( \p input(p) ).
+ *
+ * \pre \p output.domain >= \p input.domain
+ */
+ template <typename I, typename F, typename O>
+ void transform(const Image<I>& input, const Function_v2v<F>& f, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename F, typename O>
+ void transform(const Image<I>& input_, const Function_v2v<F>& f_, Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const F& f = exact(f_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() >= input.domain());
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ output(p) = f( input(p) );
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_TRANSFORM_HH
Index: mln/accu/histo.hh
--- mln/accu/histo.hh (revision 1014)
+++ mln/accu/histo.hh (working copy)
@@ -37,6 +37,7 @@
# include <algorithm>
# include <mln/core/concept/value_set.hh>
+# include <mln/core/concept/accumulator.hh>
# include <mln/value/set.hh>
@@ -50,7 +51,7 @@
/*! Generic histogram class over a value set with type \c S.
*/
template <typename S>
- struct histo_on_set
+ struct histo_on_set : public Accumulator< histo_on_set<S> >
{
histo_on_set(const Value_Set<S>& s);
@@ -84,6 +85,9 @@
/*! Generic histogram class over the set of values of type \c T.
+ *
+ * \todo Inheritance is badly formed since this concrete class
+ * derives from another concrete class.
*/
template <typename T>
struct histo_on_type : public histo_on_set< value::set_<T> >
Index: mln/accu/median.hh
--- mln/accu/median.hh (revision 1014)
+++ mln/accu/median.hh (working copy)
@@ -33,6 +33,7 @@
* \brief Define FIXME
*/
+# include <mln/core/concept/accumulator.hh>
# include <mln/accu/histo.hh>
@@ -47,7 +48,7 @@
* with type \c S.
*/
template <typename S>
- struct median
+ struct median : public Accumulator< median<S> >
{
typedef mln_value(S) value;
@@ -91,6 +92,11 @@
};
+ /*! Generic median class over the set of values of type \c T.
+ *
+ * \todo Inheritance is badly formed since this concrete class
+ * derives from another concrete class.
+ */
template <typename T>
struct median_on : public median< value::set_<T> >
{
Index: mln/accu/counter.hh
--- mln/accu/counter.hh (revision 0)
+++ mln/accu/counter.hh (revision 0)
@@ -0,0 +1,109 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ACCU_COUNTER_HH
+# define MLN_ACCU_COUNTER_HH
+
+/*! \file mln/accu/counter.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 counter : public Accumulator< counter<V> >
+ {
+ typedef V value;
+
+ counter();
+ void take(const value&);
+ void init();
+
+ operator std::size_t() const;
+ std::size_t to_value() const;
+
+ protected:
+
+ std::size_t count_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ counter<V>::counter()
+ {
+ init();
+ }
+
+ template <typename V>
+ void
+ counter<V>::take(const value&)
+ {
+ ++count_;
+ }
+
+ template <typename V>
+ void
+ counter<V>::init()
+ {
+ count_ = 0;
+ }
+
+ template <typename V>
+ counter<V>::operator std::size_t() const
+ {
+ return to_value();
+ }
+
+ template <typename V>
+ std::size_t
+ counter<V>::to_value() const
+ {
+ return count_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_COUNTER_HH
Index: mln/accu/mean.hh
--- mln/accu/mean.hh (revision 0)
+++ mln/accu/mean.hh (revision 0)
@@ -0,0 +1,116 @@
+// 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_MEAN_HH
+# define MLN_ACCU_MEAN_HH
+
+/*! \file mln/accu/mean.hh
+ *
+ * \brief Define an accumulator that computes a mean.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! Generic mean accumulator class.
+ *
+ * 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.
+ */
+ template <typename V, typename S = V, typename M = S>
+ struct mean : public Accumulator< mean<V,S,M> >
+ {
+ typedef V value;
+
+ mean();
+ void take(const value& v);
+ void init();
+
+ operator M() const;
+ M to_value() const;
+
+ protected:
+
+ std::size_t count_;
+ S sum_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, typename S, typename M>
+ mean<V,S,M>::mean()
+ {
+ init();
+ }
+
+ template <typename V, typename S, typename M>
+ void mean<V,S,M>::take(const value& v)
+ {
+ ++count_;
+ sum_ += v;
+ }
+
+ template <typename V, typename S, typename M>
+ void
+ mean<V,S,M>::init()
+ {
+ count_ = 0;
+ sum_ = 0;
+ }
+
+ template <typename V, typename S, typename M>
+ mean<V,S,M>::operator M() const
+ {
+ return to_value;
+ }
+
+ template <typename V, typename S, typename M>
+ M
+ mean<V,S,M>::to_value() const
+ {
+ return sum_ / count_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_MEAN_HH
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1014)
+++ mln/value/props.hh (working copy)
@@ -36,6 +36,9 @@
# include <climits>
# include <cfloat>
+# include <mln/core/macros.hh>
+# include <mln/value/kind.hh>
+
/// Get the minimum value of type \c T.
# define mln_min(T) mln::value::props<T>::min()
@@ -49,6 +52,11 @@
# define mln_card(T) mln::value::props<T>::card()
+/// Get the kind of the value type of image \c I.
+# define mln_kind(I) typename mln::value::props< mln_value(I) >::kind
+
+
+
namespace mln
{
@@ -56,6 +64,7 @@
namespace value
{
+
/*! Class that defines the properties of the value type \c T.
*/
template <typename T>
@@ -80,6 +89,7 @@
static bool min() { return false; }
static bool max() { return true; }
static std::size_t card() { return 2; }
+ typedef binary_kind kind;
};
// integers
@@ -90,6 +100,7 @@
static unsigned char min() { return 0; }
static unsigned char max() { return 255; }
static std::size_t card() { return 256; }
+ typedef data_kind kind;
};
template <>
@@ -98,6 +109,7 @@
static signed char min() { return -128; }
static signed char max() { return 127; }
static std::size_t card() { return 256; }
+ typedef data_kind kind;
};
template <>
@@ -106,6 +118,7 @@
static unsigned short min() { return 0; }
static unsigned short max() { return 65535; }
static std::size_t card() { return 65536; }
+ typedef data_kind kind;
};
template <>
@@ -114,6 +127,7 @@
static signed short min() { return -32768; }
static signed short max() { return 32767; }
static std::size_t card() { return 655356; }
+ typedef data_kind kind;
};
template <>
@@ -122,6 +136,7 @@
static unsigned int min() { return 0; }
static unsigned int max() { return UINT_MAX; }
static std::size_t card() { return std::size_t(UINT_MAX) + 1; }
+ typedef data_kind kind;
};
template <>
@@ -130,6 +145,7 @@
static signed int min() { return INT_MIN; }
static signed int max() { return INT_MAX; }
static std::size_t card() { return std::size_t(UINT_MAX) + 1; }
+ typedef data_kind kind;
};
template <>
@@ -137,6 +153,7 @@
{
static unsigned long int min() { return 0; }
static unsigned long int max() { return ULONG_MAX; }
+ typedef data_kind kind;
};
template <>
@@ -144,6 +161,7 @@
{
static signed long int min() { return LONG_MIN; }
static signed long int max() { return LONG_MAX; }
+ typedef data_kind kind;
};
// floating
@@ -153,6 +171,7 @@
{
static float min() { return FLT_MIN; }
static float max() { return FLT_MAX; }
+ typedef data_kind kind;
};
template <>
@@ -160,6 +179,7 @@
{
static double min() { return DBL_MIN; }
static double max() { return DBL_MAX; }
+ typedef data_kind kind;
};
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/kind.hh
--- mln/value/kind.hh (revision 0)
+++ mln/value/kind.hh (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_VALUE_KIND_HH
+# define MLN_VALUE_KIND_HH
+
+/*! \file mln/value/tags.hh
+ *
+ * \brief Define the set of kinds of value.
+ */
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ // FIXME: Doc!
+
+ struct kind
+ {
+ };
+
+ struct gray_level_kind : kind {};
+ struct color_kind : kind {};
+ struct label_kind : kind {};
+ struct binary_kind : kind {};
+ struct data_kind : kind {};
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_KIND_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add subset notion in milena.
Add materials.
* mln/convert/to_image.hh: New.
* mln/convert/to_window.hh: New.
* mln/estim: New.
* mln/estim/count.hh: New.
* mln/debug/format.hh: New.
* mln/geom: New.
* mln/geom/pmin_pmax.hh: New.
* mln/geom/bbox.hh: New.
* mln/core/psubset.hh: New.
* mln/core/psubset_piter.hh: New.
* mln/core/concept/function.hh: New.
* mln/core/internal/piter_adaptor.hh: New.
* mln/fun/chess.hh: New.
Add some tests.
* tests/safe_image.cc: New.
* tests/to_image.cc: New.
* tests/psubset.cc: New.
* tests/println.cc: New.
Several improvements.
* mln/debug/println.hh: Use debug::format.
* mln/core/box.hh (len): Move...
* mln/core/concept/box.hh: ...here.
* mln/core/point.hh (zero): Turn into var.
(point_): Bound ctor arg f.
* mln/core/dpoint.hh: Likewise.
* mln/core/neighb.hh (dpoint): New typedef.
* mln/core/concept/image.hh: Remove obsolete commentary.
* mln/core/concept/iterator.hh
(for_all_remaining): New macro.
* mln/core/concept/point_set.hh (operator<<): New.
* mln/core/concept/neighborhood.hh
(dpoint): Make it appear in commentary.
* mln/core/concept/doc/neighborhood.hh (dpoint): New.
* mln/core/concept/doc/box.hh: Cosmetics.
* mln/core/window.hh (b_): New attribute.
Update.
* mln/core/image2d_b.hh (bbox): Remove; redundant.
(at): New couple of methods.
Update.
* mln/core/internal/image_adaptor.hh: Fix.
* mln/core/internal/image_base.hh: Add preconditions.
* mln/core/internal/set_of.hh: Add a todo entry.
* mln/core/safe_image.hh: Help g++-2.95.
* mln/fun/all.hh: Add inheritance.
Change mk_<object> into make::<object>.
* mln/make: New directory.
* mln/core/dpoint2d.hh (mk_dpoint2d): Move to...
* mln/make/dpoint2d.hh: this new file.
(mk_dpoint2d): Rename as...
(dpoint2d): ...this.
* mln/core/window2d.hh (mk_window2d): Move to...
* mln/make/window2d.hh: this new file.
(mk_window2d): Rename as...
(window2d): ...this.
* mln/core/box2d.hh (mk_box2d): Move to...
* mln/make/box2d.hh: this new file.
(mk_box2d): Rename as...
(box2d): ...this.
* mln/core/point2d.hh (mk_point2d): Move to...
* mln/make/point2d.hh: this new file.
(mk_point2d): Rename as...
(point2d): ...this.
* tests/window2d.cc,
* tests/pixter_dpoint2d.cc,
* tests/box2d.cc,
* tests/point2d.cc,
* tests/dpoint2d.cc,
* tests/main.cc,
* mln/core/neighb2d.hh,
* mln/debug/println.hh,
* mln/core/rectangle2d.hh,
* mln/core/pixter2d_b.hh,
* mln/io/save_pgm.hh,
* mln/io/load_pgm.hh: Update.
mln/convert/to_image.hh | 109 +++++++++++++++++++
mln/convert/to_window.hh | 73 +++++++++++++
mln/core/box.hh | 13 --
mln/core/box2d.hh | 43 -------
mln/core/concept/box.hh | 19 ++-
mln/core/concept/doc/box.hh | 4
mln/core/concept/doc/neighborhood.hh | 3
mln/core/concept/function.hh | 135 ++++++++++++++++++++++++
mln/core/concept/image.hh | 2
mln/core/concept/iterator.hh | 8 +
mln/core/concept/neighborhood.hh | 3
mln/core/concept/point_set.hh | 27 ++++
mln/core/dpoint.hh | 15 +-
mln/core/dpoint2d.hh | 33 +----
mln/core/image2d_b.hh | 44 +++++--
mln/core/internal/image_adaptor.hh | 2
mln/core/internal/image_base.hh | 3
mln/core/internal/piter_adaptor.hh | 171 ++++++++++++++++++++++++++++++
mln/core/internal/set_of.hh | 2
mln/core/neighb.hh | 3
mln/core/neighb2d.hh | 16 +-
mln/core/pixter2d_b.hh | 4
mln/core/point.hh | 15 +-
mln/core/point2d.hh | 16 --
mln/core/psubset.hh | 194 +++++++++++++++++++++++++++++++++++
mln/core/psubset_piter.hh | 118 +++++++++++++++++++++
mln/core/rectangle2d.hh | 2
mln/core/safe_image.hh | 10 +
mln/core/window.hh | 10 +
mln/core/window2d.hh | 32 -----
mln/debug/format.hh | 92 ++++++++++++++++
mln/debug/println.hh | 20 ++-
mln/estim/count.hh | 86 +++++++++++++++
mln/fun/all.hh | 6 -
mln/fun/chess.hh | 71 ++++++++++++
mln/geom/bbox.hh | 113 ++++++++++++++++++++
mln/geom/pmin_pmax.hh | 90 ++++++++++++++++
mln/io/load_pgm.hh | 2
mln/io/save_pgm.hh | 2
mln/make/box2d.hh | 101 ++++++++++++++++++
mln/make/dpoint2d.hh | 72 ++++++++++++
mln/make/point2d.hh | 72 ++++++++++++
mln/make/window2d.hh | 82 ++++++++++++++
tests/box2d.cc | 2
tests/dpoint2d.cc | 6 -
tests/main.cc | 4
tests/pixter_dpoint2d.cc | 8 -
tests/point2d.cc | 2
tests/println.cc | 46 ++++++++
tests/psubset.cc | 45 ++++++++
tests/safe_image.cc | 47 ++++++++
tests/to_image.cc | 65 +++++++++++
tests/window2d.cc | 9 +
53 files changed, 1974 insertions(+), 198 deletions(-)
Index: tests/window2d.cc
--- tests/window2d.cc (revision 1009)
+++ tests/window2d.cc (working copy)
@@ -31,6 +31,9 @@
*/
#include <mln/core/window2d.hh>
+#include <mln/core/image2d_b.hh>
+#include <mln/convert/to_image.hh>
+#include <mln/debug/println.hh>
@@ -41,5 +44,9 @@
window2d w;
mln_assertion(w.is_centered() = false);
mln_assertion(w.is_symmetric() = true);
-}
+ w.insert(make::dpoint2d(-1,-1));
+ w.insert(make::dpoint2d( 1, 1));
+ image2d_b<bool> ima = convert::to_image(w);
+ debug::println(ima);
+}
Index: tests/pixter_dpoint2d.cc
--- tests/pixter_dpoint2d.cc (revision 1009)
+++ tests/pixter_dpoint2d.cc (working copy)
@@ -17,10 +17,10 @@
I::piter f(ima.domain());
window_<I::dpoint> set;
- set.insert(mk_dpoint2d(0, -1));
- set.insert(mk_dpoint2d(0, -1));
- set.insert(mk_dpoint2d(1, 0));
- set.insert(mk_dpoint2d(1, 0));
+ set.insert(make::dpoint2d(0, -1));
+ set.insert(make::dpoint2d(0, -1));
+ set.insert(make::dpoint2d(1, 0));
+ set.insert(make::dpoint2d(1, 0));
for_all(f)
{
Index: tests/box2d.cc
--- tests/box2d.cc (revision 1009)
+++ tests/box2d.cc (working copy)
@@ -38,5 +38,5 @@
{
using namespace mln;
- box2d b = mk_box2d(2, 3);
+ box2d b = make::box2d(2, 3);
}
Index: tests/point2d.cc
--- tests/point2d.cc (revision 1009)
+++ tests/point2d.cc (working copy)
@@ -50,7 +50,7 @@
mln_assertion(p.col() = 1 && p[1] = 1);
// construction
- q = mk_point2d(5, 1);
+ q = make::point2d(5, 1);
mln_assertion(p = q);
q.set_all(0);
Index: tests/safe_image.cc
--- tests/safe_image.cc (revision 0)
+++ tests/safe_image.cc (revision 0)
@@ -0,0 +1,47 @@
+// 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/safe_image.cc
+ *
+ * \brief Tests on mln::safe_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/safe_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(1, 1);
+ safe_image<I> ima_ = safe(ima);
+
+ point2d p = make::point2d(-5, -1);
+ ima_(p) = 0;
+}
Index: tests/dpoint2d.cc
--- tests/dpoint2d.cc (revision 1009)
+++ tests/dpoint2d.cc (working copy)
@@ -41,9 +41,9 @@
point2d p, q;
dpoint2d dp;
- p = mk_point2d(1, 2);
- q = mk_point2d(4, 7);
- dp = mk_dpoint2d(3, 5);
+ p = make::point2d(1, 2);
+ q = make::point2d(4, 7);
+ dp = make::dpoint2d(3, 5);
mln_assertion(dp = q - p);
mln_assertion(q = p + dp);
Index: tests/to_image.cc
--- tests/to_image.cc (revision 0)
+++ tests/to_image.cc (revision 0)
@@ -0,0 +1,65 @@
+// 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/to_image.cc
+ *
+ * \brief Tests on mln::convert::to_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/psubset.hh>
+#include <mln/fun/chess.hh>
+#include <mln/level/compare.hh>
+
+#include <mln/convert/to_image.hh>
+
+
+#include <mln/debug/println.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d box_3x3 = make::box2d(-1,+1, -1,+1);
+ // ^^^^^ ^^^^^
+ // rows cols
+
+ // center point
+ // V
+ bool X[] = { 1, 0, 1,
+ 0, 1, 0, // < center point
+ 1, 0, 1 };
+
+ image2d_b<bool> ima_X = convert::to_image(box_3x3 | fun::chess);
+ window2d win_X = make::window2d(X);
+ mln_assertion(convert::to_image(win_X) = ima_X);
+
+ // FIXME: nbh!
+}
Index: tests/main.cc
--- tests/main.cc (revision 1009)
+++ tests/main.cc (working copy)
@@ -60,7 +60,7 @@
-// box2d b = mk_box2d(/* row = */ 1, 3,
+// box2d b = make::box2d(/* row = */ 1, 3,
// /* col = */ 4, 6);
// std::cout << b << std::endl;
@@ -68,7 +68,7 @@
// { 0, 1, 0,
// 0, 1, 0,
// 1, 0, 0 };
-// window2d win = mk_window2d(w);
+// window2d win = make::window2d(w);
// std::cout << win << std::endl;
// std::cout << c8() << std::endl;
Index: tests/psubset.cc
--- tests/psubset.cc (revision 0)
+++ tests/psubset.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/psubset.cc
+ *
+ * \brief Tests on mln::psubset.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/psubset.hh>
+#include <mln/fun/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::chess).npoints() = 32);
+}
Index: tests/println.cc
--- tests/println.cc (revision 0)
+++ tests/println.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/println.cc
+ *
+ * \brief Test on mln::debug::println.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/level/fill.hh>
+#include <mln/debug/println.hh>
+
+
+using namespace mln;
+
+
+int main()
+{
+ image2d_b<bool> msk(3, 3);
+ msk.at(1, 1) = true;
+ debug::println(msk);
+}
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 0)
+++ mln/convert/to_image.hh (revision 0)
@@ -0,0 +1,109 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CONVERT_TO_IMAGE_HH
+# define MLN_CONVERT_TO_IMAGE_HH
+
+/*! \file mln/convert/to_image.hh
+ *
+ * \brief Convertions to mln::Image.
+ */
+
+# include <mln/core/image2d_b.hh>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/core/concept/neighborhood.hh>
+
+# include <mln/convert/to_window.hh>
+# include <mln/geom/bbox.hh>
+# include <mln/level/fill.hh>
+
+
+namespace mln
+{
+
+ 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);
+
+ /// Convert a window \p win into a binary image.
+ template <typename W>
+ image2d_b<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);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ image2d_b<bool> to_image(const Point_Set<S>& pset_)
+ {
+ const S& pset = exact(pset_);
+ image2d_b<bool> ima(pset.bbox());
+ level::fill(ima, false);
+ mln_piter(S) p(pset);
+ for_all(p)
+ ima(p) = true;
+ return ima;
+ }
+
+ template <typename W>
+ image2d_b<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);
+ level::fill(ima, false);
+ mln_qiter(W) q(win, P::zero);
+ for_all(q)
+ ima(q) = true;
+ return ima;
+ }
+
+ template <typename N>
+ image2d_b<bool> to_image(const Neighborhood<N>& nbh)
+ {
+ return to_image(convert::to_window(nbh));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_IMAGE_HH
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 0)
+++ mln/convert/to_window.hh (revision 0)
@@ -0,0 +1,73 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CONVERT_TO_WINDOW_HH
+# define MLN_CONVERT_TO_WINDOW_HH
+
+/*! \file mln/convert/to_window.hh
+ *
+ * \brief Convertions to mln::Image.
+ */
+
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/window.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a neighborhood \p nbh into a window.
+ template <typename N>
+ window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename N>
+ window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
+ {
+ const N& nbh = exact(nbh_);
+ typedef mln_dpoint(N) D;
+ typedef mln_point(D) P;
+ window_<D> win;
+ mln_niter(N) n(nbh, P::zero);
+ for_all(n)
+ win.insert(n - P::zero);
+ return win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_WINDOW_HH
Index: mln/estim/count.hh
--- mln/estim/count.hh (revision 0)
+++ mln/estim/count.hh (revision 0)
@@ -0,0 +1,86 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ESTIM_COUNT_HH
+# define MLN_ESTIM_COUNT_HH
+
+/*! \file mln/estim/count.hh
+ *
+ * \brief Several routines to count the number of points.
+ */
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+
+ /// Compute the number FIXME minimum and maximum points when browsing with
+ /// iterator \p p.
+ template <typename S>
+ std::size_t count(const Point_Set<S>& pset);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ std::pair<mln_point(I), mln_point(I)>
+ count(const Piter<I>& p_)
+ {
+ const I& p = exact(p_);
+
+ typedef mln_point(I) P;
+ std::pair<P, P> tmp;
+ P& pmin = tmp.first;
+ P& pmax = tmp.second;
+
+ // init with first point
+ p.start();
+ pmin = pmax = p;
+
+ // update with remaining points
+ for_all_remaining(p)
+ for (unsigned i = 0; i < P::dim; ++i)
+ if (p[i] < pmin[i])
+ pmin()[i] = p[i];
+ else if (p[i] > pmax[i])
+ pmax[i] = p[i];
+
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_COUNT_HH
Index: mln/debug/println.hh
--- mln/debug/println.hh (revision 1009)
+++ mln/debug/println.hh (working copy)
@@ -35,6 +35,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/window.hh>
+# include <mln/debug/format.hh>
+
# include <mln/core/box2d.hh>
@@ -54,24 +56,30 @@
namespace impl
{
+ // generic version
template <typename S, typename I>
void println(const S&, const Image<I>& input_)
{
const I& input = exact(input_);
mln_piter(I) p(input.domain());
for_all(p)
- std::cout << input(p) << ' ';
+ std::cout << format( input(p) ) << ' ';
std::cout << std::endl;
}
+ // "domain = box2d" version
template <typename I>
- void println(const box2d& b,
- const I& input)
+ void println(const box2d& b, const I& input)
{
- for (int row = b.pmin().row(); row <= b.pmax().row(); ++row)
+ point2d p;
+ int& row = p.row();
+ int& col = p.col();
+ const int max_row = b.max_row(), max_col = b.max_col();
+
+ for (row = b.min_row(); row <= max_row; ++row)
{
- for (int col = b.pmin().col(); col <= b.pmax().col(); ++col)
- std::cout << input(mk_point2d(row, col)) << ' ';
+ for (col = b.min_col(); col <= max_col; ++col)
+ std::cout << format( input(p) ) << ' ';
std::cout << std::endl;
}
std::cout << std::endl;
Index: mln/debug/format.hh
--- mln/debug/format.hh (revision 0)
+++ mln/debug/format.hh (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DEBUG_FORMAT_HH
+# define MLN_DEBUG_FORMAT_HH
+
+/*! \file mln/debug/format.hh
+ *
+ * \brief Routines that format a value to print it properly.
+ */
+
+
+namespace mln
+{
+
+ namespace debug
+ {
+
+ /// Default version for formatting a value is a no-op.
+ template <typename T>
+ const T& format(const T& v);
+
+ /// Format a Boolean to print it nicely: "|" for true and "-" for
+ /// false.
+ char format(bool v);
+
+ /// Format a signed char to print it properly, i.e., like an
+ /// integer value.
+ signed short format(signed char v);
+
+ /// Format an unsigned char to print it properly, i.e., like an
+ /// integer value.
+ unsigned short format(unsigned char v);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ const T& format(const T& v)
+ {
+ return v;
+ }
+
+ char format(bool v)
+ {
+ return v ? '|' : '-';
+ }
+
+ signed short format(signed char v)
+ {
+ return v;
+ }
+
+ unsigned short format(unsigned char v)
+ {
+ return v;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::debug
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DEBUG_FORMAT_HH
Index: mln/geom/pmin_pmax.hh
--- mln/geom/pmin_pmax.hh (revision 0)
+++ mln/geom/pmin_pmax.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_GEOM_PMIN_PMAX_HH
+# define MLN_GEOM_PMIN_PMAX_HH
+
+/*! \file mln/geom/pmin_pmax.hh
+ *
+ * \brief Several routines to compute the minimum point and/or maximum
+ * point.
+ */
+
+# include <utility>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+
+ /// Compute the minimum and maximum points when browsing with
+ /// iterator \p p.
+ template <typename I>
+ std::pair<mln_point(I), mln_point(I)>
+ pmin_pmax(const Piter<I>& p);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ std::pair<mln_point(I), mln_point(I)>
+ pmin_pmax(Piter<I>& p_)
+ {
+ I& p = exact(p_);
+
+ typedef mln_point(I) P;
+ std::pair<P, P> tmp;
+ P& pmin = tmp.first;
+ P& pmax = tmp.second;
+
+ // init with first point
+ p.start();
+ pmin = pmax = p;
+
+ // update with remaining points
+ for_all_remaining(p)
+ for (unsigned i = 0; i < P::dim; ++i)
+ if (p[i] < pmin[i])
+ pmin[i] = p[i];
+ else if (p[i] > pmax[i])
+ pmax[i] = p[i];
+
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_PMIN_PMAX_HH
Index: mln/geom/bbox.hh
--- mln/geom/bbox.hh (revision 0)
+++ mln/geom/bbox.hh (revision 0)
@@ -0,0 +1,113 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_GEOM_BBOX_HH
+# define MLN_GEOM_BBOX_HH
+
+/*! \file mln/geom/bbox.hh
+ *
+ * \brief Several routines to compute the precise bounding box of some
+ * objects.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/geom/pmin_pmax.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+
+ /// Compute the precise bounding box of a window \p win centered
+ /// at the origin.
+ template <typename W>
+ box_<mln_point(W)> bbox(const Window<W>& win);
+
+
+ /// Compute the precise bounding box of a point set \p pset.
+ template <typename S>
+ box_<mln_point(S)> bbox(const Point_Set<S>& pset);
+
+
+ /// Compute the precise bounding box of an image \p ima.
+ template <typename I>
+ box_<mln_point(I)> bbox(const Image<I>& ima);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename W>
+ box_<mln_point(W)> bbox(const Window<W>& win_)
+ {
+ const W& win = exact(win_);
+ mln_precondition(! win.is_empty());
+
+ typedef mln_point(W) P;
+ mln_qiter(W) q(win, P::zero);
+ std::pair<P, P> pp = geom::pmin_pmax(q);
+
+ box_<P> tmp(pp.first, pp.second);
+ return tmp;
+ }
+
+ template <typename S>
+ box_<mln_point(S)> bbox(const Point_Set<S>& pset_)
+ {
+ const S& pset = exact(pset_);
+ mln_precondition(pset.npoints() != 0);
+
+ typedef mln_point(S) P;
+ mln_piter(S) p(pset);
+ std::pair<P, P> pp = geom::pmin_pmax(p);
+
+ box_<P> tmp(pp.first, pp.second);
+ // FIXME: mln_postcondition(tmp <= pset.bbox());
+ return tmp;
+ }
+
+ template <typename I>
+ box_<mln_point(I)> bbox(const Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ return bbox(ima.domain());
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_BBOX_HH
Index: mln/core/neighb2d.hh
--- mln/core/neighb2d.hh (revision 1009)
+++ mln/core/neighb2d.hh (working copy)
@@ -101,8 +101,8 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(0, 1));
- it.insert(mk_dpoint2d(1, 0));
+ it.insert(make::dpoint2d(0, 1));
+ it.insert(make::dpoint2d(1, 0));
flower = false;
}
return it;
@@ -114,10 +114,10 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(0, 1));
- it.insert(mk_dpoint2d(1,-1));
- it.insert(mk_dpoint2d(1, 0));
- it.insert(mk_dpoint2d(1, 1));
+ it.insert(make::dpoint2d(0, 1));
+ it.insert(make::dpoint2d(1,-1));
+ it.insert(make::dpoint2d(1, 0));
+ it.insert(make::dpoint2d(1, 1));
flower = false;
}
return it;
@@ -129,7 +129,7 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(0, 1));
+ it.insert(make::dpoint2d(0, 1));
flower = false;
}
return it;
@@ -141,7 +141,7 @@
static neighb2d it;
if (flower)
{
- it.insert(mk_dpoint2d(1, 0));
+ it.insert(make::dpoint2d(1, 0));
flower = false;
}
return it;
Index: mln/core/dpoint2d.hh
--- mln/core/dpoint2d.hh (revision 1009)
+++ mln/core/dpoint2d.hh (working copy)
@@ -46,38 +46,23 @@
typedef dpoint_<2,int> dpoint2d;
- /*! \brief Create an mln::dpoint2d.
- *
- * \param[in] row Index of row.
- * \param[in] col Index of column.
- *
- * \return A 2D delta-point.
- */
- dpoint2d mk_dpoint2d(int row, int col);
-
+} // end of namespace mln
- const dpoint2d up = mk_dpoint2d( -1, 0 );
- const dpoint2d down = mk_dpoint2d( +1, 0 );
- const dpoint2d left = mk_dpoint2d( 0, -1 );
- const dpoint2d right = mk_dpoint2d( 0, +1 );
+# include <mln/make/dpoint2d.hh>
+# include <mln/core/point2d.hh>
-# ifndef MLN_INCLUDE_ONLY
- dpoint2d mk_dpoint2d(int row, int col)
+namespace mln
{
- dpoint2d tmp;
- tmp[0] = row;
- tmp[1] = col;
- return tmp;
- }
-# endif // ! MLN_INCLUDE_ONLY
+ // FIXME: Doc!
+ const dpoint2d up = make::dpoint2d( -1, 0 );
+ const dpoint2d down = make::dpoint2d( +1, 0 );
+ const dpoint2d left = make::dpoint2d( 0, -1 );
+ const dpoint2d right = make::dpoint2d( 0, +1 );
} // end of namespace mln
-# include <mln/core/point2d.hh>
-
-
#endif // ! MLN_CORE_DPOINT2D_HH
Index: mln/core/psubset.hh
--- mln/core/psubset.hh (revision 0)
+++ mln/core/psubset.hh (revision 0)
@@ -0,0 +1,194 @@
+// 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_PSUBSET_HH
+# define MLN_CORE_PSUBSET_HH
+
+/*! \file mln/core/psubset.hh
+ *
+ * \brief This file defines a generic class for subset of point set.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename S, typename F> struct psubset;
+ template <typename S, typename F> struct psubset_fwd_piter_;
+ template <typename S, typename F> struct psubset_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>
+ psubset<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 psubset : public Point_Set< psubset<S,F> >
+ {
+ /// Psite associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point associated type.
+ typedef mln_point(S) point;
+
+
+ /// Forward Piter associated type.
+ typedef psubset_fwd_piter_<S,F> fwd_piter;
+
+ /// Backward Piter associated type.
+ typedef psubset_fwd_piter_<S,F> bkd_piter; // FIXME: bkd!!!
+
+ /// Piter associated type.
+ typedef fwd_piter piter;
+
+
+ /// Constructor without argument.
+ psubset(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>
+ psubset<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f)
+ {
+ psubset<S, F> tmp(exact(pset), exact(f));
+ return tmp;
+ }
+
+
+ // psubset<S,F>
+
+ template <typename S, typename F>
+ bool
+ psubset<S,F>::has(const psite& p) const
+ {
+ return pset_.has(p) && f_(p);
+ }
+
+ template <typename S, typename F>
+ const box_<mln_point(S)>&
+ psubset<S,F>::bbox() const
+ {
+ return pset_.bbox();
+ }
+
+ template <typename S, typename F>
+ const S&
+ psubset<S,F>::overset() const
+ {
+ return pset_;
+ }
+
+ template <typename S, typename F>
+ bool
+ psubset<S,F>::pred(const psite& p) const
+ {
+ return f_(p);
+ }
+
+ template <typename S, typename F>
+ psubset<S,F>::psubset(const S& pset, const F& f)
+ : pset_(pset),
+ f_(f)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+# include <mln/core/psubset_piter.hh>
+
+
+
+namespace mln
+{
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ std::size_t
+ psubset<S,F>::npoints() const
+ {
+ std::size_t n = 0;
+ piter p(*this);
+ for_all(p)
+ ++n;
+ return n;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSUBSET_HH
Index: mln/core/psubset_piter.hh
--- mln/core/psubset_piter.hh (revision 0)
+++ mln/core/psubset_piter.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_PSUBSET_PITER_HH
+# define MLN_CORE_PSUBSET_PITER_HH
+
+/*! \file mln/core/psubset_piter.hh
+ *
+ * \brief Definition of iterators on points of psubsetes.
+ */
+
+# include <mln/core/concept/piter.hh>
+# include <mln/core/internal/piter_adaptor.hh>
+# include <mln/core/psubset.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::psubset
+ */
+ template <typename S, typename F>
+ class psubset_fwd_piter_ : public internal::piter_adaptor_< mln_fwd_piter(S),
+ psubset_fwd_piter_<S,F> >
+ {
+ typedef mln_fwd_piter(S) adaptee_;
+ typedef psubset_fwd_piter_<S,F> self_;
+ typedef internal::piter_adaptor_<adaptee_, self_> super_;
+
+ public:
+
+ /// Constructor from a subset of points.
+ psubset_fwd_piter_(const psubset<S,F>& subset);
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ private:
+
+ const psubset<S,F>& subset_;
+ };
+
+ // FIXME: psubset_bkd_piter_<S,F>
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // psubset_fwd_piter_<S,F>
+
+ template <typename S, typename F>
+ psubset_fwd_piter_<S,F>::psubset_fwd_piter_(const psubset<S,F>& subset)
+ : super_(adaptee_(subset.overset())),
+ subset_(subset)
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ psubset_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
+ psubset_fwd_piter_<S,F>::next_()
+ {
+ do
+ this->piter_.next();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_));
+ }
+
+
+ // FIXME: psubset_bkd_piter_<S,F>
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSUBSET_PITER_HH
Index: mln/core/box.hh
--- mln/core/box.hh (revision 1009)
+++ mln/core/box.hh (working copy)
@@ -90,11 +90,6 @@
*/
P& pmax();
- /*! \brief Give the length of the \p i-th side.
- * \pre i < dim
- */
- unsigned len(unsigned i) const;
-
/*! \brief Constructor without argument.
*/
box_();
@@ -158,14 +153,6 @@
}
template <typename P>
- unsigned
- box_<P>::len(unsigned i) const
- {
- mln_precondition(i < P::dim);
- return 1 + pmax_[i] - pmin_[i];
- }
-
- template <typename P>
box_<P>::box_()
{
}
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1009)
+++ mln/core/point.hh (working copy)
@@ -87,14 +87,14 @@
/*! \brief Constructor; coordinates are set by function \p f.
*/
template <typename F>
- point_(F f);
+ point_(const Function<F>& f);
/*! \brief Set all coordinates to the value \p c.
*/
void set_all(C c);
- /// Give the origin (all coordinates are 0).
- static const point_<n,C>& zero();
+ /// Origin point (all coordinates are 0).
+ static const point_<n,C> zero;
protected:
C coord_[n];
@@ -124,8 +124,9 @@
template <unsigned n, typename C>
template <typename F>
- point_<n,C>::point_(F f)
+ point_<n,C>::point_(const Function<F>& f_)
{
+ const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
coord_[i] = f(i);
}
@@ -138,11 +139,7 @@
}
template <unsigned n, typename C>
- const point_<n,C>& point_<n,C>::zero()
- {
- static const point_<n,C> zero_(all(0));
- return zero_;
- }
+ const point_<n,C> point_<n,C>::zero = all(0);
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/rectangle2d.hh
--- mln/core/rectangle2d.hh (revision 1009)
+++ mln/core/rectangle2d.hh (working copy)
@@ -139,7 +139,7 @@
const int drow = half_height, dcol = half_width;
for (int row = - drow; row <= drow; ++row)
for (int col = - dcol; col <= dcol; ++col)
- insert(mk_dpoint2d(row, col));
+ insert(make::dpoint2d(row, col));
}
bool rectangle2d::is_centered() const
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 1009)
+++ mln/core/neighb.hh (working copy)
@@ -55,6 +55,9 @@
struct neighb_ : public Neighborhood< neighb_<D> >,
public internal::set_of_<D>
{
+ /// Dpoint associated type.
+ typedef D dpoint;
+
/*! \brief Piter type to browse the points of a generic
* neighborhood w.r.t. the ordering of delta-points.
*/
Index: mln/core/concept/image.hh
--- mln/core/concept/image.hh (revision 1009)
+++ mln/core/concept/image.hh (working copy)
@@ -55,7 +55,7 @@
bool has_data() const;
- bool owns_(const psite& p) const; // default is like "has(p)"
+ bool owns_(const psite& p) const;
const pset& domain() const;
rvalue operator()(const psite& p) const;
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 0)
+++ mln/core/concept/function.hh (revision 0)
@@ -0,0 +1,135 @@
+// 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_CONCEPT_FUNCTION_HH
+# define MLN_CORE_CONCEPT_FUNCTION_HH
+
+/*! \file mln/core/concept/function.hh
+ *
+ * \brief Definition of several concepts of functions.
+ */
+
+# include <mln/core/concept/object.hh>
+
+
+namespace mln
+{
+
+
+ /*! \brief Base class for implementation of function-objects.
+ *
+ * The parameter \a E is the exact type.
+ */
+ template <typename E>
+ struct Function : public Object<E>
+ {
+ /*
+ An operator() has to be provided. Its signature depends
+ on the particular function-object one considers.
+ */
+ protected:
+ Function();
+ };
+
+
+ // Value -> Value.
+
+ /// Base class for implementation of function-objects from value to
+ /// value.
+ template <typename E>
+ struct Function_v2v : public Function<E>
+ {
+ protected:
+ Function_v2v();
+ };
+
+
+ // Point -> Value.
+
+ /// Base class for implementation of function-objects from point to
+ /// value.
+ template <typename E>
+ struct Function_p2v : public Function_v2v<E>
+ {
+ protected:
+ Function_p2v();
+ };
+
+
+ // Point -> bool.
+
+ /// Base class for implementation of function-objects from point to
+ /// bool.
+ template <typename E>
+ struct Function_p2b : public Function_p2v<E>
+ {
+ protected:
+ Function_p2b();
+ };
+
+
+ // Point -> Point.
+
+ /// Base class for implementation of function-objects from point to
+ /// point.
+ template <typename E>
+ struct Function_p2p : public Function_p2v<E>
+ {
+ protected:
+ Function_p2p();
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Function<E>::Function()
+ {
+ }
+
+ template <typename E>
+ Function_v2v<E>::Function_v2v()
+ {
+ }
+
+ template <typename E>
+ Function_p2v<E>::Function_p2v()
+ {
+ }
+
+ template <typename E>
+ Function_p2b<E>::Function_p2b()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_FUNCTION_HH
Index: mln/core/concept/box.hh
--- mln/core/concept/box.hh (revision 1009)
+++ mln/core/concept/box.hh (working copy)
@@ -52,10 +52,17 @@
/*
const point& pmin() const;
const point& pmax() const;
- unsigned len(unsigned i) const; // FIXME: Doc!
*/
- /*! \brief Return the bounding box of this point set.
+ /*! \brief Give the length of the \p i-th side of the box.
+ *
+ * \pre i < point::dim
+ *
+ * \warning This method is final for all box classes.
+ */
+ unsigned len(unsigned i) const;
+
+ /*! \brief Give the bounding box of this point set.
*
* Return the bounding box of this point set, so that is itself.
* This method is declared by the mln::Point_Set concept.
@@ -64,7 +71,7 @@
*/
const E& bbox() const;
- /*! \brief Return the number of points of this box.
+ /*! \brief Give the number of points of this box.
*
* Return the number of points of this box. This method is
* declared by the mln::Point_Set concept.
@@ -87,6 +94,12 @@
}
template <typename E>
+ unsigned Box<E>::len(unsigned i) const
+ {
+ return 1 + exact(this)->pmax()[i] - exact(this)->pmin()[i];
+ }
+
+ template <typename E>
Box<E>::Box()
{
typedef mln_point(E) point;
Index: mln/core/concept/iterator.hh
--- mln/core/concept/iterator.hh (revision 1009)
+++ mln/core/concept/iterator.hh (working copy)
@@ -40,6 +40,14 @@
# define for_all(x) for(x.start(); x.is_valid(); x.next())
+/*! \brief Loop to browse all the remaining elements targetted by the
+ * iterator \p x.
+ */
+# define for_all_remaining(x) \
+ if (! x.is_valid()) {} else while (x.next(), x.is_valid())
+
+
+
namespace mln
{
/*! \brief Base class for implementation classes that are iterators.
Index: mln/core/concept/point_set.hh
--- mln/core/concept/point_set.hh (revision 1009)
+++ mln/core/concept/point_set.hh (working copy)
@@ -64,6 +64,20 @@
};
+ /*! \brief Print a point set \p pset into the output stream \p
+ * ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] pset A point set.
+ *
+ * \return The modified output stream \p ostr.
+ *
+ * \relates mln::Point_Set
+ */
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const Point_Set<S>& pset);
+
+
# ifndef MLN_INCLUDE_ONLY
// fwd decl
@@ -74,6 +88,7 @@
{
typedef mln_point(E) point;
typedef mln_psite(E) psite;
+
typedef mln_piter(E) piter;
typedef mln_fwd_piter(E) fwd_piter;
typedef mln_bkd_piter(E) bkd_piter;
@@ -86,6 +101,18 @@
m3 = 0;
}
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const Point_Set<S>& pset_)
+ {
+ const S& pset = exact(pset_);
+ ostr << '{';
+ mln_piter(S) p(pset);
+ for_all(p)
+ ostr << p;
+ return ostr << '}';
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/concept/neighborhood.hh
--- mln/core/concept/neighborhood.hh (revision 1009)
+++ mln/core/concept/neighborhood.hh (working copy)
@@ -50,6 +50,8 @@
typedef niter;
typedef fwd_niter;
typedef bkd_niter;
+
+ typedef dpoint;
*/
protected:
@@ -65,6 +67,7 @@
typedef mln_niter(E) niter;
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
+ typedef mln_dpoint(E) dpoint;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/neighborhood.hh
--- mln/core/concept/doc/neighborhood.hh (revision 1009)
+++ mln/core/concept/doc/neighborhood.hh (working copy)
@@ -56,6 +56,9 @@
* neighbors in a backward way.
*/
typedef void bkd_niter;
+
+ /// Dpoint associated type.
+ typedef void dpoint;
};
} // end of namespace mln::doc
Index: mln/core/concept/doc/box.hh
--- mln/core/concept/doc/box.hh (revision 1009)
+++ mln/core/concept/doc/box.hh (working copy)
@@ -41,7 +41,7 @@
template <typename E>
struct Box : public Point_Set<E>
{
- /*! \brief Return the box "minimum" point.
+ /*! \brief Give the box "minimum" point.
*
* Return the "minimum" point w.r.t. the ordering between points.
* For instance, with mln::box2d, this minimum is the top left
@@ -49,7 +49,7 @@
*/
const point& pmin() const;
- /*! \brief Return the box "maximum" point.
+ /*! \brief Give the box "maximum" point.
*
* Return the "maximum" point w.r.t. the ordering between points.
* For instance, with mln::box2d, this maximum is the bottom
Index: mln/core/window2d.hh
--- mln/core/window2d.hh (revision 1009)
+++ mln/core/window2d.hh (working copy)
@@ -34,7 +34,6 @@
* routine.
*/
-# include <cmath>
# include <mln/core/window.hh>
# include <mln/core/dpoint2d.hh>
@@ -48,37 +47,10 @@
typedef window_<dpoint2d> window2d;
- /*! \brief Create an mln::window2d.
- *
- * \param[in] values Array of Booleans.
- *
- * \pre The array size, \c M, has to be a square of an odd integer.
- *
- * \return A 2D window.
- */
- template <unsigned M>
- window2d mk_window2d(const bool (&values)[M]);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <unsigned M>
- window2d mk_window2d(const bool (&values)[M])
- {
- int h = unsigned(std::sqrt(float(M))) / 2;
- assert((2 * h + 1) * (2 * h + 1) = M);
- window2d tmp;
- unsigned i = 0;
- for (int row = - h; row <= h; ++row)
- for (int col = - h; col <= h; ++col)
- if (values[i++])
- tmp.insert(mk_dpoint2d(row, col));
- return tmp;
- }
+} // end of namespace mln
-# endif // ! MLN_INCLUDE_ONLY
-} // end of namespace mln
+# include <mln/make/window2d.hh>
#endif // ! MLN_CORE_WINDOW2D_HH
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1009)
+++ mln/core/dpoint.hh (working copy)
@@ -87,14 +87,14 @@
/*! \brief Constructor; coordinates are set by function \p f.
*/
template <typename F>
- dpoint_(F f); // FIXME: Bound parameter!
+ dpoint_(const Function<F>& f);
/*! \brief Set all coordinates to the value \p c.
*/
void set_all(C c);
- /// Give the null delta-point (all coordinates are 0).
- static const dpoint_<n,C>& zero();
+ /// Null delta-point (all coordinates are 0).
+ static const dpoint_<n,C> zero;
protected:
C coord_[n];
@@ -124,8 +124,9 @@
template <unsigned n, typename C>
template <typename F>
- dpoint_<n,C>::dpoint_(F f)
+ dpoint_<n,C>::dpoint_(const Function<F>& f_)
{
+ const F& f = exact(f_);
for (unsigned i = 0; i < n; ++i)
coord_[i] = f(i);
}
@@ -138,11 +139,7 @@
}
template <unsigned n, typename C>
- const dpoint_<n,C>& dpoint_<n,C>::zero()
- {
- static const dpoint_<n,C> zero_(all(0));
- return zero_;
- }
+ const dpoint_<n,C> dpoint_<n,C>::zero = all(0);
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/pixter2d_b.hh
--- mln/core/pixter2d_b.hh (revision 1009)
+++ mln/core/pixter2d_b.hh (working copy)
@@ -79,7 +79,7 @@
+ 2 * border_size_ + 1)
{
this->start_ = &ima(ima.domain().pmin());
- this->eor_ = &ima(mk_point2d(ima.domain().pmin()[0], ima.domain().pmax()[1])) + 1;
+ this->eor_ = &ima(make::point2d(ima.domain().pmin()[0], ima.domain().pmax()[1])) + 1;
this->eoi_ = &ima(ima.domain().pmax()) + 1;
}
@@ -88,7 +88,7 @@
{
++(this->current_);
- if (this->current_ = this->eor_ and this->current_ != this->eoi_)
+ if (this->current_ = this->eor_ && this->current_ != this->eoi_)
{
this->current_ += 2 * this->border_size_;
this->eor_ += this->row_offset_;
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1009)
+++ mln/core/window.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/concept/genpoint.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/core/dpoint.hh>
+# include <mln/core/box.hh>
# include <mln/convert/to_dpoint.hh>
# include <mln/fun/all.hh>
@@ -79,6 +80,7 @@
*/
typedef fwd_qiter qiter;
+
/*! \brief Constructor without argument.
*
* The constructed window is empty.
@@ -99,6 +101,10 @@
/// Give the symmetrical window.
window_<D> sym_() const;
+
+ protected:
+
+ box_<point> b_;
};
@@ -159,7 +165,7 @@
{
typedef mln_point(W) P;
window_<mln_dpoint(W)> tmp;
- mln_qiter(W) q(win, P::zero());
+ mln_qiter(W) q(win, P::zero);
for_all(q)
tmp.insert(convert::to_dpoint(q) + dp);
return tmp;
@@ -178,7 +184,7 @@
{
typedef mln_point(W) P;
window_<mln_dpoint(W)> tmp;
- mln_qiter(W) q(lhs, P::zero());
+ mln_qiter(W) q(lhs, P::zero);
for_all(q)
{
mln_dpoint(W) dp = convert::to_dpoint(q);
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1009)
+++ mln/core/image2d_b.hh (working copy)
@@ -112,6 +112,9 @@
/// Assignment operator.
image2d_b& operator=(const image2d_b<T>& rhs);
+ /// Destructor.
+ ~image2d_b();
+
/// Initialize an empty image.
void init_with(int nrows, int ncols, unsigned bdr = border::thickness);
@@ -129,9 +132,6 @@
/// Give the definition domain.
const box2d& domain() const;
- /// Give a bounding box.
- const box2d& bbox() const;
-
/// Give the border thickness.
unsigned border() const;
@@ -144,11 +144,16 @@
/// Read-write access to the image value located at \p p.
T& operator()(const point2d& p);
- /// Return an offset from a dpoints
+ /// Read-only access to the image value located at (\p row, \p col).
+ const T& at(int row, int col) const;
+
+ /// Read-write access to the image value located at (\p row, \p col).
+ T& at(int row, int col);
+
+
+ /// Return the offset corresponding to the dpoint \p dp.
int offset(const dpoint2d& dp);
- /// Destructor.
- ~image2d_b();
private:
@@ -167,6 +172,7 @@
};
+
# ifndef MLN_INCLUDE_ONLY
// ctors
@@ -192,7 +198,7 @@
image2d_b<T>::init_with(int nrows, int ncols, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = mk_box2d(nrows, ncols);
+ b_ = make::box2d(nrows, ncols);
bdr_ = bdr;
allocate_();
}
@@ -265,14 +271,6 @@
}
template <typename T>
- const box2d&
- image2d_b<T>::bbox() const
- {
- mln_precondition(this->has_data());
- return b_;
- }
-
- template <typename T>
unsigned
image2d_b<T>::border() const
{
@@ -313,6 +311,22 @@
}
template <typename T>
+ const T&
+ image2d_b<T>::at(int row, int col) const
+ {
+ mln_precondition(this->owns_(make::point2d(row, col)));
+ return array_[row][col];
+ }
+
+ template <typename T>
+ T&
+ image2d_b<T>::at(int row, int col)
+ {
+ mln_precondition(this->owns_(make::point2d(row, col)));
+ return array_[row][col];
+ }
+
+ template <typename T>
image2d_b<T>::~image2d_b()
{
deallocate_();
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1009)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -105,7 +105,7 @@
}
template <typename I, typename E>
- const image_adaptor_<I,E>::pset&
+ const typename image_adaptor_<I,E>::pset&
image_adaptor_<I,E>::domain() const
{
return adaptee_.domain();
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1009)
+++ mln/core/internal/image_base.hh (working copy)
@@ -87,6 +87,7 @@
bool
image_base_<S,E>::has(const psite& p) const
{
+ mln_precondition(exact(this)->has_data());
return exact(this)->domain().has(p);
}
@@ -94,6 +95,7 @@
const box_<mln_point(S)>&
image_base_<S,E>::bbox() const
{
+ mln_precondition(exact(this)->has_data());
return exact(this)->domain().bbox();
}
@@ -101,6 +103,7 @@
std::size_t
image_base_<S,E>::npoints() const
{
+ mln_precondition(exact(this)->has_data());
return exact(this)->domain().npoints();
}
Index: mln/core/internal/piter_adaptor.hh
--- mln/core/internal/piter_adaptor.hh (revision 0)
+++ mln/core/internal/piter_adaptor.hh (revision 0)
@@ -0,0 +1,171 @@
+// 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_INTERNAL_PITER_ADAPTOR_HH
+# define MLN_CORE_INTERNAL_PITER_ADAPTOR_HH
+
+/*! \file mln/core/internal/piter_adaptor_.hh
+ *
+ * \brief Definition of iterators on points of boxes.
+ */
+
+# include <mln/core/concept/piter.hh>
+# include <mln/core/concept/box.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ /*! \brief A base class for point iterator adaptors.
+ *
+ * Parameter \c Pi is the type of the point iterator adaptee;
+ * parameter E is the exact type.
+ */
+ template <typename Pi, typename E>
+ class piter_adaptor_ : public Piter<E>
+ {
+ public:
+
+ /// Space dimension.
+ enum { dim = Pi::dim };
+
+ /// Psite associated type.
+ typedef mln_psite(Pi) psite;
+
+ /// Point associated type.
+ typedef mln_point(Pi) point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(Pi) dpoint;
+
+ /// Coordinate associated type.
+ typedef mln_coord(Pi) coord;
+
+
+ /// Constructor from a point iterator \p \piter.
+ piter_adaptor_(const Pi& piter);
+
+
+ /// Convertion to point.
+ operator point() const;
+
+ /// Address of the point.
+ const point* pointer() const;
+
+ /// Give the i-th coordinate.
+ coord operator[](unsigned i) const;
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ protected:
+
+ Pi piter_; // own copy
+ };
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename Pi, typename E>
+ piter_adaptor_<Pi,E>::piter_adaptor_(const Pi& piter)
+ : piter_(piter)
+ {
+ invalidate();
+ }
+
+ template <typename Pi, typename E>
+ piter_adaptor_<Pi,E>::operator mln_point(Pi) () const
+ {
+ return piter_;
+ }
+
+ template <typename Pi, typename E>
+ const mln_point(Pi)*
+ piter_adaptor_<Pi,E>::pointer() const
+ {
+ return piter_.pointer();
+ }
+
+ template <typename Pi, typename E>
+ mln_coord(Pi)
+ piter_adaptor_<Pi,E>::operator[](unsigned i) const
+ {
+ assert(i < dim);
+ return piter_[i];
+ }
+
+ template <typename Pi, typename E>
+ bool
+ piter_adaptor_<Pi,E>::is_valid() const
+ {
+ return piter_.is_valid();
+ }
+
+ template <typename Pi, typename E>
+ void
+ piter_adaptor_<Pi,E>::invalidate()
+ {
+ piter_.invalidate();
+ }
+
+ template <typename Pi, typename E>
+ void
+ piter_adaptor_<Pi,E>::start()
+ {
+ piter_.start();
+ }
+
+ template <typename Pi, typename E>
+ void
+ piter_adaptor_<Pi,E>::next_()
+ {
+ piter_.next();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_PITER_ADAPTOR_HH
Index: mln/core/internal/set_of.hh
--- mln/core/internal/set_of.hh (revision 1009)
+++ mln/core/internal/set_of.hh (working copy)
@@ -69,6 +69,8 @@
* \param[in] elt The element to be inserted.
*
* If \p elt is already in the set, this method is a no-op.
+ *
+ * \todo Returns exact(*this).
*/
void insert(const E& elt);
Index: mln/core/box2d.hh
--- mln/core/box2d.hh (revision 1009)
+++ mln/core/box2d.hh (working copy)
@@ -49,47 +49,10 @@
typedef box_<point2d> box2d;
- /*! \brief Create an mln::box2d.
- *
- * \param[in] nrows Number of rows.
- * \param[in] ncols Number of columns.
- *
- * \pre \p nrows != 0 and \p ncols != 0.
- *
- * \return A 2D box.
- */
- box2d mk_box2d(unsigned nrows, unsigned ncols)
- {
- mln_precondition(nrows != 0 && ncols != 0);
- box2d tmp(mk_point2d(0, 0),
- mk_point2d(nrows - 1, ncols - 1));
- return tmp;
- }
-
-
- /*! \brief Create an mln::box2d.
- *
- * \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_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.
- */
- box2d mk_box2d(int min_row, int max_row,
- int min_col, int max_col)
- {
- mln_precondition(max_row >= min_row && max_col >= min_col);
- box2d tmp(mk_point2d(min_row, min_col),
- mk_point2d(max_row, max_col));
- return tmp;
- }
-
} // end of namespace mln
+# include <mln/make/box2d.hh>
+
+
#endif // ! MLN_CORE_BOX2D_HH
Index: mln/core/point2d.hh
--- mln/core/point2d.hh (revision 1009)
+++ mln/core/point2d.hh (working copy)
@@ -46,24 +46,10 @@
typedef point_<2,int> point2d;
- /*! \brief Create an mln::point2d.
- *
- * \param[in] row Index of row.
- * \param[in] col Index of column.
- *
- * \return A 2D point.
- */
- point2d mk_point2d(int row, int col)
- {
- point2d tmp;
- tmp[0] = row;
- tmp[1] = col;
- return tmp;
- }
-
} // end of namespace mln
+# include <mln/make/point2d.hh>
# include <mln/core/dpoint2d.hh>
Index: mln/core/safe_image.hh
--- mln/core/safe_image.hh (revision 1009)
+++ mln/core/safe_image.hh (working copy)
@@ -44,6 +44,12 @@
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
mln_lvalue(I) operator()(const mln_psite(I)& p);
+
+ template <typename U>
+ struct change_value
+ {
+ typedef safe_image<mln_ch_value(I, U)> ret;
+ };
};
@@ -67,7 +73,7 @@
safe_image<I>::operator()(const mln_psite(I)& p) const
{
static mln_value(I) tmp;
- if (not this->owns_(p))
+ if (! this->owns_(p))
return tmp;
return this->adaptee_(p);
}
@@ -77,7 +83,7 @@
safe_image<I>::operator()(const mln_psite(I)& p)
{
static mln_value(I) tmp;
- if (not this->owns_(p))
+ if (! this->owns_(p))
return tmp;
return this->adaptee_(p);
}
Index: mln/fun/chess.hh
--- mln/fun/chess.hh (revision 0)
+++ mln/fun/chess.hh (revision 0)
@@ -0,0 +1,71 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_FUN_CHESS_HH
+# define MLN_FUN_CHESS_HH
+
+/*! \file mln/fun/chess.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/core/point2d.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ // FIXME: Doc!
+
+ struct chess_t : public Function_p2b< chess_t >
+ {
+ bool operator()(const point2d& p) const;
+ }
+
+ chess;
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ bool
+ chess_t::operator()(const point2d& p) const
+ {
+ return (p.row() + p.col()) % 2 = 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_CHESS_HH
Index: mln/fun/all.hh
--- mln/fun/all.hh (revision 1009)
+++ mln/fun/all.hh (working copy)
@@ -33,6 +33,10 @@
* \brief FIXME.
*/
+# include <mln/core/concept/function.hh>
+
+
+// FIXME: Usually all.hh is the file to include all files in the current directory...
namespace mln
{
@@ -41,7 +45,7 @@
{
template <typename T>
- struct all
+ struct all : public Function< all<T> >
{
all(T t);
template <typename U>
Index: mln/io/save_pgm.hh
--- mln/io/save_pgm.hh (revision 1009)
+++ mln/io/save_pgm.hh (working copy)
@@ -55,7 +55,7 @@
file << "# olena" << std::endl;
file << ima.ncols() << ' ' << ima.nrows() << std::endl;
file << "255" << std::endl;
- point2d p = mk_point2d(ima.domain().pmin().row(),
+ point2d p = make::point2d(ima.domain().pmin().row(),
ima.domain().pmin().col());
size_t len = ima.ncols() * sizeof(unsigned char);
for (;
Index: mln/io/load_pgm.hh
--- mln/io/load_pgm.hh (revision 1009)
+++ mln/io/load_pgm.hh (working copy)
@@ -134,7 +134,7 @@
template <typename I>
void load_pgm_raw_2d(std::ifstream& file, I& ima)
{
- point2d p = mk_point2d(0, ima.domain().pmin().col());
+ point2d p = make::point2d(0, ima.domain().pmin().col());
size_t len = ima.ncols() * sizeof(mln_value(I));
for (p.row() = ima.domain().pmin().row();
p.row() <= ima.domain().pmax().row();
Index: mln/make/dpoint2d.hh
--- mln/make/dpoint2d.hh (revision 0)
+++ mln/make/dpoint2d.hh (revision 0)
@@ -0,0 +1,72 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_DPOINT2D_HH
+# define MLN_MAKE_DPOINT2D_HH
+
+/*! \file mln/make/dpoint2d.hh
+ *
+ * \brief Routine to construct an mln::dpoint2d.
+ */
+
+# include <mln/core/dpoint2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::dpoint2d.
+ *
+ * \param[in] row Row coordinate.
+ * \param[in] Col Column coordinate.
+ *
+ * \return A 2D dpoint.
+ */
+ mln::dpoint2d dpoint2d(int row, int col);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ mln::dpoint2d dpoint2d(int row, int col)
+ {
+ mln::dpoint2d tmp;
+ tmp[0] = row;
+ tmp[1] = col;
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_DPOINT2D_HH
Index: mln/make/window2d.hh
--- mln/make/window2d.hh (revision 0)
+++ mln/make/window2d.hh (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_WINDOW2D_HH
+# define MLN_MAKE_WINDOW2D_HH
+
+/*! \file mln/make/window2d.hh
+ *
+ * \brief Routine to create an mln::window2d.
+ */
+
+# include <cmath>
+# include <mln/core/window2d.hh>
+# include <mln/make/dpoint2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::window2d.
+ *
+ * \param[in] values Array of Booleans.
+ *
+ * \pre The array size, \c M, has to be a square of an odd integer.
+ *
+ * \return A 2D window.
+ */
+ template <unsigned M>
+ mln::window2d window2d(const bool (&values)[M]);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned M>
+ mln::window2d window2d(const bool (&values)[M])
+ {
+ int h = unsigned(std::sqrt(float(M))) / 2;
+ assert((2 * h + 1) * (2 * h + 1) = M);
+ mln::window2d tmp;
+ unsigned i = 0;
+ for (int row = - h; row <= h; ++row)
+ for (int col = - h; col <= h; ++col)
+ if (values[i++])
+ tmp.insert(make::dpoint2d(row, col));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_WINDOW2D_HH
Index: mln/make/box2d.hh
--- mln/make/box2d.hh (revision 0)
+++ mln/make/box2d.hh (revision 0)
@@ -0,0 +1,101 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_BOX2D_HH
+# define MLN_MAKE_BOX2D_HH
+
+/*! \file mln/make/box2d.hh
+ *
+ * \brief Routines to construct an mln::box2d.
+ */
+
+# include <mln/core/box2d.hh>
+# include <mln/make/point2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::box2d.
+ *
+ * \param[in] nrows Number of rows.
+ * \param[in] ncols Number of columns.
+ *
+ * \pre \p nrows != 0 and \p ncols != 0.
+ *
+ * \return A 2D box.
+ */
+ mln::box2d box2d(unsigned nrows, unsigned ncols);
+
+
+ /*! \brief Create an mln::box2d.
+ *
+ * \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_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);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ mln::box2d box2d(unsigned nrows, unsigned ncols)
+ {
+ mln_precondition(nrows != 0 && ncols != 0);
+ mln::box2d tmp(make::point2d(0, 0),
+ make::point2d(nrows - 1, ncols - 1));
+ return tmp;
+ }
+
+ mln::box2d box2d(int min_row, int max_row,
+ int min_col, int max_col)
+ {
+ mln_precondition(max_row >= min_row && max_col >= min_col);
+ mln::box2d tmp(make::point2d(min_row, min_col),
+ make::point2d(max_row, max_col));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_BOX2D_HH
Index: mln/make/point2d.hh
--- mln/make/point2d.hh (revision 0)
+++ mln/make/point2d.hh (revision 0)
@@ -0,0 +1,72 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_POINT2D_HH
+# define MLN_MAKE_POINT2D_HH
+
+/*! \file mln/make/point2d.hh
+ *
+ * \brief Routine to construct an mln::point2d.
+ */
+
+# include <mln/core/point2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::point2d.
+ *
+ * \param[in] row Row coordinate.
+ * \param[in] Col Column coordinate.
+ *
+ * \return A 2D point.
+ */
+ mln::point2d point2d(int row, int col);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ mln::point2d point2d(int row, int col)
+ {
+ mln::point2d tmp;
+ tmp[0] = row;
+ tmp[1] = col;
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_POINT2D_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Fix bug in pixter_dpoint2d.
* tests/pixter_dpoint2d.cc: Update.
* mln/core/dpoints_piter.hh: Update.
* mln/core/concept/doc/fast_iterator.hh: New documentation.
* mln/core/image2d_b.hh: Change offset method.
mln/core/concept/doc/fast_iterator.hh | 57 ++++++++++++++++++++++++++++++++++
mln/core/dpoints_piter.hh | 2 -
mln/core/image2d_b.hh | 4 +-
tests/pixter_dpoint2d.cc | 16 +++++----
4 files changed, 70 insertions(+), 9 deletions(-)
Index: tests/pixter_dpoint2d.cc
--- tests/pixter_dpoint2d.cc (revision 1008)
+++ tests/pixter_dpoint2d.cc (working copy)
@@ -1,7 +1,7 @@
#include <cassert>
#include <iostream>
-#include <mln/core/image2d.hh>
-#include <mln/core/internal/set_of.hh>
+#include <mln/core/image2d_b.hh>
+#include <mln/core/window.hh>
#include <mln/level/fill.hh>
#include <mln/core/dpoints_pixter.hh>
@@ -9,27 +9,29 @@
main()
{
using namespace mln;
- typedef image2d<int> I;
+ typedef image2d_b<int> I;
I ima(20, 20);
level::fill(ima, 5);
I::piter f(ima.domain());
- internal::set_of_<I::dpoint> set;
+ window_<I::dpoint> set;
- set.insert(mk_dpoint2d(-1, -1));
set.insert(mk_dpoint2d(0, -1));
+ set.insert(mk_dpoint2d(0, -1));
+ set.insert(mk_dpoint2d(1, 0));
set.insert(mk_dpoint2d(1, 0));
- set.insert(mk_dpoint2d(1, 1));
for_all(f)
{
+ if (f[0] > 0 && f[1] > 0 && f[0] < 19 && f[1] < 19)
+ {
I::qixter dit(set, f, ima);
- if (f[0] > 0 && f[1] > 0 && f[0] < 19 && f[1] < 19)
for_all(dit)
{
assert(*dit == 5);
}
}
}
+}
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1008)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -88,7 +88,7 @@
/// Start an iteration.
void start();
-xb
+
/// Go to the next point.
void next_();
Index: mln/core/concept/doc/fast_iterator.hh
--- mln/core/concept/doc/fast_iterator.hh (revision 0)
+++ mln/core/concept/doc/fast_iterator.hh (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 mln/core/concept/doc/fast_iterator.hh
+ * \brief This file documents the concept of mln::Fast_Iterator.
+ */
+
+namespace mln
+{
+
+ namespace doc
+ {
+ /*! \brief Documentation class for mln::Iterator.
+ * \see mln::Fast_Iterator
+ */
+ template <typename E>
+ struct Fast_Iterator : public Iterator<E>
+ {
+ /*! \brief Dereference operator.
+ * return the current pixel
+ */
+ rvalue operator* ();
+
+ /*! \brief Dereference operator.
+ * return the current pixel
+ */
+ lvalue operator* () const;
+ protected:
+ Fast_Iterator();
+ };
+ } // end of namespace doc
+
+} // end of namespace mln
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1008)
+++ mln/core/image2d_b.hh (working copy)
@@ -61,6 +61,7 @@
typedef box2d pset;
typedef point2d psite;
typedef point2d point;
+ typedef dpoint2d dpoint;
typedef mln_fwd_piter(box2d) fwd_piter;
typedef mln_bkd_piter(box2d) bkd_piter;
typedef fwd_piter piter;
@@ -72,6 +73,7 @@
/// Foward pixel iterator on dpoints assoicated to image 2d
typedef dpoints_pixter< image2d_b<T> > fwd_qixter;
+
typedef fwd_pixter pixter;
typedef fwd_qixter qixter;
@@ -368,7 +370,7 @@
int
image2d_b<T>::offset(const dpoint2d& dp)
{
- return dp[0] * vb_.pmax()[1] + dp[1];
+ return dp[0] * vb_.len(1) + dp[1];
}
# endif // ! MLN_INCLUDE_ONLY
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add pixel iterators to milena.
* tests/pixter_dpoint2d.cc,
* tests/pixter_point2d.cc: New tests.
* mln/core/dpoints_piter.hh: Delete trailing whitespace.
* mln/core/macros.hh: Add macro to get pixel iterator from an image.
* mln/core/concept/image.hh,
* mln/core/concept/doc/image.hh: Delte trailing whitespace.
* mln/core/concept/fast_iterator.hh: New fast iterator concept.
* mln/core/pixter2d_b.hh: New pixel iterator on image2d_b.
* mln/core/image2d_b.hh: Add a method to get an offset from a dpoint.
* mln/core/dpoints_pixter.hh: New pixel iterator.
mln/core/concept/doc/image.hh | 5 +
mln/core/concept/fast_iterator.hh | 79 +++++++++++++++++
mln/core/dpoints_piter.hh | 2
mln/core/dpoints_pixter.hh | 145 ++++++++++++++++++++++++++++++++
mln/core/image2d_b.hh | 21 ++++
mln/core/internal/fast_iterator_base.hh | 138 ++++++++++++++++++++++++++++++
mln/core/macros.hh | 16 +++
mln/core/pixter2d_b.hh | 103 ++++++++++++++++++++++
tests/pixter_dpoint2d.cc | 35 +++++++
tests/pixter_point2d.cc | 66 ++++++++++++++
10 files changed, 608 insertions(+), 2 deletions(-)
Index: tests/pixter_dpoint2d.cc
--- tests/pixter_dpoint2d.cc (revision 0)
+++ tests/pixter_dpoint2d.cc (revision 0)
@@ -0,0 +1,35 @@
+#include <cassert>
+#include <iostream>
+#include <mln/core/image2d.hh>
+#include <mln/core/internal/set_of.hh>
+#include <mln/level/fill.hh>
+#include <mln/core/dpoints_pixter.hh>
+
+int
+main()
+{
+ using namespace mln;
+ typedef image2d<int> I;
+
+
+ I ima(20, 20);
+ level::fill(ima, 5);
+ I::piter f(ima.domain());
+ internal::set_of_<I::dpoint> set;
+
+ set.insert(mk_dpoint2d(-1, -1));
+ set.insert(mk_dpoint2d(0, -1));
+ set.insert(mk_dpoint2d(1, 0));
+ set.insert(mk_dpoint2d(1, 1));
+
+ for_all(f)
+ {
+ I::qixter dit(set, f, ima);
+
+ if (f[0] > 0 && f[1] > 0 && f[0] < 19 && f[1] < 19)
+ for_all(dit)
+ {
+ assert(*dit == 5);
+ }
+ }
+}
Index: tests/pixter_point2d.cc
--- tests/pixter_point2d.cc (revision 0)
+++ tests/pixter_point2d.cc (revision 0)
@@ -0,0 +1,66 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <cassert>
+#include <mln/core/image2d_b.hh>
+#include <iostream>
+
+
+int
+main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(2, 2);
+
+ image2d_b<int>::piter p(ima.domain());
+ image2d_b<int>::pixter f(ima);
+ int i = 0;
+
+ for_all(p)
+ {
+ ima(p) = i++;
+ }
+ i = 0;
+
+ for_all(f)
+ {
+ std::cout << *f << std::endl;
+ assert(*f == i ++);
+ *f = 5;
+ }
+
+ for_all(p)
+ {
+ assert(ima(p) == 5);
+ }
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1006)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -88,7 +88,7 @@
/// Start an iteration.
void start();
-
+xb
/// Go to the next point.
void next_();
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1006)
+++ mln/core/macros.hh (working copy)
@@ -81,13 +81,21 @@
/// Shortcut to access the fwd_piter type associated to T.
# define mln_fwd_piter(T) typename T::fwd_piter
+/// Shortcut to access the fwd_pixter type associated to T.
+# define mln_fwd_pixter(T) typename T::fwd_pixter
+
+/// Shortcut to access the bkd_piter type associated to T.
+# define mln_bkd_piter(T) typename T::bkd_piter
+
/// Shortcut to access the fwd_qiter type associated to T.
# define mln_fwd_qiter(T) typename T::fwd_qiter
+/// Shortcut to access the fwd_qixter type associated to T.
+# define mln_fwd_qixter(T) typename T::fwd_qixter
+
/// Shortcut to access the fwd_viter type associated to T.
# define mln_fwd_viter(T) typename T::fwd_viter
-
// l
@@ -100,6 +108,9 @@
/// Shortcut to access the piter type associated to T.
# define mln_piter(T) typename T::piter
+/// Shortcut to access the pixter type associated to T.
+# define mln_pixter(T) typename T::pixter
+
/// Shortcut to access the pset type associated to T.
# define mln_pset(T) typename T::pset
@@ -115,6 +126,9 @@
/// Shortcut to access the qiter type associated to T.
# define mln_qiter(T) typename T::qiter
+// Shortcut to access to the qixter type associated to T
+# define mln_qixter(T) typename T::qixter
+
// n
Index: mln/core/concept/image.hh
Index: mln/core/concept/fast_iterator.hh
--- mln/core/concept/fast_iterator.hh (revision 0)
+++ mln/core/concept/fast_iterator.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_CORE_CONCEPT_FAST_ITERATOR_HH
+# define MLN_CORE_CONCEPT_FAST_ITERATOR_HH
+
+/*! \file mln/core/concept/fast_iterator.hh
+ * \brief Definition of the concept of mln::Fast_Iterator.
+ */
+
+# include <mln/core/concept/iterator.hh>
+
+namespace mln
+{
+
+
+ template <typename E>
+ struct Fast_Iterator : public Iterator<E>
+ {
+ /*
+ typedef rvalue
+ typedef lvalue
+ rvalue operator* ();
+ lvalue operator* () const;
+ */
+ protected:
+ Fast_Iterator();
+ };
+
+#ifndef MLN_INCLUDE_ONLY
+
+ /*! \brief Fast Iterator concept class.
+ *
+ * \see FIXME
+ */
+ template <typename E>
+ Fast_Iterator<E>::Fast_Iterator()
+ {
+ typedef mln_value(E) value;
+ typedef mln_rvalue(E) rvalue;
+ typedef mln_lvalue(E) lvalue;
+
+ rvalue (E::*m1)() = &E::operator*;
+ m1 = 0;
+ lvalue (E::*m2)() const = &E::operator*;
+ m2 = 0;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_FAST_ITERATOR_HH
Index: mln/core/concept/doc/image.hh
--- mln/core/concept/doc/image.hh (revision 1006)
+++ mln/core/concept/doc/image.hh (working copy)
@@ -162,6 +162,11 @@
std::size_t npoints() const;
};
+ template <typename E>
+ struct Fast_Image : public Image<E>
+ {
+ };
+
} // end of namespace mln::doc
} // end of namespace mln
Index: mln/core/pixter2d_b.hh
--- mln/core/pixter2d_b.hh (revision 0)
+++ mln/core/pixter2d_b.hh (revision 0)
@@ -0,0 +1,103 @@
+// 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_PIXTER2D_B_HH
+# define MLN_CORE_PIXTER2D_B_HH
+
+# include <mln/core/internal/fast_iterator_base.hh>
+# include <mln/core/point2d.hh>
+# include <iostream>
+
+
+//FIXME comment
+/*! \file mln/core/pixter2d_b.hh
+ *
+ * \brief Pixel iterator class on a image 2d with border.
+ */
+
+# include <mln/core/concept/fast_iterator.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration
+ template <typename T> class image2d_b;
+
+ template <typename T>
+ class fwd_pixter2d_b :
+ public internal::fast_iterator_base_< fwd_pixter2d_b<T>, image2d_b<T> >
+ {
+ public:
+ /// Image pixel value type.
+ typedef mln_value(image2d_b<T>) value;
+
+ /*! \brief Constructor.
+ *
+ * \param[in] ima Image to iterate.
+ */
+ fwd_pixter2d_b(image2d_b<T>& ima);
+ /// Move the iterator to the next elements
+ void next_();
+
+ private:
+ unsigned border_size_;
+ unsigned row_offset_;
+ value *eor_;
+ };
+
+#ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ fwd_pixter2d_b<T>::fwd_pixter2d_b(image2d_b<T>& ima) :
+ border_size_(ima.border()),
+ row_offset_((ima.domain().pmax()[1] - ima.domain().pmin()[1])
+ + 2 * border_size_ + 1)
+ {
+ this->start_ = &ima(ima.domain().pmin());
+ this->eor_ = &ima(mk_point2d(ima.domain().pmin()[0], ima.domain().pmax()[1])) + 1;
+ this->eoi_ = &ima(ima.domain().pmax()) + 1;
+ }
+
+ template <typename T>
+ void fwd_pixter2d_b<T>::next_()
+ {
+ ++(this->current_);
+
+ if (this->current_ == this->eor_ and this->current_ != this->eoi_)
+ {
+ this->current_ += 2 * this->border_size_;
+ this->eor_ += this->row_offset_;
+ }
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+#endif // ! MLN_CORE_PIXTER2D_B_HH
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1006)
+++ mln/core/image2d_b.hh (working copy)
@@ -39,6 +39,8 @@
# include <mln/border/thickness.hh>
# include <mln/fun/all.hh>
+# include <mln/core/pixter2d_b.hh>
+# include <mln/core/dpoints_pixter.hh>
namespace mln
@@ -64,6 +66,15 @@
typedef fwd_piter piter;
// end of warning
+ /// Forward pixel iterator associated to image2d
+ typedef fwd_pixter2d_b<T> fwd_pixter;
+
+ /// Foward pixel iterator on dpoints assoicated to image 2d
+ typedef dpoints_pixter< image2d_b<T> > fwd_qixter;
+
+ typedef fwd_pixter pixter;
+ typedef fwd_qixter qixter;
+
/// Value associated type.
typedef T value;
@@ -131,6 +142,9 @@
/// Read-write access to the image value located at \p p.
T& operator()(const point2d& p);
+ /// Return an offset from a dpoints
+ int offset(const dpoint2d& dp);
+
/// Destructor.
~image2d_b();
@@ -350,6 +364,13 @@
}
}
+ template <typename T>
+ int
+ image2d_b<T>::offset(const dpoint2d& dp)
+ {
+ return dp[0] * vb_.pmax()[1] + dp[1];
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 0)
+++ mln/core/dpoints_pixter.hh (revision 0)
@@ -0,0 +1,145 @@
+// 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_DPOINTS_PIXTER_HH
+# define MLN_CORE_DPOINTS_PIXTER_HH
+
+# include <cassert>
+# include <vector>
+# include <mln/core/concept/fast_iterator.hh>
+
+
+namespace mln
+{
+ /*! \brief A generic forward iterator on image pixel of a windows and of
+ * neighborhoods.
+ *
+ * The parameter \c I is the image type.
+ */
+ template <typename I>
+ class dpoints_pixter : public Fast_Iterator< dpoints_pixter<I> >
+ {
+ public:
+ /// Image pixel value
+ typedef mln_value(I) value;
+ /// Image pixel rvalue
+ typedef mln_rvalue(I) rvalue;
+ /// Image pixel lvalue
+ typedef mln_lvalue(I) lvalue;
+
+ /*! \brief Constructo.
+ *
+ * \param[in] dps Object that can provide an array of delta-points.
+ * \param[in] p_ref Center point to iterate around.
+ * \param[in] ima Image to iterate.
+ */
+ template <typename Dps>
+ dpoints_pixter(const Dps& dps, const typename I::point& p_ref,I& ima);
+
+ /// Set the iterator at the start.
+ void start();
+ /// Go to the next pixel.
+ void next_();
+ /// Invalidate the iterator.
+ void invalidate();
+ /// Is the iterator valid?
+ bool is_valid() const;
+
+ /// Get the iterator value
+ rvalue operator* ();
+ lvalue operator* () const;
+
+ private:
+ /// offset of each dpoints
+ std::vector<int> offset_;
+ /// current offset
+ std::vector<int>::iterator i_;
+ /// reference pixel in the image
+ value* pixref_;
+ };
+
+
+#ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ template <typename Dps>
+ dpoints_pixter<I>::dpoints_pixter(const Dps& dps, const typename I::point& ref, I& ima)
+ {
+ pixref_ = &ima(ref);
+ for (typename std::vector<typename I::dpoint>::const_iterator it = dps.vec().begin();
+ it != dps.vec().end();
+ ++it)
+ offset_.push_back(ima.offset(*it));
+ }
+
+
+ template <typename I>
+ void dpoints_pixter<I>::start()
+ {
+ i_ = offset_.begin();
+ }
+
+ template <typename I>
+ void dpoints_pixter<I>::next_()
+ {
+ ++i_;
+ }
+
+ template <typename I>
+ bool dpoints_pixter<I>::is_valid() const
+ {
+ return i_ != offset_.end();
+ }
+
+ template <typename I>
+ void dpoints_pixter<I>::invalidate()
+ {
+ i_ = offset_.end();
+ }
+
+ template <typename I>
+ typename dpoints_pixter<I>::rvalue
+ dpoints_pixter<I>::operator* ()
+ {
+ assert(this->is_valid());
+ return *(pixref_ + *i_);
+ }
+
+ template <typename I>
+ typename dpoints_pixter<I>::lvalue
+ dpoints_pixter<I>::operator* () const
+ {
+ assert(this->is_valid());
+ return *(pixref_ + *i_);
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+}
+
+
+#endif // MLN_CORE_DPOINTS_PIXTER_HH
Index: mln/core/internal/fast_iterator_base.hh
--- mln/core/internal/fast_iterator_base.hh (revision 0)
+++ mln/core/internal/fast_iterator_base.hh (revision 0)
@@ -0,0 +1,138 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_INTERNAL_FAST_ITERATOR_BASE_HH
+# define MLN_CORE_INTERNAL_FAST_ITERATOR_BASE_HH
+
+/*! \file mln/core/internal/fast_iterator_base.hh
+ *
+ * \brief Base class for Fast_Iterator concept implementation.
+ * Usefull for code factorisation
+ */
+
+# include <mln/core/concept/fast_iterator.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+
+ /*! \brief fast_iterator_base_ class
+ */
+ template <typename Exact, typename Image>
+ class fast_iterator_base_ : public Fast_Iterator<Exact>
+ {
+ public:
+ /// Image pixel value type.
+ typedef mln_value(Image) value;
+ /// Image pixel rvalue type.
+ typedef mln_value(Image)& rvalue;
+ /// Image pixel lvalue type
+ typedef mln_value(Image) lvalue;
+
+ // Go to the beginning of the image.
+ void start();
+ // Go on the next element.
+ void next_();
+ // Invalidate the iterator.
+ void invalidate();
+ // Is the iterator referencing a correct position in the image?
+ bool is_valid() const;
+
+
+ // Return the current pixel.
+ rvalue operator* ();
+ lvalue operator* () const;
+
+ protected:
+ // beginning of the image
+ value* start_;
+ // end of the image
+ value* eoi_;
+ // current position in the image
+ value* current_;
+ // End of Factoriasable
+
+ fast_iterator_base_();
+ };
+
+#ifndef MLN_INCLUDE_ONLY
+
+ template <typename Exact, typename Image>
+ fast_iterator_base_<Exact, Image>::fast_iterator_base_()
+ {
+ }
+
+ template <typename Exact, typename Image>
+ void fast_iterator_base_<Exact, Image>::start()
+ {
+ current_ = start_;
+ }
+
+ template <typename Exact, typename Image>
+ void fast_iterator_base_<Exact, Image>::next_()
+ {
+ ++current_;
+ }
+
+ template <typename Exact, typename Image>
+ void fast_iterator_base_<Exact, Image>::invalidate()
+ {
+ current_ = eoi_;
+ }
+
+ template <typename Exact, typename Image>
+ bool fast_iterator_base_<Exact, Image>::is_valid() const
+ {
+ return (current_ != eoi_);
+ }
+
+ template <typename Exact, typename Image>
+ typename fast_iterator_base_<Exact, Image>::rvalue
+ fast_iterator_base_<Exact, Image>::operator*()
+ {
+ return *current_;
+ }
+
+
+ template <typename Exact, typename Image>
+ typename fast_iterator_base_<Exact, Image>::lvalue
+ fast_iterator_base_<Exact, Image>::operator*() const
+ {
+ return *current_;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_FAST_ITERATOR_BASE_HH