$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_complex.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_CORE_SITE_SET_P_COMPLEX_HH
27 # define MLN_CORE_SITE_SET_P_COMPLEX_HH
28 
32 
33 # include <mln/core/internal/site_set_base.hh>
34 
35 # include <mln/topo/complex.hh>
36 
37 # include <mln/core/site_set/complex_psite.hh>
38 # include <mln/core/site_set/p_complex_piter.hh>
39 # include <mln/core/site_set/p_n_faces_piter.hh>
40 // FIXME: Disabled (moved to the attic).
41 # if 0
42 # include <mln/core/site_set/p_complex_faces_piter.hh>
43 # endif
44 
45 # include <mln/geom/complex_geometry.hh>
46 
47 // FIXME: Have G default to mln::geom::complex_geom<D, P>? But we
48 // don't know P...
49 
50 
51 namespace mln
52 {
53 
54  // Forward declarations.
55  template <unsigned D, typename G> class p_complex;
56 
57  template <unsigned D, typename G> class p_complex_fwd_piter_;
58  template <unsigned D, typename G> class p_complex_bkd_piter_;
59 
60 // FIXME: Disabled (moved to the attic).
61 # if 0
62  template <unsigned N, unsigned D, typename G>
63  class p_complex_faces_fwd_piter_;
64  template <unsigned N, unsigned D, typename G>
65  class p_complex_faces_bkd_piter_;
66 # endif
67 
68  namespace trait
69  {
70  template <unsigned D, typename G>
71  struct site_set_< p_complex<D, G> >
72  {
73  typedef trait::site_set::nsites::known nsites;
74  // FIXME: Depends on G!
75  typedef trait::site_set::bbox::unknown bbox;
76  typedef trait::site_set::contents::fixed contents;
77  typedef trait::site_set::arity::unique arity;
78  };
79  } // end of namespace mln::trait
80 
81 
82  /* FIXME: We should decide was G represents:
83 
84  - a unique site type for all faces of all dimensions?
85  (Acceptable for a first implementation -- the one currently
86  chosen.)
87 
88  - the site type associated to 0-faces only (site types of n-faces
89  with n > 1 will be deduced from this one)?
90  (Better, but not really flexible.)
91 
92  - a type list of the site types associated faces of each
93  dimensions, e.g.
94 
95  mln_type_list(point2d,
96  mln_type_list(util::site_pair<point2d>,
97  mln_type_list(site_set<point2d>, // or site_triplet<point2d>
98  mln_empty_list)))
99 
100  for a 2-complex?
101  (The best solution so far, but requires more work.) */
102 
103  /* FIXME: Aggregate site data (location). */
104 
112 
113 
114 
115  template <unsigned D, typename G>
116  class p_complex
117  : public internal::site_set_base_< complex_psite<D, G>, p_complex<D, G> >
118  {
119  typedef p_complex<D, G> self_;
121 
122  public:
127  p_complex(const topo::complex<D>& cplx, const G& geom);
128 
132  typedef mln_site(super_) element;
133 
135  typedef complex_psite<D, G> psite;
136 
139 
142 
144  typedef fwd_piter piter;
146 
153  unsigned nsites() const;
154 
156  unsigned nfaces() const;
158  unsigned nfaces_of_dim(unsigned n) const;
159 
160  // FIXME: This method is probably useless now.
162  bool is_valid() const;
163 
165  bool has(const psite& p) const;
166 
167  // FIXME: Dummy.
168  std::size_t memory_size() const;
169 
174  /* FIXME: Move back the const qualifier on this return type (see
175  comment below on cplx_). */
176  topo::complex<D>& cplx() const;
179  topo::complex<D>& cplx();
180 
182  const G& geom() const;
184 
185  private:
187  /* FIXME: Get rid of this `mutable' qualifier. This is needed for
188  compatiblity reasons with topo::face (see p_complex_piter).
189 
190  We should either
191 
192  - have an additional version of topo::face holding a const (not
193  mutable) complex;
194 
195  - have face_handle and topo::face do not hold a reference on a
196  complex, leading to a design of complexes similar to graphs,
197  where vertex and edge handles (named `id's) are not tied to a
198  specific graph. */
199  mutable topo::complex<D> cplx_;
201  G geom_;
202  };
203 
204 
209  template <unsigned D, typename G>
210  bool
211  operator==(const p_complex<D, G>& lhs, const p_complex<D, G>& rhs);
212 
221  template <unsigned D, typename G>
222  bool
223  operator<=(const p_complex<D, G>& lhs, const p_complex<D, G>& rhs);
224 
225 
226 
227 # ifndef MLN_INCLUDE_ONLY
228 
229  template <unsigned D, typename G>
230  inline
231  p_complex<D, G>::p_complex(const topo::complex<D>& cplx, const G& geom)
232  : cplx_(cplx), geom_(geom)
233  {
234  }
235 
236  template <unsigned D, typename G>
237  inline
238  unsigned
240  {
241  return nfaces();
242  }
243 
244  template <unsigned D, typename G>
245  inline
246  unsigned
247  p_complex<D, G>::nfaces() const
248  {
249  return cplx_.nfaces();
250  }
251 
252  template <unsigned D, typename G>
253  inline
254  unsigned
255  p_complex<D, G>::nfaces_of_dim(unsigned n) const
256  {
257  return cplx_.nfaces_of_dim(n);
258  }
259 
260  template <unsigned D, typename G>
261  inline
262  bool
263  p_complex<D, G>::is_valid() const
264  {
265  return true;
266  }
267 
268  template <unsigned D, typename G>
269  inline
270  bool
271  p_complex<D, G>::has(const psite& p) const
272  {
273  mln_precondition(is_valid());
274  return
275  // Check whether P's complex is compatible with this pset's complex.
276  (p.site_set() == *this) &&
277  // Check whether P is valid.
278  (p.is_valid());
279  }
280 
281  template <unsigned D, typename G>
282  inline
283  std::size_t
284  p_complex<D, G>::memory_size() const
285  {
286  // FIXME: Dummy; implement (see other site sets).
287  abort();
288  return 0;
289  }
290 
291  template <unsigned D, typename G>
292  topo::complex<D>&
293  p_complex<D, G>::cplx() const
294  {
295  mln_precondition(is_valid());
296  return cplx_;
297  }
298 
299  template <unsigned D, typename G>
300  topo::complex<D>&
301  p_complex<D, G>::cplx()
302  {
303  mln_precondition(is_valid());
304  return cplx_;
305  }
306 
307  template <unsigned D, typename G>
308  const G&
309  p_complex<D, G>::geom() const
310  {
311  return geom_;
312  }
313 
314 
315  /*--------------.
316  | Comparisons. |
317  `--------------*/
318 
319  template <unsigned D, typename G>
320  bool
321  operator==(const p_complex<D, G>& lhs, const p_complex<D, G>& rhs)
322  {
323  /* FIXME: When actual location data is attached to a p_complex,
324  check also the equlity w.r.t. to these data. */
325  return lhs.cplx() == rhs.cplx();
326  }
327 
328  template <unsigned D, typename G>
329  bool
330  operator<=(const p_complex<D, G>& lhs, const p_complex<D, G>& rhs)
331  {
332  /* FIXME: When actual location data is attached to a p_complex,
333  check also the equality w.r.t. to these data. */
334  return lhs == rhs;
335  }
336 
337 # endif // ! MLN_INCLUDE_ONLY
338 
339 } // end of mln
340 
341 #endif // ! MLN_CORE_SITE_SET_P_COMPLEX_HH