<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<div><br></div><div>I'm using the module vtkWeb for Remote Rendering, following this simple python example:</div><div><br></div><div><font color="#1155cc"><u><a href="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</a></u></font><br></div><div><font color="#1155cc"><u><br></u></font></div><div>and I have modified it in order to include a keyPress event. The code works but the </div><div>key event is not working . Please find my code below (the only modification from the link is the class MyInteractorStyle ).</div><div><br></div><div>I'll really appreciate any help with this! </div><div><br></div><div>Thanks !!</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>##########################################################################</div><div>##########################################################################</div><div><br></div><div><div># import to process args</div><div>import sys</div><div>import os</div><div><br></div><div># import vtk modules.</div><div>import vtk</div><div>from vtk.web import protocols</div><div>from vtk.web import wslink as vtk_wslink</div><div>from wslink import server</div><div><br></div><div>try:</div><div>  Â  import argparse</div><div>except ImportError:</div><div>  Â  # since  Python 2.6 and earlier don't have argparse, we simply provide</div><div>  Â  # the source for the same as _argparse and we use it instead.</div><div>  Â  from vtk.util import _argparse as argparse</div><div><br></div><div># =============================================================================</div><div># Create custom ServerProtocol class to handle clients requests</div><div># =============================================================================</div><div><br></div><div><br></div><div>class MyInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):</div><div><br></div><div>  Â  def __init__(self,renderer, cone):</div><div>  Â  Â  Â  self.parent = renderer.GetInteractor()</div><div><span style="white-space:pre">        </span>self.resolution=5</div><div><span style="white-space:pre">     </span>self.cone = cone</div><div><br></div><div>  Â  Â  Â  self.AddObserver("KeyPressEvent",self.keyPressEvent)</div><div><br></div><div>  Â  def keyPressEvent(self,obj,event):</div><div>  Â  Â  Â  key = self.parent.GetKeySym()</div><div>  Â  Â  Â  if key == 'l':</div><div><span style="white-space:pre">   </span>  Â  print(key)</div><div><span style="white-space:pre">      </span>  Â  self.cone.SetResolution(self.resolution)</div><div><span style="white-space:pre">        </span>  Â  self.resolution+=1</div><div>  Â  Â  Â  return</div><div><br></div><div><br></div><div><br></div><div><br></div><div>class _WebCone(vtk_wslink.ServerProtocol):</div><div><br></div><div>  Â  # Application configuration</div><div>  Â  view  Â  = None</div><div>  Â  authKey = "wslink-secret"</div><div><br></div><div>  Â  def initialize(self):</div><div>  Â  Â  Â  global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor</div><div><br></div><div>  Â  Â  Â  # Bring used components</div><div>  Â  Â  Â  self.registerVtkWebProtocol(protocols.vtkWebMouseHandler())</div><div>  Â  Â  Â  self.registerVtkWebProtocol(protocols.vtkWebViewPort())</div><div>  Â  Â  Â  self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery())</div><div>  Â  Â  Â  self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery())</div><div><br></div><div>  Â  Â  Â  # Update authentication key to use</div><div>  Â  Â  Â  self.updateSecret(_WebCone.authKey)</div><div><br></div><div>  Â  Â  Â  # Create default pipeline (Only once for all the session)</div><div>  Â  Â  Â  if not _WebCone.view:</div><div>  Â  Â  Â  Â  Â  # VTK specific code</div><div>  Â  Â  Â  Â  Â  renderer = vtk.vtkRenderer()</div><div>  Â  Â  Â  Â  Â  renderWindow = vtk.vtkRenderWindow()</div><div>  Â  Â  Â  Â  Â  renderWindow.AddRenderer(renderer)</div><div><br></div><div>  Â  Â  Â  Â  Â  renderWindowInteractor = vtk.vtkRenderWindowInteractor()</div><div>  Â  Â  Â  Â  Â  renderWindowInteractor.SetRenderWindow(renderWindow)</div><div>  Â  Â  Â  Â  Â Â </div><div><span style="white-space:pre">   </span>  Â Â <br></div><div><br></div><div>  Â  Â  Â  Â  Â  cone = vtk.vtkConeSource()</div><div>  Â  Â  Â  Â  Â  mapper = vtk.vtkPolyDataMapper()</div><div>  Â  Â  Â  Â  Â  actor = vtk.vtkActor()</div><div><br></div><div>  Â  Â  Â  Â  Â  mapper.SetInputConnection(cone.GetOutputPort())</div><div>  Â  Â  Â  Â  Â  actor.SetMapper(mapper)</div><div><br></div><div><span style="white-space:pre">       </span>  Â  renderWindowInteractor.SetInteractorStyle(MyInteractorStyle(renderWindow, cone))</div><div><br></div><div>  Â  Â  Â  Â  Â  renderer.AddActor(actor)</div><div>  Â  Â  Â  Â  Â  renderer.ResetCamera()</div><div>  Â  Â  Â  Â  Â  renderWindow.Render()</div><div><br></div><div>  Â  Â  Â  Â  Â  # VTK Web application specific</div><div>  Â  Â  Â  Â  Â  _WebCone.view = renderWindow</div><div>  Â  Â  Â  Â  Â  self.getApplication().GetObjectIdMap().SetActiveObject("VIEW", renderWindow)</div><div><br></div><div><span style="white-space:pre">    </span>  #  renderWindowInteractor.Start()</div><div><br></div><div># =============================================================================</div><div># Main: Parse args and start server</div><div># =============================================================================</div><div><br></div><div>if __name__ == "__main__":</div><div>  Â  # Create argument parser</div><div>  Â  parser = argparse.ArgumentParser(description="VTK/Web Cone web-application")</div><div><br></div><div>  Â  # Add default arguments</div><div>  Â  server.add_arguments(parser)</div><div><br></div><div>  Â  # Extract arguments</div><div>  Â  args = parser.parse_args()</div><div><br></div><div>  Â  # Configure our current application</div><div>  Â  _WebCone.authKey = args.authKey</div><div><br></div><div>  Â  # Start server</div><div>  Â  server.start_webserver(options=args, protocol=_WebCone)</div></div><div><br></div></div></div></div></div>