trame.widgets.vtklocal module

class trame.widgets.vtklocal.LocalView(render_window, throttle_rate=10, **kwargs)

Bases: AbstractElement

LocalView allow to mirror a server side vtkRenderWindow on the client side using VTK.wasm.

Args:
render_window (vtkRenderWindow):

Specify the VTK window to mirror

throttle_rate (number):

Number of update per second the render_throttle() method will actually perform.

cache_size (number):

Size of client side cache for geometry and arrays in Bytes.

eager_sync (bool):

If enabled, the server will push states rather than waiting for the client to request them. Usually improve fast update behavior.

listeners (dict):

Dynamic structure describing what to observe and how to map internal WASM state to trame state variable.

use_handler (string):

Name of a global instance of WASM handler to use. This is useful for skipping WASM reinitialization when your vue component is going to be mounted/unmounted often. (i.e. used inside VueRouter element)

progress_enabled (bool):

Allow the progress synchronization to show (or not).

progress_delay (int):

Number of ms to wait before showing the progress. This allow to disable progress dialog to show for short synchronization time.

config (dict):

Provide configuration for your wasm runtime. {

rendering: ‘webgpu’ or ‘webgl’, exec: ‘sync’ or ‘async’, wasmBaseName: ‘vtk’, # base name of the wasm file, will look for ${wasmBaseName}WebAssembly.mjs

}

emit_memory (bool):

Emit memory information events. By default it is skipped.

auto_resize (bool):

Enabled by default. If disabled, the render window will not automatically resize when the canvas is resized.

updated (event):

Emitted after each completed client side update.

memory_vtk (event):

Event which provides the current memory used by vtk object structures.

memory_arrays (event):

Event which provides the current memory used by vtk arrays.

camera (event):

Event emitted when any camera is changed. The actual state of the camera is passed as arg.

progress (event):

Event emitted during wasm sync. Payload includes active flag and current/total counts for states and blobs.

property api

Return API from helper

property object_manager

Return object_manager

eval(state_mapping)

Evaluate WASM state extract and map it onto trame state variables

>>> html_view.eval({
...    "trame_state_name": {
...        "prop_name1": (wasm_id, "PropName"),
...        "origin": (wasm_id, "WidgetRepresentation", "origin"),
...        "widget_state": widget_id,
...    }
... }
detach_handler()

When using use_handler= property, you may reach a point where you want to free the global WASM handler on the client side. This method will remove the global reference so an unmount would release it, while a new mount will re-create a new handler.

property update_throttle

Throttled update method on which you can update its rate by doing

>>> html_view.update_throttle.rate = 15  # time per second
>>> html_view.update_throttle()
update(push_camera=False)

Sync view by pushing updates to client

register_vtk_object(vtk_instance)

Register external element (i.e. widget) into the scene so it can be managed and return its wasm_id

register_widget(w)

Register external element (i.e. widget) into the scene so it can be managed and return its wasm_id

unregister_vtk_object(vtk_instance)

Unregister external element (i.e. widget) from the scene so it can removed from tracking

unregister_all_vtk_objects()

Unregister all external element (i.e. widget) from the scene

unregister_widgets()

Unregister all external element (i.e. widget) from the scene

export(format='zip', **kwargs)

Export standalone scene for WASMViewer

Parameters:

format – Can be either be “zip” or “json”.

save(file_name, wasm_ids=None)

Save zip file capturing state and blob data for a given render window

reset_camera(renderer_or_render_window=None, **kwargs)

Reset camera by making the call on the client side

start_web_xr(mode=1, required_features=1, optional_features=2)

Start WebXR session

Parameters:

mode – 0 (inline), 1 (VR) or 2 (AR)

stop_web_xr()

Stop WebXR session

property ref_name

Return the assigned name as a vue.js ref

get_wasm_id(vtk_object)

Return vtkObject id used within WASM scene manager

get_wasm_obj_id(vtk_object)

Return vtkObject {Id: id} used within WASM scene manager

get_vtk_obj(wasm_id)

Return corresponding VTK object

vtk_update_from_state(state_obj)

Use a state from WASM to update a VTK object