# Disable interaction with camera

**URL:** <https://discourse.slicer.org/t/disable-interaction-with-camera/12586>\
**Category:** Development\
**Created:** [July 16, 2020, 10:02pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586 "2020-07-16T22:02:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eloi\_gbrt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eloi_gbrt/32/7175_2.png) [@Eloi\_gbrt](https://discourse.slicer.org/u/Eloi_gbrt)\
**Post date:** [July 16, 2020, 10:02pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/1 "2020-07-16T22:02:24Z")

</div>

Hello everyone,  
So I’m developping a module in python and at some point i need to move the camera around. For that I need to disable all the interaction that moves the camera around in the 3D view.  
My solution for now is to reach the interactor and to delete it until the module does not need it anymore. I use those few lines to achieve it :

#Copy original interactor  
self.interactorStyle = slicer.app.layoutManager().threeDWidget(0).threeDView().interactorStyle()  
self.interactor = self.interactorStyle.GetInteractor()  
#Delete the interactor  
self.interactorStyle.SetInteractor(None)  
#Reset the interactor  
self.interactorStyle.SetInteractor(self.interactor)

It works for now but i’m afraid that it could interfere with other modules or cause problem with slicer directly.  
I tried to find some other functions on vtkInteractorStyle but none seemed to work as i wanted.

Is there a way to achieve what i did directly in slicer or with a function i would have missed ?

Thank you.  
Eloi

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 16, 2020, 10:31pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/2 "2020-07-16T22:31:29Z")

</div>

There is a proper interface to customize what mouse gestures you enable on every view. Here is an example in the script repository for slice views that works the same way for 3D views with small adjustments: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Disable\_certain\_user\_interactions\_in\_slice\_views](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Disable_certain_user_interactions_in_slice_views)

---

<div class="post-metadata">

**Author:** ![Eloi\_gbrt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eloi_gbrt/32/7175_2.png) [@Eloi\_gbrt](https://discourse.slicer.org/u/Eloi_gbrt)\
**Post date:** [July 17, 2020, 11:01pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/3 "2020-07-17T23:01:32Z")

</div>

Yes, i saw this example and tried to adapt it but i did not find a documentation to use SetActionEnabled().

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 17, 2020, 11:26pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/4 "2020-07-17T23:26:19Z")

</div>

If you search for “SetActionEnabled” in Slicer’s source code or API documentation to find the usable values:

> <https://github.com/Slicer/Slicer/blob/47deb76d7556e40de4e25e585c4b24a63a153da5/Libs/MRML/DisplayableManager/vtkMRMLSliceViewInteractorStyle.h#L69-L82>

---

<div class="post-metadata">

**Author:** ![atracsys-sbt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atracsys-sbt/32/11434_2.png) [@atracsys-sbt](https://discourse.slicer.org/u/atracsys-sbt)\
**Post date:** [September 8, 2021, 2:54pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/5 "2021-09-08T14:54:10Z")

</div>

Sorry to re-open this topic, but I don’t undestand the proposed solution since `vtkMRMLThreeDViewInteractorStyle` has no `SetActionEnabled` function.  
Also, `vtkMRMLThreeDViewInteractorStyle::EnabledOff()` and `vtkMRMLThreeDViewInteractorStyle::Off()` do not deactivate interaction with the 3D scene.  
So, how does one disable interaction in a 3D view ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 8, 2021, 2:59pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/6 "2021-09-08T14:59:21Z")

</div>

