# Clipping an stl with a cylinder

**URL:** https://discourse.vtk.org/t/clipping-an-stl-with-a-cylinder/2012
**Category:** Support
**Created:** [October 31, 2019, 9:03am UTC](https://discourse.vtk.org/t/clipping-an-stl-with-a-cylinder/2012 "2019-10-31T09:03:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [October 31, 2019, 9:03am UTC](https://discourse.vtk.org/t/clipping-an-stl-with-a-cylinder/2012/1 "2019-10-31T09:03:24Z")

</div>

Hi !!

I have a doubt i try to make a hole to a polydata (stl) given a cylinder but the resulting hole is not smooth.  
[Screenshot\_1|552x500](https://discourse.vtk.org/uploads/short-url/q4LjTAPRv8FnVGZLV8ANCCOGuwo.png)

I have also tried vtkBooleanOperationPolyDataFilter but it is very very slow. It can be hours so i cannot use it.

There is a faster way to make holes in an stl (polydata) with smooth results? Or i have to use stencils to transform it into volume, make the boolean operation with images and transform it back to surface?

Thanks

```
       vtkSmartPointer<vtkDelaunay3D> tri = vtkSmartPointer<vtkDelaunay3D>::New();
	tri->SetInputData(PolyData);
	tri->BoundingTriangulationOff();
	tri->Update();

	//vtkImplicitDataSet needs some scalars to interpolate to find inside / outside
	vtkSmartPointer<vtkElevationFilter>	elev = vtkSmartPointer<vtkElevationFilter>::New();
	elev->SetInputConnection(tri->GetOutputPort());
	elev->Update();
	vtkSmartPointer<vtkImplicitDataSet> implicit = vtkSmartPointer<vtkImplicitDataSet>::New();
	implicit->SetDataSet(elev->GetOutput());

	vtkSmartPointer<vtkClipPolyData> clipper = vtkSmartPointer<vtkClipPolyData>::New();
	clipper->SetClipFunction(implicit);
	clipper->SetInputData(extrude_dental);
	clipper->InsideOutOn();
	clipper->Update();
```

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [October 31, 2019, 11:37am UTC](https://discourse.vtk.org/t/clipping-an-stl-with-a-cylinder/2012/2 "2019-10-31T11:37:27Z")

</div>

Boolean operation on meshes is one of the hardest problems problems in computational geometry. Considering that, the result you got on your first try is quite good. If you increase your mesh resolution then you may get acceptable results. You can also try Roemer’s Boolean filter implementation ([Adding Roemer's Boolean Filter as a Remote Module](https://discourse.vtk.org/t/adding-roemers-boolean-filter-as-a-remote-module/1635/34)) and you may find a few other relevant discussions on this forum (search for words like Boolean, intersection).

---

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [October 31, 2019, 3:32pm UTC](https://discourse.vtk.org/t/clipping-an-stl-with-a-cylinder/2012/3 "2019-10-31T15:32:22Z")

</div>

Thank you very much for your quick respose. I will follow this post. By now, i will use stencils. The results are a bit better and faster. And i will check novelties in this topic.

---

<div class="post-metadata">

### Author: ![Ron84](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ron84/32/630_2.png) [@Ron84](https://discourse.vtk.org/u/Ron84)
#### Post date: [October 31, 2019, 3:52pm UTC](https://discourse.vtk.org/t/clipping-an-stl-with-a-cylinder/2012/4 "2019-10-31T15:52:22Z")

</div>

Please try it: [https://github.com/zippy84/vtkbool](https://github.com/zippy84/vtkbool)

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 31, 2019, 5:41pm UTC](https://discourse.vtk.org/t/clipping-an-stl-with-a-cylinder/2012/5 "2019-10-31T17:41:34Z")

</div>

If you want to clip all the way through your polydata with a cylinder, then the fastest way is to use [vtkClipPolyData](https://vtk.org/doc/nightly/html/classvtkClipPolyData.html) with [vtkCylinder](https://vtk.org/doc/nightly/html/classvtkCylinder.html). The vtkCylinder defines an implicit function for the cylinder, instead of defining the cylinder with polygons. Clipping polydata with a function is hundreds of times faster than clipping polydata with another polydata.

For example, see [this example](https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/ClipSphereCylinder/) (unfortunately, it’s not a good example, since the example is much more complicated than what you need).

Edit: Note that if you use vtkImplicitDataSet to create the implicit function, you lose all of the speed benefits of implicit functions. The fast implicit functions are the simple ones: vtkPlane, vtkCylinder, vtkSphere and vtkImplicitVolume.
