copper3d 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +16 -3
  2. package/ai-index/guides/load-callbacks.md +24 -5
  3. package/ai-index/guides/orientation.md +155 -0
  4. package/ai-index/guides/segmentation-module.md +51 -25
  5. package/ai-index/guides/volume-display.md +1 -1
  6. package/ai-index/manifest.json +14 -6
  7. package/ai-index/symbols.json +1 -1
  8. package/dist/Controls/orbitFraming.d.ts +4 -4
  9. package/dist/Controls/orbitFraming.js +4 -4
  10. package/dist/Loader/copperNrrdLoader.d.ts +15 -1
  11. package/dist/Loader/copperNrrdLoader.js +30 -8
  12. package/dist/Loader/copperNrrdLoader.js.map +1 -1
  13. package/dist/Loader/nrrdWorkerCore.d.ts +15 -2
  14. package/dist/Loader/nrrdWorkerCore.js +47 -3
  15. package/dist/Loader/nrrdWorkerCore.js.map +1 -1
  16. package/dist/Loader/rasDimensions.d.ts +9 -0
  17. package/dist/Loader/rasDimensions.js +12 -0
  18. package/dist/Loader/rasDimensions.js.map +1 -0
  19. package/dist/Scene/commonSceneMethod.d.ts +10 -1
  20. package/dist/Scene/commonSceneMethod.js +11 -3
  21. package/dist/Scene/commonSceneMethod.js.map +1 -1
  22. package/dist/Utils/orientation.d.ts +94 -0
  23. package/dist/Utils/orientation.js +261 -0
  24. package/dist/Utils/orientation.js.map +1 -0
  25. package/dist/Utils/segmentation/NrrdTools.d.ts +4 -0
  26. package/dist/Utils/segmentation/NrrdTools.js +4 -2
  27. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  28. package/dist/Utils/segmentation/RenderingUtils.d.ts +0 -5
  29. package/dist/Utils/segmentation/RenderingUtils.js +3 -23
  30. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
  31. package/dist/Utils/segmentation/contourPaint.d.ts +5 -0
  32. package/dist/Utils/segmentation/contourPaint.js +10 -3
  33. package/dist/Utils/segmentation/contourPaint.js.map +1 -1
  34. package/dist/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  35. package/dist/Utils/segmentation/core/MaskVolume.js +38 -38
  36. package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
  37. package/dist/Utils/segmentation/tools/AiAssistTool.js +10 -10
  38. package/dist/Utils/segmentation/tools/AiAssistTool.js.map +1 -1
  39. package/dist/Utils/segmentation/tools/ContrastTool.js +1 -1
  40. package/dist/Utils/segmentation/tools/CrosshairTool.js +30 -22
  41. package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
  42. package/dist/Utils/segmentation/tools/DrawingTool.js +14 -14
  43. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
  44. package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +3 -5
  45. package/dist/Utils/segmentation/tools/ImageStoreHelper.js +7 -11
  46. package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
  47. package/dist/Utils/segmentation/tools/MaskMirror.js +5 -5
  48. package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -1
  49. package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +28 -4
  50. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +50 -24
  51. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
  52. package/dist/Utils/segmentation/tools/SphereBrushTool.js +5 -4
  53. package/dist/Utils/segmentation/tools/SphereBrushTool.js.map +1 -1
  54. package/dist/Utils/segmentation/tools/SphereTool.js +13 -11
  55. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
  56. package/dist/bundle.esm.mjs +611 -312
  57. package/dist/bundle.umd.js +618 -311
  58. package/dist/index.d.ts +5 -2
  59. package/dist/index.js +3 -1
  60. package/dist/index.js.map +1 -1
  61. package/dist/types/Controls/orbitFraming.d.ts +4 -4
  62. package/dist/types/Loader/copperNrrdLoader.d.ts +15 -1
  63. package/dist/types/Loader/nrrdWorkerCore.d.ts +15 -2
  64. package/dist/types/Loader/rasDimensions.d.ts +9 -0
  65. package/dist/types/Scene/commonSceneMethod.d.ts +10 -1
  66. package/dist/types/Utils/orientation.d.ts +94 -0
  67. package/dist/types/Utils/segmentation/NrrdTools.d.ts +4 -0
  68. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +0 -5
  69. package/dist/types/Utils/segmentation/contourPaint.d.ts +5 -0
  70. package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  71. package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +3 -5
  72. package/dist/types/Utils/segmentation/tools/SliceRenderPipeline.d.ts +28 -4
  73. package/dist/types/index.d.ts +5 -2
  74. package/package.json +1 -1
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The canonical voxel order, and the rule that puts any volume into it.
3
+ *
4
+ * Canonical order: voxel index i increases toward the patient's Left, j toward Posterior, k
5
+ * toward Superior. Axis codes use the TOWARD convention of DICOM, nibabel and SimpleITK, so "LPS"
6
+ * names that order (legacy ITK and ITK-SNAP call the same order "RAI").
7
+ *
8
+ * Each native axis is assigned the anatomical axis it is nearest to and flipped when it points the
9
+ * other way. That is a permutation and flips, never a resampling, so obliquity stays in the
10
+ * geometry instead of being snapped away. With the voxels in this order, the fixed per-axis display
11
+ * mapping (SliceRenderPipeline.flipDisplayImageByAxis) shows every volume in the radiological
12
+ * convention, whatever order its file stores.
13
+ *
14
+ * The backend (app/geometry/canonical.py) implements the same rule for everything it reads and
15
+ * writes. The app holds both to one fixture, annotator-backend/tests/fixtures/orientation_cases.json.
16
+ *
17
+ * Pure: no DOM and no three, so it runs inside the NRRD worker as well as on the main thread.
18
+ */
19
+ export type Vec3 = [number, number, number];
20
+ /** A voxel grid in patient space. */
21
+ export interface VolumeGeometry {
22
+ dims: Vec3;
23
+ /** `directions[a]` is one step along voxel axis a, in LPS millimetres. Its length is the spacing. */
24
+ directions: [Vec3, Vec3, Vec3];
25
+ /** The LPS position of the centre of voxel (0, 0, 0). */
26
+ origin: Vec3;
27
+ }
28
+ /** From the native voxel order to a target order. */
29
+ export interface OrientationTransform {
30
+ /** `perm[c]` is the native axis that becomes axis c. */
31
+ perm: Vec3;
32
+ /** `flip[c]`: index c runs opposite to that native axis (c = n - 1 - native). */
33
+ flip: [boolean, boolean, boolean];
34
+ /** The angle between axis c and its anatomical axis, in degrees. */
35
+ obliquityDeg: Vec3;
36
+ }
37
+ export type OrientationErrorCode = "no_space" | "time_space" | "scanner_space" | "non_anatomical_space" | "unknown_space" | "no_directions" | "not_3d" | "no_origin" | "degenerate" | "ambiguous_oblique";
38
+ /** A volume whose patient orientation cannot be established. It is refused, never guessed. */
39
+ export declare class OrientationError extends Error {
40
+ readonly code: OrientationErrorCode;
41
+ readonly detail: string;
42
+ constructor(code: OrientationErrorCode, detail: string);
43
+ }
44
+ /** How a loaded volume reached the canonical order, and where its canonical grid lies in patient space. */
45
+ export interface VolumeOrientation {
46
+ /** The transform the file's voxels went through. */
47
+ transform: OrientationTransform;
48
+ /** The file's own dims, before reordering. */
49
+ nativeDims: Vec3;
50
+ /** The canonical grid in LPS, obliquity included. Unlike `volume.matrix`, this is never snapped. */
51
+ geometry: VolumeGeometry;
52
+ }
53
+ /** The orientation fields of an NRRD header, as written in the file. */
54
+ export interface NrrdOrientationFields {
55
+ space: string | null;
56
+ sizes: number[];
57
+ /** One vector per axis; `null` where the file says `none` (a non-spatial axis). */
58
+ spaceDirections: (number[] | null)[] | null;
59
+ spaceOrigin: number[] | null;
60
+ }
61
+ export type ViewAxis = "x" | "y" | "z";
62
+ export interface ViewLabels {
63
+ left: string;
64
+ right: string;
65
+ top: string;
66
+ bottom: string;
67
+ }
68
+ /**
69
+ * The text header of an NRRD document: everything before the first blank line. Read here instead
70
+ * of taken from three's NRRDLoader, which fills in identity directions when a file has none and so
71
+ * makes "no orientation" indistinguishable from "identity".
72
+ */
73
+ export declare function nrrdHeaderText(buffer: ArrayBuffer): string;
74
+ /** Reads the orientation fields from an NRRD header's text. Comments and `key:=value` pairs are skipped. */
75
+ export declare function readNrrdOrientationFields(headerText: string): NrrdOrientationFields;
76
+ /** An NRRD's geometry in LPS. Throws OrientationError when its patient orientation cannot be established. */
77
+ export declare function geometryFromNrrd(fields: NrrdOrientationFields): VolumeGeometry;
78
+ /** The transform into the voxel order that `codes` names (TOWARD), e.g. "LPS" or "RAI". */
79
+ export declare function orientationTransform(geometry: VolumeGeometry, codes?: string): OrientationTransform;
80
+ /** The transform into the canonical order (i->L, j->P, k->S). */
81
+ export declare function canonicalTransform(geometry: VolumeGeometry): OrientationTransform;
82
+ export declare function isIdentityTransform(transform: OrientationTransform): boolean;
83
+ /** The same grid described in the transform's voxel order. The origin moves to the new first voxel. */
84
+ export declare function reorientedGeometry(geometry: VolumeGeometry, transform: OrientationTransform): VolumeGeometry;
85
+ type VoxelArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
86
+ /**
87
+ * Voxels (i fastest, as NRRD stores them) rewritten in the transform's order. The identity
88
+ * returns `data` itself, with no copy; any other transform returns a new array of the same type.
89
+ */
90
+ export declare function reorientVoxels<T extends VoxelArray>(data: T, dims: Vec3, transform: OrientationTransform): T;
91
+ /** The orientation letters at each screen edge of a view of a canonical grid. */
92
+ export declare function viewLabels(axis: ViewAxis, geometry: VolumeGeometry): ViewLabels;
93
+ export declare function spacingOf(geometry: VolumeGeometry): Vec3;
94
+ export {};
@@ -0,0 +1,261 @@
1
+ /**
2
+ * The canonical voxel order, and the rule that puts any volume into it.
3
+ *
4
+ * Canonical order: voxel index i increases toward the patient's Left, j toward Posterior, k
5
+ * toward Superior. Axis codes use the TOWARD convention of DICOM, nibabel and SimpleITK, so "LPS"
6
+ * names that order (legacy ITK and ITK-SNAP call the same order "RAI").
7
+ *
8
+ * Each native axis is assigned the anatomical axis it is nearest to and flipped when it points the
9
+ * other way. That is a permutation and flips, never a resampling, so obliquity stays in the
10
+ * geometry instead of being snapped away. With the voxels in this order, the fixed per-axis display
11
+ * mapping (SliceRenderPipeline.flipDisplayImageByAxis) shows every volume in the radiological
12
+ * convention, whatever order its file stores.
13
+ *
14
+ * The backend (app/geometry/canonical.py) implements the same rule for everything it reads and
15
+ * writes. The app holds both to one fixture, annotator-backend/tests/fixtures/orientation_cases.json.
16
+ *
17
+ * Pure: no DOM and no three, so it runs inside the NRRD worker as well as on the main thread.
18
+ */
19
+ /** A volume whose patient orientation cannot be established. It is refused, never guessed. */
20
+ export class OrientationError extends Error {
21
+ constructor(code, detail) {
22
+ super(`${code}: ${detail}`);
23
+ this.name = "OrientationError";
24
+ this.code = code;
25
+ this.detail = detail;
26
+ }
27
+ }
28
+ /** A screen axis more than 1 degree off an anatomical axis also gets that axis's letter (the rule
29
+ * of 3D Slicer's GetDirectionLabel). */
30
+ const LABEL_TOL = Math.sin((1 * Math.PI) / 180);
31
+ /** At 45 degrees an axis is equally near two anatomical axes, so it has no nearest one. */
32
+ const AMBIGUOUS_COS = Math.cos((45 * Math.PI) / 180) + 1e-9;
33
+ /** NRRD space -> the per-component signs that turn its coordinates into LPS. */
34
+ const LPS_SIGNS = {
35
+ "left-posterior-superior": [1, 1, 1],
36
+ lps: [1, 1, 1],
37
+ "right-anterior-superior": [-1, -1, 1],
38
+ ras: [-1, -1, 1],
39
+ "left-anterior-superior": [1, -1, 1],
40
+ las: [1, -1, 1],
41
+ };
42
+ const TIME_SPACES = new Set(["rast", "last", "lpst"]);
43
+ const NON_ANATOMICAL_SPACES = new Set(["3d-right-handed", "3d-left-handed"]);
44
+ /** TOWARD letter -> [patient axis in LPS, sign]. */
45
+ const LETTERS = {
46
+ L: [0, 1], R: [0, -1], P: [1, 1], A: [1, -1], S: [2, 1], I: [2, -1],
47
+ };
48
+ /**
49
+ * Each view's screen-right and screen-down steps in canonical index space, as
50
+ * SliceRenderPipeline.flipDisplayImageByAxis draws them. A layout change there changes this
51
+ * table in the same commit.
52
+ */
53
+ const VIEW_LAYOUT = {
54
+ z: [[1, 0, 0], [0, 1, 0]], // axial: right = +i, down = +j
55
+ y: [[1, 0, 0], [0, 0, -1]], // coronal: right = +i, down = -k
56
+ x: [[0, 1, 0], [0, 0, -1]], // sagittal: right = +j, down = -k
57
+ };
58
+ /** The longest header looked for; NRRD headers are a few hundred bytes. */
59
+ const MAX_HEADER_BYTES = 64 * 1024;
60
+ /**
61
+ * The text header of an NRRD document: everything before the first blank line. Read here instead
62
+ * of taken from three's NRRDLoader, which fills in identity directions when a file has none and so
63
+ * makes "no orientation" indistinguishable from "identity".
64
+ */
65
+ export function nrrdHeaderText(buffer) {
66
+ const bytes = new Uint8Array(buffer, 0, Math.min(buffer.byteLength, MAX_HEADER_BYTES));
67
+ if (String.fromCharCode(...bytes.subarray(0, 4)) !== "NRRD")
68
+ throw new Error("not an NRRD document (no NRRD magic)");
69
+ for (let n = 0; n < bytes.length - 1; n++) {
70
+ if (bytes[n] !== 0x0a)
71
+ continue;
72
+ const blankLf = bytes[n + 1] === 0x0a;
73
+ const blankCrlf = bytes[n + 1] === 0x0d && bytes[n + 2] === 0x0a;
74
+ if (blankLf || blankCrlf) {
75
+ const end = n > 0 && bytes[n - 1] === 0x0d ? n - 1 : n;
76
+ return new TextDecoder("latin1").decode(bytes.subarray(0, end));
77
+ }
78
+ }
79
+ throw new Error("NRRD header has no terminating blank line");
80
+ }
81
+ /** Reads the orientation fields from an NRRD header's text. Comments and `key:=value` pairs are skipped. */
82
+ export function readNrrdOrientationFields(headerText) {
83
+ var _a;
84
+ const out = { space: null, sizes: [], spaceDirections: null, spaceOrigin: null };
85
+ for (const line of headerText.split(/\r?\n/)) {
86
+ if (line.startsWith("#"))
87
+ continue;
88
+ const colon = line.indexOf(":");
89
+ if (colon < 0 || line[colon + 1] === "=")
90
+ continue;
91
+ const name = line.slice(0, colon).trim().toLowerCase();
92
+ const value = line.slice(colon + 1).trim();
93
+ if (name === "space")
94
+ out.space = value;
95
+ else if (name === "sizes")
96
+ out.sizes = value.split(/\s+/).map((n) => parseInt(n, 10));
97
+ else if (name === "space directions")
98
+ out.spaceDirections = parseVectors(value);
99
+ else if (name === "space origin")
100
+ out.spaceOrigin = (_a = parseVectors(value)[0]) !== null && _a !== void 0 ? _a : null;
101
+ }
102
+ return out;
103
+ }
104
+ /** An NRRD's geometry in LPS. Throws OrientationError when its patient orientation cannot be established. */
105
+ export function geometryFromNrrd(fields) {
106
+ var _a;
107
+ const space = (_a = fields.space) === null || _a === void 0 ? void 0 : _a.trim();
108
+ if (!space) {
109
+ throw new OrientationError("no_space", "the header has no 'space' field, so its patient orientation is unknown");
110
+ }
111
+ const name = space.toLowerCase();
112
+ if (name.endsWith("-time") || TIME_SPACES.has(name)) {
113
+ throw new OrientationError("time_space", `space '${space}' is a time series; only 3D volumes are supported`);
114
+ }
115
+ if (name === "scanner-xyz") {
116
+ throw new OrientationError("scanner_space", "space 'scanner-xyz' is in scanner coordinates, whose patient orientation depends on how the patient lay (breast MRI is acquired prone)");
117
+ }
118
+ if (NON_ANATOMICAL_SPACES.has(name)) {
119
+ throw new OrientationError("non_anatomical_space", `space '${space}' has no anatomical meaning`);
120
+ }
121
+ const signs = LPS_SIGNS[name];
122
+ if (!signs)
123
+ throw new OrientationError("unknown_space", `space '${space}' is not a recognised anatomical space`);
124
+ const vectors = fields.spaceDirections;
125
+ if (!vectors || vectors.length === 0)
126
+ throw new OrientationError("no_directions", "the header has no 'space directions'");
127
+ if (fields.sizes.length !== 3 || vectors.length !== 3 || vectors.some((v) => v === null || v.length !== 3)) {
128
+ throw new OrientationError("not_3d", `expected 3 spatial axes, got sizes [${fields.sizes.join(", ")}]`);
129
+ }
130
+ if (!fields.spaceOrigin || fields.spaceOrigin.length !== 3) {
131
+ throw new OrientationError("no_origin", "the header has no 'space origin', so the grid has no patient position");
132
+ }
133
+ // "+ 0" turns a negated zero into 0, so a converted axis compares equal to the literal.
134
+ const directions = vectors.map((v) => v.map((c, x) => c * signs[x] + 0));
135
+ const origin = fields.spaceOrigin.map((c, x) => c * signs[x] + 0);
136
+ return checked({ dims: [fields.sizes[0], fields.sizes[1], fields.sizes[2]], directions, origin });
137
+ }
138
+ /** The transform into the voxel order that `codes` names (TOWARD), e.g. "LPS" or "RAI". */
139
+ export function orientationTransform(geometry, codes = "LPS") {
140
+ const target = parseCodes(codes);
141
+ const spacing = spacingOf(geometry);
142
+ const units = geometry.directions.map((d, a) => d.map((c) => c / spacing[a]));
143
+ const nearest = units.map((u) => [0, 1, 2].reduce((best, x) => (Math.abs(u[x]) > Math.abs(u[best]) ? x : best), 0));
144
+ const strength = units.map((u, a) => Math.abs(u[nearest[a]]));
145
+ const obliquity = strength.map((s) => (Math.acos(Math.min(1, s)) * 180) / Math.PI);
146
+ if (strength.some((s) => s <= AMBIGUOUS_COS) || new Set(nearest).size !== 3) {
147
+ throw new OrientationError("ambiguous_oblique", `a voxel axis is ${Math.max(...obliquity).toFixed(1)} degrees from every anatomical axis, so it has no nearest one`);
148
+ }
149
+ const perm = [0, 0, 0];
150
+ const flip = [false, false, false];
151
+ const obliquityDeg = [0, 0, 0];
152
+ target.forEach(([patientAxis, sign], axis) => {
153
+ const native = nearest.indexOf(patientAxis);
154
+ perm[axis] = native;
155
+ flip[axis] = Math.sign(units[native][patientAxis]) !== sign;
156
+ obliquityDeg[axis] = obliquity[native];
157
+ });
158
+ return { perm, flip, obliquityDeg };
159
+ }
160
+ /** The transform into the canonical order (i->L, j->P, k->S). */
161
+ export function canonicalTransform(geometry) {
162
+ return orientationTransform(geometry, "LPS");
163
+ }
164
+ export function isIdentityTransform(transform) {
165
+ return transform.perm[0] === 0 && transform.perm[1] === 1 && transform.perm[2] === 2 && !transform.flip.some(Boolean);
166
+ }
167
+ /** The same grid described in the transform's voxel order. The origin moves to the new first voxel. */
168
+ export function reorientedGeometry(geometry, transform) {
169
+ const origin = [...geometry.origin];
170
+ transform.perm.forEach((native, axis) => {
171
+ if (!transform.flip[axis])
172
+ return;
173
+ for (let x = 0; x < 3; x++)
174
+ origin[x] += (geometry.dims[native] - 1) * geometry.directions[native][x];
175
+ });
176
+ return {
177
+ dims: transform.perm.map((native) => geometry.dims[native]),
178
+ // "+ 0" turns a negated zero into 0 (see geometryFromNrrd).
179
+ directions: transform.perm.map((native, axis) => geometry.directions[native].map((c) => (transform.flip[axis] ? -c : c) + 0)),
180
+ origin,
181
+ };
182
+ }
183
+ /**
184
+ * Voxels (i fastest, as NRRD stores them) rewritten in the transform's order. The identity
185
+ * returns `data` itself, with no copy; any other transform returns a new array of the same type.
186
+ */
187
+ export function reorientVoxels(data, dims, transform) {
188
+ if (data.length !== dims[0] * dims[1] * dims[2]) {
189
+ throw new Error(`voxel count ${data.length} does not fill a ${dims.join("x")} grid`);
190
+ }
191
+ if (isIdentityTransform(transform))
192
+ return data;
193
+ const nativeStride = [1, dims[0], dims[0] * dims[1]];
194
+ const outDims = transform.perm.map((native) => dims[native]);
195
+ const step = transform.perm.map((native, axis) => (transform.flip[axis] ? -1 : 1) * nativeStride[native]);
196
+ let start = 0;
197
+ transform.perm.forEach((native, axis) => {
198
+ if (transform.flip[axis])
199
+ start += (dims[native] - 1) * nativeStride[native];
200
+ });
201
+ const out = new data.constructor(data.length);
202
+ let n = 0;
203
+ for (let c2 = 0, base2 = start; c2 < outDims[2]; c2++, base2 += step[2]) {
204
+ for (let c1 = 0, base1 = base2; c1 < outDims[1]; c1++, base1 += step[1]) {
205
+ for (let c0 = 0, index = base1; c0 < outDims[0]; c0++, index += step[0]) {
206
+ out[n++] = data[index];
207
+ }
208
+ }
209
+ }
210
+ return out;
211
+ }
212
+ /** The orientation letters at each screen edge of a view of a canonical grid. */
213
+ export function viewLabels(axis, geometry) {
214
+ const spacing = spacingOf(geometry);
215
+ const units = geometry.directions.map((d, a) => d.map((c) => c / spacing[a]));
216
+ const along = (step) => [0, 1, 2].map((x) => step[0] * units[0][x] + step[1] * units[1][x] + step[2] * units[2][x]);
217
+ const [rightStep, downStep] = VIEW_LAYOUT[axis];
218
+ const right = along(rightStep);
219
+ const down = along(downStep);
220
+ const negate = (v) => v.map((c) => -c);
221
+ return { left: letters(negate(right)), right: letters(right), top: letters(negate(down)), bottom: letters(down) };
222
+ }
223
+ export function spacingOf(geometry) {
224
+ return geometry.directions.map((d) => Math.hypot(d[0], d[1], d[2]));
225
+ }
226
+ function letters(direction) {
227
+ return [0, 1, 2]
228
+ .filter((x) => Math.abs(direction[x]) > LABEL_TOL)
229
+ .sort((a, b) => Math.abs(direction[b]) - Math.abs(direction[a]))
230
+ .map((x) => (direction[x] > 0 ? "LPS" : "RAI")[x])
231
+ .join("");
232
+ }
233
+ function parseCodes(codes) {
234
+ if (codes.length !== 3 || [...codes].some((c) => !(c in LETTERS))) {
235
+ throw new Error(`not a three-letter orientation code: '${codes}'`);
236
+ }
237
+ const target = [...codes].map((c) => LETTERS[c]);
238
+ if (new Set(target.map(([patientAxis]) => patientAxis)).size !== 3) {
239
+ throw new Error(`orientation code '${codes}' names a patient axis twice`);
240
+ }
241
+ return target;
242
+ }
243
+ function parseVectors(text) {
244
+ const out = [];
245
+ for (const match of text.matchAll(/\(([^)]*)\)|none/gi)) {
246
+ out.push(match[1] === undefined ? null : match[1].split(",").map((c) => parseFloat(c)));
247
+ }
248
+ return out;
249
+ }
250
+ function checked(geometry) {
251
+ const values = [...geometry.directions.flat(), ...geometry.origin];
252
+ if (values.some((v) => !Number.isFinite(v))) {
253
+ throw new OrientationError("degenerate", "the geometry contains non-finite values");
254
+ }
255
+ const spacing = spacingOf(geometry);
256
+ if (spacing.some((s) => s <= 1e-12) || geometry.dims.some((n) => !(n >= 1))) {
257
+ throw new OrientationError("degenerate", `a voxel axis has no extent (dims [${geometry.dims.join(", ")}], spacing [${spacing.join(", ")}])`);
258
+ }
259
+ return geometry;
260
+ }
261
+ //# sourceMappingURL=orientation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orientation.js","sourceRoot":"","sources":["../../src/Utils/orientation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAmCH,8FAA8F;AAC9F,MAAM,OAAO,gBAAiB,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AC;IACpC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,gBAAgB,CACxB,YAAY,EACZ,qCAAqC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CACnG,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -471,6 +471,10 @@ export declare class NrrdTools {
471
471
  */
