When adding a volume using viewer.add_image the camera settings are reset.
I would argue that the camera settings should be retained even if a volume is added.
In interactive use, the user may have spent quite some time to set up the particular view
and my just want to visualize an additional channel. The view then needs to be set up again.
Maybe there are good arguments that speak for resetting the viewport when an image
is added, but I can't think of any.
I noticed this behaviour while working on this example:
https://github.com/VolkerH/napari/blob/3dkymo/examples/3d_kymograph.py
Steps to reproduce the behavior:
add_image. Observe that the volume is not oriented the same way as in 1. because the parameters have been reset.I would expect the camera viewport to be retained.
napari: 0.4.1.dev27+g56f9dca
Platform: Linux-5.4.0-52-generic-x86_64-with-debian-bullseye-sid
Python: 3.7.9 (default, Aug 31 2020, 12:42:55) [GCC 7.3.0]
Qt: 5.14.2
PyQt5: 5.14.2
NumPy: 1.19.2
SciPy: 1.5.3
Dask: 2.30.0
VisPy: 0.6.5
GL version: 4.6.0 NVIDIA 450.80.02
MAX_TEXTURE_SIZE: 32768
Plugins:
- napari_plugin_engine: 0.1.8
- svg: 0.1.4
Amusingly, @zeroth and I encountered the opposite problem: when updating the scale of an image after the layer has been created, the camera is not reset. When scale is <<1, this means that the zoom and rotation centre is way outside of the image, which makes for a really confusing interaction.
import napari
from skimage import data
image = data.binary_blobs(length=64, n_dim=3)
with napari.gui_qt():
v = napari.Viewer(ndisplay=3)
layer = v.add_image(image)
layer.scale = [0.1, 0.1, 0.1]
So unfortunately it means resetting the camera is very much context dependent...
I think the above situation explains the rationale for resetting the camera in the first place: if new data significantly changes the extent of all the data, it might be difficult to see what's been added/whether it's been added, in the current view.
Move the camera setup commands here https://github.com/VolkerH/napari/blob/f33f3ed863394a990c2eee6a010dd30ec2f5a324/examples/3d_kymograph.py#L146 further up in the code, such that they get executed before the add_image. Observe that the volume is not oriented the same way as in 1. because the parameters have been reset.
@VolkerH the camera actually only resets when the first layer is added to an empty layer list, done here https://github.com/napari/napari/blob/v0.4.0/napari/components/add_layers_mixin.py#L75-L76
Now that we have a camera model, I can see why you were surprised when adding a layer changed that setting. We could try and do something more clever here, like reset if no data has been added and camera is in default state, but I'm not sure.
when updating the scale of an image after the layer has been created, the camera is not reset. When scale is <<1, this means that the zoom and rotation centre is way outside of the image, which makes for a really confusing interaction.
ha, indeed @jni I can see how that was confusing too.
I'm not sure what's best to do next, we probably need more discussion here
I think the above situation explains the rationale for resetting the camera in the first place: if new data significantly changes the extent of all the data, it might be difficult to see what's been added/whether it's been added, in the current view.
maybe something based off this idea is the way forward, if the world extent changes then reset camera (possibly keeping center just rescaling zoom).
That could actually be quite nice!!