cleanup-2008 2159: Move new site sets in proper place, cleanup, and bug fix.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Move new site sets in proper place, cleanup, and bug fix. Move site set files that only belong to that branch to a dedicated new directory. * mln/core/site_set: New directory. * mln/core/p_double.hh, * mln/core/p_key.hh, * mln/core/p_mutable_array_of.hh, * mln/core/p_set_of.hh, * mln/core/p_vaccess.hh: Move to... * mln/core/site_set/p_double.hh, * mln/core/site_set/p_key.hh, * mln/core/site_set/p_mutable_array_of.hh, * mln/core/site_set/p_set_of.hh, * mln/core/site_set/p_vaccess.hh: ...here. (file, guards): Update. * mln/core/p_queue_fast.hh, * mln/core/alias/p_runs2d.hh, * mln/core/p_queue.hh, * mln/core/p_priority_queue.hh, * mln/core/p_set.hh, * mln/core/safe.hh, * mln/core/p_runs.hh: Update. * doc/tutorial/examples/image_if.cc, * doc/tutorial/examples/p_queue.cc, * doc/tutorial/examples/p_vaccess.cc, * doc/tutorial/examples/p_key.cc, * doc/tutorial/examples/p_key.2.cc, * doc/tutorial/examples/p_run.cc, * doc/tutorial/examples/p_mutable_array_of.cc: Update and augment. * mln/core/site_set/all.hh: New. * mln/trait/site_set/status.txt: Move to... * mln/core/site_set/status.txt: ...here and update. Bug fix. * mln/core/p_queue_fast.hh: Fix doc. * mln/core/site_set/p_double.hh (todo): Remove; obsolete. (todo): New. * mln/core/site_set/p_mutable_array_of.hh, * mln/core/site_set/p_set_of.hh (site_set_base_): Fix the 1st param. This base class expects a type to deduce the site type and, in compound site sets, such type cannot be an element (a compound). (doc): Fix. (has): Implement so remove FIXME. (insert): Add missing precondition. * mln/core/site_set/p_mutable_array_of.hh (reserve): New. * mln/core/safe.hh (speed): Fix. A couple of site set cleanup. * mln/core/p_queue.hh: Revamp. (todo): New. * mln/core/p_image2d.hh: Copy to... * mln/core/site_set/p_image.hh: ...this new file. Revamp to make it generic. * doc/tutorial/examples/p_image.cc: New. Also move the image status file. * mln/trait/image/status.txt: Move to... * mln/core/image/status.txt: ...here. doc/tutorial/examples/image_if.cc | 1 doc/tutorial/examples/p_image.cc | 52 ++++ doc/tutorial/examples/p_key.2.cc | 2 doc/tutorial/examples/p_key.cc | 2 doc/tutorial/examples/p_mutable_array_of.cc | 13 - doc/tutorial/examples/p_queue.cc | 37 ++ doc/tutorial/examples/p_run.cc | 2 doc/tutorial/examples/p_vaccess.cc | 2 mln/core/alias/p_runs2d.hh | 2 mln/core/p_priority_queue.hh | 2 mln/core/p_queue.hh | 242 +++++++++--------- mln/core/p_queue_fast.hh | 38 +- mln/core/p_runs.hh | 2 mln/core/p_set.hh | 5 mln/core/safe.hh | 3 mln/core/site_set/all.hh | 48 +++ mln/core/site_set/p_double.hh | 13 - mln/core/site_set/p_image.hh | 362 ++++++++++++++-------------- mln/core/site_set/p_key.hh | 10 mln/core/site_set/p_mutable_array_of.hh | 37 ++ mln/core/site_set/p_set_of.hh | 22 - mln/core/site_set/p_vaccess.hh | 10 mln/core/site_set/status.txt | 20 - 23 files changed, 544 insertions(+), 383 deletions(-) Index: doc/tutorial/examples/image_if.cc --- doc/tutorial/examples/image_if.cc (revision 2158) +++ doc/tutorial/examples/image_if.cc (working copy) @@ -1,6 +1,5 @@ # include <mln/core/image2d.hh> # include <mln/core/image_if.hh> -# include <mln/core/alias.hh> # include <mln/debug/iota.hh> # include <mln/debug/println.hh> Index: doc/tutorial/examples/p_image.cc --- doc/tutorial/examples/p_image.cc (revision 0) +++ doc/tutorial/examples/p_image.cc (revision 0) @@ -0,0 +1,52 @@ +# include <mln/core/image2d.hh> +# include <mln/core/p_array.hh> +# include <mln/core/site_set/p_image.hh> +# include <mln/debug/println.hh> +# include <mln/level/fill.hh> + + +template <typename A> +void picture(const A& arr) +{ + using namespace mln; + + image2d<char> ima(5, 5); + level::fill(ima, '-'); + + unsigned i = 0; + mln_piter(A) p(arr); + for_all(p) + ima(p) = '0' + i++; + + debug::println(ima); +} + + + +int main() +{ + using namespace mln; + + typedef p_array<point2d> Arr; + Arr arr; + + { + point2d p(1,1); + arr.append(p); + dpoint2d dp[] = { right, right, down, down, left, left, up }; + for (unsigned i = 0; i < 7; ++i) + p += dp[i], arr.append(p); + + std::cout << "arr = " << arr << std::endl; + picture(arr); + } + + typedef image2d<bool> I; + I ima(5, 5); + p_image<I> s(ima); + s += arr; + std::cout << "ima = " << s << std::endl; + picture(s); + + debug::println(s.image_hook_()); +} Index: doc/tutorial/examples/p_queue.cc --- doc/tutorial/examples/p_queue.cc (revision 2158) +++ doc/tutorial/examples/p_queue.cc (working copy) @@ -1,4 +1,5 @@ # include <mln/core/image2d.hh> +# include <mln/core/p_queue.hh> # include <mln/core/p_queue_fast.hh> # include <mln/debug/println.hh> # include <mln/level/fill.hh> @@ -25,11 +26,26 @@ -int main() +template <typename P> +void try_purge(mln::p_queue<P>&) +{ + // No-op. +} + +template <typename P> +void try_purge(mln::p_queue_fast<P>& q) +{ + std::cout << "purge!" << std::endl; + q.purge(); + picture(q); +} + + +template <typename Q> +void run() { using namespace mln; - typedef p_queue_fast<point2d> Q; Q q; { @@ -45,7 +61,7 @@ picture(q); { - Q::psite p(q, 0); + mln_psite(Q) p(q, 0); mln_assertion(q.has(p)); p.change_index(6); mln_assertion(q.has(p)); @@ -54,17 +70,24 @@ mln_assertion(! q.has(p)); } - std::cout << "purge!" << std::endl; - q.purge(); - picture(q); + try_purge(q); { typedef p_priority<unsigned, Q> PQ; PQ pq; - Q::piter p(q); + mln_piter(Q) p(q); for_all(p) pq.push(p.row() + p.col(), p); std::cout << pq << std::endl; } } + + +int main() +{ + using namespace mln; + // typedef p_queue<point2d> Q; + typedef p_queue_fast<point2d> Q; + run<Q>(); +} Index: doc/tutorial/examples/p_vaccess.cc --- doc/tutorial/examples/p_vaccess.cc (revision 2158) +++ doc/tutorial/examples/p_vaccess.cc (working copy) @@ -9,7 +9,7 @@ # include <mln/labeling/blobs.hh> # include <mln/core/alias/p_runs2d.hh> -# include <mln/core/p_vaccess.hh> +# include <mln/core/site_set/p_vaccess.hh> # include <mln/core/image_if.hh> # include <mln/pw/all.hh> # include <mln/convert/from_to.hh> Index: doc/tutorial/examples/p_key.cc --- doc/tutorial/examples/p_key.cc (revision 2158) +++ doc/tutorial/examples/p_key.cc (working copy) @@ -1,5 +1,5 @@ # include <mln/core/image2d.hh> -# include <mln/core/p_key.hh> +# include <mln/core/site_set/p_key.hh> # include <mln/debug/println.hh> # include <mln/level/fill.hh> Index: doc/tutorial/examples/p_key.2.cc --- doc/tutorial/examples/p_key.2.cc (revision 2158) +++ doc/tutorial/examples/p_key.2.cc (working copy) @@ -1,5 +1,5 @@ # include <mln/core/image2d.hh> -# include <mln/core/p_key.hh> +# include <mln/core/site_set/p_key.hh> # include <mln/value/int_u8.hh> # include <mln/io/pgm/load.hh> # include <mln/io/pgm/save.hh> Index: doc/tutorial/examples/p_run.cc --- doc/tutorial/examples/p_run.cc (revision 2158) +++ doc/tutorial/examples/p_run.cc (working copy) @@ -1,6 +1,6 @@ # include <mln/core/image2d.hh> # include <mln/core/alias/p_run2d.hh> -# include <mln/core/p_set_of.hh> +# include <mln/core/site_set/p_set_of.hh> # include <mln/convert/from_to.hh> # include <mln/debug/println.hh> Index: doc/tutorial/examples/p_mutable_array_of.cc --- doc/tutorial/examples/p_mutable_array_of.cc (revision 2158) +++ doc/tutorial/examples/p_mutable_array_of.cc (working copy) @@ -1,5 +1,5 @@ # include <mln/core/image2d.hh> -# include <mln/core/p_mutable_array_of.hh> +# include <mln/core/site_set/p_mutable_array_of.hh> # include <mln/core/p_run.hh> # include <mln/convert/from_to.hh> @@ -46,4 +46,15 @@ display(rs); // FIXME: Use the "mutable" feature of rs... + + + { + typedef p_mutable_array_of<Runs> Arr; // Array of arrays of runs. + Arr arr; + arr.insert(rs); + arr.insert(rs); + std::cout << arr << std::endl; + display(arr); + } + } Index: mln/core/p_queue_fast.hh --- mln/core/p_queue_fast.hh (revision 2158) +++ mln/core/p_queue_fast.hh (working copy) @@ -63,7 +63,11 @@ - /*! \brief Point queue class (based on p_array<P>). + /*! \brief Queue of sites class (based on p_array<P>). + * + * This container is efficient; FIXME: explain... + * + * The parameter \c P shall be a site or pseudo-site type. */ template <typename P> class p_queue_fast : public internal::site_set_base_< P, p_queue_fast<P> > @@ -87,49 +91,49 @@ typedef fwd_piter piter; - /// Constructor. + /// Constructor without argument. p_queue_fast(); /// Reserve \p n cells. void reserve(std::size_t n); - /// Test if \p p belongs to this point set. + /// Test if \p p belongs to this site set. bool has(const psite& p) const; - /// Test if index \p i belongs to this point set. + /// Test if index \p i belongs to this site set. bool has(const util::index& i) const; /// This set is always valid so it returns true. bool is_valid() const; - /// Test if \p p belongs to this point set. + /// Test if \p p belongs to this site set. bool compute_has(const P& p) const; - /// Give the number of points. + /// Give the number of sites. unsigned nsites() const; - /// Push a point \p p in the queue. + /// Push a site \p p in the queue. void push(const P& p); /// Insertion element associated type. typedef P i_element; - /// Insert a point \p p (equivalent as 'push'). + /// Insert a site \p p (equivalent as 'push'). void insert(const P& p); - /// Pop (remove) the front point \p p from the queue; \p p is the - /// least recently inserted point. + /// Pop (remove) the front site \p p from the queue; \p p is the + /// least recently inserted site. void pop(); - /// Give the front point \p p of the queue; \p p is the least - /// recently inserted point. + /// Give the front site \p p of the queue; \p p is the least + /// recently inserted site. const P& front() const; - /// Pop (remove) the front point \p p from the queue; \p p is the - /// least recently inserted point and give the front point \p p of - /// the queue; \p p is the least recently inserted point. + /// Pop (remove) the front site \p p from the queue; \p p is the + /// least recently inserted site and give the front site \p p of + /// the queue; \p p is the least recently inserted site. const P& pop_front(); @@ -140,10 +144,10 @@ void clear(); - /// Return the \p i-th point. + /// Return the \p i-th site. const P& operator[](unsigned i) const; - /// Return the corresponding std::vector of points. + /// Return the corresponding std::vector of sites. const std::vector<P>& std_vector() const; /// Return the size of this site set in memory. Index: mln/core/alias/p_runs2d.hh --- mln/core/alias/p_runs2d.hh (revision 2158) +++ mln/core/alias/p_runs2d.hh (working copy) @@ -34,7 +34,7 @@ */ # include <mln/core/alias/p_run2d.hh> -# include <mln/core/p_set_of.hh> +# include <mln/core/site_set/p_set_of.hh> namespace mln Index: mln/core/p_queue.hh --- mln/core/p_queue.hh (revision 2158) +++ mln/core/p_queue.hh (working copy) @@ -30,101 +30,128 @@ /*! \file mln/core/p_queue.hh * - * \brief Definition of a point set class based on std::deque. + * \brief Definition of a site set based on std::deque. + * + * \todo Rename 'front' because it is ambiguous for C++ users; we + * have: + * - 'p_queue::pop' means 'deque::pop_front' + * - 'p_queue::pop_front' means 'return deque::front and run + * deque::pop_front' */ -# include <vector> # include <deque> -# include <algorithm> -# include <iterator> - -# include <mln/core/internal/site_set_base.hh> -# include <mln/core/p_array_piter.hh> -# include <mln/accu/bbox.hh> +# include <mln/core/p_array.hh> namespace mln { - // Fwd decls. - template <typename P> struct p_array_fwd_piter_; - template <typename P> struct p_array_bkd_piter_; + // Forward declaration. + template <typename P> class p_queue; - /*! \brief Point queue class (based on std::deque). - * - * This is a mathematical set of points (unique insertion). - * - * \todo Make it work with P being a Point_Site. - * \todo Add a parameter flag to choose another policy for "push" - * (i.e., no-op if multiple or allow multiple insertions). + namespace trait + { + + template <typename P> + struct site_set_< p_queue<P> > + { + typedef trait::site_set::nsites::known nsites; + typedef trait::site_set::bbox::unknown bbox; + typedef trait::site_set::contents::growing contents; + typedef trait::site_set::arity::multiple arity; + }; + + } // end of namespace trait + + + + /*! \brief Queue of sites (based on std::deque). * - * \warning We have some troubles with point set comparison based on - * a call to nsites() when this container is multiple. + * The parameter \c P shall be a site or pseudo-site type. */ template <typename P> class p_queue : public internal::site_set_base_< P, p_queue<P> > { + typedef p_queue<P> self_; public: + /// Element associated type. + typedef P element; + + + /// Psite associated type. + typedef p_indexed_psite<self_> psite; + /// Forward Site_Iterator associated type. - typedef p_array_fwd_piter_<P> fwd_piter; + typedef p_indexed_fwd_piter<self_> fwd_piter; /// Backward Site_Iterator associated type. - typedef p_array_bkd_piter_<P> bkd_piter; + typedef p_indexed_bkd_piter<self_> bkd_piter; + + /// Site_Iterator associated type. + typedef fwd_piter piter; - /// Constructor. + + /// Constructor without argument. p_queue(); - /// Test is \p p belongs to this point set. - bool has(const P& p) const; - /// Give the number of points. + /// Test if \p p belongs to this site set. + bool has(const psite& p) const; + + /// Test if index \p i belongs to this site set. + bool has(const util::index& i) const; + + /// This set is always valid so it returns true. + bool is_valid() const; + + + /// Give the number of sites. unsigned nsites() const; - /// Give the exact bounding box. - const box_<P>& bbox() const; - /// Push force a point \p p in the queue. - p_queue<P>& push_force(const P& p); + /// Push a site \p p in the queue. + void push(const P& p); + + /// Insertion element associated type. + typedef P i_element; + + /// Insert a site \p p (equivalent as 'push'). + void insert(const P& p); - /// Push a point \p p in the queue. - p_queue<P>& push(const P& p); - /// Pop (remove) the front point \p p from the queue; \p p is the - /// least recently inserted point. + /// Pop (remove) the front site \p p from the queue; \p p is the + /// least recently inserted site. void pop(); - /// Give the front point \p p of the queue; \p p is the least - /// recently inserted point. + /// Give the front site \p p of the queue; \p p is the least + /// recently inserted site. const P& front() const; - /// Give the front point \p p of the queue; \p p is the least - /// recently inserted point and pop (remove) the front point \p p - /// from the queue; \p p is the least recently inserted point. - const P& pop_front(); + /// Pop (remove) the front site \p p from the queue; \p p is the + /// least recently inserted site and give the front site \p p of + /// the queue; \p p is the least recently inserted site. + P pop_front(); + /// Clear the queue. void clear(); - /// Return the corresponding std::vector of points. - const std::vector<P>& vect() const; - /// Return the \p i-th point. + /// Return the \p i-th site. const P& operator[](unsigned i) const; - protected: + /// Return the corresponding std::deque of sites. + const std::deque<P>& std_deque() const; - std::deque<P> q_; + /// Return the size of this site set in memory. + std::size_t memory_size() const; - mutable std::vector<P> vect_; - mutable bool vect_needs_update_; - void vect_update_() const; - - mutable accu::bbox<P> bb_; - mutable bool bb_needs_update_; - void bb_update_() const; + protected: + + std::deque<P> q_; }; @@ -135,42 +162,35 @@ inline p_queue<P>::p_queue() { - vect_needs_update_ = false; - bb_needs_update_ = false; } template <typename P> inline - void - p_queue<P>::vect_update_() const + bool + p_queue<P>::has(const psite& p) const { - vect_.clear(); - vect_.reserve(q_.size()); - std::copy(q_.begin(), q_.end(), - std::back_inserter(vect_)); - vect_needs_update_ = false; + mln_precondition(p.target_() == this); // FIXME: Refine. + if (p.index() < 0 || unsigned(p.index()) >= nsites()) + return false; + // The type of rhs below is mln_site(p_array<P>). + mln_invariant(p.to_site() == (*this)[p.index()]); + return true; } template <typename P> inline - void - p_queue<P>::bb_update_() const + bool + p_queue<P>::has(const util::index& i) const { - bb_.init(); - for (unsigned i = 0; i < q_.size(); ++i) - bb_.take(q_[i]); - bb_needs_update_ = false; + return i >= 0 && unsigned(i) < nsites(); } template <typename P> inline bool - p_queue<P>::has(const P& p) const + p_queue<P>::is_valid() const { - for (unsigned i = 0; i < q_.size(); ++i) - if (q_[i] == p) return true; - return false; } template <typename P> @@ -183,37 +203,10 @@ template <typename P> inline - const box_<P>& - p_queue<P>::bbox() const - { - mln_precondition(nsites() != 0); - if (bb_needs_update_) - bb_update_(); - return bb_.to_result(); - } - - template <typename P> - inline - p_queue<P>& - p_queue<P>::push_force(const P& p) - { - q_.push_back(p); - if (! vect_needs_update_) - { - vect_needs_update_ = true; - bb_needs_update_ = true; - } - return *this; - } - - template <typename P> - inline - p_queue<P>& + void p_queue<P>::push(const P& p) { - mln_precondition(! has(p)); - // FIXME: Our choice is "error if multiple insertions" - return this->push_force(p); + q_.push_back(p); } template <typename P> @@ -221,12 +214,8 @@ void p_queue<P>::pop() { + mln_precondition(! this->is_empty()); q_.pop_front(); - if (! vect_needs_update_) - { - vect_needs_update_ = true; - bb_needs_update_ = true; - } } template <typename P> @@ -234,17 +223,17 @@ const P& p_queue<P>::front() const { - mln_precondition(! q_.empty()); + mln_precondition(! this->is_empty()); return q_.front(); } template <typename P> inline - const P& + P p_queue<P>::pop_front() { - const P& res = this->front(); - + mln_precondition(! this->is_empty()); + P res = this->front(); this->pop(); return res; } @@ -255,28 +244,39 @@ p_queue<P>::clear() { q_.clear(); - vect_.clear(); - vect_needs_update_ = false; - bb_needs_update_ = false; } template <typename P> inline - const std::vector<P>& - p_queue<P>::vect() const + const P& + p_queue<P>::operator[](unsigned i) const { - if (vect_needs_update_) - vect_update_(); - return vect_; + mln_precondition(i < nsites()); + return q_[i]; } template <typename P> inline - const P& - p_queue<P>::operator[](unsigned i) const + void + p_queue<P>::insert(const P& p) { - mln_precondition(i < nsites()); - return q_[i]; + this->push(p); + } + + template <typename P> + inline + const std::deque<P>& + p_queue<P>::std_deque() const + { + return q_; + } + + template <typename P> + inline + std::size_t + p_queue<P>::memory_size() const + { + return sizeof(q_) + nsites() * sizeof(P); } # endif // ! MLN_INCLUDE_ONLY Index: mln/core/p_priority_queue.hh --- mln/core/p_priority_queue.hh (revision 2158) +++ mln/core/p_priority_queue.hh (working copy) @@ -36,7 +36,7 @@ */ # include <map> -# include <mln/core/p_double.hh> +# include <mln/core/site_set/p_double.hh> # include <mln/core/internal/site_set_base.hh> # include <mln/util/set.hh> Index: mln/core/p_set.hh --- mln/core/p_set.hh (revision 2158) +++ mln/core/p_set.hh (working copy) @@ -63,8 +63,9 @@ /*! \brief Point set class based on util::set. * - * This is a mathematical set of points (not a multi-set). The - * parameter \p P shall be a Point type. + * This is a mathematical set of sites (not a multi-set). + * + * The parameter \c P shall be a site or pseudo-site type. */ template <typename P> class p_set : public internal::site_set_base_< P, p_set<P> > Index: mln/core/site_set/p_image.hh --- mln/core/site_set/p_image.hh (revision 0) +++ mln/core/site_set/p_image.hh (working copy) @@ -25,252 +25,262 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_P_IMAGE2D_HH -# define MLN_CORE_P_IMAGE2D_HH +#ifndef MLN_CORE_SITE_SET_P_IMAGE_HH +# define MLN_CORE_SITE_SET_P_IMAGE_HH -/*! \file mln/core/p_image2d.hh +/*! \file mln/core/site_set/p_image.hh * - * \brief Definition of a point set class based on a image of booleans. + * \brief Definition of a site set class based on an image of + * Booleans. + * + * \todo Add an init method (deferred initialization). */ -# include <mln/core/internal/site_set_base.hh> -# include <mln/core/box2d.hh> -# include <mln/core/image2d.hh> -# include <mln/core/sub_image.hh> - -# include <mln/accu/bbox.hh> -# include <mln/geom/ncols.hh> -# include <mln/accu/bbox.hh> -# include <mln/level/fill.hh> +# include <mln/core/pset_if.hh> +# include <mln/fun/ops.hh> +# include <mln/pw/value.hh> +# include <mln/pw/cst.hh> +# include <mln/level/fill_with_value.hh> + -# include <mln/level/memset_.hh> namespace mln { + // Forward declaration. + template <typename I> class p_image; + - // Fwd decls. - template <typename P> struct p_image2d_fwd_piter_; - template <typename P> struct p_image2d_bkd_piter_; + namespace trait + { - template <typename P> - class p_image2d : public internal::site_set_base_<P, p_image2d<P> > + template <typename I> + struct site_set_< p_image<I> > { + typedef trait::site_set::nsites::known nsites; + typedef trait::site_set::bbox::unknown bbox; // FIXME + typedef trait::site_set::contents::free contents; + typedef trait::site_set::arity::unique arity; + }; + + } // end of namespace trait + + + + template <typename I> + class p_image : public internal::site_set_base_< mln_psite(I), p_image<I> > + { + typedef mln_pset(I) S_; + typedef fun::eq_p2b_expr_< pw::value_<I>, pw::cst_<bool> > F_; public: - typedef image2d<bool> image_type; + /// Equivalent site_set type. + typedef pset_if<S_, F_> S; + + /// Conversion towards the equivalent site set. + operator S() const; + + + /// Element associated type. + typedef mln_psite(I) element; + + + /// Psite associated type. + typedef mln_psite(I) psite; /// Forward Site_Iterator associated type. - typedef p_image2d_fwd_piter_<P> fwd_piter; + typedef mln_fwd_piter(S) fwd_piter; /// Backward Site_Iterator associated type. - typedef p_image2d_bkd_piter_<P> bkd_piter; + typedef mln_bkd_piter(S) bkd_piter; + + /// Site_Iterator associated type. + typedef mln_piter(S) piter; + + + /// Constructor without argument. + p_image(); /// Constructor. - p_image2d(int nrows, int ncols); - p_image2d(const box2d& b); + p_image(const I& ima); - /// Insert a point \p p. - p_image2d<P>& insert(const P p); - template <typename S> - p_image2d<P>& insert(const Site_Set<S>& set); - - /// Remove a point \p p. - p_image2d<P>& remove(const P p); - template <typename S> - p_image2d<P>& remove(const Site_Set<S>& set); - - /// Give the number of points. - unsigned npoints() const; - /// Test is \p p belongs to this point set. - bool has(const P& p) const; - /// Test if the set is empty. - bool is_empty() const; + /// Test is the psite \p p belongs to this site set. + bool has(const psite&) const; - /// Give the exact bounding box. - const box_<mln_point(P)>& bbox();; - /// Clear this set. - void clear(); + /// Test if this site set is valid, i.e., initialized. + bool is_valid() const; - /// Hook to the image2d - const image2d<bool>& image() const; - image2d<bool>& image_non_const(); - private: - image2d<bool> points_; - unsigned npoints_; - accu::bbox<P> bb_; - bool bb_need_update_; - }; + /// Give the number of sites. + unsigned nsites() const; -# ifndef MLN_INCLUDE_ONLY + /// Insertion element associated type. + typedef psite i_element; - template <typename P> - p_image2d<P>::p_image2d(int nrows, int ncols) - : points_(nrows, ncols, 0), - npoints_(0), - bb_need_update_(false) - { - level::fill(points_, false); - } + /// Insert a site \p p. + void insert(const psite& p); - template <typename P> - p_image2d<P>::p_image2d(const box2d& b) - : points_(b), - npoints_(0), - bb_need_update_(false) - { - level::fill(points_, false); - } + /// Removal element associated type. + typedef psite r_element; + /// Remove a site \p p. + void remove(const psite& p); - template <typename P> - p_image2d<P>& - p_image2d<P>::insert(const P p) - { - if (points_(p) == false) - { - bb_.take(p); - points_(p) = true; - npoints_++; - } - return *this; - } - template <typename P> - template <typename S> - p_image2d<P>& - p_image2d<P>::insert(const Site_Set<S>& set_) - { - const S& set = exact(set_); - mln_fwd_piter(S) p(set); - for_all(p) - if (this->points_.has(p)) - this->insert(p); - return *this; - } + /// Change the status in/out of a site \p p. + void toggle(const psite& p); - template <typename P> - p_image2d<P>& - p_image2d<P>::remove(const P p) - { - if (points_(p) == true) - { - points_(p) = false; - npoints_--; - if (npoints_ == 0) - { - bb_.init(); - bb_need_update_ = false; - } - else - bb_need_update_ = true; + /// Return the size of this site set in memory. + std::size_t memory_size() const; - } - return *this; - } - template <typename P> - template <typename S> - p_image2d<P>& - p_image2d<P>::remove(const Site_Set<S>& set_) + /// Clear this set. + void clear(); + + + /// Hook to the image + const I& image_hook_() const; + + private: + + I ima_; + unsigned nsites_; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + inline + p_image<I>::operator S() const { - const S& set = exact(set_); - if (this->is_empty()) - return *this; - mln_fwd_piter(S) p(set); - for_all(p) - if (this->points_.has(p)) - this->remove(p); + S tmp(ima_.domain(), pw::value(ima_) == pw::cst(true)); + return tmp; + } - return *this; + template <typename I> + inline + p_image<I>::p_image() + { + nsites_ = 0; } - template <typename P> - unsigned - p_image2d<P>::npoints() const + template <typename I> + inline + p_image<I>::p_image(const I& ima) { - return npoints_; + mln_precondition(ima.has_data()); + ima_ = ima; + clear(); } - template <typename P> + template <typename I> + inline bool - p_image2d<P>::has(const P& p) const + p_image<I>::has(const psite& p) const { - return points_(p); + mln_precondition(is_valid()); + return ima_.domain().has(p) && ima_(p) == true; } - template <typename P> + template <typename I> + inline bool - p_image2d<P>::is_empty() const + p_image<I>::is_valid() const { - return npoints_ == 0; + return ima_.has_data(); } - - template <typename P> + template <typename I> inline - const box_<mln_point(P)>& - p_image2d<P>::bbox() - { - mln_precondition(npoints() != 0); - if (bb_need_update_) + unsigned + p_image<I>::nsites() const { - bb_.init(); - mln_fwd_piter(p_image2d<P>) p(*this); - for_all(p) - bb_.take(p); - bb_need_update_ = false; + return nsites_; } - return bb_.to_result(); + template <typename I> + inline + void + p_image<I>::insert(const psite& p) + { + mln_precondition(is_valid()); + mln_precondition(ima_.domain().has(p)); + if (ima_(p) == true) + return; // No-op. + ima_(p) = true; + ++nsites_; } - - template <typename P> + template <typename I> + inline void - p_image2d<P>::clear() + p_image<I>::remove(const psite& p) { - if (npoints_ == 0) - return; - - unsigned bb_nrows = geom::nrows(bb_.to_result()); - unsigned ima_nrows = geom::nrows(points_); + mln_precondition(is_valid()); + mln_precondition(ima_.domain().has(p)); + if (ima_(p) == false) + return; // No-op. + ima_(p) = false; + mln_assertion(nsites_ > 0); + --nsites_; + } - if (bb_nrows * 3 < ima_nrows * 2) + template <typename I> + inline + void + p_image<I>::toggle(const psite& p) { - unsigned bb_ncols = geom::ncols(bb_.to_result()); - mln_line_piter_(image2d<bool>) p(bb_.to_result()); - for_all(p) + mln_precondition(is_valid()); + mln_precondition(ima_.domain().has(p)); + if (ima_(p) == true) + { + // Removal. + ima_(p) = false; + mln_assertion(nsites_ > 0); + --nsites_; + } + else { - level::memset_(points_, p, false, bb_ncols); + // Insertion. + ima_(p) = true; + ++nsites_; } } - else - level::fill(inplace(points_), false); - npoints_ = 0; - bb_.init(); - bb_need_update_ = false; + template <typename I> + inline + std::size_t + p_image<I>::memory_size() const + { + if (! is_valid()) + return sizeof(*this); + return 0; // FIXME } - template <typename P> - const image2d<bool>& - p_image2d<P>::image() const + template <typename I> + inline + void + p_image<I>::clear() { - return points_; + if (! is_valid()) + return; // No-op. + nsites_ = 0; + level::fill_with_value(ima_, false); } - template <typename P> - image2d<bool>& - p_image2d<P>::image_non_const() + template <typename I> + inline + const I& + p_image<I>::image_hook_() const { - return points_; + mln_precondition(is_valid()); + return ima_; } # endif // ! MLN_INCLUDE_ONLY @@ -278,8 +288,4 @@ } // end of namespace mln -# include <mln/core/p_image2d_piter.hh> -# include <mln/core/p_image2d_pixter.hh> - - -#endif // ! MLN_CORE_P_IMAGE2D_HH +#endif // ! MLN_CORE_SITE_SET_P_IMAGE_HH Index: mln/core/site_set/status.txt --- mln/core/site_set/status.txt (revision 0) +++ mln/core/site_set/status.txt (working copy) @@ -7,7 +7,10 @@ ok p_run ok p_set -KO p_image2d +new p_key +new p_image (replacement of p_image2d) + +rm p_image2d * utility @@ -15,23 +18,25 @@ * derived -ok p_runs -> rename as p_run_set - => better factored as p_set_of<S> +ok p_vaccess +ok line2d new p_set_of new p_mutable_array_of -todo p_array_of + +TODO p_array_of + +rm p_runs (use p_set_of< p_run<P> > instead) * queue-based +ok p_queue ok p_queue_fast ok p_priority_queue -> rename as p_priority rm p_priority_queue_fast rm p_priority_queue_fast_with_array -KO p_queue - * graph-based KO p_bgraph @@ -40,9 +45,6 @@ * adapters -ok p_vaccess -ok line2d - rm pset_array.hh ?? pset_if Index: mln/core/site_set/p_vaccess.hh --- mln/core/site_set/p_vaccess.hh (revision 0) +++ mln/core/site_set/p_vaccess.hh (working copy) @@ -25,16 +25,16 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_P_VACCESS_HH -# define MLN_CORE_P_VACCESS_HH +#ifndef MLN_CORE_SITE_SET_P_VACCESS_HH +# define MLN_CORE_SITE_SET_P_VACCESS_HH -/*! \file mln/core/p_vaccess.hh +/*! \file mln/core/site_set/p_vaccess.hh * * \todo Fix the FIXMEs. */ # include <utility> -# include <mln/core/p_double.hh> +# include <mln/core/site_set/p_double.hh> # include <mln/core/internal/site_set_base.hh> # include <mln/core/internal/pseudo_site_base.hh> # include <mln/core/internal/site_set_impl.hh> @@ -276,4 +276,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_P_VACCESS_HH +#endif // ! MLN_CORE_SITE_SET_P_VACCESS_HH Index: mln/core/site_set/p_key.hh --- mln/core/site_set/p_key.hh (revision 0) +++ mln/core/site_set/p_key.hh (working copy) @@ -25,10 +25,10 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_P_KEY_HH -# define MLN_CORE_P_KEY_HH +#ifndef MLN_CORE_SITE_SET_P_KEY_HH +# define MLN_CORE_SITE_SET_P_KEY_HH -/*! \file mln/core/p_key.hh +/*! \file mln/core/site_set/p_key.hh * * \brief Definition of a FIXME * @@ -38,7 +38,7 @@ # include <map> # include <mln/core/concept/function.hh> # include <mln/core/p_set.hh> -# include <mln/core/p_double.hh> +# include <mln/core/site_set/p_double.hh> # include <mln/core/internal/site_set_base.hh> # include <mln/util/ord.hh> @@ -649,4 +649,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_P_KEY_HH +#endif // ! MLN_CORE_SITE_SET_P_KEY_HH Index: mln/core/site_set/all.hh --- mln/core/site_set/all.hh (revision 0) +++ mln/core/site_set/all.hh (revision 0) @@ -0,0 +1,48 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory +// +// 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_SITE_SET_ALL_HH +# define MLN_CORE_SITE_SET_ALL_HH + +/*! \file mln/core/site_set/all.hh + * + * \brief File that includes all site_set types. + * + * \todo Make it effective after having moved image-defining files. + */ + + +// # include <mln/core/site_set/p_array_of.hh> // FIXME: Uncomment. +# include <mln/core/site_set/p_image.hh> +# include <mln/core/site_set/p_key.hh> +# include <mln/core/site_set/p_mutable_array_of.hh> +# include <mln/core/site_set/p_set_of.hh> +# include <mln/core/site_set/p_vaccess.hh> +// FIXME: Complete... + + +#endif // ! MLN_CORE_SITE_SET_ALL_HH Index: mln/core/site_set/p_double.hh --- mln/core/site_set/p_double.hh (revision 0) +++ mln/core/site_set/p_double.hh (working copy) @@ -25,19 +25,16 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_P_DOUBLE_HH -# define MLN_CORE_P_DOUBLE_HH +#ifndef MLN_CORE_SITE_SET_P_DOUBLE_HH +# define MLN_CORE_SITE_SET_P_DOUBLE_HH -/*! \file mln/core/p_double.hh +/*! \file mln/core/site_set/p_double.hh * * FIXME * * \todo Document! * - * \todo Zed: IMPORTANT FIXME: a psite shall know about both iterators - * to be fully located. Think about an image based on - * p_array_of<p_run<P>>: its psite has to know the first index to - * access the associated value set. + * \todo Add tests about validity of compounded site sets (?) */ # include <mln/core/internal/pseudo_site_base.hh> @@ -317,4 +314,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_P_DOUBLE_HH +#endif // ! MLN_CORE_SITE_SET_P_DOUBLE_HH Index: mln/core/site_set/p_mutable_array_of.hh --- mln/core/site_set/p_mutable_array_of.hh (revision 0) +++ mln/core/site_set/p_mutable_array_of.hh (working copy) @@ -25,10 +25,10 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_P_MUTABLE_ARRAY_OF_HH -# define MLN_CORE_P_MUTABLE_ARRAY_OF_HH +#ifndef MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH +# define MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH -/*! \file mln/core/p_mutable_array_of.hh +/*! \file mln/core/site_set/p_mutable_array_of.hh * * \brief Definition of a mutable array of site sets. * @@ -36,9 +36,11 @@ * inherit, when possible, nsites and bbox (just like in p_vaccess). * It is a different class since such a feature is incompatible with * the "op[] mutable". + * + * \todo Zed: Add element browsing. */ -# include <mln/core/p_double.hh> +# include <mln/core/site_set/p_double.hh> # include <mln/core/internal/site_set_base.hh> # include <mln/util/array.hh> @@ -72,7 +74,7 @@ * Parameter \c S is the type of the contained site sets. */ template <typename S> - class p_mutable_array_of : public internal::site_set_base_< mln_element(S), + class p_mutable_array_of : public internal::site_set_base_< mln_site(S), p_mutable_array_of<S> >, private mlc_is_a(S, Site_Set)::check_t { @@ -105,10 +107,14 @@ p_mutable_array_of(); + /// Reserve memory for \p n elements. + void reserve(unsigned n); + + /// Test if \p p belongs to this point set. - bool has(const psite&) const; + bool has(const psite& p) const; - /// Test if this set of runs is valid. + /// Test this set validity so returns always true. bool is_valid() const; @@ -116,6 +122,7 @@ typedef S i_element; /// Insert a site set \p s. + /// \pre \p s is valid. void insert(const S& s); @@ -172,11 +179,18 @@ template <typename S> inline + void + p_mutable_array_of<S>::reserve(unsigned n) + { + arr_.reserve(n); + } + + template <typename S> + inline bool - p_mutable_array_of<S>::has(const psite&) const + p_mutable_array_of<S>::has(const psite& p) const { - // FIXME - return true; + return p.index() < arr_.nelements() && arr_[p.index()].has(p.p()); } template <typename S> @@ -192,6 +206,7 @@ void p_mutable_array_of<S>::insert(const S& s) { + mln_precondition(s.is_valid()); arr_.append(s); } @@ -283,4 +298,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_P_MUTABLE_ARRAY_OF_HH +#endif // ! MLN_CORE_SITE_SET_P_MUTABLE_ARRAY_OF_HH Index: mln/core/site_set/p_set_of.hh --- mln/core/site_set/p_set_of.hh (revision 0) +++ mln/core/site_set/p_set_of.hh (working copy) @@ -25,15 +25,17 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_P_SET_OF_HH -# define MLN_CORE_P_SET_OF_HH +#ifndef MLN_CORE_SITE_SET_P_SET_OF_HH +# define MLN_CORE_SITE_SET_P_SET_OF_HH -/*! \file mln/core/p_set_of.hh +/*! \file mln/core/site_set/p_set_of.hh * * \brief Definition of a set of site sets. + * + * \todo Zed: Add element browsing. */ -# include <mln/core/p_double.hh> +# include <mln/core/site_set/p_double.hh> # include <mln/core/internal/site_set_base.hh> # include <mln/core/internal/site_set_impl.hh> # include <mln/util/set.hh> @@ -68,7 +70,7 @@ * Parameter \c S is the type of the contained site sets. */ template <typename S> - class p_set_of : public internal::site_set_base_< mln_element(S), + class p_set_of : public internal::site_set_base_< mln_site(S), p_set_of<S> >, public internal::site_set_impl<S>, private mlc_is_a(S, Site_Set)::check_t @@ -103,7 +105,7 @@ /// Test if \p p belongs to this point set. - bool has(const psite&) const; + bool has(const psite& p) const; /// Test if this set of runs is valid. bool is_valid() const; @@ -164,10 +166,9 @@ template <typename S> inline bool - p_set_of<S>::has(const psite&) const + p_set_of<S>::has(const psite& p) const { - // FIXME - return true; + return p.index() < s_.nelements() && s_[p.index()].has(p.p()); } template <typename S> @@ -183,6 +184,7 @@ void p_set_of<S>::insert(const S& s) { + mln_precondition(s.is_valid()); s_.insert(s); this->update_nsites_(s); this->update_bbox_(s); @@ -259,4 +261,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_P_SET_OF_HH +#endif // ! MLN_CORE_SITE_SET_P_SET_OF_HH Index: mln/core/safe.hh --- mln/core/safe.hh (revision 2158) +++ mln/core/safe.hh (working copy) @@ -70,8 +70,9 @@ template <typename I> struct image_< safe_image<I> > : image_< I > // Same as I except... { - // ...this change. + // ...these changes. typedef trait::image::category::identity_morpher category; + typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. }; } // end of namespace mln::trait Index: mln/core/p_runs.hh --- mln/core/p_runs.hh (revision 2158) +++ mln/core/p_runs.hh (working copy) @@ -40,7 +40,7 @@ # include <mln/accu/bbox.hh> # include <mln/core/p_run.hh> -# include <mln/core/p_double.hh> +# include <mln/core/site_set/p_double.hh> # include <mln/core/internal/piter_adaptor.hh> # include <mln/util/set.hh>
participants (1)
-
Thierry Geraud