Пример #1
0
    def setupOptionsFrame(self):

        self.methodSelectorComboBox = qt.QComboBox()
        self.methodSelectorComboBox.addItem("Copy", LOGICAL_COPY)
        self.methodSelectorComboBox.addItem("Add", LOGICAL_UNION)
        self.methodSelectorComboBox.addItem("Subtract", LOGICAL_SUBTRACT)
        self.methodSelectorComboBox.addItem("Intersect", LOGICAL_INTERSECT)
        self.methodSelectorComboBox.addItem("Invert", LOGICAL_INVERT)
        self.methodSelectorComboBox.addItem("Clear", LOGICAL_CLEAR)
        self.methodSelectorComboBox.addItem("Fill", LOGICAL_FILL)
        self.methodSelectorComboBox.setToolTip(
            '<html>Available operations:<ul style="margin: 0">'
            '<li><b>Replace by segment:</b> replace the selected segment by the modifier segment.</li>'
            '<li><b>Add segment:</b> add modifier segment to current segment.</li>'
            '<li><b>Subtract segment:</b> subtract region of modifier segment from the selected segment.</li>'
            '<li><b>Intersection with segment:</b> only keeps those regions in the select segment that are common with the modifier segment.</li>'
            '<li><b>Invert:</b> inverts selected segment.</li>'
            '<li><b>Clear:</b> clears selected segment.</li>'
            '<li><b>Fill:</b> completely fills selected segment.</li>')

        self.bypassMaskingCheckBox = qt.QCheckBox("Bypass masking")
        self.bypassMaskingCheckBox.setToolTip(
            "Ignore all masking options and only modify the selected segment.")
        self.bypassMaskingCheckBox.objectName = self.__class__.__name__ + 'BypassMasking'

        operationFrame = qt.QHBoxLayout()
        operationFrame.addWidget(self.methodSelectorComboBox)
        operationFrame.addWidget(self.bypassMaskingCheckBox)
        self.marginSizeMmLabel = self.scriptedEffect.addLabeledOptionsWidget(
            "Operation:", operationFrame)

        self.modifierSegmentSelectorLabel = qt.QLabel("Modifier segment:")
        self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelectorLabel)

        self.modifierSegmentSelector = slicer.qMRMLSegmentsTableView()
        self.modifierSegmentSelector.selectionMode = qt.QAbstractItemView.SingleSelection
        self.modifierSegmentSelector.headerVisible = False
        self.modifierSegmentSelector.visibilityColumnVisible = False
        self.modifierSegmentSelector.opacityColumnVisible = False

        self.modifierSegmentSelector.setMRMLScene(slicer.mrmlScene)
        self.modifierSegmentSelector.setToolTip(
            'Contents of this segment will be used for modifying the selected segment. This segment itself will not be changed.'
        )
        self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelector)

        self.applyButton = qt.QPushButton("Apply")
        self.applyButton.objectName = self.__class__.__name__ + 'Apply'
        self.scriptedEffect.addOptionsWidget(self.applyButton)

        self.applyButton.connect('clicked()', self.onApply)
        self.methodSelectorComboBox.connect("currentIndexChanged(int)",
                                            self.updateMRMLFromGUI)
        self.modifierSegmentSelector.connect(
            "selectionChanged(QItemSelection, QItemSelection)",
            self.updateMRMLFromGUI)
        self.bypassMaskingCheckBox.connect("stateChanged(int)",
                                           self.updateMRMLFromGUI)
