Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
tests/core/image/complex_image.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
2 // (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 
29 
30 #ifndef TESTS_CORE_IMAGE_COMPLEX_IMAGE_HH
31 # define TESTS_CORE_IMAGE_COMPLEX_IMAGE_HH
32 
33 # include <mln/core/image/complex_image.hh>
34 # include <mln/core/alias/complex_image.hh>
35 # include <mln/value/int_u8.hh>
36 
37 // FIXME: Keep this? (See below.)
38 # include <mln/core/site_set/p_faces.hh>
39 
40 
41 inline
43 make_test_complex_image()
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).
78 
79  // 1-faces (segments).
80  mln::topo::n_face<1, D> e0 = c.add_face(v0 + v1);
81  mln::topo::n_face<1, D> e1 = c.add_face(v0 + v2);
82  mln::topo::n_face<1, D> e2 = c.add_face(v1 + v2);
83  mln::topo::n_face<1, D> e3 = c.add_face(v0 + v3);
84  mln::topo::n_face<1, D> e4 = c.add_face(v2 + v3);
85 
86  // 2-faces (triangles).
87  mln::topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2);
88  mln::topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4);
89 
90 
91  /*------------------------------.
92  | Complex geometry (location). |
93  `------------------------------*/
94 
96  G geom;
97  geom.add_location(mln::point2d(0,1)); // 0-face #0.
98  geom.add_location(mln::point2d(2,0)); // 0-face #1.
99  geom.add_location(mln::point2d(2,2)); // 0-face #2.
100  geom.add_location(mln::point2d(0,3)); // 0-face #3.
101 
102 
103  /*---------------------.
104  | Complex-based pset. |
105  `---------------------*/
106 
107  // A pset.
108  mln::p_complex<D, G> pc(c, geom);
109  mln::topo::face<D> af(e0);
110  // An associated psite.
111  mln::complex_psite<D, G> cs(pc, af);
112 
113 
114  /*--------------------.
115  | Faces-based psets. |
116  `--------------------*/
117 
118  /* FIXME: Not that p_faces have become less interesting since the
119  introduction of p_complex_faces_{fwd,bkd}_piter_. Keep this part
120  of the test? */
121 
122  /* FIXME: Move this parts out of this function? (into an existing
123  test?) */
124 
125  // Pset of 0-faces.
126  mln::p_faces<0, D, G> pf0(c);
127  // Pset of 1-faces.
128  mln::p_faces<1, D, G> pf1(c);
129  // Pset of 2-faces.
130  mln::p_faces<2, D, G> pf2(c);
131 
132  // Some psites on faces.
133  mln::faces_psite<0, D, G> fs0(pf0, v0);
134  mln::faces_psite<1, D, G> fs1(pf1, e0);
135  mln::faces_psite<2, D, G> fs2(pf2, t0);
136 
137 
138  /*----------------------.
139  | Complex-based image. |
140  `----------------------*/
141 
142  using mln::value::int_u8;
143 
144  // An image type built on a 2-complex with mln::int_u8 values on
145  // each face.
146  typedef mln::complex_image<D, G, int_u8> ima_t;
147 
148  // Values.
149  mln::metal::vec<D + 1, std::vector< int_u8 > > values;
150  // Assign 0 to 0-faces, 1 to 1-faces and 2 to 2-faces.
151  for (unsigned d = 0; d <= D; ++d)
152  for (unsigned n = 0; n < pc.cplx().nfaces(d); ++n)
153  values[d].push_back(d);
154 
155  // Create and init an image based on PC.
156  ima_t ima(pc, values);
157 
158  // Check the value associated to edge E0 (through complex psite CS).
159  mln_postcondition(ima(cs) == 1u);
160 
161  return ima;
162 }
163 
164 #endif // ! TESTS_CORE_IMAGE_COMPLEX_IMAGE_HH