$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
algebraic_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_ALGEBRAIC_N_FACE_HH
27 # define MLN_TOPO_ALGEBRAIC_N_FACE_HH
28 
31 
32 #include <mln/topo/n_face.hh>
33 
34 
35 namespace mln
36 {
37 
38  namespace topo
39  {
40 
41  /*-------------------.
42  | Algebraic n-Face. |
43  `-------------------*/
44 
49  template <unsigned N, unsigned D>
50  class algebraic_n_face : public n_face<N, D>
51  {
52  typedef n_face<N, D> super_;
53 
54  public:
60  algebraic_n_face(const n_face<N, D>& f, bool sign);
61 
65  bool sign() const;
67  void set_sign(bool sign);
69 
70  private:
71  bool sign_;
72  };
73 
74 
76  template <unsigned N, unsigned D>
78  make_algebraic_n_face(const n_face<N, D>& f, bool sign);
79 
80 
83  template <unsigned N, unsigned D>
85  operator-(const n_face<N, D>& f);
86 
87  template <unsigned N, unsigned D>
91 
92 
95 
100  template <unsigned N, unsigned D>
101  bool
103  const algebraic_n_face<N, D>& rhs);
104 
109  template <unsigned N, unsigned D>
110  bool
112  const algebraic_n_face<N, D>& rhs);
113 
121  template <unsigned N, unsigned D>
122  bool
123  operator< (const algebraic_n_face<N, D>& lhs,
124  const algebraic_n_face<N, D>& rhs);
125 
127 
128 
130  template <unsigned N, unsigned D>
131  std::ostream&
132  operator<<(std::ostream& ostr, const algebraic_n_face<N, D>& f);
133 
134 
137 
155  template <unsigned D>
157  edge(const n_face<0, D>& f1, const n_face<0, D>& f2);
159 
160 
161 
162 # ifndef MLN_INCLUDE_ONLY
163 
164  template <unsigned N, unsigned D>
165  inline
167  : super_(), sign_(true)
168  {
169  // Ensure N is compatible with D.
170  metal::bool_< N <= D >::check();
171  mln_postcondition(!this->is_valid());
172  }
173 
174  template <unsigned N, unsigned D>
175  inline
176  algebraic_n_face<N, D>::algebraic_n_face(complex<D>& c, unsigned face_id,
177  bool sign)
178  : super_(c, face_id), sign_(sign)
179  {
180  // Ensure N is compatible with D.
181  metal::bool_< N <= D >::check();
182  }
183 
184  template <unsigned N, unsigned D>
185  inline
187  : super_(f), sign_(sign)
188  {
189  // Ensure N is compatible with D.
190  metal::bool_< N <= D >::check();
191  }
192 
193 
194  template <unsigned N, unsigned D>
195  inline
196  bool
198  {
199  return sign_;
200  }
201 
202  template <unsigned N, unsigned D>
203  inline
204  void
206  {
207  sign_ = sign;
208  }
209 
210 
211  template <unsigned N, unsigned D>
212  algebraic_n_face<N, D>
213  make_algebraic_n_face(const n_face<N, D>& f, bool sign)
214  {
215  return algebraic_n_face<N, D>(f, sign);
216  }
217 
218 
219  template <unsigned N, unsigned D>
220  algebraic_n_face<N, D>
221  operator-(const n_face<N, D>& f)
222  {
223  return algebraic_n_face<N, D>(f, false);
224  }
225 
226  template <unsigned N, unsigned D>
227  algebraic_n_face<N, D>
228  operator-(const algebraic_n_face<N, D>& f)
229  {
230  algebraic_n_face<N, D> f2(f);
231  f2.set_sign(!f.sign());
232  return f2;
233  }
234 
235 
236  template <unsigned N, unsigned D>
237  inline
238  bool
239  operator==(const algebraic_n_face<N, D>& lhs,
240  const algebraic_n_face<N, D>& rhs)
241  {
242  // Ensure LHS and RHS belong to the same complex.
243  mln_precondition(lhs.cplx() == rhs.cplx());
244  return lhs.face_id() == rhs.face_id() && lhs.sign() == rhs.sign();
245  }
246 
247  template <unsigned N, unsigned D>
248  inline
249  bool
250  operator!=(const algebraic_n_face<N, D>& lhs,
251  const algebraic_n_face<N, D>& rhs)
252  {
253  // Ensure LHS and RHS belong to the same complex.
254  mln_precondition(lhs.cplx() == rhs.cplx());
255  return !(lhs == rhs);
256  }
257 
258  template <unsigned N, unsigned D>
259  inline
260  bool
261  operator< (const algebraic_n_face<N, D>& lhs,
262  const algebraic_n_face<N, D>& rhs)
263  {
264  // Ensure LHS and RHS belong to the same complex.
265  mln_precondition(lhs.cplx() == rhs.cplx());
266  return lhs.face_id() < rhs.face_id();
267  }
268 
269 
270  template <unsigned N, unsigned D>
271  inline
272  std::ostream&
273  operator<<(std::ostream& ostr, const algebraic_n_face<N, D>& f)
274  {
275  return
276  ostr << "(cplx = " << f.cplx().addr() << ", dim = " << f.n()
277  << ", id = " << f.face_id() << ", sign = " << f.sign()<< ')';
278  }
279 
280  /*----------.
281  | Helpers. |
282  `----------*/
283 
284  template <unsigned D>
285  algebraic_n_face<1, D>
286  edge(const n_face<0, D>& f1, const n_face<0, D>& f2)
287  {
288  typedef std::vector< algebraic_n_face<0, D> > n0_faces_t;
289  typedef std::vector< algebraic_n_face<1, D> > n1_faces_t;
290 
291  n1_faces_t f1_adj_edges = f1.higher_dim_adj_faces();
292  for (typename n1_faces_t::const_iterator e = f1_adj_edges.begin();
293  e != f1_adj_edges.end(); ++e)
294  {
295  n0_faces_t e_adj_vertices = e->lower_dim_adj_faces();
296  for (typename n0_faces_t::const_iterator w = e_adj_vertices.begin();
297  w != e_adj_vertices.end(); ++w)
298  if (*w == f2)
299  // E is the edge linking F1 and F2.
300  return *e;
301  }
302 
303  // If no shared edge was found, retun an empty (invalid) 1-face.
304  return algebraic_n_face<1, D>();
305  }
306 
307 # endif // ! MLN_INCLUDE_ONLY
308 
309  } // end of namespace mln::topo
310 
311 } // end of namespace mln
312 
313 #endif // ! MLN_TOPO_ALGEBRAIC_N_FACE_HH