[vtkusers] key press event in vtkWeb

Sebastien Jourdain sebastien.jourdain at kitware.com
Mon Dec 3 10:54:03 EST 2018


The event handling needs to happen on the client side (JS) which should
then trigger a RPC call to the server to adjust the resolution of the
server data. I don't think we register any key listener in the browser
that's why they don't get forwarded to the server.

On Mon, Dec 3, 2018 at 8:47 AM ivan rodriguez <ivandiegorodriguez at gmail.com>
wrote:

> 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)
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181203/17c7ab8f/attachment.html>


More information about the vtkusers mailing list