简体   繁体   中英

Python - VTK boxwidget rotation-handlers

what I have seen so far, is that there is a widget which shows a 3D-bounding-box with 6-handles. Python Boxwidget Exampler

I would like translate the box by clicking [cntrl]+draging the handle and rotate only around the y-axis by clicking [shift]+draging the handle...

Every interaction should just only occur to the box in the scene and nothing else.

Do I have to overwrite the box-widget functions? Or which exact function should I modify. Should I add an interaction obeserver?

And somehow - the handles are getting larger in size with the first 2 or 3 interactions, did someone experience the same issue?

EDIT:

在此处输入图片说明

That is my current code:

                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()

Where self.boxes_3d_actors is an array of vtk.vtkAssembly(), which consist of polylines.

Now I need somehow to overwrite the interaction event of the handles. The best would be to create an inherited class of vtkBoxwidget with own interaction functions.

You have to set Interactor according to your requirement. for common pan and rotate below is the code.

#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()

For setting the rotation and translate of object you can see the following links of documnetations: https://vtk.org/Wiki/VTK/Examples/Python/Interaction/MouseEvents https://vtk.org/doc/nightly/html/classvtkCamera.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM