From ce7761d00bb9dd0dcd611eff33f741385aa762b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Sat, 24 Feb 2024 00:15:49 +0100 Subject: [PATCH] Use unordered maps --- .../internal/dual_contouring_functors.h | 12 +++--- .../partition_traits_Cartesian_grid.h | 40 +++++++++++++++++-- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/dual_contouring_functors.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/dual_contouring_functors.h index a696bfeba45..e2f35256e2a 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/dual_contouring_functors.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/dual_contouring_functors.h @@ -315,8 +315,8 @@ public: const bool do_not_triangulate_faces = choose_parameter(get_parameter(np, internal_np::do_not_triangulate_faces), false); - using Edge_to_point_ID_map = std::map; - using Cell_to_point_ID_map = std::map; + using Edge_to_point_ID_map = std::unordered_map; + using Cell_to_point_ID_map = std::unordered_map; Edge_to_point_ID_map edge_to_point_id; Cell_to_point_ID_map cell_to_point_id; @@ -446,8 +446,8 @@ public: bool do_not_triangulate_faces = choose_parameter(get_parameter(np, internal_np::do_not_triangulate_faces), false); - using Edge_to_point_ID_map = std::map; - using Cell_to_point_ID_map = std::map; + using Edge_to_point_ID_map = std::unordered_map; + using Cell_to_point_ID_map = std::unordered_map; Edge_to_point_ID_map edge_to_point_id; Cell_to_point_ID_map cell_to_point_id; @@ -560,8 +560,8 @@ public: bool do_not_triangulate_faces = choose_parameter(get_parameter(np, internal_np::do_not_triangulate_faces), false); - using Edge_to_point_ID_map = std::map; - using Cell_to_point_ID_map = std::map; + using Edge_to_point_ID_map = std::unordered_map; + using Cell_to_point_ID_map = std::unordered_map; Edge_to_point_ID_map edge_to_point_id; Cell_to_point_ID_map cell_to_point_id; diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Cartesian_grid.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Cartesian_grid.h index 8786c8c6cb6..94d18dfbcfd 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Cartesian_grid.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/partition_traits_Cartesian_grid.h @@ -37,19 +37,22 @@ class Cartesian_grid_3; template struct partition_traits; +struct CG_Edge_descriptor : public std::array { }; +struct CG_Cell_descriptor : public std::array { }; + template struct partition_traits > { - using Self = Cartesian_grid_3; + using Grid = Cartesian_grid_3; // identifies a vertex by its (i, j, k) indices using Vertex_descriptor = std::array; // identifies an edge by its starting vertex (i, j, k) and the direction x -> 0, y -> 1, z -> 2 - using Edge_descriptor = std::array; + using Edge_descriptor = CG_Edge_descriptor; // identifies a cell by its corner vertex with the smallest (i, j, k) index - using Cell_descriptor = std::array; + using Cell_descriptor = CG_Cell_descriptor; static constexpr Cell_type CELL_TYPE = CUBICAL_CELL; static constexpr std::size_t VERTICES_PER_CELL = 8; @@ -259,4 +262,35 @@ struct partition_traits > } // namespace Isosurfacing } // namespace CGAL +namespace std { + +template <> +struct hash +{ + std::size_t operator()(const CGAL::Isosurfacing::CG_Edge_descriptor& e) const + { + std::size_t seed = 0; + boost::hash_combine(seed, e[0]); + boost::hash_combine(seed, e[1]); + boost::hash_combine(seed, e[2]); + boost::hash_combine(seed, e[3]); + return seed; + } +}; + +template <> +struct hash +{ + std::size_t operator()(const CGAL::Isosurfacing::CG_Cell_descriptor& e) const + { + std::size_t seed = 0; + boost::hash_combine(seed, e[0]); + boost::hash_combine(seed, e[1]); + boost::hash_combine(seed, e[2]); + return seed; + } +}; + +} // namespace std + #endif // CGAL_ISOSURFACING_3_INTERNAL_PARTITION_TRAITS_CARTESIAN_GRID_3_H