It’s likely you defined one boundary for the central hole, right? So, you can extend the boundary polyline to achieve the desired output. Just add two additional boundaries connecting the points belonging to the red outlines shown below:
A possible implementation based on that example:
(...)
// Create a cell array to store the boundary polygon in
vtkNew<vtkCellArray> aCellArray;
// Define the polygonal hole with a clockwise polygon for the central boundary
vtkNew<vtkPolygon> aPolygon;
aPolygon->GetPointIds()->InsertNextId(22);
(...)
aPolygon->GetPointIds()->InsertNextId(32);
aCellArray->InsertNextCell(aPolygon);
// Define the polygonal hole with a clockwise polygon for the rightmost boundary
vtkNew<vtkPolygon> aPolygon2;
aPolygon2->GetPointIds()->InsertNextId(42);
(...)
aPolygon2->GetPointIds()->InsertNextId(45);
aCellArray->InsertNextCell(aPolygon2);
// Define the polygonal hole with a clockwise polygon for the leftmost boundary
vtkNew<vtkPolygon> aPolygon3;
aPolygon3->GetPointIds()->InsertNextId(52);
(...)
aPolygon3->GetPointIds()->InsertNextId(55);
aCellArray->InsertNextCell(aPolygon3);
(...)
Thanks for your reply Paulo, I think you misunderstood me . You are right, I defined the inner and outer boundaries for a polygon with holes, but the red area you drew is not what I wanted, the first image is what I wanted
Yeah, you’re right. I can treat the extra triangles as holes. However, this is not universal, and depending on the width and height of the polygon, or other dimensions, it may not generate extra triangles. I’m actually going to generate a perforated polygon based on two or more sets of boundaries. However, the results generated by vtkDelaunay2D are sometimes unstable, which makes me very confused. Is there any other better method recommended?
That is not vtkDelauney2D fault. There is no way for the triangulation algorithm to guess what is hole and what is not based on so few control points. Perhaps you could increase the density of the points along the lines and in the inside areas to have very small triangles. Setting an upper size threshold for the triangles may give you the wanted result automatically. After that first step, optimize the mesh to get back to low poly count. But even this is not quite stable depending on the shapes you have.