Re: key press event in vtkWeb

ivan rodriguez <[email protected]>
Newsgroups gmane.comp.lib.vtk.user
Message-ID <CAOJ-3OSrLfjTZOfQk1-98a+M_2BRAjyEN1-AM==ke8QXOXzEiA@mail.gmail.com>
Thanks for the explanation! I don't really know how to add a listener on
the client side so I'll really appreciate any help with that.  Do you have
some example or do you know if there are some examples online about that?







On Mon, Dec 3, 2018 at 5:12 PM Sebastien Jourdain <
[email protected]> wrote:

> I'm not saying it is not the way to go. You just need to add a listener on
> the client side for the keyPress and forward that to the server.
> That's it. Nothing more than that.
>
> On Mon, Dec 3, 2018 at 9:06 AM ivan rodriguez <
> [email protected]> wrote:
>
>> Thanks for the quick response!
>>
>> I have an application written in VTK doing an animation through a
>> timerCallback and using key events and I wanted to have a similar version
>> for the browser.
>> So if vtkWeb is not the right way to go, do you know if vtk.js could be a
>> good option for that?
>>
>> Thanks!
>>
>> On Mon, Dec 3, 2018 at 4:54 PM Sebastien Jourdain <
>> [email protected]> wrote:
>>
>>> 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 <
>>> [email protected]> 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
>>>>
>>>

_______________________________________________
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.