Skip to content

Fix: Segmentation Hide All fails when switching from 2D to 3D fourUp#5995

Merged
wayfarer3130 merged 11 commits into
OHIF:masterfrom
nithin-trenser:fix-seg-load-3d-hide-error
Jun 24, 2026
Merged

Fix: Segmentation Hide All fails when switching from 2D to 3D fourUp#5995
wayfarer3130 merged 11 commits into
OHIF:masterfrom
nithin-trenser:fix-seg-load-3d-hide-error

Conversation

@nithin-trenser

@nithin-trenser nithin-trenser commented May 6, 2026

Copy link
Copy Markdown
Contributor

Context

Fix issue: #5948

After loading a segmentation file in the 2D viewport, switching to the 3D four-up viewport causes the "Hide All" functionality to stop working. When the user selects "Hide All", the segmentations remain visible instead of being hidden.

Changes & Results

Refactor segmentation type selection to use explicit viewport-based logic.
For 3D viewports, enforce Surface; for 2D, allow Contour or default to Labelmap.
This change will ensure consistent behavior and prevent unsupported types from propagating

Seg-3d-four-up-hide-error.mp4

Testing

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • OS: Ubuntu 24.04
  • Node version: 22
  • Browser: Chrome 147.0.7727.138

Summary by CodeRabbit

Bug Fixes

  • Improved segmentation representation selection to be viewport-aware.
    • 3D viewports now reliably use Surface representations.
    • For non-3D viewports, the requested non-Surface representation (such as Contour) is preserved when available; otherwise it falls back to Labelmap when the request is missing or Surface.
  • Updated the “3D four up SEG hydration” test flow to account for asynchronous hydration propagation to MPR viewports by adding an additional render/wait step.

Greptile Summary

This PR fixes a bug where "Hide All" segmentation control stops working after switching from a 2D viewport to a 3D four-up layout. The root cause was that the SEGMENTATION_REPRESENTATION_MODIFIED synchronizer was propagating the Surface representation type (produced by the 3D viewport) to 2D MPR target viewports, leaving those viewports in an unsupported state.

  • The representation-selection logic in createHydrateSegmentationSynchronizer.ts now explicitly rejects Surface as a fallback for non-3D viewports, using Labelmap instead, while still preserving Contour when that is the requested type.
  • The end-to-end test is updated with an additional waitForViewportsRendered guard to account for the asynchronous nature of labelmap propagation to MPR viewports after the first render cycle.

Confidence Score: 5/5

Safe to merge; the fix is narrowly scoped to representation-type selection and does not touch rendering pipelines or data loading.

The logic change is small and correct: it adds a single additional guard (requestedRepresentation !== Surface) so 2D MPR viewports never receive a Surface representation they cannot handle. The existing fallback chain is otherwise preserved. The test update mirrors the async behaviour that already existed in production and the screenshot baseline matches the fixed output.

No files require special attention.

Important Files Changed

Filename Overview
extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts Adds explicit Surface-exclusion guard for non-3D viewports; correctly prevents Surface representation from propagating to MPR viewports when source event originates from a 3D viewport.
tests/SEGHydrationFrom3DFourUp.spec.ts Adds a second waitForViewportsRendered call after the initial render cycle to account for async labelmap propagation to MPR viewports; screenshot baseline updated accordingly.

Reviews (14): Last reviewed commit: "Merge branch 'master' into fix-seg-load-..." | Re-trigger Greptile

@netlify

netlify Bot commented May 6, 2026

Copy link
Copy Markdown

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit 1c456fc
🔍 Latest deploy log https://app.netlify.com/projects/ohif-dev/deploys/6a3c2b7fe38f7b0008de5122
😎 Deploy Preview https://deploy-preview-5995--ohif-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sen-trenser

Copy link
Copy Markdown

@sedghi Could you please take a look at this PR and provide your feedback?
Thanks!

@Belbin-GK

Copy link
Copy Markdown
Contributor

@wayfarer3130 Could you please review this PR?

nithin-trenser and others added 2 commits May 26, 2026 16:04
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@Belbin-GK Belbin-GK force-pushed the fix-seg-load-3d-hide-error branch from 2245ecf to 06408d2 Compare May 26, 2026 10:34
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The segmentation representation type selection is refactored to explicitly check target viewport dimensionality. For 3D viewports it forces Surface. For non-3D viewports it preserves explicitly requested representations (including Contour) when present and non-Surface, otherwise defaults to Labelmap. The related integration test is updated with an explicit asynchronous synchronization wait to account for labelmap volume propagation timing.

Changes

Segmentation Representation Hydration

