1 #include <CGAL/Simple_cartesian.h>
2 #include <CGAL/Surface_mesh.h>
3
4 #include <CGAL/Heat_method_3/Surface_mesh_geodesic_distances_3.h>
5
6 #include <fstream>
7 #include <iostream>
8
9 typedef CGAL::Simple_cartesian<double> Kernel;
10 typedef Kernel::Point_3 Point_3;
11 typedef CGAL::Surface_mesh<Point_3> Triangle_mesh;
12
13 typedef boost::graph_traits<Triangle_mesh>::vertex_descriptor vertex_descriptor;
14 typedef Triangle_mesh::Property_map<vertex_descriptor,double> Vertex_distance_map;
15 typedef CGAL::Heat_method_3::Surface_mesh_geodesic_distances_3<Triangle_mesh> Heat_method;
16
main(int argc,char * argv[])17 int main(int argc, char* argv[])
18 {
19 const char* filename = (argc > 1) ? argv[1] : "./data/sphere.off";
20
21 Triangle_mesh tm;
22 if(!CGAL::IO::read_polygon_mesh(filename, tm) ||
23 CGAL::is_empty(tm) || !CGAL::is_triangle_mesh(tm))
24 {
25 std::cerr << "Invalid input file." << std::endl;
26 return EXIT_FAILURE;
27 }
28
29 //property map for the distance values to the source set
30 Vertex_distance_map vertex_distance = tm.add_property_map<vertex_descriptor, double>("v:distance", 0).first;
31
32 Heat_method hm(tm);
33
34 //add the first vertex as the source set
35 vertex_descriptor source = *(vertices(tm).first);
36 hm.add_source(source);
37 hm.estimate_geodesic_distances(vertex_distance);
38
39 Point_3 sp = tm.point(source);
40
41 std::cout << "source: " << sp << " " << source << std::endl;
42 vertex_descriptor vfar;
43 double sdistance = 0;
44
45 for(vertex_descriptor vd : vertices(tm)){
46 std::cout << vd << " is at distance " << get(vertex_distance, vd) << " to " << source << std::endl;
47 if(get(vertex_distance, vd) > sdistance){
48 vfar = vd;
49 sdistance = get(vertex_distance, vd);
50 }
51 }
52
53 std::cout << "vfar: " << tm.point(vfar) << " " << vfar << std::endl;
54
55 hm.add_source(vfar);
56 hm.estimate_geodesic_distances(vertex_distance);
57
58 for(vertex_descriptor vd : vertices(tm)){
59 std::cout << vd << " is at distance " << get(vertex_distance, vd) << "to the set of two sources" << std::endl;
60 }
61
62 std::cout << "done" << std::endl;
63 return 0;
64 }
65