* mln/core/image/graph_elt_neighborhood.hh,
* mln/core/image/graph_elt_window.hh:
Use the new util::graph API.
* mln/core/image/graph_window_piter.hh,
* mln/core/image/graph_neighborhood_piter.hh:
Update template parameters.
* mln/core/image/graph_psite.hh:
Deleted.
Replaced by mln/util/internal/graph_vertex_psite.
* mln/core/image/image2d.hh: Update comments.
* mln/core/internal/graph_iter_base.hh:
Deleted.
Replaced by mln/util/internal/graph_iter_base.hh.
* mln/core/internal/graph_vicinity_piter.hh: Renamed as...
* mln/core/internal/graph_relative_piter.hh: ...this.
* mln/core/internal/site_relative_iterator_base.hh:
Update an assertion.
* mln/core/site_set/p_vertices.hh,
* mln/core/site_set/p_edges.hh: returns the function by reference.
* mln/labeling/blobs.hh,
* mln/core/site_set/p_graph_piter.hh: reindent.
* mln/core/var.hh: add mln_const_VAR().
* mln/util/internal/graph_psite_base.hh:
pass the vertex id to the site set's function instead of the
vertex itself.
* tests/core/image/graph_image.cc: Update according the new graph
structure.
---
milena/ChangeLog | 43 +++
milena/mln/core/image/graph_elt_neighborhood.hh | 69 ++---
milena/mln/core/image/graph_elt_window.hh | 98 +++---
milena/mln/core/image/graph_neighborhood_piter.hh | 117 ++++----
milena/mln/core/image/graph_psite.hh | 341 --------------------
milena/mln/core/image/graph_window_piter.hh | 102 +++---
milena/mln/core/image/image2d.hh | 4 +-
milena/mln/core/internal/graph_iter_base.hh | 135 --------
...h_vicinity_piter.hh => graph_relative_piter.hh} | 64 +---
.../core/internal/site_relative_iterator_base.hh | 3 +-
milena/mln/core/site_set/p_edges.hh | 13 +-
milena/mln/core/site_set/p_graph_piter.hh | 4 +-
milena/mln/core/site_set/p_vertices.hh | 4 +-
milena/mln/core/var.hh | 5 +
milena/mln/labeling/blobs.hh | 6 +-
milena/mln/util/internal/graph_psite_base.hh | 2 +-
milena/tests/core/image/graph_image.cc | 186 ++++++++----
17 files changed, 388 insertions(+), 808 deletions(-)
delete mode 100644 milena/mln/core/image/graph_psite.hh
delete mode 100644 milena/mln/core/internal/graph_iter_base.hh
rename milena/mln/core/internal/{graph_vicinity_piter.hh => graph_relative_piter.hh}
(61%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index b1305d2..cd2632d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,46 @@
+2008-10-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Update the window and the neighborhood on graph vertices.
+
+ * mln/core/image/graph_elt_neighborhood.hh,
+ * mln/core/image/graph_elt_window.hh:
+ Use the new util::graph API.
+
+ * mln/core/image/graph_window_piter.hh,
+ * mln/core/image/graph_neighborhood_piter.hh:
+ Update template parameters.
+
+ * mln/core/image/graph_psite.hh:
+ Deleted.
+ Replaced by mln/util/internal/graph_vertex_psite.
+
+ * mln/core/image/image2d.hh: Update comments.
+
+ * mln/core/internal/graph_iter_base.hh:
+ Deleted.
+ Replaced by mln/util/internal/graph_iter_base.hh.
+
+ * mln/core/internal/graph_vicinity_piter.hh: Renamed as...
+ * mln/core/internal/graph_relative_piter.hh: ...this.
+
+ * mln/core/internal/site_relative_iterator_base.hh:
+ Update an assertion.
+
+ * mln/core/site_set/p_vertices.hh,
+ * mln/core/site_set/p_edges.hh: returns the function by reference.
+
+ * mln/labeling/blobs.hh,
+ * mln/core/site_set/p_graph_piter.hh: reindent.
+
+ * mln/core/var.hh: add mln_const_VAR().
+
+ * mln/util/internal/graph_psite_base.hh:
+ pass the vertex id to the site set's function instead of the
+ vertex itself.
+
+ * tests/core/image/graph_image.cc: Update according the new graph
+ structure.
+
2008-10-28 Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add morphological top hats.
diff --git a/milena/mln/core/image/graph_elt_neighborhood.hh
b/milena/mln/core/image/graph_elt_neighborhood.hh
index df0420a..80f40d4 100644
--- a/milena/mln/core/image/graph_elt_neighborhood.hh
+++ b/milena/mln/core/image/graph_elt_neighborhood.hh
@@ -31,9 +31,6 @@
/// \file mln/core/image/graph_elt_neighborhood.hh
/// \brief Definition of the elementary ``neighborhood'' on a graph.
-/* FIXME: Have a consistent naming: we have neighborhood (without '_')
- but point_, neighb_, etc. */
-
/* FIXME: Factor those classes:
- mln::graph_elt_window
- mln::graph_elt_neighborhood
@@ -42,14 +39,10 @@
See
https://trac.lrde.org/olena/ticket/139. */
-/* FIXME: Due to the poor interface of mln::p_line_graph and
- mln::util::graph, we show to much implementation details here.
- Enrich their interfaces to avoid that. */
-
# include <set>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/image/graph_psite.hh>
+# include <mln/util/internal/graph_vertex_psite.hh>
# include <mln/core/image/graph_neighborhood_piter.hh>
# include <mln/core/image/graph_elt_window.hh>
@@ -58,35 +51,35 @@
namespace mln
{
// Fwd decls.
- template <typename P, typename N> class graph_neighborhood_fwd_piter;
- template <typename P, typename N> class graph_neighborhood_bkd_piter;
+ template <typename G, typename F, typename N> class
graph_neighborhood_fwd_piter;
+ template <typename G, typename F, typename N> class
graph_neighborhood_bkd_piter;
/// \brief Elementary neighborhood on graph class.
- template <typename P>
+ template <typename G, typename F>
class graph_elt_neighborhood
- : public Neighborhood< graph_elt_neighborhood<P> >
+ : public Neighborhood< graph_elt_neighborhood<G, F> >
{
- typedef graph_elt_neighborhood<P> self_;
+ typedef graph_elt_neighborhood<G, F> self_;
public:
/// Associated types.
/// \{
/// The type of psite corresponding to the neighborhood.
- typedef graph_psite<P> psite;
+ typedef internal::vertex_psite<G, F> psite;
/// The type of site corresponding to the neighborhood.
typedef mln_site(psite) site;
// The type of the set of neighbors (vertex ids adjacent to the
// reference psite).
- typedef std::set<util::vertex_id> sites_t;
+ typedef std::set<unsigned> sites_t;
/// \brief Site_Iterator type to browse the psites of the
/// neighborhood w.r.t. the ordering of vertices.
- typedef graph_neighborhood_fwd_piter<P, self_> fwd_niter;
+ typedef graph_neighborhood_fwd_piter<G, F, self_> fwd_niter;
/// \brief Site_Iterator type to browse the psites of the
/// neighborhood w.r.t. the reverse ordering of vertices.
- typedef graph_neighborhood_bkd_piter<P, self_> bkd_niter;
+ typedef graph_neighborhood_bkd_piter<G, F, self_> bkd_niter;
/// The default niter type.
typedef fwd_niter niter;
@@ -95,9 +88,9 @@ namespace mln
/// Conversions.
/// \{
/// The window type corresponding to this neighborhood.
- typedef graph_elt_window<P> window;
+ typedef graph_elt_window<G, F> window;
/// Create a window corresponding to this neighborhood.
- window to_window() const;
+ window win() const;
/// \}
/// Services for iterators.
@@ -111,44 +104,30 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
- template <typename P>
+ template <typename G, typename F>
inline
- graph_elt_window<P>
- graph_elt_neighborhood<P>::to_window() const
+ graph_elt_window<G, F>
+ graph_elt_neighborhood<G, F>::win() const
{
- return graph_elt_window<P>();
+ return graph_elt_window<G, F>();
}
- template <typename P>
+ template <typename G, typename F>
template <typename Piter>
inline
void
- graph_elt_neighborhood<P>::compute_sites_(Site_Iterator<Piter>& piter_)
const
+ graph_elt_neighborhood<G, F>::compute_sites_(Site_Iterator<Piter>&
piter_) const
{
Piter& piter = exact(piter_);
- util::vertex_id ref_vertex_id = piter.center().vertex_id();
+ unsigned central_vertex = piter.center().v().id();
+ const G& g = piter.center().graph();
+
sites_t& sites = piter.sites();
sites.clear();
- const util::vertex<P>& ref_vertex =
- piter.center().site_set().gr_->vertex(ref_vertex_id);
- /* FIXME: Move this computation out of the neighborhood. In fact,
- this should be a service of the graph, also proposed by the
- p_line_graph. */
+
// Adjacent vertices.
- for (std::vector<util::edge_id>::const_iterator e =
- ref_vertex.edges.begin();
- e != ref_vertex.edges.end(); ++e)
- {
- util::vertex_id v1 = piter.center().site_set().gr_->edges()[*e]->v1();
- // We explicitly enforce that the reference piter vertex id is
- // *not* inserted into SITES.
- if (v1 != ref_vertex_id)
- sites.insert(v1);
- util::vertex_id v2 = piter.center().site_set().gr_->edges()[*e]->v2();
- // Likewise.
- if (v2 != ref_vertex_id)
- sites.insert(v2);
- }
+ for (unsigned i = 0; i < g.v_nmax_nbh_vertices(central_vertex); ++i)
+ sites.insert(g.v_ith_nbh_vertex(central_vertex, i));
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/core/image/graph_elt_window.hh
b/milena/mln/core/image/graph_elt_window.hh
index c679afd..0c7bb06 100644
--- a/milena/mln/core/image/graph_elt_window.hh
+++ b/milena/mln/core/image/graph_elt_window.hh
@@ -31,9 +31,6 @@
/// \file mln/core/image/graph_elt_window.hh
/// \brief Definition of the elementary ``window'' on a graph.
-/* FIXME: Have a consistent naming: we have window (without '_') but
- point_, neighb_, etc. */
-
/* FIXME: Factor those classes:
- mln::graph_elt_window
- mln::graph_elt_neighborhood
@@ -42,49 +39,60 @@
See
https://trac.lrde.org/olena/ticket/139. */
-/* FIXME: Due to the poor interface of mln::p_line_graph and
- mln::util::graph, we show to much implementation details here.
- Enrich their interfaces to avoid that. */
-
# include <mln/core/concept/window.hh>
-# include <mln/core/image/graph_psite.hh>
+# include <mln/util/internal/graph_vertex_psite.hh>
# include <mln/core/image/graph_window_piter.hh>
namespace mln
{
- // Fwd decls.
- template <typename P, typename W> class graph_window_fwd_piter;
- template <typename P, typename W> class graph_window_bkd_piter;
+
+ /// Forward declaration
+ template <typename G, typename F> class graph_elt_window;
+
+ namespace trait
+ {
+
+ ///FIXME: check that!
+ template <typename G, typename F>
+ struct window_< mln::graph_elt_window<G, F> >
+ {
+ typedef trait::window::size::unknown size;
+ typedef trait::window::support::irregular support;
+ typedef trait::window::definition::varying definition;
+ };
+
+ } // end of namespace mln::trait
/// \brief Elementary window on graph class.
- template <typename P>
- class graph_elt_window : public Window< graph_elt_window<P> >
+ template <typename G, typename F>
+ class graph_elt_window : public Window< graph_elt_window<G, F> >
{
- typedef graph_elt_window<P> self_;
+ typedef graph_elt_window<G, F> self_;
+ typedef mln_result(F) P;
public:
/// Associated types.
/// \{
/// The type of psite corresponding to the window.
- typedef graph_psite<P> psite;
+ typedef internal::vertex_psite<G, F> psite;
/// The type of site corresponding to the window.
typedef mln_site(psite) site;
// The type of the set of window sites (vertex ids adjacent to the
// reference psite).
- typedef std::set<util::vertex_id> sites_t;
+ typedef std::set<unsigned> sites_t;
// FIXME: This is a dummy value.
typedef void dpsite;
/// \brief Site_Iterator type to browse the psites of the window
/// w.r.t. the ordering of vertices.
- typedef graph_window_fwd_piter<P, self_> fwd_qiter;
+ typedef graph_window_fwd_piter<G, F, self_> fwd_qiter;
/// \brief Site_Iterator type to browse the psites of the window
/// w.r.t. the reverse ordering of vertices.
- typedef graph_window_bkd_piter<P, self_> bkd_qiter;
+ typedef graph_window_bkd_piter<G, F, self_> bkd_qiter;
/// The default qiter type.
typedef fwd_qiter qiter;
@@ -127,75 +135,61 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
- template <typename P>
+ template <typename G, typename F>
template <typename Piter>
inline
void
- graph_elt_window<P>::compute_sites_(Site_Iterator<Piter>& piter_)
const
+ graph_elt_window<G, F>::compute_sites_(Site_Iterator<Piter>& piter_)
const
{
Piter& piter = exact(piter_);
- util::vertex_id ref_vertex_id = piter.center().vertex_id();
+ const G& g = piter.center().graph();
+
+ unsigned central_vertex = piter.center().v().id();
sites_t& sites = piter.sites();
sites.clear();
- const util::vertex<P>& ref_vertex =
- piter.center().site_set().gr_->vertex(ref_vertex_id);
- /* FIXME: Move this computation out of the window. In fact,
- this should be a service of the graph, also proposed by the
- p_line_graph. */
- /* Adjacent vertices.
-
- We don't need to explicitely insert the reference piter (vertex
- id) itself into SITES, since it is part of the set of vertices
- adjacent to V1 and V2, and will therefore be
- automatically added. */
- for (std::vector<util::edge_id>::const_iterator e =
- ref_vertex.edges.begin();
- e != ref_vertex.edges.end(); ++e)
- {
- util::vertex_id v1 = piter.center().site_set().gr_->edges()[*e]->v1();
- sites.insert(v1);
- util::vertex_id v2 = piter.center().site_set().gr_->edges()[*e]->v2();
- sites.insert(v2);
- }
+
+ sites.insert(central_vertex);
+ for (unsigned i = 0; i < g.v_nmax_nbh_vertices(central_vertex); ++i)
+ sites.insert(g.v_ith_nbh_vertex(central_vertex, i));
}
- template <typename P>
+ template <typename G, typename F>
inline
bool
- graph_elt_window<P>::is_empty() const
+ graph_elt_window<G, F>::is_empty() const
{
return false;
}
- template <typename P>
+ template <typename G, typename F>
inline
bool
- graph_elt_window<P>::is_centered() const
+ graph_elt_window<G, F>::is_centered() const
{
return false;
}
- template <typename P>
+ template <typename G, typename F>
inline
bool
- graph_elt_window<P>::is_symmetric() const
+ graph_elt_window<G, F>::is_symmetric() const
{
return true;
}
- template <typename P>
+ template <typename G, typename F>
inline
unsigned
- graph_elt_window<P>::delta() const
+ graph_elt_window<G, F>::delta() const
{
// Dummy value (see the interface of the method above).
return 0;
}
- template <typename P>
+ template <typename G, typename F>
inline
- graph_elt_window<P>&
- graph_elt_window<P>::sym()
+ graph_elt_window<G, F>&
+ graph_elt_window<G, F>::sym()
{
return *this;
}
diff --git a/milena/mln/core/image/graph_neighborhood_piter.hh
b/milena/mln/core/image/graph_neighborhood_piter.hh
index a39128f..9823148 100644
--- a/milena/mln/core/image/graph_neighborhood_piter.hh
+++ b/milena/mln/core/image/graph_neighborhood_piter.hh
@@ -31,26 +31,25 @@
/// \file mln/core/image/graph_neighborhood_piter.hh
/// \brief Definition of a point iterator on a graph neighborhood.
-# include <mln/core/internal/graph_vicinity_piter.hh>
-
-/* FIXME: Due to the poor interface of mln::p_graph and
- mln::util::graph, we show to much implementation details here.
- Enrich their interfaces to avoid that. */
+# include <mln/core/internal/graph_relative_piter.hh>
namespace mln
{
- /*-------------------------------------.
- | graph_neighborhood_fwd_piter<P, N>. |
- `-------------------------------------*/
+ /*----------------------------------------.
+ | graph_neighborhood_fwd_piter<G, F, N>. |
+ `----------------------------------------*/
- template <typename P, typename N>
+ /// \p G Graph type.
+ /// \p F function i2p used in the p_vertices<G, F>.
+ /// \p N Type of the neighborhood.
+ template <typename G, typename F, typename N>
class graph_neighborhood_fwd_piter :
- public internal::graph_vicinity_piter_< P, N,
- graph_neighborhood_fwd_piter<P, N> >
+ public internal::graph_relative_piter< mln_result(F), N,
+ graph_neighborhood_fwd_piter<G, F, N> >
{
- typedef graph_neighborhood_fwd_piter<P, N> self_;
- typedef internal::graph_vicinity_piter_<P, N, self_> super_;
+ typedef graph_neighborhood_fwd_piter<G, F, N> self_;
+ typedef internal::graph_relative_piter<mln_result(F), N, self_> super_;
public:
/// The Point_Site type.
@@ -83,21 +82,21 @@ namespace mln
private:
/// An iterator on the set of adjacent edges.
- typename super_::sites_t::const_iterator i_;
+ typename super_::sites_t::const_iterator i_;
};
- /*-------------------------------------.
- | graph_neighborhood_bkd_piter<P, N>. |
- `-------------------------------------*/
+ /*----------------------------------------.
+ | graph_neighborhood_bkd_piter<G, F, N>. |
+ `----------------------------------------*/
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
class graph_neighborhood_bkd_piter :
- public internal::graph_vicinity_piter_< P, N,
- graph_neighborhood_bkd_piter<P, N> >
+ public internal::graph_relative_piter< mln_result(F), N,
+ graph_neighborhood_bkd_piter<G, F, N> >
{
- typedef graph_neighborhood_bkd_piter<P, N> self_;
- typedef internal::graph_vicinity_piter_<P, N, self_> super_;
+ typedef graph_neighborhood_bkd_piter<G, F, N> self_;
+ typedef internal::graph_relative_piter<mln_result(F), N, self_> super_;
/// The Point_Site type.
typedef mln_psite(N) psite;
@@ -129,134 +128,134 @@ namespace mln
private:
/// An iterator on the set of adjacent edges.
- typename super_::sites_t::const_reverse_iterator i_;
+ typename super_::sites_t::const_reverse_iterator i_;
};
# ifndef MLN_INCLUDE_ONLY
- /*-------------------------------------.
- | graph_neighborhood_fwd_piter<P, N>. |
- `-------------------------------------*/
+ /*----------------------------------------.
+ | graph_neighborhood_fwd_piter<G, F, N>. |
+ `----------------------------------------*/
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
- graph_neighborhood_fwd_piter<P, N>::graph_neighborhood_fwd_piter()
+ graph_neighborhood_fwd_piter<G, F, N>::graph_neighborhood_fwd_piter()
{
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
template <typename Pref>
inline
- graph_neighborhood_fwd_piter<P, N>::graph_neighborhood_fwd_piter(const
Neighborhood<N>& nbh,
+ graph_neighborhood_fwd_piter<G, F, N>::graph_neighborhood_fwd_piter(const
Neighborhood<N>& nbh,
const Pref& p_ref)
: super_(p_ref)
{
this->change_target(exact(nbh));
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
bool
- graph_neighborhood_fwd_piter<P, N>::is_valid_() const
+ graph_neighborhood_fwd_piter<G, F, N>::is_valid_() const
{
return i_ != this->sites_.end();
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
void
- graph_neighborhood_fwd_piter<P, N>::invalidate_()
+ graph_neighborhood_fwd_piter<G, F, N>::invalidate_()
{
i_ = this->sites_.end();
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
void
- graph_neighborhood_fwd_piter<P, N>::do_start_()
+ graph_neighborhood_fwd_piter<G, F, N>::do_start_()
{
this->site_set().compute_sites_(*this);
i_ = this->sites_.begin();
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
void
- graph_neighborhood_fwd_piter<P, N>::do_next_()
+ graph_neighborhood_fwd_piter<G, F, N>::do_next_()
{
++i_;
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
mln_psite(N)
- graph_neighborhood_fwd_piter<P, N>::compute_p_() const
+ graph_neighborhood_fwd_piter<G, F, N>::compute_p_() const
{
- return graph_psite<P>(this->center().site_set(), *i_);
+ return internal::vertex_psite<G, F>(this->center().site_set(), *i_);
}
- /*-------------------------------------.
- | graph_neighborhood_bkd_piter<P, N>. |
- `-------------------------------------*/
+ /*----------------------------------------.
+ | graph_neighborhood_bkd_piter<G, F, N>. |
+ `----------------------------------------*/
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
- graph_neighborhood_bkd_piter<P, N>::graph_neighborhood_bkd_piter()
+ graph_neighborhood_bkd_piter<G, F, N>::graph_neighborhood_bkd_piter()
{
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
template <typename Pref>
inline
- graph_neighborhood_bkd_piter<P, N>::graph_neighborhood_bkd_piter(const
Neighborhood<N>& nbh,
+ graph_neighborhood_bkd_piter<G, F, N>::graph_neighborhood_bkd_piter(const
Neighborhood<N>& nbh,
const Pref& p_ref)
: super_(p_ref)
{
this->change_target(exact(nbh));
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
bool
- graph_neighborhood_bkd_piter<P, N>::is_valid_() const
+ graph_neighborhood_bkd_piter<G, F, N>::is_valid_() const
{
return i_ != this->sites_.rend();
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
void
- graph_neighborhood_bkd_piter<P, N>::invalidate_()
+ graph_neighborhood_bkd_piter<G, F, N>::invalidate_()
{
i_ = this->sites_.rend();
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
void
- graph_neighborhood_bkd_piter<P, N>::do_start_()
+ graph_neighborhood_bkd_piter<G, F, N>::do_start_()
{
this->site_set().compute_sites_(*this);
i_ = this->sites_.rbegin();
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
void
- graph_neighborhood_bkd_piter<P, N>::do_next_()
+ graph_neighborhood_bkd_piter<G, F, N>::do_next_()
{
++i_;
}
- template <typename P, typename N>
+ template <typename G, typename F, typename N>
inline
mln_psite(N)
- graph_neighborhood_bkd_piter<P, N>::compute_p_() const
+ graph_neighborhood_bkd_piter<G, F, N>::compute_p_() const
{
- return graph_psite<P>(this->center().site_set(), *i_);
+ return internal::vertex_psite<G, F>(this->center().site_set(), *i_);
}
diff --git a/milena/mln/core/image/graph_psite.hh b/milena/mln/core/image/graph_psite.hh
deleted file mode 100644
index 23b0638..0000000
--- a/milena/mln/core/image/graph_psite.hh
+++ /dev/null
@@ -1,341 +0,0 @@
-// 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
-// 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_IMAGE_GRAPH_PSITE_HH
-# define MLN_CORE_IMAGE_GRAPH_PSITE_HH
-
-/// \file mln/core/image/graph_psite.hh
-/// \brief Definition of a graph-based psite.
-
-# include <mln/core/internal/pseudo_site_base.hh>
-
-# include <mln/core/site_set/p_graph.hh>
-
-/* FIXME: This class shares a lot with line_graph_psite. Factor as
- much as possible. */
-
-// FIXME: Rename graph_psite as p_graph_psite, and move this
-// to core/site_set.
-
-
-namespace mln
-{
-
- // Forward declaration.
- template <typename P> class p_graph;
- template <typename P> class graph_psite;
-
-
- /// \brief Point site associated to a mln::graph_image.
- ///
- /// \arg \p P The type of the site.
- template <typename P>
- class graph_psite
- : public internal::pseudo_site_base_< const P&, graph_psite<P> >
- {
- typedef graph_psite<P> self_;
-
- public:
- // This associated type is important to know that this particular
- // pseudo site knows the site set it refers to.
- typedef p_graph<P> target;
-
- /// Construction and assignment.
- /// \{
- graph_psite();
- graph_psite(const p_graph<P>& pg_, util::vertex_id id);
- /// \}
-
- /// Psite manipulators.
- /// \{
- /// Is this psite valid?
- bool is_valid() const;
- /// Invalidate this psite.
- void invalidate();
- /// \}
-
- /// Site set manipulators.
- /// \{
- /// \brief Get the site set (shortcut for *target()).
- /// \pre Member plg_ is non null.
- const target& site_set() const;
-
- /// Get a pointer to the target site_set.
- const target* target_() const;
- /// Set the target site_set.
- void change_target(const target& new_target);
- /// \}
-
- /// Proxy manipulators.
- /// \{
- /// Return the site corresponding to this psite.
- const P& subj_();
- /// \}
-
- /// Vertex id manipulators.
- //// \{
- /// Return the vertex id of this point site.
- util::vertex_id vertex_id() const;
- /// Set the vertex id of this point site.
- void change_vertex_id(const util::vertex_id& id);
- /// Increment the vertex id of this point site.
- void inc_vertex_id();
- /// Increment the vertex id of this point site.
- void dec_vertex_id();
- /// \}
-
- private:
- /// Site-related members.
- /// \{
- /// Update the site corresponding to this psite.
- void update_();
- // The site corresponding to this psite.
- P p_;
- /// \}
-
- private:
- /// Graph-related members.
- /// \{
- /// The p_graph this point site belongs to.
- const target* pg_;
- /// The id of the vertex this psite is pointing towards.
- util::vertex_id id_;
- /// \}
- };
-
-
- /// Comparison of two mln::graph_psite<P> instances.
- /// \{
- /* FIXME: Shouldn't those comparisons be part of a much general
- mechanism? */
-
- /// \brief Is \a lhs equal to \a rhs?
- ///
- /// \pre Arguments \a lhs and \a rhs must belong to the same
- /// mln::p_graph.
- template <typename P>
- bool
- operator==(const graph_psite<P>& lhs, const graph_psite<P>& rhs);
-
- /// \brief Is \a lhs not equal to \a rhs?
- ///
- /// \pre Arguments \a lhs and \a rhs must belong to the same
- /// mln::p_graph.
- template <typename P>
- bool
- operator!=(const graph_psite<P>& lhs, const graph_psite<P>& rhs);
-
- /// \brief Is \a lhs ``less'' than \a rhs?
- ///
- /// This comparison is required by algorithms sorting psites.
- ///
- /// \pre Arguments \a lhs and \a rhs must belong to the same
- /// mln::p_graph.
- template <typename P>
- bool
- operator< (const graph_psite<P>& lhs, const graph_psite<P>&
rhs);
- /// \}
-
-
- template <typename P>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const graph_psite<P>& p);
-
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename P>
- inline
- graph_psite<P>::graph_psite()
- : pg_(0)
- {
- }
-
- template <typename P>
- inline
- graph_psite<P>::graph_psite(const p_graph<P>& g, util::vertex_id id)
- // FIXME: Use change_target instead.
- : pg_(&g),
- id_(id)
- {
- update_();
- }
-
- template <typename P>
- inline
- bool
- graph_psite<P>::is_valid() const
- {
- /* FIXME: Instead of `plg_->gr_->nvertices()', we should have
- something like `run_->has_edge_id(id_)' (see the implementation of
- p_run_psite. */
- return pg_ && id_ < pg_->gr_->nvertices();
- }
-
- template <typename P>
- inline
- void
- graph_psite<P>::invalidate()
- {
- /* FIXME: Instead of `plg_->gr_->nvertices()', we should have
- something like `run_->has_edge_id(id_)' (see the implementation of
- p_run_psite. */
- id_ = pg_->gr_->nvertices();
- }
-
- template <typename P>
- inline
- const p_graph<P>&
- graph_psite<P>::site_set() const
- {
- mln_precondition(target_());
- return *target_();
- }
-
- template <typename P>
- inline
- const p_graph<P>*
- graph_psite<P>::target_() const
- {
- return pg_;
- }
-
- template <typename P>
- inline
- void
- graph_psite<P>::change_target(const target& new_target)
- {
- pg_ = &new_target;
- invalidate();
- }
-
- // FIXME: Write or extend a test to exercise this method.
- template <typename P>
- inline
- const P&
- graph_psite<P>::subj_()
- {
- return p_;
- }
-
- template <typename P>
- inline
- util::vertex_id
- graph_psite<P>::vertex_id() const
- {
- return id_;
- }
-
- template <typename P>
- inline
- void
- graph_psite<P>::change_vertex_id(const util::vertex_id& id)
- {
- id_ = id;
- if (is_valid())
- update_();
- }
-
- template <typename P>
- inline
- void
- graph_psite<P>::inc_vertex_id()
- {
- ++id_.to_equiv();
- if (is_valid())
- update_();
- }
-
- template <typename P>
- inline
- void
- graph_psite<P>::dec_vertex_id()
- {
- --id_.to_equiv();
- if (is_valid())
- update_();
- }
-
- template <typename P>
- inline
- void
- graph_psite<P>::update_()
- {
- mln_precondition(is_valid());
- p_ = site_set().point_from_id(id_);
- }
-
-
- /*--------------.
- | Comparisons. |
- `--------------*/
-
- template <typename P>
- bool
- operator==(const graph_psite<P>& lhs, const graph_psite<P>& rhs)
- {
- mln_assertion(lhs.target_() == rhs.target_());
- return lhs.vertex_id() == rhs.vertex_id();
- }
-
- template <typename P>
- bool
- operator!=(const graph_psite<P>& lhs, const graph_psite<P>& rhs)
- {
- mln_assertion(lhs.target_() == rhs.target_());
- return lhs.vertex_id() != rhs.vertex_id();
- }
-
- template <typename P>
- bool
- operator< (const graph_psite<P>& lhs, const graph_psite<P>&
rhs)
- {
- mln_assertion(lhs.target_() == rhs.target_());
- return lhs.vertex_id() < rhs.vertex_id();
- }
-
-
- /*------------------.
- | Pretty-printing. |
- `------------------*/
-
- template <typename P>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const graph_psite<P>& p)
- {
- return ostr << p.unproxy_();
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
-
-} // end of mln
-
-#endif // MLN_CORE_IMAGE_GRAPH_PSITE_HH
diff --git a/milena/mln/core/image/graph_window_piter.hh
b/milena/mln/core/image/graph_window_piter.hh
index d9191ee..af15998 100644
--- a/milena/mln/core/image/graph_window_piter.hh
+++ b/milena/mln/core/image/graph_window_piter.hh
@@ -31,26 +31,22 @@
/// \file mln/core/image/graph_window_piter.hh
/// \brief Definition of a point iterator on a graph window.
-# include <mln/core/internal/graph_vicinity_piter.hh>
-
-/* FIXME: Due to the poor interface of mln::p_graph and
- mln::util::graph, we show to much implementation details here.
- Enrich their interfaces to avoid that. */
+# include <mln/core/internal/graph_relative_piter.hh>
namespace mln
{
- /*-------------------------------.
- | graph_window_fwd_piter<P, W>. |
- `-------------------------------*/
+ /*----------------------------------.
+ | graph_window_fwd_piter<G, F, W>. |
+ `----------------------------------*/
/// \brief Forward iterator on graph window.
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
class graph_window_fwd_piter :
- public internal::graph_vicinity_piter_< P, W, graph_window_fwd_piter<P, W>
>
+ public internal::graph_relative_piter< mln_result(F), W,
graph_window_fwd_piter<G, F, W> >
{
- typedef graph_window_fwd_piter<P, W> self_;
- typedef internal::graph_vicinity_piter_<P, W, self_> super_;
+ typedef graph_window_fwd_piter<G, F, W> self_;
+ typedef internal::graph_relative_piter<mln_result(F), W, self_> super_;
public:
/// The Point_Site type.
@@ -82,21 +78,21 @@ namespace mln
private:
/// An iterator on the set of adjacent vertices.
- typename super_::sites_t::const_iterator i_;
+ typename super_::sites_t::const_iterator i_;
};
- /*-------------------------------.
- | graph_window_bkd_piter<P, W>. |
- `-------------------------------*/
+ /*----------------------------------.
+ | graph_window_bkd_piter<G, F, W>. |
+ `----------------------------------*/
/// \brief Backward iterator on graph window.
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
class graph_window_bkd_piter :
- public internal::graph_vicinity_piter_< P, W, graph_window_bkd_piter<P, W>
>
+ public internal::graph_relative_piter< mln_result(F), W,
graph_window_bkd_piter<G, F, W> >
{
- typedef graph_window_bkd_piter<P, W> self_;
- typedef internal::graph_vicinity_piter_<P, W, self_> super_;
+ typedef graph_window_bkd_piter<G, F, W> self_;
+ typedef internal::graph_relative_piter<mln_result(F), W, self_> super_;
public:
/// The Point_Site type.
@@ -128,7 +124,7 @@ namespace mln
private:
/// An iterator on the set of adjacent vertices.
- typename super_::sites_t::const_reverse_iterator i_;
+ typename super_::sites_t::const_reverse_iterator i_;
};
@@ -136,126 +132,126 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
/*-------------------------------.
- | graph_window_fwd_piter<P, W>. |
+ | graph_window_fwd_piter<G, F, W>. |
`-------------------------------*/
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
- graph_window_fwd_piter<P, W>::graph_window_fwd_piter()
+ graph_window_fwd_piter<G, F, W>::graph_window_fwd_piter()
{
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
template <typename Pref>
inline
- graph_window_fwd_piter<P, W>::graph_window_fwd_piter(const Window<W>&
win,
+ graph_window_fwd_piter<G, F, W>::graph_window_fwd_piter(const
Window<W>& win,
const Pref& p_ref)
: super_(p_ref)
{
this->change_target(exact(win));
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
bool
- graph_window_fwd_piter<P, W>::is_valid_() const
+ graph_window_fwd_piter<G, F, W>::is_valid_() const
{
return i_ != this->sites_.end();
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
void
- graph_window_fwd_piter<P, W>::invalidate_()
+ graph_window_fwd_piter<G, F, W>::invalidate_()
{
i_ = this->sites_.end();
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
void
- graph_window_fwd_piter<P, W>::do_start_()
+ graph_window_fwd_piter<G, F, W>::do_start_()
{
this->site_set().compute_sites_(*this);
i_ = this->sites_.begin();
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
void
- graph_window_fwd_piter<P, W>::do_next_()
+ graph_window_fwd_piter<G, F, W>::do_next_()
{
++i_;
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
mln_psite(W)
- graph_window_fwd_piter<P, W>::compute_p_() const
+ graph_window_fwd_piter<G, F, W>::compute_p_() const
{
- return graph_psite<P>(this->center().site_set(), *i_);
+ return internal::vertex_psite<G, F>(this->center().site_set(), *i_);
}
/*-------------------------------.
- | graph_window_bkd_piter<P, W>. |
+ | graph_window_bkd_piter<G, F, W>. |
`-------------------------------*/
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
- graph_window_bkd_piter<P, W>::graph_window_bkd_piter()
+ graph_window_bkd_piter<G, F, W>::graph_window_bkd_piter()
{
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
template <typename Pref>
inline
- graph_window_bkd_piter<P, W>::graph_window_bkd_piter(const Window<W>&
win,
+ graph_window_bkd_piter<G, F, W>::graph_window_bkd_piter(const
Window<W>& win,
const Pref& p_ref)
: super_(p_ref)
{
this->change_target(exact(win));
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
bool
- graph_window_bkd_piter<P, W>::is_valid_() const
+ graph_window_bkd_piter<G, F, W>::is_valid_() const
{
return i_ != this->sites_.rend();
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
void
- graph_window_bkd_piter<P, W>::invalidate_()
+ graph_window_bkd_piter<G, F, W>::invalidate_()
{
i_ = this->sites_.rend();
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
void
- graph_window_bkd_piter<P, W>::do_start_()
+ graph_window_bkd_piter<G, F, W>::do_start_()
{
this->site_set().compute_sites_(*this);
i_ = this->sites_.rbegin();
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
void
- graph_window_bkd_piter<P, W>::do_next_()
+ graph_window_bkd_piter<G, F, W>::do_next_()
{
++i_;
}
- template <typename P, typename W>
+ template <typename G, typename F, typename W>
inline
mln_psite(W)
- graph_window_bkd_piter<P, W>::compute_p_() const
+ graph_window_bkd_piter<G, F, W>::compute_p_() const
{
- return graph_psite<P>(this->center().site_set(), *i_);
+ return internal::vertex_psite<G, F>(this->center().site_set(), *i_);
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/core/image/image2d.hh b/milena/mln/core/image/image2d.hh
index 45c62bc..edf0a40 100644
--- a/milena/mln/core/image/image2d.hh
+++ b/milena/mln/core/image/image2d.hh
@@ -55,7 +55,7 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename T> struct image2d;
@@ -255,7 +255,7 @@ namespace mln
- // Fwd decl.
+ // Forward declaration
template <typename T>
void init_(tag::border_t, unsigned& bdr, const image2d<T>& model);
diff --git a/milena/mln/core/internal/graph_iter_base.hh
b/milena/mln/core/internal/graph_iter_base.hh
deleted file mode 100644
index 2d7297c..0000000
--- a/milena/mln/core/internal/graph_iter_base.hh
+++ /dev/null
@@ -1,135 +0,0 @@
-// 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_GRAPH_ITER_BASE_HH
-# define MLN_CORE_INTERNAL_GRAPH_ITER_BASE_HH
-
-# include <mln/core/concept/iterator.hh>
-# include <mln/core/concept/proxy.hh>
-
-/// \file mln/core/internal/graph_iter_base.hh
-/// \brief Base class for graph iterators.
-
-namespace mln
-{
-
- namespace internal
- {
-
- /// Base class for graph iterators
- /// \p G graph type.
- /// \p S the type of the data pointed by the iterator.
- /// For instance : edge, vertex....
- template<typename G, typename S>
- class graph_iterator_base
- : public Iterator< graph_iterator_base<G> >,
- public internal::proxy_impl< const S&, graph_iterator_base<G> >
- {
- public:
- /// Constructors.
- /// \{
- graph_iterator_base();
- graph_iterator_base(const G& g);
- /// \}
-
- /// Iterator interface.
- /// \{
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
-
- /// Start an iteration.
- void start();
-
- /// Go to the next value.
- void next_();
-
- /// Return current index
- unsigned index() const;
- /// \}
-
- /// Proxy.
- /// \{
- /// Proxy subject
- const S& subj_();
- /// \}
-
- protected:
- const G *g_;
- unsigned i_;
- };
-
-
- template<typename G, typename S>
- class graph_fwd_iterator_base
- : public Iterator< graph_fwd_iterator_base<G> >,
- public internal::proxy_impl< const S&, graph_fwd_iterator_base<G> >
- {
- public:
- /// Construction and assignment.
- /// \{
- graph_fwd_iterator_base();
- graph_fwd_iterator_base(const G& g);
- /// \}
-
- /// Manipulation.
- /// \{
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
- /// \}
-
- /// Start an iteration.
- void start();
-
- /// Go to the next value.
- void next_();
-
- /// Return current index
- unsigned index() const;
-
- /// Proxy.
- /// \{
- /// Proxy Subject type
- typedef const mln_vertex(G)& q_subject;
-
- /// Proxy subject
- q_subject subj_();
- /// \}
-
- protected:
- const G *g_;
- unsigned i_;
- };
-
- } // End of namespace mln::internal.
-
-} // End of namespace mln.
-
-#endif // !MLN_CORE_INTERNAL_GRAPH_ITER_BASE_HH
diff --git a/milena/mln/core/internal/graph_vicinity_piter.hh
b/milena/mln/core/internal/graph_relative_piter.hh
similarity index 61%
rename from milena/mln/core/internal/graph_vicinity_piter.hh
rename to milena/mln/core/internal/graph_relative_piter.hh
index b51ab97..5b09421 100644
--- a/milena/mln/core/internal/graph_vicinity_piter.hh
+++ b/milena/mln/core/internal/graph_relative_piter.hh
@@ -25,45 +25,31 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_INTERNAL_GRAPH_VICINITY_PITER_HH
-# define MLN_CORE_INTERNAL_GRAPH_VICINITY_PITER_HH
+#ifndef MLN_CORE_INTERNAL_GRAPH_RELATIVE_PITER_HH
+# define MLN_CORE_INTERNAL_GRAPH_RELATIVE_PITER_HH
-/// \file mln/core/internal/graph_vicinity_piter.hh
+/// \file mln/core/internal/graph_relative_piter.hh
/// \brief Factored implementation for point iterators on a graph windows
-/// and graph neighborhoods, called "vicinities".
+/// and graph neighborhoods.
# include <set>
# include <mln/core/internal/site_relative_iterator_base.hh>
-# include <mln/core/site_set/p_graph.hh>
-# include <mln/core/image/graph_psite.hh>
/* FIXME: Factor those classes:
- - mln::internal::graph_vicinity_piter.hh
- - mln::internal::line_graph_vicinity_piter.hh */
-
-/* FIXME: Due to the poor interface of mln::p_graph and
- mln::util::graph, we show to much implementation details here.
- Enrich their interfaces to avoid that. */
-
+ - mln::internal::graph_relative_piter.hh
+ - mln::internal::line_graph_relative_piter.hh */
namespace mln
{
- // Fwd decls.
- template <typename P> class p_graph;
- template <typename P> class graph_psite;
-
- // FIXME: Consider renaming graph_vicinity_piter_ as
- // graph_relative_piter_.
-
namespace internal
{
/// \brief Base for iterator on a graph vicinity.
template <typename P, typename S, typename E>
- class graph_vicinity_piter_
+ class graph_relative_piter
: public internal::site_relative_iterator_base< S, E >
{
public:
@@ -74,8 +60,8 @@ namespace mln
// FIXME: Dummy value.
typedef void mesh;
- // The type of the set of vicinity sites (adjacent vertex ids).
- typedef std::set<util::vertex_id> sites_t;
+ // The type of the set of sites (adjacent vertex ids).
+ typedef std::set<unsigned> sites_t;
public:
/// Return the set of sites (adjacent vertex ids).
@@ -84,9 +70,9 @@ namespace mln
protected:
/// Construction.
/// \{
- graph_vicinity_piter_();
+ graph_relative_piter();
template <typename Pref>
- graph_vicinity_piter_(const Pref& p_ref);
+ graph_relative_piter(const Pref& p_ref);
/// \}
protected:
@@ -94,52 +80,34 @@ namespace mln
sites_t sites_;
};
-
- /// Print an mln::line_graph_vicinity_piter_<P, S, E>.
- template <typename P, typename S, typename E>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const graph_vicinity_piter_<P, S,
E>& p);
-
-
-
# ifndef MLN_INCLUDE_ONLY
template <typename P, typename S, typename E>
inline
- graph_vicinity_piter_<P, S, E>::graph_vicinity_piter_()
+ graph_relative_piter<P, S, E>::graph_relative_piter()
{
}
template <typename P, typename S, typename E>
template <typename Pref>
inline
- graph_vicinity_piter_<P, S, E>::graph_vicinity_piter_(const Pref& p_ref)
+ graph_relative_piter<P, S, E>::graph_relative_piter(const Pref& p_ref)
{
center_at(p_ref);
}
template <typename P, typename S, typename E>
inline
- std::set<util::vertex_id>&
- graph_vicinity_piter_<P, S, E>::sites()
+ std::set<unsigned>&
+ graph_relative_piter<P, S, E>::sites()
{
return sites_;
}
-
- template <typename P, typename S, typename E>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const graph_vicinity_piter_<P, S,
E>& p)
- {
- return ostr << p.unproxy_();
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
} // end of namespace mln
-#endif // ! MLN_CORE_INTERNAL_GRAPH_VICINITY_PITER_HH
+#endif // ! MLN_CORE_INTERNAL_GRAPH_RELATIVE_PITER_HH
diff --git a/milena/mln/core/internal/site_relative_iterator_base.hh
b/milena/mln/core/internal/site_relative_iterator_base.hh
index eeb2092..9b3a7d4 100644
--- a/milena/mln/core/internal/site_relative_iterator_base.hh
+++ b/milena/mln/core/internal/site_relative_iterator_base.hh
@@ -191,8 +191,7 @@ namespace mln
const mln_psite(S)&
site_relative_iterator_base<S,E>::subj_()
{
- mln_psite(S) p_now = exact(this)->compute_p_();
- mln_assertion(p_now == p_);
+ mln_assertion(exact(this)->compute_p_() == p_);
return p_;
}
diff --git a/milena/mln/core/site_set/p_edges.hh b/milena/mln/core/site_set/p_edges.hh
index 6a62f8b..2ce48b8 100644
--- a/milena/mln/core/site_set/p_edges.hh
+++ b/milena/mln/core/site_set/p_edges.hh
@@ -65,9 +65,10 @@ namespace mln
typedef p_edges<G, F> self_;
typedef internal::site_set_base_< typename F::result, self_ > super_;
+ public:
+ /// Type of the graph this site set is based on.
typedef G graph_t;
- public:
/// \brief Construct a graph edge psite set from a graph and a function.
///
/// \param gr The graph upon which the graph edge psite set is built.
@@ -118,7 +119,7 @@ namespace mln
/// Return the graph associated to this site set
const graph_t& graph() const;
/// Return the mapping function.
- F function() const;
+ const F& function() const;
/// \}
private:
@@ -231,7 +232,7 @@ namespace mln
template <typename G, typename F>
inline
- F
+ const F&
p_edges<G, F>::function() const
{
return f_;
@@ -241,11 +242,7 @@ namespace mln
bool
operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& 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.g_) == (*rhs.g_);
+ return lhs.graph() == rhs.graph();
}
template <typename G, typename F>
diff --git a/milena/mln/core/site_set/p_graph_piter.hh
b/milena/mln/core/site_set/p_graph_piter.hh
index 886be0d..ac356f3 100644
--- a/milena/mln/core/site_set/p_graph_piter.hh
+++ b/milena/mln/core/site_set/p_graph_piter.hh
@@ -139,8 +139,8 @@ namespace mln
p_graph_piter<S,I>::start_()
{
iter_.start();
- if (this->is_valid())
- update_();
+ if (this->is_valid())
+ update_();
}
template <typename S, typename I>
diff --git a/milena/mln/core/site_set/p_vertices.hh
b/milena/mln/core/site_set/p_vertices.hh
index cbae9fd..3b9eb82 100644
--- a/milena/mln/core/site_set/p_vertices.hh
+++ b/milena/mln/core/site_set/p_vertices.hh
@@ -138,7 +138,7 @@ namespace mln
/// Return the graph associated to this site set (const version)
const graph_t& graph() const;
/// Return the association function.
- F function() const;
+ const F& function() const;
/// \}
private:
@@ -293,7 +293,7 @@ namespace mln
template <typename G, typename F>
inline
- F
+ const F&
p_vertices<G, F>::function() const
{
return f_;
diff --git a/milena/mln/core/var.hh b/milena/mln/core/var.hh
index 39e5fa0..dfec471 100644
--- a/milena/mln/core/var.hh
+++ b/milena/mln/core/var.hh
@@ -40,5 +40,10 @@
typeof(Expr) Var = Expr; \
typedef typeof(Expr) Var##_t
+#define mln_const_VAR(Var, Expr) \
+ \
+ const typeof(Expr) Var = Expr; \
+ typedef const typeof(Expr) Var##_t
+
#endif // ! MLN_CORE_VAR_HH
diff --git a/milena/mln/labeling/blobs.hh b/milena/mln/labeling/blobs.hh
index 5711ac7..9f521a9 100644
--- a/milena/mln/labeling/blobs.hh
+++ b/milena/mln/labeling/blobs.hh
@@ -76,7 +76,7 @@ namespace mln
namespace generic
{
-
+
template <typename I, typename N, typename L>
mln_ch_value(I, L)
blobs_(const I& input, const N& nbh, L& nlabels)
@@ -122,10 +122,10 @@ namespace mln
}
while (! qu.is_empty());
}
-
+
return output;
}
-
+
} // end of namespace mln::labeling::impl::generic
diff --git a/milena/mln/util/internal/graph_psite_base.hh
b/milena/mln/util/internal/graph_psite_base.hh
index 38431a8..8e5a515 100644
--- a/milena/mln/util/internal/graph_psite_base.hh
+++ b/milena/mln/util/internal/graph_psite_base.hh
@@ -222,7 +222,7 @@ namespace mln
const typename graph_psite_base<V, P, S, E>::site&
graph_psite_base<V, P, S, E>::to_site() const
{
- return t_->function()(v_);
+ return t_->function()(v_.id());
}
} // end of namespace internal
diff --git a/milena/tests/core/image/graph_image.cc
b/milena/tests/core/image/graph_image.cc
index 7913589..34faf3a 100644
--- a/milena/tests/core/image/graph_image.cc
+++ b/milena/tests/core/image/graph_image.cc
@@ -33,13 +33,50 @@
#include <mln/accu/bbox.hh>
#include <mln/core/alias/box2d.hh>
#include <mln/core/alias/point2d.hh>
-#include <mln/core/image/graph_image.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/image/graph_window_piter.hh>
+#include <mln/core/image/graph_elt_neighborhood.hh>
-#include <mln/draw/graph.hh>
-#include <mln/debug/iota.hh>
+#include <mln/fun/i2v/array.hh>
+#include <mln/fun/p2v/iota.hh>
+
+#include <mln/util/graph.hh>
+
+#include <mln/debug/graph.hh>
+//#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
+#include <mln/core/concept/function.hh>
+
+template <typename S>
+struct viota_t : public mln::Function_p2v< viota_t<S> >
+{
+ typedef unsigned result;
+
+ viota_t(unsigned size)
+ {
+ v_.resize(size);
+ for (unsigned i = 0; i < size; ++i)
+ v_[i] = 10 + i;
+ }
+
+ unsigned
+ operator()(const mln_psite(S)& p) const
+ {
+ return v_[p.v().id()];
+ }
+
+ protected:
+ std::vector<result> v_;
+};
+
int main()
@@ -64,18 +101,19 @@ int main()
*/
// Points associated to vertices.
- std::vector<point2d> points;
- points.push_back(point2d(0,0)); // Point associated to vertex 0.
- points.push_back(point2d(2,2)); // Point associated to vertex 1.
- points.push_back(point2d(0,4)); // Point associated to vertex 2.
- points.push_back(point2d(4,3)); // Point associated to vertex 3.
- points.push_back(point2d(4,4)); // Point associated to vertex 4.
+ typedef fun::i2v::array<point2d> fpoint_t;
+ fpoint_t points(5);
+ points(0) = point2d(0,0); // Point associated to vertex 0.
+ points(1) = point2d(2,2); // Point associated to vertex 1.
+ points(2) = point2d(0,4); // Point associated to vertex 2.
+ points(3) = point2d(4,3); // Point associated to vertex 3.
+ points(4) = point2d(4,4); // Point associated to vertex 4.
// Edges.
- util::graph<point2d> g;
+ util::graph g;
// Populate the graph with vertices.
for (unsigned i = 0; i < points.size(); ++i)
- g.add_vertex (points[i]);
+ g.add_vertex();
// Populate the graph with edges.
g.add_edge(0, 1);
g.add_edge(1, 2);
@@ -89,37 +127,31 @@ int main()
| Graph image support. |
`----------------------*/
- p_graph<point2d> pg(g);
-
- // Check adjacencies of vertex 1.
- mln_assertion( pg.adjacent(1, 0));
- mln_assertion(!pg.adjacent(1, 1));
- mln_assertion( pg.adjacent(1, 2));
- mln_assertion( pg.adjacent(1, 3));
- mln_assertion(!pg.adjacent(1, 4));
+ typedef p_vertices<util::graph, fpoint_t> S;
+ S pv(g, points);
/*-------------.
| Graph image. |
`-------------*/
- // Values ("empty" vector).
- std::vector<int> values(5);
- // Graph image.
- typedef graph_image<point2d, int> ima_t;
- ima_t ima(pg, values);
- // Initialize values.
- debug::iota(ima);
- // Compute the bounding box of IMA.
- /* FIXME: mln::graph_image should automatically feature a bbox when
- its parameter P is akin to a point. */
- accu::bbox<point2d> a;
- for (std::vector<point2d>::const_iterator i = points.begin();
- i != points.end(); ++i)
- a.take(*i);
- box2d bbox = a.to_result();
+ // Graph values.
+ viota_t<S> iota(5);
+
+ // Create graph image.
+ mln_const_VAR(ima, (iota | pv));
+
+ {
+ // Compute the bounding box of 'ima'.
+ accu::bbox<point2d> a;
+ mln_piter_(ima_t) p(ima.domain());
+ for_all(p)
+ a.take(p);
+ box2d bbox = a.to_result();
+ mln_assertion(bbox == make::box2d(5, 5));
+
// Print the image.
/* FIXME: Unfortunately, displaying graph images is not easy right
- now (2008-02-05). We could use
+ now (2008-02-05). We could use
debug::println(ima);
@@ -128,40 +160,84 @@ int main()
interface of graph_image to work with points (not psites).
Moreover, this implementation only shows *values*, not the graph
itslef.
-
- An alternative is to use draw::graph (which, again, is misnamed),
+
+ An alternative is to use debug::graph,
but it doesn't show the values, only the vertices and edges of the
graph.
- The current solution is a mix between draw::graph and hand-made
+ The current solution is a mix between debug::graph and hand-made
iterations. */
- image2d<int> ima_rep(bbox);
- // We use the value 9 in draw::graph instead of the default (which is
- // 1) to represent edges to distinguish it from vertices holding a
- // value of 1.
- draw::graph (ima_rep, ima, 9);
- debug::println (ima_rep);
+ image2d<int> ima_rep(bbox);
+ // We use the value 9 in debug::graph to represent edges to distinguish it
+ // from vertices holding a value of 1.
+ debug::graph(ima_rep, pv, 1, 9);
+ debug::println(ima_rep);
+ }
/*------------.
| Iterators. |
`------------*/
- // Manual iteration over the domain of IMA.
+ // iteration over the domain of IMA.
mln_piter_(ima_t) p(ima.domain());
for_all (p)
std::cout << "ima (" << p << ") = " <<
ima(p) << std::endl;
- // Manual iterations over the neighborhoods of each point site of IMA.
- typedef graph_elt_window<point2d> win_t;
- win_t win;
- mln_qiter_(win_t) q(win, p);
- for_all (p)
{
- std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
- << "including the site itself:" << std::endl;
- for_all (q)
- std::cout << " " << q << " (level = "
<< ima(q) << ")" << std::endl;
+ // Window - Forward iteration
+ typedef graph_elt_window<util::graph, fpoint_t> win_t;
+ win_t win;
+ mln_qiter_(win_t) q(win, p);
+ for_all (p)
+ {
+ std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
+ << "including the site itself:" << std::endl;
+ for_all (q)
+ std::cout << " " << q << " (level = " <<
ima(q) << ")" << std::endl;
+ }
+ }
+
+ {
+ // Window - Backward iteration
+ typedef graph_elt_window<util::graph, fpoint_t> win_t;
+ 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;
+ for_all (q)
+ std::cout << " " << q << " (level = " <<
ima(q) << ")" << std::endl;
+ }
+ }
+
+ {
+ // Neighborhood - Forward iteration
+ typedef graph_elt_neighborhood<util::graph, fpoint_t> neigh_t;
+ neigh_t neigh;
+ mln_niter_(neigh_t) n(neigh, p);
+ for_all (p)
+ {
+ std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
+ << "including the site itself:" << std::endl;
+ for_all (n)
+ std::cout << " " << n << " (level = " <<
ima(n) << ")" << std::endl;
+ }
+ }
+
+ {
+ // Neighborhood - Backward iteration
+ typedef graph_elt_neighborhood<util::graph, fpoint_t> neigh_t;
+ neigh_t neigh;
+ mln_bkd_niter_(neigh_t) n(neigh, p);
+ for_all (p)
+ {
+ std::cout << "neighbors of " << p << " ("
<< ima(p) << "), "
+ << "including the site itself:" << std::endl;
+ for_all (n)
+ std::cout << " " << n << " (level = " <<
ima(n) << ")" << std::endl;
+ }
}
std::cout << std::endl;
}
--
1.5.6.5