I am using pyvista to visualize stl file. To get point information, i used below code to achieve this
import pyvista as pv
p = pv.Plotter()
mesh = pv.read(filename)
p.add_mesh(mesh)
def callback(x, y) :return
p.enable_point_picking(callback=callback)
p.show()
I could pick point by keeping cursor on point and press key 'P'.
I want this function without key press by clicking on mouse. is it possible?
I got one solution for this action. as pyvista is base from vtk, i used vtk function and it is working fine. if anyone found better solution, please post.
mouse=pv._vtk.vtkInteractorStyleTrackballCamera()
mouse.SetDefaultRenderer(plotter.ren_win.GetRenderers().GetFirstRenderer())
plotter.SetInteractorStyle(mouse)
def clicked(m,event):
try:
modifiers = QApplication.keyboardModifiers()
if modifiers==QtCore.Qt.ControlModifier:pass
else:
clickPos = m.GetInteractor().GetEventPosition()
picker = pv._vtk.vtkPointPicker()
picker.Pick(clickPos[0], clickPos[1],0, m.GetDefaultRenderer())
actor=picker.GetActor()
if actor!=None:print(actor)
m.OnLeftButtonDown()
except Exception as e:print(e)
mouse.AddObserver("LeftButtonPressEvent", clicked)
You can use the track_click_position
method of pyvista Plotter and still use your callback function as above. The documentation is here .
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.