Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color widget in the layer-bar #54

Closed
wants to merge 42 commits into from
Closed

Color widget in the layer-bar #54

wants to merge 42 commits into from

Conversation

aranega
Copy link
Member

@aranega aranega commented Nov 20, 2024

Summary

This PR introduces a new color widget in the layer bar, which reflects the color status of a layer set by the user. It indicates three states for layer colors:

Unsupported: For layers that do not have a color.
Rainbow: For layers like segmentation with multiple colors, or when a color cannot be determined while the layer supports color (e.g: annotation with non-default color).
Single Color: For layers with only one color, or when a segmentation has only one visible segment.
This feature allows users to see the current color state directly in the layer bar.

The activation of this new widget is controlled by a new entry in the global settings menu. The following screenshot shows the new menu entry, as well as the state of the layer bar and the layer panel when the option is activated.

with
menu

We can observe in this screenshot the 3 states:

  • unsupported for FABFB.surf.vt.gz
  • single color for synapses
  • multiple colors for segmentation

Currently annotation and segmentation layers are supported for automatic color detection, while image and mesh layers are not.

Motivation

Users often need to quickly identify the color status of layers, especially with segmentation layers that might have multiple colors. This widget provides an immediate visual indicator of the layer’s color configuration.

User Interaction

The color widget in the layer bar displays the current color state for each layer. Users can easily see if a layer uses multiple colors or a single color. The widget offers quick insight into the layer’s visual setup. The display of the color widgets is turned on and off via a "Enable layer color legend" setting in the settings panel, which is off by default.

Implementation

This update modifies the layer bar, and the layer panel to add the possibility to display the color widget. The two components register themselves on the layer they are targetting to get notified when a new color is computed.

Layers are modified to consider a new attribute that is stating if it can or not give a color (if it supports the feature). Two new methods defined on layers, and reified by layer type if necessary, are used to:

  1. register a callback to all the necessary signals that would imply a refresh of the color widget
  2. provide the actual color, depending on multiple factors in the layer's state.

Extension

Currently only few layers are supported:

  1. segmentation layer
  2. annotation layer

To support another layer type, e.g: img layer, the class variable supportsLayerBarColorSyncOption needs to be set to true, then the observeLayerColor function can be overriden in the reifed class of the layer to register all the signals or elements that needs to be watched. The automaticLayerBarColor method can be then implemented in the layer to find the color depending on the various information that is available in the layer.

In the case of the img layer, it would be possible to look for emitGrayscale or emitRGBA to extract the color and display it, but we intentionally didn't implement it as it requires a complex implementation if we want to have a perfect idea of what's the color used reading the code. Indeed, parsing properly the content of emitRGBA(...) calls requires to possibly track variables in case the color is encoded somewhere in a variable and used later in the emitRGBA(...) call. The same symbol resolution/variable tracking applies if we need to determine the shade of a color defined as vec4(x, 0.0, 0.0, 1.0) where x would be defined in another place in the code.

In addition to parsing the shader code, as a future possibility, the default image layer shader could be modified to add a defaultColor which would create a color widget in the image layer. This could then be used to inform the color in the automaticLayerBarColor if defaultColor is used in the shader. This would then function similarly to the setup for annotation layers in this PR.

aranega and others added 30 commits November 1, 2024 06:18
src/ui/layer_bar.ts Show resolved Hide resolved
src/ui/layer_bar.ts Outdated Show resolved Hide resolved
src/ui/layer_list_panel.ts Outdated Show resolved Hide resolved
src/layer/index.ts Outdated Show resolved Hide resolved
@aranega aranega requested review from seankmartin January 8, 2025 14:22
@aranega
Copy link
Member Author

aranega commented Jan 8, 2025

@seankmartin The modifications were easier than what I was expecting, an event was sent for the change that were already caught by the code in the layer_list file. The code is shorted also now for the layer list implementation

Copy link

@seankmartin seankmartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks so much!

@aranega
Copy link
Member Author

aranega commented Jan 9, 2025

PR open here google#693

@aranega aranega closed this Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants