コード例 #1
0
ファイル: IGTRecorderGUI.py プロジェクト: 151706061/Slicer3
 def __init__(self):
     ScriptedModuleGUI.__init__(self)
     self.vtkScriptedModuleGUI.SetCategory("IGT")
     self.TransformNodeSelector = slicer.vtkSlicerNodeSelectorWidget()
     self.StartStopButton = slicer.vtkKWPushButton()
     self.LabelMapSelector = slicer.vtkSlicerNodeSelectorWidget()
     self.LabelMapIJKToRAS = slicer.vtkMatrix4x4()
     self.LabelMapTransform = slicer.vtkMatrix4x4()
     self.ObservedTransform = 0
コード例 #2
0
def dispV0(dataD, inputVolume, shpV):
    scene = slicer.MRMLScene

    r1 = slicer.vtkMRMLScalarVolumeNode()
    r11 = slicer.vtkMRMLScalarVolumeDisplayNode()
    scene.AddNode(r11)

    r1.AddAndObserveDisplayNodeID(r11.GetName())

    imgD = slicer.vtkImageData()
    imgD.SetDimensions(shpV[0], shpV[1], shpV[2])
    imgD.SetScalarTypeToShort()

    org = inputVolume.GetOrigin()
    spa = inputVolume.GetSpacing()

    mat = slicer.vtkMatrix4x4()
    inputVolume.GetIJKToRASMatrix(mat)

    r1.SetAndObserveImageData(imgD)
    r1.SetIJKToRASMatrix(mat)
    r1.SetOrigin(org[0], org[1], org[2])
    r1.SetSpacing(spa[0], spa[1], spa[2])

    scene.AddNode(r1)

    tmp = r1.GetImageData().ToArray()
    tmp[:] = dataD[:]

    r1.GetDisplayNode().SetDefaultColorMap()
    r1.Modified()

    return
コード例 #3
0
def fiberGPFieldToMRMLScalarVN(fib, vn):
    from Slicer import slicer
    matrix = slicer.vtkMatrix4x4()
    matrix.SetElement(0, 0, 0)
    matrix.SetElement(1, 1, 0)
    matrix.SetElement(2, 2, 0)

    matrix.SetElement(0, 2, 2)
    matrix.SetElement(1, 1, 2)
    matrix.SetElement(2, 0, 2)

    matrix.SetElement(0, 3, fib[0][0, 0])
    matrix.SetElement(1, 3, fib[0][0, 1])
    matrix.SetElement(2, 3, fib[0][0, 2])
    matrix.Invert()

    vn.SetRASToIJKMatrix(matrix)

    id = vn.GetImageData()

    fb = fib[1]
    shape = fb.shape
    id.SetDimensions(shape[-1], shape[-2], shape[-3])
    id.SetNumberOfScalarComponents(1)
    id.AllocateScalars()

    id.ToArray()[:] = fb

    id.Modified()

    vn.Modified()
コード例 #4
0
def fiberGPFieldToMRMLScalarVN( fib, vn ):
  from Slicer import slicer
  matrix = slicer.vtkMatrix4x4()
  matrix.SetElement(0,0,0)
  matrix.SetElement(1,1,0)
  matrix.SetElement(2,2,0)

  matrix.SetElement(0,2,2)
  matrix.SetElement(1,1,2)
  matrix.SetElement(2,0,2)

  matrix.SetElement(0,3,fib[0][0,0])
  matrix.SetElement(1,3,fib[0][0,1])
  matrix.SetElement(2,3,fib[0][0,2])
  matrix.Invert()

  vn.SetRASToIJKMatrix(matrix)

  id = vn.GetImageData()

  fb = fib[1] 
  shape = fb.shape
  id.SetDimensions( shape[-1], shape[-2], shape[-3] )
  id.SetNumberOfScalarComponents(1)
  id.AllocateScalars()

  id.ToArray()[:] = fb

  id.Modified()

  vn.Modified()
コード例 #5
0
ファイル: dispV.py プロジェクト: 151706061/Slicer3
def dispV0(dataD, inputVolume, shpV):
    scene = slicer.MRMLScene

    r1 = slicer.vtkMRMLScalarVolumeNode()
    r11 = slicer.vtkMRMLScalarVolumeDisplayNode()
    scene.AddNode(r11)

    r1.AddAndObserveDisplayNodeID(r11.GetName())


    imgD = slicer.vtkImageData()
    imgD.SetDimensions(shpV[0], shpV[1], shpV[2])
    imgD.SetScalarTypeToShort()

    org = inputVolume.GetOrigin()
    spa = inputVolume.GetSpacing()

    mat = slicer.vtkMatrix4x4()
    inputVolume.GetIJKToRASMatrix(mat)

    r1.SetAndObserveImageData(imgD)
    r1.SetIJKToRASMatrix(mat)
    r1.SetOrigin(org[0], org[1], org[2])
    r1.SetSpacing(spa[0], spa[1], spa[2])

    scene.AddNode(r1)

    tmp = r1.GetImageData().ToArray()
    tmp[:] = dataD[:] 

    r1.GetDisplayNode().SetDefaultColorMap()
    r1.Modified()

    return
コード例 #6
0
ファイル: dispV.py プロジェクト: Surfndez/Slicer4
def dispW0(dataD, inputVolume, shpV, nvol):
    scene = slicer.MRMLScene

    r1 = slicer.vtkMRMLDiffusionWeightedVolumeNode()
    r11 = slicer.vtkMRMLDiffusionWeightedVolumeDisplayNode()
    scene.AddNode(r11)

    r1.AddAndObserveDisplayNodeID(r11.GetName())

    imgD = slicer.vtkImageData()
    imgD.SetDimensions(shpV[0], shpV[1], shpV[2])
    imgD.SetScalarTypeToShort()

    org = inputVolume.GetOrigin()
    spa = inputVolume.GetSpacing()

    mat = slicer.vtkMatrix4x4()
    inputVolume.GetIJKToRASMatrix(mat)

    r1.SetAndObserveImageData(imgD)
    r1.SetIJKToRASMatrix(mat)
    r1.SetOrigin(org[0], org[1], org[2])
    r1.SetSpacing(spa[0], spa[1], spa[2])

    scene.AddNode(r1)

    tmp = r1.GetImageData().ToArray()
    print 'tmp   : ', tmp.shape
    print 'dataD : ', dataD.shape
    tmp[...] = dataD[..., nvol]

    r1.GetDisplayNode().SetDefaultColorMap()
    r1.Modified()

    return
    def VolumeRendering(self, volumeNode, color, flipImage=0, cf=0):

        matrix = slicer.vtkMatrix4x4()

        image = volumeNode.GetImageData()
        volumeNode.GetIJKToRASMatrix(matrix)

        scalarRange = image.GetPointData().GetScalars().GetRange()

        if color == "red":  # initialization mode
            r = 0.8
            g = 0.0
            b = 0.0

            if flipImage:
                minV = 0
                maxV = scalarRange[1]
            else:
                minV = scalarRange[0]
                maxV = 0

            if cf:
                minV = scalarRange[0]
                maxV = -0.1

        elif color == "blue":  # evolution mode
            r = 1.0
            g = 1.0
            b = 0.0

            minV = -0.4
            maxV = 0.4

        self._parentClass.GetMyLogic().VolumeRendering(image, matrix, minV, maxV, [r, g, b])
コード例 #8
0
    def VolumeRendering(self, volumeNode, color, flipImage=0, cf=0):

        matrix = slicer.vtkMatrix4x4()

        image = volumeNode.GetImageData()
        volumeNode.GetIJKToRASMatrix(matrix)

        scalarRange = image.GetPointData().GetScalars().GetRange()

        if color == 'red':  # initialization mode
            r = 0.8
            g = 0.0
            b = 0.0

            if flipImage:
                minV = 0
                maxV = scalarRange[1]
            else:
                minV = scalarRange[0]
                maxV = 0

            if cf:
                minV = scalarRange[0]
                maxV = -0.1

        elif color == 'blue':  # evolution mode
            r = 1.0
            g = 1.0
            b = 0.0

            minV = -0.4
            maxV = 0.4

        self._parentClass.GetMyLogic().VolumeRendering(image, matrix, minV,
                                                       maxV, [r, g, b])
