From 69abbc0c6fbd19b1c702d983b04eb69892326da0 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Sat, 3 Feb 2024 17:19:16 +0100 Subject: [PATCH] Add debug_regions(bool) --- .../Conforming_Delaunay_triangulation_3.h | 18 +++++- .../Constrained_Delaunay_triangulation_3.h | 55 +++++++++++++------ .../Triangulation_3/internal/CDT_3_config.h | 14 ++++- .../test/Triangulation_3/cdt_3_from_off.cpp | 11 +++- 4 files changed, 74 insertions(+), 24 deletions(-) diff --git a/Triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h b/Triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h index cc94686b8d7..3abc08cc20b 100644 --- a/Triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h @@ -351,6 +351,14 @@ public: debug_flags.set(static_cast(Debug_flags::missing_region), b); } + bool debug_regions() const { + return debug_flags[static_cast(Debug_flags::regions)]; + } + + void debug_regions(bool b) { + debug_flags.set(static_cast(Debug_flags::regions), b); + } + Vertex_handle insert(const Point &p, Locate_type lt, Cell_handle c, int li, int lj) { @@ -859,8 +867,14 @@ protected: std::stack > subconstraints_to_conform; - enum class Debug_flags { Steiner_points = 0, conforming = 1, missing_region }; - std::bitset<3> debug_flags{}; + enum class Debug_flags { + Steiner_points = 0, + conforming, + missing_region, + regions, + nb_of_flags + }; + std::bitset(Debug_flags::nb_of_flags)> debug_flags{}; }; } // end CGAL diff --git a/Triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h b/Triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h index 7761c735788..ded146abb5d 100644 --- a/Triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Constrained_Delaunay_triangulation_3.h @@ -1004,10 +1004,10 @@ private: border_edges.emplace_back(c, i, j); } } -#if CGAL_CDT_3_DEBUG_REGIONS - std::cerr << "region size is: " << fh_region.size() << "\n"; - std::cerr << "region border size is: " << border_edges.size() << "\n"; -#endif // CGAL_CDT_3_DEBUG_REGIONS + if(this->debug_regions()) { + std::cerr << "region size is: " << fh_region.size() << "\n"; + std::cerr << "region border size is: " << border_edges.size() << "\n"; + } return border_edges; } @@ -1150,12 +1150,14 @@ private: for(std::size_t i = 0; i < intersecting_edges.size(); ++i) { const auto intersecting_edge = intersecting_edges[i]; const auto [v_above, v_below] = tr.vertices(intersecting_edge); -#if CGAL_CDT_3_DEBUG_REGION - std::cerr << std::format("restore_subface_region face index: {}, region #{}, Edge #{}: ({} , {})\n", - face_index, region_index, i, - IO::oformat(v_above, with_point), - IO::oformat(v_below, with_point)); -#endif // CGAL_CDT_3_DEBUG_REGION +#if CGAL_CDT_3_CAN_USE_CXX20_FORMAT + if(this->debug_regions()) { + std::cerr << std::format("restore_subface_region face index: {}, region #{}, intersecting edge #{}: ({} {})\n", + face_index, region_index, i, + IO::oformat(v_above, with_point_and_info), + IO::oformat(v_below, with_point_and_info)); + } +#endif // CGAL_CDT_3_CAN_USE_CXX20_FORMAT CGAL_assertion(0 == region_border_vertices.count(v_above)); CGAL_assertion(0 == region_border_vertices.count(v_below)); if(new_vertex(v_above)) { @@ -1181,8 +1183,23 @@ private: if(region_border_vertices.count(vc) > 0) continue; // intersecting edges cannot touch the border auto test_edge = [&](Vertex_handle v0, int index_v0, Vertex_handle v1, int index_v1, int expected) { + auto value_returned = [this](bool b) { +#if CGAL_CDT_3_CAN_USE_CXX20_FORMAT + if(this->debug_regions()) { + std::cerr << std::format(" return {}\n", b); + } +#endif // CGAL_CDT_3_CAN_USE_CXX20_FORMAT + return b; + }; +#if CGAL_CDT_3_CAN_USE_CXX20_FORMAT + if(this->debug_regions()) { + std::cerr << std::format(" test_edge {} {}) ", + IO::oformat(v0, with_point_and_info), + IO::oformat(v1, with_point_and_info)); + } +#endif // CGAL_CDT_3_CAN_USE_CXX20_FORMAT auto [cached_value_it, not_visited] = new_edge(v0, v1, false); - if(!not_visited) return cached_value_it->second; + if(!not_visited) return value_returned(cached_value_it->second); int v0v1_intersects_region = ((v0->is_Steiner_vertex_in_face() && v0->face_index() == face_index) || (v1->is_Steiner_vertex_in_face() && v1->face_index() == face_index)) ? expected @@ -1198,10 +1215,10 @@ private: } intersecting_edges.emplace_back(cell, index_v0, index_v1); cached_value_it->second = true; - return true; + return value_returned(true); } else { cached_value_it->second = false; - return false; + return value_returned(false); } }; @@ -1280,12 +1297,14 @@ private: } return vertices; }); -#if CGAL_CDT_3_DEBUG_REGION - std::cerr << "region_border_vertices.size() = " << region_border_vertices.size() << "\n"; - for(auto v : region_border_vertices) { - std::cerr << std::format(" {}\n", IO::oformat(v, with_point)); +#if CGAL_CDT_3_CAN_USE_CXX20_FORMAT + if(this->debug_regions()) { + std::cerr << "region_border_vertices.size() = " << region_border_vertices.size() << "\n"; + for(auto v : region_border_vertices) { + std::cerr << std::format(" {}\n", IO::oformat(v, with_point)); + } } -#endif // CGAL_CDT_3_DEBUG_REGION +#endif // CGAL_CDT_3_CAN_USE_CXX20_FORMAT for(auto v: region_border_vertices) { v->mark_vertex(); } diff --git a/Triangulation_3/include/CGAL/Triangulation_3/internal/CDT_3_config.h b/Triangulation_3/include/CGAL/Triangulation_3/internal/CDT_3_config.h index d5d4adacd8b..eead116dfda 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3/internal/CDT_3_config.h +++ b/Triangulation_3/include/CGAL/Triangulation_3/internal/CDT_3_config.h @@ -18,10 +18,18 @@ // // Author(s) : Laurent Rineau -#ifdef CGAL_CDT_3_CONFIG_H +#ifndef CGAL_CDT_3_CONFIG_H #define CGAL_CDT_3_CONFIG_H - #include -#endif // CGAL_CDT_3_CONFIG_H \ No newline at end of file +#define CGAL_CDT_3_CAN_USE_CXX20_FORMAT 0 +#if __has_include() +# include +# if __cpp_lib_format >= 201907L || __cplusplus >= 202000L || _MSVC_LANG >= 202000L +# undef CGAL_CDT_3_CAN_USE_CXX20_FORMAT +# define CGAL_CDT_3_CAN_USE_CXX20_FORMAT 1 +# endif +#endif + +#endif // CGAL_CDT_3_CONFIG_H diff --git a/Triangulation_3/test/Triangulation_3/cdt_3_from_off.cpp b/Triangulation_3/test/Triangulation_3/cdt_3_from_off.cpp index cdb636eea21..1d3184cf884 100644 --- a/Triangulation_3/test/Triangulation_3/cdt_3_from_off.cpp +++ b/Triangulation_3/test/Triangulation_3/cdt_3_from_off.cpp @@ -64,6 +64,8 @@ struct CDT_options bool quiet = false; bool merge_facets = true; bool merge_facets_old_method = false; + bool debug_missing_regions = false; + int debug_regions = false; double ratio = 0.; double vertex_vertex_epsilon = 1e-6; double segment_vertex_epsilon = 1e-8; @@ -141,6 +143,10 @@ int main(int argc, char* argv[]) options.segment_vertex_epsilon = std::stod(argv[++i]); } else if(arg == "--quiet") { options.quiet = true; + } else if(arg == "--debug-missing-regions") { + options.debug_missing_regions = true; + } else if(arg == "--debug-regions") { + options.debug_regions = true; } else if(arg == "-V") { ++options.verbose; } else if(arg == "--help") { @@ -306,9 +312,12 @@ int go(Mesh mesh, CDT_options options) { if(options.verbose > 0) { cdt.debug_Steiner_points(true); } - if(options.verbose > 1) { + if(options.verbose > 1 || options.debug_missing_regions) { cdt.debug_missing_region(true); } + if(options.debug_regions) { + cdt.debug_regions(true); + } cdt.set_segment_vertex_epsilon(options.segment_vertex_epsilon); const auto bbox = CGAL::Polygon_mesh_processing::bbox(mesh);