From d8099a600ed785596ef739b1f9b7279734816af1 Mon Sep 17 00:00:00 2001 From: Andras Lasso Date: Thu, 28 Nov 2024 15:28:38 -0500 Subject: [PATCH] Slicer plugin: Keep showing segmentation in 3D when using sam_3d (#1789) * Fix Slicer plugin trainWidget disappearing from .ui file when editing in Qt Designer * 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. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- plugins/slicer/MONAILabel/MONAILabel.py | 14 ++++++ .../MONAILabel/Resources/UI/MONAILabel.ui | 47 ++++++++++++++----- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/plugins/slicer/MONAILabel/MONAILabel.py b/plugins/slicer/MONAILabel/MONAILabel.py index d018631cd..a335261d0 100644 --- a/plugins/slicer/MONAILabel/MONAILabel.py +++ b/plugins/slicer/MONAILabel/MONAILabel.py @@ -1823,9 +1823,23 @@ 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() diff --git a/plugins/slicer/MONAILabel/Resources/UI/MONAILabel.ui b/plugins/slicer/MONAILabel/Resources/UI/MONAILabel.ui index 9d0319936..5544bc9b4 100644 --- a/plugins/slicer/MONAILabel/Resources/UI/MONAILabel.ui +++ b/plugins/slicer/MONAILabel/Resources/UI/MONAILabel.ui @@ -209,8 +209,29 @@ - + + + QFrame::NoFrame + + + QFrame::Plain + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + @@ -277,8 +298,8 @@ - - + + @@ -540,19 +561,19 @@ qSlicerMarkupsPlaceWidget::ForcePlaceSingleMarkup - + - 0 - 0 - - - - - + 0 + 0 + + + + + @@ -714,10 +735,10 @@ qSlicerMarkupsPlaceWidget::ForcePlaceSingleMarkup - + 0 0 - +