[vtkusers] Mac/Cocoa/Qt "invalid drawable"
Chris Kees
Christopher.E.Kees at usace.army.mil
Tue May 5 13:25:52 EDT 2009
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_())
More information about the vtkusers
mailing list