
* mln/core/image/line_graph_psite.hh (mln::line_graph_psite<P>): Inherit from mln::internal::pseudo_site_base_. (mln::line_graph_psite<P>::line_graph_psite): Adjust ctors. (mln::line_graph_psite<P>::first) (mln::line_graph_psite<P>::second) (mln::line_graph_psite<P>::first_id) (mln::line_graph_psite<P>::second_id): Adjust methods. (operator==(const line_graph_psite<P>&, const line_graph_psite<P>&)) (operator< (const line_graph_psite<P>&, const line_graph_psite<P>&)): Adjust operators. (mln::line_graph_psite<P>::super_): Adjust. (mln::line_graph_psite<P>::target): New typedef. (mln::line_graph_psite<P>::dim) (mln::line_graph_psite<P>::coord) (mln::line_graph_psite<P>::point) (mln::line_graph_psite<P>::dpoint) (mln::line_graph_psite<P>::mesh): Remove typedefs. (mln::line_graph_psite<P>::line_graph_psite(const self_&)) (mln::line_graph_psite<P>::self_& operator=) (mln::line_graph_psite<P>::to_psite) (mln::line_graph_psite<P>::to_point) (mln::line_graph_psite<P>::operator point) (mln::line_graph_psite<P>::operator[]) (mln::line_graph_psite<P>::plg): Remove methods. (mln::line_graph_psite<P>::invalidate) (mln::line_graph_psite<P>::site_set) (mln::line_graph_psite<P>::target_) (mln::line_graph_psite<P>::change_target) (mln::line_graph_psite<P>::subj_) (mln::line_graph_psite<P>::update_) (mln::line_graph_psite<P>::change_edge_id) (mln::line_graph_psite<P>::inc_edge_id) (mln::line_graph_psite<P>::dec_edge_id): New methods. (mln::line_graph_psite<P>::id): Rename as... (mln::line_graph_psite<P>::edge_id): ...this. (mln::line_graph_psite<P>::plg_): Change type to `const target*'. (mln::line_graph_psite<P>::p_): Change type to site_pair<P>. (operator!=(const line_graph_psite<P>&, const line_graph_psite<P>&)): New operator. --- milena/ChangeLog | 50 ++++++ milena/mln/core/image/line_graph_psite.hh | 263 ++++++++++++++++++----------- 2 files changed, 212 insertions(+), 101 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 7d3f79a..ae13b3c 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,55 @@ 2008-09-17 Roland Levillain <roland@lrde.epita.fr> + Update line graph psite. + + * mln/core/image/line_graph_psite.hh + (mln::line_graph_psite<P>): Inherit from + mln::internal::pseudo_site_base_. + (mln::line_graph_psite<P>::line_graph_psite): + Adjust ctors. + (mln::line_graph_psite<P>::first) + (mln::line_graph_psite<P>::second) + (mln::line_graph_psite<P>::first_id) + (mln::line_graph_psite<P>::second_id): + Adjust methods. + (operator==(const line_graph_psite<P>&, const line_graph_psite<P>&)) + (operator< (const line_graph_psite<P>&, const line_graph_psite<P>&)): + Adjust operators. + (mln::line_graph_psite<P>::super_): Adjust. + (mln::line_graph_psite<P>::target): New typedef. + (mln::line_graph_psite<P>::dim) + (mln::line_graph_psite<P>::coord) + (mln::line_graph_psite<P>::point) + (mln::line_graph_psite<P>::dpoint) + (mln::line_graph_psite<P>::mesh): + Remove typedefs. + (mln::line_graph_psite<P>::line_graph_psite(const self_&)) + (mln::line_graph_psite<P>::self_& operator=) + (mln::line_graph_psite<P>::to_psite) + (mln::line_graph_psite<P>::to_point) + (mln::line_graph_psite<P>::operator point) + (mln::line_graph_psite<P>::operator[]) + (mln::line_graph_psite<P>::plg): + Remove methods. + (mln::line_graph_psite<P>::invalidate) + (mln::line_graph_psite<P>::site_set) + (mln::line_graph_psite<P>::target_) + (mln::line_graph_psite<P>::change_target) + (mln::line_graph_psite<P>::subj_) + (mln::line_graph_psite<P>::update_) + (mln::line_graph_psite<P>::change_edge_id) + (mln::line_graph_psite<P>::inc_edge_id) + (mln::line_graph_psite<P>::dec_edge_id): + New methods. + (mln::line_graph_psite<P>::id): Rename as... + (mln::line_graph_psite<P>::edge_id): ...this. + (mln::line_graph_psite<P>::plg_): Change type to `const target*'. + (mln::line_graph_psite<P>::p_): Change type to site_pair<P>. + (operator!=(const line_graph_psite<P>&, const line_graph_psite<P>&)): + New operator. + +2008-09-17 Roland Levillain <roland@lrde.epita.fr> + Create an util::ordpair_-based container usable as a site. * mln/util/site_pair.hh: New. diff --git a/milena/mln/core/image/line_graph_psite.hh b/milena/mln/core/image/line_graph_psite.hh index 8d65963..c3f51af 100644 --- a/milena/mln/core/image/line_graph_psite.hh +++ b/milena/mln/core/image/line_graph_psite.hh @@ -31,6 +31,9 @@ /// \file mln/core/image/line_graph_psite.hh /// \brief Definition of a line graph-based point site. +# include <mln/core/internal/pseudo_site_base.hh> + +# include <mln/util/site_pair.hh> # include <mln/core/site_set/p_line_graph.hh> /* FIXME: This class shares a lot with graph_psite. Factor as much as @@ -42,76 +45,102 @@ namespace mln // Fwd decl. template <typename P> class p_line_graph; + template <typename P> class line_graph_psite; + // FIXME: Rename as line_graph_psite as p_line_graph_psite. - /// \brief Point site associated to a mln::graph_image. + /// \brief Point site associated to a mln::line_graph_image. + /// + /// \arg \p P The type of the site. template <typename P> - class line_graph_psite : public Point_Site< line_graph_psite<P> > + class line_graph_psite + : public internal::pseudo_site_base_< const site_pair<P>&, + line_graph_psite<P> > { typedef line_graph_psite<P> self_; - typedef Point_Site<self_> super_; + typedef internal::pseudo_site_base_< P, self_ > super_; public: - typedef P point; - // FIXME: Dummy. - typedef void mesh; - enum { dim = point::dim }; - // FIXME: Dummy. - typedef void dpoint; - typedef mln_coord(point) coord; + // This associated type is important to know that this particular + // pseudo site knows the site set it refers to. + typedef p_line_graph<P> target; /// Construction and assignment. /// \{ line_graph_psite(); line_graph_psite(const p_line_graph<P>& plg, util::edge_id id); - line_graph_psite(const self_& rhs); - self_& operator= (const self_& rhs); /// \} - /// Access to psite. - const self_& to_psite() const; + /// 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); + /// \} - /// Access to point. + /// Proxy manipulators. /// \{ - const point& to_point() const; - operator point() const; - coord operator[](unsigned id) const; + /// Return the site corresponding to this psite. + const site_pair<P>& subj_(); /// \} - /// Return the mln::p_line_graph this point site belongs to. - const p_line_graph<P>& plg() const; + /// Edge id manipulators. + //// \{ /// Return the edge id of this point site. - util::edge_id id() const; + util::edge_id edge_id() const; + /// Set the edge id of this point site. + void change_edge_id(const util::edge_id& id); + /// Increment the edge id of this point site. + void inc_edge_id(); + /// Increment the edge id of this point site. + void dec_edge_id(); + /// \} + /// Accessors. + /// \{ /// Return the first associated vertex. P first() const; /// Return the second associated vertex. P second() const; /// Return the id of the first associated vertex. + // FIXME: Rename as first_vertex_id. util::vertex_id first_id() const; /// Return the id of the second associated vertex. + // FIXME: Rename as second_vertex_id. util::vertex_id second_id() const; + /// \} - /// Is this psite valid? - bool is_valid() const; + private: + /// Site-related members. + /// \{ + /// Update the site corresponding to this psite. + void update_(); + // The site corresponding to this psite. + site_pair<P> p_; + /// \} private: + /// Graph-related members. + /// \{ /// The p_line_graph this point site belongs to. - const p_line_graph<P>* plg_; + const target* plg_; /// The id of the edge this psite is pointing towards. util::edge_id id_; - /** \brief The point associated to this psite. - - Contrary to mln::graph_psite, this information is actually - stored in the mln::line_graph_psite. In mln::graph_psite, the - point is retrieved from the data associated with the - corresponding vertex in the graph. We cannot do this here, - since points associated to edges are computed on the fly - (storing them in the graph could be possible, but too costly - in space). */ - // FIXME: Actually, this is a dummy value! - point p_; + /// \} }; @@ -128,6 +157,14 @@ namespace mln bool operator==(const line_graph_psite<P>& lhs, const line_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_line_graph. + template <typename P> + bool + operator!=(const line_graph_psite<P>& lhs, const line_graph_psite<P>& rhs); + /// \brief Is \a lhs ``less'' than \a rhs? /// /// This comparison is required by algorithms sorting psites. @@ -140,31 +177,19 @@ namespace mln /// \} - /* 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> inline std::ostream& operator<<(std::ostream& ostr, const line_graph_psite<P>& p); -# ifndef MLN_INCLUDE_ONLY - /* Careful, the current interface of line_graph_psite allows the - construction of ill-formed psites (i.e., whose edge is is beyond - bounds). Actually, p_line_graph_piters *do* create ill-formed - psites at their initialization. */ +# ifndef MLN_INCLUDE_ONLY template <typename P> inline line_graph_psite<P>::line_graph_psite() - // Dummy initializations. - : super_(), - plg_(0), - id_(-1), - p_() + : plg_(0) { } @@ -172,94 +197,109 @@ namespace mln inline line_graph_psite<P>::line_graph_psite(const p_line_graph<P>& plg, util::edge_id id) - : super_(), - plg_(&plg), - id_(id), - p_() + : plg_(&plg), + id_(id) { + update_(); } template <typename P> inline - line_graph_psite<P>::line_graph_psite(const line_graph_psite<P>& rhs) - : super_(rhs), - plg_(rhs.plg_), - id_(rhs.id_), - p_() + const p_line_graph<P>& + line_graph_psite<P>::site_set() const { + mln_precondition(plg_); + return *plg_; } template <typename P> inline - line_graph_psite<P>& - line_graph_psite<P>::operator=(const line_graph_psite<P>& rhs) + const p_line_graph<P>* + line_graph_psite<P>::target_() const { - if (&rhs == this) - return *this; - plg_ = rhs.plg_; - id_ = rhs.id_; - return *this; + return plg_; } template <typename P> inline - bool - line_graph_psite<P>::is_valid() const + void + line_graph_psite<P>::change_target(const p_line_graph<P>& new_target) { - return plg_ && id_ < plg_->gr_->nedges(); + plg_ = & new_target; + invalidate(); } template <typename P> inline - const line_graph_psite<P>& - line_graph_psite<P>::to_psite() const + const site_pair<P>& + line_graph_psite<P>::subj_() { - return *this; + // FIXME: p_ is not properly updated yet; we shouldn't call this + // method yet. + abort(); + return p_; } + template <typename P> inline - const P& - line_graph_psite<P>::to_point() const + bool + line_graph_psite<P>::is_valid() const { - // Dummy value. - abort(); - return p_; + /* FIXME: Instead of `plg_->gr_->nedges()', we should have + something like `run_->has_edge_id(id_)' (see the implementation of + p_run_psite. */ + return plg_ && id_ < plg_->gr_->nedges(); } template <typename P> inline - line_graph_psite<P>::operator P() const + void + line_graph_psite<P>::invalidate() { - // Dummy value. - abort(); - return p_; + /* FIXME: Instead of `plg_->gr_->nedges()', we should have + something like `run_->has_edge_id(id_)' (see the implementation of + p_run_psite. */ + id_ = plg_->gr_->nedges(); } + template <typename P> inline - mln_coord(P) - line_graph_psite<P>::operator[](unsigned i) const + util::edge_id + line_graph_psite<P>::edge_id() const { - mln_assertion(is_valid()); - return to_point()[i]; + return id_; } template <typename P> inline - const p_line_graph<P>& - line_graph_psite<P>::plg() const + void + line_graph_psite<P>::change_edge_id(const util::edge_id& id) { - mln_assertion(plg_); - return *plg_; + id_ = id; + if (is_valid()) + update_(); } template <typename P> inline - util::edge_id - line_graph_psite<P>::id() const + void + line_graph_psite<P>::inc_edge_id() { - return id_; + ++id_.to_equiv(); + if (is_valid()) + update_(); + } + + template <typename P> + inline + void + line_graph_psite<P>::dec_edge_id() + { + --id_.to_equiv(); + if (is_valid()) + update_(); } template <typename P> @@ -268,7 +308,8 @@ namespace mln line_graph_psite<P>::first() const { mln_assertion(is_valid()); - return plg().gr_->vertex_data(first_id()); + // FIXME: Too low-level. + return plg_->gr_->vertex_data(first_id()); } template <typename P> @@ -277,17 +318,18 @@ namespace mln line_graph_psite<P>::second() const { mln_assertion(is_valid()); - return plg().gr_->vertex_data(second_id()); + // FIXME: Too low-level. + return plg_->gr_->vertex_data(second_id()); } - template <typename P> inline util::vertex_id line_graph_psite<P>::first_id() const { mln_assertion(is_valid()); - return plg().gr_->edge(id_).v1(); + // FIXME: Too low-level. + return plg_->gr_->edge(id_).v1(); } template <typename P> @@ -296,7 +338,19 @@ namespace mln line_graph_psite<P>::second_id() const { mln_assertion(is_valid()); - return plg().gr_->edge(id_).v2(); + // FIXME: Too low-level. + return plg_->gr_->edge(id_).v2(); + } + + + template <typename P> + inline + void + line_graph_psite<P>::update_() + { + mln_assertion(is_valid()); + p_.pair_.first = first(); + p_.pair_.second = second(); } @@ -308,16 +362,24 @@ namespace mln bool operator==(const line_graph_psite<P>& lhs, const line_graph_psite<P>& rhs) { - mln_assertion(&lhs.plg() == &rhs.plg()); - return lhs.id() == rhs.id(); + mln_assertion(lhs.target_() == rhs.target_()); + return lhs.edge_id() == rhs.edge_id(); + } + + template <typename P> + bool + operator!=(const line_graph_psite<P>& lhs, const line_graph_psite<P>& rhs) + { + mln_assertion(lhs.target_() == rhs.target_()); + return lhs.edge_id() != rhs.edge_id(); } template <typename P> bool operator< (const line_graph_psite<P>& lhs, const line_graph_psite<P>& rhs) { - mln_assertion(&lhs.plg() == &rhs.plg()); - return lhs.id() < rhs.id(); + mln_assertion(lhs.target_() == rhs.target_()); + return lhs.edge_id() < rhs.edge_id(); } @@ -335,7 +397,6 @@ namespace mln # endif // ! MLN_INCLUDE_ONLY - } // end of mln #endif // MLN_CORE_IMAGE_LINE_GRAPH_PSITE_HH -- 1.6.0.1