# VTK Surface creation with vtkExtractSurface

**URL:** https://discourse.vtk.org/t/vtk-surface-creation-with-vtkextractsurface/2041
**Category:** Support
**Created:** [November 5, 2019, 8:05am UTC](https://discourse.vtk.org/t/vtk-surface-creation-with-vtkextractsurface/2041 "2019-11-05T08:05:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![gishu](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/50afbb/32.png) [@gishu](https://discourse.vtk.org/u/gishu)
#### Post date: [November 5, 2019, 8:05am UTC](https://discourse.vtk.org/t/vtk-surface-creation-with-vtkextractsurface/2041/1 "2019-11-05T08:05:44Z")

</div>

Dear all,

I have a set of unstructured points that lies on a surface. I want to create a surface, I am using below example:

[http://www.kwwidgets.com/Wiki/VTK/Examples/Cxx/Points/ExtractSurfaceDemo](http://www.kwwidgets.com/Wiki/VTK/Examples/Cxx/Points/ExtractSurfaceDemo)

However the mesh is not created properly, I have attached a picture of it. It has holes I tried to use vtkFillHolesFilter and contourfilter without any luck.  
Below is my code:

```
    double bounds[6];

```

polydata\_boundary-\>GetBounds(bounds);  
double range[3];  
for (int i = 0; i \< 3; ++i)  
{  
range[i] = bounds[2 \* i + 1] - bounds[2 \* i];  
}

int sampleSize = polydata\_boundary-\>GetNumberOfPoints() \* .00005;  
if (sampleSize \< 10)  
{  
sampleSize = 10;  
}  
std::cout \<\< "Sample size is: " \<\< sampleSize \<\< std::endl;  
// Do we need to estimate normals?  
vtkSmartPointer distance =  
vtkSmartPointer::New();  
if (polydata\_boundary-\>GetPointData()-\>GetNormals())  
{  
std::cout \<\< “Using normals from input file” \<\< std::endl;  
distance-\>SetInputData(polydata\_boundary);  
}  
else  
{  
std::cout \<\< “Estimating normals using PCANormalEstimation” \<\< std::endl;  
vtkSmartPointer normals =  
vtkSmartPointer::New();  
normals-\>SetInputData(polydata\_boundary);  
normals-\>SetSampleSize(sampleSize);  
normals-\>SetNormalOrientationToGraphTraversal();  
normals-\>FlipNormalsOn();  
distance-\>SetInputConnection(normals-\>GetOutputPort());  
}  
std::cout \<\< "Range: "  
\<\< range[0] \<\< ", "  
\<\< range[1] \<\< ", "  
\<\< range[2] \<\< std::endl;  
int dimension = 256;  
double radius = range[0] \* .2;  
radius = range[0] / static\_cast(dimension) \* 20; // ~3 voxels  
std::cout \<\< "Radius: " \<\< radius \<\< std::endl;

distance-\>SetRadius(radius);  
distance-\>SetDimensions(dimension, dimension, dimension);  
distance-\>SetBounds(  
bounds[0] - range[0] \* .1,

 ![vtk1](https://discourse.vtk.org/uploads/default/original/2X/4/48165b441c01d91942e8763e2e1a600c624f3c9a.png)  
bounds[1] + range[0] \* .1,  
bounds[2] - range[1] \* .1,  
bounds[3] + range[1] \* .1,  
bounds[4] - range[2] \* .1,  
bounds[5] + range[2] \* .1);

vtkSmartPointer surface =  
vtkSmartPointer::New();  
surface-\>SetInputConnection(distance-\>GetOutputPort());  
surface-\>SetRadius(radius \* .99);  
surface-\>SetHoleFilling(true);  
surface-\>Update();

Please let me know your suggestions. Thanks in advance.
