VTK/WASM and ImplicitPlaneWidget2 for a cross-section widget?

I have been studying the documentation here in an attempt to implement a cross-section widget in a VTK/WASM project. I have not been successful, even after copying and pasting the (Python) code directly from the example at that link into my project.

Specifically, the line iren.Start() fails in VTK/WASM.

I understand that vtkRenderWindowInteractor.Start() begins mouse interaction. However, since I’m using VTK/WASM, is there some other workflow I should be using to set up this widget? Is the example at that link still relevant with this technology?

Is there more documentation on how to enable a cross-section widget with VTK/WASM? If not, could a small code example be shared here? Thanks.

The following screenshot is as far as I’ve gotten in VTK/WASM with ImplicitPlaneWidget2. I had to comment out the iren.Start() line for it to work. As you can see, there is no actual “widget”, but rather just a 2D plane that has cut a sphere mesh in half:

Hi @uv382!

Noting here for the wider audience that @uv382 is using VTK.wasm through trame-vtklocal package.

When incorporating widgets in such projects, they require special handling in server-side to properly (de)serialize across the boundary between python and WASM land.

The solution for your issue is to manually register the widgets with the scene manager. Otherwise, the widget is not visible to the marshalling layer. This explains why the widget disappears in your web client.

I suggest studying the trame-vtklocal/examples/vtk/widgets_plane.py and, the other widgets_* files in there.

fyi, @Sebastien_Jourdain

1 Like