コード例 #1
0
  def onLogicModifiedForTests(self, logic_node, event):
    status = logic_node.GetStatusString()
    if not logic_node.IsBusy():
      if status == 'Completed with errors' or status == 'Cancelled':
        self.removeObserver(logic_node, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent,
                            self.onLogicModifiedForTests)
        self.delayDisplay('Tests Failed!')
      elif status == 'Completed':
        self.removeObserver(logic_node, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent,
                            self.onLogicModifiedForTests)

        # If Shape Analysis Module is completed without errors, then run some other tests on the generated outputs
        self.assertTrue(self.test_Shape4D())
        slicer.mrmlScene.Clear(0)
        self.delayDisplay('Tests Passed!')
コード例 #2
0
    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')
コード例 #3
0
    def __init__(self):
        self.Observations = []
        self.StatusModifiedEvent = slicer.vtkMRMLCommandLineModuleNode(
        ).StatusModifiedEvent

        self.parameters = {}
        self.success = False
コード例 #4
0
    def computeFeatures(self,
                        inputScan,
                        inputSegmentation,
                        computeGLCMFeatures,
                        computeGLRLMFeatures,
                        computeBMFeatures,
                        GLCMFeaturesValueDict,
                        GLRLMFeaturesValueDict,
                        BMFeaturesValueDict):

        if not (self.inputDataVerification(inputScan, inputSegmentation)):
            return
        if not (computeGLCMFeatures or computeGLRLMFeatures or computeBMFeatures):
            slicer.util.warningDisplay("Please select at least one type of features to compute")
            return

        # Create the CLInodes, and observe them for async logic
        if computeGLCMFeatures:
            logging.info('Computing GLCM Features ...')
            _module = slicer.modules.computeglcmfeatures
            GLCMParameters = dict(GLCMFeaturesValueDict)
            GLCMParameters["inputVolume"] = inputScan
            GLCMParameters["inputMask"] = inputSegmentation
            GLCMNode = slicer.cli.createNode(_module, GLCMParameters)
            self.addObserver(GLCMNode, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onGLCMNodeModified)
            GLCMNode = slicer.cli.run(_module, node=GLCMNode, parameters=GLCMParameters, wait_for_completion=False)

        if computeGLRLMFeatures:
            logging.info('Computing GLRLM Features ...')
            _module = slicer.modules.computeglrlmfeatures
            GLRLMParameters = dict(GLRLMFeaturesValueDict)
            GLRLMParameters["inputVolume"] = inputScan
            GLRLMParameters["inputMask"] = inputSegmentation
            GLRLMNode = slicer.cli.createNode(_module, GLRLMParameters)
            self.addObserver(GLRLMNode, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onGLRLMNodeModified)
            # self.GLRLMNodeObserver = GLRLMNode.AddObserver(slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onGLRLMNodeModified)
            GLRLMNode = slicer.cli.run(_module, node=GLRLMNode, parameters=GLRLMParameters, wait_for_completion=False)

        if computeBMFeatures:
            logging.info('Computing BM Features ...')
            _module = slicer.modules.computebmfeatures
            BMParameters = dict(BMFeaturesValueDict)
            BMParameters["inputVolume"] = inputScan
            BMParameters["inputMask"] = inputSegmentation
            BMNode = slicer.cli.createNode(_module, BMParameters)
            self.addObserver(BMNode, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent, self.onBMNodeModified)
            BMNode = slicer.cli.run(_module, node=BMNode, parameters=BMParameters, wait_for_completion=False)
コード例 #5
0
  def __init__(self, interface):
    VTKObservationMixin.__init__(self)

    self.interface = interface
    self.StatusModifiedEvent = slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent
    self.shape4D_module = slicer.modules.shape4d
    self.shape4D_cli_node = slicer.cli.createNode(self.shape4D_module)
    shape4D_cli_node_name = "Shape4D"
    self.shape4D_cli_node.SetName(shape4D_cli_node_name)
コード例 #6
0
    def __init__(self):
        VTKObservationMixin.__init__(self)

        cli = slicer.vtkMRMLCommandLineModuleNode()
        self.StatusModifiedEvent = cli.StatusModifiedEvent
        self.StatusEvents = []

        self.ExecutionFinished = False
        self.StatusEventCallback = None
コード例 #7
0
ファイル: PipelineMixin.py プロジェクト: NIRALUser/SPHARM-PDM
  def __init__(self, pipelineID, CaseInput, interface):

    VTKObservationMixin.__init__(self)

    self.pipelineID = pipelineID
    self.strPipelineID = "_" + str(self.pipelineID)
    self.CaseInput = CaseInput

    # Pipeline computation time
    self.pipelineStartTime = 0
    self.pipelineEndTime = 0

    # Status
    self.StatusModifiedEvent = slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent
    self.Node = slicer.vtkMRMLCommandLineModuleNode()
    self.Node.SetStatus(self.Node.Idle)
    self.Node.SetName('Case ' + str(self.pipelineID))
    self.currentCLINode = None
    self.ProgressBar = slicer.qSlicerCLIProgressBar()
    self.ProgressBar.setCommandLineModuleNode(self.Node)
    self.ProgressBar.setNameVisibility(slicer.qSlicerCLIProgressBar.AlwaysVisible)
    self.ErrorMessage = 'Unexpected error'
