$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_complex.cc
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 #include <algorithm>
27 #include <iterator>
28 #include <iostream>
29 
30 #include <mln/value/int_u8.hh>
31 #include <mln/core/alias/point2d.hh>
32 
33 #include <mln/core/site_set/p_faces.hh>
34 #include <mln/core/image/complex_image.hh>
35 
36 /* FIXME: Split this test (and maybe factor common parts, like the
37  construction of the complex), since it exercises too many features
38  in a single file. */
39 
40 
41 int main()
42 {
43  using namespace mln;
44 
45  /*----------.
46  | Complex. |
47  `----------*/
48 
49  /* A 2-d (simplicial) complex and its adjacency graph.
50 
51  c 0 1 2 3
52  r .------------------------
53  | v0 e3 v3
54  0 | o-----------o v0----e3----v3
55  | / \ ,-----. / / \ | /
56  | / . \ \ t1/ / / \ t1 /
57  1 | e0 / / \ e1\ / / e4 e0. ,e1' `e4
58  | / /t0 \ \ ' / / t0 \ /
59  | / `-----' \ / / | \ /
60  2 | o-----------o v1----e2----v2
61  | v1 e2 v2
62 
63  v = vertex
64  e = edge
65  t = triangle
66  */
67 
68 
69  const unsigned D = 2;
70 
72 
73  // 0-faces (points).
74  topo::n_face<0, D> v0 = c.add_face();
75  topo::n_face<0, D> v1 = c.add_face();
76  topo::n_face<0, D> v2 = c.add_face();
77  topo::n_face<0, D> v3 = c.add_face();
78 
79  // 1-faces (segments).
80  topo::n_face<1, D> e0 = c.add_face(v0 + v1);
81  topo::n_face<1, D> e1 = c.add_face(v0 + v2);
82  topo::n_face<1, D> e2 = c.add_face(v1 + v2);
83  topo::n_face<1, D> e3 = c.add_face(v0 + v3);
84  topo::n_face<1, D> e4 = c.add_face(v2 + v3);
85 
86  // 2-faces (triangles).
87  topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2);
88  topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4);
89 
90 
91  /*------------------------------.
92  | Complex geometry (location). |
93  `------------------------------*/
94 
95  typedef point2d P;
97  G geom;
98  geom.add_location(point2d(0,1)); // 0-face #0.
99  geom.add_location(point2d(2,0)); // 0-face #1.
100  geom.add_location(point2d(2,2)); // 0-face #2.
101  geom.add_location(point2d(0,3)); // 0-face #3.
102 
103 
104  /*---------------------.
105  | Complex-based pset. |
106  `---------------------*/
107 
108  // A pset.
109  p_complex<D, G> pc(c, geom);
110 
111  // An iterator on this pset.
113  for_all(p)
114  {
115  std::cout << p << ": ";
116  // Print site(s).
117  mln_site_(G) s(p);
118  std::copy (s.sites.begin(), s.sites.end(),
119  std::ostream_iterator<P>(std::cout, " "));
120  std::cout << std::endl;
121  }
122 }