Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
pixter2d.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_PIXTER2D_HH
27 # define MLN_CORE_PIXTER2D_HH
28 
32 
33 # include <mln/core/internal/pixel_iterator_base.hh>
34 # include <mln/core/alias/point2d.hh>
35 # include <mln/geom/size2d.hh>
36 # include <mln/opt/at.hh>
37 
38 namespace mln
39 {
40 
41  /*------------------.
42  | fwd_pixter2d<I>. |
43  `------------------*/
44 
46  template <typename I>
48  : public internal::forward_pixel_iterator_base_< I, fwd_pixter2d<I> >
49  {
50  typedef internal::forward_pixel_iterator_base_< I, fwd_pixter2d<I> > super_;
51 
52  public:
54  typedef I image;
55 
58  fwd_pixter2d(I& image);
59 
61  void next_();
62 
64  void start_();
65 
66  private:
67 
69  unsigned border_x2_;
70 
72  unsigned row_offset_;
73 
75  mln_qlf_value(I)* eor_;
76 
77  using super_::image_;
78  };
79 
80 
81  /*------------------.
82  | bkd_pixter2d<I>. |
83  `------------------*/
84 
86  template <typename I>
88  : public internal::backward_pixel_iterator_base_< I, bkd_pixter2d<I> >
89  {
90  typedef internal::backward_pixel_iterator_base_< I, bkd_pixter2d<I> > super_;
91 
92  public:
94  typedef I image;
95 
98  bkd_pixter2d(I& image);
99 
101  void next_();
102 
104  void start_();
105 
106  private:
107 
109  unsigned border_x2_;
110 
112  unsigned row_offset_;
113 
115  mln_qlf_value(I)* bor_;
116 
117  using super_::image_;
118  };
119 
120 
121 
122 #ifndef MLN_INCLUDE_ONLY
123 
124  /*------------------.
125  | fwd_pixter2d<I>. |
126  `------------------*/
127 
128  template <typename I>
129  inline
131  : super_(image),
132  border_x2_(2 * image.border()),
133  row_offset_(image.bbox().ncols() + border_x2_)
134  {
135  mln_precondition(image.is_valid());
136  mln_precondition(image_.is_valid());
137  mln_precondition(image_.buffer() == image.buffer());
138  }
139 
140  template <typename I>
141  inline
142  void
144  {
145  ++this->value_ptr_;
146  if (this->value_ptr_ == eor_ && this->value_ptr_ != this->eoi_)
147  {
148  this->value_ptr_ += border_x2_;
149  eor_ += row_offset_;
150  }
151  }
152 
153  template <typename I>
154  inline
155  void
156  fwd_pixter2d<I>::start_()
157  {
158  mln_precondition(image_.is_valid());
159  eor_ = & opt::at(image_, geom::min_row(image_), geom::max_col(image_)) + 1;
160  }
161 
162 
163  /*------------------.
164  | fwd_pixter2d<I>. |
165  `------------------*/
166 
167  template <typename I>
168  inline
170  : super_(image),
171  border_x2_(2 * image.border()),
172  row_offset_(image.bbox().ncols() + border_x2_)
173  {
174  mln_precondition(image.is_valid());
175  }
176 
177  template <typename I>
178  inline
179  void
181  {
182  --this->value_ptr_;
183  if (this->value_ptr_ == bor_ && this->value_ptr_ != this->boi_)
184  {
185  this->value_ptr_ -= border_x2_;
186  bor_ -= row_offset_;
187  }
188  }
189 
190  template <typename I>
191  inline
192  void
193  bkd_pixter2d<I>::start_()
194  {
195  bor_ = & opt::at(image_, geom::max_row(image_), geom::min_col(image_)) - 1;
196  }
197 
198 #endif // ! MLN_INCLUDE_ONLY
199 
200 } // end of namespace mln
201 
202 #endif // ! MLN_CORE_PIXTER2D_HH