コード例 #9
0
    def ExecuteSeeds(self, inVolumeNode, sourceSeedsNode):

        self._helper.debug("Starting execution of seeds...")

        if not inVolumeNode or not sourceSeedsNode:
            slicer.Application.ErrorMessage(
                "Not enough information. Aborting Seeds..\n")
            return
        else:

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            seeds = sourceSeedsNode

            initialLevelSets = slicer.vtkImageData()
            initialLevelSets.DeepCopy(image)
            initialLevelSets.Update()

            levelSetsInputScalars = initialLevelSets.GetPointData().GetScalars(
            )
            levelSetsInputScalars.FillComponent(0, 1.0)

            for i in range(seeds.GetNumberOfFiducials()):
                rasPt = seeds.GetNthFiducialXYZ(i)
                ijkPt = self._helper.ConvertRAS2IJK(rasPt)
                id = image.ComputePointId(int(ijkPt[0]), int(ijkPt[1]),
                                          int(ijkPt[2]))
                levelSetsInputScalars.SetComponent(id, 0, -1.0)

            dilateErode = slicer.vtkImageDilateErode3D()
            dilateErode.SetInput(initialLevelSets)
            dilateErode.SetDilateValue(-1.0)
            dilateErode.SetErodeValue(1.0)
            dilateErode.SetKernelSize(3, 3, 3)
            dilateErode.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(dilateErode.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode, 0.0)

            self._helper.debug("Seeds done...")

            return outputContainer
    def ExecuteSeeds(self,inVolumeNode,sourceSeedsNode):


        self._helper.debug("Starting execution of seeds...")

        if not inVolumeNode or not sourceSeedsNode:
            slicer.Application.ErrorMessage("Not enough information. Aborting Seeds..\n")
            return
        else:

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            seeds = sourceSeedsNode
    
            initialLevelSets = slicer.vtkImageData()
            initialLevelSets.DeepCopy(image)
            initialLevelSets.Update()

            levelSetsInputScalars = initialLevelSets.GetPointData().GetScalars()
            levelSetsInputScalars.FillComponent(0,1.0)

            for i in range(seeds.GetNumberOfFiducials()):
                rasPt = seeds.GetNthFiducialXYZ(i)
                ijkPt = self._helper.ConvertRAS2IJK(rasPt)
                id = image.ComputePointId(int(ijkPt[0]),int(ijkPt[1]),int(ijkPt[2]))
                levelSetsInputScalars.SetComponent(id,0,-1.0)

            dilateErode = slicer.vtkImageDilateErode3D()
            dilateErode.SetInput(initialLevelSets)
            dilateErode.SetDilateValue(-1.0)
            dilateErode.SetErodeValue(1.0)
            dilateErode.SetKernelSize(3,3,3)
            dilateErode.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(dilateErode.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode,0.0)

            self._helper.debug("Seeds done...")

            return outputContainer
コード例 #11
0
    def Execute(self):
        SlicerVMTKAdvancedPageSkeleton.Execute(self)

        inVolume = self._parentClass._inVolumeSelector.GetSelected()
        outVolume = self._parentClass._outVolumeSelector.GetSelected()

        if not inVolume or not outVolume or not self.CheckForVmtkLibrary():
            slicer.Application.ErrorMessage(
                "No input volume or no output volume found. Aborting VED..\n")
            return
        else:

            sigmaMin = float(self._sigmaMin.GetWidget().GetValue())
            sigmaMax = float(self._sigmaMax.GetWidget().GetValue())
            numberOfSigmaSteps = int(self._numberOfSigmaSteps.GetValue())
            numberOfIterations = int(self._numberOfIterations.GetValue())
            numberOfDiffusionSubIterations = int(
                self._numberOfDiffusionSubIterations.GetValue())
            alpha = float(self._alpha.GetWidget().GetValue())
            beta = float(self._beta.GetWidget().GetValue())
            gamma = float(self._gamma.GetWidget().GetValue())
            c = float(self._c.GetWidget().GetValue())
            timestep = float(self._timestep.GetWidget().GetValue())
            epsilon = float(self._epsilon.GetWidget().GetValue())
            wstrength = float(self._wstrength.GetWidget().GetValue())
            sensitivity = float(self._sensitivity.GetWidget().GetValue())

            outVolumeImage = self._parentClass._logic.ApplyVED(
                inVolume.GetImageData(), sigmaMin, sigmaMax,
                numberOfSigmaSteps, alpha, beta, gamma, c, timestep, epsilon,
                wstrength, sensitivity, numberOfIterations,
                numberOfDiffusionSubIterations)

            matrix = slicer.vtkMatrix4x4()
            inVolume.GetIJKToRASMatrix(matrix)
            outVolume.SetAndObserveImageData(outVolumeImage)
            outVolume.SetIJKToRASMatrix(matrix)

            displayNode = inVolume.GetDisplayNode()
            if displayNode != None:
                newDisplayNode = displayNode.NewInstance()
                newDisplayNode.Copy(displayNode)
                slicer.MRMLScene.AddNodeNoNotify(newDisplayNode)
                outVolume.SetAndObserveDisplayNodeID(newDisplayNode.GetID())
                newDisplayNode.AutoWindowLevelOff()
                newDisplayNode.AutoWindowLevelOn()  # renew auto windowlevel

            appLogic = slicer.ApplicationLogic
            selectionNode = appLogic.GetSelectionNode()
            if inVolume.GetLabelMap():
                outVolume.SetLabelMap(1)
                selectionNode.SetReferenceActiveLabelVolumeID(
                    outVolume.GetID())
            else:
                selectionNode.SetReferenceActiveVolumeID(outVolume.GetID())
            appLogic.PropagateVolumeSelection()
コード例 #12
0
    def ExecuteCurves(self, origInVolumeNode, inVolumeNode, numberOfIterations,
                      propagationScaling, curvatureScaling, advectionScaling,
                      calculateFeatureImage):

        self._helper.debug("Starting execution of Curves..")

        if not inVolumeNode or not origInVolumeNode:
            slicer.Application.ErrorMessage(
                "Not enough information!!! Aborting Geodesic..\n")
            return
        else:

            cast = slicer.vtkImageCast()
            cast.SetInput(origInVolumeNode.GetImageData())
            cast.SetOutputScalarTypeToFloat()
            cast.Update()

            origImage = cast.GetOutput()
            image = inVolumeNode.GetImageData()

            levelSets = slicer.vtkvmtkCurvesLevelSetImageFilter()
            self._helper.debug("FeatureImageCalc: " +
                               str(calculateFeatureImage))
            if calculateFeatureImage == 1:
                levelSets.SetFeatureImage(
                    self.BuildGradientBasedFeatureImage(origImage))
            else:
                levelSets.SetFeatureImage(origImage)
            levelSets.SetDerivativeSigma(self.FeatureDerivativeSigma)
            levelSets.SetAutoGenerateSpeedAdvection(1)
            levelSets.SetPropagationScaling(propagationScaling)
            levelSets.SetCurvatureScaling(curvatureScaling)
            levelSets.SetAdvectionScaling(advectionScaling)

            levelSets.SetInput(image)
            levelSets.SetNumberOfIterations(numberOfIterations)
            levelSets.SetIsoSurfaceValue(self.IsoSurfaceValue)
            levelSets.SetMaximumRMSError(self.MaximumRMSError)
            levelSets.SetInterpolateSurfaceLocation(1)
            levelSets.SetUseImageSpacing(1)
            levelSets.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(levelSets.GetOutput())
            outVolumeData.Update()

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode, 0.0)

            return outputContainer
