Model2model distance: export values of vtk file

I’m using Slicer 4.11 to compare the deviation between 2 dental models.
I used the model2model distance extension to compare the models.
The output created was VTK Output File.
I would like to get the values in mm in an array so I used the following lines in the python interactor:

modelNode = slicer.util.getNode(‘VTK Output File’)
distances = slicer.util.arrayFromModelPointData(modelNode,‘testArray’)

However I am getting the following error:

distances = slicer.util.arrayFromModelPointData(modelNode,‘testArray’)
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\User\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Python\slicer\”, line 1293, in arrayFromModelPointData
narray = vtk.util.numpy_support.vtk_to_numpy(arrayVtk)
File “C:\Users\User\AppData\Local\NA-MIC\Slicer 4.11.20200930\bin\Lib\site-packages\vtkmodules\util\”, line 216, in vtk_to_numpy
typ = vtk_array.GetDataType()
AttributeError: ‘NoneType’ object has no attribute ‘GetDataType’

Any help is aprreciated. Thanks

You provided an incorrect array name. In recent Slicer versions, this error message is improved: you get the list of available arrays. You can also look up the available array names in Models module / Display / Scalars.

1 Like

thank you it worked. How do I export the array to a file / excel sheet?

You get the values as a numpy array, so you can already do all the statistics that Excel can do using a few lines of Python code (using numpy, pandas, etc.). To browse values in a nicer environment than the plain Python console, you can use Jupyter notebooks or JupyterLab (using SlicerJupyter extension).

Anyway, you can save a numpy array into csv file format that Excel can load, for example using this command pandas.DataFrame(distances).to_csv(filename).

1 Like

I am a complete newbie to python scripting however I would like to run the

modelNode = slicer.util.getNode(‘VTK Output File’)
distances = slicer.util.arrayFromModelPointData(modelNode,‘testArray’)

and I always get

modelNode = slicer.util.getNode(‘VTK Output File’)
File “”, line 1
modelNode = slicer.util.getNode(‘VTK Output File’)
SyntaxError: invalid character in identifier

I have created my vtk output file, but do I need to import it anyway?

I’m also a newbie in scripting but I managed to follow @lassoan instructions above. You cannot use the “testArray” name for your array. You have to go to Models section, select you VTK Output File then navigate to Display/Scalars and choose a name from the active scalar list. For me this code worked:

modelNode = slicer.util.getNode(VTK Output File)

distances = slicer.util.arrayFromModelPointData(modelNode,‘PointToPointVector’)

pandas.DataFrame(distances).to_csv(r’C:\Users\user\Desktop\data.csv’, index=False)

The last line of code enables the export to csv file. You’ll get 3 columns of values in the sheet. However i’m not sure if every column refers to a dimension (x,y,z).


Thank you for your quick reply however I failed on MacOS specific spellings when copying the code, i.e.
the mistake was the incorrectly converted ’ when pasting the code.

modelNode = slicer.util.getNode(‘VTK Output File’)

and to export on mac:
pandas.DataFrame(distances).to_csv(r’~/Desktop/whatever/data.csv’, index=False)

Anyway, the question remains whether “Signed” or “PointToPointVector” is more suitable to describe distances between to meshes (e.g. two dental models).
So if I only want to describe the dimension of a vertical displacement between two models then second column (y) of the Pointtopointvector would fit best???
If I am interested in the maximum deviations (regardless of the axis) then “signed” would also fit…keeping in mind that I can have a look at the distance map to see where max. deviations were found.

Unfortunately it makes a difference which scalar you choose in terms of “mm” (signed vs. pointtopointvector)!
Other software to create distance maps where a scale bar is present seem to rely on “signed”…

I would recommend to create a new topic to get advice on which metric to use. Add a few annotated images because it is not possible to explain what exactly you would like to quantify in plain text.