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 Centerlines(self):
        inModel = self._outModelPrepSelector.GetSelected()
        outModel = self._outModelSelector.GetSelected()
        vModel = self._outVSelector.GetSelected()

        seeds = self._seedsSelector.GetSelected()
        targetSeeds = self._targetSeedsSelector.GetSelected()

        vmtkFound = self.CheckForVmtkLibrary()

        if inModel and outModel and seeds and targetSeeds and vModel and vmtkFound:

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

            pointLocator = slicer.vtkPointLocator()
            pointLocator.SetDataSet(inModel.GetPolyData())
            pointLocator.BuildLocator()

            for i in range(seeds.GetNumberOfFiducials()):
                rasPt = seeds.GetNthFiducialXYZ(i)
                id = pointLocator.FindClosestPoint(int(rasPt[0]),int(rasPt[1]),int(rasPt[2]))
                sourceSeedIds.InsertNextId(id)

            for i in range(targetSeeds.GetNumberOfFiducials()):
                rasPt = targetSeeds.GetNthFiducialXYZ(i)
                id = pointLocator.FindClosestPoint(int(rasPt[0]),int(rasPt[1]),int(rasPt[2]))
                targetSeedIds.InsertNextId(id)

            result = slicer.vtkPolyData()
            result.DeepCopy(self._logic.computeCenterlines(inModel.GetPolyData(),sourceSeedIds,targetSeedIds))
            result.Update()
            outModel.SetAndObservePolyData(result)
            outModel.SetModifiedSinceRead(1)
            displayNode = outModel.GetModelDisplayNode()
            if not displayNode:
                displayNode = slicer.vtkMRMLModelDisplayNode()
            displayNode.SetPolyData(outModel.GetPolyData())
            displayNode.SetColor(0, 0, 0)
            displayNode.SetVisibility(1)
            displayNode.SetOpacity(1.0)
            self.GetLogic().GetMRMLScene().AddNode(displayNode)

            outModel.SetAndObserveDisplayNodeID(displayNode.GetID())

            vd = slicer.vtkPolyData()
            vd.DeepCopy(self._logic.GetVoronoiDiagram())
            vd.Update()
            vModel.SetAndObservePolyData(vd)
            vModel.SetModifiedSinceRead(1)
            dNode = vModel.GetModelDisplayNode()
            if not dNode:
                dNode = slicer.vtkMRMLModelDisplayNode()
            dNode.SetPolyData(vModel.GetPolyData())
            dNode.SetScalarVisibility(1)
            dNode.SetBackfaceCulling(0)
            dNode.SetActiveScalarName("MaximumInscribedSphereRadius")
            dNode.SetAndObserveColorNodeID(self.GetLogic().GetMRMLScene().GetNodesByName("Labels").GetItemAsObject(0).GetID())
            dNode.SetVisibility(1)
            dNode.SetOpacity(0.5)
            self.GetLogic().GetMRMLScene().AddNode(dNode)

            vModel.SetAndObserveDisplayNodeID(dNode.GetID())
Example #4
0
    def Centerlines(self):
        inModel = self._outModelPrepSelector.GetSelected()
        outModel = self._outModelSelector.GetSelected()
        vModel = self._outVSelector.GetSelected()

        seeds = self._seedsSelector.GetSelected()
        targetSeeds = self._targetSeedsSelector.GetSelected()

        vmtkFound = self.CheckForVmtkLibrary()

        if inModel and outModel and seeds and targetSeeds and vModel and vmtkFound:

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

            pointLocator = slicer.vtkPointLocator()
            pointLocator.SetDataSet(inModel.GetPolyData())
            pointLocator.BuildLocator()

            for i in range(seeds.GetNumberOfFiducials()):
                rasPt = seeds.GetNthFiducialXYZ(i)
                id = pointLocator.FindClosestPoint(int(rasPt[0]),
                                                   int(rasPt[1]),
                                                   int(rasPt[2]))
                sourceSeedIds.InsertNextId(id)

            for i in range(targetSeeds.GetNumberOfFiducials()):
                rasPt = targetSeeds.GetNthFiducialXYZ(i)
                id = pointLocator.FindClosestPoint(int(rasPt[0]),
                                                   int(rasPt[1]),
                                                   int(rasPt[2]))
                targetSeedIds.InsertNextId(id)

            result = slicer.vtkPolyData()
            result.DeepCopy(
                self._logic.computeCenterlines(inModel.GetPolyData(),
                                               sourceSeedIds, targetSeedIds))
            result.Update()
            outModel.SetAndObservePolyData(result)
            outModel.SetModifiedSinceRead(1)
            displayNode = outModel.GetModelDisplayNode()
            if not displayNode:
                displayNode = slicer.vtkMRMLModelDisplayNode()
            displayNode.SetPolyData(outModel.GetPolyData())
            displayNode.SetColor(0, 0, 0)
            displayNode.SetVisibility(1)
            displayNode.SetOpacity(1.0)
            self.GetLogic().GetMRMLScene().AddNode(displayNode)

            outModel.SetAndObserveDisplayNodeID(displayNode.GetID())

            vd = slicer.vtkPolyData()
            vd.DeepCopy(self._logic.GetVoronoiDiagram())
            vd.Update()
            vModel.SetAndObservePolyData(vd)
            vModel.SetModifiedSinceRead(1)
            dNode = vModel.GetModelDisplayNode()
            if not dNode:
                dNode = slicer.vtkMRMLModelDisplayNode()
            dNode.SetPolyData(vModel.GetPolyData())
            dNode.SetScalarVisibility(1)
            dNode.SetBackfaceCulling(0)
            dNode.SetActiveScalarName("MaximumInscribedSphereRadius")
            dNode.SetAndObserveColorNodeID(
                self.GetLogic().GetMRMLScene().GetNodesByName(
                    "Labels").GetItemAsObject(0).GetID())
            dNode.SetVisibility(1)
            dNode.SetOpacity(0.5)
            self.GetLogic().GetMRMLScene().AddNode(dNode)

            vModel.SetAndObserveDisplayNodeID(dNode.GetID())
    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')
Example #6
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 #7
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