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