1 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
2 #include <CGAL/boost/graph/graph_traits_Linear_cell_complex_for_combinatorial_map.h>
3 #include <CGAL/Linear_cell_complex_constructors.h>
4 
5 #include <CGAL/Polygon_mesh_processing/triangulate_hole.h>
6 #include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
7 
8 #include <iostream>
9 #include <fstream>
10 #include <vector>
11 
12 typedef CGAL::Exact_predicates_inexact_constructions_kernel                              Kernel;
13 typedef Kernel::Point_3                                                                  Point;
14 typedef CGAL::Linear_cell_complex_traits<3, Kernel>                                      MyTraits;
15 typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper<2, 3, MyTraits>::type LCC;
16 
17 typedef boost::graph_traits<LCC>::vertex_descriptor                                      vertex_descriptor;
18 typedef boost::graph_traits<LCC>::halfedge_descriptor                                    halfedge_descriptor;
19 typedef boost::graph_traits<LCC>::face_descriptor                                        face_descriptor;
20 
21 namespace PMP = CGAL::Polygon_mesh_processing;
22 
main(int argc,char * argv[])23 int main(int argc, char* argv[])
24 {
25   const char* filename = (argc > 1) ? argv[1] : "data/mech-holes-shark.off";
26 
27   LCC mesh;
28   if(!PMP::IO::read_polygon_mesh(filename, mesh))
29   {
30     std::cerr << "Invalid input." << std::endl;
31     return 1;
32   }
33 
34   // Incrementally fill the holes
35   unsigned int nb_holes = 0;
36   for ( halfedge_descriptor h : halfedges(mesh))
37   {
38     if(is_border(h,mesh))
39     {
40       std::vector<face_descriptor>  patch_facets;
41       std::vector<vertex_descriptor> patch_vertices;
42       bool success = std::get<0>(PMP::triangulate_refine_and_fair_hole(mesh,
43                                                                        h,
44                                                                        std::back_inserter(patch_facets),
45                                                                        std::back_inserter(patch_vertices),
46                                                                        PMP::parameters::vertex_point_map(get(CGAL::vertex_point, mesh))
47                                                                                        .geom_traits(Kernel())));
48 
49       std::cout << "* Number of facets in constructed patch: " << patch_facets.size() << std::endl;
50       std::cout << "  Number of vertices in constructed patch: " << patch_vertices.size() << std::endl;
51       std::cout << "  Is fairing successful: " << success << std::endl;
52       ++nb_holes;
53     }
54   }
55 
56   std::cout << std::endl;
57   std::cout << nb_holes << " holes have been filled" << std::endl;
58 
59   std::ofstream out("filled_LCC.off");
60   out.precision(17);
61   CGAL::IO::write_OFF(out, mesh);
62 
63   return 0;
64 }
65