# Spline to clip a polydata

**URL:** <https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542>\
**Category:** Development\
**Created:** [August 9, 2019, 3:10pm UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542 "2019-08-09T15:10:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bassfaye](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ba9def/32.png) [@bassfaye](https://discourse.vtk.org/u/bassfaye)\
**Post date:** [August 9, 2019, 3:10pm UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/1 "2019-08-09T15:10:17Z")

</div>

Hello,  
I choose some points in a polydata. With these points, I want to create a spline (closed) on the surface of the polydata in order to clip it in two parts.  
How can I do to create that spline? I have seen vtkOrientedGlyphContourRepresentation but it find the shortest path and it is not on the surface.  
Any help would be appreciated.  
Regards,  
Bass

---

<div class="post-metadata">

**Author:** ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)\
**Post date:** [August 10, 2019, 12:58am UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/2 "2019-08-10T00:58:04Z")

</div>

this is just an attempt … i create a closed spline from a bunch of random points on a sphere then create a “ribbon” surface and cut through the sphere with that.  
The blue part is the result. It is not perfect because also a different part of the sphere mesh is selected…

```python
from vtkplotter import *
import numpy as np

s = Sphere().alpha(0.2).lw(0.1)

sc = s.coordinates()
pts = np.array([sc[10], sc[15], sc[129], sc[165], sc[10]])

ptsm = spline(pts, smooth=0).coordinates()
pts0 = ptsm-[.3,0,0]
pts1 = ptsm+[.3,0,0]

rb = Ribbon(pts0, pts1).bc('green')

scut = s.clone().c('blue').alpha(0.5).cutWithMesh(rb)

show(s, scut, Points(pts), Line(ptsm), rb, axes=1, bg='w')

```

 ![Screenshot%20from%202019-08-10%2002-50-33](https://discourse.vtk.org/uploads/default/original/1X/7f542968b134d2efb5815afe7c3785b81f5da230.jpeg)

---

<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:** [August 11, 2019, 3:50am UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/3 "2019-08-11T03:50:24Z")

</div>

You can use the points as loop input in a vtkSelectPolyData filter, enable generation of selection scalars, and get the enclosed surface patch using vtkClipPolyData.

---

<div class="post-metadata">

**Author:** ![bassfaye](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ba9def/32.png) [@bassfaye](https://discourse.vtk.org/u/bassfaye)\
**Post date:** [August 13, 2019, 9:32am UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/4 "2019-08-13T09:32:00Z")

</div>

Thanks for the answer. But it does not resolve my problem. There are some polydata where the vtkSelectPolyData filter can not follow the edge.

---

<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:** [August 13, 2019, 5:52pm UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/5 "2019-08-13T17:52:02Z")

</div>

> [@bassfaye](#):
>
> There are some polydata where the vtkSelectPolyData filter can not follow the edge

Yes, edge following may fail if you don’t provide dense enough point list or the surface has holes. However, if the surface mesh is well behaved and you sample your mesh with appropriate spacing then it works.

---

<div class="post-metadata">

**Author:** ![Beheshtian](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/dfb087/32.png) [@Beheshtian](https://discourse.vtk.org/u/Beheshtian)\
**Post date:** [December 27, 2020, 7:41pm UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/6 "2020-12-27T19:41:21Z")

</div>

Hi Bassirou FAYE,  
could you solve this problem? how?

---

<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:** [December 27, 2020, 10:02pm UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/7 "2020-12-27T22:02:49Z")

</div>

You can use the VTK filters described above but if you want to convenient GUI to extract a surface patch using a closed curve then you can use the recently added [Dynamic modeler module](https://discourse.slicer.org/t/new-module-dynamic-modeler-parametric-surface-editing-for-biomedical-applications/11759) in 3D Slicer.

---

<div class="post-metadata">

**Author:** ![Beheshtian](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/dfb087/32.png) [@Beheshtian](https://discourse.vtk.org/u/Beheshtian)\
**Post date:** [January 2, 2021, 5:04pm UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/8 "2021-01-02T17:04:35Z")

</div>

Hi Andras Lasso,  
thanks for your reply. I need to use Python, also VTK. I use SelectPollyDataFilter but “There are some pollydata where the vtkSelectPollyData filter can not follow the edge”. How I can cut pollydata with a contour widget without SelectPollyDataFilter? or How to use vtkSelectPollyData for pollydataes are not sample?

---

<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:** [March 8, 2022, 8:13pm UTC](https://discourse.vtk.org/t/spline-to-clip-a-polydata/1542/9 "2022-03-08T20:13:34Z")

</div>

For your information, vtkSelectPolyData filter’s “Can’t follow edge” bug (and a few others) are fixed now see [https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/8964](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8964)
