[SciPy-user] scipy to vtk conversion?
Fernando.Perez at colorado.edu
Fri Dec 30 23:07:58 CST 2005
Prabhu Ramachandran wrote:
>>>>>>"Pau" == Pau Gargallo <pau.gargallo at 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
from our very own Pearu, for certain simple cases the conversion is very
straightforward. For example:
"""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):
grid = pyvtk.StructuredPoints(dims)
# RectilinearGrid is another option for this [use (x,y,z) order]:
#grid = pyvtk.RectilinearGrid(range(dims),range(dims),range(dims))
dat = arr.flat
dat = N.ravel(arr)
header = 'Data array'
point_data = pyvtk.PointData(pyvtk.Scalars(dat,
'Data Array: ','default'))
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.
More information about the SciPy-user