Skip to content

fix(viewport): restore default visual properties on reset in VolumeViewport3D and VolumeViewport#2693

Merged
jbocce merged 4 commits intocornerstonejs:mainfrom
GhadeerAlbattarni:fix/3d-reset-image-color
Apr 16, 2026
Merged

fix(viewport): restore default visual properties on reset in VolumeViewport3D and VolumeViewport#2693
jbocce merged 4 commits intocornerstonejs:mainfrom
GhadeerAlbattarni:fix/3d-reset-image-color

Conversation

@GhadeerAlbattarni
Copy link
Copy Markdown
Contributor

Context

This is fixes an issue in ohif #5922

When a user activates the 3D tool (which applies a volume rendering preset such as CT-Bone), zooms in/out, and then clicks Reset, the image reverts to black and white instead of restoring the original 3D color rendering. The same underlying issue may exist in VolumeViewport.

Root cause

Both VolumeViewport3D.resetProperties and VolumeViewport._resetProperties unconditionally called setTransferFunctionNodes with initialTransferFunctionNodes, which wipes the RGB color transfer function back to the default grayscale ramp captured at volume load time, before any preset or colormap was applied.
setTransferFunctionNodes only resets the RGB color function. It does not touch the opacity, gradient opacity, or lighting properties set by a preset. This left the viewport in an inconsistent state: preset opacity/lighting still active, but color rendering in grayscale.

Changes & Results

Replace the unconditional setTransferFunctionNodes call with a check against the configured default properties (getDefaultProperties):

  • If the defaults include a preset or colormap, apply them viasetProperties(properties, volumeId, true). This routes through applyPreset, which fully restores the color transfer function, scalar opacity, gradient opacity, interpolation, and lighting — the complete visual state — in a single call. suppressEvents is set to true to avoid duplicate or redundant events since resetProperties fires its own VOI_MODIFIED at the end.
  • If no defaults are configured, fall back to the original setTransferFunctionNodes behaviour (no regression).
    The fix is applied to both VolumeViewport3D.resetProperties and VolumeViewport._resetProperties for consistency. For VolumeViewport (MPR), the fallback path means plain CT viewports with no configured defaults behave exactly as before.

Before

3d-reset-Before.mov

After

3d-reset-After.mov

Testing

  1. Open a study and activate the 3D tool
  2. Zoom in/out on the viewport
  3. Click Reset
  4. verify the image correctly restores the 3D color preset
  • Also you can apply a different a preset (e.g, CT-AAA2), then click reset.
    Verify that not only the color has been reset to default but also the opacity, shading, and lighting all set to default.

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: macOS 10.15.4
  • Node version: v22.13.0
  • Browser: Chrome 83.0.4103.116

// Check if there are default properties (e.g., a 3D preset or colormap)
// to restore. This ensures "Reset" goes back to the configured look
// rather than the raw initial grayscale state.
const properties = this.getDefaultProperties(volumeId);
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.

not sure why we are repeating the same thing twice, can you investigate, i remember 3d viewport was extending the volume viewport. worst case we need a refactor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @sedghi for your feedback. Both VolumeViewport3D and VolumeViewport extend BaseVolumeViewport directly. So I added a new method on BaseVolumeViewport so that both subclasses can use it.

@jbocce jbocce self-requested a review April 13, 2026 19:10
* @param volumeActor - The actor entry for the volume
* @param volumeId - The id of the volume
*/
protected _restoreDefaultVisualProperties(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about renaming this to _restoreVolumeRenderingDefaults ?

Copy link
Copy Markdown
Collaborator

@jbocce jbocce left a comment

Choose a reason for hiding this comment

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

Just one small naming suggestion. I have tested locally and it looks good. @sedghi do you have anything to add to this PR?

@jbocce jbocce merged commit d1a7097 into cornerstonejs:main Apr 16, 2026
11 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.

3 participants