Ejemplo n.º 1
0
    def onCalculateButton(self):
        """
    Run processing when user clicks "Apply" button.
    """
        # cursor
        qt.QApplication.setOverrideCursor(qt.Qt.WaitCursor)
        qt.QApplication.processEvents()

        # create nodes
        sourceFiducial = self._parameterNode.GetNodeReference("SourceFiducial")
        targetFiducial = self._parameterNode.GetNodeReference("TargetFiducial")
        # reference
        size, origin, spacing = GridNodeHelper.getGridDefinition(
            self._parameterNode.GetNodeReference("InputNode"))
        userSpacing = [float(self._parameterNode.GetParameter("Spacing"))] * 3
        size = np.array(size) * (np.array(spacing) / np.array(userSpacing))
        auxVolumeNode = GridNodeHelper.emptyVolume([int(s) for s in size],
                                                   origin, userSpacing)
        # output
        outputNode = self._parameterNode.GetNodeReference(
            "OutputGridTransform")
        # params
        RBFRadius = []
        for i in range(targetFiducial.GetNumberOfControlPoints()):
            if targetFiducial.GetNthControlPointSelected(i):
                RBFRadius.append(
                    targetFiducial.GetNthControlPointDescription(i))
        RBFRadius = ",".join(RBFRadius)
        stiffness = float(self._parameterNode.GetParameter("Stiffness"))

        # save current state if leadDBS call in case of error
        if self._parameterNode.GetParameter("subjectPath") != '':
            LeadDBSCall.saveSourceTarget(
                self._parameterNode.GetParameter("subjectPath"),
                sourceFiducial, targetFiducial)

        # preview
        visualizationNodes = self.logic.previewWarp(sourceFiducial,
                                                    targetFiducial)
        qt.QApplication.processEvents()

        self._parameterNode.SetParameter("Running", "true")
        cliNode = self.logic.run(auxVolumeNode, outputNode, sourceFiducial,
                                 targetFiducial, RBFRadius, stiffness)

        if cliNode is not None:
            # set up for UI
            self.ui.landwarpWidget.setCurrentCommandLineModuleNode(cliNode)
            # add observer
            cliNode.AddObserver(slicer.vtkMRMLCommandLineModuleNode.StatusModifiedEvent, \
              lambda c,e,o=outputNode,v=visualizationNodes,a=auxVolumeNode: self.onStatusModifiedEvent(c,o,v,a))
        else:
            self.onStatusModifiedEvent(None, outputNode, visualizationNodes,
                                       auxVolumeNode)
Ejemplo n.º 2
0
 def enter(self):
     """
 Called each time the user opens this module.
 """
     # Make sure parameter node exists and observed
     self.initializeParameterNode()
     # Lead-DBS call
     if LeadDBSCall.updateParameterNodeFromArgs(
             self._parameterNode):  # was called from command line
         self.showSingleModule()
         slicer.util.mainWindow().addToolBar(Toolbar.reducedToolbar())
Ejemplo n.º 3
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)
        uiWidget = slicer.util.loadUI(self.resourcePath('UI/WarpDrive.ui'))
        self.layout.addWidget(uiWidget)
        self.ui = slicer.util.childWidgetVariables(uiWidget)

        # Add tools buttons
        toolsLayout = qt.QHBoxLayout(self.ui.toolsFrame)

        toolWidgets = [
            NoneTool.NoneToolWidget(),
            SmudgeTool.SmudgeToolWidget(),
            DrawTool.DrawToolWidget(),
            PointToPointTool.PointToPointToolWidget()
        ]

        for toolWidget in toolWidgets:
            toolsLayout.addWidget(toolWidget.effectButton)

        self.ui.drawModeMenu = toolWidgets[2].effectButton.menu()

        # Add Tree View
        dataControlTree = TreeView.WarpDriveTreeView()
        dataControlLayout = qt.QVBoxLayout(self.ui.dataControlFrame)
        dataControlLayout.addWidget(dataControlTree)

        # add plastimatch progress bar
        self.ui.landwarpWidget = slicer.modules.plastimatch_slicer_landwarp.createNewWidgetRepresentation(
        )
        self.ui.calculateFrame.layout().addWidget(
            self.ui.landwarpWidget.children()[3], 2, 0, 1, 2)  # progress bar

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

        # Create a new parameterNode
        # This parameterNode stores all user choices in parameter values, node selections, etc.
        # so that when the scene is saved and reloaded, these settings are restored.
        self.logic = WarpDriveLogic()

        # Connections
        self.ui.calculateButton.connect('clicked(bool)',
                                        self.onCalculateButton)
        self.ui.spacingSameAsInputCheckBox.toggled.connect(
            lambda b: self.ui.spacingSpinBox.setEnabled(not b))
        self.ui.autoRBFRadiusCheckBox.toggled.connect(
            lambda b: self.ui.RBFRadiusSpinBox.setEnabled(not b))

        # 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.inputSelector.connect("currentNodeChanged(vtkMRMLNode*)",
                                      self.updateParameterNodeFromGUI)
        self.ui.outputSelector.connect("currentNodeChanged(vtkMRMLNode*)",
                                       self.onOutputNodeChanged)
        self.ui.outputSelector.connect("currentNodeChanged(vtkMRMLNode*)",
                                       self.updateParameterNodeFromGUI)
        self.ui.spreadSlider.connect("valueChanged(double)",
                                     self.updateParameterNodeFromGUI)
        self.ui.spacingSameAsInputCheckBox.connect(
            "toggled(bool)", self.updateParameterNodeFromGUI)
        self.ui.spacingSpinBox.connect("valueChanged(double)",
                                       self.updateParameterNodeFromGUI)
        self.ui.autoRBFRadiusCheckBox.connect("toggled(bool)",
                                              self.updateParameterNodeFromGUI)
        self.ui.RBFRadiusSpinBox.connect("valueChanged(double)",
                                         self.updateParameterNodeFromGUI)
        self.ui.stiffnessSpinBox.connect("valueChanged(double)",
                                         self.updateParameterNodeFromGUI)
        self.ui.drawModeMenu.triggered.connect(self.updateParameterNodeFromGUI)

        # MRML Scene
        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,
                         dataControlTree.updateTree)

        # check dependencies
        if slicer.app.mainApplicationName != 'SlicerCustom':
            if LeadDBSCall.checkExtensionInstall(extensionName='SlicerRT'):
                return
            if LeadDBSCall.checkExtensionInstall(
                    extensionName='MarkupsToModel'):
                return

        # Initial GUI update
        self.updateGUIFromParameterNode()
