* mln/core/internal/site_relative_iterator_base.hh,
* mln/core/internal/site_iterator_base.hh,
* mln/core/concept/site_iterator.hh: fix comments.
* mln/core/image/line_graph_elt_window.hh,
* mln/core/image/graph_elt_window.hh: change typedefs.
* mln/core/image/graph_window_piter.hh: add center_at().
* mln/core/internal/graph_window_base.hh: add is_neighbable_().
* mln/core/neighb.hh,
* mln/core/internal/neighb_niter_impl.hh: allow optional
implementation for neighborhood based on neighb.
* mln/core/macros.hh: add mln_graph_element.
* mln/util/internal/graph_nbh_iter_base.hh: fix center_at().
* mln/util/vertex.hh: update an assertion.
* tests/core/image/graph_image.cc,
* tests/core/image/line_graph_image.cc: make them real tests and
remove debug output.
---
milena/ChangeLog | 29 ++++++
milena/mln/core/concept/site_iterator.hh | 47 +++++-----
milena/mln/core/image/graph_elt_window.hh | 8 +-
milena/mln/core/image/graph_window_piter.hh | 36 ++++++-
milena/mln/core/image/line_graph_elt_window.hh | 8 +-
milena/mln/core/internal/graph_window_base.hh | 11 ++
milena/mln/core/internal/neighb_niter_impl.hh | 97 ++++++++++++++++++++
milena/mln/core/internal/site_iterator_base.hh | 50 +++++-----
.../core/internal/site_relative_iterator_base.hh | 40 ++++----
milena/mln/core/macros.hh | 6 +
milena/mln/core/neighb.hh | 10 +-
milena/mln/util/internal/graph_nbh_iter_base.hh | 11 ++-
milena/mln/util/vertex.hh | 3 +-
milena/tests/core/image/graph_image.cc | 80 +++++++++-------
milena/tests/core/image/line_graph_image.cc | 74 ++++++++-------
15 files changed, 352 insertions(+), 158 deletions(-)
create mode 100644 milena/mln/core/internal/neighb_niter_impl.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 77c014b..bc666e4 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,32 @@
+2008-12-05 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Fix bugs in graph.
+
+ * mln/core/internal/site_relative_iterator_base.hh,
+ * mln/core/internal/site_iterator_base.hh,
+ * mln/core/concept/site_iterator.hh: fix comments.
+
+ * mln/core/image/line_graph_elt_window.hh,
+ * mln/core/image/graph_elt_window.hh: change typedefs.
+
+ * mln/core/image/graph_window_piter.hh: add center_at().
+
+ * mln/core/internal/graph_window_base.hh: add is_neighbable_().
+
+ * mln/core/neighb.hh,
+ * mln/core/internal/neighb_niter_impl.hh: allow optional
+ implementation for neighborhood based on neighb.
+
+ * mln/core/macros.hh: add mln_graph_element.
+
+ * mln/util/internal/graph_nbh_iter_base.hh: fix center_at().
+
+ * mln/util/vertex.hh: update an assertion.
+
+ * tests/core/image/graph_image.cc,
+ * tests/core/image/line_graph_image.cc: make them real tests and
+ remove debug output.
+
2008-12-05 Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Add big_chess functor.
diff --git a/milena/mln/core/concept/site_iterator.hh
b/milena/mln/core/concept/site_iterator.hh
index b3b293c..97cbc57 100644
--- a/milena/mln/core/concept/site_iterator.hh
+++ b/milena/mln/core/concept/site_iterator.hh
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 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
@@ -28,12 +29,12 @@
#ifndef MLN_CORE_CONCEPT_SITE_ITERATOR_HH
# define MLN_CORE_CONCEPT_SITE_ITERATOR_HH
-/*! \file mln/core/concept/site_iterator.hh
- *
- * \brief Definition of the concept of mln::Site_Iterator.
- *
- * \todo Fix mln/core/concept/doc/site_iterator.hh
- */
+/// \file mln/core/concept/site_iterator.hh
+///
+/// Definition of the concept of mln::Site_Iterator.
+///
+/// \todo Fix mln/core/concept/doc/site_iterator.hh
+
# include <mln/core/concept/site_proxy.hh>
# include <mln/core/concept/iterator.hh> // To fetch the macros.
@@ -42,15 +43,15 @@
namespace mln
{
- /*! \brief Base class for implementation of classes of iterator on
- * points.
- *
- * An iterator on points is an iterator that browse over a set of
- * points.
- *
- * \see mln::doc::Site_Iterator for a complete documentation of this class
- * contents.
- */
+ /// Base class for implementation of classes of iterator on
+ /// points.
+ ///
+ /// An iterator on points is an iterator that browse over a set of
+ /// points.
+ ///
+ /// \see mln::doc::Site_Iterator for a complete documentation of this class
+ /// contents.
+ ///
template <typename E>
struct Site_Iterator : public Site_Proxy<E>
{
@@ -62,14 +63,14 @@ namespace mln
const ..& target_() const;
*/
- /*! \brief Go to the next element.
- *
- * \warning This is a final method; iterator classes should not
- * re-defined this method. The actual "next" operation has to be
- * defined through the \em next_ method.
- *
- * \pre The iterator is valid.
- */
+ /// Go to the next element.
+ ///
+ /// \warning This is a final method; iterator classes should not
+ /// re-defined this method. The actual "next" operation has to be
+ /// defined through the \em next_ method.
+ ///
+ /// \pre The iterator is valid.
+ ///
void next(); // final
// FIXME: Doc!!!
diff --git a/milena/mln/core/image/graph_elt_window.hh
b/milena/mln/core/image/graph_elt_window.hh
index b48d668..2e47cb2 100644
--- a/milena/mln/core/image/graph_elt_window.hh
+++ b/milena/mln/core/image/graph_elt_window.hh
@@ -86,17 +86,17 @@ namespace mln
public:
/// Associated types.
/// \{
- typedef p_vertices<G,F> S;
+ typedef p_vertices<G,F> target;
/// The type of psite corresponding to the window.
- typedef mln_psite(S) psite;
+ typedef mln_psite(target) psite;
/// Site_Iterator type to browse the psites of the window
/// w.r.t. the ordering of vertices.
- typedef graph_window_piter<S,self_,nbh_fwd_iter_> fwd_qiter;
+ typedef graph_window_piter<target,self_,nbh_fwd_iter_> fwd_qiter;
/// Site_Iterator type to browse the psites of the window
/// w.r.t. the reverse ordering of vertices.
- typedef graph_window_piter<S,self_,nbh_bkd_iter_> bkd_qiter;
+ typedef graph_window_piter<target,self_,nbh_bkd_iter_> bkd_qiter;
/// The default qiter type.
typedef fwd_qiter qiter;
diff --git a/milena/mln/core/image/graph_window_piter.hh
b/milena/mln/core/image/graph_window_piter.hh
index d95963f..16213e8 100644
--- a/milena/mln/core/image/graph_window_piter.hh
+++ b/milena/mln/core/image/graph_window_piter.hh
@@ -33,13 +33,13 @@
///
/// Definition of a point iterator on a line_graph window.
-
# include <mln/core/internal/site_relative_iterator_base.hh>
namespace mln
{
+
/// Forward iterator on line graph window.
template <typename S, typename W, typename I>
class graph_window_piter
@@ -57,8 +57,6 @@ namespace mln
// FIXME: Dummy typedef.
typedef void dpoint;
- // FIXME: Dummy value.
- typedef void mesh;
/// \}
/// Construction.
@@ -81,6 +79,16 @@ namespace mln
/// Go to the next point.
void do_next_();
+ /// Set the reference psite.
+ /* FIXME: Careful, this method overrides the (non virtual) method
+ internal::site_relative_iterator_base<S, E>::center_at. See
+ FIXME above. */
+ template <typename Pref>
+ void center_at(const Pref& c);
+
+ /// Return the graph element pointed by this iterator.
+ const mln_graph_element(S)& element() const;
+
/// Compute the current psite.
mln_psite(W) compute_p_() const;
/// \}
@@ -104,10 +112,10 @@ namespace mln
inline
graph_window_piter<S,W,I>::graph_window_piter(const Window<W>& win,
const Pref& p_ref)
- : iter_(p_ref.hook_iter_())
{
- this->change_target(exact(win));
center_at(p_ref);
+ this->change_target(exact(win));
+ mln_postcondition(!this->is_valid());
}
template <typename S, typename W, typename I>
@@ -150,6 +158,24 @@ namespace mln
return mln_psite(S)(this->center().site_set(), iter_.id());
}
+ template <typename S, typename W, typename I>
+ template <typename Pref>
+ inline
+ void
+ graph_window_piter<S, W, I>::center_at(const Pref& c)
+ {
+ super_::center_at(c);
+ iter_.center_at(c.hook_iter_());
+ }
+
+ template <typename S, typename W, typename I>
+ inline
+ const mln_graph_element(S)&
+ graph_window_piter<S, W, I>::element() const
+ {
+ return iter_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
diff --git a/milena/mln/core/image/line_graph_elt_window.hh
b/milena/mln/core/image/line_graph_elt_window.hh
index c1b910c..9717f48 100644
--- a/milena/mln/core/image/line_graph_elt_window.hh
+++ b/milena/mln/core/image/line_graph_elt_window.hh
@@ -83,17 +83,17 @@ namespace mln
public:
/// Associated types.
/// \{
- typedef p_edges<G,F> S;
+ typedef p_edges<G,F> target;
// The type of psite corresponding to the window.
- typedef mln_psite(S) psite;
+ typedef mln_psite(target) psite;
/// Site_Iterator type to browse the psites of the window
/// w.r.t. the ordering of edges.
- typedef graph_window_piter<S,self_,nbh_fwd_iter_> fwd_qiter;
+ typedef graph_window_piter<target,self_,nbh_fwd_iter_> fwd_qiter;
/// Site_Iterator type to browse the psites of the window
/// w.r.t. the reverse ordering of edges.
- typedef graph_window_piter<S,self_,nbh_bkd_iter_> bkd_qiter;
+ typedef graph_window_piter<target,self_,nbh_bkd_iter_> bkd_qiter;
/// The default qiter type.
typedef fwd_qiter qiter;
diff --git a/milena/mln/core/internal/graph_window_base.hh
b/milena/mln/core/internal/graph_window_base.hh
index 115e680..d2ecfd5 100644
--- a/milena/mln/core/internal/graph_window_base.hh
+++ b/milena/mln/core/internal/graph_window_base.hh
@@ -76,6 +76,9 @@ namespace mln
unsigned delta() const;
/// Apply a central symmetry to the target window.
self_& sym();
+
+ /// Is the window neighbable?
+ bool is_neighbable_() const;
/// \}
protected:
@@ -134,6 +137,14 @@ namespace mln
return *this;
}
+ template <typename P, typename E>
+ inline
+ bool
+ graph_window_base<P,E>::is_neighbable_() const
+ {
+ return true;
+ }
+
# endif // !MLN_INCLUDE_ONLY
diff --git a/milena/mln/core/internal/neighb_niter_impl.hh
b/milena/mln/core/internal/neighb_niter_impl.hh
new file mode 100644
index 0000000..868e1f8
--- /dev/null
+++ b/milena/mln/core/internal/neighb_niter_impl.hh
@@ -0,0 +1,97 @@
+// 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. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_INTERNAL_NEIGHB_NITER_IMPL_HH
+# define MLN_CORE_INTERNAL_NEIGHB_NITER_IMPL_HH
+
+/// \file mln/core/internal/neighb_niter_impl.hh
+///
+/// Optional implementation for neigbh_niter.
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <typename P, typename W> class graph_window_base;
+ template <typename G, typename F> class graph_elt_window;
+ template <typename G, typename F> class line_graph_elt_window;
+
+
+ namespace internal
+ {
+
+ /// Default optional implementation.
+ template <typename W, typename E>
+ struct neighb_niter_impl
+ {
+
+ };
+
+
+ /// Add more implementation for neighborhoods made from
+ /// graph_window_base windows.
+ template <typename P, typename T, typename E>
+ struct neighb_niter_impl<graph_window_base<P,T>, E>
+ {
+ typedef typename T::target S;
+
+ const mln_graph_element(S)& element() const
+ {
+ return internal::force_exact<E>(*this).compute_p_().element();
+ }
+
+ };
+
+
+ /// Add more implementation for neighborhoods made from a
+ /// graph_window_piter.
+ template <typename G, typename F, typename E>
+ struct neighb_niter_impl<graph_elt_window<G,F>, E>
+ : public neighb_niter_impl< graph_window_base< mln_result(F),
+ graph_elt_window<G, F> >,
+ E >
+ {
+
+ };
+
+ /// Add more implementation for neighborhoods made from a
+ /// line_graph_window_piter.
+ template <typename G, typename F, typename E>
+ struct neighb_niter_impl<line_graph_elt_window<G,F>, E>
+ : public neighb_niter_impl< graph_window_base< mln_result(F),
+ line_graph_elt_window<G, F> >,
+ E >
+ {
+
+ };
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+#endif // ! MLN_CORE_INTERNAL_NEIGHB_NITER_IMPL_HH
diff --git a/milena/mln/core/internal/site_iterator_base.hh
b/milena/mln/core/internal/site_iterator_base.hh
index 87ad230..5eaedf7 100644
--- a/milena/mln/core/internal/site_iterator_base.hh
+++ b/milena/mln/core/internal/site_iterator_base.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// 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
@@ -28,12 +28,12 @@
#ifndef MLN_CORE_INTERNAL_SITE_ITERATOR_BASE_HH
# define MLN_CORE_INTERNAL_SITE_ITERATOR_BASE_HH
-/*! \file mln/core/internal/site_iterator_base.hh
- *
- * \brief Base class to factor code for site iterator classes.
- *
- * \todo Import tech doc from home.
- */
+/// \file mln/core/internal/site_iterator_base.hh
+///
+/// Base class to factor code for site iterator classes.
+///
+/// \todo Import tech doc from home.
+
# include <mln/core/concept/site_iterator.hh>
# include <mln/core/concept/pseudo_site.hh> // Use of if_possible::change_target.
@@ -49,16 +49,16 @@ namespace mln
namespace internal
{
- /*! A base class for site iterators.
- *
- * NEVER DIRECTLY DERIVE FROM THIS CLASS.
- *
- * Instead derive EITHER from site_set_iterator_base OR from
- * site_relative_iterator_base OR from piter_adaptor_.
- *
- * Parameter \c S is the targeted "site set definition" type. It
- * can be either a Site_Set, a Window, or a Neighborhood.
- */
+ /// A base class for site iterators.
+ ///
+ /// NEVER DIRECTLY DERIVE FROM THIS CLASS.
+ ///
+ /// Instead derive EITHER from site_set_iterator_base OR from
+ /// site_relative_iterator_base OR from piter_adaptor_.
+ ///
+ /// Parameter \c S is the targeted "site set definition" type. It
+ /// can be either a Site_Set, a Window, or a Neighborhood.
+ ///
template <typename S, typename E>
struct site_iterator_base : Site_Iterator<E>,
proxy_impl< const mln_psite(S)&, E>
@@ -69,13 +69,13 @@ namespace mln
/// Return the site it points to (as a Site_Proxy).
const mln_site(S)& to_site() const;
- /*! \brief Conversion towards the site it designates (as a Site_Proxy).
- *
- * \warning This is a final method; iterator classes should not
- * re-defined this method.
- *
- * \pre The iterator is valid.
- */
+ /// Conversion towards the site it designates (as a Site_Proxy).
+ ///
+ /// \warning This is a final method; iterator classes should not
+ /// re-defined this method.
+ ///
+ /// \pre The iterator is valid.
+ ///
operator mln_site(S)() const;
/// Give the subject (required by the Proxy interface).
@@ -83,7 +83,7 @@ namespace mln
/// Give the target address. It might be 0.
const S*& target_();
-
+
protected:
site_iterator_base();
diff --git a/milena/mln/core/internal/site_relative_iterator_base.hh
b/milena/mln/core/internal/site_relative_iterator_base.hh
index 01e5f19..4438134 100644
--- a/milena/mln/core/internal/site_relative_iterator_base.hh
+++ b/milena/mln/core/internal/site_relative_iterator_base.hh
@@ -28,16 +28,16 @@
#ifndef MLN_CORE_SITE_RELATIVE_ITERATOR_BASE_HH
# define MLN_CORE_SITE_RELATIVE_ITERATOR_BASE_HH
-/*! \file mln/core/internal/site_relative_iterator_base.hh
- *
- * \brief Definition of forward and backward mln::dpoint_ based
- * iterators.
- *
- * \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...
- */
+/// \file mln/core/internal/site_relative_iterator_base.hh
+///
+/// Definition of forward and backward mln::dpoint_ based
+/// iterators.
+///
+/// \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>
# include <mln/core/internal/site_iterator_base.hh>
@@ -50,16 +50,16 @@ namespace mln
namespace internal
{
- /*! \brief A generic iterator on points of windows and of
- * neighborhoods.
- *
- * Parameter \c S is the targeted "site set definition" type. It
- * can be either a Window, or a Neighborhood.
- *
- * IMPORTANT: Sub-classes have to define do_start_, do_next_,
- * is_valid_, invalidate_ and compute_p_. They shall define
- * NEITHER start_ NOR next_.
- */
+ /// A generic iterator on points of windows and of
+ /// neighborhoods.
+ ///
+ /// Parameter \c S is the targeted "site set definition" type. It
+ /// can be either a Window, or a Neighborhood.
+ ///
+ /// IMPORTANT: Sub-classes have to define do_start_, do_next_,
+ /// is_valid_, invalidate_ and compute_p_. They shall define
+ /// NEITHER start_ NOR next_.
+ ///
template <typename S, typename E>
class site_relative_iterator_base : public site_iterator_base< S, E >
{
diff --git a/milena/mln/core/macros.hh b/milena/mln/core/macros.hh
index 130cb89..16ce3fe 100644
--- a/milena/mln/core/macros.hh
+++ b/milena/mln/core/macros.hh
@@ -131,6 +131,12 @@
# define mln_element_(T) T::element
/// \}
+/// Shortcuts to access the graph element type associated to T.
+/// \{
+# define mln_graph_element(T) typename T::graph_element
+# define mln_graph_element_(T) T::graph_element
+/// \}
+
/// Shortcuts to access the encoding type associated to T.
/// \{
# define mln_enc(T) typename T::enc
diff --git a/milena/mln/core/neighb.hh b/milena/mln/core/neighb.hh
index d54b229..c13f25b 100644
--- a/milena/mln/core/neighb.hh
+++ b/milena/mln/core/neighb.hh
@@ -39,7 +39,7 @@
# include <mln/core/internal/neighborhood_base.hh>
# include <mln/core/internal/site_relative_iterator_base.hh>
-
+# include <mln/core/internal/neighb_niter_impl.hh>
namespace mln
@@ -103,7 +103,7 @@ namespace mln
void
from_to(const W& from, mln::neighb<W>& to);
- } // end of namespace convert
+ } // end of namespace mln::convert
@@ -112,7 +112,8 @@ namespace mln
template <typename W>
class neighb_fwd_niter
: public internal::site_relative_iterator_base< neighb<W>,
- neighb_fwd_niter<W> >
+ neighb_fwd_niter<W> >,
+ public internal::neighb_niter_impl<W, neighb_fwd_niter<W> >
{
public:
@@ -149,7 +150,8 @@ namespace mln
template <typename W>
class neighb_bkd_niter
: public internal::site_relative_iterator_base< neighb<W>,
- neighb_bkd_niter<W> >
+ neighb_bkd_niter<W> >,
+ public internal::neighb_niter_impl<W, neighb_fwd_niter<W> >
{
public:
diff --git a/milena/mln/util/internal/graph_nbh_iter_base.hh
b/milena/mln/util/internal/graph_nbh_iter_base.hh
index 11fbadd..a28be8b 100644
--- a/milena/mln/util/internal/graph_nbh_iter_base.hh
+++ b/milena/mln/util/internal/graph_nbh_iter_base.hh
@@ -31,7 +31,7 @@
# include <mln/core/concept/proxy.hh>
/// \file mln/util/internal/graph_nbh_iter_base.hh
-/// \brief Base implementation for graph edge and vertex neighborhood iterator.
+/// Base implementation for graph edge and vertex neighborhood iterator.
namespace mln
{
@@ -64,6 +64,11 @@ namespace mln
/// Conversion operator. Returns the element ID.
operator unsigned() const;
+
+ /// Make \p c the center of this iterator.
+ template <typename C2>
+ void center_at(const C2& c);
+
/// \}
/// Proxy.
@@ -80,9 +85,6 @@ namespace mln
nbh_iterator_base(const C2& c);
/// \}
- template <typename C2>
- void center_at(const C2& c);
-
const C* c_; // Center
P p_;
unsigned i_;
@@ -176,6 +178,7 @@ namespace mln
{
internal::get_adr(c_, c);
mln_postcondition(c_ != 0);
+ p_.change_graph(c.graph());
invalidate();
}
diff --git a/milena/mln/util/vertex.hh b/milena/mln/util/vertex.hh
index b1242e6..197dcab 100644
--- a/milena/mln/util/vertex.hh
+++ b/milena/mln/util/vertex.hh
@@ -194,7 +194,7 @@ namespace mln
vertex<G>::vertex(const G& g, unsigned id)
: g_(g), id_(id)
{
- mln_precondition(/* FIXME: g_.is_valid() && */ g_.has_v(id));
+ mln_assertion(is_valid());
}
template<typename G>
@@ -213,7 +213,6 @@ namespace mln
id_ = mln_max(unsigned);
}
-
template<typename G>
inline
unsigned
diff --git a/milena/tests/core/image/graph_image.cc
b/milena/tests/core/image/graph_image.cc
index 44866ad..bd47c8a 100644
--- a/milena/tests/core/image/graph_image.cc
+++ b/milena/tests/core/image/graph_image.cc
@@ -31,19 +31,13 @@
#include <vector>
-#include <mln/accu/bbox.hh>
-#include <mln/core/alias/box2d.hh>
-#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_vertices.hh>
-
-#include <mln/core/image/image_if.hh>
-#include <mln/core/image/sub_image.hh>
-#include <mln/core/var.hh>
-#include <mln/core/routine/ops.hh>
-#include <mln/literal/ops.hh>
-#include <mln/fun/ops.hh>
-#include <mln/value/ops.hh>
#include <mln/core/image/graph_elt_window.hh>
+#include <mln/core/concept/function.hh>
+#include <mln/core/neighb.hh>
+#include <mln/core/var.hh>
+
+#include <mln/accu/bbox.hh>
#include <mln/fun/i2v/array.hh>
@@ -51,8 +45,23 @@
#include <mln/debug/draw_graph.hh>
#include <mln/debug/println.hh>
-#include <mln/core/concept/function.hh>
-#include <mln/core/neighb.hh>
+
+
+
+// Expected neighbors for forward and backward iteration.
+static unsigned fwd[5][3] = { { 1, -1, -1 },
+ { 0, 2, 3 },
+ { 1, 4, -1 },
+ { 1, 4, -1 },
+ { 3, 2, -1 } };
+
+static unsigned bkd[5][3] = { { 1, -1, -1 },
+ { 3, 2, 0 },
+ { 4, 1, -1 },
+ { 4, 1, -1 },
+ { 2, 3, -1 } };
+
+
template <typename S>
struct viota_t : public mln::Function_p2v< viota_t<S> >
@@ -78,6 +87,7 @@ struct viota_t : public mln::Function_p2v< viota_t<S> >
+
int main()
{
using namespace mln;
@@ -140,6 +150,8 @@ int main()
mln_const_VAR(ima, (iota | pv));
{
+ // FIXME: Move this part to a special test case.
+
// Compute the bounding box of 'ima'.
accu::bbox<point2d> a;
mln_piter_(ima_t) p(ima.domain());
@@ -171,7 +183,6 @@ int main()
// We use the value 9 in debug::graph to represent edges to distinguish it
// from vertices holding a value of 1.
debug::draw_graph(ima_rep, pv, 1, 9);
- debug::println(ima_rep);
}
/*------------.
@@ -186,16 +197,18 @@ int main()
typedef graph_elt_window<util::graph, fsite_t> win_t;
win_t win;
-
+
{
// Window - Forward iteration
mln_qiter_(win_t) q(win, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
- << "including the site itself:" << std::endl;
+ i = 0;
for_all (q)
- std::cout << " " << q << " (level = " <<
ima(q) << ")" << std::endl;
+ {
+ mln_assertion(fwd[p.element().id()][i] == q.element().id());
+ ++i;
+ }
}
}
@@ -204,44 +217,43 @@ int main()
mln_bkd_qiter_(win_t) q(win, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
- << "including the site itself:" << std::endl;
+ i = 0;
for_all (q)
- std::cout << " " << q << " (level = " <<
ima(q) << ")" << std::endl;
+ {
+ mln_assertion(bkd[p.element().id()][i] == q.element().id());
+ ++i;
+ }
}
}
- typedef neighb<win_t> neigh_t;
-
+ typedef neighb<win_t> neighb_t;
+ neighb_t neigh(win);
{
// Neighborhood - Forward iteration
- neigh_t neigh(win);
- mln_niter_(neigh_t) n(neigh, p);
+ mln_niter_(neighb_t) n(neigh, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), " << std::endl;
+ i = 0;
for_all (n)
{
- mln_assertion(n != p);
- std::cout << " " << n << " (level = " <<
ima(n) << ")" << std::endl;
+ mln_assertion(fwd[p.element().id()][i] == n.element().id());
+ ++i;
}
}
}
{
// Neighborhood - Backward iteration
- neigh_t neigh(win);
- mln_bkd_niter_(neigh_t) n(neigh, p);
+ mln_bkd_niter_(neighb_t) n(neigh, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), " << std::endl;
+ i = 0;
for_all (n)
{
- mln_assertion(n != p);
- std::cout << " " << n << " (level = " <<
ima(n) << ")" << std::endl;
+ mln_assertion(bkd[p.element().id()][i] == n.element().id());
+ ++i;
}
}
}
- std::cout << std::endl;
}
diff --git a/milena/tests/core/image/line_graph_image.cc
b/milena/tests/core/image/line_graph_image.cc
index e40055a..14a43db 100644
--- a/milena/tests/core/image/line_graph_image.cc
+++ b/milena/tests/core/image/line_graph_image.cc
@@ -34,7 +34,6 @@
#include <mln/core/alias/point2d.hh>
#include <mln/pw/all.hh>
-//#include <mln/core/image/line_graph_image.hh>
#include <mln/core/image/line_graph_elt_window.hh>
#include <mln/core/site_set/p_edges.hh>
#include <mln/core/neighb.hh>
@@ -45,6 +44,22 @@
#include <mln/core/var.hh>
+
+// Expected neighbors for forward and backward iteration.
+static unsigned fwd[5][3] = { { 1, 2, -1 },
+ { 0, 2, 4 },
+ { 0, 1, 3 },
+ { 2, 4, -1 },
+ { 1, 3, -1 } };
+
+static unsigned bkd[5][3] = { { 2, 1, -1 },
+ { 4, 2, 0 },
+ { 3, 1, 0 },
+ { 4, 2, -1 },
+ { 3, 1, -1 } };
+
+
+
template <typename S>
struct viota_t : public mln::Function_p2v< viota_t<S> >
{
@@ -69,6 +84,7 @@ struct viota_t : public mln::Function_p2v< viota_t<S> >
+
int main()
{
using namespace mln;
@@ -134,14 +150,6 @@ int main()
mln_edge_iter_(util::graph) ei(g);
mln_edge_nbh_edge_iter_(util::graph) en(ei);
- for_all(ei)
- {
- std::cout << ei << std::endl;
- for_all(en)
- std::cout << en << std::endl;
- std::cout << "-----" << std::endl;
- }
-
// Manual iteration over the domain of IMA.
mln_piter_(ima_t) p(ima.domain());
unsigned i = 10;
@@ -149,66 +157,66 @@ int main()
mln_assertion(ima(p) == i++);
typedef line_graph_elt_window<util::graph, fsite_t> win_t;
- typedef neighb<win_t> neigh_t;
+ win_t win;
{
// Window - Forward iteration
- win_t win;
mln_fwd_qiter_(win_t) q(win, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
- << "including the site itself:" << std::endl;
+ i = 0;
for_all (q)
- std::cout << " " << q << " (level = " <<
ima(q) << ")" << std::endl;
+ {
+ mln_assertion(fwd[p.element().id()][i] == q.element().id());
+ ++i;
+ }
}
- std::cout << std::endl;
}
{
// Window - Backward iteration
- win_t win;
mln_bkd_qiter_(win_t) q(win, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
- << "including the site itself:" << std::endl;
+ i = 0;
for_all (q)
- std::cout << " " << q << " (level = " <<
ima(q) << ")" << std::endl;
+ {
+ mln_assertion(bkd[p.element().id()][i] == q.element().id());
+ ++i;
+ }
}
- std::cout << std::endl;
}
+
+
+ typedef neighb<win_t> neighb_t;
+ neighb_t neigh(win);
+
{
// Neighborhood - Forward iteration
- neigh_t neigh(win_t());
- mln_fwd_niter_(neigh_t) n(neigh, p);
+ mln_fwd_niter_(neighb_t) n(neigh, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), " << std::endl;
+ i = 0;
for_all (n)
{
- std::cout << " " << n << " (level = " <<
ima(n) << ")" << std::endl;
- mln_assertion(n != p);
+ mln_assertion(fwd[p.element().id()][i] == n.element().id());
+ ++i;
}
}
- std::cout << std::endl;
}
{
// Neighborhood - Backward iteration
- neigh_t neigh(win_t());
- mln_bkd_niter_(neigh_t) n(neigh, p);
+ mln_bkd_niter_(neighb_t) n(neigh, p);
for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), " << std::endl;
+ i = 0;
for_all (n)
{
- std::cout << " " << n << " (level = " <<
ima(n) << ")" << std::endl;
- mln_assertion(n != p);
+ mln_assertion(bkd[p.element().id()][i] == n.element().id());
+ ++i;
}
}
- std::cout << std::endl;
}
- std::cout << std::endl;
}
--
1.5.6.5