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

**URL:** https://discourse.vtk.org/t/construct-a-2d-surface-based-on-points-defining-the-outline-of-an-arbitrary-shape/2354
**Category:** Support
**Created:** [December 28, 2019, 6:15pm UTC](https://discourse.vtk.org/t/construct-a-2d-surface-based-on-points-defining-the-outline-of-an-arbitrary-shape/2354 "2019-12-28T18:15:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![michael23](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael23/32/837_2.png) [@michael23](https://discourse.vtk.org/u/michael23)
#### Post date: [December 28, 2019, 6:15pm UTC](https://discourse.vtk.org/t/construct-a-2d-surface-based-on-points-defining-the-outline-of-an-arbitrary-shape/2354/1 "2019-12-28T18:15:16Z")

</div>

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.

 ![Wireframe](https://discourse.vtk.org/uploads/default/original/2X/4/452f8bb8b8361e220ef8fa3b0b0da51067ba4271.jpeg) ![Surface](https://discourse.vtk.org/uploads/default/original/2X/c/c2604f5415de9d629089e8a766c03bb4ef9db202.jpeg)

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

 ![Triangulated](https://discourse.vtk.org/uploads/default/original/2X/2/2fa117face6e7de03978c859cae2bf9bf7de71da.jpeg)

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

Thank you.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [December 29, 2019, 12:20pm UTC](https://discourse.vtk.org/t/construct-a-2d-surface-based-on-points-defining-the-outline-of-an-arbitrary-shape/2354/2 "2019-12-29T12:20:54Z")

</div>

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`](https://vtk.org/doc/nightly/html/classvtkDelaunay2D.html) which is an algorithm with more parameters that you can use to fine tune the output.

all the best,

Paulo
