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_PIXTER3D_HH
00027 # define MLN_CORE_PIXTER3D_HH
00028
00032
00033 # include <mln/core/internal/pixel_iterator_base.hh>
00034 # include <mln/core/alias/point3d.hh>
00035 # include <mln/geom/size3d.hh>
00036 # include <mln/opt/at.hh>
00037
00038
00039 namespace mln
00040 {
00041
00042
00043
00044
00045
00047 template <typename I>
00048 class fwd_pixter3d
00049 : public internal::forward_pixel_iterator_base_< I, fwd_pixter3d<I> >
00050 {
00051 typedef internal::forward_pixel_iterator_base_< I, fwd_pixter3d<I> > super_;
00052
00053 public:
00055 typedef I image;
00056
00059 fwd_pixter3d(I& image);
00060
00062 void next_();
00063
00065 void start_();
00066
00067 private:
00068
00070 const unsigned border_x2_;
00071
00073 const unsigned row_offset_;
00074
00076 mln_qlf_value(I)* eor_;
00077
00079 const unsigned next_sli_offset_;
00080
00082 const unsigned next_srow_offset_;
00083
00085 const unsigned sli_offset_;
00086
00088 mln_qlf_value(I)* eos_;
00089
00090 using super_::image_;
00091 };
00092
00093
00094
00095
00096
00097
00099 template <typename I>
00100 class bkd_pixter3d
00101 : public internal::backward_pixel_iterator_base_< I, bkd_pixter3d<I> >
00102 {
00103 typedef internal::backward_pixel_iterator_base_< I, bkd_pixter3d<I> > super_;
00104
00105 public:
00107 typedef I image;
00108
00111 bkd_pixter3d(I& image);
00112
00114 void next_();
00115
00117 void start_();
00118
00119 private:
00120
00122 const unsigned border_x2_;
00123
00125 const unsigned row_offset_;
00126
00128 mln_qlf_value(I)* bor_;
00129
00131 const unsigned next_sli_offset_;
00132
00134 const unsigned next_srow_offset_;
00135
00137 const unsigned sli_offset_;
00138
00140 mln_qlf_value(I)* bos_;
00141
00142 using super_::image_;
00143 };
00144
00145
00146 #ifndef MLN_INCLUDE_ONLY
00147
00148
00149
00150
00151
00152 template <typename I>
00153 inline
00154 fwd_pixter3d<I>::fwd_pixter3d(I& image)
00155 : super_(image),
00156 border_x2_(2 * image.border()),
00157 row_offset_(image.bbox().ncols() + border_x2_),
00158 next_sli_offset_(row_offset_ * border_x2_ + border_x2_),
00159 next_srow_offset_(next_sli_offset_ + image.bbox().ncols()),
00160 sli_offset_((image.bbox().ncols() + border_x2_) *
00161 (image.bbox().nrows() + border_x2_))
00162 {
00163 mln_precondition(image.is_valid());
00164 }
00165
00166 template <typename I>
00167 inline
00168 void
00169 fwd_pixter3d<I>::start_()
00170 {
00171 eor_ = & opt::at(image_,
00172 geom::min_sli(image_),
00173 geom::min_row(image_),
00174 geom::max_col(image_)) + 1;
00175 eos_ = & opt::at(image_,
00176 geom::min_sli(image_),
00177 geom::max_row(image_),
00178 geom::max_col(image_)) + 1;
00179 }
00180
00181 template <typename I>
00182 inline
00183 void
00184 fwd_pixter3d<I>::next_()
00185 {
00186 ++this->value_ptr_;
00187 if (this->value_ptr_ == eos_ && this->value_ptr_ != this->eoi_)
00188 {
00189 this->value_ptr_ += next_sli_offset_;
00190 eos_ += sli_offset_;
00191 eor_ += next_srow_offset_;
00192 }
00193 else if (this->value_ptr_ == eor_ && this->value_ptr_ != this->eoi_)
00194 {
00195 this->value_ptr_ += border_x2_;
00196 eor_ += row_offset_;
00197 }
00198 }
00199
00200
00201
00202
00203
00204
00205 template <typename I>
00206 inline
00207 bkd_pixter3d<I>::bkd_pixter3d(I& image)
00208 : super_(image),
00209 border_x2_(2 * image.border()),
00210 row_offset_(image.bbox().ncols() + border_x2_),
00211 next_sli_offset_(row_offset_ * border_x2_ + border_x2_),
00212 next_srow_offset_(next_sli_offset_ + image.bbox().ncols()),
00213 sli_offset_((image.bbox().ncols() + border_x2_) *
00214 (image.bbox().nrows() + border_x2_))
00215 {
00216 mln_precondition(image.is_valid());
00217 }
00218
00219 template <typename I>
00220 inline
00221 void
00222 bkd_pixter3d<I>::start_()
00223 {
00224 bor_ = & opt::at(image_,
00225 geom::max_sli(image_),
00226 geom::max_row(image_),
00227 geom::min_col(image_)) - 1;
00228 bos_ = & opt::at(image_,
00229 geom::max_sli(image_),
00230 geom::min_row(image_),
00231 geom::min_col(image_)) - 1;
00232 }
00233
00234 template <typename I>
00235 inline
00236 void
00237 bkd_pixter3d<I>::next_()
00238 {
00239 --this->value_ptr_;
00240 if (this->value_ptr_ == bos_ && this->value_ptr_ != this->boi_)
00241 {
00242 this->value_ptr_ -= next_sli_offset_;
00243 bos_ -= sli_offset_;
00244 bor_ -= next_srow_offset_;
00245 }
00246 else if (this->value_ptr_ == bor_ && this->value_ptr_ != this->boi_)
00247 {
00248 this->value_ptr_ -= border_x2_;
00249 bor_ -= row_offset_;
00250 }
00251 }
00252
00253 #endif // ! MLN_INCLUDE_ONLY
00254
00255 }
00256
00257
00258 #endif // ! MLN_CORE_PIXTER3D_HH