Prabhu Ramachandran wrote:
"Pau" == Pau Gargallo <pau.gargallo@gmail.com> writes:
Pau> hi, is there a simple way to convert a scipy array to a vtk Pau> array? is there a way to do that without writing a explicit Pau> python loop over the data?
You can do this easily with TVTK:
While TVTK is certainly the 'way of the future', I think it's worth mentioning that using pyvtk http://cens.ioc.ee/projects/pyvtk/ from our very own Pearu, for certain simple cases the conversion is very straightforward. For example: def make_vtk(arr): """Build a vtk data obj from a Numeric 3d array""" dims = list(arr.shape) # We need to give the dims as (x,y,z), not (z,y,x): dims.reverse() grid = pyvtk.StructuredPoints(dims) # RectilinearGrid is another option for this [use (x,y,z) order]: #grid = pyvtk.RectilinearGrid(range(dims[2]),range(dims[1]),range(dims[0])) if arr.iscontiguous(): dat = arr.flat else: dat = N.ravel(arr) header = 'Data array' point_data = pyvtk.PointData(pyvtk.Scalars(dat, 'Data Array: ','default')) return pyvtk.VtkData(grid,header,point_data) =========== I know this doesn't have anywhere near the functionality and cleanliness of TVTK, but it may be good enough for cases where the data has simple geometry. hth, f