From 535c5bb5b20d1b35d63b54d927b22e45b55b5aa1 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 6 Apr 2016 16:03:55 +0200 Subject: [PATCH] Speed-up Triangulation_3::read_cells... ... by a factor 5 for big triangulations! The old code was using: std::map V; std::map C; whereas the indices are contiguous: from 0 to n. `std::vector` is a lot better for that use case! --- .../include/CGAL/Triangulation_file_input.h | 4 ++-- .../CGAL/Triangulation_data_structure_3.h | 17 ++++++++++------- Triangulation_3/include/CGAL/Triangulation_3.h | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h b/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h index af08e43db88..a7dd3dc32cb 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/Triangulation_file_input.h @@ -66,7 +66,7 @@ std::istream& file_input(std::istream& is, Tr2 &tr, if(!is) return is; tr.tds().set_dimension(d); - std::map< std::size_t, Vertex_handle > V; + std::vector< Vertex_handle > V(n+1); V[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 @@ -80,7 +80,7 @@ std::istream& file_input(std::istream& is, Tr2 &tr, } } - std::map< std::size_t, Cell_handle > C; + std::vector< Cell_handle > C; std::size_t m; tr.tds().read_cells(is, V, m, C); diff --git a/TDS_3/include/CGAL/Triangulation_data_structure_3.h b/TDS_3/include/CGAL/Triangulation_data_structure_3.h index fbdd537dd6a..0eb95a8a97c 100644 --- a/TDS_3/include/CGAL/Triangulation_data_structure_3.h +++ b/TDS_3/include/CGAL/Triangulation_data_structure_3.h @@ -334,8 +334,8 @@ public: } // not documented - void read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V, - std::size_t & m, std::map< std::size_t, Cell_handle > &C ); + void read_cells(std::istream& is, const std::vector< Vertex_handle > &V, + std::size_t & m, std::vector< Cell_handle > &C); // not documented void print_cells(std::ostream& os, const Unique_hash_map &V ) const; @@ -1684,7 +1684,7 @@ operator>>(std::istream& is, Triangulation_data_structure_3& tds) if(n == 0) return is; - std::map V; + std::vector V(n); // creation of the vertices for (std::size_t i=0; i < n; i++) { @@ -1694,7 +1694,7 @@ operator>>(std::istream& is, Triangulation_data_structure_3& tds) V[i] = tds.create_vertex(); } - std::map< std::size_t, Cell_handle > C; + std::vector< Cell_handle > C; std::size_t m; tds.read_cells(is, V, m, C); @@ -2231,8 +2231,8 @@ flip_really( Cell_handle c, int i, int j, template void Triangulation_data_structure_3:: -read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V, - std::size_t & m, std::map< std::size_t, Cell_handle > &C) +read_cells(std::istream& is, const std::vector< Vertex_handle > &V, + std::size_t & m, std::vector< Cell_handle > &C) { // creation of the cells and neighbors switch (dimension()) { @@ -2245,6 +2245,8 @@ read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V, else read(is, m); + C.resize(m); + for(std::size_t i = 0; i < m; i++) { Cell_handle c = create_cell(); for (int k=0; k<=dimension(); ++k) { @@ -2274,7 +2276,7 @@ read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V, case 0: { m = 2; - + C.resize(m); // CGAL_triangulation_assertion( n == 2 ); for (int i=0; i < 2; i++) { Cell_handle c = create_face(V[i], Vertex_handle(), Vertex_handle()); @@ -2290,6 +2292,7 @@ read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V, case -1: { m = 1; + C.resize(m); // CGAL_triangulation_assertion( n == 1 ); Cell_handle c = create_face(V[0], Vertex_handle(), Vertex_handle()); C[0] = c; diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index 743593cf4fb..01bfdbae6a2 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -2121,7 +2121,7 @@ operator>> (std::istream& is, Triangulation_3 &tr) if(!is) return is; tr._tds.set_dimension(d); - std::map< std::size_t, Vertex_handle > V; + std::vector< Vertex_handle > V(n+1); V[0] = tr.infinite_vertex(); // the infinite vertex is numbered 0 @@ -2130,7 +2130,7 @@ operator>> (std::istream& is, Triangulation_3 &tr) if(!(is >> *V[i])) return is; } - std::map< std::size_t, Cell_handle > C; + std::vector< Cell_handle > C; std::size_t m; tr._tds.read_cells(is, V, m, C);