Context sharing between C/C++ and Python

Dear All,

Suppose that I displayed a 3D image with VTK in Python and I want to manipulate it with C/C++ (Rotate, pick a point etc). How I share VTK context between C/C++ and Python?


Luís Gonçalves

Assuming that the Python interpreter is embedded in your running C++ process, and thus shares the same address space, you can use the “_this_” attribute to get the address (in hexadecimal) of a wrapped vtkObject:

>>> window = vtk.vtkRenderWindow()
>>> window.__this__

The format is “_” + address + “_p_” + type, where the “p” simply signifies “pointer”.

Another approach, from the C++ end, is to use the Python wrapper API:

vtkObjectBase* vtkPythonUtil::GetPointerFromObject(PyObject* obj, const char* obj_type)

There is some way to call a C/C++ program from Python (Paraview Python) with share of the variable space? (another way than system call)

Are the following approaches valid for Paraview Python?

This is a large and complicated topic. You’re best bet is to read and experiment with different possible solutions.

Cython is not supported in Paraview Python. Also not cffi.

Ctypes works and with CUDA.