[vtkusers] Construct UnstructuredGrid from numpy connectivity array

Dominik Szczerba dominik at itis.ethz.ch
Sat Jun 7 07:29:11 EDT 2014


I read my point and cell datasets as numpy arrays:

points = numpy.array(file1["/Points"])
cells = numpy.array(file1["/Cells"]) #, dtype=numpy.int32)
cellTypes = numpy.array(file1["/CellTypes"])

Without any problems I can set the points:

grid = vtk.vtkUnstructuredGrid()
vpoints = vtk.vtkPoints()
vpoints.SetData(numpy_support.numpy_to_vtk(points))
grid.SetPoints(vpoints)

but not cells:

grid.GetCells().SetCells(NC, numpy_support.numpy_to_vtk(cells))


I get the error:

TypeError: SetCells argument 2: method requires a vtkIdTypeArray, a
vtkLongArray was provided

I tried to cast/convert it, but had no luck. Is there a way to do it?
Please help.

Regards,
Dominik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140607/f83dd679/attachment.html>


More information about the vtkusers mailing list