I am using Mayavi2 in a Python script to calculate 3d iso-surfaces. As a result I get a vtkPoints object. Now I want to convert this vtkPoints object ('vtkout' in the code sample below) to a simple numpy array with 3 lines containing all x, y and z values.
I get vtkout using a code like this:
from enthought.mayavi import mlab
randVol = numpy.random.rand(50,50,50) # fill volume with some random potential
X, Y, Z = numpy.mgrid[0:50, 0:50, 0:50] # grid
surf = mlab.contour3d(X, Y, Z, randVol, contours=[0.5]) # calc contour
vtkout = surf.contour.contour_filter.output.points # get the vtkPoints object
pointsArray = numpy.zeros((3, vtkout.number_of_points))
for n in range(vtkout.number_of_points):
pointsArray[0,n] = vtkout[n]
pointsArray[1,n] = vtkout[n]
pointsArray[2,n] = vtkout[n]
As confirmed from comments on the original post, you might try:
This is a direct method that does not require looping.