[vtkusers] Throwing exception when integrating vtkOrientationMarkerWidget into VTKWeb

沈庄明 zhuangming.shen at sphic.org.cn
Fri Aug 12 02:11:57 EDT 2016


​Hi all,


I'd like to integrate vtkOrientationMarkerWidget into vtk_web_cone.py.  When I run this code and open a browser to http://localhost:8080/apps/cone, I encountered an exception (pls see attached fig1). Then, I chose Debug to look into where throws this exception(pls see attached fig2). I list my code below. What's the problem? I guess it may be related to "widget.SetInteractor(renderWindowInteractor)". Any suggestions are welcomed. Thanks in advance.


Regards,


Zhuangming Shen



==================================================================

# import to process args
import sys
import os

# import vtk modules.
import vtk
from vtk.web import protocols, server
from vtk.web import wamp as vtk_wamp

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 File Opener class to handle clients requests
# =============================================================================

class _WebCone(vtk_wamp.ServerProtocol):

    # Application configuration
    view    = None
    authKey = "vtkweb-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())

        # 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)
            # axes
            axes_actor = vtk.vtkAxesActor()

            widget = vtk.vtkOrientationMarkerWidget()
            widget.SetOrientationMarker(axes_actor)
            widget.SetInteractor(renderWindowInteractor)
            widget.SetViewport(0,0,0.2,0.2)
            widget.SetEnabled(True)
            widget.InteractiveOff()

            renderer.ResetCamera()
            renderWindow.Render()

            # VTK Web application specific
            _WebCone.view = renderWindow
            self.Application.GetObjectIdMap().SetActiveObject("VIEW", renderWindow)

# =============================================================================
# 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)

    # Exctract 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: <http://public.kitware.com/pipermail/vtkusers/attachments/20160812/71fa8dbb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fig1.PNG
Type: image/png
Size: 16183 bytes
Desc: fig1.PNG
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160812/71fa8dbb/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fig2.PNG
Type: image/png
Size: 67599 bytes
Desc: fig2.PNG
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160812/71fa8dbb/attachment-0001.png>


More information about the vtkusers mailing list