# Calculate a scalp to scalp distance

**URL:** <https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141>\
**Category:** Support\
**Created:** [September 28, 2017, 2:01pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141 "2017-09-28T14:01:20Z")\
**Posts on this page:** 10\
**Page:** 3

<div class="post-metadata">

**Author:** ![doc-xie](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@doc-xie](https://discourse.slicer.org/u/doc-xie)\
**Post date:** [December 15, 2017, 2:25pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/41 "2017-12-15T14:25:56Z")

</div>

OK! Sure!  
How can I send it to you?  
Would you like tell me about your e-mail?  
Best wishes!  
doc-xie

---

<div class="post-metadata">

**Author:** ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)\
**Post date:** [December 15, 2017, 2:42pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/42 "2017-12-15T14:42:11Z")

</div>

By WeTransfer? Dropbox? And you give me the link after.  
Best

---

<div class="post-metadata">

**Author:** ![doc-xie](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@doc-xie](https://discourse.slicer.org/u/doc-xie)\
**Post date:** [December 15, 2017, 2:46pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/44 "2017-12-15T14:46:02Z")

</div>

link：[https://pan.baidu.com/s/1kVjAtc7](https://pan.baidu.com/s/1kVjAtc7)  
passwords：1bhl

---

<div class="post-metadata">

**Author:** ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)\
**Post date:** [December 15, 2017, 3:21pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/45 "2017-12-15T15:21:47Z")

</div>

Thanks for your nmrl data, but I have need of you bone.vtk please.

---

<div class="post-metadata">

**Author:** ![doc-xie](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@doc-xie](https://discourse.slicer.org/u/doc-xie)\
**Post date:** [December 16, 2017, 2:11pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/46 "2017-12-16T14:11:39Z")

</div>

Link：[https://pan.baidu.com/s/1c2HE9Vy](https://pan.baidu.com/s/1c2HE9Vy)  
passwords：k1xq

---

<div class="post-metadata">

**Author:** ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)\
**Post date:** [December 18, 2017, 9:47am UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/47 "2017-12-18T09:47:09Z")

</div>

Convert your ‘bone.vtk’ in ‘bone.stl’ by 3dslicer, and It will works like a charm (cf. paint).

 ![Sans titre](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/5/d59d5b8e2baf41c577e22828732d500da30c1f77.jpeg)

---

<div class="post-metadata">

**Author:** ![doc-xie](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@doc-xie](https://discourse.slicer.org/u/doc-xie)\
**Post date:** [December 18, 2017, 1:37pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/48 "2017-12-18T13:37:38Z")

</div>

Good job!  
But after I load the bone.stl into 3D Slicer and paste the code with the name of the model changed by “bone”,the result is the same as before:  
Traceback (most recent call last):  
File “”, line 1, in   
NameError: name ‘vIds’ is not defined

> > > print 'length= ', dist/10 ,‘cm’  
> > > length= 0.0 cm

What is the reason about this?  
Thanks a lot!  
dox-xie

---

<div class="post-metadata">

**Author:** ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)\
**Post date:** [December 18, 2017, 2:27pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/49 "2017-12-18T14:27:15Z")

</div>

Once again, I think that is an indentation problem.  
copy the code one line by one line.

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [December 24, 2017, 12:25pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/50 "2017-12-24T12:25:23Z")

</div>

> [@Frederic](#):
>
> think that is an indentation problem.
> 
> copy the code one line by one line.

Are there a module to run this code automatically.  
I deleted all space and repeated, the errors occurred again.  
Could you send me this code with no indentation, so I can copy it in the same time.

---

<div class="post-metadata">

**Author:** ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)\
**Post date:** [January 9, 2018, 3:06pm UTC](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141/51 "2018-01-09T15:06:35Z")

</div>

No module yet, but I hope to make one later.  
The code with no indentation:

```
import sys, slicer, numpy, os, math, vtk

model = getNode('name_of_your_data.vtk') #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()
pd1=pd.GetOutputPolyData()
pd1.GetNumberOfPoints()
loc = vtk.vtkPointLocator()
loc.SetDataSet(pd1)
loc.BuildLocator()
closestPointId = loc.FindClosestPoint(list[0]) #point1 
closestPointId1 = loc.FindClosestPoint(list[1]) #point2
closestPointId2 = loc.FindClosestPoint(list[2]) #point3

#get the distance of the geodesic path 
appendFilter = vtk.vtkAppendFilter()
appendFilter.MergePointsOn()
points = vtk.vtkPoints()

vIds = [closestPointId,closestPointId1,closestPointId2]
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())
print 'length= ', dist/10 ,'cm'
```

[Previous page](https://discourse.slicer.org/t/calculate-a-scalp-to-scalp-distance/1141.md?page=2)
