961: Replace 'to_point' method by internal routine.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Replace 'to_point' method by internal routine. * oln/core/concept/iterator_on_points.hh (to_point): Remove method. (to_point): New internal routine. * oln/core/concept/point.hh: Likewise. * oln/convert/to_weighted_window.hh, * oln/debug/print.hh, * oln/core/gen/traits.hh, * oln/core/gen/sparse_encode.hh, * oln/core/gen/pset_compare.hh, * oln/core/gen/rle_encode.hh, * oln/core/internal/box.hh, * oln/core/internal/dpoints_piter_impl.hh, * oln/core/internal/encoded_image_psite.hh, * oln/core/internal/point_set_std_based.hh, * oln/core/internal/piter_adaptor.hh, * oln/core/internal/encoded_image_pset.hh, * oln/core/internal/iterator_on_points_impl.hh, * oln/linear/convolution.hh: Update. convert/to_weighted_window.hh | 4 +- core/concept/iterator_on_points.hh | 44 ++++++++++++++++++------------- core/concept/point.hh | 21 ++++++++++++++ core/gen/pset_compare.hh | 4 +- core/gen/rle_encode.hh | 22 ++++++++------- core/gen/sparse_encode.hh | 32 +++++++++++----------- core/internal/box.hh | 16 ----------- core/internal/dpoints_piter_impl.hh | 11 +------ core/internal/encoded_image_pset.hh | 8 ----- core/internal/encoded_image_psite.hh | 17 ++--------- core/internal/iterator_on_points_impl.hh | 16 +++++------ core/internal/piter_adaptor.hh | 10 ------- core/internal/point_set_std_based.hh | 43 ++++++++++-------------------- debug/print.hh | 2 - linear/convolution.hh | 6 ++-- 15 files changed, 113 insertions(+), 143 deletions(-) Index: oln/convert/to_weighted_window.hh --- oln/convert/to_weighted_window.hh (revision 960) +++ oln/convert/to_weighted_window.hh (working copy) @@ -65,7 +65,7 @@ oln_f_image_to_weighted_window(I) output; oln_piter(I) p(input.points()); for_all(p) - output.take(input(p), O - p.to_point()); // FIXME: zero - p + output.take(input(p), O - oln_point(I)(p)); // FIXME: replace to_point by zero - p return output; } @@ -78,7 +78,7 @@ oln_point(W) O; O.set_all(0); oln_qiter(W) q(win, O); for_all(q) - output.take(weight_(q), O - q.to_point()); + output.take(weight_(q), O - oln_point(W)(q)); // FIXME: to_point return output; } Index: oln/debug/print.hh --- oln/debug/print.hh (revision 960) +++ oln/debug/print.hh (working copy) @@ -61,7 +61,7 @@ { oln_fwd_piter(I) p(input.points()); for_all(p) - ostr << p.to_point() << ':' << format(input(p)) << ' '; + ostr << p << ':' << format(input(p)) << ' '; } template <typename I> Index: oln/core/gen/sparse_encode.hh --- oln/core/gen/sparse_encode.hh (revision 960) +++ oln/core/gen/sparse_encode.hh (working copy) @@ -29,11 +29,11 @@ #ifndef OLN_CORE_GEN_SPARSE_ENCODE_HH # define OLN_CORE_GEN_SPARSE_ENCODE_HH -# include <oln/core/concept/image.hh> +# include <vector> +# include <oln/core/concept/image.hh> # include <oln/core/gen/sparse_image.hh> -# include <vector> namespace oln { @@ -46,32 +46,31 @@ ** @return a sparse image */ template <typename I> - sparse_image<typename I::point, typename I::value> + sparse_image<oln_point(I), oln_value(I)> sparse_encode(const Image<I>& input) { - sparse_image<typename I::point, typename I::value> output; - typename I::piter p(input.points()); + sparse_image<oln_point(I), oln_value(I)> output; + oln_piter(I) p(input.points()); unsigned len = 1; - /// old point first dim coordinate + // old point first dim coordinate typename I::coord old = 1; - /// range pointstart - typename I::point rstart; - /// range value - std::vector<typename I::value> values; + // range pointstart + oln_point(I) rstart; + // range value + std::vector<oln_value(I)> values; p.start(); - if (!p.is_valid()) + if (not p.is_valid()) return output; rstart = p; - // FIXME: is it generall ? - old = (p.to_point())[0]; + old = p.vec()[0]; values.push_back(input(p)); p.next(); while (p.is_valid()) { - if ((p.to_point())[0] - 1 = old) + if (p.vec()[0] - 1 = old) { ++len; values.push_back(input(p)); @@ -84,12 +83,13 @@ values.clear(); values.push_back(input(p)); } - old = (p.to_point())[0]; + old = p.vec()[0]; p.next(); } output.insert(rstart, len, values); return output; } -} + +} // end of namespace oln #endif // !OLN_CORE_ENCODE_SPARSE_ENCODE_HH Index: oln/core/gen/pset_compare.hh --- oln/core/gen/pset_compare.hh (revision 960) +++ oln/core/gen/pset_compare.hh (working copy) @@ -82,7 +82,7 @@ { if (not pr.is_valid()) // while pl is valid return false; - if (pl.to_point() != pr.to_point()) + if (oln_point(L)(pl) != oln_point(R)(pr)) // FIXME: to_point return false; } if (pr.is_valid()) // while pl is not valid @@ -146,7 +146,7 @@ // oln_piter(L) p_lhs(lhs); // for_all(p_lhs) // { - // while (p_rhs.is_valid() and p_rhs.to_point() != p_lhs.to_point()) + // while (p_rhs.is_valid() and p_rhs != p_lhs) // p_rhs.next(); // if (not p_rhs.is_valid()) // return false; Index: oln/core/gen/rle_encode.hh --- oln/core/gen/rle_encode.hh (revision 960) +++ oln/core/gen/rle_encode.hh (working copy) @@ -42,13 +42,13 @@ */ template <typename P> bool - on_the_same_line(P p1, P p2) + on_the_same_line(const P& p1, const P& p2) { unsigned dim = mlc_value(typename P::grid::dim); bool same_line = true; - for (int n = dim - 1; same_line && n > 0; --n) - same_line = p1[n] = p2[n]; + for (int n = dim - 1; same_line and n > 0; --n) + same_line = (p1[n] = p2[n]); return same_line; } @@ -61,16 +61,16 @@ ** @return rle_image */ template <typename I> - rle_image<typename Image<I>::point, typename I::value> + rle_image<oln_point(I), oln_value(I)> rle_encode(const Image<I>& input) { - rle_image<typename I::point, typename I::value> output; - typename Image<I>::piter p (input.points()); + rle_image<oln_point(I), oln_value(I)> output; + oln_piter(I) p (input.points()); unsigned len = 1; /// range point start - typename I::point rstart; + oln_point(I) rstart; /// range value - typename I::value rvalue; + oln_value(I) rvalue; p.start(); if (!p.is_valid()) @@ -81,7 +81,8 @@ p.next(); while (p.is_valid()) { - if (rvalue = input(p) && on_the_same_line(rstart, p.to_point())) + if (rvalue = input(p) and + on_the_same_line(rstart, oln_point(I)(p))) // FIXME: to_point ++len; else { @@ -95,6 +96,7 @@ output.insert(rstart, len, rvalue); return output; } + } // end of namespace oln -#endif /* !OLN_CORE_GEN_RLE_ENCODE_HH */ +#endif // ! OLN_CORE_GEN_RLE_ENCODE_HH Index: oln/core/concept/iterator_on_points.hh --- oln/core/concept/iterator_on_points.hh (revision 960) +++ oln/core/concept/iterator_on_points.hh (working copy) @@ -46,7 +46,6 @@ { stc_typename(point); - point to_point() const; const point* point_adr() const; // Final. @@ -61,19 +60,20 @@ }; // end of class oln::Iterator_on_Points<Exact> - template <typename Exact> - std::ostream& operator<<(std::ostream& ostr, const Iterator_on_Points<Exact>& pit); - + template <typename It> + std::ostream& operator<<(std::ostream& ostr, const Iterator_on_Points<It>& it); -# ifndef OLN_INCLUDE_ONLY - template <typename Exact> - typename Iterator_on_Points<Exact>::point - Iterator_on_Points<Exact>::to_point() const + namespace internal { - precondition(this->is_valid()); - return exact(this)->impl_to_point(); - } + + template <typename It> + const oln_point(It)& to_point(const Iterator_on_Points<It>& it); + + } // end of namespace oln::internal + + +# ifndef OLN_INCLUDE_ONLY template <typename Exact> const typename Iterator_on_Points<Exact>::point* @@ -86,7 +86,7 @@ Iterator_on_Points<Exact>::operator typename Iterator_on_Points<Exact>::point() const { precondition(this->is_valid()); - return this->to_point(); + return *(exact(this)->impl_point_adr()); } template <typename Exact> @@ -99,19 +99,27 @@ template <typename Exact> void Iterator_on_Points<Exact>::check__() const { - point (Exact::*impl_to_point_adr)() const = & Exact::impl_to_point; - impl_to_point_adr = 0; const point* (Exact::*impl_point_adr_adr)() const = & Exact::impl_point_adr; impl_point_adr_adr = 0; - // FIXME: & Exact::operator point... } - template <typename Exact> - std::ostream& operator<<(std::ostream& ostr, const Iterator_on_Points<Exact>& pit) + template <typename It> + std::ostream& operator<<(std::ostream& ostr, const Iterator_on_Points<It>& it) { - return ostr << pit.to_point(); + return ostr << (oln_point(It)(it)); } + namespace internal + { + + template <typename It> + const oln_point(It)& to_point(const Iterator_on_Points<It>& it) + { + return *(it.point_adr()); + } + + } // end of namespace oln::internal + # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 960) +++ oln/core/concept/point.hh (working copy) @@ -113,6 +113,16 @@ + namespace internal + { + + template <typename P> + const P& to_point(const Point<P>& p); + + } // end of namespace oln::internal + + + namespace ERROR { @@ -182,6 +192,17 @@ // mlc::assert_defined_< oln_vtype(Exact, dim) >::check(); } + namespace internal + { + + template <typename P> + const P& to_point(const Point<P>& p) + { + return exact(p); + } + + } // end of namespace oln::internal + template <typename P> typename P::dpoint operator-(const Point<P>& lhs, const Point<P>& rhs) Index: oln/core/internal/box.hh --- oln/core/internal/box.hh (revision 960) +++ oln/core/internal/box.hh (working copy) @@ -161,7 +161,6 @@ void impl_next(); void impl_invalidate(); bool impl_is_valid() const; - point impl_to_point() const; const point* impl_point_adr() const; private: @@ -188,7 +187,6 @@ void impl_next(); void impl_invalidate(); bool impl_is_valid() const; - point impl_to_point() const; const point* impl_point_adr() const; private: @@ -350,13 +348,6 @@ } template <typename B> - typename box_fwd_piter_<B>::point - box_fwd_piter_<B>::impl_to_point() const - { - return p_; - } - - template <typename B> const typename box_fwd_piter_<B>::point* box_fwd_piter_<B>::impl_point_adr() const { @@ -416,13 +407,6 @@ } template <typename B> - typename box_bkd_piter_<B>::point - box_bkd_piter_<B>::impl_to_point() const - { - return p_; - } - - template <typename B> const typename box_bkd_piter_<B>::point* box_bkd_piter_<B>::impl_point_adr() const { Index: oln/core/internal/dpoints_piter_impl.hh --- oln/core/internal/dpoints_piter_impl.hh (revision 960) +++ oln/core/internal/dpoints_piter_impl.hh (working copy) @@ -41,7 +41,7 @@ /// Classes to factor code for iterators based on vector of dpoints. template <typename P> - class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) > // FIXME: Add err msg. + class dpoints_piter_impl_ { public: // dpoints_piter_impl_(const dpoints_piter_impl_&); @@ -49,7 +49,6 @@ void impl_invalidate(); bool impl_is_valid() const; - P impl_to_point() const; const P* impl_point_adr() const; protected: @@ -133,6 +132,7 @@ n_(dps.size()), i_(n_) { + mlc::assert_< mlc_is_a(P, Point) >::check(); // FIXME: Add err msg. precondition(dps.size() != 0); } @@ -151,13 +151,6 @@ } template <typename P> - P - dpoints_piter_impl_<P>::impl_to_point() const - { - return this->p_; - } - - template <typename P> const P* dpoints_piter_impl_<P>::impl_point_adr() const { Index: oln/core/internal/encoded_image_psite.hh --- oln/core/internal/encoded_image_psite.hh (revision 960) +++ oln/core/internal/encoded_image_psite.hh (working copy) @@ -42,7 +42,6 @@ { enc_image_psite_(); - P to_point() const; operator P () const; P start_; @@ -58,22 +57,14 @@ } template <typename P> - P - enc_image_psite_<P>::to_point() const - { - P p = this->start_; - - p[0] += this->index_; - return p; - } - - template <typename P> enc_image_psite_<P>::operator P() const { - return this->to_point(); + P tmp = this->start_; + tmp[0] += this->index_; + return tmp; } -# endif /* !OLN_INCLUDE_ONLY */ +# endif // ! OLN_INCLUDE_ONLY } // end of namespace internal Index: oln/core/internal/point_set_std_based.hh --- oln/core/internal/point_set_std_based.hh (revision 960) +++ oln/core/internal/point_set_std_based.hh (working copy) @@ -103,17 +103,9 @@ }; // end of class point_set_std_based_<Exact> - template <typename Exact> + template <typename Ps> std::ostream& operator<<(std::ostream& ostr, - const point_set_std_based_<Exact>& pts) - { - typename Exact::fwd_piter i(pts); - ostr << "{ "; - for_all(i) - ostr << i.to_point() << ' '; - ostr << "}"; - return ostr; - } + const point_set_std_based_<Ps>& pts); # ifndef OLN_INCLUDE_ONLY @@ -159,7 +151,19 @@ return this->con_; } -# endif + template <typename Ps> + std::ostream& operator<<(std::ostream& ostr, + const point_set_std_based_<Ps>& pts) + { + oln_fwd_piter(Ps) p(pts); + ostr << "{ "; + for_all(p) + ostr << p << ' '; + ostr << "}"; + return ostr; + } + +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln::internal @@ -221,7 +225,6 @@ void impl_next(); void impl_invalidate(); bool impl_is_valid() const; - point impl_to_point() const; const point* impl_point_adr() const; private: @@ -250,7 +253,6 @@ void impl_next(); void impl_invalidate(); bool impl_is_valid() const; - point impl_to_point() const; const point* impl_point_adr() const; private: @@ -302,13 +304,6 @@ } template <typename C> - typename pset_std_based_fwd_piter_<C>::point - pset_std_based_fwd_piter_<C>::impl_to_point() const - { - return *this->it_; - } - - template <typename C> const typename pset_std_based_fwd_piter_<C>::point* pset_std_based_fwd_piter_<C>::impl_point_adr() const { @@ -359,13 +354,6 @@ } template <typename C> - typename pset_std_based_bkd_piter_<C>::point - pset_std_based_bkd_piter_<C>::impl_to_point() const - { - return *this->it_; - } - - template <typename C> const typename pset_std_based_bkd_piter_<C>::point* pset_std_based_bkd_piter_<C>::impl_point_adr() const { @@ -373,7 +361,6 @@ // FIXME: Read comments in pset_std_based_fwd_piter_<C>. } - # endif // ! OLN_INCLUDE_ONLY Index: oln/core/internal/piter_adaptor.hh --- oln/core/internal/piter_adaptor.hh (revision 960) +++ oln/core/internal/piter_adaptor.hh (working copy) @@ -80,7 +80,6 @@ void impl_next(); void impl_invalidate(); bool impl_is_valid() const; - point impl_to_point() const; const point* impl_point_adr() const; protected: @@ -127,20 +126,13 @@ } template <typename Exact> - typename piter_adaptor_<Exact>::point - piter_adaptor_<Exact>::impl_to_point() const - { - return this->p_.to_point(); - } - - template <typename Exact> const typename piter_adaptor_<Exact>::point* piter_adaptor_<Exact>::impl_point_adr() const { return this->p_.point_adr(); } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln::internal Index: oln/core/internal/encoded_image_pset.hh --- oln/core/internal/encoded_image_pset.hh (revision 960) +++ oln/core/internal/encoded_image_pset.hh (working copy) @@ -218,7 +218,6 @@ typedef enc_image_psite_<point> psite; const enc_image_psite_<point>& impl_to_psite() const; - point impl_to_point() const; const enc_image_psite_<point>* impl_psite_adr() const; operator psite () const; const point* impl_point_adr() const; //FIXME @@ -248,13 +247,6 @@ } template <typename Exact> - typename enc_image_pset_piter_<Exact>::point - enc_image_pset_piter_<Exact>::impl_to_point() const - { - return ps_; - } - - template <typename Exact> enc_image_pset_piter_<Exact>::operator typename enc_image_pset_piter_<Exact>::psite () const { return this->impl_to_psite(); Index: oln/core/internal/iterator_on_points_impl.hh --- oln/core/internal/iterator_on_points_impl.hh (revision 960) +++ oln/core/internal/iterator_on_points_impl.hh (working copy) @@ -105,14 +105,14 @@ const typename iterator_on_points_impl_base_<Exact>::vec_t& iterator_on_points_impl_base_<Exact>::vec() const { - return static_cast<const Exact&>(*this).to_point().vec(); + return static_cast<const Exact*>(this)->impl_point_adr()->vec(); } template <typename Exact> typename iterator_on_points_impl_base_<Exact>::vec_t& iterator_on_points_impl_base_<Exact>::vec() { - return static_cast<const Exact&>(*this).to_point().vec(); + return const_cast<vec_t&>(static_cast<Exact*>(this)->impl_point_adr()->vec()); } // 1d impl @@ -121,7 +121,7 @@ typename iterator_on_points_impl_<1, Exact>::coord iterator_on_points_impl_<1, Exact>::ind() const { - return static_cast<const Exact&>(*this).to_point().ind(); + return static_cast<const Exact*>(this)->impl_point_adr()->ind(); } // 2d impl @@ -130,14 +130,14 @@ typename iterator_on_points_impl_<2, Exact>::coord iterator_on_points_impl_<2, Exact>::row() const { - return static_cast<const Exact&>(*this).to_point().row(); + return static_cast<const Exact*>(this)->impl_point_adr()->row(); } template <typename Exact> typename iterator_on_points_impl_<2, Exact>::coord iterator_on_points_impl_<2, Exact>::col() const { - return static_cast<const Exact&>(*this).to_point().col(); + return static_cast<const Exact*>(this)->impl_point_adr()->col(); } // 3d impl @@ -146,21 +146,21 @@ typename iterator_on_points_impl_<3, Exact>::coord iterator_on_points_impl_<3, Exact>::sli() const { - return static_cast<const Exact&>(*this).to_point().sli(); + return static_cast<const Exact*>(this)->impl_point_adr()->sli(); } template <typename Exact> typename iterator_on_points_impl_<3, Exact>::coord iterator_on_points_impl_<3, Exact>::row() const { - return static_cast<const Exact&>(*this).to_point().row(); + return static_cast<const Exact*>(this)->impl_point_adr()->row(); } template <typename Exact> typename iterator_on_points_impl_<3, Exact>::coord iterator_on_points_impl_<3, Exact>::col() const { - return static_cast<const Exact&>(*this).to_point().col(); + return static_cast<const Exact*>(this)->impl_point_adr()->col(); } # endif // ! OLN_INCLUDE_ONLY Index: oln/linear/convolution.hh --- oln/linear/convolution.hh (revision 960) +++ oln/linear/convolution.hh (working copy) @@ -80,8 +80,8 @@ V val = 0; for_all(q) { - oln_dpoint(I) dp = O - q.to_point(); - p_q = p.to_point() + dp; + oln_dpoint(I) dp = O - oln_point(I)(q); // FIXME: to_point + p_q = oln_point(I)(p) + dp; // FIXME: to_point if (f.has(p_q)) val += g(q) * f(p_q); // FIXME: f(p + (O - q)); } @@ -102,7 +102,7 @@ V val = 0; for (unsigned i = 0; i < w_win.size(); ++i) { - oln_point(I) q = p.to_point() + w_win.dp(i); + oln_point(I) q = oln_point(I)(p) + w_win.dp(i); // FIXME: to_point if (input.has(q)) val += w_win.w(i) * input(q); }
participants (1)
-
Thierry Geraud