mirror of https://github.com/CGAL/cgal
Refactor, reindent restore_constrained_Delaunay
This commit is contained in:
parent
155f6791a2
commit
00d815ecb3
|
|
@ -565,6 +565,99 @@ private:
|
||||||
return border_edges;
|
return border_edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restore_face(CDT_3_face_index i) {
|
||||||
|
const CDT_2& cdt_2 = face_cdt_2[i];
|
||||||
|
#if CGAL_DEBUG_CDT_3
|
||||||
|
std::cerr << "cdt_2 has " << cdt_2.number_of_vertices() << " vertices\n";
|
||||||
|
#endif // CGAL_DEBUG_CDT_3
|
||||||
|
for(auto edge : cdt_2.finite_edges()) {
|
||||||
|
const auto fh = edge.first;
|
||||||
|
const auto i = edge.second;
|
||||||
|
const auto va_3d = fh->vertex(cdt_2.cw(i))->info().vertex_handle_3d;
|
||||||
|
const auto vb_3d = fh->vertex(cdt_2.ccw(i))->info().vertex_handle_3d;
|
||||||
|
const bool is_3d = this->tds().is_edge(va_3d, vb_3d);
|
||||||
|
#if CGAL_DEBUG_CDT_3 && __has_include(<format>)
|
||||||
|
std::cerr << std::format("Edge is 3D: {:6} ({} , {})\n",
|
||||||
|
is_3d,
|
||||||
|
oformat(this->point(va_3d)),
|
||||||
|
oformat(this->point(vb_3d)));
|
||||||
|
#endif // CGAL_DEBUG_CDT_3
|
||||||
|
CGAL_assertion(is_3d || !cdt_2.is_constrained(edge));
|
||||||
|
fh->info().is_edge_also_in_3d_triangulation[unsigned(i)] = is_3d;
|
||||||
|
const auto reverse_edge = cdt_2.mirror_edge(edge);
|
||||||
|
reverse_edge.first->info().is_edge_also_in_3d_triangulation[unsigned(reverse_edge.second)] = is_3d;
|
||||||
|
}
|
||||||
|
for(CDT_2_face_handle fh : cdt_2.finite_face_handles()) {
|
||||||
|
if(fh->info().is_outside_the_face) continue;
|
||||||
|
if(false == fh->info().missing_subface) continue;
|
||||||
|
auto fh_region = region(cdt_2, fh);
|
||||||
|
assert(!fh_region.empty());
|
||||||
|
assert(fh == fh_region[0]);
|
||||||
|
auto border_edges = brute_force_border_3_of_region(fh_region);
|
||||||
|
#if CGAL_DEBUG_CDT_3
|
||||||
|
std::cerr << "region size is: " << fh_region.size() << "\n";
|
||||||
|
std::cerr << "region border size is: " << border_edges.size() << "\n";
|
||||||
|
if(border_edges.size() < 3) {
|
||||||
|
std::ofstream dump_region("dump_region_with_size_2.polylines.txt");
|
||||||
|
dump_region.precision(17);
|
||||||
|
write_region(dump_region, fh_region);
|
||||||
|
}
|
||||||
|
#endif // CGAL_DEBUG_CDT_3
|
||||||
|
const auto found_seg = [&]() -> std::optional<Edge> {
|
||||||
|
for(auto fh_2d : fh_region) {
|
||||||
|
CGAL_assertion(true == fh_2d->info().missing_subface);
|
||||||
|
CGAL_assertion(false == fh_2d->info().is_outside_the_face);
|
||||||
|
for(int index = 0; index < 3; ++index) {
|
||||||
|
const auto va_3d = fh_2d->vertex(cdt_2.cw(index))->info().vertex_handle_3d;
|
||||||
|
const auto vb_3d = fh_2d->vertex(cdt_2.ccw(index))->info().vertex_handle_3d;
|
||||||
|
Cell_handle c;
|
||||||
|
int i, j;
|
||||||
|
const bool is_3d = this->tds().is_edge(va_3d, vb_3d, c, i, j);
|
||||||
|
CGAL_assertion(fh_2d->info().is_edge_also_in_3d_triangulation[unsigned(index)] == is_3d);
|
||||||
|
if(is_3d) {
|
||||||
|
auto cell_circ = this->incident_cells(c, i, j), end = cell_circ;
|
||||||
|
CGAL_assertion(cell_circ != nullptr);
|
||||||
|
do {
|
||||||
|
if(this->is_infinite(cell_circ)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto index_va = cell_circ->index(va_3d);
|
||||||
|
const auto index_vb = cell_circ->index(vb_3d);
|
||||||
|
const auto index_vc = this->next_around_edge(index_va, index_vb);
|
||||||
|
const auto index_vd = this->next_around_edge(index_vb, index_va);
|
||||||
|
const auto vc = cell_circ->vertex(index_vd);
|
||||||
|
const auto vd = cell_circ->vertex(index_vc);
|
||||||
|
CGAL_assertion(cell_circ->has_vertex(vc));
|
||||||
|
CGAL_assertion(cell_circ->has_vertex(vd));
|
||||||
|
const auto pc = this->point(vc);
|
||||||
|
const auto pd = this->point(vd);
|
||||||
|
const typename Geom_traits::Segment_3 seg{pc, pd};
|
||||||
|
for(auto fh_2d : fh_region) {
|
||||||
|
const auto triangle = cdt_2.triangle(fh_2d);
|
||||||
|
if(do_intersect(seg, triangle)) {
|
||||||
|
std::cerr << "Segment " << seg << " intersects triangle " << triangle << "\n";
|
||||||
|
return { Edge{cell_circ, index_vc, index_vd} };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while(++cell_circ != end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}();
|
||||||
|
if(!found_seg) {
|
||||||
|
std::cerr << "No segment found\n";
|
||||||
|
{
|
||||||
|
std::ofstream dump("dump.binary.cgal");
|
||||||
|
CGAL::Mesh_3::save_binary_file(dump, *this);
|
||||||
|
std::ofstream dump_region("dump_region.polylines.txt");
|
||||||
|
dump_region.precision(17);
|
||||||
|
write_region(dump_region, fh_region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CGAL_assertion(found_seg != std::nullopt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void restore_constrained_Delaunay()
|
void restore_constrained_Delaunay()
|
||||||
|
|
@ -576,99 +669,7 @@ public:
|
||||||
const auto npos = face_constraint_misses_subfaces.npos;
|
const auto npos = face_constraint_misses_subfaces.npos;
|
||||||
auto i = face_constraint_misses_subfaces.find_first();
|
auto i = face_constraint_misses_subfaces.find_first();
|
||||||
while(i != npos) {
|
while(i != npos) {
|
||||||
const CDT_2& cdt_2 = face_cdt_2[i];
|
restore_face(i);
|
||||||
#if CGAL_DEBUG_CDT_3
|
|
||||||
std::cerr << "cdt_2 has " << cdt_2.number_of_vertices() << " vertices\n";
|
|
||||||
#endif // CGAL_DEBUG_CDT_3
|
|
||||||
for(auto edge : cdt_2.finite_edges()) {
|
|
||||||
const auto fh = edge.first;
|
|
||||||
const auto i = edge.second;
|
|
||||||
const auto va_3d = fh->vertex(cdt_2.cw(i))->info().vertex_handle_3d;
|
|
||||||
const auto vb_3d = fh->vertex(cdt_2.ccw(i))->info().vertex_handle_3d;
|
|
||||||
const bool is_3d = this->tds().is_edge(va_3d, vb_3d);
|
|
||||||
#if CGAL_DEBUG_CDT_3 && __has_include(<format>)
|
|
||||||
std::cerr << std::format("Edge is 3D: {:6} ({} , {})\n",
|
|
||||||
is_3d,
|
|
||||||
oformat(this->point(va_3d)),
|
|
||||||
oformat(this->point(vb_3d)));
|
|
||||||
#endif // CGAL_DEBUG_CDT_3
|
|
||||||
CGAL_assertion(is_3d || !cdt_2.is_constrained(edge));
|
|
||||||
fh->info().is_edge_also_in_3d_triangulation[unsigned(i)] = is_3d;
|
|
||||||
const auto reverse_edge = cdt_2.mirror_edge(edge);
|
|
||||||
reverse_edge.first->info().is_edge_also_in_3d_triangulation[unsigned(reverse_edge.second)] = is_3d;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(CDT_2_face_handle fh : cdt_2.finite_face_handles()) {
|
|
||||||
if(false == fh->info().is_outside_the_face && true == fh->info().missing_subface) {
|
|
||||||
auto fh_region = region(cdt_2, fh);
|
|
||||||
assert(!fh_region.empty());
|
|
||||||
assert(fh == fh_region[0]);
|
|
||||||
auto border_edges = brute_force_border_3_of_region(fh_region);
|
|
||||||
#if CGAL_DEBUG_CDT_3
|
|
||||||
std::cerr << "region size is: " << fh_region.size() << "\n";
|
|
||||||
std::cerr << "region border size is: " << border_edges.size() << "\n";
|
|
||||||
if(border_edges.size() < 3) {
|
|
||||||
std::ofstream dump_region("dump_region_with_size_2.polylines.txt");
|
|
||||||
dump_region.precision(17);
|
|
||||||
write_region(dump_region, fh_region);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // CGAL_DEBUG_CDT_3
|
|
||||||
const auto found_seg = [&]() -> std::optional<Edge> {
|
|
||||||
for(auto fh_2d : fh_region) {
|
|
||||||
CGAL_assertion(true == fh_2d->info().missing_subface);
|
|
||||||
CGAL_assertion(false == fh_2d->info().is_outside_the_face);
|
|
||||||
for(int index = 0; index < 3; ++index) {
|
|
||||||
const auto va_3d = fh_2d->vertex(cdt_2.cw(index))->info().vertex_handle_3d;
|
|
||||||
const auto vb_3d = fh_2d->vertex(cdt_2.ccw(index))->info().vertex_handle_3d;
|
|
||||||
Cell_handle c;
|
|
||||||
int i, j;
|
|
||||||
const bool is_3d = this->tds().is_edge(va_3d, vb_3d, c, i, j);
|
|
||||||
CGAL_assertion(fh_2d->info().is_edge_also_in_3d_triangulation[unsigned(index)] == is_3d);
|
|
||||||
if(is_3d) {
|
|
||||||
auto cell_circ = this->incident_cells(c, i, j), end = cell_circ;
|
|
||||||
CGAL_assertion(cell_circ != nullptr);
|
|
||||||
do {
|
|
||||||
if(this->is_infinite(cell_circ)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto index_va = cell_circ->index(va_3d);
|
|
||||||
const auto index_vb = cell_circ->index(vb_3d);
|
|
||||||
const auto index_vc = this->next_around_edge(index_va, index_vb);
|
|
||||||
const auto index_vd = this->next_around_edge(index_vb, index_va);
|
|
||||||
const auto vc = cell_circ->vertex(index_vd);
|
|
||||||
const auto vd = cell_circ->vertex(index_vc);
|
|
||||||
CGAL_assertion(cell_circ->has_vertex(vc));
|
|
||||||
CGAL_assertion(cell_circ->has_vertex(vd));
|
|
||||||
const auto pc = this->point(vc);
|
|
||||||
const auto pd = this->point(vd);
|
|
||||||
const typename Geom_traits::Segment_3 seg{pc, pd};
|
|
||||||
for(auto fh_2d : fh_region) {
|
|
||||||
const auto triangle = cdt_2.triangle(fh_2d);
|
|
||||||
if(do_intersect(seg, triangle)) {
|
|
||||||
std::cerr << "Segment " << seg << " intersects triangle " << triangle << "\n";
|
|
||||||
return { Edge{cell_circ, index_vc, index_vd} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while(++cell_circ != end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}();
|
|
||||||
if(!found_seg) {
|
|
||||||
std::cerr << "No segment found\n";
|
|
||||||
{
|
|
||||||
std::ofstream dump("dump.binary.cgal");
|
|
||||||
CGAL::Mesh_3::save_binary_file(dump, *this);
|
|
||||||
std::ofstream dump_region("dump_region.polylines.txt");
|
|
||||||
dump_region.precision(17);
|
|
||||||
write_region(dump_region, fh_region);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CGAL_assertion(found_seg != std::nullopt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i = face_constraint_misses_subfaces.find_next(i);
|
i = face_constraint_misses_subfaces.find_next(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue