1 #include <CGAL/Simple_cartesian.h>
2
3 #include <CGAL/Surface_mesh.h>
4
5 #include <CGAL/Surface_mesh_parameterization/IO/File_off.h>
6 #include <CGAL/Surface_mesh_parameterization/parameterize.h>
7
8 #include <CGAL/Polygon_mesh_processing/measure.h>
9
10 #include <iostream>
11 #include <fstream>
12
13 typedef CGAL::Simple_cartesian<double> Kernel;
14 typedef Kernel::Point_2 Point_2;
15 typedef Kernel::Point_3 Point_3;
16 typedef CGAL::Surface_mesh<Kernel::Point_3> SurfaceMesh;
17
18 typedef boost::graph_traits<SurfaceMesh>::vertex_descriptor vertex_descriptor;
19 typedef boost::graph_traits<SurfaceMesh>::halfedge_descriptor halfedge_descriptor;
20 typedef boost::graph_traits<SurfaceMesh>::face_descriptor face_descriptor;
21
22 namespace SMP = CGAL::Surface_mesh_parameterization;
23
main(int argc,char ** argv)24 int main(int argc, char** argv)
25 {
26 const char* filename = (argc>1) ? argv[1] : "data/nefertiti.off";
27
28 SurfaceMesh sm;
29 if(!CGAL::IO::read_polygon_mesh(filename, sm))
30 {
31 std::cerr << "Invalid input file." << std::endl;
32 return EXIT_FAILURE;
33 }
34
35 // a halfedge on the border
36 halfedge_descriptor bhd = CGAL::Polygon_mesh_processing::longest_border(sm).first;
37
38 // The UV property map that holds the parameterized values
39 typedef SurfaceMesh::Property_map<vertex_descriptor, Point_2> UV_pmap;
40 UV_pmap uv_map = sm.add_property_map<vertex_descriptor, Point_2>("h:uv").first;
41
42 SMP::parameterize(sm, bhd, uv_map);
43
44 std::ofstream out("result.off");
45 SMP::IO::output_uvmap_to_off(sm, bhd, uv_map, out);
46
47 return EXIT_SUCCESS;
48 }
49