
Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> fast iterator on image3b_b. * tests/core/fiter_point2d_b.cc: update test. * tests/core/fiter_point3d_b.cc: New test. * tests/core/Makefile.am: Update. * oln/core/2d/fast_iterator_2d.hh, * oln/core/2d/fast_iterator_2d_b.hh, * oln/core/3d/fast_iterator_3d.hh: clean code. * oln/core/3d/image3d_b.hh: add method to get the image array. * oln/core/3d/fast_iterator_3d_b.hh: New fast iterator. oln/core/2d/fast_iterator_2d.hh | 3 oln/core/2d/fast_iterator_2d_b.hh | 18 ++--- oln/core/3d/fast_iterator_3d.hh | 5 - oln/core/3d/fast_iterator_3d_b.hh | 134 ++++++++++++++++++++++++++++++++++++++ oln/core/3d/image3d_b.hh | 23 ++++++ tests/core/Makefile.am | 2 tests/core/fiter_point2d_b.cc | 2 tests/core/fiter_point3d_b.cc | 61 +++++++++++++++++ 8 files changed, 230 insertions(+), 18 deletions(-) Index: tests/core/fiter_point2d_b.cc --- tests/core/fiter_point2d_b.cc (revision 971) +++ tests/core/fiter_point2d_b.cc (working copy) @@ -34,7 +34,7 @@ { using namespace oln; - image2d_b<int> ima(2, 5, 2); + image2d_b<int> ima(50, 50, 2); image2d_b<int>::piter p(ima.points()); image2d_b<int>::fiter f(ima); Index: tests/core/fiter_point3d_b.cc --- tests/core/fiter_point3d_b.cc (revision 0) +++ tests/core/fiter_point3d_b.cc (revision 0) @@ -0,0 +1,61 @@ +// 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/3d/image3d_b.hh> + + +int +main() +{ + using namespace oln; + + image3d_b<int> ima(100, 100, 100, 2); + + image3d_b<int>::piter p(ima.points()); + image3d_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: tests/core/Makefile.am --- tests/core/Makefile.am (revision 971) +++ tests/core/Makefile.am (working copy) @@ -32,6 +32,7 @@ fiter_point3d \ fiter_point1d_b \ fiter_point2d_b \ + fiter_point3d_b \ neighb2d \ npoints \ point2d \ @@ -56,6 +57,7 @@ fiter_point3d_SOURCES = fiter_point3d.cc fiter_point1d_b_SOURCES = fiter_point1d_b.cc fiter_point2d_b_SOURCES = fiter_point2d_b.cc +fiter_point3d_b_SOURCES = fiter_point3d_b.cc neighb2d_SOURCES = neighb2d.cc npoints_SOURCES = npoints.cc point2d_SOURCES = point2d.cc Index: oln/core/2d/fast_iterator_2d.hh --- oln/core/2d/fast_iterator_2d.hh (revision 971) +++ oln/core/2d/fast_iterator_2d.hh (working copy) @@ -72,8 +72,7 @@ template <typename T> fast_iterator_2d<T>::fast_iterator_2d(image2d<T>& ima) { - this->start_ = ima.img_array().buffer() + - ima.img_array().imin() * ima.img_array().jmin() + ima.img_array().jmin(); + this->start_ = ima.img_array().buffer(); this->current_elt_ = this->start_; this->eoi_ = ima.img_array().buffer() + (ima.img_array().imax() + 1) * (ima.img_array().jmax() + 1); Index: oln/core/2d/fast_iterator_2d_b.hh --- oln/core/2d/fast_iterator_2d_b.hh (revision 971) +++ oln/core/2d/fast_iterator_2d_b.hh (working copy) @@ -18,7 +18,7 @@ // // 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 +// instantiate templates or use macros or inraw 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 @@ -53,7 +53,7 @@ typedef T value; }; - // Fast iterator for image in one dimension + // Fast iterator for image in two dimension template <typename T> class fast_iterator_2d_b : public internal::fast_iterator_base_< fast_iterator_2d_b<T> > @@ -68,7 +68,7 @@ protected: unsigned border_size_; - int line_offset_; + int row_offset_; value *eor_; // end of row }; @@ -76,22 +76,20 @@ 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()) + border_size_(ima.border()), row_offset_(ima.img_array().i_pad()) { this->start_ = ima.img_array().buffer() + - (this->border_size_) * this->line_offset_ + this->border_size_; + (this->border_size_) * this->row_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->row_offset_ + this->row_offset_ - this->border_size_; this->eoi_ = this->eor_ + - this->line_offset_ * (ima.img_array().imax() - this->border_size_); - - + this->row_offset_ * (ima.img_array().imax() - this->border_size_); } template <typename T> @@ -103,7 +101,7 @@ if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_) { this->current_elt_ += 2 * this->border_size_; - this->eor_ += this->line_offset_; + this->eor_ += this->row_offset_; } } Index: oln/core/3d/image3d_b.hh --- oln/core/3d/image3d_b.hh (revision 971) +++ oln/core/3d/image3d_b.hh (working copy) @@ -33,7 +33,7 @@ # include <oln/core/internal/image_base.hh> # include <oln/core/internal/utils.hh> # include <oln/core/3d/array3d.hh> - +# include <oln/core/3d/fast_iterator_3d_b.hh> namespace oln { @@ -65,6 +65,8 @@ typedef image3d_b<T> plain; typedef image3d_b<pl::value> skeleton; + + typedef fast_iterator_3d_b<value> fiter; }; @@ -86,6 +88,8 @@ typedef internal::plain_primitive_image_<current> super; typedef array3d_<T, int> array_t; public: + //FIXME (fast image concept??) + typedef typename vtypes< image3d_b<T> >::fiter fiter; stc_using(data); image3d_b(); @@ -94,6 +98,9 @@ image3d_b(unsigned nslis, unsigned nrows, unsigned ncols, unsigned border = 2); + array_t& img_array(); + const array_t& img_array() const; + bool impl_owns_(const point3d& p) const; bool impl_has_at(int sli, int row, int col) const; @@ -164,6 +171,20 @@ } template <typename T> + typename image3d_b<T>::array_t& + image3d_b<T>::img_array() + { + return this->data_->first; + } + + template <typename T> + const typename image3d_b<T>::array_t& + image3d_b<T>::img_array() const + { + return this->data_->first; + } + + template <typename T> bool image3d_b<T>::impl_owns_(const point3d& p) const { assert(this->has_data()); Index: oln/core/3d/fast_iterator_3d.hh --- oln/core/3d/fast_iterator_3d.hh (revision 971) +++ oln/core/3d/fast_iterator_3d.hh (working copy) @@ -71,10 +71,7 @@ template <typename T> fast_iterator_3d<T>::fast_iterator_3d(image3d<T>& ima) { - 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(); + this->start_ = ima.img_array().buffer(); this->current_elt_ = this->start_; Index: oln/core/3d/fast_iterator_3d_b.hh --- oln/core/3d/fast_iterator_3d_b.hh (revision 0) +++ oln/core/3d/fast_iterator_3d_b.hh (revision 0) @@ -0,0 +1,134 @@ +// 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 3 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 03111-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_3D_FAST_ITERATOR_3D_B_HH +# define OLN_CORE_3D_FAST_ITERATOR_3D_B_HH + +# include <cstddef> +# include <oln/core/internal/fast_iterator_base.hh> +# include <oln/core/3d/point3d.hh> + +namespace oln +{ + // Fwd decl. + template <typename T> class image3d_b; + template <typename T> class fast_iterator_3d_b; + + // Super type. + template <typename T> + struct super_trait_< fast_iterator_3d_b<T> > + { + typedef fast_iterator_3d_b<T> current; + typedef internal::fast_iterator_base_<current> ret; + }; + + // Virtual types. + template <typename T> + struct vtypes< fast_iterator_3d_b<T> > + { + typedef T value; + }; + + // Fast iterator for image in one dimension + template <typename T> + class fast_iterator_3d_b : + public internal::fast_iterator_base_< fast_iterator_3d_b<T> > + { + typedef fast_iterator_3d_b<T> current; + typedef internal::fast_iterator_base_<current> super; + public: + stc_using(value); + + fast_iterator_3d_b(image3d_b<T>& ima); + void impl_next(); + + protected: + unsigned border_size_; + int sli_offset_; + int row_offset_; + + value *eor_; // end of row + value *eos_; // end of slice + + }; + +# ifndef OLN_INCLUDE_ONLY + + template <typename T> + fast_iterator_3d_b<T>::fast_iterator_3d_b(image3d_b<T>& ima) : + border_size_(ima.border()), + sli_offset_(ima.img_array().i_pad()), + row_offset_(ima.img_array().j_pad()) + { + this->start_ = &ima(point3d(0, 0, 0)); + + this->current_elt_ = this->start_; + + this->eor_ = this->start_ + ima.ncols(); + + this->eos_ = ima.img_array().buffer() + + this->sli_offset_ * this->border_size_ + + this->row_offset_ * (ima.img_array().jlen() - 1 - this->border_size_) + + + ima.img_array().klen() - this->border_size_ ; + + this->eoi_ = ima.img_array().buffer() + + this->sli_offset_ * (ima.img_array().ilen() - 1 - this->border_size_) + + this->row_offset_ * (ima.img_array().jlen() - 1 - this->border_size_) + + + ima.img_array().klen() - this->border_size_ ; + } + + template <typename T> + void + fast_iterator_3d_b<T>::impl_next() + { + ++(this->current_elt_); + + if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_) + { + if (this->current_elt_ != this->eos_) // end of a sli + { + this->current_elt_ += 2 * this->border_size_; + this->eor_ += this->row_offset_; + } + else // end of a slice + { + this->eor_ += (2 * this->border_size_ + 1) * this->row_offset_; + + this->current_elt_ += 2 * this->border_size_ + + (2 * this->border_size_) * this->row_offset_; + + this->eos_ += this->sli_offset_; + } + } + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + +#endif // OLN_CORE_3D_FAST_ITERATOR_3D_B_HH