diff --git a/plugins/slicer/MONAILabel/MONAILabel.py b/plugins/slicer/MONAILabel/MONAILabel.py index d018631cd..1346f55b3 100644 --- a/plugins/slicer/MONAILabel/MONAILabel.py +++ b/plugins/slicer/MONAILabel/MONAILabel.py @@ -1823,9 +1823,20 @@ def updateSegmentationMask(self, in_file, labels, sliceIndex=None, freeze=None): segmentIds.InsertNextValue(label) # faster import (based on selected segmentIds) + + # ImportLabelmapToSegmentationNode overwrites segments, which removes all non-source representations. + # We remember if closed surface representation was present and restore it after import. + segmentationRepresentationNames = [] + segmentationNode.GetSegmentation().GetContainedRepresentationNames(segmentationRepresentationNames) + hasClosedSurfaceRepresentation = slicer.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName() in segmentationRepresentationNames + slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode( labelmapVolumeNode, segmentationNode, segmentIds ) + + if hasClosedSurfaceRepresentation: + segmentationNode.CreateClosedSurfaceRepresentation() + slicer.mrmlScene.RemoveNode(labelmapVolumeNode) else: existingCount = segmentation.GetNumberOfSegments()