VTK widgets for trame
Project description
trame-vtk extend trame widgets with components that can interface with VTK and ParaView.
This package is under the same BSD License as VTK and ParaView which can be exposed via this library.
VTK integration in trame allows you to create rich visualization and data processing applications by leveraging the Python wrapping of the VTK library. Several components are available so you can leverage VTK either for its data processing and/or rendering. trame lets you choose if you want to leverage Remote Rendering or if the client should do the rendering by leveraging vtk.js under the hood.
VtkRemoteView
The VtkRemoteView component relies on the server for rendering by sending images to the client by simply binding your vtkRenderWindow to it. This component gives you controls to the image size reduction and quality to reduce latency while interacting.
How to use it?
The component allows you to directly tap into a vtk.js interactor’s events so you can bind your own method from Python to them. The list of available events can be found here.
The component also provides a convenient method for pushing a new image to the client when you’re modifying your scene on the Python side.
from trame.widgets import vtk
def end():
pass
remote_view = vtk.vtkRemoteView(
view=..., # Instance of vtkRenderWindow (required)
ref=..., # Identifier for this component
interactive_quality=60, # [0, 100] 0 for fastest render, 100 for best quality
interactive_ratio=..., # [0.1, 1] Image size scale factor while interacting
interactor_events=( # Enable vtk.js interactor events for method binding
"events",
["EndAnimation"],
),
EndAnimation=end, # Bind method to the enabled event
)
remote_view.update() # Force image to be pushed to client
Examples
VtkLocalView
The VtkLocalView component relies on the server for defining the vtkRenderWindow but then only the geometry is exchanged with the client. The server does not need a GPU as no rendering is happening on the server. The vtkRenderWindow is only used to retrieve the scene data and parameters (coloring by, representations, …). By relying on the same vtkRenderWindow, you can easily switch from a VtkRemoteView to a VtkLocalView or vice-versa. This component gives you controls on how you want to map mouse interaction with the camera. The default setting mimic default VTK interactor style so you will rarely have to override to the interactor_settings.
How to use it?
The component allows you to directly tap into a vtk.js interactor events so you can bind your own method from python to them. The list of available events can be found here.
The component also provides a convenient method to push the scene to the client when you’re modifying your scene on the python side.
from trame.widgets import vtk
def end():
pass
local_view = vtk.VtkLocalView(
view=..., # Instance of vtkRenderWindow (required)
ref=..., # Identifier for this component
context_name=..., # Namespace for geometry cache
interactor_settings=..., # Options for camera controls. See below.
interactor_events=( # Enable vtk.js interactor events for method binding
"events",
['EndAnimation'],
),
EndAnimation=end, # Bind method to the enabled event
)
local_view.update() # Force geometry to be pushed
Interactor Settings
For the interactor_settings we expect a list of mouse event type linked to an action. The example below is what is used as default:
interactor_settings=[
{
button: 1,
action: 'Rotate',
}, {
button: 2,
action: 'Pan',
}, {
button: 3,
action: 'Zoom',
scrollEnabled: true,
}, {
button: 1,
action: 'Pan',
shift: true,
}, {
button: 1,
action: 'Zoom',
alt: true,
}, {
button: 1,
action: 'ZoomToMouse',
control: true,
}, {
button: 1,
action: 'Roll',
alt: true,
shift: true,
}
]
A mouse event can be identified with the following set of properties:
And the action could be one of the following:
Examples
VtkRemoteLocalView
The VtkRemoteLocalView component is a blend of VtkLocalView and VtkRemoteView where the user can choose dynamically which mode they want to be in. When instantiating a VtkRemoteLocalView several variables and triggers will be created for you to more easily control your view.
How to use it?
from trame.html import vtk
rl_view = vtk.VtkRemoteLocalView(
view=..., # Instance of vtkRenderWindow (required)
# Just VtkRemoteLocalView params
namespace=..., # Prefix for variables and triggers. See below. (required)
mode="local", # Decide between local or remote. See below.
# VtkRemoteView params
**remote_view_params,
# VtkLocalView params
**local_view_params,
)
rl_view.update_geometry() # Force update to geometry
rl_view.update_image() # Force update to image
rl_view.view() # Get linked vtkRenderWindow instance
Namespace parameter
Constructing a VtkRemoteLocalView will set several variables, prefixed by a namespace. In the example below we used namespace=”view”.
Constructing a VtkRemoteLocalView will also set several trame triggers.
The namespace will also be used as ref= unless provided by the user.
Mode parameter
The mode is driven by the variable {namespace}Mode but can be provided when instantiated so the default can be overriden and a JavaScript expression can be used instead of the default variable. This attribute behaves the same way as any trame one except, we won’t register the left side as a state entry since we already have one under {namespace}Mode. This means we will evaluate the left side of the expression assuming a tuple is provided and the right side of the tuple is used to set its inital value.
Examples
Development
To update the client code, run the following command line while updating the targeted version
curl https://unpkg.com/vue-vtk-js@2.0.6 -Lo ./trame_vtk/modules/common/serve/trame-vtk.js
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for trame_vtk-2.0.0rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f9b85be2d62fc155d251ce766d25c32fcc8212c4e84a8a5fefbc709b0b1b4ae |
|
MD5 | bd37f3e94e4778cfe493ba1e8a57f81c |
|
BLAKE2b-256 | 4df9aecc7244216f3c8b3d18932543aec958388a32d2263bd83b85d4fddbb4df |