# How can I run the Mesh statistics?

**URL:** <https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760>\
**Category:** Support\
**Created:** [May 4, 2018, 11:08am UTC](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760 "2018-05-04T11:08:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pilar](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Pilar](https://discourse.slicer.org/u/Pilar)\
**Post date:** [May 4, 2018, 11:08am UTC](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760/1 "2018-05-04T11:08:18Z")

</div>

Hi 3Dslicer users,  
I am working on a University project and I need to get the statistics (the distance between all the points in a colormap file (.vtk file).  
This file was done with the two models of the hemimandibles which were firstly superimposed (voxel based registration) and then I used the Model to Model distance command to create it.  
It is posible to get the file with all the numbers. I mean, the distance between every correspondent point to analyze them?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 9, 2018, 4:59am UTC](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760/2 "2018-05-09T04:59:35Z")

</div>

You can simply save the file in vtk or vtp file format and that will contain all the computed distances for each point.

Note that you can also access all the distance values in Python and compute statistics (histogram, etc). For example, this script shows how to compute and plot histogram:

```
modelNode = getNode('VTK Output File')

# Get distances from model node (stored in point data array)
import vtk.util.numpy_support
distanceArrayVtk =modelNode.GetPolyData().GetPointData().GetArray('Signed')
distanceArray = vtk.util.numpy_support.vtk_to_numpy(distanceArrayVtk) 

# Compute histogram values
import numpy as np
histogram = np.histogram(distanceArray, bins=50)

# Save results to a new table node
tableNode=slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTableNode")
updateTableFromArray(tableNode, histogram)
tableNode.GetTable().GetColumn(0).SetName("Count")
tableNode.GetTable().GetColumn(1).SetName("Intensity")

# Create plot
plotSeriesNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotSeriesNode", 'Distance histogram')
plotSeriesNode.SetAndObserveTableNodeID(tableNode.GetID())
plotSeriesNode.SetXColumnName("Intensity")
plotSeriesNode.SetYColumnName("Count")
plotSeriesNode.SetPlotType(plotSeriesNode.PlotTypeScatterBar)
plotSeriesNode.SetColor(0, 0.6, 1.0)

# Create chart and add plot
plotChartNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlotChartNode")
plotChartNode.AddAndObservePlotSeriesNodeID(plotSeriesNode.GetID())
#plotChartNode.YAxisRangeAutoOff()
#plotChartNode.SetYAxisRange(0, 500000)

# Show plot in layout
slicer.modules.plots.logic().ShowChartInLayout(plotChartNode)

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/2/b22e1f577b9207e6b67dc6a0054fd76f052648ff.png)

---

<div class="post-metadata">

**Author:** ![Pilar](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Pilar](https://discourse.slicer.org/u/Pilar)\
**Post date:** [May 11, 2018, 11:05am UTC](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760/3 "2018-05-11T11:05:46Z")

</div>

Andras, thank so much for your help.  
I will try to do this and let you know.

Regards

---

<div class="post-metadata">

**Author:** ![antoniolch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/antoniolch/32/7027_2.png) [@antoniolch](https://discourse.slicer.org/u/antoniolch)\
**Post date:** [June 3, 2020, 9:18pm UTC](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760/4 "2020-06-03T21:18:08Z")

</div>

Hi,

I am trying to use your script to see the histogram of my vtk file but I am having some problems with the getNode(‘file.vtk’) instruction. I though that this method was inside the slicer.util package but when python3 raises me the error

> AttributeError: module ‘slicer.slicer’ has no attribute ‘util’

I am using a simple python script outside the slider program. Should I use the python environment inside Slicer? Please, could do you help me?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 3, 2020, 9:30pm UTC](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760/5 "2020-06-03T21:30:06Z")

</div>

It seems that you are calling `slicer.slicer.util.getNode()`. It should be `slicer.util.getNode()`.

---

<div class="post-metadata">

**Author:** ![antoniolch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/antoniolch/32/7027_2.png) [@antoniolch](https://discourse.slicer.org/u/antoniolch)\
**Post date:** [June 4, 2020, 7:12am UTC](https://discourse.slicer.org/t/how-can-i-run-the-mesh-statistics/2760/6 "2020-06-04T07:12:09Z")

</div>

Thanks but the problem still remain.  
I am trying to plot an histogram from the vtk saved file containing distances.  
So, how can I use a python script outside the slicer program to do it?
