1 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
2 
3 #include <CGAL/Mesh_triangulation_3.h>
4 #include <CGAL/Mesh_complex_3_in_triangulation_3.h>
5 #include <CGAL/Mesh_criteria_3.h>
6 
7 #include <CGAL/Polyhedral_mesh_domain_with_features_3.h>
8 #include <CGAL/make_mesh_3.h>
9 
10 #include <CGAL/tetrahedral_remeshing.h>
11 
12 // Domain
13 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
14 typedef CGAL::Mesh_polyhedron_3<K>::type Polyhedron;
15 typedef CGAL::Polyhedral_mesh_domain_with_features_3<K> Mesh_domain;
16 
17 #ifdef CGAL_CONCURRENT_MESH_3
18 typedef CGAL::Parallel_tag Concurrency_tag;
19 #else
20 typedef CGAL::Sequential_tag Concurrency_tag;
21 #endif
22 
23 // Triangulation for Meshing
24 typedef CGAL::Mesh_triangulation_3<Mesh_domain, CGAL::Default, Concurrency_tag>::type Tr;
25 typedef CGAL::Mesh_complex_3_in_triangulation_3<
26   Tr, Mesh_domain::Corner_index, Mesh_domain::Curve_index> C3t3;
27 
28 // Criteria
29 typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
30 
31 // Triangulation for Remeshing
32 typedef CGAL::Triangulation_3<typename Tr::Geom_traits,
33   typename Tr::Triangulation_data_structure> Triangulation_3;
34 
35 // To avoid verbose function and named parameters call
36 using namespace CGAL::parameters;
37 
main(int argc,char * argv[])38 int main(int argc, char* argv[])
39 {
40   const char* fname = (argc > 1) ? argv[1] : "data/fandisk.off";
41   std::ifstream input(fname);
42   Polyhedron polyhedron;
43   input >> polyhedron;
44   if (input.fail()) {
45     std::cerr << "Error: Cannot read file " << fname << std::endl;
46     return EXIT_FAILURE;
47   }
48 
49   if (!CGAL::is_triangle_mesh(polyhedron)) {
50     std::cerr << "Input geometry is not triangulated." << std::endl;
51     return EXIT_FAILURE;
52   }
53 
54   // Create domain
55   Mesh_domain domain(polyhedron);
56 
57   // Get sharp features
58   domain.detect_features();
59 
60   // Mesh criteria
61   Mesh_criteria criteria(edge_size = 0.025,
62     facet_angle = 25, facet_size = 0.05, facet_distance = 0.005,
63     cell_radius_edge_ratio = 3, cell_size = 0.05);
64 
65   // Mesh generation
66   C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);
67 
68   Triangulation_3 tr = CGAL::convert_to_triangulation_3(std::move(c3t3));
69   //note we use the move semantic, with std::move(c3t3),
70   //  to avoid a copy of the triangulation by the function
71   //  `CGAL::convert_to_triangulation_3()`
72   //  After the call to this function, c3t3 is an empty and valid C3t3.
73   //It is possible to use :  CGAL::convert_to_triangulation_3(c3t3),
74   //  Then the triangulation is copied and duplicated, and c3t3 remains as is.
75 
76   const double target_edge_length = 0.1;//coarsen the mesh
77   CGAL::tetrahedral_isotropic_remeshing(tr, target_edge_length,
78     CGAL::parameters::number_of_iterations(3));
79 
80   return EXIT_SUCCESS;
81 }
82