$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
n_faces_set.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_FACES_SET_HH
27 # define MLN_TOPO_N_FACES_SET_HH
28 
31 
32 #include <vector>
33 
34 #include <mln/core/contract.hh>
35 #include <mln/topo/algebraic_n_face.hh>
36 
37 // FIXME: Rename as algebraic_n_faces_set?
38 
39 
40 namespace mln
41 {
42 
43  namespace topo
44  {
45 
46  // Forward declaration.
47  template <unsigned D> class complex;
48 
49 
50  /*------------------------------------.
51  | Set of (algebraic) n-face handles. |
52  `------------------------------------*/
53 
55  template <unsigned N, unsigned D>
57  {
58  public:
60  void add(const algebraic_n_face<N, D>& f);
61 
67  void reserve(size_t n);
68 
70  typedef std::vector< algebraic_n_face<N, D> > faces_type;
71 
76  const faces_type& faces() const;
78 
79  private:
80  friend class complex<D>;
81 
83  faces_type faces_;
84  };
85 
86 
87  /*-----------------------.
88  | Construction helpers. |
89  `-----------------------*/
90 
91  /* FIXME: We can probably reduce the number of operators, given
92  the fact that ``a - b'' is equivalent to ``a + (-b)''. */
93 
96  template <unsigned N, unsigned D>
99  const algebraic_n_face<N, D>& f2);
100 
101  template <unsigned N, unsigned D>
103  operator+(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2);
104 
105  template <unsigned N, unsigned D>
107  operator+(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2);
108 
109  template <unsigned N, unsigned D>
111  operator+(const n_face<N, D>& f1, const n_face<N, D>& f2);
112 
113 
114  template <unsigned N, unsigned D>
117 
118  template <unsigned N, unsigned D>
120  operator+(const n_faces_set<N, D>& fs, const n_face<N, D>& f);
121 
122  template <unsigned N, unsigned D>
126 
129  template <unsigned N, unsigned D>
132  const algebraic_n_face<N, D>& f2);
133 
134  template <unsigned N, unsigned D>
136  operator-(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2);
137 
138  template <unsigned N, unsigned D>
140  operator-(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2);
141 
142  template <unsigned N, unsigned D>
144  operator-(const n_face<N, D>& f1, const n_face<N, D>& f2);
145 
146 
147  template <unsigned N, unsigned D>
150 
151  template <unsigned N, unsigned D>
153  operator-(const n_faces_set<N, D>& fs, const n_face<N, D>& f);
154 
155  template <unsigned N, unsigned D>
159 
160 
161 
162 # ifndef MLN_INCLUDE_ONLY
163 
164  /*------------------------------------.
165  | Set of (algebraic) n-face handles. |
166  `------------------------------------*/
167 
168  template <unsigned N, unsigned D>
169  inline
170  void
172  {
173  // Check consistency.
174  if (!faces_.empty())
175  mln_precondition(faces_.front().cplx() == f.cplx());
176  faces_.push_back(f);
177  }
178 
179  template <unsigned N, unsigned D>
180  inline
181  void
183  {
184  faces_.reserve(n);
185  }
186 
187  template <unsigned N, unsigned D>
188  inline
189  const std::vector< algebraic_n_face<N, D> >&
191  {
192  return faces_;
193  }
194 
195  /*-----------------------.
196  | Construction helpers. |
197  `-----------------------*/
198 
199  // ---------- //
200  // Addition. //
201  // ---------- //
202 
203  template <unsigned N, unsigned D>
204  inline
205  n_faces_set<N, D>
206  operator+(const algebraic_n_face<N, D>& f1,
207  const algebraic_n_face<N, D>& f2)
208  {
209  n_faces_set<N, D> fs;
210  fs.add(f1);
211  fs.add(f2);
212  return fs;
213  }
214 
215  template <unsigned N, unsigned D>
216  inline
217  n_faces_set<N, D>
218  operator+(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2)
219  {
220  n_faces_set<N, D> fs;
221  fs.add(f1);
222  fs.add(make_algebraic_n_face(f2, true));
223  return fs;
224  }
225 
226  template <unsigned N, unsigned D>
227  inline
228  n_faces_set<N, D>
229  operator+(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2)
230  {
231  n_faces_set<N, D> fs;
232  fs.add(make_algebraic_n_face(f1, true));
233  fs.add(f2);
234  return fs;
235  }
236 
237  template <unsigned N, unsigned D>
238  inline
239  n_faces_set<N, D>
240  operator+(const n_face<N, D>& f1, const n_face<N, D>& f2)
241  {
242  n_faces_set<N, D> fs;
243  fs.add(make_algebraic_n_face(f1, true));
244  fs.add(make_algebraic_n_face(f2, true));
245  return fs;
246  }
247 
248 
249  template <unsigned N, unsigned D>
250  inline
251  n_faces_set<N, D>
252  operator+(const n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
253  {
254  n_faces_set<N, D> fs2(fs);
255  fs2.add(f);
256  return fs2;
257  }
258 
259  template <unsigned N, unsigned D>
260  inline
261  n_faces_set<N, D>
262  operator+(const n_faces_set<N, D>& fs, const n_face<N, D>& f)
263  {
264  n_faces_set<N, D> fs2(fs);
265  fs2.add(make_algebraic_n_face(f, true));
266  return fs2;
267  }
268 
269  template <unsigned N, unsigned D>
270  n_faces_set<N, D>&
271  operator+=(n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
272  {
273  fs.add(f);
274  return fs;
275  }
276 
277  // ------------- //
278  // Subtraction. //
279  // ------------- //
280 
281  template <unsigned N, unsigned D>
282  inline
283  n_faces_set<N, D>
284  operator-(const algebraic_n_face<N, D>& f1,
285  const algebraic_n_face<N, D>& f2)
286  {
287  n_faces_set<N, D> fs;
288  fs.add(f1);
289  fs.add(-f2);
290  return fs;
291  }
292 
293  template <unsigned N, unsigned D>
294  inline
295  n_faces_set<N, D>
296  operator-(const algebraic_n_face<N, D>& f1, const n_face<N, D>& f2)
297  {
298  n_faces_set<N, D> fs;
299  fs.add(f1);
300  fs.add(make_algebraic_n_face(f2, false));
301  return fs;
302  }
303 
304  template <unsigned N, unsigned D>
305  inline
306  n_faces_set<N, D>
307  operator-(const n_face<N, D>& f1, const algebraic_n_face<N, D>& f2)
308  {
309  n_faces_set<N, D> fs;
310  fs.add(make_algebraic_n_face(f1, true));
311  fs.add(-f2);
312  return fs;
313  }
314 
315  template <unsigned N, unsigned D>
316  inline
317  n_faces_set<N, D>
318  operator-(const n_face<N, D>& f1, const n_face<N, D>& f2)
319  {
320  n_faces_set<N, D> fs;
321  fs.add(make_algebraic_n_face(f1, true));
322  fs.add(make_algebraic_n_face(f2, false));
323  return fs;
324  }
325 
326 
327  template <unsigned N, unsigned D>
328  inline
329  n_faces_set<N, D>
330  operator-(const n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
331  {
332  n_faces_set<N, D> fs2(fs);
333  fs2.add(-f);
334  return fs2;
335  }
336 
337  template <unsigned N, unsigned D>
338  inline
339  n_faces_set<N, D>
340  operator-(const n_faces_set<N, D>& fs, const n_face<N, D>& f)
341  {
342  n_faces_set<N, D> fs2(fs);
343  fs2.add(make_algebraic_n_face(f, false));
344  return fs2;
345  }
346 
347  template <unsigned N, unsigned D>
348  n_faces_set<N, D>&
349  operator-=(n_faces_set<N, D>& fs, const algebraic_n_face<N, D>& f)
350  {
351  fs.add(-f);
352  return fs;
353  }
354 
355 # endif // ! MLN_INCLUDE_ONLY
356 
357  } // end of namespace mln::topo
358 
359 } // end of namespace mln
360 
361 #endif // ! MLN_TOPO_N_FACES_SET_HH