How to triangulate polygon with holes?

An example is here:

https://examples.vtk.org/site/Cxx/Modelling/ContourTriangulator/

The typical usage of this class is

vtkNew<vtkContourTriangulator> triangulator;
triangulator->SetInputData(contourData);
triangulator->Update();
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;
appendData->AddInputData(contourB);
appendData->AddInputData(contourA);
appendData->Update();

vtkNew<vtkContourTriangulator> triangulator;
triangulator->SetInputData(appendData->GetOutput());
triangulator->Update();
vtkPolyData *polygons = triangulator->GetOutput();
2 Likes