From 70b9a1e3633ce3bc6112488ea6e0342ea910c772 Mon Sep 17 00:00:00 2001 From: Hind-M Date: Thu, 30 Jun 2022 16:43:47 +0200 Subject: Reuse vector of points and reserve to avoid reallocations --- src/Cech_complex/include/gudhi/Cech_complex_blocker.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index 1bb205b3..fb452326 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -14,6 +14,8 @@ #include // for casting from FT to Filtration_value #include // for CGAL::exact +#include + #include #include #include @@ -73,6 +75,8 @@ class Cech_blocker { CGAL::NT_converter cast_to_fv; Filtration_value radius = 0; bool is_min_enclos_ball = false; + Point_cloud points; + points.reserve(boost::size(sc_ptr_->simplex_vertex_range(sh))); // for each face of simplex sh, test outsider point is indeed inside enclosing ball, if yes, take it and exit loop, otherwise, new sphere is circumsphere of all vertices for (auto face_opposite_vertex : sc_ptr_->boundary_opposite_vertex_simplex_range(sh)) { @@ -82,19 +86,18 @@ class Cech_blocker { sph = cc_ptr_->get_cache().at(k); } else { - Point_cloud face_points; for (auto vertex : sc_ptr_->simplex_vertex_range(face_opposite_vertex.first)) { - face_points.push_back(cc_ptr_->get_point(vertex)); + points.push_back(cc_ptr_->get_point(vertex)); #ifdef DEBUG_TRACES std::clog << "#(" << vertex << ")#"; #endif // DEBUG_TRACES } - sph = get_sphere(face_points.cbegin(), face_points.cend()); + sph = get_sphere(points.cbegin(), points.cend()); // Put edge sphere in cache sc_ptr_->assign_key(face_opposite_vertex.first, cc_ptr_->get_cache().size()); cc_ptr_->get_cache().push_back(sph); - // Clear face_points - face_points.clear(); + // Clear face points + points.clear(); } // Check if the minimal enclosing ball of current face contains the extra point/opposite vertex if (kernel_.squared_distance_d_object()(sph.first, cc_ptr_->get_point(face_opposite_vertex.second)) <= sph.second) { @@ -113,7 +116,6 @@ class Cech_blocker { } // Spheres of each face don't contain the whole simplex if(!is_min_enclos_ball) { - Point_cloud points; for (auto vertex : sc_ptr_->simplex_vertex_range(sh)) { points.push_back(cc_ptr_->get_point(vertex)); } -- cgit v1.2.3