[vtkusers] Mac/Cocoa/Qt "invalid drawable"

Clinton Stimpson clinton at elemtech.com
Tue May 5 14:53:35 EDT 2009


I saw the same thing when doing it in C++ with Qt 4.5 and  Cocoa.
The fix there was to overload vtkRenderWindowInteractor::Initialize()
and skip the Render() and let the GUI say when to do the first render.

Can you do that in QVTKRenderWindowInteractor.py?  Or try commenting out 
the Render() call in vtkRenderWindowInteractor::Initialize() to see if 
that fixes your problem.

I don't know why it even has the Render() in there.  It seems if the 
window is coming up for the first time and an event loop is being used, 
one would get an event to do a first Render() anyways.  If one isn't 
using an event loop (and probably not using the interactor), they are 
calling Render() themselves.

Clint


Chris Kees wrote:
> Hi,
>
> I've installed vtk from cvs on a Mac with OS X 10.5.6 using the 64 bit 
> Qt 4.5 libraries and the patched VTK source. The code runs fine except 
> I get a warning:
>
> 2009-05-05 12:17:16.313 python[75352:807] invalid drawable
>
> when calling Initialize on the QVTKRenderWindowInteractor.  If I just 
> remove the Initialize call then the code runs fine without warnings. I 
> saw a post from 2005 that mentioned the warning and a work around that 
> I don't quite understand.  Anybody know if this is still  something 
> that needs a work around, or am I just doing something wrong?
>
> Chris
>
> Here's an example that generates the warning (needs PyQt installed as 
> well):
>
> #!/usr/bin/env python
> from vtk import *
> from vtk.qt4.QVTKRenderWindowInteractor import *
> import sys
> from PyQt4 import QtGui
> import copy
>
> app = QtGui.QApplication(sys.argv)
>
> import numpy
> from math import cos,sin
>
> nPoints=10
> x = numpy.zeros((3,),'d')
> d=2.0
> pointData=vtkPoints()
> pointData.SetNumberOfPoints(2*nPoints)
> for ix in range(2):
>     for iTheta in range(nPoints):
>     x[0] = ix*d
>     x[1] = cos(float(iTheta)*(2.0*3.14)/float(nPoints))
>     x[2] = sin(float(iTheta)*(2.0*3.14)/float(nPoints))
>     pointData.SetPoint(ix*nPoints+iTheta,x)
> polygons=vtkCellArray()
> scalars=vtkDoubleArray()
>
> for ix in range(2):
>     polygons.InsertNextCell(nPoints)
>     scalars.InsertNextValue(float(ix))
>     for iTheta in range(nPoints):
>         polygons.InsertCellPoint(ix*nPoints+iTheta)
>
> ix=0
> for iTheta in range(nPoints):
>     polygons.InsertNextCell(4)
>     scalars.InsertNextValue(0.5)
>     polygons.InsertCellPoint(ix*nPoints+iTheta)
>     polygons.InsertCellPoint(ix*nPoints+(iTheta+1)%nPoints)
>     polygons.InsertCellPoint((ix+1)*nPoints+(iTheta+1)%nPoints)
>     polygons.InsertCellPoint((ix+1)*nPoints+iTheta)
>
> cylinder = vtkPolyData()
> cylinder.SetPoints(pointData)
> cylinder.SetPolys(polygons)
> cylinder.GetCellData().SetScalars(scalars)
>
> #
> #visualize
> #
> tabs = True#False
> mainWindow = QtGui.QMainWindow()
>
> if tabs:
>     tabWidget = QtGui.QTabWidget(mainWindow)
>     mainWindow.setCentralWidget(tabWidget)
>     frameWidget = QtGui.QFrame(mainWindow)
>     hbox = QtGui.QHBoxLayout()
>     frameWidget2 = QtGui.QFrame(mainWindow)
>     hbox2 = QtGui.QHBoxLayout()
>     iren = QVTKRenderWindowInteractor(frameWidget)
>     iren2 = QVTKRenderWindowInteractor(frameWidget2)
> else:
>     frameWidget = QtGui.QFrame(mainWindow)
>     hbox = QtGui.QHBoxLayout()
>     mainWindow.setCentralWidget(frameWidget)
>     iren = QVTKRenderWindowInteractor(frameWidget)
>     iren2 = QVTKRenderWindowInteractor(frameWidget)
>
> iren.Initialize()
> iren2.Initialize()
>
> cylinderMapper = vtkPolyDataMapper()
> cylinderMapper.SetInput(cylinder)
> cylinderMapper.SetScalarRange(0,1)
>
> cylinderActor = vtkActor()
> cylinderActor.SetMapper(cylinderMapper)
>
> renderer = vtkRenderer()
> renderer.AddActor(cylinderActor)
>
> renderer2 = vtkRenderer()
> renderer2.AddActor(cylinderActor)
>
> renWin = iren.GetRenderWindow()
> renWin.AddRenderer(renderer)
>
> renWin2 = iren2.GetRenderWindow()
> renWin2.AddRenderer(renderer2)
>
> if tabs:
>     hbox.addWidget(iren)
>     frameWidget.setLayout(hbox)
>     hbox2.addWidget(iren2)
>     frameWidget2.setLayout(hbox2)
>     tabWidget.addTab(frameWidget,"Cylinder 1")
>     tabWidget.addTab(frameWidget2,"Cylinder 2")
> else:
>     hbox.addWidget(iren)
>     hbox.addWidget(iren2)
>     frameWidget.setLayout(hbox)
>
> mainWindow.show()
>
> #iren.show()
> #iren2.show()
> #app.exec_()
> #iren.show()
> #iren2.show()
> #app.exec_()
> sys.exit(app.exec_())
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: 
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list