我需要在 PyQt 应用程序中集成 VTK 可视化。但是,当我将模型放入 QVTKRenderWindowInteractor 时,显示会显示一些不想要的透明效果(见下图)。无论我尝试加载什么,这都会发生在表面或点云上。
有没有办法在 QVTKRenderWindowInteractor 中实现正确的表示?
第一张图片是来自 vtk.vtkConeSource()
的锥体.
第二张图片是cturtle.pcd PCL 测试中的点云。
左:没有 QVTKRenderWindowInteractor。 右:使用 QVTKRenderWindowInteractor
我附上问题的示例代码以供复制。
这是没有Qt的代码:
#!/usr/bin/env python
import vtk
from vtk.util.colors import tomato
"""This simple example shows how to do basic rendering and pipeline creation."""
cone = vtk.vtkConeSource()
cone.SetResolution(8)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
coneActor.GetProperty().SetColor(tomato)
coneActor.RotateX(30.0)
coneActor.RotateY(-45.0)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren.AddActor(coneActor)
ren.SetBackground(0.1, 0.2, 0.4)
iren.Initialize()
ren.ResetCamera()
ren.GetActiveCamera().Zoom(1.5)
renWin.Render()
iren.Start()
这是 QVTKRenderWindowInteractor 中的等效显示:
#!/usr/bin/env python
import vtk
from PyQt5.QtWidgets import QApplication
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vtk.util.colors import tomato
"""A simple example that uses the QVTKRenderWindowInteractor class."""
app = QApplication(['QVTKRenderWindowInteractor'])
cone = vtk.vtkConeSource()
cone.SetResolution(8)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
coneActor.GetProperty().SetColor(tomato)
coneActor.RotateX(30.0)
coneActor.RotateY(-45.0)
ren = vtk.vtkRenderer()
widget = QVTKRenderWindowInteractor()
widget.GetRenderWindow().AddRenderer(ren)
ren.AddActor(coneActor)
ren.SetBackground(0.1,0.2,0.4)
widget.Initialize()
ren.ResetCamera()
ren.GetActiveCamera().Zoom(1.5)
widget.GetRenderWindow().Render()
widget.Start()
widget.show()
app.exec_()
最佳答案
尝试了几件事后,我得到了以下解决方案Merge Request .
我使用 QGLWidget 作为 QVTKRenderWindowInteractor 的基类,而不是 QWidget。这个改动是因为据说QWidget有时会导致渲染问题。
为此,我在导入 QVTKRenderWindowInteractor 之前放置了以下代码:
import vtk.qt
vtk.qt.QVTKRWIBase = "QGLWidget"
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
为了使用 QGLWidget,我必须安装以下软件包:
sudo apt-get install python3-pyqt5.qtopengl
关于python-3.x - VTK 渲染在 PyQt 中无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51357630/