# vtkClipPolyData results in hollow models

**URL:** https://discourse.slicer.org/t/vtkclippolydata-results-in-hollow-models/42083
**Category:** Development
**Tags:** segmentation, python, 3d-model
**Created:** [March 12, 2025, 8:41am UTC](https://discourse.slicer.org/t/vtkclippolydata-results-in-hollow-models/42083 "2025-03-12T08:41:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![huwqchn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/huwqchn/32/77074_2.png) [@huwqchn](https://discourse.slicer.org/u/huwqchn)
#### Post date: [March 12, 2025, 8:41am UTC](https://discourse.slicer.org/t/vtkclippolydata-results-in-hollow-models/42083/1 "2025-03-12T08:41:29Z")

</div>

Hello All,

I’m trying to use `vtkClipPolyData()` to split a model into two separate segments within a scripted segment editor effect. The operation itself works, but the resulting models are hollow shells (open surfaces) rather than closed, solid segments. I need these segments to be closed surfaces after clipping.

Here is my current code snippet:

```auto
def cutSurfaceWithModel(self, segmentMarkupNode, segmentModel):
    parameterSetNode = self.scriptedEffect.parameterSetNode()
    segmentationNode = parameterSetNode.GetSegmentationNode()
    if not segmentationNode:
        logging.warning("No segmentation node is available.")
        return

    segmentID = parameterSetNode.GetSelectedSegmentID()
    if not segmentID:
        logging.warning("No selected segment to cut.")
        return

    segmentIDs = vtk.vtkStringArray()
    segmentIDs.InsertNextValue(segmentID)

    shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
    exportFolderItemId = shNode.CreateFolderItem(shNode.GetSceneItemID(), "TempExportFolder")
    slicer.modules.segmentations.logic().ExportSegmentsToModels(segmentationNode, segmentIDs, exportFolderItemId)

    modelItemIDs = vtk.vtkIdList()
    shNode.GetItemChildren(exportFolderItemId, modelItemIDs)
    if modelItemIDs.GetNumberOfIds() < 1:
        logging.warning("No segment was exported to model.")
        return

    sourceNode = slicer.mrmlScene.GetNodeByID(shNode.GetItemDataNode(modelItemIDs.GetId(0)).GetID())
    sourcePolyData = vtk.vtkPolyData()
    sourcePolyData.DeepCopy(sourceNode.GetPolyData())
    shNode.RemoveItem(exportFolderItemId)

    segmentPolyData = segmentModel.GetPolyData()
    clipFunction = vtk.vtkImplicitPolyDataDistance()
    clipFunction.SetInput(segmentPolyData)

    clipper = vtk.vtkClipPolyData()
    clipper.SetInputData(sourcePolyData)
    clipper.SetClipFunction(clipFunction)
    clipper.GenerateClippedOutputOn()
    clipper.InsideOutOn()
    clipper.Update()

    insidePolyData = vtk.vtkPolyData()
    insidePolyData.DeepCopy(clipper.GetOutput())

    outsidePolyData = vtk.vtkPolyData()
    outsidePolyData.DeepCopy(clipper.GetClippedOutput())

    segmentationNode.AddSegmentFromClosedSurfaceRepresentation(insidePolyData, "TPSCut_Inside")
    segmentationNode.AddSegmentFromClosedSurfaceRepresentation(outsidePolyData, "TPSCut_Outside")

```
