Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
pixel_iterator_base.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_INTERNAL_PIXEL_ITERATOR_BASE_HH
27 # define MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH
28 
32 
33 # include <mln/core/concept/pixel_iterator.hh>
34 # include <mln/core/internal/pixel_impl.hh>
35 # include <mln/core/trait/qlf_value.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace internal
42  {
43 
44  /*---------------------------------------.
45  | internal::pixel_iterator_base_<I, E>. |
46  `---------------------------------------*/
47 
49  template <typename I, typename E>
50  class pixel_iterator_base_ : public Pixel_Iterator<E>,
51  public internal::pixel_impl_<I, E>
52  {
53  typedef internal::pixel_impl_<I, E> super_;
54 
55  protected:
57  pixel_iterator_base_(I& image);
58 
59  protected:
60 
62  mln_qlf_value(I)* boi_;
63 
65  mln_qlf_value(I)* eoi_;
66 
68  void start_();
69  };
70 
71 
72  /*-----------------------------------------------.
73  | internal::forward_pixel_iterator_base_<I, E>. |
74  `-----------------------------------------------*/
75 
77  template <typename I, typename E>
78  class forward_pixel_iterator_base_ : public pixel_iterator_base_<I, E>
79  {
80  typedef pixel_iterator_base_<I, E> super_;
81 
82  public:
83 
87  void start();
89  void invalidate();
91  bool is_valid() const;
93 
94  protected:
95 
97  forward_pixel_iterator_base_(I& image);
98  };
99 
100 
101  /*------------------------------------------------.
102  | internal::backward_pixel_iterator_base_<I, E>. |
103  `------------------------------------------------*/
104 
106  template <typename I, typename E>
107  class backward_pixel_iterator_base_ : public pixel_iterator_base_<I, E>
108  {
109  typedef pixel_iterator_base_<I, E> super_;
110 
111  public:
115  void start();
117  void invalidate();
119  bool is_valid() const;
121 
122  protected:
123 
125  backward_pixel_iterator_base_(I& image);
126  };
127 
128 
129 
130 #ifndef MLN_INCLUDE_ONLY
131 
132 
133  /*---------------------------------------.
134  | internal::pixel_iterator_base_<I, E>. |
135  `---------------------------------------*/
136 
137  template <typename I, typename E>
138  inline
139  pixel_iterator_base_<I, E>::pixel_iterator_base_(I& image)
140  : super_(image)
141  {
142  mln_precondition(image.is_valid());
143  I& ima = this->image_;
144  boi_ = & ima( ima.domain().pmin() ) - 1;
145  eoi_ = & ima( ima.domain().pmax() ) + 1;
146  exact(*this).invalidate();
147  }
148 
149  template <typename I, typename E>
150  inline
151  void
152  pixel_iterator_base_<I, E>::start_()
153  {
154  // Default impl is no-op.
155  }
156 
157 
158  /*-----------------------------------------------.
159  | internal::forward_pixel_iterator_base_<I, E>. |
160  `-----------------------------------------------*/
161 
162  template <typename I, typename E>
163  inline
164  forward_pixel_iterator_base_<I, E>::forward_pixel_iterator_base_(I& image)
165  : super_(image)
166  {
167  }
168 
169  template <typename I, typename E>
170  inline
171  void
172  forward_pixel_iterator_base_<I, E>::start()
173  {
174  this->value_ptr_ = this->boi_ + 1;
175  exact(this)->start_();
176  }
177 
178  template <typename I, typename E>
179  inline
180  void
181  forward_pixel_iterator_base_<I, E>::invalidate()
182  {
183  this->value_ptr_ = this->eoi_;
184  }
185 
186  template <typename I, typename E>
187  inline
188  bool
189  forward_pixel_iterator_base_<I, E>::is_valid() const
190  {
191  return this->value_ptr_ != this->eoi_;
192  }
193 
194 
195  /*------------------------------------------------.
196  | internal::backward_pixel_iterator_base_<I, E>. |
197  `------------------------------------------------*/
198 
199  template <typename I, typename E>
200  inline
201  backward_pixel_iterator_base_<I, E>::backward_pixel_iterator_base_(I& image)
202  : super_(image)
203  {
204  }
205 
206  template <typename I, typename E>
207  inline
208  void
209  backward_pixel_iterator_base_<I, E>::start()
210  {
211  this->value_ptr_ = this->eoi_ - 1;
212  exact(this)->start_();
213  }
214 
215  template <typename I, typename E>
216  inline
217  void
218  backward_pixel_iterator_base_<I, E>::invalidate()
219  {
220  this->value_ptr_ = this->boi_;
221  }
222 
223  template <typename I, typename E>
224  inline
225  bool
226  backward_pixel_iterator_base_<I, E>::is_valid() const
227  {
228  return this->value_ptr_ != this->boi_;
229  }
230 
231 #endif // ! MLN_INCLUDE_ONLY
232 
233  } // end of namespace internal
234 
235 } // end of namespace mln
236 
237 
238 #endif // ! MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH