[vtkusers] Raw pointer returned as a string in Python

David Gobbi david.gobbi at gmail.com
Wed Jul 9 13:03:42 EDT 2014


Hi Guillaume,

I'm surprised that the "float *Initialize()" method is even wrapped.
Generally, such methods only return a "_xxxx_void_p" string if
they return "void *".

Anyway, in VTK 6.2, the IsPointOccluded() method is wrapped and
you will be able to call it after you turn the "zBuffer" into a python
container of some sort.  I'd recommend using a numpy array as the
container for the sake of efficiency.

So, what you will have to do is find a way of creating a numpy float
array from the hexadecimal address in the string.  I have no idea
how to do it, but I'm sure there is a way.

Note, however, that the docs for vtkSelectVisiblePoints::Initialize()
say that it returns a new pointer that must be deleted.  In other words,
you will also have to find some way of deleting the pointer from
Python or else you will end up with a memory leak.

  - David

On Wed, Jul 9, 2014 at 10:19 AM, Guillaume Dumont <rippalka at gmail.com> wrote:
> Hi all,
>
> I am having a little issue concerning a function in Python that returns what
> seems like a pointer as a string.
>
>>> visPts = vtk.vtkSelectVisiblePoints()
>>> visPts.SetInputData(polyData)
>>> visPts.SetRenderer(ren)
>>> zbuff = visPts.Initialize(True)
>>> print zbuff
>>> print type(zbuff)
>
> and it prints:
> _000000000dc90040_void_p
> <type 'str'>
>
> I understand that `vtkSelectVisiblePoints::vtInitialize(bool)' returns a raw
> pointer (float*) which I believe cannot directly be exposed to Python, but
> is there a way to pass it to `vtkSelectVisiblePoints::IsPointOccluded(const
> double[3], connst float* zBuffer)' in Python somehow? Or is it just a
> limitation of the Python interface?
>
> Thanks a lot for your help!
>
> Guillaume


More information about the vtkusers mailing list