[vtkusers] Vtk renderindow out of the main wx window

Rafael de Oliveira Lopes Gonçalves rafaelolg at gmail.com
Mon Apr 29 12:49:36 EDT 2013


I'm having some trouble with a RenderWindow poping out of a wx.Frame. Is
this a bug or a issue with my code.

Sample code:

import vtk
import wx
from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor

from controller.slice_viewer.BaseInteractorStyle import BaseInteractorStyle
class SliceViewer(object):
    '''
    Pane do wx visualizador de um plano de uma imagem.
    Decorator do  vtkResliceImageViewer.
    '''
    ORIENTATION_XY = vtk.vtkResliceImageViewer.SLICE_ORIENTATION_XY
    ORIENTATION_YZ = vtk.vtkResliceImageViewer.SLICE_ORIENTATION_YZ
    ORIENTATION_XZ = vtk.vtkResliceImageViewer.SLICE_ORIENTATION_XZ


    def __init__(self, parent, ID):
        self._slice = 0
        self._viewer = vtk.vtkImageViewer2()
        self._interactor = wxVTKRenderWindowInteractor(parent, ID)
        self._viewer.SetRenderWindow(self._interactor.GetRenderWindow())
        self._viewer.SetupInteractor(self._interactor)

self._interactor.GetRenderWindow().AddRenderer(self._viewer.GetRenderer())
        #self._viewer.SetSliceScrollOnMouseWheel(1)
        #self._viewer.SetThickMode(0)
        self.actors = []
        self.actor_renderer = self._viewer.GetRenderer()



    def __getattr__(self,name):
        return getattr(self._viewer, name)

    def SetInteractorStyle(self, style):
        style.set_main_interactor(self._interactor)

    def GetWxWidget(self):
        return self._interactor

    def AddActor(self, actor):
        self.actors.append(actor)
        self.actor_renderer.AddActor(actor)

    def SetCursor(self, cursor):
        cursorMapper = vtk.vtkPolyDataMapper()
        cursorMapper.SetInputConnection(cursor.GetOutputPort())
        self.cursorActor = vtk.vtkActor()
        self.cursorActor.SetMapper(cursorMapper)
        self.cursorActor.GetProperty().SetColor(1,0,0)
        self.AddActor(self.cursorActor)


def test():
    # every wx app needs an app
    from vtk.util.misc import vtkGetDataRoot
    VTK_DATA_ROOT = vtkGetDataRoot()
# Start by loading some data.
    v16 = vtk.vtkVolume16Reader()
    v16.SetDataDimensions(64, 64)
    v16.SetDataByteOrderToLittleEndian()
    v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter")
    v16.SetImageRange(1, 93)
    v16.SetDataSpacing(3.2, 3.2, 1.5)
    v16.Update()


    # create the top-level frame, sizer and wxVTKRWI
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, "wxVTKRenderWindowInteractor",
size=(400,400))
    siv = SliceViewer(frame, -1)
    siv.SetSliceOrientation(-0)
    siv.SetInput(v16.GetOutput())



    siv.SetInteractorStyle(BaseInteractorStyle())
    sizer = wx.BoxSizer(wx.VERTICAL)
    frame.SetSizer(sizer)
    frame.Layout()

    cone = vtk.vtkConeSource()
    cone.SetResolution(8)

    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())

    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    siv.AddActor(coneActor)

    w = siv.GetWxWidget()
    sizer.Add(w, 1, wx.EXPAND)
    w.AddObserver("ExitEvent", lambda o,e: frame.Close())
    w.Enable(1)
    siv.SetSlice(3)
    frame.Show()
    app.MainLoop()

if __name__ == "__main__":
    test()



-- 
python -c 'import this'
Rafael Lopes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130429/3227a79d/attachment.htm>


More information about the vtkusers mailing list