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

Allow selective segment visibility regardless of proofreading tool #8281

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

philippotto
Copy link
Member

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • view annotations with a segmentation layer
  • ensure that the hovering of segments works as usual
  • enable the new "Selective Visibility" toggle in the sidebar -> only the active segment and hovered segments should be visible
  • switch to the proofreading mode -> the selective visibility toggle should be disabled now. the already existing selective visibility toggle in the toolbar should now have precedencw

Issues:


(Please delete unneeded items, merge only when none are left open)

@philippotto philippotto self-assigned this Dec 16, 2024
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces a new feature for selective segment visibility in the frontend application. This enhancement allows users to control the visibility of segments through a toggle in the layer settings tab. The changes span multiple files, including the material factory, shaders, store configuration, and UI components. The implementation adds a new boolean property selectiveSegmentVisibility and integrates it into the rendering pipeline and user interface.

Changes

File Change Summary
frontend/javascripts/oxalis/geometries/materials/plane_material_factory.ts Added new uniform selectiveSegmentVisibility and listener to update its value
frontend/javascripts/oxalis/shaders/main_data_shaders.glsl.ts Introduced new function getSegmentationAlphaIncrement and added selectiveSegmentVisibility uniform
frontend/javascripts/oxalis/shaders/segmentation.glsl.ts Added getSegmentationAlphaIncrement function to control segment alpha
frontend/javascripts/oxalis/store.ts Added selectiveSegmentVisibility property to DatasetConfiguration type
frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx Added selective visibility switch and updated props management
frontend/javascripts/types/schemas/dataset_view_configuration.schema.ts Added selectiveSegmentVisibility to default configuration
frontend/javascripts/libs/input.ts Added methods for handling double-click events in mouse input classes
frontend/javascripts/oxalis/controller/combinations/tool_controls.ts Introduced leftDoubleClick method for the Move tool to handle double-click events

Assessment against linked issues

Objective Addressed Explanation
Support selective segment visibility
Expose toggle in layer settings
Independent of proofreading tool

Possibly related PRs

  • Add button to select all trees and all segments that match a search #8123: This PR introduces a button to select all matching trees and segments, which relates to the new selectiveSegmentVisibility uniform added in the main PR, as both involve enhancing visibility and selection features in the application.
  • Allow dollar in layer name #8241: This PR allows the dollar sign in layer names, which is relevant because it modifies the validation logic that could interact with the new selectiveSegmentVisibility feature in terms of how layers are managed and displayed.
  • Update Cursor Right Away When Bounding Box Is Hovered #8253: This PR updates cursor behavior when hovering over bounding boxes, which is related to the rendering and visibility aspects of segments controlled by the selectiveSegmentVisibility uniform in the main PR.

Suggested labels

frontend, enhancement

Suggested reviewers

  • MichaelBuessemeyer
  • daniel-wer

Poem

🐰 A rabbit's tale of segments bright,
Visibility now set just right,
With toggle switch so neat and clean,
Segments dance across the scene,
Proofreading's magic, clear and light! 🔍

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69576c8 and 0b841c9.

📒 Files selected for processing (2)
  • frontend/javascripts/libs/input.ts (5 hunks)
  • frontend/javascripts/oxalis/controller/combinations/tool_controls.ts (1 hunks)
🔇 Additional comments (4)
frontend/javascripts/libs/input.ts (3)

387-403: LGTM: Well-structured double-click handler implementation.

The implementation follows existing patterns and includes proper checks for:

  • Mouse button validation
  • Movement threshold to prevent accidental triggers
  • Touch device compatibility

458-458: LGTM: Proper event handling setup and cleanup.

The double-click event is correctly:

  • Added in the constructor
  • Cleaned up in the destroy method

Also applies to: 511-511


565-569: LGTM: Clean double-click implementation.

The method correctly:

  • Validates the click target
  • Delegates to the left mouse button handler
frontend/javascripts/oxalis/controller/combinations/tool_controls.ts (1)

140-153: LGTM: Well-documented and carefully implemented double-click handler.

The implementation:

  • Correctly limits segment selection to Move tool only
  • Includes clear documentation explaining the rationale
  • Prevents unintended interactions with other tools

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
frontend/javascripts/oxalis/shaders/segmentation.glsl.ts (2)

358-392: Add documentation for the alpha increment calculation logic.

The implementation is correct, but the complex visibility logic would benefit from documentation explaining:

  • The different alpha values and their visual effects
  • The interaction between proofreading and normal modes
  • The purpose of each condition branch

Add a documentation block like this:

