Package: trame-vtk
trame-vtk extend tramewidgetswith components that can interface with VTK and/or ParaView.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.Installingtrame-vtk can be installed withpip:pipinstall--upgradetrame-vtkUsageTheTrame Tutorialis the place to go to learn how to use the library and start building your own application.TheAPI Referencedocumentation provides API-level documentation.Licensetrame-vtk is made available under the BSD-3-Clause License. For more details, seeLICENSEThis license has been chosen to match the one use byVTKandParaViewwhich can be exposed via this library.CommunityTrame|Discussions|Issues|RoadMap|Contact UsEnjoying trame?Share your experiencewith a testimonialorwith a brand approval.Development: Grabbing client before push to PyPITo update the client code, run the following command line while updating the targeted versionbash .fetch_externals.shTrame widgetsVtkRemoteViewThe 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 foundhere.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.fromtrame.widgetsimportvtkdefend():passremote_view=vtk.vtkRemoteView(view=...,# Instance of vtkRenderWindow (required)ref=...,# Identifier for this componentinteractive_quality=60,# [0, 100] 0 for fastest render, 100 for best qualityinteractive_ratio=...,# [0.1, 1] Image size scale factor while interactinginteractor_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 clientExamplesVTK/SimpleCone/RemoteRenderingVTK/ContourGeometry/RemoteRenderingVTK/Applications/ZarrContourViewerVtkLocalViewThe 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 aVtkRemoteViewto aVtkLocalViewor 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 theinteractor_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 foundhere.The component also provides a convenient method to push the scene to the client when you’re modifying your scene on the python side.fromtrame.widgetsimportvtkdefend():passlocal_view=vtk.VtkLocalView(view=...,# Instance of vtkRenderWindow (required)ref=...,# Identifier for this componentcontext_name=...,# Namespace for geometry cacheinteractor_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 pushedInteractor SettingsFor theinteractor_settingswe 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:AttributeValueDescriptionbutton1, 2, 3Which button should be downshifttrue/falseIs the Shift key downalttrue/falseIs the Alt key downcontroltrue/falseIs the Ctrl key downscrollEnabledtrue/falseSome action could also be triggered by scrolldragEnabledtrue/falseMostly used to disable default drag behaviorAnd the action could be one of the following:ActionDescriptionPanWill pan the object on the plane normal to the cameraZoomWill zoom closer or further from the object based on the drag directionRollWill rotate the object around the view directionZoomToMouseWill zoom while keeping the location that was initially under the mouse at the same spotExamplesVTK/SimpleCone/LocalRenderingVTK/ContourGeometry/LocalRenderingTutorial/VTK/CarotidFlowVtkRemoteLocalViewThe VtkRemoteLocalView component is a blend ofVtkLocalViewandVtkRemoteViewwhere the user can choose dynamically which mode they want to be in.
When instantiating aVtkRemoteLocalViewseveral variables and triggers will be created for you to more easily control your view.How to use it?fromtrame.htmlimportvtkrl_view=vtk.VtkRemoteLocalView(view=...,# Instance of vtkRenderWindow (required)# Just VtkRemoteLocalView paramsnamespace=...,# 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 geometryrl_view.update_image()# Force update to imagerl_view.view()# Get linked vtkRenderWindow instanceNamespace parameterConstructing a VtkRemoteLocalView will set several variables, prefixed by a namespace. In the example below we usednamespace=”view”.VariableDescriptionviewIdstrrepresenting the vtkRenderWindow idviewModelocal`or `remoteto control which View is displayed to the userConstructing a VtkRemoteLocalView will also set several trame triggers.TriggerDescriptionviewCameraWhen call with no arguments, the server will push its camera to the clientviewAnimateStartStart the animation loop for constantly renderingviewAnimateStopStop the animation loopThenamespacewill also be used asref=unless provided by the user.Mode parameterThe mode is driven by the variable{namespace}Modebut can be provided when instantiated so the default can be overridden 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 initial value.ExamplesAPIVTK/ContourGeometry/DynamicLocalRemoteRendering