Beispiel #1
0
    def addFiducials(self):
        shaderFiducials = slicer.util.getNode('shaderFiducials')
        if not shaderFiducials:
            displayNode = slicer.vtkMRMLMarkupsDisplayNode()
            slicer.mrmlScene.AddNode(displayNode)
            fiducialNode = slicer.vtkMRMLMarkupsFiducialNode()
            fiducialNode.SetName('shaderFiducials')
            slicer.mrmlScene.AddNode(fiducialNode)
            fiducialNode.SetAndObserveDisplayNodeID(displayNode.GetID())
            for ras in ((28.338526, 34.064367, 10), (-10, 0, -5)):
                fiducialNode.AddFiducial(*ras)
            import random
            fiducialCount = 10
            radius = 75
            for index in range(fiducialCount):
                uvw = [random.random(), random.random(), random.random()]
                ras = map(lambda e: radius * (2. * e - 1.), uvw)
                fiducialNode.AddFiducial(*ras)

            # make it active
            selectionNode = slicer.mrmlScene.GetNodeByID(
                "vtkMRMLSelectionNodeSingleton")
            if (selectionNode is not None):
                selectionNode.SetReferenceActivePlaceNodeID(
                    fiducialNode.GetID())
  def run(self,numToAdd=100,rOffset=0,usefewerModifyCalls=0):
    """
    Run the actual algorithm
    """
    print('Running test to add %s fidicuals' % (numToAdd,))
    print('Index\tTime to add fid\tDelta between adds')
    print "%(index)04s\t" % {'index': "i"}, "t\tdt'"
    r = rOffset
    a = 0
    s = 0
    t1 = 0
    t2 = 0
    t3 = 0
    t4 = 0
    timeToAddThisFid = 0
    timeToAddLastFid = 0

    testStartTime = time.clock()
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode = slicer.vtkMRMLMarkupsFiducialNode()
    slicer.mrmlScene.AddNode(fidNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

    if usefewerModifyCalls == 1:
      print "Start modify"
      mod = fidNode.StartModify()

    # iterate over the number of fiducials to add
    for i in range(numToAdd):
      #    print "i = ", i, "/", numToAdd, ", r = ", r, ", a = ", a, ", s = ", s
      t1 = time.clock()
      fidNode.AddFiducial(r,a,s)
      t2 = time.clock()
      timeToAddThisFid = t2 - t1
      dt = timeToAddThisFid - timeToAddLastFid
      print '%(index)04d\t' % {'index': i}, timeToAddThisFid, "\t", dt
      r = r + 1.0
      a = a + 1.0
      s = s + 1.0
      timeToAddLastFid = timeToAddThisFid

    if usefewerModifyCalls == 1:
      fidNode.EndModify(mod)

    testEndTime = time.clock()
    testTime = testEndTime - testStartTime
    print "Total time to add ",numToAdd," = ", testTime

    return True
    def run(self, numToAdd=100, rOffset=0, usefewerModifyCalls=0):
        """
    Run the actual algorithm
    """
        print('Running test to add %s fidicuals' % (numToAdd, ))
        print('Index\tTime to add fid\tDelta between adds')
        print "%(index)04s\t" % {'index': "i"}, "t\tdt'"
        r = rOffset
        a = 0
        s = 0
        t1 = 0
        t2 = 0
        t3 = 0
        t4 = 0
        timeToAddThisFid = 0
        timeToAddLastFid = 0

        testStartTime = time.clock()
        displayNode = slicer.vtkMRMLMarkupsDisplayNode()
        slicer.mrmlScene.AddNode(displayNode)
        fidNode = slicer.vtkMRMLMarkupsFiducialNode()
        slicer.mrmlScene.AddNode(fidNode)
        fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

        if usefewerModifyCalls == 1:
            print "Start modify"
            mod = fidNode.StartModify()

        # iterate over the number of fiducials to add
        for i in range(numToAdd):
            #    print "i = ", i, "/", numToAdd, ", r = ", r, ", a = ", a, ", s = ", s
            t1 = time.clock()
            fidNode.AddFiducial(r, a, s)
            t2 = time.clock()
            timeToAddThisFid = t2 - t1
            dt = timeToAddThisFid - timeToAddLastFid
            print '%(index)04d\t' % {'index': i}, timeToAddThisFid, "\t", dt
            r = r + 1.0
            a = a + 1.0
            s = s + 1.0
            timeToAddLastFid = timeToAddThisFid

        if usefewerModifyCalls == 1:
            fidNode.EndModify(mod)

        testEndTime = time.clock()
        testTime = testEndTime - testStartTime
        print "Total time to add ", numToAdd, " = ", testTime

        return True
Beispiel #4
0
    def test_VolumeClipWithModel1(self):

        # Download MRHead from sample data
        import SampleData
        sampleDataLogic = SampleData.SampleDataLogic()
        self.delayDisplay("Getting MR Head Volume")
        inputVolume = sampleDataLogic.downloadMRHead()

        # Create empty model node
        clippingModel = slicer.vtkMRMLModelNode()
        slicer.mrmlScene.AddNode(clippingModel)

        # Create markup fiducials
        displayNode = slicer.vtkMRMLMarkupsDisplayNode()
        slicer.mrmlScene.AddNode(displayNode)
        inputMarkup = slicer.vtkMRMLMarkupsFiducialNode()
        inputMarkup.SetName('C')
        slicer.mrmlScene.AddNode(inputMarkup)
        inputMarkup.SetAndObserveDisplayNodeID(displayNode.GetID())
        inputMarkup.AddFiducial(35, -10, -10)
        inputMarkup.AddFiducial(-15, 20, -10)
        inputMarkup.AddFiducial(-25, -25, -10)
        inputMarkup.AddFiducial(-5, -60, -15)
        inputMarkup.AddFiducial(-5, 5, 60)
        inputMarkup.AddFiducial(-5, -35, -30)

        # Create output volume
        outputVolume = slicer.vtkMRMLScalarVolumeNode()
        slicer.mrmlScene.AddNode(outputVolume)

        # Clip volume
        logic = VolumeClipWithModelLogic()
        clipOutsideSurface = True
        fillOutsideValue = 0
        clipInsideSurface = True
        fillInsideValue = 255

        logic.updateModelFromMarkup(inputMarkup, clippingModel)
        logic.clipVolumeWithModel(inputVolume, clippingModel,
                                  clipOutsideSurface, fillOutsideValue,
                                  outputVolume)
        logic.showInSliceViewers(outputVolume, ["Red", "Yellow", "Green"])

        self.delayDisplay("Test passed!")
Beispiel #5
0
  def placeFiducials(self):

    # Create empty model node
    clippingModel = slicer.vtkMRMLModelNode()
    clippingModel.SetName('clipModelNode')
    slicer.mrmlScene.AddNode(clippingModel)

    # Create markup display fiducials - why do i need that?
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)

    # create markup fiducial node
    inputMarkup = slicer.vtkMRMLMarkupsFiducialNode()
    inputMarkup.SetName('inputMarkupNode')
    slicer.mrmlScene.AddNode(inputMarkup)
    inputMarkup.SetAndObserveDisplayNodeID(displayNode.GetID())

    # add Observer
    inputMarkup.AddObserver(vtk.vtkCommand.ModifiedEvent,self.updateModel)

    return True
