VTK internal error messages

David Gobbi dgobbi at irus.rri.on.ca
Sun Apr 30 14:49:16 EDT 2000


On Sun, 30 Apr 2000, Randall Hopper wrote:

>  |Also a warning:  when you use SetVoidArray(), whether from Python
>  |or C++, you're playing with fire.  In the future the VTK graphics
>  |pipeline will be probably be expanded to deal with both float and
>  |double, and your code expects that vtkVectors are float.  
> 
> Ok, thanks for the tip.  Is there a better way to bulk-load floating-point
> data into VTK from a scripting language (without having to loop through
> every grid cell)?

Unfortunately no.  The SetVoidArray() method is meant specifically for
moving large chunks of data into VTK.  For image data (including
structured points) you can use the vtkImageImport() class, or even
the vtkImageImportFromArray.py pseudo-class that is in vtk/python.

For python, in particular, I think that it's best if you hide
any code that uses SetVoidArray() in helper classes like
vtkImageImportFromArray.py.  You also have to be very careful
with the .tostring() method... what guarantees to you have that
Python won't garbage-collect the string before VTK is done with it?

 - David

> In this case, I'm loading a 2D velocity grid from a file.  The velocity
> components are stored in separate grids, and the grids are in column-major
> order (i.e. not VTK-compatible).  So, I'm using NumPy to do the data
> shuffling (column- to row-major, merge components into vectors), and then
> loading the entire grid into a vtkStructuredPoints dataset:
> 
>     u = transpose( reshape( fromstring( u_data, Float32 ), 
>                             (dim[1], dim[0]) ) )
>     v = transpose( reshape( fromstring( v_data, Float32 ),
>                             (dim[1], dim[0]) ) )
>     veloc = ( u[:,:,NewAxis] * array([0,1,0], Float32) +       #FIXME
>               v[:,:,NewAxis] * array([1,0,0], Float32) )       #FIXME
>     data = veloc.astype( Float32 ).tostring()
> 
>     vectors = vtkVectors()
>     vectors.GetData().SetVoidArray( data, dim[0] * dim[1] * 3, 1 )
> 
>     sp = vtkStructuredPoints()
>     sp.GetPointData().SetVectors( vectors )
> 
> This avoids looping over thousands of cells in the scripting language.
> 
>  |If VTK detects an error, then it _does_ return a useful error message
>  |in nearly all cases.  The problem you are seeing is a problem with the
>  |Python wrappers, not with the core VTK libraries.
> ...
>  |I've attached a patched vtkPythonUtil.cxx that does proper
>  |type-checking.  Enjoy.
> 
> Thanks.  I'll try it out.
> 
> Randall
> 
> 

-- 
--
  David Gobbi, MSc                    dgobbi at irus.rri.on.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario


--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list