From 9d1e849517ad2d6b2ad7bdaddb8788de1fdcaea3 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 27 Aug 2020 10:26:58 +0200 Subject: [PATCH 1/6] Allow the .mesh to be read even with null domains --- Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h | 18 ++++++++++++------ .../Plugins/Mesh_3/C3t3_io_plugin.cpp | 9 +++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h index e7e8c6d87f3..52c82371776 100644 --- a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h +++ b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h @@ -106,7 +106,8 @@ bool build_finite_cells(Tr& tr, boost::unordered_map, std::vector > >& incident_cells_map, const std::map, typename Tr::Cell::Surface_patch_index>& border_facets, - const bool verbose) + const bool verbose, + bool prevent_domain_0 = true) { typedef std::array Tet_with_ref; // 4 ids + 1 reference @@ -141,7 +142,10 @@ bool build_finite_cells(Tr& tr, Cell_handle c = tr.tds().create_cell(vs[0], vs[1], vs[2], vs[3]); c->set_subdomain_index(tet[4]); // the cell's info keeps the reference of the tetrahedron - + c->info() = tet[4]; // the cell's info keeps the reference of the tetrahedron + if(prevent_domain_0){ + CGAL_precondition(tet[4] > 0); + } // assign cells to vertices for(int j=0; j<4; ++j) { @@ -328,7 +332,8 @@ bool build_triangulation(Tr& tr, const std::vector >& finite_cells, const std::map, typename Tr::Cell::Surface_patch_index>& border_facets, std::vector& vertex_handle_vector, - const bool verbose = false) + const bool verbose = false, + bool prevent_domain_0 = true) { typedef typename Tr::Vertex_handle Vertex_handle; typedef typename Tr::Cell_handle Cell_handle; @@ -360,7 +365,7 @@ bool build_triangulation(Tr& tr, if (!finite_cells.empty()) { if(!build_finite_cells(tr, finite_cells, vertex_handle_vector, incident_cells_map, - border_facets, verbose)) + border_facets, verbose, prevent_domain_0)) return false; if(!build_infinite_cells(tr, incident_cells_map, verbose)) return false; @@ -384,7 +389,8 @@ bool build_triangulation(Tr& tr, template bool build_triangulation_from_file(std::istream& is, - Tr& tr) + Tr& tr, + bool prevent_domain_0 = true) { typedef typename Tr::Point Point_3; @@ -473,7 +479,7 @@ bool build_triangulation_from_file(std::istream& is, std::vector vertices(points.size() + 1); bool is_well_built = build_triangulation(tr, - points, finite_cells, border_facets, vertices); + points, finite_cells, border_facets, vertices, false, prevent_domain_0); return is_well_built; } diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index 95bf0246fe6..b1dd73cd90a 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -127,7 +127,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load( item->setName(fileinfo.baseName()); item->set_valid(false); - if(CGAL::build_triangulation_from_file(in, item->c3t3().triangulation())) + if(CGAL::build_triangulation_from_file(in, item->c3t3().triangulation(), false)) { item->c3t3().rescan_after_load_of_triangulation(); for( C3t3::Triangulation::Finite_cells_iterator @@ -135,13 +135,14 @@ Polyhedron_demo_c3t3_binary_io_plugin::load( cit != item->c3t3().triangulation().finite_cells_end(); ++cit) { + if(cit->subdomain_index() != C3t3::Triangulation::Cell::Subdomain_index()) - item->c3t3().add_to_complex(cit, cit->subdomain_index()); + item->c3t3().add_to_complex(cit, cit->subdomain_index() == 0 ? 1 : cit->subdomain_index()); for(int i=0; i < 4; ++i) { - if(cit->surface_patch_index(i)>0) + if(cit->surface_patch_index(i)>=0) { - item->c3t3().add_to_complex(cit, i, cit->surface_patch_index(i)); + item->c3t3().add_to_complex(cit, i, cit->surface_patch_index(i) == 0 ? 1 : cit->surface_patch_index(i)); } } } From 39c0f964922b4be9a2b4d0a7380280257e67c33a Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 27 Aug 2020 13:18:46 +0200 Subject: [PATCH 2/6] Fix domain 0 behaviour --- Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h | 16 +++++++++++++++- .../Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp | 7 +++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h index 52c82371776..ed43decbe56 100644 --- a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h +++ b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h @@ -119,7 +119,16 @@ bool build_finite_cells(Tr& tr, typename Tr::Geom_traits::Construct_point_3 cp = tr.geom_traits().construct_point_3_object(); ) - + int max_domain = -1; + if(!prevent_domain_0) + { + for(std::size_t i=0; i max_domain) + max_domain=tet[4]; + } + } // build the finite cells for(std::size_t i=0; i 0); } + else + { + c->set_subdomain_index(max_domain+1); // the cell's info keeps the reference of the tetrahedron + c->info() = max_domain+1; // the cell's info keeps the reference of the tetrahedron + } // assign cells to vertices for(int j=0; j<4; ++j) { diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index b1dd73cd90a..1ea57c3958b 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -135,14 +135,13 @@ Polyhedron_demo_c3t3_binary_io_plugin::load( cit != item->c3t3().triangulation().finite_cells_end(); ++cit) { - if(cit->subdomain_index() != C3t3::Triangulation::Cell::Subdomain_index()) - item->c3t3().add_to_complex(cit, cit->subdomain_index() == 0 ? 1 : cit->subdomain_index()); + item->c3t3().add_to_complex(cit, cit->subdomain_index()); for(int i=0; i < 4; ++i) { - if(cit->surface_patch_index(i)>=0) + if(cit->surface_patch_index(i)>0) { - item->c3t3().add_to_complex(cit, i, cit->surface_patch_index(i) == 0 ? 1 : cit->surface_patch_index(i)); + item->c3t3().add_to_complex(cit, i, cit->surface_patch_index(i)); } } } From 56af55ecd434b2c6a44bc86a966042e041c442a3 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 27 Aug 2020 13:46:04 +0200 Subject: [PATCH 3/6] Fix bug in mesh_3 tests --- .../CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h | 6 +++++- Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h b/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h index 2f4705e66d0..d6852a072f2 100644 --- a/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h +++ b/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h @@ -24,8 +24,12 @@ class Mesh_complex_3_in_triangulation_3; template bool build_triangulation_from_file(std::istream& is, - Tr& tr); + Tr& tr, + bool prevent_domain_0); +template +bool build_triangulation_from_file(std::istream& is, + Tr& tr); } // CGAL #endif diff --git a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h index ed43decbe56..b928aa3801f 100644 --- a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h +++ b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h @@ -404,7 +404,7 @@ bool build_triangulation(Tr& tr, template bool build_triangulation_from_file(std::istream& is, Tr& tr, - bool prevent_domain_0 = true) + bool prevent_domain_0) { typedef typename Tr::Point Point_3; @@ -497,6 +497,12 @@ bool build_triangulation_from_file(std::istream& is, return is_well_built; } +template +bool build_triangulation_from_file(std::istream& is, + Tr& tr) +{ + return build_triangulation_from_file(is, tr, true); +} } // namespace CGAL #include From 98c80402bca9c936c75f25a66bbafdc8e87c31bf Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 4 Sep 2020 12:27:32 +0200 Subject: [PATCH 4/6] Don't use cell info() --- Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h index b928aa3801f..6cacd32ebe3 100644 --- a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h +++ b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h @@ -151,14 +151,14 @@ bool build_finite_cells(Tr& tr, Cell_handle c = tr.tds().create_cell(vs[0], vs[1], vs[2], vs[3]); c->set_subdomain_index(tet[4]); // the cell's info keeps the reference of the tetrahedron - c->info() = tet[4]; // the cell's info keeps the reference of the tetrahedron + //c->info() = tet[4]; // the cell's info keeps the reference of the tetrahedron if(prevent_domain_0){ CGAL_precondition(tet[4] > 0); } else { c->set_subdomain_index(max_domain+1); // the cell's info keeps the reference of the tetrahedron - c->info() = max_domain+1; // the cell's info keeps the reference of the tetrahedron +// c->info() = max_domain+1; // the cell's info keeps the reference of the tetrahedron } // assign cells to vertices for(int j=0; j<4; ++j) From aeda2ef58c0f794ea4cc03ea89d770faa480c82d Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Mon, 7 Sep 2020 12:35:54 +0200 Subject: [PATCH 5/6] Replace boolean name and prevent maxx_domain=0 --- .../Mesh_complex_3_in_triangulation_3_fwd.h | 2 +- Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h | 20 +++++++++---------- .../Plugins/Mesh_3/C3t3_io_plugin.cpp | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h b/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h index d6852a072f2..d0202553abc 100644 --- a/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h +++ b/Installation/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_fwd.h @@ -25,7 +25,7 @@ class Mesh_complex_3_in_triangulation_3; template bool build_triangulation_from_file(std::istream& is, Tr& tr, - bool prevent_domain_0); + bool replace_domain_0); template bool build_triangulation_from_file(std::istream& is, diff --git a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h index 6cacd32ebe3..7ee67fe5c31 100644 --- a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h +++ b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h @@ -107,7 +107,7 @@ bool build_finite_cells(Tr& tr, std::vector > >& incident_cells_map, const std::map, typename Tr::Cell::Surface_patch_index>& border_facets, const bool verbose, - bool prevent_domain_0 = true) + bool replace_domain_0 = false) { typedef std::array Tet_with_ref; // 4 ids + 1 reference @@ -119,8 +119,8 @@ bool build_finite_cells(Tr& tr, typename Tr::Geom_traits::Construct_point_3 cp = tr.geom_traits().construct_point_3_object(); ) - int max_domain = -1; - if(!prevent_domain_0) + int max_domain = 0; + if(replace_domain_0) { for(std::size_t i=0; iset_subdomain_index(tet[4]); // the cell's info keeps the reference of the tetrahedron - //c->info() = tet[4]; // the cell's info keeps the reference of the tetrahedron - if(prevent_domain_0){ + if(!replace_domain_0){ CGAL_precondition(tet[4] > 0); } else { c->set_subdomain_index(max_domain+1); // the cell's info keeps the reference of the tetrahedron -// c->info() = max_domain+1; // the cell's info keeps the reference of the tetrahedron } // assign cells to vertices for(int j=0; j<4; ++j) @@ -347,7 +345,7 @@ bool build_triangulation(Tr& tr, const std::map, typename Tr::Cell::Surface_patch_index>& border_facets, std::vector& vertex_handle_vector, const bool verbose = false, - bool prevent_domain_0 = true) + bool replace_domain_0 = false) { typedef typename Tr::Vertex_handle Vertex_handle; typedef typename Tr::Cell_handle Cell_handle; @@ -379,7 +377,7 @@ bool build_triangulation(Tr& tr, if (!finite_cells.empty()) { if(!build_finite_cells(tr, finite_cells, vertex_handle_vector, incident_cells_map, - border_facets, verbose, prevent_domain_0)) + border_facets, verbose, replace_domain_0)) return false; if(!build_infinite_cells(tr, incident_cells_map, verbose)) return false; @@ -404,7 +402,7 @@ bool build_triangulation(Tr& tr, template bool build_triangulation_from_file(std::istream& is, Tr& tr, - bool prevent_domain_0) + bool replace_domain_0) { typedef typename Tr::Point Point_3; @@ -493,7 +491,7 @@ bool build_triangulation_from_file(std::istream& is, std::vector vertices(points.size() + 1); bool is_well_built = build_triangulation(tr, - points, finite_cells, border_facets, vertices, false, prevent_domain_0); + points, finite_cells, border_facets, vertices, false, replace_domain_0); return is_well_built; } @@ -501,7 +499,7 @@ template bool build_triangulation_from_file(std::istream& is, Tr& tr) { - return build_triangulation_from_file(is, tr, true); + return build_triangulation_from_file(is, tr, false); } } // namespace CGAL diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index 1ea57c3958b..4dfab1afc69 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -127,7 +127,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load( item->setName(fileinfo.baseName()); item->set_valid(false); - if(CGAL::build_triangulation_from_file(in, item->c3t3().triangulation(), false)) + if(CGAL::build_triangulation_from_file(in, item->c3t3().triangulation(), true)) { item->c3t3().rescan_after_load_of_triangulation(); for( C3t3::Triangulation::Finite_cells_iterator From efc903d8dc0b1af8ac778e6cc442d9b781e602b5 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 10 Sep 2020 10:22:09 +0200 Subject: [PATCH 6/6] Fix error --- Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h index 7ee67fe5c31..677d37124fa 100644 --- a/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h +++ b/Mesh_3/include/CGAL/Mesh_3/tet_soup_to_c3t3.h @@ -151,10 +151,7 @@ bool build_finite_cells(Tr& tr, Cell_handle c = tr.tds().create_cell(vs[0], vs[1], vs[2], vs[3]); c->set_subdomain_index(tet[4]); // the cell's info keeps the reference of the tetrahedron - if(!replace_domain_0){ - CGAL_precondition(tet[4] > 0); - } - else + if(replace_domain_0 && tet[4] == 0) { c->set_subdomain_index(max_domain+1); // the cell's info keeps the reference of the tetrahedron }