How to triangulate polygon with holes?

I have a set of 3d points defining a polygon A, and a set of points defining polygon B. All these points are planar, and A is actually a loop within B.
My question is: how can i generate a triangulated polygon with hole? ie. the green region on the right.


I searched relevant documentation and found that vtkContourTriangulator::TriangulateContours( can do this. However, I don’t know how to use this function. Is there any example code for this?


An example is here:

The typical usage of this class is

vtkNew<vtkContourTriangulator> triangulator;
vtkPolyData *polygons = triangulator->GetOutput();

If you have concentric contours, you can append them before triangulating them. For good results, the contours should be in opposite directions. If B is counterclockwise, then A should be clockwise.

vtkNew<vtkAppendPolyData> appendData;

vtkNew<vtkContourTriangulator> triangulator;
vtkPolyData *polygons = triangulator->GetOutput();
1 Like

thanks! that’s exatcly what I’m looking for.

I tried the code above and encountered an empty result. After a bit of toggle I found that the root cause is I forgot to set the lines of polygon’s polydata. For anyone who needs to do the same, remember to set the lines before using vtkContourTriangulator.