$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
complex_relative_iterator_base.hh
1 // Copyright (C) 2008, 2009, 2011, 2012 EPITA Research and Development
2 // 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_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_BASE_HH
28 # define MLN_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_BASE_HH
29 
50 # include <vector>
51 
52 # include <mln/topo/internal/complex_iterator_base.hh>
53 
54 /* FIXME: By moving iterator `i_' into
55  internal::complex_relative_iterator_base, we'll be able to factor
56  more methods (do_next_, update_f); this requires the type of this
57  iterator be passed as an extra parameter to
58  internal::complex_relative_iterator_base. */
59 
60 
61 namespace mln
62 {
63 
64  namespace topo
65  {
66 
67  namespace internal
68  {
69 
70  // Forward declaration.
71  template <typename F, typename E>
72  class complex_iterator_base;
73 
74 
75  /*----------------------------------------------------------.
76  | topo::internal::complex_relative_iterator_base<C, F, E>. |
77  `----------------------------------------------------------*/
78 
87  template <typename C, typename F, typename E>
89  public complex_iterator_base<F, E>
90  {
92 
93  public:
95  typedef C center_type;
97  typedef F face_type;
98 
102  template <typename Fref>
103  complex_relative_iterator_base(const Fref& f_ref);
105 
109  void center_at(const center_type& c);
110 
112  void start();
114  void next_();
116 
117  protected:
120  const center_type* c_;
121 
122  // The type of the set of vicinity sites (adjacent face handles).
123  typedef std::vector<face_type> adj_faces_t;
126  };
127 
128 
129 
130  /*------------------------------------------------------------------.
131  | topo::internal::forward_complex_relative_iterator_base<C, F, E>. |
132  `------------------------------------------------------------------*/
133 
143  template <typename C, typename F, typename E>
145  : public complex_relative_iterator_base<C, F, E>
146  {
149 
150  public:
151  typedef F face_type;
152 
153  public:
157  template <typename Fref>
158  forward_complex_relative_iterator_base(const Fref& f_ref);
160 
161  public:
165  bool is_valid() const;
167  void invalidate();
168 
170  void do_start_();
172  void do_next_();
173 
175  void update_f_();
177 
178  protected:
180  typename super_::adj_faces_t::const_iterator i_;
181  };
182 
183 
184  /*-------------------------------------------------------------------.
185  | topo::internal::backward_complex_relative_iterator_base<C, F, E>. |
186  `-------------------------------------------------------------------*/
187 
197  template <typename C, typename F, typename E>
199  : public complex_relative_iterator_base<C, F, E>
200  {
203 
204  public:
205  typedef F face_type;
206 
207  public:
211  template <typename Fref>
212  backward_complex_relative_iterator_base(const Fref& f_ref);
214 
215  public:
219  bool is_valid() const;
221  void invalidate();
222 
224  void do_start_();
226  void do_next_();
227 
229  void update_f_();
231 
232  protected:
234  typename super_::adj_faces_t::const_reverse_iterator i_;
235  };
236 
237 
238 
239 # ifndef MLN_INCLUDE_ONLY
240 
241  /*----------------------------------------------------------.
242  | topo::internal::complex_relative_iterator_base<C, F, E>. |
243  `----------------------------------------------------------*/
244 
245  template <typename C, typename F, typename E>
246  inline
248  : c_(0)
249  {
250  // Check for required methods in E.
251  void (E::*m)() = & E::update_adj_faces_;
252  (void) m;
253 
254  exact(this)->invalidate();
255  }
256 
257  template <typename C, typename F, typename E>
258  template <typename Fref>
259  inline
260  complex_relative_iterator_base<C, F, E>::complex_relative_iterator_base(const Fref& f_ref)
261  {
262  // Check for required methods in E.
263  void (E::*m)() = & E::update_adj_faces_;
264  (void) m;
265 
266  center_at(f_ref);
267  }
268 
269  template <typename C, typename F, typename E>
270  inline
271  void
272  complex_relative_iterator_base<C, F, E>::center_at(const C& c)
273  {
274  c_ = &c;
275  exact(this)->invalidate();
276  }
277 
278  template <typename C, typename F, typename E>
279  inline
280  void
281  complex_relative_iterator_base<C, F, E>::start()
282  {
283  exact(this)->do_start_();
284  if (exact(this)->is_valid())
285  exact(this)->update_f_();
286  }
287 
288  template <typename C, typename F, typename E>
289  inline
290  void
291  complex_relative_iterator_base<C, F, E>::next_()
292  {
293  exact(this)->do_next_();
294  if (exact(this)->is_valid())
295  exact(this)->update_f_();
296  }
297 
298 
299 
300  /*------------------------------------------------------------------.
301  | topo::internal::forward_complex_relative_iterator_base<C, F, E>. |
302  `------------------------------------------------------------------*/
303 
304  template <typename C, typename F, typename E>
305  inline
306  forward_complex_relative_iterator_base<C, F, E>::forward_complex_relative_iterator_base()
307  {
308  }
309 
310  template <typename C, typename F, typename E>
311  template <typename Fref>
312  inline
313  forward_complex_relative_iterator_base<C, F, E>::forward_complex_relative_iterator_base(const Fref& f_ref)
314  : super_(f_ref)
315  {
316  }
317 
318  template <typename C, typename F, typename E>
319  inline
320  bool
321  forward_complex_relative_iterator_base<C, F, E>::is_valid() const
322  {
323  return i_ != this->adj_faces_.end();
324  }
325 
326  template <typename C, typename F, typename E>
327  inline
328  void
329  forward_complex_relative_iterator_base<C, F, E>::invalidate()
330  {
331  i_ = this->adj_faces_.end();
332  }
333 
334  template <typename C, typename F, typename E>
335  inline
336  void
337  forward_complex_relative_iterator_base<C, F, E>::do_start_()
338  {
339  exact(this)->update_adj_faces_();
340  i_ = this->adj_faces_.begin();
341  }
342 
343  template <typename C, typename F, typename E>
344  inline
345  void
346  forward_complex_relative_iterator_base<C, F, E>::do_next_()
347  {
348  ++i_;
349  }
350 
351  template <typename C, typename F, typename E>
352  inline
353  void
354  forward_complex_relative_iterator_base<C, F, E>::update_f_()
355  {
356  mln_precondition(is_valid());
357  this->f_ = *i_;
358  }
359 
360 
361  /*-------------------------------------------------------------------.
362  | topo::internal::backward_complex_relative_iterator_base<C, F, E>. |
363  `-------------------------------------------------------------------*/
364 
365  template <typename C, typename F, typename E>
366  inline
367  backward_complex_relative_iterator_base<C, F, E>::backward_complex_relative_iterator_base()
368  {
369  }
370 
371  template <typename C, typename F, typename E>
372  template <typename Fref>
373  inline
374  backward_complex_relative_iterator_base<C, F, E>::backward_complex_relative_iterator_base(const Fref& f_ref)
375  : super_(f_ref)
376  {
377  }
378 
379  template <typename C, typename F, typename E>
380  inline
381  bool
382  backward_complex_relative_iterator_base<C, F, E>::is_valid() const
383  {
384  return i_ != this->adj_faces_.rend();
385  }
386 
387  template <typename C, typename F, typename E>
388  inline
389  void
390  backward_complex_relative_iterator_base<C, F, E>::invalidate()
391  {
392  i_ = this->adj_faces_.rend();
393  }
394 
395  template <typename C, typename F, typename E>
396  inline
397  void
398  backward_complex_relative_iterator_base<C, F, E>::do_start_()
399  {
400  exact(this)->update_adj_faces_();
401  i_ = this->adj_faces_.rbegin();
402  }
403 
404  template <typename C, typename F, typename E>
405  inline
406  void
407  backward_complex_relative_iterator_base<C, F, E>::do_next_()
408  {
409  ++i_;
410  }
411 
412  template <typename C, typename F, typename E>
413  inline
414  void
415  backward_complex_relative_iterator_base<C, F, E>::update_f_()
416  {
417  mln_precondition(is_valid());
418  this->f_ = *i_;
419  }
420 
421 # endif // ! MLN_INCLUDE_ONLY
422 
423  } // end of namespace mln::topo::internal
424 
425  } // end of namespace mln::topo
426 
427 } // end of namespace mln
428 
429 #endif // ! MLN_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_BASE_HH