本文整理汇总了Python中vtk.qt4.QVTKRenderWindowInteractor.QVTKRenderWindowInteractor.update方法的典型用法代码示例。如果您正苦于以下问题:Python QVTKRenderWindowInteractor.update方法的具体用法?Python QVTKRenderWindowInteractor.update怎么用?Python QVTKRenderWindowInteractor.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vtk.qt4.QVTKRenderWindowInteractor.QVTKRenderWindowInteractor
的用法示例。
在下文中一共展示了QVTKRenderWindowInteractor.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VtkFgBgDisplayWidget
# 需要导入模块: from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor [as 别名]
# 或者: from vtk.qt4.QVTKRenderWindowInteractor.QVTKRenderWindowInteractor import update [as 别名]
class VtkFgBgDisplayWidget(QFrame):
def __init__(self, parent=None):
super(VtkFgBgDisplayWidget, self).__init__(parent)
self.imVtkBg = None
self.imVtkFg = None
self.matrix4x4 = vtk.vtkMatrix4x4()
self.matrix4x4.DeepCopy((
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
))
self.reslice = vtk.vtkImageReslice()
self.reslice.SetOutputDimensionality(3)
self.reslice.SetResliceAxes(self.matrix4x4)
self.reslice.SetInterpolationModeToLinear()
self.setupVtkRendering()
def setupVtkRendering(self):
self.vtkWidget = QVTKRenderWindowInteractor(self)
self.ren = vtk.vtkRenderer()
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
self.ren.ResetCamera()
self.ren.GetActiveCamera().ParallelProjectionOn()
self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
# layout
vlayout = QVBoxLayout()
vlayout.addWidget(self.vtkWidget)
self.setLayout(vlayout)
def initialize(self):
self.iren.Initialize()
@staticmethod
def convertNpyToVtk(imgNpy):
assert(imgNpy.dtype == np.uint8)
nx, ny, nz = imgNpy.shape
dataImporter = vtk.vtkImageImport()
dataString = imgNpy.tostring(order='F')
dataImporter.CopyImportVoidPointer(dataString, len(dataString))
dataImporter.SetDataScalarTypeToUnsignedChar()
dataImporter.SetNumberOfScalarComponents(1)
dataImporter.SetDataExtent(0, nx-1, 0, ny-1, 0, nz-1)
dataImporter.SetWholeExtent(0, nx-1, 0, ny-1, 0, nz-1)
dataImporter.Update()
return dataImporter.GetOutput()
def setMatrix(self, matrix):
if matrix is not None:
assert(matrix.shape == (4, 4))
self.setMatrixTuple(tuple(matrix.flatten()))
def setMatrixTuple(self, matrix):
if matrix is not None:
assert(len(matrix) == 16)
self.matrix4x4.DeepCopy(matrix)
def render(self):
# self.ren.Render()
self.ren.ResetCamera()
def setDirection(self, direction):
if direction == 0:
# X-Y plane
self.ren.GetActiveCamera().SetPosition(0, 0, -1)
self.ren.GetActiveCamera().SetFocalPoint(0, 0, 0)
self.ren.GetActiveCamera().SetViewUp(-1, 0, 0)
elif direction == 1:
# X-Z plane
self.ren.GetActiveCamera().SetPosition(0, -1, 0)
self.ren.GetActiveCamera().SetFocalPoint(0, 0, 0)
self.ren.GetActiveCamera().SetViewUp(0, 0, -1)
elif direction == 2:
# Y-Z plane
self.ren.GetActiveCamera().SetPosition(-1, 0, 0)
self.ren.GetActiveCamera().SetFocalPoint(0, 0, 0)
self.ren.GetActiveCamera().SetViewUp(0, 0, -1)
def update(self):
self.vtkWidget.update()
super(VtkFgBgDisplayWidget, self).update()