Extract map_cavity_vertices_to_ambient_vertices

- make it const,
 - and simplify the reuse of the API.
This commit is contained in:
Laurent Rineau 2023-11-08 15:52:20 +01:00
parent 25de4ee6b7
commit 4d7a2fee64
1 changed files with 21 additions and 21 deletions

View File

@ -1337,24 +1337,21 @@ private:
face_constraint_misses_subfaces.set(static_cast<std::size_t>(polygon_contraint_id)); face_constraint_misses_subfaces.set(static_cast<std::size_t>(polygon_contraint_id));
}; };
typename T_3::Vertex_handle_unique_hash_map map_cavity_vertices_to_ambient_vertices;
typename T_3::Vertex_handle_unique_hash_map map_lower_cavity_vertices_to_ambient_vertices;
#if CGAL_DEBUG_CDT_3 & 128 #if CGAL_DEBUG_CDT_3 & 128
std::cerr << "# upper cavity\n"; std::cerr << "# upper cavity\n";
#endif // CGAL_DEBUG_CDT_3 #endif // CGAL_DEBUG_CDT_3
const auto [upper_cavity_triangulation, interior_constrained_faces_upper, nb_of_add_vertices_upper] = const auto [upper_cavity_triangulation, map_upper_cavity_vertices_to_ambient_vertices,
interior_constrained_faces_upper, nb_of_added_vertices_upper] =
triangulate_cavity(intersecting_cells, facets_of_upper_cavity, triangulate_cavity(intersecting_cells, facets_of_upper_cavity,
map_cavity_vertices_to_ambient_vertices,
vertices_of_upper_cavity); vertices_of_upper_cavity);
std::for_each(interior_constrained_faces_upper.begin(), interior_constrained_faces_upper.end(), std::for_each(interior_constrained_faces_upper.begin(), interior_constrained_faces_upper.end(),
register_internal_constrained_facet); register_internal_constrained_facet);
#if CGAL_DEBUG_CDT_3 & 128 #if CGAL_DEBUG_CDT_3 & 128
std::cerr << "# lower cavity\n"; std::cerr << "# lower cavity\n";
#endif // CGAL_DEBUG_CDT_3 #endif // CGAL_DEBUG_CDT_3
const auto [lower_cavity_triangulation, interior_constrained_faces_lower, nb_of_add_vertices_lower] = const auto [lower_cavity_triangulation, map_lower_cavity_vertices_to_ambient_vertices,
interior_constrained_faces_lower, nb_of_added_vertices_lower] =
triangulate_cavity(intersecting_cells, facets_of_lower_cavity, triangulate_cavity(intersecting_cells, facets_of_lower_cavity,
map_lower_cavity_vertices_to_ambient_vertices,
vertices_of_lower_cavity); vertices_of_lower_cavity);
std::for_each(interior_constrained_faces_lower.begin(), interior_constrained_faces_lower.end(), std::for_each(interior_constrained_faces_lower.begin(), interior_constrained_faces_lower.end(),
register_internal_constrained_facet); register_internal_constrained_facet);
@ -1413,7 +1410,7 @@ private:
#if CGAL_DEBUG_CDT_3 & 64 #if CGAL_DEBUG_CDT_3 & 64
std::cerr << "# glu the upper triangulation of the cavity\n"; std::cerr << "# glu the upper triangulation of the cavity\n";
if(nb_of_add_vertices_upper > 0 || nb_of_add_vertices_lower > 0) if(nb_of_added_vertices_upper > 0 || nb_of_added_vertices_lower > 0)
{ {
std::cerr << std::format("!! Cavity has grown and has now {} cells and {} edges, " std::cerr << std::format("!! Cavity has grown and has now {} cells and {} edges, "
"{} vertices in upper cavity and {} in lower, " "{} vertices in upper cavity and {} in lower, "
@ -1451,13 +1448,15 @@ private:
fill_outer_map_of_cavity(upper_cavity_triangulation, facets_of_upper_cavity); fill_outer_map_of_cavity(upper_cavity_triangulation, facets_of_upper_cavity);
auto add_pseudo_cells_to_outer_map = [&](const auto& tr, bool is_upper_cavity) { auto add_pseudo_cells_to_outer_map = [&](const auto& tr, const auto& map_cavity_vertices_to_ambient_vertices,
bool is_upper_cavity) {
std::vector<std::pair<Cell_handle, CDT_2_face_handle>> pseudo_cells; std::vector<std::pair<Cell_handle, CDT_2_face_handle>> pseudo_cells;
for(auto f : tr.finite_facets()) { for(auto f : tr.finite_facets()) {
if(!is_facet_of_polygon(tr, f)) if(!is_facet_of_polygon(tr, f))
continue; continue;
const auto is_facet = facet_is_facet_of_cdt_2(tr, f, cdt_2); const auto is_facet = facet_is_facet_of_cdt_2(tr, f, cdt_2);
if(!is_facet) continue; // we might be in a sliver in the plane of the polygon if(!is_facet)
continue; // we might be in a sliver in the plane of the polygon
const auto [fh_2d, reverse_orientation] = *is_facet; const auto [fh_2d, reverse_orientation] = *is_facet;
const auto vt_aux = this->make_vertex_triple(f); const auto vt_aux = this->make_vertex_triple(f);
@ -1476,9 +1475,10 @@ private:
} }
return pseudo_cells; return pseudo_cells;
}; };
const auto pseudo_cells = add_pseudo_cells_to_outer_map(upper_cavity_triangulation, true); const auto pseudo_cells =
add_pseudo_cells_to_outer_map(upper_cavity_triangulation, map_upper_cavity_vertices_to_ambient_vertices, true);
auto inner_map_of_cavity = [&](const auto& tr) { auto inner_map_of_cavity = [&](const auto& tr, const auto& map_cavity_vertices_to_ambient_vertices) {
typename T_3::Vertex_triple_Facet_map inner_map; typename T_3::Vertex_triple_Facet_map inner_map;
auto add_facet_to_inner_map = [&](Facet f) { auto add_facet_to_inner_map = [&](Facet f) {
const auto vt_aux = this->make_vertex_triple(f); const auto vt_aux = this->make_vertex_triple(f);
@ -1511,9 +1511,10 @@ private:
// write_facets(out, *this, std::ranges::views::values(outer_map)); // write_facets(out, *this, std::ranges::views::values(outer_map));
// out.close(); // out.close();
// #endif // CGAL_DEBUG_CDT_3 // #endif // CGAL_DEBUG_CDT_3
const auto upper_inner_map = inner_map_of_cavity(upper_cavity_triangulation); const auto upper_inner_map =
inner_map_of_cavity(upper_cavity_triangulation, map_upper_cavity_vertices_to_ambient_vertices);
this->copy_triangulation_into_hole(map_cavity_vertices_to_ambient_vertices, this->copy_triangulation_into_hole(map_upper_cavity_vertices_to_ambient_vertices,
std::move(outer_map), std::move(outer_map),
upper_inner_map, upper_inner_map,
Emptyset_iterator{}); Emptyset_iterator{});
@ -1522,9 +1523,6 @@ private:
std::cerr << "# glu the lower triangulation of the cavity\n"; std::cerr << "# glu the lower triangulation of the cavity\n";
#endif // CGAL_DEBUG_CDT_3 #endif // CGAL_DEBUG_CDT_3
map_cavity_vertices_to_ambient_vertices.clear();
map_cavity_vertices_to_ambient_vertices = std::move(map_lower_cavity_vertices_to_ambient_vertices);
outer_map.clear(); outer_map.clear();
std::vector<std::pair<Facet, CDT_2_face_handle>> new_constrained_facets; std::vector<std::pair<Facet, CDT_2_face_handle>> new_constrained_facets;
new_constrained_facets.reserve(pseudo_cells.size()); new_constrained_facets.reserve(pseudo_cells.size());
@ -1539,7 +1537,8 @@ private:
} }
fill_outer_map_of_cavity(lower_cavity_triangulation, facets_of_lower_cavity); fill_outer_map_of_cavity(lower_cavity_triangulation, facets_of_lower_cavity);
{ {
const auto lower_inner_map = inner_map_of_cavity(lower_cavity_triangulation); const auto lower_inner_map =
inner_map_of_cavity(lower_cavity_triangulation, map_lower_cavity_vertices_to_ambient_vertices);
#if CGAL_DEBUG_CDT_3 & 128 #if CGAL_DEBUG_CDT_3 & 128
std::cerr << "outer_map:\n"; std::cerr << "outer_map:\n";
for(auto [vt, _] : outer_map) { for(auto [vt, _] : outer_map) {
@ -1553,7 +1552,7 @@ private:
write_facets(out, *this, std::ranges::views::values(outer_map)); write_facets(out, *this, std::ranges::views::values(outer_map));
out.close(); out.close();
#endif // CGAL_DEBUG_CDT_3 #endif // CGAL_DEBUG_CDT_3
this->copy_triangulation_into_hole(map_cavity_vertices_to_ambient_vertices, std::move(outer_map), lower_inner_map, this->copy_triangulation_into_hole(map_lower_cavity_vertices_to_ambient_vertices, std::move(outer_map), lower_inner_map,
Emptyset_iterator{}); Emptyset_iterator{});
} }
for(auto c : intersecting_cells) { for(auto c : intersecting_cells) {
@ -1672,18 +1671,19 @@ private:
return {std::nullopt}; return {std::nullopt};
}; };
template <typename Vertex_map>
auto triangulate_cavity(std::set<Cell_handle> cells_of_cavity, auto triangulate_cavity(std::set<Cell_handle> cells_of_cavity,
std::set<Facet>& facets_of_cavity_border, std::set<Facet>& facets_of_cavity_border,
Vertex_map& map_cavity_vertices_to_ambient_vertices,
std::set<Vertex_handle>& vertices_of_cavity) ///@TODO: not deterministic std::set<Vertex_handle>& vertices_of_cavity) ///@TODO: not deterministic
{ {
using Vertex_map = T_3::Vertex_handle_unique_hash_map;
struct { struct {
Constrained_Delaunay_triangulation_3 cavity_triangulation{}; Constrained_Delaunay_triangulation_3 cavity_triangulation{};
Vertex_map vertices_to_ambient_vertices;
std::vector<Facet> interior_constrained_faces; std::vector<Facet> interior_constrained_faces;
std::size_t number_of_added_vertices = 0; std::size_t number_of_added_vertices = 0;
} result; } result;
auto& cavity_triangulation = result.cavity_triangulation; auto& cavity_triangulation = result.cavity_triangulation;
auto& map_cavity_vertices_to_ambient_vertices = result.vertices_to_ambient_vertices;
CGAL::Unique_hash_map<Vertex_handle, Vertex_handle> vertex_map; CGAL::Unique_hash_map<Vertex_handle, Vertex_handle> vertex_map;
auto insert_new_vertex = [&](Vertex_handle v, bool extra_b = false, [[maybe_unused]] std::string_view extra = "") { auto insert_new_vertex = [&](Vertex_handle v, bool extra_b = false, [[maybe_unused]] std::string_view extra = "") {