Beispiel #1
0
 def setEraseEffectEnabled(enabled):
     with NodeModify(EditUtil.getParameterNode()):
         if enabled and not EditUtil.isEraseEffectEnabled():
             EditUtil.backupLabel()
             EditUtil.setLabel(0)
         elif not enabled and EditUtil.isEraseEffectEnabled():
             EditUtil.restoreLabel()
Beispiel #2
0
 def setEraseEffectEnabled(self, enabled):
     with NodeModify(self.getParameterNode()):
         if enabled and not self.isEraseEffectEnabled():
             self.backupLabel()
             self.setLabel(0)
         elif not enabled and self.isEraseEffectEnabled():
             self.restoreLabel()
Beispiel #3
0
 def setSlicesZoom(factor):
     for sliceLogic in slicer.app.applicationLogic().GetSliceLogics():
         sliceNode = sliceLogic.GetSliceNode()
         with NodeModify(sliceNode):
             sliceLogic.FitSliceToAll()
             fov = sliceNode.GetFieldOfView()
             sliceNode.SetFieldOfView(fov[0] * factor, fov[1] * factor,
                                      fov[2])
Beispiel #4
0
 def setWindowLevelPreset(self, presetName):
     for volumeNode in slicer.util.getNodesByClass(
             "vtkMRMLScalarVolumeNode"):
         volumeDisplayNode = volumeNode.GetDisplayNode()
         with NodeModify(volumeDisplayNode):
             volumeDisplayNode.SetAutoWindowLevel(0)
             volumeDisplayNode.SetWindowLevel(
                 *self.WINDOW_LEVEL_PRESETS[presetName])
Beispiel #5
0
    def setSlicesZoomOneToOne(volumeNode):
        """1:1 means image 1 image pixel to 1 screen pixel.

    This means 512 by 512 image occupies 512 by 512 screen pixels.
    """
        for sliceLogic in slicer.app.applicationLogic().GetSliceLogics():
            sliceNode = sliceLogic.GetSliceNode()
            with NodeModify(sliceNode):
                QReadsLogic.setSliceZoomOneToOne(sliceLogic, volumeNode)
                QReadsLogic.centerSlice(sliceLogic, volumeNode)
                sliceLogic.SnapSliceOffsetToIJK()
Beispiel #6
0
  def setUserStatisticsTableNode(self, node):
    parameterNode = self.getParameterNode()
    if parameterNode is None:
      return

    with NodeModify(parameterNode):
      tableNode = parameterNode.GetNodeReference(self.USER_STATISTICS_TABLE_REFERENCE_ROLE)
      if node is tableNode:
        return

      nodeID = ""
      if node:
        nodeID = node.GetID()
      parameterNode.SetNodeReferenceID(self.USER_STATISTICS_TABLE_REFERENCE_ROLE, nodeID)
Beispiel #7
0
    def updateWindowLevel(windowStep=None, levelStep=None):
        for volumeNode in slicer.util.getNodesByClass(
                "vtkMRMLScalarVolumeNode"):
            volumeDisplayNode = volumeNode.GetDisplayNode()
            with NodeModify(volumeDisplayNode):

                window = volumeDisplayNode.GetWindow()
                if windowStep is not None:
                    window = window + windowStep

                level = volumeDisplayNode.GetLevel()
                if levelStep is not None:
                    level = level + levelStep

                volumeDisplayNode.SetAutoWindowLevel(0)
                volumeDisplayNode.SetWindowLevel(window, level)
    def updateParameterNodeFromGui(self):

        self.updateButtonStates()

        if self._parameterNode is None:
            return

        with NodeModify(self._parameterNode):
            self._parameterNode.SetParameter("InputVectorVolume",
                                             getNodeID(self.inputVolumeNode()))
            self._parameterNode.SetParameter(
                "OutputScalarVolume", getNodeID(self.outputVolumeNode()))
            self._parameterNode.SetParameter(
                "ConversionMethod",
                self.conversionMethodWidget.conversionMethod())
            self._parameterNode.SetParameter(
                "ComponentToExtract",
                str(self.conversionMethodWidget.componentToExtract()))
Beispiel #9
0
 def updateMRMLFromGUI(self):
     with NodeModify(self.parameterNode):
         super().updateMRMLFromGUI()
         self.scope = self.availableScopeOptions[
             self.scopeComboBox.currentIndex]
         self.parameterNode.SetParameter("Effect,scope", str(self.scope))