Пример #2
0
    def TestSection_02_qMRMLSegmentsTableView(self):
        logging.info('Test section 2: qMRMLSegmentsTableView')

        displayNode = self.inputSegmentationNode.GetDisplayNode()
        self.assertIsNotNone(displayNode)

        segmentsTableView = slicer.qMRMLSegmentsTableView()
        segmentsTableView.setMRMLScene(slicer.mrmlScene)
        segmentsTableView.setSegmentationNode(self.inputSegmentationNode)
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 3)
        segmentsTableView.show()
        slicer.app.processEvents()
        slicer.util.delayDisplay("All shown")

        segmentsTableView.setHideSegments(['second'])
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 2)
        slicer.app.processEvents()
        slicer.util.delayDisplay("Hidden 'second'")

        segmentsTableView.setHideSegments([])
        segmentsTableView.filterBarVisible = True
        segmentsTableView.textFilter = "third"
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 1)
        slicer.app.processEvents()
        slicer.util.delayDisplay("All but 'third' filtered")

        segmentsTableView.textFilter = ""
        firstSegment = self.inputSegmentationNode.GetSegmentation().GetSegment(
            "first")
        logic = slicer.modules.segmentations.logic()
        logic.SetSegmentStatus(firstSegment, logic.InProgress)
        sortFilterProxyModel = segmentsTableView.sortFilterProxyModel()
        sortFilterProxyModel.setShowStatus(logic.NotStarted, True)
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 2)
        slicer.app.processEvents()
        slicer.util.delayDisplay("'NotStarted' shown")

        segmentsTableView.setSelectedSegmentIDs(["third"])
        segmentsTableView.setHideSegments(['second'])
        segmentsTableView.showOnlySelectedSegments()
        self.assertEqual(displayNode.GetSegmentVisibility("first"), False)
        self.assertEqual(displayNode.GetSegmentVisibility("second"), True)
        self.assertEqual(displayNode.GetSegmentVisibility("third"), True)
        slicer.app.processEvents()
        slicer.util.delayDisplay("Show only selected segments")

        displayNode.SetSegmentVisibility("first", True)
        displayNode.SetSegmentVisibility("second", True)
        displayNode.SetSegmentVisibility("third", True)
        segmentsTableView.filterBarVisible = False

        # Reset the filtering parameters in the segmentation node to avoid interference with other tests that
        # use this segmentation node
        self.inputSegmentationNode.SetSegmentListFilterEnabled(False)
        self.inputSegmentationNode.SetSegmentListFilterOptions("")
Пример #3
0
    def setupOptionsFrame(self):

        self.methodSelectorComboBox = qt.QComboBox()
        self.methodSelectorComboBox.addItem("Copy", LOGICAL_COPY)
        self.methodSelectorComboBox.addItem("Add", LOGICAL_UNION)
        self.methodSelectorComboBox.addItem("Subtract", LOGICAL_SUBTRACT)
        self.methodSelectorComboBox.addItem("Intersect", LOGICAL_INTERSECT)
        self.methodSelectorComboBox.addItem("Invert", LOGICAL_INVERT)
        self.methodSelectorComboBox.addItem("Clear", LOGICAL_CLEAR)
        self.methodSelectorComboBox.addItem("Fill", LOGICAL_FILL)
        self.methodSelectorComboBox.setToolTip(
            'Click <dfn>Show details</dfn> link above for description of operations.'
        )

        self.bypassMaskingCheckBox = qt.QCheckBox("Bypass masking")
        self.bypassMaskingCheckBox.setToolTip(
            "Ignore all masking options and only modify the selected segment.")
        self.bypassMaskingCheckBox.objectName = self.__class__.__name__ + 'BypassMasking'

        self.applyButton = qt.QPushButton("Apply")
        self.applyButton.objectName = self.__class__.__name__ + 'Apply'

        operationFrame = qt.QHBoxLayout()
        operationFrame.addWidget(self.methodSelectorComboBox)
        operationFrame.addWidget(self.applyButton)
        operationFrame.addWidget(self.bypassMaskingCheckBox)
        self.marginSizeMmLabel = self.scriptedEffect.addLabeledOptionsWidget(
            "Operation:", operationFrame)

        self.modifierSegmentSelectorLabel = qt.QLabel("Modifier segment:")
        self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelectorLabel)

        self.modifierSegmentSelector = slicer.qMRMLSegmentsTableView()
        self.modifierSegmentSelector.selectionMode = qt.QAbstractItemView.SingleSelection
        self.modifierSegmentSelector.headerVisible = False
        self.modifierSegmentSelector.visibilityColumnVisible = False
        self.modifierSegmentSelector.opacityColumnVisible = False

        self.modifierSegmentSelector.setMRMLScene(slicer.mrmlScene)
        self.modifierSegmentSelector.setToolTip(
            'Contents of this segment will be used for modifying the selected segment. This segment itself will not be changed.'
        )
        self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelector)

        self.applyButton.connect('clicked()', self.onApply)
        self.methodSelectorComboBox.connect("currentIndexChanged(int)",
                                            self.updateMRMLFromGUI)
        self.modifierSegmentSelector.connect(
            "selectionChanged(QItemSelection, QItemSelection)",
            self.updateMRMLFromGUI)
        self.bypassMaskingCheckBox.connect("stateChanged(int)",
                                           self.updateMRMLFromGUI)
