33 std::cout <<
"Loading mesh..." << std::endl;
34 std::cout <<
"Fill volume mode: " << (fill_volume ?
"enabled (3D)" :
"disabled (2D surface)") << std::endl;
36 GEO::MeshIOFlags flags;
37 flags.set_element(GEO::MESH_FACETS);
39 flags.set_element(GEO::MESH_CELLS);
40 flags.set_attribute(GEO::MESH_CELL_REGION);
43 if(!mesh_load(filename, M, flags)) {
47 if(!M.facets.are_simplices()) {
48 std::cout <<
"Triangulating facets..." << std::endl;
49 M.facets.triangulate();
54 if(!M.cells.are_simplices()) {
55 std::cout <<
"Tetrahedralizing cells..." << std::endl;
56 if(!mesh_tetrahedralize(M,
true,
true)) {
61 if(M.cells.nb() == 0) {
62 std::cout <<
"File " << filename <<
" does not contain a volume" << std::endl;
63 std::cout <<
"Trying to tetrahedralize..." << std::endl;
64 if(!mesh_tetrahedralize(M,
true,
true)) {
70 std::cout <<
"Surface mesh mode: skipping volume tetrahedralization" << std::endl;
71 if(M.cells.nb() > 0) {
72 std::cout <<
"Warning: Input mesh contains volume cells, but fill_volume=false. Cells will be ignored." << std::endl;
117 GEO::Mesh input_mesh;
119 throw std::runtime_error(
"Failed to load input mesh: " + input_mesh_file);
123 std::string::size_type pos = 0;
124 while ((pos = output_dir.find(
'/', pos + 1)) != std::string::npos) {
130 const int total_vertices = input_mesh.vertices.nb();
132 int surface_vertices = 0;
133 std::vector<bool> visited(input_mesh.vertices.nb(),
false);
134 for(GEO::index_t c: input_mesh.facet_corners) {
135 visited[input_mesh.facet_corners.vertex(c)] =
true;
137 for(GEO::index_t v: input_mesh.vertices) {
143 const int level1_vertices = std::min(surface_vertices,
max_vertices_);
146 std::cout <<
"Initial mesh has " << total_vertices <<
" total vertices (" << surface_vertices <<
" surface vertices)" << std::endl;
147 std::cout <<
"Level 1 will have maximum of " <<
max_vertices_ <<
" vertices" << std::endl;
148 std::cout <<
"Creating " <<
num_levels_ <<
" levels of meshes" << std::endl;
152 GEO::Mesh level_mesh;
156 level_mesh.copy(input_mesh);
157 std::cout <<
"Level 0: using original mesh with " << surface_vertices <<
" surface vertices" << std::endl;
161 std::cout <<
"Level " << level <<
": targeting " << points_for_level <<
" surface points" << std::endl;
163 GEO::remesh_smooth(input_mesh, level_mesh, points_for_level);
167 std::cout <<
"Applying volume tetrahedralization for level " << level << std::endl;
168 GEO::MeshTetrahedralizeParameters params;
169 params.refine =
true;
170 params.refine_quality = 1.0;
171 mesh_tetrahedralize(level_mesh, params);
174 std::cout <<
"Keeping level " << level <<
" as surface mesh (2D mode)" << std::endl;
179 std::string output_file = output_dir +
"/level_" + std::to_string(level) +
".msh";
180 mesh_save(level_mesh, output_file);
181 std::cout <<
"Saved level " << level <<
" mesh to " << output_file << std::endl;