vtk-js remoteview example get any widget interaction

Hello, Sorry about my simple question. I was testing remoteview using exist example. (vtk_server.py). I added a simple vtkBoxWidget. After I couldn’t any interaction on remoteview or when I interact window the session crashed. How can I interact with this widget on remoteview. Please help me and give me suggestions.

I used the link https://kitware.github.io/vtk-js/examples/RemoteView.html
boxWidget code is below,

        boxWidget = vtk.vtkBoxWidget()
        boxWidget.SetInteractor(renderWindowInteractor)
        boxWidget.SetProp3D(actor)
        boxWidget.SetPlaceFactor(1.25)  
        boxWidget.PlaceWidget()
        boxWidget.On()

Can you define box widget as global (variable) and try ? Probably your problem will be solved.

1 Like

If you define in python initialize method any widgets. You can solve this problem. But I didn’t understand why we are defining it like this.
why is that! I need to learn the reason.

Please share your code otherwise it is hard to tell where it was defined. Initialize method is only called onced and only when the server is ready. I’m not sure where you put your code before.

Hello, Thank u for your interest. If I write the box widget on initializing method its works. But it actually has to work like this, isn’t it?

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.vtkWebPublishImageDelivery(decode=False))
        self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery())
        
        # Update authentication key to use
        self.updateSecret(_WebCone.authKey)

        # tell the C++ web app to use no encoding.
        # ParaViewWebPublishImageDelivery must be set to decode=False to match.
        self.getApplication().SetImageEncoding(0)

        # 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)
            renderWindowInteractor.GetInteractorStyle().SetCurrentStyleToTrackballCamera()

            cone = vtk.vtkConeSource()
            mapper = vtk.vtkPolyDataMapper()
            actor = vtk.vtkActor()

            mapper.SetInputConnection(cone.GetOutputPort())
            actor.SetMapper(mapper)
            renderer.AddActor(actor)
            
            boxWidget =  vtk.vtkBoxWidget()
            boxWidget.SetInteractor(renderWindowInteractor)
            boxWidget.SetProp3D(actor)
            boxWidget.SetPlaceFactor(1.25)
            boxWidget.PlaceWidget()
            boxWidget.On()
            
            renderer.ResetCamera()
            renderWindow.Render()
           
            # VTK Web application specific
            _WebCone.view = renderWindow
            self.getApplication().GetObjectIdMap().SetActiveObject("VIEW", renderWindow)

yes

What did you do to resolve this issue? I also followed the example from vtk.js

The Python script stalls, I cannot rotate the cone or zoom.

Thank you,
Bernhard

Which version of VTK are you using?

VTK 9.0.3 (installed through pip) and Python 3.8
@kitware/vtk.js 20.1.0 (installed through npm)

Can you start your own thread describing your issue. I’m guessing it is just running the example as-is? Or are you editing the code with other stuff?

After reading Unable to get RemoteView outputs on client side, I updated to the following version:

  • Python 3.9
  • VTK 9.1.0rc4

The example is now working, thank you for your support.

1 Like