Skip to content

fix(WindowLevelRegionTool): make region WL sampling image-space invariant - #2895

Open
atehrani-statrad wants to merge 3 commits into
cornerstonejs:mainfrom
atehrani-statrad:main
Open

fix(WindowLevelRegionTool): make region WL sampling image-space invariant#2895
atehrani-statrad wants to merge 3 commits into
cornerstonejs:mainfrom
atehrani-statrad:main

Conversation

@atehrani-statrad

@atehrani-statrad atehrani-statrad commented Sep 2, 2026

Copy link
Copy Markdown

Context

This PR is to address and fix issue #2423

Changes & Results

WindowLevelRegionTool was deriving ROI extents in canvas space, so resizing the viewport changed sampled pixels and produced different WW/WL for the same visual region. This update makes ROI sampling image-space invariant while preserving existing no-backing-image behavior for unsupported native reformatted/oblique slices.

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:
  • [] "Node version:
  • [] "Browser:

Summary by CodeRabbit

  • Bug Fixes

    • Corrected window-level region calculations to use image coordinates, improving ROI sampling accuracy across viewport types.
    • Ensured regions without available image data exit safely without applying changes or triggering unnecessary rendering.
  • Tests

    • Added coverage for image-space ROI sampling, window-level range calculation, property updates, rendering, and missing image data handling.

Copilot AI and others added 3 commits September 2, 2026 17:48
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: db922e57-ff42-4f30-adac-5a3f1de580b4

📥 Commits

Reviewing files that changed from the base of the PR and between e94ad53 and cc787b5.

📒 Files selected for processing (3)
  • packages/tools/src/tools/WindowLevelRegionTool.ts
  • packages/tools/src/utilities/voi/windowlevel/extractWindowLevelRegionToolData.ts
  • packages/tools/test/WindowLevelRegionTool.jest.js

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The window-level region tool now calculates ROI bounds in image coordinates. Volume, stack, and generic viewport extractors provide worldToImage functions. Jest tests verify image-space sampling, VOI updates, rendering, and early return behavior.

Changes

Window-level region coordinate flow

Layer / File(s) Summary
Image coordinate extraction
packages/tools/src/utilities/voi/windowlevel/extractWindowLevelRegionToolData.ts
Volume, stack, and generic viewport extractors now return worldToImage functions. Volume conversion applies the slice matrix.
Region tool integration and validation
packages/tools/src/tools/WindowLevelRegionTool.ts, packages/tools/test/WindowLevelRegionTool.jest.js
applyWindowLevelRegion computes bounds from image-space handles. Tests validate image-space sampling, VOI updates, rendering, and early return behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to cc787

The window-level region tool now samples the same image pixels regardless of viewport resizing while preserving existing unsupported-view behavior. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: sedghi

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the issue and summarizes the implementation, but the Testing section is empty, the tested environment is not provided, and all required checklist items remain unchecked. Add concrete testing steps and the tested OS, Node version, and browser. Complete the checklist by changing each applicable [] entry to [x].
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix and follows the repository's semantic-release format: fix(WindowLevelRegionTool): make region WL sampling image-space invariant.
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.
  • Fix all pre-merge checks with AI
✨ 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.

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.

2 participants