fix(VolumeViewport) fix viewportProperties on VolumeViewport setOrientation #1842
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
In
setViewReference
, when the new view reference normal is not aligned with the previous one, a call tosetOrientation
followed bysetViewReference
is doneThe 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 someOrientationVectors
but does not remove theviewportProperties.orientation
value (which is some case can be defined, such asaxial
from the previous volume).This will ultimately lead to
applyViewOrientation
, where the call toresetCamera
reverts back the orientation becauseviewportProperties.orientation === 'axial'
Changes & Results
I am resetting the
viewportProperties.orientation
value toundefined
whensetOrientation
is called withOrientationVectors
. This will prevent theapplyViewOrientation ... resetCamera
calls to revert the orientation back.Testing
Checklist
PR
semantic-release format and guidelines.
Code
My code has been well-documented (function documentation, inline comments,
etc.)
I have run the
yarn build:update-api
to update the API documentation, and havecommitted the changes to this PR. (Read more here https://www.cornerstonejs.org/docs/contribute/update-api)
Public Documentation Updates
additions or removals.
Tested Environment