Faster insert for iterator ranges in Triangulation_hierarchy_2.

This commit is contained in:
Christophe Delage 2007-09-05 13:57:52 +00:00
parent 8342dfe408
commit 3feac5dc4c
1 changed files with 23 additions and 4 deletions

View File

@ -97,20 +97,39 @@ public:
template < class InputIterator >
int insert(InputIterator first, InputIterator last)
{
{
int n = this->number_of_vertices();
std::vector<Point> points CGAL_make_vector(first, last);
std::random_shuffle (points.begin(), points.end());
CGAL::spatial_sort (points.begin(), points.end(), geom_traits());
Face_handle hint;
// hints[i] is the face of the previously inserted point in level i.
// Thanks to spatial sort, they are better hints than what the hierarchy
// would give us.
Face_handle hints[Triangulation_hierarchy_2__maxlevel];
for (typename std::vector<Point>::const_iterator p = points.begin(), end = points.end();
p != end; ++p)
hint = insert (*p, hint)->face();
{
int vertex_level = random_level();
Vertex_handle v = hierarchy[0]->insert (*p, hints[0]);
hints[0] = v->face();
Vertex_handle prev = v;
for (int level = 1; level <= vertex_level; ++level) {
v = hierarchy[level]->insert (*p, hints[level]);
hints[level] = v->face();
v->set_down (prev);
prev->set_up (v);
prev = v;
}
}
return this->number_of_vertices() - n;
}
}
void remove_degree_3(Vertex_handle v);
void remove_first(Vertex_handle v);