[vtkusers] [python] vtkWin32OpenGLRenderWindow error when calling from thread vtkJPEGWriter.writer method

Gustavo Serra Scalet gsscalet at gmail.com
Mon Nov 19 08:46:27 EST 2007


Hello to all,

I'm trying to do a recording system that catches what is happening on the
interactor and writes to a file. It has to be a thread or else the
interactor will be unreachable while writing the movie. I've got the same
error when I simplified the problem to just get a jpeg screenshot of the
interactor when using threads. When I just call the method (self.img.Write)
I don't get this error msg and everything goes perfectly. Can someone tell
me what's wrong with my code?

    def __init__(self, parent):
        from vtk import vtkConeSource, vtkPolyDataMapper, vtkActor,
vtkRenderer
        # creates a dumme Cone
        self.c = vtkConeSource()
        self.c.SetHeight(3)
        self.c.SetRadius(1)
        self.c.SetResolution(10)
        # creates a mapper with the cone
        self.m = vtkPolyDataMapper()
        self.m.SetInput(self.c.GetOutput())
        # sets the actor with the mapper
        self.a = vtkActor()
        self.a.SetMapper(map)
        self.a.SetPosition((0,0,0)) # middle of the screen
        # puts the actor inside the renderer
        self.r = vtkRenderer()
        self.r.SetBackground((0,0,0)) # black bg
        self.r.AddActor(self.a)
        self.r.GetActiveCamera().SetPosition((10,10,10)) # camera at some
position

        # set the interactor with this renderer, attached to a wx panel
        from vtk.wx.wxVTKRenderWindowInteractor import
wxVTKRenderWindowInteractor
        self.i = wxVTKRenderWindowInteractor(self.panel, -1 , size =
self.panel.GetSize())
        self.i.GetRenderWindow().AddRenderer(self.r)
        self.i = interactor(self.r,self.panel)

        # imaging filter
        from vtk import vtkWindowToImageFilter
        self.w2i = vtkWindowToImageFilter()
        self.w2i.SetInput(self.i.GetRenderWindow())

        # the jpeg object
        from vtk import vtkJPEGWriter
        self.img = vtkJPEGWriter()
        self.img.SetQuality(80) # 80% is good
        self.img.SetInput(self.w2i.GetOutput())
        self.img.SetFileName('01.jpg')

    def OnGetPictureButton(self, event):
        # threading the image writing
        from thread import start_new_thread
        start_new_thread(self.img.Write,()) # error
        # this way I don't get the error msg
        # self.img.Write()
        event.Skip()

when "OnGetPictureButton" is called, I get this error on a pop up screen
from vtk:

"ERROR: In ..\..\VTK-5.0]\Rendering\vtkWin32OpenGLRenderWindow.cxx, lin
vtkWin32OpenGLRenderWindow(02FE1640): wglMakeCurrent failed in Mak"

Is it some lock issue?

thx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071119/633f051a/attachment.htm>


More information about the vtkusers mailing list