472
472
  dispose(): void;
473
473
  configMouseSliceWheel(): (e: WheelEvent) => void;
474
+ /**
475
+ * Rebuilds the zoom/slice wheel handler for the current wheel setting. It attaches no listener:
476
+ * the EventRouter owns the canvas's `wheel` event and calls this handler in zoom mode only.
477
+ */
474
478
  updateMouseWheelEvent(): void;
475
479
  setIsDrawFalse(target: number): void;
476
480
  private setShowInMainArea;
@@ -1455,8 +1455,11 @@ export class NrrdTools {
1455
1455
  };
1456
1456
  return handleMouseZoomSliceWheelMove;
1457
1457
  }
1458
+ /**
1459
+ * Rebuilds the zoom/slice wheel handler for the current wheel setting. It attaches no listener:
1460
+ * the EventRouter owns the canvas's `wheel` event and calls this handler in zoom mode only.
1461
+ */
1458
1462
  updateMouseWheelEvent() {
1459
- this.state.protectedData.canvases.drawingCanvas.removeEventListener("wheel", this.drawCore.drawingPrameters.handleMouseZoomSliceWheel);
1460
1463
  switch (this.state.keyboardSettings.mouseWheel) {
1461
1464
  case "Scroll:Zoom":
1462
1465
  this.drawCore.drawingPrameters.handleMouseZoomSliceWheel = this.drawCore.configMouseZoomWheel();
@@ -1468,7 +1471,6 @@ export class NrrdTools {
1468
1471
  this.drawCore.drawingPrameters.handleMouseZoomSliceWheel = this.drawCore.configMouseZoomWheel();
1469
1472
  break;
1470
1473
  }
1471
- this.state.protectedData.canvases.drawingCanvas.addEventListener("wheel", this.drawCore.drawingPrameters.handleMouseZoomSliceWheel);
1472
1474
  }
1473
1475
  // ═══════════════════════════════════════════════════════════════════════════
1474
1476
  // 13. Internal — Utility