https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Factor implementation of piters on line graph neighborhoods.
* mln/core/line_graph_elt_neighborhood.hh
(mln::graph_elt_neighborhood<P, N>::neighbors_t): Rename as...
(mln::graph_elt_neighborhood<P, N>::sites_t): ...this.
(mln::graph_elt_neighborhood<P, N>::compute_neighbors_): Rename as...
(mln::graph_elt_neighborhood<P, N>::compute_sites_): ...this.
* mln/core/line_graph_neighborhood_piter.hh:
(mln::line_graph_neighborhood_fwd_piter<P, W>)
(mln::line_graph_neighborhood_bkd_piter<P, N>):
Inherit from mln::internal::line_graph_vicinity_piter_.
(mln::line_graph_neighborhood_fwd_piter<P, N>::start)
(mln::line_graph_neighborhood_bkd_piter<P, N>::start):
Adjust w.r.t. the changes in graph_elt_neighborhood.
(mln::line_graph_neighborhood_fwd_piter<P, N>::super_)
(mln::line_graph_neighborhood_bkd_piter<P, N>::super_):
Adjust typedef.
(mln::line_graph_neighborhood_fwd_piter<P, N>::i_)
(mln::line_graph_neighborhood_bkd_piter<P, N>::i_):
Adjust.
(line_graph_neighborhood_fwd_piter<P, W>)
(line_graph_neighborhood_bkd_piter<P, N>):
Adjust ctors.
(mln::line_graph_neighborhood_fwd_piter<P, N>::psite)
(mln::line_graph_neighborhood_fwd_piter<P, N>::point)
(mln::line_graph_neighborhood_fwd_piter<P, N>::coord)
(mln::line_graph_neighborhood_fwd_piter<P, N>::dpoint)
(mln::line_graph_neighborhood_fwd_piter<P, N>::mesh)
(mln::line_graph_neighborhood_fwd_piter<P, N>::sites_t)
(mln::line_graph_neighborhood_bkd_piter<P, N>::psite)
(mln::line_graph_neighborhood_bkd_piter<P, N>::point)
(mln::line_graph_neighborhood_bkd_piter<P, N>::coord)
(mln::line_graph_neighborhood_bkd_piter<P, N>::dpoint)
(mln::line_graph_neighborhood_bkd_piter<P, N>::mesh)
(mln::line_graph_neighborhood_bkd_piter<P, N>::sites_t):
Remove (now useless) typedefs.
(mln::line_graph_neighborhood_fwd_piter<P, N>::to_point)
(mln::line_graph_neighborhood_fwd_piter<P, N>::to_psite)
(mln::line_graph_neighborhood_fwd_piter<P, N>::operator psite)
(mln::line_graph_neighborhood_fwd_piter<P, N>::p_ref)
(mln::line_graph_neighborhood_fwd_piter<P, N>::plg)
(mln::line_graph_neighborhood_fwd_piter<P, N>::sites)
(mln::line_graph_neighborhood_fwd_piter<P, N>::operator[])
(mln::line_graph_neighborhood_bkd_piter<P, N>::to_point)
(mln::line_graph_neighborhood_bkd_piter<P, N>::to_psite)
(mln::line_graph_neighborhood_bkd_piter<P, N>::operator psite)
(mln::line_graph_neighborhood_bkd_piter<P, N>::p_ref)
(mln::line_graph_neighborhood_bkd_piter<P, N>::plg)
(mln::line_graph_neighborhood_bkd_piter<P, N>::sites)
(mln::line_graph_neighborhood_bkd_piter<P, N>::operator[]):
Remove methods.
(mln::line_graph_neighborhood_fwd_piter<P, N>::p_ref_)
(mln::line_graph_neighborhood_fwd_piter<P, N>::saved_p_ref_)
(mln::line_graph_neighborhood_fwd_piter<P, N>::sites_)
(mln::line_graph_neighborhood_fwd_piter<P, N>::psite_)
(mln::line_graph_neighborhood_fwd_piter<P, N>::point_)
(mln::line_graph_neighborhood_bkd_piter<P, N>::p_ref_)
(mln::line_graph_neighborhood_bkd_piter<P, N>::saved_p_ref_)
(mln::line_graph_neighborhood_bkd_piter<P, N>::sites_)
(mln::line_graph_neighborhood_bkd_piter<P, N>::psite_)
(mln::line_graph_neighborhood_bkd_piter<P, N>::point_):
Remove attributes.
(operator<<(ostream&, const line_graph_neighborhood_fwd_piter<P,
N>&))
(operator<<(ostream&, const line_graph_neighborhood_bkd_piter<P,
N>&)):
Remove.
* mln/core/internal/line_graph_vicinity_piter.hh: Add missing
inclusion of standard header `set'.
internal/line_graph_vicinity_piter.hh | 2
line_graph_elt_neighborhood.hh | 16 -
line_graph_neighborhood_piter.hh | 337 +++-------------------------------
3 files changed, 43 insertions(+), 312 deletions(-)
Index: mln/core/line_graph_elt_neighborhood.hh
--- mln/core/line_graph_elt_neighborhood.hh (revision 1902)
+++ mln/core/line_graph_elt_neighborhood.hh (working copy)
@@ -74,7 +74,7 @@
typedef line_graph_psite<P> psite;
// The type of the set of neighbors (edge ids adjacent to the
// reference psite).
- typedef std::set<util::edge_id> neighbors_t;
+ typedef std::set<util::edge_id> sites_t;
// FIXME: This is a dummy value.
typedef void dpoint;
@@ -94,7 +94,7 @@
/// Services for iterators.
/// \{
template <typename Piter>
- void compute_neighbors_(Point_Iterator<Piter>& piter) const;
+ void compute_sites_(Point_Iterator<Piter>& piter) const;
/// \}
};
@@ -106,12 +106,12 @@
template <typename Piter>
inline
void
-
line_graph_elt_neighborhood<P>::compute_neighbors_(Point_Iterator<Piter>&
piter_) const
+ line_graph_elt_neighborhood<P>::compute_sites_(Point_Iterator<Piter>&
piter_) const
{
Piter& piter = exact(piter_);
util::edge_id ref_edge_id = piter.p_ref().id();
- neighbors_t& neighbors = piter.neighbors();
- neighbors.clear();
+ sites_t& sites = piter.sites();
+ sites.clear();
/* 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. */
@@ -122,9 +122,9 @@
for (std::vector<util::edge_id>::const_iterator e =
node1.edges.begin(); e != node1.edges.end(); ++e)
/* We explicitely enforce that the reference piter edge id is
- not inserted into NEIGHBORS. */
+ not inserted into SITES. */
if (*e != ref_edge_id)
- neighbors.insert(*e);
+ sites.insert(*e);
// Ajacent edges connected through node 2.
// FIXME: Likewise.
util::node_id id2 = piter.p_ref().second_id();
@@ -133,7 +133,7 @@
node2.edges.begin(); e != node2.edges.end(); ++e)
// Same remark as above.
if (*e != ref_edge_id)
- neighbors.insert(*e);
+ sites.insert(*e);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/line_graph_neighborhood_piter.hh
--- mln/core/line_graph_neighborhood_piter.hh (revision 1902)
+++ mln/core/line_graph_neighborhood_piter.hh (working copy)
@@ -31,22 +31,7 @@
/// \file mln/core/line_graph_neighborhood_piter.hh
/// \brief Definition of a point iterator on a line graph neighborhood.
-/* FIXME: Factor those classes:
-
- - mln::graph_window_fwd_piter
- - mln::graph_neighborhood_fwd_piter
- - mln::line_graph_window_fwd_piter
- - mln::line_graph_neighborhood_fwd_piter.
- - mln::graph_window_bkd_piter
- - mln::graph_neighborhood_bkd_piter
- - mln::line_graph_window_bkd_piter
- - mln::line_graph_neighborhood_bkd_piter. */
-
-# include <set>
-
-# include <mln/core/concept/point_iterator.hh>
-# include <mln/core/p_line_graph.hh>
-# include <mln/core/line_graph_psite.hh>
+# include <mln/core/internal/line_graph_vicinity_piter.hh>
/* FIXME: Due to the poor interface of mln::p_line_graph and
mln::util::graph, we show to much implementation details here.
@@ -54,10 +39,6 @@
namespace mln
{
- // Fwd decls.
- template <typename P> class p_line_graph;
- template <typename P> class line_graph_psite;
-
/*------------------------------------------.
| line_graph_neighborhood_fwd_piter<P, N>. |
@@ -66,24 +47,10 @@
/// \brief Forward iterator on line graph neighborhood.
template <typename P, typename N>
class line_graph_neighborhood_fwd_piter :
- public Point_Iterator< line_graph_neighborhood_fwd_piter<P, N> >
+ public internal::line_graph_vicinity_piter_< P,
line_graph_neighborhood_fwd_piter<P, N> >
{
typedef line_graph_neighborhood_fwd_piter<P, N> self_;
- typedef Point_Iterator< self_ > super_;
-
- public:
- enum { dim = P::dim };
-
- typedef line_graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(point) coord;
- // FIXME: Dummy typedef.
- typedef void dpoint;
- // FIXME: Dummy typedef.
- typedef void mesh;
-
- // The type of the set of neighbors (adjacent edge ids).
- typedef std::set<util::edge_id> neighbors_t;
+ typedef internal::line_graph_vicinity_piter_<P, self_> super_;
public:
/// Construction.
@@ -108,58 +75,14 @@
void update_();
/// \}
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding point.
- const point& to_point() const;
- /// Reference to the corresponding point site.
- const psite& to_psite() const;
- /// Convert the iterator into a line graph psite.
- operator psite() const;
-
- /// Return the reference psite.
- const psite& p_ref() const;
- /// Return the mln::p_line_graph corresponding to this piter.
- const p_line_graph<P>& plg() const;
- /// Return the set of neighbors (adjacent edge ids).
- neighbors_t& neighbors();
-
- /// Read-only access to the \a i-th coordinate.
- // FIXME: Dummy.
- coord operator[](unsigned i) const;
- /// \}
-
private:
/// The neighborhood.
const N& nbh_;
- /// The ``central'' psite of the neighborhood.
- const psite& p_ref_;
- /// The last reference psite whose ajacent psites have been computed.
- psite saved_p_ref_;
- /// The set of edge ids adjacent to the reference psite.
- neighbors_t neighbors_;
/// An iterator on the set of adjacent edges.
- neighbors_t::const_iterator i_;
-
- /// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- /* FIXME: Dummy value. To be removed as soon as the conversion
- from psite to point is no longer mandatory. */
- point p_;
+ typename super_::sites_t::const_iterator i_;
};
- /* FIXME: This hand-made delegation is painful. We should rely on
- the general mechanism provided by Point_Site. But then again, we
- need to refine/adjust the interface of Point_Site w.r.t. the
- mandatory conversions to points. */
- template <typename P, typename N>
- inline
- std::ostream&
- operator<<(std::ostream& ostr,
- const line_graph_neighborhood_fwd_piter<P, N>& p);
-
/*------------------------------------------.
| line_graph_neighborhood_bkd_piter<P, N>. |
@@ -168,24 +91,10 @@
/// \brief Backward iterator on line graph neighborhood.
template <typename P, typename N>
class line_graph_neighborhood_bkd_piter :
- public Point_Iterator< line_graph_neighborhood_bkd_piter<P, N> >
+ public internal::line_graph_vicinity_piter_< P,
line_graph_neighborhood_bkd_piter<P, N> >
{
typedef line_graph_neighborhood_bkd_piter<P, N> self_;
- typedef Point_Iterator< self_ > super_;
-
- public:
- enum { dim = P::dim };
-
- typedef line_graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(point) coord;
- // FIXME: Dummy typedef.
- typedef void dpoint;
- // FIXME: Dummy typedef.
- typedef void mesh;
-
- // The type of the set of neighbors (adjacent edge ids).
- typedef std::set<util::edge_id> neighbors_t;
+ typedef internal::line_graph_vicinity_piter_<P, self_> super_;
public:
/// Construction.
@@ -210,58 +119,14 @@
void update_();
/// \}
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding point.
- const point& to_point() const;
- /// Reference to the corresponding point site.
- const psite& to_psite() const;
- /// Convert the iterator into a line graph psite.
- operator psite() const;
-
- /// Return the reference psite.
- const psite& p_ref() const;
- /// Return the mln::p_line_graph corresponding to this piter.
- const p_line_graph<P>& plg() const;
- /// Return the set of neighbors (adjacent edge ids).
- neighbors_t& neighbors();
-
- /// Read-only access to the \a i-th coordinate.
- // FIXME: Dummy.
- coord operator[](unsigned i) const;
- /// \}
-
private:
/// The neighborhood.
const N& nbh_;
- /// The ``central'' psite of the neighborhood.
- const psite& p_ref_;
- /// The last reference psite whose ajacent psites have been computed.
- psite saved_p_ref_;
- /// The set of edge ids adjacent to the reference psite.
- neighbors_t neighbors_;
/// An iterator on the set of adjacent edges.
- neighbors_t::const_reverse_iterator i_;
-
- /// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- /* FIXME: Dummy value. To be removed as soon as the conversion
- from psite to point is no longer mandatory. */
- point p_;
+ typename super_::sites_t::const_reverse_iterator i_;
};
- /* FIXME: This hand-made delegation is painful. We should rely on
- the general mechanism provided by Point_Site. But then again, we
- need to refine/adjust the interface of Point_Site w.r.t. the
- mandatory conversions to points. */
- template <typename P, typename N>
- inline
- std::ostream&
- operator<<(std::ostream& ostr,
- const line_graph_neighborhood_bkd_piter<P, N>& p);
-
# ifndef MLN_INCLUDE_ONLY
@@ -275,10 +140,8 @@
inline
line_graph_neighborhood_fwd_piter<P, N>::line_graph_neighborhood_fwd_piter(const
Neighborhood<N>& nbh,
const Point_Site<Pref>& p_ref)
- : nbh_(exact(nbh)),
- p_ref_(exact(p_ref).to_psite()),
- // Initialize psite_ to a dummy value.
- psite_()
+ : super_(p_ref),
+ nbh_(exact(nbh))
{
// Invalidate i_.
invalidate();
@@ -291,12 +154,12 @@
{
return
// The reference point must be valid...
- p_ref_.is_valid()
+ this->p_ref_.is_valid()
// ...and must not have changed since the neighborhood has been
// computed...
- && p_ref_ == saved_p_ref_
+ && this->p_ref_ == this->saved_p_ref_
// ...and the iterator i_ must point a valid value.
- && i_ != neighbors_.end();
+ && i_ != this->sites_.end();
}
template <typename P, typename N>
@@ -304,7 +167,7 @@
void
line_graph_neighborhood_fwd_piter<P, N>::invalidate()
{
- i_ = neighbors_.end();
+ i_ = this->sites_.end();
}
template <typename P, typename N>
@@ -312,14 +175,14 @@
void
line_graph_neighborhood_fwd_piter<P, N>::start()
{
- mln_precondition(p_ref_.is_valid());
+ mln_precondition(this->p_ref_.is_valid());
// Update the neighbors, if needed.
- if (!saved_p_ref_.is_valid() || p_ref_ != saved_p_ref_)
+ if (!this->saved_p_ref_.is_valid() || this->p_ref_ != this->saved_p_ref_)
{
- saved_p_ref_ = p_ref_;
- nbh_.compute_neighbors_(*this);
+ this->saved_p_ref_ = this->p_ref_;
+ nbh_.compute_sites_(*this);
}
- i_ = neighbors_.begin();
+ i_ = this->sites_.begin();
// FIXME: We might move the is_valid condition within update_.
if (is_valid())
update_();
@@ -331,7 +194,7 @@
line_graph_neighborhood_fwd_piter<P, N>::next_()
{
// Ensure the p_ref_ has not changed.
- mln_precondition(p_ref_ == saved_p_ref_);
+ mln_precondition(this->p_ref_ == this->saved_p_ref_);
++i_;
// FIXME: We might move the is_valid condition within update_.
if (is_valid())
@@ -344,73 +207,7 @@
line_graph_neighborhood_fwd_piter<P, N>::update_()
{
// Update psite_.
- psite_ = line_graph_psite<P>(plg(), *i_);
- }
-
- template <typename P, typename N>
- inline
- const P&
- line_graph_neighborhood_fwd_piter<P, N>::to_point() const
- {
- return p_;
- }
-
- template <typename P, typename N>
- inline
- const line_graph_psite<P>&
- line_graph_neighborhood_fwd_piter<P, N>::to_psite() const
- {
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- line_graph_neighborhood_fwd_piter<P, N>::operator line_graph_psite<P> ()
const
- {
- mln_precondition(is_valid());
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- const line_graph_psite<P>&
- line_graph_neighborhood_fwd_piter<P, N>::p_ref() const
- {
- return p_ref_;
- }
-
- template <typename P, typename N>
- inline
- const p_line_graph<P>&
- line_graph_neighborhood_fwd_piter<P, N>::plg() const
- {
- return p_ref_.plg();
- }
-
- template <typename P, typename N>
- inline
- std::set<util::edge_id>&
- line_graph_neighborhood_fwd_piter<P, N>::neighbors()
- {
- return neighbors_;
- }
-
- template <typename P, typename N>
- inline
- mln_coord(P)
- line_graph_neighborhood_fwd_piter<P, N>::operator[](unsigned i) const
- {
- assert(i < dim);
- return p_[i];
- }
-
- template <typename P, typename N>
- inline
- std::ostream&
- operator<<(std::ostream& ostr,
- const line_graph_neighborhood_fwd_piter<P, N>& p)
- {
- return ostr << p.to_psite();
+ this->psite_ = line_graph_psite<P>(this->plg(), *i_);
}
@@ -423,10 +220,8 @@
inline
line_graph_neighborhood_bkd_piter<P, N>::line_graph_neighborhood_bkd_piter(const
Neighborhood<N>& nbh,
const Point_Site<Pref>& p_ref)
- : nbh_(exact(nbh)),
- p_ref_(exact(p_ref).to_psite()),
- // Initialize psite_ to a dummy value.
- psite_()
+ : super_(p_ref),
+ nbh_(exact(nbh))
{
// Invalidate i_.
invalidate();
@@ -439,12 +234,12 @@
{
return
// The reference point must be valid...
- p_ref_.is_valid()
+ this->p_ref_.is_valid()
// ...and must not have changed since the neighborhood has been
// computed...
- && p_ref_ == saved_p_ref_
+ && this->p_ref_ == this->saved_p_ref_
// ...and the iterator i_ must point a valid value.
- && i_ != neighbors_.rend();
+ && i_ != this->sites_.rend();
}
template <typename P, typename N>
@@ -452,7 +247,7 @@
void
line_graph_neighborhood_bkd_piter<P, N>::invalidate()
{
- i_ = neighbors_.rend();
+ i_ = this->sites_.rend();
}
template <typename P, typename N>
@@ -460,14 +255,14 @@
void
line_graph_neighborhood_bkd_piter<P, N>::start()
{
- mln_precondition(p_ref_.is_valid());
+ mln_precondition(this->p_ref_.is_valid());
// Update the neighbors, if needed.
- if (!saved_p_ref_.is_valid() || p_ref_ != saved_p_ref_)
+ if (!this->saved_p_ref_.is_valid() || this->p_ref_ != this->saved_p_ref_)
{
- saved_p_ref_ = p_ref_;
- nbh_.compute_neighbors_(*this);
+ this->saved_p_ref_ = this->p_ref_;
+ nbh_.compute_sites_(*this);
}
- i_ = neighbors_.rbegin();
+ i_ = this->sites_.rbegin();
// FIXME: We might move the is_valid condition within update_.
if (is_valid())
update_();
@@ -479,7 +274,7 @@
line_graph_neighborhood_bkd_piter<P, N>::next_()
{
// Ensure the p_ref_ has not changed.
- mln_precondition(p_ref_ == saved_p_ref_);
+ mln_precondition(this->p_ref_ == this->saved_p_ref_);
++i_;
// FIXME: We might move the is_valid condition within update_.
if (is_valid())
@@ -492,73 +287,7 @@
line_graph_neighborhood_bkd_piter<P, N>::update_()
{
// Update psite_.
- psite_ = line_graph_psite<P>(plg(), *i_);
- }
-
- template <typename P, typename N>
- inline
- const P&
- line_graph_neighborhood_bkd_piter<P, N>::to_point() const
- {
- return p_;
- }
-
- template <typename P, typename N>
- inline
- const line_graph_psite<P>&
- line_graph_neighborhood_bkd_piter<P, N>::to_psite() const
- {
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- line_graph_neighborhood_bkd_piter<P, N>::operator line_graph_psite<P> ()
const
- {
- mln_precondition(is_valid());
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- const line_graph_psite<P>&
- line_graph_neighborhood_bkd_piter<P, N>::p_ref() const
- {
- return p_ref_;
- }
-
- template <typename P, typename N>
- inline
- const p_line_graph<P>&
- line_graph_neighborhood_bkd_piter<P, N>::plg() const
- {
- return p_ref_.plg();
- }
-
- template <typename P, typename N>
- inline
- std::set<util::edge_id>&
- line_graph_neighborhood_bkd_piter<P, N>::neighbors()
- {
- return neighbors_;
- }
-
- template <typename P, typename N>
- inline
- mln_coord(P)
- line_graph_neighborhood_bkd_piter<P, N>::operator[](unsigned i) const
- {
- assert(i < dim);
- return p_[i];
- }
-
- template <typename P, typename N>
- inline
- std::ostream&
- operator<<(std::ostream& ostr,
- const line_graph_neighborhood_bkd_piter<P, N>& p)
- {
- return ostr << p.to_psite();
+ this->psite_ = line_graph_psite<P>(this->plg(), *i_);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/internal/line_graph_vicinity_piter.hh
--- mln/core/internal/line_graph_vicinity_piter.hh (revision 1902)
+++ mln/core/internal/line_graph_vicinity_piter.hh (working copy)
@@ -37,6 +37,8 @@
- mln::internal::graph_vicinity_piter.hh
- mln::internal::line_graph_vicinity_piter.hh */
+# include <set>
+
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/p_line_graph.hh>
# include <mln/core/line_graph_psite.hh>