Speed-up Triangulation_3::read_cells...

... by a factor 5 for big triangulations! The old code was using:

    std::map<size_t, Vertex_handle> V;
    std::map<size_t, Cell_handle> C;

whereas the indices are contiguous: from 0 to n. `std::vector` is a lot
better for that use case!
This commit is contained in:
Laurent Rineau 2016-04-06 16:03:55 +02:00
parent 8e604f70f2
commit 535c5bb5b2
3 changed files with 14 additions and 11 deletions

View File

@ -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);

View File

@ -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<Vertex_handle, std::size_t> &V ) const;
@ -1684,7 +1684,7 @@ operator>>(std::istream& is, Triangulation_data_structure_3<Vb,Cb,Ct>& tds)
if(n == 0)
return is;
std::map<std::size_t , Vertex_handle > V;
std::vector<Vertex_handle > 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<Vb,Cb,Ct>& 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 <class Vb, class Cb, class Ct>
void
Triangulation_data_structure_3<Vb,Cb,Ct>::
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;

View File

@ -2121,7 +2121,7 @@ operator>> (std::istream& is, Triangulation_3<GT, Tds, Lds> &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<GT, Tds, Lds> &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);