$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pixter3d.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_PIXTER3D_HH
28 # define MLN_CORE_PIXTER3D_HH
29 
33 
34 # include <mln/core/internal/pixel_iterator_base.hh>
35 # include <mln/core/alias/point3d.hh>
36 # include <mln/geom/size3d.hh>
37 # include <mln/opt/at.hh>
38 
39 
40 namespace mln
41 {
42 
43  /*------------------.
44  | fwd_pixter3d<I>. |
45  `------------------*/
46 
50  template <typename I>
52  : public internal::forward_pixel_iterator_base_< I, fwd_pixter3d<I> >
53  {
55 
56  public:
58  typedef I image;
59 
62  fwd_pixter3d(I& image);
63 
66  void next_();
67 
69  void start_();
71 
72  private:
73 
75  const unsigned border_x2_;
76 
78  const unsigned row_offset_;
79 
81  mln_qlf_value(I)* eor_;
82 
84  const unsigned next_sli_offset_;
85 
87  const unsigned next_srow_offset_;
88 
90  const unsigned sli_offset_;
91 
93  mln_qlf_value(I)* eos_;
94 
95  using super_::image_;
96  };
97 
98 
99  /*------------------.
100  | bkd_pixter3d<I>. |
101  `------------------*/
102 
106  template <typename I>
108  : public internal::backward_pixel_iterator_base_< I, bkd_pixter3d<I> >
109  {
111 
112  public:
114  typedef I image;
115 
118  bkd_pixter3d(I& image);
119 
122  void next_();
123 
125  void start_();
127 
128  private:
129 
131  const unsigned border_x2_;
132 
134  const unsigned row_offset_;
135 
137  mln_qlf_value(I)* bor_;
138 
140  const unsigned next_sli_offset_;
141 
143  const unsigned next_srow_offset_;
144 
146  const unsigned sli_offset_;
147 
149  mln_qlf_value(I)* bos_;
150 
151  using super_::image_;
152  };
153 
154 
155 #ifndef MLN_INCLUDE_ONLY
156 
157  /*------------------.
158  | fwd_pixter3d<I>. |
159  `------------------*/
160 
161  template <typename I>
162  inline
164  : super_(image),
165  border_x2_(2 * image.border()),
166  row_offset_(image.bbox().ncols() + border_x2_),
167  next_sli_offset_(row_offset_ * border_x2_ + border_x2_),
168  next_srow_offset_(next_sli_offset_ + image.bbox().ncols()),
169  sli_offset_((image.bbox().ncols() + border_x2_) *
170  (image.bbox().nrows() + border_x2_))
171  {
172  mln_precondition(image.is_valid());
173  }
174 
175  template <typename I>
176  inline
177  void
179  {
180  eor_ = & opt::at(image_,
181  geom::min_sli(image_),
182  geom::min_row(image_),
183  geom::max_col(image_)) + 1;
184  eos_ = & opt::at(image_,
185  geom::min_sli(image_),
186  geom::max_row(image_),
187  geom::max_col(image_)) + 1;
188  }
189 
190  template <typename I>
191  inline
192  void
194  {
195  ++this->value_ptr_;
196  if (this->value_ptr_ == eos_ && this->value_ptr_ != this->eoi_)
197  {
198  this->value_ptr_ += next_sli_offset_;
199  eos_ += sli_offset_;
200  eor_ += next_srow_offset_;
201  }
202  else if (this->value_ptr_ == eor_ && this->value_ptr_ != this->eoi_)
203  {
204  this->value_ptr_ += border_x2_;
205  eor_ += row_offset_;
206  }
207  }
208 
209 
210  /*------------------.
211  | bkd_pixter3d<I>. |
212  `------------------*/
213 
214  template <typename I>
215  inline
217  : super_(image),
218  border_x2_(2 * image.border()),
219  row_offset_(image.bbox().ncols() + border_x2_),
220  next_sli_offset_(row_offset_ * border_x2_ + border_x2_),
221  next_srow_offset_(next_sli_offset_ + image.bbox().ncols()),
222  sli_offset_((image.bbox().ncols() + border_x2_) *
223  (image.bbox().nrows() + border_x2_))
224  {
225  mln_precondition(image.is_valid());
226  }
227 
228  template <typename I>
229  inline
230  void
232  {
233  bor_ = & opt::at(image_,
234  geom::max_sli(image_),
235  geom::max_row(image_),
236  geom::min_col(image_)) - 1;
237  bos_ = & opt::at(image_,
238  geom::max_sli(image_),
239  geom::min_row(image_),
240  geom::min_col(image_)) - 1;
241  }
242 
243  template <typename I>
244  inline
245  void
247  {
248  --this->value_ptr_;
249  if (this->value_ptr_ == bos_ && this->value_ptr_ != this->boi_)
250  {
251  this->value_ptr_ -= next_sli_offset_;
252  bos_ -= sli_offset_;
253  bor_ -= next_srow_offset_;
254  }
255  else if (this->value_ptr_ == bor_ && this->value_ptr_ != this->boi_)
256  {
257  this->value_ptr_ -= border_x2_;
258  bor_ -= row_offset_;
259  }
260  }
261 
262 #endif // ! MLN_INCLUDE_ONLY
263 
264 } // end of namespace mln
265 
266 
267 #endif // ! MLN_CORE_PIXTER3D_HH