# Crop segment using shapeNode

**URL:** <https://discourse.slicer.org/t/crop-segment-using-shapenode/43822>\
**Category:** Support\
**Created:** [July 23, 2025, 9:38am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822 "2025-07-23T09:38:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [July 23, 2025, 9:38am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/1 "2025-07-23T09:38:48Z")

</div>

Hi all,

I’m working with a segment representing a tubular geometry, and I have a `vtkMRMLMarkupsShapeNode` representing a cylinder placed at the end of this structure.

I’d like to crop or cut the segment using the plane defined by the cylinder’s base (the red line).

Is there a recommended way to use the shape node’s geometry — particularly the cylinder’s plane — to perform this kind of clipping on the segment?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/2/d2cb268e5971d505cc11da04661076b096316b5a.png)

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [July 23, 2025, 10:07am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/2 "2025-07-23T10:07:12Z")

</div>

A GUI method:

- convert the segment to a model in the Data module (A)
- convert the shape to a model using this [module](https://gitlab.com/chir-set/Tools7/-/tree/master/MarkupsToSurface?ref_type=heads) (B)
- perform (A - B) difference in the Combine models module
- convert the result to a segmentation in the Data module.

Alternatively, scripting in python would be faster. You would need to apply vtkPlane and vtkCutter on the segment’s closed surface representation.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [July 23, 2025, 10:12am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/3 "2025-07-23T10:12:52Z")

</div>

Many thanks, I’ll try it. Is there any possibility of doing this directly using segmentation nodes instead of models?

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [July 23, 2025, 10:29am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/4 "2025-07-23T10:29:12Z")

</div>

> [@bserrano](#):
>
> using segmentation nodes instead of models?

Yes, you can create a segment from the shape and then use the `Logical operators` effect.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [July 23, 2025, 10:33am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/5 "2025-07-23T10:33:45Z")

</div>

> [@chir.set](#):
>
> apply vtkPlane and vtkCutter on the segment’s closed surface representation.

Erratum : `vtkCutter` won’t be useful actually, but `vtkClipPolyData` and/or `vtkClipClosedSurface` would be more appropriate.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [July 23, 2025, 10:38am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/6 "2025-07-23T10:38:29Z")

</div>

Thanks, how can I do that?

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [July 23, 2025, 11:48am UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/7 "2025-07-23T11:48:34Z")

</div>

VTK classes are very well documented with example code available. For instance, the [vtkClipClosedSurface](https://vtk.org/doc/nightly/html/classvtkClipClosedSurface.html) online page points to [sample](https://vtk.org/doc/nightly/html/c2_vtk_t_3.html#c2_vtk_t_vtkClipClosedSurface) use cases.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [July 23, 2025, 12:00pm UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/8 "2025-07-23T12:00:49Z")

</div>

I am trying but I cannot figure out how to convert the ‘vtkMRMLMarkupsShapeNode’ (cylinder) to model. Lastly I tryied with markups to model, but it only creates a triangle with the 3 points that define the cylinder

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/d/fd48b76d24ed5b4fbad3ba6522d1ffc1d8a5e66f.png)

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [July 23, 2025, 1:00pm UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/9 "2025-07-23T13:00:51Z")

</div>

> [@bserrano](#):
>
> how to convert the ‘vtkMRMLMarkupsShapeNode’ (cylinder) to model

You can get the polydata of the Shape node like [here](https://gitlab.com/chir-set/Tools7/-/blob/023b72cbb85e48ce53d91bf70ca34219f8d002d1/MarkupsToSurface/MarkupsToSurface.py#L467).

And create a model from the polydata as [there](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository/models.html#show-a-simple-surface-mesh-as-a-model-node).

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [July 23, 2025, 1:18pm UTC](https://discourse.slicer.org/t/crop-segment-using-shapenode/43822/10 "2025-07-23T13:18:44Z")

</div>

It works 😄

This is the code, just in case is useful for anybody else:

```auto
shapeNode = getNode('MyMarkupsCylinder')
nodePolyData = shapeNode.GetShapeWorld()
modelNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode", "MyModel")
modelNode.SetAndObservePolyData(nodePolyData)
modelNode.CreateDefaultDisplayNodes()
modelNode.GetDisplayNode().SetColor(1, 0, 0)

```

Then I imported modelNode as segment using Segmentations module.
