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
Example #2
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 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
Example #4
0
    def AddImages(self, imageData1, imageData2):
        ''' 
            Adds two images
            
            imageData1
                vtkImageData
            imageData2
                vtkImageData
            
            Returns
                vtkImageData after addition
        '''
        add = slicer.vtkImageMathematics()
        add.SetInput1(imageData1)
        add.SetInput2(imageData2)
        add.SetOperationToAdd()
        add.Update()

        output = slicer.vtkImageData()
        output.DeepCopy(add.GetOutput())

        return output
Example #5
0
    def MultiplyImage(self, imageData, factor):
        ''' 
            Multiply an image
            This includes automatic Re-Cast to Float
            
            imageData
                vtkImageData
            dividend
                the number to divide with, will be casted to float
            
            Returns
                vtkImageData after multiplication
        '''
        imageData.DeepCopy(self.ReCastImage(imageData, "Float"))
        mul = slicer.vtkImageMathematics()
        mul.SetInput(imageData)
        mul.SetOperationToMultiplyByK()
        mul.SetConstantK(factor)
        mul.Update()

        output = slicer.vtkImageData()
        output.DeepCopy(mul.GetOutput())

        return output
    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 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 ExecuteFM(self,image,lowerThreshold,higherThreshold,sourceSeedIds,targetSeedIds,sideBranches):

        self._parentClass.GetHelper().debug("Starting FM..")

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

        scalarRange = image.GetScalarRange()

        imageDimensions = image.GetDimensions()
        maxImageDimensions = max(imageDimensions)

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

        thresholdedImage = threshold.GetOutput()

        scalarRange = thresholdedImage.GetScalarRange()

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

        speedImage = shiftScale.GetOutput()

        if sideBranches:
            # ignore sidebranches, use colliding fronts
            self._parentClass.GetHelper().debug("COLLIDINGFRONTS")
            fastMarching = slicer.vtkvmtkCollidingFrontsImageFilter()
            fastMarching.SetInput(speedImage)
            fastMarching.SetSeeds1(sourceSeedIds)
            fastMarching.SetSeeds2(targetSeedIds)
            fastMarching.ApplyConnectivityOn()
            fastMarching.StopOnTargetsOn()            
            fastMarching.Update()

            subtract = slicer.vtkImageMathematics()
            subtract.SetInput(fastMarching.GetOutput())
            subtract.SetOperationToAddConstant()
            subtract.SetConstantC(-10*fastMarching.GetNegativeEpsilon())
            subtract.Update()

        else:
            fastMarching = slicer.vtkvmtkFastMarchingUpwindGradientImageFilter()
            fastMarching.SetInput(speedImage)
            fastMarching.SetSeeds(sourceSeedIds)
            fastMarching.GenerateGradientImageOn()
            fastMarching.SetTargetOffset(0.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:
                #self._parentClass.GetHelper().debug("No target mode "+str(fastMarching.GetTargetValue()))
                subtract = slicer.vtkImageThreshold()
                subtract.SetInput(fastMarching.GetOutput())
                subtract.ThresholdByLower(2000) # TODO find robuste value
                subtract.ReplaceInOff()
                subtract.ReplaceOutOn()
                subtract.SetOutValue(-1)
                subtract.Update()

        outVolumeData = slicer.vtkImageData()
        outVolumeData.DeepCopy(subtract.GetOutput())
        outVolumeData.Update()
        
        self._parentClass.GetHelper().debug("End of FM..")

        return outVolumeData
    def ExecuteFM(self, image, lowerThreshold, higherThreshold, sourceSeedIds,
                  targetSeedIds, sideBranches):

        self._parentClass.GetHelper().debug("Starting FM..")

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

        scalarRange = image.GetScalarRange()

        imageDimensions = image.GetDimensions()
        maxImageDimensions = max(imageDimensions)

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

        thresholdedImage = threshold.GetOutput()

        scalarRange = thresholdedImage.GetScalarRange()

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

        speedImage = shiftScale.GetOutput()

        if sideBranches:
            # ignore sidebranches, use colliding fronts
            self._parentClass.GetHelper().debug("COLLIDINGFRONTS")
            fastMarching = slicer.vtkvmtkCollidingFrontsImageFilter()
            fastMarching.SetInput(speedImage)
            fastMarching.SetSeeds1(sourceSeedIds)
            fastMarching.SetSeeds2(targetSeedIds)
            fastMarching.ApplyConnectivityOn()
            fastMarching.StopOnTargetsOn()
            fastMarching.Update()

            subtract = slicer.vtkImageMathematics()
            subtract.SetInput(fastMarching.GetOutput())
            subtract.SetOperationToAddConstant()
            subtract.SetConstantC(-10 * fastMarching.GetNegativeEpsilon())
            subtract.Update()

        else:
            fastMarching = slicer.vtkvmtkFastMarchingUpwindGradientImageFilter(
            )
            fastMarching.SetInput(speedImage)
            fastMarching.SetSeeds(sourceSeedIds)
            fastMarching.GenerateGradientImageOn()
            fastMarching.SetTargetOffset(0.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:
                #self._parentClass.GetHelper().debug("No target mode "+str(fastMarching.GetTargetValue()))
                subtract = slicer.vtkImageThreshold()
                subtract.SetInput(fastMarching.GetOutput())
                subtract.ThresholdByLower(2000)  # TODO find robuste value
                subtract.ReplaceInOff()
                subtract.ReplaceOutOn()
                subtract.SetOutValue(-1)
                subtract.Update()

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

        self._parentClass.GetHelper().debug("End of FM..")

        return outVolumeData
Example #10
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
Example #11
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
Example #12
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