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
12 Sep '08
Sorry, I don't know what happened with svn-wrapper... It commited
everything even though I specified only few files. I updated the
changelog entry (see revision 2247 or below) with the following description:
* milena/mln/level/fill_with_value.hh: fix a compilation warning
(unused variable).
* milena/mln/set/get.hh: new algorithm to get the ith element in a
site set.
* milena/tests/core/image/Makefile.am,
* milena/tests/core/site_set/Makefile.am: disable few tests.
* milena/tests/core/site_set/p_image2d.cc: rename as...
* milena/tests/core/site_set/p_image.cc: ...this file.
* milena/tests/core/site_set/p_priority_queue.cc,
* milena/tests/core/site_set/p_set.cc,
* milena/tests/core/site_set/pset_if.cc:
update assertions and make the test compile.
--
Guillaume Lazzara
1
0
* mln/core/faces_iter.hh: New.
* mln/core/complex.hh: Add forward declarations for
faces_fwd_iter_ and faces_bkd_iter_.
(mln::complex<D>::fwd_fiter<N>, mln::complex<D>::bkd_fiter<N>):
New inner classes.
* mln/core/face.hh
(mln::face_handle<N, D>::set_cplx)
(mln::face_handle<N, D>::set_face_id):
New mutators.
* mln/core/macros.hh (mln_fiter, mln_fiter_)
(mln_fwd_fiter, mln_fwd_fiter_, mln_bkd_fiter, mln_bkd_fiter_):
New macros.
* tests/core/complex.cc (main): Exercise iterators on n-faces.
---
milena/ChangeLog | 18 ++
milena/mln/core/complex.hh | 19 ++-
milena/mln/core/face.hh | 19 ++
milena/mln/core/faces_iter.hh | 448 +++++++++++++++++++++++++++++++++++++++++
milena/mln/core/macros.hh | 18 ++
milena/tests/core/complex.cc | 43 +++-
6 files changed, 549 insertions(+), 16 deletions(-)
create mode 100644 milena/mln/core/faces_iter.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index e766670..f164de6 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,23 @@
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+ Add iterators on the n-faces of a complex.
+
+ * mln/core/faces_iter.hh: New.
+ * mln/core/complex.hh: Add forward declarations for
+ faces_fwd_iter_ and faces_bkd_iter_.
+ (mln::complex<D>::fwd_fiter<N>, mln::complex<D>::bkd_fiter<N>):
+ New inner classes.
+ * mln/core/face.hh
+ (mln::face_handle<N, D>::set_cplx)
+ (mln::face_handle<N, D>::set_face_id):
+ New mutators.
+ * mln/core/macros.hh (mln_fiter, mln_fiter_)
+ (mln_fwd_fiter, mln_fwd_fiter_, mln_bkd_fiter, mln_bkd_fiter_):
+ New macros.
+ * tests/core/complex.cc (main): Exercise iterators on n-faces.
+
+2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+
Factor iterators on complexes.
* mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
diff --git a/milena/mln/core/complex.hh b/milena/mln/core/complex.hh
index c0c1b80..3b4571b 100644
--- a/milena/mln/core/complex.hh
+++ b/milena/mln/core/complex.hh
@@ -31,10 +31,8 @@
/// \file mln/core/complex.hh
/// \brief Structures for general complexes.
///
-/// A complexes defines a topological space which can be used as a
+/// A complex defines a topological space which can be used as a
/// support for an image (i.e., as site sets).
-///
-/// FIXME: More.
# include <cstddef>
@@ -44,8 +42,8 @@
# include <mln/metal/bool.hh>
# include <mln/core/face.hh>
-
# include <mln/core/complex_iter.hh>
+# include <mln/core/faces_iter.hh>
namespace mln
@@ -59,6 +57,8 @@ namespace mln
}
template <unsigned D> class complex_fwd_iter_;
template <unsigned D> class complex_bkd_iter_;
+ template <unsigned N, unsigned D> class faces_fwd_iter_;
+ template <unsigned N, unsigned D> class faces_bkd_iter_;
/*----------.
@@ -70,11 +70,18 @@ namespace mln
class complex : private internal::faces_set_mixin<D, D>
{
public:
- /// Forward mln::Iterator associated type.
+ /// Forward mln::Iterator type iterating on all faces.
typedef complex_fwd_iter_<D> fwd_citer;
- /// Backward mln::Iterator associated type.
+ /// Backward mln::Iterator type iterating on all faces.
typedef complex_bkd_iter_<D> bkd_citer;
+ /// Forward mln::Iterator type iterating on \p N-faces.
+ template <unsigned N>
+ struct fwd_fiter { typedef faces_fwd_iter_<N, D> ret; };
+ /// Backward mln::Iterator type iterating on \p N-faces.
+ template <unsigned N>
+ struct bkd_fiter { typedef faces_bkd_iter_<N, D> ret; };
+
/// Complex construction.
/// \{
/// \brief Add a 0-face to the complex.
diff --git a/milena/mln/core/face.hh b/milena/mln/core/face.hh
index 7de0e8d..4e8e958 100644
--- a/milena/mln/core/face.hh
+++ b/milena/mln/core/face.hh
@@ -165,6 +165,11 @@ namespace mln
// FIXME: Rename as `id'?
unsigned face_id() const;
+ /// Set the complex the face belongs to.
+ void set_cplx(complex<D>& cplx);
+ /// Set the id of the face.
+ void set_face_id(unsigned face_id);
+
/// Return the mln::face pointed by this handle.
face<N, D>& to_face() const;
/// \}
@@ -421,6 +426,20 @@ namespace mln
}
template <unsigned N, unsigned D>
+ void
+ face_handle<N, D>::set_cplx(complex<D>& cplx)
+ {
+ cplx_ = &cplx;
+ }
+
+ template <unsigned N, unsigned D>
+ void
+ face_handle<N, D>::set_face_id(unsigned face_id)
+ {
+ face_id_ = face_id;
+ }
+
+ template <unsigned N, unsigned D>
face<N, D>&
face_handle<N, D>::to_face() const
{
diff --git a/milena/mln/core/faces_iter.hh b/milena/mln/core/faces_iter.hh
new file mode 100644
index 0000000..25dd2c2
--- /dev/null
+++ b/milena/mln/core/faces_iter.hh
@@ -0,0 +1,448 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_FACES_ITER_HH
+# define MLN_CORE_FACES_ITER_HH
+
+/// \file mln/core/faces_iter.hh
+/// \brief Definition of forward and backward iterators on the n-faces
+/// of a complex.
+
+# include <limits>
+
+# include <mln/core/concept/iterator.hh>
+# include <mln/core/complex.hh>
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <unsigned D> class complex;
+
+ /*---------------------------------.
+ | internal::faces_iter_<N, D, E>. |
+ `---------------------------------*/
+
+ // FIXME: Maybe we should have a `face' parameter instead of N & D.
+ // This way, we could merge this class and
+ // internal::complex_iter_x<D, E>.
+
+ namespace internal
+ {
+ /// \brief Factoring classe for iterators on all the \p N-faces of
+ /// a mln::complex<D>.
+ ///
+ /// \arg \p N The dimension of the face associated to this iterator.
+ /// \arg \p D The dimension of the complex this iterator belongs to.
+ /// \arg \p E The type exact type of the iterator.
+ template <unsigned N, unsigned D, typename E>
+ class faces_iter_ : public Iterator<E>
+ {
+ typedef faces_iter_<N, D, E> self_;
+
+ public:
+ typedef face_handle<N, D> face;
+
+ /// Construction and assignment.
+ /// \{
+ /* FIXME: Keep this non-const? See a (big) comment about this in
+ milena/tests/complex_image.cc. */
+ faces_iter_(complex<D>& c);
+ faces_iter_(const self_& rhs);
+ self_& operator= (const self_& rhs);
+ /// \}
+
+ /// Manipulation.
+ /// \{
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+ /// Invalidate the iterator.
+ void invalidate();
+ /// \}
+
+ /// Conversion and accessors.
+ /// \{
+ /// Reference to the corresponding face handle.
+ const face& to_face () const;
+ /// Convert the iterator into an face handle.
+ operator face() const;
+ /// \}
+
+ protected:
+ /// The face handle this iterator is pointing to.
+ face face_;
+
+ private:
+ /// \brief An invalid value for both the dimension and the id of
+ /// the face.
+ ///
+ /// Use a function instead of a static constant, since `static'
+ /// variables needs to be compiled once, which requires a compiled
+ /// library to avoid duplicate symbols, which is something that
+ /// was not really planned in Milena. A function tagged `inlined'
+ /// can appear multiple times in a program, and solves this
+ /// problem. We rely on the compiler to inline this call.
+ ///
+ /// Of course, we could have used UINT_MAX, but it is not very
+ /// C++.
+ unsigned invalid_unsigned_() const;
+ };
+
+
+ /* FIXME: This hand-made delegation is painful. We should rely on
+ the general mechanism provided by Point_Site. But then again, we
+ need to refine/adjust the interface of Point_Site w.r.t. the
+ mandatory conversions to points. */
+ template <unsigned N, unsigned D, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const faces_iter_<N, D, E>& p);
+
+ } // end of mln::internal
+
+
+ /*------------------------.
+ | faces_fwd_iter_<N, D>. |
+ `------------------------*/
+
+ /// \brief Forward iterator on all the faces of a mln::complex<D>.
+ ///
+ /// \arg \p N The dimension of the face associated to this iterator.
+ /// \arg \p D The dimension of the complex this iterator belongs to.
+ template <unsigned N, unsigned D>
+ class faces_fwd_iter_
+ : public internal::faces_iter_< N, D, faces_fwd_iter_<N, D> >
+ {
+ typedef faces_fwd_iter_<N, D> self_;
+ typedef internal::faces_iter_< N, D, self_ > super_;
+
+ public:
+ using super_::is_valid;
+ using super_::invalidate;
+
+ public:
+ /// Construction and assignment.
+ /// \{
+ // FIXME: See above (internal::faces_iter_'s default ctor).
+ faces_fwd_iter_(complex<D>& c);
+ faces_fwd_iter_(const self_& rhs);
+ self_& operator= (const self_& rhs);
+ /// \}
+
+ /// Manipulation.
+ /// \{
+ /// Test if the iterator is valid.
+ void start();
+ /// Go to the next point.
+ void next_();
+ /// \}
+
+ private:
+ using super_::face_;
+ };
+
+
+ /*------------------------.
+ | faces_bkd_iter_<N, D>. |
+ `------------------------*/
+
+ /// \brief Backward iterator on all the faces of a mln::complex<D>.
+ ///
+ /// \arg \p N The dimension of the face associated to this iterator.
+ /// \arg \p D The dimension of the complex this iterator belongs to.
+ template <unsigned N, unsigned D>
+ class faces_bkd_iter_
+ : public internal::faces_iter_< N, D, faces_bkd_iter_<N, D> >
+ {
+ typedef faces_bkd_iter_<N, D> self_;
+ typedef internal::faces_iter_< N, D, self_ > super_;
+
+ public:
+ using super_::is_valid;
+ using super_::invalidate;
+
+ public:
+ /// Construction and assignment.
+ /// \{
+ // FIXME: See above (internal::faces_iter_'s default ctor).
+ faces_bkd_iter_(complex<D>& c);
+ faces_bkd_iter_(const self_& rhs);
+ self_& operator= (const self_& rhs);
+ /// \}
+
+ /// Manipulation.
+ /// \{
+ /// Start an iteration.
+ void start();
+ /// Go to the next point.
+ void next_();
+ /// \}
+
+ private:
+ using super_::face_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*---------------------------------.
+ | internal::faces_iter_<N, D, E>. |
+ `---------------------------------*/
+
+ namespace internal
+ {
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ faces_iter_<N, D, E>::faces_iter_(complex<D>& c)
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+
+ face_.set_cplx(c);
+ // Invalidate face_.
+ invalidate();
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ faces_iter_<N, D, E>::faces_iter_(const faces_iter_<N, D, E>& rhs)
+ : face_(rhs.face_)
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ faces_iter_<N, D, E>&
+ faces_iter_<N, D, E>::operator=(const faces_iter_<N, D, E>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ face_ = rhs.face_;
+ return *this;
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ bool
+ faces_iter_<N, D, E>::is_valid() const
+ {
+ return face_.is_valid();
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ void
+ faces_iter_<N, D, E>::invalidate()
+ {
+ face_.set_face_id(invalid_unsigned_());
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ const face_handle<N, D>&
+ faces_iter_<N, D, E>::to_face() const
+ {
+ return face_;
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ faces_iter_<N, D, E>::operator face_handle<N, D>() const
+ {
+ mln_precondition(is_valid());
+ return face_;
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ unsigned
+ faces_iter_<N, D, E>::invalid_unsigned_() const
+ {
+ return std::numeric_limits<unsigned>::max();
+ }
+
+ template <unsigned N, unsigned D, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const faces_iter_<N, D, E>& p)
+ {
+ /* FIXME: We should use p.to_face() here, but as it lacks the
+ precondition the conversion operator has, so we use the latter.
+
+ We should
+ - rename `to_face' as `to_face_';
+ - write a new `to_face' routine checking the validity of the
+ iterator;
+ - have the conversion operator to face use this new `to_face'
+ routine;
+ - adjust former clients of `to_face'
+
+ This is a general remark that applies to all iterators of
+ Milena. */
+ typename faces_iter_<N, D, E>::face f = p;
+ return ostr << "(dim = " << N << ", id = " << f.face_id() << ')';
+ }
+
+ } // end of mln::internal
+
+
+ /*------------------------.
+ | faces_fwd_iter_<N, D>. |
+ `------------------------*/
+
+ template <unsigned N, unsigned D>
+ inline
+ faces_fwd_iter_<N, D>::faces_fwd_iter_(complex<D>& c)
+ : super_(c)
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ faces_fwd_iter_<N, D>::faces_fwd_iter_(const faces_fwd_iter_<N, D>& rhs)
+ : super_(rhs)
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ faces_fwd_iter_<N, D>&
+ faces_fwd_iter_<N, D>::operator=(const faces_fwd_iter_<N, D>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ super_::operator=(rhs);
+ return *this;
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ void
+ faces_fwd_iter_<N, D>::start()
+ {
+ face_.set_face_id(0u);
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ void
+ faces_fwd_iter_<N, D>::next_()
+ {
+ if (is_valid())
+ {
+ unsigned face_id = face_.face_id();
+ if (face_id + 1 < face_.cplx().template nfaces<N>())
+ /* FIXME: Provide accessor face_handle::n() returning
+ a mutable reference? This way, we could just write
+
+ ++face_.face_id();
+
+ instead of the following. */
+ face_.set_face_id(face_id + 1);
+ else
+ invalidate();
+ }
+ }
+
+
+ /*------------------------.
+ | faces_bkd_iter_<N, D>. |
+ `------------------------*/
+
+ // FIXME: Resume here.
+
+ template <unsigned N, unsigned D>
+ inline
+ faces_bkd_iter_<N, D>::faces_bkd_iter_(complex<D>& c)
+ : super_(c)
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ faces_bkd_iter_<N, D>::faces_bkd_iter_(const faces_bkd_iter_<N, D>& rhs)
+ : super_(rhs)
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ faces_bkd_iter_<N, D>&
+ faces_bkd_iter_<N, D>::operator=(const faces_bkd_iter_<N, D>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ super_::operator=(rhs);
+ return *this;
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ void
+ faces_bkd_iter_<N, D>::start()
+ {
+ face_.set_face_id(face_.cplx().template nfaces<N>() - 1);
+ }
+
+ template <unsigned N, unsigned D>
+ inline
+ void
+ faces_bkd_iter_<N, D>::next_()
+ {
+ if (is_valid())
+ {
+ unsigned face_id = face_.face_id();
+ if (face_id > 0)
+ /* FIXME: Provide accessor face_handle::n() returning
+ a mutable reference? This way, we could just write
+
+ ++face_.face_id();
+
+ instead of the following. */
+ face_.set_face_id(face_id - 1);
+ else
+ invalidate();
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // ! MLN_CORE_FACES_ITER_HH
diff --git a/milena/mln/core/macros.hh b/milena/mln/core/macros.hh
index a7376ca..d098814 100644
--- a/milena/mln/core/macros.hh
+++ b/milena/mln/core/macros.hh
@@ -51,6 +51,12 @@
# define mln_bkd_citer_(T) T::bkd_citer
/// \}
+/// Shortcuts to access the (N-faces) bkd_fiter type associated to T.
+/// \{
+# define mln_bkd_fiter(N, T) typename T::template bkd_fiter< N >::ret
+# define mln_bkd_fiter_(N, T) T:: bkd_fiter< N >::ret
+/// \}
+
/// Shortcuts to access the bkd_niter type associated to T.
/// \{
# define mln_bkd_niter(T) typename T::bkd_niter
@@ -123,12 +129,24 @@
// f
+/// Shortcuts to access the (N-faces) fiter type associated to T.
+/// \{
+# define mln_fiter(N, T) typename T::template fwd_fiter< N >::ret
+# define mln_fiter_(N, T) T:: fwd_fiter< N >::ret
+/// \}
+
/// Shortcuts to access the fwd_citer type associated to T.
/// \{
# define mln_fwd_citer(T) typename T::fwd_citer
# define mln_fwd_citer_(T) T::fwd_citer
/// \}
+/// Shortcuts to access the (N-faces) fwd_fiter type associated to T.
+/// \{
+# define mln_fwd_fiter(N, T) typename T::template fwd_fiter< N >::ret
+# define mln_fwd_fiter_(N, T) T:: fwd_fiter< N >::ret
+/// \}
+
/// Shortcuts to access the fwd_niter type associated to T.
/// \{
# define mln_fwd_niter(T) typename T::fwd_niter
diff --git a/milena/tests/core/complex.cc b/milena/tests/core/complex.cc
index 91bae55..49ec3d4 100644
--- a/milena/tests/core/complex.cc
+++ b/milena/tests/core/complex.cc
@@ -32,11 +32,15 @@
#include <mln/core/complex.hh>
+using namespace mln;
+
+
+// Forward declaration.
+template <unsigned N, unsigned D> void test_faces_iter(complex<D>& c);
+
int main()
{
- using namespace mln;
-
/* A 2-d (simplicial) complex and its adjacency graph.
v0 e3 v3
@@ -94,7 +98,8 @@ int main()
<< "Using ``dynamic'' manipulators." << std::endl
<< " number of 0-faces: c.nfaces(0) = " << c.nfaces(0) << std::endl
<< " number of 1-faces: c.nfaces(1) = " << c.nfaces(1) << std::endl
- << " number of 2-faces: c.nfaces(2) = " << c.nfaces(2) << std::endl;
+ << " number of 2-faces: c.nfaces(2) = " << c.nfaces(2) << std::endl
+ << std::endl;
/*-------------------.
| Handles and data. |
@@ -110,24 +115,31 @@ int main()
mln_assertion(&face1 == &face2);
-
/*------------.
| Iteration. |
`------------*/
// FIXME: Possibly split this test (create a test for iterators).
+ // --------------- //
+ // Iterator on C. //
+ // --------------- //
+
// Iterators on a complex (not complex_image), or more precisely on
// (all) the faces of complex C.
mln_fwd_citer_(complex<D>) fwd_f(c);
- for_all(fwd_f)
- std::cout << fwd_f << std::endl;
-
+ mln_bkd_citer_(complex<D>) bkd_f(c);
+ for_all_2(fwd_f, bkd_f)
+ std::cout << fwd_f << ' ' << bkd_f << std::endl;
std::cout << std::endl;
- mln_bkd_citer_(complex<D>) bkd_f(c);
- for_all(bkd_f)
- std::cout << bkd_f << std::endl;
+ // -------------------------- //
+ // Iterator on n-faces of C. //
+ // -------------------------- //
+
+ test_faces_iter<0>(c);
+ test_faces_iter<1>(c);
+ test_faces_iter<2>(c);
/* FIXME: Exercice more iterators (see
milena/tests/core/complex_image.cc) and ticket #162
@@ -135,3 +147,14 @@ int main()
// ...
}
+
+template <unsigned N, unsigned D>
+void
+test_faces_iter(complex<D>& c)
+{
+ mln_fwd_fiter(N, complex<D>) fwd_nf(c);
+ mln_bkd_fiter(N, complex<D>) bkd_nf(c);
+ for_all_2(fwd_nf, bkd_nf)
+ std::cout << fwd_nf << ' ' << bkd_nf << std::endl;
+ std::cout << std::endl;
+}
--
1.6.0.1
1
0
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
ChangeLog:
2008-09-12 Guillaume Lazzara <z(a)lrde.epita.fr>
Fix Changelog and comments.
* ChangeLog: Add missing entries.
* milena/tests/core/site_set/p_image.cc: Fix comments.
---
p_image.cc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: branches/cleanup-2008/milena/tests/core/site_set/p_image.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/site_set/p_image.cc (revision 2246)
+++ branches/cleanup-2008/milena/tests/core/site_set/p_image.cc (revision 2247)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2008 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,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/core/site_set/p_image2d.cc
+/*! \file tests/core/site_set/p_image.cc
*
- * \brief Tests on mln::p_image2d.
+ * \brief Tests on mln::p_image.
*/
#include <mln/core/image/image2d.hh>
1
0
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
ChangeLog:
2008-09-12 Guillaume Lazzara <z(a)lrde.epita.fr>
Remove deprecated tests.
* milena/tests/core/site_set/p_priority_queue_fast.cc,
* milena/tests/core/site_set/p_priority_queue_fast_with_array.cc,
* milena/tests/core/site_set/p_runs.cc,
* milena/tests/core/site_set/pset_array.cc:
Remove these tests according to core/site_set/status.txt.
---
mln/level/fill_with_value.hh | 2
mln/set/get.hh | 84 ++++++++++++++++++++++++++++++++
tests/core/image/Makefile.am | 28 +++++-----
tests/core/site_set/Makefile.am | 18 +-----
tests/core/site_set/p_image.cc | 68 +++++++++++++++++++++++++
tests/core/site_set/p_priority_queue.cc | 7 +-
tests/core/site_set/p_set.cc | 20 ++-----
tests/core/site_set/pset_if.cc | 6 +-
8 files changed, 187 insertions(+), 46 deletions(-)
Index: branches/cleanup-2008/milena/tests/core/site_set/p_priority_queue_fast.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/tests/core/site_set/p_runs.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/tests/core/site_set/p_image2d.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/tests/core/site_set/pset_array.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/tests/core/site_set/p_priority_queue_fast_with_array.cc (deleted)
===================================================================
Index: branches/cleanup-2008/milena/tests/core/site_set/p_image.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/site_set/p_image.cc (revision 0)
+++ branches/cleanup-2008/milena/tests/core/site_set/p_image.cc (revision 2246)
@@ -0,0 +1,68 @@
+// Copyright (C) 2007, 2008 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/core/site_set/p_image2d.cc
+ *
+ * \brief Tests on mln::p_image2d.
+ */
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/site_set/p_image.hh>
+
+int main()
+{
+ using namespace mln;
+
+ image2d<bool> ima(box2d(20,20));
+ p_image<image2d<bool> > ps(ima);
+ ps.insert(make::point2d(6, 9));
+ ps.insert(make::point2d(4, 2));
+ ps.insert(make::point2d(4, 2));
+ ps.insert(make::point2d(5, 1));
+ mln_assertion(ps.nsites() == 3);
+
+ ps.remove(make::point2d(5, 1));
+ ps.remove(make::point2d(5, 1));
+
+ ps.remove(make::point2d(6, 9));
+ ps.remove(make::point2d(4, 2));
+
+ mln_assertion(ps.nsites() == 0);
+ mln_assertion(ps.is_empty());
+
+ mln_fwd_piter_(box2d) p(inplace(make::box2d(13,13,19,15)));
+ for_all(p)
+ {
+ ps.insert(p);
+ }
+ ps.clear();
+ for_all(p)
+ {
+ mln_assertion(!ps.has(p));
+ }
+
+}
Index: branches/cleanup-2008/milena/tests/core/site_set/p_priority_queue.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/site_set/p_priority_queue.cc (revision 2245)
+++ branches/cleanup-2008/milena/tests/core/site_set/p_priority_queue.cc (revision 2246)
@@ -36,6 +36,7 @@
#include <mln/geom/bbox.hh>
#include <mln/make/box2d.hh>
#include <mln/set/has.hh>
+#include <mln/set/get.hh>
int main()
@@ -95,9 +96,9 @@
q.push(5, p2);
q.push(3, p1);
-// mln_assertion(q[2] == p3);
-// mln_assertion(q[1] == p1);
-// mln_assertion(q[0] == p2);
+ mln_assertion(set::get(q, 2) == p3);
+ mln_assertion(set::get(q, 0) == p2);
+ mln_assertion(set::get(q, 1) == p1);
q.clear();
mln_assertion(q.is_empty());
}
Index: branches/cleanup-2008/milena/tests/core/site_set/Makefile.am
===================================================================
--- branches/cleanup-2008/milena/tests/core/site_set/Makefile.am (revision 2245)
+++ branches/cleanup-2008/milena/tests/core/site_set/Makefile.am (revision 2246)
@@ -4,29 +4,21 @@
check_PROGRAMS = \
p_array \
- p_bgraph \
- p_image2d \
+## p_bgraph \
+ p_image \
p_priority_queue \
- p_priority_queue_fast \
- p_priority_queue_fast_with_array \
p_queue \
p_queue_fast \
- p_runs \
p_set \
- pset_array \
pset_if
p_array_SOURCES = p_array.cc
p_bgraph_SOURCES = p_bgraph.cc
-p_image2d_SOURCES = p_image2d.cc
+p_image_SOURCES = p_image.cc
p_priority_queue_SOURCES = p_priority_queue.cc
-p_priority_queue_fast_SOURCES = p_priority_queue_fast.cc
-p_priority_queue_fast_with_array_SOURCES = p_priority_queue_fast.cc
-p_queue_SOURCES = p_priority_queue_fast.cc
-p_queue_fast_SOURCES = p_priority_queue_fast.cc
-p_runs_SOURCES = p_runs.cc
+p_queue_SOURCES = p_queue.cc
+p_queue_fast_SOURCES = p_queue_fast.cc
p_set_SOURCES = p_set.cc
-pset_array_SOURCES = pset_array.cc
pset_if_SOURCES = pset_if.cc
TESTS = $(check_PROGRAMS)
Index: branches/cleanup-2008/milena/tests/core/site_set/pset_if.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/site_set/pset_if.cc (revision 2245)
+++ branches/cleanup-2008/milena/tests/core/site_set/pset_if.cc (revision 2246)
@@ -36,6 +36,7 @@
#include <mln/fun/p2b/chess.hh>
#include <mln/convert/to_image.hh>
#include <mln/convert/to_p_set.hh>
+#include <mln/estim/nsites.hh>
int main()
@@ -43,11 +44,10 @@
using namespace mln;
box2d box_8x8 = make::box2d(8, 8);
- mln_assertion((box_8x8 | fun::p2b::chess).nsites() == 32);
+ mln_assertion(estim::nsites((box_8x8 | fun::p2b::chess)) == 32);
{
p_set<point2d> s = convert::to_p_set(box_8x8 | fun::p2b::chess);
- std::cout << (box_8x8 | fun::p2b::chess) << std::endl;
- std::cout << s << std::endl;
+ mln_precondition(s == (box_8x8 | fun::p2b::chess));
}
}
Index: branches/cleanup-2008/milena/tests/core/site_set/p_set.cc
===================================================================
--- branches/cleanup-2008/milena/tests/core/site_set/p_set.cc (revision 2245)
+++ branches/cleanup-2008/milena/tests/core/site_set/p_set.cc (revision 2246)
@@ -34,6 +34,8 @@
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_set.hh>
+#include <mln/make/box2d.hh>
+#include <mln/geom/bbox.hh>
@@ -42,23 +44,15 @@
using namespace mln;
p_set<point2d> ps;
- ps
- .insert(make::point2d(6, 9))
- .insert(make::point2d(4, 2))
- .insert(make::point2d(4, 2))
- .insert(make::point2d(5, 1));
+ ps.insert(point2d(6, 9));
+ ps.insert(point2d(4, 2));
+ ps.insert(point2d(5, 1));
mln_assertion(ps.nsites() == 3);
- std::cout << ps.bbox() << std::endl;
- std::copy(ps.vect().begin(), ps.vect().end(),
- std::ostream_iterator<point2d>(std::cout, " "));
- std::cout << std::endl;
+ mln_assertion(geom::bbox(ps) == make::box2d(4,1, 6, 9));
ps.remove(make::point2d(4, 2));
mln_assertion(ps.nsites() == 2);
- std::cout << ps.bbox() << std::endl;
- std::copy(ps.vect().begin(), ps.vect().end(),
- std::ostream_iterator<point2d>(std::cout, " "));
- std::cout << std::endl;
+ mln_assertion(geom::bbox(ps) == make::box2d(5,1, 6, 9));
}
Index: branches/cleanup-2008/milena/tests/core/image/Makefile.am
===================================================================
--- branches/cleanup-2008/milena/tests/core/image/Makefile.am (revision 2245)
+++ branches/cleanup-2008/milena/tests/core/image/Makefile.am (revision 2246)
@@ -3,23 +3,25 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
- bgraph_image \
+## bgraph_image \
cast_image \
- complex_image \
+## complex_image \
decorated_image \
flat_image \
- graph_image \
- graph_image_wst \
- hexa \
+## hexa \
+## graph_image \
+## graph_image_wst \
image1d \
image2d \
- image2d_h \
+## image2d_h \
image3d \
image_if \
+
image_if_interval \
image_if_value \
- interpolated \
- line_graph_image \
+
+## interpolated \
+## line_graph_image \
mono_obased_rle_image \
mono_rle_image \
obased_rle_image \
@@ -33,14 +35,14 @@
translate_image \
value_enc_image
-bgraph_image_SOURCES = bgraph_image.cc
+##bgraph_image_SOURCES = bgraph_image.cc
cast_image_SOURCES = cast_image.cc
-complex_image_SOURCES = complex_image.cc
+##complex_image_SOURCES = complex_image.cc
decorated_image_SOURCES = decorated_image.cc
-graph_image_SOURCES = graph_image.cc
-graph_image_wst_SOURCES = graph_image_wst.cc
+##graph_image_SOURCES = graph_image.cc
+##graph_image_wst_SOURCES = graph_image_wst.cc
flat_image_SOURCES = flat_image.cc
-hexa_SOURCES = hexa.cc
+##hexa_SOURCES = hexa.cc
image1d_SOURCES = image1d.cc
image2d_SOURCES = image2d.cc
image2d_h_SOURCES = image2d_h.cc
Index: branches/cleanup-2008/milena/mln/level/fill_with_value.hh
===================================================================
--- branches/cleanup-2008/milena/mln/level/fill_with_value.hh (revision 2245)
+++ branches/cleanup-2008/milena/mln/level/fill_with_value.hh (revision 2246)
@@ -81,7 +81,7 @@
template <typename I, typename V>
inline
- void fill_with_value_tests(Image<I>& ima, const V& val)
+ void fill_with_value_tests(Image<I>& ima, const V&)
{
mlc_is(mln_trait_image_value_io(I),
mln::trait::image::value_io::read_write)::check();
Index: branches/cleanup-2008/milena/mln/set/get.hh
===================================================================
--- branches/cleanup-2008/milena/mln/set/get.hh (revision 0)
+++ branches/cleanup-2008/milena/mln/set/get.hh (revision 2246)
@@ -0,0 +1,84 @@
+// Copyright (C) 2008 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_SET_GET_HH
+# define MLN_SET_GET_HH
+
+/*! \file mln/set/has.hh
+ *
+ * \brief Algorithm that returns the i th element in a site set.
+ *
+ * \todo Layout and specialize.
+ */
+
+# include <mln/core/concept/site_set.hh>
+
+
+
+namespace mln
+{
+
+ namespace set
+ {
+
+ /// FIXME
+ template <typename S>
+ mln_site(S)
+ get(const Site_Set<S>& s, size_t index);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ mln_site(S)
+ get(const Site_Set<S>& s_, size_t index)
+ {
+ trace::entering("set::get");
+ const S& s = exact(s_);
+
+ mln_precondition(s.is_valid());
+ mln_precondition(s.nsites() > index);
+
+ mln_piter(S) p(s);
+ for_all(p)
+ if (index == 0)
+ break;
+ else
+ --index;
+
+ trace::exiting("set::get");
+ return p;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::set
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SET_GET_HH
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add an 'estim nsites' routine for Z.
* doc/tutorial/examples/image2d.cc: Augment.
* mln/estim/nsites.hh: New.
doc/tutorial/examples/image2d.cc | 6 -
mln/estim/nsites.hh | 178 +++++++++++++++++++++++++++++++++++++++
2 files changed, 182 insertions(+), 2 deletions(-)
Index: doc/tutorial/examples/image2d.cc
--- doc/tutorial/examples/image2d.cc (revision 2244)
+++ doc/tutorial/examples/image2d.cc (working copy)
@@ -6,6 +6,7 @@
# include <mln/debug/println.hh>
# include <mln/core/alias/neighb2d.hh>
+# include <mln/estim/nsites.hh>
template <typename I, typename W, typename P>
@@ -34,16 +35,17 @@
}
-
int main()
{
using namespace mln;
typedef image2d<unsigned> I;
I ima(2, 3, 0); // no border
+
debug::iota(ima);
debug::println(ima);
- mln_invariant(ima.nsites() == 6);
+ mln_assertion(ima.nsites() == 6);
+ mln_assertion(estim::nsites(ima) == ima.nsites());
window2d win;
win
Index: mln/estim/nsites.hh
--- mln/estim/nsites.hh (revision 0)
+++ mln/estim/nsites.hh (revision 0)
@@ -0,0 +1,178 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ESTIM_NSITES_HH
+# define MLN_ESTIM_NSITES_HH
+
+/*! \file mln/estim/nsites.hh
+ *
+ * \brief Compute the number of sites of an image or a site set.
+ */
+
+# include <mln/core/concept/site_set.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+ /// Compute the number of sites of the site set \p input.
+ template <typename S>
+ unsigned nsites(const Site_Set<S>& s);
+
+ /// Compute the number of sites of the image \p input.
+ template <typename I>
+ unsigned nsites(const Image<I>& input);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ namespace generic
+ {
+
+ template <typename S>
+ unsigned nsites(const Site_Set<S>& s_)
+ {
+ trace::entering("estim::impl::generic::nsites");
+ const S& s = exact(s_);
+ mln_precondition(s.is_valid());
+
+ unsigned n = 0;
+ mln_piter(S) p(s);
+ for_all(p)
+ ++n;
+
+ trace::exiting("estim::impl::generic::nsites");
+ return n;
+ }
+
+ } // end of namespace mln::estim::impl::generic
+
+
+ // A single specialization.
+
+ template <typename S>
+ inline
+ unsigned nsites_method(const Site_Set<S>& s)
+ {
+ trace::entering("estim::impl::nsites_method");
+ unsigned n = exact(s).nsites();
+ trace::exiting("estim::impl::nsites_method");
+ return n;
+ }
+
+ } // end of namespace mln::estim::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename S>
+ inline
+ unsigned nsites_dispatch(mln::trait::site_set::nsites::any,
+ const Site_Set<S>& s)
+ {
+ return impl::generic::nsites(s);
+ }
+
+ template <typename S>
+ inline
+ unsigned nsites_dispatch(mln::trait::site_set::nsites::known,
+ const Site_Set<S>& s)
+ {
+ return impl::nsites_method(s);
+ }
+
+ // Dispatch facade.
+
+ template <typename S>
+ inline
+ unsigned nsites_dispatch(const Site_Set<S>& s)
+ {
+ return nsites_dispatch(mln_trait_site_set_nsites(S)(),
+ s);
+ }
+
+ } // end of namespace mln::estim::internal
+
+
+
+ // Facades.
+
+ template <typename S>
+ inline
+ unsigned nsites(const Site_Set<S>& s)
+ {
+ trace::entering("estim::nsites");
+ mln_precondition(exact(s).is_valid());
+
+ unsigned n = internal::nsites_dispatch(s);
+
+ trace::exiting("estim::nsites");
+ return n;
+ }
+
+ template <typename I>
+ inline
+ unsigned nsites(const Image<I>& input_)
+ {
+ trace::entering("estim::nsites");
+ const I& input = exact(input_);
+
+ mln_precondition(input.has_data());
+ mln_precondition(input.domain().is_valid());
+
+ // Relies on the nsites routines on a site set.
+ unsigned n = internal::nsites_dispatch(input.domain());
+
+ trace::exiting("estim::nsites");
+ return n;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_NSITES_HH
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Get rid of dpoints_piter.
* mln/core/dpoints_piter.hh: Remove; obsolete thanks to
the more general file dpsites_piter.hh.
* mln/core/w_window.hh,
* mln/core/clock_neighb.hh,
* sandbox/nivault/dyn_line.hh,
* sandbox/garrigues/fllt/fllt_simple.cc: Update.
mln/core/clock_neighb.hh | 10 +++++-----
mln/core/w_window.hh | 6 +++---
sandbox/garrigues/fllt/fllt_simple.cc | 4 ++--
sandbox/nivault/dyn_line.hh | 6 +++---
4 files changed, 13 insertions(+), 13 deletions(-)
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 2243)
+++ mln/core/w_window.hh (working copy)
@@ -37,7 +37,7 @@
# include <mln/core/window.hh>
# include <mln/core/concept/weighted_window.hh>
-# include <mln/core/dpoints_piter.hh>
+# include <mln/core/dpsites_piter.hh>
namespace mln
{
@@ -70,10 +70,10 @@
/// Site_Iterator type to browse (forward) the points of a generic w_window.
- typedef with_w_< dpoints_fwd_piter<D>, W > fwd_qiter;
+ typedef with_w_< dpsites_fwd_piter<D>, W > fwd_qiter;
/// Site_Iterator type to browse (backward) the points of a generic w_window.
- typedef with_w_< dpoints_bkd_piter<D>, W > bkd_qiter;
+ typedef with_w_< dpsites_bkd_piter<D>, W > bkd_qiter;
/// Constructor without argument.
Index: mln/core/clock_neighb.hh
--- mln/core/clock_neighb.hh (revision 2243)
+++ mln/core/clock_neighb.hh (working copy)
@@ -42,8 +42,8 @@
{
// fwd decls
- template <typename D> class dpoints_fwd_piter;
- template <typename D> class dpoints_bkd_piter;
+ template <typename D> class dpsites_fwd_piter;
+ template <typename D> class dpsites_bkd_piter;
/*! \brief Generic neighborhood class.
@@ -63,14 +63,14 @@
/*! \brief Site_Iterator type to browse the points of a generic
* neighborhood w.r.t. the ordering of delta-points.
*/
- typedef dpoints_fwd_piter<D> fwd_niter;
+ typedef dpsites_fwd_piter<D> fwd_niter;
/*! \brief Site_Iterator type to browse the points of a generic
* neighborhood w.r.t. the reverse ordering of delta-points.
*
* !!! Be careful the start delta point become the last now.
*/
- typedef dpoints_bkd_piter<D> bkd_niter;
+ typedef dpsites_bkd_piter<D> bkd_niter;
/*! \brief Same as fwd_niter.
*/
@@ -126,7 +126,7 @@
} // end of namespace mln
-# include <mln/core/dpoints_piter.hh>
+# include <mln/core/dpsites_piter.hh>
#endif // ! MLN_CORE_CLOCK_NEIGHB_HH
Index: sandbox/nivault/dyn_line.hh
--- sandbox/nivault/dyn_line.hh (revision 2243)
+++ sandbox/nivault/dyn_line.hh (working copy)
@@ -36,7 +36,7 @@
# include <mln/core/concept/window.hh>
# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint.hh>
-# include <mln/core/dpoints_piter.hh>
+# include <mln/core/dpsites_piter.hh>
namespace mln
@@ -56,10 +56,10 @@
typedef dpoint_<M, int> dpoint;
/// Site_Iterator type to browse a dyn_line forward
- typedef dpoints_fwd_piter<dpoint> fwd_qiter;
+ typedef dpsites_fwd_piter<dpoint> fwd_qiter;
/// Site_Iterator type to browse a dyn_line backward
- typedef dpoints_bkd_piter<dpoint> bkd_qiter;
+ typedef dpsites_bkd_piter<dpoint> bkd_qiter;
/// Same as fwd_qiter
typedef fwd_qiter qiter;
Index: sandbox/garrigues/fllt/fllt_simple.cc
--- sandbox/garrigues/fllt/fllt_simple.cc (revision 2243)
+++ sandbox/garrigues/fllt/fllt_simple.cc (working copy)
@@ -276,9 +276,9 @@
const c6_interpixel& ip_ref_;
};
- struct c6_niter : public dpoints_fwd_piter<dpoint2d>
+ struct c6_niter : public dpsites_fwd_piter<dpoint2d>
{
- typedef dpoints_fwd_piter<dpoint2d> super;
+ typedef dpsites_fwd_piter<dpoint2d> super;
c6_niter(const point2d& p)
: super(c6_neighb::get(p), p)
1
0
12 Sep '08
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Minor cleanup in set diff and geom shift.
* mln/core/dpoints_pixter.hh: Remove dead code.
* mln/geom/shift.hh: New static check.
* mln/set/diff.hh: New static checks.
(diff): De-activate the erroneous version with Site_Set.
core/dpoints_pixter.hh | 2 --
geom/shift.hh | 1 +
set/diff.hh | 30 +++++++++++++++++-------------
3 files changed, 18 insertions(+), 15 deletions(-)
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 2242)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -226,7 +226,6 @@
{
mln_precondition(image.has_data());
internal::get_adr(p_ref_, p_ref);
-// p_ref_ = & exact(p_ref).to_site();
value_ref_ = 0;
init_(dps);
}
@@ -338,7 +337,6 @@
{
mln_precondition(image.has_data());
internal::get_adr(p_ref_, p_ref);
-// p_ref_ = & exact(p_ref).to_site();
value_ref_ = 0;
init_(dps);
}
Index: mln/geom/shift.hh
--- mln/geom/shift.hh (revision 2242)
+++ mln/geom/shift.hh (working copy)
@@ -56,6 +56,7 @@
window<mln_dpsite(W)>
shift(const Window<W>& win_, const mln_dpsite(W)& dp)
{
+ mlc_is_a(mln_site(W), Gpoint)::check();
const W& win = exact(win_);
window<mln_dpsite(W)> tmp;
Index: mln/set/diff.hh
--- mln/set/diff.hh (revision 2242)
+++ mln/set/diff.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -74,7 +74,9 @@
diff(const Window<Wl>& lhs_, const Window<Wr>& rhs_)
{
trace::entering("set::diff");
- mlc_equal(mln_dpsite(Wl), mln_dpsite(Wr))::check();
+ mlc_is_a(mln_site(Wl), Gpoint)::check();
+ mlc_is_a(mln_site(Wr), Gpoint)::check();
+ mlc_converts_to(mln_dpsite(Wl), mln_dpsite(Wr))::check();
const Wl& lhs = exact(lhs_);
const Wr& rhs = exact(rhs_);
@@ -94,21 +96,23 @@
template <typename Wl, typename Wr>
inline
- p_set<mln_point(Wl)>
+ p_set<mln_site(Wl)>
diff(const Site_Set<Wl>& lhs, const Site_Set<Wr>& rhs)
{
trace::entering("set::diff");
- mln::metal::equal<mln_point(Wl), mln_point(Wr)>::check();
- typedef mln_point(Wl) P;
- std::set<P>
- sl = convert::to_std_set(lhs),
- sr = convert::to_std_set(rhs),
- s;
- std::set_difference(sl.begin(), sl.end(),
- sr.begin(), sr.end(),
- std::inserter(s, s.begin()));
+ p_set<mln_site(Wl)> s;
+ abort();
+// mln::metal::equal<mln_point(Wl), mln_point(Wr)>::check();
+// typedef mln_point(Wl) P;
+// std::set<P>
+// sl = convert::to_std_set(lhs),
+// sr = convert::to_std_set(rhs),
+// s;
+// std::set_difference(sl.begin(), sl.end(),
+// sr.begin(), sr.end(),
+// std::inserter(s, s.begin()));
trace::exiting("set::diff");
- return convert::to_p_set(s);
+ return s;
}
# endif // ! MLN_INCLUDE_ONLY
1
0
* mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
New class.
Use it to factor...
(mln::complex_fwd_iter_<D>, mln::complex_bkd_iter_<D>):
...these.
(operator<<(std::ostream&, const complex_iter_<D, E>&)):
New.
(operator<<(std::ostream&, const complex_fwd_iter_<D>&))
(operator<<(std::ostream&, const complex_bkd_iter_<D>&)):
Remove.
* tests/core/complex.cc: Use clearer names for iterators.
---
milena/ChangeLog | 16 ++
milena/mln/core/complex_iter.hh | 410 ++++++++++++++++++++-------------------
milena/tests/core/complex.cc | 17 +-
3 files changed, 238 insertions(+), 205 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index cd60428..e766670 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,19 @@
+2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Factor iterators on complexes.
+
+ * mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
+ New class.
+ Use it to factor...
+ (mln::complex_fwd_iter_<D>, mln::complex_bkd_iter_<D>):
+ ...these.
+ (operator<<(std::ostream&, const complex_iter_<D, E>&)):
+ New.
+ (operator<<(std::ostream&, const complex_fwd_iter_<D>&))
+ (operator<<(std::ostream&, const complex_bkd_iter_<D>&)):
+ Remove.
+ * tests/core/complex.cc: Use clearer names for iterators.
+
2008-09-11 Roland Levillain <roland(a)lrde.epita.fr>
Factor iterators on p_complexes with iterator on complexes.
diff --git a/milena/mln/core/complex_iter.hh b/milena/mln/core/complex_iter.hh
index 7588a32..4aa9b99 100644
--- a/milena/mln/core/complex_iter.hh
+++ b/milena/mln/core/complex_iter.hh
@@ -31,40 +31,118 @@
/// \file mln/core/complex_iter.hh
/// \brief Definition of forward and backward iterators on complexes.
-
# include <limits>
# include <mln/core/concept/iterator.hh>
# include <mln/core/complex.hh>
-
-// Factor complex_fwd_iter_<D> and complex_bkd_iter_<D>?
-
namespace mln
{
// Fwd decls.
template <unsigned D> class complex;
+ /*--------------------------------.
+ | internal::complex_iter_<D, E>. |
+ `--------------------------------*/
+
+ namespace internal
+ {
+ /// \brief Factoring classe for iterators on all the faces of
+ /// a mln::complex<D>.
+ ///
+ /// \arg \p D The dimension of the complex this iterator belongs to.
+ /// \arg \p E The type exact type of the iterator.
+ template <unsigned D, typename E>
+ class complex_iter_ : public Iterator<E>
+ {
+ typedef complex_iter_<D, E> self_;
+
+ public:
+ typedef any_face_handle<D> face;
+
+ /// Construction and assignment.
+ /// \{
+ complex_iter_();
+ /* FIXME: Keep this non-const? See a (big) comment about this in
+ milena/tests/complex_image.cc. */
+ complex_iter_(complex<D>& c);
+ complex_iter_(const self_& rhs);
+ self_& operator= (const self_& rhs);
+ /// \}
+
+ /// Manipulation.
+ /// \{
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+ /// Invalidate the iterator.
+ void invalidate();
+ /// \}
+
+ /// Conversion and accessors.
+ /// \{
+ /// Reference to the corresponding any-face handle.
+ const face& to_face () const;
+ /// Convert the iterator into an any-face handle.
+ operator face() const;
+ /// \}
+
+ protected:
+ /// The face handle this iterator is pointing to.
+ face face_;
+
+ private:
+ /// \brief An invalid value for both the dimension and the id of
+ /// the face.
+ ///
+ /// Use a function instead of a static constant, since `static'
+ /// variables needs to be compiled once, which requires a compiled
+ /// library to avoid duplicate symbols, which is something that
+ /// was not really planned in Milena. A function tagged `inlined'
+ /// can appear multiple times in a program, and solves this
+ /// problem. We rely on the compiler to inline this call.
+ ///
+ /// Of course, we could have used UINT_MAX, but it is not very
+ /// C++.
+ unsigned invalid_unsigned_() const;
+ };
+
+
+ /* FIXME: This hand-made delegation is painful. We should rely on
+ the general mechanism provided by Point_Site. But then again, we
+ need to refine/adjust the interface of Point_Site w.r.t. the
+ mandatory conversions to points. */
+ template <unsigned D, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_<D, E>& p);
+
+ } // end of mln::internal
+
/*-----------------------.
| complex_fwd_iter_<D>. |
`-----------------------*/
- /// \brief Forward iterator on all the faces of mln::complex<D>.
+ /// \brief Forward iterator on all the faces of a mln::complex<D>.
+ ///
+ /// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
- class complex_fwd_iter_ : public Iterator< complex_fwd_iter_<D> >
+ class complex_fwd_iter_
+ : public internal::complex_iter_< D, complex_fwd_iter_<D> >
{
typedef complex_fwd_iter_<D> self_;
+ typedef internal::complex_iter_< D, self_ > super_;
public:
- typedef any_face_handle<D> face;
+ using super_::is_valid;
+ using super_::invalidate;
+ public:
/// Construction and assignment.
/// \{
complex_fwd_iter_();
- /* FIXME: Keep this non-const? See a (big) comment about this in
- milena/tests/complex_image.cc. */
+ // FIXME: See above (internal::complex_iter_'s default ctor).
complex_fwd_iter_(complex<D>& c);
complex_fwd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -77,72 +155,39 @@ namespace mln
void set_cplx(complex<D>& c);
/// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
- /// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
/// \}
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding any-face handle.
- const face& to_face () const;
- /// Convert the iterator into an any-face handle.
- operator face() const;
- /// \}
-
private:
- /// The face handle this iterator is pointing to.
- face face_;
-
- /// \brief An invalid value for both the dimension and the id of
- /// the face.
- ///
- /// Use a function instead of a static constant, since `static'
- /// variables needs to be compiled once, which requires a compiled
- /// library to avoid duplicate symbols, which is something that
- /// was not really planned in Milena. A function tagged `inlined'
- /// can appear multiple times in a program, and solves this
- /// problem. We rely on the compiler to inline this call.
- ///
- /// Of course, we could have used UINT_MAX, but it is not very
- /// C++.
- unsigned invalid_unsigned_() const;
+ using super_::face_;
};
- /* FIXME: This hand-made delegation is painful. We should rely on
- the general mechanism provided by Point_Site. But then again, we
- need to refine/adjust the interface of Point_Site w.r.t. the
- mandatory conversions to points. */
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_fwd_iter_<D>& p);
-
-
/*-----------------------.
| complex_bkd_iter_<D>. |
`-----------------------*/
- /// \brief Backward iterator on all the faces of mln::complex<D>.
+ /// \brief Backward iterator on all the faces of a mln::complex<D>.
+ ///
+ /// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
- class complex_bkd_iter_ : public Iterator< complex_bkd_iter_<D> >
+ class complex_bkd_iter_
+ : public internal::complex_iter_< D, complex_bkd_iter_<D> >
{
typedef complex_bkd_iter_<D> self_;
+ typedef internal::complex_iter_< D, self_ > super_;
public:
- typedef any_face_handle<D> face;
+ using super_::is_valid;
+ using super_::invalidate;
+ public:
/// Construction and assignment.
/// \{
complex_bkd_iter_();
- /* FIXME: Keep this non-const? See a (big) comment about this in
- milena/tests/complex_image.cc. */
+ // FIXME: See above (internal::complex_iter_'s default ctor).
complex_bkd_iter_(complex<D>& c);
complex_bkd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -154,57 +199,126 @@ namespace mln
// FIXME: Same comment as the ctor above.
void set_cplx(complex<D>& c);
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
/// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
/// \}
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding any-face handle.
- const face& to_face () const;
- /// Convert the iterator into an any-face handle.
- operator face() const;
- /// \}
-
private:
- /// The face handle this iterator is pointing to.
- face face_;
-
- /// \brief An invalid value for both the dimension and the id of
- /// the face.
- ///
- /// Use a function instead of a static constant, since `static'
- /// variables needs to be compiled once, which requires a compiled
- /// library to avoid duplicate symbols, which is something that
- /// was not really planned in Milena. A function tagged `inlined'
- /// can appear multiple times in a program, and solves this
- /// problem. We rely on the compiler to inline this call.
- ///
- /// Of course, we could have used UINT_MAX, but it is not very
- /// C++.
- unsigned invalid_unsigned_() const;
+ using super_::face_;
};
- /* FIXME: This hand-made delegation is painful. We should rely on
- the general mechanism provided by Point_Site. But then again, we
- need to refine/adjust the interface of Point_Site w.r.t. the
- mandatory conversions to points. */
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_bkd_iter_<D>& p);
+# ifndef MLN_INCLUDE_ONLY
+ /*--------------------------------.
+ | internal::complex_iter_<D, E>. |
+ `--------------------------------*/
+
+ namespace internal
+ {
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::complex_iter_()
+ {
+ // Invalidate face_.
+ invalidate();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::complex_iter_(complex<D>& c)
+ {
+ face_.set_cplx(c);
+ // Invalidate face_.
+ invalidate();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::complex_iter_(const complex_iter_<D, E>& rhs)
+ : face_(rhs.face_)
+ {
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>&
+ complex_iter_<D, E>::operator=(const complex_iter_<D, E>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ face_ = rhs.face_;
+ return *this;
+ }
+
+ template <unsigned D, typename E>
+ inline
+ bool
+ complex_iter_<D, E>::is_valid() const
+ {
+ return face_.is_valid();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ void
+ complex_iter_<D, E>::invalidate()
+ {
+ face_.set_n(invalid_unsigned_());
+ face_.set_face_id(invalid_unsigned_());
+ }
+
+ template <unsigned D, typename E>
+ inline
+ const any_face_handle<D>&
+ complex_iter_<D, E>::to_face() const
+ {
+ return face_;
+ }
+
+ template <unsigned D, typename E>
+ inline
+ complex_iter_<D, E>::operator any_face_handle<D>() const
+ {
+ mln_precondition(is_valid());
+ return face_;
+ }
+
+ template <unsigned D, typename E>
+ unsigned
+ complex_iter_<D, E>::invalid_unsigned_() const
+ {
+ return std::numeric_limits<unsigned>::max();
+ }
+
+ template <unsigned D, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_<D, E>& p)
+ {
+ /* FIXME: We should use p.to_face() here, but as it lacks the
+ precondition the conversion operator has, so we use the latter.
+
+ We should
+ - rename `to_face' as `to_face_';
+ - write a new `to_face' routine checking the validity of the
+ iterator;
+ - have the conversion operator to face use this new `to_face'
+ routine;
+ - adjust former clients of `to_face'
+
+ This is a general remark that applies to all iterators of
+ Milena. */
+ any_face_handle<D> f = p;
+ return ostr << "(dim = " << f.n() << ", id = " << f.face_id() << ')';
+ }
+
+ } // end of mln::internal
-# ifndef MLN_INCLUDE_ONLY
/*-----------------------.
| complex_fwd_iter_<D>. |
@@ -213,8 +327,8 @@ namespace mln
template <unsigned D>
inline
complex_fwd_iter_<D>::complex_fwd_iter_()
+ : super_()
{
- invalidate();
}
template <unsigned D>
@@ -228,7 +342,7 @@ namespace mln
template <unsigned D>
inline
complex_fwd_iter_<D>::complex_fwd_iter_(const complex_fwd_iter_<D>& rhs)
- : face_(rhs.face_)
+ : super_(rhs)
{
}
@@ -239,7 +353,7 @@ namespace mln
{
if (&rhs == this)
return *this;
- face_ = rhs.face_;
+ super_::operator=(rhs);
return *this;
}
@@ -255,23 +369,6 @@ namespace mln
template <unsigned D>
inline
- bool
- complex_fwd_iter_<D>::is_valid() const
- {
- return face_.is_valid();
- }
-
- template <unsigned D>
- inline
- void
- complex_fwd_iter_<D>::invalidate()
- {
- face_.set_n(invalid_unsigned_());
- face_.set_face_id(invalid_unsigned_());
- }
-
- template <unsigned D>
- inline
void
complex_fwd_iter_<D>::start()
{
@@ -311,49 +408,18 @@ namespace mln
}
}
- template <unsigned D>
- inline
- const any_face_handle<D>&
- complex_fwd_iter_<D>::to_face() const
- {
- return face_;
- }
-
- template <unsigned D>
- inline
- complex_fwd_iter_<D>::operator any_face_handle<D>() const
- {
- mln_precondition(is_valid());
- return face_;
- }
-
- template <unsigned D>
- unsigned
- complex_fwd_iter_<D>::invalid_unsigned_() const
- {
- return std::numeric_limits<unsigned>::max();
- }
-
-
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_fwd_iter_<D>& p)
- {
- return ostr << "(dim = " << p.to_face().n()
- << ", id = " << p.to_face().face_id() << ')';
- }
-
/*-----------------------.
| complex_bkd_iter_<D>. |
`-----------------------*/
+ // FIXME: Resume here.
+
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_()
+ : super_()
{
- invalidate();
}
template <unsigned D>
@@ -367,7 +433,7 @@ namespace mln
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_(const complex_bkd_iter_<D>& rhs)
- : face_(rhs.face_)
+ : super_(rhs)
{
}
@@ -378,7 +444,7 @@ namespace mln
{
if (&rhs == this)
return *this;
- face_ = rhs.face_;
+ super_::operator=(rhs);
return *this;
}
@@ -394,23 +460,6 @@ namespace mln
template <unsigned D>
inline
- bool
- complex_bkd_iter_<D>::is_valid() const
- {
- return face_.is_valid();
- }
-
- template <unsigned D>
- inline
- void
- complex_bkd_iter_<D>::invalidate()
- {
- face_.set_n(invalid_unsigned_());
- face_.set_face_id(invalid_unsigned_());
- }
-
- template <unsigned D>
- inline
void
complex_bkd_iter_<D>::start()
{
@@ -450,39 +499,6 @@ namespace mln
}
}
- template <unsigned D>
- inline
- const any_face_handle<D>&
- complex_bkd_iter_<D>::to_face() const
- {
- return face_;
- }
-
- template <unsigned D>
- inline
- complex_bkd_iter_<D>::operator any_face_handle<D>() const
- {
- mln_precondition(is_valid());
- return face_;
- }
-
- template <unsigned D>
- unsigned
- complex_bkd_iter_<D>::invalid_unsigned_() const
- {
- return std::numeric_limits<unsigned>::max();
- }
-
-
- template <unsigned D>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const complex_bkd_iter_<D>& p)
- {
- return ostr << "(dim = " << p.to_face().n()
- << ", id = " << p.to_face().face_id() << ')';
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of mln
diff --git a/milena/tests/core/complex.cc b/milena/tests/core/complex.cc
index 1bacd6e..91bae55 100644
--- a/milena/tests/core/complex.cc
+++ b/milena/tests/core/complex.cc
@@ -115,18 +115,19 @@ int main()
| Iteration. |
`------------*/
- // Iterators on a complex (not complex_image), or more precisely on
- // the faces of a complex.
+ // FIXME: Possibly split this test (create a test for iterators).
- mln_fwd_citer_(complex<D>) ff(c);
- for_all(ff)
- std::cout << ff << std::endl;
+ // Iterators on a complex (not complex_image), or more precisely on
+ // (all) the faces of complex C.
+ mln_fwd_citer_(complex<D>) fwd_f(c);
+ for_all(fwd_f)
+ std::cout << fwd_f << std::endl;
std::cout << std::endl;
- mln_bkd_citer_(complex<D>) bf(c);
- for_all(bf)
- std::cout << bf << std::endl;
+ mln_bkd_citer_(complex<D>) bkd_f(c);
+ for_all(bkd_f)
+ std::cout << bkd_f << std::endl;
/* FIXME: Exercice more iterators (see
milena/tests/core/complex_image.cc) and ticket #162
--
1.6.0.1
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make the median_fast test pass.
* tests/convert/to_window.cc,
* tests/win/cuboid3d.cc,
* tests/win/rectangle2d.cc,
* mln/core/w_window.hh,
* mln/core/window.hh,
* mln/core/dpoints_pixter.hh,
* mln/core/internal/dpoints_base.hh,
* mln/convert/to_p_array.hh,
* sandbox/geraud/dmap.cc,
* sandbox/geraud/cs2d/dbl_neighb.hh (ndpoints): Update to...
(size): ...its new name.
* mln/core/window.hh (has): New method.
* mln/core/dpoints_pixter.hh (p_ref): Use get_adr.
* mln/level/fast_median.hh (int, median): Replace by...
(def::coord, median_h): ...this.
Update.
* mln/geom/shift.hh: Rewrite.
* mln/set/diff.hh: Rewrite without std::set.
* mln/win/rectangle2d.hh (typedef): Import super ones.
mln/convert/to_p_array.hh | 2 +-
mln/core/dpoints_pixter.hh | 22 ++++++++++++----------
mln/core/internal/dpoints_base.hh | 8 ++++----
mln/core/w_window.hh | 30 +++++++++++++++---------------
mln/core/window.hh | 13 +++++++++++--
mln/geom/shift.hh | 14 +++++++-------
mln/level/fast_median.hh | 14 ++++++++------
mln/set/diff.hh | 31 ++++++++++++++++++-------------
mln/win/rectangle2d.hh | 6 ++++++
sandbox/geraud/cs2d/dbl_neighb.hh | 4 ++--
sandbox/geraud/dmap.cc | 2 +-
tests/convert/to_window.cc | 4 ++--
tests/win/cuboid3d.cc | 2 +-
tests/win/rectangle2d.cc | 2 +-
14 files changed, 89 insertions(+), 65 deletions(-)
Index: tests/convert/to_window.cc
--- tests/convert/to_window.cc (revision 2241)
+++ tests/convert/to_window.cc (working copy)
@@ -47,8 +47,8 @@
void test(window2d ref, window2d cmp)
{
- mln_assertion(ref.ndpoints() == cmp.ndpoints());
- for (unsigned i = 0; i < ref.ndpoints(); ++i)
+ mln_assertion(ref.size() == cmp.size());
+ for (unsigned i = 0; i < ref.size(); ++i)
mln_assertion(ref.dp(i) == cmp.dp(i));
}
Index: tests/win/cuboid3d.cc
--- tests/win/cuboid3d.cc (revision 2241)
+++ tests/win/cuboid3d.cc (working copy)
@@ -48,7 +48,7 @@
mln_assertion(cuboid.is_centered());
mln_assertion(cuboid.is_symmetric());
mln_assertion(cuboid == geom::sym(cuboid));
- mln_assertion(cuboid.ndpoints() == d * h * w);
+ mln_assertion(cuboid.size() == d * h * w);
mln_assertion(cuboid.delta() == 3);
Index: tests/win/rectangle2d.cc
--- tests/win/rectangle2d.cc (revision 2241)
+++ tests/win/rectangle2d.cc (working copy)
@@ -48,7 +48,7 @@
mln_assertion(rec.is_centered());
mln_assertion(rec.is_symmetric());
mln_assertion(rec == geom::sym(rec));
- mln_assertion(rec.ndpoints() == h * w);
+ mln_assertion(rec.size() == h * w);
mln_assertion(rec.delta() == 2);
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 2241)
+++ mln/core/w_window.hh (working copy)
@@ -95,7 +95,7 @@
const D& dp(unsigned i) const;
/// Give the number of delta-points.
- unsigned ndpoints() const;
+ unsigned size() const;
/// Give access to the vector of delta-points.
const std::vector<D>& vect() const;
@@ -191,18 +191,18 @@
const D&
w_window<D,W>::dp(unsigned i) const
{
- mln_precondition(i < win_.ndpoints());
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_precondition(i < win_.size());
+ mln_invariant(wei_.size() == win_.size());
return win_.dp(i);
}
template <typename D, typename W>
inline
unsigned
- w_window<D,W>::ndpoints() const
+ w_window<D,W>::size() const
{
- mln_invariant(wei_.size() == win_.ndpoints());
- return win_.ndpoints();
+ mln_invariant(wei_.size() == win_.size());
+ return win_.size();
}
template <typename D, typename W>
@@ -227,7 +227,7 @@
w_window<D,W>::w(unsigned i) const
{
mln_precondition(i < wei_.size());
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_invariant(wei_.size() == win_.size());
return wei_[i];
}
@@ -236,7 +236,7 @@
w_window<D,W>&
w_window<D,W>::insert(const W& w, const D& d)
{
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_invariant(wei_.size() == win_.size());
mln_precondition(! win_.has(d));
if (w == W(0)) // FIXME: Implicit restriction "W scalar"...
@@ -245,7 +245,7 @@
// memorization: d_i -> w_i
std::map<D, W> memo_wei_;
- for (unsigned i = 0; i < win_.ndpoints(); ++i)
+ for (unsigned i = 0; i < win_.size(); ++i)
memo_wei_[win_.dp(i)] = wei_[i];
// insertion of d and w:
@@ -253,11 +253,11 @@
memo_wei_[d] = w;
// re-mapping: w_i <- d_i
- wei_.resize(win_.ndpoints());
- for (unsigned i = 0; i < win_.ndpoints(); ++i)
+ wei_.resize(win_.size());
+ for (unsigned i = 0; i < win_.size(); ++i)
wei_[i] = memo_wei_[win_.dp(i)];
- mln_invariant(wei_.size() == win_.ndpoints());
+ mln_invariant(wei_.size() == win_.size());
return *this;
}
@@ -267,7 +267,7 @@
w_window<D,W>::sym()
{
w_window<D,W> tmp;
- for (unsigned i = 0; i < this->ndpoints(); ++i)
+ for (unsigned i = 0; i < this->size(); ++i)
tmp.insert(this->w(i), - this->dp(i));
*this = tmp;
return *this;
@@ -280,7 +280,7 @@
std::ostream& operator<<(std::ostream& ostr, const w_window<D,W>& w_win)
{
ostr << '[';
- for (unsigned i = 0; i < w_win.win().ndpoints(); ++i)
+ for (unsigned i = 0; i < w_win.win().size(); ++i)
ostr << w_win.vect()[i] << ':' << w_win.w(i) << ' ';
return ostr << ']';
}
@@ -289,7 +289,7 @@
inline
bool operator==(const w_window<D,Wl>& lhs, const w_window<D,Wr>& rhs)
{
- if (lhs.ndpoints() != rhs.ndpoints())
+ if (lhs.size() != rhs.size())
return false;
if (lhs.win() != rhs.win())
return false;
Index: mln/core/window.hh
--- mln/core/window.hh (revision 2241)
+++ mln/core/window.hh (working copy)
@@ -119,10 +119,11 @@
*/
unsigned delta() const;
- // Give the \p i-th delta-point.
+ /// Give the \p i-th delta-point.
const D& dp(unsigned i) const;
-
+ /// Test if \p dp is in this window definition.
+ bool has(const D& dp) const;
/// Insert a delta-point \p dp.
window<D>& insert(const D& dp);
@@ -254,6 +255,14 @@
template <typename D>
inline
+ bool
+ window<D>::has(const D& dp) const
+ {
+ return dps_.has(dp);
+ }
+
+ template <typename D>
+ inline
const std::vector<D>&
window<D>::std_vector() const
{
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 2241)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -190,7 +190,7 @@
private:
/// \brief Offset of each delta-point.
///
- /// offset_[dps.ndpoints() - 1] is absolute, while other offsets
+ /// offset_[dps.size() - 1] is absolute, while other offsets
/// are relative (i.e., offset_[i] is the memory difference to go
/// from pixel i+1 to pixel i.
std::vector<int> offset_;
@@ -225,7 +225,8 @@
: super_(image)
{
mln_precondition(image.has_data());
- p_ref_ = & exact(p_ref).to_site();
+ internal::get_adr(p_ref_, p_ref);
+// p_ref_ = & exact(p_ref).to_site();
value_ref_ = 0;
init_(dps);
}
@@ -263,12 +264,12 @@
void
dpoints_fwd_pixter<I>::init_(const Dps& dps)
{
- for (unsigned i = 0; i < dps.ndpoints(); ++i)
+ for (unsigned i = 0; i < dps.size(); ++i)
offset_.push_back(this->image_.delta_index(dps.dp(i)));
// offset_[0] is absolute
// other offsets are relative:
- if (dps.ndpoints() > 1)
- for (unsigned i = dps.ndpoints() - 1; i > 0; --i)
+ if (dps.size() > 1)
+ for (unsigned i = dps.size() - 1; i > 0; --i)
offset_[i] -= offset_[i - 1];
invalidate();
}
@@ -336,7 +337,8 @@
: super_(image)
{
mln_precondition(image.has_data());
- p_ref_ = & exact(p_ref).to_site();
+ internal::get_adr(p_ref_, p_ref);
+// p_ref_ = & exact(p_ref).to_site();
value_ref_ = 0;
init_(dps);
}
@@ -374,12 +376,12 @@
void
dpoints_bkd_pixter<I>::init_(const Dps& dps)
{
- for (unsigned i = 0; i < dps.ndpoints(); ++i)
+ for (unsigned i = 0; i < dps.size(); ++i)
offset_.push_back(this->image_.delta_index(dps.dp(i)));
- // offset_[ndpoints() - 1] is absolute
+ // offset_[size() - 1] is absolute
// other offsets are relative:
- if (dps.ndpoints() > 1)
- for (unsigned i = 0; i < dps.ndpoints() - 1; ++i)
+ if (dps.size() > 1)
+ for (unsigned i = 0; i < dps.size() - 1; ++i)
offset_[i] -= offset_[i + 1];
invalidate();
}
Index: mln/core/internal/dpoints_base.hh
--- mln/core/internal/dpoints_base.hh (revision 2241)
+++ mln/core/internal/dpoints_base.hh (working copy)
@@ -92,7 +92,7 @@
unsigned delta() const;
/// Give the number of delta-points.
- unsigned ndpoints() const;
+ unsigned size() const;
/// Test if the delta-point \p dp belongs to the window.
bool has(const D& dp) const;
@@ -149,7 +149,7 @@
template <typename D, typename E>
inline
unsigned
- dpoints_base_<D,E>::ndpoints() const
+ dpoints_base_<D,E>::size() const
{
return win_.size();
}
@@ -159,7 +159,7 @@
const D&
dpoints_base_<D,E>::dp(unsigned i) const
{
- mln_precondition(i < ndpoints());
+ mln_precondition(i < size());
return win_.dp(i);
}
@@ -184,7 +184,7 @@
bool
dpoints_base_<D,E>::has(const D& dp) const
{
- return win_.dps_hook_().has(dp);
+ return win_.has(dp);
}
template <typename D, typename E>
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 2241)
+++ mln/level/fast_median.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -31,11 +31,13 @@
/*! \file mln/level/fast_median.hh
*
* \brief Fast Median filtering of an image.
+ *
+ * \todo There are implicit assumptions about input being 2D!!!
*/
# include <mln/core/concept/image.hh>
# include <mln/core/alias/window2d.hh>
-# include <mln/accu/median.hh>
+# include <mln/accu/median_h.hh>
# include <mln/geom/shift.hh>
# include <mln/geom/min_col.hh>
# include <mln/geom/min_row.hh>
@@ -79,7 +81,7 @@
mln_precondition(input.has_data());
mln_precondition(output.has_data());
- int
+ def::coord
min_row = geom::min_row(input), max_row = geom::max_row(input),
min_col = geom::min_col(input), max_col = geom::max_col(input);
@@ -91,7 +93,7 @@
win_bot = set::diff(win, geom::shift(win, up)),
win_top = set::diff(geom::shift(win, up), win);
- accu::median<mln_vset(I)> med(input.values());
+ accu::median_h<mln_value(I)> med;
// initialization
@@ -109,8 +111,8 @@
med.take(q.val());
}
- int& row = p.row();
- int& col = p.col();
+ def::coord& row = p.row();
+ def::coord& col = p.col();
bool fwd = true;
mln_assertion(p.col() == min_col);
Index: mln/convert/to_p_array.hh
--- mln/convert/to_p_array.hh (revision 2241)
+++ mln/convert/to_p_array.hh (working copy)
@@ -82,7 +82,7 @@
const mln_psite(W)& p)
{
p_array<mln_psite(W)> v;
- v.reserve(exact(win).ndpoints());
+ v.reserve(exact(win).size());
mln_qiter(W) q(win, p);
for_all(q)
v.append(q);
Index: mln/geom/shift.hh
--- mln/geom/shift.hh (revision 2241)
+++ mln/geom/shift.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 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
@@ -34,7 +34,6 @@
*/
# include <mln/core/window.hh>
-# include <mln/convert/to.hh>
@@ -55,13 +54,14 @@
template <typename W>
inline
window<mln_dpsite(W)>
- shift(const Window<W>& win, const mln_dpsite(W)& dp)
+ shift(const Window<W>& win_, const mln_dpsite(W)& dp)
{
- typedef mln_site(W) P;
+ const W& win = exact(win_);
+
window<mln_dpsite(W)> tmp;
- mln_qiter(W) q(win, P::origin);
- for_all(q)
- tmp.insert(convert::to(q) + dp);
+ unsigned n = win.size();
+ for (unsigned i = 0; i < n; ++i)
+ tmp.insert(win.dp(i) + dp);
return tmp;
}
Index: mln/set/diff.hh
--- mln/set/diff.hh (revision 2241)
+++ mln/set/diff.hh (working copy)
@@ -54,7 +54,7 @@
* \relates mln::Window
*/
template <typename Wl, typename Wr>
- window<mln_dpoint(Wl)>
+ window<mln_dpsite(Wl)>
diff(const Window<Wl>& lhs, const Window<Wr>& rhs);
/*! \brief Set theoretic difference of \p lhs and \p rhs.
@@ -70,21 +70,26 @@
template <typename Wl, typename Wr>
inline
- window<mln_dpoint(Wl)>
- diff(const Window<Wl>& lhs, const Window<Wr>& rhs)
+ window<mln_dpsite(Wl)>
+ diff(const Window<Wl>& lhs_, const Window<Wr>& rhs_)
{
trace::entering("set::diff");
- mln::metal::equal<mln_dpoint(Wl), mln_dpoint(Wr)>::check();
- typedef mln_dpoint(Wl) D;
- std::set<D>
- sl = convert::to_std_set(lhs),
- sr = convert::to_std_set(rhs),
- s;
- std::set_difference(sl.begin(), sl.end(),
- sr.begin(), sr.end(),
- std::inserter(s, s.begin()));
+ mlc_equal(mln_dpsite(Wl), mln_dpsite(Wr))::check();
+
+ const Wl& lhs = exact(lhs_);
+ const Wr& rhs = exact(rhs_);
+ window<mln_dpsite(Wl)> tmp;
+
+ const unsigned n = lhs.size();
+ for (unsigned i = 0; i < n; ++i)
+ {
+ if (rhs.has(lhs.dp(i)))
+ continue;
+ tmp.insert(lhs.dp(i));
+ }
+
trace::exiting("set::diff");
- return convert::to_window(s);
+ return tmp;
}
template <typename Wl, typename Wr>
Index: mln/win/rectangle2d.hh
--- mln/win/rectangle2d.hh (revision 2241)
+++ mln/win/rectangle2d.hh (working copy)
@@ -60,6 +60,12 @@
struct rectangle2d : public internal::window_base< dpoint2d, rectangle2d >,
public internal::dpoints_base_< dpoint2d, rectangle2d >
{
+ typedef internal::dpoints_base_< dpoint2d, rectangle2d > super_;
+
+ typedef super_::site site;
+ typedef super_::psite psite;
+ typedef super_::dpsite dpsite;
+
/*! \brief Constructor.
*
* \param[in] height Height of the rectangle2d.
Index: sandbox/geraud/dmap.cc
--- sandbox/geraud/dmap.cc (revision 2241)
+++ sandbox/geraud/dmap.cc (working copy)
@@ -29,7 +29,7 @@
// Mod determination.
mln_accu_with_(accu::max, unsigned) max;
- for (unsigned i = 0; i < win.ndpoints(); ++i)
+ for (unsigned i = 0; i < win.size(); ++i)
max.take(win.w(i));
unsigned mod = unsigned(max) + 1;
Index: sandbox/geraud/cs2d/dbl_neighb.hh
--- sandbox/geraud/cs2d/dbl_neighb.hh (revision 2241)
+++ sandbox/geraud/cs2d/dbl_neighb.hh (working copy)
@@ -52,7 +52,7 @@
dbl_neighb_& when_true(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
- for (unsigned i = 0; i < nbh.ndpoints(); ++i)
+ for (unsigned i = 0; i < nbh.size(); ++i)
trues.push_back(nbh.dp(i));
return *this;
}
@@ -61,7 +61,7 @@
dbl_neighb_& when_false(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
- for (unsigned i = 0; i < nbh.ndpoints(); ++i)
+ for (unsigned i = 0; i < nbh.size(); ++i)
falses.push_back(nbh.dp(i));
return *this;
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-09-12 Guillaume Lazzara <z(a)lrde.epita.fr>
Add missing init_().
* milena/mln/core/image/cast_image.hh,
* milena/mln/core/image/decorated_image.hh: add missing init_().
---
cast_image.hh | 15 +++++++++++----
decorated_image.hh | 14 ++++++++++++++
2 files changed, 25 insertions(+), 4 deletions(-)
Index: branches/cleanup-2008/milena/mln/core/image/cast_image.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/image/cast_image.hh (revision 2240)
+++ branches/cleanup-2008/milena/mln/core/image/cast_image.hh (revision 2241)
@@ -95,10 +95,11 @@
/// Skeleton.
typedef cast_image_< tag::value_<T>, tag::image_<I> > skeleton;
-
/// Constructor.
cast_image_(const Image<I>& ima);
+ /// Initialize an empty image.
+ void init_(const Image<I>& ima);
/// Read-only access of pixel value at point site \p p.
T operator()(const mln_psite(I)& p) const;
@@ -108,7 +109,6 @@
};
-
template <typename T, typename I>
cast_image_<T,I>
cast_image(const Image<I>& ima)
@@ -119,7 +119,6 @@
}
-
# ifndef MLN_INCLUDE_ONLY
@@ -137,7 +136,6 @@
} // end of namespace mln::internal
-
// cast_image_<T,I>
template <typename T, typename I>
@@ -150,6 +148,15 @@
template <typename T, typename I>
inline
+ void
+ cast_image_<T,I>::init_(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).has_data());
+ this->data_ = new internal::data<cast_image_<T,I> >(exact(ima));
+ }
+
+ template <typename T, typename I>
+ inline
T
cast_image_<T,I>::operator()(const mln_psite(I)& p) const
{
Index: branches/cleanup-2008/milena/mln/core/image/decorated_image.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/image/decorated_image.hh (revision 2240)
+++ branches/cleanup-2008/milena/mln/core/image/decorated_image.hh (revision 2241)
@@ -101,6 +101,10 @@
/// Ctors
decorated_image();
decorated_image(I& ima, const D& deco);
+
+ /// Initialize an empty image.
+ void init_(I& ima, const D& deco);
+
/// Dtor
~decorated_image();
@@ -166,6 +170,16 @@
inline
decorated_image<I,D>::decorated_image(I& ima, const D& deco)
{
+ mln_precondition(exact(ima).has_data());
+ this->data_ = new internal::data< decorated_image<I,D> >(ima, deco);
+ }
+
+ template <typename I, typename D>
+ inline
+ void
+ decorated_image<I,D>::init_(I& ima, const D& deco)
+ {
+ mln_precondition(exact(ima).has_data());
this->data_ = new internal::data< decorated_image<I,D> >(ima, deco);
}
1
0