Пример #4
0
  def setupOptionsFrame(self):

    self.methodSelectorComboBox = qt.QComboBox()
    self.methodSelectorComboBox.addItem("Copy", LOGICAL_COPY)
    self.methodSelectorComboBox.addItem("Add", LOGICAL_UNION)
    self.methodSelectorComboBox.addItem("Subtract", LOGICAL_SUBTRACT)
    self.methodSelectorComboBox.addItem("Intersect", LOGICAL_INTERSECT)
    self.methodSelectorComboBox.addItem("Invert", LOGICAL_INVERT)
    self.methodSelectorComboBox.addItem("Clear", LOGICAL_CLEAR)
    self.methodSelectorComboBox.addItem("Fill", LOGICAL_FILL)
    self.methodSelectorComboBox.setToolTip('<html>Available operations:<ul style="margin: 0">'
      '<li><b>Replace by segment:</b> replace the selected segment by the modifier segment.</li>'
      '<li><b>Add segment:</b> add modifier segment to current segment.</li>'
      '<li><b>Subtract segment:</b> subtract region of modifier segment from the selected segment.</li>'
      '<li><b>Intersection with segment:</b> only keeps those regions in the select segment that are common with the modifier segment.</li>'
      '<li><b>Invert:</b> inverts selected segment.</li>'
      '<li><b>Clear:</b> clears selected segment.</li>'
      '<li><b>Fill:</b> completely fills selected segment.</li>')

    self.bypassMaskingCheckBox = qt.QCheckBox("Bypass masking")
    self.bypassMaskingCheckBox.setToolTip("Ignore all masking options and only modify the selected segment.")
    self.bypassMaskingCheckBox.objectName = self.__class__.__name__ + 'BypassMasking'

    operationFrame = qt.QHBoxLayout()
    operationFrame.addWidget(self.methodSelectorComboBox)
    operationFrame.addWidget(self.bypassMaskingCheckBox)
    self.marginSizeMmLabel = self.scriptedEffect.addLabeledOptionsWidget("Operation:", operationFrame)

    self.modifierSegmentSelectorLabel = qt.QLabel("Modifier segment:")
    self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelectorLabel)

    self.modifierSegmentSelector = slicer.qMRMLSegmentsTableView()
    self.modifierSegmentSelector.selectionMode = qt.QAbstractItemView.SingleSelection
    self.modifierSegmentSelector.headerVisible = False
    self.modifierSegmentSelector.visibilityColumnVisible = False
    self.modifierSegmentSelector.opacityColumnVisible = False

    self.modifierSegmentSelector.setMRMLScene(slicer.mrmlScene)
    self.modifierSegmentSelector.setToolTip('Contents of this segment will be used for modifying the selected segment. This segment itself will not be changed.')
    self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelector)

    self.applyButton = qt.QPushButton("Apply")
    self.applyButton.objectName = self.__class__.__name__ + 'Apply'
    self.scriptedEffect.addOptionsWidget(self.applyButton)

    self.applyButton.connect('clicked()', self.onApply)
    self.methodSelectorComboBox.connect("currentIndexChanged(int)", self.updateMRMLFromGUI)
    self.modifierSegmentSelector.connect("selectionChanged(QItemSelection, QItemSelection)", self.updateMRMLFromGUI)
    self.bypassMaskingCheckBox.connect("stateChanged(int)", self.updateMRMLFromGUI)
Пример #5
0
  def TestSection_1_qMRMLSegmentsTableView(self):
    logging.info('Test section 1: qMRMLSegmentsTableView')

    segmentsTableView = slicer.qMRMLSegmentsTableView()
    segmentsTableView.setMRMLScene(slicer.mrmlScene)
    segmentsTableView.setSegmentationNode(self.inputSegmentationNode)
    self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 3)
    segmentsTableView.show()

    slicer.app.processEvents()
    slicer.util.delayDisplay("All shown")

    segmentsTableView.setHideSegments(['second'])
    self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 2)
    slicer.app.processEvents()
    slicer.util.delayDisplay("Hidden 'second'")
Пример #6
0
    def TestSection_1_qMRMLSegmentsTableView(self):
        logging.info('Test section 1: qMRMLSegmentsTableView')

        segmentsTableView = slicer.qMRMLSegmentsTableView()
        segmentsTableView.setMRMLScene(slicer.mrmlScene)
        segmentsTableView.setSegmentationNode(self.inputSegmentationNode)
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 3)
        segmentsTableView.show()

        slicer.app.processEvents()
        slicer.util.delayDisplay("All shown")

        segmentsTableView.setHideSegments(['second'])
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 2)
        slicer.app.processEvents()
        slicer.util.delayDisplay("Hidden 'second'")
