I’m trying to add an Observer to a class that inherit from vtkInteractorStyleRubberBandPick.
My goal is to trigger a function when I finished to make a bouding box on the screen with the key ‘r’.
The issue is I don’t find a way to trigger my function when I release the left button.
I try to use the EndPickEvent but I never pass into the EndPickEventfunc
When the window opens, I press the ‘r’ key in order to select a square on the window, but when I finished to select the square (left mouse is released) I do not enter in the function self.EndPickEventfunc
import vtk
class MouseInteractorHighLightActor(vtk.vtkInteractorStyleRubberBandPick):
def __init__(self, parent=None):
self.AddObserver(vtk.vtkCommand.EndPickEvent, self.EndPickEventfunc)
return
def EndPickEventfunc(self, obj, event):
print('I was here!')
clickPos = self.GetInteractor().GetEventPosition()
# A renderer and render window
renderer = vtk.vtkRenderer()
renderer.SetBackground(.3, .4, .5)
renwin = vtk.vtkRenderWindow()
renwin.AddRenderer(renderer)
# An interactor
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renwin)
# add the custom style
style = MouseInteractorHighLightActor()
style.SetDefaultRenderer(renderer)
interactor.SetInteractorStyle(style)
# Add spheres to play with
for i in range(10):
source = vtk.vtkSphereSource()
source.SetRadius(vtk.vtkMath.Random(.5, 1.0))
source.SetCenter(vtk.vtkMath.Random(-5, 5), vtk.vtkMath.Random(-5, 5), vtk.vtkMath.Random(-5, 5))
source.SetPhiResolution(11)
source.SetThetaResolution(21)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetDiffuseColor(vtk.vtkMath.Random(.4, 1.0), vtk.vtkMath.Random(.4, 1.0), vtk.vtkMath.Random(.4, 1.0))
renderer.AddActor(actor)
# Start
interactor.Initialize()
interactor.Start()