Пример #1
0
  def setup( self ):
    self.workflow = ctk.ctkWorkflow()
    workflowWidget = ctk.ctkWorkflowStackedWidget()
    workflowWidget.setWorkflow( self.workflow )
  
    nNodes = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLScriptedModuleNode')
    self.parameterNode = None
    for n in xrange(nNodes):
      compNode = slicer.mrmlScene.GetNthNodeByClass(n, 'vtkMRMLScriptedModuleNode')
      nodeid = None
      if compNode.GetModuleName() == 'workflow':
        self.parameterNode = compNode
        print 'Found existing workflow parameter node'
        break
    if self.parameterNode == None:
      self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
      self.parameterNode.SetModuleName('workflow')
      slicer.mrmlScene.AddNode(self.parameterNode)

    loginStep = WorkflowSteps.LoginStep('Login', self.parameterNode)
    approachStep = WorkflowSteps.ApproachStep('Approach', self.parameterNode)
    screwStep = WorkflowSteps.ScrewStep('Screw', self.parameterNode)
    doneStep = WorkflowSteps.FinalStep('Final', self.parameterNode)
    
    self.workflow.addTransition(loginStep, approachStep, None, ctk.ctkWorkflow.Forward)
    self.workflow.addTransition(approachStep, screwStep, None, ctk.ctkWorkflow.Forward)
    self.workflow.addTransition(screwStep, doneStep, None, ctk.ctkWorkflow.Forward)

    self.workflow.setInitialStep(loginStep)
    self.workflow.start()
    workflowWidget.visible = True
    self.layout.addWidget( workflowWidget )
Пример #2
0
  def compileScript(self, animationNode):
    """Convert the node's script into sequences and a sequence browser node.
       Returns the sequenceBrowserNode.
    """
    sequenceBrowserNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSequenceBrowserNode')
    sequenceBrowserNode.SetName(animationNode.GetName() + "-Browser")

    # TODO: use this when exporting
    # sequenceBrowserNode.SetPlaybackItemSkippingEnabled(False)

    sequenceNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSequenceNode')
    sequenceNode.SetIndexType(sequenceNode.NumericIndex)
    sequenceNode.SetName(animationNode.GetName() + "-TimingSequence")
    sequenceBrowserNode.AddSynchronizedSequenceNode(sequenceNode)

    # create one data node per frame of the script.
    # these are used to synchronize the animation
    # but don't hold any other data
    script = self.getScript(animationNode)
    frames = script['framesPerSecond'] * script['duration']
    secondsPerFrame = 1. / script['framesPerSecond']
    for frame in range(math.ceil(frames)):
      scriptTime = frame * secondsPerFrame
      timePointDataNode = slicer.vtkMRMLScriptedModuleNode()
      sequenceNode.SetDataNodeAtValue(timePointDataNode, str(scriptTime))

    return(sequenceBrowserNode)
 def runRegistration(self):
     logging.debug("Starting Registration")
     self.progress = self.createProgressDialog(value=1, maximum=4)
     parameterNode = slicer.vtkMRMLScriptedModuleNode()
     parameterNode.SetAttribute(
         'FixedImageNodeID',
         self.fixedVolumeSelector.currentNode().GetID())
     parameterNode.SetAttribute(
         'FixedLabelNodeID',
         self.fixedLabelSelector.currentNode().GetID())
     parameterNode.SetAttribute(
         'MovingImageNodeID',
         self.movingVolumeSelector.currentNode().GetID())
     parameterNode.SetAttribute(
         'MovingLabelNodeID',
         self.movingLabelSelector.currentNode().GetID())
     if self.fiducialSelector.currentNode():
         parameterNode.SetAttribute(
             'TargetsNodeID',
             self.fiducialSelector.currentNode().GetID())
     if self.initialTransformSelector.currentNode():
         parameterNode.SetAttribute(
             'InitialTransformNodeID',
             self.initialTransformSelector.currentNode().GetID())
         self.logic.runReRegistration(
             parameterNode, progressCallback=self.updateProgressBar)
     else:
         self.logic.run(parameterNode,
                        progressCallback=self.updateProgressBar)
     self.progress.close()
Пример #4
0
 def nodeCheck(self):
   """If there is no parameter node, create one and add it to the scene
   """
   if(self.parameterSelector.currentNode() == None):
     node = slicer.vtkMRMLScriptedModuleNode()
     slicer.mrmlScene.AddNode(node)
     self.parameterNodeCreated(node)
     self.parameterSelector.setCurrentNode(node)
Пример #5
0
 def createParameterNode(self):
   """create the Editor parameter node - a singleton in the scene
   This is used internally by getParameterNode - shouldn't really
   be called for any other reason.
   """
   node = slicer.vtkMRMLScriptedModuleNode()
   node.SetModuleName( "Editor" )
   slicer.mrmlScene.AddNode(node)
   return node
Пример #6
0
 def createParameterNode(self):
     """create the Editor parameter node - a singleton in the scene
 This is used internally by getParameterNode - shouldn't really
 be called for any other reason.
 """
     node = slicer.vtkMRMLScriptedModuleNode()
     node.SetModuleName("Editor")
     slicer.mrmlScene.AddNode(node)
     return node
Пример #7
0
    def __init__(self):
        ScriptedLoadableModuleLogic.__init__(self)

        import serial

        self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
        self.parameterNode.SetName("arduinoNode")
        slicer.mrmlScene.AddNode(self.parameterNode)

        self.arduinoConnection = None
  def runRegistration(self):
    self.progress = self.makeProgressIndicator(4, 1)
    parameterNode = slicer.vtkMRMLScriptedModuleNode()
    parameterNode.SetAttribute('FixedImageNodeID', self.intraopVolumeSelector.currentNode().GetID())
    parameterNode.SetAttribute('FixedLabelNodeID', self.intraopLabelSelector.currentNode().GetID())
    parameterNode.SetAttribute('MovingImageNodeID', self.preopVolumeSelector.currentNode().GetID())
    parameterNode.SetAttribute('MovingLabelNodeID', self.preopLabelSelector.currentNode().GetID())
    if self.fiducialSelector.currentNode():
      parameterNode.SetAttribute('TargetsNodeID', self.fiducialSelector.currentNode().GetID())

    self.logic.run(parameterNode, progressCallback=self.updateProgressBar)
    self.progress.close()
