import sys, slicer, numpy, os, math, vtk
model = getNode(‘kk’) #Go to Data module and see the name of your model, “Name”
#Access to Fiducial Properties (to determinate the start and the end point of the geodesic path)
fidList = slicer.util.getNode(‘F’)
numFids = fidList.GetNumberOfFiducials()
list=
for i in range(numFids):
… ras = [0,0,0]
… fidList.GetNthFiducialPosition(i,ras)
… print i,“: RAS =”,ras
… list.append(ras)
…
… #create locator
… pd = model.GetModelDisplayNode()
File “”, line 8
pd = model.GetModelDisplayNode()
^
SyntaxError: invalid syntax
pd1=pd.GetOutputPolyData()
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘pd’ is not defined
pd1.GetNumberOfPoints()
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘pd1’ is not defined
loc = vtk.vtkPointLocator()
loc.SetDataSet(pd1)
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘pd1’ is not defined
loc.BuildLocator()
closestPointId = loc.FindClosestPoint(list[0]) #point1
Traceback (most recent call last):
File “”, line 1, in
IndexError: list index out of range
closestPointId1 = loc.FindClosestPoint(list[1]) #point2
Traceback (most recent call last):
File “”, line 1, in
IndexError: list index out of range
closestPointId2 = loc.FindClosestPoint(list[2]) #point3
Traceback (most recent call last):
File “”, line 1, in
IndexError: list index out of range
#get the distance of the geodesic path
appendFilter = vtk.vtkAppendFilter()
appendFilter.MergePointsOn()
points = vtk.vtkPoints()
vIds = [closestPointId,closestPointId1,closestPointId2]
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘closestPointId’ is not defined
p0 = [0,0,0]
p1 = [0,0,0]
dist = 0.0
for n in range(len(vIds)-1):
… v0 = vIds[n]
… v1 = vIds[n+1]
…
… #create geodesic path: vtkDijkstraGraphGeodesicPath
… dijkstra = vtk.vtkDijkstraGraphGeodesicPath()
… dijkstra.SetInputConnection(pd.GetOutputPolyDataConnection())
… dijkstra.SetStartVertex(v0)
… dijkstra.SetEndVertex(v1)
… dijkstra.Update()
…
… pts = dijkstra.GetOutput().GetPoints()
… end = n<len(vIds)-2 and 0 or -1
… for ptId in range(pts.GetNumberOfPoints()-1, end, -1):
… pts.GetPoint(ptId, p0)
… points.InsertNextPoint(p0)
…
… for ptId in range(pts.GetNumberOfPoints()-1):
… pts.GetPoint(ptId, p0)
… pts.GetPoint(ptId+1, p1)
… dist += math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p0, p1))
…
… appendFilter.AddInputConnection(dijkstra.GetOutputPort())
…
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘vIds’ is not defined
print 'length= ', dist/10 ,‘cm’
length= 0.0 cm