Search code examples
cgaldelaunay

Delaunay_triangulation_2 in CGAL doesn't keep order of input vertices


I have a set of points and I am doing a CGAL::Delaunay_triangulation_2 with them. However, the order of the points in the resulting triangulation is not the same as in the input points. For example, is input point 0 is in (-1,-1), the output point 0 in the triangulation is not in the same position. The point in position (-1,-1) is another one, but not necesarily the 0th.

For me, it is important to keep the order, as I am taking some references (as indices) to the original set of points, so I need the vertex number i in the input set and in the output set to be the same one.

Is there any way to make the output set be ordered the same as the input set? I dont care if I need to reorder the input set, as I can easily do that before taking the references.


Solution

  • As documented here: "Note that this function is not guaranteed to insert the points following the order of PointInputIterator, as spatial_sort() is used to improve efficiency."

    If you insert your points one by one then they will be in the insertion order (provided there is no duplicate).

    See also this example that can be used to set input id as info() of vertices (then a vector can be created to have direct access from id -> vertex).