Пример #9
0
 def _createParameterNode(self):
     """create the Editor parameter node - a singleton in the scene
 This is used internally by getParameterNode - shouldn't really
 be called for any other reason.
 """
     node = slicer.vtkMRMLScriptedModuleNode()
     node.SetSingletonTag("Editor")
     node.SetModuleName("Editor")
     node.SetParameter("label", "1")
     slicer.mrmlScene.AddNode(node)
     # Since we are a singleton, the scene won't add our node into the scene,
     # but will instead insert a copy, so we find that and return it
     node = self._findParameterNodeInScene()
     return node
Пример #10
0
 def _createParameterNode(self):
   """create the Editor parameter node - a singleton in the scene
   This is used internally by getParameterNode - shouldn't really
   be called for any other reason.
   """
   node = slicer.vtkMRMLScriptedModuleNode()
   node.SetSingletonTag( "Editor" )
   node.SetModuleName( "Editor" )
   node.SetParameter( "label", "1" )
   slicer.mrmlScene.AddNode(node)
   # Since we are a singleton, the scene won't add our node into the scene,
   # but will instead insert a copy, so we find that and return it
   node = self._findParameterNodeInScene()
   return node
Пример #11
0
    def __init__(self, arduinoNode):
        ScriptedLoadableModuleLogic.__init__(self)
        self.ArduinoNode = arduinoNode

        self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
        self.parameterNode.SetName("arduinoNode")
        slicer.mrmlScene.AddNode(self.parameterNode)

        #Layout Selected (example: Red, Yellow, Green or Complete)
        self.selected_view = 0

        self.button1 = None
        self.button2 = None
        self.button3 = None
def runRegistration(fixedVolume, fixedLabel, movingVolume, movingLabel):
    registrationLogic = SliceTrackerRegistrationLogic()
    data = SessionData()
    result = data.createResult(fixedVolume.GetName())
    registrationLogic.registrationResult = result

    parameterNode = slicer.vtkMRMLScriptedModuleNode()
    parameterNode.SetAttribute('FixedImageNodeID', fixedVolume.GetID())
    parameterNode.SetAttribute('FixedLabelNodeID', fixedLabel.GetID())
    parameterNode.SetAttribute('MovingImageNodeID', movingVolume.GetID())
    parameterNode.SetAttribute('MovingLabelNodeID', movingLabel.GetID())

    registrationLogic.run(parameterNode)

    return result
Пример #13
0
 def createParameterNode(self):
   """
   Create a new parameter node
   The node is of vtkMRMLScriptedModuleNode class. Module name is added as an attribute to allow filtering
   in node selector widgets (attribute name: ModuleName, attribute value: the module's name).
   This method can be overridden in derived classes to create a default parameter node with all
   parameter values set to their default.
   """
   node = slicer.vtkMRMLScriptedModuleNode()
   if self.isSingletonParameterNode:
     node.SetSingletonTag( self.moduleName )
   # Add module name in an attribute to allow filtering in node selector widgets
   # Note that SetModuleName is not used anymore as it would be redundant with the ModuleName attribute.
   node.SetAttribute( "ModuleName", self.moduleName )
   node.SetName(slicer.mrmlScene.GenerateUniqueName(self.moduleName))
   return node
Пример #14
0
 def createParameterNode(self):
     """
 Create a new parameter node
 The node is of vtkMRMLScriptedModuleNode class. Module name is added as an attribute to allow filtering
 in node selector widgets (attribute name: ModuleName, attribute value: the module's name).
 This method can be overridden in derived classes to create a default parameter node with all
 parameter values set to their default.
 """
     node = slicer.vtkMRMLScriptedModuleNode()
     if self.isSingletonParameterNode:
         node.SetSingletonTag(self.moduleName)
     # Add module name in an attribute to allow filtering in node selector widgets
     # Note that SetModuleName is not used anymore as it would be redundant with the ModuleName attribute.
     node.SetAttribute("ModuleName", self.moduleName)
     node.SetName(slicer.mrmlScene.GenerateUniqueName(self.moduleName))
     return node
 def runRegistration(self):
   logging.debug("Starting Registration")
   self.progress = slicer.util.createProgressDialog(value=1, maximum=4)
   parameterNode = slicer.vtkMRMLScriptedModuleNode()
   parameterNode.SetAttribute('FixedImageNodeID', self.fixedVolumeSelector.currentNode().GetID())
   parameterNode.SetAttribute('FixedLabelNodeID', self.fixedLabelSelector.currentNode().GetID())
   parameterNode.SetAttribute('MovingImageNodeID', self.movingVolumeSelector.currentNode().GetID())
   parameterNode.SetAttribute('MovingLabelNodeID', self.movingLabelSelector.currentNode().GetID())
   if self.fiducialSelector.currentNode():
     parameterNode.SetAttribute('TargetsNodeID', self.fiducialSelector.currentNode().GetID())
   if self.initialTransformSelector.currentNode():
     parameterNode.SetAttribute('InitialTransformNodeID', self.initialTransformSelector.currentNode().GetID())
     self.logic.runReRegistration(parameterNode, progressCallback=self.updateProgressBar)
   else:
     self.logic.run(parameterNode, progressCallback=self.updateProgressBar)
   self.progress.close()
