
Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Add a new class encoded_image_ in order to factorize code for rle_image and sparse_image. rle_image and sparse_image are know based on std::vector. * tests/core/sparse_image.cc, * tests/core/rle_image.cc: Add new tests. * oln/core/rle/rle_image.hh, oln/core/rle/rle_psite.hh, * oln/core/rle/rle_pset.hh, oln/core/gen/sparse_encode.hh, * oln/core/gen/rle_pset.hh, oln/core/gen/rle_psite.hh, * oln/core/encode/sparse_encode.hh, * oln/core/sparse/sparse_image.hh: Remove. * oln/core/gen/rle_image.hh: rle_image is an encoded_image_. * oln/core/gen/rle_encode.hh: Header inclusion modifcation. * oln/core/gen/sparse_image.hh: sparse_image is an encoded_image, and it is based on a std::vector. * oln/core/internal/encoded_image.hh: New. * oln/core/internal/encoded_image_psite.hh: New. * oln/core/internal/encoded_image_pset.hh: New.. oln/core/gen/rle_encode.hh | 6 oln/core/gen/rle_image.hh | 45 -- oln/core/gen/sparse_encode.hh | 95 ++++++ oln/core/gen/sparse_image.hh | 138 ++++++++ oln/core/internal/encoded_image.hh | 108 ++++++ oln/core/internal/encoded_image_pset.hh | 488 +++++++++++++++++++++++++++++++ oln/core/internal/encoded_image_psite.hh | 83 +++++ tests/core/rle_image.cc | 27 + tests/core/sparse_image.cc | 51 ++- 9 files changed, 983 insertions(+), 58 deletions(-) Index: tests/core/sparse_image.cc --- tests/core/sparse_image.cc (revision 949) +++ tests/core/sparse_image.cc (working copy) @@ -1,20 +1,41 @@ -#include <iostream> -#include <oln/core/rle/rle_psite.hh> #include <oln/core/2d/image2d.hh> +#include <oln/core/gen/sparse_image.hh> +#include <oln/core/gen/sparse_encode.hh> #include <oln/debug/print.hh> -#include <oln/core/rle/rle_pset.hh> -#include <oln/core/sparse/sparse_image.hh> -#include <oln/core/encode/sparse_encode.hh> + + + +#include <iostream> + + +template <typename Pset> +void test(const Pset& my_set) +{ + typename Pset::piter run (my_set); + for (run.start(); run.is_valid(); run.next()) + ; + // std::cout << run << std::endl; + + // std::cout << "Reverse" << std::endl; + typename Pset::bkd_piter run2 (my_set); + + for (run2.start(); run2.is_valid(); run2.next()) + ; + // std::cout << run2 << std::endl; +} int main() { oln::point2d p(0,1), q(2,2), r(3, 0); - oln::image2d<int> ima2d (1, 5); + oln::internal::enc_image_pset_<oln::point2d> my_set; oln::sparse_image<oln::point2d, int> sparse; oln::sparse_image<oln::point2d, int> sparse2; - ima2d(oln::point2d(0, 4)) = 5; + + my_set.insert(p, 5); + my_set.insert(q, 8); + test(my_set); std::vector<int> values; int a =5; @@ -23,10 +44,24 @@ values.push_back(a); a = 42; values.push_back(a); - sparse.insert(q, 3, values); +// oln::debug::print(sparse); +// std::cout << std::endl; + + oln::image2d<int> ima2d (1, 5); + + + + ima2d(oln::point2d(0, 4)) = 5; + ima2d(oln::point2d(0, 3)) = 2; + +// oln::debug::print(ima2d); + sparse2 = sparse_encode(ima2d); +// oln::debug::print(sparse2); +// std::cout << std::endl; + return 0; } Index: tests/core/rle_image.cc --- tests/core/rle_image.cc (revision 949) +++ tests/core/rle_image.cc (working copy) @@ -1,28 +1,29 @@ #include <iostream> #include <oln/core/2d/image2d.hh> -#include <oln/core/gen/rle_psite.hh> + #include <oln/core/gen/rle_image.hh> #include <oln/debug/print.hh> -#include <oln/core/gen/rle_pset.hh> #include <oln/core/gen/rle_encode.hh> -template <typename P> -void test(const oln::rle_pset<P>& my_set) +template <typename Pset> +void test(const Pset& my_set) { - typename oln::rle_pset<P>::piter run (my_set); + typename Pset::piter run (my_set); for (run.start(); run.is_valid(); run.next()) - ; + /*std::cout << run << std::endl*/; + + // std::cout << "Reverse" << std::endl; - typename oln::rle_pset<P>::bkd_piter run2 (my_set); + typename Pset::bkd_piter run2 (my_set); for (run2.start(); run2.is_valid(); run2.next()) - ; + /*std::cout << run2 << std::endl*/; } int main() { oln::point2d p(0,1), q(2,2), r(3, 0); - oln::rle_pset<oln::point2d> my_set; + oln::internal::enc_image_pset_<oln::point2d> my_set; oln::rle_image<oln::point2d, int> rle; oln::rle_image<oln::point2d, int> rle2; @@ -33,10 +34,18 @@ rle.insert(p, 5, 4); rle.insert(q, 8, 9); +// oln::debug::print(rle); +// std::cout << std::endl; + oln::image2d<int> ima2d (1, 5); ima2d(oln::point2d(0, 4)) = 5; +// oln::debug::print(ima2d); + rle2 = rle_encode(ima2d); +// oln::debug::print(rle2); +// std::cout << std::endl; + return 0; } Index: oln/core/gen/sparse_encode.hh --- oln/core/gen/sparse_encode.hh (revision 0) +++ oln/core/gen/sparse_encode.hh (revision 0) @@ -0,0 +1,95 @@ +// Copyright (C) 2007 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 OLN_CORE_GEN_SPARSE_ENCODE_HH +# define OLN_CORE_GEN_SPARSE_ENCODE_HH + +# include <oln/core/concept/image.hh> + +# include <oln/core/gen/sparse_image.hh> + +# include <vector> + +namespace oln +{ + + /*! + ** encode a generic image to a sparse image format + ** + ** @param input an Image + ** + ** @return a sparse image + */ + template <typename I> + sparse_image<typename I::point, typename I::value> + sparse_encode(const Image<I>& input) + { + sparse_image<typename I::point, typename I::value> output; + typename I::piter p(input.points()); + unsigned len = 1; + /// old point first dim coordinate + typename I::coord old = 1; + /// range pointstart + typename I::point rstart; + /// range value + std::vector<typename I::value> values; + + p.start(); + if (!p.is_valid()) + return output; + + rstart = p; + + // FIXME: is it generall ? + old = (p.to_point())[0]; + values.push_back(input(p)); + p.next(); + while (p.is_valid()) + { + if ((p.to_point())[0] - 1 == old) + { + ++len; + values.push_back(input(p)); + } + else + { + output.insert(rstart, len, values); + rstart = p; + len = 1; + values.clear(); + values.push_back(input(p)); + } + old = (p.to_point())[0]; + p.next(); + } + output.insert(rstart, len, values); + return output; + } +} + +#endif // !OLN_CORE_ENCODE_SPARSE_ENCODE_HH Index: oln/core/gen/rle_image.hh --- oln/core/gen/rle_image.hh (revision 949) +++ oln/core/gen/rle_image.hh (working copy) @@ -30,9 +30,7 @@ # include <vector> -# include <oln/core/internal/image_base.hh> -# include <oln/core/gen/rle_psite.hh> -# include <oln/core/gen/rle_pset.hh> +# include <oln/core/internal/encoded_image.hh> @@ -47,7 +45,7 @@ struct super_trait_< rle_image<P, T> > { typedef rle_image<P, T> current; - typedef internal::primitive_image_<current> ret; + typedef internal::encoded_image_<current> ret; }; // Virtual types @@ -61,29 +59,20 @@ typedef P point; typedef typename P::coord coord; - typedef rle_psite<P> psite; + typedef typename vtypes< internal::encoded_image_< rle_image<P, T> > >::pset pset__; - typedef rle_pset<point> pset; - - typedef mlc::none plain; - - typedef std::pair< pset, std::vector< value > > data; + typedef std::pair< pset__, std::vector< value > > data; }; - /* - ** \class rle_image - ** \brief rle image (use a pair of point range and value as representation) - ** - */ + // rle_image template < typename P, typename T> - class rle_image : public internal::primitive_image_< rle_image<P, T> > + class rle_image : public internal::encoded_image_< rle_image<P, T> > { typedef rle_image<P, T> current; - typedef internal::primitive_image_< rle_image<P, T> > super; + typedef internal::encoded_image_<current> super; public: stc_using(pset); - stc_using(box); stc_using(point); stc_using(value); stc_using(rvalue); @@ -93,10 +82,6 @@ rle_image(); - - const pset& impl_points() const; - - bool impl_owns_(const psite& p) const; void insert(const point& p, unsigned len, value val); rvalue impl_read(const psite& p) const; lvalue impl_read_write(const psite& p); @@ -112,22 +97,6 @@ } template <typename P, typename T> - const typename rle_image<P, T>::pset& - rle_image<P, T>::impl_points() const - { - assert(this->has_data()); - return this->data_->first; - } - - template <typename P, typename T> - bool - rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const - { - assert(this->has_data()); - return this->data_->first.has(p.start_); - } - - template <typename P, typename T> void rle_image<P, T>::insert(const typename rle_image<P, T>::point& p, unsigned len, rle_image<P, T>::value val) Index: oln/core/gen/rle_encode.hh --- oln/core/gen/rle_encode.hh (revision 949) +++ oln/core/gen/rle_encode.hh (working copy) @@ -26,8 +26,8 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_ENCODE_RLE_ENCODE_HH -# define OLN_CORE_ENCODE_RLE_ENCODE_HH +#ifndef OLN_CORE_GEN_RLE_ENCODE_HH +# define OLN_CORE_GEN_RLE_ENCODE_HH # include <oln/core/concept/image.hh> @@ -81,4 +81,4 @@ } } // end of namespace oln -#endif /* !OLN_CORE_ENCODE_RLE_ENCODE_HH */ +#endif /* !OLN_CORE_GEN_RLE_ENCODE_HH */ Index: oln/core/gen/sparse_image.hh --- oln/core/gen/sparse_image.hh (revision 0) +++ oln/core/gen/sparse_image.hh (revision 0) @@ -0,0 +1,138 @@ +// Copyright (C) 2007 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 OLN_CORE_GEN_SPARSE_IMAGE_HH +# define OLN_CORE_GEN_SPARSE_IMAGE_HH + + +# include <vector> + +# include <oln/core/internal/encoded_image.hh> + + + +namespace oln +{ + // Fwd decl. + template <typename P, typename T> + struct sparse_image; + + // Super type. + template <typename P, typename T> + struct super_trait_< sparse_image<P, T> > + { + typedef sparse_image<P, T> current; + typedef internal::encoded_image_<current> ret; + }; + + // Virtual types + template <typename P, typename T> + struct vtypes< sparse_image<P, T> > + { + typedef T value; + typedef const T& rvalue; + typedef T& lvalue; + + typedef P point; + typedef typename P::coord coord; + + typedef typename vtypes< internal::encoded_image_< sparse_image<P, T> > >::pset pset__; + + typedef std::pair< pset__, std::vector <std::vector<value> > > data; + }; + + // sparse_image class + template < typename P, typename T> + class sparse_image : public internal::encoded_image_< sparse_image<P, T> > + { + typedef sparse_image<P, T> current; + typedef internal::encoded_image_< current > super; + + public: + stc_using(pset); + stc_using(point); + stc_using(value); + stc_using(rvalue); + stc_using(lvalue); + stc_using(psite); + stc_using(data); + + sparse_image(); + + void insert(const point& p, unsigned len, const std::vector<value>& val); + rvalue impl_read(const psite& p) const; + lvalue impl_read_write(const psite& p); + + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename P, typename T> + sparse_image<P, T>::sparse_image() + { + this->data_ = new data; + } + + template <typename P, typename T> + void + sparse_image<P, T>::insert(const point& p, unsigned len, + const std::vector<typename sparse_image<P, T>::value>& val) + { + assert(this->has_data()); + this->data_->first.insert(p, len); + this->data_->second.push_back(val); + } + + template <typename P, typename T> + typename sparse_image<P, T>::rvalue + sparse_image<P, T>::impl_read(const sparse_image<P, T>::psite& ps) const + { + assert(this->has_data() && ps.pset_pos_ < this->data_->second.size() && + ps.index_ < this->data_->second[ps.pset_pos_].size()); + + return this->data_->second[ps.pset_pos_][ps.index_]; + } + + template <typename P, typename T> + typename sparse_image<P, T>::lvalue + sparse_image<P, T>::impl_read_write(const sparse_image<P, T>::psite& ps) + { + assert(this->has_data() && ps.pset_pos_ < this->data_->second.size() && + ps.index_ < this->data_->second[ps.pset_pos_].size()); + + return this->data_->second[ps.pset_pos_][ps.index_]; + } + +# endif // ! OLN_INCLUDE_ONLY + + +} // end of namespace oln + +#endif // ! OLN_CORE_GEN_SPARSE_IMAGE_HH + Index: oln/core/internal/encoded_image.hh --- oln/core/internal/encoded_image.hh (revision 0) +++ oln/core/internal/encoded_image.hh (revision 0) @@ -0,0 +1,108 @@ +// Copyright (C) 2007 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 OLN_CORE_INTERNAL_ENCODED_IMAGE_HH +# define OLN_CORE_INTERNAL_ENCODED_IMAGE_HH + +# include <vector> + +# include <oln/core/internal/image_base.hh> +# include <oln/core/internal/encoded_image_psite.hh> +# include <oln/core/internal/encoded_image_pset.hh> + +namespace oln +{ + // Fwd decl. + namespace internal { template <typename Exact> struct encoded_image_; } + + // Super type. + template <typename Exact> + struct super_trait_< internal::encoded_image_<Exact> > + { + typedef internal::primitive_image_<Exact> ret; + }; + + // Virtual types + template <typename Exact> + struct vtypes< internal::encoded_image_<Exact> > + { + typedef stc_deferred(point) point__; + typedef internal::enc_image_psite_<point__> psite; + typedef internal::enc_image_pset_<point__> pset; + typedef mlc::none plain; + }; + + + namespace internal + { + // encoded_image_ + template <typename Exact> + class encoded_image_ : public primitive_image_< Exact > + { + typedef encoded_image_<Exact> current; + typedef primitive_image_< Exact > super; + public: + stc_using(pset); + stc_using(psite); + stc_using(data); + + const pset& impl_points() const; + bool impl_owns_(const psite& p) const; + protected: + encoded_image_(); + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + encoded_image_<Exact>::encoded_image_() + { + } + + template <typename Exact> + const typename encoded_image_<Exact>::pset& + encoded_image_<Exact>::impl_points() const + { + assert(this->has_data()); + return this->data_->first; + } + + template <typename Exact> + bool + encoded_image_<Exact>::impl_owns_(const typename encoded_image_<Exact>::psite& p) const + { + assert(this->has_data()); + return this->data_->first.has(p.start_); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace internal +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_ENCODED_IMAGE__HH Index: oln/core/internal/encoded_image_psite.hh --- oln/core/internal/encoded_image_psite.hh (revision 0) +++ oln/core/internal/encoded_image_psite.hh (revision 0) @@ -0,0 +1,83 @@ +// Copyright (C) 2007 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 OLN_CORE_INTERNAL_ENCODED_IMAGE_PSITE_HH +# define OLN_CORE_INTERNAL_ENCODED_IMAGE_PSITE_HH + + +namespace oln +{ + + namespace internal + { + + // psite for encoded images + + template <typename P> + struct enc_image_psite_ + { + enc_image_psite_(); + + P to_point() const; + operator P () const; + + P start_; + unsigned index_; + unsigned pset_pos_; + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename P> + enc_image_psite_<P>::enc_image_psite_() + { + } + + 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(); + } + +# endif /* !OLN_INCLUDE_ONLY */ + + } // end of namespace internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_ENCODED_IMAGE_PSITE_HH Index: oln/core/internal/encoded_image_pset.hh --- oln/core/internal/encoded_image_pset.hh (revision 0) +++ oln/core/internal/encoded_image_pset.hh (revision 0) @@ -0,0 +1,488 @@ +// Copyright (C) 2007 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 OLN_CORE_INTERNAL_ENCODED_IMAGE_PSET_HH +# define OLN_CORE_INTERNAL_ENCODED_IMAGE_PSET_HH + +# include <vector> +# include <utility> + +# include <oln/core/internal/point_set_base.hh> +# include <oln/core/internal/iterator_on_points_base.hh> +# include <oln/core/gen/fbbox.hh> +# include <oln/core/internal/encoded_image_psite.hh> + +namespace oln +{ + + // Forwards declaration + namespace internal + { + template <typename P> struct enc_image_pset_; + template <typename Exact> struct enc_image_pset_piter_; + template <typename P> struct enc_image_pset_fwd_piter_; + template <typename P> struct enc_image_pset_bkd_piter_; + } + + // Super type. + template <typename P> + struct super_trait_< internal::enc_image_pset_<P> > + { + typedef internal::enc_image_pset_<P> current; + typedef internal::point_set_base_<current> ret; + }; + + // Vtypes + template <typename P> + struct vtypes< internal::enc_image_pset_<P> > + { + typedef P point; + + typedef typename oln::internal::f_point_to_box_< P >::ret box; + typedef internal::enc_image_pset_fwd_piter_<P> fwd_piter; + typedef internal::enc_image_pset_bkd_piter_<P> bkd_piter; + }; + + namespace internal + { + + // pset for encoded image + template <typename P> + class enc_image_pset_ : public point_set_base_<enc_image_pset_ <P> > + { + typedef enc_image_pset_<P> current; + typedef point_set_base_< current > super; + + public: + stc_using(point); + stc_using(box); + + typedef std::vector<std::pair<point, unsigned> > std_container; + + enc_image_pset_(); + + unsigned impl_npoints() const; + const box& impl_bbox() const; + void insert(const P& p, unsigned len); + bool impl_has(const P& p) const; + const std_container& con() const; + + unsigned range_len_(const P& range_len_) const; + + protected: + unsigned npts; + + std_container con_; // FIXME: Add a &. + fbbox_<point> fb_; + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename P> + enc_image_pset_<P>::enc_image_pset_() : npts(0) + { + } + + + template <typename P> + unsigned + enc_image_pset_<P>::impl_npoints() const + { + return npts; + } + + template <typename P> + void + enc_image_pset_<P>::insert(const P& p, unsigned len) + { + point pend; + typename std_container::value_type elt (p, len); + + this->con_.push_back(elt); + + //update bbox + fb_.take(p); + pend = p; + pend[0] += len - 1; + fb_.take(pend); + // update size + npts += len; + } + + template <typename P> + const typename enc_image_pset_<P>::box& + enc_image_pset_<P>::impl_bbox() const + { + return fb_.box(); + } + + template <typename P> + bool + enc_image_pset_<P>::impl_has(const P& p) const + { + typename std_container::const_iterator irun; + + for (irun = this->con_.begin(); irun != this->con_.end(); ++irun) + { + if (irun->first == p) + return true; + } + return false; + } + + template <typename P> + const typename enc_image_pset_<P>::std_container& + enc_image_pset_<P>::con() const + { + return this->con_; + } + + template <typename P> + unsigned + enc_image_pset_<P>::range_len_(const P& range_start) const + { + typename std_container::const_iterator irun; + + for (irun = this->con_.begin(); irun != this->con_.end(); ++irun) + { + if (irun->first == range_start) + return irun->second; + } + assert(irun != this->con_.end()); + return (irun->second); + } + +# endif // !OLN_INCLUDE_ONLY + + } // end of namespace internal + + // end of enc_image_pset_ class + + + + + + // iterators for class internal::enc_image_pset_<P> + // base class for factorizing code + + // Super type + template <typename Exact> + struct super_trait_< internal::enc_image_pset_piter_<Exact> > + { + typedef internal::enc_image_pset_piter_<Exact> current; + typedef internal::iterator_on_points_base_<Exact> ret; + }; + + + // Virtual types + template <typename Exact> + struct vtypes< internal::enc_image_pset_piter_<Exact> > + { + }; + + namespace internal + { + // class enc_image_pset__iterator_ + template <typename Exact> + class enc_image_pset_piter_ : public iterator_on_points_base_< Exact > + { + typedef iterator_on_points_base_< Exact > super; + typedef enc_image_pset_piter_<Exact> current; + public: + stc_using(point); + 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 + + protected: + enc_image_pset_piter_(const enc_image_pset_<point>& con); + + const typename enc_image_pset_<point>::std_container& con_; + + point p_; + enc_image_psite_<point> ps_; + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + enc_image_pset_piter_<Exact>::enc_image_pset_piter_(const enc_image_pset_<typename enc_image_pset_piter_<Exact>::point>& cont) : + con_(cont.con()) + { + } + + template <typename Exact> + const enc_image_psite_<typename enc_image_pset_piter_<Exact>::point>& + enc_image_pset_piter_<Exact>::impl_to_psite() const + { + return ps_; + } + + 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(); + } + + template <typename Exact> + const enc_image_psite_<typename enc_image_pset_piter_<Exact>::point>* + enc_image_pset_piter_<Exact>::impl_psite_adr() const + { + return &ps_; + } + + template <typename Exact> + const typename enc_image_pset_piter_<Exact>::point* + enc_image_pset_piter_<Exact>::impl_point_adr() const + { + return &p_; + } + // end of class enc_image_pset__iterator_ + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace internal + + + + + + // Super type. + template <typename P> + struct super_trait_< internal::enc_image_pset_fwd_piter_<P> > + { + typedef internal::enc_image_pset_fwd_piter_<P> current; + typedef internal::enc_image_pset_piter_<current> ret; + }; + + // Virtual types + template <typename P> + struct vtypes< internal::enc_image_pset_fwd_piter_<P> > + { + typedef P point; + }; + + namespace internal + { + // class enc_image_pset__fwd_iterator_ + template <typename P> + class enc_image_pset_fwd_piter_ : public enc_image_pset_piter_<enc_image_pset_fwd_piter_<P> > + { + typedef enc_image_pset_piter_< enc_image_pset_fwd_piter_<P> > super; + typedef enc_image_pset_fwd_piter_<P> current; + public: + stc_using(point); + + enc_image_pset_fwd_piter_(const enc_image_pset_<P>& con); + + void impl_start(); + void impl_next(); + void impl_invalidate(); + bool impl_is_valid() const; + + protected: + typename enc_image_pset_<point>::std_container::const_iterator it_; + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename P> + enc_image_pset_fwd_piter_<P>::enc_image_pset_fwd_piter_(const enc_image_pset_<P>& cont) : + super(cont) + { + this->it_ = this->con_.end(); + this->ps_.pset_pos_ = this->con_.size(); + } + + template <typename P> + void + enc_image_pset_fwd_piter_<P>::impl_start() + { + this->it_ = this->con_.begin(); // FIXME: Test if (this->it_ != this->con_.end())... + this->ps_.start_ = this->it_->first; + this->ps_.index_ = 0; + this->ps_.pset_pos_ = 0; + this->p_ = this->ps_.start_; + } + + template <typename P> + void + enc_image_pset_fwd_piter_<P>::impl_next() + { + precondition(this->is_valid()); + + ++this->ps_.index_; + + if (this->ps_.index_ >= this->it_->second) + { + ++this->it_; + ++this->ps_.pset_pos_; + this->ps_.start_ = this->it_->first; + this->ps_.index_ = 0; + } + this->p_ = this->ps_.start_; + this->p_[0] += this->ps_.index_; + } + + template <typename P> + void + enc_image_pset_fwd_piter_<P>::impl_invalidate() + { + this->it_ = this->con_.end(); + this->ps_.pset_pos_ = this->con_.size(); + } + + template <typename P> + bool + enc_image_pset_fwd_piter_<P>::impl_is_valid() const + { + return this->it_ != this->con_.end(); + } +# endif // ! OLN_INCLUDE_ONLY + + // end of class enc_image_pset__fwd_iterator_ + + } // end of namespace internal + + + + + + // Super type. + template <typename P> + struct super_trait_< internal::enc_image_pset_bkd_piter_<P> > + { + typedef internal::enc_image_pset_bkd_piter_<P> current; + typedef internal::enc_image_pset_piter_<current> ret; + }; + + // Virtual type + template <typename P> + struct vtypes< internal::enc_image_pset_bkd_piter_<P> > + { + typedef P point; + }; + + namespace internal + { + // enc_image_pset_bkd_piter_ + template <typename P> + class enc_image_pset_bkd_piter_ : public enc_image_pset_piter_<enc_image_pset_bkd_piter_<P> > + { + typedef enc_image_pset_piter_< enc_image_pset_bkd_piter_<P> > super; + typedef enc_image_pset_bkd_piter_<P> current; + public: + stc_using(point); + + enc_image_pset_bkd_piter_(const enc_image_pset_<P>& con); + + void impl_start(); + void impl_next(); + void impl_invalidate(); + bool impl_is_valid() const; + + protected: + typename enc_image_pset_<point>::std_container::const_reverse_iterator it_; + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename P> + enc_image_pset_bkd_piter_<P>::enc_image_pset_bkd_piter_(const enc_image_pset_<P>& cont) : + super(cont) + { + this->it_ = this->con_.rend(); + this->ps_.pset_pos_ = this->con_.size(); + } + + template <typename P> + void + enc_image_pset_bkd_piter_<P>::impl_start() + { + this->it_ = this->con_.rbegin(); // FIXME: Test if (this->it_ != this->con_.rend())... + this->ps_.start_ = this->it_->first; + this->ps_.index_ = this->it_->second - 1; + this->ps_.pset_pos_ = this->con_.size() - 1; + this->p_ = this->ps_.start_; + this->p_[0] += this->ps_.index_; + } + + template <typename P> + void + enc_image_pset_bkd_piter_<P>::impl_next() + { + precondition(this->is_valid()); + + --(this->ps_.index_); + + if (this->ps_.index_ + 1 == 0) + { + ++this->it_; + --this->ps_.pset_pos_; + this->ps_.start_ = this->it_->first; + this->ps_.index_ = this->it_->second - 1; + } + this->p_ = this->ps_.start_; + this->p_[0] += this->ps_.index_; + } + + template <typename P> + void + enc_image_pset_bkd_piter_<P>::impl_invalidate() + { + this->it_ = this->con_.rend(); + this->ps_.pset_pos_ = this->con_.size(); + } + + template <typename P> + bool + enc_image_pset_bkd_piter_<P>::impl_is_valid() const + { + return this->it_ != this->con_.rend(); + } +# endif // ! OLN_INCLUDE_ONLY + + // end of class enc_image_pset_bkd_piter_ + + } // end of namespace internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_ENCODED_IMAGE_PSET_HH