[vtkusers] key press event in vtkWeb
ivan rodriguez
ivandiegorodriguez at gmail.com
Mon Dec 3 10:46:46 EST 2018
Hello,
I'm using the module vtkWeb for Remote Rendering, following this simple
python example:
*https://github.com/dmreagan/vtk-remote-render/blob/master/server/vtk_server.py
<https://github.com/dmreagan/vtk-remote-render/blob/master/server/vtk_server.py>*
and I have modified it in order to include a keyPress event. The code works
but the
key event is not working . Please find my code below (the only modification
from the link is the class MyInteractorStyle ).
I'll really appreciate any help with this!
Thanks !!
##########################################################################
##########################################################################
# 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
#
=============================================================================
class MyInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):
def __init__(self,renderer, cone):
self.parent = renderer.GetInteractor()
self.resolution=5
self.cone = cone
self.AddObserver("KeyPressEvent",self.keyPressEvent)
def keyPressEvent(self,obj,event):
key = self.parent.GetKeySym()
if key == 'l':
print(key)
self.cone.SetResolution(self.resolution)
self.resolution+=1
return
class _WebCone(vtk_wslink.ServerProtocol):
# Application configuration
view = None
authKey = "wslink-secret"
def initialize(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)
if not _WebCone.view:
# VTK specific code
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
cone = vtk.vtkConeSource()
mapper = vtk.vtkPolyDataMapper()
actor = vtk.vtkActor()
mapper.SetInputConnection(cone.GetOutputPort())
actor.SetMapper(mapper)
renderWindowInteractor.SetInteractorStyle(MyInteractorStyle(renderWindow,
cone))
renderer.AddActor(actor)
renderer.ResetCamera()
renderWindow.Render()
# VTK Web application specific
_WebCone.view = renderWindow
self.getApplication().GetObjectIdMap().SetActiveObject("VIEW",
renderWindow)
# renderWindowInteractor.Start()
#
=============================================================================
# Main: Parse args and start server
#
=============================================================================
if __name__ == "__main__":
# Create argument parser
parser = argparse.ArgumentParser(description="VTK/Web Cone
web-application")
# Add default arguments
server.add_arguments(parser)
# Extract arguments
args = parser.parse_args()
# Configure our current application
_WebCone.authKey = args.authKey
# Start server
server.start_webserver(options=args, protocol=_WebCone)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181203/6c5e3700/attachment.html>
More information about the vtkusers
mailing list