@@ -100,13 +100,14 @@ def get_property_names_from_class(layer_cls):
100100 - {"mode" , "size" , "current_size" },
101101 },
102102 TrackLabels : {
103+ "forward_exclude" : {"colormap" },
103104 "reverse_exclude" : set (get_property_names_from_class (Labels ))
104105 - {
105106 "mode" ,
106107 "selected_label" ,
107108 "n_edit_dimensions" ,
108109 "brush_size" ,
109- } # Let TrackLabels handle these properties on its own because it is listening to
110+ }, # Let TrackLabels handle these properties on its own because it is listening to
110111 # them and we do not want to overwrite through reverse syncing.
111112 },
112113}
@@ -217,6 +218,40 @@ def paint_wrapper(event: Event):
217218 copied_layer .events .paint .connect (paint_wrapper )
218219
219220
221+ def colormap_hook (orig_layer : TrackLabels , copied_layer : Labels ) -> None :
222+ """Hook to sync colormap changes from the original TrackLabels layer to the copied
223+ layers. We need a hook for the special case in which one of the views is showing a 3D
224+ rendering in combination with partially filled contour labels. Since contours are not
225+ rendered in 3D, we want to display the non-filled labels with full opacity instead.
226+
227+ Args:
228+ orig_layer (TrackLabels): TracksLabels layer from which the copied layer is
229+ derived.
230+ copied_layer (ContourLabels): ContourLabels equivalent of the TracksLabels layer.
231+ """
232+
233+ def sync_colormap (orig_layer : TrackLabels , copied_layer : Labels , event : Event ):
234+ """Sync the colormap from the original TrackLabels instance to the copied
235+ ContourLabels instance. Check the slice ndisplay and contour settings to adjust
236+ background opacity accordingly."""
237+
238+ copied_layer .colormap = orig_layer .colormap
239+ if copied_layer ._slice .slice_input .ndisplay == 3 and orig_layer .contour > 0 :
240+ copied_layer .set_opacity (orig_layer .background , 0 )
241+ else :
242+ copied_layer .set_opacity (
243+ orig_layer .background , orig_layer .background_opacity
244+ )
245+ copied_layer .refresh_colormap ()
246+
247+ def update_colormap_wrapper (event : Event ):
248+ """Wrap paint event and send to original layer."""
249+
250+ return sync_colormap (orig_layer , copied_layer , event )
251+
252+ orig_layer .events .colormap .connect (update_colormap_wrapper )
253+
254+
220255def track_layers_hook (
221256 orig_layer : TrackLabels | TrackPoints , copied_layer : Labels | Points
222257) -> None :
@@ -265,6 +300,7 @@ def initialize_ortho_views(viewer: Viewer) -> OrthoViewManager:
265300 orth_view_manager .register_layer_hook ((TrackLabels , TrackPoints ), track_layers_hook )
266301 orth_view_manager .register_layer_hook ((TrackLabels ), paint_event_hook )
267302 orth_view_manager .register_layer_hook ((TrackPoints ), point_data_hook )
303+ orth_view_manager .register_layer_hook ((TrackLabels ), colormap_hook )
268304 orth_view_manager .set_sync_filters (sync_filters )
269305 orth_view_manager .activate_checkboxes = True
270306
0 commit comments