コード例 #8
0
ファイル: LogicMixin.py プロジェクト: NIRALUser/SPHARM-PDM
    def onPipelineModified(self, pipeline_node, event):

        pipeline_id = None
        current_pipeline = None
        for key, pipeline in self.pipeline.items():
            if pipeline.Node == pipeline_node:
                pipeline_id = key
                current_pipeline = pipeline
        if pipeline_id is None:
            logging.error('Error: Unidentified pipeline modified')
            return -1

        status = pipeline_node.GetStatusString()
        logging.info('-- %s: Case %d: %s', status, pipeline_id,
                     current_pipeline.CaseInput)

        if not pipeline_node.IsBusy():
            self.removeObserver(
                pipeline_node,
                slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent,
                self.onPipelineModified)
            # Report time taken to get to the non-busy state for the pipeline
            logging.info('Case %d (%s) took %d sec to run', pipeline_id,
                         current_pipeline.CaseInput,
                         current_pipeline.getPipelineComputationTime())
            statusForNode = None
            # If canceled, stop everything
            if pipeline_node.GetStatusString() == 'Cancelled':
                self.ErrorMessage = current_pipeline.ErrorMessage
                logging.error(current_pipeline.ErrorMessage)
                statusForNode = pipeline_node.GetStatus()
                # If completed, with errors or not
            else:
                # If completed with errors, inform user
                if pipeline_node.GetStatusString() == 'Completed with errors':
                    self.ErrorMessage = current_pipeline.ErrorMessage
                    logging.error(current_pipeline.ErrorMessage)

                # Then starts next case if it exists
                self.completed[pipeline_id] = True
                # If there is no anymore case
                if self.areAllPipelineCompleted():
                    logging.info('All pipelines took: %d sec to run',
                                 time.time() - self.allCaseStartTime)
                    statusForNode = pipeline_node.GetStatus()

            if statusForNode is None:
                # Run next pipeline
                self.startPipeline(pipeline_id + 1)
            else:
                self.Node.SetStatus(statusForNode)
コード例 #9
0
ファイル: PipelineMixin.py プロジェクト: jcfr/SPHARM-PDM
    def __init__(self, pipelineID, CaseInput, interface):

        VTKObservationMixin.__init__(self)

        self.pipelineID = pipelineID
        self.strPipelineID = "_" + str(self.pipelineID)
        self.CaseInput = CaseInput

        # Pipeline computation time
        self.pipelineStartTime = 0
        self.pipelineEndTime = 0

        # Status
        self.StatusModifiedEvent = slicer.vtkMRMLCommandLineModuleNode(
        ).StatusModifiedEvent
        self.Node = slicer.vtkMRMLCommandLineModuleNode()
        self.Node.SetStatus(self.Node.Idle)
        self.Node.SetName('Case ' + str(self.pipelineID))
        self.currentCLINode = None
        self.ProgressBar = slicer.qSlicerCLIProgressBar()
        self.ProgressBar.setCommandLineModuleNode(self.Node)
        self.ProgressBar.setNameVisibility(
            slicer.qSlicerCLIProgressBar.AlwaysVisible)
        self.ErrorMessage = 'Unexpected error'
コード例 #10
0
ファイル: LogicMixin.py プロジェクト: NIRALUser/SPHARM-PDM
  def onPipelineModified(self, pipeline_node, event):

    pipeline_id = None
    current_pipeline = None
    for key, pipeline in self.pipeline.iteritems():
      if pipeline.Node == pipeline_node:
        pipeline_id = key
        current_pipeline = pipeline
    if pipeline_id is None:
      logging.error('Error: Unidentified pipeline modified')
      return -1

    status = pipeline_node.GetStatusString()
    logging.info('-- %s: Case %d: %s', status, pipeline_id, current_pipeline.CaseInput)

    if not pipeline_node.IsBusy():
      self.removeObserver(pipeline_node, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent,
                          self.onPipelineModified)
      # Report time taken to get to the non-busy state for the pipeline
      logging.info('Case %d (%s) took %d sec to run', pipeline_id, current_pipeline.CaseInput,
                    current_pipeline.getPipelineComputationTime())
      statusForNode = None
      # If canceled, stop everything
      if pipeline_node.GetStatusString() == 'Cancelled':
        self.ErrorMessage = current_pipeline.ErrorMessage
        logging.error(current_pipeline.ErrorMessage)
        statusForNode = pipeline_node.GetStatus()
        # If completed, with errors or not
      else:
        # If completed with errors, inform user
        if pipeline_node.GetStatusString() == 'Completed with errors':
          self.ErrorMessage = current_pipeline.ErrorMessage
          logging.error(current_pipeline.ErrorMessage)

        # Then starts next case if it exists
        self.completed[pipeline_id] = True
        # If there is no anymore case
        if self.areAllPipelineCompleted():
          logging.info('All pipelines took: %d sec to run', time.time() - self.allCaseStartTime)
          statusForNode = pipeline_node.GetStatus()

      if statusForNode is None:
        # Run next pipeline
        self.startPipeline(pipeline_id + 1)
      else:
        self.Node.SetStatus(statusForNode)
