1 #include <string>
2 
3 #include <CGAL/Simple_cartesian.h>
4 #include <CGAL/Surface_mesh.h>
5 
6 typedef CGAL::Simple_cartesian<double> K;
7 typedef CGAL::Surface_mesh<K::Point_3> Mesh;
8 typedef Mesh::Vertex_index vertex_descriptor;
9 typedef Mesh::Face_index face_descriptor;
10 
main()11 int main()
12 {
13   Mesh m;
14   vertex_descriptor v0 = m.add_vertex(K::Point_3(0,2,0));
15   vertex_descriptor v1 = m.add_vertex(K::Point_3(2,2,0));
16   vertex_descriptor v2 = m.add_vertex(K::Point_3(0,0,0));
17   vertex_descriptor v3 = m.add_vertex(K::Point_3(2,0,0));
18   vertex_descriptor v4 = m.add_vertex(K::Point_3(1,1,0));
19   m.add_face(v3, v1, v4);
20   m.add_face(v0, v4, v1);
21   m.add_face(v0, v2, v4);
22   m.add_face(v2, v3, v4);
23 
24 
25   // give each vertex a name, the default is empty
26   Mesh::Property_map<vertex_descriptor,std::string> name;
27   bool created;
28   boost::tie(name, created) = m.add_property_map<vertex_descriptor,std::string>("v:name","");
29   assert(created);
30   // add some names to the vertices
31   name[v0] = "hello";
32   name[v2] = "world";
33 
34   {
35     // You get an existing property, and created will be false
36     Mesh::Property_map<vertex_descriptor,std::string> name;
37     bool created;
38     boost::tie(name, created) = m.add_property_map<vertex_descriptor,std::string>("v:name", "");
39     assert(! created);
40   }
41 
42   //  You can't get a property that does not exist
43   Mesh::Property_map<face_descriptor,std::string> gnus;
44   bool found;
45   boost::tie(gnus, found) = m.property_map<face_descriptor,std::string>("v:gnus");
46   assert(! found);
47 
48   // retrieve the point property for which exists a convenience function
49   Mesh::Property_map<vertex_descriptor, K::Point_3> location = m.points();
50   for(vertex_descriptor vd : m.vertices()) {
51     std::cout << name[vd] << " @ " << location[vd] << std::endl;
52   }
53 
54   std::vector<std::string> props = m.properties<vertex_descriptor>();
55   for(std::string p : props){
56     std::cout << p << std::endl;
57   }
58 
59   // delete the string property again
60   m.remove_property_map(name);
61 
62   return 0;
63 }
64 
65