
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Overhaul 1-D, 2-D and 3-D pixters. * mln/core/macros.hh (mln_bkd_pixter_): New macro. * mln/core/internal/pixel_iterator_base.hh (mln::pixel_iterator_base_<I, E>::start) (mln::pixel_iterator_base_<I, E>::invalidate) (mln::pixel_iterator_base_<I, E>::is_valid): Remove methods. (mln::forward_pixel_iterator_base_<I, E>) (mln::backward_pixel_iterator_base_<I, E>): New classes. * mln/core/pixter1d.hh (mln::fwd_pixter1d<I>): Inherit from mln::internal::forward_pixel_iterator_base_. (mln::bkd_pixter1d<I>): New class. * mln/core/pixter2d.hh (mln::fwd_pixter2d<I>): Inherit from mln::internal::forward_pixel_iterator_base_. (mln::bkd_pixter2d<I>): Inherit from mln::internal::backward_pixel_iterator_base_. (mln::bkd_pixter2d<I>::start): Remove method. (mln::fwd_pixter2d<I>::fwd_pixter2d) (mln::bkd_pixter2d<I>::bkd_pixter2d): Use initialization lists instead of assignments. * mln/core/pixter3d.hh (mln::fwd_pixter3d<I>): Inherit from mln::internal::forward_pixel_iterator_base_. (mln::bkd_pixter3d<I>): New class. * mln/core/p_image2d_pixter.hh (mln::p_image2d_fwd_pixter<P>): Inherit from mln::internal::forward_pixel_iterator_base_. (mln::p_image2d_bkd_pixter<P>): Inherit from mln::internal::backward_pixel_iterator_base_. * mln/core/image1d.hh (mln::trait::bkd_pixter< image1d<T> >::ret): Set to bkd_pixter1d< const image1d<T> >. * mln/core/image2d.hh: Add FIXMEs. * mln/core/image3d.hh (mln::trait::bkd_pixter< image3d<T> >::ret): Set to bkd_pixter3d< const image3d<T> >. * tests/core/pixter1d.cc, tests/core/pixter2d.cc: New tests. * tests/core/image3d.cc: Rename as... * tests/core/pixter3d.cc: ...this. Exercise bkd_pixter3d. * tests/core/Makefile.am (check_PROGRAMS): Remove image3d. Add pixter1d, pixter2d and pixter3d. (image3d_SOURCES): Remove. (pixter1d_SOURCES, pixter2d_SOURCES, pixter3d_SOURCES): New. mln/core/image1d.hh | 5 - mln/core/image2d.hh | 2 mln/core/image3d.hh | 5 - mln/core/internal/pixel_iterator_base.hh | 142 +++++++++++++++++++++++++------ mln/core/macros.hh | 2 mln/core/p_image2d_pixter.hh | 131 +++++++++++++++------------- mln/core/pixter1d.hh | 81 +++++++++++++---- mln/core/pixter2d.hh | 88 ++++++++----------- mln/core/pixter3d.hh | 118 +++++++++++++++++++++---- tests/core/Makefile.am | 8 + tests/core/pixter1d.cc | 86 ++++++++++++++++++ tests/core/pixter2d.cc | 85 ++++++++++++++++++ tests/core/pixter3d.cc | 31 ++++-- 13 files changed, 596 insertions(+), 188 deletions(-) Index: mln/core/macros.hh --- mln/core/macros.hh (revision 1910) +++ mln/core/macros.hh (working copy) @@ -286,6 +286,8 @@ # define mln_fwd_pixter_(I) mln::trait::fwd_pixter< I >::ret # define mln_bkd_pixter(I) typename mln::trait::bkd_pixter< I >::ret +# define mln_bkd_pixter_(I) mln::trait::bkd_pixter< I >::ret + # define mln_pixter(I) mln_fwd_pixter(I) # define mln_pixter_(I) mln_fwd_pixter_(I) Index: mln/core/internal/pixel_iterator_base.hh --- mln/core/internal/pixel_iterator_base.hh (revision 1910) +++ mln/core/internal/pixel_iterator_base.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,58 +28,102 @@ #ifndef MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH # define MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH -/*! \file mln/core/internal/pixel_iterator_base.hh - * - * \brief Base class to factor code for pixel iterator classes. - */ +/// \file mln/core/internal/pixel_iterator_base.hh +/// \brief Base classes factoring code for pixel iterator classes. # include <mln/core/concept/pixel_iterator.hh> # include <mln/core/internal/pixel_impl.hh> # include <mln/core/trait/qlf_value.hh> - namespace mln { namespace internal { + /*---------------------------------------. + | internal::pixel_iterator_base_<I, E>. | + `---------------------------------------*/ - /*! \internal A base class for pixel iterators. - * - */ + /// \internal A base class for pixel iterators. template <typename I, typename E> class pixel_iterator_base_ : public Pixel_Iterator<E>, public internal::pixel_impl_<I, E> { typedef internal::pixel_impl_<I, E> super_; - public: + protected: + /// Constructor. + pixel_iterator_base_(I& image); + protected: + /// Beginning of the image. + mln_qlf_value(I)* boi_; + /// End of the image (past-the-end). + mln_qlf_value(I)* eoi_; + }; + + + /*-----------------------------------------------. + | internal::forward_pixel_iterator_base_<I, E>. | + `-----------------------------------------------*/ + + /// \internal A base class for forward pixel iterators. + template <typename I, typename E> + class forward_pixel_iterator_base_ : public pixel_iterator_base_<I, E> + { + typedef pixel_iterator_base_<I, E> super_; + + public: + /// Manipulation + /// \{ /// Start an iteration. void start(); - /// Invalidate the iterator. void invalidate(); - /// Test if the iterator is valid. bool is_valid() const; + /// \} protected: + /// Constructor. + forward_pixel_iterator_base_(I& image); + }; - /// Beginning of the image. - mln_qlf_value(I)* boi_; - /// End of the image (past-the-end). - mln_qlf_value(I)* eoi_; + /*------------------------------------------------. + | internal::backward_pixel_iterator_base_<I, E>. | + `------------------------------------------------*/ + + /// \internal A base class for backward pixel iterators. + template <typename I, typename E> + class backward_pixel_iterator_base_ : public pixel_iterator_base_<I, E> + { + typedef pixel_iterator_base_<I, E> super_; + + public: + /// Manipulation + /// \{ + /// Start an iteration. + void start(); + /// Invalidate the iterator. + void invalidate(); + /// Test if the iterator is valid. + bool is_valid() const; + /// \} + protected: /// Constructor. - pixel_iterator_base_(I& image); + backward_pixel_iterator_base_(I& image); }; #ifndef MLN_INCLUDE_ONLY + /*---------------------------------------. + | internal::pixel_iterator_base_<I, E>. | + `---------------------------------------*/ + template <typename I, typename E> inline pixel_iterator_base_<I, E>::pixel_iterator_base_(I& image) @@ -89,33 +133,79 @@ I& ima = this->image_; boi_ = & ima( ima.domain().pmin() ) - 1; eoi_ = & ima( ima.domain().pmax() ) + 1; - invalidate(); + exact(*this).invalidate(); + } + + + /*-----------------------------------------------. + | internal::forward_pixel_iterator_base_<I, E>. | + `-----------------------------------------------*/ + + template <typename I, typename E> + inline + forward_pixel_iterator_base_<I, E>::forward_pixel_iterator_base_(I& image) + : super_(image) + { + } + + template <typename I, typename E> + inline + void + forward_pixel_iterator_base_<I, E>::start() + { + this->value_ptr_ = this->boi_ + 1; + } + + template <typename I, typename E> + inline + void + forward_pixel_iterator_base_<I, E>::invalidate() + { + this->value_ptr_ = this->eoi_; + } + + template <typename I, typename E> + inline + bool + forward_pixel_iterator_base_<I, E>::is_valid() const + { + return this->value_ptr_ != this->eoi_; + } + + + /*------------------------------------------------. + | internal::backward_pixel_iterator_base_<I, E>. | + `------------------------------------------------*/ + + template <typename I, typename E> + inline + backward_pixel_iterator_base_<I, E>::backward_pixel_iterator_base_(I& image) + : super_(image) + { } - // FIXME: Remove cause dangerous when bkd!!! template <typename I, typename E> inline void - pixel_iterator_base_<I, E>::start() + backward_pixel_iterator_base_<I, E>::start() { - this->value_ptr_ = boi_ + 1; + this->value_ptr_ = this->eoi_ - 1; } template <typename I, typename E> inline void - pixel_iterator_base_<I, E>::invalidate() + backward_pixel_iterator_base_<I, E>::invalidate() { - this->value_ptr_ = eoi_; + this->value_ptr_ = this->boi_; } - // FIXME: Remove casue not optimal!!! template <typename I, typename E> inline bool - pixel_iterator_base_<I, E>::is_valid() const + backward_pixel_iterator_base_<I, E>::is_valid() const { - return this->value_ptr_ != eoi_ && this->value_ptr_ != boi_; + return this->value_ptr_ != this->boi_; } #endif // ! MLN_INCLUDE_ONLY Index: mln/core/pixter1d.hh --- mln/core/pixter1d.hh (revision 1910) +++ mln/core/pixter1d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,51 +28,75 @@ #ifndef MLN_CORE_PIXTER1D_HH # define MLN_CORE_PIXTER1D_HH -/*! \file mln/core/pixter1d.hh - * - * \brief Pixel iterator class on a image 1d with border. - */ +/// \file mln/core/pixter1d.hh +/// \brief Pixel iterators on a 1-D image with border. # include <mln/core/internal/pixel_iterator_base.hh> # include <mln/core/point1d.hh> # include <mln/geom/size1d.hh> - - namespace mln { + /*------------------. + | fwd_pixter1d<I>. | + `------------------*/ + + /// Forward pixel iterator on a 1-D image with border. template <typename I> - class fwd_pixter1d : public internal::pixel_iterator_base_< I, fwd_pixter1d<I> > + class fwd_pixter1d : + public internal::forward_pixel_iterator_base_< I, fwd_pixter1d<I> > { - typedef internal::pixel_iterator_base_< I, fwd_pixter1d<I> > super_; + typedef internal::forward_pixel_iterator_base_< I, fwd_pixter1d<I> > super_; public: - /// Image type. typedef I image; - /*! \brief Constructor. - * - * \param[in] image Image to iterate over its pixels. - */ + /// \brief Constructor. + /// \param[in] image The image this pixel iterator is bound to. fwd_pixter1d(I& image); /// Go to the next pixel. void next_(); - }; - // FIXME: bkd_pixter1d + /*------------------. + | bkd_pixter1d<I>. | + `------------------*/ + + /// Backward pixel iterator on a 1-D image with border. + template <typename I> + class bkd_pixter1d : + public internal::backward_pixel_iterator_base_< I, bkd_pixter1d<I> > + { + typedef internal::backward_pixel_iterator_base_< I, bkd_pixter1d<I> > super_; + + public: + /// Image type. + typedef I image; + + /// \brief Constructor. + /// \param[in] image The image this pixel iterator is bound to. + bkd_pixter1d(I& image); + + /// Go to the next pixel. + void next_(); + }; + #ifndef MLN_INCLUDE_ONLY + /*------------------. + | fwd_pixter1d<I>. | + `------------------*/ + template <typename I> inline - fwd_pixter1d<I>::fwd_pixter1d(I& image) : - super_(image) + fwd_pixter1d<I>::fwd_pixter1d(I& image) + : super_(image) { mln_precondition(image.has_data()); } @@ -85,6 +109,27 @@ ++this->value_ptr_; } + + /*------------------. + | bkd_pixter1d<I>. | + `------------------*/ + + template <typename I> + inline + bkd_pixter1d<I>::bkd_pixter1d(I& image) + : super_(image) + { + mln_precondition(image.has_data()); + } + + template <typename I> + inline + void + bkd_pixter1d<I>::next_() + { + --this->value_ptr_; + } + #endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/pixter2d.hh --- mln/core/pixter2d.hh (revision 1910) +++ mln/core/pixter2d.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,102 +28,97 @@ #ifndef MLN_CORE_PIXTER2D_HH # define MLN_CORE_PIXTER2D_HH -/*! \file mln/core/pixter2d.hh - * - * \brief Pixel iterator class on a image 2d with border. - */ +/// \file mln/core/pixter2d.hh +/// \brief Pixel iterators on a 2-D image with border. # include <mln/core/internal/pixel_iterator_base.hh> # include <mln/core/point2d.hh> # include <mln/geom/size2d.hh> - - namespace mln { + /*------------------. + | fwd_pixter2d<I>. | + `------------------*/ + + /// Forward pixel iterator on a 2-D image with border. template <typename I> - class fwd_pixter2d : public internal::pixel_iterator_base_< I, fwd_pixter2d<I> > + class fwd_pixter2d + : public internal::forward_pixel_iterator_base_< I, fwd_pixter2d<I> > { - typedef internal::pixel_iterator_base_< I, fwd_pixter2d<I> > super_; + typedef internal::forward_pixel_iterator_base_< I, fwd_pixter2d<I> > super_; public: - /// Image type. typedef I image; - /*! \brief Constructor. - * - * \param[in] image Image to iterate over its pixels. - */ + /// \brief Constructor. + /// \param[in] image The image this pixel iterator is bound to. fwd_pixter2d(I& image); /// Go to the next pixel. void next_(); private: - /// Twice the size of the image border. unsigned border_x2_; - /// Row offset. unsigned row_offset_; - /// End of the current row. mln_qlf_value(I)* eor_; }; + /*------------------. + | bkd_pixter2d<I>. | + `------------------*/ + /// Backward pixel iterator on a 2-D image with border. template <typename I> - class bkd_pixter2d : public internal::pixel_iterator_base_< I, bkd_pixter2d<I> > + class bkd_pixter2d + : public internal::backward_pixel_iterator_base_< I, bkd_pixter2d<I> > { - typedef internal::pixel_iterator_base_< I, bkd_pixter2d<I> > super_; + typedef internal::backward_pixel_iterator_base_< I, bkd_pixter2d<I> > super_; public: - /// Image type. typedef I image; - /*! \brief Constructor. - * - * \param[in] image Image to iterate over its pixels. - */ + /// \brief Constructor. + /// \param[in] image The image this pixel iterator is bound to. bkd_pixter2d(I& image); /// Go to the next pixel. void next_(); - void start(); - private: /// Twice the size of the image border. unsigned border_x2_; - /// Row offset. unsigned row_offset_; - /// Beginning of the current row. mln_qlf_value(I)* bor_; }; - #ifndef MLN_INCLUDE_ONLY - // Fwd. + /*------------------. + | fwd_pixter2d<I>. | + `------------------*/ template <typename I> inline - fwd_pixter2d<I>::fwd_pixter2d(I& image) : - super_(image) + fwd_pixter2d<I>::fwd_pixter2d(I& image) + : super_(image), + border_x2_(2 * image.border()), + row_offset_(image.bbox().ncols() + border_x2_), + eor_(& image.at(geom::min_row(image), geom::max_col(image)) + 1) { mln_precondition(image.has_data()); - border_x2_ = 2 * image.border(); - row_offset_ = geom::max_col(image) - geom::min_col(image) + 1 + border_x2_; - eor_ = & image.at(geom::min_row(image), geom::max_col(image)) + 1; } template <typename I> @@ -139,17 +134,20 @@ } } - // Bkd. + + /*------------------. + | fwd_pixter2d<I>. | + `------------------*/ template <typename I> inline - bkd_pixter2d<I>::bkd_pixter2d(I& image) : - super_(image) + bkd_pixter2d<I>::bkd_pixter2d(I& image) + : super_(image), + border_x2_(2 * image.border()), + row_offset_(image.bbox().ncols() + border_x2_), + bor_(& image.at(geom::max_row(image), geom::min_col(image)) - 1) { mln_precondition(image.has_data()); - border_x2_ = 2 * image.border(); - row_offset_ = geom::max_col(image) - geom::min_col(image) + 1 + border_x2_; - bor_ = & image.at(geom::max_row(image), geom::min_col(image)) - 1; } template <typename I> @@ -165,14 +163,6 @@ } } - template <typename I> - inline - void - bkd_pixter2d<I>::start() - { - this->value_ptr_ = this->eoi_ - 1; - } - #endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/pixter3d.hh --- mln/core/pixter3d.hh (revision 1910) +++ mln/core/pixter3d.hh (working copy) @@ -28,70 +28,104 @@ #ifndef MLN_CORE_PIXTER3D_HH # define MLN_CORE_PIXTER3D_HH -/*! \file mln/core/pixter3d.hh - * - * \brief Pixel iterator class on a image 3d with border. - */ +/// \file mln/core/pixter3d.hh +/// \brief Pixel iterators on a 3-D image with border. # include <mln/core/internal/pixel_iterator_base.hh> # include <mln/core/point3d.hh> # include <mln/geom/size3d.hh> - - namespace mln { + /*------------------. + | fwd_pixter3d<I>. | + `------------------*/ + + /// Forward pixel iterator on a 3-D image with border. template <typename I> class fwd_pixter3d - : public internal::pixel_iterator_base_< I, fwd_pixter3d<I> > + : public internal::forward_pixel_iterator_base_< I, fwd_pixter3d<I> > { - typedef internal::pixel_iterator_base_< I, fwd_pixter3d<I> > super_; + typedef internal::forward_pixel_iterator_base_< I, fwd_pixter3d<I> > super_; public: - /// Image type. typedef I image; - /*! \brief Constructor. - * - * \param[in] image Image to iterate over its pixels. - */ + /// \brief Constructor. + /// \param[in] image The image this pixel iterator is bound to. fwd_pixter3d(I& image); /// Go to the next pixel. void next_(); private: - /// Twice the size of the image border. const unsigned border_x2_; - /// Row offset. const unsigned row_offset_; - /// End of the current row. mln_qlf_value(I)* eor_; /// Next slice offset. const unsigned next_sli_offset_; - /// Next slice offset for row. const unsigned next_srow_offset_; - /// Slice offset. const unsigned sli_offset_; - /// End of the current slice. mln_qlf_value(I)* eos_; }; - // FIXME: bkd_pixter3d + /*------------------. + | bkd_pixter3d<I>. | + `------------------*/ + + /// Backward pixel iterator on a 3-D image with border. + template <typename I> + class bkd_pixter3d + : public internal::backward_pixel_iterator_base_< I, bkd_pixter3d<I> > + { + typedef internal::backward_pixel_iterator_base_< I, bkd_pixter3d<I> > super_; + + public: + /// Image type. + typedef I image; + + /// \brief Constructor. + /// \param[in] image The image this pixel iterator is bound to. + bkd_pixter3d(I& image); + + /// Go to the next pixel. + void next_(); + + private: + /// Twice the size of the image border. + const unsigned border_x2_; + /// Row offset. + const unsigned row_offset_; + /// Beginning of the current row. + mln_qlf_value(I)* bor_; + + /// Next slice offset. + const unsigned next_sli_offset_; + /// Next slice offset for row. + const unsigned next_srow_offset_; + /// Slice offset. + const unsigned sli_offset_; + /// Beginning of the current slice. + mln_qlf_value(I)* bos_; + }; #ifndef MLN_INCLUDE_ONLY + /*------------------. + | fwd_pixter3d<I>. | + `------------------*/ + template <typename I> inline fwd_pixter3d<I>::fwd_pixter3d(I& image) @@ -131,6 +165,50 @@ } } + + /*------------------. + | bkd_pixter3d<I>. | + `------------------*/ + + template <typename I> + inline + bkd_pixter3d<I>::bkd_pixter3d(I& image) + : super_(image), + border_x2_(2 * image.border()), + row_offset_(image.bbox().ncols() + border_x2_), + bor_(& image.at(geom::max_sli(image), + geom::max_row(image), + geom::min_col(image)) - 1), + next_sli_offset_(row_offset_ * border_x2_ + border_x2_), + next_srow_offset_(next_sli_offset_ + image.bbox().ncols()), + sli_offset_((image.bbox().ncols() + border_x2_) * + (image.bbox().nrows() + border_x2_)), + bos_(& image.at(geom::max_sli(image), + geom::min_row(image), + geom::min_col(image)) - 1) + { + mln_precondition(image.has_data()); + } + + template <typename I> + inline + void + bkd_pixter3d<I>::next_() + { + --this->value_ptr_; + if (this->value_ptr_ == bos_ && this->value_ptr_ != this->boi_) + { + this->value_ptr_ -= next_sli_offset_; + bos_ -= sli_offset_; + bor_ -= next_srow_offset_; + } + else if (this->value_ptr_ == bor_ && this->value_ptr_ != this->boi_) + { + this->value_ptr_ -= border_x2_; + bor_ -= row_offset_; + } + } + #endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/p_image2d_pixter.hh --- mln/core/p_image2d_pixter.hh (revision 1910) +++ mln/core/p_image2d_pixter.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,49 +28,51 @@ #ifndef MLN_CORE_P_IMAGE2D_PIXTER_HH # define MLN_CORE_P_IMAGE2D_PIXTER_HH -/*! \file mln/core/p_image2d_pixter.hh - * - * \brief Pixel iterator class on a image 2d with border. - */ +/// \file mln/core/p_image2d_pixter.hh +/// \brief Pixel iterators on a mln::p_image2d. # include <mln/core/internal/pixel_iterator_base.hh> # include <mln/core/point2d.hh> # include <mln/geom/size2d.hh> - - namespace mln { + /*--------------------------. + | p_image2d_fwd_pixter<P>. | + `--------------------------*/ + template <typename P> - class p_image2d_fwd_pixter : public internal::pixel_iterator_base_< typename p_image2d<P>::image_type, p_image2d_fwd_pixter<P> > - { - typedef internal::pixel_iterator_base_< typename p_image2d<P>::image_type, p_image2d_fwd_pixter<P> > super_; + class p_image2d_fwd_pixter + : public internal::forward_pixel_iterator_base_< + typename p_image2d<P>::image_type, + p_image2d_fwd_pixter<P> + > + { + typedef internal::forward_pixel_iterator_base_< + typename p_image2d<P>::image_type, + p_image2d_fwd_pixter<P> + > super_; public: - /// Image type. typedef typename p_image2d<P>::image_type image; - /// Point type. typedef point2d point; - /*! \brief Constructor. - * - * \param[in] image Image to iterate over its pixels. - */ + /// \brief Constructor. + /// \param[in] image The mln::p_image2d this pixel iterator is bound to. p_image2d_fwd_pixter(p_image2d<P>& s); - /// Reference of the corresponding point. - const point to_point() const; - + /// Start an iteration. + void start(); /// Go to the next pixel. void next_(); - void start(); + /// Reference of the corresponding point. + const point to_point() const; private: - /// Row offset. unsigned row_offset_; /// End of the current row. @@ -78,66 +80,74 @@ }; + /*--------------------------. + | p_image2d_bkd_pixter<P>. | + `--------------------------*/ template <typename P> - class p_image2d_bkd_pixter : public internal::pixel_iterator_base_< typename image2d<P>::image_type, p_image2d_bkd_pixter<P> > - { - typedef internal::pixel_iterator_base_< typename image2d<P>::image_type, p_image2d_bkd_pixter<P> > super_; + class p_image2d_bkd_pixter + : public internal::backward_pixel_iterator_base_< + typename image2d<P>::image_type, + p_image2d_bkd_pixter<P> + > + { + typedef internal::backward_pixel_iterator_base_< + typename image2d<P>::image_type, + p_image2d_bkd_pixter<P> + > super_; public: - /// Image type. typedef typename p_image2d<P>::image_type image; - /// Point type. typedef point2d point; - /*! \brief Constructor. - * - * \param[in] image Image to iterate over its pixels. - */ + /// \brief Constructor. + /// \param[in] image The mln::p_image2d this pixel iterator is bound to. p_image2d_bkd_pixter(p_image2d<P>& s); + /// Start an iteration. + void start(); /// Go to the next pixel. void next_(); - void start(); - /// Reference of the corresponding point. const point to_point() const; private: - /// Row offset. unsigned row_offset_; - /// Beginning of the current row. mln_qlf_value(image)* bor_; }; - #ifndef MLN_INCLUDE_ONLY - // Fwd. + /*--------------------------. + | p_image2d_fwd_pixter<P>. | + `--------------------------*/ template <typename P> inline - p_image2d_fwd_pixter<P>::p_image2d_fwd_pixter(p_image2d<P>& s) : - super_(s.image_non_const()) + p_image2d_fwd_pixter<P>::p_image2d_fwd_pixter(p_image2d<P>& s) + : super_(s.image_non_const()) { mln_precondition(this->image_.has_data()); row_offset_ = geom::max_col(this->image_) - geom::min_col(this->image_) + 1; - eor_ = & this->image_.at(geom::min_row(this->image_), geom::max_col(this->image_)) + 1; + eor_ = & this->image_.at(geom::min_row(this->image_), + geom::max_col(this->image_)) + 1; } template <typename P> inline - const typename p_image2d_fwd_pixter<P>::point - p_image2d_fwd_pixter<P>::to_point() const + void + p_image2d_fwd_pixter<P>::start() { - return this->image_.point_at_offset(*this); + this->value_ptr_ = this->boi_ + 1; + while(this->is_valid() && !(*this->value_ptr_)) + ++this->value_ptr_; } template <typename P> @@ -150,35 +160,38 @@ ++this->value_ptr_; } - template <typename P> inline - void - p_image2d_fwd_pixter<P>::start() + const typename p_image2d_fwd_pixter<P>::point + p_image2d_fwd_pixter<P>::to_point() const { - this->value_ptr_ = this->boi_ + 1; - while(this->is_valid() && !(*this->value_ptr_)) - ++this->value_ptr_; + return this->image_.point_at_offset(*this); } - // Bkd. + + /*--------------------------. + | p_image2d_bkd_pixter<P>. | + `--------------------------*/ template <typename P> inline - p_image2d_bkd_pixter<P>::p_image2d_bkd_pixter(p_image2d<P>& s) : - super_(s.image_non_const()) + p_image2d_bkd_pixter<P>::p_image2d_bkd_pixter(p_image2d<P>& s) + : super_(s.image_non_const()) { mln_precondition(this->image_.has_data()); row_offset_ = geom::max_col(this->image_) - geom::min_col(this->image_) + 1; - bor_ = & this->image_.at(geom::max_row(this->image_), geom::min_col(this->image_)) - 1; + bor_ = & this->image_.at(geom::max_row(this->image_), + geom::min_col(this->image_)) - 1; } template <typename P> inline - const typename p_image2d_bkd_pixter<P>::point - p_image2d_bkd_pixter<P>::to_point() const + void + p_image2d_bkd_pixter<P>::start() { - return this->image_.point_at_offset(*this); + this->value_ptr_ = this->eoi_ - 1; + while(this->is_valid() && !(*this->value_ptr_)) + --this->value_ptr_; } template <typename P> @@ -193,12 +206,10 @@ template <typename P> inline - void - p_image2d_bkd_pixter<P>::start() + const typename p_image2d_bkd_pixter<P>::point + p_image2d_bkd_pixter<P>::to_point() const { - this->value_ptr_ = this->eoi_ - 1; - while(this->is_valid() && !(*this->value_ptr_)) - --this->value_ptr_; + return this->image_.point_at_offset(*this); } #endif // ! MLN_INCLUDE_ONLY Index: mln/core/image1d.hh --- mln/core/image1d.hh (revision 1910) +++ mln/core/image1d.hh (working copy) @@ -533,7 +533,7 @@ template <typename T> struct bkd_pixter< image1d<T> > { - typedef mln::internal::fixme ret; + typedef bkd_pixter1d< const image1d<T> > ret; }; // qixter @@ -553,9 +553,12 @@ template <typename T, typename W> struct bkd_qixter< image1d<T>, W > { + // FIXME: Implement dpoints_bkd_pixter. typedef mln::internal::fixme ret; }; + // FIXME: Nixters (see in image2d.hh) + } // end of namespace mln::trait } // end of namespace mln Index: mln/core/image2d.hh --- mln/core/image2d.hh (revision 1910) +++ mln/core/image2d.hh (working copy) @@ -581,6 +581,7 @@ template <typename T, typename W> struct bkd_qixter< image2d<T>, W > { + // FIXME: Implement dpoints_bkd_pixter. typedef mln::internal::fixme ret; }; @@ -601,6 +602,7 @@ template <typename T, typename N> struct bkd_nixter< image2d<T>, N > { + // FIXME: Implement dpoints_bkd_pixter. typedef mln::internal::fixme ret; }; Index: mln/core/image3d.hh --- mln/core/image3d.hh (revision 1910) +++ mln/core/image3d.hh (working copy) @@ -573,7 +573,7 @@ template <typename T> struct bkd_pixter< image3d<T> > { - typedef mln::internal::fixme ret; + typedef bkd_pixter3d< const image3d<T> > ret; }; // qixter @@ -593,9 +593,12 @@ template <typename T, typename W> struct bkd_qixter< image3d<T>, W > { + // FIXME: Implement dpoints_bkd_pixter. typedef mln::internal::fixme ret; }; + // FIXME: Nixters (see in image2d.hh) + } // end of namespace mln::trait } // end of namespace mln Index: tests/core/pixter1d.cc --- tests/core/pixter1d.cc (revision 0) +++ tests/core/pixter1d.cc (revision 0) @@ -0,0 +1,86 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// +// 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. + +/// \file tests/level/pixter1d.cc +/// \brief Tests on 1-D image pixters. + +#include <mln/core/image1d.hh> + +#include <mln/debug/iota.hh> + +int main() +{ + using namespace mln; + + { + box1d b(make::point1d(2), make::point1d(4)); + image1d<int> ima(b, 2); + + mln_pixter_(image1d<int>) p(ima); + for_all(p) + std::cout << p << std::endl; + } + + { + box1d b(make::point1d(2), make::point1d(6)); + image1d<int> ima(b, 1); + + debug::iota(ima); + + { + mln_fwd_piter_(image1d<int>) pi(ima.domain()); + mln_fwd_pixter_(image1d<int>) p(ima); + pi.start(); + p.start(); + unsigned i = 0; + while (pi.is_valid()) + { + mln_assertion(ima(pi) == p.val()); + pi.next(); + p.next(); + ++i; + } + mln_assertion(i == b.npoints()); + } + + { + mln_bkd_piter_(image1d<int>) pi(ima.domain()); + mln_bkd_pixter_(image1d<int>) p(ima); + pi.start(); + p.start(); + unsigned i = 0; + while (pi.is_valid()) + { + mln_assertion(ima(pi) == p.val()); + pi.next(); + p.next(); + ++i; + } + mln_assertion(i == b.npoints()); + } + } +} Index: tests/core/pixter2d.cc --- tests/core/pixter2d.cc (revision 0) +++ tests/core/pixter2d.cc (revision 0) @@ -0,0 +1,85 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// +// 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. + +/// \file tests/level/pixter2d.cc +/// \brief Tests on 2-D image pixters. + +#include <mln/core/image2d.hh> + +#include <mln/debug/iota.hh> + +int main() +{ + using namespace mln; + + { + box2d b(make::point2d(2, 1), make::point2d(4, 3)); + image2d<int> ima(b, 2); + + mln_pixter_(image2d<int>) p(ima); + for_all(p) + std::cout << p << std::endl; + } + + { + box2d b(make::point2d(2, 1), make::point2d(6, 3)); + image2d<int> ima(b, 1); + debug::iota(ima); + + { + mln_fwd_piter_(image2d<int>) pi(ima.domain()); + mln_fwd_pixter_(image2d<int>) p(ima); + pi.start(); + p.start(); + unsigned i = 0; + while (pi.is_valid()) + { + mln_assertion(ima(pi) == p.val()); + pi.next(); + p.next(); + ++i; + } + mln_assertion(i == b.npoints()); + } + + { + mln_bkd_piter_(image2d<int>) pi(ima.domain()); + mln_bkd_pixter_(image2d<int>) p(ima); + pi.start(); + p.start(); + unsigned i = 0; + while (pi.is_valid()) + { + mln_assertion(ima(pi) == p.val()); + pi.next(); + p.next(); + ++i; + } + mln_assertion(i == b.npoints()); + } + } +} Index: tests/core/pixter3d.cc --- tests/core/pixter3d.cc (revision 1910) +++ tests/core/pixter3d.cc (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,14 +25,10 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/level/image3d.cc - * - * \brief Tests on Image3d pixter - */ - +/// \file tests/level/pixter3d.cc +/// \brief Tests on 3-D image pixters. #include <mln/core/image3d.hh> -#include <mln/core/image2d.hh> #include <mln/debug/iota.hh> @@ -40,8 +36,6 @@ { using namespace mln; - - // Working test { box3d b(make::point3d(1,2, 1), make::point3d(2,4, 3)); image3d<int> ima(b, 2); @@ -51,10 +45,9 @@ std::cout << p << std::endl; } - { box3d b(make::point3d(1,2, 1), make::point3d(3,6, 3)); - image3d<int> ima(b, 0); + image3d<int> ima(b, 1); debug::iota(ima); @@ -73,5 +66,21 @@ } mln_assertion(i == b.npoints()); } + + { + mln_bkd_piter_(image3d<int>) pi(ima.domain()); + mln_bkd_pixter_(image3d<int>) p(ima); + pi.start(); + p.start(); + unsigned i = 0; + while (pi.is_valid()) + { + mln_assertion(ima(pi) == p.val()); + pi.next(); + p.next(); + ++i; + } + mln_assertion(i == b.npoints()); + } } } Index: tests/core/Makefile.am --- tests/core/Makefile.am (revision 1910) +++ tests/core/Makefile.am (working copy) @@ -8,7 +8,6 @@ exact \ h_vec \ initialize \ - image3d \ graph_elt_neighborhood \ graph_elt_window \ graph_image \ @@ -26,6 +25,9 @@ p_queue \ p_queue_fast \ p_runs \ + pixter1d \ + pixter2d \ + pixter3d \ point_set_compatibility \ pset_array \ rle_image \ @@ -38,7 +40,6 @@ exact_SOURCES = exact.cc h_vec_SOURCES = h_vec.cc initialize_SOURCES = initialize.cc -image3d_SOURCES = image3d.cc graph_elt_neighborhood_SOURCES = graph_elt_neighborhood.cc graph_elt_window_SOURCES = graph_elt_window.cc graph_image_SOURCES = graph_image.cc @@ -56,6 +57,9 @@ p_queue_SOURCES = p_priority_queue_fast.cc p_queue_fast_SOURCES = p_priority_queue_fast.cc p_runs_SOURCES = p_runs.cc +pixter1d_SOURCES = pixter1d.cc +pixter2d_SOURCES = pixter2d.cc +pixter3d_SOURCES = pixter3d.cc point_set_compatibility_SOURCES = point_set_compatibility.cc pset_array_SOURCES = pset_array.cc rle_image_SOURCES = rle_image.cc