Пример #16
0
 def _createParameterNode():
   """create the Editor parameter node - a singleton in the scene
   This is used internally by getParameterNode - shouldn't really
   be called for any other reason.
   """
   node = slicer.vtkMRMLScriptedModuleNode()
   node.SetSingletonTag( "Editor" )
   node.SetModuleName( "Editor" )
   node.SetParameter( "label", "1" )
   node.SetParameter( "effect", "DefaultTool" )
   node.SetParameter( "propagationMode", str(slicer.vtkMRMLApplicationLogic.BackgroundLayer | slicer.vtkMRMLApplicationLogic.LabelLayer) )
   slicer.mrmlScene.AddNode(node)
   # Since we are a singleton, the scene won't add our node into the scene,
   # but will instead insert a copy, so we find that and return it
   node = EditUtil._findParameterNodeInScene()
   return node
Пример #17
0
 def _createParameterNode():
   """create the Editor parameter node - a singleton in the scene
   This is used internally by getParameterNode - shouldn't really
   be called for any other reason.
   """
   node = slicer.vtkMRMLScriptedModuleNode()
   node.SetSingletonTag( "Editor" )
   node.SetModuleName( "Editor" )
   node.SetParameter( "label", "1" )
   node.SetParameter( "effect", "DefaultTool" )
   node.SetParameter( "propagationMode", str(slicer.vtkMRMLApplicationLogic.BackgroundLayer | slicer.vtkMRMLApplicationLogic.LabelLayer) )
   slicer.mrmlScene.AddNode(node)
   # Since we are a singleton, the scene won't add our node into the scene,
   # but will instead insert a copy, so we find that and return it
   node = EditUtil._findParameterNodeInScene()
   return node
Пример #18
0
 def _runRegistration(self, fixedVolume, fixedLabel, movingVolume, movingLabel, targets, segmentationData,
                      progressCallback):
   result = self.generateNameAndCreateRegistrationResult(fixedVolume)
   result.receivedTime = self.seriesTimeStamps[result.name.replace(result.suffix, "")]
   if segmentationData:
     result.segmentationData = segmentationData
   parameterNode = slicer.vtkMRMLScriptedModuleNode()
   parameterNode.SetAttribute('FixedImageNodeID', fixedVolume.GetID())
   parameterNode.SetAttribute('FixedLabelNodeID', fixedLabel.GetID())
   parameterNode.SetAttribute('MovingImageNodeID', movingVolume.GetID())
   parameterNode.SetAttribute('MovingLabelNodeID', movingLabel.GetID())
   parameterNode.SetAttribute('TargetsNodeID', targets.GetID())
   result.startTime = self.getTime()
   self.registrationLogic.run(parameterNode, progressCallback=progressCallback)
   result.endTime = self.getTime()
   self.addTargetsToMRMLScene(result)
   if self.seriesTypeManager.isCoverProstate(self.currentSeries) and self.temporaryIntraopTargets:
     self.addTemporaryTargetsToResult(result)
   self.invokeEvent(self.InitiateEvaluationEvent)
Пример #19
0
def main(argv):
  try:
    parser = argparse.ArgumentParser(description="Slicetracker Registration")
    parser.add_argument("-fl", "--fixed-label", dest="fixed_label", metavar="PATH", default="-", required=True,
                        help="Fixed label to be used for registration")
    parser.add_argument("-ml", "--moving-label", dest="moving_label", metavar="PATH", default="-", required=True,
                        help="Moving label to be used for registration")
    parser.add_argument("-fv", "--fixed-volume", dest="fixed_volume", metavar="PATH", default="-", required=True,
                        help="Fixed volume to be used for registration")
    parser.add_argument("-mv", "--moving-volume", dest="moving_volume", metavar="PATH", default="-", required=True,
                        help="Moving volume to be used for registration")
    parser.add_argument("-it", "--initial-transform", dest="initial_transform", metavar="PATH", default="-",
                        required=False, help="Initial rigid transform for re-registration")
    parser.add_argument("-o", "--output-directory", dest="output_directory", metavar="PATH", default="-",
                        required=False, help="Output directory for registration result")

    args = parser.parse_args(argv)

    for inputFile in [args.fixed_label, args.moving_label, args.fixed_volume, args.moving_volume]:
      if not os.path.isfile(inputFile):
        raise AttributeError("File not found: %s" % inputFile)

    success, fixedLabel = slicer.util.loadLabelVolume(args.fixed_label, returnNode=True)
    success, movingLabel = slicer.util.loadLabelVolume(args.moving_label, returnNode=True)
    success, fixedVolume = slicer.util.loadVolume(args.fixed_volume, returnNode=True)
    success, movingVolume = slicer.util.loadVolume(args.moving_volume, returnNode=True)

    parameterNode = slicer.vtkMRMLScriptedModuleNode()
    parameterNode.SetAttribute('FixedImageNodeID', fixedVolume.GetID())
    parameterNode.SetAttribute('FixedLabelNodeID', fixedLabel.GetID())
    parameterNode.SetAttribute('MovingImageNodeID', movingVolume.GetID())
    parameterNode.SetAttribute('MovingLabelNodeID', movingLabel.GetID())

    logic = SliceTrackerRegistrationLogic()
    logic.run(parameterNode)

    if args.output_directory != "-":
      logic.registrationResult.save(args.output_directory)

  except Exception as e:
    print(e)
  sys.exit(0)