コード例 #13
0
    def GenerateEvolutionModel(self, resultContainer):

        matrix = slicer.vtkMatrix4x4()

        image = resultContainer.GetNode().GetImageData()

        resultContainer.GetNode().GetIJKToRASMatrix(matrix)
        threshold = 0.0

        polyData = slicer.vtkPolyData()

        if image.GetPointData().GetScalars():
            # marching Cubes, only if image has content
            polyData.DeepCopy(self._mainGUIClass.GetMyLogic().MarchingCubes(
                image, matrix, threshold))

        scene = self._mainGUIClass.GetLogic().GetMRMLScene()
        if self._mainGUIClass._outEvolModel == None:

            # no node so far
            self._mainGUIClass._outEvolModel = slicer.vtkMRMLModelNode()
            self._mainGUIClass._outEvolModel.SetName(
                "VMTK Level-Set Evolution Output Model")
            self._mainGUIClass._outEvolModel.SetAndObservePolyData(
                slicer.vtkPolyData())
            self._mainGUIClass._outEvolModel.SetScene(scene)
            scene.AddNode(self._mainGUIClass._outEvolModel)

            self._mainGUIClass._outEvolModelDisplay = slicer.vtkMRMLModelDisplayNode(
            )
            self._mainGUIClass._outEvolModelDisplay.SetColor(0.0, 0.0, 0.8)
            self._mainGUIClass._outEvolModelDisplay.SetPolyData(
                slicer.vtkPolyData())
            self._mainGUIClass._outEvolModelDisplay.SetVisibility(1)
            self._mainGUIClass._outEvolModelDisplay.SetOpacity(0.5)
            self._mainGUIClass._outEvolModelDisplay.SetSliceIntersectionVisibility(
                1)

        self._mainGUIClass._outEvolModel.SetAndObservePolyData(polyData)
        self._mainGUIClass._outEvolModel.SetModifiedSinceRead(1)
        self._mainGUIClass._outEvolModelDisplay.SetPolyData(
            self._mainGUIClass._outEvolModel.GetPolyData())
        self._mainGUIClass._outEvolModelDisplay.SetSliceIntersectionVisibility(
            1)
        self._mainGUIClass._outEvolModelDisplay.SetVisibility(1)
        self._mainGUIClass._outEvolModelDisplay.SetOpacity(0.5)
        scene.AddNode(self._mainGUIClass._outEvolModelDisplay)

        self._mainGUIClass._outEvolModel.SetAndObserveDisplayNodeID(
            self._mainGUIClass._outEvolModelDisplay.GetID())
        self._mainGUIClass._outEvolModelDisplay.SetSliceIntersectionVisibility(
            1)
        self._mainGUIClass._outEvolModelDisplay.SetVisibility(1)
        self._mainGUIClass._outEvolModelDisplay.SetOpacity(0.5)
    def ExecuteCurves(self,origInVolumeNode,inVolumeNode,numberOfIterations,propagationScaling,curvatureScaling,advectionScaling,calculateFeatureImage):

        self._helper.debug("Starting execution of Curves..")

        if not inVolumeNode or not origInVolumeNode:
            slicer.Application.ErrorMessage("Not enough information!!! Aborting Geodesic..\n")
            return
        else:

            cast = slicer.vtkImageCast()
            cast.SetInput(origInVolumeNode.GetImageData())
            cast.SetOutputScalarTypeToFloat()
            cast.Update()

            origImage = cast.GetOutput()
            image = inVolumeNode.GetImageData()

            levelSets = slicer.vtkvmtkCurvesLevelSetImageFilter()
            self._helper.debug("FeatureImageCalc: " + str(calculateFeatureImage))
            if calculateFeatureImage==1:
                levelSets.SetFeatureImage(self.BuildGradientBasedFeatureImage(origImage))
            else:
                levelSets.SetFeatureImage(origImage)
            levelSets.SetDerivativeSigma(self.FeatureDerivativeSigma)
            levelSets.SetAutoGenerateSpeedAdvection(1)
            levelSets.SetPropagationScaling(propagationScaling)
            levelSets.SetCurvatureScaling(curvatureScaling)
            levelSets.SetAdvectionScaling(advectionScaling)


            levelSets.SetInput(image)
            levelSets.SetNumberOfIterations(numberOfIterations)
            levelSets.SetIsoSurfaceValue(self.IsoSurfaceValue)
            levelSets.SetMaximumRMSError(self.MaximumRMSError)
            levelSets.SetInterpolateSurfaceLocation(1)
            levelSets.SetUseImageSpacing(1)
            levelSets.Update()


            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(levelSets.GetOutput())
            outVolumeData.Update()

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode,0.0)

            return outputContainer
    def SetAndMergeEvolVolume(self,resultContainer):

        scene = self._mainGUIClass.GetLogic().GetMRMLScene()

        volumeNode = resultContainer.GetNode()
        threshold = resultContainer.GetThreshold()

        if self._mainGUIClass._outEvolVolume == None:

            # no node so far

            self._mainGUIClass._outEvolVolume = slicer.vtkMRMLScalarVolumeNode()
            self._mainGUIClass._outEvolVolume.SetName("VMTK Level-Set Evolution Output Volume")
            self._mainGUIClass._outEvolVolume.SetScene(scene)
            self._mainGUIClass._outEvolVolume.SetAndObserveImageData(slicer.vtkImageData())
            scene.AddNode(self._mainGUIClass._outEvolVolume)

            self._mainGUIClass._outEvolVolumeLast = slicer.vtkMRMLScalarVolumeNode()
            self._mainGUIClass._outEvolVolumeLast.SetName("VMTK Level-Set Evolution Output Volume (Last Step)")
            self._mainGUIClass._outEvolVolumeLast.SetScene(scene)
            self._mainGUIClass._outEvolVolumeLast.SetAndObserveImageData(slicer.vtkImageData())
            scene.AddNode(self._mainGUIClass._outEvolVolumeLast)

        matrix = slicer.vtkMatrix4x4()

        # copy current outEvolVolume to outEvolVolumeLast
        self._mainGUIClass._outEvolVolumeLast.SetAndObserveImageData(self._mainGUIClass._outEvolVolume.GetImageData())
        self._mainGUIClass._outEvolVolume.GetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolumeLast.SetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolumeLast.SetModifiedSinceRead(1)

        volumeNodeData = volumeNode.GetImageData()

        # merge the oldVolume with volumeNode if oldVolume has already content
        if self._mainGUIClass._outEvolVolume.GetImageData().GetPointData().GetScalars():
            # evolVolumeLast has already content
            minFilter = slicer.vtkImageMathematics()
            minFilter.SetOperationToMin()
            minFilter.SetInput1(self._mainGUIClass._outEvolVolume.GetImageData()) #the old one
            minFilter.SetInput2(volumeNode.GetImageData()) #the new one
            minFilter.Update()
            volumeNodeData.DeepCopy(minFilter.GetOutput())

        # copy new volume to outEvolVolume
        volumeNode.GetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolume.SetAndObserveImageData(volumeNodeData)
        self._mainGUIClass._outEvolVolume.SetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolume.SetModifiedSinceRead(1)

        outputContainer = SlicerVMTKLevelSetContainer(self._mainGUIClass._outEvolVolume,threshold)

        return outputContainer
    def ExecuteThreshold(self,inVolumeNode,lowerThreshold,higherThreshold):


        self._helper.debug("Starting execution of Threshold...")


        if not inVolumeNode:
            slicer.Application.ErrorMessage("No input volume found. Aborting Threshold..\n")
            return
        else:

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            scalarRange = image.GetScalarRange()


            threshold = slicer.vtkImageThreshold()
            threshold.SetInput(image)

            threshold.ThresholdBetween(lowerThreshold,higherThreshold)

            threshold.ReplaceInOff()
            threshold.ReplaceOutOn()
            threshold.SetInValue(-1.0)
            threshold.SetOutValue(1.0)
            threshold.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(threshold.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode,0.0)

            self._helper.debug("Threshold done...")
    
            return outputContainer
コード例 #17
0
    def Execute(self):
        SlicerVMTKAdvancedPageSkeleton.Execute(self)

        inVolume =  self._parentClass._inVolumeSelector.GetSelected()
        outVolume = self._parentClass._outVolumeSelector.GetSelected()

        if not inVolume or not outVolume or not self.CheckForVmtkLibrary():
            slicer.Application.ErrorMessage("No input volume or no output volume found. Aborting Frangi..\n")
            return
        else:

            sigmaMin = float(self._sigmaMin.GetWidget().GetValue())
            sigmaMax = float(self._sigmaMax.GetWidget().GetValue())
            numberOfSigmaSteps =  int(self._numberOfSigmaSteps.GetValue())
            alpha = float(self._alpha.GetWidget().GetValue())
            beta = float(self._beta.GetWidget().GetValue())
            gamma = float(self._gamma.GetWidget().GetValue())

            imageData = slicer.vtkImageData()
            imageData.DeepCopy(inVolume.GetImageData())
            imageData.Update()
            if (self._sigmaUnit.GetWidget().GetWidget(0).GetSelectedState()==1):
                self._parentClass.debug("use mm!")
                imageData.SetSpacing(inVolume.GetSpacing()[0], inVolume.GetSpacing()[1], inVolume.GetSpacing()[2])


            outVolumeImage = self._parentClass._logic.ApplyFrangiVesselness(imageData,sigmaMin,sigmaMax,numberOfSigmaSteps,alpha,beta,gamma)
            outVolumeImage.SetSpacing(1,1,1)

            matrix = slicer.vtkMatrix4x4()
            inVolume.GetIJKToRASMatrix(matrix)
            outVolume.SetAndObserveImageData(outVolumeImage)
            outVolume.SetIJKToRASMatrix(matrix)

            displayNode = inVolume.GetDisplayNode()
            if displayNode != None:
              newDisplayNode = displayNode.NewInstance()
              newDisplayNode.Copy(displayNode)
              slicer.MRMLScene.AddNodeNoNotify(newDisplayNode);
              outVolume.SetAndObserveDisplayNodeID(newDisplayNode.GetID())
              newDisplayNode.AutoWindowLevelOff()
              newDisplayNode.AutoWindowLevelOn() # renew auto windowlevel

            appLogic = slicer.ApplicationLogic
            selectionNode = appLogic.GetSelectionNode()
            if inVolume.GetLabelMap():
              outVolume.SetLabelMap(1)
              selectionNode.SetReferenceActiveLabelVolumeID(outVolume.GetID())
            else:
              selectionNode.SetReferenceActiveVolumeID(outVolume.GetID())
            appLogic.PropagateVolumeSelection()
コード例 #18
0
def slicerMRMLVolumeNode2Image_ras2ijk(volumeNode):
    from Slicer import slicer
    from numpy import eye, ndindex

    vtk_ras2ijk = slicer.vtkMatrix4x4()
    volumeNode.GetRASToIJKMatrix(vtk_ras2ijk)

    image = volumeNode.GetImageData().ToArray().T

    ras2ijk = eye(4)
    for c in ndindex(ras2ijk.shape):
        ras2ijk[c] = vtk_ras2ijk.GetElement(c[0], c[1])

    return image, ras2ijk
コード例 #19
0
def slicerMRMLVolumeNode2Image_ras2ijk( volumeNode ):
  from Slicer import slicer
  from numpy import eye, ndindex

  vtk_ras2ijk = slicer.vtkMatrix4x4()
  volumeNode.GetRASToIJKMatrix( vtk_ras2ijk )

  image = volumeNode.GetImageData().ToArray().T

  ras2ijk = eye(4)
  for c in ndindex( ras2ijk.shape ):
    ras2ijk[c] = vtk_ras2ijk.GetElement( c[0], c[1] )

  return image, ras2ijk
