1
votes

I am trying to compute the 3D Periodic Delaunay Triangulation with the CGAL library, using the example given here as a starting point:

typedef CGAL::Exact_predicates_inexact_constructions_kernel   K;
typedef CGAL::Periodic_3_Delaunay_triangulation_traits_3<K>   Gt;
typedef CGAL::Periodic_3_Delaunay_triangulation_3<Gt>         P3DT3;
typedef CGAL::Creator_uniform_3<double, Point> Creator;
typedef P3DT3::Point             Point;
//...
//...
CGAL::Random random(7);
CGAL::Random_points_in_cube_3<Point, Creator> in_cube(.5, random);
int n = 10000;
std::vector<Point> pts;
P3DT3 T;
// Generating n random points
for (int i=0 ; i < n ; i++) {
    Point p = *in_cube;
    in_cube++;
    pts.push_back(Point(p.x()+.5,p.y()+.5,p.z()+.5));
}
for (int i=0; i<n; i++)
{
    T.insert(pts[i]);
}

They offer three possibilities to insert points, each of them quite fast. However, if I take the example above and insert custom points (instead of the random ones), the insertion is almost 100 times slower. The results are the same, though. Here is a code sample:

typedef CGAL::Exact_predicates_inexact_constructions_kernel   K;
typedef CGAL::Periodic_3_Delaunay_triangulation_traits_3<K>   Gt;
typedef CGAL::Periodic_3_Delaunay_triangulation_3<Gt>         P3DT3;
typedef CGAL::Creator_uniform_3<double, Point> Creator;
typedef P3DT3::Point             Point;
//...
//...
int n = 10000;
std::vector< std::vector<float> > pts(n); // my custom points
P3DT3 T;
for (int i = 0; i < n; i++)
{
    Point p(pts[i][0],pts[i][1],pts[i][2]);
    T.insert(p);
}

Am I doing something wrong? I need to insert a very large point set (~10^7 - 10^8), so speed is critical.

Could it be that T.insert(p) sentence? BTW, what is T? - alseether
I'm sorry, I forgot to define that. I updated the question. The insert() method is called in both cases. There must be some difference in the objects (of type Point) that are inserted - but I can't figure it out. - Julian
It is better if you insert a range of points together instead of inserting them 1 by 1 (they eventually get inserted in random order, which helps). - Marc Glisse
Do you mean something like T.insert(pts.begin(),pts.end()) ? That does help (by a factor of 2 or 3), but it is still pretty slow. - Julian
In addition to Marc's comment, you should set the argument is_large_point_set to true: T.insert(pts.begin(),pts.end(), true). In any case, if your custom points have a very bad distribution, insertion can be slower than for random points (this is also true for non-periodic triangulations) - Monique Teillaud