I’m trying to write a rubber band picker using the vtk Python bindings on Windows, VTK 8.2.
I based my code off of one of the C++ examples, by creating my own Interactor style, inheriting from vtkInteractorStyleRubberBandPick, handling the LeftButtonReleaseEvent and then putting my selection code into the event handler as shown below.
Picking is supposed to be enabled by vtkInteractorStyleRubberBandPick if the ‘r’ key is pressed before the LMB down/Drag/Release gesture
My problem is that my handler gets called for every left mouse button release event, not just the ones following the ‘r’ key being pressed. In the C++ example, this is handled by checking the value of
vtkInteractorStyleRubberBandPick.CurrentMode
But this property doesn’t seem to be available via Python.
So - am I missing something? Is there an established pattern for this type of behavior when using Python or do I have handle the ‘r’ key press myself and set a state on my interactor style?
Thanks in advance for any guidance you can offer.
Doug
class InteractorStyle(vtk.vtkInteractorStyleRubberBandPick):
def __init__(self, parent = None):
self.AddObserver("LeftButtonReleaseEvent",self.OnLeftButtonUpEvent)
def OnLeftButtonUpEvent(self,obj,event):
self.OnLeftButtonUp()
print("Left button Up Event")
#if self.CurrentMode == == VTKISRBP_SELECT:
print("Target type is ", type(self.Points))
print("Number of points in target = ", self.Points.GetNumberOfPoints())
print("Number of cells in target = ", self.Points.GetNumberOfCells())
frustum = self.GetInteractor().GetPicker().GetFrustum()
print("Number of planes = ", frustum.GetNumberOfPlanes())
plane_normals = frustum.GetNormals()
plane_points = frustum.GetPoints()
for i in range(6):
print(plane_normals.GetTuple(i))
print(plane_points.GetPoint(i))
extract_geometry = vtk.vtkExtractGeometry()
extract_geometry.SetImplicitFunction(frustum)
if vtk.VTK_MAJOR_VERSION <= 5:
extract_geometry.SetInput(self.Points)
else:
extract_geometry.SetInputData(self.Points)
extract_geometry.Update()
selected = extract_geometry.GetOutput()
print("selected type is ", type(selected))
print("Number of points in selected = ", selected.GetNumberOfPoints())
print("Number of cells in selected = ", selected.GetNumberOfCells())
return