我为 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_())