4

I'm new with CGAL, i'm sure my question is very simple.

I am trying to use CGAL to do some Delaunay triangulation. I have a grid with N 3D points over a sphere and I want to triangulate the sphere using those points as the vertex of the triangles. I just need to get a list of the vertex of the resulting triangles like that:

id_triangle1 vertex_1 vertex_2 vertex_3 id_triangle2 vertex_1 vertex_2 vertex_3 .......

I have done that to perform the triangulation:

    std::vector<Point> P; 
    for(i=0;i<NSPOINTS;i++) 
            P.push_back(Point(GRID[i].x,GRID[i].y,GRID[i].z)); 

    // building Delaunay triangulation. 
    Delaunay dt(P.begin(), P.end()); 

The problem I have is that I have no idea how to get the resulting triangulation. I figured out how to get the face_iterator, but I don't know what to do from there:

    Delaunay::Finite_faces_iterator it; 
    for (it = dt.finite_faces_begin(); it != dt.finite_faces_end(); it++){ 
            std::cout << dt.triangle(it) << std::endl; 
    } 

I'm not sure if that is correct to iterate over the triangles, and if it is... a triangle = face ??¿ , i mean , each iterator position have only a triangle¿? How can I get correctly the x,y and z of each triangle¿?¿

gsamaras
  • 71,951
  • 46
  • 188
  • 305
horstmann
  • 149
  • 1
  • 2
  • 8

2 Answers2

6

As documented here, a Facet is a pair (Cell_handle,int). The integer indicate the index of the cell opposite to the facet. So getting access to the points of the facet can be done like this: it->first->vertex( (it->second+k)%4 )->point() with k=1->3.

Note that if you are interested in a triangulation of a sphere (i.e. a surface triangulation), you need to consider only facets incident to an infinite cell. Also, using the convex-hull solves this problem, see this example.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
sloriot
  • 6,070
  • 18
  • 27
  • Thank you for the fast answer, but I still don't know how to iterate over the resulting triangles, and how to get the indexes of the vertices of each triangles. As I said before, I need something like that: triangle_1 v1 v2 v3 triangle_2 v1 v3 v4 triangle_3 v2 v4 v5 ...... and so on. (At the moment, I'm not interested in the vertices x,y,z coordinates, but its indexes) Thank you again in advance. – horstmann Oct 31 '11 at 11:15
  • The follow-up lies here: http://cgal-discuss.949826.n4.nabble.com/Help-getting-triangles-coordinates-from-Delaunay-Triangulation-td3955310.html – gsamaras Apr 14 '16 at 08:58
0

If you google for finite_faces_begin() you can get a lot of CGAL hints.

The faces iterator will allow you to get at the underlying data in different ways. Here is a nice example from something called "tesis" that uses the 'vertex()' function.

http://mati-repa-repo.googlecode.com/svn/trunk/tesis/impl/HODTs/

for( Finite_faces_iterator fi = dt.finite_faces_begin(); fi != dt.finite_faces_end(); fi++){
    Point2 point0 = Point2(fi->vertex(0)->point().hx(), fi->vertex(0)->point().hy());
    Point2 point1 = Point2(fi->vertex(1)->point().hx(), fi->vertex(1)->point().hy());
    Point2 point2 = Point2(fi->vertex(2)->point().hx(), fi->vertex(2)->point().hy());
    ...
}

Good luck.

don bright
  • 1,113
  • 1
  • 11
  • 15