def main(argv):
  try:
    parser = argparse.ArgumentParser(description="Slicetracker Registration")
    parser.add_argument("-fl", "--fixed-label", dest="fixed_label", metavar="PATH", default="-", required=True,
                        help="Fixed label to be used for registration")
    parser.add_argument("-ml", "--moving-label", dest="moving_label", metavar="PATH", default="-", required=True,
                        help="Moving label to be used for registration")
    parser.add_argument("-fv", "--fixed-volume", dest="fixed_volume", metavar="PATH", default="-", required=True,
                        help="Fixed volume to be used for registration")
    parser.add_argument("-mv", "--moving-volume", dest="moving_volume", metavar="PATH", default="-", required=True,
                        help="Moving volume to be used for registration")
    parser.add_argument("-it", "--initial-transform", dest="initial_transform", metavar="PATH", default="-",
                        required=False, help="Initial rigid transform for re-registration")
    parser.add_argument("-o", "--output-directory", dest="output_directory", metavar="PATH", default="-",
                        required=False, help="Output directory for registration result")

    args = parser.parse_args(argv)

    for inputFile in [args.fixed_label, args.moving_label, args.fixed_volume, args.moving_volume]:
      if not os.path.isfile(inputFile):
        raise AttributeError, "File not found: %s" % inputFile

    success, fixedLabel = slicer.util.loadLabelVolume(args.fixed_label, returnNode=True)
    success, movingLabel = slicer.util.loadLabelVolume(args.moving_label, returnNode=True)
    success, fixedVolume = slicer.util.loadVolume(args.fixed_volume, returnNode=True)
    success, movingVolume = slicer.util.loadVolume(args.moving_volume, returnNode=True)

    parameterNode = slicer.vtkMRMLScriptedModuleNode()
    parameterNode.SetAttribute('FixedImageNodeID', fixedVolume.GetID())
    parameterNode.SetAttribute('FixedLabelNodeID', fixedLabel.GetID())
    parameterNode.SetAttribute('MovingImageNodeID', movingVolume.GetID())
    parameterNode.SetAttribute('MovingLabelNodeID', movingLabel.GetID())

    logic = SliceTrackerRegistrationLogic()
    logic.run(parameterNode)

    if args.output_directory != "-":
      logic.registrationResult.save(args.output_directory)

  except Exception, e:
    print e
  def setup(self):
    ScriptedLoadableModuleWidget.setup(self)

    # Instantiate and connect widgets ...

    self.workflow = ctk.ctkWorkflow()

    workflowWidget = ctk.ctkWorkflowStackedWidget()
    workflowWidget.setWorkflow( self.workflow )

    # create all wizard steps
    self.loadDataStep = PedicleScrewSimulatorWizard.LoadDataStep( 'LoadData'  )
    self.defineROIStep = PedicleScrewSimulatorWizard.DefineROIStep( 'DefineROI'  )
    self.measurementsStep = PedicleScrewSimulatorWizard.MeasurementsStep( 'Measurements'  )
    self.landmarksStep = PedicleScrewSimulatorWizard.LandmarksStep( 'Landmarks' )
    self.screwStep = PedicleScrewSimulatorWizard.ScrewStep( 'Screw' )
    self.gradeStep = PedicleScrewSimulatorWizard.GradeStep( 'Grade' )
    self.endStep = PedicleScrewSimulatorWizard.EndStep( 'Final'  )
    
    # add the wizard steps to an array for convenience
    allSteps = []

    allSteps.append( self.loadDataStep )
    allSteps.append( self.defineROIStep )
    allSteps.append( self.landmarksStep)
    allSteps.append( self.measurementsStep )
    allSteps.append( self.screwStep)
    allSteps.append( self.gradeStep)
    allSteps.append( self.endStep )
    
    
    # Add transition 
    # Check if volume is loaded
    self.workflow.addTransition( self.loadDataStep, self.defineROIStep )
    
    self.workflow.addTransition( self.defineROIStep, self.landmarksStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.defineROIStep, self.loadDataStep, 'fail', ctk.ctkWorkflow.Bidirectional  )
    
    self.workflow.addTransition( self.landmarksStep, self.measurementsStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.landmarksStep, self.measurementsStep, 'fail', ctk.ctkWorkflow.Bidirectional )
    
    self.workflow.addTransition( self.measurementsStep, self.screwStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.measurementsStep, self.screwStep, 'fail', ctk.ctkWorkflow.Bidirectional )
    
    self.workflow.addTransition( self.screwStep, self.gradeStep, 'pass', ctk.ctkWorkflow.Bidirectional )
    self.workflow.addTransition( self.screwStep, self.gradeStep, 'fail', ctk.ctkWorkflow.Bidirectional )
          
    self.workflow.addTransition( self.gradeStep, self.endStep )
           
    nNodes = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLScriptedModuleNode')

    self.parameterNode = None
    for n in xrange(nNodes):
      compNode = slicer.mrmlScene.GetNthNodeByClass(n, 'vtkMRMLScriptedModuleNode')
      nodeid = None
      if compNode.GetModuleName() == 'PedicleScrewSimulator':
        self.parameterNode = compNode
        print 'Found existing PedicleScrewSimulator parameter node'
        break
    if self.parameterNode == None:
      self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
      self.parameterNode.SetModuleName('PedicleScrewSimulator')
      slicer.mrmlScene.AddNode(self.parameterNode)
 
    for s in allSteps:
        s.setParameterNode (self.parameterNode)
    
    
    # restore workflow step
    currentStep = self.parameterNode.GetParameter('currentStep')
    
    if currentStep != '':
      print 'Restoring workflow step to ', currentStep
      if currentStep == 'LoadData':
        self.workflow.setInitialStep(self.loadDataStep)
      if currentStep == 'DefineROI':
        self.workflow.setInitialStep(self.defineROIStep)
      if currentStep == 'Measurements':
        self.workflow.setInitialStep(self.measurementsStep)
      if currentStep == 'Landmarks':
        self.workflow.setInitialStep(self.landmarksStep)
      if currentStep == 'Screw':
        self.workflow.setInitialStep(self.screwStep) 
      if currentStep == 'Grade':
        self.workflow.setInitialStep(self.gradeStep)   
      if currentStep == 'Final':
        self.workflow.setInitialStep(self.endStep)
    else:
      print 'currentStep in parameter node is empty!'
    
    
    # start the workflow and show the widget
    self.workflow.start()
    workflowWidget.visible = True
    self.layout.addWidget( workflowWidget )
 def _createParameterNode(self):
     parameterNode = slicer.vtkMRMLScriptedModuleNode()
     slicer.mrmlScene.AddNode(parameterNode)
     return parameterNode
