Instalando o ambiente do mini-curso de VTK no MACOSX

  • Instalar o Python 2.7.3
    • Rodar script de setar variaveis de ambiente:
      /Applications/Python\ 2.7/Update\ Shell\ Profile.command
    • Verificar a versão (Precisa retornar “Python 2.7.3”):
      python --version
tar -xzvf vtk-5.10.0.tar.gz

mkdir VTK_cmake
cd VTK_cmake

cmake ../VTK -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DVTK_USE_COCOA=ON -DVTK_USE_QT=ON -DVTK_WRAP_PYTHON=ON -DVTK_QT_USE_WEBKIT=OFF -DPYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/2.7/bin/python -DPYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib -DPYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7

make -j4
sudo make install

cd Wrapping/Python
python setup.py install
  • Salvar os exemplos (clicar no nome do arquivo, abaixo):
u4e1.py
import vtk
 
source = vtk.vtkConeSource()
 
mapper = vtk.vtkDataSetMapper()
mapper.SetInput(source.GetOutput())
 
actor = vtk.vtkActor()
actor.SetMapper(mapper)
 
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
 
window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)
 
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
interactor.Initialize()
interactor.Start()
u7e1.py
import vtk, sys
 
from PyQt4 import QtGui
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
 
class MainWindow(QtGui.QMainWindow):
 
    def __init__(self):
        super(MainWindow, self).__init__()
 
        self.createActions()
        self.createMenus()
        self.createQVTKRenderWidget()
        self.setWindowTitle('Basic Example To Use Python, Qt And VTK')
        self.resize(640, 480)
 
    def createActions(self):
        self.coneAct = QtGui.QAction('C&one', self, checkable=True, checked=True, triggered=self.coneSource)
        self.cubeAct = QtGui.QAction('C&ube', self, checkable=True, triggered=self.cubeSource)
        self.cylinderAct = QtGui.QAction('C&ylinder', self, checkable=True, triggered=self.cylinderSource)
        self.sphereAct = QtGui.QAction('S&phere', self, checkable=True, triggered=self.sphereSource)
 
        sourcesActGroup = QtGui.QActionGroup(self)
        sourcesActGroup.addAction(self.coneAct)
        sourcesActGroup.addAction(self.cubeAct)
        sourcesActGroup.addAction(self.cylinderAct)
        sourcesActGroup.addAction(self.sphereAct)
 
    def createMenus(self):
        sourcesMenu = self.menuBar().addMenu('&Sources')
        sourcesMenu.addAction(self.coneAct)
        sourcesMenu.addAction(self.cubeAct)
        sourcesMenu.addAction(self.cylinderAct)
        sourcesMenu.addAction(self.sphereAct)
 
    def coneSource(self):
        source = vtk.vtkConeSource()
        source.SetResolution(50)
 
        self.mapper.SetInput(source.GetOutput())
        self.actor.GetProperty().SetColor(1, 0, 0)
 
    def cubeSource(self):
        self.mapper.SetInput(vtk.vtkCubeSource().GetOutput())
        self.actor.GetProperty().SetColor(0, 1, 0)
 
    def cylinderSource(self):
        source = vtk.vtkCylinderSource()
        source.SetResolution(50)
 
        self.mapper.SetInput(source.GetOutput())
        self.actor.GetProperty().SetColor(0, 0, 1)
 
    def sphereSource(self):
        source = vtk.vtkSphereSource()
        source.SetPhiResolution(25)
        source.SetThetaResolution(50)
 
        self.mapper.SetInput(source.GetOutput())
        self.actor.GetProperty().SetColor(1, 1, 0)
 
    def createQVTKRenderWidget(self):
        self.mapper = vtk.vtkDataSetMapper()
 
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
 
        self.coneSource()
 
        renderer = vtk.vtkRenderer()
        renderer.AddActor(self.actor)
 
        interactor = QVTKRenderWindowInteractor(self)
        interactor.GetRenderWindow().AddRenderer(renderer)
        interactor.Initialize()
        interactor.Start()
 
        self.setCentralWidget(interactor)
 
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())
  • Rodar o exemplo
    python u4e1.py
  • Rodar o exemplo
    python u7e1.py

QR Code: URL of current page
QR Code: URL of current page howto:python_qt_pyqt_vtk_no_macosx (generated for current page)