# Retrieve Volume and Surface Area of a ModelNode (Surface Mesh (vtkPolyData)) - Python

**URL:** <https://discourse.slicer.org/t/retrieve-volume-and-surface-area-of-a-modelnode-surface-mesh-vtkpolydata-python/21556>\
**Category:** Support\
**Tags:** vtk, python, 3d-model\
**Created:** [January 21, 2022, 11:04am UTC](https://discourse.slicer.org/t/retrieve-volume-and-surface-area-of-a-modelnode-surface-mesh-vtkpolydata-python/21556 "2022-01-21T11:04:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![l.geronzi](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@l.geronzi](https://discourse.slicer.org/u/l.geronzi)\
**Post date:** [January 21, 2022, 11:04am UTC](https://discourse.slicer.org/t/retrieve-volume-and-surface-area-of-a-modelnode-surface-mesh-vtkpolydata-python/21556/1 "2022-01-21T11:04:48Z")

</div>

Hi all,  
I am a beginner and I don’t have much experience with the 3DSlicer environment and vtk libraries. I have already followed the various tutorials to get started.  
My problem is the following.  
I am trying to use python to retrieve model information, particularly Surface Area and Volume.  
The ModelNode in my case is a Surface Mesh (vtkPolyData).  
 ![problem](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/6/369e38ea8c835223fb1e0604eb5678e1bc16e3af.png)  
I’m using:  
modelnode=slicer.util.getNode(“Model\_3”)  
meshpolydata=modelnode.GetMesh()

From here, how do I get easily Surface Area and Volume?

Thank you,

Leonardo

---

<div class="post-metadata">

**Author:** ![l.geronzi](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@l.geronzi](https://discourse.slicer.org/u/l.geronzi)\
**Post date:** [January 21, 2022, 2:14pm UTC](https://discourse.slicer.org/t/retrieve-volume-and-surface-area-of-a-modelnode-surface-mesh-vtkpolydata-python/21556/2 "2022-01-21T14:14:45Z")

</div>

I don’t know if this is the best approach but I found the solution for my problem using the vtkMassProperties  
Mass = vtk.vtkMassProperties()  
Mass.SetInputData(mesh)  
Mass.Update()  
Surface\_Area=Mass.GetSurfaceArea()  
Volume=Mass.GetVolume()

I hope this can be of help to someone.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [January 21, 2022, 2:15pm UTC](https://discourse.slicer.org/t/retrieve-volume-and-surface-area-of-a-modelnode-surface-mesh-vtkpolydata-python/21556/3 "2022-01-21T14:15:08Z")

</div>

> [@l.geronzi](#):
>
> From here, how do I get easily Surface Area and Volume?

Pass the polydata to vtkMassProperties, and the rest is quite straightforward.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [January 21, 2022, 2:46pm UTC](https://discourse.slicer.org/t/retrieve-volume-and-surface-area-of-a-modelnode-surface-mesh-vtkpolydata-python/21556/4 "2022-01-21T14:46:30Z")

</div>

If you check Slicer’s code they pass the polydata by a triangleFilter with a specific option before using massProperties. I don’t know why they do it but when I have to calculate a surfaceArea or volume I do it too

Hope it helps

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [August 2, 2022, 2:57am UTC](https://discourse.slicer.org/t/retrieve-volume-and-surface-area-of-a-modelnode-surface-mesh-vtkpolydata-python/21556/5 "2022-08-02T02:57:01Z")

</div>

> [@mau\_igna\_06](#):
>
> triangleFilter

```python
.....
        tri_converter = vtk.vtkTriangleFilter()
        tri_converter.SetInputDataObject(model.GetMesh())
        tri_converter.Update()
        Mass = vtk.vtkMassProperties() 
        Mass.SetInputData(tri_converter.GetOutput()) 
        Mass.Update() 
        return Mass.GetSurfaceArea(),Mass.GetVolume()

```
