@niivue/niivue 0.52.0 → 0.53.1

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/build/index.d.ts CHANGED
@@ -208,7 +208,10 @@ declare enum ImageType {
208
208
  DCM_FOLDER = 16,
209
209
  SRC = 17,
210
210
  FIB = 18,
211
- BMP = 19
211
+ BMP = 19,
212
+ ZARR = 20,
213
+ NPY = 21,
214
+ NPZ = 22
212
215
  }
213
216
  type ImageFromUrlOptions = {
214
217
  url: string;
@@ -385,9 +388,9 @@ declare class NVImage {
385
388
  * @param colorbarVisible - TODO
386
389
  * @param colormapLabel - TODO
387
390
  */
388
- constructor(dataBuffer?: ArrayBuffer | ArrayBuffer[] | null, name?: string, colormap?: string, opacity?: number, pairedImgData?: ArrayBuffer | null, cal_min?: number, cal_max?: number, trustCalMinMax?: boolean, percentileFrac?: number, ignoreZeroVoxels?: boolean, useQFormNotSForm?: boolean, colormapNegative?: string, frame4D?: number, imageType?: ImageType, cal_minNeg?: number, cal_maxNeg?: number, colorbarVisible?: boolean, colormapLabel?: LUT | null, colormapType?: number);
389
- init(dataBuffer?: ArrayBuffer | ArrayBuffer[] | null, name?: string, colormap?: string, opacity?: number, _pairedImgData?: ArrayBuffer | null, cal_min?: number, cal_max?: number, trustCalMinMax?: boolean, percentileFrac?: number, ignoreZeroVoxels?: boolean, useQFormNotSForm?: boolean, colormapNegative?: string, frame4D?: number, imageType?: ImageType, cal_minNeg?: number, cal_maxNeg?: number, colorbarVisible?: boolean, colormapLabel?: LUT | null, colormapType?: number, imgRaw?: ArrayBuffer | null): void;
390
- static new(dataBuffer?: ArrayBuffer | ArrayBuffer[] | null, name?: string, colormap?: string, opacity?: number, pairedImgData?: ArrayBuffer | null, cal_min?: number, cal_max?: number, trustCalMinMax?: boolean, percentileFrac?: number, ignoreZeroVoxels?: boolean, useQFormNotSForm?: boolean, colormapNegative?: string, frame4D?: number, imageType?: ImageType, cal_minNeg?: number, cal_maxNeg?: number, colorbarVisible?: boolean, colormapLabel?: LUT | null, colormapType?: number): Promise<NVImage>;
391
+ constructor(dataBuffer?: ArrayBuffer | ArrayBuffer[] | ArrayBufferLike | null, name?: string, colormap?: string, opacity?: number, pairedImgData?: ArrayBuffer | null, cal_min?: number, cal_max?: number, trustCalMinMax?: boolean, percentileFrac?: number, ignoreZeroVoxels?: boolean, useQFormNotSForm?: boolean, colormapNegative?: string, frame4D?: number, imageType?: ImageType, cal_minNeg?: number, cal_maxNeg?: number, colorbarVisible?: boolean, colormapLabel?: LUT | null, colormapType?: number);
392
+ init(dataBuffer?: ArrayBuffer | ArrayBuffer[] | ArrayBufferLike | null, name?: string, colormap?: string, opacity?: number, _pairedImgData?: ArrayBuffer | null, cal_min?: number, cal_max?: number, trustCalMinMax?: boolean, percentileFrac?: number, ignoreZeroVoxels?: boolean, useQFormNotSForm?: boolean, colormapNegative?: string, frame4D?: number, imageType?: ImageType, cal_minNeg?: number, cal_maxNeg?: number, colorbarVisible?: boolean, colormapLabel?: LUT | null, colormapType?: number, imgRaw?: ArrayBuffer | ArrayBufferLike | null): void;
393
+ static new(dataBuffer?: ArrayBuffer | ArrayBuffer[] | ArrayBufferLike | null, name?: string, colormap?: string, opacity?: number, pairedImgData?: ArrayBuffer | null, cal_min?: number, cal_max?: number, trustCalMinMax?: boolean, percentileFrac?: number, ignoreZeroVoxels?: boolean, useQFormNotSForm?: boolean, colormapNegative?: string, frame4D?: number, imageType?: ImageType, cal_minNeg?: number, cal_maxNeg?: number, colorbarVisible?: boolean, colormapLabel?: LUT | null, colormapType?: number): Promise<NVImage>;
391
394
  computeObliqueAngle(mtx44: mat4): number;
392
395
  float32V1asRGBA(inImg: Float32Array): Uint8Array;
393
396
  loadImgV1(isFlipX?: boolean, isFlipY?: boolean, isFlipZ?: boolean): boolean;
@@ -396,16 +399,16 @@ declare class NVImage {
396
399
  SetPixDimFromSForm(): void;
397
400
  readECAT(buffer: ArrayBuffer): ArrayBuffer;
398
401
  readV16(buffer: ArrayBuffer): ArrayBuffer;
402
+ readNPY(buffer: ArrayBuffer): Promise<ArrayBuffer>;
403
+ readNPZ(buffer: ArrayBuffer): Promise<ArrayBuffer>;
399
404
  imageDataFromArrayBuffer(buffer: ArrayBuffer): Promise<ImageData>;
400
405
  readBMP(buffer: ArrayBuffer): Promise<ArrayBuffer>;
401
406
  readVMR(buffer: ArrayBuffer): ArrayBuffer;
402
- readMGH(buffer: ArrayBuffer): Promise<ArrayBuffer>;
403
407
  readFIB(buffer: ArrayBuffer): Promise<[ArrayBuffer, Float32Array]>;
404
408
  readSRC(buffer: ArrayBuffer): Promise<ArrayBuffer>;
405
409
  readHEAD(dataBuffer: ArrayBuffer, pairedImgData: ArrayBuffer | null): Promise<ArrayBuffer>;
406
410
  readMHA(buffer: ArrayBuffer, pairedImgData: ArrayBuffer | null): Promise<ArrayBuffer>;
407
411
  readMIF(buffer: ArrayBuffer, pairedImgData: ArrayBuffer | null): Promise<ArrayBuffer>;
408
- readNRRD(dataBuffer: ArrayBuffer, pairedImgData: ArrayBuffer | null): Promise<ArrayBuffer>;
409
412
  calculateRAS(): void;
410
413
  hdr2RAS(nVolumes?: number): Promise<NIFTI1 | NIFTI2>;
411
414
  img2RAS(nVolume?: number): TypedVoxelArray;
@@ -431,7 +434,21 @@ declare class NVImage {
431
434
  calMinMax(vol?: number, isBorder?: boolean): number[];
432
435
  intensityRaw2Scaled(raw: number): number;
433
436
  intensityScaled2Raw(scaled: number): number;
437
+ /**
438
+ * Converts NVImage to NIfTI compliant byte array, potentially compressed.
439
+ * Delegates to ImageWriter.saveToUint8Array.
440
+ * @param fnm - Filename (determines if compression is needed via .gz suffix)
441
+ * @param drawing8 - Optional Uint8Array drawing overlay
442
+ * @returns Promise<Uint8Array>
443
+ */
434
444
  saveToUint8Array(fnm: string, drawing8?: Uint8Array | null): Promise<Uint8Array>;
445
+ /**
446
+ * save image as NIfTI volume and trigger download.
447
+ * Delegates to ImageWriter.saveToDisk.
448
+ * @param fnm - Filename for download. If empty, returns data without download.
449
+ * @param drawing8 - Optional Uint8Array drawing overlay
450
+ * @returns Promise<Uint8Array>
451
+ */
435
452
  saveToDisk(fnm?: string, drawing8?: Uint8Array | null): Promise<Uint8Array>;
436
453
  static fetchDicomData(url: string, headers?: Record<string, string>): Promise<Array<{
437
454
  name: string;
@@ -455,15 +472,15 @@ declare class NVImage {
455
472
  static loadFromFile({ file, // file can be an array of file objects or a single file object
456
473
  name, colormap, opacity, urlImgData, cal_min, cal_max, trustCalMinMax, percentileFrac, ignoreZeroVoxels, useQFormNotSForm, colormapNegative, frame4D, limitFrames4D, imageType }: ImageFromFileOptions): Promise<NVImage>;
457
474
  /**
458
- * factory function to load and return a new NVImage instance from a base64 encoded string
459
- *
460
- * @returns NVImage instance
461
- * @example
462
- * myImage = NVImage.loadFromBase64('SomeBase64String')
475
+ * Creates a Uint8Array representing a NIFTI file (header + optional image data).
476
+ * Delegates to ImageWriter.createNiftiArray.
477
+ */
478
+ static createNiftiArray(dims?: number[], pixDims?: number[], affine?: number[], datatypeCode?: NiiDataType, img?: TypedVoxelArray | Uint8Array): Uint8Array;
479
+ /**
480
+ * Creates a NIFTI1 header object with basic properties.
481
+ * Delegates to ImageWriter.createNiftiHeader.
463
482
  */
464
- static createNiftiArray(dims?: number[], pixDims?: number[], affine?: number[], datatypeCode?: number, // DT_UINT8
465
- img?: Uint8Array): Uint8Array;
466
- static createNiftiHeader(dims?: number[], pixDims?: number[], affine?: number[], datatypeCode?: number): NIFTI1;
483
+ static createNiftiHeader(dims?: number[], pixDims?: number[], affine?: number[], datatypeCode?: NiiDataType): NIFTI1;
467
484
  /**
468
485
  * read a 3D slab of voxels from a volume
469
486
  * @param voxStart - first row, column and slice (RAS order) for selection
@@ -472,6 +489,14 @@ declare class NVImage {
472
489
  * @returns the an array where ret[0] is the voxel values and ret[1] is dimension of selection
473
490
  * @see {@link https://niivue.github.io/niivue/features/slab_selection.html | live demo usage}
474
491
  */
492
+ /**
493
+ * read a 3D slab of voxels from a volume, specified in RAS coordinates.
494
+ * Delegates to VolumeUtils.getVolumeData.
495
+ * @param voxStart - first row, column and slice (RAS order) for selection
496
+ * @param voxEnd - final row, column and slice (RAS order) for selection
497
+ * @param dataType - array data type. Options: 'same' (default), 'uint8', 'float32', 'scaled', 'normalized', 'windowed'
498
+ * @returns the an array where ret[0] is the voxel values and ret[1] is dimension of selection
499
+ */
475
500
  getVolumeData(voxStart?: number[], voxEnd?: number[], dataType?: string): [TypedVoxelArray, number[]];
476
501
  /**
477
502
  * write a 3D slab of voxels from a volume
@@ -480,6 +505,14 @@ declare class NVImage {
480
505
  * @param img - array of voxel values to insert (RAS order)
481
506
  * @see {@link https://niivue.github.io/niivue/features/slab_selection.html | live demo usage}
482
507
  */
508
+ /**
509
+ * write a 3D slab of voxels from a volume, specified in RAS coordinates.
510
+ * Delegates to VolumeUtils.setVolumeData.
511
+ * Input slabData is assumed to be in the correct raw data type for the target image.
512
+ * @param voxStart - first row, column and slice (RAS order) for selection
513
+ * @param voxEnd - final row, column and slice (RAS order) for selection
514
+ * @param img - array of voxel values to insert (RAS order, raw data type)
515
+ */
483
516
  setVolumeData(voxStart?: number[], voxEnd?: number[], img?: TypedVoxelArray): void;
484
517
  /**
485
518
  * factory function to load and return a new NVImage instance from a base64 encoded string
@@ -518,20 +551,28 @@ declare class NVImage {
518
551
  * newZeroImage = NVImage.zerosLike(myImage)
519
552
  */
520
553
  static zerosLike(nvImage: NVImage, dataType?: string): NVImage;
521
- getValue(x: number, y: number, z: number, frame4D?: number, isReadImaginary?: boolean): number;
522
554
  /**
523
- * @param id - id of 3D Object (is this the base volume or an overlay?)
524
- * @param gl - WebGL rendering context
525
- * @returns new 3D object in model space
555
+ * Returns voxel intensity at specific native coordinates.
556
+ * Delegates to VolumeUtils.getValue.
557
+ * @param x - Native X coordinate (0-indexed)
558
+ * @param y - Native Y coordinate (0-indexed)
559
+ * @param z - Native Z coordinate (0-indexed)
560
+ * @param frame4D - 4D frame index (0-indexed)
561
+ * @param isReadImaginary - Flag to read from imaginary data array
562
+ * @returns Scaled voxel intensity
526
563
  */
527
- toNiivueObject3D(id: number, gl: WebGL2RenderingContext): NiivueObject3D;
564
+ getValue(x: number, y: number, z: number, frame4D?: number, isReadImaginary?: boolean): number;
528
565
  /**
529
566
  * Update options for image
530
567
  */
531
568
  applyOptionsUpdate(options: ImageFromUrlOptions): void;
532
569
  getImageOptions(): ImageFromUrlOptions;
533
570
  /**
534
- * Converts NVImage to NIfTI compliant byte array
571
+ * Converts NVImage to NIfTI compliant byte array.
572
+ * Handles potential re-orientation of drawing data.
573
+ * Delegates to ImageWriter.toUint8Array.
574
+ * @param drawingBytes - Optional Uint8Array drawing overlay
575
+ * @returns Uint8Array
535
576
  */
536
577
  toUint8Array(drawingBytes?: Uint8Array | null): Uint8Array;
537
578
  convertVox2Frac(vox: vec3): vec3;
@@ -731,6 +772,7 @@ type NVConfigOptions = {
731
772
  isAlphaClipDark: boolean;
732
773
  gradientOrder: number;
733
774
  gradientOpacity: number;
775
+ invertScrollDirection: boolean;
734
776
  };
735
777
  declare const DEFAULT_OPTIONS: NVConfigOptions;
736
778
  type SceneData = {
@@ -956,7 +998,7 @@ type Point = {
956
998
  };
957
999
  };
958
1000
  /**
959
- * Representes the vertices of a connectome
1001
+ * Represents the vertices of a connectome
960
1002
  * @ignore
961
1003
  */
962
1004
  type NVConnectomeNode = {
@@ -1291,7 +1333,7 @@ declare class NVMesh {
1291
1333
  decimateFaces(n: number, ntarget: number): void;
1292
1334
  decimateHierarchicalMesh(gl: WebGL2RenderingContext, order?: number): boolean;
1293
1335
  setLayerProperty(id: number, key: keyof NVMeshLayer, val: number | string | boolean, gl: WebGL2RenderingContext): Promise<void>;
1294
- setProperty(key: keyof this, val: unknown, gl: WebGL2RenderingContext): void;
1336
+ setProperty(key: keyof this, val: number | string | boolean | Uint8Array | number[] | ColorMap | LegacyConnectome | Float32Array, gl: WebGL2RenderingContext): void;
1295
1337
  generatePosNormClr(pts: Float32Array, tris: Uint32Array, rgba255: Uint8Array): Float32Array;
1296
1338
  static readMesh(buffer: ArrayBuffer, name: string, gl: WebGL2RenderingContext, opacity?: number, rgba255?: Uint8Array, visible?: boolean): Promise<NVMesh>;
1297
1339
  static loadLayer(layer: NVMeshLayer, nvmesh: NVMesh): Promise<void>;
@@ -1317,7 +1359,7 @@ declare class NVUtilities {
1317
1359
  static arrayBufferToBase64(arrayBuffer: ArrayBuffer): string;
1318
1360
  static decompress(data: Uint8Array): Promise<Uint8Array>;
1319
1361
  static decompressToBuffer(data: Uint8Array): Promise<ArrayBuffer>;
1320
- static readMatV4(buffer: ArrayBuffer): Promise<Record<string, TypedNumberArray>>;
1362
+ static readMatV4(buffer: ArrayBuffer, isReplaceDots?: boolean): Promise<Record<string, TypedNumberArray>>;
1321
1363
  static b64toUint8(base64: string): Uint8Array;
1322
1364
  static uint8tob64(bytes: Uint8Array): string;
1323
1365
  static download(content: string | ArrayBuffer, fileName: string, contentType: string): void;
@@ -1622,6 +1664,8 @@ declare class Niivue {
1622
1664
  extentsMin?: vec3;
1623
1665
  extentsMax?: vec3;
1624
1666
  private resizeObserver;
1667
+ private resizeEventListener;
1668
+ private canvasObserver;
1625
1669
  syncOpts: SyncOpts;
1626
1670
  readyForSync: boolean;
1627
1671
  uiData: UIData;
@@ -1858,6 +1902,13 @@ declare class Niivue {
1858
1902
  * @param options - options object to set modifiable Niivue properties
1859
1903
  */
1860
1904
  constructor(options?: Partial<NVConfigOptions>);
1905
+ /**
1906
+ * Clean up event listeners and observers
1907
+ * Call this when the Niivue instance is no longer needed.
1908
+ * This will be called when the canvas is detached from the DOM
1909
+ * @example niivue.cleanup();
1910
+ */
1911
+ cleanup(): void;
1861
1912
  get volumes(): NVImage[];
1862
1913
  set volumes(volumes: NVImage[]);
1863
1914
  get meshes(): NVMesh[];
@@ -1878,7 +1929,7 @@ declare class Niivue {
1878
1929
  * @param id - the id of an html canvas element
1879
1930
  * @param isAntiAlias - determines if anti-aliasing is requested (if not specified, AA usage depends on hardware)
1880
1931
  * @example niivue = new Niivue().attachTo('gl')
1881
- * @example niivue.attachTo('gl')
1932
+ * @example await niivue.attachTo('gl')
1882
1933
  * @see {@link https://niivue.github.io/niivue/features/basic.multiplanar.html | live demo usage}
1883
1934
  */
1884
1935
  attachTo(id: string, isAntiAlias?: any): Promise<this>;
@@ -1887,7 +1938,7 @@ declare class Niivue {
1887
1938
  * @param canvas - the canvas element reference
1888
1939
  * @example
1889
1940
  * niivue = new Niivue()
1890
- * niivue.attachToCanvas(document.getElementById(id))
1941
+ * await niivue.attachToCanvas(document.getElementById(id))
1891
1942
  */
1892
1943
  attachToCanvas(canvas: HTMLCanvasElement, isAntiAlias?: boolean | null): Promise<this>;
1893
1944
  /**
@@ -1985,6 +2036,7 @@ declare class Niivue {
1985
2036
  touchStartListener(e: TouchEvent): void;
1986
2037
  touchEndListener(e: TouchEvent): void;
1987
2038
  windowingHandler(x: number, y: number, volIdx?: number): void;
2039
+ mouseLeaveListener(): void;
1988
2040
  mouseMoveListener(e: MouseEvent): void;
1989
2041
  resetBriCon(msg?: TouchEvent | MouseEvent | null): void;
1990
2042
  setDragStart(x: number, y: number): void;
@@ -2200,7 +2252,7 @@ declare class Niivue {
2200
2252
  * @example niivue.setMeshProperty(niivue.meshes[0].id, 'fiberLength', 42)
2201
2253
  * @see {@link https://niivue.github.io/niivue/features/meshes.html | live demo usage}
2202
2254
  */
2203
- setMeshProperty(id: number, key: keyof NVMesh, val: number): void;
2255
+ setMeshProperty(id: number, key: keyof NVMesh, val: number | string | boolean | Uint8Array | number[] | ColorMap | LegacyConnectome | Float32Array): void;
2204
2256
  /**
2205
2257
  * returns the index of the mesh vertex that is closest to the provided coordinates
2206
2258
  * @param id - identity of mesh to change
@@ -2607,7 +2659,7 @@ declare class Niivue {
2607
2659
  * @see {@link https://niivue.github.io/niivue/features/draw2.html | live demo usage}
2608
2660
  */
2609
2661
  drawGrowCut(): void;
2610
- drawPt(x: number, y: number, z: number, penValue: number): void;
2662
+ drawPt(x: number, y: number, z: number, penValue: number, drawBitmap?: Uint8Array | null): void;
2611
2663
  drawPenLine(ptA: number[], ptB: number[], penValue: number): void;
2612
2664
  /**
2613
2665
  * Performs a 1-voxel binary dilation on a connected cluster within the drawing mask using the drawFloodFillCore function.
@@ -2618,8 +2670,7 @@ declare class Niivue {
2618
2670
  drawingBinaryDilationWithSeed(seedXYZ: number[], // seed voxel x,y,z
2619
2671
  neighbors?: 6 | 18 | 26): void;
2620
2672
  drawFloodFillCore(img: Uint8Array, seedVx: number, neighbors?: number): void;
2621
- drawFloodFill(seedXYZ: number[], newColor?: number, growSelectedCluster?: number, // if non-zero, growth based on background intensity POSITIVE_INFINITY for selected or bright, NEGATIVE_INFINITY for selected or darker
2622
- forceMin?: number, forceMax?: number, neighbors?: number, maxDistanceMM?: number, is2D?: boolean): void;
2673
+ drawFloodFill(seedXYZ: number[], newColor?: number, growSelectedCluster?: number, forceMin?: number, forceMax?: number, neighbors?: number, maxDistanceMM?: number, is2D?: boolean, targetBitmap?: Uint8Array | null, isGrowClusterTool?: boolean): void;
2623
2674
  drawPenFilled(): void;
2624
2675
  /**
2625
2676
  * close drawing: make sure you have saved any changes before calling this!
@@ -2895,6 +2946,11 @@ declare class Niivue {
2895
2946
  inGraphTile(x: number, y: number): boolean;
2896
2947
  updateBitmapFromClickToSegment(): void;
2897
2948
  sumBitmap(img: Uint8Array): number;
2949
+ doClickToSegment(options: {
2950
+ x: number;
2951
+ y: number;
2952
+ tileIndex: number;
2953
+ }): void;
2898
2954
  mouseClick(x: number, y: number, posChange?: number, isDelta?: boolean): void;
2899
2955
  drawRuler(): void;
2900
2956
  drawRuler10cm(startXYendXY: number[], rulerColor: number[], rulerWidth?: number): void;