The RemoteView can be used with either the VTK-Web or ParaView-Web servers. The current example will not work until you start one of the servers below on your local machine.
Using VTK as server
vtk_server.py
r""" This module is a VTK Web server application. The following command line illustrates how to use it:: $ vtkpython .../vtk_server.py Any VTK Web executable script comes with a set of standard arguments that can be overriden if need be:: --host localhost Interface on which the HTTP server will listen. --port 8080 Port number on which the HTTP server will listen. --content /path-to-web-content/ Directory that you want to serve as static web content. By default, this variable is empty which means that we rely on another server to deliver the static content and the current process only focuses on the WebSocket connectivity of clients. --authKey wslink-secret Secret key that should be provided by the client to allow it to make any WebSocket communication. The client will assume if none is given that the server expects "wslink-secret" as the secret key. """
# import to process args import sys import os
# import vtk modules. import vtk from vtk.web import protocols from vtk.web import wslink as vtk_wslink from wslink import server
import argparse
# ============================================================================= # Create custom ServerProtocol class to handle clients requests # =============================================================================
definitialize(self): global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor
# Bring used components self.registerVtkWebProtocol(protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(protocols.vtkWebViewPort()) self.registerVtkWebProtocol(protocols.vtkWebPublishImageDelivery(decode=False)) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery())
# Update authentication key to use self.updateSecret(_WebCone.authKey)
# tell the C++ web app to use no encoding. # ParaViewWebPublishImageDelivery must be set to decode=False to match. self.getApplication().SetImageEncoding(0)
# Create default pipeline (Only once for all the session) ifnot _WebCone.view: # VTK specific code renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer)
definitialize(self): # Bring used components self.registerVtkWebProtocol(pv_protocols.ParaViewWebMouseHandler()) self.registerVtkWebProtocol(pv_protocols.ParaViewWebViewPort()) self.registerVtkWebProtocol( pv_protocols.ParaViewWebPublishImageDelivery(decode=False)) self.updateSecret(_DemoServer.authKey)
# tell the C++ web app to use no encoding. # ParaViewWebPublishImageDelivery must be set to decode=False to match. self.getApplication().SetImageEncoding(0)
# Start server server.start_webserver(options=args, protocol=_DemoServer)
In order to run the server, you will need a ParaView (5.6+) binary and run the following command line where the Python file provided as argument is available here
/.../pvpython ./pv-server.py --port 1234
Caution: For ParaView 5.13 the web dependencies have been removed in favor of using your own venv along ParaView pvpython. In order to make that example for with ParaView 5.13, you will need to do the following.
// hint: if you use the launcher.py and ws-proxy just leave out sessionURL // (it will be provided by the launcher) const config = { application: 'cone', sessionURL: 'ws://localhost:1234/ws', };