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/Surface_mesh.h>
8 #include <CGAL/Polyhedral_mesh_domain_with_features_3.h>
9 #include <CGAL/make_mesh_3.h>
10 #include <CGAL/IO/output_to_vtu.h>
11 
12 // Domain
13 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
14 typedef CGAL::Surface_mesh<K::Point_3> Polyhedron;
15 typedef CGAL::Polyhedral_mesh_domain_with_features_3<K, Polyhedron> Mesh_domain;
16 
17 
18 #ifdef CGAL_CONCURRENT_MESH_3
19 typedef CGAL::Parallel_tag Concurrency_tag;
20 #else
21 typedef CGAL::Sequential_tag Concurrency_tag;
22 #endif
23 
24 // Triangulation
25 typedef CGAL::Mesh_triangulation_3<Mesh_domain,CGAL::Default,Concurrency_tag>::type Tr;
26 
27 typedef CGAL::Mesh_complex_3_in_triangulation_3<
28   Tr,Mesh_domain::Corner_index,Mesh_domain::Curve_index> C3t3;
29 
30 // Criteria
31 typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
32 
33 // To avoid verbose function and named parameters call
34 using namespace CGAL::parameters;
35 
main(int argc,char * argv[])36 int main(int argc, char*argv[])
37 {
38   const char* fname = (argc>1)?argv[1]:"data/fandisk.off";
39   std::ifstream input(fname);
40   Polyhedron polyhedron;
41   input >> polyhedron;
42   if(input.fail()){
43     std::cerr << "Error: Cannot read file " <<  fname << std::endl;
44     return EXIT_FAILURE;
45   }
46 
47   if (!CGAL::is_triangle_mesh(polyhedron)){
48     std::cerr << "Input geometry is not triangulated." << std::endl;
49     return EXIT_FAILURE;
50   }
51 
52   // Create domain
53   Mesh_domain domain(polyhedron);
54 
55   // Get sharp features
56   domain.detect_features();
57 
58   // Mesh criteria
59   Mesh_criteria criteria(edge_size = 0.025,
60                          facet_angle = 25, facet_size = 0.05, facet_distance = 0.005,
61                          cell_radius_edge_ratio = 3, cell_size = 0.05);
62 
63   // Mesh generation
64   C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);
65 
66   // Output
67   std::ofstream file("out-sm.vtu");
68   CGAL::IO::output_to_vtu(file, c3t3, CGAL::IO::ASCII);
69   // Could be replaced by:
70   // c3t3.output_to_medit(file);
71 
72   return EXIT_SUCCESS;
73 }
74