milena r1602: Replace the point in run_psite by the p_runs reference

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-12-12 Simon Nivault <simon.nivault@lrde.epita.fr> Replace the point in run_psite by the p_runs reference. * mln/core/runs_psite.hh: Replace the point by the p_runs. * mln/core/p_run_piter.hh, * mln/core/internal/run_image.hh, * mln/core/mono_obased_rle_image.hh, * mln/core/mono_rle_image.hh, * mln/core/obased_rle_image.hh, * mln/core/p_runs.hh, * mln/core/rle_image.hh, * mln/core/sparse_image.hh, * tests/core/p_runs.cc: Propagate Changes. * tests/core/mono_obased_rle_image.cc, * tests/core/mono_rle_image.cc, * tests/core/obased_rle_image.cc, * tests/core/rle_image.cc, * tests/core/sparse_image.cc: Use the renamed image small.pgm. --- mln/core/internal/run_image.hh | 11 ----- mln/core/mono_obased_rle_image.hh | 8 +-- mln/core/mono_rle_image.hh | 4 - mln/core/obased_rle_image.hh | 8 +-- mln/core/p_run_piter.hh | 53 +++++++++++++++++++++--- mln/core/p_runs.hh | 41 ++++++++---------- mln/core/rle_image.hh | 8 +-- mln/core/runs_psite.hh | 78 ++++++++++++------------------------ mln/core/sparse_image.hh | 12 ++--- tests/core/mono_obased_rle_image.cc | 2 tests/core/mono_rle_image.cc | 2 tests/core/obased_rle_image.cc | 2 tests/core/p_runs.cc | 28 ++++-------- tests/core/rle_image.cc | 2 tests/core/sparse_image.cc | 2 15 files changed, 126 insertions(+), 135 deletions(-) Index: trunk/milena/tests/core/mono_rle_image.cc =================================================================== --- trunk/milena/tests/core/mono_rle_image.cc (revision 1601) +++ trunk/milena/tests/core/mono_rle_image.cc (revision 1602) @@ -62,7 +62,7 @@ using value::int_u8; image2d<int_u8> lena; - io::pgm::load(lena, "../../img/tiny.pgm"); + io::pgm::load(lena, "../../img/small.pgm"); image2d<int_u8> cmp(lena.domain()); unsigned n; Index: trunk/milena/tests/core/sparse_image.cc =================================================================== --- trunk/milena/tests/core/sparse_image.cc (revision 1601) +++ trunk/milena/tests/core/sparse_image.cc (revision 1602) @@ -58,7 +58,7 @@ using value::int_u8; image2d<int_u8> lena; - io::pgm::load(lena, "../../img/tiny.pgm"); + io::pgm::load(lena, "../../img/small.pgm"); image2d<int_u8> cmp(lena.domain()); unsigned n; Index: trunk/milena/tests/core/obased_rle_image.cc =================================================================== --- trunk/milena/tests/core/obased_rle_image.cc (revision 1601) +++ trunk/milena/tests/core/obased_rle_image.cc (revision 1602) @@ -58,7 +58,7 @@ using value::int_u8; image2d<int_u8> lena; - io::pgm::load(lena, "../../img/tiny.pgm"); + io::pgm::load(lena, "../../img/small.pgm"); image2d<int_u8> cmp(lena.domain()); unsigned n; Index: trunk/milena/tests/core/rle_image.cc =================================================================== --- trunk/milena/tests/core/rle_image.cc (revision 1601) +++ trunk/milena/tests/core/rle_image.cc (revision 1602) @@ -58,7 +58,7 @@ using value::int_u8; image2d<int_u8> lena; - io::pgm::load(lena, "../../img/tiny.pgm"); + io::pgm::load(lena, "../../img/small.pgm"); image2d<int_u8> cmp(lena.domain()); unsigned n; Index: trunk/milena/tests/core/p_runs.cc =================================================================== --- trunk/milena/tests/core/p_runs.cc (revision 1601) +++ trunk/milena/tests/core/p_runs.cc (revision 1602) @@ -56,10 +56,6 @@ q = make::point2d(18, 42); r = make::point2d(50, 76); - // Psite declaration - runs_psite<point2d> site(p, 5, 0); - runs_psite<point2d> site2(r, 40, 0); - // Pset test p_runs_<point2d> ps; @@ -69,23 +65,17 @@ ps.insert(p_run<point2d>(q, 5)); mln_assertion(ps.npoints() == 12); + ps.insert(p_run<point2d>(r, 2)); + + ps.insert(p_run<point2d>(make::point2d(17,40), 6)); + + // Psite declaration + runs_psite<point2d> site(ps, 5, 0); + runs_psite<point2d> site2(ps, 6, 1); + mln_assertion(ps.has(site)); mln_assertion(!ps.has(site2)); - ps.insert(p_run<point2d>(r, 2)); - mln_assertion(!ps.has(site2)); - ps.insert(p_run<point2d>(make::point2d(17,40), 6)); - mln_fwd_piter_(p_runs_<point2d>) ppf(ps); - for_all(ppf) - { - std::cout << ppf << std::endl; - } - std::cout << std::endl; - mln_bkd_piter_(p_runs_<point2d>) ppb(ps); - for_all(ppb) - { - std::cout << ppb << std::endl; - } - // parc(ps); + parc(ps); } Index: trunk/milena/tests/core/mono_obased_rle_image.cc =================================================================== --- trunk/milena/tests/core/mono_obased_rle_image.cc (revision 1601) +++ trunk/milena/tests/core/mono_obased_rle_image.cc (revision 1602) @@ -58,7 +58,7 @@ using value::int_u8; image2d<int_u8> lena; - io::pgm::load(lena, "../../img/tiny.pgm"); + io::pgm::load(lena, "../../img/small.pgm"); image2d<int_u8> cmp(lena.domain()); unsigned n; Index: trunk/milena/mln/core/internal/run_image.hh =================================================================== --- trunk/milena/mln/core/internal/run_image.hh (revision 1601) +++ trunk/milena/mln/core/internal/run_image.hh (revision 1602) @@ -87,17 +87,6 @@ float run_image_<T, P, E>::compression() const { - std::cout << float(exact(this)->data_->size_mem()) - << " / ( " - << float (sizeof(T)) - << " * " - << float (exact(this)->data_->domain_.bbox().npoints()) - << " )" - << std::endl; - std::cout << exact(this)->data_->domain_.bbox().pmin() - << " " - << exact(this)->data_->domain_.bbox().pmax() - << std::endl; return float(exact(this)->data_->size_mem()) / float (sizeof(T) * exact(this)->data_->domain_.bbox().npoints()); } Index: trunk/milena/mln/core/rle_image.hh =================================================================== --- trunk/milena/mln/core/rle_image.hh (revision 1601) +++ trunk/milena/mln/core/rle_image.hh (revision 1602) @@ -213,8 +213,8 @@ const { mln_precondition(this->has_data() && - site.pset_pos_() < this->data_->values_.size()); - return this->data_->values_[site.pset_pos_()]; + site.p_of_run() < this->data_->values_.size()); + return this->data_->values_[site.p_of_run()]; } template <typename P, typename T> @@ -223,8 +223,8 @@ rle_image<P, T>::operator() (const typename rle_image<P, T>::psite& site) { mln_precondition(this->has_data() && - site.pset_pos_() < this->data_->values_.size()); - return this->data_->values_[site.pset_pos_()]; + site.p_of_run() < this->data_->values_.size()); + return this->data_->values_[site.p_of_run()]; } template <typename P, typename T> Index: trunk/milena/mln/core/mono_rle_image.hh =================================================================== --- trunk/milena/mln/core/mono_rle_image.hh (revision 1601) +++ trunk/milena/mln/core/mono_rle_image.hh (revision 1602) @@ -214,7 +214,7 @@ mono_rle_image<P, T>::operator() (const typename mono_rle_image<P, T>::psite& site) const { - mln_precondition(site.pset_pos_() < this->data_->domain_.nruns()); + mln_precondition(site.p_of_run() < this->data_->domain_.nruns()); return this->data_->value_; } @@ -231,7 +231,7 @@ typename mono_rle_image<P, T>::lvalue mono_rle_image<P, T>::operator() (const typename mono_rle_image<P, T>::psite& site) { - mln_precondition(site.pset_pos_() < this->data_->domain_.nruns()); + mln_precondition(site.p_of_run() < this->data_->domain_.nruns()); return this->data_->value_; } Index: trunk/milena/mln/core/runs_psite.hh =================================================================== --- trunk/milena/mln/core/runs_psite.hh (revision 1601) +++ trunk/milena/mln/core/runs_psite.hh (revision 1602) @@ -34,6 +34,7 @@ */ # include <mln/core/concept/point_site.hh> +# include <mln/core/p_runs.hh> namespace mln @@ -56,9 +57,7 @@ typedef mln_dpoint(P) dpoint; typedef mln_coord(P) coord; - runs_psite(); - runs_psite(const p_runs_<P>& pr, const P& p); - runs_psite(P point, unsigned index, unsigned pset_pos); + runs_psite(const p_runs_<P>& pr, unsigned in_run, unsigned of_run); operator P () const; @@ -69,16 +68,16 @@ const P& range_start_() const; /// Return the position of this psite in the point set. - unsigned pset_pos_() const; + unsigned p_of_run() const; /// Return the position of this psite in the point set. - unsigned& pset_pos_(); + unsigned& p_of_run(); /// Return the position of this psite in the current range. - unsigned index_() const; + unsigned p_in_run() const; /// Return the position of this psite in the current range. - unsigned& index_(); + unsigned& p_in_run(); /// Reference to the corresponding point. const P& to_point() const; @@ -89,13 +88,13 @@ protected: /// Start of the psite range. - P p_; + const p_runs_<P>& pr_; /// Position in the psite range. - unsigned range_index_; + unsigned p_in_run_; /// Position of the psite in the point set. - unsigned pset_position_; + unsigned p_of_run_; }; @@ -103,37 +102,20 @@ template <typename P> inline - runs_psite<P>::runs_psite(const p_runs_<P>& pr, const P& p) - { - unsigned i = 0; - while (i < pr.nruns() && p >= pr[i].first()) - ++i; - mln_assertion(i != 0); - - range_index_ = p[P::dim - 1] - pr[i - 1].first()[P::dim - 1]; - - mln_assertion(pr[i - 1].npoints() > range_index_); - - pset_position_ = i - 1; - p_ = pr[pset_position_].first(); - } - - template <typename P> - inline - runs_psite<P>::runs_psite(P point, unsigned index, unsigned pset_pos) : - p_(point), - range_index_(index), - pset_position_(pset_pos) + runs_psite<P>::runs_psite(const p_runs_<P>& pr, unsigned in_run, unsigned of_run) + : pr_(pr), + p_in_run_(in_run), + p_of_run_(of_run) { + mln_precondition(of_run < pr.nruns()); + mln_precondition(in_run < pr[of_run].length()); } template <typename P> inline runs_psite<P>::operator P() const { - P p = p_; - p[dim - 1] += range_index_; - return p; + return pr_[p_of_run_][p_in_run_]; } template <typename P> @@ -141,7 +123,7 @@ const P& runs_psite<P>::range_start_() const { - return p_; + return pr_[p_of_run_].first(); } template <typename P> @@ -149,39 +131,39 @@ P& runs_psite<P>::range_start_() { - return p_; + return pr_[p_of_run_].first(); } template <typename P> inline unsigned - runs_psite<P>::pset_pos_() const + runs_psite<P>::p_of_run() const { - return pset_position_; + return p_of_run_; } template <typename P> inline unsigned& - runs_psite<P>::pset_pos_() + runs_psite<P>::p_of_run() { - return pset_position_; + return p_of_run_; } template <typename P> inline unsigned - runs_psite<P>::index_() const + runs_psite<P>::p_in_run() const { - return range_index_; + return p_in_run_; } template <typename P> inline unsigned& - runs_psite<P>::index_() + runs_psite<P>::p_in_run() { - return range_index_; + return p_in_run_; } template <typename P> @@ -189,8 +171,7 @@ const P& runs_psite<P>::to_point() const { - static P p = p_; - p[dim - 1] += range_index_; + static P p = pr_[p_of_run_][p_in_run_]; return p; } @@ -200,10 +181,7 @@ runs_psite<P>::operator[](unsigned i) const { mln_precondition(i < dim); - if (i == dim - 1) - return p_[i] + range_index_; - else - return p_[i]; + return pr_[p_of_run_][p_in_run_][i]; } # endif // ! MLN_INCLUDE_ONLY Index: trunk/milena/mln/core/obased_rle_image.hh =================================================================== --- trunk/milena/mln/core/obased_rle_image.hh (revision 1601) +++ trunk/milena/mln/core/obased_rle_image.hh (revision 1602) @@ -241,8 +241,8 @@ const { mln_precondition(this->has_data() && - site.pset_pos_() < this->data_->domain_.nruns()); - return this->data_->values_[site.pset_pos_()]; + site.p_of_run() < this->data_->domain_.nruns()); + return this->data_->values_[site.p_of_run()]; } template <typename P, typename T> @@ -251,8 +251,8 @@ obased_rle_image<P, T>::operator() (const typename obased_rle_image<P, T>::psite& site) { mln_precondition(this->has_data() && - site.pset_pos_() < this->data_->domain_.nruns()); - return this->data_->values_[site.pset_pos_()]; + site.p_of_run() < this->data_->domain_.nruns()); + return this->data_->values_[site.p_of_run()]; } template <typename P, typename T> Index: trunk/milena/mln/core/p_run_piter.hh =================================================================== --- trunk/milena/mln/core/p_run_piter.hh (revision 1601) +++ trunk/milena/mln/core/p_run_piter.hh (revision 1602) @@ -79,12 +79,16 @@ /// Go to the next point. void next_(); + /// Get the index of the point in the run. + unsigned ind() const; + /// Convert the iterator into a point. operator P() const; protected: const p_run<P>* run_; bool is_valid_; + unsigned i_; P p_; }; @@ -130,12 +134,16 @@ /// Go to the next point. void next_(); + /// Get the index of the point in the run. + unsigned ind() const; + /// Convert the iterator into a point. operator P() const; protected: const p_run<P>* run_; bool is_valid_; + unsigned i_; P p_; }; @@ -148,16 +156,17 @@ template <typename P> inline p_run_fwd_piter_<P>::p_run_fwd_piter_() - : run_ (0) + : run_ (0), + is_valid_(false) { } template <typename P> inline p_run_fwd_piter_<P>::p_run_fwd_piter_(const p_run<P>& pr) - : run_(&pr) + : run_(&pr), + is_valid_(false) { - invalidate(); } template <typename P> @@ -166,7 +175,7 @@ p_run_fwd_piter_<P>::assign_run(const p_run<P>& pr) { run_ = ≺ - invalidate(); + is_valid_ = false; } template <typename P> @@ -175,6 +184,7 @@ p_run_fwd_piter_<P>::to_point() const { mln_precondition(is_valid()); + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); return p_; } @@ -185,6 +195,7 @@ { mln_precondition(i < dim); mln_precondition(is_valid()); + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); return p_[i]; } @@ -210,6 +221,7 @@ p_run_fwd_piter_<P>::start() { p_ = run_->first(); + i_ = 0; is_valid_ = true; } @@ -218,15 +230,27 @@ void p_run_fwd_piter_<P>::next_() { + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); p_[dim - 1]++; + ++i_; is_valid_ = p_[dim - 1] - run_->first()[dim - 1] < (signed)run_->length(); } template <typename P> inline + unsigned + p_run_fwd_piter_<P>::ind() const + { + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); + return i_; + } + + template <typename P> + inline p_run_fwd_piter_<P>::operator P() const { mln_precondition(is_valid()); + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); return p_; } @@ -243,9 +267,9 @@ template <typename P> inline p_run_bkd_piter_<P>::p_run_bkd_piter_(const p_run<P>& pr) - : run_(&pr) + : run_(&pr), + is_valid_(false) { - invalidate(); } template <typename P> @@ -254,7 +278,7 @@ p_run_bkd_piter_<P>::assign_run(const p_run<P>& pr) { run_ = ≺ - invalidate(); + is_valid_ = false; } template <typename P> @@ -263,6 +287,7 @@ p_run_bkd_piter_<P>::to_point() const { mln_precondition(is_valid()); + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); return p_; } @@ -273,6 +298,7 @@ { mln_precondition(i < dim); mln_precondition(is_valid()); + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); return p_[i]; } @@ -298,6 +324,7 @@ p_run_bkd_piter_<P>::start() { p_ = (*run_)[run_->length() - 1]; + i_ = run_->length() - 1; is_valid_ = true; } @@ -306,15 +333,27 @@ void p_run_bkd_piter_<P>::next_() { + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); p_[dim - 1]--; + --i_; is_valid_ = p_[dim - 1] - run_->first()[dim - 1] >= 0; } template <typename P> inline + unsigned + p_run_bkd_piter_<P>::ind() const + { + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); + return i_; + } + + template <typename P> + inline p_run_bkd_piter_<P>::operator P() const { mln_precondition(is_valid()); + mln_assertion(p_[P::dim - 1] - run_->first()[P::dim - 1] == signed(i_)); return p_; } Index: trunk/milena/mln/core/mono_obased_rle_image.hh =================================================================== --- trunk/milena/mln/core/mono_obased_rle_image.hh (revision 1601) +++ trunk/milena/mln/core/mono_obased_rle_image.hh (revision 1602) @@ -229,8 +229,8 @@ const { mln_precondition(this->has_data() && - site.pset_pos_() < this->data_->domain_.nruns()); - return this->data_->values_[site.pset_pos_()]; + site.p_of_run() < this->data_->domain_.nruns()); + return this->data_->values_[site.p_of_run()]; } template <typename P, typename T> @@ -239,8 +239,8 @@ mono_obased_rle_image<P, T>::operator() (const typename mono_obased_rle_image<P, T>::psite& site) { mln_precondition(this->has_data() && - site.pset_pos_() < this->data_->domain_.nruns()); - return this->data_->values_[site.pset_pos_()]; + site.p_of_run() < this->data_->domain_.nruns()); + return this->data_->values_[site.p_of_run()]; } template <typename P, typename T> Index: trunk/milena/mln/core/sparse_image.hh =================================================================== --- trunk/milena/mln/core/sparse_image.hh (revision 1601) +++ trunk/milena/mln/core/sparse_image.hh (revision 1602) @@ -213,9 +213,9 @@ const { mln_precondition(this->has_data()); - mln_precondition(site.pset_pos_() < this->data_->values_.size()); - mln_precondition(site.index_() < this->data_->values_[site.pset_pos_()].size()); - return this->data_->values_[site.pset_pos_()][site.index_()]; + mln_precondition(site.p_of_run() < this->data_->values_.size()); + mln_precondition(site.p_in_run() < this->data_->values_[site.p_of_run()].size()); + return this->data_->values_[site.p_of_run()][site.p_in_run()]; } template <typename P, typename T> @@ -224,9 +224,9 @@ sparse_image<P, T>::operator() (const typename sparse_image<P, T>::psite& site) { mln_precondition(this->has_data() && - site.pset_pos_() < this->data_->values_.size() && - site.index_() < this->data_->values_[site.pset_pos_()].size()); - return this->data_->values_[site.pset_pos_()][site.index_()]; + site.p_of_run() < this->data_->values_.size() && + site.p_in_run() < this->data_->values_[site.p_of_run()].size()); + return this->data_->values_[site.p_of_run()][site.p_in_run()]; } template <typename P, typename T> Index: trunk/milena/mln/core/p_runs.hh =================================================================== --- trunk/milena/mln/core/p_runs.hh (revision 1601) +++ trunk/milena/mln/core/p_runs.hh (revision 1602) @@ -127,7 +127,7 @@ { for (unsigned i = 0; i < con_.nelements(); ++i) { - if (con_[i].first() == p.range_start_() && con_[i].length() > p.index_()) + if (con_[i].first() == p.range_start_() && con_[i].length() > p.p_in_run()) return true; } return false; @@ -262,9 +262,6 @@ { public: - /// Convertion into a point-site. - operator runs_psite<P> () const; - /// Convertion into a point. operator P () const; @@ -296,12 +293,6 @@ } template <typename P, typename E> - p_runs_piter_<P, E>::operator runs_psite<P> () const - { - return runs_psite<P>(con_, p_); - } - - template <typename P, typename E> inline p_runs_piter_<P, E>::operator P () const { @@ -353,6 +344,9 @@ /// Go to the next point. void next_(); + /// Convertion into a point-site. + operator runs_psite<P> () const; + protected: unsigned i_; @@ -417,20 +411,12 @@ return; } this->p_ = it_; + } - -// mln_precondition(this->is_valid()); -// ++(this->site_.index_()); - -// if (this->site_.index_() >= it_->second) -// { -// ++it_; -// ++this->site_.pset_pos_(); -// this->site_.range_start_() = it_->first; -// this->site_.index_() = 0; -// } -// this->p_ = this->site_.range_start_(); -// this->p_[0] += this->site_.index_(); + template <typename P> + p_runs_fwd_piter_<P>::operator runs_psite<P> () const + { + return runs_psite<P>(this->con_, it_.ind(), i_); } # endif // ! MLN_INCLUDE_ONLY @@ -460,6 +446,9 @@ /// Go to the next point. void next_(); + /// Convertion into a point-site. + operator runs_psite<P> () const; + protected: unsigned i_; @@ -527,6 +516,12 @@ this->p_ = it_; } + template <typename P> + p_runs_bkd_piter_<P>::operator runs_psite<P> () const + { + return runs_psite<P>(this->con_, it_.ind(), i_); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln
participants (1)
-
nivaul_s@lrde.epita.fr