Hi Andras,

I have been trying to learn some python 3 using codeacademy.com which seems good.

I added some extra lines to your code to print out the min, max, mean and RMS values from the distances in the table.

I am not sure about the RMS calculation. I was looking at the code for the fiducial to model registration module in Slicer IGT here and trying to copy what the ComputeMeanDistance function does. However their closest point function must work differently to your one as your code seems to give a negative distance when the fiducial is inside the surface of the model (which is good), however it is not possible to take the square root of a negative number.

To get around this I have taken the absolute value of the numbers in the table but I cannot get the same result as is printed in the fiducial to model registration. I have tried applying the transfrom to the model, I have tried inverting the transform and applying it to the model and I have tried with no transform applied. I cannot get my RMS printout to match the value in the fiducials-model registration output box.

Do you know what I might be doing wrong? Here is my code. I donâ€™t understand how to use the vtk arrays so I have made a parallel list to do operations on.

```
import statistics
import math
markupsNode = getNode('F')
modelNode = getNode('mymodel')
# Transform model polydata to world coordinate system
if modelNode.GetParentTransformNode():
transformModelToWorld = vtk.vtkGeneralTransform()
slicer.vtkMRMLTransformNode.GetTransformBetweenNodes(modelNode.GetParentTransformNode(), None, transformModelToWorld)
polyTransformToWorld = vtk.vtkTransformPolyDataFilter()
polyTransformToWorld.SetTransform(transformModelToWorld)
polyTransformToWorld.SetInputData(modelNode.GetPolyData())
polyTransformToWorld.Update()
surface_World = polyTransformToWorld.GetOutput()
else:
surface_World = modelNode.GetPolyData()
# Create arrays to store results
indexCol = vtk.vtkIntArray()
indexCol.SetName("Index")
labelCol = vtk.vtkStringArray()
labelCol.SetName("Name")
distanceCol = vtk.vtkDoubleArray()
distanceCol.SetName("Distance")
# Create blank list becuase I dont know how to use vtk arrays yet
dist_list = []
distanceFilter = vtk.vtkImplicitPolyDataDistance()
distanceFilter.SetInput(surface_World);
nOfFiduciallPoints = markupsNode.GetNumberOfFiducials()
for i in range(0, nOfFiduciallPoints):
point_World = [0,0,0]
markupsNode.GetNthControlPointPositionWorld(i, point_World)
closestPointOnSurface_World = [0,0,0]
closestPointDistance = distanceFilter.EvaluateFunctionAndGetClosestPoint(point_World, closestPointOnSurface_World)
indexCol.InsertNextValue(i)
labelCol.InsertNextValue(markupsNode.GetNthControlPointLabel(i))
distanceCol.InsertNextValue(closestPointDistance)
#fill the list with closest point distances
dist_list.append(closestPointDistance)
# Create a table from result arrays
resultTableNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode", "Points from surface distance")
resultTableNode.AddColumn(indexCol)
resultTableNode.AddColumn(labelCol)
resultTableNode.AddColumn(distanceCol)
# Show table in view layout
slicer.app.layoutManager().setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpTableView)
slicer.app.applicationLogic().GetSelectionNode().SetReferenceActiveTableID(resultTableNode.GetID())
slicer.app.applicationLogic().PropagateTableSelection()
# math for min, max, mean and RMS values
max_value = max(dist_list)
min_value = min(dist_list)
mean_value = statistics.mean(dist_list)
sqrt_list = [math.sqrt(abs(i)) for i in dist_list]
rms_value = statistics.mean(sqrt_list)
# print min, max, mean and RMS values
print("The min value is " + "%.3f" % min_value + ".")
print("The max value is " + "%.3f" % max_value + ".")
print("The mean value is " + "%.3f" % mean_value + ".")
print("The Root Mean Square Value is " + "%.3f" % rms_value + ".")
```