URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add test for convert/to_tiles.hh.
* convert_to_tiles.cc: New test.
---
convert_to_tiles.cc | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
Index: trunk/milena/tests/convert_to_tiles.cc
===================================================================
--- trunk/milena/tests/convert_to_tiles.cc (revision 0)
+++ trunk/milena/tests/convert_to_tiles.cc (revision 1294)
@@ -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.
+
+/*! \file tests/convert_to_tiles.cc
+ *
+ * \brief Tests on mln::convert::to_tiles.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/debug/iota.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/paste.hh>
+#include <mln/border/fill.hh>
+#include <mln/debug/println_with_border.hh>
+#include <mln/debug/println.hh>
+#include <mln/core/translate_image.hh>
+#include <mln/convert/to_tiles.hh>
+
+int main ()
+{
+ using namespace mln;
+
+ typedef image2d<value::int_u8> I;
+ std::vector<I> vec;
+
+ I ima1 (4, 2, 1);
+ level::fill(ima1, 1);
+ vec.push_back(ima1);
+
+ I ima2 (4, 2, 1);
+ level::fill(ima2, 2);
+ vec.push_back(ima2);
+
+ I ima3 (4, 2, 1);
+ level::fill(ima3, 3);
+ vec.push_back(ima3);
+
+ I ima4 (4, 2, 1);
+ level::fill(ima4, 4);
+ vec.push_back(ima4);
+
+ I ima5 (4, 2, 1);
+ level::fill(ima5, 5);
+ vec.push_back(ima5);
+
+ I ima6 (4, 2, 1);
+ level::fill(ima6, 6);
+ vec.push_back(ima6);
+
+ I ima7 (4, 2, 1);
+ level::fill(ima7, 7);
+ vec.push_back(ima7);
+
+ I ima8 (4, 2, 1);
+ level::fill(ima8, 8);
+ vec.push_back(ima8);
+
+ I ima9 (4, 2, 1);
+ level::fill(ima9, 9);
+ vec.push_back(ima9);
+
+ I output = convert::to_tiles(vec, 1.33333f);
+
+ debug::println (output);
+}
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
About nothing.
* mln/core/h_vec.hh: Clean-up.
(dim): New.
* mln/metal/vec.hh (value_type): Rename as...
(coord): ...this.
* mln/metal/mat.hh: Likewise.
(dim): New.
* mln/metal/math/pow.hh: Fix file doc.
* mln/metal/math/sqrt.hh: New.
* mln/metal/math/all.hh: Update.
* mln/fun/x2x/translation_alt.hh: New; just for the
record.
* mln/fun/internal/x2x_impl.hh: New.
core/h_vec.hh | 50 +++++++++++--------
fun/internal/x2x_impl.hh | 88 +++++++++++++++++++++++++++++++++++
fun/x2x/translation_alt.hh | 75 +++++++++++++----------------
metal/mat.hh | 7 +-
metal/math/all.hh | 1
metal/math/pow.hh | 2
metal/math/sqrt.hh | 113 +++++++++++++++++++++++++++++++++++++++++++++
metal/vec.hh | 2
8 files changed, 274 insertions(+), 64 deletions(-)
Index: mln/core/h_vec.hh
--- mln/core/h_vec.hh (revision 1292)
+++ mln/core/h_vec.hh (working copy)
@@ -41,38 +41,49 @@
{
- template <unsigned dim, typename T>
- struct h_vec : public metal::vec<dim + 1, T>
+ template <unsigned d, typename C>
+ struct h_vec : public metal::vec<d + 1, C>
{
- h_vec()
- : metal::vec<dim + 1, T>(make::vec<dim + 1, T>(0))
- { // FIXME: Move in MLN_INCLUDE_ONLY
- this->data_[dim] = 1;
- }
+ /// Dimension is the 'natural' one (3 for 3D), not the one of the vector (dim + 1).
+ enum { dim = d };
+
+ /// Constructor without argument.
+ h_vec();
- h_vec(const metal::vec<dim, T>& x);
+ /// Constructor from a metal::vec.
+ h_vec(const metal::vec<d,C>& x);
- operator metal::vec<dim, T>() const;
+ /// Conversion to a metal::vec.
+ operator metal::vec<d,C>() const;
};
+
# ifndef MLN_INCLUDE_ONLY
- template <unsigned dim, typename T>
- h_vec<dim,T>::h_vec(const metal::vec<dim, T>& x)
+ template <unsigned d, typename C>
+ h_vec<d,C>::h_vec()
+ {
+ }
+
+ template <unsigned d, typename C>
+ h_vec<d,C>::h_vec(const metal::vec<d,C>& x)
{
- for (unsigned i = 0; i < dim; ++i)
+ for (unsigned i = 0; i < d; ++i)
this->data_[i] = x[i];
- this->data_[dim] = 1;
+ this->data_[d] = 1; // FIXME: literal::one
}
- template <unsigned dim, typename T>
- h_vec<dim,T>::operator metal::vec<dim,T>() const
+ template <unsigned d, typename C>
+ h_vec<d,C>::operator metal::vec<d,C>() const
{
- metal::vec<dim,T> x;
- for (unsigned i = 0; i < dim; ++i)
- x[i] = this->data_[i] / this->data_[dim];
- return x;
+ const C w = this->data_[d];
+ mln_assertion(w != 0);
+
+ metal::vec<d,C> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = this->data_[i] / w;
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -80,5 +91,4 @@
} // end of namespace mln
-
#endif // ! MLN_CORE_H_VEC_HH
Index: mln/metal/mat.hh
--- mln/metal/mat.hh (revision 1292)
+++ mln/metal/mat.hh (working copy)
@@ -52,8 +52,11 @@
{
public:
- typedef T value_type;
- enum {N = n, M = m};
+ typedef T coord;
+ enum { N = n,
+ M = m,
+ dim = n * m };
+
static const mat<n,m,T> Id;
mat()
Index: mln/metal/math/pow.hh
--- mln/metal/math/pow.hh (revision 1292)
+++ mln/metal/math/pow.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/metal/math/pow.hh
*
- * \brief Definition of some mathematical static functions.
+ * \brief Definition of the 'power' static function.
*/
# include <mln/metal/bool.hh>
Index: mln/metal/math/all.hh
--- mln/metal/math/all.hh (revision 1292)
+++ mln/metal/math/all.hh (working copy)
@@ -50,6 +50,7 @@
# include <mln/metal/math/pow.hh>
+# include <mln/metal/math/sqrt.hh>
// ...
Index: mln/metal/math/sqrt.hh
--- mln/metal/math/sqrt.hh (revision 0)
+++ mln/metal/math/sqrt.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_METAL_MATH_SQRT_HH
+# define MLN_METAL_MATH_SQRT_HH
+
+/*! \file mln/metal/math/sqrt.hh
+ *
+ * \brief Definition of the 'sqrt' static function.
+ */
+
+# include <mln/metal/bool.hh>
+# include <mln/metal/int.hh>
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace math
+ {
+
+ // sqrt_int<x, n>
+
+ namespace impl
+ {
+
+ template <int n, int lo = 1, int hi = n>
+ struct sqrt_int_
+ {
+ enum { mid = (lo + hi + 1) / 2 };
+
+ enum { value = n < mid * mid
+ ? sqrt_int_<n, lo, mid-1>::value
+ : sqrt_int_<n, mid, hi>::result };
+ };
+
+ template<int n, int m>
+ struct sqrt_int_<n, m, m>
+ {
+ enum { value = m };
+ };
+
+ // Entry.
+
+ template <int n, bool b>
+ struct sqrt_int_if_ : sqrt_int_<n>
+ {
+ enum { value_ = sqrt_int_<n>::value,
+ reminder_ = n - value_ * value_ };
+ // FIXME: Check that reminder_ = 0.
+ };
+
+ template <int n>
+ struct sqrt_int_if_< n, false >
+ {
+ };
+
+ } // end of namespace mln::metal::math::impl
+
+ template <int n>
+ struct sqrt_int : impl::sqrt_int_if_< n, (n >= 0) >
+ {
+ };
+
+
+ // sqrt<N>
+
+ template <typename X, typename N>
+ struct sqrt;
+
+ template <int n>
+ struct sqrt< int_<n> > : sqrt_int<n>
+ {
+ typedef sqrt_int<n> super_;
+ typedef int_<super_::value> ret;
+ };
+
+
+ } // end of namespace mln::metal::math
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_MATH_SQRT_HH
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1292)
+++ mln/metal/vec.hh (working copy)
@@ -134,7 +134,7 @@
typedef T equiv[n];
typedef T enc[n];
- typedef T value_type;
+ typedef T coord;
enum { dim = n };
vec();
Index: mln/fun/x2x/translation_alt.hh
--- mln/fun/x2x/translation_alt.hh (revision 1287)
+++ mln/fun/x2x/translation_alt.hh (working copy)
@@ -25,17 +25,16 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_FUN_X2X_TRANSLATION_HH
-# define MLN_FUN_X2X_TRANSLATION_HH
+#ifndef MLN_FUN_X2X_TRANSLATION_ALT_HH
+# define MLN_FUN_X2X_TRANSLATION_ALT_HH
-/*! \file mln/fun/x2x/translation.hh
+/*! \file mln/fun/x2x/translation_alt.hh
*
* \brief FIXME.
*/
# include <mln/fun/x2x/bijective_tr.hh>
-# include <mln/metal/vec.hh>
-# include <mln/metal/mat.hh>
+# include <mln/fun/internal/x2x_base.hh>
namespace mln
@@ -50,76 +49,72 @@
// FIXME: Doc!
template <unsigned n, typename C>
- struct translation : public bijective_tr< translation<n,C> >
- {
+ struct translation_alt
+ :
- enum {dim = n};
+ fun::internal::x2x_base_< metal::vec<n,C>, translation_alt<n,C> >
+ ,
+ Function_x2x< translation_alt<n,C> >
- typedef metal::vec<n,C> result;
- typedef translation<n,C> invert;
+ // FIXME: Activate public bijective_tr< translation_alt<n,C> >
+ {
+ typedef fun::internal::x2x_base_< metal::vec<n,C>, translation_alt<n,C> > super_;
+ // typedef translation_alt<n,C> invert;
+ // invert inv() const;
- translation();
- translation(const metal::vec<n,C>& t);
+ translation_alt();
+ translation_alt(const metal::vec<n,C>& t);
+ using super_::operator();
result operator()(const metal::vec<n,C>& v) const;
- invert inv() const;
void set_t(const metal::vec<n,C>& t);
protected:
-
metal::vec<n,C> t_;
- metal::mat<n + 1,n + 1,C> m_;
};
# ifndef MLN_INCLUDE_ONLY
template <unsigned n, typename C>
- translation<n,C>::translation()
+ translation_alt<n,C>::translation_alt()
{
- t_ = make::vec<n,C>(0);
- m_ = metal::mat<n+1,n+1,C>::Id;
}
template <unsigned n, typename C>
- translation<n,C>::translation(const metal::vec<n,C>& t)
- :t_(t)
+ translation_alt<n,C>::translation_alt(const metal::vec<n,C>& t)
+ :
+ t_(t)
{
- m_ = metal::mat<n+1,n+1,C>::Id;
+ this->m_ = matrix::Id;
for (unsigned i = 0; i < n; ++i)
- m_(i,n) = t_[i];
+ this->m_(i,n) = t_[i];
}
template <unsigned n, typename C>
metal::vec<n,C>
- translation<n,C>::operator()(const metal::vec<n,C>& v) const
+ translation_alt<n,C>::operator()(const metal::vec<n,C>& v) const
{
- typename translation::result res;
- // FIXME: Why not "res = v + t_;"?
- for (unsigned i = 0; i < n; ++i)
- res[i] = v[i] + t_[i];
- return res;
- }
-
- template <unsigned n, typename C>
- translation<n,C>
- translation<n,C>::inv() const
- {
- typename translation::invert res(-t_);
-
- return res;
+ return v + t;
}
template <unsigned n, typename C>
void
- translation<n,C>::set_t(const metal::vec<n,C>& t)
+ translation_alt<n,C>::set_t(const metal::vec<n,C>& t)
{
t_ = t;
for (unsigned i = 0; i < n; ++i)
- m_(i,n) = t_[i];
+ this->m_(i, n) = t_[i];
}
+// template <unsigned n, typename C>
+// translation_alt<n,C>
+// translation_alt<n,C>::inv() const
+// {
+// typename translation_alt::invert res(-t_);
+// return res;
+// }
# endif // ! MLN_INCLUDE_ONLY
@@ -130,4 +125,4 @@
} // end of namespace mln
-#endif // ! MLN_FUN_X2X_TRANSLATION_HH
+#endif // ! MLN_FUN_X2X_TRANSLATION_ALT_HH
Index: mln/fun/internal/x2x_impl.hh
--- mln/fun/internal/x2x_impl.hh (revision 0)
+++ mln/fun/internal/x2x_impl.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_FUN_INTERNAL_X2X_IMPL_HH
+# define MLN_FUN_INTERNAL_X2X_IMPL_HH
+
+/*! \file mln/fun/internal/x2x_impl.hh
+ *
+ * \brief Implementation class for every Function_x2x.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/metal/mat.hh>
+# include <mln/core/h_vec.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace internal
+ {
+
+ template <typename V, typename E>
+ struct x2x_impl_
+ {
+ enum { dim = V::dim };
+
+ typedef V argument;
+ typedef V result;
+ typedef typename V::coord coord;
+
+ h_vec<dim, coord> operator()(const h_vec<dim, coord>& x) const
+ {
+ return m_ * x;
+ }
+
+ protected:
+ x2x_impl_();
+
+ metal::mat<dim+1, dim+1, coord> m_; // FIXME: Change mat into h_mat<dim, dim, coord>!
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, typename E>
+ x2x_impl_<V,E>::x2x_impl_()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::internal
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_INTERNAL_X2X_IMPL_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Move translate image into mln/core and add comment on some files.
New image.
* translate_image.hh: New.
Comment
* concept/image.hh,
* internal/image_domain_morpher.hh,
* internal/image_identity.hh: New comment.
* point.hh: Add operator -= between point and dpoint.
---
concept/image.hh | 3
internal/image_domain_morpher.hh | 2
internal/image_identity.hh | 3
point.hh | 12 ++
translate_image.hh | 196 +++++++++++++++++++++++++++++++++++++++
5 files changed, 214 insertions(+), 2 deletions(-)
Index: trunk/milena/mln/core/point.hh
===================================================================
--- trunk/milena/mln/core/point.hh (revision 1288)
+++ trunk/milena/mln/core/point.hh (revision 1289)
@@ -117,6 +117,9 @@
/// Shifting by \p dp.
point_<M,C>& operator+=(const dpoint& dp);
+ /// Shifting by \p the inverse of dp.
+ point_<M,C>& operator-=(const dpoint& dp);
+
/// Type of the array of coordinates.
typedef metal::vec<M::dim, C> vec_t;
@@ -187,6 +190,15 @@
}
template <typename M, typename C>
+ point_<M,C>&
+ point_<M,C>::operator-=(const dpoint& dp)
+ {
+ for (unsigned i = 0; i < dim; ++i)
+ coord_[i] -= dp[i];
+ return *this;
+ }
+
+ template <typename M, typename C>
point_<M,C>::operator typename internal::point_to_<M, C>::metal_vec () const
{
return coord_; // FIXME: Is-it OK?
Index: trunk/milena/mln/core/translate_image.hh
===================================================================
--- trunk/milena/mln/core/translate_image.hh (revision 0)
+++ trunk/milena/mln/core/translate_image.hh (revision 1289)
@@ -0,0 +1,196 @@
+// 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_TRANSLATE_IMAGE_HH
+# define MLN_CORE_TRANSLATE_IMAGE_HH
+
+/*! \file mln/core/translate_image.hh
+ *
+ * \brief Definition of a translated image.
+ */
+
+# include <cmath>
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/core/box2d.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename I> struct translate_image;
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< translate_image<I> >
+ {
+ data_(I& ima, const mln_dpoint(I) dp);
+
+ I ima_;
+ box2d bb_;
+ const mln_dpoint(I) dp_;
+ };
+
+ } // end of namespace mln::internal
+
+
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct image_< translate_image<I> > : default_image_morpher_< I, mln_value(I),
+ translate_image<I> >
+ {
+
+ typedef trait::image::category::domain_morpher category;
+
+ typedef mln_trait_image_io_from_(I) io;
+
+ typedef mln_trait_image_data_from_(I) data;
+
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename I>
+ struct translate_image : public mln::internal::image_identity_< I, mln_pset(I), translate_image<I> >
+ {
+
+ typedef mln::internal::image_morpher_< I, mln_pset(I), translate_image<I> > super_;
+
+ /// Return type of read-write access.
+ typedef typename internal::morpher_lvalue_<I>::ret lvalue;
+
+ /// Skeleton.
+ typedef translate_image< tag::image_<I> > skeleton;
+
+ /// Test if a pixel value is accessible at \p p.
+ using super_::has_data;
+
+ /// Constructors.
+ translate_image(I& ima, const mln_dpoint(I) dp);
+ translate_image();
+
+ /// Return domain of translated_image.
+ const box2d& domain() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_psite(I)& ) const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_rvalue(I) operator()(const mln_psite(I)& p) const;
+
+ /// Read and "write if possible" access of pixel value at point site \p p.
+ lvalue operator()(const mln_psite(I)& p);
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ // internal::data_< translate_image<I,S> >
+
+ template <typename I>
+ data_< translate_image<I> >::data_(I& ima, const mln_dpoint(I) dp)
+ : ima_ (ima),
+ dp_ (dp)
+ {
+ point2d start = ima.bbox ().pmin () + dp;
+ point2d end = ima.bbox ().pmax () + dp;
+ int x1 = start[0];
+ int y1 = start[1];
+ int x2 = end[0];
+ int y2 = end[1];
+
+ bb_ = make::box2d (x1, y1, x2, y2);
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename I>
+ translate_image<I>::translate_image(I& ima, const mln_dpoint(I) dp)
+ {
+ mln_precondition(ima.has_data());
+ this->data_ = new internal::data_< translate_image<I> >(ima, dp);
+ }
+
+ template <typename I>
+ translate_image<I>::translate_image()
+ {
+ }
+
+ template <typename I>
+ bool translate_image<I>::owns_(const mln_psite(I)& p) const
+ {
+ mln_point(I) np = p - this->data_->dp_;
+ return this->data_->ima_.owns_(np);
+ }
+
+ template <typename I>
+ mln_rvalue(I)
+ translate_image<I>::operator()(const mln_psite(I)& p) const
+ {
+ mln_assertion(this->owns_(p));
+ mln_point(I) np = p - this->data_->dp_;
+ return this->data_->ima_(np);
+ }
+
+
+ template <typename I>
+ typename translate_image<I>::lvalue
+ translate_image<I>::operator()(const mln_psite(I)& p)
+ {
+ mln_assertion(this->owns_(p));
+ mln_point(I) np = p - this->data_->dp_;
+ return this->data_->ima_(np);
+ }
+
+ template <typename I>
+ const box2d&
+ translate_image<I>::domain() const
+ {
+ return this->data_->bb_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_TRANSLATE_IMAGE_HH
Index: trunk/milena/mln/core/internal/image_identity.hh
===================================================================
--- trunk/milena/mln/core/internal/image_identity.hh (revision 1288)
+++ trunk/milena/mln/core/internal/image_identity.hh (revision 1289)
@@ -76,10 +76,13 @@
/// Read-write access of pixel value at point site \p p.
lvalue operator()(const mln_psite(S)& p);
+ // FIXME Matthieu: Doc! Cf. core/concept/doc/image
const mln_pset(I)& domain() const;
bool owns_(const mln_psite(I)& p) const;
protected:
+
+ /// Constructor.
image_identity_();
};
Index: trunk/milena/mln/core/internal/image_domain_morpher.hh
===================================================================
--- trunk/milena/mln/core/internal/image_domain_morpher.hh (revision 1288)
+++ trunk/milena/mln/core/internal/image_domain_morpher.hh (revision 1289)
@@ -73,7 +73,7 @@
/// Read-only access of pixel value at point site \p p.
rvalue operator()(const mln_psite(S)& p) const;
- /// Read-write access of pixel value at point site \p p.
+ /// Read and "write if possible" access of pixel value at point site \p p.
lvalue operator()(const mln_psite(S)& p);
protected:
Index: trunk/milena/mln/core/concept/image.hh
===================================================================
--- trunk/milena/mln/core/concept/image.hh (revision 1288)
+++ trunk/milena/mln/core/concept/image.hh (revision 1289)
@@ -82,7 +82,6 @@
typedef lvalue;
typedef vset;
- bool has_data() const;
const vset& values() const;
bool owns_(const psite& p) const;
@@ -109,6 +108,8 @@
bool has(const psite& p) const;
const box_<point>& bbox() const;
std::size_t npoints() const;
+
+ bool has_data() const;
*/
protected:
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-10 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add test for translate image.
* translate_image.cc: New test.
---
translate_image.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
Index: trunk/milena/tests/translate_image.cc
===================================================================
--- trunk/milena/tests/translate_image.cc (revision 0)
+++ trunk/milena/tests/translate_image.cc (revision 1288)
@@ -0,0 +1,76 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/translate_image.cc
+ *
+ * \brief Tests on mln::core::translate_image.hh.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/debug/iota.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/paste.hh>
+#include <mln/border/fill.hh>
+#include <mln/debug/println_with_border.hh>
+#include <mln/debug/println.hh>
+#include <mln/core/translate_image.hh>
+
+
+int main ()
+{
+ using namespace mln;
+
+ typedef image2d<value::int_u8> I;
+
+ I ima (4, 2, 1);
+ debug::iota (ima);
+ translate_image<I> tmp (ima, make::point2d (0,2) - make::point2d (0,0));
+ std::cout << "orginal image domain : "
+ << ima.domain ()
+ << std::endl
+ << "translated image domain : "
+ << tmp.domain ()
+ << std::endl;
+
+ std::cout << "original image :"
+ << std::endl;
+ debug::println (ima);
+ std::cout << std::endl;
+ std::cout << "translated image :"
+ << std::endl;
+ debug::println (tmp);
+
+ std::cout << std::endl;
+ I out (4,4);
+ level::paste(ima, out);
+ level::paste(tmp, out);
+ std::cout << "pasted image :"
+ << std::endl;
+ debug::println (out);
+ std::cout << std::endl;
+}
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean value traits.
Augment metal.
* mln/metal/int.hh: New.
* mln/metal/math: New directory.
(math): New namespace.
* mln/metal/math.hh: Rename as...
* mln/metal/math/pow.hh: ...this.
(pow): Move into math:: and rename as...
(pow_int): ...this.
(pow): New; work on metal::int_.
* mln/metal/math/all.hh: New.
* mln/metal/bool.hh (value): Strengthen type.
* mln/metal/all.hh: Update.
* mln/metal/is.hh (helper_is_): Change selector arg from &
to *; that allows for this tool to work on non-POD types.
* tests/metal_pow.cc: New.
Clean value traits.
* mln/trait/image_from_mesh.hh: Add FIXMEs.
* mln/trait/images.hh: Fix file doc.
* mln/trait/value_.hh: Augment.
* mln/trait/value/quant.hh: New.
* mln/trait/value/all.hh: New.
* mln/trait/value/print.hh: Update.
* mln/trait/value/nature.hh (unknown): New.
* mln/value/graylevel.hh,
* mln/value/float01_.hh,
* mln/value/builtin.hh,
* mln/value/int_s.hh,
* mln/value/int_u.hh,
* mln/value/int_u_sat.hh,
* mln/value/props.hh,
* mln/value/rgb.hh,
* mln/value/rgb8_non_templated.hh,
* mln/value/label.hh: Update.
Misc.
* mln/fun/x2x/bijective_tr.hh: Fix.
* mln/morpho/erosion.hh (erosion): New overload with output as
return.
* tests/morpho_erosion.cc: Update.
mln/fun/x2x/bijective_tr.hh | 21 +++++++--
mln/metal/all.hh | 4 -
mln/metal/bool.hh | 5 ++
mln/metal/int.hh | 72 +++++++++++++++++++++++++++++++
mln/metal/is.hh | 7 +--
mln/metal/math/all.hh | 57 ++++++++++++++++++++++++
mln/metal/math/pow.hh | 66 ++++++++++++++++++++++++----
mln/morpho/erosion.hh | 18 +++++++
mln/trait/image_from_mesh.hh | 5 ++
mln/trait/images.hh | 2
mln/trait/value/all.hh | 58 +++++++++++++++++++++++++
mln/trait/value/nature.hh | 2
mln/trait/value/print.hh | 15 +++++-
mln/trait/value/quant.hh | 62 ++++++++++++++++++++++++++
mln/trait/value_.hh | 65 +++++++++++++++++++++++-----
mln/value/builtin.hh | 92 ++++++++++++++++++++++++++++++++++++++++
mln/value/float01_.hh | 4 -
mln/value/graylevel.hh | 4 -
mln/value/int_s.hh | 10 ++--
mln/value/int_u.hh | 11 ++--
mln/value/int_u_sat.hh | 4 -
mln/value/label.hh | 6 +-
mln/value/props.hh | 7 +++
mln/value/rgb.hh | 2
mln/value/rgb8_non_templated.hh | 2
tests/metal_pow.cc | 47 ++++++++++++++++++++
tests/morpho_erosion.cc | 7 +--
27 files changed, 598 insertions(+), 57 deletions(-)
Index: tests/metal_pow.cc
--- tests/metal_pow.cc (revision 0)
+++ tests/metal_pow.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/metal_pow.cc
+ *
+ * \brief Test on mln::metal::math::pow.
+ */
+
+#include <iostream>
+#include <mln/core/contract.hh>
+#include <mln/metal/math/pow.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using namespace mln::metal;
+
+ int res = metal::math::pow_int<2,3>::value;
+ mln_assertion(res = 8);
+
+ std::cout << metal::math::pow< int_<2>, int_<3> >::ret().name() << std::endl;
+}
Index: tests/morpho_erosion.cc
--- tests/morpho_erosion.cc (revision 1286)
+++ tests/morpho_erosion.cc (working copy)
@@ -69,10 +69,9 @@
}
{
- win::octagon2d oct(31);
- image2d<int_u8> out(lena.domain());
- morpho::erosion(lena, oct, out);
- io::pgm::save(out, "out2.pgm");
+ io::pgm::save(morpho::erosion(lena,
+ win::octagon2d(31)),
+ "out2.pgm");
}
// {
Index: mln/trait/image_from_mesh.hh
--- mln/trait/image_from_mesh.hh (revision 1286)
+++ mln/trait/image_from_mesh.hh (working copy)
@@ -74,6 +74,11 @@
};
+ // FIXME: Return other image types than imagend when size trait is not regular...
+
+ // FIXME: Add cases when the mesh is not a grid...
+
+
} // end of namespace mln::trait
} // end of namespace mln
Index: mln/trait/images.hh
--- mln/trait/images.hh (revision 1286)
+++ mln/trait/images.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/trait/images.hh
*
- * \brief Forward declarations of all image types.
+ * \brief Some base trait types for images.
*
* \todo Split this file into many.
*/
Index: mln/trait/value_.hh
--- mln/trait/value_.hh (revision 1286)
+++ mln/trait/value_.hh (working copy)
@@ -28,24 +28,31 @@
#ifndef MLN_TRAIT_VALUE__HH
# define MLN_TRAIT_VALUE__HH
-/*! \file mln/trait/images.hh
+/*! \file mln/trait/value_.hh
*
- * \brief Forward declarations of all image types.
- *
- * \todo Split this file into many.
+ * \brief Some base trait types for value types.
*/
# include <iostream>
# include <string>
-# include <mln/trait/undef.hh>
+# include <mln/metal/math/pow.hh>
+# include <mln/metal/if.hh>
-# include <mln/trait/value/nature.hh>
-# include <mln/trait/value/kind.hh>
+# include <mln/trait/value/all.hh>
-# define mln_trait_value_nature(I) typename mln::trait::value_< V >::nature
+# define mln_trait_value_nature(V) typename mln::trait::value_< V >::nature
# define mln_trait_value_kind(V) typename mln::trait::value_< V >::kind
+# define mln_trait_value_quant(V) typename mln::trait::value_< V >::quant
+# define mln_trait_value_card(V) typename mln::trait::value_< V >::card
+
+
+# define mln_value_quant_from_card(C) \
+ mlc_if(mln::metal::bool_<( C::value > 65536 || C::value = 0 )>, \
+ mln::trait::value::quant::high, \
+ mln::trait::value::quant::low)
+
namespace mln
@@ -55,17 +62,55 @@
{
- template <typename V>
struct undefined_value_
{
typedef undef nature;
typedef undef kind;
+ typedef undef quant;
+ typedef undef card;
+ typedef undef sum;
+ // FIXME: signed or not, with zero or not, centered or not, etc.
+ };
+
+
+ struct default_value_
+ {
+ typedef trait::value::nature::unknown nature;
+ typedef trait::value::kind::data kind;
+ typedef trait::value::quant::high quant;
+ typedef metal::int_<0> card;
+ typedef undef sum;
};
template <typename V>
- struct value_ : undefined_value_<V>
+ struct value_ : undefined_value_
+ {
+ };
+
+
+ template <unsigned n_bits, int card_ = 1>
+ struct value_integer_
+ {
+ typedef metal::math::pow_int<2, n_bits> pow_;
+
+ typedef metal::int_<n_bits> nbits;
+ typedef trait::value::nature::integer nature;
+ typedef trait::value::kind::data kind;
+ typedef metal::int_<pow_::value> card;
+ typedef mln_value_quant_from_card(card) quant;
+ typedef float sum;
+ };
+
+ template <unsigned n_bits>
+ struct value_integer_< n_bits, 0 >
{
+ typedef metal::int_<n_bits> nbits;
+ typedef trait::value::nature::integer nature;
+ typedef value::kind::data kind;
+ typedef metal::int_<0> card;
+ typedef value::quant::high quant;
+ typedef float sum;
};
Index: mln/trait/value/quant.hh
--- mln/trait/value/quant.hh (revision 0)
+++ mln/trait/value/quant.hh (revision 0)
@@ -0,0 +1,62 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_VALUE_QUANT_HH
+# define MLN_TRAIT_VALUE_QUANT_HH
+
+/*! \file mln/trait/value/quant.hh
+ *
+ * \brief Quantification of values (for use in images).
+ */
+
+# include <string>
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace value
+ {
+
+ struct quant
+ {
+ struct any {};
+ struct low : any { std::string name() const { return "quant::low"; } };
+ struct high : any { std::string name() const { return "quant::high"; } };
+ };
+
+ } // end of namespace mln::trait::quant
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_VALUE_QUANT_HH
Index: mln/trait/value/all.hh
--- mln/trait/value/all.hh (revision 0)
+++ mln/trait/value/all.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_VALUE_ALL_HH
+# define MLN_TRAIT_VALUE_ALL_HH
+
+/*! \file mln/trait/value/all.hh
+ *
+ * \brief FIXME
+ */
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ /// FIXME: Doc!
+ namespace value {}
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+
+# include <mln/trait/undef.hh>
+# include <mln/trait/value/nature.hh>
+# include <mln/trait/value/kind.hh>
+# include <mln/trait/value/quant.hh>
+
+
+#endif // ! MLN_TRAIT_VALUE_ALL_HH
Index: mln/trait/value/print.hh
--- mln/trait/value/print.hh (revision 1286)
+++ mln/trait/value/print.hh (working copy)
@@ -55,17 +55,28 @@
template <typename V>
void print(std::ostream& ostr);
+ template <typename V>
+ void print(const Value<V>& v, std::ostream& ostr);
+
# ifndef MLN_INCLUDE_ONLY
template <typename V>
void print(std::ostream& ostr)
{
- mlc_is_a(V, Value)::check();
+ mlc_is_a(V, Value)::check(); // FIXME: What about built-ins?
typedef mln::trait::value_<V> the;
ostr << "{ "
<< typename the::nature().name() << ", "
- << typename the::kind() .name() << " }" << std::endl;
+ << typename the::kind() .name() << ", "
+ << typename the::quant() .name() << ", "
+ << typename the::card() .name() << " }" << std::endl;
+ }
+
+ template <typename V>
+ void print(const Value<V>&, std::ostream& ostr)
+ {
+ print<V>(ostr);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/trait/value/nature.hh
--- mln/trait/value/nature.hh (revision 1286)
+++ mln/trait/value/nature.hh (working copy)
@@ -56,6 +56,8 @@
struct vectorial : any { std::string name() const { return "nature::vectorial"; } };
struct symbolic : any { std::string name() const { return "nature::symbolic"; } };
struct structured : any { std::string name() const { return "nature::structured"; } };
+
+ struct unknown : any { std::string name() const { return "nature::unknown"; } };
};
} // end of namespace mln::trait::value
Index: mln/metal/int.hh
--- mln/metal/int.hh (revision 0)
+++ mln/metal/int.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_METAL_INT_HH
+# define MLN_METAL_INT_HH
+
+/*! \file mln/metal/int.hh
+ *
+ * \brief Definition of an integer value type.
+ */
+
+# include <string>
+# include <sstream>
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ /// "int" type.
+ template <int i>
+ struct int_
+ {
+ static const int value = i;
+ std::string name() const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <int i>
+ std::string int_<i>::name() const
+ {
+ std::ostringstream o;
+ o << "metal::int_<" << i << ">";
+ return o.str();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_INT_HH
Index: mln/metal/math/pow.hh
--- mln/metal/math/pow.hh (revision 0)
+++ mln/metal/math/pow.hh (working copy)
@@ -25,14 +25,17 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_METAL_MATH_HH
-# define MLN_METAL_MATH_HH
+#ifndef MLN_METAL_MATH_POW_HH
+# define MLN_METAL_MATH_POW_HH
-/*! \file mln/metal/math.hh
+/*! \file mln/metal/math/pow.hh
*
* \brief Definition of some mathematical static functions.
*/
+# include <mln/metal/bool.hh>
+# include <mln/metal/int.hh>
+
namespace mln
{
@@ -40,24 +43,69 @@
namespace metal
{
- // pow<x, n>
+ namespace math
+ {
+
+ // pow_int<x, n>
- template <int x, unsigned n>
- struct pow
+ namespace impl
{
- enum { value = x * pow<x, n-1>::value };
+
+ template <int x, int n>
+ struct pow_int_
+ {
+ enum { value = x * pow_int_<x, n-1>::value };
};
template <int x>
- struct pow< x, 0 >
+ struct pow_int_< x, 0 >
{
enum { value = 1 };
};
+ template <>
+ struct pow_int_< 0, 0 >;
+
+
+ // Entry.
+
+ template <int x, int n, bool b>
+ struct pow_int_if_ : pow_int_<x, n>
+ {
+ };
+
+ template <int x, int n>
+ struct pow_int_if_< x, n, false >
+ {
+ };
+
+ }
+
+ template <int x, int n>
+ struct pow_int : impl::pow_int_if_< x, n,
+ (n >= 0 && ! (x = 0 && n = 0)) >
+ {
+ };
+
+
+ // pow<X, N>
+
+ template <typename X, typename N>
+ struct pow;
+
+ template <int x, int n>
+ struct pow< int_<x>, int_<n> > : pow_int<x, n>
+ {
+ typedef pow_int<x, n> super_;
+ typedef int_<super_::value> ret;
+ };
+
+
+ } // end of namespace mln::metal::math
} // end of namespace mln::metal
} // end of namespace mln
-#endif // ! MLN_METAL_MATH_HH
+#endif // ! MLN_METAL_MATH_POW_HH
Index: mln/metal/math/all.hh
--- mln/metal/math/all.hh (revision 0)
+++ mln/metal/math/all.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.
+
+#ifndef MLN_METAL_MATH_ALL_HH
+# define MLN_METAL_MATH_ALL_HH
+
+/*! \file mln/metal/math/all.hh
+ *
+ * \brief Include all static mathematical functions.
+ */
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ /// Namespace of static mathematical functions.
+ namespace math {}
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+
+# include <mln/metal/math/pow.hh>
+// ...
+
+
+
+#endif // ! MLN_METAL_MATH_ALL_HH
Index: mln/metal/bool.hh
--- mln/metal/bool.hh (revision 1286)
+++ mln/metal/bool.hh (working copy)
@@ -33,6 +33,8 @@
* \brief Definition of a Boolean value type.
*/
+# include <string>
+
namespace mln
{
@@ -43,6 +45,7 @@
// Fwd decl.
template <bool b> struct bool_;
+
/// "true" type.
template <>
struct bool_< true >
@@ -50,6 +53,7 @@
static const bool value = true;
typedef bool_<true> eval;
static void check();
+ std::string name() const { return "true"; }
};
typedef bool_<true> true_;
@@ -62,6 +66,7 @@
static const bool value = false;
typedef bool_<false> eval;
static void check_not();
+ std::string name() const { return "false"; }
};
typedef bool_<false> false_;
Index: mln/metal/all.hh
--- mln/metal/all.hh (revision 1286)
+++ mln/metal/all.hh (working copy)
@@ -55,8 +55,6 @@
# include <mln/metal/is_a.hh>
# include <mln/metal/goes_to.hh>
-# include <mln/metal/math.hh>
-
# include <mln/metal/const.hh>
# include <mln/metal/unconst.hh>
# include <mln/metal/is_const.hh>
@@ -70,6 +68,8 @@
# include <mln/metal/vec.hh>
# include <mln/metal/mat.hh>
+# include <mln/metal/math/all.hh>
+
// FIXME: Remove the following includes below!
# include <mln/metal/same_coord.hh>
# include <mln/metal/same_point.hh>
Index: mln/metal/is.hh
--- mln/metal/is.hh (revision 1286)
+++ mln/metal/is.hh (working copy)
@@ -52,7 +52,7 @@
template <typename T, typename U>
struct helper_is_
{
- static yes_ selector(U&);
+ static yes_ selector(U*const);
static no_ selector(...);
};
@@ -65,10 +65,11 @@
* FIXME: Doc!
*/
template <typename T, typename U>
- struct is : bool_<( sizeof(internal::helper_is_<T, U>::selector(*internal::make_<T>::ptr()))
+ struct is : bool_<( sizeof(internal::helper_is_<T, U>::selector(internal::make_<T>::ptr()))
=
sizeof(internal::yes_) )>
- {};
+ {
+ };
template <typename T, typename U>
struct is< T*, U* > : is<T, U>::eval
Index: mln/value/graylevel.hh
--- mln/value/graylevel.hh (revision 1286)
+++ mln/value/graylevel.hh (working copy)
@@ -31,7 +31,7 @@
# include <iostream>
# include <mln/core/contract.hh>
-# include <mln/metal/math.hh>
+# include <mln/metal/math/pow.hh>
# include <mln/metal/bexpr.hh>
# include <mln/value/int_u.hh>
@@ -76,7 +76,7 @@
template <unsigned n>
struct props< graylevel<n> >
{
- static const std::size_t card_ = metal::pow<2, n>::value;
+ static const std::size_t card_ = metal::math::pow_int<2, n>::value;
static const graylevel<n> min() { return 0; }
static const graylevel<n> max() { return card_ - 1; }
static const unsigned nbits = n;
Index: mln/value/float01_.hh
--- mln/value/float01_.hh (revision 1286)
+++ mln/value/float01_.hh (working copy)
@@ -30,7 +30,7 @@
# include <iostream>
# include <mln/core/contract.hh>
-# include <mln/metal/math.hh>
+# include <mln/metal/math/pow.hh>
# include <mln/metal/bexpr.hh>
# include <mln/value/int_u.hh>
@@ -101,7 +101,7 @@
template <unsigned n>
struct props< float01_<n> >
{
- static const std::size_t card_ = metal::pow<2, n>::value;
+ static const std::size_t card_ = metal::math::pow_int<2, n>::value;
static const float min() { return 0.f; }
static const float max() { return 1.f; }
static const unsigned nbits = n;
Index: mln/value/builtin.hh
--- mln/value/builtin.hh (revision 1286)
+++ mln/value/builtin.hh (working copy)
@@ -29,10 +29,13 @@
# define MLN_VALUE_BUILTIN_HH
/*! \file mln/value/builtin.hh
+ *
* \brief Some definitions about builtins.
*/
# include <mln/core/category.hh>
+# include <mln/metal/int.hh>
+# include <mln/trait/value_.hh>
namespace mln
@@ -68,6 +71,95 @@
// FIXME: ...
+ namespace trait
+ {
+
+ // Fwd decl.
+ template <typename V> struct value_;
+
+
+ // Bool.
+
+ template <>
+ struct value_< bool>
+ {
+ typedef metal::int_<1> nbits;
+ typedef value::nature::symbolic nature;
+ typedef value::kind::binary kind;
+ typedef value::quant::low quant;
+ typedef metal::int_<2> card;
+ };
+
+
+ // Integer.
+
+ template <>
+ struct value_< unsigned char > : value_integer_<8>
+ {
+ };
+
+ template <>
+ struct value_< signed char > : value_integer_<8>
+ {
+ };
+
+ template <>
+ struct value_< unsigned short > : value_integer_<16>
+ {
+ };
+
+ template <>
+ struct value_< signed short > : value_integer_<16>
+ {
+ };
+
+ template <>
+ struct value_< unsigned int > : value_integer_<8 * sizeof(unsigned int), 0>
+ {
+ };
+
+ template <>
+ struct value_< signed int > : value_integer_<8 * sizeof(signed int), 0>
+ {
+ };
+
+ template <>
+ struct value_< unsigned long int > : value_integer_<8 * sizeof(unsigned long), 0>
+ {
+ };
+
+ template <>
+ struct value_< signed long int > : value_integer_<8 * sizeof(signed long), 0>
+ {
+ };
+
+
+ // Floating.
+
+ template <>
+ struct value_< float >
+ {
+ typedef metal::int_<8*sizeof(float)> nbits;
+ typedef value::nature::floating nature;
+ typedef value::kind::data kind;
+ typedef metal::int_<0> card;
+ typedef value::quant::high quant;
+ typedef float sum;
+ };
+
+ template <>
+ struct value_< double >
+ {
+ typedef metal::int_<8*sizeof(double)> nbits;
+ typedef value::nature::floating nature;
+ typedef value::kind::data kind;
+ typedef metal::int_<0> card;
+ typedef value::quant::high quant;
+ typedef double sum;
+ };
+
+ } // end of namespace mln::trait
+
} // end of namespace mln
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1286)
+++ mln/value/int_s.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Define a generic class for signed integers.
*/
-# include <mln/metal/math.hh>
+# include <mln/metal/math/pow.hh>
# include <mln/value/internal/value_like.hh>
# include <mln/value/concept/integer.hh>
# include <mln/value/internal/encoding.hh>
@@ -137,8 +137,8 @@
template <unsigned n>
struct props< int_s<n> >
{
- static const std::size_t card_ = metal::pow<2, n>::value - 1;
- static const int_s<n> max() { return metal::pow<2, n-1>::value - 1; }
+ static const std::size_t card_ = metal::math::pow_int<2, n>::value - 1;
+ static const int_s<n> max() { return metal::math::pow_int<2, n-1>::value - 1; }
static const int_s<n> min() { return - max(); }
static const unsigned nbits = n;
typedef trait::value::kind::data kind;
@@ -175,7 +175,7 @@
template <unsigned n>
int_s<n>::int_s(int i)
{
- static const int max = metal::pow<2, n-1>::value - 1;
+ static const int max = metal::math::pow_int<2, n-1>::value - 1;
static const int min = - max;
mln_precondition(i >= min);
mln_precondition(i <= max);
@@ -186,7 +186,7 @@
int_s<n>&
int_s<n>::operator=(int i)
{
- static const int max = metal::pow<2, n-1>::value - 1;
+ static const int max = metal::math::pow_int<2, n-1>::value - 1;
static const int min = - max;
mln_precondition(i >= min);
mln_precondition(i <= max);
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1286)
+++ mln/value/int_u.hh (working copy)
@@ -33,12 +33,13 @@
* \brief Define a generic class for unsigned integers.
*/
-# include <mln/metal/math.hh>
+# include <mln/metal/math/pow.hh>
# include <mln/value/internal/value_like.hh>
# include <mln/value/internal/encoding.hh>
# include <mln/value/concept/integer.hh>
# include <mln/value/props.hh>
-# include <mln/trait/all.hh>
+# include <mln/trait/all.hh> // FIXME!
+# include <mln/trait/value_.hh>
# include <mln/debug/format.hh>
@@ -81,10 +82,8 @@
// FIXME: Is that all? (No!)
template <unsigned n>
- struct value_< mln::value::int_u<n> >
+ struct value_< mln::value::int_u<n> > : mln::trait::value_integer_<8>
{
- typedef trait::value::nature::integer nature;
- typedef trait::value::kind::data kind;
};
} // end of namespace mln::trait
@@ -144,7 +143,7 @@
template <unsigned n>
struct props< int_u<n> >
{
- static const std::size_t card_ = metal::pow<2, n>::value;
+ static const std::size_t card_ = metal::math::pow_int<2, n>::value;
static const int_u<n> min() { return 0; }
static const int_u<n> max() { return card_ - 1; }
static const unsigned nbits = n;
Index: mln/value/int_u_sat.hh
--- mln/value/int_u_sat.hh (revision 1286)
+++ mln/value/int_u_sat.hh (working copy)
@@ -34,7 +34,7 @@
* behavior.
*/
-# include <mln/metal/math.hh>
+# include <mln/metal/math/pow.hh>
# include <mln/value/internal/value_like.hh>
# include <mln/value/concept/integer.hh>
# include <mln/value/internal/encoding.hh>
@@ -98,7 +98,7 @@
template <unsigned n>
struct props< int_u_sat<n> >
{
- static const std::size_t card_ = metal::pow<2, n>::value;
+ static const std::size_t card_ = metal::math::pow_int<2, n>::value;
static const int_u_sat<n> min() { return 0; }
static const int_u_sat<n> max() { return card_ - 1; }
static const unsigned nbits = n;
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1286)
+++ mln/value/props.hh (working copy)
@@ -106,6 +106,13 @@
}
};
+ template <typename T>
+ struct helper_quant_
+ {
+ static const std::size_t card = mln::value::props<T>::card_;
+
+ };
+
} // end of namespace mln::value::internal
Index: mln/value/rgb.hh
--- mln/value/rgb.hh (revision 1286)
+++ mln/value/rgb.hh (working copy)
@@ -133,7 +133,7 @@
struct props< rgb<n> >
{
static const unsigned nbits = 24;
- static const std::size_t card_ = 0; // FIXME: was: metal::pow<2, nbits>::value;
+ static const std::size_t card_ = 0; // FIXME: was: metal::math::pow_int<2, nbits>::value;
typedef trait::value::kind::color kind;
typedef float_x3_t sum;
typedef uchar_x3_t interop;
Index: mln/value/rgb8_non_templated.hh
--- mln/value/rgb8_non_templated.hh (revision 1286)
+++ mln/value/rgb8_non_templated.hh (working copy)
@@ -105,7 +105,7 @@
struct props< rgb8 >
{
static const unsigned nbits = 24;
- static const std::size_t card_ = metal::pow<2, nbits>::value;
+ static const std::size_t card_ = metal::math::pow_int<2, nbits>::value;
typedef trait::value::kind::color kind;
typedef float_x3_t sum;
typedef uchar_x3_t interop;
Index: mln/value/label.hh
--- mln/value/label.hh (revision 1286)
+++ mln/value/label.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Define a generic class for labels.
*/
-# include <mln/metal/math.hh>
+# include <mln/metal/math/pow.hh>
# include <mln/value/internal/value_like.hh>
# include <mln/value/concept/symbolic.hh>
# include <mln/value/internal/encoding.hh>
@@ -129,7 +129,7 @@
template <unsigned n>
struct props< label<n> >
{
- static const std::size_t card_ = metal::pow<2, n>::value;
+ static const std::size_t card_ = metal::math::pow_int<2, n>::value;
static const label<n> min; // = 0
static const label<n> max; // = card_ - 1
static const unsigned nbits = n;
@@ -222,7 +222,7 @@
template <unsigned n>
const label<n>
- props< label<n> >::max = metal::pow<2, n>::value - 1;
+ props< label<n> >::max = metal::math::pow_int<2, n>::value - 1;
template <unsigned n>
std::ostream& operator<<(std::ostream& ostr, const label<n>& i)
Index: mln/fun/x2x/bijective_tr.hh
--- mln/fun/x2x/bijective_tr.hh (revision 1286)
+++ mln/fun/x2x/bijective_tr.hh (working copy)
@@ -52,12 +52,27 @@
template <typename E>
struct bijective_tr : public Function_x2x< E >
{
- typedef E::result result;
- typedef E::invert invert;
-
+ /*
+ typedef invert;
invert inv() const;
+ */
+ protected:
+ bijective_tr();
};
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ bijective_tr<E>::bijective_tr()
+ {
+ typedef typename E::invert invert;
+ invert (E::*m)() const = & E::inv;
+ m = 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln::fun::x2x
} // end of namespace mln::fun
Index: mln/morpho/erosion.hh
--- mln/morpho/erosion.hh (revision 1286)
+++ mln/morpho/erosion.hh (working copy)
@@ -55,6 +55,12 @@
void erosion(const Image<I>& input, const Window<W>& win, Image<O>& output);
+ // FIXME: Doc!
+ template <typename I, typename W>
+ mln_concrete(I)
+ erosion(const Image<I>& input, const Window<W>& win);
+
+
# ifndef MLN_INCLUDE_ONLY
namespace impl
@@ -108,7 +114,7 @@
- // Facade.
+ // Facades.
template <typename I, typename W, typename O>
void erosion(const Image<I>& input, const Window<W>& win, Image<O>& output)
@@ -124,6 +130,16 @@
trace::exiting("morpho::erosion");
}
+ template <typename I, typename W>
+ mln_concrete(I)
+ erosion(const Image<I>& input, const Window<W>& win)
+ {
+ mln_concrete(I) output;
+ initialize(output, input);
+ erosion(input, win, output);
+ return output;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-09 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Improve hexagonal images. Fixme : doesn't work properly now.
* mln/debug/println.hh: Println for hexa images.
* mln/core/box2d_h.hh: Box with hexa points.
* mln/core/hexa.hh: Hexa image class declaration.
* tests/hexa.cc: Hexa test
* tests/image2d_h.cc: hexagonal image2d test.
* mln/core/hexa_piter.hh: Hexagonal iterator.
* mln/core/image2d_h.hh: Shortcut to hexa< image2d<V> >
---
mln/core/box2d_h.hh | 11 +--
mln/core/hexa.hh | 55 ++++++++++++------
mln/core/hexa_piter.hh | 147 +++++++++++++++++++++++++++++++++++++++++++++++++
mln/core/image2d_h.hh | 86 ++++++++++++++++++++++++++++
mln/debug/println.hh | 41 +++++++++++++
tests/hexa.cc | 8 +-
tests/image2d_h.cc | 65 +++++++++++++++++++++
7 files changed, 386 insertions(+), 27 deletions(-)
Index: trunk/milena/tests/image2d_h.cc
===================================================================
--- trunk/milena/tests/image2d_h.cc (revision 0)
+++ trunk/milena/tests/image2d_h.cc (revision 1286)
@@ -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/hexa.cc
+ *
+ * \brief Tests on mln::hexa
+ */
+
+#include <mln/core/image2d_h.hh>
+
+#include <mln/value/int_u16.hh>
+#include <mln/trait/image/print.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u16;
+
+ image2d_h<int_u16> h(2,7);
+
+ debug::iota(h);
+
+ debug::println(h);
+
+// image2d<int_u16> h(2,7);
+// debug::println(h);
+
+ trait::image::print(h, std::cout);
+
+
+ // FIXME : to put into debug::println
+ image2d_h<int_u16>::fwd_piter p(h.domain());
+
+// for_all(p)
+// {
+// std::cout << p << "->" << std::endl;
+// }
+}
Index: trunk/milena/tests/hexa.cc
===================================================================
--- trunk/milena/tests/hexa.cc (revision 1285)
+++ trunk/milena/tests/hexa.cc (revision 1286)
@@ -35,6 +35,7 @@
#include <mln/value/int_u8.hh>
#include <mln/trait/image/print.hh>
+#include <mln/debug/iota.hh>
int main()
@@ -46,14 +47,15 @@
I ima(3,3);
hexa<I> h(ima);
-
+ debug::iota(ima);
trait::image::print(h, std::cout);
// FIXME : to put into debug::println
- I::fwd_piter p(ima.domain());
+ hexa<I>::fwd_piter p(h.domain());
+
for_all(p)
{
- ;
+ std::cout << p << "->" << h(p) << std::endl;
}
}
Index: trunk/milena/mln/debug/println.hh
===================================================================
--- trunk/milena/mln/debug/println.hh (revision 1285)
+++ trunk/milena/mln/debug/println.hh (revision 1286)
@@ -56,8 +56,11 @@
// generic version
template <typename S, typename I>
- void println(const S&, const Image<I>& input_)
+ void println(const S& b, const Image<I>& input_)
{
+ void* tes = exact(input_);
+ void* a = b;
+
const I& input = exact(input_);
mln_piter(I) p(input.domain());
for_all(p)
@@ -92,6 +95,42 @@
# endif // MLN_CORE_BOX2D_HH
+# ifdef MLN_CORE_IMAGE2D_H_HH
+
+ // Hexa version
+ template <typename I>
+ void println(const box2d_h& b, const hexa<I>& input)
+ {
+ typename hexa<I>::fwd_piter p(input.domain());
+
+ int c = 1;
+ int r = 1;
+ int row_len = (b.max_col() - b.min_col()) / 2;
+
+ for_all(p)
+ {
+ //if (input.has(p))
+ //std::cout << p << " ";
+ std::cout << format(input(p)) << " ";
+ //else
+ // std::cout << " ";
+
+ if (c >= row_len)
+ {
+ std::cout << std::endl;
+ if (r % 2)
+ std::cout << " ";
+ c = 0;
+ r++;
+ }
+ c++;
+ }
+ std::cout << std::endl;
+ }
+
+# endif // MLN_CORE_IMAGE2D_H_HH
+
+
# ifdef MLN_CORE_BOX3D_HH
template <typename I>
Index: trunk/milena/mln/core/hexa.hh
===================================================================
--- trunk/milena/mln/core/hexa.hh (revision 1285)
+++ trunk/milena/mln/core/hexa.hh (revision 1286)
@@ -37,6 +37,8 @@
# include <mln/core/internal/image_domain_morpher.hh>
# include <mln/core/point2d_h.hh>
+# include <mln/core/box2d_h.hh>
+# include <mln/core/hexa_piter.hh>
namespace mln
@@ -51,9 +53,10 @@
template <typename I>
struct data_< hexa<I> >
{
- data_(I& ima);
+ data_(I& ima, box2d_h b);
I ima_;
+ mln::box2d_h b_;
};
} // end of namespace mln::internal
@@ -92,22 +95,24 @@
* which handles hexagonal grid.
*
* Ex :
+ * 1 3 5 7 9 11
+ * 0 2 4 6 8 10
* -------------------
- * XX| | | | | | |XX
+ * 0 XX| | | | | | |XX
* ---------------------
- * XX| | | | | | |XX
+ * 2 XX| | | | | | |XX
* ---------------------
- * XX| | | | | | |XX
+ * 4 XX| | | | | | |XX
* ---------------------
- * XX| | | | | | |XX
+ * 6 XX| | | | | | |XX
* ---------------------
- * XX| | | | | | |XX
+ * 8 XX| | | | | | |XX
* -------------------
*
*
*/
template <typename I>
- struct hexa : public internal::image_domain_morpher_< I, mln_pset(I), hexa<I> >
+ struct hexa : public internal::image_domain_morpher_< I, box2d_h, hexa<I> >
{
/// Skeleton.
typedef hexa< tag::image_<I> > skeleton;
@@ -116,7 +121,7 @@
typedef mln_value(I) value;
/// Lvalue associated type.
- typedef mln_value(I) lvalue;
+ typedef mln_lvalue(I) lvalue;
/// Return type of read-only access.
typedef mln_rvalue(I) rvalue;
@@ -124,6 +129,15 @@
/// Point site type
typedef point2d_h psite;
+ /// FIXME : should it be in box2d_h?
+ /// Forward Point_Iterator associated type.
+ typedef hexa_fwd_piter_<box2d> fwd_piter;
+
+ /// FIXME : should it be in box2d_h?
+ /// Backward Point_Iterator associated type.
+ /// typedef hexa_fwd_piter_<box2d> bkd_piter;
+
+
/// Constructor without argument.
hexa();
@@ -134,7 +148,7 @@
void init_(I& ima);
/// Give the definition domain.
- const mln_pset(I)& domain() const;
+ const box2d_h& domain() const;
/// Test if \p p belongs to the image domain.
bool has(const psite& p) const;
@@ -144,7 +158,7 @@
rvalue operator()(const point2d_h& p) const;
/// Read-write access of pixel value at hexa point site \p p.
- value operator()(const point2d_h& p);
+ lvalue operator()(const point2d_h& p);
};
template <typename I, typename J>
@@ -171,8 +185,9 @@
{
template <typename I>
- data_< hexa<I> >::data_(I& ima)
- : ima_(ima)
+ data_< hexa<I> >::data_(I& ima, box2d_h b)
+ : ima_(ima),
+ b_(b)
{
}
@@ -184,11 +199,13 @@
hexa<I>::init_(I& ima)
{
mln_precondition(! this->has_data());
- this->data_ = new internal::data_< hexa<I> >(ima);
+ box2d b_in = ima.bbox();
+ box2d_h b = make::box2d_h(b_in.pmin()[0], b_in.pmin()[1] * 2 - 1,
+ b_in.pmax()[0], b_in.pmax()[1] * 2 - 1);
+ this->data_ = new internal::data_< hexa<I> >(ima, b);
}
-
template <typename I>
hexa<I>::hexa()
{
@@ -205,27 +222,31 @@
typename hexa<I>::rvalue
hexa<I>::operator()(const point2d_h& p) const
{
+ mln_precondition(this->has_data());
return this->data_->ima_(make::point2d(p[0] / 2, p[1] / 2));
}
template <typename I>
- typename hexa<I>::value
+ typename hexa<I>::lvalue
hexa<I>::operator()(const point2d_h& p)
{
+ mln_precondition(this->has_data());
return this->data_->ima_(make::point2d(p[0] / 2, p[1] / 2));
}
template <typename I>
- const mln_pset(I)&
+ const box2d_h&
hexa<I>::domain() const
{
- return this->data_->ima_.domain();
+ mln_precondition(this->has_data());
+ return this->data_->b_;
}
template <typename I>
bool
hexa<I>::has(const psite& p) const
{
+ mln_precondition(this->has_data());
return this->data_->ima_.has(make::point2d(p[0] / 2, p[1] / 2));
}
Index: trunk/milena/mln/core/hexa_piter.hh
===================================================================
--- trunk/milena/mln/core/hexa_piter.hh (revision 0)
+++ trunk/milena/mln/core/hexa_piter.hh (revision 1286)
@@ -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_CORE_HEXA_PITER_HH
+# define MLN_CORE_HEXA_PITER_HH
+
+/*! \file mln/core/hexa_piter.hh
+ *
+ * \brief Definition of iterators on points of pset_ifes.
+ */
+
+# include <mln/core/internal/piter_adaptor.hh>
+
+# include <mln/core/box2d.hh>
+# include <mln/core/inplace.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::hexa
+ */
+ template <typename S>
+ class hexa_fwd_piter_
+ : public internal::piter_adaptor_< mln_fwd_piter(S),
+ hexa_fwd_piter_<S> >
+ {
+ typedef mln_fwd_piter(S) adaptee_;
+ typedef hexa_fwd_piter_<S> self_;
+ typedef internal::piter_adaptor_<adaptee_, self_> super_;
+
+ public:
+
+ /// Constructor from a subset of points.
+ hexa_fwd_piter_(const box2d& subset);
+ hexa_fwd_piter_(const box2d_h& subset);
+
+ /// Dtor
+ ~hexa_fwd_piter_();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ operator point2d_h() const;
+ private:
+
+ point2d_h p_;
+ };
+
+
+ // FIXME:
+ template <typename S>
+ class hexa_bkd_piter_
+ :
+ public mln::internal::fixme
+ {};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // hexa_fwd_piter_<I>
+
+ template <typename S>
+ hexa_fwd_piter_<S>::hexa_fwd_piter_(const box2d& b)
+ : super_(adaptee_(b))
+ {
+ }
+
+ template <typename S>
+ hexa_fwd_piter_<S>::hexa_fwd_piter_(const box2d_h& b)
+ : super_(adaptee_(*new box2d(make::box2d(b.pmin()[0] / 2, b.pmin()[1] / 2,
+ b.pmax()[0] / 2 + 1, b.pmax()[1] / 2 + 1))))
+ {
+ }
+
+ template <typename S>
+ hexa_fwd_piter_<S>::~hexa_fwd_piter_()
+ {
+ }
+
+ template <typename S>
+ void
+ hexa_fwd_piter_<S>::start()
+ {
+ this->piter_.start();
+ p_[0] = this->piter_[0];
+ p_[1] = this->piter_[1];
+ }
+
+ template <typename S>
+ void
+ hexa_fwd_piter_<S>::next_()
+ {
+ this->piter_.next();
+ p_[0] = this->piter_[0] * 2;
+ p_[1] = this->piter_[1] * 2 + this->piter_[0] % 2;
+ std::cout << "next :" << p_ << std::endl;
+ }
+
+ template <typename S>
+ hexa_fwd_piter_<S>::operator point2d_h() const
+ {
+ return p_;
+ }
+
+ // FIXME: hexa_bkd_piter_<S>
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_HEXA_PITER_HH
Index: trunk/milena/mln/core/box2d_h.hh
===================================================================
--- trunk/milena/mln/core/box2d_h.hh (revision 1285)
+++ trunk/milena/mln/core/box2d_h.hh (revision 1286)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_BOX2D_HH
-# define MLN_CORE_BOX2D_HH
+#ifndef MLN_CORE_BOX2D_H_HH
+# define MLN_CORE_BOX2D_H_HH
/*! \file mln/core/box2d.hh
*
@@ -35,19 +35,18 @@
*/
# include <mln/core/box.hh>
+# include <mln/core/box2d.hh>
# include <mln/core/point2d_h.hh>
namespace mln
{
- /*! \brief Type alias for a box defined on the 2D square grid with
- * integer coordinates.
+ /*! \brief FIXME
*
- * \see mln::win::rectangle2d.
*/
- typedef box_<point2d_h> box2d_h;
+ typedef box_<point2d_h> box2d_h;
} // end of namespace mln
Index: trunk/milena/mln/core/image2d_h.hh
===================================================================
--- trunk/milena/mln/core/image2d_h.hh (revision 0)
+++ trunk/milena/mln/core/image2d_h.hh (revision 1286)
@@ -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_CORE_IMAGE2D_H_HH
+# define MLN_CORE_IMAGE2D_H_HH
+
+/*! \file mln/core/hexa_piter.hh
+ *
+ * \brief Definition of iterators on points of pset_ifes.
+ */
+
+# include <mln/core/image2d.hh>
+# include <mln/core/hexa.hh>
+
+# include <mln/border/thickness.hh>
+
+
+# include <mln/debug/println.hh>
+
+namespace mln
+{
+ template <typename V>
+ struct image2d_h
+ : public hexa< image2d<V> >
+ {
+ //typedef hexa< image2d<V> > super_;
+
+ /// Point site type
+ typedef point2d_h psite;
+
+ /// Constructor with the numbers of rows and columns
+ /// border thickness.
+ image2d_h(int nrows, int ncols, unsigned bdr = border::thickness);
+
+ //using super_::init_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ image2d_h<V>::image2d_h(int nrows, int ncols, unsigned bdr)
+ {
+ std::cout << "Image2d_h Ctor " << nrows << " "
+ << ncols / 2 + 1 << std::endl;
+
+ mln_assertion(ncols % 2 == 1);
+ image2d<V> ima(nrows,
+ ncols / 2 + 1,
+ bdr);
+
+ debug::println(ima);
+
+ this->init_(ima);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE2D_H_HH