コード例 #11
0
  def __init__(self, ModuleNodeName):
    VTKObservationMixin.__init__(self)

    self.InputCases = list()
    self.allCaseStartTime = 0

    # Dictionaries
    self.pipeline = {}
    self.completed = {}

    # Status
    self.Node = slicer.vtkMRMLCommandLineModuleNode()
    self.Node.SetStatus(self.Node.Idle)
    self.Node.SetName(ModuleNodeName)
    self.ProgressBar = slicer.qSlicerCLIProgressBar()
    self.ProgressBar.setCommandLineModuleNode(self.Node)
    self.ProgressBar.setNameVisibility(slicer.qSlicerCLIProgressBar.AlwaysVisible)
    self.ErrorMessage = 'Unexpected error'
コード例 #12
0
  def test_RegressionComputation(self):
    self.delayDisplay('Test : Regression Computation')

    #   Creation of input folder
    inputDirectoryPath = slicer.app.temporaryPath + '/RegressionComputationInputData'
    if not os.path.exists(inputDirectoryPath):
      os.makedirs(inputDirectoryPath)

    #   Download the shape input data
    input_downloads = (
      ('https://data.kitware.com/api/v1/file/5977a6558d777f16d01e9dd3/download', 'SphereToEllipsoid_00.vtk'),
      ('https://data.kitware.com/api/v1/file/5977a6558d777f16d01e9dd6/download', 'SphereToEllipsoid_01.vtk'),
      ('https://data.kitware.com/api/v1/file/5977a6568d777f16d01e9dd9/download', 'SphereToEllipsoid_02.vtk'),
      ('https://data.kitware.com/api/v1/file/5977a6568d777f16d01e9ddc/download', 'SphereToEllipsoid_03.vtk'),
      ('https://data.kitware.com/api/v1/file/5977a6568d777f16d01e9ddf/download', 'SphereToEllipsoid_04.vtk'),
    )
    inputRootnames = list()
    for i in range(len(input_downloads)):
      inputRootnames.append(input_downloads[i][1].split(".")[0])
    self.download_files(inputDirectoryPath, input_downloads)

    #   Creation of output folder
    outputDirectoryPath =  slicer.app.temporaryPath + '/RegressionComputationOutputData'
    if not os.path.exists(outputDirectoryPath):
      os.makedirs(outputDirectoryPath)

    moduleWidget = slicer.modules.RegressionComputationWidget

    # Parameter by default
    moduleWidget.shapeInputDirectory.directory = inputDirectoryPath
    inputShapeParameters = {'SphereToEllipsoid_00':[16,30,0,1], 'SphereToEllipsoid_01':[17,10,0,1], 'SphereToEllipsoid_02':[19,10,0,1], 'SphereToEllipsoid_03':[21,10,0,1], 'SphereToEllipsoid_04':[24,10,0,1] } #[age, sigmaW, tris, weight]

    for row in range(0, moduleWidget.tableWidget_inputShapeParameters.rowCount):
      inputshaperootname = moduleWidget.tableWidget_inputShapeParameters.cellWidget(row, 0).text
      param = inputShapeParameters[inputshaperootname]
      for column in range (0,moduleWidget.tableWidget_inputShapeParameters.columnCount - 1):
        widget = moduleWidget.tableWidget_inputShapeParameters.cellWidget(row, column + 1)
        tuple = widget.children()
        spinBox = tuple[1]
        spinBox.value = param[column]

    moduleWidget.t0.value = 16
    moduleWidget.tn.value = 24
    moduleWidget.T.value = 10

    moduleWidget.defKernelWidth.value = 70
    moduleWidget.kernelType.setCurrentIndex(1)  # p3m
    moduleWidget.regularityWeight.value = 0.01

    moduleWidget.outputDirectory.directory = outputDirectoryPath
    moduleWidget.outputPrefix.text = "regression_"
    moduleWidget.saveEveryN.value = 5

    moduleWidget.estimateBaseline.setCheckState(qt.Qt.Unchecked)
    moduleWidget.optimMethod.setCurrentIndex(0)  # FISTA
    moduleWidget.breakRatio.value = 0.00001
    moduleWidget.maxIters.value = 3000

    self.addObserver(moduleWidget.Logic.shape4D_cli_node, slicer.vtkMRMLCommandLineModuleNode().StatusModifiedEvent,
                     self.onLogicModifiedForTests)


    self.delayDisplay('Run Regression Computation')
    moduleWidget.applyButton.click()