Skip to content

Commit

Permalink
refactor(MultiscaleSpatialImage): better naming on internal vars
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Jun 4, 2024
1 parent c96acc6 commit 7332d2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/element/examples/image-io-read-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ document.addEventListener('DOMContentLoaded', async function () {
const viewerElement = document.querySelector('#viewer')! as ItkViewer2d;
const viewer = viewerElement.getActor();

// const path = 'prostate-slight-rotation.nrrd';
const path = 'prostate-slight-rotation.nrrd';
const url = new URL(path, document.location.origin);
const response = await fetch(url.href);
Expand Down
15 changes: 8 additions & 7 deletions packages/io/src/MultiscaleSpatialImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,21 @@ const makeMat4 = ({
return mat4.scale(mat, mat, spacing);
};

type Maybe2dVec =
// Number array of length 2 or 3
type Vec2dOr3d =
| [number, number]
| [number, number, number]
| vec3
| Array<number>;
| Array<number>
| vec3;

const maybe2dSpatialToMat4 = ({
direction: inDirection,
origin,
spacing,
}: {
direction: ReadonlyFloatArray;
origin: Maybe2dVec;
spacing: Maybe2dVec;
origin: Vec2dOr3d;
spacing: Vec2dOr3d;
}) => {
const inDirection3d = ensure3dDirection(inDirection);
// ITK (and VTKMath) uses row-major index axis, but gl-matrix uses column-major. Transpose.
Expand Down Expand Up @@ -294,11 +295,11 @@ const normalizedImageBoundsToIndexBounds = (
arrayShape: ChunkParameter,
normalizedImageBounds: ReadonlyBounds,
) => {
const toIndexScale = XYZ.map((axis) => arrayShape.get(axis) ?? 1);
const normalizedToIndexScale = XYZ.map((axis) => arrayShape.get(axis) ?? 1);
const normalizedToIndex = maybe2dSpatialToMat4({
direction: mat3.identity(mat3.create()),
origin: vec3.create(),
spacing: toIndexScale,
spacing: normalizedToIndexScale,
}) as ReadonlyMat4;
const indexBounds = transformBounds(normalizedToIndex, normalizedImageBounds);
return indexBounds;
Expand Down

0 comments on commit 7332d2d

Please sign in to comment.