$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
face_iter.hh
1 // Copyright (C) 2008, 2009, 2012, 2013 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_FACE_ITER_HH
28 # define MLN_TOPO_FACE_ITER_HH
29 
34 
35 # include <mln/topo/internal/complex_set_iterator_base.hh>
36 # include <mln/topo/face.hh>
37 # include <mln/topo/face_iter.hh>
38 
39 // FIXME: Factor a bit more? (Using complex_set_iterator_base.)
40 
41 
42 namespace mln
43 {
44 
45  namespace topo
46  {
47 
48  // Forward declarations.
49  template <unsigned D> class complex;
50 
51  namespace internal
52  {
53 
54  template <typename F, typename E>
55  class complex_set_iterator_base;
56 
57  } // end of namespace mln::topo::internal
58 
59 
60  /*-------------------------.
61  | topo::face_fwd_iter<D>. |
62  `-------------------------*/
63 
71  template <unsigned D>
73  : public internal::complex_set_iterator_base< topo::face<D>, face_fwd_iter<D> >
74  {
75  // Tech note: we use topo::face to help g++-2.95.
76  private:
77  typedef face_fwd_iter<D> self_;
79 
80  public:
81  using super_::is_valid;
82  using super_::invalidate;
83 
84  public:
87  face_fwd_iter();
88  // FIXME: See comment in internal::complex_set_iterator_base's
89  // default ctor.
92 
96  void start();
98  void next_();
100 
101  private:
102  using super_::f_;
103  };
104 
105 
106  /*-------------------------.
107  | topo::face_bkd_iter<D>. |
108  `-------------------------*/
109 
116  template <unsigned D>
118  : public internal::complex_set_iterator_base< topo::face<D>, face_bkd_iter<D> >
119  {
120  // Tech note: we use topo::face to help g++-2.95.
121  private:
122  typedef face_bkd_iter<D> self_;
124 
125  public:
126  using super_::is_valid;
127  using super_::invalidate;
128 
129  public:
132  face_bkd_iter();
133  // FIXME: See comment in internal::complex_set_iterator_base's
134  // default ctor.
137 
141  void start();
143  void next_();
145 
146  private:
147  using super_::f_;
148  };
149 
150 
151 
152 # ifndef MLN_INCLUDE_ONLY
153 
154  /*-------------------------.
155  | topo::face_fwd_iter<D>. |
156  `-------------------------*/
157 
158  template <unsigned D>
159  inline
161  : super_()
162  {
163  }
164 
165  template <unsigned D>
166  inline
167  face_fwd_iter<D>::face_fwd_iter(complex<D>& c)
168  : super_(c)
169  {
170  this->set_cplx(c);
171  mln_postcondition(!is_valid());
172  }
173 
174  template <unsigned D>
175  inline
176  void
178  {
179  f_.set_n(0u);
180  f_.set_face_id(0u);
181  }
182 
183  template <unsigned D>
184  inline
185  void
187  {
188  if (is_valid())
189  {
190  if (f_.face_id() + 1 < f_.cplx().nfaces_of_dim(f_.n()))
191  f_.inc_face_id();
192  else
193  // Start to iterate on the faces of the next dimension if
194  // possible.
195  if (f_.n() <= D)
196  {
197  f_.inc_n();
198  f_.set_face_id(0u);
199  }
200  else
201  invalidate();
202  }
203  }
204 
205 
206  /*-------------------------.
207  | topo::face_bkd_iter<D>. |
208  `-------------------------*/
209 
210  template <unsigned D>
211  inline
213  : super_()
214  {
215  }
216 
217  template <unsigned D>
218  inline
219  face_bkd_iter<D>::face_bkd_iter(complex<D>& c)
220  : super_(c)
221  {
222  this->set_cplx(c);
223  mln_postcondition(!is_valid());
224  }
225 
226  template <unsigned D>
227  inline
228  void
230  {
231  f_.set_n(D);
232  f_.set_face_id(f_.cplx().template nfaces_of_static_dim<D>() - 1);
233  }
234 
235  template <unsigned D>
236  inline
237  void
239  {
240  if (is_valid())
241  {
242  if (f_.face_id() > 0)
243  f_.dec_face_id();
244  else
245  // Start to iterate on the faces of the previous dimension
246  // if it exists.
247  if (f_.n() > 0)
248  {
249  f_.dec_n();
250  f_.set_face_id(f_.cplx().nfaces_of_dim(f_.n()) - 1);
251  }
252  else
253  invalidate();
254  }
255  }
256 
257 # endif // ! MLN_INCLUDE_ONLY
258 
259  } // end of namespace mln::topo
260 
261 } // end of namespace mln
262 
263 #endif // ! MLN_TOPO_FACE_ITER_HH