Trame support in Panel to fully support vtk?

First of all, I thank Panel for supporting vtkjs. It supported PyVista plots and made me very happy.

However, vtkjs is not the same as vtk in Python, as mentioned in past discussions.
Recently, Kitware has started developing a component called trame which aims to be fully compatible with vtk.

Do you have any ideas on how to use this project with panel?

1 Like

Hi @tkoyama010

Welcome to the community.

I took a look at the repository Kitware/trame and its not much that I can infer from that. As they support Jupyter environments you could try to see if they can be used via Panels built in support for Ipywidgets?

Maybe @xavArtley would know more?

1 Like

@Marc hanks for your comment, Trame supports the Jupyter backend so if we can use Jupyter results we can fully support vtk results. I don’t understand how ipywidget can use jupyter results so I will study it.

Additional reports:
PyVista has a method that returns the result of Trame as ipywidgets.widgets.HTML, but I am not sure how to integrate this into the panel.

Yes. I was able to display Trame results with ipywidget. Later, I would like to compile the results and contribute them to the panel project.

1 Like

Sounds great. Do you have a minimum, working example you could share here? It would help build the knowledgebase.

The layout is terrible as it is still being test script, but I will share it first. (I will update this code here later).

import pyvista as pv
from IPython.display import IFrame
import panel as pn

mesh = pv.Sphere()


def handler(viewer, src, **kwargs):
    return IFrame(src, "75%", "500px")


p = pv.Plotter(notebook=True)
_ = p.add_mesh(mesh)

iframe = p.show(
    jupyter_backend="trame",
    jupyter_kwargs=dict(handler=handler),
    return_viewer=True,
)

pn.extension()
pn.panel(iframe, width=1000).show()

Panel Application (1)

2 Likes

And this is a more advanced example. Using trame means we can use all features of vtk.
Using Physically Based Rendering example in pyvista.

import panel as pn
import pyvista as pv
from IPython.display import IFrame
from pyvista import examples


def handler(viewer, src, **kwargs):
    return IFrame(src, "75%", "500px")


# Load the statue mesh
mesh = examples.download_nefertiti()
mesh.rotate_x(-90.0, inplace=True)  # rotate to orient with the skybox

# Download skybox
cubemap = examples.download_sky_box_cube_map()

p = pv.Plotter(notebook=True)
p.add_actor(cubemap.to_skybox())
p.set_environment_texture(cubemap)  # For reflecting the environment off the mesh
p.add_mesh(mesh, color="linen", pbr=True, metallic=0.8, roughness=0.1, diffuse=1)

# Define a nice camera perspective
cpos = [(-313.40, 66.09, 1000.61), (0.0, 0.0, 0.0), (0.018, 0.99, -0.06)]

iframe = p.show(
    jupyter_backend="trame",
    jupyter_kwargs=dict(handler=handler),
    return_viewer=True,
    cpos=cpos,
)

pn.extension()
pn.panel(iframe, width=2000).show()

2 Likes

Thanks for sharing.

What if you want to integrate it with Panel widgets to say change or update the VTK/ Trame object. Is that possible and does it work nicely?

1 Like

Thank you for your comment. PyVista’s show method provides an ipywidget that can be used with Jupyter (see this tweet). I am not sure how this should be provided on the Panel side, because I am new to Panel. In any case, vtk.js is not being developed diligently and will need to be migrated to trame in the future. I would really appreciate ideas on how to incorporate the sample scripts into the Panel design.
Sorry to get ahead of myself, but I created an issue on this.

1 Like

I guess I’m a new comer here and was looking around as I will have some question on improving the comm for trame to use pyviz_comms but I will open another topic…

But as a comment for your trame interest. I would say that you can easily create side UI for controlling in a reactive manner anything on your Python side as well.

On top of that even if trame allow you to do remote rendering and get the full power of VTK, the local rendering option still rely on vtk.js.

2 Likes

image
Thanks for your comments, Trame is a great project. For the record, I would like to add my understanding.
As you mentioned, local rendering relies on vtk.js, so we are not able to reproduce VTK perfectly. Switching to remote rendering can be done by pressing the blue highlighted button in the image. This is derived from PyVista’s Jupyter support (derived from Trame’s Jupyter support maybe). In this mode, VTK is fully reproduced, but operations such as moving objects require resources.

2 Likes