[vtkusers] Depth peeling and Qt
Ignacio Fernández Galván
jellby at yahoo.com
Fri Jan 12 09:50:37 EST 2018
On 12/01/18, at 14:48, Sankhesh Jhaveri wrote:
>
> In general, depth peeling is known to work with VTK and Qt5.
> Are you using the QVTKOpenGLWidget
> <https://www.vtk.org/doc/nightly/html/classQVTKOpenGLWidget.html>?
> Could you post your modifications somewhere for us to see?
>
I'm not using QVTKOpenGLWidget directly, I'm just using
QVTKRenderWindowInteractor, as in
https://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt
My modified EmbedPyQt.py:
#==============================================
#!/usr/bin/env python
import sys
import vtk
from PyQt5.QtWidgets import QApplication, QFrame, QPushButton,
QVBoxLayout, QMainWindow, QFrame
from QVTKRenderWindowInteractor_5 import QVTKRenderWindowInteractor
class MainWindow(QMainWindow):
def __init__(self, parent = None):
QMainWindow.__init__(self, parent)
self.frame = QFrame()
self.vl = QVBoxLayout()
self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
self.vl.addWidget(self.vtkWidget)
self.ren = vtk.vtkRenderer()
self.ren.UseDepthPeelingOn()
self.ren.SetOcclusionRatio(0.01)
self.ren.SetMaximumNumberOfPeels(20)
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
# Create source
source = vtk.vtkSphereSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.5)
self.ren.AddActor(actor)
self.ren.ResetCamera()
self.frame.setLayout(self.vl)
self.setCentralWidget(self.frame)
self.show()
self.iren.Initialize()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
print window.ren.GetLastRenderingUsedDepthPeeling()
sys.exit(app.exec_())
#==============================================
and QVTKRenderWindowInteractor_5.py is the same as
https://gitlab.kitware.com/vtk/vtk/blob/1cea85a8d40114374c329c8d26d92c4356df678a/Wrapping/Python/vtk/qt5/QVTKRenderWindowInteractor.py
with just a couple of changes:
$ diff -c QVTKRenderWindowInteractor.py QVTKRenderWindowInteractor_5.py
*** QVTKRenderWindowInteractor.py 2018-01-12 14:59:18.194879513 +0100
--- QVTKRenderWindowInteractor_5.py 2018-01-12 15:32:09.765069627 +0100
***************
*** 164,169 ****
--- 164,171 ----
self._RenderWindow = rw
else:
self._RenderWindow = vtk.vtkRenderWindow()
+ self._RenderWindow.SetMultiSamples(0)
+ self._RenderWindow.SetAlphaBitPlanes(1)
WId = self.winId()
***************
*** 366,372 ****
self._Iren.KeyReleaseEvent()
def wheelEvent(self, ev):
! if ev.delta() >= 0:
self._Iren.MouseWheelForwardEvent()
else:
self._Iren.MouseWheelBackwardEvent()
--- 368,374 ----
self._Iren.KeyReleaseEvent()
def wheelEvent(self, ev):
! if ev.angleDelta().y() >= 0:
self._Iren.MouseWheelForwardEvent()
else:
self._Iren.MouseWheelBackwardEvent()
More information about the vtkusers
mailing list