Skip to content

Commit

Permalink
Slicer plugin: Keep showing segmentation in 3D when using sam_3d
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lassoan committed Nov 28, 2024
1 parent b14dbbd commit 060800e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/slicer/MONAILabel/MONAILabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 060800e

Please sign in to comment.