Пример #23
0
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)

        # Instantiate and connect widgets ...
        self.pbucLogic = ImagelessUSCalibrationLogic(
        )  # Have reference to an instance of the logic

        #
        # Points group box
        #
        self.pointGroupBox = qt.QGroupBox()
        self.pointGroupBox.setTitle("Points")
        self.layout.addWidget(self.pointGroupBox)
        # Layout within the group box
        self.pointGroupBoxLayout = qt.QVBoxLayout(self.pointGroupBox)

        # Marked point frame
        self.markedPointFrame = qt.QFrame()
        self.pointGroupBoxLayout.addWidget(self.markedPointFrame)
        # Layout within the frame
        self.markedPointLayout = qt.QHBoxLayout(self.markedPointFrame)

        # Select point
        self.selectMarkedPointButton = qt.QPushButton("Marked corner")
        self.selectMarkedPointButton.setIcon(
            qt.QIcon(":/Icons/MarkupsMouseModePlace.png"))
        self.selectMarkedPointButton.setToolTip(
            "Place points on the corners of the ultrasound probe's foot on the marked side."
        )
        self.markedPointLayout.addWidget(self.selectMarkedPointButton)

        # Reset
        self.resetMarkedPointsButton = qt.QPushButton("")
        self.resetMarkedPointsButton.setIcon(
            qt.QApplication.style().standardIcon(
                qt.QStyle.SP_DialogResetButton))
        self.resetMarkedPointsButton.setSizePolicy(qt.QSizePolicy.Fixed,
                                                   qt.QSizePolicy.Fixed)
        self.resetMarkedPointsButton.setToolTip("Clear all points.")
        self.markedPointLayout.addWidget(self.resetMarkedPointsButton)

        # Unmarked point frame
        self.unmarkedPointFrame = qt.QFrame()
        self.pointGroupBoxLayout.addWidget(self.unmarkedPointFrame)
        # Layout within the frame
        self.unmarkedPointLayout = qt.QHBoxLayout(self.unmarkedPointFrame)

        # Select point
        self.selectUnmarkedPointButton = qt.QPushButton("Unmarked corner")
        self.selectUnmarkedPointButton.setIcon(
            qt.QIcon(":/Icons/MarkupsMouseModePlace.png"))
        self.selectUnmarkedPointButton.setToolTip(
            "Place points on the corners of the ultrasound probe's foot on the unmarked side."
        )
        self.unmarkedPointLayout.addWidget(self.selectUnmarkedPointButton)

        # Reset
        self.resetUnmarkedPointsButton = qt.QPushButton("")
        self.resetUnmarkedPointsButton.setIcon(
            qt.QApplication.style().standardIcon(
                qt.QStyle.SP_DialogResetButton))
        self.resetUnmarkedPointsButton.setSizePolicy(qt.QSizePolicy.Fixed,
                                                     qt.QSizePolicy.Fixed)
        self.resetUnmarkedPointsButton.setToolTip("Clear all points.")
        self.unmarkedPointLayout.addWidget(self.resetUnmarkedPointsButton)

        #
        # Depth group box
        #
        self.depthGroupBox = qt.QGroupBox()
        self.depthGroupBox.setTitle("Depth")
        self.layout.addWidget(self.depthGroupBox)
        # Layout within the group box
        self.depthGroupBoxLayout = qt.QHBoxLayout(self.depthGroupBox)

        # Depth label
        self.depthLabel = qt.QLabel("Depth \t")
        self.depthLabel.setSizePolicy(qt.QSizePolicy.Fixed,
                                      qt.QSizePolicy.Fixed)
        self.depthGroupBoxLayout.addWidget(self.depthLabel)

        # Depth spin box
        self.depthSpinBox = qt.QSpinBox()
        self.depthSpinBox.setRange(0, 1000)
        self.depthSpinBox.setSingleStep(1)
        self.depthSpinBox.setSuffix("mm")
        self.depthSpinBox.setToolTip("Ultrasound imaging depth.")
        self.depthGroupBoxLayout.addWidget(self.depthSpinBox)

        #
        # Result label
        #
        self.calibrationResultLabel = qt.QLabel()
        self.calibrationResultLabel.setText(
            "No calibration parameters selected.")
        self.calibrationResultLabel.setToolTip("Output from the calibration.")
        self.layout.addWidget(self.calibrationResultLabel)

        #
        # Advanced area
        #
        self.advancedCollapsibleButton = ctk.ctkCollapsibleButton()
        self.advancedCollapsibleButton.setText("Advanced")
        self.advancedCollapsibleButton.collapsed = True
        self.layout.addWidget(self.advancedCollapsibleButton)
        # Layout within the collapsible button
        self.advancedLayout = qt.QFormLayout(self.advancedCollapsibleButton)

        # Mark point
        self.applyButton = qt.QPushButton("Apply")
        self.applyButton.setToolTip(
            "Apply the ImageToProbe transform to the ultrasound image.")
        self.advancedLayout.addWidget(self.applyButton)

        #
        # Parameters area
        #
        self.parametersCollapsibleButton = ctk.ctkCollapsibleButton()
        self.parametersCollapsibleButton.setText("Parameters")
        self.parametersCollapsibleButton.collapsed = True
        self.advancedLayout.addWidget(self.parametersCollapsibleButton)
        # Layout within the collapsible button
        self.parametersLayout = qt.QVBoxLayout(
            self.parametersCollapsibleButton)

        # Parameters node
        self.usCalibrationNodeSelector = slicer.qMRMLNodeComboBox()
        self.usCalibrationNodeSelector.nodeTypes = [
            "vtkMRMLScriptedModuleNode"
        ]
        self.usCalibrationNodeSelector.addEnabled = True
        self.usCalibrationNodeSelector.removeEnabled = True
        self.usCalibrationNodeSelector.noneEnabled = False
        self.usCalibrationNodeSelector.showHidden = True  # Since scripted module nodes are hidden by default
        self.usCalibrationNodeSelector.showChildNodeTypes = False
        self.usCalibrationNodeSelector.baseName = "UltrasoundCalibration"
        self.usCalibrationNodeSelector.setMRMLScene(slicer.mrmlScene)
        self.usCalibrationNodeSelector.setToolTip(
            "Select the ultrasound calibration parameters node.")
        self.parametersLayout.addWidget(self.usCalibrationNodeSelector)

        #
        # Input group box
        #
        self.inputGroupBox = qt.QGroupBox(self.parametersCollapsibleButton)
        self.inputGroupBox.setTitle("Input")
        self.parametersLayout.addWidget(self.inputGroupBox)
        # Layout within the group box
        self.inputGroupBoxLayout = qt.QFormLayout(self.inputGroupBox)

        # US image selector
        self.usImageNodeSelector = slicer.qMRMLNodeComboBox()
        self.usImageNodeSelector.nodeTypes = ["vtkMRMLVolumeNode"]
        self.usImageNodeSelector.addEnabled = False
        self.usImageNodeSelector.removeEnabled = False
        self.usImageNodeSelector.noneEnabled = True
        self.usImageNodeSelector.showHidden = False
        self.usImageNodeSelector.showChildNodeTypes = True
        self.usImageNodeSelector.setMRMLScene(slicer.mrmlScene)
        self.usImageNodeSelector.setToolTip(
            "Select the ultrasound image node.")
        self.inputGroupBoxLayout.addRow("Ultrasound image ",
                                        self.usImageNodeSelector)

        # StylusTipToProbe selector
        self.stylusTipToProbeNodeSelector = slicer.qMRMLNodeComboBox()
        self.stylusTipToProbeNodeSelector.nodeTypes = [
            "vtkMRMLLinearTransformNode"
        ]
        self.stylusTipToProbeNodeSelector.addEnabled = False
        self.stylusTipToProbeNodeSelector.removeEnabled = False
        self.stylusTipToProbeNodeSelector.noneEnabled = True
        self.stylusTipToProbeNodeSelector.showHidden = False
        self.stylusTipToProbeNodeSelector.showChildNodeTypes = True
        self.stylusTipToProbeNodeSelector.setMRMLScene(slicer.mrmlScene)
        self.stylusTipToProbeNodeSelector.setToolTip(
            "Select the StylusTipToProbe node (parent transforms will be applied)."
        )
        self.inputGroupBoxLayout.addRow("StylusTipToProbe ",
                                        self.stylusTipToProbeNodeSelector)

        #
        # Output group box
        #
        self.outputGroupBox = qt.QGroupBox(self.parametersCollapsibleButton)
        self.outputGroupBox.setTitle("Output")
        self.parametersLayout.addWidget(self.outputGroupBox)
        # Layout within the group box
        self.outputGroupBoxLayout = qt.QFormLayout(self.outputGroupBox)

        # ImageToProbe selector
        self.imageToProbeNodeSelector = slicer.qMRMLNodeComboBox()
        self.imageToProbeNodeSelector.nodeTypes = [
            "vtkMRMLLinearTransformNode"
        ]
        self.imageToProbeNodeSelector.addEnabled = True
        self.imageToProbeNodeSelector.removeEnabled = False
        self.imageToProbeNodeSelector.noneEnabled = True
        self.imageToProbeNodeSelector.renameEnabled = True
        self.imageToProbeNodeSelector.showHidden = False
        self.imageToProbeNodeSelector.showChildNodeTypes = True
        self.imageToProbeNodeSelector.setMRMLScene(slicer.mrmlScene)
        self.imageToProbeNodeSelector.setToolTip(
            "Select the ImageToProbe output node (stores the result of the calibration)."
        )
        self.outputGroupBoxLayout.addRow("ImageToProbe ",
                                         self.imageToProbeNodeSelector)

        #
        # Set up connections
        #
        self.selectMarkedPointButton.connect(
            "clicked(bool)", self.onSelectMarkedPointButtonClicked)
        self.resetMarkedPointsButton.connect(
            "clicked(bool)", self.onResetMarkedPointsButtonClicked)

        self.selectUnmarkedPointButton.connect(
            "clicked(bool)", self.onSelectUnmarkedPointButtonClicked)
        self.resetUnmarkedPointsButton.connect(
            "clicked(bool)", self.onResetUnmarkedPointsButtonClicked)

        self.depthSpinBox.connect("valueChanged(int)", self.onDepthChanged)

        self.usCalibrationNodeSelector.connect(
            "currentNodeChanged(vtkMRMLNode*)", self.onCalibrationNodeChanged)
        self.usImageNodeSelector.connect("currentNodeChanged(vtkMRMLNode*)",
                                         self.onUSImageNodeChanged)
        self.stylusTipToProbeNodeSelector.connect(
            "currentNodeChanged(vtkMRMLNode*)",
            self.onStylusTipToProbeNodeChanged)

        self.imageToProbeNodeSelector.connect(
            "currentNodeChanged(vtkMRMLNode*)", self.onImageToProbeNodeChanged)

        self.applyButton.connect("clicked(bool)",
                                 self.onApplyOutputTransformToImageClicked)

        #
        # Create a parameters node by default
        #
        defaultUSCalibrationNode = slicer.vtkMRMLScriptedModuleNode()
        defaultUSCalibrationNode.SetName("UltrasoundCalibration")
        defaultUSCalibrationNode.SetScene(slicer.mrmlScene)
        slicer.mrmlScene.AddNode(defaultUSCalibrationNode)
        self.usCalibrationNodeSelector.setCurrentNodeID(
            defaultUSCalibrationNode.GetID())

        # Add vertical spacer
        self.layout.addStretch(1)