`SetActionEnabled` was added at the time when keyboard&mouse gestures were hardcoded and we needed a way to disable some. Now you can add/remove/edit all keyboard&mouse gestures - see for example [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#customize-keyboard-mouse-gestures-in-viewers). `SetActionEnabled` method is only kept for backward compatibility, but I would not recommend using them anymore.

---

<div class="post-metadata">

**Author:** ![atracsys-sbt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atracsys-sbt/32/11434_2.png) [@atracsys-sbt](https://discourse.slicer.org/u/atracsys-sbt)\
**Post date:** [September 8, 2021, 3:20pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/7 "2021-09-08T15:20:50Z")

</div>

I see, but if I were to follow this example, disabling all interaction would require to set all events of the camerawidget to `vtk.vtkWidgetEvent.NoEvent`, right ? Given the number of interactions possible in vtkCommand, this will be quite long (unless I could loop on it). Isn’t there a simpler way ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 8, 2021, 3:26pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/8 "2021-09-08T15:26:22Z")

</div>

In general, it is not expected that a module disables all other modules. You are always expected to know what features you disable and why. You might be able to implement some simpler hacks, such as adding an observer to the interactor for all interaction events with very high priority that consumes all the events (as it is done in [Segment Editor](https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Segmentations/Widgets/qMRMLSegmentEditorWidget.cxx#L2625-L2727), which was implemented before the widget infrastructure was in place).

Why do you need to disable all interactions?

---

<div class="post-metadata">

**Author:** ![atracsys-sbt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atracsys-sbt/32/11434_2.png) [@atracsys-sbt](https://discourse.slicer.org/u/atracsys-sbt)\
**Post date:** [September 8, 2021, 3:31pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/9 "2021-09-08T15:31:50Z")

</div>

I’m displaying a frustum in 3D from a very specific point of view, so I don’t want the user to be able to move the camera and change that point of view.  
Also, I’m using parallel projection for the camera and mouse-wheel zooming turns it off for some reason (if it’s a bug I’ll open a new separate ticket).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 8, 2021, 3:43pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/10 "2021-09-08T15:43:04Z")

</div>

> I’m displaying a frustum in 3D from a very specific point of view, so I don’t want the user to be able to move the camera and change that point of view.

Then disabling camera translation & rotation may make sense. You may still want to allow right-click menu, etc. so it makes sense not to disable all interactions.

> [@atracsys-sbt](#):
>
> Also, I’m using parallel projection for the camera and mouse-wheel zooming turns it off for some reason (if it’s a bug I’ll open a new separate ticket).

Mouse wheel should not change camera projection, so it that happens then it is a bug. I tried this and for me the view is zoomed in/out with mouse wheel correctly (without changing projection mode).

---

<div class="post-metadata">

**Author:** ![atracsys-sbt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atracsys-sbt/32/11434_2.png) [@atracsys-sbt](https://discourse.slicer.org/u/atracsys-sbt)\
**Post date:** [September 8, 2021, 3:55pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/11 "2021-09-08T15:55:34Z")

</div>

> [@lassoan](#):
>
> Then disabling camera translation & rotation may make sense. You may still want to allow right-click menu, etc. so it makes sense not to disable all interactions.

Ok, I’ll try to find a way to disable only the necessary.

> [@lassoan](#):
>
> Mouse wheel should not change camera projection, so it that happens then it is a bug. I tried this and for me the view is zoomed in/out with mouse wheel correctly (without changing projection mode).

I’m able to reproduce the bug with:

```auto
layoutManager = slicer.app.layoutManager()
view = layoutManager.threeDWidget(0).threeDView()
renderWindow = view.renderWindow()
renderer = renderWindow.GetRenderers().GetItemAsObject(0)
camera = renderer.GetActiveCamera()
camera.ParallelProjectionOn()

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 8, 2021, 4:15pm UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/12 "2021-09-08T16:15:09Z")

</div>

> [@atracsys-sbt](#):
>
> I’m able to reproduce the bug with:
> 
> ```auto
> layoutManager = slicer.app.layoutManager()
> view = layoutManager.threeDWidget(0).threeDView()
> renderWindow = view.renderWindow()
> renderer = renderWindow.GetRenderers().GetItemAsObject(0)
> camera = renderer.GetActiveCamera()
> camera.ParallelProjectionOn()
> 
> ```

I see, this is not a bug, but it is due to that camera projection mode is defined in vtkMRMLViewNode. If you change it in the camera VTK object then the view node will restore it to the stored value at the next update. I agree that this can be unexpected and it is probably like this due to historical reasons. You could [file an enhancement request](https://issues.slicer.org/) to change this (i.e., only store projection mode in the camera node, not in the view node).

---

<div class="post-metadata">

**Author:** ![atracsys-sbt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atracsys-sbt/32/11434_2.png) [@atracsys-sbt](https://discourse.slicer.org/u/atracsys-sbt)\
**Post date:** [September 9, 2021, 7:35am UTC](https://discourse.slicer.org/t/disable-interaction-with-camera/12586/13 "2021-09-09T07:35:04Z")

</div>

The enhancement request has been posted [here](https://github.com/Slicer/Slicer/issues/5841).
