mirror of https://github.com/CGAL/cgal
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:
parent
8e604f70f2
commit
535c5bb5b2
|
|
@ -66,7 +66,7 @@ std::istream& file_input(std::istream& is, Tr2 &tr,
|
||||||
if(!is) return is;
|
if(!is) return is;
|
||||||
tr.tds().set_dimension(d);
|
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();
|
V[0] = tr.infinite_vertex();
|
||||||
// the infinite vertex is numbered 0
|
// 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;
|
std::size_t m;
|
||||||
tr.tds().read_cells(is, V, m, C);
|
tr.tds().read_cells(is, V, m, C);
|
||||||
|
|
|
||||||
|
|
@ -334,8 +334,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// not documented
|
// not documented
|
||||||
void read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V,
|
void read_cells(std::istream& is, const std::vector< Vertex_handle > &V,
|
||||||
std::size_t & m, std::map< std::size_t, Cell_handle > &C );
|
std::size_t & m, std::vector< Cell_handle > &C);
|
||||||
// not documented
|
// not documented
|
||||||
void print_cells(std::ostream& os,
|
void print_cells(std::ostream& os,
|
||||||
const Unique_hash_map<Vertex_handle, std::size_t> &V ) const;
|
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)
|
if(n == 0)
|
||||||
return is;
|
return is;
|
||||||
|
|
||||||
std::map<std::size_t , Vertex_handle > V;
|
std::vector<Vertex_handle > V(n);
|
||||||
|
|
||||||
// creation of the vertices
|
// creation of the vertices
|
||||||
for (std::size_t i=0; i < n; i++) {
|
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();
|
V[i] = tds.create_vertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map< std::size_t, Cell_handle > C;
|
std::vector< Cell_handle > C;
|
||||||
std::size_t m;
|
std::size_t m;
|
||||||
|
|
||||||
tds.read_cells(is, V, m, C);
|
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>
|
template <class Vb, class Cb, class Ct>
|
||||||
void
|
void
|
||||||
Triangulation_data_structure_3<Vb,Cb,Ct>::
|
Triangulation_data_structure_3<Vb,Cb,Ct>::
|
||||||
read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V,
|
read_cells(std::istream& is, const std::vector< Vertex_handle > &V,
|
||||||
std::size_t & m, std::map< std::size_t, Cell_handle > &C)
|
std::size_t & m, std::vector< Cell_handle > &C)
|
||||||
{
|
{
|
||||||
// creation of the cells and neighbors
|
// creation of the cells and neighbors
|
||||||
switch (dimension()) {
|
switch (dimension()) {
|
||||||
|
|
@ -2245,6 +2245,8 @@ read_cells(std::istream& is, std::map< std::size_t, Vertex_handle > &V,
|
||||||
else
|
else
|
||||||
read(is, m);
|
read(is, m);
|
||||||
|
|
||||||
|
C.resize(m);
|
||||||
|
|
||||||
for(std::size_t i = 0; i < m; i++) {
|
for(std::size_t i = 0; i < m; i++) {
|
||||||
Cell_handle c = create_cell();
|
Cell_handle c = create_cell();
|
||||||
for (int k=0; k<=dimension(); ++k) {
|
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:
|
case 0:
|
||||||
{
|
{
|
||||||
m = 2;
|
m = 2;
|
||||||
|
C.resize(m);
|
||||||
// CGAL_triangulation_assertion( n == 2 );
|
// CGAL_triangulation_assertion( n == 2 );
|
||||||
for (int i=0; i < 2; i++) {
|
for (int i=0; i < 2; i++) {
|
||||||
Cell_handle c = create_face(V[i], Vertex_handle(), Vertex_handle());
|
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:
|
case -1:
|
||||||
{
|
{
|
||||||
m = 1;
|
m = 1;
|
||||||
|
C.resize(m);
|
||||||
// CGAL_triangulation_assertion( n == 1 );
|
// CGAL_triangulation_assertion( n == 1 );
|
||||||
Cell_handle c = create_face(V[0], Vertex_handle(), Vertex_handle());
|
Cell_handle c = create_face(V[0], Vertex_handle(), Vertex_handle());
|
||||||
C[0] = c;
|
C[0] = c;
|
||||||
|
|
|
||||||
|
|
@ -2121,7 +2121,7 @@ operator>> (std::istream& is, Triangulation_3<GT, Tds, Lds> &tr)
|
||||||
if(!is) return is;
|
if(!is) return is;
|
||||||
tr._tds.set_dimension(d);
|
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();
|
V[0] = tr.infinite_vertex();
|
||||||
// the infinite vertex is numbered 0
|
// 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;
|
if(!(is >> *V[i])) return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map< std::size_t, Cell_handle > C;
|
std::vector< Cell_handle > C;
|
||||||
|
|
||||||
std::size_t m;
|
std::size_t m;
|
||||||
tr._tds.read_cells(is, V, m, C);
|
tr._tds.read_cells(is, V, m, C);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue