# can VTK get COM and Inertia of object?

**URL:** https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628
**Category:** Support
**Created:** [November 11, 2020, 1:53pm UTC](https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628 "2020-11-11T13:53:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![azk](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/e0b2c6/32.png) [@azk](https://discourse.vtk.org/u/azk)
#### Post date: [November 11, 2020, 1:53pm UTC](https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628/1 "2020-11-11T13:53:20Z")

</div>

Hello,

Is there a way to get the properties of an object using Python? Like the Center Of Mass and Inertia Matrix?  
I tried to find but I could only find [this](https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/CenterOfMass/) which is in C++ and not in Python. I am not that familiar with C so I am not sure how to translate it to Python.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![azk](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/e0b2c6/32.png) [@azk](https://discourse.vtk.org/u/azk)
#### Post date: [November 11, 2020, 3:43pm UTC](https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628/2 "2020-11-11T15:43:24Z")

</div>

I could not find a function in the VTK library so I used [Trimesh](https://pypi.org/project/trimesh/) instead.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [November 11, 2020, 10:33pm UTC](https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628/3 "2020-11-11T22:33:41Z")

</div>

All VTK classes are Python-wrapped. You can instantiate vtkCenterOfMass class by typing 'cofm = vtk.vtkCenterOfMass()`.

Of course neither Trimesh, nor this VTK filter provides the center-of-mass of the solid object, just center of mass of it surface points. If you need true center of mass or moments then you can convert the mesh to a volume using stencil filter and compute everything from that binary image. For example, using [SimpleITK’s label shape statistics filter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1LabelShapeStatisticsImageFilter.html).

---

<div class="post-metadata">

### Author: ![azk](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/e0b2c6/32.png) [@azk](https://discourse.vtk.org/u/azk)
#### Post date: [November 12, 2020, 9:25am UTC](https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628/4 "2020-11-12T09:25:39Z")

</div>

I was not aware of that, thank you for saying it!

I tried looking at the SimpleITK’s Label shape statistics filter but I am not sure how to implement it. Could you give an example please?

I found you can do what you said with scipi. I tried so, but my CoM is 2 values instead of 3 and I am not sure why… I am still trying to figure it out

I will keep looking

[EDIT]: I was trying to see if the values I get are the same in Meshlab, so I uploaded my mesh and I realized the mesh is not watertight… is there a way to do so in vtk? So far I have seen with open3d, but I cannot generate a nice, proper full mesh. It turns my mesh into a block instead of an actual object.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [November 12, 2020, 12:30pm UTC](https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628/5 "2020-11-12T12:30:48Z")

</div>

We implemented a [VTK wrapper class](https://github.com/Slicer/Slicer/blob/master/Libs/vtkITK/vtkITKLabelShapeStatistics.h) to conveniently use label shape statistics on VTK images in Python. You can either copy and build this class in your project or use it directly in 3D Slicer’s Python environment (here is a [complete example](https://github.com/Slicer/Slicer/blob/ef84547c0905277e61b5350a7bab2fe228ff3900/Modules/Scripted/SegmentStatistics/SegmentStatisticsPlugins/LabelmapSegmentStatisticsPlugin.py#L44) of how it can be used).

You may also ask about ITK or SimpleITK Python wrapping of the class on the ITK forum (I suspect we inplemented our own wrapper because the available Python wrapping was not sufficient, but I don’t recall the details).

---

<div class="post-metadata">

### Author: ![azk](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/e0b2c6/32.png) [@azk](https://discourse.vtk.org/u/azk)
#### Post date: [November 12, 2020, 12:34pm UTC](https://discourse.vtk.org/t/can-vtk-get-com-and-inertia-of-object/4628/6 "2020-11-12T12:34:35Z")

</div>

Thank you, I will look into them
