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
13 Sep '08
---
milena/ChangeLog | 4 ++++
milena/mln/core/concept/iterator.hh | 5 ++++-
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 474ee9d..0e9fac5 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+ * mln/core/concept/iterator.hh (for_all_2): Wrap a long line.
+
+2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+
* mln/core/face.hh: Add missing `inline' keywords.
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
diff --git a/milena/mln/core/concept/iterator.hh b/milena/mln/core/concept/iterator.hh
index d072329..26ae2ef 100644
--- a/milena/mln/core/concept/iterator.hh
+++ b/milena/mln/core/concept/iterator.hh
@@ -43,7 +43,10 @@
/*! \brief Loop to browse all the elements targetted by the couples of
* iterators \p x1 and \p x2.
*/
-# define for_all_2(x1, x2) for(x1.start(),x2.start(); x1.is_valid(); x1.next(),x2.next())
+# define for_all_2(x1, x2) \
+ for(x1.start(), x2.start(); \
+ x1.is_valid(); \
+ x1.next(), x2.next())
/*! \brief Loop to browse all the elements targetted by the triplet of
--
1.6.0.1
1
0
---
milena/ChangeLog | 4 ++++
milena/mln/core/face.hh | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index f4629b7..474ee9d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+ * mln/core/face.hh: Add missing `inline' keywords.
+
+2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+
Factor (more) iterators on complexes and faces.
* mln/core/internal/complex_iter_base.hh: New.
diff --git a/milena/mln/core/face.hh b/milena/mln/core/face.hh
index 9fd685a..4692d65 100644
--- a/milena/mln/core/face.hh
+++ b/milena/mln/core/face.hh
@@ -360,6 +360,7 @@ namespace mln
namespace internal
{
template <unsigned N, unsigned D>
+ inline
void
lower_dim_faces_mixin<N, D>::connect_lower_dim_face(const face_handle<N - 1, D>& f)
{
@@ -367,6 +368,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
higher_dim_faces_mixin<N, D>::connect_higher_dim_face(const face_handle<N + 1, D>& f)
{
@@ -381,6 +383,7 @@ namespace mln
`--------------*/
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>::face_handle()
: cplx_(0), face_id_(std::numeric_limits<unsigned>::max())
{
@@ -389,6 +392,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>::face_handle(complex<D>& c, unsigned face_id)
: cplx_(&c), face_id_(face_id)
{
@@ -397,6 +401,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>::face_handle(const face_handle<N, D>& rhs)
: cplx_(rhs.cplx_), face_id_(rhs.face_id_)
{
@@ -405,6 +410,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>&
face_handle<N, D>::operator=(const face_handle<N, D>& rhs)
{
@@ -417,6 +423,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
bool
face_handle<N, D>::is_valid() const
{
@@ -424,6 +431,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
face_handle<N, D>::invalidate()
{
@@ -431,6 +439,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
complex<D>&
face_handle<N, D>::cplx() const
{
@@ -439,6 +448,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
unsigned
face_handle<N, D>::n() const
{
@@ -446,6 +456,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
unsigned
face_handle<N, D>::face_id() const
{
@@ -453,6 +464,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
face_handle<N, D>::set_cplx(complex<D>& cplx)
{
@@ -460,6 +472,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
face_handle<N, D>::set_face_id(unsigned face_id)
{
@@ -467,6 +480,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face<N, D>&
face_handle<N, D>::to_face() const
{
@@ -476,6 +490,7 @@ namespace mln
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>
make_face_handle(const complex<D>& c, unsigned face_id)
{
@@ -483,6 +498,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
bool
operator==(const face_handle<N, D>& lhs, const face_handle<N, D>& rhs)
{
@@ -492,6 +508,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
bool
operator< (const face_handle<N, D>& lhs, const face_handle<N, D>& rhs)
{
@@ -506,6 +523,7 @@ namespace mln
`---------------*/
template <unsigned N, unsigned D>
+ inline
void
faces_set<N, D>::add(const face_handle<N, D>& f)
{
@@ -516,6 +534,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
const std::vector< face_handle<N, D> >&
faces_set<N, D>::faces() const
{
@@ -524,6 +543,7 @@ namespace mln
template <unsigned N, unsigned D>
+ inline
faces_set<N, D>
operator+(const face_handle<N, D>& f1, const face_handle<N, D>& f2)
{
@@ -534,6 +554,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
faces_set<N, D>
operator+(const faces_set<N, D>& fs, const face_handle<N, D>& f)
{
@@ -548,6 +569,7 @@ namespace mln
`----------------------*/
template <unsigned D>
+ inline
any_face_handle<D>::any_face_handle()
: cplx_(0),
n_(std::numeric_limits<unsigned>::max()),
@@ -556,6 +578,7 @@ namespace mln
}
template <unsigned D>
+ inline
any_face_handle<D>::any_face_handle(complex<D>& c, unsigned n,
unsigned face_id)
: cplx_(&c), n_(n), face_id_(face_id)
@@ -566,6 +589,7 @@ namespace mln
template <unsigned D>
template <unsigned N>
+ inline
any_face_handle<D>::any_face_handle(const face_handle<N, D>& f)
: cplx_(&f.cplx()), n_(N), face_id_(f.face_id())
{
@@ -575,12 +599,14 @@ namespace mln
}
template <unsigned D>
+ inline
any_face_handle<D>::any_face_handle(const any_face_handle<D>& rhs)
: cplx_(rhs.cplx_), n_(rhs.n_), face_id_(rhs.face_id_)
{
}
template <unsigned D>
+ inline
any_face_handle<D>&
any_face_handle<D>::operator=(const any_face_handle<D>& rhs)
{
@@ -594,6 +620,7 @@ namespace mln
}
template <unsigned D>
+ inline
bool
any_face_handle<D>::is_valid() const
{
@@ -601,6 +628,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::invalidate()
{
@@ -609,6 +637,7 @@ namespace mln
}
template <unsigned D>
+ inline
complex<D>&
any_face_handle<D>::cplx() const
{
@@ -617,6 +646,7 @@ namespace mln
}
template <unsigned D>
+ inline
unsigned
any_face_handle<D>::n() const
{
@@ -624,6 +654,7 @@ namespace mln
}
template <unsigned D>
+ inline
unsigned
any_face_handle<D>::face_id() const
{
@@ -631,6 +662,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::set_cplx(complex<D>& cplx)
{
@@ -638,6 +670,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::set_n(unsigned n)
{
@@ -645,6 +678,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::set_face_id(unsigned face_id)
{
@@ -653,6 +687,7 @@ namespace mln
template <unsigned D>
template <unsigned N>
+ inline
face<N, D>&
any_face_handle<D>::to_face() const
{
@@ -663,6 +698,7 @@ namespace mln
template <unsigned D>
+ inline
bool
operator==(const any_face_handle<D>& lhs, const any_face_handle<D>& rhs)
{
@@ -674,6 +710,7 @@ namespace mln
}
template <unsigned D>
+ inline
bool
operator< (const any_face_handle<D>& lhs, const any_face_handle<D>& rhs)
{
--
1.6.0.1
1
0
* mln/core/internal/complex_iter_base.hh: New.
* mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
Remove.
(mln::internal::complex_fwd_iter_<D>)
(mln::internal::complex_bkd_iter_<D>):
Inherit from mln::internal::complex_iter_base_.
Adjust.
* mln/core/faces_iter.hh (mln::internal::faces_iter_<N, D, E>):
Remove.
(mln::internal::faces_fwd_iter_<N, D>)
(mln::internal::faces_bkd_iter_<N, D>):
Inherit from mln::internal::complex_iter_base_.
Adjust.
* mln/core/face.hh (mln::face_handle<N, D>::n): New accessor.
(mln::face_handle<N, D>::complex_type)
(mln::any_face_handle<D>::complex_type):
New typedefs.
(mln::face_handle<N, D>::invalidate)
(mln::any_face_handle<D>::invalidate):
New methods.
---
milena/ChangeLog | 25 +++
milena/mln/core/complex_iter.hh | 219 ++----------------------
milena/mln/core/face.hh | 35 ++++
milena/mln/core/faces_iter.hh | 215 ++----------------------
milena/mln/core/internal/complex_iter_base.hh | 214 ++++++++++++++++++++++++
5 files changed, 310 insertions(+), 398 deletions(-)
create mode 100644 milena/mln/core/internal/complex_iter_base.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index f164de6..f4629b7 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,30 @@
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+ Factor (more) iterators on complexes and faces.
+
+ * mln/core/internal/complex_iter_base.hh: New.
+ * mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
+ Remove.
+ (mln::internal::complex_fwd_iter_<D>)
+ (mln::internal::complex_bkd_iter_<D>):
+ Inherit from mln::internal::complex_iter_base_.
+ Adjust.
+ * mln/core/faces_iter.hh (mln::internal::faces_iter_<N, D, E>):
+ Remove.
+ (mln::internal::faces_fwd_iter_<N, D>)
+ (mln::internal::faces_bkd_iter_<N, D>):
+ Inherit from mln::internal::complex_iter_base_.
+ Adjust.
+ * mln/core/face.hh (mln::face_handle<N, D>::n): New accessor.
+ (mln::face_handle<N, D>::complex_type)
+ (mln::any_face_handle<D>::complex_type):
+ New typedefs.
+ (mln::face_handle<N, D>::invalidate)
+ (mln::any_face_handle<D>::invalidate):
+ New methods.
+
+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.
diff --git a/milena/mln/core/complex_iter.hh b/milena/mln/core/complex_iter.hh
index 4aa9b99..3dcb445 100644
--- a/milena/mln/core/complex_iter.hh
+++ b/milena/mln/core/complex_iter.hh
@@ -31,95 +31,11 @@
/// \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>
+# include <mln/core/internal/complex_iter_base.hh>
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>. |
`-----------------------*/
@@ -129,10 +45,15 @@ namespace mln
/// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
class complex_fwd_iter_
- : public internal::complex_iter_< D, complex_fwd_iter_<D> >
+ : public internal::complex_iter_base_< any_face_handle<D>,
+ complex_fwd_iter_<D> >
{
+ public:
+ typedef any_face_handle<D> face;
+
+ private:
typedef complex_fwd_iter_<D> self_;
- typedef internal::complex_iter_< D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -142,7 +63,7 @@ namespace mln
/// Construction and assignment.
/// \{
complex_fwd_iter_();
- // FIXME: See above (internal::complex_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
complex_fwd_iter_(complex<D>& c);
complex_fwd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -174,10 +95,15 @@ namespace mln
/// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
class complex_bkd_iter_
- : public internal::complex_iter_< D, complex_bkd_iter_<D> >
+ : public internal::complex_iter_base_< any_face_handle<D>,
+ complex_bkd_iter_<D> >
{
+ public:
+ typedef any_face_handle<D> face;
+
+ private:
typedef complex_bkd_iter_<D> self_;
- typedef internal::complex_iter_< D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -187,7 +113,7 @@ namespace mln
/// Construction and assignment.
/// \{
complex_bkd_iter_();
- // FIXME: See above (internal::complex_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
complex_bkd_iter_(complex<D>& c);
complex_bkd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -213,113 +139,6 @@ namespace mln
# 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
-
-
/*-----------------------.
| complex_fwd_iter_<D>. |
`-----------------------*/
@@ -334,6 +153,7 @@ namespace mln
template <unsigned D>
inline
complex_fwd_iter_<D>::complex_fwd_iter_(complex<D>& c)
+ : super_(c)
{
set_cplx(c);
mln_postcondition(!is_valid());
@@ -413,8 +233,6 @@ namespace mln
| complex_bkd_iter_<D>. |
`-----------------------*/
- // FIXME: Resume here.
-
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_()
@@ -425,6 +243,7 @@ namespace mln
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_(complex<D>& c)
+ : super_(c)
{
set_cplx(c);
mln_postcondition(!is_valid());
diff --git a/milena/mln/core/face.hh b/milena/mln/core/face.hh
index 4e8e958..9fd685a 100644
--- a/milena/mln/core/face.hh
+++ b/milena/mln/core/face.hh
@@ -143,6 +143,9 @@ namespace mln
template <unsigned N, unsigned D>
struct face_handle
{
+ // The type of the complex this handle points to.
+ typedef complex<D> complex_type;
+
/// Build a non-initialized face handle.
face_handle();
/// Build a face handle from \a complex and \a face_id.
@@ -156,6 +159,8 @@ namespace mln
/// Is this handle valid?
bool is_valid() const;
+ /// Invalidate this handle.
+ void invalidate();
/// Accessors.
/// \{
@@ -167,6 +172,9 @@ namespace mln
/// Set the complex the face belongs to.
void set_cplx(complex<D>& cplx);
+ /// Return the dimension of the face.
+ // FIXME: Rename as `dim'?
+ unsigned n() const;
/// Set the id of the face.
void set_face_id(unsigned face_id);
@@ -259,6 +267,9 @@ namespace mln
template <unsigned D>
struct any_face_handle
{
+ // The type of the complex this handle points to.
+ typedef complex<D> complex_type;
+
/// Build a non-initialized face handle.
any_face_handle();
/// Build a face handle from \a complex and \a face_id.
@@ -276,6 +287,8 @@ namespace mln
/// Is this handle valid?
bool is_valid() const;
+ /// Invalidate this handle.
+ void invalidate();
/// Accessors.
/// \{
@@ -411,6 +424,13 @@ namespace mln
}
template <unsigned N, unsigned D>
+ void
+ face_handle<N, D>::invalidate()
+ {
+ set_face_id(std::numeric_limits<unsigned>::max());
+ }
+
+ template <unsigned N, unsigned D>
complex<D>&
face_handle<N, D>::cplx() const
{
@@ -420,6 +440,13 @@ namespace mln
template <unsigned N, unsigned D>
unsigned
+ face_handle<N, D>::n() const
+ {
+ return N;
+ }
+
+ template <unsigned N, unsigned D>
+ unsigned
face_handle<N, D>::face_id() const
{
return face_id_;
@@ -574,6 +601,14 @@ namespace mln
}
template <unsigned D>
+ void
+ any_face_handle<D>::invalidate()
+ {
+ set_n(std::numeric_limits<unsigned>::max());
+ set_face_id(std::numeric_limits<unsigned>::max());
+ }
+
+ template <unsigned D>
complex<D>&
any_face_handle<D>::cplx() const
{
diff --git a/milena/mln/core/faces_iter.hh b/milena/mln/core/faces_iter.hh
index 25dd2c2..e11073d 100644
--- a/milena/mln/core/faces_iter.hh
+++ b/milena/mln/core/faces_iter.hh
@@ -32,99 +32,11 @@
/// \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>
+# include <mln/core/internal/complex_iter_base.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>. |
`------------------------*/
@@ -135,10 +47,15 @@ namespace mln
/// \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> >
+ : public internal::complex_iter_base_< face_handle<N, D>,
+ faces_fwd_iter_<N, D> >
{
+ public:
+ typedef face_handle<N, D> face;
+
+ private:
typedef faces_fwd_iter_<N, D> self_;
- typedef internal::faces_iter_< N, D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -147,7 +64,7 @@ namespace mln
public:
/// Construction and assignment.
/// \{
- // FIXME: See above (internal::faces_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
faces_fwd_iter_(complex<D>& c);
faces_fwd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -176,10 +93,15 @@ namespace mln
/// \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> >
+ : public internal::complex_iter_base_< face_handle<N, D>,
+ faces_bkd_iter_<N, D> >
{
+ public:
+ typedef face_handle<N, D> face;
+
+ private:
typedef faces_bkd_iter_<N, D> self_;
- typedef internal::faces_iter_< N, D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -188,7 +110,7 @@ namespace mln
public:
/// Construction and assignment.
/// \{
- // FIXME: See above (internal::faces_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
faces_bkd_iter_(complex<D>& c);
faces_bkd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -210,109 +132,6 @@ namespace mln
# 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>. |
`------------------------*/
diff --git a/milena/mln/core/internal/complex_iter_base.hh b/milena/mln/core/internal/complex_iter_base.hh
new file mode 100644
index 0000000..df9b39a
--- /dev/null
+++ b/milena/mln/core/internal/complex_iter_base.hh
@@ -0,0 +1,214 @@
+// 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_INTERNAL_COMPLEX_ITER_BASE_HH
+# define MLN_CORE_INTERNAL_COMPLEX_ITER_BASE_HH
+
+/// \file mln/core/complex_iter_base.hh
+/// \brief Definition of an implementation (factoring) class for
+/// iterators on complexes.
+
+# include <limits>
+
+# include <mln/metal/equal.hh>
+
+# include <mln/core/concept/iterator.hh>
+# include <mln/core/complex.hh>
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <unsigned D> class complex;
+
+ namespace internal
+ {
+ /// \brief Factoring classe for iterators on complexes.
+ ///
+ /// \arg \p F The type of the face handle.
+ /// \arg \p E The type exact type of the iterator.
+ template <typename F, typename E>
+ class complex_iter_base_ : public Iterator<E>
+ {
+ typedef complex_iter_base_<F, E> self_;
+
+ public:
+ typedef F face;
+ typedef typename F::complex_type complex_type;
+
+ /// Construction and assignment.
+ /// \{
+ /* FIXME: Keep this non-const? See a (big) comment about this in
+ milena/tests/complex_image.cc. */
+ complex_iter_base_();
+ complex_iter_base_(complex_type& c);
+ complex_iter_base_(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_;
+ };
+
+
+ /* 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 <typename F, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_base_<F, E>& p);
+
+ } // end of mln::internal
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::complex_iter_base_()
+ {
+ // Ensure F and E are compatible.
+ mlc_equal(F, typename E::face)::check();
+
+ invalidate();
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::complex_iter_base_(complex_type& c)
+ {
+ // Ensure F and E are compatible.
+ mlc_equal(F, typename E::face)::check();
+
+ face_.set_cplx(c);
+ // Invalidate face_.
+ invalidate();
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::complex_iter_base_(const complex_iter_base_<F, E>& rhs)
+ : face_(rhs.face_)
+ {
+ // Ensure F and E are compatible.
+ mlc_equal(F, typename E::face)::check();
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>&
+ complex_iter_base_<F, E>::operator=(const complex_iter_base_<F, E>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ face_ = rhs.face_;
+ return *this;
+ }
+
+ template <typename F, typename E>
+ inline
+ bool
+ complex_iter_base_<F, E>::is_valid() const
+ {
+ return face_.is_valid();
+ }
+
+ template <typename F, typename E>
+ inline
+ void
+ complex_iter_base_<F, E>::invalidate()
+ {
+ face_.invalidate();
+ }
+
+ template <typename F, typename E>
+ inline
+ const F&
+ complex_iter_base_<F, E>::to_face() const
+ {
+ return face_;
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::operator F() const
+ {
+ mln_precondition(is_valid());
+ return face_;
+ }
+
+
+ template <typename F, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_base_<F, 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. */
+ F f = p;
+ return ostr << "(dim = " << f.n() << ", id = " << f.face_id() << ')';
+ }
+
+ } // end of mln::internal
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+#endif // ! MLN_CORE_INTERNAL_COMPLEX_ITER_BASE_HH
--
1.6.0.1
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
* 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
12 Sep '08
---
milena/ChangeLog | 4 ++++
milena/mln/core/concept/iterator.hh | 5 ++++-
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 474ee9d..0e9fac5 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+ * mln/core/concept/iterator.hh (for_all_2): Wrap a long line.
+
+2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+
* mln/core/face.hh: Add missing `inline' keywords.
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
diff --git a/milena/mln/core/concept/iterator.hh b/milena/mln/core/concept/iterator.hh
index d072329..26ae2ef 100644
--- a/milena/mln/core/concept/iterator.hh
+++ b/milena/mln/core/concept/iterator.hh
@@ -43,7 +43,10 @@
/*! \brief Loop to browse all the elements targetted by the couples of
* iterators \p x1 and \p x2.
*/
-# define for_all_2(x1, x2) for(x1.start(),x2.start(); x1.is_valid(); x1.next(),x2.next())
+# define for_all_2(x1, x2) \
+ for(x1.start(), x2.start(); \
+ x1.is_valid(); \
+ x1.next(), x2.next())
/*! \brief Loop to browse all the elements targetted by the triplet of
--
1.6.0.1
1
0
---
milena/ChangeLog | 4 ++++
milena/mln/core/face.hh | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index f4629b7..474ee9d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+ * mln/core/face.hh: Add missing `inline' keywords.
+
+2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+
Factor (more) iterators on complexes and faces.
* mln/core/internal/complex_iter_base.hh: New.
diff --git a/milena/mln/core/face.hh b/milena/mln/core/face.hh
index 9fd685a..4692d65 100644
--- a/milena/mln/core/face.hh
+++ b/milena/mln/core/face.hh
@@ -360,6 +360,7 @@ namespace mln
namespace internal
{
template <unsigned N, unsigned D>
+ inline
void
lower_dim_faces_mixin<N, D>::connect_lower_dim_face(const face_handle<N - 1, D>& f)
{
@@ -367,6 +368,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
higher_dim_faces_mixin<N, D>::connect_higher_dim_face(const face_handle<N + 1, D>& f)
{
@@ -381,6 +383,7 @@ namespace mln
`--------------*/
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>::face_handle()
: cplx_(0), face_id_(std::numeric_limits<unsigned>::max())
{
@@ -389,6 +392,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>::face_handle(complex<D>& c, unsigned face_id)
: cplx_(&c), face_id_(face_id)
{
@@ -397,6 +401,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>::face_handle(const face_handle<N, D>& rhs)
: cplx_(rhs.cplx_), face_id_(rhs.face_id_)
{
@@ -405,6 +410,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>&
face_handle<N, D>::operator=(const face_handle<N, D>& rhs)
{
@@ -417,6 +423,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
bool
face_handle<N, D>::is_valid() const
{
@@ -424,6 +431,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
face_handle<N, D>::invalidate()
{
@@ -431,6 +439,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
complex<D>&
face_handle<N, D>::cplx() const
{
@@ -439,6 +448,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
unsigned
face_handle<N, D>::n() const
{
@@ -446,6 +456,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
unsigned
face_handle<N, D>::face_id() const
{
@@ -453,6 +464,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
face_handle<N, D>::set_cplx(complex<D>& cplx)
{
@@ -460,6 +472,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
void
face_handle<N, D>::set_face_id(unsigned face_id)
{
@@ -467,6 +480,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
face<N, D>&
face_handle<N, D>::to_face() const
{
@@ -476,6 +490,7 @@ namespace mln
template <unsigned N, unsigned D>
+ inline
face_handle<N, D>
make_face_handle(const complex<D>& c, unsigned face_id)
{
@@ -483,6 +498,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
bool
operator==(const face_handle<N, D>& lhs, const face_handle<N, D>& rhs)
{
@@ -492,6 +508,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
bool
operator< (const face_handle<N, D>& lhs, const face_handle<N, D>& rhs)
{
@@ -506,6 +523,7 @@ namespace mln
`---------------*/
template <unsigned N, unsigned D>
+ inline
void
faces_set<N, D>::add(const face_handle<N, D>& f)
{
@@ -516,6 +534,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
const std::vector< face_handle<N, D> >&
faces_set<N, D>::faces() const
{
@@ -524,6 +543,7 @@ namespace mln
template <unsigned N, unsigned D>
+ inline
faces_set<N, D>
operator+(const face_handle<N, D>& f1, const face_handle<N, D>& f2)
{
@@ -534,6 +554,7 @@ namespace mln
}
template <unsigned N, unsigned D>
+ inline
faces_set<N, D>
operator+(const faces_set<N, D>& fs, const face_handle<N, D>& f)
{
@@ -548,6 +569,7 @@ namespace mln
`----------------------*/
template <unsigned D>
+ inline
any_face_handle<D>::any_face_handle()
: cplx_(0),
n_(std::numeric_limits<unsigned>::max()),
@@ -556,6 +578,7 @@ namespace mln
}
template <unsigned D>
+ inline
any_face_handle<D>::any_face_handle(complex<D>& c, unsigned n,
unsigned face_id)
: cplx_(&c), n_(n), face_id_(face_id)
@@ -566,6 +589,7 @@ namespace mln
template <unsigned D>
template <unsigned N>
+ inline
any_face_handle<D>::any_face_handle(const face_handle<N, D>& f)
: cplx_(&f.cplx()), n_(N), face_id_(f.face_id())
{
@@ -575,12 +599,14 @@ namespace mln
}
template <unsigned D>
+ inline
any_face_handle<D>::any_face_handle(const any_face_handle<D>& rhs)
: cplx_(rhs.cplx_), n_(rhs.n_), face_id_(rhs.face_id_)
{
}
template <unsigned D>
+ inline
any_face_handle<D>&
any_face_handle<D>::operator=(const any_face_handle<D>& rhs)
{
@@ -594,6 +620,7 @@ namespace mln
}
template <unsigned D>
+ inline
bool
any_face_handle<D>::is_valid() const
{
@@ -601,6 +628,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::invalidate()
{
@@ -609,6 +637,7 @@ namespace mln
}
template <unsigned D>
+ inline
complex<D>&
any_face_handle<D>::cplx() const
{
@@ -617,6 +646,7 @@ namespace mln
}
template <unsigned D>
+ inline
unsigned
any_face_handle<D>::n() const
{
@@ -624,6 +654,7 @@ namespace mln
}
template <unsigned D>
+ inline
unsigned
any_face_handle<D>::face_id() const
{
@@ -631,6 +662,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::set_cplx(complex<D>& cplx)
{
@@ -638,6 +670,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::set_n(unsigned n)
{
@@ -645,6 +678,7 @@ namespace mln
}
template <unsigned D>
+ inline
void
any_face_handle<D>::set_face_id(unsigned face_id)
{
@@ -653,6 +687,7 @@ namespace mln
template <unsigned D>
template <unsigned N>
+ inline
face<N, D>&
any_face_handle<D>::to_face() const
{
@@ -663,6 +698,7 @@ namespace mln
template <unsigned D>
+ inline
bool
operator==(const any_face_handle<D>& lhs, const any_face_handle<D>& rhs)
{
@@ -674,6 +710,7 @@ namespace mln
}
template <unsigned D>
+ inline
bool
operator< (const any_face_handle<D>& lhs, const any_face_handle<D>& rhs)
{
--
1.6.0.1
1
0
* mln/core/internal/complex_iter_base.hh: New.
* mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
Remove.
(mln::internal::complex_fwd_iter_<D>)
(mln::internal::complex_bkd_iter_<D>):
Inherit from mln::internal::complex_iter_base_.
Adjust.
* mln/core/faces_iter.hh (mln::internal::faces_iter_<N, D, E>):
Remove.
(mln::internal::faces_fwd_iter_<N, D>)
(mln::internal::faces_bkd_iter_<N, D>):
Inherit from mln::internal::complex_iter_base_.
Adjust.
* mln/core/face.hh (mln::face_handle<N, D>::n): New accessor.
(mln::face_handle<N, D>::complex_type)
(mln::any_face_handle<D>::complex_type):
New typedefs.
(mln::face_handle<N, D>::invalidate)
(mln::any_face_handle<D>::invalidate):
New methods.
---
milena/ChangeLog | 25 +++
milena/mln/core/complex_iter.hh | 219 ++----------------------
milena/mln/core/face.hh | 35 ++++
milena/mln/core/faces_iter.hh | 215 ++----------------------
milena/mln/core/internal/complex_iter_base.hh | 214 ++++++++++++++++++++++++
5 files changed, 310 insertions(+), 398 deletions(-)
create mode 100644 milena/mln/core/internal/complex_iter_base.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index f164de6..f4629b7 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,30 @@
2008-09-12 Roland Levillain <roland(a)lrde.epita.fr>
+ Factor (more) iterators on complexes and faces.
+
+ * mln/core/internal/complex_iter_base.hh: New.
+ * mln/core/complex_iter.hh (mln::internal::complex_iter_<D, E>):
+ Remove.
+ (mln::internal::complex_fwd_iter_<D>)
+ (mln::internal::complex_bkd_iter_<D>):
+ Inherit from mln::internal::complex_iter_base_.
+ Adjust.
+ * mln/core/faces_iter.hh (mln::internal::faces_iter_<N, D, E>):
+ Remove.
+ (mln::internal::faces_fwd_iter_<N, D>)
+ (mln::internal::faces_bkd_iter_<N, D>):
+ Inherit from mln::internal::complex_iter_base_.
+ Adjust.
+ * mln/core/face.hh (mln::face_handle<N, D>::n): New accessor.
+ (mln::face_handle<N, D>::complex_type)
+ (mln::any_face_handle<D>::complex_type):
+ New typedefs.
+ (mln::face_handle<N, D>::invalidate)
+ (mln::any_face_handle<D>::invalidate):
+ New methods.
+
+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.
diff --git a/milena/mln/core/complex_iter.hh b/milena/mln/core/complex_iter.hh
index 4aa9b99..3dcb445 100644
--- a/milena/mln/core/complex_iter.hh
+++ b/milena/mln/core/complex_iter.hh
@@ -31,95 +31,11 @@
/// \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>
+# include <mln/core/internal/complex_iter_base.hh>
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>. |
`-----------------------*/
@@ -129,10 +45,15 @@ namespace mln
/// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
class complex_fwd_iter_
- : public internal::complex_iter_< D, complex_fwd_iter_<D> >
+ : public internal::complex_iter_base_< any_face_handle<D>,
+ complex_fwd_iter_<D> >
{
+ public:
+ typedef any_face_handle<D> face;
+
+ private:
typedef complex_fwd_iter_<D> self_;
- typedef internal::complex_iter_< D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -142,7 +63,7 @@ namespace mln
/// Construction and assignment.
/// \{
complex_fwd_iter_();
- // FIXME: See above (internal::complex_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
complex_fwd_iter_(complex<D>& c);
complex_fwd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -174,10 +95,15 @@ namespace mln
/// \arg \p D The dimension of the complex this iterator belongs to.
template <unsigned D>
class complex_bkd_iter_
- : public internal::complex_iter_< D, complex_bkd_iter_<D> >
+ : public internal::complex_iter_base_< any_face_handle<D>,
+ complex_bkd_iter_<D> >
{
+ public:
+ typedef any_face_handle<D> face;
+
+ private:
typedef complex_bkd_iter_<D> self_;
- typedef internal::complex_iter_< D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -187,7 +113,7 @@ namespace mln
/// Construction and assignment.
/// \{
complex_bkd_iter_();
- // FIXME: See above (internal::complex_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
complex_bkd_iter_(complex<D>& c);
complex_bkd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -213,113 +139,6 @@ namespace mln
# 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
-
-
/*-----------------------.
| complex_fwd_iter_<D>. |
`-----------------------*/
@@ -334,6 +153,7 @@ namespace mln
template <unsigned D>
inline
complex_fwd_iter_<D>::complex_fwd_iter_(complex<D>& c)
+ : super_(c)
{
set_cplx(c);
mln_postcondition(!is_valid());
@@ -413,8 +233,6 @@ namespace mln
| complex_bkd_iter_<D>. |
`-----------------------*/
- // FIXME: Resume here.
-
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_()
@@ -425,6 +243,7 @@ namespace mln
template <unsigned D>
inline
complex_bkd_iter_<D>::complex_bkd_iter_(complex<D>& c)
+ : super_(c)
{
set_cplx(c);
mln_postcondition(!is_valid());
diff --git a/milena/mln/core/face.hh b/milena/mln/core/face.hh
index 4e8e958..9fd685a 100644
--- a/milena/mln/core/face.hh
+++ b/milena/mln/core/face.hh
@@ -143,6 +143,9 @@ namespace mln
template <unsigned N, unsigned D>
struct face_handle
{
+ // The type of the complex this handle points to.
+ typedef complex<D> complex_type;
+
/// Build a non-initialized face handle.
face_handle();
/// Build a face handle from \a complex and \a face_id.
@@ -156,6 +159,8 @@ namespace mln
/// Is this handle valid?
bool is_valid() const;
+ /// Invalidate this handle.
+ void invalidate();
/// Accessors.
/// \{
@@ -167,6 +172,9 @@ namespace mln
/// Set the complex the face belongs to.
void set_cplx(complex<D>& cplx);
+ /// Return the dimension of the face.
+ // FIXME: Rename as `dim'?
+ unsigned n() const;
/// Set the id of the face.
void set_face_id(unsigned face_id);
@@ -259,6 +267,9 @@ namespace mln
template <unsigned D>
struct any_face_handle
{
+ // The type of the complex this handle points to.
+ typedef complex<D> complex_type;
+
/// Build a non-initialized face handle.
any_face_handle();
/// Build a face handle from \a complex and \a face_id.
@@ -276,6 +287,8 @@ namespace mln
/// Is this handle valid?
bool is_valid() const;
+ /// Invalidate this handle.
+ void invalidate();
/// Accessors.
/// \{
@@ -411,6 +424,13 @@ namespace mln
}
template <unsigned N, unsigned D>
+ void
+ face_handle<N, D>::invalidate()
+ {
+ set_face_id(std::numeric_limits<unsigned>::max());
+ }
+
+ template <unsigned N, unsigned D>
complex<D>&
face_handle<N, D>::cplx() const
{
@@ -420,6 +440,13 @@ namespace mln
template <unsigned N, unsigned D>
unsigned
+ face_handle<N, D>::n() const
+ {
+ return N;
+ }
+
+ template <unsigned N, unsigned D>
+ unsigned
face_handle<N, D>::face_id() const
{
return face_id_;
@@ -574,6 +601,14 @@ namespace mln
}
template <unsigned D>
+ void
+ any_face_handle<D>::invalidate()
+ {
+ set_n(std::numeric_limits<unsigned>::max());
+ set_face_id(std::numeric_limits<unsigned>::max());
+ }
+
+ template <unsigned D>
complex<D>&
any_face_handle<D>::cplx() const
{
diff --git a/milena/mln/core/faces_iter.hh b/milena/mln/core/faces_iter.hh
index 25dd2c2..e11073d 100644
--- a/milena/mln/core/faces_iter.hh
+++ b/milena/mln/core/faces_iter.hh
@@ -32,99 +32,11 @@
/// \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>
+# include <mln/core/internal/complex_iter_base.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>. |
`------------------------*/
@@ -135,10 +47,15 @@ namespace mln
/// \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> >
+ : public internal::complex_iter_base_< face_handle<N, D>,
+ faces_fwd_iter_<N, D> >
{
+ public:
+ typedef face_handle<N, D> face;
+
+ private:
typedef faces_fwd_iter_<N, D> self_;
- typedef internal::faces_iter_< N, D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -147,7 +64,7 @@ namespace mln
public:
/// Construction and assignment.
/// \{
- // FIXME: See above (internal::faces_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
faces_fwd_iter_(complex<D>& c);
faces_fwd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -176,10 +93,15 @@ namespace mln
/// \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> >
+ : public internal::complex_iter_base_< face_handle<N, D>,
+ faces_bkd_iter_<N, D> >
{
+ public:
+ typedef face_handle<N, D> face;
+
+ private:
typedef faces_bkd_iter_<N, D> self_;
- typedef internal::faces_iter_< N, D, self_ > super_;
+ typedef internal::complex_iter_base_< face, self_ > super_;
public:
using super_::is_valid;
@@ -188,7 +110,7 @@ namespace mln
public:
/// Construction and assignment.
/// \{
- // FIXME: See above (internal::faces_iter_'s default ctor).
+ // FIXME: See above (internal::complex_iter_base_'s default ctor).
faces_bkd_iter_(complex<D>& c);
faces_bkd_iter_(const self_& rhs);
self_& operator= (const self_& rhs);
@@ -210,109 +132,6 @@ namespace mln
# 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>. |
`------------------------*/
diff --git a/milena/mln/core/internal/complex_iter_base.hh b/milena/mln/core/internal/complex_iter_base.hh
new file mode 100644
index 0000000..df9b39a
--- /dev/null
+++ b/milena/mln/core/internal/complex_iter_base.hh
@@ -0,0 +1,214 @@
+// 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_INTERNAL_COMPLEX_ITER_BASE_HH
+# define MLN_CORE_INTERNAL_COMPLEX_ITER_BASE_HH
+
+/// \file mln/core/complex_iter_base.hh
+/// \brief Definition of an implementation (factoring) class for
+/// iterators on complexes.
+
+# include <limits>
+
+# include <mln/metal/equal.hh>
+
+# include <mln/core/concept/iterator.hh>
+# include <mln/core/complex.hh>
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <unsigned D> class complex;
+
+ namespace internal
+ {
+ /// \brief Factoring classe for iterators on complexes.
+ ///
+ /// \arg \p F The type of the face handle.
+ /// \arg \p E The type exact type of the iterator.
+ template <typename F, typename E>
+ class complex_iter_base_ : public Iterator<E>
+ {
+ typedef complex_iter_base_<F, E> self_;
+
+ public:
+ typedef F face;
+ typedef typename F::complex_type complex_type;
+
+ /// Construction and assignment.
+ /// \{
+ /* FIXME: Keep this non-const? See a (big) comment about this in
+ milena/tests/complex_image.cc. */
+ complex_iter_base_();
+ complex_iter_base_(complex_type& c);
+ complex_iter_base_(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_;
+ };
+
+
+ /* 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 <typename F, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_base_<F, E>& p);
+
+ } // end of mln::internal
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::complex_iter_base_()
+ {
+ // Ensure F and E are compatible.
+ mlc_equal(F, typename E::face)::check();
+
+ invalidate();
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::complex_iter_base_(complex_type& c)
+ {
+ // Ensure F and E are compatible.
+ mlc_equal(F, typename E::face)::check();
+
+ face_.set_cplx(c);
+ // Invalidate face_.
+ invalidate();
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::complex_iter_base_(const complex_iter_base_<F, E>& rhs)
+ : face_(rhs.face_)
+ {
+ // Ensure F and E are compatible.
+ mlc_equal(F, typename E::face)::check();
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>&
+ complex_iter_base_<F, E>::operator=(const complex_iter_base_<F, E>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ face_ = rhs.face_;
+ return *this;
+ }
+
+ template <typename F, typename E>
+ inline
+ bool
+ complex_iter_base_<F, E>::is_valid() const
+ {
+ return face_.is_valid();
+ }
+
+ template <typename F, typename E>
+ inline
+ void
+ complex_iter_base_<F, E>::invalidate()
+ {
+ face_.invalidate();
+ }
+
+ template <typename F, typename E>
+ inline
+ const F&
+ complex_iter_base_<F, E>::to_face() const
+ {
+ return face_;
+ }
+
+ template <typename F, typename E>
+ inline
+ complex_iter_base_<F, E>::operator F() const
+ {
+ mln_precondition(is_valid());
+ return face_;
+ }
+
+
+ template <typename F, typename E>
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const complex_iter_base_<F, 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. */
+ F f = p;
+ return ostr << "(dim = " << f.n() << ", id = " << f.face_id() << ')';
+ }
+
+ } // end of mln::internal
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+#endif // ! MLN_CORE_INTERNAL_COMPLEX_ITER_BASE_HH
--
1.6.0.1
1
0
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-09-12 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add fast arbitrary erosion.
* mln/morpho/erosion.hh: (erosion_arbitrary_2d_fastest) New, erosion
on fast images with an arbitrary window using min_h and the snake
browsing.
(erosion_arbitrary_2d_fastest) New, erosion on non-fast images with an
arbitrary window using min_h and the snake browsing.
* mln/morpho/erosion.spe.hh: Dummy fix.
---
erosion.hh | 4
erosion.spe.hh | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 228 insertions(+), 30 deletions(-)
Index: branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh
===================================================================
--- branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2248)
+++ branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2249)
@@ -34,6 +34,10 @@
# include <mln/win/octagon2d.hh>
# include <mln/win/rectangle2d.hh>
+# include <mln/geom/shift.hh>
+# include <mln/accu/min_h.hh>
+# include <mln/set/diff.hh>
+# include <mln/canvas/browsing/snake_fwd.hh>
/*! \file mln/morpho/erosion.spe.hh
@@ -57,30 +61,10 @@
erosion(const Image<I>& input, const Window<W>& win);
- namespace internal
- {
- template <typename I, typename W>
- mln_concrete(I)
- erosion_dispatch(const Image<I>& input, const Window<W>& win)
- {
- if (mlc_equal(mln_trait_image_kind(I)(),
- trait::image::kind::logic)::value == true)
- if (mlc_equal(mln_trait_image_speed(I)(),
- trait::image::speed::fastest)::value == true)
- impl::erosion_on_set_fastest(input, win);
- else
- impl::generic::erosion_on_set(input, win);
- else
- if (mlc_equal(mln_trait_image_speed(I)(),
- trait::image::speed::fastest)::value == true)
- impl::erosion_on_function_fastest(input, win);
- else
- impl::generic::erosion_on_function(input, win);
- }
-
namespace impl
{
+
namespace generic
{
// Fwd decl.
@@ -143,6 +127,7 @@
mln_pixter(const I) p(input);
mln_pixter(O) p_out(output);
+ mln_qixter(const I, W) q(p, win);
for_all_2(p, p_out)
{
for_all(q)
@@ -220,14 +205,11 @@
template <typename I>
inline
mln_concrete(I)
- erosion_rectangle2d(const Image<I>& input_, const Window<W>& win_)
+ erosion_rectangle2d(const Image<I>& input_, const win::rectangle2d& win)
{
- mlc_equal(W, win::rectangle2d)::check();
-
trace::entering("morpho::impl::erosion_rectangle2d");
const I& input = exact(input_);
- const W& win = exact(win_);
mln_concrete(I) temp, output;
temp = morpho::erosion(input, win::hline2d(win.width()));
@@ -241,11 +223,12 @@
template <typename I>
inline
mln_concrete(I)
- erosion_octagon2d(const I& input, const win::octagon2d& win)
+ erosion_octagon2d(const Image<I>& input_, const win::octagon2d& win)
{
- mlc_equal(W, win::octagon2d)::check();
-
trace::entering("morpho::impl::erosion_octagon2d");
+
+ const I& input = exact(input_);
+
const unsigned len = win.length() / 3 + 1;
mln_concrete(I) temp_1, temp_2, output;
@@ -258,8 +241,223 @@
return output;
}
+ template <typename I, typename W>
+ struct erosion_arbitrary_2d_fastest_functor
+ {
+ const I& input;
+ const W& win;
+ mln_concrete(I) output;
+ accu::min_h<mln_value(I)> min;
+
+ mln_psite(I) p;
+
+ window2d
+ win_left,
+ win_right,
+ win_bot,
+ win_top;
+
+ mln_qixter(const I, window2d)
+ q_l,
+ q_r,
+ q_top,
+ q_bot;
+
+ erosion_arbitrary_2d_fastest_functor(const I& input, const W& win)
+ : input(input),
+ win(win),
+ min(input.values()),
+ win_left(set::diff(geom::shift(win, left), win)),
+ win_right(set::diff(win, geom::shift(win, left))),
+ win_bot(set::diff(win, geom::shift(win, up))),
+ win_top(set::diff(geom::shift(win, up), win)),
+ q_l(input, win_left, p),
+ q_r(input, win_right, p),
+ q_top(input, win_top, p),
+ q_bot(input, win_bot, p)
+ { }
+
+ void init()
+ {
+ initialize(output, input);
+ min.init();
+ p = input.domain().pmin() + up;
+ mln_qixter(const I, W) q(input, win, p);
+ for_all(q)
+ min.take(q.val());
+ }
+
+ void fwd()
+ {
+ ++p.col();
+ for_all(q_l)
+ min.untake(q_l.val());
+ for_all(q_r)
+ min.take(q_r.val());
+ output(p) = min;
+ }
+
+ void bkd()
+ {
+ --p.col();
+ for_all(q_r)
+ min.untake(q_r.val());
+ for_all(q_l)
+ min.take(q_l.val());
+ output(p) = min;
+ }
+
+ void down()
+ {
+ ++p.row();
+ for_all(q_top)
+ min.untake(q_top.val());
+ for_all(q_bot)
+ min.take(q_bot.val());
+ output(p) = min;
+ }
+
+ };
+
+ template <typename I, typename W>
+ inline
+ mln_concrete(I)
+ erosion_arbitrary_2d_fastest(const Image<I>& input, const Window<W>& win)
+ {
+ trace::entering("morpho::impl:erosion_arbitrary_2d_fastest");
+
+ typedef erosion_arbitrary_2d_fastest_functor<I, W> F;
+ mlc_equal(W, win::octagon2d)::check();
+ F f(input, win);
+ canvas::browsing::snake_fwd(f);
+
+ trace::exiting("morpho::impl:erosion_arbitrary_2d_fastest");
+
+ return f.output;
+ }
+
+
+ template <typename I, typename W>
+ struct erosion_arbitrary_2d_functor
+ {
+ const I& input;
+ const W& win;
+ mln_concrete(I) output;
+ accu::min_h<mln_value(I)> min;
+
+ mln_psite(I) p;
+
+ window2d
+ win_left,
+ win_right,
+ win_bot,
+ win_top;
+
+ mln_qiter(window2d)
+ q_l,
+ q_r,
+ q_top,
+ q_bot;
+
+ erosion_arbitrary_2d_functor(const I& input, const W& win)
+ : input(input),
+ win(win),
+ min(input.values()),
+ win_left(set::diff(geom::shift(win, left), win)),
+ win_right(set::diff(win, geom::shift(win, left))),
+ win_bot(set::diff(win, geom::shift(win, up))),
+ win_top(set::diff(geom::shift(win, up), win)),
+ q_l(win_left, p),
+ q_r(win_right, p),
+ q_top(win_top, p),
+ q_bot(win_bot, p)
+ { }
+
+ void init()
+ {
+ initialize(output, input);
+ min.init();
+ p = input.domain().pmin() + up;
+ mln_qiter(W) q(win, p);
+ for_all(q)
+ min.take(input(q));
+ }
+
+ void fwd()
+ {
+ ++p.col();
+ for_all(q_l)
+ min.untake(input(q_l));
+ for_all(q_r)
+ min.take(input(q_r));
+ output(p) = min;
+ }
+
+ void bkd()
+ {
+ --p.col();
+ for_all(q_r)
+ min.untake(input(q_r));
+ for_all(q_l)
+ min.take(input(q_l));
+ output(p) = min;
+ }
+
+ void down()
+ {
+ ++p.row();
+ for_all(q_top)
+ min.untake(input(q_top));
+ for_all(q_bot)
+ min.take(input(q_bot));
+ output(p) = min;
+ }
+
+ };
+
+ template <typename I, typename W>
+ inline
+ mln_concrete(I)
+ erosion_arbitrary_2d(const Image<I>& input, const Window<W>& win)
+ {
+ trace::entering("morpho::impl:erosion_arbitrary_2d");
+
+ typedef erosion_arbitrary_2d_functor<I, W> F;
+ mlc_equal(W, win::octagon2d)::check();
+ F f(input, win);
+ canvas::browsing::snake_fwd(f);
+
+ trace::exiting("morpho::impl:erosion_arbitrary_2d");
+
+ return f.output;
+ }
+
} // end of namespace mln::morpho::impl
+
+ namespace internal
+ {
+ template <typename I, typename W>
+ mln_concrete(I)
+ erosion_dispatch(const Image<I>& input, const Window<W>& win)
+ {
+ if (mlc_equal(mln_trait_image_kind(I)(),
+ trait::image::kind::logic)::value == true)
+ if (mlc_equal(mln_trait_image_speed(I)(),
+ trait::image::speed::fastest)::value == true)
+ impl::erosion_on_set_fastest(input, win);
+ else
+ impl::generic::erosion_on_set(input, win);
+ else
+ if (mlc_equal(mln_trait_image_speed(I)(),
+ trait::image::speed::fastest)::value == true)
+ impl::erosion_on_function_fastest(input, win);
+ else
+ impl::generic::erosion_on_function(input, win);
+ }
+
+ } // end of namespace mln::morpho::internal
+
} // end of namespace mln::morpho
} // end of namespace mln
Index: branches/cleanup-2008/milena/mln/morpho/erosion.hh
===================================================================
--- branches/cleanup-2008/milena/mln/morpho/erosion.hh (revision 2248)
+++ branches/cleanup-2008/milena/mln/morpho/erosion.hh (revision 2249)
@@ -63,7 +63,7 @@
template <typename I, typename W>
inline
mln_concrete(I)
- erosion_on_function(const Image<I>& input_, const Window<W>& win_);
+ erosion_on_function(const Image<I>& input_, const Window<W>& win_)
{
trace::entering("morpho::impl::generic::erosion_on_function");
@@ -93,7 +93,7 @@
template <typename I, typename W>
inline
mln_concrete(I)
- erosion_on_set(const Image<I>& input_, const Window<W>& win_);
+ erosion_on_set(const Image<I>& input_, const Window<W>& win_)
{
trace::entering("morpho::impl::generic::erosion_on_set");
1
0
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Start a multiple window class.
* doc/tutorial/examples/win_multiple.cc: New.
* mln/core/internal/site_relative_iterator_base.hh: .
* mln/win/multiple.hh: New.
doc/tutorial/examples/win_multiple.cc | 59 ++++++
mln/core/internal/site_relative_iterator_base.hh | 6
mln/win/multiple.hh | 194 +++++++++++------------
3 files changed, 162 insertions(+), 97 deletions(-)
Index: doc/tutorial/examples/win_multiple.cc
--- doc/tutorial/examples/win_multiple.cc (revision 0)
+++ doc/tutorial/examples/win_multiple.cc (revision 0)
@@ -0,0 +1,59 @@
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/window2d.hh>
+# include <mln/win/multiple.hh>
+
+# include <mln/debug/iota.hh>
+# include <mln/debug/println.hh>
+
+# include <mln/core/alias/neighb2d.hh>
+
+
+
+template <typename I, typename W>
+void browse(const I& ima, const W& win)
+{
+ mln_fwd_piter(I) p(ima.domain());
+ mln_fwd_qiter(W) q(win, p);
+ for_all(p)
+ {
+ std::cout << ima(p) << ": ";
+ for_all(q)
+ if (ima.has(q))
+ std::cout << ima(q) << ' ';
+ std::cout << std::endl;
+ }
+}
+
+
+struct row_oddity
+{
+ unsigned operator()(const mln::point2d& p) const
+ {
+ return p.row() % 2;
+ }
+};
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<unsigned> I;
+ I ima(3, 3, 0); // no border
+ debug::iota(ima);
+ debug::println(ima);
+
+ win::multiple<2, window2d, row_oddity> w;
+
+ bool vert[] = { 0, 1, 0,
+ 0, 0, 0,
+ 0, 1, 0 };
+ w.set_window(0, make::window2d(vert));
+ bool horiz[] = { 0, 0, 0,
+ 1, 0, 1,
+ 0, 0, 0 };
+ w.set_window(1, make::window2d(horiz));
+
+ browse(ima, w);
+
+}
Index: mln/core/internal/site_relative_iterator_base.hh
--- mln/core/internal/site_relative_iterator_base.hh (revision 2247)
+++ mln/core/internal/site_relative_iterator_base.hh (working copy)
@@ -35,6 +35,8 @@
*
* \todo Add a method to get the site set (if the center is defined) or
* the site set at a given center.
+ *
+ * \todo In start_ and next_, think about the commented code...
*/
# include <vector>
@@ -143,6 +145,8 @@
exact(this)->do_start_();
if (this->is_valid())
p_ = exact(this)->compute_p_();
+// else
+// exact(this)->invalidate();
}
template <typename S, typename E>
@@ -153,6 +157,8 @@
exact(this)->do_next_();
if (this->is_valid())
p_ = exact(this)->compute_p_();
+// else
+// exact(this)->invalidate();
}
template <typename S, typename E>
Index: mln/win/multiple.hh
--- mln/win/multiple.hh (revision 2245)
+++ mln/win/multiple.hh (working copy)
@@ -1,167 +1,167 @@
-# include <mln/core/concept/neighborhood.hh>
+// 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_WIN_MULTIPLE_HH
+# define MLN_WIN_MULTIPLE_HH
+
+/*! \file mln/win/multiple.hh
+ *
+ * \brief Definition of a multiple window.
+ */
+
+# include <mln/core/internal/window_base.hh>
+# include <mln/core/internal/site_relative_iterator_base.hh>
+
namespace mln
{
+ namespace win
+ {
- // Fwd decl.
- template <typename D, typename F> class dbl_niter_;
+ // Forward declaration.
+ template <unsigned n, typename W, typename F> class multiple_qiter;
- template <typename D, typename F>
- struct dbl_neighb_ : public Neighborhood< dbl_neighb_<D,F> >
+ template <unsigned n, typename W, typename F>
+ class multiple : public internal::window_base< mln_dpsite(W), multiple<n,W,F> >
{
- typedef D dpoint;
- typedef mln_point(D) point;
+ public:
- typedef dbl_niter_<D,F> fwd_niter;
- typedef dbl_niter_<D,F> bkd_niter;
- typedef dbl_niter_<D,F> niter;
+ typedef mln_dpsite(W) dpsite;
+ typedef mln_psite(W) psite;
+ typedef mln_site(W) site;
- dbl_neighb_(F f)
- : f(f)
- {
- }
+ typedef multiple_qiter<n,W,F> fwd_qiter;
+ typedef multiple_qiter<n,W,F> bkd_qiter;
+ typedef multiple_qiter<n,W,F> qiter;
- dbl_neighb_()
- : f()
+ multiple()
+ : f_()
{
}
- bool is_empty() const
+ multiple(const F& f)
+ : f_(f)
{
- return trues.size() == 0 && falses.size() == 0;
}
- dbl_neighb_& insert_true(const D& dp)
+ bool is_empty() const
{
- trues.push_back(dp);
- trues.push_back(-dp);
- return *this;
+ bool res = false;
+ for (unsigned i = 0; i < n; ++i)
+ if (win_[i].is_empty())
+ return true;
+ return res;
}
- dbl_neighb_& insert_false(const D& dp)
+ void set_window(unsigned i, const W& win)
{
- falses.push_back(dp);
- falses.push_back(-dp);
- return *this;
+ mln_precondition(i < n);
+ win_[i] = win;
}
- template <typename N>
- dbl_neighb_& when_true(const Neighborhood<N>& nbh_)
+ const W& window(unsigned i) const
{
- const N& nbh = exact(nbh_);
- for (unsigned i = 0; i < nbh.size(); ++i)
- trues.push_back(nbh.dp(i));
- return *this;
+ mln_precondition(i < n);
+ return win_[i];
}
- template <typename N>
- dbl_neighb_& when_false(const Neighborhood<N>& nbh_)
+ const F& fun() const
{
- const N& nbh = exact(nbh_);
- for (unsigned i = 0; i < nbh.size(); ++i)
- falses.push_back(nbh.dp(i));
- return *this;
+ return f_;
}
- std::vector<D> trues, falses;
- F f;
+ private:
+ W win_[n];
+ F f_;
};
- template <typename D, typename F>
- class dbl_niter_
- : public internal::point_iterator_base_< mln_point(D), dbl_niter_<D,F> >
+ template <unsigned n, typename W, typename F>
+ class multiple_qiter
+ : public internal::site_relative_iterator_base< multiple<n,W,F>,
+ multiple_qiter<n,W,F> >
{
public:
- typedef mln_point(D) point;
-
- template <typename Pref>
- dbl_niter_(const Neighborhood< dbl_neighb_<D,F> >& nbh,
- const Point_Site<Pref>& p_ref) :
- dps_true(exact(nbh).trues),
- dps_false(exact(nbh).falses),
- p_ref_(exact(p_ref).to_point()),
- f(exact(nbh).f)
+ multiple_qiter()
{
- invalidate();
}
- /// Conversion to point.
- operator point () const
+ template <typename P>
+ multiple_qiter(const multiple<n,W,F>& w, const P& c)
{
- mln_precondition(is_valid());
- return p_;
- }
-
- /// Reference to the corresponding point.
- const point& to_point() const
- {
- return p_;
+ this->change_target(w);
+ this->center_at(c);
}
/// Test the iterator validity.
- bool is_valid() const
+ bool is_valid_() const
{
- return i_ != dps_true.size();
+ return i_ != -1;
}
/// Invalidate the iterator.
- void invalidate()
+ void invalidate_()
{
- i_ = dps_true.size();
+ i_ = -1;
}
/// Start an iteration.
- void start()
+ void do_start_()
{
i_ = 0;
- update();
}
/// Go to the next point.
- void next_()
+ void do_next_()
{
++i_;
- update();
- }
-
- /// Give the i-th coordinate.
- int operator[](unsigned i) const
- {
- mln_precondition(is_valid());
- return p_[i];
}
- /// The point around which this iterator moves.
- const point& center_point() const
+ /// Compute the current psite.
+ mln_psite(W) compute_p_() const
{
- return p_ref_;
+ unsigned w = this->s_->fun()(*this->c_);
+ return *this->c_ + this->s_->window(w).std_vector()[i_];
}
- /// Force this iterator to update its location to take into
- /// account that its center point may have moved.
- void update()
- {
- if (is_valid())
- p_ = p_ref_ + (f(p_ref_) ? dps_true[i_] : dps_false[i_]);
- }
+ private:
+ int i_;
+ };
- protected:
- const std::vector<D>& dps_true, dps_false;
- const point& p_ref_; // reference point (or "center point")
- F f;
- unsigned i_;
- point p_; // location of this iterator; p_ makes this iterator be
- // itself a potential center point.
- };
+ } // end of namespace mln::win
+} // end of namespace mln
-} // mln
+#endif // ! MLN_WIN_MULTIPLE_HH
1
0