Skip to content

fix middle slice circle 3d - #2775

Open
salimkanoun wants to merge 1 commit into
cornerstonejs:mainfrom
salimkanoun:fix-middle-slice-circle-start-end
Open

fix middle slice circle 3d#2775
salimkanoun wants to merge 1 commit into
cornerstonejs:mainfrom
salimkanoun:fix-middle-slice-circle-start-end

Conversation

@salimkanoun

@salimkanoun salimkanoun commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Context

We had an issue for circleStartEnd, as the central slice is the only one interactable, if we had an even number of slice the camera position was never able to match the center of the ROI.

This PR changes behaviour to activate handles for closest slices of the center (determined by slice position is lower than thickness, can select two slices for even number of slice in ROI)

Changes & Results

Handles are not lost if even number of slices in the ROI

Testing

Manually through test

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

Linux and chrome latest

Summary by CodeRabbit

  • Bug Fixes
    • Improved slice detection for circle ROI rendering so it works with near-center positions instead of requiring an exact match.
    • Updated line and handle display behavior to stay consistent when the view is close to the middle slice, reducing unexpected solid/dashed rendering changes.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

In CircleROIStartEndThresholdTool, the middle-slice detection in renderAnnotation changes from exact coordinate equality to a tolerance-based check. A new isNearMiddleSlice flag uses the absolute difference between roundedCameraCoordinate and middleCoordinate compared against the volume's normal-direction slice spacing. All rendering branches previously using isMiddleSlice now use isNearMiddleSlice.

Changes

Middle Slice Tolerance Detection

Layer / File(s) Summary
isNearMiddleSlice computation and rendering
packages/tools/src/tools/segmentation/CircleROIStartEndThresholdTool.ts
Replaces exact-match isMiddleSlice with isNearMiddleSlice computed via spacing tolerance from imageVolume and viewplaneNormal; updates handle canvas coord gating and circle line style (solid vs dashed) to use the new flag.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

A rabbit hops from slice to slice,
Exact coords were never quite nice.
Now spacing grants a little grace—
The middle found in fuzzy space!
🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers context, changes, testing, and checklist, but several checklist items remain unchecked and the test environment details are incomplete. Complete all checklist checkboxes, add the missing Node/browser details, and include any issue link or more concrete testing steps if available.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly matches the PR's fix for middle-slice circle behavior in 3D.
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.
✨ 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.

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 `@packages/tools/src/tools/segmentation/CircleROIStartEndThresholdTool.ts`:
- Around line 429-435: The middle-slice spacing check in
CircleROIStartEndThresholdTool should use the annotation’s persisted spacing
instead of reloading the volume from cache. Remove the cache.getVolume lookup
based on getTargetId(viewport), and read spacingInNormal from the annotation
metadata already attached to the ROI state. Update the Math.abs(...) comparison
in the render-path logic to pass that stored spacing into the threshold check so
it remains stable after decaching or viewport target switches.
🪄 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: e9b2832a-a44d-4cb3-9c53-2558f1b1a049

📥 Commits

Reviewing files that changed from the base of the PR and between 0cc8f0d and 28888e6.

📒 Files selected for processing (1)
  • packages/tools/src/tools/segmentation/CircleROIStartEndThresholdTool.ts

Comment on lines +429 to +435
let isNearMiddleSlice = false;
const targetId = this.getTargetId(viewport);
const imageVolume = cache.getVolume(targetId.split(/volumeId:|\?/)[1]);
if (
Math.abs(roundedCameraCoordinate - middleCoordinate) <
csUtils.getSpacingInNormalDirection(imageVolume, viewplaneNormal)
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Use the annotation’s stored spacing here instead of reloading the viewport volume.

This render-path lookup can now throw if the volume was decached, and it can also pick the wrong spacing after a viewport target switch. spacingInNormal is already persisted on the annotation metadata, so use that instead of cache.getVolume(...) here.

Proposed fix
-      let isNearMiddleSlice = false;
-      const targetId = this.getTargetId(viewport);
-      const imageVolume = cache.getVolume(targetId.split(/volumeId:|\?/)[1]);
-      if (
-        Math.abs(roundedCameraCoordinate - middleCoordinate) <
-        csUtils.getSpacingInNormalDirection(imageVolume, viewplaneNormal)
-      ) {
-        isNearMiddleSlice = true;
-      }
+      const isNearMiddleSlice =
+        Math.abs(roundedCameraCoordinate - middleCoordinate) <
+        metadata.spacingInNormal;
📝 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
let isNearMiddleSlice = false;
const targetId = this.getTargetId(viewport);
const imageVolume = cache.getVolume(targetId.split(/volumeId:|\?/)[1]);
if (
Math.abs(roundedCameraCoordinate - middleCoordinate) <
csUtils.getSpacingInNormalDirection(imageVolume, viewplaneNormal)
) {
const isNearMiddleSlice =
Math.abs(roundedCameraCoordinate - middleCoordinate) <
metadata.spacingInNormal;
🤖 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 `@packages/tools/src/tools/segmentation/CircleROIStartEndThresholdTool.ts`
around lines 429 - 435, The middle-slice spacing check in
CircleROIStartEndThresholdTool should use the annotation’s persisted spacing
instead of reloading the volume from cache. Remove the cache.getVolume lookup
based on getTargetId(viewport), and read spacingInNormal from the annotation
metadata already attached to the ROI state. Update the Math.abs(...) comparison
in the render-path logic to pass that stored spacing into the threshold check so
it remains stable after decaching or viewport target switches.

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.

1 participant