def adjustPose(self): if(self.vtk_widget.bPoseAdjustment): self.vtk_widget.bPoseAdjustment = False self.vtk_widget.renderer.RemoveActor(self.vtk_widget.AxesActor) self.vtk_widget.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) vtkpoints = self.vtk_widget.polydata_show.GetPoints() pm = vtk_to_numpy(vtkpoints.GetData()) M=self.vtk_widget.actor.GetUserMatrix() transform=self.vtkTransform2Numpy(M) pm = self.pmTransForm(pm,transform) self.AddPmAddShow(pm) mat = np.eye(4) vtkMatic = self.Numpy2vtkTransform(mat) self.vtk_widget.actor.SetUserMatrix(vtkMatic) if(self.vtk_widget.bSetScalarColorZ): self.vtk_widget.actionscalarColorZ() self.vtk_widget.actionscalarColorZ() else: if(self.vtk_widget.bShowFrame): self.ShowFrame() self.vtk_widget.bPoseAdjustment = True center=self.vtk_widget.actor.GetCenter() mat = np.eye(4) mat[0:3,3]=center vtkMatic = self.Numpy2vtkTransform(mat) self.vtk_widget.AxesActor.SetUserMatrix(vtkMatic) dim = self.vtk_widget.actor.GetBounds() self.vtk_widget.AxesActor.SetTotalLength(dim[1]-dim[0], dim[3]-dim[2], dim[5]-dim[4]) self.vtk_widget.renderer.AddActor(self.vtk_widget.AxesActor) self.vtk_widget.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballActor()) self.vtk_widget.render_window.Render()
时间: 2024-04-05 14:31:01 浏览: 119
step08.rar_site:www.pudn.com_vtk
这是一段使用 VTK 库进行三维模型姿态调整的 Python 代码。在函数 `adjustPose` 中,如果 `vtk_widget.bPoseAdjustment` 为真,则将其设置为假,移除 `vtk_widget.renderer` 中的 `vtk_widget.AxesActor`,并将交互器样式设置为 `vtk.vtkInteractorStyleTrackballCamera()`。然后,将 `vtk_widget.polydata_show` 中的点转换为 numpy 数组,通过 `self.pmTransForm` 函数将其与 `transform` 矩阵相乘得到新的点,再将新的点添加到 `vtk_widget.polydata_show` 中,并将 `self.vtk_widget.actor` 的用户矩阵设置为单位矩阵。如果 `vtk_widget.bSetScalarColorZ` 为真,则调用两次 `self.vtk_widget.actionscalarColorZ()` 函数。如果 `vtk_widget.bPoseAdjustment` 为假,则显示坐标轴,将 `vtk_widget.bPoseAdjustment` 设置为真,获取 `self.vtk_widget.actor` 的中心点坐标,将 `vtk_widget.AxesActor` 的用户矩阵设置为该中心点坐标,调整 `vtk_widget.AxesActor` 的尺寸,最后将 `vtk_widget.AxesActor` 添加到 `vtk_widget.renderer` 中。最后,调用 `vtk_widget.render_window.Render()` 函数显示渲染结果。
阅读全文