hi, is there a simple way to convert a scipy array to a vtk array? is there a way to do that without writing a explicit python loop over the data? thanks, pau
"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: http://www.enthought.com/enthought/wiki/TVTK Currently TVTK uses "numerix" to support numeric/numarray and scipy. For reasons too long to elaborate here, it defaults to numeric and will use scipy if you set the environment variable NUMERIX to 'scipy'. Full support for scipy in tvtk or mayavi2 requires a patch to traits which is available here: http://www.enthought.com/enthought/ticket/326 However, when you build traits you might run into difficulties since it uses scipy_distutils which is part of old scipy. I know that this is not ideal but there is little I can do about it. cheers, prabhu
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
participants (3)
-
Fernando Perez -
Pau Gargallo -
Prabhu Ramachandran