Skip to content

refactor: use RENDERING_DEFAULTS constant for minimum slab thickness - #2564

Merged
wayfarer3130 merged 6 commits into
cornerstonejs:mainfrom
theoc0702:refactor/use-constant-for-slab-thickness
Jul 6, 2026
Merged

refactor: use RENDERING_DEFAULTS constant for minimum slab thickness#2564
wayfarer3130 merged 6 commits into
cornerstonejs:mainfrom
theoc0702:refactor/use-constant-for-slab-thickness

Conversation

@theoc0702

@theoc0702 theoc0702 commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Context

Currently, the minimum slab thickness in setSlabThickness is hardcoded to 0.1. This PR replaces the hardcoded value with the existing RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS constant to improve maintainability and ensure consistency across the library.

Changes & Results

  • VolumeViewport.ts: Replaced hardcoded 0.1 with RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS in the setSlabThickness method.

Effect:
No functional change for the user, but it centralizes the configuration of the minimum rendering thickness.

Testing

  1. Use any example utilizing Volume Viewports with Slab Thickness (e.g., MIP or Average intensity projection).
  2. Set the slab thickness to a value lower than 0.1.
  3. Verify that the system correctly defaults to the constant value defined in RENDERING_DEFAULTS.

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 22.04
  • Node version: 18.x
  • Browser: Chrome

Summary by CodeRabbit

  • Bug Fixes
    • Improved the “Slab Thickness” slider so it now starts at a small non-zero value, preventing zero-thickness settings.
    • Updated the minimum thickness behavior to better match the app’s standard rendering limits, keeping volume rendering stable when very small values are selected.

@salimkanoun

Copy link
Copy Markdown
Contributor

This PR is because we found a small bug in crosshairs, it was checking the minimum value which was expected to be MINIMUM_SLAB_THICKNESS while it was 0.1 in the viewport

if (slabThickness < 0.1) {
// Cannot render zero thickness
slabThickness = 0.1;
slabThickness = RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is our default 0.1 too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nop 0.05

MINIMUM_SLAB_THICKNESS: 5e-2,

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The slab thickness example slider minimum and default were raised to 0.05, and the viewport clamp now uses the shared minimum slab thickness constant instead of a hardcoded value.

Changes

Slab thickness minimum alignment

Layer / File(s) Summary
Viewport clamp
packages/core/src/RenderingEngine/VolumeViewport.ts
setSlabThickness now clamps values below the threshold with RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS instead of 0.1.
Example slider bounds
packages/core/examples/volumeAPI/index.ts
The “Slab Thickness” slider minimum and default are set to 0.05, while selection still updates the viewport slab thickness and renders.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny hopped by with a whisker and grin,
“Zero is out, point-oh-five hops in!”
The slab stayed tidy, the viewport sang light,
And my ears did a twirl in the rendering night. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, accurate, and follows the semantic-release refactor prefix for the main change.
Description check ✅ Passed The description includes context, changes, testing steps, and a completed checklist, matching the template well.
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.

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

♻️ Duplicate comments (1)
packages/core/src/RenderingEngine/VolumeViewport.ts (1)

497-499: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the shared minimum in the guard condition too.

Line 497 still hardcodes 0.1, so values between 0.05 and 0.1 get incorrectly clamped down to 0.05. The threshold should match RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS.

Proposed fix
-    if (slabThickness < 0.1) {
+    if (slabThickness < RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS) {
       // Cannot render zero thickness
       slabThickness = RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS;
     }
🤖 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/core/src/RenderingEngine/VolumeViewport.ts` around lines 497 - 499,
The slab thickness guard in VolumeViewport still uses a hardcoded threshold
instead of the shared minimum, so update the conditional around the
slabThickness check to use RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS in the same
place where the clamp is applied. Keep the behavior in VolumeViewport consistent
by referencing the shared constant in both the guard and the assignment, rather
than comparing against 0.1 directly.
🤖 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.

Duplicate comments:
In `@packages/core/src/RenderingEngine/VolumeViewport.ts`:
- Around line 497-499: The slab thickness guard in VolumeViewport still uses a
hardcoded threshold instead of the shared minimum, so update the conditional
around the slabThickness check to use RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS
in the same place where the clamp is applied. Keep the behavior in
VolumeViewport consistent by referencing the shared constant in both the guard
and the assignment, rather than comparing against 0.1 directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 35836b1d-4e7e-479f-a06b-c11af990003b

📥 Commits

Reviewing files that changed from the base of the PR and between fcab92d and 3b0e4b9.

📒 Files selected for processing (2)
  • packages/core/examples/volumeAPI/index.ts
  • packages/core/src/RenderingEngine/VolumeViewport.ts

@wayfarer3130

Copy link
Copy Markdown
Collaborator

@jbocce and @sedghi - here is an example of a PR that never runs the tests - Ive updated the underlying PR to latests CS3D but the tests don't seem to want to run. Hard to know if things pass without test results.

@sedghi

sedghi commented Jun 25, 2026

Copy link
Copy Markdown
Member

@theoc0702 can you run the tests locally and post screenshot it passes

@jbocce

jbocce commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

@jbocce and @sedghi - here is an example of a PR that never runs the tests - Ive updated the underlying PR to latests CS3D but the tests don't seem to want to run. Hard to know if things pass without test results.

I think the runner is offline.

@salimkanoun

Copy link
Copy Markdown
Contributor

is it good ? I see all test running except downstream validation

@wayfarer3130
wayfarer3130 merged commit 98e0508 into cornerstonejs:main Jul 6, 2026
17 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