Beispiel #6
0
  def addFiducials(self):
    shaderFiducials = slicer.util.getNode('shaderFiducials')
    if not shaderFiducials:
      displayNode = slicer.vtkMRMLMarkupsDisplayNode()
      slicer.mrmlScene.AddNode(displayNode)
      fiducialNode = slicer.vtkMRMLMarkupsFiducialNode()
      fiducialNode.SetName('shaderFiducials')
      slicer.mrmlScene.AddNode(fiducialNode)
      fiducialNode.SetAndObserveDisplayNodeID(displayNode.GetID())
      for ras in ((28.338526, 34.064367, 10), (-10, 0, -5)):
        fiducialNode.AddFiducial(*ras)
      import random
      fiducialCount = 10
      radius = 75
      for index in range(fiducialCount):
        uvw = [random.random(), random.random(), random.random()]
        ras = map(lambda e: radius * (2. * e - 1.), uvw)
        fiducialNode.AddFiducial(*ras)

      # make it active
      selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
      if (selectionNode is not None):
        selectionNode.SetReferenceActivePlaceNodeID(fiducialNode.GetID())
    def run(self, enableScreenshots=0, screenshotScaleFactor=1):
        """
    Run the actual algorithm
    """
        self.delayDisplay(
            'Running test of the Neurosurgical Planning tutorial')

        self.enableScreenshots = enableScreenshots
        self.screenshotScaleFactor = screenshotScaleFactor

        # conventional layout
        lm = slicer.app.layoutManager()
        lm.setLayout(2)

        moduleSelector = slicer.util.mainWindow().moduleSelector()
        #
        # first load the data
        #
        if self.enableScreenshots == 1:
            # for the tutorial, do it through the welcome module
            moduleSelector.selectModule('Welcome')
            self.delayDisplay("Screenshot")
            self.takeScreenshot('NeurosurgicalPlanning-Welcome',
                                'Welcome module', -1)
        else:
            # otherwise show the sample data module
            moduleSelector.selectModule('SampleData')

        # use the sample data module logic to load data for the self test
        import SampleData
        sampleDataLogic = SampleData.SampleDataLogic()

        self.delayDisplay("Getting Baseline volume")
        baselineVolume = sampleDataLogic.downloadWhiteMatterExplorationBaselineVolume(
        )

        self.delayDisplay("Getting DTI volume")
        dtiVolume = sampleDataLogic.downloadWhiteMatterExplorationDTIVolume()

        self.takeScreenshot('NeurosurgicalPlanning-Loaded', 'Data loaded', -1)

        #
        # link the viewers
        #

        if self.enableScreenshots == 1:
            # for the tutorial, pop up the linking control
            sliceController = slicer.app.layoutManager().sliceWidget(
                "Red").sliceController()
            popupWidget = sliceController.findChild("ctkPopupWidget")
            if popupWidget != None:
                popupWidget.pinPopup(1)
                self.takeScreenshot('NeurosurgicalPlanning-Link',
                                    'Link slice viewers', -1)
                popupWidget.pinPopup(0)

        sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
        compositeNode = sliceLogic.GetSliceCompositeNode()
        compositeNode.SetLinkedControl(1)

        #
        # baseline in the background
        #
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetBackgroundVolumeID(baselineVolume.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()

        self.takeScreenshot('NeurosurgicalPlanning-Baseline',
                            'Baseline in background', -1)

        #
        # adjust window level on baseline
        #
        moduleSelector.selectModule('Volumes')
        baselineDisplay = baselineVolume.GetDisplayNode()
        baselineDisplay.SetAutoWindowLevel(0)
        baselineDisplay.SetWindow(2600)
        baselineDisplay.SetLevel(1206)
        self.takeScreenshot('NeurosurgicalPlanning-WindowLevel',
                            'Set W/L on baseline', -1)

        #
        # switch to red slice only
        #
        lm.setLayout(6)
        self.takeScreenshot('NeurosurgicalPlanning-RedSliceOnly',
                            'Set layout to Red Slice only', -1)

        #
        # segmentation of tumour
        #

        #
        # create a label map and set it for editing
        #
        volumesLogic = slicer.modules.volumes.logic()
        baselineVolumeLabel = volumesLogic.CreateAndAddLabelVolume(
            slicer.mrmlScene, baselineVolume,
            baselineVolume.GetName() + '-label')
        baselineDisplayNode = baselineVolumeLabel.GetDisplayNode()
        baselineDisplayNode.SetAndObserveColorNodeID(
            'vtkMRMLColorTableNodeFileGenericAnatomyColors.txt')
        selectionNode = slicer.app.applicationLogic().GetSelectionNode()
        selectionNode.SetReferenceActiveVolumeID(baselineVolume.GetID())
        selectionNode.SetReferenceActiveLabelVolumeID(
            baselineVolumeLabel.GetID())
        slicer.app.applicationLogic().PropagateVolumeSelection(0)

        #
        # editor module
        #
        moduleSelector.selectModule('Editor')
        self.takeScreenshot('NeurosurgicalPlanning-Editor',
                            'Showing Editor Module', -1)

        # set the slice offset so drawing is right
        sliceNode = sliceLogic.GetSliceNode()
        sliceOffset = 58.7
        sliceNode.SetSliceOffset(sliceOffset)

        #
        # paint
        #
        editUtil = EditorLib.EditUtil.EditUtil()
        parameterNode = editUtil.getParameterNode()
        paintEffect = EditorLib.PaintEffectOptions()
        paintEffect.setMRMLDefaults()
        paintEffect.__del__()
        sliceWidget = lm.sliceWidget('Red')
        paintTool = EditorLib.PaintEffectTool(sliceWidget)
        self.takeScreenshot('NeurosurgicalPlanning-Paint',
                            'Paint tool in Editor Module', -1)

        #
        # paint in cystic part of tumor, using converstion from RAS coords to
        # avoid slice widget size differences
        #
        editUtil.setLabel(293)
        displayCoords = self.rasToDisplay(-7.4, 71, sliceOffset)
        paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        displayCoords = self.rasToDisplay(-11, 73, sliceOffset)
        paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        displayCoords = self.rasToDisplay(-12, 85, sliceOffset)
        paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        displayCoords = self.rasToDisplay(-13, 91, sliceOffset)
        paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        displayCoords = self.rasToDisplay(-15, 78, sliceOffset)
        paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        paintTool.paintApply()
        self.takeScreenshot('NeurosurgicalPlanning-PaintCystic',
                            'Paint cystic part of tumor', -1)

        #
        # paint in solid part of tumor
        #
        editUtil.setLabel(7)
        displayCoords = self.rasToDisplay(-0.5, 118.5, sliceOffset)
        paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        displayCoords = self.rasToDisplay(-7.4, 116, sliceOffset)
        paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        paintTool.paintApply()
        self.takeScreenshot('NeurosurgicalPlanning-PaintSolid',
                            'Paint solid part of tumor', -1)

        #
        # paint around the tumor
        #
        editUtil.setLabel(295)
        rMax = 25
        rMin = -50
        aMax = 145
        aMin = 50
        rasStep = 5

        # draw the top and bottom
        for r in range(rMin, rMax, rasStep):
            displayCoords = self.rasToDisplay(r, aMin, sliceOffset)
            paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
            displayCoords = self.rasToDisplay(r, aMax, sliceOffset)
            paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
        # draw the left and right
        for a in range(aMin, aMax, rasStep):
            displayCoords = self.rasToDisplay(rMin, a, sliceOffset)
            paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
            displayCoords = self.rasToDisplay(rMax, a, sliceOffset)
            paintTool.paintAddPoint(displayCoords[0], displayCoords[1])

        paintTool.paintApply()

        self.takeScreenshot('NeurosurgicalPlanning-PaintAround',
                            'Paint around tumor', -1)
        #
        # clean up after painting
        #
        paintTool.cleanup()
        paintTool = None

        #
        # Grow cut
        #
        growCutLogic = EditorLib.GrowCutEffectLogic(sliceWidget.sliceLogic())
        growCutLogic.growCut()
        self.takeScreenshot('NeurosurgicalPlanning-Growcut', 'Growcut', -1)

        #
        # Merge split volume
        #
        slicer.util.selectModule('Editor')
        slicer.util.findChildren(text='Split Merge Volume')[0].clicked()
        self.takeScreenshot('NeurosurgicalPlanning-SplitMerge', 'SplitMerge',
                            -1)

        #
        # go to the data module
        #
        moduleSelector.selectModule('Data')
        self.takeScreenshot('NeurosurgicalPlanning-SplitMergeData',
                            'SplitMerge results in Data', -1)

        #
        # Ventricles Segmentation
        #

        moduleSelector.selectModule('Editor')
        #
        # select the label volume with the area around the tumor
        slicer.util.findChildren(
            name='PerStructureVolumesFrame')[0].collapsed = False
        treeView = slicer.util.findChildren(name='StructuresView')[0]
        selection = qt.QItemSelection()
        # selecting the last split volume in the third row
        row = 2
        rowStart = treeView.model().index(row, 0)
        rowEnd = treeView.model().index(row,
                                        treeView.model().columnCount() - 1)
        # rowSel = qt.QItemSelection(rowStart, rowEnd)
        selection.select(rowStart, rowEnd)
        # backup: select the label map in the slice logic too
        baselinelabel295 = slicer.mrmlScene.GetFirstNodeByName(
            "BaselineVolume-region 3-label")
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetLabelVolumeID(baselinelabel295.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()
        self.takeScreenshot('NeurosurgicalPlanning-SelOutside',
                            'Select outside region', -1)

        #
        # Threshold tool
        #
        slicer.modules.EditorWidget.toolsBox.selectEffect('ThresholdEffect')
        parameterNode = slicer.modules.EditorWidget.toolsBox.currentOption.editUtil.getParameterNode(
        )
        parameterNode.SetParameter('ThresholdEffect,min', str(1700))
        slicer.modules.EditorWidget.toolsBox.currentTools[0].apply()
        self.takeScreenshot('NeurosurgicalPlanning-Ventricles',
                            'Ventricles segmentation', -1)

        #
        # Save Islands
        #
        slicer.modules.EditorWidget.toolsBox.selectEffect('SaveIslandEffect')
        saveIslandLogic = EditorLib.SaveIslandEffectLogic(
            sliceWidget.sliceLogic())
        displayCoords = self.rasToDisplay(25.3, 5.8, sliceOffset)
        xy = (displayCoords[0], displayCoords[1])
        saveIslandLogic.saveIsland(xy)
        self.takeScreenshot('NeurosurgicalPlanning-SaveIsland',
                            'Ventricles save island', -1)

        #
        # Merge and build
        #
        slicer.util.findChildren(text='Merge And Build')[0].clicked()

        #
        # switch to conventional layout
        #
        lm.setLayout(2)
        self.takeScreenshot('NeurosurgicalPlanning-MergeAndBuild',
                            'Merged and built models', -1)

        #
        # Tractography label map seeding
        #

        #
        # select label volume with label 293, in the second row
        #
        row = 1
        rowStart = treeView.model().index(row, 0)
        rowEnd = treeView.model().index(row,
                                        treeView.model().columnCount() - 1)
        # rowSel = qt.QItemSelection(rowStart, rowEnd)
        selection.select(rowStart, rowEnd)
        # backup: select the label map in the slice logic too
        baselinelabel293 = slicer.mrmlScene.GetFirstNodeByName(
            "BaselineVolume-region 1-label")
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetLabelVolumeID(baselinelabel293.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()
        self.takeScreenshot('NeurosurgicalPlanning-SelCystic',
                            'Select cystic region', -1)

        #
        # Dilate
        #
        slicer.modules.EditorWidget.toolsBox.selectEffect('DilateEffect')
        editUtil.setLabel(293)
        self.takeScreenshot('NeurosurgicalPlanning-Dilate', 'Dilate tool', -1)
        # tutorial says to click apply three times
        for d in range(1, 3):
            print d
            # slicer.util.findChildren(name='DilateEffectOptionsApply')[0].clicked()
            # slicer.modules.EditorWidget.toolsBox.currentTools[0].apply()
            slicer.modules.EditorWidget.toolsBox.currentOption.onApply()
        self.takeScreenshot('NeurosurgicalPlanning-Dilated', 'Dilated tumor',
                            -1)

        #
        # Tractography Label Map Seeding module
        #
        moduleSelector.selectModule('TractographyLabelMapSeeding')
        self.takeScreenshot('NeurosurgicalPlanning-LabelMapSeedingModule',
                            'Showing Tractography Label Seeding Module', -1)
        tractographyLabelSeeding = slicer.modules.tractographylabelmapseeding
        parameters = {}
        parameters['InputVolume'] = dtiVolume.GetID()
        baselinelabel293 = slicer.mrmlScene.GetFirstNodeByName(
            "BaselineVolume-region 1-label")
        # VTK6 TODO - set 'InputROIPipelineInfo'
        parameters['InputROI'] = baselinelabel293.GetID()
        fibers = slicer.vtkMRMLFiberBundleNode()
        slicer.mrmlScene.AddNode(fibers)
        parameters['OutputFibers'] = fibers.GetID()
        parameters['UseIndexSpace'] = 1
        parameters['StoppingValue'] = 0.15
        parameters['ROIlabel'] = 293
        parameters['StoppingMode'] = 'FractionalAnisotropy'
        # defaults
        # parameters['ClTh'] = 0.3
        # parameters['MinimumLength'] = 20
        # parameters['MaximumLength'] = 800
        # parameters['StoppingCurvature'] = 0.7
        # parameters['IntegrationStepLength'] = 0.5
        # parameters['SeedSpacing'] = 2
        # and run it
        slicer.cli.run(tractographyLabelSeeding, None, parameters)
        self.takeScreenshot('NeurosurgicalPlanning-LabelMapSeeding',
                            'Showing Tractography Label Seeding Results', -1)

        #
        # tractography fiducial seeding
        #
        moduleSelector.selectModule('TractographyInteractiveSeeding')
        self.takeScreenshot('NeurosurgicalPlanning-TIS',
                            'Showing Tractography Interactive Seeding Module',
                            -1)

        # DTI in background
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetBackgroundVolumeID(dtiVolume.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()

        # DTI visible in 3D
        sliceNode = sliceLogic.GetSliceNode()
        sliceLogic.StartSliceNodeInteraction(128)
        sliceNode.SetSliceVisible(1)
        sliceLogic.EndSliceNodeInteraction()

        self.takeScreenshot(
            'NeurosurgicalPlanning-TIS-DTI',
            'DTI volume with Tractography Interactive Seeding Module', -1)

        # place a fiducial
        displayNode = slicer.vtkMRMLMarkupsDisplayNode()
        slicer.mrmlScene.AddNode(displayNode)
        fidNode = slicer.vtkMRMLMarkupsFiducialNode()
        fidNode.SetName('F')
        slicer.mrmlScene.AddNode(fidNode)
        fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
        r = 28.338526
        a = 34.064367
        s = sliceOffset
        fidNode.AddFiducial(r, a, s)

        # make it active
        selectionNode = slicer.mrmlScene.GetNodeByID(
            "vtkMRMLSelectionNodeSingleton")
        if (selectionNode != None):
            selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

        self.takeScreenshot(
            'NeurosurgicalPlanning-TIS-Fid1',
            'Fiducial in Tractography Interactive Seeding Module', -1)

        # set up the arguments
        wr = slicer.modules.tractographyinteractiveseeding.widgetRepresentation(
        )
        wr.setDiffusionTensorVolumeNode(dtiVolume)
        # create a fiber bundle
        fiducialFibers = slicer.vtkMRMLFiberBundleNode()
        slicer.mrmlScene.AddNode(fiducialFibers)
        wr.setFiberBundleNode(fiducialFibers)
        wr.setSeedingNode(fidNode)
        wr.setMinimumPath(10)
        wr.setStoppingValue(0.15)

        self.takeScreenshot('NeurosurgicalPlanning-TIS-Args',
                            'Tractography Interactive Seeding arguments', -1)

        self.delayDisplay("Moving the fiducial")
        for y in range(-20, 100, 5):
            msg = "Moving the fiducial to y = " + str(y)
            self.delayDisplay(msg, 250)
            fidNode.SetNthFiducialPosition(0, r, y, s)

        self.takeScreenshot(
            'NeurosurgicalPlanning-TIS-Moved',
            'Moved fiducial and did Tractography Interactive Seeding', -1)

        return True
  def run(self):
    """
    Run the actual algorithm
    """
    print('Running test of the markups in different views')

    #
    # first load the data
    #
    import SampleData
    sampleDataLogic = SampleData.SampleDataLogic()
    print("Getting MR Head Volume")
    mrHeadVolume = sampleDataLogic.downloadMRHead()

    #
    # link the viewers
    #
    sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
    compositeNode = sliceLogic.GetSliceCompositeNode()
    compositeNode.SetLinkedControl(1)

    #
    # MR Head in the background
    #
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetBackgroundVolumeID(mrHeadVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()

    #
    # switch to conventional layout
    #
    lm = slicer.app.layoutManager()
    lm.setLayout(2)

    # create a fiducial list
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode = slicer.vtkMRMLMarkupsFiducialNode()
    slicer.mrmlScene.AddNode(fidNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

    # make it active
    selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
    if (selectionNode != None):
      selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

    # add some known points to it
    eye1 = [33.4975, 79.4042, -10.2143]
    eye2 = [-31.283, 80.9652, -16.2143]
    nose = [4.61944, 114.526, -33.2143]
    index = fidNode.AddFiducialFromArray(eye1)
    fidNode.SetNthFiducialLabel(index, "eye-1")
    index = fidNode.AddFiducialFromArray(eye2)
    fidNode.SetNthFiducialLabel(index, "eye-2")
    # hide the second eye as a test of visibility flags
    fidNode.SetNthFiducialVisibility(index, 0)
    index = fidNode.AddFiducialFromArray(nose)
    fidNode.SetNthFiducialLabel(index, "nose")

    self.logicDelayDisplay("Placed 3 fiducials")

    # self.printViewAndSliceNodes()

    if self.widgetVisible(fidNode, 'vtkMRMLViewNode1') == 0:
      self.logicDelayDisplay("Test failed: widget is not visible in view 1")
      # self.printViewNodeIDs(displayNode)
      return False

    #
    # switch to 2 3D views layout
    #
    lm.setLayout(15)
    self.logicDelayDisplay("Switched to 2 3D views")
    # self.printViewAndSliceNodes()

    if self.widgetVisible(fidNode, 'vtkMRMLViewNode1') == 0 or self.widgetVisible(fidNode, 'vtkMRMLViewNode2') == 0:
      self.logicDelayDisplay("Test failed: widget is not visible in view 1 and 2")
      # self.printViewNodeIDs(displayNode)
      return False

    #
    # show only in view 2
    #
    displayNode.AddViewNodeID("vtkMRMLViewNode2")
    self.logicDelayDisplay("Showing only in view 2")
    if self.widgetVisible(fidNode, 'vtkMRMLViewNode1') == 1:
      self.logicDelayDisplay("Test failed: widget is not supposed to be visible in view 1")
      # self.printViewNodeIDs(displayNode)
      return False
    if self.widgetVisible(fidNode, 'vtkMRMLViewNode2') == 0:
      self.logicDelayDisplay("Test failed: widget is not visible in view 2")
      # self.printViewNodeIDs(displayNode)
      return False

    #
    # remove it so show in all
    #
    displayNode.RemoveAllViewNodeIDs()
    self.logicDelayDisplay("Showing in both views")
    if self.widgetVisible(fidNode, 'vtkMRMLViewNode1') == 0 or self.widgetVisible(fidNode, 'vtkMRMLViewNode2') == 0:
      self.logicDelayDisplay("Test failed: widget is not visible in view 1 and 2")
      self.printViewNodeIDs(displayNode)
      return False

    #
    # show only in view 1
    #
    displayNode.AddViewNodeID("vtkMRMLViewNode1")
    self.logicDelayDisplay("Showing only in view 1")
    if self.widgetVisible(fidNode, 'vtkMRMLViewNode2') == 1:
      self.logicDelayDisplay("Test failed: widget is not supposed to be visible in view 2")
      # self.printViewNodeIDs(displayNode)
      return False
    if self.widgetVisible(fidNode, 'vtkMRMLViewNode1') == 0:
      self.logicDelayDisplay("Test failed: widget is not visible in view 1")
      # self.printViewNodeIDs(displayNode)
      return False

    # switch back to conventional
    lm.setLayout(2)
    self.logicDelayDisplay("Switched back to conventional layout")
    # self.printViewAndSliceNodes()

    # test of the visibility in slice views
    displayNode.RemoveAllViewNodeIDs()

    # jump to the last fiducial
    slicer.modules.markups.logic().JumpSlicesToNthPointInMarkup(fidNode.GetID(), index, 1)

    # show only in red
    displayNode.AddViewNodeID('vtkMRMLSliceNodeRed')
    self.logicDelayDisplay("Show only in red slice")
    if self.widgetVisibleOnSlice(fidNode,'vtkMRMLSliceNodeRed') != 1:
      self.logicDelayDisplay("Test failed: widget not displayed on red slice")
      # self.printViewNodeIDs(displayNode)
      return False

    # remove all, add green
    # print 'before remove all, after added red'
    # self.printViewNodeIDs(displayNode)
    displayNode.RemoveAllViewNodeIDs()
    # print 'after removed all'
    # self.printViewNodeIDs(displayNode)
    displayNode.AddViewNodeID('vtkMRMLSliceNodeGreen')
    self.logicDelayDisplay('Show only in green slice')
    if self.widgetVisibleOnSlice(fidNode,'vtkMRMLSliceNodeRed') != 0 or self.widgetVisibleOnSlice(fidNode,'vtkMRMLSliceNodeGreen') != 1:
      self.logicDelayDisplay("Test failed: widget not displayed only on green slice")
      print '\tred = ',self.widgetVisibleOnSlice(fidNode,'vtkMRMLSliceNodeRed')
      print '\tgreen =',self.widgetVisibleOnSlice(fidNode,'vtkMRMLSliceNodeGreen')
      self.printViewNodeIDs(displayNode)
      return False

    return True
    def run(self):
        """
    Run the actual algorithm
    """
        print("Running test of the markups in compare viewers")

        #
        # first load the data
        #
        import SampleData

        sampleDataLogic = SampleData.SampleDataLogic()
        print("Getting MR Head Volume")
        mrHeadVolume = sampleDataLogic.downloadMRHead()

        #
        # link the viewers
        #
        sliceLogic = slicer.app.layoutManager().sliceWidget("Red").sliceLogic()
        compositeNode = sliceLogic.GetSliceCompositeNode()
        compositeNode.SetLinkedControl(1)

        #
        # MR Head in the background
        #
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetBackgroundVolumeID(mrHeadVolume.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()

        #
        # switch to conventional layout
        #
        lm = slicer.app.layoutManager()
        lm.setLayout(2)

        # create a fiducial list
        displayNode = slicer.vtkMRMLMarkupsDisplayNode()
        slicer.mrmlScene.AddNode(displayNode)
        fidNode = slicer.vtkMRMLMarkupsFiducialNode()
        slicer.mrmlScene.AddNode(fidNode)
        fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

        # make it active
        selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
        if selectionNode != None:
            selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

        # add some known points to it
        eye1 = [33.4975, 79.4042, -10.2143]
        eye2 = [-31.283, 80.9652, -16.2143]
        nose = [4.61944, 114.526, -33.2143]
        index = fidNode.AddFiducialFromArray(eye1)
        fidNode.SetNthFiducialLabel(index, "eye-1")
        index = fidNode.AddFiducialFromArray(eye2)
        fidNode.SetNthFiducialLabel(index, "eye-2")
        index = fidNode.AddFiducialFromArray(nose)
        fidNode.SetNthFiducialLabel(index, "nose")

        self.logicDelayDisplay("Placed 3 fiducials")

        #
        # switch to 2 viewers compare layout
        #
        lm.setLayout(12)
        self.logicDelayDisplay("Switched to Compare 2 viewers")

        #
        # get compare slice composite node
        #
        compareLogic1 = slicer.app.layoutManager().sliceWidget("Compare1").sliceLogic()
        compareCompositeNode1 = compareLogic1.GetSliceCompositeNode()

        # set MRHead in the background
        compareLogic1.StartSliceCompositeNodeInteraction(1)
        compareCompositeNode1.SetBackgroundVolumeID(mrHeadVolume.GetID())
        compareLogic1.EndSliceCompositeNodeInteraction()
        compareLogic1.FitSliceToAll()
        # make it visible in 3D
        compareLogic1.GetSliceNode().SetSliceVisible(1)

        # scroll to a fiducial location
        compareLogic1.StartSliceOffsetInteraction()
        compareLogic1.SetSliceOffset(eye1[2])
        compareLogic1.EndSliceOffsetInteraction()
        self.logicDelayDisplay("MH Head in background, scrolled to a fiducial")

        # scroll around through the range of points
        offset = nose[2]
        while offset < eye1[2]:
            compareLogic1.StartSliceOffsetInteraction()
            compareLogic1.SetSliceOffset(offset)
            compareLogic1.EndSliceOffsetInteraction()
            msg = "Scrolled to " + str(offset)
            self.logicDelayDisplay(msg, 250)
            offset += 1.0

        # switch back to conventional
        lm.setLayout(2)
        self.logicDelayDisplay("Switched back to conventional layout")

        # switch to compare grid
        lm.setLayout(23)
        compareLogic1.FitSliceToAll()
        self.logicDelayDisplay("Switched to Compare grid")

        # switch back to conventional
        lm.setLayout(2)
        self.logicDelayDisplay("Switched back to conventional layout")

        return True
    def run(self):
        """
    Run the actual algorithm
    """
        print('Running test of the markups in compare viewers')

        #
        # first load the data
        #
        import SampleData
        sampleDataLogic = SampleData.SampleDataLogic()
        print("Getting MR Head Volume")
        mrHeadVolume = sampleDataLogic.downloadMRHead()

        #
        # link the viewers
        #
        sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
        compositeNode = sliceLogic.GetSliceCompositeNode()
        compositeNode.SetLinkedControl(1)

        #
        # MR Head in the background
        #
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetBackgroundVolumeID(mrHeadVolume.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()

        #
        # switch to conventional layout
        #
        lm = slicer.app.layoutManager()
        lm.setLayout(2)

        # create a fiducial list
        displayNode = slicer.vtkMRMLMarkupsDisplayNode()
        slicer.mrmlScene.AddNode(displayNode)
        fidNode = slicer.vtkMRMLMarkupsFiducialNode()
        slicer.mrmlScene.AddNode(fidNode)
        fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

        # make it active
        selectionNode = slicer.mrmlScene.GetNodeByID(
            "vtkMRMLSelectionNodeSingleton")
        if (selectionNode != None):
            selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

        # add some known points to it
        eye1 = [33.4975, 79.4042, -10.2143]
        eye2 = [-31.283, 80.9652, -16.2143]
        nose = [4.61944, 114.526, -33.2143]
        index = fidNode.AddFiducialFromArray(eye1)
        fidNode.SetNthFiducialLabel(index, "eye-1")
        index = fidNode.AddFiducialFromArray(eye2)
        fidNode.SetNthFiducialLabel(index, "eye-2")
        index = fidNode.AddFiducialFromArray(nose)
        fidNode.SetNthFiducialLabel(index, "nose")

        self.logicDelayDisplay("Placed 3 fiducials")

        #
        # switch to 2 viewers compare layout
        #
        lm.setLayout(12)
        self.logicDelayDisplay("Switched to Compare 2 viewers")

        #
        # get compare slice composite node
        #
        compareLogic1 = slicer.app.layoutManager().sliceWidget(
            'Compare1').sliceLogic()
        compareCompositeNode1 = compareLogic1.GetSliceCompositeNode()

        # set MRHead in the background
        compareLogic1.StartSliceCompositeNodeInteraction(1)
        compareCompositeNode1.SetBackgroundVolumeID(mrHeadVolume.GetID())
        compareLogic1.EndSliceCompositeNodeInteraction()
        compareLogic1.FitSliceToAll()
        # make it visible in 3D
        compareLogic1.GetSliceNode().SetSliceVisible(1)

        # scroll to a fiducial location
        compareLogic1.StartSliceOffsetInteraction()
        compareLogic1.SetSliceOffset(eye1[2])
        compareLogic1.EndSliceOffsetInteraction()
        self.logicDelayDisplay("MH Head in background, scrolled to a fiducial")

        # scroll around through the range of points
        offset = nose[2]
        while offset < eye1[2]:
            compareLogic1.StartSliceOffsetInteraction()
            compareLogic1.SetSliceOffset(offset)
            compareLogic1.EndSliceOffsetInteraction()
            msg = "Scrolled to " + str(offset)
            self.logicDelayDisplay(msg, 250)
            offset += 1.0

        # switch back to conventional
        lm.setLayout(2)
        self.logicDelayDisplay("Switched back to conventional layout")

        # switch to compare grid
        lm.setLayout(23)
        compareLogic1.FitSliceToAll()
        self.logicDelayDisplay("Switched to Compare grid")

        # switch back to conventional
        lm.setLayout(2)
        self.logicDelayDisplay("Switched back to conventional layout")

        return True
Beispiel #11
0
    def testSegmentationWizard(self):
        """ Test the ChangeTracker module
    """
        self.delayDisplay("Starting the test")

        try:

            self.delayDisplay("Loading sample data")

            import SampleData
            sampleDataLogic = SampleData.SampleDataLogic()
            head = sampleDataLogic.downloadMRHead()
            braintumor1 = sampleDataLogic.downloadMRBrainTumor1()
            braintumor2 = sampleDataLogic.downloadMRBrainTumor2()

            self.delayDisplay("Getting scene variables")

            mainWindow = slicer.util.mainWindow()
            layoutManager = slicer.app.layoutManager()
            threeDView = layoutManager.threeDWidget(0).threeDView()
            redWidget = layoutManager.sliceWidget('Red')
            redController = redWidget.sliceController()
            viewNode = threeDView.mrmlViewNode()
            cameras = slicer.util.getNodes('vtkMRMLCameraNode*')

            mainWindow.moduleSelector().selectModule('SegmentationWizard')
            modelsegmentation_module = slicer.modules.modelsegmentation.widgetRepresentation(
            ).self()

            self.delayDisplay('Select Volumes')
            baselineNode = braintumor1
            followupNode = braintumor2
            modelsegmentation_module.Step1._VolumeSelectStep__enableSubtractionMapping.setChecked(
                True)
            modelsegmentation_module.Step1._VolumeSelectStep__baselineVolumeSelector.setCurrentNode(
                baselineNode)
            modelsegmentation_module.Step1._VolumeSelectStep__followupVolumeSelector.setCurrentNode(
                followupNode)

            self.delayDisplay('Go Forward')
            modelsegmentation_module.workflow.goForward()

            self.delayDisplay('Register Images')
            modelsegmentation_module.Step2.onRegistrationRequest(
                wait_for_completion=True)

            self.delayDisplay('Go Forward')
            modelsegmentation_module.workflow.goForward()

            self.delayDisplay('Normalize Images')
            modelsegmentation_module.Step3.onGaussianNormalizationRequest()

            self.delayDisplay('Subtract Images')
            modelsegmentation_module.Step3.onSubtractionRequest(
                wait_for_completion=True)

            self.delayDisplay('Go Forward')
            modelsegmentation_module.workflow.goForward()

            self.delayDisplay('Load model')

            displayNode = slicer.vtkMRMLMarkupsDisplayNode()
            slicer.mrmlScene.AddNode(displayNode)
            inputMarkup = slicer.vtkMRMLMarkupsFiducialNode()
            inputMarkup.SetName('Test')
            slicer.mrmlScene.AddNode(inputMarkup)
            inputMarkup.SetAndObserveDisplayNodeID(displayNode.GetID())

            modelsegmentation_module.Step4._ROIStep__clippingMarkupSelector.setCurrentNode(
                inputMarkup)

            inputMarkup.AddFiducial(35, -10, -10)
            inputMarkup.AddFiducial(-15, 20, -10)
            inputMarkup.AddFiducial(-25, -25, -10)
            inputMarkup.AddFiducial(-5, -60, -15)
            inputMarkup.AddFiducial(-5, 5, 60)
            inputMarkup.AddFiducial(-5, -35, -30)

            self.delayDisplay('Go Forward')
            modelsegmentation_module.workflow.goForward()

            self.delayDisplay('Set Thresholds')
            modelsegmentation_module.Step5._ThresholdStep__threshRange.minimumValue = 50
            modelsegmentation_module.Step5._ThresholdStep__threshRange.maximumValue = 150

            self.delayDisplay('Go Forward')
            modelsegmentation_module.workflow.goForward()

            self.delayDisplay('Restart Module')
            modelsegmentation_module.Step6.Restart()

            self.delayDisplay('Test passed!')

        except Exception, e:
            import traceback
            traceback.print_exc()
            self.delayDisplay('Test caused exception!\n' + str(e))
  def run(self,enableScreenshots=0,screenshotScaleFactor=1):
    """
    Run the actual algorithm
    """
    self.delayDisplay('Running test of the Neurosurgical Planning tutorial')

    self.enableScreenshots = enableScreenshots
    self.screenshotScaleFactor = screenshotScaleFactor

    # conventional layout
    lm = slicer.app.layoutManager()
    lm.setLayout(2)

    moduleSelector = slicer.util.mainWindow().moduleSelector()
    #
    # first load the data
    #
    if self.enableScreenshots == 1:
      # for the tutorial, do it through the welcome module
      moduleSelector.selectModule('Welcome')
      self.delayDisplay("Screenshot")
      self.takeScreenshot('NeurosurgicalPlanning-Welcome','Welcome module',-1)
    else:
      # otherwise show the sample data module
      moduleSelector.selectModule('SampleData')

    # use the sample data module logic to load data for the self test
    import SampleData
    sampleDataLogic = SampleData.SampleDataLogic()

    self.delayDisplay("Getting Baseline volume")
    baselineVolume = sampleDataLogic.downloadWhiteMatterExplorationBaselineVolume()

    self.delayDisplay("Getting DTI volume")
    dtiVolume = sampleDataLogic.downloadWhiteMatterExplorationDTIVolume()

    self.takeScreenshot('NeurosurgicalPlanning-Loaded','Data loaded',-1)

    #
    # link the viewers
    #

    if self.enableScreenshots == 1:
      # for the tutorial, pop up the linking control
      sliceController = slicer.app.layoutManager().sliceWidget("Red").sliceController()
      popupWidget = sliceController.findChild("ctkPopupWidget")
      if popupWidget != None:
        popupWidget.pinPopup(1)
        self.takeScreenshot('NeurosurgicalPlanning-Link','Link slice viewers',-1)
        popupWidget.pinPopup(0)

    sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
    compositeNode = sliceLogic.GetSliceCompositeNode()
    compositeNode.SetLinkedControl(1)

    #
    # baseline in the background
    #
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetBackgroundVolumeID(baselineVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()

    self.takeScreenshot('NeurosurgicalPlanning-Baseline','Baseline in background',-1)

    #
    # adjust window level on baseline
    #
    moduleSelector.selectModule('Volumes')
    baselineDisplay = baselineVolume.GetDisplayNode()
    baselineDisplay.SetAutoWindowLevel(0)
    baselineDisplay.SetWindow(2600)
    baselineDisplay.SetLevel(1206)
    self.takeScreenshot('NeurosurgicalPlanning-WindowLevel','Set W/L on baseline',-1)

    #
    # switch to red slice only
    #
    lm.setLayout(6)
    self.takeScreenshot('NeurosurgicalPlanning-RedSliceOnly','Set layout to Red Slice only',-1)

    #
    # segmentation of tumour
    #

    #
    # create a label map and set it for editing
    #
    volumesLogic = slicer.modules.volumes.logic()
    baselineVolumeLabel =  volumesLogic.CreateAndAddLabelVolume( slicer.mrmlScene, baselineVolume, baselineVolume.GetName() + '-label' )
    baselineDisplayNode = baselineVolumeLabel.GetDisplayNode()
    baselineDisplayNode.SetAndObserveColorNodeID('vtkMRMLColorTableNodeFileGenericAnatomyColors.txt')
    selectionNode = slicer.app.applicationLogic().GetSelectionNode()
    selectionNode.SetReferenceActiveVolumeID(baselineVolume.GetID())
    selectionNode.SetReferenceActiveLabelVolumeID(baselineVolumeLabel.GetID())
    slicer.app.applicationLogic().PropagateVolumeSelection(0)

    #
    # editor module
    #
    moduleSelector.selectModule('Editor')
    self.takeScreenshot('NeurosurgicalPlanning-Editor','Showing Editor Module',-1)

    # set the slice offset so drawing is right
    sliceNode = sliceLogic.GetSliceNode()
    sliceOffset = 58.7
    sliceNode.SetSliceOffset(sliceOffset)

    #
    # paint
    #
    parameterNode = EditUtil.getParameterNode()
    paintEffect = EditorLib.PaintEffectOptions()
    paintEffect.setMRMLDefaults()
    paintEffect.__del__()
    sliceWidget = lm.sliceWidget('Red')
    paintTool = EditorLib.PaintEffectTool(sliceWidget)
    self.takeScreenshot('NeurosurgicalPlanning-Paint','Paint tool in Editor Module',-1)

    #
    # paint in cystic part of tumor, using converstion from RAS coords to
    # avoid slice widget size differences
    #
    EditUtil.setLabel(293)
    displayCoords = self.rasToDisplay(-7.4, 71, sliceOffset)
    paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    displayCoords = self.rasToDisplay(-11, 73, sliceOffset)
    paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    displayCoords = self.rasToDisplay(-12, 85, sliceOffset)
    paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    displayCoords = self.rasToDisplay(-13, 91, sliceOffset)
    paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    displayCoords = self.rasToDisplay(-15, 78, sliceOffset)
    paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    paintTool.paintApply()
    self.takeScreenshot('NeurosurgicalPlanning-PaintCystic','Paint cystic part of tumor',-1)

    #
    # paint in solid part of tumor
    #
    EditUtil.setLabel(7)
    displayCoords = self.rasToDisplay(-0.5 , 118.5, sliceOffset)
    paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    displayCoords = self.rasToDisplay(-7.4 , 116, sliceOffset)
    paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    paintTool.paintApply()
    self.takeScreenshot('NeurosurgicalPlanning-PaintSolid','Paint solid part of tumor',-1)

    #
    # paint around the tumor
    #
    EditUtil.setLabel(295)
    rMax = 25
    rMin = -50
    aMax = 145
    aMin = 50
    rasStep = 5

    # draw the top and bottom
    for r in range(rMin, rMax, rasStep):
      displayCoords = self.rasToDisplay(r, aMin, sliceOffset)
      paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
      displayCoords = self.rasToDisplay(r, aMax, sliceOffset)
      paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
    # draw the left and right
    for a in range(aMin, aMax, rasStep):
      displayCoords = self.rasToDisplay(rMin, a, sliceOffset)
      paintTool.paintAddPoint(displayCoords[0], displayCoords[1])
      displayCoords = self.rasToDisplay(rMax, a, sliceOffset)
      paintTool.paintAddPoint(displayCoords[0], displayCoords[1])

    paintTool.paintApply()

    self.takeScreenshot('NeurosurgicalPlanning-PaintAround','Paint around tumor',-1)
    #
    # clean up after painting
    #
    paintTool.cleanup()
    paintTool = None

    #
    # Grow cut
    #
    growCutLogic = EditorLib.GrowCutEffectLogic(sliceWidget.sliceLogic())
    growCutLogic.growCut()
    self.takeScreenshot('NeurosurgicalPlanning-Growcut','Growcut',-1)

    #
    # Merge split volume
    #
    slicer.util.selectModule('Editor')
    slicer.util.findChildren(text='Split Merge Volume')[0].clicked()
    self.takeScreenshot('NeurosurgicalPlanning-SplitMerge','SplitMerge',-1)

    #
    # go to the data module
    #
    moduleSelector.selectModule('Data')
    self.takeScreenshot('NeurosurgicalPlanning-SplitMergeData','SplitMerge results in Data',-1)

    #
    # Ventricles Segmentation
    #

    moduleSelector.selectModule('Editor')
    #
    # select the label volume with the area around the tumor
    slicer.util.findChildren(name='PerStructureVolumesFrame')[0].collapsed = False
    treeView = slicer.util.findChildren(name='StructuresView')[0]
    selection = qt.QItemSelection()
    # selecting the last split volume in the third row
    row = 2
    rowStart = treeView.model().index(row,0)
    rowEnd = treeView.model().index(row,treeView.model().columnCount() - 1)
    # rowSel = qt.QItemSelection(rowStart, rowEnd)
    selection.select(rowStart, rowEnd)
    # backup: select the label map in the slice logic too
    baselinelabel295 = slicer.mrmlScene.GetFirstNodeByName("BaselineVolume-region 3-label")
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetLabelVolumeID(baselinelabel295.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()
    self.takeScreenshot('NeurosurgicalPlanning-SelOutside','Select outside region',-1)

    #
    # Threshold tool
    #
    slicer.modules.EditorWidget.toolsBox.selectEffect('ThresholdEffect')
    parameterNode = EditUtil.getParameterNode()
    parameterNode.SetParameter('ThresholdEffect,min', str(1700))
    slicer.modules.EditorWidget.toolsBox.currentTools[0].apply()
    self.takeScreenshot('NeurosurgicalPlanning-Ventricles','Ventricles segmentation',-1)

    #
    # Save Islands
    #
    slicer.modules.EditorWidget.toolsBox.selectEffect('SaveIslandEffect')
    saveIslandLogic = EditorLib.SaveIslandEffectLogic(sliceWidget.sliceLogic())
    displayCoords = self.rasToDisplay(25.3, 5.8, sliceOffset)
    xy = (displayCoords[0], displayCoords[1])
    saveIslandLogic.saveIsland(xy)
    self.takeScreenshot('NeurosurgicalPlanning-SaveIsland','Ventricles save island',-1)

    #
    # Merge and build
    #
    slicer.util.findChildren(text='Merge And Build')[0].clicked()

    #
    # switch to conventional layout
    #
    lm.setLayout(2)
    self.takeScreenshot('NeurosurgicalPlanning-MergeAndBuild','Merged and built models',-1)

    #
    # Tractography label map seeding
    #

    #
    # select label volume with label 293, in the second row
    #
    row = 1
    rowStart = treeView.model().index(row,0)
    rowEnd = treeView.model().index(row,treeView.model().columnCount() - 1)
    # rowSel = qt.QItemSelection(rowStart, rowEnd)
    selection.select(rowStart, rowEnd)
    # backup: select the label map in the slice logic too
    baselinelabel293 = slicer.mrmlScene.GetFirstNodeByName("BaselineVolume-region 1-label")
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetLabelVolumeID(baselinelabel293.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()
    self.takeScreenshot('NeurosurgicalPlanning-SelCystic','Select cystic region',-1)

    #
    # Dilate
    #
    slicer.modules.EditorWidget.toolsBox.selectEffect('DilateEffect')
    EditUtil.setLabel(293)
    self.takeScreenshot('NeurosurgicalPlanning-Dilate','Dilate tool',-1)
    # tutorial says to click apply three times
    for d in range (1,3):
      print d
      # slicer.util.findChildren(name='DilateEffectOptionsApply')[0].clicked()
      # slicer.modules.EditorWidget.toolsBox.currentTools[0].apply()
      slicer.modules.EditorWidget.toolsBox.currentOption.onApply()
    self.takeScreenshot('NeurosurgicalPlanning-Dilated','Dilated tumor',-1)

    #
    # Tractography Label Map Seeding module
    #
    moduleSelector.selectModule('TractographyLabelMapSeeding')
    self.takeScreenshot('NeurosurgicalPlanning-LabelMapSeedingModule','Showing Tractography Label Seeding Module',-1)
    tractographyLabelSeeding = slicer.modules.tractographylabelmapseeding
    parameters = {}
    parameters['InputVolume'] = dtiVolume.GetID()
    baselinelabel293 = slicer.mrmlScene.GetFirstNodeByName("BaselineVolume-region 1-label")
# VTK6 TODO - set 'InputROIPipelineInfo'
    parameters['InputROI'] = baselinelabel293.GetID()
    fibers = slicer.vtkMRMLFiberBundleNode()
    slicer.mrmlScene.AddNode(fibers)
    parameters['OutputFibers'] = fibers.GetID()
    parameters['UseIndexSpace'] = 1
    parameters['StoppingValue'] = 0.15
    parameters['ROIlabel'] = 293
    parameters['StoppingMode'] = 'FractionalAnisotropy'
    # defaults
    # parameters['ClTh'] = 0.3
    # parameters['MinimumLength'] = 20
    # parameters['MaximumLength'] = 800
    # parameters['StoppingCurvature'] = 0.7
    # parameters['IntegrationStepLength'] = 0.5
    # parameters['SeedSpacing'] = 2
    # and run it
    slicer.cli.run(tractographyLabelSeeding, None, parameters)
    self.takeScreenshot('NeurosurgicalPlanning-LabelMapSeeding','Showing Tractography Label Seeding Results',-1)

    #
    # tractography fiducial seeding
    #
    moduleSelector.selectModule('TractographyInteractiveSeeding')
    self.takeScreenshot('NeurosurgicalPlanning-TIS','Showing Tractography Interactive Seeding Module',-1)

    # DTI in background
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetBackgroundVolumeID(dtiVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()

    # DTI visible in 3D
    sliceNode = sliceLogic.GetSliceNode()
    sliceLogic.StartSliceNodeInteraction(128)
    sliceNode.SetSliceVisible(1)
    sliceLogic.EndSliceNodeInteraction()

    self.takeScreenshot('NeurosurgicalPlanning-TIS-DTI','DTI volume with Tractography Interactive Seeding Module',-1)

    # place a fiducial
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode = slicer.vtkMRMLMarkupsFiducialNode()
    fidNode.SetName('F')
    slicer.mrmlScene.AddNode(fidNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
    r = 28.338526
    a = 34.064367
    s = sliceOffset
    fidNode.AddFiducial(r,a,s)

    # make it active
    selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
    if (selectionNode != None):
      selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

    self.takeScreenshot('NeurosurgicalPlanning-TIS-Fid1','Fiducial in Tractography Interactive Seeding Module',-1)


    # set up the arguments
    wr = slicer.modules.tractographyinteractiveseeding.widgetRepresentation()
    wr.setDiffusionTensorVolumeNode(dtiVolume)
    # create a fiber bundle
    fiducialFibers = slicer.vtkMRMLFiberBundleNode()
    slicer.mrmlScene.AddNode(fiducialFibers)
    wr.setFiberBundleNode(fiducialFibers)
    wr.setSeedingNode(fidNode)
    wr.setMinimumPath(10)
    wr.setStoppingValue(0.15)

    self.takeScreenshot('NeurosurgicalPlanning-TIS-Args','Tractography Interactive Seeding arguments',-1)

    self.delayDisplay("Moving the fiducial")
    for y in range(-20, 100, 5):
      msg = "Moving the fiducial to y = " + str(y)
      self.delayDisplay(msg,250)
      fidNode.SetNthFiducialPosition(0, r, y, s)

    self.takeScreenshot('NeurosurgicalPlanning-TIS-Moved','Moved fiducial and did Tractography Interactive Seeding',-1)

    return True
Beispiel #13
0
    def run(self):
        """
    Run the actual algorithm
    """
        print('Running test of the Neurosurgical Planning tutorial')

        #
        # first load the data
        #
        import SampleData
        sampleDataLogic = SampleData.SampleDataLogic()
        print("Getting Baseline volume")
        baselineVolume = sampleDataLogic.downloadWhiteMatterExplorationBaselineVolume(
        )

        print("Getting DTI volume")
        dtiVolume = sampleDataLogic.downloadWhiteMatterExplorationDTIVolume()

        #
        # link the viewers
        #
        sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
        compositeNode = sliceLogic.GetSliceCompositeNode()
        compositeNode.SetLinkedControl(1)

        #
        # baseline in the background
        #
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetBackgroundVolumeID(baselineVolume.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()

        #
        # adjust window level on baseline
        #
        mainWindow = slicer.util.mainWindow()
        mainWindow.moduleSelector().selectModule('Volumes')
        baselineVolume.GetDisplayNode().SetWindow(2600)
        baselineVolume.GetDisplayNode().SetLevel(1206)

        #
        # switch to red slice only
        #
        lm = slicer.app.layoutManager()
        lm.setLayout(6)

        #
        # skip segmentation of tumour
        #

        #
        # switch to conventional layout
        #
        lm.setLayout(2)

        #
        # skip tractography label map seeding
        #

        #
        # tractography fiducial seeding
        #
        mainWindow.moduleSelector().selectModule(
            'TractographyInteractiveSeeding')
        # DTI in background
        sliceLogic.StartSliceCompositeNodeInteraction(1)
        compositeNode.SetBackgroundVolumeID(dtiVolume.GetID())
        sliceLogic.EndSliceCompositeNodeInteraction()
        # place a fiducial
        displayNode = slicer.vtkMRMLMarkupsDisplayNode()
        slicer.mrmlScene.AddNode(displayNode)
        fidNode = slicer.vtkMRMLMarkupsFiducialNode()
        slicer.mrmlScene.AddNode(fidNode)
        fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
        r = 28.338526
        a = 34.064367
        s = 58.74121
        fidNode.AddFiducial(r, a, s)

        # make it active
        selectionNode = slicer.mrmlScene.GetNodeByID(
            "vtkMRMLSelectionNodeSingleton")
        if (selectionNode != None):
            selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

        # set up the arguments
        wr = slicer.modules.tractographyinteractiveseeding.widgetRepresentation(
        )
        wr.setDiffusionTensorVolumeNode(dtiVolume)
        # fiber bundle is created automatically
        wr.setSeedingNode(fidNode)
        wr.setMinimumPath(10)
        wr.setStoppingValue(0.15)

        print("Moving the fiducial")
        for y in range(-20, 100, 5):
            msg = "Moving the fiducial to y = " + str(y)
            print msg
            moveMsg = qt.QDialog()
            moveMsg.setLayout(qt.QVBoxLayout())
            moveMsg.layout().addWidget(qt.QLabel(msg))
            qt.QTimer.singleShot(250, moveMsg.close)
            moveMsg.exec_()
            fidNode.SetNthFiducialPosition(0, r, y, s)

        return True
 def readPlane(self):
     filename = qt.QFileDialog.getOpenFileName(parent=self,caption='Open file')
     print 'filename:', filename
     fichier2 = open(filename, 'r')
     fichier2.readline()
     NodeRed = slicer.mrmlScene.GetNodeByID('vtkMRMLSliceNodeRed')
     matRed = NodeRed.GetSliceToRAS()
     
     for i in range(0, 4):
         ligne = fichier2.readline()
         ligne = ligne.replace('[', '')
         ligne = ligne.replace('   ', ' ')
         ligne = ligne.replace(']', '')
         ligne = ligne.replace('\n', '')
         print ligne
         items = ligne.split()
         print items
         for j in range(0, 4):
             matRed.SetElement(i, j, float(items[j]))
     
     
     print matRed
     compare_red = 0
     for i in range(0,4):
         for j in range(0,4):
             if matRed.GetElement(i,j) == self.matRed_init[i,j]:
                 compare_red = compare_red + 1
     
     print compare_red
     
     if compare_red != 16:
         self.redslice = slicer.util.getNode('vtkMRMLSliceNodeRed')
         if self.red_plane_box.isChecked():
             self.red_plane_box.setChecked(False)
             self.redslice.SetWidgetVisible(False)
         self.red_plane_box.setChecked(True)
         self.redPlaneCheckBoxClicked()
     
     fichier2.readline()
     fichier2.readline()
     
     
     NodeGreen = slicer.mrmlScene.GetNodeByID('vtkMRMLSliceNodeGreen')
     matGreen = NodeGreen.GetSliceToRAS()
     for i in range (0,4):
         ligne = fichier2.readline()
         ligne = ligne.replace('[', '')
         ligne = ligne.replace('   ', ' ')
         ligne = ligne.replace(']', '')
         ligne = ligne.replace('\n', '')
         print ligne
         items = ligne.split()
         print items
         for j in range(0, 4):
             matGreen.SetElement(i, j, float(items[j]))
     
     
     print matGreen
     
     
     compare_green = 0
     for i in range(0,4):
         for j in range(0,4):
             if matGreen.GetElement(i,j) == self.matGreen_init[i,j]:
                 compare_green = compare_green + 1
     
     print compare_green
     
     if compare_green != 16:
         self.greenslice = slicer.util.getNode('vtkMRMLSliceNodeGreen')
         if self.green_plane_box.isChecked():
             self.green_plane_box.setChecked(False)
             self.greenslice.SetWidgetVisible(False)
         
         self.green_plane_box.setChecked(True)
         self.greenPlaneCheckBoxClicked()
     
     
     fichier2.readline()
     fichier2.readline()
     
     displayNode = slicer.vtkMRMLMarkupsDisplayNode()
     slicer.mrmlScene.AddNode(displayNode)
     fidNode = slicer.vtkMRMLMarkupsFiducialNode()
     slicer.mrmlScene.AddNode(fidNode)
     fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
     
     ligne = fichier2.readline()
     ligne = ligne.replace('[', '')
     ligne = ligne.replace('   ', ' ')
     ligne = ligne.replace(']', '')
     ligne = ligne.replace('\n', '')
     print ligne
     items = ligne.split()
     print items
     
     r = float(items[0])
     a = float(items[1])
     s = float(items[2])
     fidNode.AddFiducial(r,a,s)
     
     fichier2.readline()
     
     displayNode = slicer.vtkMRMLMarkupsDisplayNode()
     slicer.mrmlScene.AddNode(displayNode)
     fidNode = slicer.vtkMRMLMarkupsFiducialNode()
     slicer.mrmlScene.AddNode(fidNode)
     fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
     
     ligne = fichier2.readline()
     ligne = ligne.replace('[', '')
     ligne = ligne.replace('   ', ' ')
     ligne = ligne.replace(']', '')
     ligne = ligne.replace('\n', '')
     print ligne
     items = ligne.split()
     print items
     
     r = float(items[0])
     a = float(items[1])
     s = float(items[2])
     fidNode.AddFiducial(r,a,s)
     
     fichier2.readline()
     
     displayNode = slicer.vtkMRMLMarkupsDisplayNode()
     slicer.mrmlScene.AddNode(displayNode)
     fidNode = slicer.vtkMRMLMarkupsFiducialNode()
     slicer.mrmlScene.AddNode(fidNode)
     fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
     
     ligne = fichier2.readline()
     ligne = ligne.replace('[', '')
     ligne = ligne.replace('   ', ' ')
     ligne = ligne.replace(']', '')
     ligne = ligne.replace('\n', '')
     print ligne
     items = ligne.split()
     print items
     
     r = float(items[0])
     a = float(items[1])
     s = float(items[2])
     fidNode.AddFiducial(r,a,s)
     
     fichier2.close()
  def run(self,enableScreenshots=0,screenshotScaleFactor=1):
    """
    Run the actual algorithm
    """
    self.delayDisplay('Running test of the Neurosurgical Planning tutorial')

    moduleSelector = slicer.util.mainWindow().moduleSelector()
    #
    # first load the data
    #
    if enableScreenshots == 1:
      # for the tutorial, do it through the welcome module
      moduleSelector.selectModule('Welcome')
      self.delayDisplay("Screenshot")
      self.takeScreenshot('NeurosurgicalPlanning-Welcome','Welcome module',-1,screenshotScaleFactor)

    # but use the sample data module logic to load it for the self test
    import SampleData
    sampleDataLogic = SampleData.SampleDataLogic()
    self.delayDisplay("Getting Baseline volume")
    baselineVolume = sampleDataLogic.downloadWhiteMatterExplorationBaselineVolume()

    self.delayDisplay("Getting DTI volume")
    dtiVolume = sampleDataLogic.downloadWhiteMatterExplorationDTIVolume()

    if enableScreenshots == 1:
      self.delayDisplay("Screenshot")
      self.takeScreenshot('NeurosurgicalPlanning-Loaded','Data loaded',-1,screenshotScaleFactor)

    #
    # link the viewers
    #

    if enableScreenshots == 1:
      # for the tutorial, pop up the linking control
      # TODO: pipPopup is not exposed to python
      sliceController = slicer.app.layoutManager().sliceWidget("Red").sliceController()
      # sliceController.pinPopup(1)
      # self.delayDisplay("Screenshot")
      # self.takeScreenshot('NeurosurgicalPlanning-Link','Link slice viewers',-1,screenshotScaleFactor)
      # sliceController.pinPopup(0)

    sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
    compositeNode = sliceLogic.GetSliceCompositeNode()
    compositeNode.SetLinkedControl(1)

    #
    # baseline in the background
    #
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetBackgroundVolumeID(baselineVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()

    if enableScreenshots == 1:
      self.delayDisplay("Screenshot")
      self.takeScreenshot('NeurosurgicalPlanning-Baseline','Baseline in background',-1,screenshotScaleFactor)

    #
    # adjust window level on baseline
    #
    moduleSelector.selectModule('Volumes')
    baselineVolume.GetDisplayNode().SetWindow(2600)
    baselineVolume.GetDisplayNode().SetLevel(1206)
    if enableScreenshots == 1:
      self.delayDisplay("Screenshot")
      self.takeScreenshot('NeurosurgicalPlanning-WindowLevel','Set W/L on baseline',-1,screenshotScaleFactor)

    #
    # switch to red slice only
    #
    lm = slicer.app.layoutManager()
    lm.setLayout(6)
    if enableScreenshots == 1:
      self.delayDisplay("Screenshot")
      self.takeScreenshot('NeurosurgicalPlanning-RedSliceOnly','Set layout to Red Slice only',-1,screenshotScaleFactor)

    #
    # skip segmentation of tumour
    #

    #
    # switch to conventional layout
    #
    lm.setLayout(2)

    #
    # skip tractography label map seeding
    #


    #
    # tractography fiducial seeding
    #
    moduleSelector.selectModule('TractographyInteractiveSeeding')
    if enableScreenshots == 1:
     self.delayDisplay("Screenshot")
     self.takeScreenshot('NeurosurgicalPlanning-TIS','Showing Tractography Interactive Seeding Module',-1,screenshotScaleFactor)

    # DTI in background
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetBackgroundVolumeID(dtiVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()

    # DTI visible in 3D
    sliceNode = sliceLogic.GetSliceNode()
    sliceLogic.StartSliceNodeInteraction(128)
    sliceNode.SetSliceVisible(1)
    sliceLogic.EndSliceNodeInteraction()

    if enableScreenshots == 1:
     self.delayDisplay("Screenshot")
     self.takeScreenshot('NeurosurgicalPlanning-TIS-DTI','DTI volume with Tractography Interactive Seeding Module',-1,screenshotScaleFactor)

    # place a fiducial
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode = slicer.vtkMRMLMarkupsFiducialNode()
    fidNode.SetName('F')
    slicer.mrmlScene.AddNode(fidNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
    r = 28.338526
    a = 34.064367
    s = 58.74121
    fidNode.AddFiducial(r,a,s)

    # make it active
    selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
    if (selectionNode != None):
      selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

    if enableScreenshots == 1:
     self.delayDisplay("Screenshot")
     self.takeScreenshot('NeurosurgicalPlanning-TIS-Fid1','Fiducial in Tractography Interactive Seeding Module',-1,screenshotScaleFactor)


    # set up the arguments
    wr = slicer.modules.tractographyinteractiveseeding.widgetRepresentation()
    wr.setDiffusionTensorVolumeNode(dtiVolume)
    # fiber bundle is created automatically
    wr.setSeedingNode(fidNode)
    wr.setMinimumPath(10)
    wr.setStoppingValue(0.15)

    if enableScreenshots == 1:
     self.delayDisplay("Screenshot")
     self.takeScreenshot('NeurosurgicalPlanning-TIS-Args','Tractography Interactive Seeding arguments',-1,screenshotScaleFactor)

    self.delayDisplay("Moving the fiducial")
    for y in range(-20, 100, 5):
      msg = "Moving the fiducial to y = " + str(y)
      self.delayDisplay(msg,250)
      fidNode.SetNthFiducialPosition(0, r, y, s)

    if enableScreenshots == 1:
     self.delayDisplay("Screenshot")
     self.takeScreenshot('NeurosurgicalPlanning-TIS-Moved','Moved fiducial and did Tractography Interactive Seeding',-1,screenshotScaleFactor)

    return True
  def run(self):
    """
    Run the actual algorithm
    """
    print('Running test of the Neurosurgical Planning tutorial')

    #
    # first load the data
    #
    import SampleData
    sampleDataLogic = SampleData.SampleDataLogic()
    print("Getting Baseline volume")
    baselineVolume = sampleDataLogic.downloadWhiteMatterExplorationBaselineVolume()

    print("Getting DTI volume")
    dtiVolume = sampleDataLogic.downloadWhiteMatterExplorationDTIVolume()

    #
    # link the viewers
    #
    sliceLogic = slicer.app.layoutManager().sliceWidget('Red').sliceLogic()
    compositeNode = sliceLogic.GetSliceCompositeNode()
    compositeNode.SetLinkedControl(1)

    #
    # baseline in the background
    #
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetBackgroundVolumeID(baselineVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()

    #
    # adjust window level on baseline
    #
    mainWindow = slicer.util.mainWindow()
    mainWindow.moduleSelector().selectModule('Volumes')
    baselineVolume.GetDisplayNode().SetWindow(2600)
    baselineVolume.GetDisplayNode().SetLevel(1206)

    #
    # switch to red slice only
    #
    lm = slicer.app.layoutManager()
    lm.setLayout(6)

    #
    # skip segmentation of tumour
    #

    #
    # switch to conventional layout
    #
    lm.setLayout(2)

    #
    # skip tractography label map seeding
    #


    #
    # tractography fiducial seeding
    #
    mainWindow.moduleSelector().selectModule('TractographyInteractiveSeeding')
    # DTI in background
    sliceLogic.StartSliceCompositeNodeInteraction(1)
    compositeNode.SetBackgroundVolumeID(dtiVolume.GetID())
    sliceLogic.EndSliceCompositeNodeInteraction()
    # place a fiducial
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode = slicer.vtkMRMLMarkupsFiducialNode()
    slicer.mrmlScene.AddNode(fidNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())
    r = 28.338526
    a = 34.064367
    s = 58.74121
    fidNode.AddFiducial(r,a,s)

    # make it active
    selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
    if (selectionNode != None):
      selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())

    # set up the arguments
    wr = slicer.modules.tractographyinteractiveseeding.widgetRepresentation()
    wr.setDiffusionTensorVolumeNode(dtiVolume)
    # fiber bundle is created automatically
    wr.setSeedingNode(fidNode)
    wr.setMinimumPath(10)
    wr.setStoppingValue(0.15)

    print("Moving the fiducial")
    for y in range(-20, 100, 5):
      msg = "Moving the fiducial to y = " + str(y)
      print msg
      moveMsg = qt.QDialog()
      moveMsg.setLayout(qt.QVBoxLayout())
      moveMsg.layout().addWidget(qt.QLabel(msg))
      qt.QTimer.singleShot(250, moveMsg.close)
      moveMsg.exec_()
      fidNode.SetNthFiducialPosition(0, r, y, s)

    return True