$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_faces.hh
1 // Copyright (C) 2008, 2009, 2011, 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_CORE_SITE_SET_P_FACES_HH
28 # define MLN_CORE_SITE_SET_P_FACES_HH
29 
34 
35 # include <mln/core/internal/site_set_base.hh>
36 
37 # include <mln/topo/complex.hh>
38 
39 # include <mln/core/faces_psite.hh>
40 
41 // FIXME: Disabled (moved to the attic).
42 # if 0
43 # include <mln/core/site_set/p_faces_piter.hh>
44 # endif
45 
46 # include <mln/core/site_set/p_complex.hh>
47 
48 
49 namespace mln
50 {
51 
52  // Forward declarations.
53  template <unsigned N, unsigned D, typename P> struct p_faces;
54 
55  template <unsigned N, unsigned D, typename P> class p_faces_fwd_piter_;
56  template <unsigned N, unsigned D, typename P> class p_faces_bkd_piter_;
57 
58 
59  namespace trait
60  {
61  template <unsigned N, unsigned D, typename P>
62  struct site_set_< p_faces<N, D, P> >
63  {
64  typedef trait::site_set::nsites::known nsites;
65  // FIXME: Depends on P!
66  typedef trait::site_set::bbox::unknown bbox;
67  typedef trait::site_set::contents::fixed contents;
68  typedef trait::site_set::arity::unique arity;
69  };
70  } // end of namespace mln::trait
71 
72 
77  template <unsigned N, unsigned D, typename P>
78  struct p_faces
79  : public internal::site_set_base_< faces_psite<N, D, P>,
80  p_faces<N, D, P> >
81  {
84 
89 
95  p_faces(const p_complex<D, P>& pc);
96 
100  typedef mln_site(super_) element;
101 
103  typedef faces_psite<N, D, P> psite;
104 
105  // FIXME: Fake.
107  typedef p_faces_fwd_piter_<N, D, P> fwd_piter;
108 
109  // FIXME: Fake.
111  typedef p_faces_bkd_piter_<N, D, P> bkd_piter;
112 
114  typedef fwd_piter piter;
116 
123  unsigned nsites() const;
124 
126  unsigned nfaces() const;
127 
128  // FIXME: This method is probably useless now.
130  bool is_valid() const;
131 
132  bool has(const psite& p) const;
133 
134  // FIXME: Dummy.
135  std::size_t memory_size() const;
136 
141  /* FIXME: Move back the const qualifier on this return type (see
142  comment below on cplx_). */
143  topo::complex<D>& cplx() const;
146  topo::complex<D>& cplx();
148 
149  private:
151  /* FIXME: Get rid of this `mutable' qualifier. This is needed for
152  compatiblity reasons with face_handle (see p_faces_piter).
153 
154  We should either
155 
156  - have an additional version of face_handle holding a const
157  (not mutable) complex;
158 
159  - have face_handle and any_face_handle do not hold a reference
160  on a complex, leading to a design of complexes similar to
161  graphs, where vertex and edge handles (named `id's) are not
162  tied to a specific graph. */
163  mutable topo::complex<D> cplx_;
164  };
165 
166 
172  template <unsigned N, unsigned D, typename P>
173  bool
174  operator==(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs);
175 
185  template <unsigned N, unsigned D, typename P>
186  bool
187  operator<=(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs);
188 
189 
190 
191 # ifndef MLN_INCLUDE_ONLY
192 
193  template <unsigned N, unsigned D, typename P>
194  inline
196  : cplx_(cplx)
197  {
198  // Ensure N is compatible with D.
199  metal::bool_< N <= D >::check();
200  }
201 
202  template <unsigned N, unsigned D, typename P>
203  inline
205  : cplx_(pc.cplx())
206  {
207  // Ensure N is compatible with D.
208  metal::bool_< N <= D >::check();
209  }
210 
211  template <unsigned N, unsigned D, typename P>
212  inline
213  unsigned
215  {
216  return nfaces();
217  }
218 
219  template <unsigned N, unsigned D, typename P>
220  inline
221  unsigned
223  {
224  return cplx_.template nfaces_of_static_dim<N>();
225  }
226 
227  template <unsigned N, unsigned D, typename P>
228  inline
229  bool
231  {
232  return true;
233  }
234 
235  template <unsigned N, unsigned D, typename P>
236  inline
237  bool
238  p_faces<N, D, P>::has(const psite& p) const
239  {
240  mln_precondition(is_valid());
241  return
242  // Check whether P's complex is compatible with this pset's complex.
243  (p.site_set() == *this) &&
244  // Check whether P is valid.
245  (p.is_valid());
246  }
247 
248  template <unsigned N, unsigned D, typename P>
249  inline
250  std::size_t
252  {
253  // FIXME: Dummy; implement (see other site sets).
254  abort();
255  return 0;
256  }
257 
258  template <unsigned N, unsigned D, typename P>
259  topo::complex<D>&
260  p_faces<N, D, P>::cplx() const
261  {
262  mln_precondition(is_valid());
263  return cplx_;
264  }
265 
266  template <unsigned N, unsigned D, typename P>
267  topo::complex<D>&
269  {
270  mln_precondition(is_valid());
271  return cplx_;
272  }
273 
274 
275  /*--------------.
276  | Comparisons. |
277  `--------------*/
278 
279  template <unsigned N, unsigned D, typename P>
280  bool
281  operator==(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
282  {
283  /* FIXME: When actual location data is attached to a p_faces,
284  check also the equality w.r.t. to these data. */
285  return lhs.cplx() == rhs.cplx();
286  }
287 
288  template <unsigned N, unsigned D, typename P>
289  bool
290  operator<=(const p_faces<N, D, P>& lhs, const p_faces<N, D, P>& rhs)
291  {
292  /* FIXME: When actual location data is attached to a p_faces,
293  check also the equality w.r.t. to these data. */
294  return lhs == rhs;
295  }
296 
297 # endif // ! MLN_INCLUDE_ONLY
298 
299 } // end of mln
300 
301 #endif // ! MLN_CORE_SITE_SET_P_FACES_HH