MEPP2 Project
test_property_maps.inl
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 
14 
15 #include <sstream> // std::ostringstream
16 // must be the last include to avoid side effect of disabling NDEBUG
17 #undef NDEBUG // enable assert in release mode
18 #include <cassert>
19 
20 //----------------------------------------------------------
21 
22 template< typename PointCloud,
23  typename Point,
24  typename Normal,
25  typename Color >
26 void
28 {
30 
31  // create property maps bag
32  FEVV::PMapsContainer pmaps_bag;
33 
34  // add some points
35  for(int i = 0; i < 4; i++)
36  add_vertex(pc);
37 
38 #ifdef __GNUC__
39 #pragma GCC diagnostic push
40 #pragma GCC diagnostic ignored "-Wunused-variable"
41 #endif
42  //--------------------------------------------------------------------------
43  // test Point type
44  //--------------------------------------------------------------------------
45  //
46  {
47  Point p1; // ctor with no parameter
48  Point p2(1.f, 2.f, 3.f); // ctor with 3 parameters
49  auto tmp = p1[0]; // operator[] as RValue, not in Geometry traits
50  std::ostringstream ss; // not in Geometry traits
51  ss << p2; // operator<<
52  }
53 
54  //--------------------------------------------------------------------------
55  // initialize PointMap
56  //--------------------------------------------------------------------------
57  //
58  {
59  auto pm = get(boost::vertex_point, pc);
60 
61  auto iterator_pair = vertices(pc);
62  int cnt = 1;
63  auto vi = iterator_pair.first;
64  auto vi_end = iterator_pair.second;
65  for(; vi != vi_end; ++vi)
66  {
67  put(pm, *vi, Point(cnt, cnt+1, cnt+2));
68  cnt += 3;
69  }
70 
71  assert(get(pm, 0) == Point(1, 2, 3));
72  assert(get(pm, 1) == Point(4, 5, 6));
73  assert(get(pm, 2) == Point(7, 8, 9));
74  assert(get(pm, 3) == Point(10, 11, 12));
75  }
76 
77  //--------------------------------------------------------------------------
78  // read-write PointMap
79  //--------------------------------------------------------------------------
80  //
81  {
82  auto pm = get(boost::vertex_point, pc);
83 
84  auto iterator_pair = vertices(pc);
85  auto vi = iterator_pair.first;
86  auto vi_end = iterator_pair.second;
87  for(; vi != vi_end; ++vi)
88  {
89  auto p = get(pm, *vi);
90  Point p2(gt.get_x(p)*2, gt.get_y(p)*2, gt.get_z(p)*2);
91  put(pm, *vi, p2);
92  }
93 
94  assert(get(pm, 0) == Point(2, 4, 6));
95  assert(get(pm, 1) == Point(8, 10, 12));
96  assert(get(pm, 2) == Point(14, 16, 18));
97  assert(get(pm, 3) == Point(20, 22, 24));
98  }
99 
100  //--------------------------------------------------------------------------
101  // test Normal type
102  //--------------------------------------------------------------------------
103  //
104  {
105  Normal n1; // ctor with no parameter
106  Normal n2(1., 2., 3.); // ctor with 3 parameters
107  auto tmp = n1[0]; // operator[] as RValue
108  std::ostringstream ss; // not in Geometry traits
109  ss << n2; // operator<<
110  }
111 
112  //--------------------------------------------------------------------------
113  // create NormalMap
114  //--------------------------------------------------------------------------
115  //
116  {
117  auto v_nm = make_property_map(FEVV::vertex_normal, pc);
118  put_property_map(FEVV::vertex_normal, pc, pmaps_bag, v_nm);
119  }
120 
121  //--------------------------------------------------------------------------
122  // initialize NormalMap
123  //--------------------------------------------------------------------------
124  //
125  {
126  auto v_nm = get_property_map(FEVV::vertex_normal, pc, pmaps_bag);
127 
128  auto iterator_pair = vertices(pc);
129  int cnt = 10;
130  auto vi = iterator_pair.first;
131  auto vi_end = iterator_pair.second;
132  for(; vi != vi_end; ++vi)
133  {
134  put(v_nm, *vi, Normal(cnt, cnt+1, cnt+2));
135  cnt += 3;
136  }
137 
138  assert(get(v_nm, 0) == Normal(10, 11, 12));
139  assert(get(v_nm, 1) == Normal(13, 14, 15));
140  assert(get(v_nm, 2) == Normal(16, 17, 18));
141  assert(get(v_nm, 3) == Normal(19, 20, 21));
142  }
143 
144  //--------------------------------------------------------------------------
145  // read-write NormalMap
146  //--------------------------------------------------------------------------
147  //
148  {
149  auto v_nm = get_property_map(FEVV::vertex_normal, pc, pmaps_bag);
150 
151  auto iterator_pair = vertices(pc);
152  auto vi = iterator_pair.first;
153  auto vi_end = iterator_pair.second;
154  for(; vi != vi_end; ++vi)
155  {
156  auto n = get(v_nm, *vi);
157  Normal n2(n[0]*10, n[1]*10, n[2]*10);
158  put(v_nm, *vi, n2);
159  }
160 
161  assert(get(v_nm, 0) == Normal(100, 110, 120));
162  assert(get(v_nm, 1) == Normal(130, 140, 150));
163  assert(get(v_nm, 2) == Normal(160, 170, 180));
164  assert(get(v_nm, 3) == Normal(190, 200, 210));
165  }
166 
167  //--------------------------------------------------------------------------
168  // test Color type
169  //--------------------------------------------------------------------------
170  //
171  {
172  // Color type is not in the Geometry traits
173  Color c1; // ctor with no parameter
174  Color c2(1, 2, 3); // ctor with 3 parameters
175  auto tmp = c1[0]; // operator[] as RValue
176  std::ostringstream ss;
177  ss << c2; // operator<<
178  }
179 #ifdef __GNUC__
180 #pragma GCC diagnostic pop
181 #endif
182 
183  //--------------------------------------------------------------------------
184  // create ColorMap
185  //--------------------------------------------------------------------------
186  //
187  {
188  auto v_cm = make_property_map(FEVV::vertex_color, pc);
189  put_property_map(FEVV::vertex_color, pc, pmaps_bag, v_cm);
190  }
191 
192  //--------------------------------------------------------------------------
193  // initialize ColorMap
194  //--------------------------------------------------------------------------
195  //
196  {
197  auto v_cm = get_property_map(FEVV::vertex_color, pc, pmaps_bag);
198 
199  auto iterator_pair = vertices(pc);
200  int cnt = 210;
201  auto vi = iterator_pair.first;
202  auto vi_end = iterator_pair.second;
203  for(; vi != vi_end; ++vi)
204  {
205  put(v_cm, *vi, Color(cnt, cnt+1, cnt+2));
206  cnt += 3;
207  }
208 
209  assert(get(v_cm, 0) == Color(210, 211, 212));
210  assert(get(v_cm, 1) == Color(213, 214, 215));
211  assert(get(v_cm, 2) == Color(216, 217, 218));
212  assert(get(v_cm, 3) == Color(219, 220, 221));
213  }
214 
215  //--------------------------------------------------------------------------
216  // read-write ColorMap
217  //--------------------------------------------------------------------------
218  //
219  {
220  auto v_cm = get_property_map(FEVV::vertex_color, pc, pmaps_bag);
221 
222  auto iterator_pair = vertices(pc);
223  auto vi = iterator_pair.first;
224  auto vi_end = iterator_pair.second;
225  for(; vi != vi_end; ++vi)
226  {
227  auto c = get(v_cm, *vi);
228  Color c2(c[0]-100, c[1]-100, c[2]-100);
229  put(v_cm, *vi, c2);
230  }
231 
232  assert(get(v_cm, 0) == Color(110, 111, 112));
233  assert(get(v_cm, 1) == Color(113, 114 ,115));
234  assert(get(v_cm, 2) == Color(116, 117, 118));
235  assert(get(v_cm, 3) == Color(119, 120, 121));
236  }
237 
238  //--------------------------------------------------------------------------
239  // create non-standard property map
240  //--------------------------------------------------------------------------
241  //
242  auto special_prop_map =
243  FEVV::make_vertex_property_map< PointCloud, int >(pc);
244 
245  //--------------------------------------------------------------------------
246  // initialize non-standard property map
247  //--------------------------------------------------------------------------
248  //
249  {
250  auto iterator_pair = vertices(pc);
251  int cnt = 333;
252  auto vi = iterator_pair.first;
253  auto vi_end = iterator_pair.second;
254  for(; vi != vi_end; ++vi)
255  {
256  put(special_prop_map, *vi, cnt);
257  cnt++;
258  }
259 
260  assert(get(special_prop_map, 0) == 333);
261  assert(get(special_prop_map, 1) == 334);
262  assert(get(special_prop_map, 2) == 335);
263  assert(get(special_prop_map, 3) == 336);
264  }
265 
266  //--------------------------------------------------------------------------
267  // read-write non-standard property map
268  //--------------------------------------------------------------------------
269  //
270  {
271  auto iterator_pair = vertices(pc);
272  auto vi = iterator_pair.first;
273  auto vi_end = iterator_pair.second;
274  for(; vi != vi_end; ++vi)
275  {
276  auto v = get(special_prop_map, *vi);
277  put(special_prop_map, *vi, v*2);
278  }
279 
280  assert(get(special_prop_map, 0) == 666);
281  assert(get(special_prop_map, 1) == 668);
282  assert(get(special_prop_map, 2) == 670);
283  assert(get(special_prop_map, 3) == 672);
284  }
285 
286  //--------------------------------------------------------------------------
287  // all tests passed
288  //--------------------------------------------------------------------------
289  //
290  std::cout << "Test passed.\n";
291 }
FEVV::DataStructures::AIF::vertices
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator > vertices(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the vertices of the mesh.
Definition: Graph_traits_aif.h:172
FEVV::put_property_map
void put_property_map(PropertyT p, const MeshT &, PMapsContainer &pmaps, const typename PMap_traits< PropertyT, MeshT >::pmap_type &pmap)
Definition: properties.h:664
test_property_maps_point_cloud
void test_property_maps_point_cloud(PointCloud &pc)
Definition: test_property_maps.inl:27
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
Geometry_traits.h
FEVV::DataStructures::AIF::add_vertex
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor add_vertex(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_property_type vp, FEVV::DataStructures::AIF::AIFMesh &sm)
Definition: Graph_properties_aif.h:263
boost::get
boost::property_map< FEVV::DataStructures::AIF::AIFMesh, boost::vertex_index_t >::const_type get(const boost::vertex_index_t &, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the vertex index property map of the mesh.
Definition: Graph_properties_aif.h:108
properties.h
FEVV::vertex_normal
@ vertex_normal
Definition: properties.h:35
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31
FEVV::DataStructures::AIF::put
void put(const typename FEVV::DataStructures::AIF::PropertyMap< ValueT > &pm, KeyT k, const ValueT &v)
Specialization of put(pmap, key, value) for AIF.
Definition: Graph_properties_aif.h:214