Ejemplo n.º 4
0
    def onCalculateButton(self):
        """
    Run processing when user clicks "Apply" button.
    """
        # cursor
        qt.QApplication.setOverrideCursor(qt.Qt.WaitCursor)
        qt.QApplication.processEvents()

        # update (sets the RBF value)
        self.updateParameterNodeFromGUI()
        # get source and target from points
        sourcePoints = WarpDriveUtil.getPointsFromAttribute('source')
        targetPoints = WarpDriveUtil.getPointsFromAttribute('target')
        fixedPoints = WarpDriveUtil.getPointsFromAttribute('fixed')
        # add fixed to source and target
        sourcePoints.InsertPoints(sourcePoints.GetNumberOfPoints(),
                                  fixedPoints.GetNumberOfPoints(), 0,
                                  fixedPoints)
        targetPoints.InsertPoints(targetPoints.GetNumberOfPoints(),
                                  fixedPoints.GetNumberOfPoints(), 0,
                                  fixedPoints)
        # create nodes
        sourceFiducial = slicer.mrmlScene.AddNewNodeByClass(
            'vtkMRMLMarkupsFiducialNode')
        sourceFiducial.SetControlPointPositionsWorld(sourcePoints)
        sourceFiducial.GetDisplayNode().SetTextScale(0)
        targetFiducial = slicer.mrmlScene.AddNewNodeByClass(
            'vtkMRMLMarkupsFiducialNode')
        targetFiducial.SetControlPointPositionsWorld(targetPoints)
        targetFiducial.GetDisplayNode().SetVisibility(0)
        # reference
        size, origin, spacing = GridNodeHelper.getGridDefinition(
            self._parameterNode.GetNodeReference("InputNode"))
        userSpacing = [float(self._parameterNode.GetParameter("Spacing"))] * 3
        size = np.array(size) * (np.array(spacing) / np.array(userSpacing))
        auxVolumeNode = GridNodeHelper.emptyVolume([int(s) for s in size],
                                                   origin, userSpacing)
        # output
        outputNode = self._parameterNode.GetNodeReference(
            "OutputGridTransform")
        # params
        RBFRadius = float(self._parameterNode.GetParameter("Spread"))
        stiffness = float(self._parameterNode.GetParameter("Stiffness"))
        # mask
        maskVolume = WarpDriveUtil.getMaskVolume(auxVolumeNode)

        # save current state if leadDBS call in case of error
        if self._parameterNode.GetParameter("subjectPath") != '':
            LeadDBSCall.saveCurrentScene(
                self._parameterNode.GetParameter("subjectPath"))

        # unset current warp
        self._parameterNode.GetNodeReference(
            "InputNode").SetAndObserveTransformNodeID(None)

        # preview
        visualizationNode = WarpDriveUtil.previewWarp(sourceFiducial,
                                                      targetFiducial,
                                                      outputNode)

        # run
        self._parameterNode.SetParameter("Running", "true")
        cliNode = self.logic.run(auxVolumeNode, outputNode, sourceFiducial,
                                 targetFiducial, RBFRadius, stiffness,
                                 maskVolume)

        if cliNode is not None:
            # set up for UI
            self.ui.landwarpWidget.setCurrentCommandLineModuleNode(cliNode)
            # add observer
            cliNode.AddObserver(slicer.vtkMRMLCommandLineModuleNode.StatusModifiedEvent, \
              lambda c,e,o=outputNode,m=maskVolume,v=visualizationNode,s=sourceFiducial,t=targetFiducial,a=auxVolumeNode: self.onStatusModifiedEvent(c,o,m,v,s,t,a))
        else:
            self.onStatusModifiedEvent(None, outputNode, maskVolume,
                                       visualizationNode, sourceFiducial,
                                       targetFiducial, auxVolumeNode)

        # cursor
        qt.QApplication.setOverrideCursor(qt.Qt.ArrowCursor)