Skip to content

Commit

Permalink
Slicer plugin: Keep showing segmentation in 3D when using sam_3d (#1789)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lassoan and pre-commit-ci[bot] authored Nov 28, 2024
1 parent da0247e commit d8099a6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
14 changes: 14 additions & 0 deletions plugins/slicer/MONAILabel/MONAILabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 34 additions & 13 deletions plugins/slicer/MONAILabel/Resources/UI/MONAILabel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,29 @@
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QWidget" name="trainWidget">
<widget class="QFrame" name="trainWidget">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<property name="spacing">
<number>3</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
Expand Down Expand Up @@ -277,8 +298,8 @@
</item>
</layout>
</item>
</layout>
</widget>
</layout>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="saveLabelButton">
Expand Down Expand Up @@ -540,19 +561,19 @@
<property name="placeMultipleMarkups">
<enum>qSlicerMarkupsPlaceWidget::ForcePlaceSingleMarkup</enum>
</property>
<property name="sizePolicy">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
Expand Down Expand Up @@ -714,10 +735,10 @@
<enum>qSlicerMarkupsPlaceWidget::ForcePlaceSingleMarkup</enum>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</sizepolicy>
</property>
</widget>
</item>
Expand Down

0 comments on commit d8099a6

Please sign in to comment.