$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
n_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_N_FACE_ITER_HH
28 # define MLN_TOPO_N_FACE_ITER_HH
29 
34 
35 # include <mln/topo/internal/complex_set_iterator_base.hh>
36 # include <mln/topo/face.hh>
37 
38 // \todo Factor a bit more? (Using complex_set_iterator_base.)
39 
40 // FIXME: Rename the old commplex_faces_{fwd,bkd}_iter as
41 // static_n_face_{fwd,bkd}_iter.
42 
43 
44 namespace mln
45 {
46 
47  namespace topo
48  {
49 
50  // Forward declarations.
51  template <unsigned D> class complex;
52 
53  namespace internal
54  {
55 
56  // Forward declaration.
57  template <typename F, typename E>
58  class complex_set_iterator_base;
59 
60  } // end of namespace mln::topo::internal
61 
62 
63  /*---------------------------.
64  | topo::n_face_fwd_iter<D>. |
65  `---------------------------*/
66 
74  template <unsigned D>
76  : public internal::complex_set_iterator_base< topo::face<D>,
77  n_face_fwd_iter<D> >
78  {
79  // Tech note: we use topo::face to help g++-2.95.
80  private:
81  typedef n_face_fwd_iter<D> self_;
83 
84  public:
85  using super_::is_valid;
86  using super_::invalidate;
87 
88  public:
92  // FIXME: See comment in internal::complex_set_iterator_base's
93  // default ctor.
94  n_face_fwd_iter(complex<D>& c, unsigned n);
96 
100  void start();
102  void next_();
104 
109  unsigned n() const;
110  void set_n (unsigned n);
112 
113  private:
115  void invalidate_face_id_();
116 
117  private:
118  using super_::f_;
119  };
120 
121 
122  /*---------------------------.
123  | topo::n_face_bkd_iter<D>. |
124  `---------------------------*/
125 
132  template <unsigned D>
134  : public internal::complex_set_iterator_base< topo::face<D>,
135  n_face_bkd_iter<D> >
136  {
137  // Tech note: we use topo::face to help g++-2.95.
138  private:
139  typedef n_face_bkd_iter<D> self_;
141 
142  public:
143  using super_::is_valid;
144  using super_::invalidate;
145 
146  public:
149  n_face_bkd_iter();
150  // FIXME: See comment in internal::complex_set_iterator_base's
151  // default ctor.
152  n_face_bkd_iter(complex<D>& c, unsigned n);
154 
158  void start();
160  void next_();
162 
167  unsigned n() const;
168  void set_n (unsigned n);
170 
171  private:
173  void invalidate_face_id_();
174 
175  private:
176  using super_::f_;
177  };
178 
179 
180 
181 # ifndef MLN_INCLUDE_ONLY
182 
183  /*---------------------------.
184  | topo::n_face_fwd_iter<D>. |
185  `---------------------------*/
186 
187  template <unsigned D>
188  inline
190  : super_()
191  {
192  }
193 
194  template <unsigned D>
195  inline
196  n_face_fwd_iter<D>::n_face_fwd_iter(complex<D>& c, unsigned n)
197  : super_(c)
198  {
199  mln_precondition(n <= D);
200  this->set_cplx(c);
201  set_n(n);
202  mln_postcondition(!is_valid());
203  }
204 
205  template <unsigned D>
206  inline
207  void
209  {
210  f_.set_face_id(0u);
211  }
212 
213  template <unsigned D>
214  inline
215  void
217  {
218  if (is_valid())
219  {
220  if (f_.face_id() + 1 < f_.cplx().nfaces_of_dim(n()))
221  f_.inc_face_id();
222  else
223  /* Don't invalidate the whole face if we have reached the
224  last face of the dimension---this would lose the
225  dimension. Instead, invalidate the face_id only. */
226  invalidate_face_id_();
227  }
228  }
229 
230  template <unsigned D>
231  inline
232  void
233  n_face_fwd_iter<D>::invalidate_face_id_()
234  {
235  f_.set_face_id(f_.cplx().nfaces_of_dim(n()));
236  }
237 
238  template <unsigned D>
239  inline
240  unsigned
241  n_face_fwd_iter<D>::n() const
242  {
243  return f_.n();
244  }
245 
246  template <unsigned D>
247  inline
248  void
249  n_face_fwd_iter<D>::set_n(unsigned n)
250  {
251  mln_precondition(n <= D);
252  f_.set_n(n);
253  }
254 
255 
256  /*---------------------------.
257  | topo::n_face_bkd_iter<D>. |
258  `---------------------------*/
259 
260  template <unsigned D>
261  inline
263  : super_()
264  {
265  }
266 
267  template <unsigned D>
268  inline
269  n_face_bkd_iter<D>::n_face_bkd_iter(complex<D>& c, unsigned n)
270  : super_(c)
271  {
272  mln_precondition(n <= D);
273  set_cplx(c);
274  set_n(n);
275  mln_postcondition(!is_valid());
276  }
277 
278  template <unsigned D>
279  inline
280  void
282  {
283  f_.set_face_id(f_.cplx().nfaces_of_dim(n()) - 1);
284  }
285 
286  template <unsigned D>
287  inline
288  void
290  {
291  if (is_valid())
292  {
293  if (f_.face_id() > 0)
294  f_.dec_face_id();
295  else
296  /* Don't invalidate the whole face if we have reached the
297  last face of the dimension---this would lose the
298  dimension. Instead, invalidate the face_id only. */
299  invalidate_face_id_();
300  }
301  }
302 
303  template <unsigned D>
304  inline
305  void
306  n_face_bkd_iter<D>::invalidate_face_id_()
307  {
308  f_.set_face_id(f_.cplx().nfaces_of_dim(n()));
309  }
310 
311  template <unsigned D>
312  inline
313  unsigned
314  n_face_bkd_iter<D>::n() const
315  {
316  return f_.n();
317  }
318 
319  template <unsigned D>
320  inline
321  void
322  n_face_bkd_iter<D>::set_n(unsigned n)
323  {
324  mln_precondition(n <= D);
325  f_.set_n(n);
326  }
327 
328 # endif // ! MLN_INCLUDE_ONLY
329 
330  } // end of namespace mln::topo
331 
332 } // end of namespace mln
333 
334 #endif // ! MLN_TOPO_N_FACE_ITER_HH