[vtkusers] events freeze X using vtk with wxPython

John Hunter jdhunter at ace.bsd.uchicago.edu
Sat Nov 17 16:11:04 EST 2001


Ok more details from painstaking testing.  I have found precisely what
is causing the freeze but don't know why.  The behavior is the same
whether I am use wxPython.lib.vtk or Prabu's updated wx_vtk.

The freeze only occurs when I have a mouse button down and move the
mouse (mouse drag), regardless of LEFT, MIDDLE or DOWN.  These event
call wxVTKRenderWindow's Rotate, Pan and Zoom respectively.  The
freeze happens 100% of the time on any of these events, and never
otherwise.  If I comment out self.Rotate(event.x, event.y) etc... in
wxVTKRenderWindow.OnMouseMove(), the freezes never happens.

I focused my debugging efforts on Zoom, and added print statements to
that function to find out where it was freezing.  It freezes on the
call to renderer.ResetCameraClippingRange().  If I comment out that
function, it freezes on the subsequent call to self.Render().  If I
comment out that call too, miraculously I recover some of the Zoom
functionality, but it is buggy and weird (not surprisingly!) but it
doesn't crash or freeze.

I wonder if anyone could repeat my test who is using VTK 4.0.  I don't
suspect a hardware problem because I have seen this with a Matrox g400
with DRI and with an ATI Rage 128 without DRI.  But you never know....

Anyway, thanks for the help thus far.  I feel like I am making a
little progress.  Hopefully the additional details may give someone an
idea about what I can do to fix this mess.  In the mean time, I am
going to try and go back down to vtk3.2 and do some testing with that.

John Hunter

>From vtk.py with diagnostic print statements:

    def Zoom(self,x,y):
        if self._CurrentRenderer:

            renderer = self._CurrentRenderer
            camera = self._CurrentCamera

            zoomFactor = math.pow(1.02,(0.5*(self._LastY - y)))
            self._CurrentZoom = self._CurrentZoom * zoomFactor

            if camera.GetParallelProjection():
                parallelScale = camera.GetParallelScale()/zoomFactor
                camera.SetParallelScale(parallelScale)
            else:
                print '1'
                camera.Dolly(zoomFactor)
                print '1a'
#freeze here=>  renderer.ResetCameraClippingRange()
                print '1b'
            self._LastX = x
            self._LastY = y
            print '1c'
            self.Render()
            print '1d'


Here is the test code I am working with.  I got rid of any event
handling in the code to simplify:
 

rom wxPython.wx import * 
from wxPython.lib import vtk
#import wx_vtk as vtk 

class MyApp(wxApp):
     def OnInit(self):
         frame = MyFrame(NULL, -1, "John's VTK")
         frame.Show(true)
         self.SetTopWindow(frame)
         return true

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                         size=(450, 300),                  
                         style=wxDEFAULT_FRAME_STYLE|
                         wxNO_FULL_REPAINT_ON_RESIZE)
                          

        vtkwin = vtk.wxVTKRenderWindow(self, -1)

        cone = vtk.vtkConeSource()
        cone.SetResolution(80)
        coneMapper = vtk.vtkPolyDataMapper()
        coneMapper.SetInput(cone.GetOutput())
        coneActor = vtk.vtkActor()
        coneActor.SetMapper(coneMapper)
        ren = vtk.vtkRenderer()
        vtkwin.GetRenderWindow().AddRenderer(ren)
        ren.AddActor(coneActor)


app = MyApp(0)
app.MainLoop()






More information about the vtkusers mailing list