# Making an arcball camera in vtk python

**URL:** https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658
**Category:** Development
**Created:** [April 28, 2021, 9:44pm UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658 "2021-04-28T21:44:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Kiordestruk\_k](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kiordestruk_k/32/3317_2.png) [@Kiordestruk\_k](https://discourse.vtk.org/u/Kiordestruk_k)
#### Post date: [April 28, 2021, 9:44pm UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658/1 "2021-04-28T21:44:46Z")

</div>

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](https://sites.fas.harvard.edu/~lib175/notes_2018/balls-handout.pdf). (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.

```python
    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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [April 29, 2021, 7:47am UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658/2 "2021-04-29T07:47:27Z")

</div>

> [@Kiordestruk\_k](#):
>
> I wonder why this is not already available in VTK ?

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

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](https://gitlab.kitware.com/f3d/f3d/-/blob/master/src/vtkF3DInteractorStyle.cxx#L257)

---

<div class="post-metadata">

### Author: ![Kiordestruk\_k](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kiordestruk_k/32/3317_2.png) [@Kiordestruk\_k](https://discourse.vtk.org/u/Kiordestruk_k)
#### Post date: [April 29, 2021, 8:14am UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658/3 "2021-04-29T08:14:12Z")

</div>

Thank you @mwestphal !

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

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.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [April 29, 2021, 8:42am UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658/4 "2021-04-29T08:42:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [April 29, 2021, 7:38pm UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658/5 "2021-04-29T19:38:49Z")

</div>

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)`.

---

<div class="post-metadata">

### Author: ![Kiordestruk\_k](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kiordestruk_k/32/3317_2.png) [@Kiordestruk\_k](https://discourse.vtk.org/u/Kiordestruk_k)
#### Post date: [April 30, 2021, 7:54am UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658/6 "2021-04-30T07:54:44Z")

</div>

Thank you David

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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [May 1, 2021, 3:45am UTC](https://discourse.vtk.org/t/making-an-arcball-camera-in-vtk-python/5658/7 "2021-05-01T03:45:10Z")

</div>

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.