Пример #24
0
  def updateWidgetFromMRML(self):
    """Changes the displayed inputs to match the current parameter node
       If an attribute has not been set, it is set from the currently
       displayed attribute
    """

    # If there is no parameter node, create one and add it to the scene
    if self.parameterSelector.currentNode() is None:
      node = slicer.vtkMRMLScriptedModuleNode()
      slicer.mrmlScene.AddNode(node)
      self.parameterNodeCreated(node)
      self.parameterSelector.setCurrentNode(node)
    paramNode = self.parameterSelector.currentNode()

    if paramNode is not None:
      # DVH Array 1
      dvh1Node = paramNode.GetNodeReferenceID(self.dvh1NodeReference)
      self.dvh1Selector.blockSignals(True)
      self.dvh1Selector.setCurrentNodeID(dvh1Node)
      self.dvh1Selector.blockSignals(False)

      # DVH Array 2
      dvh2Node = paramNode.GetNodeReferenceID(self.dvh2NodeReference)
      self.dvh2Selector.blockSignals(True)
      self.dvh2Selector.setCurrentNodeID(dvh2Node)
      self.dvh2Selector.blockSignals(False)

      # Dose Volume
      doseVolumeNode = paramNode.GetNodeReferenceID(self.doseVolumeNodeReference)
      self.doseVolumeSelector.blockSignals(True)
      self.doseVolumeSelector.setCurrentNodeID(doseVolumeNode)
      self.doseVolumeSelector.blockSignals(False)

      # Dose Volume Only Checkbox
      doseVolumeOnlyChecked = paramNode.GetAttribute(self.doseVolumeOnlyCheckedAttrName)
      if doseVolumeOnlyChecked is not None:
        checkedState = int(doseVolumeOnlyChecked)
        self.showDoseVolumeOnlyCheckbox.blockSignals(True)
        if checkedState:
          self.showDoseVolumeOnlyCheckbox.setCheckState(2)
        else:
          self.showDoseVolumeOnlyCheckbox.setCheckState(0)
        self.showDoseVolumeOnlyCheckbox.blockSignals(False)
      else:
        self.parameterSelector.currentNode().SetAttribute(self.doseVolumeOnlyCheckedAttrName, str(self.showDoseVolumeOnlyCheckbox.checkState()))

      # Dose To Agreement Criterion
      doseToAgreementCriterion = paramNode.GetAttribute(self.doseToAgreementCriterionAttrName)
      if doseToAgreementCriterion is not None:
        self.doseToAgreementSpinbox.blockSignals(True)
        self.doseToAgreementSpinbox.setValue(float(doseToAgreementCriterion))
        self.doseToAgreementSpinbox.blockSignals(False)
      else:
        paramNode.SetAttribute(self.doseToAgreementCriterionAttrName, str(self.doseToAgreementSpinbox.value))

      # Volume Difference Criterion
      volumeDifferenceCriterion = paramNode.GetAttribute(self.volumeDifferenceCriterionAttrName)
      if volumeDifferenceCriterion is not None:
        self.volumeDifferenceSpinbox.blockSignals(True)
        self.volumeDifferenceSpinbox.setValue(float(volumeDifferenceCriterion))
        self.volumeDifferenceSpinbox.blockSignals(False)
      else:
        paramNode.SetAttribute(self.volumeDifferenceCriterionAttrName, str(self.volumeDifferenceSpinbox.value))

      # Agreement Acceptance % (use previously stored one if availiable)
      agreementAcceptancePercentage = paramNode.GetAttribute(self.agreementAcceptanceAttrName)
      if agreementAcceptancePercentage is not None:
        self.agreementAcceptanceOutput.text = agreementAcceptancePercentage
      else:
        self.agreementAcceptanceOutput.text = ''
