$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pixter2d.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_PIXTER2D_HH
28 # define MLN_CORE_PIXTER2D_HH
29 
33 
34 # include <mln/core/internal/pixel_iterator_base.hh>
35 # include <mln/core/alias/point2d.hh>
36 # include <mln/geom/size2d.hh>
37 # include <mln/opt/at.hh>
38 
39 namespace mln
40 {
41 
42  /*------------------.
43  | fwd_pixter2d<I>. |
44  `------------------*/
45 
50  template <typename I>
52  : public internal::forward_pixel_iterator_base_< I, fwd_pixter2d<I> >
53  {
55 
56  public:
58  typedef I image;
59 
62  fwd_pixter2d(I& image);
63 
64 
67  void next_();
68 
70  void start_();
71 
72  private:
73 
75  unsigned border_x2_;
76 
78  unsigned row_offset_;
79 
81  mln_qlf_value(I)* eor_;
82 
83  using super_::image_;
84 
86  };
87 
88 
89  /*------------------.
90  | bkd_pixter2d<I>. |
91  `------------------*/
92 
97  template <typename I>
99  : public internal::backward_pixel_iterator_base_< I, bkd_pixter2d<I> >
100  {
102 
103  public:
105  typedef I image;
106 
109  bkd_pixter2d(I& image);
110 
111 
114  void next_();
115 
117  void start_();
118 
119  private:
120 
122  unsigned border_x2_;
123 
125  unsigned row_offset_;
126 
128  mln_qlf_value(I)* bor_;
129 
130  using super_::image_;
131 
133  };
134 
135 
136 
137 #ifndef MLN_INCLUDE_ONLY
138 
139  /*------------------.
140  | fwd_pixter2d<I>. |
141  `------------------*/
142 
143  template <typename I>
144  inline
146  : super_(image),
147  border_x2_(2 * image.border()),
148  row_offset_(image.bbox().ncols() + border_x2_)
149  {
150  mln_precondition(image.is_valid());
151  mln_precondition(image_.is_valid());
152  mln_precondition(image_.buffer() == image.buffer());
153  }
154 
155  template <typename I>
156  inline
157  void
159  {
160  ++this->value_ptr_;
161  if (this->value_ptr_ == eor_ && this->value_ptr_ != this->eoi_)
162  {
163  this->value_ptr_ += border_x2_;
164  eor_ += row_offset_;
165  }
166  }
167 
168  template <typename I>
169  inline
170  void
172  {
173  mln_precondition(image_.is_valid());
174  eor_ = & opt::at(image_, geom::min_row(image_), geom::max_col(image_)) + 1;
175  }
176 
177 
178  /*------------------.
179  | fwd_pixter2d<I>. |
180  `------------------*/
181 
182  template <typename I>
183  inline
185  : super_(image),
186  border_x2_(2 * image.border()),
187  row_offset_(image.bbox().ncols() + border_x2_)
188  {
189  mln_precondition(image.is_valid());
190  }
191 
192  template <typename I>
193  inline
194  void
196  {
197  --this->value_ptr_;
198  if (this->value_ptr_ == bor_ && this->value_ptr_ != this->boi_)
199  {
200  this->value_ptr_ -= border_x2_;
201  bor_ -= row_offset_;
202  }
203  }
204 
205  template <typename I>
206  inline
207  void
209  {
210  bor_ = & opt::at(image_, geom::max_row(image_), geom::min_col(image_)) - 1;
211  }
212 
213 #endif // ! MLN_INCLUDE_ONLY
214 
215 } // end of namespace mln
216 
217 #endif // ! MLN_CORE_PIXTER2D_HH