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 6 commits into
base: master
Choose a base branch
from

Conversation

philippotto
Copy link
Member

@philippotto philippotto commented Dec 16, 2024

URL of deployed dev instance (used for testing):

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

enhancement, frontend, bug, documentation

Suggested reviewers

  • hotzenklotz
  • MichaelBuessemeyer

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! 🔍


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 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.

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: 1

🧹 Nitpick comments (3)
docs/ui/layers.md (2)

34-34: LGTM! Documentation is clear and well-placed.

The explanation of the selective visibility feature is concise and helpful. Consider adding a period at the end of the sentence for consistency with other entries in this section.

- `Selective Visibility`: When activated, only segments are shown that are currently active or hovered.
+ `Selective Visibility`: When activated, only segments are shown that are currently active or hovered..
🧰 Tools
🪛 LanguageTool

[uncategorized] ~34-~34: Loose punctuation mark.
Context: ...tween segments. - Selective Visibility: When activated, only segments are shown...

(UNLIKELY_OPENING_PUNCTUATION)


34-34: Consider adding information about proofreading tool interaction.

To provide complete context for users, consider mentioning that this feature is automatically disabled when switching to proofreading mode.

- `Selective Visibility`: When activated, only segments are shown that are currently active or hovered.
+ `Selective Visibility`: When activated, only segments are shown that are currently active or hovered. Note: This feature is automatically disabled when switching to proofreading mode, where the toolbar's selective visibility toggle takes precedence.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~34-~34: Loose punctuation mark.
Context: ...tween segments. - Selective Visibility: When activated, only segments are shown...

(UNLIKELY_OPENING_PUNCTUATION)

frontend/javascripts/libs/input.ts (1)

574-579: Consider supporting double-clicks for middle and right mouse buttons.

Currently, only left mouse button double-clicks are supported. Consider extending the functionality to support double-clicks for middle and right mouse buttons as well.

Apply this diff to add support for all mouse buttons:

  doubleClick = (event: MouseEvent): void => {
    if (this.isHit(event)) {
      this.leftMouseButton.handleDoubleClick(event, false);
+     this.middleMouseButton.handleDoubleClick(event, false);
+     this.rightMouseButton.handleDoubleClick(event, false);
    }
  };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b841c9 and 779e71c.

📒 Files selected for processing (3)
  • CHANGELOG.unreleased.md (1 hunks)
  • docs/ui/layers.md (1 hunks)
  • frontend/javascripts/libs/input.ts (5 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/ui/layers.md

[uncategorized] ~34-~34: Loose punctuation mark.
Context: ...tween segments. - Selective Visibility: When activated, only segments are shown...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (3)
CHANGELOG.unreleased.md (1)

16-16: LGTM! Clear and well-structured changelog entry.

The entry effectively communicates the new feature, its location, and functionality to users.

frontend/javascripts/libs/input.ts (2)

467-467: LGTM: Proper event listener cleanup.

The double-click event listener is correctly added in the constructor and properly cleaned up in the destroy method.

Also applies to: 520-520


574-579: Verify existing double-click handlers in the codebase.

Let's ensure there are no conflicting double-click handlers in the codebase that might interfere with this implementation.

✅ Verification successful

Based on the search results, I can now generate the final response:

Double-click implementation is consistent with existing patterns

The implementation in input.ts follows the established double-click handling patterns in the codebase:

  • It's properly integrated with the existing input system that already supports double-click events
  • The handler is correctly registered/unregistered using standard DOM events
  • It follows the same pattern as other mouse button handlers in the codebase
  • No conflicting implementations were found; other double-click handlers in the codebase are either:
    • Component-specific handlers (slider, pricing enforcers)
    • Tool-specific controls with proper guards
    • UI elements like folder tree and dataset table
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing double-click handlers
echo "Searching for existing double-click event listeners..."
rg -i "dblclick|doubleclick" --type ts

echo "Searching for existing double-click method implementations..."
ast-grep --pattern 'function $FUNC($$$) { 
  $$$
  dblclick
  $$$
}'

Length of output: 2728

Comment on lines +396 to +412
handleDoubleClick(event: MouseEvent, triggeredByTouch: boolean): void {
// event.which is 0 on touch devices as there are no mouse buttons, interpret that as the left mouse button
// Safari doesn't support evt.buttons, but only evt.which is non-standardized
const eventWhich = event.which !== 0 ? event.which : 1;

if (eventWhich === this.which) {
if (this.moveDelta <= MOUSE_MOVE_DELTA_THRESHOLD) {
this.mouse.emitter.emit(
`${this.name}DoubleClick`,
this.mouse.lastPosition,
this.id,
event,
triggeredByTouch,
);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check for lastPosition in handleDoubleClick.

The method emits an event using this.mouse.lastPosition without checking if it's null, which could lead to runtime errors since lastPosition is declared as Point2 | null | undefined.

Apply this diff to add the safety check:

  handleDoubleClick(event: MouseEvent, triggeredByTouch: boolean): void {
    const eventWhich = event.which !== 0 ? event.which : 1;

    if (eventWhich === this.which) {
      if (this.moveDelta <= MOUSE_MOVE_DELTA_THRESHOLD) {
+       if (this.mouse.lastPosition == null) return;
        this.mouse.emitter.emit(
          `${this.name}DoubleClick`,
          this.mouse.lastPosition,
          this.id,
          event,
          triggeredByTouch,
        );
      }
    }
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
handleDoubleClick(event: MouseEvent, triggeredByTouch: boolean): void {
// event.which is 0 on touch devices as there are no mouse buttons, interpret that as the left mouse button
// Safari doesn't support evt.buttons, but only evt.which is non-standardized
const eventWhich = event.which !== 0 ? event.which : 1;
if (eventWhich === this.which) {
if (this.moveDelta <= MOUSE_MOVE_DELTA_THRESHOLD) {
this.mouse.emitter.emit(
`${this.name}DoubleClick`,
this.mouse.lastPosition,
this.id,
event,
triggeredByTouch,
);
}
}
}
handleDoubleClick(event: MouseEvent, triggeredByTouch: boolean): void {
// event.which is 0 on touch devices as there are no mouse buttons, interpret that as the left mouse button
// Safari doesn't support evt.buttons, but only evt.which is non-standardized
const eventWhich = event.which !== 0 ? event.which : 1;
if (eventWhich === this.which) {
if (this.moveDelta <= MOUSE_MOVE_DELTA_THRESHOLD) {
if (this.mouse.lastPosition == null) return;
this.mouse.emitter.emit(
`${this.name}DoubleClick`,
this.mouse.lastPosition,
this.id,
event,
triggeredByTouch,
);
}
}
}

Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

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

Nice, works like a charm!
At first I was unsure whether having two settings, a general one and the one for proofreading, might be confusing, but it has definitely grown on me during the testing and I prefer it that way :)
I think I read somewhere that making this work in view mode is more involved since we don't remember the active segment there, right?

  • I understand why you chose the location for the setting switch in the layers tab. However, I find it slightly unexpected that the setting is shown per segmentation layer, but changing it for one changes it for all of them. Another fitting spot without this issue would be the "Data Rendering" section of the Settings tab imo. What do you think?

@@ -551,6 +571,12 @@ export class InputMouse {
}
};

doubleClick = (event: MouseEvent): void => {
if (this.isHit(event)) {
this.leftMouseButton.handleDoubleClick(event, false);
Copy link
Member

@daniel-wer daniel-wer Dec 20, 2024

Choose a reason for hiding this comment

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

In line 343 it says {left,right}DoubleClick, but this looks like it only works for the left mouse button?

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
2 participants