965: Add fast iterator for image with border in 1d or 2d.

Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Add fast iterator for image with border in 1d or 2d. * olena/tests/core/fiter_point1d_b.cc, * olena/tests/core/fiter_point2d_b.cc: New test. * olena/tests/core/Makefile.am: Update. * olena/oln/core/1d/fast_iterator_1d_b.hh: New fast_iterator for image1d_b. * olena/oln/core/2d/fast_iterator_2d_b.hh: New fast_iterator for image1d_b. * olena/oln/core/1d/fast_iterator_1d.hh, * olena/oln/core/2d/fast_iterator_2d.hh, * olena/oln/core/3d/fast_iterator_3d.hh: factorizing some codes * olena/oln/core/1d/image1d_b.hh, * olena/oln/core/2d/image2d_b.hh: add method to get the array associated with the image. * olena/oln/core/1d/image1d.hh, * olena/oln/core/2d/image2d.hh, * olena/oln/core/3d/image3d.hh: Change fiter type. * olena/oln/core/concept/fast_iterator.hh: factorizing some codes. * olena/oln/core/internal/fast_iterator_base.hh: New base class for fast iterator based on image with array. oln/core/1d/fast_iterator_1d.hh | 95 +++------------- oln/core/1d/fast_iterator_1d_b.hh | 93 +++++++++++++++ oln/core/1d/image1d.hh | 2 oln/core/1d/image1d_b.hh | 26 ++++ oln/core/2d/fast_iterator_2d.hh | 99 +++------------- oln/core/2d/fast_iterator_2d_b.hh | 114 +++++++++++++++++++ oln/core/2d/image2d.hh | 2 oln/core/2d/image2d_b.hh | 22 +++ oln/core/3d/fast_iterator_3d.hh | 98 +++------------- oln/core/3d/image3d.hh | 2 oln/core/concept/fast_iterator.hh | 2 oln/core/internal/fast_iterator_base.hh | 189 ++++++++++++++++++++++++++++++++ tests/core/Makefile.am | 4 tests/core/fiter_point1d_b.cc | 60 ++++++++++ tests/core/fiter_point2d_b.cc | 63 ++++++++++ 15 files changed, 633 insertions(+), 238 deletions(-) Index: olena/tests/core/fiter_point1d_b.cc --- olena/tests/core/fiter_point1d_b.cc (revision 0) +++ olena/tests/core/fiter_point1d_b.cc (revision 0) @@ -0,0 +1,60 @@ +// 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. + +#include <cassert> +#include <oln/core/1d/image1d_b.hh> + +int +main() +{ + using namespace oln; + + image1d_b<int> ima(50, 5); + + image1d_b<int>::piter p(ima.points()); + image1d_b<int>::fiter f(ima); + int i = 0; + + for_all(p) + ima(p) = i++; + + i = 0; + + for_all(f) + { + assert(*f == i ++); + *f = 5; + } + + for_all(p) + assert(ima(p) == 5); + + f.start(); + assert(f.is_valid()); + f.invalidate(); + assert(!f.is_valid()); +} Index: olena/tests/core/fiter_point2d_b.cc --- olena/tests/core/fiter_point2d_b.cc (revision 0) +++ olena/tests/core/fiter_point2d_b.cc (revision 0) @@ -0,0 +1,63 @@ +// 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. + +#include <cassert> +#include <oln/core/2d/image2d_b.hh> + + +int +main() +{ + using namespace oln; + + image2d_b<int> ima(2, 5, 2); + + image2d_b<int>::piter p(ima.points()); + image2d_b<int>::fiter f(ima); + int i = 0; + + for_all(p) + { + ima(p) = i++; + } + + i = 0; + + for_all(f) + { + assert(*f == i ++); + *f = 5; + } + + for_all(p) + assert(ima(p) == 5); + + f.start(); + assert(f.is_valid()); + f.invalidate(); + assert(!f.is_valid()); +} Index: olena/tests/core/Makefile.am --- olena/tests/core/Makefile.am (revision 964) +++ olena/tests/core/Makefile.am (working copy) @@ -30,6 +30,8 @@ fiter_point1d \ fiter_point2d \ fiter_point3d \ + fiter_point1d_b \ + fiter_point2d_b \ neighb2d \ npoints \ point2d \ @@ -52,6 +54,8 @@ fiter_point1d_SOURCES = fiter_point1d.cc fiter_point2d_SOURCES = fiter_point2d.cc fiter_point3d_SOURCES = fiter_point3d.cc +fiter_point1d_b_SOURCES = fiter_point1d_b.cc +fiter_point2d_b_SOURCES = fiter_point2d_b.cc neighb2d_SOURCES = neighb2d.cc npoints_SOURCES = npoints.cc point2d_SOURCES = point2d.cc Index: olena/oln/core/1d/image1d.hh --- olena/oln/core/1d/image1d.hh (revision 964) +++ olena/oln/core/1d/image1d.hh (working copy) @@ -62,7 +62,7 @@ typedef image1d<T> plain; typedef image1d<pl::value> skeleton; - typedef fast_iterator_1d<value, coord> fiter; + typedef fast_iterator_1d<value> fiter; }; Index: olena/oln/core/1d/image1d_b.hh --- olena/oln/core/1d/image1d_b.hh (revision 964) +++ olena/oln/core/1d/image1d_b.hh (working copy) @@ -32,6 +32,7 @@ # include <oln/core/internal/image_base.hh> # include <oln/core/internal/utils.hh> # include <oln/core/1d/array1d.hh> +# include <oln/core/1d/fast_iterator_1d_b.hh> namespace oln @@ -63,6 +64,8 @@ typedef image1d_b<T> plain; typedef image1d_b<pl::value> skeleton; + + typedef fast_iterator_1d_b<value> fiter; }; @@ -84,12 +87,17 @@ typedef internal::plain_primitive_image_<current> super; typedef array1d_<T, int> array_t; public: + //FIXME (fast image concept??) + typedef typename vtypes< image1d_b<T> >::fiter fiter; stc_using(data); image1d_b(); image1d_b(const box1d& b, unsigned border = 2); image1d_b(unsigned n, unsigned border = 2); + array_t& img_array(); + const array_t& img_array() const; + bool impl_owns_(const point1d& p) const; const T& impl_read(const point1d& p) const; @@ -135,7 +143,21 @@ this->data_ = new data(new array_t(- border, n - 1 + border), border, - box1d(0, n - 1)); + box1d(point1d(0), point1d(n - 1))); + } + + template <typename T> + typename image1d_b<T>::array_t& + image1d_b<T>::img_array() + { + return this->data_->first; + } + + template <typename T> + const typename image1d_b<T>::array_t& + image1d_b<T>::img_array() const + { + return this->data_->first; } template <typename T> @@ -201,7 +223,7 @@ { precondition(not target.has_data()); box1d b; - bool box_ok = init(b, with, dat); + bool box_ok = init5A(b, with, dat); postcondition(box_ok); unsigned border = 2; // FIXME: Use init! array1d_<T,int>* ptr = new array1d_<T,int>(b.pmin().ind() - border, Index: olena/oln/core/1d/fast_iterator_1d.hh --- olena/oln/core/1d/fast_iterator_1d.hh (revision 964) +++ olena/oln/core/1d/fast_iterator_1d.hh (working copy) @@ -29,109 +29,50 @@ #ifndef OLN_CORE_1D_FAST_ITERATOR_1D_HH # define OLN_CORE_1D_FAST_ITERATOR_1D_HH -# include <cassert> -# include <oln/core/concept/fast_iterator.hh> +# include <oln/core/internal/fast_iterator_base.hh> namespace oln { // Fwd decl. template <typename T> class image1d; - template <typename T, typename C> class fast_iterator_1d; + template <typename T> class fast_iterator_1d; // Super type. - template <typename T, typename C> - struct super_trait_< fast_iterator_1d<T, C> > + template <typename T> + struct super_trait_< fast_iterator_1d<T> > { - typedef fast_iterator_1d<T, C> current; - typedef Fast_Iterator<current> ret; + typedef fast_iterator_1d<T> current; + typedef internal::fast_iterator_without_b_<current> ret; }; // Virtual types. - template <typename T, typename C> - struct vtypes< fast_iterator_1d<T, C> > + template <typename T> + struct vtypes< fast_iterator_1d<T> > { typedef T value; }; // Fast iterator for image in one dimension - template <typename T, typename C> - class fast_iterator_1d : public Fast_Iterator< fast_iterator_1d<T, C> > + template <typename T> + class fast_iterator_1d : + public internal::fast_iterator_without_b_< fast_iterator_1d<T> > { - typedef fast_iterator_1d<T, C> current; - typedef Fast_Iterator<current> super; + typedef fast_iterator_1d<T> current; + typedef internal::fast_iterator_without_b_<current> super; public: - stc_using(value); fast_iterator_1d(image1d<T>& ima); - - void impl_start(); - void impl_next(); - void impl_invalidate(); - bool impl_is_valid() const; - - value& impl_dereference(); - const value& impl_dereference() const; - - protected: - T* start_; // buffer start - T* current_elt_; - T* eoi_; // buffer end; }; # ifndef OLN_INCLUDE_ONLY // initialize the fields start_ and eoi_, to image buffer start and end - template <typename T, typename C> - fast_iterator_1d<T, C>::fast_iterator_1d(image1d<T>& ima) - { - start_ = ima.img_array().buffer() + ima.img_array().imin(); - current_elt_ = start_; - eoi_ = ima.img_array().buffer() + ima.img_array().imax() + 1; - } - - template <typename T, typename C> - void - fast_iterator_1d<T, C>::impl_start() - { - current_elt_ = start_; - } - - template <typename T, typename C> - void - fast_iterator_1d<T, C>::impl_next() - { - assert(this->impl_is_valid()); - ++current_elt_; - } - - template <typename T, typename C> - void - fast_iterator_1d<T, C>::impl_invalidate() - { - current_elt_ = eoi_; - } - - template <typename T, typename C> - bool - fast_iterator_1d<T, C>::impl_is_valid() const - { - return current_elt_ != eoi_; - } - - template <typename T, typename C> - typename fast_iterator_1d<T, C>::value& - fast_iterator_1d<T, C>::impl_dereference() - { - assert(this->impl_is_valid()); - return *current_elt_; - } - - template <typename T, typename C> - const typename fast_iterator_1d<T, C>::value& - fast_iterator_1d<T, C>::impl_dereference() const + template <typename T> + fast_iterator_1d<T>::fast_iterator_1d(image1d<T>& ima) { - assert(this->impl_is_valid()); - return *current_elt_; + this->start_ = ima.img_array().buffer() + ima.img_array().imin(); + this->current_elt_ = this->start_; + this->eoi_ = ima.img_array().buffer() + ima.img_array().imax() + 1; } # endif // ! OLN_INCLUDE_ONLY Index: olena/oln/core/1d/fast_iterator_1d_b.hh --- olena/oln/core/1d/fast_iterator_1d_b.hh (revision 0) +++ olena/oln/core/1d/fast_iterator_1d_b.hh (revision 0) @@ -0,0 +1,93 @@ +// 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_1D_FAST_ITERATOR_1D_B_HH +# define OLN_CORE_1D_FAST_ITERATOR_1D_B_HH + +# include <oln/core/internal/fast_iterator_base.hh> + +namespace oln +{ + // Fwd decl. + template <typename T> class image1d_b; + template <typename T> class fast_iterator_1d_b; + + // Super type. + template <typename T> + struct super_trait_< fast_iterator_1d_b<T> > + { + typedef fast_iterator_1d_b<T> current; + typedef internal::fast_iterator_base_<current> ret; + }; + + // Virtual types. + template <typename T> + struct vtypes< fast_iterator_1d_b<T> > + { + typedef T value; + }; + + // Fast iterator for image in one dimension + template <typename T> + class fast_iterator_1d_b : + public internal::fast_iterator_base_< fast_iterator_1d_b<T> > + { + typedef fast_iterator_1d_b<T> current; + typedef internal::fast_iterator_base_<current> super; + public: + + fast_iterator_1d_b(image1d_b<T>& ima); + void impl_next(); + }; + +# ifndef OLN_INCLUDE_ONLY + + // initialize the fields start_ and eoi_, to image buffer start and end + template <typename T> + fast_iterator_1d_b<T>::fast_iterator_1d_b(image1d_b<T>& ima) + { + unsigned border = ima.border(); + + this->start_ = ima.img_array().buffer() + ima.img_array().imin() + border; + this->current_elt_ = this->start_; + this->eoi_ = ima.img_array().buffer() + ima.img_array().imax() - border + 1; + } + + template <typename T> + void + fast_iterator_1d_b<T>::impl_next() + { + ++(this->current_elt_); + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + +#endif // OLN_CORE_1D_FAST_ITERATOR_1D_B_HH + Index: olena/oln/core/2d/fast_iterator_2d.hh --- olena/oln/core/2d/fast_iterator_2d.hh (revision 964) +++ olena/oln/core/2d/fast_iterator_2d.hh (working copy) @@ -30,110 +30,53 @@ # define OLN_CORE_2D_FAST_ITERATOR_2D_HH # include <cassert> -# include <oln/core/concept/fast_iterator.hh> +# include <oln/core/internal/fast_iterator_base.hh> namespace oln { // Fwd decl. template <typename T> class image2d; - template <typename T, typename C> class fast_iterator_2d; + template <typename T> class fast_iterator_2d; // Super type. - template <typename T, typename C> - struct super_trait_< fast_iterator_2d<T, C> > + template <typename T> + struct super_trait_< fast_iterator_2d<T> > { - typedef fast_iterator_2d<T, C> current; - typedef Fast_Iterator<current> ret; + typedef fast_iterator_2d<T> current; + typedef internal::fast_iterator_without_b_<current> ret; }; // Virtual types. - template <typename T, typename C> - struct vtypes< fast_iterator_2d<T, C> > + template <typename T> + struct vtypes< fast_iterator_2d<T> > { typedef T value; }; // fast iterator for image2d - template <typename T, typename C> - class fast_iterator_2d : public Fast_Iterator< fast_iterator_2d<T, C> > + template <typename T> + class fast_iterator_2d : + public internal::fast_iterator_without_b_< fast_iterator_2d<T> > { - typedef fast_iterator_2d<T, C> current; - typedef Fast_Iterator<current> super; + typedef fast_iterator_2d<T> current; + typedef internal::fast_iterator_without_b_<current> super; public: - stc_using(value); - fast_iterator_2d(image2d<T>& ima); - void impl_start(); - void impl_next(); - void impl_invalidate(); - bool impl_is_valid() const; - - value& impl_dereference(); - const value& impl_dereference() const; - - protected: - T* start_; // buffer start - T* current_elt_; - T* eoi_; // buffer end; + fast_iterator_2d(image2d<T>& ima); }; # ifndef OLN_INCLUDE_ONLY // initialize the fields start_ and eoi_, to image buffer start and end - template <typename T, typename C> - fast_iterator_2d<T, C>::fast_iterator_2d(image2d<T>& ima) - { - start_ = ima.img_array().buffer() + ima.img_array().imin() * ima.img_array().jmin() + - ima.img_array().jmin(); - current_elt_ = start_; - eoi_ = ima.img_array().buffer() + (ima.img_array().imax() - ima.img_array().imin() + 1) * - (ima.img_array().jmax() - ima.img_array().imin() + 1); - } - - template <typename T, typename C> - void - fast_iterator_2d<T, C>::impl_start() - { - current_elt_ = start_; - } - - template <typename T, typename C> - void - fast_iterator_2d<T, C>::impl_next() - { - assert(this->impl_is_valid()); - ++current_elt_; - } - - template <typename T, typename C> - void - fast_iterator_2d<T, C>::impl_invalidate() - { - current_elt_ = eoi_; - } - - template <typename T, typename C> - bool - fast_iterator_2d<T, C>::impl_is_valid() const - { - return current_elt_ != eoi_; - } - - template <typename T, typename C> - typename fast_iterator_2d<T, C>::value& - fast_iterator_2d<T, C>::impl_dereference() - { - assert(this->impl_is_valid()); - return *current_elt_; - } - - template <typename T, typename C> - const typename fast_iterator_2d<T, C>::value& - fast_iterator_2d<T, C>::impl_dereference() const + template <typename T> + fast_iterator_2d<T>::fast_iterator_2d(image2d<T>& ima) { - assert(this->impl_is_valid()); - return *current_elt_; + this->start_ = ima.img_array().buffer() + + ima.img_array().imin() * ima.img_array().jmin() + ima.img_array().jmin(); + this->current_elt_ = this->start_; + this->eoi_ = ima.img_array().buffer() + (ima.img_array().imax() + 1) * + (ima.img_array().jmax() + 1); } # endif // ! OLN_INCLUDE_ONLY Index: olena/oln/core/2d/fast_iterator_2d_b.hh --- olena/oln/core/2d/fast_iterator_2d_b.hh (revision 0) +++ olena/oln/core/2d/fast_iterator_2d_b.hh (revision 0) @@ -0,0 +1,114 @@ +// 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_2D_FAST_ITERATOR_2D_B_HH +# define OLN_CORE_2D_FAST_ITERATOR_2D_B_HH + +# include <cstddef> +# include <oln/core/internal/fast_iterator_base.hh> + +namespace oln +{ + // Fwd decl. + template <typename T> class image2d_b; + template <typename T> class fast_iterator_2d_b; + + // Super type. + template <typename T> + struct super_trait_< fast_iterator_2d_b<T> > + { + typedef fast_iterator_2d_b<T> current; + typedef internal::fast_iterator_base_<current> ret; + }; + + // Virtual types. + template <typename T> + struct vtypes< fast_iterator_2d_b<T> > + { + typedef T value; + }; + + // Fast iterator for image in one dimension + template <typename T> + class fast_iterator_2d_b : + public internal::fast_iterator_base_< fast_iterator_2d_b<T> > + { + typedef fast_iterator_2d_b<T> current; + typedef internal::fast_iterator_base_<current> super; + public: + stc_using(value); + + fast_iterator_2d_b(image2d_b<T>& ima); + void impl_next(); + + protected: + unsigned border_size_; + int line_offset_; + value *eor_; // end of row + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename T> + fast_iterator_2d_b<T>::fast_iterator_2d_b(image2d_b<T>& ima) : + border_size_(ima.border()), line_offset_(ima.img_array().i_pad()) + { + this->start_ = ima.img_array().buffer() + + (this->border_size_) * this->line_offset_ + this->border_size_; + + this->current_elt_ = this->start_; + + + this->eor_ = ima.img_array().buffer() + + (this->border_size_) * this->line_offset_ + this->line_offset_ - + this->border_size_; + + this->eoi_ = this->eor_ + + this->line_offset_ * (ima.img_array().imax() - this->border_size_); + + + } + + template <typename T> + void + fast_iterator_2d_b<T>::impl_next() + { + ++(this->current_elt_); + + if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_) + { + this->current_elt_ += 2 * this->border_size_; + this->eor_ += this->line_offset_; + } + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + +#endif // OLN_CORE_2D_FAST_ITERATOR_2D_B_HH Index: olena/oln/core/2d/image2d.hh --- olena/oln/core/2d/image2d.hh (revision 964) +++ olena/oln/core/2d/image2d.hh (working copy) @@ -62,7 +62,7 @@ typedef image2d<T> plain; typedef image2d<pl::value> skeleton; - typedef fast_iterator_2d<value, coord> fiter; + typedef fast_iterator_2d<value> fiter; }; Index: olena/oln/core/2d/image2d_b.hh --- olena/oln/core/2d/image2d_b.hh (revision 964) +++ olena/oln/core/2d/image2d_b.hh (working copy) @@ -33,6 +33,7 @@ # include <oln/core/internal/image_base.hh> # include <oln/core/internal/utils.hh> # include <oln/core/2d/array2d.hh> +# include <oln/core/2d/fast_iterator_2d_b.hh> namespace oln @@ -65,6 +66,8 @@ typedef image2d_b<T> plain; typedef image2d_b<pl::value> skeleton; + + typedef fast_iterator_2d_b<value> fiter; }; @@ -86,12 +89,17 @@ typedef internal::plain_primitive_image_<current> super; typedef array2d_<T, int> array_t; public: + //FIXME (fast image concept??) + typedef typename vtypes< image2d_b<T> >::fiter fiter; stc_using(data); image2d_b(); image2d_b(const box2d& b, unsigned border = 2); image2d_b(unsigned nrows, unsigned ncols, unsigned border = 2); + array_t& img_array(); + const array_t& img_array() const; + bool impl_owns_(const point2d& p) const; bool impl_has_at(int row, int col) const; @@ -154,6 +162,20 @@ } template <typename T> + typename image2d_b<T>::array_t& + image2d_b<T>::img_array() + { + return this->data_->first; + } + + template <typename T> + const typename image2d_b<T>::array_t& + image2d_b<T>::img_array() const + { + return this->data_->first; + } + + template <typename T> bool image2d_b<T>::impl_owns_(const point2d& p) const { assert(this->has_data()); Index: olena/oln/core/3d/image3d.hh --- olena/oln/core/3d/image3d.hh (revision 964) +++ olena/oln/core/3d/image3d.hh (working copy) @@ -62,7 +62,7 @@ typedef image3d<T> plain; typedef image3d<pl::value> skeleton; - typedef fast_iterator_3d<value, coord> fiter; + typedef fast_iterator_3d<value> fiter; }; Index: olena/oln/core/3d/fast_iterator_3d.hh --- olena/oln/core/3d/fast_iterator_3d.hh (revision 964) +++ olena/oln/core/3d/fast_iterator_3d.hh (working copy) @@ -26,122 +26,64 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_2D_FAST_ITERATOR_3D_HH -# define OLN_CORE_2D_FAST_ITERATOR_3D_HH +#ifndef OLN_CORE_3D_FAST_ITERATOR_3D_HH +# define OLN_CORE_3D_FAST_ITERATOR_3D_HH # include <cassert> -# include <oln/core/concept/fast_iterator.hh> +# include <oln/core/internal/fast_iterator_base.hh> namespace oln { // Fwd decl. template <typename T> class image3d; - template <typename T, typename C> class fast_iterator_3d; + template <typename T> class fast_iterator_3d; // Super type. - template <typename T, typename C> - struct super_trait_< fast_iterator_3d<T, C> > + template <typename T> + struct super_trait_< fast_iterator_3d<T> > { - typedef fast_iterator_3d<T, C> current; - typedef Fast_Iterator<current> ret; + typedef fast_iterator_3d<T> current; + typedef internal::fast_iterator_without_b_<current> ret; }; // Virtual types. - template <typename T, typename C> - struct vtypes< fast_iterator_3d<T, C> > + template <typename T> + struct vtypes< fast_iterator_3d<T> > { typedef T value; }; // fast iterator for image3d - template <typename T, typename C> - class fast_iterator_3d : public Fast_Iterator< fast_iterator_3d<T, C> > + template <typename T> + class fast_iterator_3d : public internal::fast_iterator_without_b_< fast_iterator_3d<T> > { - typedef fast_iterator_3d<T, C> current; - typedef Fast_Iterator<current> super; + typedef fast_iterator_3d<T> current; + typedef internal::fast_iterator_without_b_<current> super; public: - stc_using(value); - fast_iterator_3d(image3d<T>& ima); - void impl_start(); - void impl_next(); - void impl_invalidate(); - bool impl_is_valid() const; - - value& impl_dereference(); - const value& impl_dereference() const; - - protected: - T* start_; // buffer start - T* current_elt_; - T* eoi_; // buffer end; + fast_iterator_3d(image3d<T>& ima); }; # ifndef OLN_INCLUDE_ONLY // initialize the fields start_ and eoi_, to image buffer start and end - template <typename T, typename C> - fast_iterator_3d<T, C>::fast_iterator_3d(image3d<T>& ima) + template <typename T> + fast_iterator_3d<T>::fast_iterator_3d(image3d<T>& ima) { - start_ = ima.img_array().buffer() + + this->start_ = ima.img_array().buffer() + ima.img_array().imin() * ima.img_array().jmin() * ima.img_array().kmin() + ima.img_array().jmin() * ima.img_array().kmin() + ima.img_array().kmin(); - current_elt_ = start_; + this->current_elt_ = this->start_; - eoi_ = ima.img_array().buffer() + + this->eoi_ = ima.img_array().buffer() + (ima.img_array().imax() - ima.img_array().imin() + 1) * (ima.img_array().jmax() - ima.img_array().imin() + 1) * (ima.img_array().kmax() - ima.img_array().kmin() + 1); } - template <typename T, typename C> - void - fast_iterator_3d<T, C>::impl_start() - { - current_elt_ = start_; - } - - template <typename T, typename C> - void - fast_iterator_3d<T, C>::impl_next() - { - assert(this->impl_is_valid()); - ++current_elt_; - } - - template <typename T, typename C> - void - fast_iterator_3d<T, C>::impl_invalidate() - { - current_elt_ = eoi_; - } - - template <typename T, typename C> - bool - fast_iterator_3d<T, C>::impl_is_valid() const - { - return current_elt_ != eoi_; - } - - template <typename T, typename C> - typename fast_iterator_3d<T, C>::value& - fast_iterator_3d<T, C>::impl_dereference() - { - assert(this->impl_is_valid()); - return *current_elt_; - } - - template <typename T, typename C> - const typename fast_iterator_3d<T, C>::value& - fast_iterator_3d<T, C>::impl_dereference() const - { - assert(this->impl_is_valid()); - return *current_elt_; - } - # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: olena/oln/core/concept/fast_iterator.hh --- olena/oln/core/concept/fast_iterator.hh (revision 964) +++ olena/oln/core/concept/fast_iterator.hh (working copy) @@ -62,6 +62,7 @@ typename Fast_Iterator<Exact>::value& Fast_Iterator<Exact>::operator* () { + precondition(exact(this)->impl_is_valid()); return exact(this)->impl_dereference(); } @@ -69,6 +70,7 @@ const typename Fast_Iterator<Exact>::value& Fast_Iterator<Exact>::operator* () const { + precondition(exact(this)->impl_is_valid()); return exact(this)->impl_dereference(); } Index: olena/oln/core/internal/fast_iterator_base.hh --- olena/oln/core/internal/fast_iterator_base.hh (revision 0) +++ olena/oln/core/internal/fast_iterator_base.hh (revision 0) @@ -0,0 +1,189 @@ +// 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_FAST_ITERATOR_BASE_HH +# define OLN_CORE_INTERNAL_FAST_ITERATOR_BASE_HH + +# include <oln/core/concept/fast_iterator.hh> + +namespace oln +{ + + // fast iterator on image based on a array + + // Fwd decl. + namespace internal { template <typename Exact> class fast_iterator_base_; } + + // Super type. + template <typename Exact> + struct super_trait_< internal::fast_iterator_base_<Exact> > + { + typedef Fast_Iterator<Exact> ret; + }; + + // Virtual types. + template <typename Exact> + struct vtypes< internal::fast_iterator_base_<Exact> > + { + typedef stc::abstract value; + }; + + namespace internal + { + // Fast iterator for image in one dimension + template <typename Exact> + class fast_iterator_base_ : public Fast_Iterator< Exact > + { + typedef fast_iterator_base_<Exact> current; + typedef Fast_Iterator<Exact> super; + public: + stc_using(value); + + void impl_start(); + void impl_next(); + void impl_invalidate(); + bool impl_is_valid() const; + + value& impl_dereference(); + const value& impl_dereference() const; + + protected: + fast_iterator_base_(); + + value* start_; // buffer start + value* current_elt_; + value* eoi_; // buffer end; + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + fast_iterator_base_<Exact>::fast_iterator_base_() + { + } + + template <typename Exact> + void + fast_iterator_base_<Exact>::impl_start() + { + this->current_elt_ = this->start_; + } + + template <typename Exact> + void + fast_iterator_base_<Exact>::impl_invalidate() + { + this->current_elt_ = this->eoi_; + } + + template <typename Exact> + bool + fast_iterator_base_<Exact>::impl_is_valid() const + { + return this->current_elt_ != this->eoi_; + } + + template <typename Exact> + typename fast_iterator_base_<Exact>::value& + fast_iterator_base_<Exact>::impl_dereference() + { + + return *(this->current_elt_); + } + + template <typename Exact> + const typename fast_iterator_base_<Exact>::value& + fast_iterator_base_<Exact>::impl_dereference() const + { + return *(this->current_elt_); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace internal + + + // fast iterator on array image without border + + // Fwd decl. + namespace internal + { + template <typename Exact> class fast_iterator_without_b_; + } + + // Super type. + template <typename Exact> + struct super_trait_< internal::fast_iterator_without_b_<Exact> > + { + typedef internal::fast_iterator_base_<Exact> ret; + }; + + // Virtual types. + template <typename Exact> + struct vtypes< internal::fast_iterator_without_b_<Exact> > + { + }; + + namespace internal + { + + template <typename Exact> + class fast_iterator_without_b_ : public internal::fast_iterator_base_<Exact> + { + typedef fast_iterator_without_b_<Exact> current; + typedef internal::fast_iterator_base_<Exact> super; + + public: + void impl_next(); + + protected: + fast_iterator_without_b_(); + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + fast_iterator_without_b_<Exact>::fast_iterator_without_b_() + { + } + + template <typename Exact> + void + fast_iterator_without_b_<Exact>::impl_next() + { + ++(this->current_elt_); + } + +# endif // ! OLN_INCLUDE_ONLY + + + } // end of namespace internal + +} // end of namespace oln + +#endif // OLN_CORE_1D_FAST_ITERATOR_1D_HH
participants (1)
-
Nicolas Ballas