# Measuring the average discrete gaussian and mean curvature of a model with vtk in python?

Hi, I am trying to calculate the mean and gaussian curvature across the surface of the model and then obtain the array of the values for every point and run some simple statistics on the array for mean, median, std, etc. I was wondering how to go about accessing the vtkpolydata from the output curvature model to get this array? Also, I was wondering if there is a way to normalize the values to compare each portion of the gaussian curvature values to the values of an elipse of the same major, minor and least axes?

This may give you some ideas: CurvaturesAdjustEdges.

I don’t think this will help at all. I don’t want to adjust or change the curvature values. I want to simply evaluate them and compare them to an elipsoid for a 3d model of an organ. Basically giving me a different in curvature measure between the organ and an eclipse, as well as just an overall average Gaussian and mean curvature value.

I thought the function `def adjust_edge_curvatures(source, curvature_name, epsilon=1.0e-08):` may have been of some use to you.

If you just want curvatures and points then these lines will do it for you, if you add them at around line 353 of after setting small values to zero:

``````    np_curv = numpy_support.vtk_to_numpy(curvatures)
np_pts = numpy_support.vtk_to_numpy(source.GetPoints().GetData())
``````

From np_curv you can easily compute whatever you like.

If your data has holes or edges I suspect you will need a function like this. Also even simple objects like a sphere may need curvatures to be constrained. Curvatures in VTK are computed on non-smooth surfaces since triangles are used to compute the curvatures.

Forgive me, are you saying line 353 of the demo code you pointed me towards before or some other code? Also, with the snippet you sent, I’m assuming numpy_support is a vtkmodule, but the np_curv that you are defining, would that be specifically the curvatures created by the following code:

curv = vtk.vtkCurvatures()
curv.SetInputData(mesh)
curv.SetCurvatureTypeToGaussian()
curv.Update()
pd = curv.GetOutputData(0)

from pd or would I use curv?

Also, I forgot to ask, is there a built-in function for generating an eclipse or plane in vtk so I can run the curvature filter on it, get the average curvature, then normalize the curvatures from this calculation by the ellipse or planar curvature to get a scoring of how elliptical or planar the curvature is?

Just search: Python. Also for ellipsoids, you can use vtkTransform on a sphere e.g. something like this:

``````    trans = vtkTransform()
trans.Scale(1, 0.5, 0.333)

sphere = vtkSphere()