Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VolumeViewport) fix viewportProperties on VolumeViewport setOrientation #1842

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Gabsha
Copy link

@Gabsha Gabsha commented Feb 20, 2025

Context

We have an OHIF extension where we display MRI on volume viewports.

We align the camera's viewPlaneNormal with the volume direction cosine that most fit the axial orientation. On some images, the volume orientation will match the patient orientation (eg [0,0,1]), but sometimes won't (eg. image has been co-registered).

When changing volumes in the same viewport (one of which has a non patient-aligned direction cosine), cornerstone will enter a recursive call stack that end up in a stack overflow and crashing the tab.

I can see it happens only because there is a warning (about CrossHair on volume viewport not being enabled) that gets printed on the console +10k times before it crashes.


I'm having a hard time coming up with a minimal reproducible example (volume viewports in the OHIF demo are aligned with the patient axis and do not trigger this issue), but I can point down where it's happening:

When changing volumes in a viewport, the following function stack is invoked:

setViewReference (BaseVolumeViewport.js:520)
_setPositionPresentation (CornerstoneViewportService.ts:1144)
setPresentations (CornerstoneViewportService.ts:222)
setVolumesForViewport (CornerstoneViewportService.ts:852)
await in setVolumesForViewport
_setVolumeViewport (CornerstoneViewportService.ts:798)
_setDisplaySets (CornerstoneViewportService.ts:972)
setViewportData (CornerstoneViewportService.ts:459)
loadViewportData (OHIFCornerstoneViewport.tsx:280)
...

In setViewReference, when the new view reference normal is not aligned with the previous one, a call to setOrientation followed by setViewReference is done

The main issue seems to be that setOrientation fails to actually update the orientation and therefore start recursively calling setViewReference.

setOrientation will change the orientation for some OrientationVectors but does not remove the viewportProperties.orientation value (which is some case can be defined, such as axial from the previous volume).

This will ultimately lead to applyViewOrientation, where the call to resetCamera reverts back the orientation because viewportProperties.orientation === 'axial'

Changes & Results

I am resetting the viewportProperties.orientation value to undefined when setOrientation is called with OrientationVectors. This will prevent the applyViewOrientation ... resetCamera calls to revert the orientation back.

Testing

Checklist

PR

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

Code

Public Documentation Updates

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

Tested Environment

  • "OS: Linux 6.13.2-arch1-1
  • "Node version: v20.18
  • "Browser: Chrome 133

When calling setOrientation with an OrientationVectors,
update the viewportProperties.orientation so that is does not
revert back the orientation when subsequently
calling resetCamera in applyViewOrientation.
Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for cornerstone-3d-docs ready!

Name Link
🔨 Latest commit f91c7f5
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/67b78a0aee0d7a00086fa17c
😎 Deploy Preview https://deploy-preview-1842--cornerstone-3d-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

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