Beispiel #10
0
    def setup(self):
        """
    Called when the user opens the module the first time and the widget is initialized.
    """
        ScriptedLoadableModuleWidget.setup(self)

        # Load widget from .ui file (created by Qt Designer).
        # Additional widgets can be instantiated manually and added to self.layout.
        uiWidget = slicer.util.loadUI(self.resourcePath('UI/QReads.ui'))
        self.layout.addWidget(uiWidget)
        self.ui = slicer.util.childWidgetVariables(uiWidget)
        self.slabModeButtonGroup = qt.QButtonGroup()
        self.slabModeButtonGroup.addButton(self.ui.SlabModeMaxRadioButton,
                                           vtk.VTK_IMAGE_SLAB_MAX)
        self.slabModeButtonGroup.addButton(self.ui.SlabModeMeanRadioButton,
                                           vtk.VTK_IMAGE_SLAB_MEAN)
        self.slabModeButtonGroup.addButton(self.ui.SlabModeMinRadioButton,
                                           vtk.VTK_IMAGE_SLAB_MIN)
        self.ui.ZoomComboBox.addItems(self.ZOOM_ACTIONS)

        # Set scene in MRML widgets. Make sure that in Qt designer the top-level qMRMLWidget's
        # "mrmlSceneChanged(vtkMRMLScene*)" signal in is connected to each MRML widget's.
        # "setMRMLScene(vtkMRMLScene*)" slot.
        #uiWidget.setMRMLScene(slicer.mrmlScene)

        # Create logic class. Logic implements all computations that should be possible to run
        # in batch mode, without a graphical user interface.
        self.logic = QReadsLogic()

        # Connections

        # These connections ensure that we update parameter node when scene is closed
        self.addObserver(slicer.mrmlScene, slicer.mrmlScene.StartCloseEvent,
                         self.onSceneStartClose)
        self.addObserver(slicer.mrmlScene, slicer.mrmlScene.EndCloseEvent,
                         self.onSceneEndClose)
        self.addObserver(slicer.mrmlScene, slicer.mrmlScene.NodeAddedEvent,
                         self.onNodeAdded)

        # These connections ensure that whenever user changes some settings on the GUI, that is saved in the MRML scene
        # (in the selected parameter node).
        self.ui.ShowReferenceMarkersButton.connect(
            "clicked()", self.updateParameterNodeFromGUI)
        self.ui.ResetReferenceMarkersButton.connect(
            "clicked()", QReadsLogic.resetReferenceMarkers)
        self.ui.SlabButton.connect("clicked()",
                                   self.updateParameterNodeFromGUI)
        self.slabModeButtonGroup.connect("buttonClicked(int)",
                                         self.updateParameterNodeFromGUI)
        self.ui.SlabThicknessSliderWidget.connect(
            "valueChanged(double)", self.updateParameterNodeFromGUI)
        self.ui.InverseGrayButton.connect("clicked(bool)",
                                          self.updateParameterNodeFromGUI)

        # Increasing the level will make the image darker, whereas decreasing the level value will make the image brighter
        self.ui.BrightnessUpButton.connect(
            "clicked()",
            lambda step=-self.BRIGHTNESS_STEP: QReadsLogic.updateWindowLevel(
                levelStep=step))
        self.ui.BrightnessDownButton.connect(
            "clicked()",
            lambda step=self.BRIGHTNESS_STEP: QReadsLogic.updateWindowLevel(
                levelStep=step))

        # Increasing window will reduce display contrast, whereas decreasing the window increases the brightness
        self.ui.ContrastUpButton.connect(
            "clicked()",
            lambda step=-self.CONTRAST_STEP: QReadsLogic.updateWindowLevel(
                windowStep=step))
        self.ui.ContrastDownButton.connect(
            "clicked()",
            lambda step=self.CONTRAST_STEP: QReadsLogic.updateWindowLevel(
                windowStep=step))

        self.ui.CTBodySoftTissueWLPresetButton.connect(
            "clicked()",
            lambda presetName="CT-BodySoftTissue": self.logic.
            setWindowLevelPreset(presetName))
        self.ui.CTBoneWLPresetButton.connect(
            "clicked()",
            lambda presetName="CT-Bone": self.logic.setWindowLevelPreset(
                presetName))
        self.ui.CTBrainWLPresetButton.connect(
            "clicked()",
            lambda presetName="CT-Head": self.logic.setWindowLevelPreset(
                presetName))
        self.ui.CTLungWLPresetButton.connect(
            "clicked()",
            lambda presetName="CT-Lung": self.logic.setWindowLevelPreset(
                presetName))

        self.ui.ZoomComboBox.connect("currentTextChanged(QString)",
                                     self.updateParameterNodeFromGUI)

        self.ui.CloseApplicationPushButton.connect("clicked()",
                                                   slicer.util.quit)

        # Make sure parameter node is initialized (needed for module reload)
        self.initializeParameterNode()

        # Hide main window components
        slicer.util.setApplicationLogoVisible(False)
        slicer.util.setMenuBarsVisible(False)
        slicer.util.setModuleHelpSectionVisible(False)
        slicer.util.setModulePanelTitleVisible(False)
        slicer.util.setToolbarsVisible(False)

        # Layout
        slicer.app.layoutManager().setLayout(self.logic.registerCustomLayout())

        for viewName, viewColor in QReadsLogic.SLICEVIEW_BACKGROUND_COLORS.items(
        ):
            sliceWidget = slicer.app.layoutManager().sliceWidget(viewName)
            sliceWidget.sliceView().setBackgroundColor(qt.QColor(viewColor))
            sliceNode = sliceWidget.mrmlSliceNode()
            sliceNode.SetOrientationMarkerType(
                slicer.vtkMRMLAbstractViewNode.OrientationMarkerTypeAxes)
            sliceNode.SetSliceVisible(True)

        for viewName, viewColor in QReadsLogic.THREEDVIEW_BACKGROUND_COLORS.items(
        ):
            with NodeModify(slicer.util.getNode("vtkMRMLViewNode%s" %
                                                viewName)) as viewNode:
                viewNode.SetBackgroundColor(0., 0., 0.)
                viewNode.SetBackgroundColor2(0., 0., 0.)
                viewNode.SetBoxVisible(False)
                viewNode.SetAxisLabelsVisible(False)
                viewNode.SetOrientationMarkerType(
                    slicer.vtkMRMLAbstractViewNode.OrientationMarkerTypeAxes)