Construct a 2D surface based on points defining the outline of an arbitrary shape

Hello,

I have a set of points which define the outline of an arbitrary shape. The shape is closed and contains no holes. Now I want to create the corresponding surface in VTK.

My current approach is to create a vtkPolyData as follows:

// Create the points
auto points = vtkSmartPointer::New();
for (int i = 0; i < shape.count(); i++)
{
points->InsertNextPoint(shape.at(i).x(), shape.at(i).y(), 0);
}

// Create a polygon
vtkSmartPointer polygon = vtkSmartPointer::New();
polygon->GetPointIds()->SetNumberOfIds(shape.count());
for (int i = 0; i < shape.count(); i++)
{
polygon->GetPointIds()->SetId(i, i);
}

// Add the polygon to a list of polygons
vtkSmartPointer polygons = vtkSmartPointer::New();
polygons->InsertNextCell(polygon);

// Create a PolyData
vtkSmartPointer polydata = vtkSmartPointer::New();
polydata ->SetPoints(points);
polydata ->SetPolys(polygons);

The resulting shape is correct when using the “Wireframe” representation. Nevertheless, the “Surface” representation is wrong.

I tried to triangulate the polygon using vtkTriangleFilter, but the result contains a rectangular hole (vtkFillHolesFilter does not help).

Any ideas how to create a simple vtkPolyData surface based on some points defining the outline of the shape?

Thank you.

Hello, Michael,

I suggest you do add control points in the inside of the shape, so the algorithm will fill the inside with triangle. You can start experimenting by adding a single point at the center of the shape. In the particular case of your example, computing the mean x, y, z of all points will do.

You can also try vtkDelaunay2D which is an algorithm with more parameters that you can use to fine tune the output.

all the best,

Paulo