@@ -123,11 +123,7 @@ def __init__(
123123 # Connect click events to node selection
124124 def click (self , _ , event ):
125125 if (
126- event .type == "mouse_press"
127- and self .mode == "pan_zoom"
128- and not (
129- self .tracks_viewer .mode == "lineage" and self .viewer .dims .ndisplay == 3
130- )
126+ event .type == "mouse_press" and self .mode == "pan_zoom"
131127 ): # disable selecting in lineage mode in 3D
132128 # differentiate between click and drag
133129 was_click = yield from detect_click (event )
@@ -140,18 +136,37 @@ def assign_new_label(self, event):
140136
141137 new_label (self )
142138
143- def process_click (self , event : Event , label : int ):
144- """Process the click event to update the selected nodes"""
139+ def process_click (
140+ self , event : Event , label : int , layer : ContourLabels | None = None
141+ ):
142+ """Process the click event to update the selected nodes.
145143
146- if (
147- label is not None and label != 0 and self .colormap .map (label )[- 1 ] != 0
148- ): # check opacity (=visibility) in the colormap
149- append = "Shift" in event .modifiers
150- jump = "Control" in event .modifiers
151- if jump :
152- self .tracks_viewer .center_on_node (label )
144+ Args:
145+ event (Event): The click event.
146+ label (int): The label value at the clicked position.
147+ layer (ContourLabels | None): The (ortho view) layer from which the click originated.
148+ If provided, it is used to check label visibility in that layer's colormap.
149+ """
150+
151+ if label is not None and label != 0 :
152+ # check visibility in the respective colormap. If a label is not visible, it
153+ # is not allowed to be selected from this view
154+ if layer is not None :
155+ is_visible = layer .colormap .color_dict .get (label )[3 ] > 0
156+ else :
157+ is_visible = self .colormap .color_dict .get (label )[3 ] > 0
158+ if is_visible :
159+ append = "Shift" in event .modifiers
160+ jump = "Control" in event .modifiers
161+ if jump :
162+ self .tracks_viewer .center_on_node (label )
163+ else :
164+ self .tracks_viewer .selected_nodes .add (label , append )
153165 else :
154- self .tracks_viewer .selected_nodes .add (label , append )
166+ warnings .warn (
167+ f"Node { label } is not visible in this view and cannot be selected." ,
168+ stacklevel = 2 ,
169+ )
155170
156171 def _get_colormap (self ) -> DirectLabelColormap :
157172 """Get a DirectLabelColormap that maps node ids to their track ids, and then
@@ -315,7 +330,7 @@ def update_label_colormap(self, visible: list[int] | str) -> None:
315330
316331 highlighted = set (self .tracks_viewer .selected_nodes )
317332 foreground = self .colormap .color_dict .keys () if visible == "all" else visible
318- background = (
333+ self . background = (
319334 []
320335 if visible == "all"
321336 else self .colormap .color_dict .keys () - visible - highlighted
@@ -328,7 +343,13 @@ def update_label_colormap(self, visible: list[int] | str) -> None:
328343 if not self .foreground_contour :
329344 self .filled_labels .extend (foreground )
330345
331- self .set_opacity (background , self .background_opacity )
346+ # special case: 3D rendering + partially filled contours -> set background opacity
347+ # to 0
348+ if self ._slice .slice_input .ndisplay == 3 and self .contour > 0 :
349+ self .set_opacity (self .background , 0 )
350+ else :
351+ # set normal background opacity
352+ self .set_opacity (self .background , self .background_opacity )
332353 self .set_opacity (foreground , self .foreground_opacity )
333354 self .set_opacity (highlighted , self .highlight_opacity )
334355 self .refresh_colormap ()
0 commit comments