Skip to content

Commit d8099a6

Browse files
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>
1 parent da0247e commit d8099a6

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

plugins/slicer/MONAILabel/MONAILabel.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,9 +1823,23 @@ def updateSegmentationMask(self, in_file, labels, sliceIndex=None, freeze=None):
18231823
segmentIds.InsertNextValue(label)
18241824

18251825
# faster import (based on selected segmentIds)
1826+
1827+
# ImportLabelmapToSegmentationNode overwrites segments, which removes all non-source representations.
1828+
# We remember if closed surface representation was present and restore it after import.
1829+
segmentationRepresentationNames = []
1830+
segmentationNode.GetSegmentation().GetContainedRepresentationNames(segmentationRepresentationNames)
1831+
hasClosedSurfaceRepresentation = (
1832+
slicer.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName()
1833+
in segmentationRepresentationNames
1834+
)
1835+
18261836
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(
18271837
labelmapVolumeNode, segmentationNode, segmentIds
18281838
)
1839+
1840+
if hasClosedSurfaceRepresentation:
1841+
segmentationNode.CreateClosedSurfaceRepresentation()
1842+
18291843
slicer.mrmlScene.RemoveNode(labelmapVolumeNode)
18301844
else:
18311845
existingCount = segmentation.GetNumberOfSegments()

plugins/slicer/MONAILabel/Resources/UI/MONAILabel.ui

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,29 @@
209209
</widget>
210210
</item>
211211
<item row="8" column="0" colspan="2">
212-
<widget class="QWidget" name="trainWidget">
212+
<widget class="QFrame" name="trainWidget">
213+
<property name="frameShape">
214+
<enum>QFrame::NoFrame</enum>
215+
</property>
216+
<property name="frameShadow">
217+
<enum>QFrame::Plain</enum>
218+
</property>
213219
<layout class="QGridLayout" name="gridLayout_5">
220+
<property name="leftMargin">
221+
<number>3</number>
222+
</property>
223+
<property name="topMargin">
224+
<number>3</number>
225+
</property>
226+
<property name="rightMargin">
227+
<number>3</number>
228+
</property>
229+
<property name="bottomMargin">
230+
<number>3</number>
231+
</property>
232+
<property name="spacing">
233+
<number>3</number>
234+
</property>
214235
<item row="1" column="0">
215236
<widget class="QLabel" name="label_9">
216237
<property name="text">
@@ -277,8 +298,8 @@
277298
</item>
278299
</layout>
279300
</item>
280-
</layout>
281-
</widget>
301+
</layout>
302+
</widget>
282303
</item>
283304
<item row="4" column="1">
284305
<widget class="QPushButton" name="saveLabelButton">
@@ -540,19 +561,19 @@
540561
<property name="placeMultipleMarkups">
541562
<enum>qSlicerMarkupsPlaceWidget::ForcePlaceSingleMarkup</enum>
542563
</property>
543-
<property name="sizePolicy">
564+
<property name="sizePolicy">
544565
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
545-
<horstretch>0</horstretch>
546-
<verstretch>0</verstretch>
547-
</sizepolicy>
548-
</property>
549-
</widget>
550-
</item>
551-
</layout>
566+
<horstretch>0</horstretch>
567+
<verstretch>0</verstretch>
568+
</sizepolicy>
569+
</property>
570+
</widget>
552571
</item>
553572
</layout>
554573
</item>
555574
</layout>
575+
</item>
576+
</layout>
556577
</widget>
557578
</item>
558579
<item>
@@ -714,10 +735,10 @@
714735
<enum>qSlicerMarkupsPlaceWidget::ForcePlaceSingleMarkup</enum>
715736
</property>
716737
<property name="sizePolicy">
717-
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
738+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
718739
<horstretch>0</horstretch>
719740
<verstretch>0</verstretch>
720-
</sizepolicy>
741+
</sizepolicy>
721742
</property>
722743
</widget>
723744
</item>

0 commit comments

Comments
 (0)