[vtkusers] vtkImageImportFromArray.py problem on Debian Linux

Tony Willis Tony.Willis at nrc-cnrc.gc.ca
Thu Apr 14 14:47:13 EDT 2005


Hi Prabhu

Thanks for your reply (the Internet is indeed a source of infinite
knowledge!). As you suggested, the test script worked on the Debian
Linux box when I replaced the numarrays by their Numeric equivalents.

In the longer term I need to use numarray since
the data is passed into the actual application I'm developing
in the form of numarrays and I wish to avoid unnecessary copies.
However in the short term I can just copy the contents of
the incoming numarray to a Numeric equivalent (our lead
developer will no doubt cringe at this idea of an extra copy!),
while I play around with the use of the f._data pointer and
get a modified version of vtkImageImportFromArray.py up and running.

Cheers

Tony
___________
Tony Willis
National Research Council   Tony.Willis at nrc-cnrc.gc.ca
Box 248                     (250)493-2277
Penticton, BC  V2A 6J9      fax: 493-7767
Government of Canada        Gouvernement du Canada


On Thu, 14 Apr 2005, Prabhu Ramachandran wrote:

> >>>>> "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