Skip to content

Instantly share code, notes, and snippets.

@fmorency
Created May 4, 2012 18:53
Show Gist options
  • Save fmorency/2596951 to your computer and use it in GitHub Desktop.
Save fmorency/2596951 to your computer and use it in GitHub Desktop.
VTK Qt Python example
"""
A simple example that uses the QVTKRenderWindowInteractor
class.
"""
#from PySide import QtGui
from PyQt4 import QtGui
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import vtk
import sys
if __name__ == '__main__':
# every QT app needs an app
app = QtGui.QApplication(['QVTKRenderWindowInteractor'])
# create the widget
widget = QVTKRenderWindowInteractor()
widget.Initialize()
widget.Start()
# if you dont want the 'q' key to exit comment this.
widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())
ren = vtk.vtkRenderer()
widget.GetRenderWindow().AddRenderer(ren)
cone = vtk.vtkConeSource()
cone.SetResolution(8)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren.AddActor(coneActor)
widget.SetPicker(vtk.vtkPointPicker())
# show the widget
widget.show()
# start event processing
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment