当前位置: 首页>>代码示例>>Python>>正文


Python QVTKRenderWindowInteractor.update方法代码示例

本文整理汇总了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()
开发者ID:lirenzhucn,项目名称:ManualRegistrationTool,代码行数:85,代码来源:ManualRegistrationTool.py


注:本文中的vtk.qt4.QVTKRenderWindowInteractor.QVTKRenderWindowInteractor.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。