Making an arcball camera in vtk python

Hello,

I am trying to modify the Rotate() function of vtkInteractorStyleTrackballCamera in order to obtain an arcball camera instead of a trackball camera.
The advantage of arcball camera is path invariance, as described here. (I wonder why this is not already available in VTK ?)

I am using the Python vtk wrapper. (vtk version : 9.0.1)

My problem is that I cannot access the method Rotate() of vtkInteractorStyleTrackballCamera.
I tried to subclass vtkInteractorStyleTrackballCamera and making mock methods to verify that the methods are working as expected.

    class subclass(vtk.vtkInteractorStyleTrackballCamera):
        def aMethodFromParent(self):
            print('aMethodFromParent has been called !')
            (return) super().aMethodFromParent()

It works for methods like OnLeftButtonDown, OnMouseMove, GetState.
It does not for methods like Rotate, OnStartRotate, OnStartPan. (nothing happens when, for example, I rotate the view in my 3D viewport)

Do you know what I am missing here ?

Thanks

Because someone need to add it, you’d be very welcome to do so :slight_smile:

Take a look at this for en example how to override rotation in a interactor style:
https://gitlab.kitware.com/f3d/f3d/-/blob/master/src/vtkF3DInteractorStyle.cxx#L257

1 Like

Thank you @mwestphal !

If I succeed to make it work, I would be happy to contribute to the C++ codebase :slight_smile:.

However I would like to make it work first in vtk python, and the link you provided is a C++ implementation.

I tried to make the same thing but in python. In Python the overriding of Rotate seems not to be working and I cannot figure out why. In fact, Rotate method seems to be never called, even when rotating the view in the 3D viewer. (As I mentionned, I can check that methods like OnLeftButtonDown are called when left clicking on the viewer)

I guess it has to do with the Python wrapper.

I think that it should be supported but unsure why it is not working.

The wrappers don’t automatically hook virtual method overrides from C++ through to Python. In the cases where it works, it works because the method has been set as a observer for a VTK event via AddObserver(event, method).

2 Likes

Thank you David

Ok it makes sense. Is it still possible to override method Rotate of vtkInteractorStyleTrackballCamera in Python by adding a specific observer ?

Edit: Before the edit, I had proposed using OnRotate() since it’s associated with an event. It turns out Rotate() and OnRotate() are very different things. The OnRotate() method is for catching multi-touch events, when someone puts two fingers on a touchscreen and does a “rotate” gesture. So it’s totally unrelated to the issue at hand.