I have the following code
class MyInteractorStyle(vtkInteractorStyleTerrain):
def __init__(self, renderer):
self.SetCurrentRenderer(renderer)
self.AddObserver("MouseMoveEvent", self.mouse_move_event)
def mouse_move_event(self, obj, event):
# Get the interactor
iren = self.GetInteractor()
if iren is None: return
dx = iren.GetEventPosition()[0] - iren.GetLastEventPosition()[0];
dy = iren.GetEventPosition()[1] - iren.GetLastEventPosition()[1];
camera = self.GetCurrentRenderer().GetActiveCamera()
camera.SetRoll(0)
screenSize = iren.GetRenderWindow().GetSize()
# Yaw changes in a negative direction but the pitch is correct
camera.Yaw(-float(dx) / float(screenSize[0]) * 360 * 2.0);
camera.Pitch(float(dy) / float(screenSize[1]) * 180 / 2.0);
# Update the clipping range of the camera
self.GetCurrentRenderer().ResetCameraClippingRange()
# render
self.GetCurrentRenderer().GetRenderWindow().Render()
return
However everytime I move the mouse, I get the following error:
Input In [4], in MyInteractorStyle.mouse_move_event(self, obj, event)
—> 25 camera = self.GetCurrentRenderer().GetActiveCamera()
AttributeError: ‘NoneType’ object has no attribute ‘GetActiveCamera’
I pass a renderer whenever I initialize an instance of MyInteractorStyle