コード例 #20
0
    def ExecuteThreshold(self, inVolumeNode, lowerThreshold, higherThreshold):

        self._helper.debug("Starting execution of Threshold...")

        if not inVolumeNode:
            slicer.Application.ErrorMessage(
                "No input volume found. Aborting Threshold..\n")
            return
        else:

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            scalarRange = image.GetScalarRange()

            threshold = slicer.vtkImageThreshold()
            threshold.SetInput(image)

            threshold.ThresholdBetween(lowerThreshold, higherThreshold)

            threshold.ReplaceInOff()
            threshold.ReplaceOutOn()
            threshold.SetInValue(-1.0)
            threshold.SetOutValue(1.0)
            threshold.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(threshold.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode, 0.0)

            self._helper.debug("Threshold done...")

            return outputContainer
    def ExecuteIsosurface(self,inVolumeNode,value):


        self._helper.debug("Starting execution of Isosurface...")

        if not inVolumeNode:
            slicer.Application.ErrorMessage("No input volume found. Aborting Isosurface..\n")
            return
        else:

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            imageMathematics = slicer.vtkImageMathematics()
            imageMathematics.SetInput(image)
            imageMathematics.SetConstantK(-1.0)
            imageMathematics.SetOperationToMultiplyByK()
            imageMathematics.Update()

            subtract = slicer.vtkImageMathematics()
            subtract.SetInput(imageMathematics.GetOutput())
            subtract.SetOperationToAddConstant()
            subtract.SetConstantC(value)
            subtract.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(subtract.GetOutput())

            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode,10)

            self._helper.debug("Isosurface done...")

            return outputContainer
コード例 #22
0
    def ExecuteIsosurface(self, inVolumeNode, value):

        self._helper.debug("Starting execution of Isosurface...")

        if not inVolumeNode:
            slicer.Application.ErrorMessage(
                "No input volume found. Aborting Isosurface..\n")
            return
        else:

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            imageMathematics = slicer.vtkImageMathematics()
            imageMathematics.SetInput(image)
            imageMathematics.SetConstantK(-1.0)
            imageMathematics.SetOperationToMultiplyByK()
            imageMathematics.Update()

            subtract = slicer.vtkImageMathematics()
            subtract.SetInput(imageMathematics.GetOutput())
            subtract.SetOperationToAddConstant()
            subtract.SetConstantC(value)
            subtract.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(subtract.GetOutput())

            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode, 10)

            self._helper.debug("Isosurface done...")

            return outputContainer
    def Execute(self):
        SlicerVMTKAdvancedPageSkeleton.Execute(self)

        inVolume =  self._parentClass._inVolumeSelector.GetSelected()
        outVolume = self._parentClass._outVolumeSelector.GetSelected()

        if not inVolume or not outVolume or not self.CheckForVmtkLibrary():
            slicer.Application.ErrorMessage("No input volume or no output volume found. Aborting VED..\n")
            return
        else:

            sigmaMin = float(self._sigmaMin.GetWidget().GetValue())
            sigmaMax = float(self._sigmaMax.GetWidget().GetValue())
            numberOfSigmaSteps =  int(self._numberOfSigmaSteps.GetValue())
            numberOfIterations =  int(self._numberOfIterations.GetValue())
            numberOfDiffusionSubIterations =  int(self._numberOfDiffusionSubIterations.GetValue())
            alpha = float(self._alpha.GetWidget().GetValue())
            beta = float(self._beta.GetWidget().GetValue())
            gamma = float(self._gamma.GetWidget().GetValue())
            c = float(self._c.GetWidget().GetValue())
            timestep = float(self._timestep.GetWidget().GetValue())
            epsilon = float(self._epsilon.GetWidget().GetValue())
            wstrength = float(self._wstrength.GetWidget().GetValue())
            sensitivity = float(self._sensitivity.GetWidget().GetValue())

            outVolumeImage = self._parentClass._logic.ApplyVED(inVolume.GetImageData(),sigmaMin,sigmaMax,numberOfSigmaSteps,alpha,beta,gamma,c,timestep,epsilon,wstrength,sensitivity,numberOfIterations,numberOfDiffusionSubIterations)

            matrix = slicer.vtkMatrix4x4()
            inVolume.GetIJKToRASMatrix(matrix)
            outVolume.SetAndObserveImageData(outVolumeImage)
            outVolume.SetIJKToRASMatrix(matrix)

            displayNode = inVolume.GetDisplayNode()
            if displayNode != None:
              newDisplayNode = displayNode.NewInstance()
              newDisplayNode.Copy(displayNode)
              slicer.MRMLScene.AddNodeNoNotify(newDisplayNode);
              outVolume.SetAndObserveDisplayNodeID(newDisplayNode.GetID())
              newDisplayNode.AutoWindowLevelOff()
              newDisplayNode.AutoWindowLevelOn() # renew auto windowlevel

            appLogic = slicer.ApplicationLogic
            selectionNode = appLogic.GetSelectionNode()
            if inVolume.GetLabelMap():
              outVolume.SetLabelMap(1)
              selectionNode.SetReferenceActiveLabelVolumeID(outVolume.GetID())
            else:
              selectionNode.SetReferenceActiveVolumeID(outVolume.GetID())
            appLogic.PropagateVolumeSelection()
    def UndoEvol(self):

        # copy outEvolVolumeLast to outEvolVolume

        matrix = slicer.vtkMatrix4x4()
        self._mainGUIClass._outEvolVolumeLast.GetIJKToRASMatrix(matrix)

        self._mainGUIClass._outEvolVolume.SetAndObserveImageData(self._mainGUIClass._outEvolVolumeLast.GetImageData())
        self._mainGUIClass._outEvolVolume.SetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolume.SetModifiedSinceRead(1)


        outputContainer = SlicerVMTKLevelSetContainer(self._mainGUIClass._outEvolVolume,0.0)

        return outputContainer
コード例 #25
0
    def UndoEvol(self):

        # copy outEvolVolumeLast to outEvolVolume

        matrix = slicer.vtkMatrix4x4()
        self._mainGUIClass._outEvolVolumeLast.GetIJKToRASMatrix(matrix)

        self._mainGUIClass._outEvolVolume.SetAndObserveImageData(
            self._mainGUIClass._outEvolVolumeLast.GetImageData())
        self._mainGUIClass._outEvolVolume.SetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolume.SetModifiedSinceRead(1)

        outputContainer = SlicerVMTKLevelSetContainer(
            self._mainGUIClass._outEvolVolume, 0.0)

        return outputContainer
コード例 #26
0
    def ConvertCoordinates2IJK(self, which, coordinates):
        #need RAS
        rasPt = self.ConvertCoordinates2RAS(which, coordinates)

        #convert to IJK
        node = self._mainGUIClass.GetScriptedModuleNode()
        if node:
            inVolume = node.GetParameter('InputVolumeRef')
            if not inVolume:
                slicer.Application.ErrorMessage("No input volume found\n")
                return
            else:
                matrixIJK = slicer.vtkMatrix4x4()
                inVolume.GetRASToIJKMatrix(matrixIJK)
                ijkPt = matrixIJK.MultiplyPoint(*rasPt)
                return ijkPt
    def ConvertCoordinates2IJK(self,which,coordinates):
        #need RAS
        rasPt = self.ConvertCoordinates2RAS(which,coordinates)

        #convert to IJK
        node = self._mainGUIClass.GetScriptedModuleNode()
        if node:
            inVolume = node.GetParameter('InputVolumeRef')
            if not inVolume:
                slicer.Application.ErrorMessage("No input volume found\n")
                return
            else:
                matrixIJK = slicer.vtkMatrix4x4()
                inVolume.GetRASToIJKMatrix(matrixIJK)
                ijkPt = matrixIJK.MultiplyPoint(*rasPt)
                return ijkPt
