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/Labeled_mesh_domain_3.h>
8 #include <CGAL/make_mesh_3.h>
9 #include <CGAL/Image_3.h>
10 
11 // Domain
12 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
13 typedef CGAL::Labeled_mesh_domain_3<K> Mesh_domain;
14 
15 #ifdef CGAL_CONCURRENT_MESH_3
16 typedef CGAL::Parallel_tag Concurrency_tag;
17 #else
18 typedef CGAL::Sequential_tag Concurrency_tag;
19 #endif
20 
21 // Triangulation
22 typedef CGAL::Mesh_triangulation_3<Mesh_domain,CGAL::Default,Concurrency_tag>::type Tr;
23 
24 typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3;
25 
26 // Mesh Criteria
27 typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
28 
29 // To avoid verbose function and named parameters call
30 using namespace CGAL::parameters;
31 
main(int argc,char * argv[])32 int main(int argc, char* argv[])
33 {
34   const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz";
35   // Domain
36   CGAL::Image_3 image;
37   if(!image.read(fname)){
38     std::cerr << "Error: Cannot read file " <<  fname << std::endl;
39     return EXIT_FAILURE;
40   }
41 
42   Mesh_domain domain = Mesh_domain::create_labeled_image_mesh_domain(image);
43 
44   // Mesh criteria
45   Mesh_criteria criteria(facet_angle=30, facet_size=5, facet_distance=1.5,
46                          cell_radius_edge_ratio=2, cell_size=7);
47 
48   // Mesh generation and optimization in one call (sliver_bound is the
49   // targeted dihedral angle in degrees)
50   C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
51                                       no_exude(),
52                                       perturb(sliver_bound=10, time_limit=15));
53 
54   // Mesh generation and optimization in several call
55   C3t3 c3t3_bis = CGAL::make_mesh_3<C3t3>(domain, criteria,
56                                           no_perturb(), no_exude());
57 
58   CGAL::perturb_mesh_3(c3t3_bis, domain, time_limit=15);
59 
60   // Output
61   std::ofstream medit_file("out.mesh");
62   c3t3.output_to_medit(medit_file);
63 
64   std::ofstream medit_file_bis("out_bis.mesh");
65   c3t3_bis.output_to_medit(medit_file_bis);
66 
67   return 0;
68 }
69