[vtk-developers] VTK python wrapping - returning binary buffer to python?

Aron Helser aron.helser at kitware.com
Fri Aug 4 11:08:25 EDT 2017


On Fri, Aug 4, 2017 at 10:30 AM, David Gobbi <david.gobbi at gmail.com> wrote:

> On Fri, Aug 4, 2017 at 7:45 AM, Aron Helser <aron.helser at kitware.com>
> wrote:
>
>> Hi David, all,
>>
>> I'm trying to re-write a C++ VTK method used in VTK web, to get rid of a
>> base-64 string encoding of an image - so the C++ method I'm working on
>> returns a buffer in a vtkUnsignedCharArray* to python. As a result, the
>> python wrapping seems to return a 'str' type in both Python 2 and 3.
>>
>
> The 'str' part doesn't make sense to me.  What method are you calling to
> get an 'str' from a vtkUnsignedCharArray?
>
>
>> The new result I want to return is a binary buffer (a raw JPG) - I tried
>> returning the new result with the same type, and it gets cut off at the
>> first null in the buffer. Is there a vtk return type should I be using
>> instead?
>>
>
> You'll have to show me the python code that you're using.  There is
> nothing in the wrappers themselves that would treat the contents of a
> vtkUnsignedCharArray is if they were a c-style string.  Are you using a
> python "bytes" object as an intermediate?
>

Sure thing. And as I trace the code more carefully, I found at least part
of the issue.

I miss-spoke - the method in question is in ParaView, an override of a
method in VTK:

ParaView/Web/Core/vtkPVWebApplication.cxx:
vtkUnsignedCharArray* vtkPVWebApplication::StillRender(vtkSMViewProxy*
view, int quality)

However, that method is wrapped in const char*
vtkPVWebApplication::StillRenderToString(), which does this:


return reinterpret_cast<char*>(array->GetPointer(0));

So that's where the 'char *' to python 'str' conversion happens.

If I avoid that wrapper and return vtkUnsignedCharArray* directly, can I
get a python 'bytes' object out of it in the Python code without copying?


>
>  - David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20170804/eecc2e99/attachment-0001.html>


More information about the vtk-developers mailing list