# vtkClipClosedSurface bad results

**URL:** https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073
**Category:** Support
**Created:** [November 4, 2021, 12:12pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073 "2021-11-04T12:12:50Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 4, 2021, 12:12pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/1 "2021-11-04T12:12:50Z")

</div>

Hi,

Here is a quite simple scene that produces bad result after a vtkClipClosedSurface filter.  
The scene consists of several PolyData nested inside a vtkMultiBlockDataSet.  
The filter is applied by the mean of vtkThreadedCompositeDataPipeline.

Screenshots show before and after clipping.  
You can see there are missing triangles on the “cap” of the cylinder and near it.  
VTM attached.

 ![Before](https://discourse.vtk.org/uploads/default/original/2X/a/a81d70bd028ad9ec9a25e7fdaec95aef6fafbf00.jpeg)  
 ![After](https://discourse.vtk.org/uploads/default/original/2X/5/55d3b69df6ae21d39a9e40df06d5e44c12a9f483.jpeg)  
[export.zip](https://discourse.vtk.org/uploads/short-url/e76DRIWsKiI8YbliwHMp0e3ZPYr.zip) (104.5 KB)

---

<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: [November 4, 2021, 2:39pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/2 "2021-11-04T14:39:45Z")

</div>

From the screenshots, it looks like the outer wall (brown) and inner wall (blue) of the cylinder are separate polydata. If that’s the case, then vtkClipClosedSurface will not work on this dataset.

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 4, 2021, 2:59pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/3 "2021-11-04T14:59:46Z")

</div>

All objects are separated PolyData, and are valid closed shell.  
The brown cylinder is an empty one, and the blue cylinder is filling it.  
There is no reason vtkClipClosedSurface fail …

 ![Cylindre](https://discourse.vtk.org/uploads/default/original/2X/9/99e4fd690fb41f249c6b01ecae1f988ad7bcc0b6.jpeg)  
 ![Cylindre clipped](https://discourse.vtk.org/uploads/default/original/2X/e/ede9153792f30f0faeb6b7619074eeca2aabdcf5.jpeg)

---

<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: [November 4, 2021, 3:05pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/4 "2021-11-04T15:05:11Z")

</div>

Can you show the brown cylinder by itself, both before and after clipping?

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 4, 2021, 3:13pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/5 "2021-11-04T15:13:01Z")

</div>

done

---

<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: [November 4, 2021, 3:17pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/6 "2021-11-04T15:17:57Z")

</div>

Thanks, that helps a lot. Can you tell me which one of the .vtp files it is? I might have time to look at it tonight.

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 4, 2021, 3:19pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/7 "2021-11-04T15:19:29Z")

</div>

export\_44.vtp 😉

---

<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: [November 5, 2021, 2:33am UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/8 "2021-11-05T02:33:31Z")

</div>

I ran the cylinder through [vtkFeatureEdges](https://vtk.org/doc/nightly/html/classvtkFeatureEdges.html) to see if it had any boundary edges, meaning edges that belong to only one polygon. All of the sharp edges are, in fact, boundary edges:  
 ![cylinder](https://discourse.vtk.org/uploads/default/original/2X/6/6af7cbff8d2ff53ad0e009ba9c46826089d80a33.png)

What this means is that the polygons are not connected across those edges. The algorithm used by vtkClipClosedSurface requires connectivity of all polygons, not just spatial adjacency.

In this case, you can fix the problem by passing the cylinder through vtkCleanPolyData before passing it through vtkClipClosedSurface. One caveat to doing this is that the normals associated with the points will be lost, but if the normals are needed they can be re-generated with vtkPolyDataNormals.

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 5, 2021, 8:08am UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/9 "2021-11-05T08:08:43Z")

</div>

Thanks a lot David for you research !

All my geometry is obtained by a tessellator, and is thus triangulated.  
Before passing it to VTK, all coincident vertices are merged, but not the edges / faces.  
Consequently, there is indeed no connectivity (other than pure geometric proximity) between edges / faces.

I’ll try the “cleansing” approach.

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 5, 2021, 6:57pm UTC](https://discourse.vtk.org/t/vtkclipclosedsurface-bad-results/7073/10 "2021-11-05T18:57:48Z")

</div>

Results are ok after vtkCleanPolyData, thanks again.
