Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add vector and interpolated image based on it.
* mln/core/interpolated.hh: Interpolated image.
* mln/make/vec.hh: Build a vector.
* sandbox/nivault/binary_arith.hh: Rename to...
* mln/metal/binary_arith_trait.hh: ...this, Promotion.
* mln/metal/vec.hh: Update.
* sandbox/nivault/tests/test.cc: Rename to ....
* tests/interpolated.cc: ...this.
* tests/metal_vec.cc: New.
---
trunk/milena/mln/core/interpolated.hh | 186 +++++++++++++++++
trunk/milena/mln/make/vec.hh | 133 ++++++++++++
trunk/milena/mln/metal/binary_arith_trait.hh | 73 ++++++
trunk/milena/mln/metal/vec.hh | 293 ++++++++++++++++++++++-----
trunk/milena/tests/interpolated.cc | 70 ++++++
trunk/milena/tests/metal_vec.cc | 43 +++
6 files changed, 752 insertions(+), 46 deletions(-)
Index: trunk/milena/tests/metal_vec.cc
===================================================================
--- trunk/milena/tests/metal_vec.cc (revision 0)
+++ trunk/milena/tests/metal_vec.cc (revision 1130)
@@ -0,0 +1,43 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/level_median.cc
+ *
+ * \brief Test on mln::median::median_dir.
+ */
+
+#include <mln/metal/vec.hh>
+
+int main()
+{
+ using namespace mln;
+
+ metal::vec<3,int> v_int = make::vec(3,6,7);
+ metal::vec<3,float> v_f = make::vec(2.6, 1.9, 5.2);
+
+ std::cout << v_int + v_f << std::endl;
+}
Index: trunk/milena/tests/interpolated.cc
===================================================================
--- trunk/milena/tests/interpolated.cc (revision 0)
+++ trunk/milena/tests/interpolated.cc (revision 1130)
@@ -0,0 +1,70 @@
+// 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/image2d_b.cc
+ *
+ * \brief Tests on mln::image2d_b.
+ */
+
+
+#include <iostream>
+#include <mln/core/image2d_b.hh>
+#include <mln/core/interpolated.hh>\
+
+#include <mln/metal/vec.hh>
+
+#include <mln/level/fill.hh>
+
+#include <mln/debug/println.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ const unsigned nrows = 4;
+ const unsigned ncols = 4;
+ const unsigned border = 4;
+
+ image2d_b<float> f(nrows, ncols, border);
+ float tab[] = {1., 3., 5., 7.,
+ 4., 7., 10., 13.,
+ 7., 11., 15., 19.,
+ 10., 15., 20., 25.};
+ level::fill(f, tab);
+
+ interpolated<image2d_b<float> > inter(f);
+
+ metal::vec<2, float> v1 = make::vec(2.3, 0.6);
+ metal::vec<2, float> v2 = make::vec(3.2, 1.8);
+
+ debug::println(f);
+
+ std::cout << v1 << " : " << inter(v1) << std::endl;
+ std::cout << v2 << " : " << inter(v2) << std::endl;
+}
Index: trunk/milena/mln/core/interpolated.hh
===================================================================
--- trunk/milena/mln/core/interpolated.hh (revision 0)
+++ trunk/milena/mln/core/interpolated.hh (revision 1130)
@@ -0,0 +1,186 @@
+// 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_INTERPOLATED_HH
+# define MLN_CORE_INTERPOLATED_HH
+
+/*! \file mln/core/interpolated.hh
+ *
+ * \brief Definition of an image class FIXME
+ */
+
+# include <cmath>
+
+# include <mln/core/concept/image.hh>
+# include <mln/metal/vec.hh>
+
+
+namespace mln
+{
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename I>
+ struct interpolated : public mln::internal::image_base_< mln_pset(I), interpolated<I> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(I) psite;
+
+ /// Value associated type.
+ typedef mln_value(I) value;
+
+ /// Return type of read-write access.
+ typedef mln_lvalue(I) lvalue;
+
+ /// Return type of read-only access.
+ typedef mln_rvalue(I) rvalue;
+
+ /// Value set associated type.
+ typedef mln::value::set<value> vset;
+
+
+
+ /// Constructor.
+ interpolated(const Image<I>& ima);
+
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const psite& p) const;
+
+ /// Give the definition domain.
+ const mln_pset(I)& domain() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_value(I) operator()(const psite& p) const;
+
+ /// Mutable access is only OK for reading (not writing).
+ mln_value(I) operator()(const psite& p);
+
+ mln_value(I) operator()(const mln::metal::vec<I::point::dim, float>& v) const;
+
+ mln_value(I) operator()(const mln::metal::vec<I::point::dim, float>& v);
+
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Change value type.
+ template <typename U>
+ struct change_value
+ {
+ typedef mln_ch_value(I, U) ret;
+ };
+
+ protected:
+ const I& ima_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ interpolated<I>::interpolated(const Image<I>& ima)
+ : ima_(exact(ima))
+ {
+ mln_precondition(exact(ima).has_data());
+ }
+
+ template <typename I>
+ bool interpolated<I>::has_data() const
+ {
+ mln_invariant(ima_.has_data());
+ return true;
+ }
+
+ template <typename I>
+ bool interpolated<I>::owns_(const psite& p) const
+ {
+ return ima_.owns_(p);
+ }
+
+ template <typename I>
+ const mln_pset(I)&
+ interpolated<I>::domain() const
+ {
+ return ima_.domain();
+ }
+
+ template <typename I>
+ mln_value(I)
+ interpolated<I>::operator()(const psite& p) const
+ {
+ mln_precondition(ima_.owns_(p));
+ return ima_(p);
+ }
+
+ template <typename I>
+ mln_value(I)
+ interpolated<I>::operator()(const psite& p)
+ {
+ return ima_(p);
+ }
+
+ template <typename I>
+ mln_value(I)
+ interpolated<I>::operator()(const mln::metal::vec<I::point::dim, float>& v) const
+ {
+ mln_point(I) p;
+ for (unsigned i = 0; i < I::point::dim; ++i)
+ p[i] = static_cast<int>(round(v[i]));
+ mln_assertion(ima_.owns_(p));
+ return (ima_(p));
+ }
+
+ template <typename I>
+ mln_value(I)
+ interpolated<I>::operator()(const mln::metal::vec<I::point::dim, float>& v)
+ {
+ mln_point(I) p;
+ for (unsigned i = 0; i < I::point::dim; ++i)
+ p[i] = static_cast<int>(round(v[i]));
+ mln_assertion(ima_.owns_(p));
+ return (ima_(p));
+ }
+
+ template <typename I>
+ const mln::value::set<mln_value(I) >&
+ interpolated<I>::values() const
+ {
+ return vset::the();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERPOLATED_HH
Index: trunk/milena/mln/metal/vec.hh
===================================================================
--- trunk/milena/mln/metal/vec.hh (revision 1129)
+++ trunk/milena/mln/metal/vec.hh (revision 1130)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2006 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
@@ -25,12 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_METAL_VEC_HH
-# define MLN_CORE_METAL_VEC_HH
+#ifndef MLN_METAL_VEC_HH
+# define MLN_METAL_VEC_HH
-# include <cstdarg>
+# include <iostream>
-# include <mln/core/concept/object.hh>
+# include <mln/core/contract.hh>
+# include <mln/metal/binary_arith_trait.hh>
+
+// FIXME: Document.
namespace mln
@@ -39,76 +42,137 @@
namespace metal
{
- // FIXME: Doc! + Change coord into comp.
+ namespace internal
+ {
template <unsigned n, typename T>
- struct vec : public Object< vec<n,T> >
+ class vec_base_
{
- enum { dim = n };
- typedef T coord;
+ protected:
+ T data_[n];
+ };
+
+ template <typename T>
+ class vec_base_ <1, T>
+ {
+ public:
+ void set(const T& val0)
+ {
+ data_[0] = val0;
+ }
+ protected:
+ T data_[1];
+ };
- vec();
- vec(T (&values)[n]);
+ template <typename T>
+ class vec_base_ <2, T>
+ {
+ public:
+ void set(const T& val0, const T& val1)
+ {
+ data_[0] = val0;
+ data_[1] = val1;
+ }
+ protected:
+ T data_[2];
+ };
- T& operator[](unsigned i);
- T operator[](unsigned i) const;
+ template <typename T>
+ class vec_base_ <3, T>
+ {
+ public:
+ void set(const T& val0, const T& val1, const T& val2)
+ {
+ data_[0] = val0;
+ data_[1] = val1;
+ data_[2] = val2;
+ }
+ protected:
+ T data_[3];
+ };
+ template <typename T>
+ class vec_base_ <4, T>
+ {
+ public:
+ void set(const T& val0, const T& val1, const T& val2, const T& val3)
+ {
+ data_[0] = val0;
+ data_[1] = val1;
+ data_[2] = val2;
+ data_[3] = val3;
+ }
protected:
- T coord_[n];
+ T data_[4];
};
- template <unsigned n, typename T>
- std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v);
+ } // end of namespace mln::metal::internal
+
template <unsigned n, typename T>
- bool operator==(const vec<n,T>& lhs, const vec<n,T>& rhs);
+ class vec : public internal::vec_base_<n, T>
+ {
+ typedef internal::vec_base_<n,T> super;
+ using super::data_;
+ public:
-# ifndef MLN_INCLUDE_ONLY
+ typedef T value_type;
+ enum { dim = n };
- template <unsigned n, typename T>
- vec<n,T>::vec()
+ vec()
{
}
- template <unsigned n, typename T>
- vec<n,T>::vec(T (&values)[n])
+ template <typename U>
+ vec(const vec<n, U>& rhs)
{
for (unsigned i = 0; i < n; ++i)
- coord_[i] = values[i];
+ data_[i] = rhs[i];
}
- template <unsigned n, typename T>
- T&
- vec<n,T>::operator[](unsigned i)
+ template <typename U>
+ vec& operator=(const vec<n, U>& rhs)
{
- mln_precondition(i < n);
- return coord_[i];
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = rhs[i];
+ return *this;
}
- template <unsigned n, typename T>
- T
- vec<n,T>::operator[](unsigned i) const
+ const T& operator[](unsigned i) const
{
- mln_precondition(i < n);
- return coord_[i];
+ mln_precondition(i < dim);
+ return data_[i];
}
- // operators
+ T& operator[](unsigned i)
+ {
+ mln_precondition(i < dim);
+ return data_[i];
+ }
- template <unsigned n, typename T>
- std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v)
+ void set_all(const T& val)
{
- ostr << "[ ";
for (unsigned i = 0; i < n; ++i)
- ostr << v[i] << ' ';
- return ostr << ']';
+ data_[i] = val;
}
- template <unsigned n, typename T>
- bool operator==(const vec<n,T>& lhs, const vec<n,T>& rhs)
+ unsigned size() const
+ {
+ return n;
+ }
+
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // eq
+
+ template <unsigned n, typename T, typename U>
+ bool operator==(const vec<n,T>& lhs, const vec<n,U>& rhs)
{
for (unsigned i = 0; i < n; ++i)
if (lhs[i] != rhs[i])
@@ -116,15 +180,152 @@
return true;
}
-# endif // ! MLN_INCLUDE_ONLY
+ template <unsigned n, typename T, typename U>
+ bool operator!=(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ return not (lhs == rhs);
+ }
+
+ // +
- } // end of namespace mln::metal
+ template <unsigned n, typename T, typename U>
+ vec<n,T>&
+ operator+=(vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ lhs[i] += rhs[i];
+ return lhs;
+ }
+
+ template <unsigned n, typename T, typename U>
+ vec<n, typename binary_arith_trait<T, U>::ret >
+ operator+(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ vec<n, typename binary_arith_trait<T, U>::ret> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] + rhs[i];
+ return tmp;
+ }
+
+
+ // -
+
+ template <unsigned n, typename T, typename U>
+ vec<n,T>&
+ operator-=(vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ lhs[i] -= rhs[i];
+ return lhs;
+ }
+
+ template <unsigned n, typename T, typename U>
+ vec<n, typename binary_arith_trait<T, U>::ret>
+ operator-(const vec<n,T>& lhs, const vec<n,U>& rhs)
+ {
+ vec<n, typename binary_arith_trait<T, U>::ret> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] - rhs[i];
+ return tmp;
+ }
+
+ template <unsigned n, typename T>
+ vec<n, T>
+ operator-(const vec<n,T>& lhs)
+ {
+ vec<n, T> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = - lhs[i];
+ return tmp;
+ }
+
+
+ // *
+
+ template <unsigned n, typename T, typename S>
+ vec<n,T>&
+ operator*=(vec<n,T>& lhs, const S& scalar)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ lhs[i] *= scalar;
+ return lhs;
+ }
+
+ template <unsigned n, typename T, typename S>
+ vec<n, typename binary_arith_trait<T, S>::ret>
+ operator*(const vec<n,T>& lhs, const S& scalar)
+ {
+ vec<n, typename binary_arith_trait<T, S>::ret> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] * scalar;
+ return tmp;
+ }
-} // end of namespace mln
+ // /
-# include <mln/metal/make/vec.hh>
+ template <unsigned n, typename T, typename S>
+ vec<n,T>&
+ operator/=(vec<n,T>& lhs, const S& scalar)
+ {
+ precondition(scalar != 0);
+ for (unsigned i = 0; i < n; ++i)
+ lhs[i] /= scalar;
+ return lhs;
+ }
+
+ template <unsigned n, typename T, typename S>
+ vec<n, typename binary_arith_trait<T, S>::ret>
+ operator/(const vec<n,T>& lhs, const S& scalar)
+ {
+ precondition(scalar != 0);
+ vec<n, typename binary_arith_trait<T, S>::ret> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp[i] = lhs[i] / scalar;
+ return tmp;
+ }
+
+
+ // <<
+
+ template <unsigned n, typename T>
+ std::ostream&
+ operator<<(std::ostream& ostr, const vec<n,T>& v)
+ {
+ ostr << '(';
+ for (unsigned i = 0; i < n; ++i)
+ ostr << v[i] << (i == n - 1 ? ")" : ", ");
+ return ostr;
+ }
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const vec<n,unsigned char>& v)
+ {
+ ostr << '(';
+ for (unsigned i = 0; i < n; ++i)
+ ostr << (unsigned int)(v[i]) << (i == n - 1 ? ")" : ", ");
+ return ostr;
+ }
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const vec<n,signed char>& v)
+ {
+ ostr << '(';
+ for (unsigned i = 0; i < n; ++i)
+ ostr << (signed int)(v[i]) << (i == n - 1 ? ")" : ", ");
+ return ostr;
+ }
+
+
+# endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+# include <mln/make/vec.hh>
-#endif // ! MLN_CORE_METAL_VEC_HH
+#endif // ! MLN_METAL_VEC_HH
Index: trunk/milena/mln/metal/binary_arith_trait.hh
===================================================================
--- trunk/milena/mln/metal/binary_arith_trait.hh (revision 0)
+++ trunk/milena/mln/metal/binary_arith_trait.hh (revision 1130)
@@ -0,0 +1,73 @@
+// Copyright (C) 2006 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_BINARY_ARITH_TRAIT_HH
+# define MLN_METAL_BINARY_ARITH_TRAIT_HH
+
+
+ template <typename T, typename U>
+ struct binary_arith_trait
+ {
+ typedef T ret;
+ };
+
+
+ template <>
+ struct binary_arith_trait<int, float>
+ {
+ typedef float ret;
+ };
+ template <>
+ struct binary_arith_trait<float, int>
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct binary_arith_trait<int, double>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct binary_arith_trait<double, int>
+ {
+ typedef double ret;
+ };
+
+ template <>
+ struct binary_arith_trait<double, float>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct binary_arith_trait<float, double>
+ {
+ typedef double ret;
+ };
+
+
+#endif // ! MLN_METAL_BINARY_ARITH_TRAIT_HH
Index: trunk/milena/mln/make/vec.hh
===================================================================
--- trunk/milena/mln/make/vec.hh (revision 0)
+++ trunk/milena/mln/make/vec.hh (revision 1130)
@@ -0,0 +1,133 @@
+// Copyright (C) 2006 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_VEC_HH
+# define MLN_METAL_VEC_HH
+
+/*! \file mln/make/vec.hh
+ *
+ * \brief Routine to construct an mln::metal::vec.
+ */
+
+# include <mln/metal/vec.hh>
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an mln::metal::vec<1,T>.
+ *
+ * \param[in] v_0 First coordinate.
+ *
+ * \return A 1D vector.
+ */
+ template <typename T>
+ mln::metal::vec<1, T> vec(const T& v_0);
+
+ /*! \brief Create an mln::metal::vec<2,T>.
+ *
+ * \param[in] v_0 First coordinate.
+ * \param[in] v_1 Second coordinate.
+ *
+ * \return A 2D vector.
+ */
+ template <typename T>
+ mln::metal::vec<2, T> vec(const T& v_0, const T& v_1);
+
+ /*! \brief Create an mln::metal::vec<3,T>.
+ *
+ * \param[in] v_0 First coordinate.
+ * \param[in] v_1 Second coordinate.
+ * \param[in] v_2 Third coordinate.
+ *
+ * \return A 3D vector.
+ */
+ template <typename T>
+ mln::metal::vec<3, T> vec(const T& v_0, const T& v_1, const T& v_2);
+
+ /*! \brief Create an mln::metal::vec<4,T>.
+ *
+ * \param[in] v_0 First coordinate.
+ * \param[in] v_1 Second coordinate.
+ * \param[in] v_2 Third coordinate.
+ * \param[in] v_3 Fourth coordinate.
+ *
+ * \return A 4D vector.
+ */
+ template <typename T>
+ mln::metal::vec<4, T> vec(const T& v_0, const T& v_1, const T& v_2, const T& v_3);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ mln::metal::vec<1, T> vec(const T& v_0)
+ {
+ mln::metal::vec<1, T> tmp;
+ tmp[0] = v_0;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<2, T> vec(const T& v_0, const T& v_1)
+ {
+ mln::metal::vec<2, T> tmp;
+ tmp[0] = v_0;
+ tmp[1] = v_1;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<3, T> vec(const T& v_0, const T& v_1, const T& v_2)
+ {
+ mln::metal::vec<3, T> tmp;
+ tmp[0] = v_0;
+ tmp[1] = v_1;
+ tmp[2] = v_2;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<4, T> vec(const T& v_0, const T& v_1, const T& v_2, const T& v_3)
+ {
+ mln::metal::vec<4, T> tmp;
+ tmp[0] = v_0;
+ tmp[1] = v_1;
+ tmp[2] = v_2;
+ tmp[3] = v_3;
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace make
+
+} // end of namespace mln
+
+#endif // ! MLN_METAL_VEC_HH
Index: trunk/milena/sandbox/nivault/binary_arith.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/nivault/tests/test.cc (deleted)
===================================================================
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-18 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add tests for labeling level.
* labeling_level_fast_10000x1000.cc: Test labeling::level with
fast version.
* labeling_level_generic_10000x1000.cc: Test labeling::level with
generic version.
* labeling_level_fast.cc,
* labeling_level.hh,
* border_fill.hh: Update.
---
border_fill.hh | 18 +++++++---
labeling_level.hh | 33 +++++++++++++++++-
labeling_level_fast.cc | 14 -------
labeling_level_fast_10000x1000.cc | 63 +++++++++++++++++++++++++++++++++++
labeling_level_generic_10000x1000.cc | 63 +++++++++++++++++++++++++++++++++++
5 files changed, 171 insertions(+), 20 deletions(-)
Index: trunk/milena/sandbox/duhamel/border_fill.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_fill.hh (revision 1128)
+++ trunk/milena/sandbox/duhamel/border_fill.hh (revision 1129)
@@ -39,10 +39,11 @@
//# include <mln/core/line_piter.hh>
#include <mln/geom/nrows.hh>
#include <mln/geom/ncols.hh>
-#include <mln/core/image2d_b.hh>
-#include <mln/core/image2d_b.hh>
#include <mln/core/pixel.hh>
#include <mln/core/line_piter.hh>
+# include <mln/core/inplace.hh>
+# include <mln/level/memcpy_.hh>
+# include <mln/core/point2d.hh>
namespace mln
{
@@ -72,7 +73,7 @@
const I& ima = exact(ima_);
mln_precondition(ima.has_data());
// FIX
- typedef mln_point(I) point;
+ typedef mln_point(I) P;
typedef mln_dpoint(I) delta_point;
Fast_Image<I> im (ima);
@@ -80,15 +81,24 @@
std::size_t border = ima.border ();
std::size_t nbrows = geom::max_row(ima) - geom::min_row(ima);
std::size_t nbcols = geom::max_col(ima) - geom::min_col(ima);
+ // std::size_t n = ima.bbox().len(P::dim - 1);
point2d p = ima.bbox ().pmin ();
// FIXME : REMOVE THIS LOOP BY MEMSET
-
std::size_t s = border * (2 * (border + 1) + nbcols);
for (std::size_t i = 0; i < s; ++i)
const_cast<I&>(ima)[i] = v;
+ // typename I::line_piter p(ima.domain());
+
+// for (std::size_t i = 0; i < border; ++i, p = p.next ())
+// {
+// // memset_(inplace(make::pixel(ima, p)),
+// // v,
+// // n);
+// }
+
// ACCESS TO RIGHT UP CORNER
s = nbcols + 1;
for (std::size_t i = 0; i < s; ++i)
Index: trunk/milena/sandbox/duhamel/labeling_level_generic_10000x1000.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level_generic_10000x1000.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/labeling_level_generic_10000x1000.cc (revision 1129)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/labeling_foreground.cc
+ *
+ * \brief Test on mln::labeling::foreground.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/pw/all.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/labeling/level.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println_with_border.hh>
+
+#include "paste.hh"
+#include "fill.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ unsigned border = 1;
+
+ image2d_b<value::int_u8> i1(10000, 1000, border);
+ i1[10009] = i1[10010] = 2;
+
+ unsigned n;
+ image2d_b<value::int_u8> out(i1.domain(), border);
+ labeling::level(i1, 2, c4(), out, n);
+
+ mln_assertion (n == 1);
+}
Index: trunk/milena/sandbox/duhamel/labeling_level.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level.hh (revision 1128)
+++ trunk/milena/sandbox/duhamel/labeling_level.hh (revision 1129)
@@ -38,11 +38,36 @@
# include <mln/debug/println.hh>
# include <mln/core/window2d.hh>
# include <mln/convert/to_window.hh>
+# include <mln/core/concept/dpoint.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/window.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
+# include <mln/metal/is_a.hh>
+
namespace mln
{
+ namespace convert
+ {
+ template <typename N>
+ window<mln_dpoint(N)> to_upper_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)
+ // FIXME: pour Guillaume
+ if (n < P::zero)
+ win.insert(n - P::zero);
+ return win;
+ }
+
+ } // end of namespace convert
template <typename F>
struct labeling_fast_try2
@@ -65,6 +90,8 @@
void run()
{
+// std::cout << "fast"
+// << std::endl;
// init
{
f.nlabels = 0;
@@ -72,8 +99,10 @@
}
// first pass
{
+ typedef mln_point (I) P;
mln_bkd_pixter(const I) p(f.input);
mln_nixter(const I, N) n(p, f.nbh);
+ // mln_qixter(const I, window<P>) n(p, convert::to_upper_window(f.nbh));
for_all(p) if (f.handles(p))
{
@@ -153,8 +182,8 @@
// const S& s;
void init() { mln::level::fill(this->output, 0); }
- bool handles(unsigned p) const { return input[p] == val; }
- bool equiv(unsigned n, unsigned) const { return input[n] == val; }
+ bool handles(unsigned p) const { return mln::labeling::impl::base_fast_<I_,N_,O_>::input[p] == val; }
+ bool equiv(unsigned n, unsigned) const { return mln::labeling::impl::base_fast_<I_,N_,O_>::input[n] == val; }
const mln_value(I_)& val;
Index: trunk/milena/sandbox/duhamel/labeling_level_fast.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1128)
+++ trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1129)
@@ -63,18 +63,4 @@
std::cout << "n = " << n << std::endl;
debug::println(out);
-
-// image2d_b<int_u8>
-// lena = io::pgm::load("../../img/tiny.pgm"),
-// out(lena.domain());
-
-// debug::println_with_border(out);
-
-// labeling::foreground((pw::value(lena) > pw::cst(127)) | lena.domain(),
-// c4(), out, n);
-
- // debug::println_with_border(out);
-
-// io::pgm::save(out, "out.pgm");
-// mln_assertion(n == 14);
}
Index: trunk/milena/sandbox/duhamel/labeling_level_fast_10000x1000.cc
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level_fast_10000x1000.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/labeling_level_fast_10000x1000.cc (revision 1129)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/labeling_foreground.cc
+ *
+ * \brief Test on mln::labeling::foreground.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/pw/all.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include "labeling_level.hh"
+#include <mln/debug/iota.hh>
+#include <mln/debug/println_with_border.hh>
+
+#include "paste.hh"
+#include "fill.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ unsigned border = 1;
+
+ image2d_b<value::int_u8> i1(10000, 1000, border);
+ i1[10009] = i1[10010] = 2;
+
+ unsigned n;
+ image2d_b<value::int_u8> out(i1.domain(), border);
+ labeling_level_fast(i1, 2, c4(), out, n);
+
+ mln_assertion (n == 1);
+}
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fixes.
* mln/core/internal/piter_adaptor.hh,
* mln/core/line_piter.hh,
* mln/core/vec_p_piter.hh: Import dim for g++-4.1.
* mln/level/paste.hh (paste_): Rename as...
(paste_pw_, paste_fast_): ...these.
(paste_): New with dynamic disjunction.
core/internal/piter_adaptor.hh | 4 ++++
core/line_piter.hh | 2 ++
core/vec_p_piter.hh | 12 ++++++++++++
level/paste.hh | 21 +++++++++++++++++++--
4 files changed, 37 insertions(+), 2 deletions(-)
Index: mln/core/internal/piter_adaptor.hh
--- mln/core/internal/piter_adaptor.hh (revision 1127)
+++ mln/core/internal/piter_adaptor.hh (working copy)
@@ -51,8 +51,12 @@
template <typename Pi, typename E>
class piter_adaptor_ : public internal::point_iterator_base_< mln_psite(Pi), E >
{
+ typedef internal::point_iterator_base_< mln_psite(Pi), E > super_;
public:
+ // Make dim definition from super class available.
+ enum { dim = super_::dim };
+
/// Constructor from a point iterator \p piter.
piter_adaptor_(const Pi& piter);
Index: mln/core/line_piter.hh
--- mln/core/line_piter.hh (revision 1127)
+++ mln/core/line_piter.hh (working copy)
@@ -31,6 +31,8 @@
/*! \file mln/core/line_piter.hh
*
* \brief Definition of iterators on points by lines.
+ *
+ * \todo Rename as box_line_piter.
*/
# include <mln/core/internal/point_iterator_base.hh>
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1127)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -45,6 +45,12 @@
template <typename P>
struct vec_p_fwd_piter_ : public internal::point_iterator_base_< P, vec_p_fwd_piter_<P> >
{
+ typedef vec_p_fwd_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+ public:
+
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
/// Coordinate associated type.
template <typename S>
@@ -85,6 +91,12 @@
template <typename P>
struct vec_p_bkd_piter_ : public internal::point_iterator_base_< P, vec_p_bkd_piter_<P> >
{
+ typedef vec_p_bkd_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+ public:
+
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
/// Coordinate associated type.
template <typename S>
Index: mln/level/paste.hh
--- mln/level/paste.hh (revision 1127)
+++ mln/level/paste.hh (working copy)
@@ -70,7 +70,7 @@
{
template <typename I, typename J>
- void paste_(const Image<I>& data_, Image<J>& destination_)
+ void paste_pw_(const Image<I>& data_, Image<J>& destination_)
{
const I& data = exact(data_);
J& destination = exact(destination_);
@@ -81,7 +81,7 @@
}
template <typename I, typename J>
- void paste_(const Fast_Image<I>& data_, Fast_Image<J>& destination_)
+ void paste_fast_(const Fast_Image<I>& data_, Fast_Image<J>& destination_)
{
const I& data = exact(data_);
J& destination = exact(destination_);
@@ -96,6 +96,23 @@
n);
}
+ // Disjunction.
+
+ template <typename I, typename J>
+ void paste_(const Image<I>& data, Image<J>& destination)
+ {
+ paste_pw_(data, destination);
+ }
+
+ template <typename I, typename J>
+ void paste_(const Fast_Image<I>& data, Fast_Image<J>& destination)
+ {
+ if (sizeof(mln_value(I)) = sizeof(mln_value(J)))
+ paste_fast_(data, destination);
+ else
+ paste_pw_(data, destination);
+ }
+
} // end of namespace mln::level::impl
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add fast pixel iterators on neighbors.
* mln/core/internal/pixel_iterator_base.hh (boi_): Make it
before-the-beginning (reverse of past-the-end).
(start, is_valid): Update.
* mln/core/line_piter.hh: Import super_::dim.
* mln/core/box_piter.hh: Likewise.
* mln/core/neighb.hh: Change inheritance to dpoints_base_.
* mln/core/image2d_b.hh (bkd_pixter): Fix missing.
(fwd_nixter, bkd_nixter): Likewise.
* mln/core/pixter2d_b.hh (bkd_pixter2d_b): New.
* mln/labeling/base.hh (base_fast_): New.
* sandbox/duhamel/labeling_level.hh,
* sandbox/duhamel/labeling_level_fast.cc,
* sandbox/duhamel/canvas_labeling.hh: Update.
mln/core/box_piter.hh | 10 +
mln/core/image2d_b.hh | 28 ++++
mln/core/internal/pixel_iterator_base.hh | 8 -
mln/core/line_piter.hh | 5
mln/core/neighb.hh | 4
mln/core/pixter2d_b.hh | 69 +++++++++++
mln/labeling/base.hh | 35 +++++
sandbox/duhamel/canvas_labeling.hh | 23 ++-
sandbox/duhamel/labeling_level.hh | 184 ++++++++++++++++++-------------
sandbox/duhamel/labeling_level_fast.cc | 20 +--
10 files changed, 286 insertions(+), 100 deletions(-)
Index: mln/core/internal/pixel_iterator_base.hh
--- mln/core/internal/pixel_iterator_base.hh (revision 1126)
+++ mln/core/internal/pixel_iterator_base.hh (working copy)
@@ -86,16 +86,17 @@
{
mln_precondition(image.has_data());
I& ima = this->image_;
- boi_ = & ima( ima.domain().pmin() );
+ boi_ = & ima( ima.domain().pmin() ) - 1;
eoi_ = & ima( ima.domain().pmax() ) + 1;
invalidate();
}
+ // FIXME: Remove cause dangerous when bkd!!!
template <typename I, typename E>
void
pixel_iterator_base_<I, E>::start()
{
- this->value_ptr_ = boi_;
+ this->value_ptr_ = boi_ + 1;
}
template <typename I, typename E>
@@ -105,11 +106,12 @@
this->value_ptr_ = eoi_;
}
+ // FIXME: Remove casue not optimal!!!
template <typename I, typename E>
bool
pixel_iterator_base_<I, E>::is_valid() const
{
- return this->value_ptr_ != eoi_;
+ return this->value_ptr_ != eoi_ && this->value_ptr_ != boi_;
}
#endif // ! MLN_INCLUDE_ONLY
Index: mln/core/line_piter.hh
--- mln/core/line_piter.hh (revision 1126)
+++ mln/core/line_piter.hh (working copy)
@@ -46,8 +46,13 @@
template <typename P>
class line_piter_ : public internal::point_iterator_base_< P, line_piter_<P> >
{
+ typedef line_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
public:
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+
/*! \brief Constructor.
*
* \param[in] b A box.
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 1126)
+++ mln/core/neighb.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/internal/set_of.hh>
+# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint.hh>
@@ -53,7 +53,7 @@
*/
template <typename D>
struct neighb_ : public Neighborhood< neighb_<D> >,
- public internal::set_of_<D>
+ public internal::dpoints_base_<D, neighb_<D> >
{
/// Dpoint associated type.
typedef D dpoint;
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1126)
+++ mln/core/image2d_b.hh (working copy)
@@ -508,7 +508,13 @@
template <typename T>
struct bkd_pixter< image2d_b<T> >
{
- typedef internal::fixme ret;
+ typedef bkd_pixter2d_b< image2d_b<T> > ret;
+ };
+
+ template <typename T>
+ struct bkd_pixter< const image2d_b<T> >
+ {
+ typedef bkd_pixter2d_b< const image2d_b<T> > ret;
};
// qixter
@@ -531,6 +537,26 @@
typedef internal::fixme ret;
};
+ // nixter
+
+ template <typename T, typename N>
+ struct fwd_nixter< image2d_b<T>, N >
+ {
+ typedef dpoints_fwd_pixter< image2d_b<T> > ret;
+ };
+
+ template <typename T, typename N>
+ struct fwd_nixter< const image2d_b<T>, N >
+ {
+ typedef dpoints_fwd_pixter< const image2d_b<T> > ret;
+ };
+
+ template <typename T, typename N>
+ struct bkd_nixter< image2d_b<T>, N >
+ {
+ typedef internal::fixme ret;
+ };
+
} // end of namespace mln::trait
} // end of namespace mln
Index: mln/core/box_piter.hh
--- mln/core/box_piter.hh (revision 1126)
+++ mln/core/box_piter.hh (working copy)
@@ -49,8 +49,13 @@
template <typename P>
class box_fwd_piter_ : public internal::point_iterator_base_< P, box_fwd_piter_<P> >
{
+ typedef box_fwd_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
public:
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+
/*! \brief Constructor.
*
* \param[in] b A box.
@@ -94,8 +99,13 @@
template <typename P>
class box_bkd_piter_ : public internal::point_iterator_base_< P, box_bkd_piter_<P> >
{
+ typedef box_bkd_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
public:
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+
/*! \brief Constructor.
*
* \param[in] b A box.
Index: mln/core/pixter2d_b.hh
--- mln/core/pixter2d_b.hh (revision 1126)
+++ mln/core/pixter2d_b.hh (working copy)
@@ -74,11 +74,47 @@
};
- // FIXME: bkd_pixter2d_b
+
+ template <typename I>
+ class bkd_pixter2d_b : public internal::pixel_iterator_base_< I, bkd_pixter2d_b<I> >
+ {
+ typedef internal::pixel_iterator_base_< I, bkd_pixter2d_b<I> > super_;
+
+ public:
+
+ /// Image type.
+ typedef I image;
+
+ /*! \brief Constructor.
+ *
+ * \param[in] image Image to iterate over its pixels.
+ */
+ bkd_pixter2d_b(I& image);
+
+ /// Go to the next pixel.
+ void next_();
+
+ void start();
+
+ private:
+
+ /// Twice the size of the image border.
+ unsigned border_x2_;
+
+ /// Row offset.
+ unsigned row_offset_;
+
+ /// Beginning of the current row.
+ mln_qlf_value(I)* bor_;
+ };
+
+
#ifndef MLN_INCLUDE_ONLY
+ // Fwd.
+
template <typename I>
fwd_pixter2d_b<I>::fwd_pixter2d_b(I& image) :
super_(image)
@@ -101,6 +137,37 @@
}
}
+ // Bkd.
+
+ template <typename I>
+ bkd_pixter2d_b<I>::bkd_pixter2d_b(I& image) :
+ super_(image)
+ {
+ mln_precondition(image.has_data());
+ border_x2_ = 2 * image.border();
+ row_offset_ = geom::max_col(image) - geom::min_col(image) + 1 + border_x2_;
+ bor_ = & image.at(geom::max_row(image), geom::min_col(image)) - 1;
+ }
+
+ template <typename I>
+ void
+ bkd_pixter2d_b<I>::next_()
+ {
+ --this->value_ptr_;
+ if (this->value_ptr_ = bor_ && this->value_ptr_ != this->boi_)
+ {
+ this->value_ptr_ -= border_x2_;
+ bor_ -= row_offset_;
+ }
+ }
+
+ template <typename I>
+ void
+ bkd_pixter2d_b<I>::start()
+ {
+ this->value_ptr_ = this->eoi_ - 1;
+ }
+
#endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/labeling/base.hh
--- mln/labeling/base.hh (revision 1126)
+++ mln/labeling/base.hh (working copy)
@@ -50,6 +50,7 @@
{
/// Base class for labeling functors.
+
template <typename I_, typename N_, typename O_>
struct base_
{
@@ -82,6 +83,40 @@
void merge_attr(const P&, const P&) {}
};
+
+ /// Base class for labeling functors on fast images.
+
+ template <typename I_, typename N_, typename O_>
+ struct base_fast_
+ {
+ typedef I_ I;
+ typedef N_ N;
+ typedef O_ O;
+
+ const I& input;
+ const N& nbh;
+ O& output;
+
+ mln_value(O_) nlabels;
+ bool status;
+
+ base_fast_(const I_& input, const N_& nbh, O_& output)
+ : input(input),
+ nbh(nbh),
+ output(output)
+ {
+ }
+
+ // Defaults.
+
+ bool handles(unsigned) const { return true; }
+ bool labels(unsigned) const { return true; }
+ void init() {}
+ void do_no_union(unsigned, unsigned) {}
+ void init_attr(unsigned) {}
+ void merge_attr(unsigned, unsigned) {}
+ };
+
} // end of namespace mln::labeling::impl
# endif // ! MLN_INCLUDE_ONLY
Index: sandbox/duhamel/labeling_level.hh
--- sandbox/duhamel/labeling_level.hh (revision 1126)
+++ sandbox/duhamel/labeling_level.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_LABELING_LEVEL_HH
-# define MLN_LABELING_LEVEL_HH
+#ifndef SANDBOX_MLN_LABELING_LEVEL_HH
+# define SANDBOX_MLN_LABELING_LEVEL_HH
/*! \file mln/labeling/level.hh
*
@@ -35,113 +35,149 @@
*/
# include <mln/labeling/base.hh>
-# include <mln/level/fill.hh>
+# include <mln/debug/println.hh>
+# include <mln/core/window2d.hh>
+# include <mln/convert/to_window.hh>
namespace mln
{
- namespace labeling
+
+ template <typename F>
+ struct labeling_fast_try2
{
+ F& f;
- /*! Connected component labeling of the image objects at a given
- * level.
- *
- * \param[in] input The input image.
- * \param[in] val The level to consider for the labeling.
- * \param[in] nbh The neighborhood.
- * \param[out] output The label image.
- * \param[out] nlabels The number of labels.
- *
- * \return Succeed or not.
- */
- template <typename I, typename N, typename O>
- bool level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels);
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::O O;
+
+ // aux:
+ mln_ch_value(O, unsigned) parent;
+
+ labeling_fast_try2(F& f)
+ : f(f),
+ parent(f.output.domain(), f.input.border())
+ {
+ run();
+ }
+
+ void run()
+ {
+ // init
+ {
+ f.nlabels = 0;
+ f.init();
+ }
+ // first pass
+ {
+ mln_bkd_pixter(const I) p(f.input);
+ mln_nixter(const I, N) n(p, f.nbh);
+ for_all(p) if (f.handles(p))
+ {
+ make_set(p);
+ for_all(n) if (n > p)
+ if (f.equiv(n, p))
+ do_union(n, p);
+ else
+ f.do_no_union(n, p);
+ }
+ }
+ // second pass
+ {
+ mln_fwd_pixter(const I) p(f.input);
+ for_all(p) if (f.handles(p))
+ {
+ if (is_root(p))
+ {
+ if (f.labels(p))
+ {
+ if (f.nlabels = mln_max(mln_value(O)))
+ {
+ f.status = false;
+ return;
+ }
+ f.output[p] = ++f.nlabels;
+ }
+ }
+ else
+ f.output[p] = f.output[parent[p]];
+ }
+ f.status = true;
+ }
-# ifndef MLN_INCLUDE_ONLY
+ } // end of run()
- namespace impl
+ void make_set(unsigned p)
{
+ parent[p] = p;
+ f.init_attr(p);
+ }
+
+ bool is_root(unsigned p) const
+ {
+ return parent[p] = p;
+ }
+
+ unsigned find_root(unsigned x)
+ {
+ if (parent[x] = x)
+ return x;
+ else
+ return parent[x] = find_root(parent[x]);
+ }
+
+ void do_union(unsigned n, unsigned p)
+ {
+ unsigned r = find_root(n);
+ if (r != p)
+ {
+ parent[r] = p;
+ f.merge_attr(r, p);
+ }
+ }
+
+ };
+
- // Functors.
template <typename I_, typename N_, typename O_>
- struct level_t : base_<I_,N_,O_>
+ struct level_fast_t : mln::labeling::impl::base_fast_<I_,N_,O_>
{
typedef mln_point(I_) P;
- // requirements from mln::canvas::labeling:
-
- typedef mln_pset(I_) S;
- const S& s;
+ // typedef mln_pset(I_) S;
+ // const S& s;
void init() { mln::level::fill(this->output, 0); }
- bool handles(const P& p) const { return input(p) = val; }
- bool equiv(const P& n, const P&) const { return input(n) = val; }
-
- // end of requirements
+ bool handles(unsigned p) const { return input[p] = val; }
+ bool equiv(unsigned n, unsigned) const { return input[n] = val; }
const mln_value(I_)& val;
- level_t(const I_& input, const mln_value(I_)& val, const N_& nbh, O_& output)
- : base_<I_,N_,O_>(input, nbh, output),
- s(input.domain()),
+ level_fast_t(const I_& input, const mln_value(I_)& val, const N_& nbh, O_& output)
+ : mln::labeling::impl::base_fast_<I_,N_,O_>(input, nbh, output),
+ // s(input.domain()),
val(val)
{}
};
- // Routines.
template <typename I, typename N, typename O>
- bool level_(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels)
+ bool labeling_level_fast(const Fast_Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ Fast_Image<O>& output, unsigned& nlabels)
{
- typedef impl::level_t<I,N,O> F;
+ typedef level_fast_t<I,N,O> F;
F f(exact(input), val, exact(nbh), exact(output));
- canvas::labeling<F> run(f);
+ labeling_fast_try2<F> run(f);
nlabels = f.nlabels;
return f.status;
}
- // FIXME: Add fast versions.
-
- // FIXME (ADD)
- //
- template <typename I, typename N, typename O>
- bool level_(const Fast_Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels)
- {
- typedef impl::level_t<I,N,O> F;
- F f(exact(input), val, exact(nbh), exact(output));
- canvas::labeling_fast<F> run(f);
- nlabels = f.nlabels;
- return f.status;
- }
-
- //
- //END FIXME (ADD)
-
- } // end of namespace mln::labeling::impl
-
-
- // Facade.
-
- template <typename I, typename N, typename O>
- bool level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- Image<O>& output, unsigned& nlabels)
- {
- mln_precondition(exact(output).domain() = exact(input).domain());
- return impl::level_(exact(input), val, nbh, output, nlabels);
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::labeling
-
} // end of namespace mln
-#endif // ! MLN_LABELING_LEVEL_HH
+#endif // ! SANDBOX_MLN_LABELING_LEVEL_HH
Index: sandbox/duhamel/labeling_level_fast.cc
--- sandbox/duhamel/labeling_level_fast.cc (revision 1126)
+++ sandbox/duhamel/labeling_level_fast.cc (working copy)
@@ -37,7 +37,8 @@
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
-#include <mln/labeling/foreground.hh>
+#include "labeling_level.hh"
+#include <mln/debug/iota.hh>
#include <mln/debug/println_with_border.hh>
#include "paste.hh"
@@ -49,18 +50,19 @@
using namespace mln;
using value::int_u8;
- image2d_b<value::int_u8> i1(3, 3);
- image2d_b<value::int_u8> out (i1.domain ());
+ unsigned border = 1;
- level::fill_opt2(i1, 8);
-
- for (int i = 0; i < 81; ++i)
- i1[i] = (i * 4452) % 255;
+ image2d_b<value::int_u8> i1(3, 3, border);
+ debug::iota(i1);
+ i1[12] = i1[18] = 2;
debug::println_with_border(i1);
unsigned n;
- labeling::level(i1, true, c4(), out, n);
- printf ("\nn=%u\n", n);
+ image2d_b<value::int_u8> out(i1.domain(), border);
+ labeling_level_fast(i1, 2, c4(), out, n);
+
+ std::cout << "n = " << n << std::endl;
+ debug::println(out);
// image2d_b<int_u8>
// lena = io::pgm::load("../../img/tiny.pgm"),
Index: sandbox/duhamel/canvas_labeling.hh
--- sandbox/duhamel/canvas_labeling.hh (revision 1126)
+++ sandbox/duhamel/canvas_labeling.hh (working copy)
@@ -78,17 +78,20 @@
{
mln_fwd_pixter(const I) p(f.input); // p is a pixel
- W win = convert::to_window(f.nbh);
- mln_qixter(const I, W) q(f.input, win, p);
+// W win = convert::to_window(f.nbh);
+// mln_qixter(const I, W) q(f.input, win, p);
+
+// mln_nixter(const I, N) n(f.input, f.nbh, p);
- for_all(p) // if (f.handles(p))
+ for_all(p) if (f.handles(p))
{
make_set(p);
- for_all(q)
- if (f.equiv(n, p))
- do_union(n, p);
- else
- f.do_no_union(n, p);
+// for_all(n)
+// if (f.deja_vu(n))
+// if (f.equiv(n, p))
+// do_union(n, p);
+// else
+// f.do_no_union(n, p);
}
}
@@ -128,7 +131,7 @@
return parent[p] = p;
}
- point find_root(const unsigned& x)
+ unsigned find_root(const unsigned& x)
{
if (parent[x] = x)
return x;
@@ -138,7 +141,7 @@
void do_union(const unsigned& n, const unsigned& p)
{
- point r = find_root(n);
+ unsigned r = find_root(n);
if (r != p)
{
parent[r] = p;
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make pixels convertible to offsets.
* mln/core/concept/generalized_pixel.hh
(operator unsigned): New.
* tests/pixel.cc: Update.
* sandbox/duhamel/canvas_labeling.hh
(labeling_fast_try2): New.
mln/core/concept/generalized_pixel.hh | 7 +
sandbox/duhamel/canvas_labeling.hh | 126 ++++++++++++++++++++++++++++++++++
tests/pixel.cc | 4 +
3 files changed, 137 insertions(+)
Index: tests/pixel.cc
--- tests/pixel.cc (revision 1125)
+++ tests/pixel.cc (working copy)
@@ -40,6 +40,8 @@
using namespace mln;
typedef image2d_b<int> I;
+
+ border::thickness = 0;
I ima(3, 3);
{
@@ -51,8 +53,10 @@
{
pixel<const I> pxl(ima, make::point2d(1, 1));
ima.at(1, 1) = 51;
+ mln_assertion(unsigned(pxl) = 4);
mln_assertion(pxl.val() = 51);
+
// hopefully the code below does not compile:
// pxl.val() = 0;
// assignment of read-only location
Index: mln/core/concept/generalized_pixel.hh
--- mln/core/concept/generalized_pixel.hh (revision 1125)
+++ mln/core/concept/generalized_pixel.hh (working copy)
@@ -64,6 +64,13 @@
image& ima() const;
mln_qlf_value(image)** address_() const;
*/
+
+ operator unsigned() const // FIXME: Change to std::size_t
+ {
+ const E& it_ = internal::force_exact<E>(*this);
+ return & it_.val() - & it_.ima()[0];
+ }
+
protected:
Generalized_Pixel();
};
Index: sandbox/duhamel/canvas_labeling.hh
--- sandbox/duhamel/canvas_labeling.hh (revision 1125)
+++ sandbox/duhamel/canvas_labeling.hh (working copy)
@@ -45,6 +45,117 @@
namespace canvas
{
+ // Fast version (version 2).
+
+ template <typename F>
+ struct labeling_fast_try2
+ {
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::O O;
+ typedef typename F::S S;
+
+ // aux:
+ mln_ch_value(O, unsigned) parent;
+
+ labeling(F& f)
+ : f(f),
+ parent(f.output.domain())
+ {
+ run();
+ }
+
+ void run()
+ {
+ // init
+ {
+ f.nlabels = 0;
+ f.init();
+ }
+ // first pass
+ {
+ mln_fwd_pixter(const I) p(f.input); // p is a pixel
+
+ W win = convert::to_window(f.nbh);
+ mln_qixter(const I, W) q(f.input, win, p);
+
+ for_all(p) // if (f.handles(p))
+ {
+ make_set(p);
+ for_all(q)
+ if (f.equiv(n, p))
+ do_union(n, p);
+ else
+ f.do_no_union(n, p);
+ }
+ }
+
+// // second pass
+// {
+// mln_bkd_piter(S) p(f.s);
+// for_all(p) if (f.handles(p))
+// {
+// if (is_root(p))
+// {
+// if (f.labels(p))
+// {
+// if (f.nlabels = mln_max(mln_value(O)))
+// {
+// f.status = false;
+// return;
+// }
+// f.output(p) = ++f.nlabels;
+// }
+// }
+// else
+// f.output(p) = f.output(parent[p]);
+// }
+// f.status = true;
+// }
+
+ } // end of run()
+
+ void make_set(const unsigned& p)
+ {
+ parent[p] = p;
+ f.init_attr(p);
+ }
+
+ bool is_root(const unsigned& p) const
+ {
+ return parent[p] = p;
+ }
+
+ point find_root(const unsigned& x)
+ {
+ if (parent[x] = x)
+ return x;
+ else
+ return parent[x] = find_root(parent[x]);
+ }
+
+ void do_union(const unsigned& n, const unsigned& p)
+ {
+ point r = find_root(n);
+ if (r != p)
+ {
+ parent[r] = p;
+ f.merge_attr(r, p);
+ }
+ }
+
+ };
+
+
+
+
+
+
+
+
+
// General version.
template <typename F>
@@ -152,6 +263,21 @@
};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
// FIXME: Fast version.
// FIXME (ADD)
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-18 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add labeling and update border.
* canvas_labeling.hh: Copy from mln/canvas/labeling.hh.
* labeling_level.hh: Specialize with fast image.
* border_duplicate.cc,
* border_duplicate.hh,
* border_fill.cc,
* border_fill.hh: Update.
---
border_duplicate.cc | 22 ++--
border_duplicate.hh | 1
border_fill.cc | 2
border_fill.hh | 8 +
canvas_labeling.hh | 275 ++++++++++++++++++++++++++++++++++++++++++++++++++++
labeling_level.hh | 147 +++++++++++++++++++++++++++
6 files changed, 441 insertions(+), 14 deletions(-)
Index: trunk/milena/sandbox/duhamel/border_fill.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_fill.hh (revision 1124)
+++ trunk/milena/sandbox/duhamel/border_fill.hh (revision 1125)
@@ -42,6 +42,7 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/image2d_b.hh>
#include <mln/core/pixel.hh>
+#include <mln/core/line_piter.hh>
namespace mln
{
@@ -83,11 +84,14 @@
point2d p = ima.bbox ().pmin ();
// FIXME : REMOVE THIS LOOP BY MEMSET
- for (std::size_t i = 0; i < border * (2 * (border + 1) + nbcols); ++i)
+
+ std::size_t s = border * (2 * (border + 1) + nbcols);
+ for (std::size_t i = 0; i < s; ++i)
const_cast<I&>(ima)[i] = v;
// ACCESS TO RIGHT UP CORNER
- for (std::size_t i = 0; i < nbcols + 1; ++i)
+ s = nbcols + 1;
+ for (std::size_t i = 0; i < s; ++i)
p = p + right;
// FILL BORDER
Index: trunk/milena/sandbox/duhamel/border_duplicate.cc
===================================================================
--- trunk/milena/sandbox/duhamel/border_duplicate.cc (revision 1124)
+++ trunk/milena/sandbox/duhamel/border_duplicate.cc (revision 1125)
@@ -41,21 +41,21 @@
int
main (void)
{
- image2d_b<value::int_u8> i1(5, 7);
+ image2d_b<value::int_u8> i1(10000, 1000);
// Fill with randomized value.
- for (unsigned int i = 0; i < i1.ncells (); ++i)
- i1[i] = i;//(i * 4452) % 10;
- std::cout << "before duplicate"
- << std::endl
- << std::endl;
- debug::println_with_border(i1);
+// for (unsigned int i = 0; i < i1.ncells (); ++i)
+// i1[i] = i;//(i * 4452) % 10;
+// std::cout << "before duplicate"
+// << std::endl
+// << std::endl;
+// debug::println_with_border(i1);
border::duplicate (i1);
- std::cout << "after duplicate"
- << std::endl
- << std::endl;
- debug::println_with_border(i1);
+// std::cout << "after duplicate"
+// << std::endl
+// << std::endl;
+// debug::println_with_border(i1);
}
Index: trunk/milena/sandbox/duhamel/labeling_level.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/labeling_level.hh (revision 1125)
@@ -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_LABELING_LEVEL_HH
+# define MLN_LABELING_LEVEL_HH
+
+/*! \file mln/labeling/level.hh
+ *
+ * \brief Connected component labeling of the image objects at a given
+ * level.
+ */
+
+# include <mln/labeling/base.hh>
+# include <mln/level/fill.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Connected component labeling of the image objects at a given
+ * level.
+ *
+ * \param[in] input The input image.
+ * \param[in] val The level to consider for the labeling.
+ * \param[in] nbh The neighborhood.
+ * \param[out] output The label image.
+ * \param[out] nlabels The number of labels.
+ *
+ * \return Succeed or not.
+ */
+ template <typename I, typename N, typename O>
+ bool level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Functors.
+
+ template <typename I_, typename N_, typename O_>
+ struct level_t : base_<I_,N_,O_>
+ {
+ typedef mln_point(I_) P;
+
+ // requirements from mln::canvas::labeling:
+
+ typedef mln_pset(I_) S;
+ const S& s;
+
+ void init() { mln::level::fill(this->output, 0); }
+ bool handles(const P& p) const { return input(p) == val; }
+ bool equiv(const P& n, const P&) const { return input(n) == val; }
+
+ // end of requirements
+
+ const mln_value(I_)& val;
+
+ level_t(const I_& input, const mln_value(I_)& val, const N_& nbh, O_& output)
+ : base_<I_,N_,O_>(input, nbh, output),
+ s(input.domain()),
+ val(val)
+ {}
+ };
+
+ // Routines.
+
+ template <typename I, typename N, typename O>
+ bool level_(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels)
+ {
+ typedef impl::level_t<I,N,O> F;
+ F f(exact(input), val, exact(nbh), exact(output));
+ canvas::labeling<F> run(f);
+ nlabels = f.nlabels;
+ return f.status;
+ }
+
+ // FIXME: Add fast versions.
+
+ // FIXME (ADD)
+ //
+ template <typename I, typename N, typename O>
+ bool level_(const Fast_Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels)
+ {
+ typedef impl::level_t<I,N,O> F;
+ F f(exact(input), val, exact(nbh), exact(output));
+ canvas::labeling_fast<F> run(f);
+ nlabels = f.nlabels;
+ return f.status;
+ }
+
+ //
+ //END FIXME (ADD)
+
+ } // end of namespace mln::labeling::impl
+
+
+ // Facade.
+
+ template <typename I, typename N, typename O>
+ bool level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels)
+ {
+ mln_precondition(exact(output).domain() == exact(input).domain());
+ return impl::level_(exact(input), val, nbh, output, nlabels);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_LEVEL_HH
Index: trunk/milena/sandbox/duhamel/border_duplicate.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_duplicate.hh (revision 1124)
+++ trunk/milena/sandbox/duhamel/border_duplicate.hh (revision 1125)
@@ -79,6 +79,7 @@
std::size_t real_nbcols = (nbcols + 1) + 2 * border;
std::size_t start = real_nbcols * border + border;
std::size_t s = start;
+
// duplicate top left corner
for (std::size_t i = 0; i < border + 1; ++i)
for (std::size_t j = 0; j < border + 1; ++j)
Index: trunk/milena/sandbox/duhamel/canvas_labeling.hh
===================================================================
--- trunk/milena/sandbox/duhamel/canvas_labeling.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/canvas_labeling.hh (revision 1125)
@@ -0,0 +1,275 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CANVAS_LABELING_HH
+# define MLN_CANVAS_LABELING_HH
+
+/*! \file mln/canvas/labeling.hh
+ *
+ * \brief Connected component labeling of the object part in a binary
+ * image.
+ */
+
+# include <mln/level/fill.hh>
+# include <mln/level/sort_points.hh>
+
+# include <mln/convert/to_window.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ // General version.
+
+ template <typename F>
+ struct labeling
+ {
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::O O;
+ typedef typename F::S S;
+ typedef mln_point(I) point;
+
+ // aux:
+ mln_ch_value(O, bool) deja_vu;
+ mln_ch_value(O, point) parent;
+
+ labeling(F& f)
+ : f(f),
+ deja_vu(f.output.domain()),
+ parent(f.output.domain())
+ {
+ run();
+ }
+
+ void run()
+ {
+ // init
+ {
+ f.nlabels = 0;
+ mln::level::fill(deja_vu, false);
+ f.init();
+ }
+ // first pass
+ {
+ mln_fwd_piter(S) p(f.s);
+ mln_niter(N) n(f.nbh, p);
+ for_all(p) if (f.handles(p))
+ {
+ make_set(p);
+ for_all(n)
+ if (f.input.has(n) && deja_vu(n))
+ if (f.equiv(n, p))
+ do_union(n, p);
+ else
+ f.do_no_union(n, p);
+ deja_vu(p) = true;
+ }
+ }
+
+ // second pass
+ {
+ mln_bkd_piter(S) p(f.s);
+ for_all(p) if (f.handles(p))
+ {
+ if (is_root(p))
+ {
+ if (f.labels(p))
+ {
+ if (f.nlabels == mln_max(mln_value(O)))
+ {
+ f.status = false;
+ return;
+ }
+ f.output(p) = ++f.nlabels;
+ }
+ }
+ else
+ f.output(p) = f.output(parent(p));
+ }
+ f.status = true;
+ }
+
+ } // end of run()
+
+ void make_set(const point& p)
+ {
+ parent(p) = p;
+ f.init_attr(p);
+ }
+
+ bool is_root(const point& p) const
+ {
+ return parent(p) == p;
+ }
+
+ point find_root(const point& x)
+ {
+ if (parent(x) == x)
+ return x;
+ else
+ return parent(x) = find_root(parent(x));
+ }
+
+ void do_union(const point& n, const point& p)
+ {
+ point r = find_root(n);
+ if (r != p)
+ {
+ parent(r) = p;
+ f.merge_attr(r, p);
+ }
+ }
+
+ };
+
+
+ // FIXME: Fast version.
+
+ // FIXME (ADD)
+ //
+ template <typename F>
+ struct labeling_fast
+ {
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::O O;
+ typedef typename F::S S;
+ typedef mln_point(I) point;
+
+ labeling_fast(F& f)
+ : f(f)
+ {
+ run();
+ }
+
+ void run()
+ {
+ // init
+ {
+ f.nlabels = 0;
+ f.init();
+ }
+ // first pass
+ {
+ typedef mln_dpoint(N) DP;
+ typedef mln_point(N) P;
+ typedef window<DP> W;
+
+ mln_fwd_pixter(const I) pix_input(f.input);
+ W win = convert::to_window(f.nbh);
+
+ mln_qiter(W) q_input(win, P::zero);
+
+ for_all(pix_input)
+ {
+// if (f.handles(pix_input))
+// {
+ const point p = pix_input;
+ make_set(p);
+ for_all(q_input)
+ {
+// const point q;
+// if (f.equiv(q, p))
+// do_union(q, p);
+// else
+// f.do_no_union(q, p);
+ }
+// }
+ }
+ }
+
+// // second pass
+// {
+// mln_bkd_piter(S) p(f.s);
+// for_all(p) if (f.handles(p))
+// {
+// if (is_root(p))
+// {
+// if (f.labels(p))
+// {
+// if (f.nlabels == mln_max(mln_value(O)))
+// {
+// f.status = false;
+// return;
+// }
+// f.output(p) = ++f.nlabels;
+// }
+// }
+// else
+// f.output(p) = f.output(parent(p));
+// }
+// f.status = true;
+// }
+
+ } // end of run()
+
+ void make_set(const point& p)
+ {
+ parent(p) = p;
+ f.init_attr(p);
+ }
+
+ bool is_root(const point& p) const
+ {
+ return parent(p) == p;
+ }
+
+ point find_root(const point& x)
+ {
+ if (parent(x) == x)
+ return x;
+ else
+ return parent(x) = find_root(parent(x));
+ }
+
+ void do_union(const point& n, const point& p)
+ {
+ point r = find_root(n);
+ if (r != p)
+ {
+ parent(r) = p;
+ f.merge_attr(r, p);
+ }
+ }
+ };
+ //
+ // END FIXME (ADD)
+
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_HH
Index: trunk/milena/sandbox/duhamel/border_fill.cc
===================================================================
--- trunk/milena/sandbox/duhamel/border_fill.cc (revision 1124)
+++ trunk/milena/sandbox/duhamel/border_fill.cc (revision 1125)
@@ -41,7 +41,7 @@
int
main (void)
{
- image2d_b<value::int_u8> i1(9, 7);
+ image2d_b<value::int_u8> i1(9, 6);
border::fill (i1, 8);
debug::println_with_border(i1);
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add level::paste for fast images and fix line_piter.
* tests/line_piter.cc: Fix doc.
(main): Start at non-zero point.
* mln/core/line_piter.hh (operator[]): Fix.
(next_): Fix.
* mln/level/paste.hh: Specialize for Fast_Image.
* tests/level_paste.cc: New.
mln/core/line_piter.hh | 4 +--
mln/level/paste.hh | 36 ++++++++++++++++++++++++++++--
tests/level_paste.cc | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/line_piter.cc | 13 +++-------
4 files changed, 98 insertions(+), 13 deletions(-)
Index: tests/level_paste.cc
--- tests/level_paste.cc (revision 0)
+++ tests/level_paste.cc (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/level_fill.cc
+ *
+ * \brief Tests on mln::level::fill
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/paste.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d b(make::point2d(1,2), make::point2d(2,4));
+ image2d_b<int> ima(b, 2);
+ debug::iota(ima);
+ debug::println(ima);
+
+
+ box2d b2(make::point2d(-1,-2), make::point2d(3,6));
+ image2d_b<int> ima2(b2, 0);
+ debug::iota(ima2);
+ debug::println(ima2);
+
+ level::paste(ima, ima2);
+ debug::println(ima2);
+}
Index: tests/line_piter.cc
--- tests/line_piter.cc (revision 1123)
+++ tests/line_piter.cc (working copy)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/image2d_b.cc
+/*! \file tests/line_piter.cc
*
- * \brief Tests on mln::image2d_b.
+ * \brief Tests on mln::line_piter.
*/
#include <mln/core/image2d_b.hh>
@@ -37,16 +37,11 @@
{
using namespace mln;
- const unsigned nrows = 6;
- const unsigned ncols = 4;
+ box2d b(make::point2d(1,2), make::point2d(5,8));
const unsigned border = 2;
-
- image2d_b<int> f(nrows, ncols, border);
+ image2d_b<int> f(b, border);
image2d_b<int>::line_piter p(f.domain());
-
for_all(p)
- {
std::cout << p <<std::endl;
}
-}
Index: mln/core/line_piter.hh
--- mln/core/line_piter.hh (revision 1123)
+++ mln/core/line_piter.hh (working copy)
@@ -118,7 +118,7 @@
mln_coord(P)
line_piter_<P>::operator[](unsigned i) const
{
- mln_invariant(p_[0] = 0);
+ mln_invariant(p_[dim - 1] = b_.pmin()[dim - 1]);
assert(i < dim);
return p_[i];
}
@@ -148,7 +148,7 @@
void
line_piter_<P>::next_()
{
- for (int c = 1; c < dim; ++c)
+ for (int c = dim - 2; c >= 0; --c)
{
if (p_[c] != b_.pmax()[c])
{
Index: mln/level/paste.hh
--- mln/level/paste.hh (revision 1123)
+++ mln/level/paste.hh (working copy)
@@ -34,6 +34,8 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/inplace.hh>
+# include <mln/level/memcpy_.hh>
namespace mln
@@ -64,18 +66,48 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename I, typename J>
- void paste(const Image<I>& data_, Image<J>& destination_)
+ void paste_(const Image<I>& data_, Image<J>& destination_)
{
const I& data = exact(data_);
J& destination = exact(destination_);
- mln_precondition(data.domain() <= destination.domain());
mln_piter(I) p(data.domain());
for_all(p)
destination(p) = data(p);
}
+ template <typename I, typename J>
+ void paste_(const Fast_Image<I>& data_, Fast_Image<J>& destination_)
+ {
+ const I& data = exact(data_);
+ J& destination = exact(destination_);
+
+ typedef mln_point(I) P;
+ std::size_t n = data.bbox().len(P::dim - 1);
+
+ typename I::line_piter p(data.domain());
+ for_all(p)
+ memcpy_(inplace(make::pixel(destination, p)),
+ make::pixel(data, p),
+ n);
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facade.
+
+ template <typename I, typename J>
+ void paste(const Image<I>& data, Image<J>& destination)
+ {
+ mln_precondition(exact(data).domain() <= exact(destination).domain());
+ impl::paste_(exact(data), exact(destination));
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::level
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add mesh and factor some code.
New files.
* mln/core/internal/point_iterator_base.hh: New.
* mln/core/internal/point_set_base.hh: New.
* mln/core/concept/mesh.hh: New.
* mln/core/concept/regular_grid.hh: New.
* mln/core/grids.hh: New.
Update to take into account the notion of mesh.
* doc/Doxyfile.in,
* mln/pw/image.hh,
* mln/core/dpoint1d.hh,
* mln/core/dpoint2d.hh,
* mln/core/dpoints_piter.hh,
* mln/core/dpoint3d.hh,
* mln/core/macros.hh,
* mln/core/box.hh,
* mln/core/point.hh,
* mln/core/internal/piter_adaptor.hh,
* mln/core/internal/run_pset.hh,
* mln/core/internal/run_psite.hh,
* mln/core/internal/image_base.hh,
* mln/core/point1d.hh,
* mln/core/point2d.hh,
* mln/core/point3d.hh,
* mln/core/line_piter.hh,
* mln/core/vec_p_piter.hh,
* mln/core/line2d.hh,
* mln/core/box_piter.hh,
* mln/core/cast_image.hh,
* mln/core/queue_p.hh,
* mln/core/pset_if.hh,
* mln/core/vec_p.hh,
* mln/core/concept/image.hh,
* mln/core/concept/dpoint.hh,
* mln/core/concept/point_iterator.hh,
* mln/core/concept/generalized_point.hh,
* mln/core/concept/point_set.hh,
* mln/core/concept/object.hh,
* mln/core/dpoint.hh,
* mln/core/set_p.hh,
* mln/metal/is_a.hh: Update.
doc/Doxyfile.in | 1
mln/core/box.hh | 36 +++++------
mln/core/box_piter.hh | 40 +------------
mln/core/cast_image.hh | 11 +--
mln/core/concept/dpoint.hh | 1
mln/core/concept/generalized_point.hh | 7 +-
mln/core/concept/image.hh | 7 ++
mln/core/concept/mesh.hh | 74 ++++++++++++++++++++++++
mln/core/concept/object.hh | 1
mln/core/concept/point_iterator.hh | 3
mln/core/concept/point_set.hh | 4 +
mln/core/concept/regular_grid.hh | 65 +++++++++++++++++++++
mln/core/dpoint.hh | 68 ++++++++++------------
mln/core/dpoint1d.hh | 2
mln/core/dpoint2d.hh | 2
mln/core/dpoint3d.hh | 2
mln/core/dpoints_piter.hh | 29 ++-------
mln/core/grids.hh | 83 +++++++++++++++++++++++++++
mln/core/internal/image_base.hh | 8 ++
mln/core/internal/piter_adaptor.hh | 26 +-------
mln/core/internal/point_iterator_base.hh | 95 +++++++++++++++++++++++++++++++
mln/core/internal/point_set_base.hh | 86 ++++++++++++++++++++++++++++
mln/core/internal/run_pset.hh | 33 ++++------
mln/core/internal/run_psite.hh | 31 +++++++++-
mln/core/line2d.hh | 10 ---
mln/core/line_piter.hh | 21 ------
mln/core/macros.hh | 7 ++
mln/core/point.hh | 78 ++++++++++++-------------
mln/core/point1d.hh | 2
mln/core/point2d.hh | 2
mln/core/point3d.hh | 2
mln/core/pset_if.hh | 15 ++--
mln/core/queue_p.hh | 10 ---
mln/core/set_p.hh | 12 ---
mln/core/vec_p.hh | 13 ----
mln/core/vec_p_piter.hh | 34 +----------
mln/metal/is_a.hh | 2
mln/pw/image.hh | 11 +--
38 files changed, 628 insertions(+), 306 deletions(-)
Index: doc/Doxyfile.in
--- doc/Doxyfile.in (revision 1122)
+++ doc/Doxyfile.in (working copy)
@@ -1064,6 +1064,7 @@
"mln_vset(T)=typename T::vset" \
"mln_rvalue(T)=typename T::rvalue" \
"mln_lvalue(T)=typename T::lvalue" \
+ "mln_mesh(T)=typename T::mesh" \
"mln_coord(T)=typename T::coord" \
"mln_point(T)=typename T::point" \
"mln_dpoint(T)=typename T::dpoint"
Index: mln/pw/image.hh
--- mln/pw/image.hh (revision 1122)
+++ mln/pw/image.hh (working copy)
@@ -62,13 +62,14 @@
*
*/
template <typename F, typename S>
- struct image : public internal::image_base_< S, image<F,S> >
+ class image : public internal::image_base_< S, image<F,S> >
{
- /// Point_Site associated type.
- typedef mln_psite(S) psite;
+ typedef internal::image_base_< S, image<F,S> > super_;
+ public:
+
+ // From super class.
+ typedef mln_psite(super_) psite;
- /// Point_Set associated type.
- typedef S pset;
/// Value associated type.
typedef mln_result(F) value;
Index: mln/core/dpoint1d.hh
--- mln/core/dpoint1d.hh (revision 1122)
+++ mln/core/dpoint1d.hh (working copy)
@@ -43,7 +43,7 @@
/*! \brief Type alias for a delta-point defined on the 1D square
* grid with integer coordinates.
*/
- typedef dpoint_<1,int> dpoint1d;
+ typedef dpoint_<grid::tick, int> dpoint1d;
} // end of namespace mln
Index: mln/core/dpoint2d.hh
--- mln/core/dpoint2d.hh (revision 1122)
+++ mln/core/dpoint2d.hh (working copy)
@@ -43,7 +43,7 @@
/*! \brief Type alias for a delta-point defined on the 2D square
* grid with integer coordinates.
*/
- typedef dpoint_<2,int> dpoint2d;
+ typedef dpoint_<grid::square, int> dpoint2d;
} // end of namespace mln
Index: mln/core/dpoints_piter.hh
--- mln/core/dpoints_piter.hh (revision 1122)
+++ mln/core/dpoints_piter.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Definition of mln::dpoints_fwd_piter and mln::dpoints_bkd_piter.
*/
-# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/point_iterator_base.hh>
# include <mln/core/concept/generalized_point.hh>
@@ -46,25 +46,10 @@
* The parameter \c D is the type of delta-points.
*/
template <typename D>
- class dpoints_fwd_piter : public Point_Iterator< dpoints_fwd_piter<D> >
+ class dpoints_fwd_piter : public internal::point_iterator_base_< mln_point(D), dpoints_fwd_piter<D> >
{
public:
- /// Space dimension.
- enum { dim = D::dim };
-
- /// Dpoint associated type.
- typedef D dpoint;
-
- /// Point associated type.
- typedef mln_point(D) point;
-
- /// Point_Site associated type.
- typedef point psite;
-
- /// Coordinate associated type.
- typedef mln_coord(D) coord;
-
/*! \brief Constructor.
*
* \param[in] dps Object that can provide an array of delta-points.
@@ -78,7 +63,7 @@
operator mln_point(D) () const;
/// Address of the point this iterator designates.
- const point* pointer_() const;
+ const mln_point(D)* pointer_() const;
/// Test the iterator validity.
bool is_valid() const;
@@ -93,10 +78,10 @@
void next_();
/// Give the i-th coordinate.
- coord operator[](unsigned i) const;
+ mln_coord(D) operator[](unsigned i) const;
/// The point around which this iterator moves.
- const point& center_point() const;
+ const mln_point(D)& center_point() const;
/// Force this iterator to update its location to take into
/// account that its center point may have moved.
@@ -105,10 +90,10 @@
protected:
const std::vector<D>& dps_;
- const point& p_ref_; // reference point (or "center point")
+ const mln_point(D)& p_ref_; // reference point (or "center point")
unsigned i_;
- point p_; // location of this iterator; p_ makes this iterator be
+ mln_point(D) p_; // location of this iterator; p_ makes this iterator be
// itself a potential center point (Cf. the pointer_() method).
};
Index: mln/core/dpoint3d.hh
--- mln/core/dpoint3d.hh (revision 1122)
+++ mln/core/dpoint3d.hh (working copy)
@@ -43,7 +43,7 @@
/*! \brief Type alias for a delta-point defined on the 3D square
* grid with integer coordinates.
*/
- typedef dpoint_<3,int> dpoint3d;
+ typedef dpoint_<grid::cube, int> dpoint3d;
} // end of namespace mln
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1122)
+++ mln/core/macros.hh (working copy)
@@ -104,6 +104,13 @@
# define mln_lvalue(T) typename T::lvalue
+// m
+
+
+/// Shortcut to access the mesh type associated to T.
+# define mln_mesh(T) typename T::mesh
+
+
// p
/// Shortcut to access the type of point iterator (piter) associated to T.
Index: mln/core/box.hh
--- mln/core/box.hh (revision 1122)
+++ mln/core/box.hh (working copy)
@@ -54,44 +54,40 @@
struct box_ : public Box< box_<P> >,
public internal::box_impl_< P::dim, mln_coord(P), box_<P> >
{
- /*! \brief Point_Site associated type.
- */
+ /// Mesh associated type.
+ typedef mln_mesh(P) mesh;
+
+ /// Point_Site associated type.
typedef P psite;
- /*! \brief Point associated type.
- */
+ /// Point associated type.
typedef P point;
- /*! \brief Forward Point_Iterator associated type.
- */
+ /// Dpoint associated type.
+ typedef mln_dpoint(P) dpoint;
+
+ /// Forward Point_Iterator associated type.
typedef box_fwd_piter_<P> fwd_piter;
- /*! \brief Backward Point_Iterator associated type.
- */
+ /// Backward Point_Iterator associated type.
typedef box_bkd_piter_<P> bkd_piter;
- /*! \brief Minimum point.
- */
+ /// Minimum point.
P pmin() const;
- /*! \brief Reference to the minimum point.
- */
+ /// Reference to the minimum point.
P& pmin();
- /*! \brief Maximum point.
- */
+ /// Maximum point.
P pmax() const;
- /*! \brief Reference to the maximum point.
- */
+ /// Reference to the maximum point.
P& pmax();
- /*! \brief Constructor without argument.
- */
+ /// Constructor without argument.
box_();
- /*! \brief Constructor of a box going from \p pmin to \p pmax.
- */
+ /// Constructor of a box going from \p pmin to \p pmax.
box_(const point& pmin, const point& pmax);
/*! \brief Test if \p p belongs to the box.
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1122)
+++ mln/core/point.hh (working copy)
@@ -42,7 +42,7 @@
{
// fwd decl
- template <unsigned n, typename C> struct dpoint_;
+ template <typename M, typename C> struct dpoint_;
/*! \brief Generic point class.
@@ -50,22 +50,23 @@
* Parameters are \c n the dimension of the space and \c C the
* coordinate type in this space.
*/
- template <unsigned n, typename C>
- struct point_ : public Point< point_<n,C> >,
- public internal::mutable_coord_impl_< n, C, point_<n,C> >
+ template <typename M, typename C>
+ struct point_ : public Point< point_<M,C> >,
+ public internal::mutable_coord_impl_< M::dim, C, point_<M,C> >
{
/*! \var dim
* \brief Dimension of the space.
* \invariant dim > 0
*/
- enum { dim = n };
+ enum { dim = M::dim };
- /*! \brief Dpoint associated type.
- */
- typedef dpoint_<n,C> dpoint;
+ /// Mesh associated type.
+ typedef M mesh;
- /*! \brief Coordinate associated type.
- */
+ /// Dpoint associated type.
+ typedef dpoint_<M,C> dpoint;
+
+ /// Coordinate associated type.
typedef C coord;
/*! \brief Read-only access to the \p i-th coordinate value.
@@ -80,81 +81,78 @@
*/
C& operator[](unsigned i);
- /*! \brief Constructor without argument.
- */
+ /// Constructor without argument.
point_();
- /*! \brief Constructor; coordinates are set by function \p f.
- */
+ /// Constructor; coordinates are set by function \p f.
template <typename F>
point_(const Function_i2v<F>& f);
- /*! \brief Set all coordinates to the value \p c.
- */
+ /// Set all coordinates to the value \p c.
void set_all(C c);
/// Origin point (all coordinates are 0).
- static const point_<n,C> zero;
+ static const point_<M,C> zero;
/// Shifting by \p dp.
- point_<n, C>& operator+=(const dpoint& dp);
+ point_<M,C>& operator+=(const dpoint& dp);
/// Type of the array of coordinates.
- typedef const C (&vec_t)[n];
+ typedef const C (&vec_t)[dim];
/// Hook to coordinates.
vec_t to_vec() const { return coord_; }
protected:
- C coord_[n];
+ C coord_[dim];
};
# ifndef MLN_INCLUDE_ONLY
- template <unsigned n, typename C>
- C point_<n,C>::operator[](unsigned i) const
+ template <typename M, typename C>
+ C point_<M,C>::operator[](unsigned i) const
{
- assert(i < n);
+ assert(i < dim);
return this->coord_[i];
}
- template <unsigned n, typename C>
- C& point_<n,C>::operator[](unsigned i)
+ template <typename M, typename C>
+ C& point_<M,C>::operator[](unsigned i)
{
- assert(i < n);
+ assert(i < dim);
return this->coord_[i];
}
- template <unsigned n, typename C>
- point_<n,C>::point_()
+ template <typename M, typename C>
+ point_<M,C>::point_()
{
}
- template <unsigned n, typename C>
+ template <typename M, typename C>
template <typename F>
- point_<n,C>::point_(const Function_i2v<F>& f_)
+ point_<M,C>::point_(const Function_i2v<F>& f_)
{
const F& f = exact(f_);
- for (unsigned i = 0; i < n; ++i)
+ for (unsigned i = 0; i < dim; ++i)
coord_[i] = f(i);
}
- template <unsigned n, typename C>
- void point_<n,C>::set_all(C c)
+ template <typename M, typename C>
+ void point_<M,C>::set_all(C c)
{
- for (unsigned i = 0; i < n; ++i)
+ for (unsigned i = 0; i < dim; ++i)
coord_[i] = c;
}
- template <unsigned n, typename C>
- const point_<n,C> point_<n,C>::zero = all(0);
+ template <typename M, typename C>
+ const point_<M,C> point_<M,C>::zero = all(0);
- template <unsigned n, typename C>
- point_<n, C>&
- point_<n,C>::operator+=(const dpoint& dp)
+ template <typename M, typename C>
+ point_<M,C>&
+ point_<M,C>::operator+=(const dpoint& dp)
{
- for (unsigned i = 0; i < n; ++i)
+ for (unsigned i = 0; i < dim; ++i)
coord_[i] += dp[i];
return *this;
}
Index: mln/core/internal/point_iterator_base.hh
--- mln/core/internal/point_iterator_base.hh (revision 0)
+++ mln/core/internal/point_iterator_base.hh (revision 0)
@@ -0,0 +1,95 @@
+// 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_POINT_ITERATOR_BASE_HH
+# define MLN_CORE_INTERNAL_POINT_ITERATOR_BASE_HH
+
+/*! \file mln/core/internal/point_iterator_base.hh
+ *
+ * \brief Base class to factor code for point iterator classes.
+ */
+
+# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/concept/point_site.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+
+ /*! \brief A base class for point iterators.
+ *
+ * Parameter \c P is a point site type.
+ *
+ * \internal
+ */
+ template <typename P, typename E>
+ struct point_iterator_base_ : public Point_Iterator<E>
+ {
+ /// Psite associated type.
+ typedef P psite;
+
+ /// Mesh associated type.
+ typedef mln_mesh(P) mesh;
+
+ /// Dim value.
+ enum { dim = mesh::dim };
+
+ /// Point associated type.
+ typedef mln_point(P) point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(P) dpoint;
+
+ /// Coord associated type.
+ typedef mln_coord(point) coord;
+
+ protected:
+ /// Constructor.
+ point_iterator_base_();
+ };
+
+
+#ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ point_iterator_base_<P, E>::point_iterator_base_()
+ {
+ mln::metal::is_a<P, Point_Site>::check();
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_POINT_ITERATOR_BASE_HH
Index: mln/core/internal/piter_adaptor.hh
--- mln/core/internal/piter_adaptor.hh (revision 1122)
+++ mln/core/internal/piter_adaptor.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Definition of iterators on points of boxes.
*/
-# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/point_iterator_base.hh>
# include <mln/core/concept/box.hh>
@@ -49,38 +49,21 @@
* parameter E is the exact type.
*/
template <typename Pi, typename E>
- class piter_adaptor_ : public Point_Iterator<E>
+ class piter_adaptor_ : public internal::point_iterator_base_< mln_psite(Pi), E >
{
public:
- /// Space dimension.
- enum { dim = Pi::dim };
-
- /// Point_Site 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 mln_point(Pi) () const;
/// Address of the point.
- const point* pointer_() const;
+ const mln_point(Pi)* pointer_() const;
/// Give the i-th coordinate.
- coord operator[](unsigned i) const;
+ mln_coord(Pi) operator[](unsigned i) const;
/// Test the iterator validity.
bool is_valid() const;
@@ -104,7 +87,6 @@
# ifndef MLN_INCLUDE_ONLY
-
template <typename Pi, typename E>
piter_adaptor_<Pi,E>::piter_adaptor_(const Pi& piter)
: piter_(piter)
Index: mln/core/internal/point_set_base.hh
--- mln/core/internal/point_set_base.hh (revision 0)
+++ mln/core/internal/point_set_base.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_CORE_INTERNAL_POINT_SET_BASE_HH
+# define MLN_CORE_INTERNAL_POINT_SET_BASE_HH
+
+/*! \file mln/core/internal/point_set_base.hh
+ *
+ * \brief Definition of a base class for point set classes.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/grids.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+ /*! \brief A base class for point set classes.
+ *
+ * \p P is a point site type.
+ *
+ * \internal
+ */
+ template <typename P, typename E>
+ struct point_set_base_ : public Point_Set<E>
+ {
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Mesh associated type.
+ typedef mln_mesh(P) mesh;
+
+ /// Point associated type.
+ typedef mln_point(P) point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(point) dpoint;
+
+ protected:
+ point_set_base_();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename E>
+ point_set_base_<S,E>::point_set_base_()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_POINT_SET_BASE_HH
Index: mln/core/internal/run_pset.hh
--- mln/core/internal/run_pset.hh (revision 1122)
+++ mln/core/internal/run_pset.hh (working copy)
@@ -34,8 +34,8 @@
* (for internal use only).
*/
-# include <mln/core/concept/point_set.hh>
-# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/internal/point_iterator_base.hh>
# include <mln/core/internal/run_psite.hh>
# include <mln/accu/bbox.hh>
@@ -59,19 +59,18 @@
* Parameter \c P is the type of the image point.
*/
template <typename P>
- class run_pset_ : public Point_Set<run_pset_<P> >
+ class run_pset_ : public internal::point_set_base_< run_psite<P>, run_pset_<P> >
{
public:
- typedef P point;
- typedef internal::run_psite<point> psite;
- typedef std::vector<std::pair<point, unsigned> > std_container;
+
+ typedef std::vector<std::pair<P, unsigned> > std_container;
typedef run_fwd_piter_<P> fwd_piter;
typedef run_bkd_piter_<P> bkd_piter;
run_pset_();
/// Test is \p p belongs to this point set.
- bool has(const psite& p) const;
+ bool has(const run_psite<P>& p) const;
/// Give the exact bounding box.
const box_<P>& bbox() const;
/// Give the number of points.
@@ -104,7 +103,7 @@
template <typename P>
bool
- run_pset_<P>::has(const typename run_pset_<P>::psite& p) const
+ run_pset_<P>::has(const run_psite<P>& p) const
{
for (unsigned i = 0; i < con_.size(); ++i)
{
@@ -132,7 +131,7 @@
void
run_pset_<P>::insert(const P& p, unsigned len)
{
- point run_pend;
+ P run_pend;
typename std_container::value_type elt (p, len);
con_.push_back(elt);
@@ -176,31 +175,25 @@
* Parameter \c E is the exact type of the iterator
*/
template <typename P, typename E>
- class run_piter_ : public Point_Iterator<E>
+ class run_piter_ : public internal::point_iterator_base_< internal::run_psite<P>, E >
{
public:
typedef typename run_pset_<P>::std_container std_container;
- typedef P point;
- typedef mln_dpoint(P) dpoint;
- typedef mln_coord(P) coord;
- typedef internal::run_psite<P> psite;
-
- enum { dim = P::dim };
/// Convertion into a point-site.
- operator psite () const;
+ operator internal::run_psite<P> () const;
/// Convertion into a point.
operator P () const;
/// Return a pointer of the current point.
const P* pointer_() const;
/// Access to the current point coordinates.
- coord operator[](unsigned i) const;
+ mln_coord(P) operator[](unsigned i) const;
protected:
/// Current point.
P p_;
/// Current site.
- psite site_;
+ internal::run_psite<P> site_;
/// Point set container.
const std_container& con_;
@@ -237,7 +230,7 @@
}
template <typename P, typename E>
- typename run_piter_<P, E>::coord
+ mln_coord(P)
run_piter_<P, E>::operator[] (unsigned i) const
{
mln_precondition(exact(this)->is_valid());
Index: mln/core/internal/run_psite.hh
--- mln/core/internal/run_psite.hh (revision 1122)
+++ mln/core/internal/run_psite.hh (working copy)
@@ -33,6 +33,9 @@
* \brief Definition of class mln::internal::run_psite_ for internal use only
*/
+# include <mln/core/concept/point_site.hh>
+
+
namespace mln
{
@@ -44,9 +47,16 @@
* Parameter \c P is the type of the image point.
*/
template <typename P>
- class run_psite
+ class run_psite : public Point_Site< run_psite<P> >
{
public:
+
+ typedef mln_mesh(P) mesh;
+ enum { dim = P::dim };
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+
run_psite();
run_psite(P point, unsigned index, unsigned pset_pos);
@@ -64,6 +74,9 @@
/// Return the position of this psite in the current range.
unsigned& index_();
+ const P* pointer_() const;
+ mln_coord(P) operator[](unsigned i) const;
+
protected:
/// Start of the psite range.
P point_;
@@ -136,6 +149,22 @@
{
return range_index_;
}
+
+ template <typename P>
+ const P*
+ run_psite<P>::pointer_() const
+ {
+ return & point_;
+ }
+
+ template <typename P>
+ mln_coord(P)
+ run_psite<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ return point_[i];
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1122)
+++ mln/core/internal/image_base.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/grids.hh>
namespace mln
@@ -82,6 +83,8 @@
/*! \brief A base class for images.
*
+ * Parameter \p S is a point set type.
+ *
* \internal
*/
template <typename S, typename E>
@@ -93,13 +96,16 @@
/// Point_Set associated type.
typedef S pset;
+
+ /// Mesh associated type.
+ typedef mln_mesh(S) mesh;
+
/// Point_Site associated type.
typedef mln_psite(S) psite;
/// Point associated type.
typedef mln_point(S) point;
-
/// Dpoint associated type.
typedef mln_dpoint(point) dpoint;
Index: mln/core/point1d.hh
--- mln/core/point1d.hh (revision 1122)
+++ mln/core/point1d.hh (working copy)
@@ -43,7 +43,7 @@
/*! \brief Type alias for a point defined on the 1D square grid with
* integer coordinates.
*/
- typedef point_<1,int> point1d;
+ typedef point_<grid::tick, int> point1d;
} // end of namespace mln
Index: mln/core/point2d.hh
--- mln/core/point2d.hh (revision 1122)
+++ mln/core/point2d.hh (working copy)
@@ -43,7 +43,7 @@
/*! \brief Type alias for a point defined on the 2D square grid with
* integer coordinates.
*/
- typedef point_<2,int> point2d;
+ typedef point_<grid::square, int> point2d;
} // end of namespace mln
Index: mln/core/point3d.hh
--- mln/core/point3d.hh (revision 1122)
+++ mln/core/point3d.hh (working copy)
@@ -43,7 +43,7 @@
/*! \brief Type alias for a point defined on the 3D square grid with
* integer coordinates.
*/
- typedef point_<3,int> point3d;
+ typedef point_<grid::cube, int> point3d;
} // end of namespace mln
Index: mln/core/line_piter.hh
--- mln/core/line_piter.hh (revision 1122)
+++ mln/core/line_piter.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Definition of iterators on points by lines.
*/
-# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/point_iterator_base.hh>
namespace mln
@@ -44,25 +44,10 @@
* The parameter \c P is the type of points.
*/
template <typename P>
- class line_piter_ : public Point_Iterator< line_piter_<P> >
+ class line_piter_ : public internal::point_iterator_base_< P, line_piter_<P> >
{
public:
- /// Space dimension.
- enum { dim = P::dim };
-
- /// Point_Site associated type.
- typedef P psite;
-
- /// Point associated type.
- typedef P point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
- /// Coordinate associated type.
- typedef mln_coord(P) coord;
-
/*! \brief Constructor.
*
* \param[in] b A box.
@@ -76,7 +61,7 @@
const P* pointer_() const;
/// Give the i-th coordinate.
- coord operator[](unsigned i) const;
+ mln_coord(P) operator[](unsigned i) const;
/// Test the iterator validity.
bool is_valid() const;
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1122)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -43,21 +43,8 @@
*
*/
template <typename P>
- struct vec_p_fwd_piter_ : public Point_Iterator< vec_p_fwd_piter_<P> >
+ struct vec_p_fwd_piter_ : public internal::point_iterator_base_< P, vec_p_fwd_piter_<P> >
{
- enum { dim = P::dim };
-
- /// Point_Site associated type.
- typedef P psite;
-
- /// Point associated type.
- typedef P point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
- /// Coordinate associated type.
- typedef mln_coord(P) coord;
/// Coordinate associated type.
template <typename S>
@@ -67,7 +54,7 @@
const P* pointer_() const;
/// Read-only access to the \p i-th coordinate.
- coord operator[](unsigned i) const;
+ mln_coord(P) operator[](unsigned i) const;
/// Test if the iterator is valid.
bool is_valid() const;
@@ -96,21 +83,8 @@
*
*/
template <typename P>
- struct vec_p_bkd_piter_ : public Point_Iterator< vec_p_bkd_piter_<P> >
+ struct vec_p_bkd_piter_ : public internal::point_iterator_base_< P, vec_p_bkd_piter_<P> >
{
- enum { dim = P::dim };
-
- /// Point_Site associated type.
- typedef P psite;
-
- /// Point associated type.
- typedef P point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
- /// Coordinate associated type.
- typedef mln_coord(P) coord;
/// Coordinate associated type.
template <typename S>
@@ -120,7 +94,7 @@
const P* pointer_() const;
/// Read-only access to the \p i-th coordinate.
- coord operator[](unsigned i) const;
+ mln_coord(P) operator[](unsigned i) const;
/// Test if the iterator is valid.
bool is_valid() const;
Index: mln/core/line2d.hh
--- mln/core/line2d.hh (revision 1122)
+++ mln/core/line2d.hh (working copy)
@@ -35,7 +35,7 @@
# include <vector>
-# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/point_set_base.hh>
# include <mln/core/vec_p_piter.hh>
# include <mln/core/box2d.hh>
# include <mln/math/all.hh>
@@ -47,16 +47,10 @@
/*! \brief 2D line point set class.
*/
- class line2d : public Point_Set< line2d >
+ class line2d : public internal::point_set_base_< point2d, line2d >
{
public:
- /// Point associated type.
- typedef point2d point;
-
- /// Point_Site associated type.
- typedef point2d psite;
-
/// Forward Point_Iterator associated type.
typedef vec_p_fwd_piter_<point2d> fwd_piter;
Index: mln/core/box_piter.hh
--- mln/core/box_piter.hh (revision 1122)
+++ mln/core/box_piter.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Definition of iterators on points of boxes.
*/
-# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/point_iterator_base.hh>
# include <mln/core/concept/box.hh>
@@ -47,25 +47,10 @@
* \see mln::box_
*/
template <typename P>
- class box_fwd_piter_ : public Point_Iterator< box_fwd_piter_<P> >
+ class box_fwd_piter_ : public internal::point_iterator_base_< P, box_fwd_piter_<P> >
{
public:
- /// Space dimension.
- enum { dim = P::dim };
-
- /// Point_Site associated type.
- typedef P psite;
-
- /// Point associated type.
- typedef P point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
- /// Coordinate associated type.
- typedef mln_coord(P) coord;
-
/*! \brief Constructor.
*
* \param[in] b A box.
@@ -79,7 +64,7 @@
const P* pointer_() const;
/// Give the i-th coordinate.
- coord operator[](unsigned i) const;
+ mln_coord(P) operator[](unsigned i) const;
/// Test the iterator validity.
bool is_valid() const;
@@ -107,25 +92,10 @@
* \see mln::box_
*/
template <typename P>
- class box_bkd_piter_ : public Point_Iterator< box_bkd_piter_<P> >
+ class box_bkd_piter_ : public internal::point_iterator_base_< P, box_bkd_piter_<P> >
{
public:
- /// Space dimension.
- enum { dim = P::dim };
-
- /// Point_Site associated type.
- typedef P psite;
-
- /// Point associated type.
- typedef P point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
- /// Coordinate associated type.
- typedef mln_coord(P) coord;
-
/*! \brief Constructor.
*
* \param[in] b A box.
@@ -139,7 +109,7 @@
const P* pointer_() const;
/// Give the i-th coordinate.
- coord operator[](unsigned i) const;
+ mln_coord(P) operator[](unsigned i) const;
/// Test the iterator validity.
bool is_valid() const;
Index: mln/core/cast_image.hh
--- mln/core/cast_image.hh (revision 1122)
+++ mln/core/cast_image.hh (working copy)
@@ -45,13 +45,14 @@
*
*/
template <typename T, typename I>
- struct cast_image_ : public mln::internal::image_base_< mln_pset(I), cast_image_<T,I> >
+ class cast_image_ : public mln::internal::image_base_< mln_pset(I), cast_image_<T,I> >
{
- /// Point_Site associated type.
- typedef mln_psite(I) psite;
+ typedef cast_image_<T,I> self_;
+ typedef mln::internal::image_base_<mln_pset(I), self_> super_;
+ public:
+
+ typedef mln_psite(super_) psite;
- /// Point_Set associated type.
- typedef mln_pset(I) pset;
/// Value associated type.
typedef T value;
Index: mln/core/queue_p.hh
--- mln/core/queue_p.hh (revision 1122)
+++ mln/core/queue_p.hh (working copy)
@@ -38,7 +38,7 @@
# include <algorithm>
# include <iterator>
-# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/point_set_base.hh>
# include <mln/core/vec_p_piter.hh>
# include <mln/accu/bbox.hh>
@@ -63,16 +63,10 @@
* a call to npoints() when this container is multiple.
*/
template <typename P>
- class queue_p : public Point_Set< queue_p<P> >
+ class queue_p : public internal::point_set_base_< P, queue_p<P> >
{
public:
- /// Point associated type.
- typedef P point;
-
- /// Point_Site associated type.
- typedef P psite;
-
/// Forward Point_Iterator associated type.
typedef vec_p_fwd_piter_<P> fwd_piter;
Index: mln/core/pset_if.hh
--- mln/core/pset_if.hh (revision 1122)
+++ mln/core/pset_if.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Definition of the restriction of a point set w.r.t. a predicate.
*/
-# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/point_set_base.hh>
# include <mln/core/concept/function.hh>
@@ -65,14 +65,13 @@
* from point to Boolean.
*/
template <typename S, typename F>
- struct pset_if : public Point_Set< pset_if<S,F> >
+ class pset_if : public internal::point_set_base_< mln_psite(S), pset_if<S,F> >
{
- /// Point_Site associated type.
- typedef mln_psite(S) psite;
-
- /// Point associated type.
- typedef mln_point(S) point;
+ typedef pset_if<S,F> self_;
+ typedef internal::point_set_base_<mln_psite(S), self_> super_;
+ public:
+ typedef mln_psite(super_) psite;
/// Forward Point_Iterator associated type.
typedef pset_if_fwd_piter_<S,F> fwd_piter;
@@ -89,7 +88,7 @@
bool has(const psite& p) const;
/// Give a bounding box of the subset.
- const box_<point>& bbox() const;
+ const box_<mln_point(S)>& bbox() const;
/// Give the number of points of the subset.
std::size_t npoints() const;
Index: mln/core/vec_p.hh
--- mln/core/vec_p.hh (revision 1122)
+++ mln/core/vec_p.hh (working copy)
@@ -35,7 +35,7 @@
# include <vector>
-# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/point_set_base.hh>
# include <mln/accu/bbox.hh>
@@ -57,19 +57,10 @@
* \todo Make it work with P being a Point_Site.
*/
template <typename P>
- class vec_p : public Point_Set< vec_p<P> >
+ class vec_p : public internal::point_set_base_< P, vec_p<P> >
{
public:
- /// Point associated type.
- typedef P point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
- /// Point_Site associated type.
- typedef P psite;
-
/// Forward Point_Iterator associated type.
typedef vec_p_fwd_piter_<P> fwd_piter;
Index: mln/core/concept/image.hh
--- mln/core/concept/image.hh (revision 1122)
+++ mln/core/concept/image.hh (working copy)
@@ -33,7 +33,9 @@
*/
# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/mesh.hh>
# include <mln/core/trait/all.hh>
+# include <mln/metal/is_a.hh>
namespace mln
@@ -50,6 +52,8 @@
/*
// to be provided in concrete image classes:
+ typedef mesh;
+
typedef value;
typedef rvalue;
typedef lvalue;
@@ -117,6 +121,9 @@
// to be provided in concrete image classes:
+ typedef mln_mesh(E) mesh;
+ metal::is_a<mesh, Mesh>::check(); // FIXME: Add other checks.
+
typedef mln_value(E) value;
typedef mln_rvalue(E) rvalue;
typedef mln_lvalue(E) lvalue;
Index: mln/core/concept/mesh.hh
--- mln/core/concept/mesh.hh (revision 0)
+++ mln/core/concept/mesh.hh (revision 0)
@@ -0,0 +1,74 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_CONCEPT_MESH_HH
+# define MLN_CORE_CONCEPT_MESH_HH
+
+/*! \file mln/core/concept/mesh.hh
+ * \brief Definition of the concept of mln::Mesh.
+ */
+
+# include <mln/core/concept/object.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Base class for implementation classes of meshes.
+ *
+ * \see mln::doc::Mesh for a complete documentation of this class
+ * contents.
+ */
+ template <typename E>
+ struct Mesh : public Object<E>
+ {
+ /*
+ typedef regular;
+ typedef aligned;
+ enum { dim }; // FIXME: of the underlying space (?)
+ */
+
+ protected:
+ Mesh();
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Mesh<E>::Mesh()
+ {
+ // FIXME: Check for typedefs.
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_MESH_HH
Index: mln/core/concept/dpoint.hh
--- mln/core/concept/dpoint.hh (revision 1122)
+++ mln/core/concept/dpoint.hh (working copy)
@@ -33,6 +33,7 @@
*/
# include <mln/core/concept/object.hh>
+# include <mln/core/grids.hh>
namespace mln
Index: mln/core/concept/point_iterator.hh
--- mln/core/concept/point_iterator.hh (revision 1122)
+++ mln/core/concept/point_iterator.hh (working copy)
@@ -35,6 +35,7 @@
# include <mln/core/concept/iterator.hh>
# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/point_site.hh>
namespace mln
@@ -69,6 +70,8 @@
Point_Iterator<E>::Point_Iterator()
{
typedef mln_psite(E) psite;
+ mln::metal::is_a<psite, Point_Site>::check();
+
psite (E::*m)() const = & E::operator psite;
m = 0;
}
Index: mln/core/concept/generalized_point.hh
--- mln/core/concept/generalized_point.hh (revision 1122)
+++ mln/core/concept/generalized_point.hh (working copy)
@@ -36,6 +36,7 @@
# include <mln/metal/same_coord.hh>
# include <mln/core/concept/object.hh>
+# include <mln/core/grids.hh>
# include <mln/core/internal/force_exact.hh>
@@ -62,10 +63,11 @@
/*
enum { dim };
+ typedef mesh;
+
typedef point;
typedef dpoint;
typedef coord;
- typedef topo; // FIXME
either Point
or operator point() const;
@@ -205,13 +207,13 @@
# ifndef MLN_INCLUDE_ONLY
-
template <typename E>
Generalized_Point<E>::Generalized_Point()
{
int dim = E::dim;
mln_invariant(dim > 0);
dim = 0;
+ typedef mln_mesh(E) mesh;
typedef mln_point(E) point;
typedef mln_dpoint(E) dpoint;
typedef mln_coord(E) coord;
@@ -221,6 +223,7 @@
m2 = 0;
}
+ // Operators.
template <typename Pl, typename Pr>
bool operator=(const Generalized_Point<Pl>& lhs, const Generalized_Point<Pr>& rhs)
Index: mln/core/concept/point_set.hh
--- mln/core/concept/point_set.hh (revision 1122)
+++ mln/core/concept/point_set.hh (working copy)
@@ -49,6 +49,8 @@
struct Point_Set : public Object<E>
{
/*
+ typedef mesh;
+
typedef point;
typedef psite;
@@ -125,6 +127,8 @@
template <typename E>
Point_Set<E>::Point_Set()
{
+ typedef mln_mesh(E) mesh;
+
typedef mln_point(E) point;
typedef mln_psite(E) psite;
Index: mln/core/concept/object.hh
--- mln/core/concept/object.hh (revision 1122)
+++ mln/core/concept/object.hh (working copy)
@@ -39,6 +39,7 @@
# include <mln/core/macros.hh>
# include <mln/core/contract.hh>
# include <mln/core/internal/fixme.hh>
+# include <mln/metal/is_a.hh>
/*! \namespace mln
Index: mln/core/concept/regular_grid.hh
--- mln/core/concept/regular_grid.hh (revision 0)
+++ mln/core/concept/regular_grid.hh (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.
+
+#ifndef MLN_CORE_CONCEPT_REGULAR_GRID_HH
+# define MLN_CORE_CONCEPT_REGULAR_GRID_HH
+
+/*! \file mln/core/concept/regular_grid.hh
+ * \brief Definition of the concept of mln::Regular_Grid.
+ */
+
+# include <mln/core/concept/mesh.hh>
+# include <mln/metal/bool.hh>
+
+
+namespace mln
+{
+
+ /// Base class for implementation classes of regular grids.
+ template <typename E>
+ struct Regular_Grid : public Mesh<E>
+ {
+ typedef metal::true_ regular;
+ protected:
+ Regular_Grid();
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Regular_Grid<E>::Regular_Grid()
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_REGULAR_GRID_HH
Index: mln/core/dpoint.hh
--- mln/core/dpoint.hh (revision 1122)
+++ mln/core/dpoint.hh (working copy)
@@ -42,7 +42,7 @@
{
// fwd decl
- template <unsigned n, typename C> struct point_;
+ template <typename M, typename C> struct point_;
/*! \brief Generic delta-point class.
@@ -50,22 +50,23 @@
* Parameters are \c n the dimension of the space and \c C the
* coordinate type in this space.
*/
- template <unsigned n, typename C>
- struct dpoint_ : public Dpoint< dpoint_<n,C> >,
- public internal::mutable_coord_impl_< n, C, dpoint_<n,C> >
+ template <typename M, typename C>
+ struct dpoint_ : public Dpoint< dpoint_<M,C> >,
+ public internal::mutable_coord_impl_< M::dim, C, dpoint_<M,C> >
{
/*! \var dim
* \brief Dimension of the space.
* \invariant dim > 0
*/
- enum { dim = n };
+ enum { dim = M::dim };
- /*! \brief Point associated type.
- */
- typedef point_<n,C> point;
+ /// Mesh associated type.
+ typedef M mesh;
- /*! \brief Coordinate associated type.
- */
+ /// Point associated type.
+ typedef point_<M,C> point;
+
+ /// Coordinate associated type.
typedef C coord;
/*! \brief Read-only access to the \p i-th coordinate value.
@@ -80,74 +81,71 @@
*/
C& operator[](unsigned i);
- /*! \brief Constructor without argument.
- */
+ /// Constructor without argument.
dpoint_();
- /*! \brief Constructor; coordinates are set by function \p f.
- */
+ /// Constructor; coordinates are set by function \p f.
template <typename F>
dpoint_(const Function_i2v<F>& f);
- /*! \brief Set all coordinates to the value \p c.
- */
+ /// Set all coordinates to the value \p c.
void set_all(C c);
/// Null delta-point (all coordinates are 0).
- static const dpoint_<n,C> zero;
+ static const dpoint_<M,C> zero;
const C* coords_() const { return coord_; }
/// Type of the array of coordinates.
- typedef const C (&vec_t)[n];
+ typedef const C (&vec_t)[dim];
/// Hook to coordinates.
vec_t to_vec() const { return coord_; }
protected:
- C coord_[n];
+ C coord_[dim];
};
# ifndef MLN_INCLUDE_ONLY
- template <unsigned n, typename C>
- C dpoint_<n,C>::operator[](unsigned i) const
+ template <typename M, typename C>
+ C dpoint_<M,C>::operator[](unsigned i) const
{
- assert(i < n);
+ assert(i < dim);
return coord_[i];
}
- template <unsigned n, typename C>
- C& dpoint_<n,C>::operator[](unsigned i)
+ template <typename M, typename C>
+ C& dpoint_<M,C>::operator[](unsigned i)
{
- assert(i < n);
+ assert(i < dim);
return coord_[i];
}
- template <unsigned n, typename C>
- dpoint_<n,C>::dpoint_()
+ template <typename M, typename C>
+ dpoint_<M,C>::dpoint_()
{
}
- template <unsigned n, typename C>
+ template <typename M, typename C>
template <typename F>
- dpoint_<n,C>::dpoint_(const Function_i2v<F>& f_)
+ dpoint_<M,C>::dpoint_(const Function_i2v<F>& f_)
{
const F& f = exact(f_);
- for (unsigned i = 0; i < n; ++i)
+ for (unsigned i = 0; i < dim; ++i)
coord_[i] = f(i);
}
- template <unsigned n, typename C>
- void dpoint_<n,C>::set_all(C c)
+ template <typename M, typename C>
+ void dpoint_<M,C>::set_all(C c)
{
- for (unsigned i = 0; i < n; ++i)
+ for (unsigned i = 0; i < dim; ++i)
coord_[i] = c;
}
- template <unsigned n, typename C>
- const dpoint_<n,C> dpoint_<n,C>::zero = all(0);
+ template <typename M, typename C>
+ const dpoint_<M,C> dpoint_<M,C>::zero = all(0);
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/grids.hh
--- mln/core/grids.hh (revision 0)
+++ mln/core/grids.hh (revision 0)
@@ -0,0 +1,83 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_GRIDS_HH
+# define MLN_CORE_GRIDS_HH
+
+/*! \file mln/core/grids.hh
+ *
+ * \brief This file defines some grid classes.
+ */
+
+# include <mln/core/concept/regular_grid.hh>
+# include <mln/metal/bool.hh>
+
+
+namespace mln
+{
+
+ // Grids.
+
+ namespace grid
+ {
+
+ struct tick : public Regular_Grid< tick >
+ {
+ typedef metal::true_ aligned;
+ enum { dim = 1 };
+ };
+
+ struct square : public Regular_Grid< square >
+ {
+ typedef metal::true_ aligned;
+ enum { dim = 2 };
+ };
+
+ struct cube : public Regular_Grid< cube >
+ {
+ typedef metal::true_ aligned;
+ enum { dim = 3 };
+ };
+
+ } // end of namespace mln::grid
+
+
+ // Function: dim -> regular grid.
+
+ template <unsigned dim> struct regular_grid_from_dim_;
+
+ template <> struct regular_grid_from_dim_<1> { typedef grid::tick ret; };
+ template <> struct regular_grid_from_dim_<2> { typedef grid::square ret; };
+ template <> struct regular_grid_from_dim_<3> { typedef grid::cube ret; };
+
+} // end of namespace mln
+
+
+# define mln_regular_grid_from_dim(N) typename mln::regular_grid_from_dim_< N >::ret
+
+
+#endif // ! MLN_CORE_GRIDS_HH
Index: mln/core/set_p.hh
--- mln/core/set_p.hh (revision 1122)
+++ mln/core/set_p.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Definition of a point set class based on std::set.
*/
-# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/point_set_base.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/accu/bbox.hh>
# include <mln/core/vec_p.hh>
@@ -50,19 +50,13 @@
* \todo Test if \p P being a Point_Site is ok.
*/
template <typename P>
- class set_p : public Point_Set< set_p<P> >,
+ class set_p : public internal::point_set_base_< P, set_p<P> >,
private internal::set_of_<P>
{
typedef internal::set_of_<P> super_;
public:
- /// Point associated type.
- typedef mln_point(P) point;
-
- /// Point_Site associated type.
- typedef P psite;
-
/// Forward Point_Iterator associated type.
typedef vec_p_fwd_piter_<P> fwd_piter;
@@ -91,7 +85,7 @@
void clear();
/// Give the exact bounding box.
- const box_<point>& bbox() const;
+ const box_<mln_point(P)>& bbox() const;
protected:
Index: mln/metal/is_a.hh
--- mln/metal/is_a.hh (revision 1122)
+++ mln/metal/is_a.hh (working copy)
@@ -33,6 +33,8 @@
* \brief Definition of a type that means "is_a".
*/
+# include <mln/metal/bool.hh>
+
# define mlc_is_a(T, U) mln::metal::is_a< T, U >
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-18 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Fix a bug in mirroring.
* border_mirror.hh: Fix.
---
border_mirror.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: trunk/milena/sandbox/duhamel/border_mirror.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_mirror.hh (revision 1121)
+++ trunk/milena/sandbox/duhamel/border_mirror.hh (revision 1122)
@@ -111,7 +111,7 @@
// mirror left border
s = start;
for (std::size_t i = 0; i <= nbrows; ++i)
- for (std::size_t j = 0; j <= border; ++j)
+ for (std::size_t j = 1; j <= border; ++j)
const_cast<I&>(ima)[s + (i * real_nbcols) - j] = ima[s + (i * real_nbcols) + (j - 1)];
// mirror right border
1
0
ChangeLog:
2007-09-17 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add mirroring for borders.
* border_mirror.cc: Test file for border mirroring.
* border_mirror.hh: Fix border mirroring.
---
border_mirror.cc | 61 ++++++++++++++++++++++++
border_mirror.hh | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 200 insertions(+)
Index: trunk/milena/sandbox/duhamel/border_mirror.cc
===================================================================
--- trunk/milena/sandbox/duhamel/border_mirror.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/border_mirror.cc (revision 1121)
@@ -0,0 +1,61 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/border_fill.cc
+ *
+ * \brief Tests on mln::border::fill.
+ */
+
+#include "border_mirror.hh"
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/pw/all.hh>
+#include <mln/debug/println_with_border.hh>
+
+using namespace mln;
+
+int
+main (void)
+{
+ image2d_b<value::int_u8> i1(5, 7);
+
+ // Fill with randomized value.
+ for (unsigned int i = 0; i < i1.ncells (); ++i)
+ i1[i] = i;//(i * 4452) % 10;
+ std::cout << "before mirror"
+ << std::endl
+ << std::endl;
+ debug::println_with_border(i1);
+
+ border::mirror (i1);
+ std::cout << "after mirror"
+ << std::endl
+ << std::endl;
+ debug::println_with_border(i1);
+}
+
+
Index: trunk/milena/sandbox/duhamel/border_mirror.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_mirror.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/border_mirror.hh (revision 1121)
@@ -0,0 +1,139 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_BORDER_MIRROR_HH
+# define MLN_BORDER_MIRROR_HH
+
+/*! \file mln/border/mirror.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
+# include <mln/level/memset_.hh>
+//# include <mln/core/line_piter.hh>
+#include <mln/geom/nrows.hh>
+#include <mln/geom/ncols.hh>
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image2d_b.hh>
+#include <mln/core/pixel.hh>
+
+
+namespace mln
+{
+
+ namespace border
+ {
+
+ /*! Mirror the virtual (outer) border of image \p ima with the
+ * (inner) level contents of this image.
+ *
+ * \param[in,out] ima The image whose border is to be mirrored.
+ *
+ * \pre \p ima has to be initialized.
+ *
+ * \todo Implement it + optimize with memset if possible.
+ */
+ template <typename I>
+ void mirror(const Fast_Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ void mirror(const Fast_Image<I>& ima_)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ // internal::fixme();
+ // FIX
+ std::size_t border = ima.border ();
+ std::size_t nbrows = geom::max_row(ima) - geom::min_row(ima);
+ std::size_t nbcols = geom::max_col(ima) - geom::min_col(ima);
+ std::size_t real_nbcols = (nbcols + 1) + 2 * border;
+ std::size_t start = real_nbcols * border + border;
+ std::size_t s = start;
+
+ // duplicate top left corner
+ for (std::size_t i = 0; i < border; ++i)
+ for (std::size_t j = 0; j < border; ++j)
+ const_cast<I&>(ima)[i * ((nbcols + 1) + 2 * border) + j] = ima[s];
+
+ // duplicate top left corner
+ s = start + nbcols;
+ for (std::size_t i = 0; i < border; ++i)
+ for (std::size_t j = 1; j <= border; ++j)
+ const_cast<I&>(ima)[i * ((nbcols + 1) + 2 * border) + (nbcols + border + j)] = ima[s];
+
+ // duplicate bottom left corner
+ s = start + (nbrows * real_nbcols);
+ for (std::size_t i = 1; i <= border; ++i)
+ for (std::size_t j = 1; j <= border; ++j)
+ const_cast<I&>(ima)[s - i + (j * (real_nbcols))] = ima[s];
+
+ // duplicate bottom right corner
+ s = start + (nbrows * real_nbcols) + nbcols;
+ for (std::size_t i = 1; i <= border; ++i)
+ for (std::size_t j = 1; j <= border; ++j)
+ const_cast<I&>(ima)[s + i + (j * real_nbcols)] = ima[s];
+
+ // mirror top border
+ s = start;
+ for (std::size_t i = 0; i <= nbcols; ++i)
+ for (std::size_t j = 1; j <= border; ++j)
+ const_cast<I&>(ima)[s + i - (j * real_nbcols)] = ima[s + i + ((j - 1)* real_nbcols)];
+
+ // mirror left border
+ s = start;
+ for (std::size_t i = 0; i <= nbrows; ++i)
+ for (std::size_t j = 0; j <= border; ++j)
+ const_cast<I&>(ima)[s + (i * real_nbcols) - j] = ima[s + (i * real_nbcols) + (j - 1)];
+
+ // mirror right border
+ s = start;
+ for (std::size_t i = 0; i <= nbrows; ++i)
+ for (std::size_t j = 1; j <= border; ++j)
+ const_cast<I&>(ima)[s + (i * real_nbcols + nbcols) + j] = ima[s + (i * real_nbcols + nbcols) - (j - 1)];
+
+ // mirror bottom border
+ s = start + (nbrows * real_nbcols);
+ for (std::size_t i = 0; i <= nbcols; ++i)
+ for (std::size_t j = 1; j <= border; ++j)
+ const_cast<I&>(ima)[s + i + (j * real_nbcols)] = ima[s + i - ((j - 1)* real_nbcols)];
+
+ //END FIX
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::border
+
+} // end of namespace mln
+
+
+#endif // ! MLN_BORDER_MIRROR_HH
1
0