Layer / File(s) Summary
Segmentation Representation Type Mapping
extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts
The type selection logic now derives the representation type using an explicit is3D check against the target viewport. For 3D viewports it forces Surface. For non-3D viewports it preserves requested representations when present and not Surface (including Contour), and defaults to Labelmap when the representation is missing or Surface.
Hydration Propagation Synchronization in Tests
tests/SEGHydrationFrom3DFourUp.spec.ts
Test adds an explicit await waitForViewportsRendered(page) synchronization step after the initial viewport render-cycle, documenting that SEG labelmap volumes propagate to MPR viewports asynchronously before continuing with hydration-related validations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hopping refactor with logic so neat,
Three branches emerge where the viewports meet,
3D gets Surface, non-3D gets a choice,
Contour and Labelmap find their own voice,
Async waits patiently—timing rings true! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the bug being fixed (segmentation Hide All failing after switching to 3D fourUp) and follows semantic-release format (fix: ...).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description provides comprehensive context, changes, testing steps, and has all required checklist items marked complete.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts (1)

96-102: ⚡ Quick win

Simplify the conditional logic by removing the redundant Contour check.

The explicit check for Contour on lines 98-99 is redundant because when requestedRepresentation === Contour, it will also satisfy the condition on line 100 (requestedRepresentation && requestedRepresentation !== Surface). Both branches return the same value for Contour requests.

♻️ Proposed simplification
 const type: Enums.SegmentationRepresentations = is3D
   ? Surface
-  : requestedRepresentation === Contour
-    ? Contour
-    : requestedRepresentation && requestedRepresentation !== Surface
+  : requestedRepresentation && requestedRepresentation !== Surface
       ? requestedRepresentation
       : Labelmap;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts`
around lines 96 - 102, The ternary that computes the `type` in
`createHydrateSegmentationSynchronizer` is redundant: remove the explicit
`requestedRepresentation === Contour ? Contour :` branch and simplify the
expression to first choose `Surface` when `is3D` is true, otherwise return
`requestedRepresentation` if it exists and is not `Surface`, and fall back to
`Labelmap`; update the `const type: Enums.SegmentationRepresentations`
assignment accordingly (references: `type`, `is3D`, `requestedRepresentation`,
`Surface`, `Contour`, `Labelmap`, `Enums.SegmentationRepresentations`).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts`:
- Around line 96-102: The ternary that computes the `type` in
`createHydrateSegmentationSynchronizer` is redundant: remove the explicit
`requestedRepresentation === Contour ? Contour :` branch and simplify the
expression to first choose `Surface` when `is3D` is true, otherwise return
`requestedRepresentation` if it exists and is not `Surface`, and fall back to
`Labelmap`; update the `const type: Enums.SegmentationRepresentations`
assignment accordingly (references: `type`, `is3D`, `requestedRepresentation`,
`Surface`, `Contour`, `Labelmap`, `Enums.SegmentationRepresentations`).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7bdc94f-7219-414e-b10a-8faf1647a136

📥 Commits

Reviewing files that changed from the base of the PR and between 0885468 and 3da6b38.

📒 Files selected for processing (1)
  • extensions/cornerstone/src/services/SyncGroupService/createHydrateSegmentationSynchronizer.ts

@nithin-trenser nithin-trenser changed the title Fix: Segmentation "Hide All" fails when switching from 2D to 3D four-… Fix: Segmentation Hide All fails when switching from 2D to 3D fourUp Jun 18, 2026
@Devu-trenser Devu-trenser force-pushed the fix-seg-load-3d-hide-error branch from 6f7f140 to e1e5456 Compare June 21, 2026 14:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/SEGHydrationFrom3DFourUp.spec.ts`:
- Around line 63-65: The waitForViewportsRendered function call at line 65 uses
the default 15 second timeout, which is insufficient given that the test
scenario documents multi-viewport render times of up to 240 seconds (as shown in
the earlier assertions). To prevent test flakiness under slower CI conditions,
add an explicit longer timeout parameter to the waitForViewportsRendered(page)
call to match or exceed the documented render times in the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7fe81a63-fb40-48e6-839d-2467736aba4c

📥 Commits

Reviewing files that changed from the base of the PR and between 47c3f6b and eedaf4c.

⛔ Files ignored due to path filters (1)
  • tests/screenshots/chromium/SEGHydrationFrom3DFourUp.spec.ts/threeDFourUpAfterSegHydrated.png is excluded by !**/*.png
📒 Files selected for processing (1)
  • tests/SEGHydrationFrom3DFourUp.spec.ts

Comment thread tests/SEGHydrationFrom3DFourUp.spec.ts Outdated
@wayfarer3130 wayfarer3130 merged commit ee165b4 into OHIF:master Jun 24, 2026
8 checks passed
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.

5 participants