
* mln/core/image/line_graph_image.hh: (mln::line_graph_image<P, V>): Fix access to members. (mln::line_graph_image<P, V>::super_): Remove typedef. * mln/core/site_set/p_line_graph.hh: Update documentation. (mln::p_line_graph<P>::gr() const) (mln::p_line_graph<P>::gr()): New accessors. (mln::p_line_graph<P>::bbox): Remove method. (mln::p_line_graph<P>::bb_): Remove attributes. (mln::p_line_graph<P>::p_line_graph<P>): Ajust ctor. (mln::p_line_graph<P>::has): Ensure the site set is valid. (mln::p_line_graph<P>::memory_size): Temporarily prevent the method from being executed. * mln/core/image/line_graph_psite.hh: Aesthetic changes. (mln::line_graph_psite<P>::super_): Remove typedef. (mln::line_graph_psite<P>::line_graph_psite): Invalidate the psite in the default ctor. (mln::line_graph_psite<P>::site_set): Use target_() instead of manipulating plg_ directly. * mln/core/site_set/p_line_graph_piter.hh: Update documentation. (p_line_graph_fwd_piter_<P>::p_line_graph_fwd_piter_) (p_line_graph_bkd_piter_<P>::p_line_graph_bkd_piter_): Add postconditions. --- milena/ChangeLog | 28 ++++++++ milena/mln/core/image/line_graph_image.hh | 20 +++--- milena/mln/core/image/line_graph_psite.hh | 80 +++++++++++------------ milena/mln/core/site_set/p_line_graph.hh | 84 ++++++++++++++---------- milena/mln/core/site_set/p_line_graph_piter.hh | 15 +++- 5 files changed, 136 insertions(+), 91 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 4fffc21..1636331 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,31 @@ +2008-09-22 Roland Levillain <roland@lrde.epita.fr> + + Complete the overhaul of line graph images. + + * mln/core/image/line_graph_image.hh: + (mln::line_graph_image<P, V>): Fix access to members. + (mln::line_graph_image<P, V>::super_): Remove typedef. + * mln/core/site_set/p_line_graph.hh: Update documentation. + (mln::p_line_graph<P>::gr() const) + (mln::p_line_graph<P>::gr()): + New accessors. + (mln::p_line_graph<P>::bbox): Remove method. + (mln::p_line_graph<P>::bb_): Remove attributes. + (mln::p_line_graph<P>::p_line_graph<P>): Ajust ctor. + (mln::p_line_graph<P>::has): Ensure the site set is valid. + (mln::p_line_graph<P>::memory_size): Temporarily prevent the + method from being executed. + * mln/core/image/line_graph_psite.hh: Aesthetic changes. + (mln::line_graph_psite<P>::super_): Remove typedef. + (mln::line_graph_psite<P>::line_graph_psite): Invalidate the psite + in the default ctor. + (mln::line_graph_psite<P>::site_set): Use target_() instead of + manipulating plg_ directly. + * mln/core/site_set/p_line_graph_piter.hh: Update documentation. + (p_line_graph_fwd_piter_<P>::p_line_graph_fwd_piter_) + (p_line_graph_bkd_piter_<P>::p_line_graph_bkd_piter_): + Add postconditions. + 2008-09-22 Nicolas Ballas <ballas@lrde.epita.fr> Update median"". diff --git a/milena/mln/core/image/line_graph_image.hh b/milena/mln/core/image/line_graph_image.hh index b06b6c9..6b9b7ba 100644 --- a/milena/mln/core/image/line_graph_image.hh +++ b/milena/mln/core/image/line_graph_image.hh @@ -31,6 +31,8 @@ /// \file mln/core/image/line_graph_image.hh /// \brief Definition of a line graph-based image. +# include <vector> + # include <mln/trait/images.hh> # include <mln/core/internal/image_primary.hh> @@ -38,7 +40,6 @@ # include <mln/core/site_set/p_line_graph.hh> # include <mln/core/image/line_graph_psite.hh> # include <mln/value/set.hh> -# include <vector> /* FIXME: This class shares a lot with graph_image. Factor as much as possible. */ @@ -57,7 +58,7 @@ namespace mln { - // Fwd decl. + // Forward declaration. template <typename P, typename V> struct line_graph_image; namespace internal @@ -104,11 +105,9 @@ namespace mln // FIXME: Likewise. typedef typename trait::image::space_from_point<P>::ret dimension; - // extended domain + // Extended domain typedef trait::image::ext_domain::none ext_domain; - // FIXME: Is that right? typedef trait::image::ext_value::irrelevant ext_value; - // FIXME: Is that right? typedef trait::image::ext_io::irrelevant ext_io; }; @@ -119,13 +118,11 @@ namespace mln /// /// Values are stored on the edges of the graph. template <typename P, typename V> - struct line_graph_image : - public internal::image_primary<V, p_line_graph<P>, line_graph_image<P, V> > + class line_graph_image + : public internal::image_primary< V, p_line_graph<P>, + line_graph_image<P, V> > { - /// Super type. - typedef mln::internal::image_base< V, p_line_graph<P>, - line_graph_image<P, V> > super_; - + public: /// Value associated type. typedef V value; @@ -143,6 +140,7 @@ namespace mln /// Skeleton. typedef line_graph_image< tag::psite_<P>, tag::value_<V> > skeleton; + public: /// Constructors. /// \{ line_graph_image(); diff --git a/milena/mln/core/image/line_graph_psite.hh b/milena/mln/core/image/line_graph_psite.hh index 6e66436..869a5cf 100644 --- a/milena/mln/core/image/line_graph_psite.hh +++ b/milena/mln/core/image/line_graph_psite.hh @@ -39,6 +39,9 @@ /* FIXME: This class shares a lot with graph_psite. Factor as much as possible. */ +// FIXME: Rename line_graph_psite as p_line_graph_psite, and move this +// to core/site_set. + namespace mln { @@ -47,8 +50,6 @@ namespace mln 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::line_graph_image. /// /// \arg \p P The type of the site. @@ -58,7 +59,6 @@ namespace mln line_graph_psite<P> > { typedef line_graph_psite<P> self_; - typedef internal::pseudo_site_base_< P, self_ > super_; public: // This associated type is important to know that this particular @@ -191,12 +191,14 @@ namespace mln line_graph_psite<P>::line_graph_psite() : plg_(0) { + invalidate(); } template <typename P> inline line_graph_psite<P>::line_graph_psite(const p_line_graph<P>& plg, util::edge_id id) + // FIXME: Use change_target instead. : plg_(&plg), id_(id) { @@ -205,11 +207,33 @@ namespace mln template <typename P> inline + bool + line_graph_psite<P>::is_valid() const + { + /* 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 + void + line_graph_psite<P>::invalidate() + { + /* 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 const p_line_graph<P>& line_graph_psite<P>::site_set() const { - mln_precondition(plg_); - return *plg_; + mln_precondition(target_()); + return *target_(); } template <typename P> @@ -225,45 +249,19 @@ namespace mln void line_graph_psite<P>::change_target(const p_line_graph<P>& new_target) { - plg_ = & new_target; + plg_ = &new_target; invalidate(); } + // FIXME: Write or extend a test to exercise this method. template <typename P> inline const site_pair<P>& line_graph_psite<P>::subj_() { - // FIXME: p_ is not properly updated yet; we shouldn't call this - // method yet. - abort(); return p_; } - - template <typename P> - inline - bool - line_graph_psite<P>::is_valid() const - { - /* 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 - void - line_graph_psite<P>::invalidate() - { - /* 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 util::edge_id @@ -307,7 +305,7 @@ namespace mln P line_graph_psite<P>::first() const { - mln_assertion(is_valid()); + mln_precondition(is_valid()); // FIXME: Too low-level. return plg_->gr_->vertex_data(first_id()); } @@ -317,7 +315,7 @@ namespace mln P line_graph_psite<P>::second() const { - mln_assertion(is_valid()); + mln_precondition(is_valid()); // FIXME: Too low-level. return plg_->gr_->vertex_data(second_id()); } @@ -327,7 +325,7 @@ namespace mln util::vertex_id line_graph_psite<P>::first_id() const { - mln_assertion(is_valid()); + mln_precondition(is_valid()); // FIXME: Too low-level. return plg_->gr_->edge(id_).v1(); } @@ -337,7 +335,7 @@ namespace mln util::vertex_id line_graph_psite<P>::second_id() const { - mln_assertion(is_valid()); + mln_precondition(is_valid()); // FIXME: Too low-level. return plg_->gr_->edge(id_).v2(); } @@ -348,7 +346,7 @@ namespace mln void line_graph_psite<P>::update_() { - mln_assertion(is_valid()); + mln_precondition(is_valid()); p_.pair_.change_both(first(), second()); } @@ -361,7 +359,7 @@ namespace mln bool operator==(const line_graph_psite<P>& lhs, const line_graph_psite<P>& rhs) { - mln_assertion(lhs.target_() == rhs.target_()); + mln_precondition(lhs.target_() == rhs.target_()); return lhs.edge_id() == rhs.edge_id(); } @@ -369,7 +367,7 @@ namespace mln bool operator!=(const line_graph_psite<P>& lhs, const line_graph_psite<P>& rhs) { - mln_assertion(lhs.target_() == rhs.target_()); + mln_precondition(lhs.target_() == rhs.target_()); return lhs.edge_id() != rhs.edge_id(); } @@ -377,7 +375,7 @@ namespace mln bool operator< (const line_graph_psite<P>& lhs, const line_graph_psite<P>& rhs) { - mln_assertion(lhs.target_() == rhs.target_()); + mln_precondition(lhs.target_() == rhs.target_()); return lhs.edge_id() < rhs.edge_id(); } diff --git a/milena/mln/core/site_set/p_line_graph.hh b/milena/mln/core/site_set/p_line_graph.hh index 548b9e2..96b2c93 100644 --- a/milena/mln/core/site_set/p_line_graph.hh +++ b/milena/mln/core/site_set/p_line_graph.hh @@ -28,24 +28,23 @@ #ifndef MLN_CORE_SITE_SET_P_LINE_GRAPH_HH # define MLN_CORE_SITE_SET_P_LINE_GRAPH_HH -# include <mln/util/site_pair.hh> +/// \file mln/core/site_set/p_line_graph.hh +/// \brief Definition of a point set based on line graph. # include <mln/core/concept/point_site.hh> # include <mln/core/internal/site_set_base.hh> -# include <mln/accu/bbox.hh> # include <mln/util/graph.hh> # include <mln/util/tracked_ptr.hh> +# include <mln/util/site_pair.hh> # include <mln/core/image/line_graph_psite.hh> # include <mln/core/site_set/p_line_graph_piter.hh> /* FIXME: This class shares a lot with p_graph. Factor as much as possible. */ -// FIXME: We should move the `adjacent_or_equal method' from -// iterators into this class. +/* FIXME: We should move the `adjacent_or_equal method' from iterators + into this class. */ -/// \file mln/core/site_set/p_line_graph.hh -/// \brief Definition of a point set based on line graph. namespace mln { @@ -53,6 +52,7 @@ namespace mln // Forward declaration. template<typename P> struct p_line_graph; + namespace trait { template <typename P> @@ -66,9 +66,6 @@ namespace mln }; } // end of namespace mln::trait - /* FIXME: Contray to, e.g., p_array, the sole parameter P of - p_line_graph is expected to be a point, not a psite!! We should - have a uniform scheme for point site sets. */ template<typename P> struct p_line_graph @@ -101,15 +98,16 @@ namespace mln /// Backward Site_Iterator associated type. typedef p_line_graph_bkd_piter_<P> bkd_piter; - /// Forward Site_Iterator associated type. + /// Site_Iterator associated type. typedef fwd_piter piter; /// \} - /// \brief Return The number of points (sites) of the set, i.e., - /// the number of \em edges, since this is a point set based on a - /// line graph. + /// \brief Return The number of sites of the set, i.e., the number + /// of \em edges. /// - /// Required by the mln::Point_Set concept. + /// (Required by the mln::Site_Set concept, since the property + /// trait::site_set::nsites::known of this site set is set to + /// `known'.) /* FIXME: Return type should be std::size_t (see mln/core/concept/site_set.hh). */ unsigned nsites() const; @@ -119,9 +117,6 @@ namespace mln /// Return The number of edges in the graph. std::size_t nedges() const; - /// Give the exact bounding box. - const box<P>& bbox() const; - /// Is this site set valid? bool is_valid() const; @@ -131,6 +126,19 @@ namespace mln // FIXME: Dummy. std::size_t memory_size() const; + /// Accessors. + /// \{ + /// Return the graph associated to the p_graph domain (const + /// version) + const graph& gr() const; + /// Return the graph associated to the p_graph domain (mutable + /// version). + graph& gr(); + /// \} + + // FIXME: These would probably be no longer needed as soon as + // iterators on graphs are available. + /// Adjacency tests. /// \{ /// Return true if the psites \a lhs and \a rhs are adjacent. @@ -148,12 +156,8 @@ namespace mln /// \} // FIXME: Should be private. + /// The graph on which the pset is built. util::tracked_ptr<graph> gr_; - // FIXME: (Roland) Is it really useful/needed? - /* 2007-12-19: It seems so, since graph_image must implement a - method named bbox(). Now the question is: should each image - type have a bounding box? */ - box<P> bb_; }; @@ -182,6 +186,7 @@ namespace mln operator<=(const p_line_graph<P>& lhs, const p_line_graph<P>& rhs); + # ifndef MLN_INCLUDE_ONLY template <typename P> @@ -190,10 +195,6 @@ namespace mln // Create a deep, managed copy of GR. : gr_ (new util::graph<P>(gr)) { - accu::bbox<P> a; - for (unsigned i = 0; i < nvertices(); ++i) - a.take(gr_->vertex_data(i)); - bb_ = a.to_result(); } template <typename P> @@ -222,14 +223,6 @@ namespace mln template <typename P> inline - const box<P>& - p_line_graph<P>::bbox() const - { - return bb_; - } - - template <typename P> - inline bool p_line_graph<P>::is_valid() const { @@ -242,6 +235,7 @@ namespace mln bool p_line_graph<P>::has(const psite& p) const { + mln_precondition(is_valid()); return // Check whether P is compatible with this psite set. (p.target_() == this) && @@ -254,10 +248,26 @@ namespace mln std::size_t p_line_graph<P>::memory_size() const { - // FIXME: Dummy + // FIXME: Dummy; implement (see other site sets). + abort(); return 0; } + template <typename P> + const util::graph<P>& + p_graph<P>::gr() const + { + mln_precondition(is_valid()); + return *gr_.ptr_; + } + + template <typename P> + util::graph<P>& + p_graph<P>::gr() + { + mln_precondition(is_valid()); + return *gr_.ptr_; + } template <typename P> inline @@ -322,6 +332,10 @@ namespace mln } + /*--------------. + | Comparisons. | + `--------------*/ + template <typename P> bool operator==(const p_line_graph<P>& lhs, const p_line_graph<P>& rhs) diff --git a/milena/mln/core/site_set/p_line_graph_piter.hh b/milena/mln/core/site_set/p_line_graph_piter.hh index 4971075..90b8e3c 100644 --- a/milena/mln/core/site_set/p_line_graph_piter.hh +++ b/milena/mln/core/site_set/p_line_graph_piter.hh @@ -28,16 +28,18 @@ #ifndef MLN_CORE_SITE_SET_P_LINE_GRAPH_PITER_HH # define MLN_CORE_SITE_SET_P_LINE_GRAPH_PITER_HH +/// \file mln/core/site_set/p_line_graph_piter.hh +/// \brief Definition of point iterators on line graph-based site set. + # include <mln/core/internal/site_iterator_base.hh> # include <mln/core/site_set/p_line_graph.hh> # include <mln/core/image/line_graph_psite.hh> -/// \file mln/core/site_set/p_line_graph_piter.hh -/// \brief Definition of point iterator on line graph-based point set. namespace mln { - // Fwd decls. + + // Forward declarations. template <typename P> class p_line_graph; template <typename P> class line_graph_psite; @@ -121,11 +123,12 @@ namespace mln /// \} protected: + /// The psite corresponding to this iterator. using super_::p_; }; - /// Print a mln::p_line_graph_bkd_piter_<P>. + /// Print an mln::p_line_graph_bkd_piter_<P>. template <typename P> inline std::ostream& @@ -142,6 +145,7 @@ namespace mln inline p_line_graph_fwd_piter_<P>::p_line_graph_fwd_piter_() { + mln_postcondition(!is_valid()); } template <typename P> @@ -149,6 +153,7 @@ namespace mln p_line_graph_fwd_piter_<P>::p_line_graph_fwd_piter_(const p_line_graph<P>& plg) { this->change_target(plg); + mln_postcondition(!is_valid()); } template <typename P> @@ -201,6 +206,7 @@ namespace mln inline p_line_graph_bkd_piter_<P>::p_line_graph_bkd_piter_() { + mln_postcondition(!is_valid()); } template <typename P> @@ -208,6 +214,7 @@ namespace mln p_line_graph_bkd_piter_<P>::p_line_graph_bkd_piter_(const p_line_graph<P>& plg) { this->change_target(plg); + mln_postcondition(!is_valid()); } template <typename P> -- 1.6.0.1