[vtkusers] python - volume/surface area calculations

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Sun Mar 3 22:04:43 EST 2002


>>>>> "RH" == rod holland <rhh at StructureLABS.com> writes:

    RH> Can someone give me a tip on how to take a polygon data set -
    RH> say like spleen.color.vtk and do surface area and volume
    RH> calculations on the data set.  I am working in python (idle /
    RH> mayavi) and have tried various approaches using
    RH> vtkTriangleFilter and vtkMassProperties but I have not been
    RH> succesful.  Is there a code fragment somewhere that can point
    RH> the way?

VTK 3.2 has a few examples in contrib/examplesTcl/ 
Here is a quick and dirty example in Python.

r = vtkPolyDataReader()
r.SetFileName('spleen.color.vtk')
r.Update()
t = vtkTriangleFilter()
t.SetInput(r.GetOutput())
m = vtkMassProperties()
m.SetInput(t.GetOutput())
print m.GetVolume()
print m.GetSurfaceArea()

prabhu



More information about the vtkusers mailing list