From 060800e2b9d409e5a32339914adde464e86900b4 Mon Sep 17 00:00:00 2001 From: Andras Lasso Date: Thu, 28 Nov 2024 14:59:53 -0500 Subject: [PATCH] Slicer plugin: Keep showing segmentation in 3D when using sam_3d In 3D Slicer, when sam_3d result was imported it always removed the closed surface representation, therefore if a user wanted to see the segmentation in 3D then after each sam_3d update the user had to go to "Segment Editor" section and click "Show 3D". This commit makes the MONAILabel module remember the "Show 3D" state when performing a sam_3d update. --- plugins/slicer/MONAILabel/MONAILabel.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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()