Python VTK boxwidget RotationHandler

2024-05-26 00:33:19 发布

您现在位置:Python中文网/ 问答频道 /正文

到目前为止,我所看到的是,有一个小部件显示了一个带有6个手柄的3D边界框。 Python Boxwidget Exampler

我想通过单击[cntrl]+拖动控制柄来平移长方体,并通过单击[shift]+拖动控制柄来仅绕y轴旋转

每一次交互都应该只发生在场景中的盒子上,而不发生其他任何事情

我必须覆盖box小部件功能吗? 或者我应该修改哪个确切的函数。我应该添加一个交互服务器吗

不知何故,在最初的2到3次交互中,手柄的尺寸越来越大,有人遇到过同样的问题吗

编辑:

enter image description here

这是我目前的代码:

                self.boxWidget = vtk.vtkBoxWidget()
                self.boxWidget.SetInteractor(self.renderWindowInteractor)
                self.boxWidget.SetProp3D(self.boxes_3d_actors[obj_cls_name][0])
                self.boxWidget.SetPlaceFactor(1.0)
                self.boxWidget.PlaceWidget()

其中self.box_3d_actors是由多段线组成的vtk.vtkAssembly()数组

现在我需要以某种方式覆盖句柄的交互事件。最好是创建一个继承的vtkBoxwidget类,该类具有自己的交互功能


Tags: self功能boxshift部件场景actors边界
1条回答
网友
1楼 · 发布于 2024-05-26 00:33:19

您必须根据需要设置Interactior。下面是普通平移和旋转的代码

#Setting Renderer
renderer = vtk.vtkRenderer()
renderer.AddActor(self.boxes_3d_actors[obj_cls_name][0])
renwin = vtk.vtkRenderWindow()
renwin.AddRenderer(renderer)

# Setting interactor
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renwin)

boxWidget = vtk.vtkBoxWidget()
boxWidget.SetInteractor(interactor)
boxWidget.SetProp3D(self.boxes_3d_actors[obj_cls_name][0])
boxWidget.SetPlaceFactor(1.0)
boxWidget.PlaceWidget()

要设置对象的旋转和平移,您可以看到以下documnetations链接: https://vtk.org/Wiki/VTK/Examples/Python/Interaction/MouseEventshttps://vtk.org/doc/nightly/html/classvtkCamera.html

相关问题 更多 >