---
milena/ChangeLog | 4 +++
milena/tests/core/image/complex_image.cc | 34 ++++++++++++++++++++++++++---
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 743cc09..f4e7d20 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2008-09-24 Roland Levillain <roland(a)lrde.epita.fr>
+ * tests/core/image/complex_image.cc: Exercise iterators on p_faces.
+
+2008-09-24 Roland Levillain <roland(a)lrde.epita.fr>
+
Add iterators on p_faces.
* mln/core/site_set/p_faces_piter.hh: New.
diff --git a/milena/tests/core/image/complex_image.cc b/milena/tests/core/image/complex_image.cc
index 39e6239..1b06036 100644
--- a/milena/tests/core/image/complex_image.cc
+++ b/milena/tests/core/image/complex_image.cc
@@ -141,24 +141,48 @@ int main()
| Complex-based image iterators. |
`--------------------------------*/
+ // ---------------------------- //
+ // Iterators on all the faces. //
+ // ---------------------------- //
+
mln_fwd_piter_(ima_t) fp(ima.domain());
for_all(fp)
std::cout << "ima(" << fp << ") = " << ima(fp) << std::endl;
-
std::cout << std::endl;
mln_bkd_piter_(ima_t) bp(ima.domain());
for_all(bp)
std::cout << "ima(" << bp << ") = " << ima(bp) << std::endl;
+ std::cout << std::endl;
+
+
+ // ----------------------------------------------- //
+ // Iterators on n-faces (with n fixed in [0, D]). //
+ // ----------------------------------------------- //
+
+ // We need to instantiate a (non temporary) object on the stack, so
+ // that it can be referenced later by face_psites held by iterators
+ // (as for windows and neighborhoods).
+
+ typedef p_faces<0, D, point2d> p0f_t;
+ p0f_t pf(ima.domain());
+ mln_piter_(p0f_t) f0p(pf);
+ for_all(f0p)
+ /* FIXME: This explicit call to unproxy_() is not elegant... But
+ is required for ima() to work, since the target operator() is
+ templated. */
+ std::cout << "ima(" << f0p << ") = " << ima(f0p.unproxy_()) << std::endl;
/* FIXME: Implement other psite iterators, for instance:
- - iterators on N-faces with N fixed in [0, D] (using p_faces
- and faces_psite?)
- iterators on N-faces with N in a subset of [0, D];
- etc. */
+ // ---------------------------------------- //
+ // Iterators on windows and neighborhoods. //
+ // ---------------------------------------- //
+
/* FIXME: Implement windows (and neighborhoods) and corresponding
iterators for complex-based images.
@@ -188,5 +212,7 @@ int main()
- what else?
We might want to look at operators on (simplicial?) complexes
- like star, link, etc. and possibly implement them. */
+ like star, link, etc. and possibly implement them.
+
+ See also https://trac.lrde.org/olena/ticket/162. */
}
--
1.6.0.1
* mln/core/site_set/p_faces_piter.hh: New.
Add forward declarations for these iterators...
* mln/core/site_set/p_faces.hh: ...here.
(mln::p_faces<N,D,P>::fwd_piter): Set to p_faces_fwd_piter_<N,D,P>.
(mln::p_faces<N,D,P>::bkd_piter): Set to p_faces_bkd_piter_<N,D,P>.
(mln::p_faces<N, D, P>::p_faces(const p_complex<D, P>&)):
New ctor.
---
milena/ChangeLog | 12 +++
milena/mln/core/site_set/p_faces.hh | 32 +++++--
milena/mln/core/site_set/p_faces_piter.hh | 148 +++++++++++++++++++++++++++++
3 files changed, 184 insertions(+), 8 deletions(-)
create mode 100644 milena/mln/core/site_set/p_faces_piter.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 784f4a4..743cc09 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2008-09-24 Roland Levillain <roland(a)lrde.epita.fr>
+ Add iterators on p_faces.
+
+ * mln/core/site_set/p_faces_piter.hh: New.
+ Add forward declarations for these iterators...
+ * mln/core/site_set/p_faces.hh: ...here.
+ (mln::p_faces<N,D,P>::fwd_piter): Set to p_faces_fwd_piter_<N,D,P>.
+ (mln::p_faces<N,D,P>::bkd_piter): Set to p_faces_bkd_piter_<N,D,P>.
+ (mln::p_faces<N, D, P>::p_faces(const p_complex<D, P>&)):
+ New ctor.
+
+2008-09-24 Roland Levillain <roland(a)lrde.epita.fr>
+
Make internal::p_complex_piter_base generic w.r.t. the site set.
* mln/core/internal/p_complex_piter_base.hh
diff --git a/milena/mln/core/site_set/p_faces.hh b/milena/mln/core/site_set/p_faces.hh
index 3c48100..21cd898 100644
--- a/milena/mln/core/site_set/p_faces.hh
+++ b/milena/mln/core/site_set/p_faces.hh
@@ -34,10 +34,12 @@
# include <mln/core/internal/site_set_base.hh>
-# include <mln/accu/bbox.hh>
# include <mln/core/complex.hh>
# include <mln/core/faces_psite.hh>
+# include <mln/core/site_set/p_faces_piter.hh>
+
+# include <mln/core/site_set/p_complex.hh>
namespace mln
@@ -45,11 +47,9 @@ namespace mln
// Forward declarations.
template <unsigned N, unsigned D, typename P> class p_faces;
- // FIXME: Enable when available.
-#if 0
+
template <unsigned N, unsigned D, typename P> class p_faces_fwd_piter_;
template <unsigned N, unsigned D, typename P> class p_faces_bkd_piter_;
-#endif
namespace trait
@@ -79,8 +79,14 @@ namespace mln
/// \brief Construct a faces psite set from an mln::complex.
///
/// \param gr The complex upon which the complex psite set is built.
+ p_faces(const complex<D>& cplx);
+
+ /// \brief Construct a faces psite set from an mln::p_complex.
+ ///
+ /// \param gr The complex upon which the complex psite set is built.
///
- p_faces (const complex<D>& cplx);
+ /// \todo When available, get location information from \a pc.
+ p_faces(const p_complex<D, P>& pc);
/// Associated types.
/// \{
@@ -92,11 +98,11 @@ namespace mln
// FIXME: Fake.
/// Forward Site_Iterator associated type.
- typedef void fwd_piter;
+ typedef p_faces_fwd_piter_<N, D, P> fwd_piter;
// FIXME: Fake.
/// Backward Site_Iterator associated type.
- typedef void bkd_piter;
+ typedef p_faces_bkd_piter_<N, D, P> bkd_piter;
/// Site_Iterator associated type.
typedef fwd_piter piter;
@@ -119,6 +125,7 @@ namespace mln
// simplify (and lighten) the implementation of piters, psites,
// etc.
+ // FIXME: This method is probably useless now.
/// Is this site set valid?
bool is_valid() const;
@@ -192,6 +199,15 @@ namespace mln
template <unsigned N, unsigned D, typename P>
inline
+ p_faces<N, D, P>::p_faces(const p_complex<D, P>& pc)
+ : cplx_(pc.cplx())
+ {
+ // Ensure N is compatible with D.
+ metal::bool_< N <= D >::check();
+ }
+
+ template <unsigned N, unsigned D, typename P>
+ inline
unsigned
p_faces<N, D, P>::nsites() const
{
@@ -223,7 +239,7 @@ namespace mln
return
// Check whether P's complex is compatible with this pset's complex.
(p.site_set() == *this) &&
- // Check whether the complex has the face associated to P.
+ // Check whether P is valid.
(p.is_valid());
}
diff --git a/milena/mln/core/site_set/p_faces_piter.hh b/milena/mln/core/site_set/p_faces_piter.hh
new file mode 100644
index 0000000..b26ca9b
--- /dev/null
+++ b/milena/mln/core/site_set/p_faces_piter.hh
@@ -0,0 +1,148 @@
+// 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_SITE_SET_P_FACES_PITER_HH
+# define MLN_CORE_SITE_SET_P_FACES_PITER_HH
+
+/// \file mln/core/site_set/p_faces_piter.hh
+/// \brief Definition of point iterator on complex-based pset.
+
+# include <mln/core/site_set/p_faces.hh>
+# include <mln/core/internal/p_complex_piter_base.hh>
+# include <mln/core/faces_iter.hh>
+
+
+namespace mln
+{
+
+ // Forward declarations.
+ template <unsigned N, unsigned D, typename P> class p_faces;
+
+ template <unsigned N, unsigned D> class faces_fwd_iter_;
+ template <unsigned N, unsigned D> class faces_bkd_iter_;
+
+
+ /*------------------------------.
+ | p_faces_fwd_piter_<N, D, P>. |
+ `------------------------------*/
+
+ /// \brief Forward iterator on point sites of a mln::p_faces<N, D, P>.
+ template <unsigned N, unsigned D, typename P>
+ class p_faces_fwd_piter_
+ : public internal::p_complex_piter_base_< faces_fwd_iter_<N, D>,
+ p_faces<N, D, P>,
+ P,
+ p_faces_fwd_piter_<N, D, P> >
+ {
+ typedef p_faces_fwd_piter_<N, D, P> self_;
+ typedef internal::p_complex_piter_base_< faces_fwd_iter_<N, D>,
+ p_faces<N, D, P>,
+ P,
+ self_ > super_;
+
+ public:
+ /// Construction and assignment.
+ /// \{
+ p_faces_fwd_piter_();
+ p_faces_fwd_piter_(const p_faces<N, D, P>& pc);
+ /// \}
+ };
+
+
+ /*------------------------------.
+ | p_faces_bkd_piter_<N, D, P>. |
+ `------------------------------*/
+
+ /// \brief Backward iterator on point sites of a mln::p_faces<N, D, P>.
+ template <unsigned N, unsigned D, typename P>
+ class p_faces_bkd_piter_
+ /* FIXME: Rename internal::p_complex_piter_base_ to something else,
+ as it is also used for p_faces piters! */
+ : public internal::p_complex_piter_base_< faces_bkd_iter_<N, D>,
+ p_faces<N, D, P>,
+ P,
+ p_faces_bkd_piter_<N, D, P> >
+ {
+ typedef p_faces_bkd_piter_<N, D, P> self_;
+ typedef internal::p_complex_piter_base_< faces_bkd_iter_<N, D>,
+ p_faces<N, D, P>,
+ P,
+ self_ > super_;
+
+ public:
+ /// Construction and assignment.
+ /// \{
+ p_faces_bkd_piter_();
+ p_faces_bkd_piter_(const p_faces<N, D, P>& pc);
+ /// \}
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*------------------------------.
+ | p_faces_fwd_piter_<N, D, P>. |
+ `------------------------------*/
+
+ template <unsigned N, unsigned D, typename P>
+ inline
+ p_faces_fwd_piter_<N, D, P>::p_faces_fwd_piter_()
+ {
+ }
+
+ template <unsigned N, unsigned D, typename P>
+ inline
+ p_faces_fwd_piter_<N, D, P>::p_faces_fwd_piter_(const p_faces<N, D, P>& pc)
+ : super_(pc)
+ {
+ }
+
+
+ /*------------------------------.
+ | p_faces_bkd_piter_<N, D, P>. |
+ `------------------------------*/
+
+ template <unsigned N, unsigned D, typename P>
+ inline
+ p_faces_bkd_piter_<N, D, P>::p_faces_bkd_piter_()
+ {
+ }
+
+ template <unsigned N, unsigned D, typename P>
+ inline
+ p_faces_bkd_piter_<N, D, P>::p_faces_bkd_piter_(const p_faces<N, D, P>& pc)
+ : super_(pc)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // ! MLN_CORE_SITE_SET_P_FACES_PITER_HH
--
1.6.0.1
* mln/core/image/complex_image.hh
(complex_image<D, P, V>::operator()(const faces_psite<N, D, P>) const)
(complex_image<D, P, V>::operator()(const faces_psite<N, D, P>)):
New operators.
---
milena/ChangeLog | 9 +++++++
milena/mln/core/image/complex_image.hh | 37 +++++++++++++++++++++++++++----
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index afbf257..413bbb6 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2008-09-24 Roland Levillain <roland(a)lrde.epita.fr>
+ Have mln::complex_image be accessible via faces_psites.
+
+ * mln/core/image/complex_image.hh
+ (complex_image<D, P, V>::operator()(const faces_psite<N, D, P>) const)
+ (complex_image<D, P, V>::operator()(const faces_psite<N, D, P>)):
+ New operators.
+
+2008-09-24 Roland Levillain <roland(a)lrde.epita.fr>
+
Complete iterators on faces.
* mln/core/faces_iter.hh
diff --git a/milena/mln/core/image/complex_image.hh b/milena/mln/core/image/complex_image.hh
index 6dbc522..0512d0f 100644
--- a/milena/mln/core/image/complex_image.hh
+++ b/milena/mln/core/image/complex_image.hh
@@ -143,12 +143,18 @@ namespace mln
void init_(const p_complex<D, P>& pc,
const metal::vec< D + 1, std::vector<V> >& values);
- /// Read-only access of pixel value at point site \p p.
+ /// Read-only access of face value at point site \p p.
rvalue operator()(const complex_psite<D, P>& p) const;
-
- /// Read-write access of pixel value at point site \p p.
+ /// Read-write access of face value at point site \p p.
lvalue operator()(const complex_psite<D, P>& p);
+ /// Read-only access of face value at point site \p p.
+ template <unsigned N>
+ rvalue operator()(const faces_psite<N, D, P>& p) const;
+ /// Read-write access of face value at point site \p p.
+ template <unsigned N>
+ lvalue operator()(const faces_psite<N, D, P>& p);
+
/// Accessors.
/// \{
/// Return the domain of psites od the image.
@@ -193,8 +199,7 @@ namespace mln
template <unsigned D, typename P, typename V>
inline
data< complex_image<D, P, V> >::data(const p_complex<D, P>& pc,
- const metal::vec< D + 1,
- std::vector<V> >& values)
+ const metal::vec< D + 1, std::vector<V> >& values)
: values_(values),
pc_(pc)
{
@@ -272,6 +277,28 @@ namespace mln
}
template <unsigned D, typename P, typename V>
+ template <unsigned N>
+ inline
+ typename complex_image<D, P, V>::rvalue
+ complex_image<D, P, V>::operator()(const faces_psite<N, D, P>& p) const
+ {
+ /* FIXME: We should ensure data_->pc_ has P, but it is not
+ trivial: a daces_psite has no idea what a p_complex is. */
+ return this->data_->values_[p.n()][p.face_id()];
+ }
+
+ template <unsigned D, typename P, typename V>
+ template <unsigned N>
+ inline
+ typename complex_image<D, P, V>::lvalue
+ complex_image<D, P, V>::operator()(const faces_psite<N, D, P>& p)
+ {
+ /* FIXME: We should ensure data_->pc_ has P, but it is not
+ trivial: a daces_psite has no idea what a p_complex is. */
+ return this->data_->values_[p.n()][p.face_id()];
+ }
+
+ template <unsigned D, typename P, typename V>
inline
const metal::vec< D + 1, std::vector<V> >&
complex_image<D, P, V>::face_values() const
--
1.6.0.1
* mln/core/site_set/p_complex.hh (mln::p_complex<D, P>::cplx_):
* mln/core/site_set/p_faces.hh (mln::p_faces<D, P>::cplx_):
Remove the tracked_ptr wrapper and change type to
mutable complex<D>.
(p_complex<D, P>::p_complex(const complex<D>&))
(p_faces<N, D, P>::p_faces(const complex<D>&)):
Adjust ctors.
(p_complex<D, P>::nfaces)
(p_complex<D, P>::is_valid)
(p_complex<D, P>::cplx)
(p_faces<N, D, P>::nfaces)
(p_faces<N, D, P>::is_valid)
(p_faces<N, D, P>::cplx)
(operator==(const p_complex<D, P>&, const p_complex<D, P>&))
(operator< (const p_complex<D, P>&, const p_complex<D, P>&))
(operator==(const p_faces<N, D, P>&, const p_faces<N, D, P>&))
(operator< (const p_faces<N, D, P>&, const p_faces<N, D, P>&)):
Adjust.
---
milena/ChangeLog | 23 ++++++++++++++
milena/mln/core/site_set/p_complex.hh | 55 ++++++++++++--------------------
milena/mln/core/site_set/p_faces.hh | 44 +++++++++++++++-----------
3 files changed, 69 insertions(+), 53 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 5ace73e..6e0cd55 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -74,6 +74,29 @@
2008-09-23 Roland Levillain <roland(a)lrde.epita.fr>
+ No longer hold complexes through tracked_ptr in site sets.
+
+ * mln/core/site_set/p_complex.hh (mln::p_complex<D, P>::cplx_):
+ * mln/core/site_set/p_faces.hh (mln::p_faces<D, P>::cplx_):
+ Remove the tracked_ptr wrapper and change type to
+ mutable complex<D>.
+ (p_complex<D, P>::p_complex(const complex<D>&))
+ (p_faces<N, D, P>::p_faces(const complex<D>&)):
+ Adjust ctors.
+ (p_complex<D, P>::nfaces)
+ (p_complex<D, P>::is_valid)
+ (p_complex<D, P>::cplx)
+ (p_faces<N, D, P>::nfaces)
+ (p_faces<N, D, P>::is_valid)
+ (p_faces<N, D, P>::cplx)
+ (operator==(const p_complex<D, P>&, const p_complex<D, P>&))
+ (operator< (const p_complex<D, P>&, const p_complex<D, P>&))
+ (operator==(const p_faces<N, D, P>&, const p_faces<N, D, P>&))
+ (operator< (const p_faces<N, D, P>&, const p_faces<N, D, P>&)):
+ Adjust.
+
+2008-09-23 Roland Levillain <roland(a)lrde.epita.fr>
+
Have the compiler check more code, even in NDEBUG mode.
* mln/core/complex.hh (mln::complex<D>::add_face): Use
diff --git a/milena/mln/core/site_set/p_complex.hh b/milena/mln/core/site_set/p_complex.hh
index 6065df4..6c30c25 100644
--- a/milena/mln/core/site_set/p_complex.hh
+++ b/milena/mln/core/site_set/p_complex.hh
@@ -33,7 +33,6 @@
# include <mln/core/internal/site_set_base.hh>
-# include <mln/util/tracked_ptr.hh>
# include <mln/core/complex.hh>
# include <mln/core/complex_psite.hh>
@@ -44,6 +43,8 @@ namespace mln
{
// Forward declarations.
+ template <unsigned D, typename P> class p_complex;
+
template <unsigned D, typename P> class p_complex_fwd_piter_;
template <unsigned D, typename P> class p_complex_bkd_piter_;
@@ -98,9 +99,6 @@ namespace mln
/// \brief Construct a complex psite set from a complex.
///
/// \param gr The complex upon which the complex psite set is built.
- ///
- /// \a gr is \em copied internally, so that the complex psite set is
- /// still valid after the initial complex has been removed.
p_complex (const complex<D>& cplx);
/// Associated types.
@@ -161,29 +159,20 @@ namespace mln
private:
/// The complex on which this pset is built.
- /* FIXME:Get rid of this `mutable' qualifier. This is needed for
- compatiblity reasons with any_face_handle (see p_complex_piter)
+ /* FIXME: Get rid of this `mutable' qualifier. This is needed for
+ compatiblity reasons with any_face_handle (see
+ p_complex_piter).
We should either
- - do not use any_face_handle in the implementation of
- p_complex_piter;
-
- - have an additional version of any_face_handles holding a
+ - have an additional version of any_face_handle holding a
const (not mutable) complex;
- - or even have face_handle and any_face_handle do not hold a
- reference on a complex, leading to a design of complexes
- similar to graphs, where vertex and edge handles (named `id's)
- are not tied to a specific graph. */
- mutable util::tracked_ptr< complex<D> > cplx_;
-
- // FIXME: Remove as soon as the tracked_ptr is move into the
- // complex itself.
- template <unsigned D_, typename P_>
- friend
- bool operator==(const p_complex<D_, P_>& lhs,
- const p_complex<D_, P_>& rhs);
+ - have face_handle and any_face_handle do not hold a reference
+ on a complex, leading to a design of complexes similar to
+ graphs, where vertex and edge handles (named `id's) are not
+ tied to a specific graph. */
+ mutable complex<D> cplx_;
};
@@ -214,8 +203,7 @@ namespace mln
template <unsigned D, typename P>
inline
p_complex<D, P>::p_complex(const complex<D>& cplx)
- // Create a deep, managed copy of CPLX.
- : cplx_(new complex<D>(cplx))
+ : cplx_(cplx)
{
}
@@ -232,7 +220,7 @@ namespace mln
std::size_t
p_complex<D, P>::nfaces() const
{
- return cplx_->nfaces();
+ return cplx_.nfaces();
}
template <unsigned D, typename P>
@@ -240,8 +228,7 @@ namespace mln
bool
p_complex<D, P>::is_valid() const
{
- // FIXME: Might be too low-level, again.
- return (cplx_.ptr_);
+ return true;
}
template <unsigned D, typename P>
@@ -272,7 +259,7 @@ namespace mln
p_complex<D, P>::cplx() const
{
mln_precondition(is_valid());
- return *cplx_.ptr_;
+ return cplx_;
}
template <unsigned D, typename P>
@@ -280,7 +267,7 @@ namespace mln
p_complex<D, P>::cplx()
{
mln_precondition(is_valid());
- return *cplx_.ptr_;
+ return cplx_;
}
@@ -292,17 +279,17 @@ namespace mln
bool
operator==(const p_complex<D, P>& lhs, const p_complex<D, P>& rhs)
{
- /* FIXME: We should not rely on pointer equality here, as graph
- will soon become shells using (shared) tracked pointers to
- actual data. So, delegate the equality test to the graphs
- themselves. */
- return lhs.cplx_.ptr_ == rhs.cplx_.ptr_;
+ /* FIXME: When actual location data is attached to a p_complex,
+ check also the equlity w.r.t. to these data. */
+ return lhs.cplx() == rhs.cplx();
}
template <unsigned D, typename P>
bool
operator<=(const p_complex<D, P>& lhs, const p_complex<D, P>& rhs)
{
+ /* FIXME: When actual location data is attached to a p_complex,
+ check also the equality w.r.t. to these data. */
return lhs == rhs;
}
diff --git a/milena/mln/core/site_set/p_faces.hh b/milena/mln/core/site_set/p_faces.hh
index 025023d..3c48100 100644
--- a/milena/mln/core/site_set/p_faces.hh
+++ b/milena/mln/core/site_set/p_faces.hh
@@ -35,7 +35,6 @@
# include <mln/core/internal/site_set_base.hh>
# include <mln/accu/bbox.hh>
-# include <mln/util/tracked_ptr.hh>
# include <mln/core/complex.hh>
# include <mln/core/faces_psite.hh>
@@ -77,12 +76,10 @@ namespace mln
typedef p_faces<N, D, P> self_;
typedef internal::site_set_base_< faces_psite<N, D, P>, self_ > super_;
- /// \brief Construct a complex psite set from a complex.
+ /// \brief Construct a faces psite set from an mln::complex.
///
/// \param gr The complex upon which the complex psite set is built.
///
- /// \a gr is \em copied internally, so that the complex psite set is
- /// still valid after the initial complex has been removed.
p_faces (const complex<D>& cplx);
/// Associated types.
@@ -144,12 +141,19 @@ namespace mln
private:
/// The complex on which this pset is built.
- util::tracked_ptr< complex<D> > cplx_;
+ /* FIXME: Get rid of this `mutable' qualifier. This is needed for
+ compatiblity reasons with face_handle (see p_faces_piter).
- template <unsigned D_, unsigned N_, typename P_>
- friend
- bool operator==(const p_faces<D_, N_, P_>& lhs,
- const p_faces<D_, N_, P_>& rhs);
+ We should either
+
+ - have an additional version of face_handle holding a const
+ (not mutable) complex;
+
+ - have face_handle and any_face_handle do not hold a reference
+ on a complex, leading to a design of complexes similar to
+ graphs, where vertex and edge handles (named `id's) are not
+ tied to a specific graph. */
+ mutable complex<D> cplx_;
};
@@ -180,8 +184,7 @@ namespace mln
template <unsigned N, unsigned D, typename P>
inline
p_faces<N, D, P>::p_faces(const complex<D>& cplx)
- // Create a deep, managed copy of CPLX.
- : cplx_(new complex<D>(cplx))
+ : cplx_(cplx)
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
@@ -200,7 +203,7 @@ namespace mln
std::size_t
p_faces<N, D, P>::nfaces() const
{
- return cplx_->template nfaces<N>();
+ return cplx_.template nfaces<N>();
}
template <unsigned N, unsigned D, typename P>
@@ -208,8 +211,7 @@ namespace mln
bool
p_faces<N, D, P>::is_valid() const
{
- // FIXME: Might be too low-level, again.
- return (cplx_.ptr_);
+ return true;
}
template <unsigned N, unsigned D, typename P>
@@ -239,16 +241,16 @@ namespace mln
complex<D>&
p_faces<N, D, P>::cplx() const
{
- mln_precondition(cplx_);
- return *cplx_.ptr_;
+ mln_precondition(is_valid());
+ return cplx_;
}
template <unsigned N, unsigned D, typename P>
complex<D>&
p_faces<N, D, P>::cplx()
{
- mln_precondition(cplx_);
- return *cplx_.ptr_;
+ mln_precondition(is_valid());
+ return cplx_;
}
@@ -260,13 +262,17 @@ namespace mln
bool
operator==(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
{
- return lhs.cplx_.ptr_ == rhs.cplx_.ptr_;
+ /* FIXME: When actual location data is attached to a p_faces,
+ check also the equality w.r.t. to these data. */
+ return lhs.cplx() == rhs.cplx();
}
template <unsigned N, unsigned D, typename P>
bool
operator<=(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
{
+ /* FIXME: When actual location data is attached to a p_faces,
+ check also the equality w.r.t. to these data. */
return lhs == rhs;
}
--
1.6.0.1
* mln/core/complex.hh (mln::complex<D>::add_face): Use
`if (!HAS_NDEBUG)' instead of `#ifndef NDEBUG'.
---
milena/ChangeLog | 7 +++++++
milena/mln/core/complex.hh | 17 +++++++----------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 44e4772..5ace73e 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -74,6 +74,13 @@
2008-09-23 Roland Levillain <roland(a)lrde.epita.fr>
+ Have the compiler check more code, even in NDEBUG mode.
+
+ * mln/core/complex.hh (mln::complex<D>::add_face): Use
+ `if (!HAS_NDEBUG)' instead of `#ifndef NDEBUG'.
+
+2008-09-23 Roland Levillain <roland(a)lrde.epita.fr>
+
Make use of the new semantics of complexes in tests.
* tests/core/image/complex_image.cc: Update.
diff --git a/milena/mln/core/complex.hh b/milena/mln/core/complex.hh
index d1e5bad..32197f4 100644
--- a/milena/mln/core/complex.hh
+++ b/milena/mln/core/complex.hh
@@ -420,16 +420,13 @@ namespace mln
typedef typename std::vector< face_handle<N, D> >::const_iterator iter_t;
// Ensure ADJACENT_FACES are already part of the complex.
- /* FIXME: We need additional macros in mln/core/contract.hh for
- big blocks of preconditions like this one. */
-# ifndef NDEBUG
- for (iter_t a = adjacent_faces.faces().begin();
- a != adjacent_faces.faces().end(); ++a)
- {
- mln_precondition(&a->cplx() == this);
- mln_precondition(a->is_valid());
- }
-# endif // !NDEBUG
+ if (!HAS_NDEBUG)
+ for (iter_t a = adjacent_faces.faces().begin();
+ a != adjacent_faces.faces().end(); ++a)
+ {
+ mln_precondition(&a->cplx() == this);
+ mln_precondition(a->is_valid());
+ }
face<N + 1, D> f;
/* FIXME: This is not thread-proof (these two lines should
--
1.6.0.1