1024: Repair lineary pixel iterator.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Repair lineary pixel iterator. * mln/core/pixter2d_b.hh: Adapt pixter2d_b to the new pixel iterator hierachy. * mln/core/internal/pixel_iterator_base.hh: Fix dead code. * mln/core/internal/lineary_pixel_iterator_base.hh: New factorization class. internal/lineary_pixel_iterator_base.hh | 109 ++++++++++++++++++++++++++++++++ internal/pixel_iterator_base.hh | 101 +---------------------------- pixter2d_b.hh | 31 +++++---- 3 files changed, 131 insertions(+), 110 deletions(-) Index: mln/core/pixter2d_b.hh --- mln/core/pixter2d_b.hh (revision 1023) +++ mln/core/pixter2d_b.hh (working copy) @@ -28,7 +28,7 @@ #ifndef MLN_CORE_PIXTER2D_B_HH # define MLN_CORE_PIXTER2D_B_HH -# include <mln/core/internal/pixel_iterator_base.hh> +# include <mln/core/internal/lineary_pixel_iterator_base.hh> # include <mln/core/point2d.hh> # include <iostream> @@ -49,8 +49,9 @@ template <typename T> class fwd_pixter2d_b : - public internal::pixel_iterator_base_< fwd_pixter2d_b<T>, image2d_b<T> > + public internal::lineary_pixel_iterator_base_<image2d_b<T>, fwd_pixter2d_b<T> > { + typedef internal::lineary_pixel_iterator_base_<image2d_b<T>, fwd_pixter2d_b<T> > super; public: /// Image pixel value type. typedef mln_value(image2d_b<T>) value; @@ -59,37 +60,41 @@ * * \param[in] ima Image to iterate. */ - fwd_pixter2d_b(image2d_b<T>& ima); - /// Move the iterator to the next elements + fwd_pixter2d_b(image2d_b<T>& image); + /// Move the iterator on the next element. void next_(); private: + /// Size of the image border. unsigned border_size_; + /// Row offset. unsigned row_offset_; + /// End of a row. value *eor_; }; #ifndef MLN_INCLUDE_ONLY template <typename T> - fwd_pixter2d_b<T>::fwd_pixter2d_b(image2d_b<T>& ima) : - border_size_(ima.border()), - row_offset_((ima.domain().pmax()[1] - ima.domain().pmin()[1]) + fwd_pixter2d_b<T>::fwd_pixter2d_b(image2d_b<T>& image) : + super(image), + border_size_(image.border()), + row_offset_((image.domain().pmax()[1] - image.domain().pmin()[1]) + 2 * border_size_ + 1) { - this->start_ = &ima(ima.domain().pmin()); - this->eor_ = &ima(make::point2d(ima.domain().pmin()[0], ima.domain().pmax()[1])) + 1; - this->eoi_ = &ima(ima.domain().pmax()) + 1; + this->start_ = &image(image.domain().pmin()); + this->eor_ = &image(make::point2d(image.domain().pmin()[0], image.domain().pmax()[1])) + 1; + this->eoi_ = &image(image.domain().pmax()) + 1; } template <typename T> void fwd_pixter2d_b<T>::next_() { - ++(this->current_); + ++(this->value_ptr_); - if (this->current_ == this->eor_ && this->current_ != this->eoi_) + if (this->value_ptr_ == this->eor_ && this->value_ptr_ != this->eoi_) { - this->current_ += 2 * this->border_size_; + this->value_ptr_ += 2 * this->border_size_; this->eor_ += this->row_offset_; } } Index: mln/core/internal/pixel_iterator_base.hh --- mln/core/internal/pixel_iterator_base.hh (revision 1023) +++ mln/core/internal/pixel_iterator_base.hh (working copy) @@ -93,12 +93,12 @@ protected: - /// Current pixel / value - value* value_ptr_; - /// Image associated to the iterator I& image_; + /// Current pixel / value + value* value_ptr_; + // FIXME: Inactivated: // /// Psite of the pixel @@ -174,101 +174,8 @@ // return p_; // } - - - - -// FIXME: Dead code -// ################# - - - -// /*! \brief pixel_iterator_base_ class -// */ -// template <typename E, typename I> -// class pixel_iterator_base_ : public Pixel_Iterator<E> -// { -// public: -// /// I pixel value type. -// typedef mln_value(I) value; -// /// I pixel rvalue type. -// typedef mln_value(I)& rvalue; -// /// I pixel lvalue type -// typedef mln_value(I) lvalue; - -// // Go to the beginning of the image. -// void start(); -// // Go on the next element. -// void next_(); -// // Invalidate the iterator. -// void invalidate(); -// // Is the iterator referencing a correct position in the image? -// bool is_valid() const; - - -// // Return the current pixel. -// rvalue operator* (); -// lvalue operator* () const; - -// protected: -// // beginning of the image -// value* start_; -// // end of the image -// value* eoi_; -// // current position in the image -// value* current_; -// // End of Factoriasable - -// pixel_iterator_base_(); -// }; - -// #ifndef MLN_INCLUDE_ONLY - -// template <typename E, typename I> -// pixel_iterator_base_<E,I>::pixel_iterator_base_() -// { -// } - -// template <typename E, typename I> -// void pixel_iterator_base_<E,I>::start() -// { -// current_ = start_; -// } - -// template <typename E, typename I> -// void pixel_iterator_base_<E,I>::next_() -// { -// ++current_; -// } - -// template <typename E, typename I> -// void pixel_iterator_base_<E,I>::invalidate() -// { -// current_ = eoi_; -// } - -// template <typename E, typename I> -// bool pixel_iterator_base_<E,I>::is_valid() const -// { -// return (current_ != eoi_); -// } - -// template <typename E, typename I> -// typename pixel_iterator_base_<E,I>::rvalue -// pixel_iterator_base_<E,I>::operator*() -// { -// return *current_; -// } - - -// template <typename E, typename I> -// typename pixel_iterator_base_<E,I>::lvalue -// pixel_iterator_base_<E,I>::operator*() const -// { -// return *current_; -// } - #endif // ! MLN_INCLUDE_ONLY + } // end of namespace internal } // end of namespace mln Index: mln/core/internal/lineary_pixel_iterator_base.hh --- mln/core/internal/lineary_pixel_iterator_base.hh (revision 0) +++ mln/core/internal/lineary_pixel_iterator_base.hh (revision 0) @@ -0,0 +1,109 @@ +// 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 MLN_CORE_INTERNAL_LINEARY_PIXEL_ITERATOR_BASE_HH +# define MLN_CORE_INTERNAL_LINEARY_PIXEL_ITERATOR_BASE_HH + +/*! \file mln/core/internal/lineary_pixel_iterator_base.hh + * + * \brief Code factorization for lineary pixel iterator classes. + */ + +# include <mln/core/internal/pixel_iterator_base.hh> + +namespace mln +{ + + namespace internal + { + + /*! \brief lineary_pixel_iterator_base_ class + * + */ + template <typename I, typename E> + class lineary_pixel_iterator_base_ : public pixel_iterator_base_<I, E> + { + typedef pixel_iterator_base_<I, E> super; + public: + /// Image pixel value type. + typedef mln_value(I) value; + + /// Go to the beginning of the image. + void start(); + /// Invalidate the iterator. + void invalidate(); + /// Is the iterator referencing a correct position in the image? + bool is_valid() const; + + + protected: + /// beginning of the image + value* start_; + /// end of the image + value* eoi_; + + /// Constructor + lineary_pixel_iterator_base_(I& image); + }; + +#ifndef MLN_INCLUDE_ONLY + + template <typename I, typename E> + lineary_pixel_iterator_base_<I, E>::lineary_pixel_iterator_base_(I& image) + : super(image) + { + } + + template <typename I, typename E> + void + lineary_pixel_iterator_base_<I, E>::start() + { + this->value_ptr_ = start_; + } + + template <typename I, typename E> + void + lineary_pixel_iterator_base_<I, E>::invalidate() + { + this->value_ptr_ = eoi_; + } + + template <typename I, typename E> + bool + lineary_pixel_iterator_base_<I, E>::is_valid() const + { + return (this->value_ptr_ != eoi_); + } + +#endif // ! MLN_INCLUDE_ONLY + + } // end of namespace internal + +} // end of namespace mln + + +#endif // ! MLN_CORE_INTERNAL_LINEARY_PIXEL_ITERATOR_BASE_HH

