$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
n_face.hh
1 // Copyright (C) 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_TOPO_N_FACE_HH
27 # define MLN_TOPO_N_FACE_HH
28 
32 
33 # include <iostream>
34 # include <vector>
35 
36 # include <mln/value/internal/limits.hh>
37 # include <mln/core/contract.hh>
38 # include <mln/metal/bool.hh>
39 
40 namespace mln
41 {
42 
43  namespace topo
44  {
45 
46  // Forward declaration.
47  template <unsigned D> class complex;
48  template <unsigned N, unsigned D> class face_data;
49  template <unsigned N, unsigned D> class algebraic_n_face;
50 
51 
52  /*---------.
53  | n-Face. |
54  `---------*/
55 
60  template <unsigned N, unsigned D>
61  class n_face
62  {
63  public:
64  // The type of the complex this handle points to.
66 
68  n_face();
70  n_face(complex<D>& complex, unsigned face_id);
71 
73  bool is_valid() const;
75  void invalidate();
76 
80  complex<D> cplx() const;
82  // FIXME: Rename as `id'?
83  unsigned face_id() const;
84 
86  void set_cplx(const complex<D>& cplx);
88  // FIXME: Rename as `dim'?
89  unsigned n() const;
91  void set_face_id(unsigned face_id);
93  void inc_face_id();
95  void dec_face_id();
96 
98  face_data<N, D>& data() const;
99 
100  /* FIXME: We should not provide lower_dim_adj_faces() when N ==
101  0 nor higher_dim_adj_faces() when N == D. */
103  std::vector< algebraic_n_face<N - 1, D> > lower_dim_adj_faces() const;
105  std::vector< algebraic_n_face<N + 1, D> > higher_dim_adj_faces() const;
107 
108  private:
112  mutable complex<D> cplx_;
114  // FIXME: Rename as `id_'?
115  unsigned face_id_;
116  };
117 
118 
121 
126  template <unsigned N, unsigned D>
127  bool operator==(const n_face<N, D>& lhs, const n_face<N, D>& rhs);
128 
133  template <unsigned N, unsigned D>
134  bool operator!=(const n_face<N, D>& lhs, const n_face<N, D>& rhs);
135 
142  template <unsigned N, unsigned D>
143  bool operator< (const n_face<N, D>& lhs, const n_face<N, D>& rhs);
144 
146 
147 
149  template <unsigned N, unsigned D>
150  std::ostream&
151  operator<<(std::ostream& ostr, const n_face<N, D>& f);
152 
153 
154 
155 # ifndef MLN_INCLUDE_ONLY
156 
157  template <unsigned N, unsigned D>
158  inline
160  : cplx_(), face_id_(value::internal::limits<unsigned>::max())
161  {
162  // Ensure N is compatible with D.
163  metal::bool_< N <= D >::check();
164  mln_postcondition(!is_valid());
165  }
166 
167  template <unsigned N, unsigned D>
168  inline
169  n_face<N, D>::n_face(complex<D>& c, unsigned face_id)
170  : cplx_(c), face_id_(face_id)
171  {
172  // Ensure N is compatible with D.
173  metal::bool_< N <= D >::check();
174  }
175 
176  template <unsigned N, unsigned D>
177  inline
178  bool
179  n_face<N, D>::is_valid() const
180  {
181  return face_id_ < cplx_.template nfaces_of_static_dim<N>();
182  }
183 
184  template <unsigned N, unsigned D>
185  inline
186  void
188  {
190  }
191 
192  template <unsigned N, unsigned D>
193  inline
194  complex<D>
195  n_face<N, D>::cplx() const
196  {
197  return cplx_;
198  }
199 
200  template <unsigned N, unsigned D>
201  inline
202  unsigned
203  n_face<N, D>::n() const
204  {
205  return N;
206  }
207 
208  template <unsigned N, unsigned D>
209  inline
210  unsigned
211  n_face<N, D>::face_id() const
212  {
213  return face_id_;
214  }
215 
216  template <unsigned N, unsigned D>
217  inline
218  void
219  n_face<N, D>::set_cplx(const complex<D>& cplx)
220  {
221  cplx_ = cplx;
222  }
223 
224  template <unsigned N, unsigned D>
225  inline
226  void
227  n_face<N, D>::set_face_id(unsigned face_id)
228  {
229  face_id_ = face_id;
230  }
231 
232  template <unsigned N, unsigned D>
233  inline
234  void
236  {
237  ++face_id_;
238  }
239 
240  template <unsigned N, unsigned D>
241  inline
242  void
244  {
245  --face_id_;
246  }
247 
248  template <unsigned N, unsigned D>
249  inline
251  n_face<N, D>::data() const
252  {
253  mln_precondition(is_valid());
254  return cplx_.template face_data_<N>(face_id_);
255  }
256 
257  template <unsigned N, unsigned D>
258  inline
259  std::vector< algebraic_n_face<N - 1, D> >
261  {
262  mln_precondition(N > 0);
263  mln_precondition(is_valid());
264  return cplx_.template face_data_<N>(face_id_).lower_dim_faces_;
265  }
266 
267  template <unsigned N, unsigned D>
268  inline
269  std::vector< algebraic_n_face<N + 1, D> >
271  {
272  mln_precondition(N <= D);
273  mln_precondition(is_valid());
274  return cplx_.template face_data_<N>(face_id_).higher_dim_faces_;
275  }
276 
277 
278  template <unsigned N, unsigned D>
279  inline
280  bool
281  operator==(const n_face<N, D>& lhs, const n_face<N, D>& rhs)
282  {
283  // Ensure LHS and RHS belong to the same complex.
284  mln_precondition(lhs.cplx() == rhs.cplx());
285  return lhs.face_id() == rhs.face_id();
286  }
287 
288  template <unsigned N, unsigned D>
289  inline
290  bool
291  operator!=(const n_face<N, D>& lhs, const n_face<N, D>& rhs)
292  {
293  // Ensure LHS and RHS belong to the same complex.
294  mln_precondition(lhs.cplx() == rhs.cplx());
295  return !(lhs == rhs);
296  }
297 
298  template <unsigned N, unsigned D>
299  inline
300  bool
301  operator< (const n_face<N, D>& lhs, const n_face<N, D>& rhs)
302  {
303  // Ensure LHS and RHS belong to the same complex.
304  mln_precondition(lhs.cplx() == rhs.cplx());
305  return lhs.face_id() < rhs.face_id();
306  }
307 
308 
309  template <unsigned N, unsigned D>
310  inline
311  std::ostream&
312  operator<<(std::ostream& ostr, const n_face<N, D>& f)
313  {
314  return ostr << "(cplx = " << f.cplx().addr() << ", dim = " << f.n()
315  << ", id = " << f.face_id() << ')';
316  }
317 
318 # endif // ! MLN_INCLUDE_ONLY
319 
320  } // end of namespace mln::topo
321 
322 } // end of namespace mln
323 
324 #endif // ! MLN_TOPO_N_FACE_HH