The RemoteRenderer 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
try: import argparse except ImportError: # since Python 2.6 and earlier don't have argparse, we simply provide # the source for the same as _argparse and we use it instead. from vtk.util import _argparse as 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.vtkWebViewPortImageDelivery()) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery())
# Update authentication key to use self.updateSecret(_WebCone.authKey)
# Create default pipeline (Only once for all the session) ifnot _WebCone.view: # VTK specific code renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer)
# Configure our current application _WebCone.authKey = args.authKey
# Start server server.start_webserver(options=args, protocol=_WebCone)
And run it via the following command line:
vtkpython vtk_server.py --port 1234
Using ParaView as server
pv_server.py
# import to process args import os
# import paraview modules. from paraview.web import pv_wslink from paraview.web import protocols as pv_protocols
from paraview import simple from wslink import server
try: import argparse except ImportError: # since Python 2.6 and earlier don't have argparse, we simply provide # the source for the same as _argparse and we use it instead. from vtk.util import _argparse as argparse
# ============================================================================= # Create custom PVServerProtocol class to handle clients requests # =============================================================================