+    /*
+     * Calculates the alpha increment for segment visibility based on the segment state:
+     * 
+     * Proofreading mode:
+     * - Active cell + hovered unmapped: +0.4 (highlight super-voxel)
+     * - Active cell + hovered: +0.15 (highlight non-hovered parts)
+     * - Hovered cell: +0.2
+     * - Other cells: -alpha if selective visibility enabled
+     *
+     * Normal mode:
+     * - Hovered segment: +0.2
+     * - Active cell with selective visibility: +0.15
+     * - Other cells with selective visibility: -alpha (hide)
+     * - Default: no change
+     */
     float getSegmentationAlphaIncrement(float alpha, bool isHoveredSegment, bool isHoveredUnmappedSegment, bool isActiveCell) {

358-392: Consider refactoring for improved readability.

The nested conditional logic could be simplified using early returns and helper functions.

Consider this refactor:

-    float getSegmentationAlphaIncrement(float alpha, bool isHoveredSegment, bool isHoveredUnmappedSegment, bool isActiveCell) {
-      if (isProofreading) {
-        if (isActiveCell) {
-          return (isHoveredUnmappedSegment
-            ? 0.4
-            : (isHoveredSegment
-              ? 0.15
-              : 0.0
-            )
-          );
-        } else {
-          return (isHoveredSegment
-            ? 0.2
-            : (selectiveVisibilityInProofreading ? -alpha : 0.0)
-          );
-        }
-      }
-
-      if (isHoveredSegment) {
-        return 0.2;
-      } else if (selectiveSegmentVisibility) {
-        return isActiveCell ? 0.15 : -alpha;
-      } else {
-        return 0.;
-      }
-    }
+    float getProofreadingAlphaIncrement(float alpha, bool isHoveredSegment, bool isHoveredUnmappedSegment, bool isActiveCell) {
+      if (isActiveCell) {
+        if (isHoveredUnmappedSegment) return 0.4;
+        if (isHoveredSegment) return 0.15;
+        return 0.0;
+      }
+      
+      if (isHoveredSegment) return 0.2;
+      return selectiveVisibilityInProofreading ? -alpha : 0.0;
+    }
+    
+    float getNormalModeAlphaIncrement(float alpha, bool isHoveredSegment, bool isActiveCell) {
+      if (isHoveredSegment) return 0.2;
+      if (!selectiveSegmentVisibility) return 0.0;
+      return isActiveCell ? 0.15 : -alpha;
+    }
+    
+    float getSegmentationAlphaIncrement(float alpha, bool isHoveredSegment, bool isHoveredUnmappedSegment, bool isActiveCell) {
+      return isProofreading
+        ? getProofreadingAlphaIncrement(alpha, isHoveredSegment, isHoveredUnmappedSegment, isActiveCell)
+        : getNormalModeAlphaIncrement(alpha, isHoveredSegment, isActiveCell);
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1dd067 and 69576c8.

📒 Files selected for processing (6)
  • frontend/javascripts/oxalis/geometries/materials/plane_material_factory.ts (2 hunks)
  • frontend/javascripts/oxalis/shaders/main_data_shaders.glsl.ts (4 hunks)
  • frontend/javascripts/oxalis/shaders/segmentation.glsl.ts (1 hunks)
  • frontend/javascripts/oxalis/store.ts (1 hunks)
  • frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx (5 hunks)
  • frontend/javascripts/types/schemas/dataset_view_configuration.schema.ts (1 hunks)
🔇 Additional comments (8)
frontend/javascripts/types/schemas/dataset_view_configuration.schema.ts (1)

92-92: LGTM: Configuration property added correctly.

The new selectiveSegmentVisibility property is appropriately added to the dataset view configuration with a sensible default value of false.

frontend/javascripts/oxalis/shaders/main_data_shaders.glsl.ts (1)

9-9: LGTM: Clean integration of the new shader module.

The changes correctly:

  1. Import the new shader module
  2. Declare the required uniform
  3. Replace the inline alpha calculation with the new modular function

Also applies to: 114-114, 297-302

frontend/javascripts/oxalis/store.ts (1)

333-333: LGTM: Property addition follows TypeScript best practices.

The new selectiveSegmentVisibility property is correctly typed and well-placed within the DatasetConfiguration interface.

frontend/javascripts/oxalis/geometries/materials/plane_material_factory.ts (2)

149-151: LGTM: New uniform property follows existing patterns.

The new selectiveSegmentVisibility uniform is correctly initialized to false and follows the same pattern as other uniform properties in the shader material.


568-578: LGTM: Listener setup is consistent with existing patterns.

The listener for selectiveSegmentVisibility is properly implemented:

  • Uses the established listenToStoreProperty pattern.
  • Updates the uniform value when the store property changes.
  • Correctly placed with other similar listeners.
frontend/javascripts/oxalis/view/left-border-tabs/layer_settings_tab.tsx (3)

1589-1589: LGTM: Correctly added activeTool to props.

The activeTool is properly added to mapStateToProps to support the conditional disabling of selective visibility in proofreading mode.


1341-1341: LGTM: Added selectiveSegmentVisibility to saved settings.

The selectiveSegmentVisibility setting is correctly added to the list of settings that can be saved as default configuration.


902-928: LGTM: Well-implemented UI toggle for selective segment visibility.

The selective visibility toggle is properly implemented with:

  • Clear tooltip explaining the override behavior in proofreading mode.
  • Correct conditional disabling based on proofreading mode.
  • Consistent styling and spacing with other settings.

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.

Support selective segment visibility independent of proofreading tool
1 participant