1 #define CGAL_MESH_3_VERBOSE
2 
3 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
4 
5 #include <CGAL/Mesh_triangulation_3.h>
6 #include <CGAL/Mesh_complex_3_in_triangulation_3.h>
7 #include <CGAL/Mesh_criteria_3.h>
8 #include <CGAL/Mesh_constant_domain_field_3.h>
9 
10 #include <CGAL/Labeled_mesh_domain_3.h>
11 #include <CGAL/make_mesh_3.h>
12 #include <CGAL/Image_3.h>
13 
14 // Domain
15 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
16 typedef CGAL::Labeled_mesh_domain_3<K> Mesh_domain;
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<Tr> C3t3;
28 
29 // Criteria
30 typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
31 typedef CGAL::Mesh_constant_domain_field_3<Mesh_domain::R,
32                                            Mesh_domain::Index> Sizing_field;
33 
34 // To avoid verbose function and named parameters call
35 using namespace CGAL::parameters;
36 
main(int argc,char * argv[])37 int main(int argc, char* argv[])
38 {
39   const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz";
40   // Loads image
41   CGAL::Image_3 image;
42   if(!image.read(fname)){
43     std::cerr << "Error: Cannot read file " <<  fname << std::endl;
44     return EXIT_FAILURE;
45   }
46 
47   // Domain
48   Mesh_domain domain = Mesh_domain::create_labeled_image_mesh_domain(image);
49 
50   // Sizing field: set global size to 8 and kidney size (label 127) to 3
51   double kidney_size = 3.;
52   int volume_dimension = 3;
53   Sizing_field size(8);
54   size.set_size(kidney_size, volume_dimension,
55                 domain.index_from_subdomain_index(127));
56 
57   // Mesh criteria
58   Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=2,
59                          cell_radius_edge_ratio=3, cell_size=size);
60 
61   // Meshing
62   C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);
63 
64   // Output
65   std::ofstream medit_file("out.mesh");
66   c3t3.output_to_medit(medit_file);
67 
68   return 0;
69 }
70