Пример #7
0
  def setupOptionsFrame(self):

    self.methodSelectorComboBox = qt.QComboBox()
    self.methodSelectorComboBox.addItem("Copy", LOGICAL_COPY)
    self.methodSelectorComboBox.addItem("Add", LOGICAL_UNION)
    self.methodSelectorComboBox.addItem("Subtract", LOGICAL_SUBTRACT)
    self.methodSelectorComboBox.addItem("Intersect", LOGICAL_INTERSECT)
    self.methodSelectorComboBox.addItem("Invert", LOGICAL_INVERT)
    self.methodSelectorComboBox.addItem("Clear", LOGICAL_CLEAR)
    self.methodSelectorComboBox.addItem("Fill", LOGICAL_FILL)
    self.methodSelectorComboBox.setToolTip('Click <dfn>Show details</dfn> link above for description of operations.')

    self.bypassMaskingCheckBox = qt.QCheckBox("Bypass masking")
    self.bypassMaskingCheckBox.setToolTip("Ignore all masking options and only modify the selected segment.")
    self.bypassMaskingCheckBox.objectName = self.__class__.__name__ + 'BypassMasking'

    self.applyButton = qt.QPushButton("Apply")
    self.applyButton.objectName = self.__class__.__name__ + 'Apply'

    operationFrame = qt.QHBoxLayout()
    operationFrame.addWidget(self.methodSelectorComboBox)
    operationFrame.addWidget(self.applyButton)
    operationFrame.addWidget(self.bypassMaskingCheckBox)
    self.marginSizeMmLabel = self.scriptedEffect.addLabeledOptionsWidget("Operation:", operationFrame)

    self.modifierSegmentSelectorLabel = qt.QLabel("Modifier segment:")
    self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelectorLabel)

    self.modifierSegmentSelector = slicer.qMRMLSegmentsTableView()
    self.modifierSegmentSelector.selectionMode = qt.QAbstractItemView.SingleSelection
    self.modifierSegmentSelector.headerVisible = False
    self.modifierSegmentSelector.visibilityColumnVisible = False
    self.modifierSegmentSelector.opacityColumnVisible = False

    self.modifierSegmentSelector.setMRMLScene(slicer.mrmlScene)
    self.modifierSegmentSelector.setToolTip('Contents of this segment will be used for modifying the selected segment. This segment itself will not be changed.')
    self.scriptedEffect.addOptionsWidget(self.modifierSegmentSelector)

    self.applyButton.connect('clicked()', self.onApply)
    self.methodSelectorComboBox.connect("currentIndexChanged(int)", self.updateMRMLFromGUI)
    self.modifierSegmentSelector.connect("selectionChanged(QItemSelection, QItemSelection)", self.updateMRMLFromGUI)
    self.bypassMaskingCheckBox.connect("stateChanged(int)", self.updateMRMLFromGUI)
Пример #8
0
    def TestSection_02_qMRMLSegmentsTableView(self):
        logging.info('Test section 2: qMRMLSegmentsTableView')

        self.inputSegmentationNode.CreateDefaultDisplayNodes()
        displayNode = self.inputSegmentationNode.GetDisplayNode()
        self.assertIsNotNone(displayNode)

        segmentsTableView = slicer.qMRMLSegmentsTableView()
        segmentsTableView.setMRMLScene(slicer.mrmlScene)
        segmentsTableView.setSegmentationNode(self.inputSegmentationNode)
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 3)
        segmentsTableView.show()

        slicer.app.processEvents()
        slicer.util.delayDisplay("All shown")

        segmentsTableView.setHideSegments(['second'])
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 2)
        slicer.app.processEvents()
        slicer.util.delayDisplay("Hidden 'second'")

        segmentsTableView.setHideSegments([])

        sortFilterProxyModel = segmentsTableView.sortFilterProxyModel()
        sortFilterProxyModel.filterEnabled = True
        sortFilterProxyModel.textFilter = "third"
        slicer.app.processEvents()
        slicer.util.delayDisplay("All but 'third' filtered")
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 1)

        sortFilterProxyModel.textFilter = ""

        firstSegment = self.inputSegmentationNode.GetSegmentation().GetSegment(
            "first")

        logic = slicer.modules.segmentations.logic()
        logic.SetSegmentStatus(firstSegment, logic.InProgress)
        sortFilterProxyModel.setShowStatus(logic.NotStarted, True)

        slicer.app.processEvents()
        slicer.util.delayDisplay("'NotStarted' shown")
        self.assertEqual(len(segmentsTableView.displayedSegmentIDs()), 2)