Пример #25
0
  def updateWidgetFromMRML(self):
    """Changes the displayed inputs to match the current parameter node
       If an attribute has not been set, it is set from the currently
       displayed attribute
    """

    # If there is no parameter node, create one and add it to the scene
    if self.parameterSelector.currentNode() is None:
      node = slicer.vtkMRMLScriptedModuleNode()
      slicer.mrmlScene.AddNode(node)
      self.parameterNodeCreated(node)
      self.parameterSelector.setCurrentNode(node)
    paramNode = self.parameterSelector.currentNode()

    if paramNode is not None:
      # DVH Table 1
      dvh1Node = paramNode.GetNodeReferenceID(self.dvh1NodeReference)
      self.dvh1Selector.blockSignals(True)
      self.dvh1Selector.setCurrentNodeID(dvh1Node)
      self.dvh1Selector.blockSignals(False)

      # DVH Table 2
      dvh2Node = paramNode.GetNodeReferenceID(self.dvh2NodeReference)
      self.dvh2Selector.blockSignals(True)
      self.dvh2Selector.setCurrentNodeID(dvh2Node)
      self.dvh2Selector.blockSignals(False)

      # Dose Volume
      doseVolumeNode = paramNode.GetNodeReferenceID(self.doseVolumeNodeReference)
      self.doseVolumeSelector.blockSignals(True)
      self.doseVolumeSelector.setCurrentNodeID(doseVolumeNode)
      self.doseVolumeSelector.blockSignals(False)

      # Dose Volume Only Checkbox
      doseVolumeOnlyChecked = paramNode.GetAttribute(self.doseVolumeOnlyCheckedAttrName)
      if doseVolumeOnlyChecked is not None:
        checkedState = int(doseVolumeOnlyChecked)
        self.showDoseVolumeOnlyCheckbox.blockSignals(True)
        if checkedState:
          self.showDoseVolumeOnlyCheckbox.setCheckState(2)
        else:
          self.showDoseVolumeOnlyCheckbox.setCheckState(0)
        self.showDoseVolumeOnlyCheckbox.blockSignals(False)
      else:
        self.parameterSelector.currentNode().SetAttribute(self.doseVolumeOnlyCheckedAttrName, str(self.showDoseVolumeOnlyCheckbox.checkState()))

      # Dose To Agreement Criterion
      doseToAgreementCriterion = paramNode.GetAttribute(self.doseToAgreementCriterionAttrName)
      if doseToAgreementCriterion is not None:
        self.doseToAgreementSpinbox.blockSignals(True)
        self.doseToAgreementSpinbox.setValue(float(doseToAgreementCriterion))
        self.doseToAgreementSpinbox.blockSignals(False)
      else:
        paramNode.SetAttribute(self.doseToAgreementCriterionAttrName, str(self.doseToAgreementSpinbox.value))

      # Volume Difference Criterion
      volumeDifferenceCriterion = paramNode.GetAttribute(self.volumeDifferenceCriterionAttrName)
      if volumeDifferenceCriterion is not None:
        self.volumeDifferenceSpinbox.blockSignals(True)
        self.volumeDifferenceSpinbox.setValue(float(volumeDifferenceCriterion))
        self.volumeDifferenceSpinbox.blockSignals(False)
      else:
        paramNode.SetAttribute(self.volumeDifferenceCriterionAttrName, str(self.volumeDifferenceSpinbox.value))

      # Agreement Acceptance % (use previously stored one if availiable)
      agreementAcceptancePercentage = paramNode.GetAttribute(self.agreementAcceptanceAttrName)
      if agreementAcceptancePercentage is not None:
        self.agreementAcceptanceOutput.text = agreementAcceptancePercentage
      else:
        self.agreementAcceptanceOutput.text = ''
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)

        # Instantiate and connect widgets ...

        self.workflow = ctk.ctkWorkflow()

        workflowWidget = ctk.ctkWorkflowStackedWidget()
        workflowWidget.setWorkflow(self.workflow)

        # create all wizard steps
        self.loadDataStep = PedicleScrewSimulatorWizard.LoadDataStep(
            'LoadData')
        self.defineROIStep = PedicleScrewSimulatorWizard.DefineROIStep(
            'DefineROI')
        self.measurementsStep = PedicleScrewSimulatorWizard.MeasurementsStep(
            'Measurements')
        self.landmarksStep = PedicleScrewSimulatorWizard.LandmarksStep(
            'Landmarks')
        self.screwStep = PedicleScrewSimulatorWizard.ScrewStep('Screw')
        self.gradeStep = PedicleScrewSimulatorWizard.GradeStep('Grade')
        self.endStep = PedicleScrewSimulatorWizard.EndStep('Final')

        # add the wizard steps to an array for convenience
        allSteps = []

        allSteps.append(self.loadDataStep)
        allSteps.append(self.defineROIStep)
        allSteps.append(self.landmarksStep)
        allSteps.append(self.measurementsStep)
        allSteps.append(self.screwStep)
        allSteps.append(self.gradeStep)
        allSteps.append(self.endStep)

        # Add transition
        # Check if volume is loaded
        self.workflow.addTransition(self.loadDataStep, self.defineROIStep)

        self.workflow.addTransition(self.defineROIStep, self.landmarksStep,
                                    'pass', ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.defineROIStep, self.loadDataStep,
                                    'fail', ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.landmarksStep, self.measurementsStep,
                                    'pass', ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.landmarksStep, self.measurementsStep,
                                    'fail', ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.measurementsStep, self.screwStep,
                                    'pass', ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.measurementsStep, self.screwStep,
                                    'fail', ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.screwStep, self.gradeStep, 'pass',
                                    ctk.ctkWorkflow.Bidirectional)
        self.workflow.addTransition(self.screwStep, self.gradeStep, 'fail',
                                    ctk.ctkWorkflow.Bidirectional)

        self.workflow.addTransition(self.gradeStep, self.endStep)

        nNodes = slicer.mrmlScene.GetNumberOfNodesByClass(
            'vtkMRMLScriptedModuleNode')

        self.parameterNode = None
        for n in xrange(nNodes):
            compNode = slicer.mrmlScene.GetNthNodeByClass(
                n, 'vtkMRMLScriptedModuleNode')
            nodeid = None
            if compNode.GetModuleName() == 'PedicleScrewSimulator':
                self.parameterNode = compNode
                print 'Found existing PedicleScrewSimulator parameter node'
                break
        if self.parameterNode == None:
            self.parameterNode = slicer.vtkMRMLScriptedModuleNode()
            self.parameterNode.SetModuleName('PedicleScrewSimulator')
            slicer.mrmlScene.AddNode(self.parameterNode)

        for s in allSteps:
            s.setParameterNode(self.parameterNode)

        # restore workflow step
        currentStep = self.parameterNode.GetParameter('currentStep')

        if currentStep != '':
            print 'Restoring workflow step to ', currentStep
            if currentStep == 'LoadData':
                self.workflow.setInitialStep(self.loadDataStep)
            if currentStep == 'DefineROI':
                self.workflow.setInitialStep(self.defineROIStep)
            if currentStep == 'Measurements':
                self.workflow.setInitialStep(self.measurementsStep)
            if currentStep == 'Landmarks':
                self.workflow.setInitialStep(self.landmarksStep)
            if currentStep == 'Screw':
                self.workflow.setInitialStep(self.screwStep)
            if currentStep == 'Grade':
                self.workflow.setInitialStep(self.gradeStep)
            if currentStep == 'Final':
                self.workflow.setInitialStep(self.endStep)
        else:
            print 'currentStep in parameter node is empty!'

        # start the workflow and show the widget
        self.workflow.start()
        workflowWidget.visible = True
        self.layout.addWidget(workflowWidget)
Пример #27
0
 def _getParameterNode(self):
   parameterNode = slicer.vtkMRMLScriptedModuleNode()
   slicer.mrmlScene.AddNode(parameterNode)
   return parameterNode