コード例 #28
0
    def GenerateModel(self, volumeNode, color):

        if color == 'red':
            r = 0.8
            g = 0.0
            b = 0.0
            name = "VMTK Initialization Model"
            registerModel = 1
        elif color == 'blue':
            r = 1.0
            g = 1.0
            b = 0.0
            name = "VMTK Evolution Model"
            registerModel = 0

        matrix = slicer.vtkMatrix4x4()

        image = volumeNode.GetImageData()
        volumeNode.GetIJKToRASMatrix(matrix)

        polyData = slicer.vtkPolyData()

        if image.GetPointData().GetScalars():
            # marching Cubes, only if image has content
            polyData.DeepCopy(self._parentClass.GetMyLogic().MarchingCubes(
                image, matrix, 0.0))
        scene = self._parentClass.GetLogic().GetMRMLScene()

        newModel = slicer.vtkMRMLModelNode()
        newModel.SetName(name)
        newModel.SetScene(scene)
        newModel.SetAndObservePolyData(polyData)
        scene.AddNode(newModel)

        newModelDisplay = slicer.vtkMRMLModelDisplayNode()
        newModelDisplay.SetPolyData(newModel.GetPolyData())
        newModelDisplay.SetColor(r, g, b)
        newModelDisplay.SetBackfaceCulling(0)
        newModelDisplay.SetSliceIntersectionVisibility(1)
        newModelDisplay.SetVisibility(1)
        newModelDisplay.SetOpacity(1.0)
        scene.AddNode(newModelDisplay)

        newModel.SetAndObserveDisplayNodeID(newModelDisplay.GetID())

        if registerModel:
            self._parentClass.SetOutInitModelDisplay(newModelDisplay)
    def GenerateModel(self, volumeNode, color):

        if color == "red":
            r = 0.8
            g = 0.0
            b = 0.0
            name = "VMTK Initialization Model"
            registerModel = 1
        elif color == "blue":
            r = 1.0
            g = 1.0
            b = 0.0
            name = "VMTK Evolution Model"
            registerModel = 0

        matrix = slicer.vtkMatrix4x4()

        image = volumeNode.GetImageData()
        volumeNode.GetIJKToRASMatrix(matrix)

        polyData = slicer.vtkPolyData()

        if image.GetPointData().GetScalars():
            # marching Cubes, only if image has content
            polyData.DeepCopy(self._parentClass.GetMyLogic().MarchingCubes(image, matrix, 0.0))
        scene = self._parentClass.GetLogic().GetMRMLScene()

        newModel = slicer.vtkMRMLModelNode()
        newModel.SetName(name)
        newModel.SetScene(scene)
        newModel.SetAndObservePolyData(polyData)
        scene.AddNode(newModel)

        newModelDisplay = slicer.vtkMRMLModelDisplayNode()
        newModelDisplay.SetPolyData(newModel.GetPolyData())
        newModelDisplay.SetColor(r, g, b)
        newModelDisplay.SetBackfaceCulling(0)
        newModelDisplay.SetSliceIntersectionVisibility(1)
        newModelDisplay.SetVisibility(1)
        newModelDisplay.SetOpacity(1.0)
        scene.AddNode(newModelDisplay)

        newModel.SetAndObserveDisplayNodeID(newModelDisplay.GetID())

        if registerModel:
            self._parentClass.SetOutInitModelDisplay(newModelDisplay)
    def GenerateEvolutionModel(self,resultContainer):

        matrix = slicer.vtkMatrix4x4()

        image = resultContainer.GetNode().GetImageData()

        resultContainer.GetNode().GetIJKToRASMatrix(matrix)
        threshold = 0.0

        polyData = slicer.vtkPolyData()

        if image.GetPointData().GetScalars():
            # marching Cubes, only if image has content
            polyData.DeepCopy(self._mainGUIClass.GetMyLogic().MarchingCubes(image,matrix,threshold))

        scene = self._mainGUIClass.GetLogic().GetMRMLScene()
        if self._mainGUIClass._outEvolModel == None:

            # no node so far
            self._mainGUIClass._outEvolModel = slicer.vtkMRMLModelNode()
            self._mainGUIClass._outEvolModel.SetName("VMTK Level-Set Evolution Output Model")
            self._mainGUIClass._outEvolModel.SetAndObservePolyData(slicer.vtkPolyData())
            self._mainGUIClass._outEvolModel.SetScene(scene)
            scene.AddNode(self._mainGUIClass._outEvolModel)

            self._mainGUIClass._outEvolModelDisplay = slicer.vtkMRMLModelDisplayNode()
            self._mainGUIClass._outEvolModelDisplay.SetColor(0.0, 0.0, 0.8)
            self._mainGUIClass._outEvolModelDisplay.SetPolyData(slicer.vtkPolyData())
            self._mainGUIClass._outEvolModelDisplay.SetVisibility(1)
            self._mainGUIClass._outEvolModelDisplay.SetOpacity(0.5)
            self._mainGUIClass._outEvolModelDisplay.SetSliceIntersectionVisibility(1)


        self._mainGUIClass._outEvolModel.SetAndObservePolyData(polyData)
        self._mainGUIClass._outEvolModel.SetModifiedSinceRead(1)
        self._mainGUIClass._outEvolModelDisplay.SetPolyData(self._mainGUIClass._outEvolModel.GetPolyData())
        self._mainGUIClass._outEvolModelDisplay.SetSliceIntersectionVisibility(1)
        self._mainGUIClass._outEvolModelDisplay.SetVisibility(1)
        self._mainGUIClass._outEvolModelDisplay.SetOpacity(0.5)
        scene.AddNode(self._mainGUIClass._outEvolModelDisplay)

        self._mainGUIClass._outEvolModel.SetAndObserveDisplayNodeID(self._mainGUIClass._outEvolModelDisplay.GetID())
        self._mainGUIClass._outEvolModelDisplay.SetSliceIntersectionVisibility(1)
        self._mainGUIClass._outEvolModelDisplay.SetVisibility(1)
        self._mainGUIClass._outEvolModelDisplay.SetOpacity(0.5)
コード例 #31
0
ファイル: dispV.py プロジェクト: Surfndez/Slicer4
def dispS(dataD, inputVolume, shpV):
    scene = slicer.MRMLScene

    r1 = slicer.vtkMRMLScalarVolumeNode()
    r11 = slicer.vtkMRMLScalarVolumeDisplayNode()
    r11.ScalarVisibilityOn()
    r11.SetScalarRange(dataD.min(), dataD.max())
    scene.AddNode(r11)

    r1.AddAndObserveDisplayNodeID(r11.GetName())

    imgD = slicer.vtkImageData()
    imgD.SetDimensions(shpV[0], shpV[1], shpV[2])
    imgD.SetNumberOfScalarComponents(1)
    imgD.SetScalarTypeToDouble()
    imgD.AllocateScalars()

    org = inputVolume.GetOrigin()
    spa = inputVolume.GetSpacing()

    mat = slicer.vtkMatrix4x4()
    inputVolume.GetIJKToRASMatrix(mat)

    r1.SetAndObserveImageData(imgD)
    r1.SetIJKToRASMatrix(mat)
    r1.SetOrigin(org[0], org[1], org[2])
    r1.SetSpacing(spa[0], spa[1], spa[2])

    scene.AddNode(r1)

    tmp = r1.GetImageData().GetPointData().GetScalars().ToArray()
    print 'tmp   : ', tmp.shape
    print 'dataD : ', dataD.shape
    dataD = reshape(dataD, (shpV[0] * shpV[1] * shpV[2], 1))
    tmp[:] = dataD[:]

    r1.GetDisplayNode().SetDefaultColorMap()
    r1.Modified()

    return
コード例 #32
0
ファイル: dispV.py プロジェクト: 151706061/Slicer3
def dispS(dataD, inputVolume, shpV):
    scene = slicer.MRMLScene

    r1 = slicer.vtkMRMLScalarVolumeNode()
    r11 = slicer.vtkMRMLScalarVolumeDisplayNode()
    r11.ScalarVisibilityOn()
    r11.SetScalarRange(dataD.min(), dataD.max())
    scene.AddNode(r11)

    r1.AddAndObserveDisplayNodeID(r11.GetName())

    imgD = slicer.vtkImageData()
    imgD.SetDimensions(shpV[0], shpV[1], shpV[2])
    imgD.SetNumberOfScalarComponents(1)
    imgD.SetScalarTypeToDouble()
    imgD.AllocateScalars()

    org = inputVolume.GetOrigin()
    spa = inputVolume.GetSpacing()

    mat = slicer.vtkMatrix4x4()
    inputVolume.GetIJKToRASMatrix(mat)

    r1.SetAndObserveImageData(imgD)
    r1.SetIJKToRASMatrix(mat)
    r1.SetOrigin(org[0], org[1], org[2])
    r1.SetSpacing(spa[0], spa[1], spa[2])

    scene.AddNode(r1)

    tmp = r1.GetImageData().GetPointData().GetScalars().ToArray()
    print 'tmp   : ', tmp.shape
    print 'dataD : ', dataD.shape
    dataD = reshape(dataD, (shpV[0]*shpV[1]*shpV[2], 1))
    tmp[:] = dataD[:]

    r1.GetDisplayNode().SetDefaultColorMap()
    r1.Modified()

    return
