VTK provides a method for determining the center of mass of a dataset. See:
I’m interested in adding this capability to an extension in Slicer, the goal being to determine the center of mass of a given segment.
I’ve done some reading of the source (I know C++ and a little python) but I am very much a newbie on the architecture of Slicer. I’m wondering if someone has done something similar (adding VTK method and accessing it through python for an Extension GUI) that I can borrow/steal.
Thanks in advance,
Hi Hollister -
Yes, pretty much all vtk functionality is accessible through python and easy to use in a python scripted extension.
These two programming tutorials are a good start:
Also you can find examples the script repository here:
For example, if you have created a default segmentation with a surface mode, you can do this:
>>> n = getNode('Segmentation')
>>> s = n.GetSegmentation()
>>> ss = s.GetSegment('Segment_1')
>>> pd = ss.GetRepresentation('Closed surface')
>>> com = vtk.vtkCenterOfMass()
(33.686966862924784, 10.410245678682282, 5.923210996529306)
That’s exactly what I was looking for!
Thank you very much!