[vtkusers] Python Qt4 Vtk (5.8/5.10.1) Ubuntu 12.04

lindeval at dmat.ufrr.br lindeval at dmat.ufrr.br
Sat Jan 5 14:43:07 EST 2013


Try this way, it worked here.


from PyQt4.QtCore import *
from PyQt4.QtGui  import *
import vtk
#from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys
class Ui_MainWindow(QWidget):
    def setupUi(self, MainWindow):
       MainWindow.setObjectName("MainWindow")
       MainWindow.resize(603, 553)
       self.centralWidget = QWidget(MainWindow)
       self.vtkWidget = vtk.QVTKWidget(self.centralWidget)
       self.gridlayout = QGridLayout(self.centralWidget)
       #self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
       self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1)
       MainWindow.setCentralWidget(self.centralWidget)

class SimpleView(QMainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
	self.ui.setupUi(self)
        widget = self.ui.vtkWidget
	self.ren = vtk.vtkRenderer()
        renwin = widget.GetRenderWindow()
	renwin.AddRenderer(self.ren)
        iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
	cube = vtk.vtkCubeSource()
	cube.SetXLength(200)
	cube.SetYLength(200)
	cube.SetZLength(200)
	cube.Update()
	cm = vtk.vtkPolyDataMapper()
	cm.SetInputConnection(cube.GetOutputPort())
	ca = vtk.vtkActor()
	ca.SetMapper(cm)
	self.ren.AddActor(ca)
	self.axesActor = vtk.vtkAnnotatedCubeActor();
	self.axesActor.SetXPlusFaceText('R')
	self.axesActor.SetXMinusFaceText('L')
	self.axesActor.SetYMinusFaceText('H')
	self.axesActor.SetYPlusFaceText('F')
	self.axesActor.SetZMinusFaceText('P')
	self.axesActor.SetZPlusFaceText('A')
	self.axesActor.GetTextEdgesProperty().SetColor(1,1,0)
	self.axesActor.GetTextEdgesProperty().SetLineWidth(2)
	self.axesActor.GetCubeProperty().SetColor(0,0,1)
	self.axes = vtk.vtkOrientationMarkerWidget()
	self.axes.SetOrientationMarker(self.axesActor)
	self.axes.SetInteractor(iren)
	self.axes.EnabledOn()
	self.axes.InteractiveOn()
	self.ren.ResetCamera()
	
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = SimpleView()
    window.show()
    app.exec_() 







----- Mensagem original -----
De: "Niels Linnemann" <ne.linnemann at gmail.com>
Para: vtkusers at vtk.org
Enviadas: Sábado, 5 de Janeiro de 2013 14:39:34 GMT -04:00 Georgetown
Assunto: [vtkusers] Python Qt4 Vtk (5.8/5.10.1) Ubuntu 12.04



Hi 


I've been struggling with this for a while now and don't seem to get any further. 


I have a Win 7 machine running the latest pythonxy release and a CentOS 6.3 machine using python 2.6, PyQt-4.6 and vtk 5.6. 


I'm embedding a VTK render window inside a QFrame. 


This example works on the other two machines. 



from PyQt4 import QtCore, QtGui 


from PyQt4.QtGui import QApplication 

import vtk 

from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor 

import sys 



class Ui_MainWindow(object): 

def setupUi(self, MainWindow): 

MainWindow.setObjectName("MainWindow") 

MainWindow.resize(603, 553) 

self.centralWidget = QtGui.QWidget(MainWindow) 

self.gridlayout = QtGui.QGridLayout(self.centralWidget) 

self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget) 

self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1) 

MainWindow.setCentralWidget(self.centralWidget) 



class SimpleView(QtGui.QMainWindow): 



def __init__(self, parent = None): 

QtGui.QMainWindow.__init__(self, parent) 

self.ui = Ui_MainWindow() 

self.ui.setupUi(self) 

self.ren = vtk.vtkRenderer() 

self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren) 

iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor() 

cube = vtk.vtkCubeSource() 

cube.SetXLength(200) 

cube.SetYLength(200) 

cube.SetZLength(200) 

cube.Update() 

cm = vtk.vtkPolyDataMapper() 

cm.SetInputConnection(cube.GetOutputPort()) 

ca = vtk.vtkActor() 

ca.SetMapper(cm) 

self.ren.AddActor(ca) 

self.axesActor = vtk.vtkAnnotatedCubeActor(); 

self.axesActor.SetXPlusFaceText('R') 

self.axesActor.SetXMinusFaceText('L') 

self.axesActor.SetYMinusFaceText('H') 

self.axesActor.SetYPlusFaceText('F') 

self.axesActor.SetZMinusFaceText('P') 

self.axesActor.SetZPlusFaceText('A') 

self.axesActor.GetTextEdgesProperty().SetColor(1,1,0) 

self.axesActor.GetTextEdgesProperty().SetLineWidth(2) 

self.axesActor.GetCubeProperty().SetColor(0,0,1) 

self.axes = vtk.vtkOrientationMarkerWidget() 

self.axes.SetOrientationMarker(self.axesActor) 

self.axes.SetInteractor(iren) 

self.axes.EnabledOn() 

self.axes.InteractiveOn() 

self.ren.ResetCamera() 

iren.Initialize() 






if __name__ == "__main__": 



app = QApplication(sys.argv) 

window = SimpleView() 

window.show() 
sys.exit(app.exec_()) 


On the Ubuntu machine no window pops up. 
I have 2 machines with very different hardware and same result. 


Commenting the "iren.Initialize()" line will make the window show, but no render. 


I have tried using the built-in ubuntu vtk python wrapping (5.8) package. 
I have compiled both vtk 5.8 and 5.10.1 from source, but same result (removed the default package before). 


The challenge I'm facing is that I get absolutely no error messages or debug info that I can work with. 


I'm on the verge on giving up on Ubuntu on this issue. 


Does anyone have anything I could try before I reformat to another distro? 




_______________________________________________
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