00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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 
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 
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 
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 
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 } 
00201 
00202 #endif // ! MLN_CORE_PIXTER2D_HH