-
Notifications
You must be signed in to change notification settings - Fork 456
Feat: Axis-based Image Stretching #2443
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
Open
arul-trenser
wants to merge
19
commits into
cornerstonejs:main
Choose a base branch
from
arul-trenser:feat-axis-based-image-stretching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cb13f4f
feature for axis based stretching
arul-trenser 34696fa
fix unit tests
arul-trenser ccaf796
Normalize pan to remove effect of stretch
arul-trenser b0e7319
fix: radii calc
arul-trenser eea06d9
removed aspectRatio property in CPUFallbackViewport
arul-trenser e98f687
Added example for axialBasedImageStretching
arul-trenser 6e4f744
fixed build issue
arul-trenser 240a378
Review comments updated
arul-trenser e5dcbf2
Added aspectRatio property to viewport
arul-trenser 2570a00
updated getCenterAndRadiusInCanvas to use world and canvas point
arul-trenser 6dd83f8
Added documentation for tools
arul-trenser 700ecbf
Merge remote-tracking branch 'origin/main' into feat-axis-based-image…
wayfarer3130 920e348
Add aspect ratio testing for resize and calibration
wayfarer3130 5ad78bc
fix review comments
arul-trenser b778c4b
fixed the resize issue for aspectRatio
arul-trenser 1d22a40
Modified the getProjectionScaleIndices to getProjectScaleMatrix
arul-trenser 8f832ab
Fixed unit test
arul-trenser e31cc95
Merge branch 'cornerstonejs:main' into feat-axis-based-image-stretching
arul-trenser bbd9ee8
fixed review comments
arul-trenser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/core/src/RenderingEngine/helpers/getProjectionScaleMatrix.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { mat4, vec3 } from 'gl-matrix'; | ||
|
|
||
| const EPSILON = 1e-6; | ||
|
|
||
| /** | ||
| * Computes a projection scaling matrix with rotation-invariant scaling in patient | ||
| * coordinate space. The stretch follows patient anatomical directions (AP or SI) | ||
| * rather than screen axes, maintaining consistent scaling after view rotations. | ||
| * | ||
| * @param viewUp - Camera viewUp vector in patient space | ||
| * @param viewPlaneNormal - Camera viewPlaneNormal vector in patient space | ||
| * @param aspectRatio - [scaleX, scaleY]. scaleY applies to dominant anatomical axis | ||
| * @returns Projection scaling matrix | ||
| */ | ||
| export function getProjectionScaleMatrix( | ||
| viewUp: vec3, | ||
| viewPlaneNormal: vec3, | ||
| aspectRatio: Array<number> | ||
| ): mat4 { | ||
| // Normalize inputs | ||
| const up = vec3.normalize(vec3.create(), viewUp); | ||
| const vpn = vec3.normalize(vec3.create(), viewPlaneNormal); | ||
|
|
||
| // Screen Right axis (RH system: Up × Normal) | ||
| const viewRight = vec3.create(); | ||
| vec3.cross(viewRight, up, vpn); | ||
|
|
||
| // Fallback if Up and Normal are nearly parallel | ||
| if (vec3.length(viewRight) < EPSILON) { | ||
| // Select a non-parallel basis vector | ||
| const tmp = | ||
| Math.abs(up[0]) < 1 / Math.sqrt(2) | ||
| ? vec3.fromValues(1, 0, 0) | ||
| : vec3.fromValues(0, 1, 0); | ||
| vec3.cross(viewRight, tmp, up); | ||
| } | ||
| vec3.normalize(viewRight, viewRight); | ||
| const [scaleX, scaleY] = aspectRatio; | ||
|
|
||
| // Project patient anatomical axes onto view plane to determine stretch direction | ||
| const projectToPlane = (axis: vec3) => { | ||
| const dot = vec3.dot(axis, vpn); | ||
| const projection = vec3.create(); | ||
| vec3.scaleAndAdd(projection, axis, vpn, -dot); | ||
| return projection; | ||
| }; | ||
|
|
||
| const projY = projectToPlane(vec3.fromValues(0, 1, 0)); | ||
| const projZ = projectToPlane(vec3.fromValues(0, 0, 1)); | ||
|
|
||
| // Use most visible anatomical axis as stretch direction | ||
| const stretchAxis = vec3.length(projY) > vec3.length(projZ) ? projY : projZ; | ||
| vec3.normalize(stretchAxis, stretchAxis); | ||
|
|
||
| // Scale based on alignment: aligned -> scaleY, perpendicular -> scaleX | ||
| function getScaleFactor(screenVec: vec3): number { | ||
| const alignment = Math.abs(vec3.dot(screenVec, stretchAxis)); | ||
| return alignment * scaleY + (1 - alignment) * scaleX; | ||
| } | ||
|
|
||
| const out = mat4.create(); | ||
| return mat4.fromScaling(out, [ | ||
| getScaleFactor(viewRight), | ||
| getScaleFactor(up), | ||
| 1.0, | ||
| ]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.