コード例 #33
0
ファイル: dispV.py プロジェクト: 151706061/Slicer3
def dispW0(dataD, inputVolume, shpV, nvol):
    scene = slicer.MRMLScene

    r1 = slicer.vtkMRMLDiffusionWeightedVolumeNode()
    r11 = slicer.vtkMRMLDiffusionWeightedVolumeDisplayNode()
    scene.AddNode(r11)

    r1.AddAndObserveDisplayNodeID(r11.GetName())


    imgD = slicer.vtkImageData()
    imgD.SetDimensions(shpV[0], shpV[1], shpV[2])
    imgD.SetScalarTypeToShort()

    org = inputVolume.GetOrigin()
    spa = inputVolume.GetSpacing()

    mat = slicer.vtkMatrix4x4()
    inputVolume.GetIJKToRASMatrix(mat)

    r1.SetAndObserveImageData(imgD)
    r1.SetIJKToRASMatrix(mat)
    r1.SetOrigin(org[0], org[1], org[2])
    r1.SetSpacing(spa[0], spa[1], spa[2])

    scene.AddNode(r1)

    tmp = r1.GetImageData().ToArray()
    print 'tmp   : ', tmp.shape
    print 'dataD : ', dataD.shape
    tmp[...] = dataD[..., nvol] 

    r1.GetDisplayNode().SetDefaultColorMap()
    r1.Modified()

    return
    def GAC(self):

        origVolume = self._inVolumeSelector.GetSelected()            
        segmentationVolume = self._outVolumeSelector.GetSelected()      
        outVolume = self._outEvolVolumeSelector.GetSelected() 
        seeds = self._seedsSelector.GetSelected()
        targetSeeds = self._targetSeedsSelector.GetSelected()

        vmtkFound = self.CheckForVmtkLibrary()

        if origVolume and segmentationVolume and outVolume and vmtkFound:

            numberOfIterations = int(self._iterationsSpinbox.GetWidget().GetValue())
            propagationScaling = self._propagationScale.GetValue()
            curvatureScaling = self._curvatureScale.GetValue()
            advectionScaling = self._advectionScale.GetValue()

            if (self._evolMethod.GetWidget().GetWidget(0).GetSelectedState()==1):
                result = self._logic.ExecuteGAC(origVolume.GetImageData(),segmentationVolume.GetImageData(),numberOfIterations,propagationScaling,curvatureScaling,advectionScaling,'geodesic')
            else:
                result = self._logic.ExecuteGAC(origVolume.GetImageData(),segmentationVolume.GetImageData(),numberOfIterations,propagationScaling,curvatureScaling,advectionScaling,'curves')

            ijkToRasMatrix = slicer.vtkMatrix4x4()
            origVolume.GetIJKToRASMatrix(ijkToRasMatrix)

            #outVolume.LabelMapOn()
            outVolume.SetAndObserveImageData(result)
            outVolume.SetIJKToRASMatrix(ijkToRasMatrix)
            outVolume.SetModifiedSinceRead(1)

            inValue = 0
            outValue = 5

            if seeds and targetSeeds:                
                if targetSeeds.GetID()!=seeds.GetID():
                    # switch thresholds for labelmap when using target points
                    inValue = 5
                    outValue = 0

            scene = self.GetLogic().GetMRMLScene()

            newDisplayNode = slicer.vtkMRMLLabelMapVolumeDisplayNode()
            newDisplayNode.SetScene(scene)
            newDisplayNode.SetDefaultColorMap()
            slicer.MRMLScene.AddNodeNoNotify(newDisplayNode)

            labelMap = slicer.vtkMRMLScalarVolumeNode()
            labelMap.SetName("VMTKEvolutionLabelMap")
            labelMap.SetAndObserveImageData(self._logic.BuildSimpleLabelMap(result,inValue,outValue))
            labelMap.SetIJKToRASMatrix(ijkToRasMatrix)
            labelMap.LabelMapOn()
            labelMap.SetAndObserveDisplayNodeID(newDisplayNode.GetID())
            scene.AddNode(labelMap)

            slicer.ApplicationLogic.GetSelectionNode().SetReferenceActiveLabelVolumeID(labelMap.GetID())
            slicer.ApplicationLogic.GetSelectionNode().SetReferenceActiveVolumeID(origVolume.GetID())
            slicer.ApplicationLogic.PropagateVolumeSelection()

            #slicer.ApplicationLogic.GetSelectionNode().SetReferenceActiveLabelVolumeID(outVolume.GetID())
            #slicer.ApplicationLogic.PropagateVolumeSelection()

            if self._outInitModelDisplay != None: # deactivate old init model if it exists
                #nodeId = self.GetLogic().GetMRMLScene().GetNodeByID(self._outInitModelDisplay.GetID())
                #if nodeId:
                    #if self.GetLogic().GetMRMLScene().IsNodePresent(nodeId):
                        self._helper.debug("hiding old model..")
                        self._outInitModelDisplay.SetVisibility(0)
                        self._outInitModelDisplay.SetModifiedSinceRead(1)

            if self._vrCheckButton.GetSelectedState():
                self._helper.HideVR()
                if targetSeeds:
                    self._helper.VolumeRendering(outVolume,'blue',targetSeeds.GetID()==seeds.GetID())
                else:
                    self._helper.VolumeRendering(outVolume,'blue',1)
                #self._helper.VolumeRendering(outVolume,'blue')
                self._helper.ShowVR()
            else:
                self._helper.HideVR()
                self._helper.GenerateModel(outVolume,'blue')
