Crop segment using shapeNode

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?

Thanks :slight_smile:

A GUI method:

  • convert the segment to a model in the Data module (A)
  • convert the shape to a model using this module (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.

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

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

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

1 Like

Thanks, how can I do that?

VTK classes are very well documented with example code available. For instance, the vtkClipClosedSurface online page points to sample use cases.

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

You can get the polydata of the Shape node like here.

And create a model from the polydata as there.

It works :smile:

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

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.