C++ vtkWindow rendered in juypter/web (trame)

I have a large C++ application which uses VTK as a visualisation system. I plan to have some minimal binding of my C++ application in Python (using pybind11) allowing users to drive the application from Jupyter. Now it would be excellent to use the existing capabilities of trame.vtk to provide an interactive widget instead of my C++ vtkRenderWindow.

My question is then how is this most easily done? Is there any sensible way to get a python vtkRenderWindow object from a C++ object? Questions

  1. Is there any way of setting the internal python wrapped C++ pointer to something provided externally
  2. A custom class could be wrapped with the VTK python binding system, so that a C++ class could provide a wrapped python object (i.e vtkRenderWindow)
  3. Alternative mechanism for C++/python interoperation. e.g. some combination of RPC and offscreen rendering etc

Suggestions most welcome.

Hi Stewart,

With pybind11, you should be able to wrap your code and exchange vtkSmartPointers of any vtk class easily. Once you have it on the Python side, you just need to pass it to the trame.vtk widget of your choice.

That example do it in the other direction, but you should be able to get it from your C++ side as easily.

As always, Kitware can help you with your project, don’t hesitate to reach out for professional support.

Hey Sebastien,

Thanks for your suggestion. It appears the example you sent is the correct direction, i.e from C++ VTK engine to python client side. I think the important part here for me is the type casting, which I didn’t really have a handle on.


Actually, in the example, the Python creates the vtkRenderWindow, and then we pass it to the C++ that will modify that instance by adding stuff to it. (just to be precise :wink: