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 extractNetwork(self,polydata,seed):

        surfaceTriangulator = slicer.vtkTriangleFilter()
        surfaceTriangulator.SetInput(polydata)
        surfaceTriangulator.PassLinesOff()
        surfaceTriangulator.PassVertsOff()
        surfaceTriangulator.Update()

        # new steps for preparation to avoid problems because of slim models (f.e. at stenosis)
        subdiv = slicer.vtkLinearSubdivisionFilter()
        subdiv.SetInput(surfaceTriangulator.GetOutput())
        subdiv.SetNumberOfSubdivisions(1)
        subdiv.Update()

        # now close the surface
        surfaceCapper = slicer.vtkvmtkCapPolyData()                                                                                                                  
        surfaceCapper.SetInput(subdiv.GetOutput())                                                                                                                  
        surfaceCapper.SetDisplacement(0.0)                                                                                                         
        surfaceCapper.SetInPlaneDisplacement(0.0)                                                                                                  
        surfaceCapper.Update() 

        # re-open it where the seed is placed
        someradius = 1.0

        surface=surfaceCapper.GetOutput()

        pointLocator = slicer.vtkPointLocator()                                                                                                                  
        pointLocator.SetDataSet(surface)                                                                                                           
        pointLocator.BuildLocator() 

        id=pointLocator.FindClosestPoint(int(seed[0]),int(seed[1]),int(seed[2]))

        seed = surface.GetPoint(id)

        sphere = slicer.vtkSphere()
        sphere.SetCenter(seed[0],seed[1],seed[2])
        sphere.SetRadius(someradius)

        clip = slicer.vtkClipPolyData()
        clip.SetInput(surface)
        clip.SetClipFunction(sphere)
        clip.Update()

        opensurface = clip.GetOutput()

        networkExtraction = slicer.vtkvmtkPolyDataNetworkExtraction()                                                                    
        networkExtraction.SetInput(opensurface)                                                                                          
        networkExtraction.SetAdvancementRatio(self._advancementRatio)                                                                      
        networkExtraction.SetRadiusArrayName(self._radiusArrayName)                                                                        
        networkExtraction.SetTopologyArrayName(self._topologyArrayName)                                                                    
        networkExtraction.SetMarksArrayName(self._marksArrayName)                                                                          
        networkExtraction.Update()

        self._parentClass._helper.debug(self._topologyArrayName)

        network=networkExtraction.GetOutput()
        arrayNames = []
        celldata = network.GetCellData()

        for i in range(celldata.GetNumberOfArrays()):                                                                                                      
            array = celldata.GetArray(i)                                                                                                                   
            arrayName = array.GetName()                                                                                                                      
            if arrayName == None:                                                                                                                            
                continue                                                                                                                                     
            if (arrayName[-1]=='_'):                                                                                                                         
                continue                                                                                                                                     
            arrayNames.append(arrayName)

        numberOfPoints = network.GetNumberOfPoints()

        for i in range(numberOfPoints):

            point = network.GetPoint(numberOfPoints - i - 1)

            line = str(point[0]) + ' ' + str(point[1]) + ' ' + str(point[2])
            for arrayName in arrayNames:                                                                                                                     
                array = celldata.GetArray(arrayName)                                                                                                       
                for j in range(array.GetNumberOfComponents()):                                                                                               
                    line = line + ' ' + arrayName + ": " + str(array.GetComponent(numberOfPoints - i,j))                                                                         

            self._parentClass._helper.debug(line)

        polyDataNew = slicer.vtkPolyData()
        polyDataNew.DeepCopy(network)
        polyDataNew.Update()

        return polyDataNew