napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.07k stars 410 forks source link

Layer.bounding_box.line_color sets default to red color if ```ndisplay = 3``` is not set in advance #6852

Closed pganes closed 4 weeks ago

pganes commented 1 month ago

πŸ› Bug Report

It was first posted in image.sc forum. The layer bounding box shows the required effect in 2D viewing mode. However, as soon as we switch to 3D mode, the bounding box goes to the default color [red] and default thickness.

Furthermore, if we specify n_display=3 either when initializing viewer as viewer = napari.Viewer(ndisplay=3) or later by keeping viewer.dims.ndisplay = 3 line before img_layer.bounding_box.line_color = 'magenta' line, we can see the desired effect at the first time. But if we switch to 2D mode and then to 3D mode, the bounding_box will regain its default color and thickness.

πŸ’‘ Steps to Reproduce

Please run the aboA simple code to generate this effect is shown below.

import numpy as np
import napari
# Create a simple 4D image (axis0 = time, axis1=Z, axis2=Y, axis3=X )
img = np.random.random((5, 25, 100, 100)) 
viewer = napari.Viewer()
img_layer = viewer.add_image(img)
img_layer.bounding_box.visible = True
img_layer.bounding_box.points = False
img_layer.bounding_box.line_color = 'magenta'  # Set bbox line_color to magenta
img_layer.bounding_box.line_thickness = 2   # Adjust bbox line_thickness
napari.run()

Expected behavior in 2D viewing mode

2d_view

Unexpected behavior in 2D viewing mode

3d_view

πŸ’‘ Expected Behavior

No response

🌎 Environment

napari: 0.4.19.post1 Platform: Windows-10-10.0.22631-SP0 Python: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] Qt: 5.15.2 PyQt5: 5.15.10 NumPy: 1.24.3 SciPy: 1.10.1 Dask: 2024.3.1 VisPy: 0.14.2 magicgui: 0.8.2 superqt: 0.6.2 in-n-out: 0.2.0 app-model: 0.2.5 npe2: 0.7.4

OpenGL:

Screens:

Settings path:

πŸ’‘ Additional Context

No response

imagesc-bot commented 1 month ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/napari-layer-bounding-box-line-color-does-not-change-in-3d-viewing-mode/95005/3

brisvag commented 4 weeks ago

@pganes check out #6855, it should fix your issue :)