def __init__(self, dbpath): maxthread = 1 self.pool_sema = BoundedSemaphore(maxthread) self.resample_sema = BoundedSemaphore(1) self.dbpath = dbpath # Status self.StatusModifiedEvent = slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent self.CLINode = slicer.vtkMRMLCommandLineModuleNode() self.CLINode.SetStatus(self.CLINode.Idle) # VTK Signals variables self.Observations = []
def __init__(self): # VTK Signals variables self.Observations = [] self.StatusModifiedEvent = slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent # Parameters dictionnaries self.ChangeLabelParameters = {} self.GenerateModelParameters = {} self.DecimateParameters = {} # Status self.CLINode = slicer.vtkMRMLCommandLineModuleNode() self.CLINode.SetStatus(self.CLINode.Idle)
def _testCLIStatusEventOnErrorTest(self, wait_for_completion): self.delayDisplay('Testing status events for a bad execution of a CLI') tempFile = qt.QTemporaryFile("CLIEventTest-outputFile-XXXXXX"); self.assertTrue(tempFile.open()) logic = CLIEventTestLogic() parameters = {} parameters["InputValue1"] = 1 parameters["InputValue2"] = 2 parameters["OperationType"] = 'Fail' parameters["OutputFile"] = tempFile.fileName() cliModule = slicer.modules.cli4test cli = slicer.cli.createNode(cliModule) self.assertEqual(cli.GetStatus(), cli.Idle) logic.runCLI(cliModule, cli, parameters, wait_for_completion) while not logic.ExecutionFinished: self.delayDisplay('Waiting for module to complete...') cli = slicer.vtkMRMLCommandLineModuleNode() expectedEvents = [] if not wait_for_completion: expectedEvents.append(cli.Scheduled) expectedEvents.append(cli.CompletedWithErrors) # Ignore cli.Running event (it may or may not be fired) if cli.Running in logic.StatusEvents: logic.StatusEvents.remove(cli.Running) self.assertEqual(logic.StatusEvents, expectedEvents) self.delayDisplay('Testing bad execution Passed')
def __init__(self): VTKObservationMixin.__init__(self) cli = slicer.vtkMRMLCommandLineModuleNode() self.StatusModifiedEvent = cli.StatusModifiedEvent self.StatusEvents = [] self.ExecutionFinished = False self.StatusEventCallback = None
def runRegistration( self, run ): if run: cliNode = self.WorkflowStep.getCLINode(slicer.modules.expertautomatedregistration) parameters = self.registerImageWorkflowParameters() self.get('RegisterApplyPushButton').setChecked(True) self.WorkflowStep.observeCLINode(cliNode, self.onRegistrationCLIModified) cliNode = slicer.cli.run(slicer.modules.expertautomatedregistration, cliNode, parameters, wait_for_completion = False) else: cliNode = self.WorkflowStep.observer( slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onRegistrationCLIModified) self.get('RegisterApplyPushButton').enabled = False cliNode.Cancel()
def runVesselEnhancement( self, run ): if run: cliNode = self.getCLINode(slicer.modules.enhancetubesusingdiscriminantanalysis) parameters = self.vesselEnhancementParameters() self.get('VesselEnhancementApplyPushButton').setChecked(True) self.observeCLINode(cliNode, self.onVesselEnhancementCLIModified) cliNode = slicer.cli.run(slicer.modules.enhancetubesusingdiscriminantanalysis, cliNode, parameters, wait_for_completion = False) else: cliNode = self.observer( slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onVesselEnhancementCLIModified) self.get('VesselEnhancementApplyPushButton').enabled = False cliNode.Cancel()
def runMergeAll( self, run, currentMerge = 0 ): if run: # Add observer on the PDF segmenter CLI cliNode = self.getCLINode(slicer.modules.imagelabelcombine) parameters = self.imageLabelCombineParameters() self.observeCLINode(cliNode, self.onImageLabelCombineModified) self.get('MergeAllApplyButton').setChecked(True) cliNode = slicer.cli.run(slicer.modules.imagelabelcombine, cliNode, parameters, wait_for_completion = False) else: cliNode = self.observer( slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onImageLabelCombineModified) self.get('SegmentApplyPDFPushButton').enabled = False cliNode.Cancel()
def runPDFSegmenter( self, run ): if run: # Add observer on the PDF segmenter CLI pdfSegmenterCLINode = self.WorkflowStep.getCLINode(slicer.modules.segmentconnectedcomponentsusingparzenpdfs, 'PDFSegmenterEditorEffect') self.observeCLINode(pdfSegmenterCLINode, self.onPDFSegmenterCLIModified) self.get('SegmentApplyPDFPushButton').setChecked(True) self.UndoRedo.saveState() self.updatePDFSegmenterParameters() self.PDFSegmenter.logic(None).applyPDFSegmenter() else: cliNode = self.observer( slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onPDFSegmenterCLIModified) self.get('SegmentApplyPDFPushButton').enabled = False cliNode.Cancel()
def runVesselEnhancement(self, run): if run: cliNode = self.getCLINode( slicer.modules.enhancetubesusingdiscriminantanalysis) parameters = self.vesselEnhancementParameters() self.get('VesselEnhancementApplyPushButton').setChecked(True) self.observeCLINode(cliNode, self.onVesselEnhancementCLIModified) cliNode = slicer.cli.run( slicer.modules.enhancetubesusingdiscriminantanalysis, cliNode, parameters, wait_for_completion=False) else: cliNode = self.observer( slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onVesselEnhancementCLIModified) self.get('VesselEnhancementApplyPushButton').enabled = False cliNode.Cancel()
def runPDFSegmenter(self, run): if run: # Add observer on the PDF segmenter CLI pdfSegmenterCLINode = self.WorkflowStep.getCLINode( slicer.modules.segmentconnectedcomponentsusingparzenpdfs, 'PDFSegmenterEditorEffect') self.observeCLINode(pdfSegmenterCLINode, self.onPDFSegmenterCLIModified) self.get('SegmentApplyPDFPushButton').setChecked(True) self.UndoRedo.saveState() self.updatePDFSegmenterParameters() self.PDFSegmenter.logic(None).applyPDFSegmenter() else: cliNode = self.observer( slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onPDFSegmenterCLIModified) self.get('SegmentApplyPDFPushButton').enabled = False cliNode.Cancel()
def onApply(self, run): if run: self.get('ApplyPushButton').setChecked(True) parameters = {} parameters["InputVolume"] = self.get('VolumeNodeComboBox').currentNode() parameters["OutputGeometry"] = self.get('OutputSkinModelNodeComboBox').currentNode() parameters['BackgroundLabel'] = self.get('BackgroundLabelSpinBox').value parameters['SkinLabel'] = self.get('SkinLabelsLineEdit').text parameters['Decimate'] = self.get('DecimateOutputSkinLabelCheckBox').isChecked() parameters['Spacing'] = self.get('SpacingLineEdit').text for i in parameters.keys(): if parameters[i] == None: print 'Skin model maker not ran: Parameters incorrect' self.get('ApplyPushButton').setChecked(False) return self.Logic.addObserver(self.Logic.GetCLINode(), slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onLogicModified) self.Logic.CreateSkinModel(parameters, False) else: self.get('ApplyPushButton').setChecked(True) # Keep checked until actually cancelled self.get('ApplyPushButton').setEnabled(False) self.Logic.Cancel()
def observeCLINode(self, cliNode, onCLINodeModified = None): if cliNode != None and onCLINodeModified != None: self.WorkflowStep.addObserver(cliNode, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, onCLINodeModified) self.WorkflowStep.Workflow.getProgressBar().setCommandLineModuleNode(cliNode)
def __init__(self): self.Observations = [] self.StatusModifiedEvent = slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent self.parameters = {} self.success = False
def observeCLINode(self, cliNode, onCLINodeModified=None): """Utility function to observe the given cli StatusModifiedEvent. """ if cliNode != None and onCLINodeModified != None: self.addObserver(cliNode, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, onCLINodeModified)