From c10dcf7daf6ba7fa8b382043a220430618492a9b Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 10 Jun 2024 18:18:59 +0200 Subject: [PATCH 1/3] allow to call save_binary_file on non-C3t3 type (like a CDT_3) --- SMDS_3/include/CGAL/IO/File_binary_mesh_3.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h b/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h index e7363047a924..9d3aa0c5d22a 100644 --- a/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h +++ b/SMDS_3/include/CGAL/IO/File_binary_mesh_3.h @@ -46,14 +46,13 @@ save_binary_file(std::ostream& os, , bool binary = true) #endif { - typedef typename C3T3::Triangulation::Geom_traits::FT FT; if(binary) os << "binary "; os << "CGAL c3t3 " << CGAL::Get_io_signature()() << "\n"; if(binary) { CGAL::IO::set_binary_mode(os); } else { CGAL::IO::set_ascii_mode(os); - os.precision(std::numeric_limits::digits10+2); + os.precision(std::numeric_limits::max_digits10); } return !!(os << c3t3); // call operator!() twice, because operator bool() is C++11 From 93fd96644c9e2a1aab33433880afada3e4eed02c Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 15 Apr 2024 11:03:20 +0200 Subject: [PATCH 2/3] use boost::unordered_flat_map to optimize Polyline_constraint_hierarchy_2 --- .../Polyline_constraint_hierarchy_2.h | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/Triangulation_2/include/CGAL/Triangulation_2/internal/Polyline_constraint_hierarchy_2.h b/Triangulation_2/include/CGAL/Triangulation_2/internal/Polyline_constraint_hierarchy_2.h index 73a7db231ac6..b96752e91fe5 100644 --- a/Triangulation_2/include/CGAL/Triangulation_2/internal/Polyline_constraint_hierarchy_2.h +++ b/Triangulation_2/include/CGAL/Triangulation_2/internal/Polyline_constraint_hierarchy_2.h @@ -21,6 +21,15 @@ #include #include #include + +#include +#if BOOST_VERSION >= 108100 +# include +# define CGAL_USE_BOOST_UNORDERED 1 +#else // BOOST before 1.81.0 +# include +#endif + #include #include @@ -134,24 +143,6 @@ class Polyline_constraint_hierarchy_2 } }; - class Pair_compare { - Compare comp; - - public: - Pair_compare(const Compare& comp) : comp(comp) {} - - bool operator()(const Edge& e1, const Edge& e2) const { - if(comp(e1.first, e2.first)) { - return true; - } else if((! comp(e2.first, e1.first)) && // !less(e1,e2) && !less(e2,e1) == equal - comp(e1.second, e2.second)) { - return true; - } else { - return false; - } - } - }; - class Context { friend class Polyline_constraint_hierarchy_2; private: @@ -171,8 +162,11 @@ class Polyline_constraint_hierarchy_2 typedef typename Context_list::iterator Context_iterator; typedef std::set Constraint_set; - typedef std::map Sc_to_c_map; +#if CGAL_USE_BOOST_UNORDERED + typedef boost::unordered_flat_map> Sc_to_c_map; +#else + typedef std::unordered_map> Sc_to_c_map; +#endif typedef typename Constraint_set::iterator C_iterator; typedef typename Sc_to_c_map::const_iterator Sc_iterator; typedef Sc_iterator Subconstraint_iterator; @@ -186,7 +180,7 @@ class Polyline_constraint_hierarchy_2 public: Polyline_constraint_hierarchy_2(const Compare& comp) : comp(comp) - , sc_to_c_map(Pair_compare(comp)) + , sc_to_c_map() { } Polyline_constraint_hierarchy_2(const Polyline_constraint_hierarchy_2& ch); Polyline_constraint_hierarchy_2(Polyline_constraint_hierarchy_2&&) = default; @@ -290,7 +284,7 @@ template Polyline_constraint_hierarchy_2:: Polyline_constraint_hierarchy_2(const Polyline_constraint_hierarchy_2& ch) : comp(ch.comp) - , sc_to_c_map(Pair_compare(comp)) + , sc_to_c_map() { copy(ch); } From 82b53596fd6beaaf6c5accf2182cbdd3553b3365 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 13 Jun 2024 16:31:32 +0200 Subject: [PATCH 3/3] Mesh_2: sort the sequence tr.subconstraints_begin(), tr.subconstraints_end() --- Mesh_2/include/CGAL/Mesh_2/Refine_edges.h | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h b/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h index 852ec07faf0a..b2bb3b50b3de 100644 --- a/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h +++ b/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h @@ -346,12 +346,26 @@ class Refine_edges_base : { // with constraint hierarchy - for(typename Tr::Subconstraint_iterator it = tr.subconstraints_begin(); - it != tr.subconstraints_end(); ++it) - { - const Vertex_handle& v1 = it->first.first; - const Vertex_handle& v2 = it->first.second; + // create a vector of pairs of vertex handles, from the subconstraints + // and sort it to ensure the determinism + std::vector> subconstraints_vector(tr.number_of_subconstraints()); + std::transform(tr.subconstraints_begin(), tr.subconstraints_end(), subconstraints_vector.begin(), + [](const auto& sc) { + return std::array{sc.first.first, sc.first.second}; + }); + + auto comp_vh = [&] (Vertex_handle va, Vertex_handle vb) { + return tr.compare_xy(va->point(), vb->point()) == SMALLER; + }; + auto comp_pair_vh = [&] (const auto& e1, const auto& e2) { + return comp_vh(e1[0], e2[0]) || + (!comp_vh(e2[0], e1[0]) && comp_vh(e1[1], e2[1])); + }; + std::sort(subconstraints_vector.begin(), subconstraints_vector.end(), comp_pair_vh); + + for(const auto& [v1, v2] : subconstraints_vector) + { if(!is_locally_conform(tr, v1, v2) ){ add_constrained_edge_to_be_conformed(v1, v2); }