[vtkusers] c api and python and vtk
David Gobbi
dgobbi at imaging.robarts.ca
Tue Jan 27 13:50:08 EST 2004
Hi Ross,
There is already a python data type that is ideally suited for this:
the python 'string' type.
In your C++ code, make a python string from your data array using
the PyString_FromStringAndSize() API.
Then, in VTK/Python you do something like this, where 'dataString'
is a python string that holds your data:
>>> data = vtkDoubleArray()
>>> data.SetVoidArray(dataString,len(dataString)/data.GetDataTypeSize(),1)
Now the array will use the python string as its internal memory store.
This is exactly the same method used to get Numeric data into VTK,
with Numeric you would call .tostring() on a Numeric array and then pass
the string to VTK.
- David
On Tue, 27 Jan 2004 rharder at uiuc.edu wrote:
> Hi,
> I have a problem. It's probably easy, but the available
> documentation is not making it obvious.
>
> I have a set of C codes that manipulate a data structure, one
> component of which is an array of doubles. I've managed to
> wrap the C codes with SWIG so I have access to the structure
> with the typical SWIG accessor functions, i.e. Sp4Array_data_get()
> What do I have to do to get this data array into vtk?
> data is declared within the structure as double* data.
>
> I would like to avoid using Numarray or Numeric, I think I
> should write a short C++ function to move the data to a
> vtk datatype and the pass it back to python to impliment the
> visualization. How do I do that, assuming that is what's needed?
> I don't get how my C++ instantiation of a vtk datatype is
> passed back to a python instantiation of the same type.
>
> I may not be able to see the forest for the trees, this is my
> first forray into python and vtk. Thanks in advance for any
> help you can offer.
>
> Ross
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list