コード例 #35
0
    def ExecuteCollidingFronts(self, inVolumeNode, lowerThreshold,
                               higherThreshold, sourceSeedsNode,
                               targetSeedsNode):

        self._helper.debug("Starting execution of Colliding Fronts..")

        if not inVolumeNode or not sourceSeedsNode or not targetSeedsNode:
            self._helper.debug(inVolumeNode)
            self._helper.debug(lowerThreshold)
            self._helper.debug(higherThreshold)
            self._helper.debug(sourceSeedsNode)
            self._helper.debug(targetSeedsNode)
            slicer.Application.ErrorMessage(
                "Not enough information!!! Aborting Colliding Fronts..\n")
            return
        else:

            sourceSeedIds = slicer.vtkIdList()
            targetSeedIds = slicer.vtkIdList()

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            rasPt = sourceSeedsNode.GetNthFiducialXYZ(0)
            self._helper.debug(rasPt)
            ijkPt = self._helper.ConvertRAS2IJK(rasPt)
            self._helper.debug(ijkPt)
            sourceSeedIds.InsertNextId(
                image.ComputePointId(int(ijkPt[0]), int(ijkPt[1]),
                                     int(ijkPt[2])))

            rasPt = targetSeedsNode.GetNthFiducialXYZ(0)
            self._helper.debug(rasPt)
            ijkPt = self._helper.ConvertRAS2IJK(rasPt)
            self._helper.debug(ijkPt)
            targetSeedIds.InsertNextId(
                image.ComputePointId(int(ijkPt[0]), int(ijkPt[1]),
                                     int(ijkPt[2])))

            scalarRange = image.GetScalarRange()
            self._helper.debug("CF: after converting seeds")

            threshold = slicer.vtkImageThreshold()
            threshold.SetInput(image)
            threshold.ThresholdBetween(lowerThreshold, higherThreshold)
            threshold.ReplaceInOff()
            threshold.ReplaceOutOn()
            threshold.SetOutValue(scalarRange[0] - scalarRange[1])
            threshold.Update()

            self._helper.debug("CF: after thresholding")

            scalarRange = threshold.GetOutput().GetScalarRange()

            thresholdedImage = threshold.GetOutput()

            shiftScale = slicer.vtkImageShiftScale()
            shiftScale.SetInput(thresholdedImage)
            shiftScale.SetShift(-scalarRange[0])
            shiftScale.SetScale(1 / (scalarRange[1] - scalarRange[0]))
            shiftScale.Update()

            speedImage = shiftScale.GetOutput()

            self._helper.debug("CF: after shiftScale")

            collidingFronts = slicer.vtkvmtkCollidingFrontsImageFilter()
            collidingFronts.SetInput(speedImage)
            collidingFronts.SetSeeds1(sourceSeedIds)
            collidingFronts.SetSeeds2(targetSeedIds)
            collidingFronts.ApplyConnectivityOn()
            collidingFronts.StopOnTargetsOn()
            collidingFronts.Update()

            self._helper.debug("CF: after CF")

            subtract = slicer.vtkImageMathematics()
            subtract.SetInput(collidingFronts.GetOutput())
            subtract.SetOperationToAddConstant()
            subtract.SetConstantC(-10.0 * collidingFronts.GetNegativeEpsilon())
            subtract.Update()

            self._helper.debug("CF: after substract")

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(subtract.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(
                outVolumeNode, collidingFronts.GetNegativeEpsilon())

            self._helper.debug("Colliding Fronts done...")

            return outputContainer
コード例 #36
0
    def SetAndMergeEvolVolume(self, resultContainer):

        scene = self._mainGUIClass.GetLogic().GetMRMLScene()

        volumeNode = resultContainer.GetNode()
        threshold = resultContainer.GetThreshold()

        if self._mainGUIClass._outEvolVolume == None:

            # no node so far

            self._mainGUIClass._outEvolVolume = slicer.vtkMRMLScalarVolumeNode(
            )
            self._mainGUIClass._outEvolVolume.SetName(
                "VMTK Level-Set Evolution Output Volume")
            self._mainGUIClass._outEvolVolume.SetScene(scene)
            self._mainGUIClass._outEvolVolume.SetAndObserveImageData(
                slicer.vtkImageData())
            scene.AddNode(self._mainGUIClass._outEvolVolume)

            self._mainGUIClass._outEvolVolumeLast = slicer.vtkMRMLScalarVolumeNode(
            )
            self._mainGUIClass._outEvolVolumeLast.SetName(
                "VMTK Level-Set Evolution Output Volume (Last Step)")
            self._mainGUIClass._outEvolVolumeLast.SetScene(scene)
            self._mainGUIClass._outEvolVolumeLast.SetAndObserveImageData(
                slicer.vtkImageData())
            scene.AddNode(self._mainGUIClass._outEvolVolumeLast)

        matrix = slicer.vtkMatrix4x4()

        # copy current outEvolVolume to outEvolVolumeLast
        self._mainGUIClass._outEvolVolumeLast.SetAndObserveImageData(
            self._mainGUIClass._outEvolVolume.GetImageData())
        self._mainGUIClass._outEvolVolume.GetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolumeLast.SetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolumeLast.SetModifiedSinceRead(1)

        volumeNodeData = volumeNode.GetImageData()

        # merge the oldVolume with volumeNode if oldVolume has already content
        if self._mainGUIClass._outEvolVolume.GetImageData().GetPointData(
        ).GetScalars():
            # evolVolumeLast has already content
            minFilter = slicer.vtkImageMathematics()
            minFilter.SetOperationToMin()
            minFilter.SetInput1(
                self._mainGUIClass._outEvolVolume.GetImageData())  #the old one
            minFilter.SetInput2(volumeNode.GetImageData())  #the new one
            minFilter.Update()
            volumeNodeData.DeepCopy(minFilter.GetOutput())

        # copy new volume to outEvolVolume
        volumeNode.GetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolume.SetAndObserveImageData(
            volumeNodeData)
        self._mainGUIClass._outEvolVolume.SetIJKToRASMatrix(matrix)
        self._mainGUIClass._outEvolVolume.SetModifiedSinceRead(1)

        outputContainer = SlicerVMTKLevelSetContainer(
            self._mainGUIClass._outEvolVolume, threshold)

        return outputContainer
    def ExecuteFastMarching(self,inVolumeNode,lowerThreshold,higherThreshold,sourceSeedsNode,targetSeedsNode):

        self._helper.debug("Starting execution of Fast Marching...")

        if not inVolumeNode or not sourceSeedsNode:
            self._helper.debug(inVolumeNode)
            self._helper.debug(lowerThreshold)         
            self._helper.debug(higherThreshold)  
            self._helper.debug(sourceSeedsNode)  
            self._helper.debug(targetSeedsNode)         
            slicer.Application.ErrorMessage("Not enough information!!! Aborting Fast Marching..\n")
            return
        else:

            sourceSeedIds = slicer.vtkIdList()
            targetSeedIds = slicer.vtkIdList()

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            for i in range(sourceSeedsNode.GetNumberOfFiducials()):
                rasPt = sourceSeedsNode.GetNthFiducialXYZ(i)
                ijkPt = self._helper.ConvertRAS2IJK(rasPt)
                sourceSeedIds.InsertNextId(image.ComputePointId(int(ijkPt[0]),int(ijkPt[1]),int(ijkPt[2])))

            if targetSeedsNode:
                for i in range(targetSeedsNode.GetNumberOfFiducials()):
                    rasPt = targetSeedsNode.GetNthFiducialXYZ(i)
                    ijkPt = self._helper.ConvertRAS2IJK(rasPt)
                    targetSeedIds.InsertNextId(image.ComputePointId(int(ijkPt[0]),int(ijkPt[1]),int(ijkPt[2])))

            scalarRange = image.GetScalarRange()

            threshold = slicer.vtkImageThreshold()
            threshold.SetInput(image)
            threshold.ThresholdBetween(lowerThreshold,higherThreshold)
            threshold.ReplaceInOff()
            threshold.ReplaceOutOn()
            threshold.SetOutValue(scalarRange[0] - scalarRange[1])
            threshold.Update()

            scalarRange = threshold.GetOutput().GetScalarRange()

            thresholdedImage = threshold.GetOutput()

            shiftScale = slicer.vtkImageShiftScale()
            shiftScale.SetInput(thresholdedImage)
            shiftScale.SetShift(-scalarRange[0])
            shiftScale.SetScale(1/(scalarRange[1]-scalarRange[0]))
            shiftScale.Update()

            speedImage = shiftScale.GetOutput()

            fastMarching = slicer.vtkvmtkFastMarchingUpwindGradientImageFilter()
            fastMarching.SetInput(speedImage)
            fastMarching.SetSeeds(sourceSeedIds)
            fastMarching.GenerateGradientImageOff()
            fastMarching.SetTargetOffset(100.0)
            fastMarching.SetTargets(targetSeedIds)
            if targetSeedIds.GetNumberOfIds() > 0:
                fastMarching.SetTargetReachedModeToOneTarget()
            else:
                fastMarching.SetTargetReachedModeToNoTargets()
            fastMarching.Update()

            if targetSeedIds.GetNumberOfIds() > 0:
                subtract = slicer.vtkImageMathematics()
                subtract.SetInput(fastMarching.GetOutput())
                subtract.SetOperationToAddConstant()
                subtract.SetConstantC(-fastMarching.GetTargetValue())
                subtract.Update()
            else:
                subtract = slicer.vtkImageThreshold()
                subtract.SetInput(fastMarching.GetOutput())
                subtract.ThresholdByLower(1000)#better value soon
                subtract.ReplaceInOff()
                subtract.ReplaceOutOn()
                subtract.SetOutValue(-1)
                subtract.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(subtract.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode,0.0)

            self._helper.debug("Fast Marching done...")

            return outputContainer
    def ExecuteCollidingFronts(self,inVolumeNode,lowerThreshold,higherThreshold,sourceSeedsNode,targetSeedsNode):

        self._helper.debug("Starting execution of Colliding Fronts..")

        if not inVolumeNode or not sourceSeedsNode or not targetSeedsNode:
            self._helper.debug(inVolumeNode)
            self._helper.debug(lowerThreshold)         
            self._helper.debug(higherThreshold)  
            self._helper.debug(sourceSeedsNode)  
            self._helper.debug(targetSeedsNode)         
            slicer.Application.ErrorMessage("Not enough information!!! Aborting Colliding Fronts..\n")
            return
        else:

            sourceSeedIds = slicer.vtkIdList()
            targetSeedIds = slicer.vtkIdList()

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            rasPt = sourceSeedsNode.GetNthFiducialXYZ(0)
            self._helper.debug(rasPt)
            ijkPt = self._helper.ConvertRAS2IJK(rasPt)
            self._helper.debug(ijkPt)
            sourceSeedIds.InsertNextId(image.ComputePointId(int(ijkPt[0]),int(ijkPt[1]),int(ijkPt[2])))

            rasPt = targetSeedsNode.GetNthFiducialXYZ(0)
            self._helper.debug(rasPt)
            ijkPt = self._helper.ConvertRAS2IJK(rasPt)
            self._helper.debug(ijkPt)
            targetSeedIds.InsertNextId(image.ComputePointId(int(ijkPt[0]),int(ijkPt[1]),int(ijkPt[2])))

            scalarRange = image.GetScalarRange()
            self._helper.debug("CF: after converting seeds")

            threshold = slicer.vtkImageThreshold()
            threshold.SetInput(image)
            threshold.ThresholdBetween(lowerThreshold, higherThreshold)
            threshold.ReplaceInOff()
            threshold.ReplaceOutOn()
            threshold.SetOutValue(scalarRange[0] - scalarRange[1])
            threshold.Update()

            self._helper.debug("CF: after thresholding")
    
            scalarRange = threshold.GetOutput().GetScalarRange()

            thresholdedImage = threshold.GetOutput()

            shiftScale = slicer.vtkImageShiftScale()
            shiftScale.SetInput(thresholdedImage)
            shiftScale.SetShift(-scalarRange[0])
            shiftScale.SetScale(1/(scalarRange[1]-scalarRange[0]))
            shiftScale.Update()
            
            speedImage = shiftScale.GetOutput()

            self._helper.debug("CF: after shiftScale")            

            collidingFronts = slicer.vtkvmtkCollidingFrontsImageFilter()
            collidingFronts.SetInput(speedImage)
            collidingFronts.SetSeeds1(sourceSeedIds)
            collidingFronts.SetSeeds2(targetSeedIds)
            collidingFronts.ApplyConnectivityOn()
            collidingFronts.StopOnTargetsOn()
            collidingFronts.Update()

            self._helper.debug("CF: after CF")

            subtract = slicer.vtkImageMathematics()
            subtract.SetInput(collidingFronts.GetOutput())
            subtract.SetOperationToAddConstant()
            subtract.SetConstantC(-10.0 * collidingFronts.GetNegativeEpsilon())
            subtract.Update()

            self._helper.debug("CF: after substract")

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(subtract.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode,collidingFronts.GetNegativeEpsilon())

            self._helper.debug("Colliding Fronts done...")

            return outputContainer
    def FM(self):
        inVolume = self._inVolumeSelector.GetSelected()
        outVolume = self._outVolumeSelector.GetSelected()
        seeds = self._seedsSelector.GetSelected()
        targetSeeds = self._targetSeedsSelector.GetSelected()

        vmtkFound = self.CheckForVmtkLibrary()

        if inVolume and outVolume and seeds and vmtkFound:

            extentValues = self._thresholdExtent.GetExtent()

            sourceSeedIds = slicer.vtkIdList()
            targetSeedIds = slicer.vtkIdList()

            image = inVolume.GetImageData()

            rasToIjkMatrix = slicer.vtkMatrix4x4()
            inVolume.GetRASToIJKMatrix(rasToIjkMatrix)


            for i in range(seeds.GetNumberOfFiducials()):
                rasPt = seeds.GetNthFiducialXYZ(i)
                rasPt.append(1)
                ijkPt = rasToIjkMatrix.MultiplyPoint(*rasPt)   
                sourceSeedIds.InsertNextId(image.ComputePointId(int(ijkPt[0]),int(ijkPt[1]),int(ijkPt[2])))

            inValue = 0
            outValue = 5

            sideBranchSwitch=0
            
            if targetSeeds:
                if targetSeeds.GetID()!=seeds.GetID():

                    #only run if different fiducial lists
                    self._helper.debug("Using target points..")

                    for i in range(targetSeeds.GetNumberOfFiducials()):
                        rasPt = targetSeeds.GetNthFiducialXYZ(i)
                        rasPt.append(1)
                        ijkPt = rasToIjkMatrix.MultiplyPoint(*rasPt)
                        targetSeedIds.InsertNextId(image.ComputePointId(int(ijkPt[0]),int(ijkPt[1]),int(ijkPt[2])))

                    if self._sbCheckButton.GetSelectedState():
                        sideBranchSwitch=1 # allow side branches only if targetseeds are available

                    # switch thresholds for labelmap when using target points
                    inValue = 5
                    outValue = 0

            result = self._logic.ExecuteFM(inVolume.GetImageData(),extentValues[0],extentValues[1],sourceSeedIds,targetSeedIds,sideBranchSwitch)

            #self._helper.debug(result)

            ijkToRasMatrix = slicer.vtkMatrix4x4()
            inVolume.GetIJKToRASMatrix(ijkToRasMatrix)

            self.CreateOutVolumeNode()

            #outVolume.LabelMapOn()
            outVolume.SetAndObserveImageData(result)
            outVolume.SetIJKToRASMatrix(ijkToRasMatrix)
            outVolume.SetModifiedSinceRead(1)

            scene = self.GetLogic().GetMRMLScene()

            newDisplayNode = slicer.vtkMRMLLabelMapVolumeDisplayNode()
            newDisplayNode.SetScene(scene)
            newDisplayNode.SetDefaultColorMap()
            slicer.MRMLScene.AddNodeNoNotify(newDisplayNode)

            labelMap = slicer.vtkMRMLScalarVolumeNode()
            labelMap.SetName("VMTKInitializationLabelMap")
            labelMap.SetAndObserveImageData(self._logic.BuildSimpleLabelMap(result,inValue,outValue))
            labelMap.SetIJKToRASMatrix(ijkToRasMatrix)
            labelMap.LabelMapOn()
            labelMap.SetAndObserveDisplayNodeID(newDisplayNode.GetID())
            labelMap.SetModifiedSinceRead(1)
            scene.AddNode(labelMap)

            slicer.ApplicationLogic.GetSelectionNode().SetReferenceActiveLabelVolumeID(labelMap.GetID())
            slicer.ApplicationLogic.PropagateVolumeSelection()

            displayNode = inVolume.GetDisplayNode() # reset threshold for visualization
            extentValues = self._thresholdExtent.GetExtentRange()

            displayNode.SetLowerThreshold(extentValues[0])
            displayNode.SetUpperThreshold(extentValues[1])
            displayNode.SetApplyThreshold(1)

            if self._vrCheckButton.GetSelectedState():
                self._helper.HideVR()
                if targetSeeds:
                    self._helper.VolumeRendering(outVolume,'red',targetSeeds.GetID()==seeds.GetID(),sideBranchSwitch)
                else:
                    self._helper.VolumeRendering(outVolume,'red',1)
                self._helper.ShowVR()
            else:
                self._helper.HideVR()
                self._helper.GenerateModel(outVolume,'red')
コード例 #40
0
    def Apply(self):

        inputVolume = self.VolumeSelector.GetSelected()
        if not inputVolume:
            self.ErrorDialog("No input volume found")
            return

        outputVolume = self.OutVolumeSelector.GetSelected()
        if not outputVolume:
            self.ErrorDialog("No output volume found")
            return

        inputSeeds = self.FiducialsNodeSelector.GetSelected()
        if not inputSeeds:
            self.ErrorDialog("No fiducials found")
            return

        if inputSeeds.GetNumberOfFiducials() < 2:
            self.ErrorDialog("Need at least 2 fiducials in the list")
            return

        self.Status("Applying Subvolume...")

        # get the seed points (RAS)
        p0 = inputSeeds.GetNthFiducialXYZ(0)
        p1 = inputSeeds.GetNthFiducialXYZ(1)
        lower = map(min, p0, p1)

        # convert seed points to input volume IJK
        rasToIJK = slicer.vtkMatrix4x4()
        inputVolume.GetRASToIJKMatrix(rasToIJK)
        p0IJK = rasToIJK.MultiplyPoint(p0[0], p0[1], p0[2], 1.0)
        p1IJK = rasToIJK.MultiplyPoint(p1[0], p1[1], p1[2], 1.0)

        # find the bounding box of the seeds
        lowerIJK = map(int, map(min, p0IJK, p1IJK))
        upperIJK = map(int, map(max, p0IJK, p1IJK))

        # get an array of the input volume, extract the sub
        a = inputVolume.GetImageData().ToArray()
        sub = a[lowerIJK[2] : upperIJK[2], lowerIJK[1] : upperIJK[1], lowerIJK[0] : upperIJK[0]]

        # set up output node
        outImage = slicer.vtkImageData()
        outImage.SetDimensions(sub.shape[2], sub.shape[1], sub.shape[0])
        outImage.AllocateScalars()
        outImage.ToArray()[:] = sub[:]
        outputVolume.SetAndObserveImageData(outImage)
        rasToIJK.Invert()
        ijkToRAS = rasToIJK
        outputVolume.SetIJKToRASMatrix(rasToIJK)
        origin = ijkToRAS.MultiplyPoint(lowerIJK[0], lowerIJK[1], lowerIJK[2], 1.0)
        outputVolume.SetOrigin(origin[0], origin[1], origin[2])
        outputVolume.ModifiedSinceReadOn()

        displayNode = inputVolume.GetDisplayNode()
        if displayNode != None:
            newDisplayNode = displayNode.NewInstance()
            newDisplayNode.Copy(displayNode)
            slicer.MRMLScene.AddNodeNoNotify(newDisplayNode)
            outputVolume.SetAndObserveDisplayNodeID(newDisplayNode.GetID())

        appLogic = slicer.ApplicationLogic
        selectionNode = appLogic.GetSelectionNode()
        if inputVolume.GetLabelMap():
            outputVolume.SetLabelMap(1)
            selectionNode.SetReferenceActiveLabelVolumeID(outputVolume.GetID())
        else:
            selectionNode.SetReferenceActiveVolumeID(outputVolume.GetID())
        appLogic.PropagateVolumeSelection()

        self.Status("Done applying Subvolume.")
コード例 #41
0
    def ExecuteFastMarching(self, inVolumeNode, lowerThreshold,
                            higherThreshold, sourceSeedsNode, targetSeedsNode):

        self._helper.debug("Starting execution of Fast Marching...")

        if not inVolumeNode or not sourceSeedsNode:
            self._helper.debug(inVolumeNode)
            self._helper.debug(lowerThreshold)
            self._helper.debug(higherThreshold)
            self._helper.debug(sourceSeedsNode)
            self._helper.debug(targetSeedsNode)
            slicer.Application.ErrorMessage(
                "Not enough information!!! Aborting Fast Marching..\n")
            return
        else:

            sourceSeedIds = slicer.vtkIdList()
            targetSeedIds = slicer.vtkIdList()

            image = inVolumeNode.GetImageData()

            cast = slicer.vtkImageCast()
            cast.SetInput(image)
            cast.SetOutputScalarTypeToFloat()
            cast.Update()
            image = cast.GetOutput()

            for i in range(sourceSeedsNode.GetNumberOfFiducials()):
                rasPt = sourceSeedsNode.GetNthFiducialXYZ(i)
                ijkPt = self._helper.ConvertRAS2IJK(rasPt)
                sourceSeedIds.InsertNextId(
                    image.ComputePointId(int(ijkPt[0]), int(ijkPt[1]),
                                         int(ijkPt[2])))

            if targetSeedsNode:
                for i in range(targetSeedsNode.GetNumberOfFiducials()):
                    rasPt = targetSeedsNode.GetNthFiducialXYZ(i)
                    ijkPt = self._helper.ConvertRAS2IJK(rasPt)
                    targetSeedIds.InsertNextId(
                        image.ComputePointId(int(ijkPt[0]), int(ijkPt[1]),
                                             int(ijkPt[2])))

            scalarRange = image.GetScalarRange()

            threshold = slicer.vtkImageThreshold()
            threshold.SetInput(image)
            threshold.ThresholdBetween(lowerThreshold, higherThreshold)
            threshold.ReplaceInOff()
            threshold.ReplaceOutOn()
            threshold.SetOutValue(scalarRange[0] - scalarRange[1])
            threshold.Update()

            scalarRange = threshold.GetOutput().GetScalarRange()

            thresholdedImage = threshold.GetOutput()

            shiftScale = slicer.vtkImageShiftScale()
            shiftScale.SetInput(thresholdedImage)
            shiftScale.SetShift(-scalarRange[0])
            shiftScale.SetScale(1 / (scalarRange[1] - scalarRange[0]))
            shiftScale.Update()

            speedImage = shiftScale.GetOutput()

            fastMarching = slicer.vtkvmtkFastMarchingUpwindGradientImageFilter(
            )
            fastMarching.SetInput(speedImage)
            fastMarching.SetSeeds(sourceSeedIds)
            fastMarching.GenerateGradientImageOff()
            fastMarching.SetTargetOffset(100.0)
            fastMarching.SetTargets(targetSeedIds)
            if targetSeedIds.GetNumberOfIds() > 0:
                fastMarching.SetTargetReachedModeToOneTarget()
            else:
                fastMarching.SetTargetReachedModeToNoTargets()
            fastMarching.Update()

            if targetSeedIds.GetNumberOfIds() > 0:
                subtract = slicer.vtkImageMathematics()
                subtract.SetInput(fastMarching.GetOutput())
                subtract.SetOperationToAddConstant()
                subtract.SetConstantC(-fastMarching.GetTargetValue())
                subtract.Update()
            else:
                subtract = slicer.vtkImageThreshold()
                subtract.SetInput(fastMarching.GetOutput())
                subtract.ThresholdByLower(1000)  #better value soon
                subtract.ReplaceInOff()
                subtract.ReplaceOutOn()
                subtract.SetOutValue(-1)
                subtract.Update()

            matrix = slicer.vtkMatrix4x4()
            inVolumeNode.GetIJKToRASMatrix(matrix)

            outVolumeData = slicer.vtkImageData()
            outVolumeData.DeepCopy(subtract.GetOutput())
            outVolumeData.Update()

            # volume calculated...

            outVolumeNode = slicer.vtkMRMLScalarVolumeNode()
            outVolumeNode.SetAndObserveImageData(outVolumeData)
            outVolumeNode.SetIJKToRASMatrix(matrix)

            outputContainer = SlicerVMTKLevelSetContainer(outVolumeNode, 0.0)

            self._helper.debug("Fast Marching done...")

            return outputContainer