[vtkusers] [python] issue on vtkPolyData and array...
fred
fredmfp at gmail.com
Fri Apr 20 17:04:15 EDT 2007
Hi,
I try to write vtkPolyData file using python vtk functions:
from vtk import vtkPoints, vtkCellArray, vtkIdTypeArray, vtkPolyData,
vtkXMLPolyDataWriter
from vtk import vtkVertex
from scipy import array
from sys import stdout
VTK_VERTEX = vtkVertex().GetCellType()
VTK_VERTEX_NB_POINTS = vtkVertex().GetNumberOfPoints()
print 'Computing vtkPolyData...',
stdout.flush()
writer = vtkPolyData()
coords = vtkFloatArray()
coords.SetNumberOfComponents(3)
coords_array = array([datas[0][:,0], datas[0][:,1],
datas[0][:,2]]).transpose().ravel()
coords.SetVoidArray(coords_array, coords_array.size, 1)
points = vtkPoints()
points.SetData(coords)
writer.SetPoints(points)
idtype = vtkIdTypeArray()
csize = datas[0][:,3].size
cells_array = array([[VTK_VERTEX_NB_POINTS]*csize,
range(csize)]).transpose()
#cells_array = array([[VTK_VERTEX_NB_POINTS, i] for i in range(csize)])
idtype.SetVoidArray(cells_array, cells_array.size, 1)
verts = vtkCellArray()
verts.SetCells(csize, idtype)
writer.SetVerts(verts)
.../...
If I use the first cells_array, it segfaults,
if I use the second cells_array, it works fine,
although the two arrays are identical (but I guess the first is filled
faster,
so I would want to use it)
What am I doing wrong ?
Thanks in advance.
Cheers,
--
/F
More information about the vtkusers
mailing list