Milena (Olena)
User documentation 2.0a Id
|
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_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 | fwd_pixter3d<I>. | 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 | bkd_pixter3d<I>. | 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 | fwd_pixter3d<I>. | 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 | bkd_pixter3d<I>. | 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 } // end of namespace mln 00256 00257 00258 #endif // ! MLN_CORE_PIXTER3D_HH