proper class encapsulation for CDT_vb_3

This commit is contained in:
Laurent Rineau 2024-01-30 10:57:41 +01:00
parent bbc45c01fa
commit 3cfa54ce1a
3 changed files with 39 additions and 19 deletions

View File

@ -43,10 +43,9 @@ namespace CGAL {
enum class CDT_3_vertex_type { FREE, CORNER, STEINER_ON_EDGE, STEINER_IN_FACE }; enum class CDT_3_vertex_type { FREE, CORNER, STEINER_ON_EDGE, STEINER_IN_FACE };
template <typename Gt, typename Vb = Triangulation_vertex_base_3<Gt> > template <typename Gt, typename Vb = Triangulation_vertex_base_3<Gt> >
struct Conforming_Delaunay_triangulation_vertex_base_3 : public Base_with_time_stamp<Vb> { class Conforming_Delaunay_triangulation_vertex_base_3 : public Base_with_time_stamp<Vb> {
int nb_of_incident_constraints = 0; int nb_of_incident_constraints = 0;
void* c_id = nullptr; void* c_id = nullptr;
private:
CDT_3_vertex_type m_vertex_type = CDT_3_vertex_type::FREE; CDT_3_vertex_type m_vertex_type = CDT_3_vertex_type::FREE;
public: public:
// To get correct vertex type in TDS // To get correct vertex type in TDS
@ -59,6 +58,31 @@ public:
using Base = Base_with_time_stamp<Vb>; using Base = Base_with_time_stamp<Vb>;
using Base::Base; using Base::Base;
void set_on_constraint(auto constraint_id) {
++nb_of_incident_constraints;
c_id = constraint_id.vl_ptr();
}
int number_of_incident_constraints() const {
CGAL_assertion(nb_of_incident_constraints >= 0);
return nb_of_incident_constraints;
}
void mark_vertex() {
CGAL_assertion(nb_of_incident_constraints > 0);
nb_of_incident_constraints = -nb_of_incident_constraints;
}
void unmark_vertex() {
CGAL_assertion(nb_of_incident_constraints < 0);
nb_of_incident_constraints = -nb_of_incident_constraints;
}
bool is_marked() const {
CGAL_assertion(nb_of_incident_constraints != 0);
return nb_of_incident_constraints < 0;
}
template<typename Triangulation> template<typename Triangulation>
auto constraint_id(const Triangulation&) const { auto constraint_id(const Triangulation&) const {
using C_id = typename Triangulation::Constraint_id; using C_id = typename Triangulation::Constraint_id;
@ -209,8 +233,7 @@ protected:
// std::cerr << "- " << oformat(simplex, With_point_tag{}) << '\n'; // std::cerr << "- " << oformat(simplex, With_point_tag{}) << '\n';
if(simplex.dimension() == 0) { if(simplex.dimension() == 0) {
const auto v = static_cast<Vertex_handle>(simplex); const auto v = static_cast<Vertex_handle>(simplex);
v->c_id = c_id.vl_ptr(); v->set_on_constraint(c_id);
++v->nb_of_incident_constraints;
if(prev != Vertex_handle{}) { if(prev != Vertex_handle{}) {
if(v != vb) { if(v != vb) {
v->set_vertex_type(CDT_3_vertex_type::STEINER_ON_EDGE); v->set_vertex_type(CDT_3_vertex_type::STEINER_ON_EDGE);
@ -340,7 +363,7 @@ public:
auto ancestors_of_Steiner_vertex_on_edge(Vertex_handle v) const { auto ancestors_of_Steiner_vertex_on_edge(Vertex_handle v) const {
std::pair<Vertex_handle, Vertex_handle> result; std::pair<Vertex_handle, Vertex_handle> result;
CGAL_precondition(v->is_Steiner_vertex_on_edge()); CGAL_precondition(v->is_Steiner_vertex_on_edge());
CGAL_assertion(v->nb_of_incident_constraints == 1); CGAL_assertion(v->number_of_incident_constraints() == 1);
const auto v_time_stamp = v->time_stamp(); const auto v_time_stamp = v->time_stamp();
const auto constraint_id = v->constraint_id(*this); const auto constraint_id = v->constraint_id(*this);
const auto first = this->constraint_hierarchy.vertices_in_constraint_begin(constraint_id); const auto first = this->constraint_hierarchy.vertices_in_constraint_begin(constraint_id);
@ -449,8 +472,7 @@ protected:
const Vertex_handle v = visitor.insert_in_triangulation(steiner_pt, lt, c, li, lj); const Vertex_handle v = visitor.insert_in_triangulation(steiner_pt, lt, c, li, lj);
v->set_vertex_type(CDT_3_vertex_type::STEINER_ON_EDGE); v->set_vertex_type(CDT_3_vertex_type::STEINER_ON_EDGE);
if(lt != T_3::VERTEX) { if(lt != T_3::VERTEX) {
v->nb_of_incident_constraints = 1; v->set_on_constraint(constraint);
v->c_id = constraint.vl_ptr();
} }
constraint_hierarchy.add_Steiner(va, vb, v); constraint_hierarchy.add_Steiner(va, vb, v);
visitor.insert_Steiner_point_on_constraint(constraint, va, vb, v); visitor.insert_Steiner_point_on_constraint(constraint, va, vb, v);
@ -485,7 +507,7 @@ protected:
} }
Constraint_id constraint_from_extremities(Vertex_handle va, Vertex_handle vb) const { Constraint_id constraint_from_extremities(Vertex_handle va, Vertex_handle vb) const {
if (va->nb_of_incident_constraints == 0 || vb->nb_of_incident_constraints == 0) if (va->number_of_incident_constraints() == 0 || vb->number_of_incident_constraints() == 0)
{ {
return {}; return {};
} }
@ -528,12 +550,12 @@ protected:
return true; return true;
return false; return false;
}; // end lambda constraint_id_goes_to_vb }; // end lambda constraint_id_goes_to_vb
if (va->nb_of_incident_constraints == 1) if (va->number_of_incident_constraints() == 1)
{ {
const Constraint_id c_id = va->constraint_id(*this); const Constraint_id c_id = va->constraint_id(*this);
CGAL_assertion(c_id != Constraint_id{}); CGAL_assertion(c_id != Constraint_id{});
if(constraint_id_goes_to_vb(c_id)) return c_id; if(constraint_id_goes_to_vb(c_id)) return c_id;
} else if (expensive == true && va->nb_of_incident_constraints > 1) { } else if (expensive == true && va->number_of_incident_constraints() > 1) {
boost::container::small_vector<Vertex_handle, 64> adj_vertices; boost::container::small_vector<Vertex_handle, 64> adj_vertices;
this->finite_adjacent_vertices(va, std::back_inserter(adj_vertices)); this->finite_adjacent_vertices(va, std::back_inserter(adj_vertices));
for(auto other_v: adj_vertices) { for(auto other_v: adj_vertices) {
@ -718,7 +740,7 @@ protected:
const auto vector_ab = vector_functor(pa, pb); const auto vector_ab = vector_functor(pa, pb);
if(reference_vertex->is_Steiner_vertex_on_edge()) { if(reference_vertex->is_Steiner_vertex_on_edge()) {
CGAL_assertion(reference_vertex->nb_of_incident_constraints == 1); CGAL_assertion(reference_vertex->number_of_incident_constraints() == 1);
const auto ref_constraint_id = reference_vertex->constraint_id(*this); const auto ref_constraint_id = reference_vertex->constraint_id(*this);
const auto [ref_va, ref_vb] = constraint_extremities(ref_constraint_id); const auto [ref_va, ref_vb] = constraint_extremities(ref_constraint_id);
#if CGAL_CDT_3_DEBUG_CONFORMING #if CGAL_CDT_3_DEBUG_CONFORMING

View File

@ -1028,8 +1028,8 @@ private:
{ {
const auto vc = cell->vertex(index_vd); const auto vc = cell->vertex(index_vd);
const auto vd = cell->vertex(index_vc); const auto vd = cell->vertex(index_vc);
if(vc->nb_of_incident_constraints < 0) return 0; // vertex marked of the border if(vc->is_Steiner_vertex_on_edge() && vc->is_marked()) return 0; // vertex marked of the border
if(vd->nb_of_incident_constraints < 0) return 0; // vertex marked of the border if(vd->is_Steiner_vertex_on_edge() && vd->is_marked()) return 0; // vertex marked of the border
const auto pc = this->point(vc); const auto pc = this->point(vc);
const auto pd = this->point(vd); const auto pd = this->point(vd);
const typename Geom_traits::Segment_3 seg{pc, pd}; const typename Geom_traits::Segment_3 seg{pc, pd};
@ -1282,13 +1282,11 @@ private:
} }
#endif // CGAL_CDT_3_DEBUG_REGION #endif // CGAL_CDT_3_DEBUG_REGION
for(auto v: polygon_border_vertices) { for(auto v: polygon_border_vertices) {
v->nb_of_incident_constraints = -v->nb_of_incident_constraints; v->mark_vertex();
CGAL_assertion(v->is_Steiner_vertex_in_face() || v->nb_of_incident_constraints < 0);
} }
const auto found_edge_opt = search_first_intersection(face_index, cdt_2, fh_region, border_edges); const auto found_edge_opt = search_first_intersection(face_index, cdt_2, fh_region, border_edges);
for(auto v: polygon_border_vertices) { for(auto v: polygon_border_vertices) {
v->nb_of_incident_constraints = -v->nb_of_incident_constraints; v->unmark_vertex();
CGAL_assertion(v->is_Steiner_vertex_in_face() || v->nb_of_incident_constraints > 0);
} }
[[maybe_unused]] auto try_flip_region_size_4 = [&] { [[maybe_unused]] auto try_flip_region_size_4 = [&] {

View File

@ -105,8 +105,8 @@ int main()
for (auto v : cdt.finite_vertex_handles()) { for (auto v : cdt.finite_vertex_handles()) {
std::cout << "Point ( " << v->point() << " )\n"; std::cout << "Point ( " << v->point() << " )\n";
std::cout << " on " << v->nb_of_incident_constraints std::cout << " on " << v->number_of_incident_constraints()
<< " constraint(s): " << v->c_id << "\n"; << " constraint(s)\n";
} }
std::cerr << "test2: " << filename << " " std::cerr << "test2: " << filename << " "
<< (cdt.is_conforming() ? "OK" : "ERROR: NOT CONFORMING") << (cdt.is_conforming() ? "OK" : "ERROR: NOT CONFORMING")