• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

pixter2d.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_CORE_PIXTER2D_HH
00027 # define MLN_CORE_PIXTER2D_HH
00028 
00032 
00033 # include <mln/core/internal/pixel_iterator_base.hh>
00034 # include <mln/core/alias/point2d.hh>
00035 # include <mln/geom/size2d.hh>
00036 # include <mln/opt/at.hh>
00037 
00038 namespace mln
00039 {
00040 
00041   /*------------------.
00042   | fwd_pixter2d<I>.  |
00043   `------------------*/
00044 
00046   template <typename I>
00047   class fwd_pixter2d
00048     : public internal::forward_pixel_iterator_base_< I, fwd_pixter2d<I> >
00049   {
00050     typedef internal::forward_pixel_iterator_base_< I, fwd_pixter2d<I> > super_;
00051 
00052   public:
00054     typedef I image;
00055 
00058     fwd_pixter2d(I& image);
00059 
00061     void next_();
00062 
00064     void start_();
00065 
00066   private:
00067 
00069     unsigned border_x2_;
00070 
00072     unsigned row_offset_;
00073 
00075     mln_qlf_value(I)* eor_;
00076 
00077     using super_::image_;
00078   };
00079 
00080 
00081   /*------------------.
00082   | bkd_pixter2d<I>.  |
00083   `------------------*/
00084 
00086   template <typename I>
00087   class bkd_pixter2d
00088     : public internal::backward_pixel_iterator_base_< I, bkd_pixter2d<I> >
00089   {
00090     typedef internal::backward_pixel_iterator_base_< I, bkd_pixter2d<I> > super_;
00091 
00092   public:
00094     typedef I image;
00095 
00098     bkd_pixter2d(I& image);
00099 
00101     void next_();
00102 
00104     void start_();
00105 
00106   private:
00107 
00109     unsigned border_x2_;
00110 
00112     unsigned row_offset_;
00113 
00115     mln_qlf_value(I)* bor_;
00116 
00117     using super_::image_;
00118   };
00119 
00120 
00121 
00122 #ifndef MLN_INCLUDE_ONLY
00123 
00124   /*------------------.
00125   | fwd_pixter2d<I>.  |
00126   `------------------*/
00127 
00128   template <typename I>
00129   inline
00130   fwd_pixter2d<I>::fwd_pixter2d(I& image)
00131     : super_(image),
00132       border_x2_(2 * image.border()),
00133       row_offset_(image.bbox().ncols() + border_x2_)
00134   {
00135     mln_precondition(image.is_valid());
00136     mln_precondition(image_.is_valid());
00137     mln_precondition(image_.buffer() == image.buffer());
00138   }
00139 
00140   template <typename I>
00141   inline
00142   void
00143   fwd_pixter2d<I>::next_()
00144   {
00145     ++this->value_ptr_;
00146     if (this->value_ptr_ == eor_ && this->value_ptr_ != this->eoi_)
00147     {
00148       this->value_ptr_ += border_x2_;
00149       eor_ += row_offset_;
00150     }
00151   }
00152 
00153   template <typename I>
00154   inline
00155   void
00156   fwd_pixter2d<I>::start_()
00157   {
00158     mln_precondition(image_.is_valid());
00159     eor_ = & opt::at(image_, geom::min_row(image_), geom::max_col(image_)) + 1;
00160   }
00161 
00162 
00163   /*------------------.
00164   | fwd_pixter2d<I>.  |
00165   `------------------*/
00166 
00167   template <typename I>
00168   inline
00169   bkd_pixter2d<I>::bkd_pixter2d(I& image)
00170     : super_(image),
00171       border_x2_(2 * image.border()),
00172       row_offset_(image.bbox().ncols() + border_x2_)
00173   {
00174     mln_precondition(image.is_valid());
00175   }
00176 
00177   template <typename I>
00178   inline
00179   void
00180   bkd_pixter2d<I>::next_()
00181   {
00182     --this->value_ptr_;
00183     if (this->value_ptr_ == bor_ && this->value_ptr_ != this->boi_)
00184     {
00185       this->value_ptr_ -= border_x2_;
00186       bor_ -= row_offset_;
00187     }
00188   }
00189 
00190   template <typename I>
00191   inline
00192   void
00193   bkd_pixter2d<I>::start_()
00194   {
00195     bor_ = & opt::at(image_, geom::max_row(image_), geom::min_col(image_)) - 1;
00196   }
00197 
00198 #endif // ! MLN_INCLUDE_ONLY
00199 
00200 } // end of namespace mln
00201 
00202 #endif // ! MLN_CORE_PIXTER2D_HH

Generated on Tue Oct 4 2011 15:24:19 for Milena (Olena) by  doxygen 1.7.1