将 vtkResliceImageViewer 或 vtkImageViewer2 与 Python3+PyQt5 结合使用

Using vtkResliceImageViewer or vtkImageViewer2 with Python3+PyQt5

我已经为 vtkImageViewer 编写了工作示例:

但是任何图像都不是用 vtkImageViewer2 或 vtkResliceImageViewer 渲染的。已找到基于 PyQt4+Python2.7 的示例,但也无法获得渲染图像(可能是因为库版本错误)。

Python 中是否有这些 类 的示例?

import sys
import vtk
from PyQt5 import QtCore, QtGui
from PyQt5 import QtWidgets

from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)

        self.frame = QtWidgets.QFrame()
        self.vl = QtWidgets.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
        self.vl.addWidget(self.vtkWidget)

        pathDicomDir = "/path/to/dicom/data"
        reader = vtk.vtkDICOMImageReader()
        reader.SetDirectoryName(pathDicomDir)
        reader.Update()

        self.viewer = vtk.vtkImageViewer()
        # self.viewer = vtk.vtkImageViewer2()
        # self.viewer = vtk.vtkResliceImageViewer()
        self.viewer.SetInputData(reader.GetOutput())

        self.viewer.SetupInteractor(self.vtkWidget)
        self.viewer.SetRenderWindow(self.vtkWidget.GetRenderWindow())
        self.viewer.Render()
        self.frame.setLayout(self.vl)
        self.setCentralWidget(self.frame)

        self.show()


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    sys.exit(app.exec_())        

只需使用

self.viewer = vtk.vtkImageViewer2()

并添加

self.vtkWidget.Initialize()

之后 self.show()