[vtkusers] vtkImageImportFromArray.py problem on Debian Linux
Prabhu Ramachandran
prabhu_r at users.sf.net
Thu Apr 14 13:46:09 EDT 2005
>>>>> "Tony" == Tony Willis <Tony.Willis at nrc-cnrc.gc.ca> writes:
Tony> Hi All A bit of background - I want to use VTK to visualize
Tony> python 3D numarrays. The contents of these arrays can
Tony> change as a function of time, and when they do, I want the
Tony> display to be updated accordingly. However I'm encountering
Tony> a problem in the visualization because the conversion of
Tony> these numarrays into a VTK data type is failing under Debian
Tony> Linux.
Here is a quick hint. Numarray arrays by default don't support the
buffer protocol (which is how the voidpointer magic happens). So,
you'll need to use the array's '_data' attribute. For example:
f = numarray.arange(0, 10, 0.1)
print f._data
Pass this instead of f itself. BTW, I asked the developers on the
numarray list to provide the buffer protocol for numarray arrays also
but that has not happened. :(
However, this in itself won't fix your code since you'll need to
modify vtkImageImportFromArray for this (unless you write code to do
this yourself -- the basics are really simple and you really don't
need all the stuff that vtkImageImportFromArray does).
OTOH, the easiest solution would be to use Numeric instead of
numarray. Your code runs fine if you simply replace
from numarray import *
with
from Numeric import *
and
image_numarray_test = ones((num_arrays,array_dim,array_dim),type=Float32)
with
image_numarray_test = ones((num_arrays,array_dim,array_dim),typecode=Float32)
cheers,
prabhu
More information about the vtkusers
mailing list