@fideus-labs/fidnii 0.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.
- package/LICENSE.txt +9 -0
- package/README.md +180 -0
- package/dist/BufferManager.d.ts +86 -0
- package/dist/BufferManager.d.ts.map +1 -0
- package/dist/BufferManager.js +146 -0
- package/dist/BufferManager.js.map +1 -0
- package/dist/ClipPlanes.d.ts +180 -0
- package/dist/ClipPlanes.d.ts.map +1 -0
- package/dist/ClipPlanes.js +513 -0
- package/dist/ClipPlanes.js.map +1 -0
- package/dist/OMEZarrNVImage.d.ts +545 -0
- package/dist/OMEZarrNVImage.d.ts.map +1 -0
- package/dist/OMEZarrNVImage.js +1799 -0
- package/dist/OMEZarrNVImage.js.map +1 -0
- package/dist/RegionCoalescer.d.ts +75 -0
- package/dist/RegionCoalescer.d.ts.map +1 -0
- package/dist/RegionCoalescer.js +151 -0
- package/dist/RegionCoalescer.js.map +1 -0
- package/dist/ResolutionSelector.d.ts +88 -0
- package/dist/ResolutionSelector.d.ts.map +1 -0
- package/dist/ResolutionSelector.js +224 -0
- package/dist/ResolutionSelector.js.map +1 -0
- package/dist/ViewportBounds.d.ts +50 -0
- package/dist/ViewportBounds.d.ts.map +1 -0
- package/dist/ViewportBounds.js +325 -0
- package/dist/ViewportBounds.js.map +1 -0
- package/dist/events.d.ts +122 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +12 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +273 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +126 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/affine.d.ts +72 -0
- package/dist/utils/affine.d.ts.map +1 -0
- package/dist/utils/affine.js +173 -0
- package/dist/utils/affine.js.map +1 -0
- package/dist/utils/coordinates.d.ts +80 -0
- package/dist/utils/coordinates.d.ts.map +1 -0
- package/dist/utils/coordinates.js +207 -0
- package/dist/utils/coordinates.js.map +1 -0
- package/package.json +61 -0
- package/src/BufferManager.ts +176 -0
- package/src/ClipPlanes.ts +640 -0
- package/src/OMEZarrNVImage.ts +2286 -0
- package/src/RegionCoalescer.ts +217 -0
- package/src/ResolutionSelector.ts +325 -0
- package/src/ViewportBounds.ts +369 -0
- package/src/events.ts +146 -0
- package/src/index.ts +153 -0
- package/src/types.ts +429 -0
- package/src/utils/affine.ts +218 -0
- package/src/utils/coordinates.ts +271 -0
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { SLICE_TYPE } from "@niivue/niivue";
|
|
2
|
+
import type { ClipPlanes } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Identifies what triggered a volume population.
|
|
5
|
+
* Extensible for future triggers (pan, zoom, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export type PopulateTrigger = "initial" | "clipPlanesChanged" | "sliceChanged" | "viewportChanged";
|
|
8
|
+
/**
|
|
9
|
+
* Type-safe event map for OMEZarrNVImage events.
|
|
10
|
+
* Maps event names to their detail types.
|
|
11
|
+
*
|
|
12
|
+
* Uses the browser-native EventTarget API pattern, following the same
|
|
13
|
+
* conventions as NiiVue's event system (see niivue/niivue#1530).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Type-safe event listening
|
|
18
|
+
* image.addEventListener('resolutionChange', (event) => {
|
|
19
|
+
* console.log('Resolution changed:', event.detail.currentLevel);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // One-time listener
|
|
23
|
+
* image.addEventListener('loadingComplete', (event) => {
|
|
24
|
+
* console.log('Loaded level:', event.detail.levelIndex);
|
|
25
|
+
* }, { once: true });
|
|
26
|
+
*
|
|
27
|
+
* // Using AbortController to remove multiple listeners
|
|
28
|
+
* const controller = new AbortController();
|
|
29
|
+
* image.addEventListener('loadingStart', handler1, { signal: controller.signal });
|
|
30
|
+
* image.addEventListener('loadingComplete', handler2, { signal: controller.signal });
|
|
31
|
+
* controller.abort(); // removes both listeners
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export interface OMEZarrNVImageEventMap {
|
|
35
|
+
/** Fired when loading starts for a resolution level */
|
|
36
|
+
loadingStart: {
|
|
37
|
+
levelIndex: number;
|
|
38
|
+
trigger: PopulateTrigger;
|
|
39
|
+
};
|
|
40
|
+
/** Fired when loading completes for a resolution level */
|
|
41
|
+
loadingComplete: {
|
|
42
|
+
levelIndex: number;
|
|
43
|
+
trigger: PopulateTrigger;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Fired when resolution level changes.
|
|
47
|
+
* This happens during progressive loading or when clip planes
|
|
48
|
+
* cause a resolution change.
|
|
49
|
+
*/
|
|
50
|
+
resolutionChange: {
|
|
51
|
+
currentLevel: number;
|
|
52
|
+
targetLevel: number;
|
|
53
|
+
previousLevel: number;
|
|
54
|
+
trigger: PopulateTrigger;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Fired when clip planes are updated (after debounce).
|
|
58
|
+
* This is emitted after the debounce delay, not on every slider movement.
|
|
59
|
+
*/
|
|
60
|
+
clipPlanesChange: {
|
|
61
|
+
clipPlanes: ClipPlanes;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Fired when populateVolume() completes and no more requests are queued.
|
|
65
|
+
* This is the final event after all loading is done.
|
|
66
|
+
*/
|
|
67
|
+
populateComplete: {
|
|
68
|
+
currentLevel: number;
|
|
69
|
+
targetLevel: number;
|
|
70
|
+
trigger: PopulateTrigger;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Fired when a queued load request is replaced by a newer one.
|
|
74
|
+
* This only fires when a pending request is overwritten, not when
|
|
75
|
+
* the first request is queued.
|
|
76
|
+
*/
|
|
77
|
+
loadingSkipped: {
|
|
78
|
+
reason: "queued-replaced";
|
|
79
|
+
trigger: PopulateTrigger;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Fired when a slab (2D slice buffer) finishes loading.
|
|
83
|
+
* This event is specific to slab-based loading for 2D slice views.
|
|
84
|
+
*/
|
|
85
|
+
slabLoadingComplete: {
|
|
86
|
+
sliceType: SLICE_TYPE;
|
|
87
|
+
levelIndex: number;
|
|
88
|
+
slabStart: number;
|
|
89
|
+
slabEnd: number;
|
|
90
|
+
trigger: PopulateTrigger;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Fired when a slab starts loading.
|
|
94
|
+
*/
|
|
95
|
+
slabLoadingStart: {
|
|
96
|
+
sliceType: SLICE_TYPE;
|
|
97
|
+
levelIndex: number;
|
|
98
|
+
trigger: PopulateTrigger;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Type-safe event class for OMEZarrNVImage events.
|
|
103
|
+
* Extends CustomEvent with typed detail property.
|
|
104
|
+
*/
|
|
105
|
+
export declare class OMEZarrNVImageEvent<K extends keyof OMEZarrNVImageEventMap> extends CustomEvent<OMEZarrNVImageEventMap[K]> {
|
|
106
|
+
constructor(type: K, detail: OMEZarrNVImageEventMap[K]);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Type-safe event listener for OMEZarrNVImage events.
|
|
110
|
+
* Listeners can be synchronous or asynchronous.
|
|
111
|
+
*/
|
|
112
|
+
export type OMEZarrNVImageEventListener<K extends keyof OMEZarrNVImageEventMap> = (event: OMEZarrNVImageEvent<K>) => void | Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Options for addEventListener/removeEventListener.
|
|
115
|
+
* Supports all standard EventTarget options including:
|
|
116
|
+
* - capture: boolean - Use capture phase
|
|
117
|
+
* - once: boolean - Remove listener after first invocation
|
|
118
|
+
* - passive: boolean - Listener will never call preventDefault()
|
|
119
|
+
* - signal: AbortSignal - Remove listener when signal is aborted
|
|
120
|
+
*/
|
|
121
|
+
export type OMEZarrNVImageEventListenerOptions = boolean | AddEventListenerOptions;
|
|
122
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,mBAAmB,GACnB,cAAc,GACd,iBAAiB,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,sBAAsB;IACrC,uDAAuD;IACvD,YAAY,EAAE;QACZ,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;IAEF,0DAA0D;IAC1D,eAAe,EAAE;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;IAEF;;;;OAIG;IACH,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;IAEF;;;OAGG;IACH,gBAAgB,EAAE;QAAE,UAAU,EAAE,UAAU,CAAA;KAAE,CAAC;IAE7C;;;OAGG;IACH,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;IAEF;;;;OAIG;IACH,cAAc,EAAE;QACd,MAAM,EAAE,iBAAiB,CAAC;QAC1B,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;IAEF;;;OAGG;IACH,mBAAmB,EAAE;QACnB,SAAS,EAAE,UAAU,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;IAEF;;OAEG;IACH,gBAAgB,EAAE;QAChB,SAAS,EAAE,UAAU,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,CAAC;CACH;AAED;;;GAGG;AACH,qBAAa,mBAAmB,CAC9B,CAAC,SAAS,MAAM,sBAAsB,CACtC,SAAQ,WAAW,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;CAGvD;AAED;;;GAGG;AACH,MAAM,MAAM,2BAA2B,CACrC,CAAC,SAAS,MAAM,sBAAsB,IACpC,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,MAAM,kCAAkC,GAC1C,OAAO,GACP,uBAAuB,CAAC"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* Type-safe event class for OMEZarrNVImage events.
|
|
5
|
+
* Extends CustomEvent with typed detail property.
|
|
6
|
+
*/
|
|
7
|
+
export class OMEZarrNVImageEvent extends CustomEvent {
|
|
8
|
+
constructor(type, detail) {
|
|
9
|
+
super(type, { detail });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,+BAA+B;AAkH/B;;;GAGG;AACH,MAAM,OAAO,mBAEX,SAAQ,WAAsC;IAC9C,YAAY,IAAO,EAAE,MAAiC;QACpD,KAAK,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fideus-labs/fidnii
|
|
3
|
+
*
|
|
4
|
+
* Render OME-Zarr images in NiiVue with progressive multi-resolution loading.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Niivue } from '@niivue/niivue';
|
|
9
|
+
* import { fromNgffZarr } from '@fideus-labs/ngff-zarr';
|
|
10
|
+
* import { OMEZarrNVImage } from '@fideus-labs/fidnii';
|
|
11
|
+
*
|
|
12
|
+
* const nv = new Niivue();
|
|
13
|
+
* await nv.attachToCanvas(document.getElementById('canvas'));
|
|
14
|
+
*
|
|
15
|
+
* const multiscales = await fromNgffZarr('/path/to/data.ome.zarr');
|
|
16
|
+
*
|
|
17
|
+
* // Image is automatically added to NiiVue and loads progressively
|
|
18
|
+
* const image = await OMEZarrNVImage.create({ multiscales, niivue: nv });
|
|
19
|
+
*
|
|
20
|
+
* // Listen for loading complete if needed
|
|
21
|
+
* image.addEventListener('populateComplete', () => console.log('Loaded!'));
|
|
22
|
+
*
|
|
23
|
+
* // For manual control, use autoLoad: false
|
|
24
|
+
* // const image = await OMEZarrNVImage.create({
|
|
25
|
+
* // multiscales,
|
|
26
|
+
* // niivue: nv,
|
|
27
|
+
* // autoLoad: false,
|
|
28
|
+
* // });
|
|
29
|
+
* // nv.addVolume(image);
|
|
30
|
+
* // await image.populateVolume();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export { OMEZarrNVImage } from "./OMEZarrNVImage.js";
|
|
34
|
+
export type { AttachedNiivueState, ChunkAlignedRegion, ChunkCache, ClipPlane, ClipPlanes, OMEZarrNVImageOptions, PixelRegion, RegionFetchResult, ResolutionSelection, SlabBufferState, SlabSliceType, TypedArray, VolumeBounds, ZarrDtype, } from "./types.js";
|
|
35
|
+
export { SLICE_TYPE } from "./types.js";
|
|
36
|
+
export { alignToChunks, azimuthElevationToNormal, calculateNiivueDepth, clipPlanesToBoundingBox, clipPlanesToNiivue, clipPlanesToPixelRegion, clipPlaneToNiivue, createAxisAlignedClipPlane, createClipPlane, createDefaultClipPlanes, getVolumeBoundsFromMultiscales, isInsideClipPlanes, MAX_CLIP_PLANES, normalizeVector, normalToAzimuthElevation, pointToPlaneDistance, validateClipPlanes, } from "./ClipPlanes.js";
|
|
37
|
+
export { alignRegionToChunks, calculateUpsampleFactor, getChunkShape, getFullVolumeDimensions, getMiddleResolutionIndex, getVolumeShape, select2DResolution, selectResolution, } from "./ResolutionSelector.js";
|
|
38
|
+
export type { OrthogonalAxis } from "./ResolutionSelector.js";
|
|
39
|
+
export { BufferManager } from "./BufferManager.js";
|
|
40
|
+
export { RegionCoalescer } from "./RegionCoalescer.js";
|
|
41
|
+
export { ceilPixelCoord, clampPixelCoord, floorPixelCoord, normalizedToWorld, pixelToWorld, pixelToWorldAffine, roundPixelCoord, worldToNormalized, worldToPixel, worldToPixelAffine, } from "./utils/coordinates.js";
|
|
42
|
+
export { affineToNiftiSrows, calculateWorldBounds, createAffineFromNgffImage, createAffineFromOMEZarr, getPixelDimensions, updateAffineForRegion, } from "./utils/affine.js";
|
|
43
|
+
export { getBytesPerPixel, getNiftiDataType, getTypedArrayConstructor, NiftiDataType, parseZarritaDtype, } from "./types.js";
|
|
44
|
+
export { terminateWorkerPool } from "@fideus-labs/ngff-zarr/browser";
|
|
45
|
+
export { boundsApproxEqual, computeViewportBounds2D, computeViewportBounds3D, intersectBounds, } from "./ViewportBounds.js";
|
|
46
|
+
export { OMEZarrNVImageEvent } from "./events.js";
|
|
47
|
+
export type { OMEZarrNVImageEventListener, OMEZarrNVImageEventListenerOptions, OMEZarrNVImageEventMap, PopulateTrigger, } from "./events.js";
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,UAAU,EACV,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,0BAA0B,EAC1B,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EACV,2BAA2B,EAC3B,kCAAkC,EAClC,sBAAsB,EACtB,eAAe,GAChB,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* @fideus-labs/fidnii
|
|
5
|
+
*
|
|
6
|
+
* Render OME-Zarr images in NiiVue with progressive multi-resolution loading.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { Niivue } from '@niivue/niivue';
|
|
11
|
+
* import { fromNgffZarr } from '@fideus-labs/ngff-zarr';
|
|
12
|
+
* import { OMEZarrNVImage } from '@fideus-labs/fidnii';
|
|
13
|
+
*
|
|
14
|
+
* const nv = new Niivue();
|
|
15
|
+
* await nv.attachToCanvas(document.getElementById('canvas'));
|
|
16
|
+
*
|
|
17
|
+
* const multiscales = await fromNgffZarr('/path/to/data.ome.zarr');
|
|
18
|
+
*
|
|
19
|
+
* // Image is automatically added to NiiVue and loads progressively
|
|
20
|
+
* const image = await OMEZarrNVImage.create({ multiscales, niivue: nv });
|
|
21
|
+
*
|
|
22
|
+
* // Listen for loading complete if needed
|
|
23
|
+
* image.addEventListener('populateComplete', () => console.log('Loaded!'));
|
|
24
|
+
*
|
|
25
|
+
* // For manual control, use autoLoad: false
|
|
26
|
+
* // const image = await OMEZarrNVImage.create({
|
|
27
|
+
* // multiscales,
|
|
28
|
+
* // niivue: nv,
|
|
29
|
+
* // autoLoad: false,
|
|
30
|
+
* // });
|
|
31
|
+
* // nv.addVolume(image);
|
|
32
|
+
* // await image.populateVolume();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
// Main class
|
|
36
|
+
export { OMEZarrNVImage } from "./OMEZarrNVImage.js";
|
|
37
|
+
// Re-export SLICE_TYPE from types (which re-exports from niivue)
|
|
38
|
+
export { SLICE_TYPE } from "./types.js";
|
|
39
|
+
// Clip planes utilities
|
|
40
|
+
export { alignToChunks, azimuthElevationToNormal, calculateNiivueDepth, clipPlanesToBoundingBox, clipPlanesToNiivue, clipPlanesToPixelRegion, clipPlaneToNiivue, createAxisAlignedClipPlane, createClipPlane, createDefaultClipPlanes, getVolumeBoundsFromMultiscales, isInsideClipPlanes, MAX_CLIP_PLANES, normalizeVector, normalToAzimuthElevation, pointToPlaneDistance, validateClipPlanes, } from "./ClipPlanes.js";
|
|
41
|
+
// Resolution selector utilities
|
|
42
|
+
export { alignRegionToChunks, calculateUpsampleFactor, getChunkShape, getFullVolumeDimensions, getMiddleResolutionIndex, getVolumeShape, select2DResolution, selectResolution, } from "./ResolutionSelector.js";
|
|
43
|
+
// Buffer manager
|
|
44
|
+
export { BufferManager } from "./BufferManager.js";
|
|
45
|
+
// Region coalescer
|
|
46
|
+
export { RegionCoalescer } from "./RegionCoalescer.js";
|
|
47
|
+
// Coordinate utilities
|
|
48
|
+
export { ceilPixelCoord, clampPixelCoord, floorPixelCoord, normalizedToWorld, pixelToWorld, pixelToWorldAffine, roundPixelCoord, worldToNormalized, worldToPixel, worldToPixelAffine, } from "./utils/coordinates.js";
|
|
49
|
+
// Affine utilities
|
|
50
|
+
export { affineToNiftiSrows, calculateWorldBounds, createAffineFromNgffImage, createAffineFromOMEZarr, getPixelDimensions, updateAffineForRegion, } from "./utils/affine.js";
|
|
51
|
+
// Type utilities
|
|
52
|
+
export { getBytesPerPixel, getNiftiDataType, getTypedArrayConstructor, NiftiDataType, parseZarritaDtype, } from "./types.js";
|
|
53
|
+
// Worker pool lifecycle (re-exported from ngff-zarr)
|
|
54
|
+
export { terminateWorkerPool } from "@fideus-labs/ngff-zarr/browser";
|
|
55
|
+
// Viewport bounds utilities
|
|
56
|
+
export { boundsApproxEqual, computeViewportBounds2D, computeViewportBounds3D, intersectBounds, } from "./ViewportBounds.js";
|
|
57
|
+
// Event system (browser-native EventTarget API)
|
|
58
|
+
export { OMEZarrNVImageEvent } from "./events.js";
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,aAAa;AACb,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAoBrD,iEAAiE;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,wBAAwB;AACxB,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,0BAA0B,EAC1B,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAIjC,iBAAiB;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,mBAAmB;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,uBAAuB;AACvB,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAEhC,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,iBAAiB;AACjB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,qDAAqD;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,4BAA4B;AAC5B,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAE7B,gDAAgD;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { Multiscales } from "@fideus-labs/ngff-zarr";
|
|
2
|
+
import type { Niivue, NVImage } from "@niivue/niivue";
|
|
3
|
+
import { SLICE_TYPE } from "@niivue/niivue";
|
|
4
|
+
import type { BufferManager } from "./BufferManager.js";
|
|
5
|
+
import type { PopulateTrigger } from "./events.js";
|
|
6
|
+
/**
|
|
7
|
+
* A single clip plane defined by a point and normal vector.
|
|
8
|
+
* The plane equation is: normal · (P - point) = 0
|
|
9
|
+
* Points on the positive side of the normal are kept (visible).
|
|
10
|
+
*/
|
|
11
|
+
export interface ClipPlane {
|
|
12
|
+
/** A point on the plane (center of volume projected to plane) [x, y, z] in world coordinates */
|
|
13
|
+
point: [number, number, number];
|
|
14
|
+
/** Unit normal vector pointing toward visible region [x, y, z] */
|
|
15
|
+
normal: [number, number, number];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Collection of clip planes that define the visible region.
|
|
19
|
+
* Each plane clips away the half-space on the negative side of its normal.
|
|
20
|
+
* Maximum 6 planes (NiiVue limit). Empty array = full volume visible.
|
|
21
|
+
*/
|
|
22
|
+
export type ClipPlanes = ClipPlane[];
|
|
23
|
+
/**
|
|
24
|
+
* Volume bounds in world space.
|
|
25
|
+
*/
|
|
26
|
+
export interface VolumeBounds {
|
|
27
|
+
min: [number, number, number];
|
|
28
|
+
max: [number, number, number];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A pixel region in array indices.
|
|
32
|
+
* Coordinates are in [z, y, x] order to match OME-Zarr conventions.
|
|
33
|
+
*/
|
|
34
|
+
export interface PixelRegion {
|
|
35
|
+
/** Start indices [z, y, x] (inclusive) */
|
|
36
|
+
start: [number, number, number];
|
|
37
|
+
/** End indices [z, y, x] (exclusive) */
|
|
38
|
+
end: [number, number, number];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A pixel region that has been aligned to chunk boundaries.
|
|
42
|
+
*/
|
|
43
|
+
export interface ChunkAlignedRegion extends PixelRegion {
|
|
44
|
+
/** Chunk-aligned start indices [z, y, x] */
|
|
45
|
+
chunkAlignedStart: [number, number, number];
|
|
46
|
+
/** Chunk-aligned end indices [z, y, x] */
|
|
47
|
+
chunkAlignedEnd: [number, number, number];
|
|
48
|
+
/** True if the original region didn't align with chunk boundaries */
|
|
49
|
+
needsClipping: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Result of selecting an appropriate resolution level.
|
|
53
|
+
*/
|
|
54
|
+
export interface ResolutionSelection {
|
|
55
|
+
/** Index into multiscales.images array */
|
|
56
|
+
levelIndex: number;
|
|
57
|
+
/** Dimensions of the buffer [z, y, x] */
|
|
58
|
+
dimensions: [number, number, number];
|
|
59
|
+
/** Total pixel count */
|
|
60
|
+
pixelCount: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Interface for a decoded-chunk cache, compatible with `Map`.
|
|
64
|
+
*
|
|
65
|
+
* Caches decoded chunks keyed by a string combining the store instance,
|
|
66
|
+
* array path, and chunk coordinates. This avoids redundant decompression
|
|
67
|
+
* when accessing overlapping selections or making repeated calls to the
|
|
68
|
+
* same data.
|
|
69
|
+
*
|
|
70
|
+
* Any object with `get(key)` and `set(key, value)` works — a plain `Map`
|
|
71
|
+
* is the simplest option. For bounded memory use an LRU cache such as
|
|
72
|
+
* `lru-cache`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* // Use a plain Map (unbounded)
|
|
77
|
+
* const cache = new Map()
|
|
78
|
+
*
|
|
79
|
+
* // Use lru-cache (bounded)
|
|
80
|
+
* import { LRUCache } from 'lru-cache'
|
|
81
|
+
* const cache = new LRUCache({ max: 200 })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export interface ChunkCache {
|
|
85
|
+
/** Look up a cached decoded chunk by key. */
|
|
86
|
+
get(key: string): unknown | undefined;
|
|
87
|
+
/** Store a decoded chunk under the given key. */
|
|
88
|
+
set(key: string, value: unknown): void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for creating an OMEZarrNVImage.
|
|
92
|
+
*/
|
|
93
|
+
export interface OMEZarrNVImageOptions {
|
|
94
|
+
/** The OME-Zarr multiscales data */
|
|
95
|
+
multiscales: Multiscales;
|
|
96
|
+
/** Reference to the NiiVue instance for rendering updates */
|
|
97
|
+
niivue: Niivue;
|
|
98
|
+
/** Maximum number of pixels to use (default: 50,000,000) */
|
|
99
|
+
maxPixels?: number;
|
|
100
|
+
/** Debounce delay for clip plane data refetch in milliseconds (default: 300) */
|
|
101
|
+
clipPlaneDebounceMs?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Automatically add to NiiVue and start progressive loading (default: true).
|
|
104
|
+
* Set to false to manually control when populateVolume() is called.
|
|
105
|
+
* Listen to 'populateComplete' event to know when loading finishes.
|
|
106
|
+
*/
|
|
107
|
+
autoLoad?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Maximum 3D render zoom level for scroll-wheel zoom (default: 10.0).
|
|
110
|
+
* NiiVue's built-in 3D zoom is hardcoded to [0.5, 2.0]. This option
|
|
111
|
+
* overrides the scroll-wheel zoom handler to allow zooming beyond that limit.
|
|
112
|
+
*/
|
|
113
|
+
max3DZoom?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Minimum 3D render zoom level for scroll-wheel zoom (default: 0.3).
|
|
116
|
+
* @see max3DZoom
|
|
117
|
+
*/
|
|
118
|
+
min3DZoom?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Enable viewport-aware resolution selection (default: true).
|
|
121
|
+
* When enabled, zoom/pan interactions constrain the fetch region to the
|
|
122
|
+
* visible viewport, allowing higher resolution within the same maxPixels budget.
|
|
123
|
+
*/
|
|
124
|
+
viewportAware?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Maximum number of decoded-chunk cache entries (default: 200).
|
|
127
|
+
*
|
|
128
|
+
* Fidnii creates an LRU cache that avoids redundant chunk decompression
|
|
129
|
+
* on repeated or overlapping reads (e.g. clip plane adjustments, viewport
|
|
130
|
+
* panning, progressive resolution loading).
|
|
131
|
+
*
|
|
132
|
+
* Set to `0` to disable caching entirely.
|
|
133
|
+
*/
|
|
134
|
+
maxCacheEntries?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Optional pre-built decoded-chunk cache. When provided, overrides the
|
|
137
|
+
* internal LRU cache created from `maxCacheEntries`.
|
|
138
|
+
*
|
|
139
|
+
* Any object with `get(key)` / `set(key, value)` works — a plain `Map`
|
|
140
|
+
* or any LRU cache implementing the same interface.
|
|
141
|
+
*
|
|
142
|
+
* @see {@link ChunkCache}
|
|
143
|
+
*/
|
|
144
|
+
cache?: ChunkCache;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Result of fetching a region from the zarr store.
|
|
148
|
+
*/
|
|
149
|
+
export interface RegionFetchResult {
|
|
150
|
+
/** The pixel data as a typed array */
|
|
151
|
+
data: TypedArray;
|
|
152
|
+
/** Shape of the fetched data [z, y, x] */
|
|
153
|
+
shape: number[];
|
|
154
|
+
/** Stride of the fetched data */
|
|
155
|
+
stride: number[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Supported zarr data types.
|
|
159
|
+
*/
|
|
160
|
+
export type ZarrDtype = "uint8" | "uint16" | "uint32" | "int8" | "int16" | "int32" | "float32" | "float64";
|
|
161
|
+
/**
|
|
162
|
+
* Union of all typed array types we support.
|
|
163
|
+
*/
|
|
164
|
+
export type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
|
|
165
|
+
/**
|
|
166
|
+
* Typed arrays supported by NiiVue.
|
|
167
|
+
* NiiVue only supports a subset of typed arrays.
|
|
168
|
+
*/
|
|
169
|
+
export type NiiVueTypedArray = Uint8Array | Uint16Array | Int16Array | Float32Array | Float64Array;
|
|
170
|
+
export { SLICE_TYPE };
|
|
171
|
+
/**
|
|
172
|
+
* The 2D slice types that use slab-based loading.
|
|
173
|
+
* These are the Niivue slice types that show a single 2D plane.
|
|
174
|
+
*/
|
|
175
|
+
export type SlabSliceType = typeof SLICE_TYPE.AXIAL | typeof SLICE_TYPE.CORONAL | typeof SLICE_TYPE.SAGITTAL;
|
|
176
|
+
/**
|
|
177
|
+
* State for a per-slice-type slab buffer.
|
|
178
|
+
*
|
|
179
|
+
* Each 2D slice view (axial, coronal, sagittal) gets its own NVImage buffer
|
|
180
|
+
* loaded with a slab (one chunk thick in the orthogonal direction) at the
|
|
181
|
+
* current slice position.
|
|
182
|
+
*/
|
|
183
|
+
export interface SlabBufferState {
|
|
184
|
+
/** The NVImage instance for this slab */
|
|
185
|
+
nvImage: NVImage;
|
|
186
|
+
/** Buffer manager for this slab's pixel data */
|
|
187
|
+
bufferManager: BufferManager;
|
|
188
|
+
/** Current resolution level index for this slab */
|
|
189
|
+
levelIndex: number;
|
|
190
|
+
/** Target resolution level index for this slab */
|
|
191
|
+
targetLevelIndex: number;
|
|
192
|
+
/** Start index of the currently loaded slab in the orthogonal axis (pixel coords at current level) */
|
|
193
|
+
slabStart: number;
|
|
194
|
+
/** End index of the currently loaded slab in the orthogonal axis (pixel coords at current level) */
|
|
195
|
+
slabEnd: number;
|
|
196
|
+
/** Whether this slab is currently loading */
|
|
197
|
+
isLoading: boolean;
|
|
198
|
+
/** Data type of the slab */
|
|
199
|
+
dtype: ZarrDtype;
|
|
200
|
+
/**
|
|
201
|
+
* The affine normalization scale applied to the slab NVImage header.
|
|
202
|
+
* NiiVue mm values = world * normalizationScale.
|
|
203
|
+
* This is 1/maxVoxelSize where maxVoxelSize = max(sx, sy, sz).
|
|
204
|
+
* Used to convert NiiVue 2D FOV coordinates back to physical world coords.
|
|
205
|
+
*/
|
|
206
|
+
normalizationScale: number;
|
|
207
|
+
/**
|
|
208
|
+
* Pending reload request queued while this slab was loading.
|
|
209
|
+
* Latest-wins semantics: only the most recent request is kept.
|
|
210
|
+
* Auto-drained when the current load completes.
|
|
211
|
+
*/
|
|
212
|
+
pendingReload: {
|
|
213
|
+
worldCoord: [number, number, number];
|
|
214
|
+
trigger: PopulateTrigger;
|
|
215
|
+
} | null;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* State for a Niivue instance attached to an OMEZarrNVImage.
|
|
219
|
+
*/
|
|
220
|
+
export interface AttachedNiivueState {
|
|
221
|
+
/** The Niivue instance */
|
|
222
|
+
nv: Niivue;
|
|
223
|
+
/** The current slice type of this NV instance */
|
|
224
|
+
currentSliceType: SLICE_TYPE;
|
|
225
|
+
/** Previous onLocationChange callback (to chain) */
|
|
226
|
+
previousOnLocationChange?: (location: unknown) => void;
|
|
227
|
+
/** Previous onOptsChange callback (to chain) */
|
|
228
|
+
previousOnOptsChange?: (propertyName: string, newValue: unknown, oldValue: unknown) => void;
|
|
229
|
+
/** Previous onMouseUp callback (to chain, for viewport-aware mode) */
|
|
230
|
+
previousOnMouseUp?: (data: unknown) => void;
|
|
231
|
+
/** Previous onZoom3DChange callback (to chain, for viewport-aware mode) */
|
|
232
|
+
previousOnZoom3DChange?: (zoom: number) => void;
|
|
233
|
+
/** AbortController for viewport-aware event listeners (wheel, etc.) */
|
|
234
|
+
viewportAbortController?: AbortController;
|
|
235
|
+
/** AbortController for the 3D zoom override wheel listener */
|
|
236
|
+
zoomOverrideAbortController?: AbortController;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Typed array constructor types.
|
|
240
|
+
*/
|
|
241
|
+
export type TypedArrayConstructor = Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
|
242
|
+
/**
|
|
243
|
+
* NIfTI data type codes.
|
|
244
|
+
*/
|
|
245
|
+
export declare const NiftiDataType: {
|
|
246
|
+
readonly UINT8: 2;
|
|
247
|
+
readonly INT16: 4;
|
|
248
|
+
readonly INT32: 8;
|
|
249
|
+
readonly FLOAT32: 16;
|
|
250
|
+
readonly FLOAT64: 64;
|
|
251
|
+
readonly INT8: 256;
|
|
252
|
+
readonly UINT16: 512;
|
|
253
|
+
readonly UINT32: 768;
|
|
254
|
+
};
|
|
255
|
+
export type NiftiDataTypeCode = (typeof NiftiDataType)[keyof typeof NiftiDataType];
|
|
256
|
+
/**
|
|
257
|
+
* Map zarr dtype to typed array constructor.
|
|
258
|
+
*/
|
|
259
|
+
export declare function getTypedArrayConstructor(dtype: ZarrDtype): TypedArrayConstructor;
|
|
260
|
+
/**
|
|
261
|
+
* Get bytes per pixel for a dtype.
|
|
262
|
+
*/
|
|
263
|
+
export declare function getBytesPerPixel(dtype: ZarrDtype): number;
|
|
264
|
+
/**
|
|
265
|
+
* Map zarr dtype to NIfTI data type code.
|
|
266
|
+
*/
|
|
267
|
+
export declare function getNiftiDataType(dtype: ZarrDtype): NiftiDataTypeCode;
|
|
268
|
+
/**
|
|
269
|
+
* Parse a zarrita dtype string to our ZarrDtype.
|
|
270
|
+
* Handles formats like "|u1", "<u2", "<f4", etc.
|
|
271
|
+
*/
|
|
272
|
+
export declare function parseZarritaDtype(dtype: string): ZarrDtype;
|
|
273
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,gGAAgG;IAChG,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,kEAAkE;IAClE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,EAAE,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;;GAGG;AACH,M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,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAErD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,SAAS,GACf,qBAAqB,CAqBvB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAiBzD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,iBAAiB,CAqBpE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAgC1D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { SLICE_TYPE } from "@niivue/niivue";
|
|
4
|
+
// Re-export SLICE_TYPE for convenience
|
|
5
|
+
export { SLICE_TYPE };
|
|
6
|
+
/**
|
|
7
|
+
* NIfTI data type codes.
|
|
8
|
+
*/
|
|
9
|
+
export const NiftiDataType = {
|
|
10
|
+
UINT8: 2,
|
|
11
|
+
INT16: 4,
|
|
12
|
+
INT32: 8,
|
|
13
|
+
FLOAT32: 16,
|
|
14
|
+
FLOAT64: 64,
|
|
15
|
+
INT8: 256,
|
|
16
|
+
UINT16: 512,
|
|
17
|
+
UINT32: 768,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Map zarr dtype to typed array constructor.
|
|
21
|
+
*/
|
|
22
|
+
export function getTypedArrayConstructor(dtype) {
|
|
23
|
+
switch (dtype) {
|
|
24
|
+
case "uint8":
|
|
25
|
+
return Uint8Array;
|
|
26
|
+
case "uint16":
|
|
27
|
+
return Uint16Array;
|
|
28
|
+
case "uint32":
|
|
29
|
+
return Uint32Array;
|
|
30
|
+
case "int8":
|
|
31
|
+
return Int8Array;
|
|
32
|
+
case "int16":
|
|
33
|
+
return Int16Array;
|
|
34
|
+
case "int32":
|
|
35
|
+
return Int32Array;
|
|
36
|
+
case "float32":
|
|
37
|
+
return Float32Array;
|
|
38
|
+
case "float64":
|
|
39
|
+
return Float64Array;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unsupported dtype: ${dtype}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get bytes per pixel for a dtype.
|
|
46
|
+
*/
|
|
47
|
+
export function getBytesPerPixel(dtype) {
|
|
48
|
+
switch (dtype) {
|
|
49
|
+
case "uint8":
|
|
50
|
+
case "int8":
|
|
51
|
+
return 1;
|
|
52
|
+
case "uint16":
|
|
53
|
+
case "int16":
|
|
54
|
+
return 2;
|
|
55
|
+
case "uint32":
|
|
56
|
+
case "int32":
|
|
57
|
+
case "float32":
|
|
58
|
+
return 4;
|
|
59
|
+
case "float64":
|
|
60
|
+
return 8;
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(`Unsupported dtype: ${dtype}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Map zarr dtype to NIfTI data type code.
|
|
67
|
+
*/
|
|
68
|
+
export function getNiftiDataType(dtype) {
|
|
69
|
+
switch (dtype) {
|
|
70
|
+
case "uint8":
|
|
71
|
+
return NiftiDataType.UINT8;
|
|
72
|
+
case "uint16":
|
|
73
|
+
return NiftiDataType.UINT16;
|
|
74
|
+
case "uint32":
|
|
75
|
+
return NiftiDataType.UINT32;
|
|
76
|
+
case "int8":
|
|
77
|
+
return NiftiDataType.INT8;
|
|
78
|
+
case "int16":
|
|
79
|
+
return NiftiDataType.INT16;
|
|
80
|
+
case "int32":
|
|
81
|
+
return NiftiDataType.INT32;
|
|
82
|
+
case "float32":
|
|
83
|
+
return NiftiDataType.FLOAT32;
|
|
84
|
+
case "float64":
|
|
85
|
+
return NiftiDataType.FLOAT64;
|
|
86
|
+
default:
|
|
87
|
+
throw new Error(`Unsupported dtype: ${dtype}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Parse a zarrita dtype string to our ZarrDtype.
|
|
92
|
+
* Handles formats like "|u1", "<u2", "<f4", etc.
|
|
93
|
+
*/
|
|
94
|
+
export function parseZarritaDtype(dtype) {
|
|
95
|
+
// Remove endianness prefix if present
|
|
96
|
+
const normalized = dtype.replace(/^[|<>]/, "");
|
|
97
|
+
switch (normalized) {
|
|
98
|
+
case "u1":
|
|
99
|
+
case "uint8":
|
|
100
|
+
return "uint8";
|
|
101
|
+
case "u2":
|
|
102
|
+
case "uint16":
|
|
103
|
+
return "uint16";
|
|
104
|
+
case "u4":
|
|
105
|
+
case "uint32":
|
|
106
|
+
return "uint32";
|
|
107
|
+
case "i1":
|
|
108
|
+
case "int8":
|
|
109
|
+
return "int8";
|
|
110
|
+
case "i2":
|
|
111
|
+
case "int16":
|
|
112
|
+
return "int16";
|
|
113
|
+
case "i4":
|
|
114
|
+
case "int32":
|
|
115
|
+
return "int32";
|
|
116
|
+
case "f4":
|
|
117
|
+
case "float32":
|
|
118
|
+
return "float32";
|
|
119
|
+
case "f8":
|
|
120
|
+
case "float64":
|
|
121
|
+
return "float64";
|
|
122
|
+
default:
|
|
123
|
+
throw new Error(`Unsupported zarrita dtype: ${dtype}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=types.js.map
|