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')
    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')