Nicolas Ballas <ballas@lrde.epita.fr> writes:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr>
Repair lineary pixel iterator.
``Lineary'' is not an English word. You probably wanted to say ``linear'' (« linéaire ») here.
* mln/core/pixter2d_b.hh: Adapt pixter2d_b to the new pixel iterator hierachy. * mln/core/internal/pixel_iterator_base.hh: Fix dead code. * mln/core/internal/lineary_pixel_iterator_base.hh: New factorization class.
Hey! Don't forget to wrap lines longer than 80 columns, especially in ChangeLogs where its easier to do (compared to a C++ file with long identifiers or type names). (Remember that changes in ChangeLogs shall not create ChangeLog entries; bypass Vcs or svn-wrapper to avoid side effects.) [...]
Index: mln/core/internal/lineary_pixel_iterator_base.hh --- mln/core/internal/lineary_pixel_iterator_base.hh (revision 0) +++ mln/core/internal/lineary_pixel_iterator_base.hh (revision 0)
[...]
+ protected: + /// beginning of the image + value* start_; + /// end of the image + value* eoi_; + + /// Constructor + lineary_pixel_iterator_base_(I& image);
It's better to start comments with a capital letter and end them with a full stop (period). Otherwise, seems good!
participants (2)
-
Nicolas Ballas
-
Roland Levillain