$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tests/core/image/complex_image.hh
1 // Copyright (C) 2008, 2009, 2011 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 # include <mln/data/fill.hh>
38 
39 // FIXME: Keep this? (See below.)
40 # include <mln/core/site_set/p_faces.hh>
41 
42 
43 inline
45 make_test_complex_image()
46 {
47  /*----------.
48  | Complex. |
49  `----------*/
50 
51  /* A 2-d (simplicial) complex and its adjacency graph.
52 
53  c 0 1 2 3
54  r .------------------------
55  | v0 e3 v3
56  0 | o-----------o v0----e3----v3
57  | / \ ,-----. / / \ | /
58  | / . \ \ t1/ / / \ t1 /
59  1 | e0 / / \ e1\ / / e4 e0. ,e1' `e4
60  | / /t0 \ \ ' / / t0 \ /
61  | / `-----' \ / / | \ /
62  2 | o-----------o v1----e2----v2
63  | v1 e2 v2
64 
65  v = vertex
66  e = edge
67  t = triangle
68  */
69 
70 
71  const unsigned D = 2;
72 
74 
75  // 0-faces (points).
80 
81  // 1-faces (segments).
82  mln::topo::n_face<1, D> e0 = c.add_face(v0 + v1);
83  mln::topo::n_face<1, D> e1 = c.add_face(v0 + v2);
84  mln::topo::n_face<1, D> e2 = c.add_face(v1 + v2);
85  mln::topo::n_face<1, D> e3 = c.add_face(v0 + v3);
86  mln::topo::n_face<1, D> e4 = c.add_face(v2 + v3);
87 
88  // 2-faces (triangles).
89  mln::topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2);
90  mln::topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4);
91 
92 
93  /*------------------------------.
94  | Complex geometry (location). |
95  `------------------------------*/
96 
98  G geom;
99  geom.add_location(mln::point2d(0,1)); // 0-face #0.
100  geom.add_location(mln::point2d(2,0)); // 0-face #1.
101  geom.add_location(mln::point2d(2,2)); // 0-face #2.
102  geom.add_location(mln::point2d(0,3)); // 0-face #3.
103 
104 
105  /*---------------------.
106  | Complex-based pset. |
107  `---------------------*/
108 
109  // A pset.
110  mln::p_complex<D, G> pc(c, geom);
111  mln::topo::face<D> af(e0);
112  // An associated psite.
113  mln::complex_psite<D, G> cs(pc, af);
114 
115 
116  /*--------------------.
117  | Faces-based psets. |
118  `--------------------*/
119 
120  /* FIXME: Not that p_faces have become less interesting since the
121  introduction of p_complex_faces_{fwd,bkd}_piter_. Keep this part
122  of the test? */
123 
124  /* FIXME: Move this parts out of this function? (into an existing
125  test?) */
126 
127  // Pset of 0-faces.
128  mln::p_faces<0, D, G> pf0(c);
129  // Pset of 1-faces.
130  mln::p_faces<1, D, G> pf1(c);
131  // Pset of 2-faces.
132  mln::p_faces<2, D, G> pf2(c);
133 
134  // Some psites on faces.
135  mln::faces_psite<0, D, G> fs0(pf0, v0);
136  mln::faces_psite<1, D, G> fs1(pf1, e0);
137  mln::faces_psite<2, D, G> fs2(pf2, t0);
138 
139 
140  /*----------------------.
141  | Complex-based image. |
142  `----------------------*/
143 
144  using mln::value::int_u8;
145 
146  // An image type built on a 2-complex with mln::int_u8 values on
147  // each face.
148  typedef mln::complex_image<D, G, int_u8> ima_t;
149 
150  // Values.
151  mln::metal::vec<D + 1, std::vector< int_u8 > > values;
152  // Assign 0 to 0-faces, 1 to 1-faces and 2 to 2-faces.
153  for (unsigned d = 0; d <= D; ++d)
154  for (unsigned n = 0; n < pc.cplx().nfaces_of_dim(d); ++n)
155  values[d].push_back(d);
156 
157  // Create and init an image based on PC.
158  ima_t ima(pc, values);
159 
160  // Check the value associated to edge E0 (through complex psite CS).
161  mln_postcondition(ima(cs) == 1u);
162 
163  return ima;
164 }
165 
166 
167 /* FIXME: Quick and dirty implementation, based on
168  `make_test_complex_image'. Factor and revamp. */
169 inline
170 mln::bin_2complex_image2d
171 make_test_bin_2complex_image2d()
172 {
173  mln::int_u8_2complex_image2d model = make_test_complex_image();
174  mln::bin_2complex_image2d ima;
175  mln::initialize(ima, model);
176  mln::data::fill(ima, true);
177  return ima;
178 }
179 
180 #endif // ! TESTS_CORE_IMAGE_COMPLEX_IMAGE_HH