MEPP2 Project
test_property_map_aif.cpp
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 Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, 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.
12 
13 // must be the last include to avoid side effect of disabling NDEBUG
14 #undef NDEBUG
15 #include <cassert>
16 
17 //----------------------------------------------------------
18 
19 template< typename T >
20 void
22 {
23  std::cout << "[";
24  for(int i = 0; i < pm->size(); i++)
25  {
26  std::cout << " " << get(*pm, i);
27  if(i != pm->size() - 1)
28  std::cout << ",";
29  }
30  std::cout << "]\n";
31 }
32 
33 //----------------------------------------------------------
34 
35 int
36 main(void)
37 {
40  typedef FEVV::DataStructures::AIF::AIFEdge AIFEdge;
41  typedef FEVV::DataStructures::AIF::AIFFace AIFFace;
42  typedef AIFMesh::Point Point;
46  typedef AIFHelpers::face_descriptor face_descriptor;
47  typedef AIFHelpers::smart_ptr_mesh smart_ptr_mesh;
49 
50 
51  {
52  smart_ptr_mesh m = AIFMesh::New();
53 
54  // create mesh with some vertices
59 
60  // populate vertex coordinates property map
61  AIFPropHelpers::set_point(m, v0, 0.1, 0.2, 0.3);
62  AIFPropHelpers::set_point(m, v1, 1.1, 1.2, 1.3);
63  AIFPropHelpers::set_point(m, v2, 2.1, 2.2, 2.3);
64  AIFPropHelpers::set_point(m, v3, 3.1, 3.2, 3.3);
65 
66  // display mesh informations to check vertex coordinates are ok
67  std::cout << "Input mesh:\n";
68  m->Print();
69 
70  // set_point()/get_point() test
71  {
72  auto v_range = AIFHelpers::vertices(m);
73  auto v_iter = v_range.begin();
74  auto v_end = v_range.end();
75  for(; v_iter != v_end; ++v_iter)
76  {
77  Point &p = AIFPropHelpers::get_point(m, *v_iter);
78  assert(((*v_iter) == v0 && p == Point(0.1, 0.2, 0.3)) ||
79  ((*v_iter) == v1 && p == Point(1.1, 1.2, 1.3)) ||
80  ((*v_iter) == v2 && p == Point(2.1, 2.2, 2.3)) ||
81  ((*v_iter) == v3 && p == Point(3.1, 3.2, 3.3)));
82  }
83  }
84 
85  // add a new property map to the vertices and populate it
87  m->AddPropertyMap< AIFVertex::ptr, Point >("v:test");
88  if(!m->isPropertyMap< AIFVertex::ptr >("v:test"))
89  throw std::runtime_error("Failed to create property map.");
90 
91  (*test_pm)[v0] = Point(10.1, 10.2, 10.3);
92  (*test_pm)[v1] = Point(11.1, 11.2, 11.3);
93  (*test_pm)[v2] = Point(12.1, 12.2, 12.3);
94 
95  // test property map #1
96  {
97  assert(test_pm->size() == 3);
98 
99  auto v_range = AIFHelpers::vertices(m);
100  auto v_iter = v_range.begin();
101  auto v_end = v_range.end();
102  for(; v_iter != v_end; ++v_iter)
103  {
104  Point &p = (*test_pm)[*v_iter];
105  assert(((*v_iter) == v0 && p == Point(10.1, 10.2, 10.3)) ||
106  ((*v_iter) == v1 && p == Point(11.1, 11.2, 11.3)) ||
107  ((*v_iter) == v2 && p == Point(12.1, 12.2, 12.3)) ||
108  ((*v_iter) == v3));
109  }
110  }
111 
112  // display property map content
113  auto v_range = AIFHelpers::vertices(m);
114  auto v_iter = v_range.begin();
115  auto v_end = v_range.end();
116  for(; v_iter != v_end; ++v_iter)
117  {
118  Point &p = (*test_pm)[*v_iter];
119  std::cout << "[" << (*v_iter)->GetIndex() << "]: " << p[0] << ", " << p[1]
120  << ", " << p[2] << '\n';
121  }
122 
123  // remove property maps
124  m->RemovePropertyMap< AIFVertex::ptr >("v:test");
125  }
126 
127  //--------------------------------------------------------------------------
128  // test adding-removing vertices/edges/faces, and effect upon property_maps
129  //--------------------------------------------------------------------------
130  {
131  smart_ptr_mesh m = AIFMesh::New();
132 
133  // test property maps on vertices
134 
136  m->AddPropertyMap< AIFVertex::ptr, std::string >("v:test_str");
138  m->AddPropertyMap< AIFVertex::ptr, int >("v:test_int");
139 
144  (*vpm_str)[v0] = "v0";
145  (*vpm_str)[v2] = "v2";
146  (*vpm_str)[v1] = "v1";
147  (*vpm_int)[v2] = 2;
148  (*vpm_int)[v1] = 1;
149  (*vpm_int)[v0] = 0;
150  (*vpm_int)[vtmp0] = 9999;
151  // vertices = [ v0 , vtmp0, v1 , v2 ]
152  // spm_str = [ "v0", , "v1", "v2" ]
153  // spm_int = [ 0 , 9999 , 1 , 2 ]
154  assert(vpm_str->size() == 4);
155  assert(vpm_int->size() == 4);
156 
158  // vertices = [ v0 , vtmp0, v1 , v2 , v3 ]
159  // spm_str = [ "v0", , "v1", "v2" ]
160  // spm_int = [ 0 , 9999 , 1 , 2 ]
161  assert(vpm_str->size() == 4);
162  assert(vpm_int->size() == 4);
163 
164  (*vpm_str)[v3] = "v3";
165  // vertices = [ v0 , vtmp0, v1 , v2 , v3 ]
166  // spm_str = [ "v0", , "v1", "v2", "v3" ]
167  // spm_int = [ 0 , 9999 , 1 , 2 ]
168  assert(vpm_str->size() == 5);
169  assert(vpm_int->size() == 4); // (*vpm_int)[v3] not created
170 
171  AIFHelpers::remove_vertex(vtmp0, m);
172  // vertices = [ v0 , v3 , v1 , v2 ]
173  // spm_str = [ "v0", "v3", "v1", "v2", "v3" ]
174  // spm_int = [ 0 , 9999, 1 , 2 ]
175  // the last element of spm_int is copied in v3 slot, which looks like a bug;
176  // let say that after a remove operation, one property map slot is undefined
177  // if no value has been set inside before;
178  // deletion doesn't free space in property maps because of
179  // boost::vector_property_maps
180  assert(vpm_int->size() == 4);
181  assert(vpm_str->size() == 5);
182  assert(get(*vpm_str, 1) == "v3"); // right value (set before)
183  assert(get(*vpm_int, 1) == 9999); // undefined value (never set before)
184 
186  (*vpm_str)[v4] = "v4";
187  (*vpm_int)[v4] = 4;
188  // vertices = [ v0 , v3 , v1 , v2 , v4 ]
189  // spm_str = [ "v0", "v3", "v1", "v2", "v4" ]
190  // spm_int = [ 0 , 9999, 1 , 2 , 4 ]
191  assert(vpm_int->size() == 5);
192  assert(vpm_str->size() == 5);
193  assert(get(*vpm_str, 0) == "v0");
194  assert(get(*vpm_str, 1) == "v3");
195  assert(get(*vpm_str, 2) == "v1");
196  assert(get(*vpm_str, 3) == "v2");
197  assert(get(*vpm_str, 4) == "v4");
198  assert(get(*vpm_int, 0) == 0);
199  assert(get(*vpm_int, 1) == 9999);
200  assert(get(*vpm_int, 2) == 1);
201  assert(get(*vpm_int, 3) == 2);
202  assert(get(*vpm_int, 4) == 4);
203  assert((*vpm_str)[v0] == "v0");
204  assert((*vpm_str)[v1] == "v1");
205  assert((*vpm_str)[v2] == "v2");
206  assert((*vpm_str)[v3] == "v3");
207  assert((*vpm_str)[v4] == "v4");
208  assert((*vpm_int)[v0] == 0);
209  assert((*vpm_int)[v1] == 1);
210  assert((*vpm_int)[v2] == 2);
211  assert((*vpm_int)[v3] == 9999); // undefined
212  assert((*vpm_int)[v4] == 4);
213 
214  // test property maps on edges
215 
217  m->AddPropertyMap< AIFEdge::ptr, std::string >("e:test_str");
218 
222  // edges = [ e0 , e1 , e2 ]
223  // spm_str = [ ]
225  // edges = [ e2 , e1 ]
226  // spm_str = [ ]
230  (*epm_str)[e4] = "e4";
231  (*epm_str)[e1] = "e1";
232  (*epm_str)[e2] = "e2";
233  (*epm_str)[e5] = "e5";
234  (*epm_str)[e3] = "e3";
235  // edges = [ e2 , e1 , e3 , e4 , e5 ]
236  // spm_str = [ "e2", "e1", "e3", "e4", "e5" ]
238  // edges = [ e2 , e1 , e3 , e4 ]
239  // spm_str = [ "e2", "e1", "e3", "e4", "e5" ]
240  assert(AIFHelpers::num_edges(m) == 4);
241  assert(epm_str->size() == 5);
242  assert(get(*epm_str, 0) == "e2");
243  assert(get(*epm_str, 1) == "e1");
244  assert(get(*epm_str, 2) == "e3");
245  assert(get(*epm_str, 3) == "e4");
246  assert(get(*epm_str, 4) == "e5");
247  assert((*epm_str)[e1] == "e1");
248  assert((*epm_str)[e2] == "e2");
249  assert((*epm_str)[e3] == "e3");
250  assert((*epm_str)[e4] == "e4");
251 
252  // test property maps on faces
253 
255  m->AddPropertyMap< AIFFace::ptr, int >("f:test");
256 
257  face_descriptor f0 = AIFHelpers::add_face(m);
258  (*fpm)[f0] = 0;
259  face_descriptor f1 = AIFHelpers::add_face(m);
260  (*fpm)[f1] = 1;
261  face_descriptor f2 = AIFHelpers::add_face(m);
262  (*fpm)[f2] = 2;
263  face_descriptor f3 = AIFHelpers::add_face(m);
264  (*fpm)[f3] = 3;
265  face_descriptor f4 = AIFHelpers::add_face(m);
266  (*fpm)[f4] = 4;
267  // faces = [ f0, f1, f2, f3, f4 ]
268  // fpm = [ 0, 1, 2, 3, 4 ]
269  assert(AIFHelpers::num_faces(m) == 5);
270  assert(fpm->size() == 5);
272  // faces = [ f0, f4, f2, f3 ]
273  // fpm = [ 0, 4, 2, 3, 4 ]
274  assert(AIFHelpers::num_faces(m) == 4);
275  assert(fpm->size() == 5);
276  face_descriptor f5 = AIFHelpers::add_face(m);
277  (*fpm)[f5] = 5;
278  // faces = [ f0, f4, f2, f3, f5 ]
279  // fpm = [ 0, 4, 2, 3, 5 ]
280  assert(AIFHelpers::num_faces(m) == 5);
281  assert(fpm->size() == 5);
283  // faces = [ f0, f4, f2, f5 ]
284  // fpm = [ 0, 4, 2, 5, 5 ]
285  assert(AIFHelpers::num_faces(m) == 4);
286  assert(fpm->size() == 5);
287  face_descriptor f6 = AIFHelpers::add_face(m);
288  (*fpm)[f6] = 6;
289  face_descriptor f7 = AIFHelpers::add_face(m);
290  (*fpm)[f7] = 7;
291  // faces = [ f0, f4, f2, f5, f6, f7 ]
292  // fpm = [ 0, 4, 2, 5, 6, 7 ]
295  // faces = [ f0, f4, f2, f5 ]
296  // fpm = [ 0, 4, 2, 5, 6, 7 ]
297  face_descriptor f8 = AIFHelpers::add_face(m);
298  (*fpm)[f8] = 8;
299  // faces = [ f0, f4, f2, f5, f8 ]
300  // fpm = [ 0, 4, 2, 5, 8, 7 ]
302  // faces = [ f8, f4, f2, f5 ]
303  // fpm = [ 7!, 4, 2, 5, 8, 7 ]
304  assert(AIFHelpers::num_edges(m) == 4);
305  assert(fpm->size() == 6);
306  assert(get(*fpm, 0) == 8);
307  assert(get(*fpm, 1) == 4);
308  assert(get(*fpm, 2) == 2);
309  assert(get(*fpm, 3) == 5);
310  assert(get(*fpm, 4) == 8);
311  assert(get(*fpm, 5) == 7);
312  assert((*fpm)[f2] == 2);
313  assert((*fpm)[f4] == 4);
314  assert((*fpm)[f5] == 5);
315  assert((*fpm)[f8] == 8);
316  }
317 
318 
319  //--------------------------------------------------------------------------
320  // test Associative property maps
321  //--------------------------------------------------------------------------
322  {
323  smart_ptr_mesh m = AIFMesh::New();
324 
325  // create and populate an associative property map
327  m->AddAssocPropertyMap< char, float >("assoc:test");
328 
329  (*pm)['a'] = 42.3f;
330  (*pm)['b'] = 42.5f;
331  assert((*pm)['a'] == 42.3f);
332  assert((*pm)['b'] == 42.5f);
333 
334  m->RemoveAssocPropertyMap("assoc:test");
335 
336  try
337  {
338  pm = m->GetAssocPropertyMap< char, float >("assoc:test");
339  // the previous line must trigger an exception
340  // so we must not pass here
341  assert(false);
342  }
343  catch(std::runtime_error &)
344  {
345  }
346  }
347 
348 
349  std::cout << "Test passed.\n";
350  return 0;
351 }
FEVV::DataStructures::AIF::AssocPropertyMap
Definition: AIFProperties.h:446
FEVV::DataStructures::AIF::AIFVertex::ptr
boost::shared_ptr< self > ptr
Definition: AIFVertex.hpp:47
FEVV::DataStructures::AIF::AIFTopologyHelpers::num_faces
static size_type num_faces(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2200
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_face
static face_descriptor add_face(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2887
print_property_map
void print_property_map(FEVV::DataStructures::AIF::PropertyMap< T > *pm)
Definition: test_property_map_aif.cpp:21
FEVV::DataStructures::AIF::AIFTopologyHelpers::vertex_descriptor
vertex_type::ptr vertex_descriptor
Definition: AIFTopologyHelpers.h:70
FEVV::DataStructures::AIF::AIFVertex
This class represents a vertex used by AIFMesh objects. An AIFVertex natively saves relations with it...
Definition: AIFVertex.hpp:41
FEVV::DataStructures::AIF::AIFTopologyHelpers::num_edges
static size_type num_edges(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2174
GraphConcept::edge_descriptor
boost::graph_traits< G >::edge_descriptor edge_descriptor
Definition: test_boost_graph_concept_aif.cpp:23
FEVV::DataStructures::AIF::AIFFace
This class represents a face used by AIFMesh objects. An AIFFace natively saves relations with its in...
Definition: AIFFace.hpp:46
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_face
static void remove_face(face_descriptor face, ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:3120
FEVV::DataStructures::AIF::AIFTopologyHelpers::edge_descriptor
edge_type::ptr edge_descriptor
Definition: AIFTopologyHelpers.h:71
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::DataStructures::AIF::AIFMesh::New
static ptr_mesh New()
Definition: AIFMesh.inl:720
FEVV::DataStructures::AIF::AIFTopologyHelpers::face_descriptor
face_type::ptr face_descriptor
Definition: AIFTopologyHelpers.h:72
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_edge
static edge_descriptor add_edge(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2772
AIFVertex
FEVV::DataStructures::AIF::AIFVertex AIFVertex
Definition: Graph_properties_aif.h:20
FEVV::DataStructures::AIF::PropertyMap
Definition: AIFProperties.h:381
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_edge
static void remove_edge(edge_descriptor edge, ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:3012
AIFMesh.hpp
FEVV::DataStructures::AIF::PropertyMap::size
std::size_t size(void) const
number of elements in the property map
Definition: AIFProperties.h:396
AIFHelpers
FEVV::DataStructures::AIF::AIFTopologyHelpers AIFHelpers
Definition: Graph_traits_aif.h:24
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_vertex
static void remove_vertex(vertex_descriptor vertex, ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2960
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
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::DataStructures::AIF::AIFTopologyHelpers::smart_ptr_mesh
mesh_type::ptr smart_ptr_mesh
Definition: AIFTopologyHelpers.h:64
FEVV::DataStructures::AIF::AIFTopologyHelpers
This class is an helper class associated to the AIFMesh structure. AIFTopologyHelpers implements all ...
Definition: AIFTopologyHelpers.h:57
FEVV::DataStructures::AIF::AIFTopologyHelpers::vertices
static boost::iterator_range< vertex_container::const_iterator > vertices(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2227
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_vertex
static vertex_descriptor add_vertex(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2709
FEVV::DataStructures::AIF::AIFEdge
This class represents an edge used by AIFMesh objects. An AIFEdge natively saves relations with its i...
Definition: AIFEdge.hpp:49
AIFMesh
FEVV::DataStructures::AIF::AIFMesh AIFMesh
Definition: Graph_properties_aif.h:19
main
int main(void)
Definition: test_property_map_aif.cpp:36
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31
FEVV::DataStructures::AIF::AIFPropertiesHelpers
This class is an helper class associated to the AIFMesh structure. AIFPropertiesHelpers implements al...
Definition: AIFPropertiesHelpers.h:28