@niivue/niivue 0.61.0 → 0.62.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/build/index.d.ts CHANGED
@@ -505,6 +505,11 @@ declare class NVImage {
505
505
  * Delegates to VolumeUtils.getValue.
506
506
  */
507
507
  getValue(x: number, y: number, z: number, frame4D?: number, isReadImaginary?: boolean): number;
508
+ /**
509
+ * Returns voxel intensities at specific native coordinates.
510
+ * Delegates to VolumeUtils.getValue.
511
+ */
512
+ getValues(x: number, y: number, z: number, frame4D?: number, isReadImaginary?: boolean): number[];
508
513
  /**
509
514
  * Update options for image
510
515
  */
@@ -561,6 +566,34 @@ declare class NVConnectome extends NVMesh {
561
566
  static loadConnectomeFromUrl(gl: WebGL2RenderingContext, url: string): Promise<NVConnectome>;
562
567
  }
563
568
 
569
+ /**
570
+ * Represents a completed measurement between two points
571
+ */
572
+ interface CompletedMeasurement {
573
+ startMM: vec3;
574
+ endMM: vec3;
575
+ distance: number;
576
+ sliceIndex: number;
577
+ sliceType: SLICE_TYPE;
578
+ slicePosition: number;
579
+ }
580
+ /**
581
+ * Represents a completed angle measurement between two lines
582
+ */
583
+ interface CompletedAngle {
584
+ firstLineMM: {
585
+ start: vec3;
586
+ end: vec3;
587
+ };
588
+ secondLineMM: {
589
+ start: vec3;
590
+ end: vec3;
591
+ };
592
+ angle: number;
593
+ sliceIndex: number;
594
+ sliceType: SLICE_TYPE;
595
+ slicePosition: number;
596
+ }
564
597
  /**
565
598
  * Slice Type
566
599
  * @ignore
@@ -572,6 +605,11 @@ declare enum SLICE_TYPE {
572
605
  MULTIPLANAR = 3,
573
606
  RENDER = 4
574
607
  }
608
+ declare enum PEN_TYPE {
609
+ PEN = 0,
610
+ RECTANGLE = 1,
611
+ ELLIPSE = 2
612
+ }
575
613
  declare enum SHOW_RENDER {
576
614
  NEVER = 0,
577
615
  ALWAYS = 1,
@@ -599,21 +637,22 @@ declare enum DRAG_MODE {
599
637
  slicer3D = 4,
600
638
  callbackOnly = 5,
601
639
  roiSelection = 6,
602
- angle = 7
640
+ angle = 7,
641
+ crosshair = 8,
642
+ windowing = 9
603
643
  }
604
- declare enum DRAG_MODE_SECONDARY {
605
- none = 0,
606
- contrast = 1,
607
- measurement = 2,
608
- pan = 3,
609
- slicer3D = 4,
610
- callbackOnly = 5,
611
- roiSelection = 6,
612
- angle = 7
644
+ interface MouseEventConfig {
645
+ leftButton: {
646
+ primary: DRAG_MODE;
647
+ withShift?: DRAG_MODE;
648
+ withCtrl?: DRAG_MODE;
649
+ };
650
+ rightButton: DRAG_MODE;
651
+ centerButton: DRAG_MODE;
613
652
  }
614
- declare enum DRAG_MODE_PRIMARY {
615
- crosshair = 0,
616
- windowing = 1
653
+ interface TouchEventConfig {
654
+ singleTouch: DRAG_MODE;
655
+ doubleTouch: DRAG_MODE;
617
656
  }
618
657
  declare enum COLORMAP_TYPE {
619
658
  MIN_TO_MAX = 0,
@@ -640,6 +679,7 @@ type NVConfigOptions = {
640
679
  fontColor: Float32List;
641
680
  selectionBoxColor: number[];
642
681
  clipPlaneColor: number[];
682
+ paqdUniforms: number[];
643
683
  clipThick: number;
644
684
  clipVolumeLow: number[];
645
685
  clipVolumeHigh: number[];
@@ -664,12 +704,15 @@ type NVConfigOptions = {
664
704
  multiplanarShowRender: SHOW_RENDER;
665
705
  isRadiologicalConvention: boolean;
666
706
  meshThicknessOn2D: number | string;
667
- dragMode: DRAG_MODE | DRAG_MODE_SECONDARY;
668
- dragModePrimary: DRAG_MODE_PRIMARY;
707
+ dragMode: DRAG_MODE;
708
+ dragModePrimary: DRAG_MODE;
709
+ mouseEventConfig?: MouseEventConfig;
710
+ touchEventConfig?: TouchEventConfig;
669
711
  yoke3Dto2DZoom: boolean;
670
712
  isDepthPickMesh: boolean;
671
713
  isCornerOrientationText: boolean;
672
714
  isOrientationTextVisible: boolean;
715
+ showAllOrientationMarkers: boolean;
673
716
  heroImageFraction: number;
674
717
  heroSliceType: SLICE_TYPE;
675
718
  sagittalNoseLeft: boolean;
@@ -682,6 +725,7 @@ type NVConfigOptions = {
682
725
  dragAndDropEnabled: boolean;
683
726
  drawingEnabled: boolean;
684
727
  penValue: number;
728
+ penType: PEN_TYPE;
685
729
  floodFillNeighbors: number;
686
730
  isFilledPen: boolean;
687
731
  thumbnail: string;
@@ -781,6 +825,8 @@ type DocumentData = {
781
825
  sceneData?: Partial<SceneData>;
782
826
  connectomes?: string[];
783
827
  customData?: string;
828
+ completedMeasurements?: CompletedMeasurement[];
829
+ completedAngles?: CompletedAngle[];
784
830
  };
785
831
  type ExportDocumentData = {
786
832
  encodedImageBlobs: string[];
@@ -794,6 +840,8 @@ type ExportDocumentData = {
794
840
  labels: NVLabel3D[];
795
841
  connectomes: string[];
796
842
  customData: string;
843
+ completedMeasurements: CompletedMeasurement[];
844
+ completedAngles: CompletedAngle[];
797
845
  };
798
846
  /**
799
847
  * Creates and instance of NVDocument
@@ -808,6 +856,8 @@ declare class NVDocument {
808
856
  drawBitmap: Uint8Array | null;
809
857
  imageOptionsMap: Map<any, any>;
810
858
  meshOptionsMap: Map<any, any>;
859
+ completedMeasurements: CompletedMeasurement[];
860
+ completedAngles: CompletedAngle[];
811
861
  private _optsProxy;
812
862
  private _optsChangeCallback;
813
863
  constructor();
@@ -888,8 +938,9 @@ declare class NVDocument {
888
938
  *
889
939
  * @param embedImages If false, encodedImageBlobs is left empty
890
940
  * (imageOptionsArray still records the URL / name).
941
+ * @param embedDrawing If false, encodedDrawingBlob is left empty
891
942
  */
892
- json(embedImages?: boolean): ExportDocumentData;
943
+ json(embedImages?: boolean, embedDrawing?: boolean): ExportDocumentData;
893
944
  download(fileName: string, compress: boolean, opts?: {
894
945
  embedImages: boolean;
895
946
  }): Promise<void>;
@@ -1571,6 +1622,8 @@ type UIData = {
1571
1622
  max3D?: number;
1572
1623
  windowX: number;
1573
1624
  windowY: number;
1625
+ activeDragMode: DRAG_MODE | null;
1626
+ activeDragButton: number | null;
1574
1627
  angleFirstLine: number[];
1575
1628
  angleState: 'none' | 'drawing_first_line' | 'drawing_second_line' | 'complete';
1576
1629
  };
@@ -1609,9 +1662,11 @@ declare class Niivue {
1609
1662
  useCustomGradientTexture: boolean;
1610
1663
  renderGradientValues: boolean;
1611
1664
  drawTexture: WebGLTexture | null;
1665
+ paqdTexture: WebGLTexture | null;
1612
1666
  drawUndoBitmaps: Uint8Array[];
1613
1667
  drawLut: LUT;
1614
1668
  drawOpacity: number;
1669
+ drawRimOpacity: number;
1615
1670
  clickToSegmentIsGrowing: boolean;
1616
1671
  clickToSegmentGrowingBitmap: Uint8Array | null;
1617
1672
  clickToSegmentXY: number[];
@@ -1621,6 +1676,8 @@ declare class Niivue {
1621
1676
  drawPenAxCorSag: number;
1622
1677
  drawFillOverwrites: boolean;
1623
1678
  drawPenFillPts: number[][];
1679
+ drawShapeStartLocation: number[];
1680
+ drawShapePreviewBitmap: Uint8Array | null;
1624
1681
  overlayTexture: WebGLTexture | null;
1625
1682
  overlayTextureID: WebGLTexture | null;
1626
1683
  sliceMMShader?: Shader;
@@ -1641,6 +1698,7 @@ declare class Niivue {
1641
1698
  pickingMeshShader?: Shader;
1642
1699
  pickingImageShader?: Shader;
1643
1700
  colorbarShader?: Shader;
1701
+ customSliceShader: Shader | null;
1644
1702
  fontShader: Shader | null;
1645
1703
  fiberShader?: Shader;
1646
1704
  fontTexture: WebGLTexture | null;
@@ -1657,6 +1715,7 @@ declare class Niivue {
1657
1715
  orientShaderI: Shader | null;
1658
1716
  orientShaderF: Shader | null;
1659
1717
  orientShaderRGBU: Shader | null;
1718
+ orientShaderPAQD: Shader | null;
1660
1719
  surfaceShader: Shader | null;
1661
1720
  blurShader: Shader | null;
1662
1721
  sobelBlurShader: Shader | null;
@@ -2113,20 +2172,38 @@ declare class Niivue {
2113
2172
  */
2114
2173
  mouseDownListener(e: MouseEvent): void;
2115
2174
  /**
2116
- * Handles left mouse button actions for crosshair or windowing mode.
2175
+ * Gets the appropriate drag mode for a mouse button based on configuration.
2176
+ * @internal
2177
+ */
2178
+ getMouseButtonDragMode(button: number, shiftKey: boolean, ctrlKey: boolean): DRAG_MODE;
2179
+ /**
2180
+ * Gets the appropriate drag mode for touch events based on configuration.
2117
2181
  * @internal
2118
2182
  */
2119
- mouseLeftButtonHandler(e: MouseEvent): void;
2183
+ getTouchDragMode(isDoubleTouch: boolean): DRAG_MODE;
2120
2184
  /**
2121
- * Handles center mouse button drag to initiate 2D panning or clip plane adjustment.
2185
+ * Sets the active drag mode for the current interaction.
2122
2186
  * @internal
2123
2187
  */
2124
- mouseCenterButtonHandler(e: MouseEvent): void;
2188
+ setActiveDragMode(button: number, shiftKey: boolean, ctrlKey: boolean): void;
2125
2189
  /**
2126
- * Handles right mouse button drag to enable 2D panning or clip plane control.
2190
+ * Gets the currently active drag mode, or falls back to configured defaults.
2127
2191
  * @internal
2128
2192
  */
2129
- mouseRightButtonHandler(e: MouseEvent): void;
2193
+ getCurrentDragMode(): DRAG_MODE;
2194
+ /**
2195
+ * Clears the active drag mode.
2196
+ * @internal
2197
+ */
2198
+ clearActiveDragMode(): void;
2199
+ /**
2200
+ * Unified handler for mouse actions based on drag mode.
2201
+ * @internal
2202
+ */
2203
+ handleMouseAction(dragMode: DRAG_MODE, e: MouseEvent, pos: {
2204
+ x: number;
2205
+ y: number;
2206
+ }): void;
2130
2207
  /**
2131
2208
  * calculate the the min and max voxel indices from an array of two values (used in selecting intensities with the selection box)
2132
2209
  * @internal
@@ -2362,6 +2439,12 @@ declare class Niivue {
2362
2439
  * @see {@link https://niivue.com/demos/features/basic.multiplanar.html | live demo usage}
2363
2440
  */
2364
2441
  setIsOrientationTextVisible(isOrientationTextVisible: boolean): void;
2442
+ /**
2443
+ * Show or hide all four orientation labels (e.g., L/R, A/P, S/I) in 2D slice views
2444
+ * @param showAllOrientationMarkers - whether all four orientation markers should be displayed
2445
+ * @example niivue.setShowAllOrientationMarkers(true)
2446
+ */
2447
+ setShowAllOrientationMarkers(showAllOrientationMarkers: boolean): void;
2365
2448
  /**
2366
2449
  * determine proportion of screen real estate devoted to rendering in multiplanar view.
2367
2450
  * @param fraction - proportion of screen devoted to primary (hero) image (0 to disable)
@@ -3097,6 +3180,16 @@ declare class Niivue {
3097
3180
  * @internal
3098
3181
  */
3099
3182
  drawPenLine(ptA: number[], ptB: number[], penValue: number): void;
3183
+ /**
3184
+ * Draw a rectangle from point A to point B
3185
+ * @internal
3186
+ */
3187
+ drawRectangleMask(ptA: number[], ptB: number[], penValue: number): void;
3188
+ /**
3189
+ * Draw an ellipse from point A to point B (treating them as opposite corners of bounding box)
3190
+ * @internal
3191
+ */
3192
+ drawEllipseMask(ptA: number[], ptB: number[], penValue: number): void;
3100
3193
  /**
3101
3194
  * Performs a 1-voxel binary dilation on a connected cluster within the drawing mask using the drawFloodFillCore function.
3102
3195
  *
@@ -3139,6 +3232,12 @@ declare class Niivue {
3139
3232
  * @see {@link https://niivue.com/demos/features/cactus.html | live demo usage}
3140
3233
  */
3141
3234
  refreshDrawing(isForceRedraw?: boolean, useClickToSegmentBitmap?: boolean): void;
3235
+ /**
3236
+ * close probabilistic atlas texture
3237
+ * @example niivue.closePAQD();
3238
+ * @internal
3239
+ */
3240
+ closePAQD(): void;
3142
3241
  /**
3143
3242
  * Creates a 2D 1-component uint8 texture on the GPU with given dimensions.
3144
3243
  * @internal
@@ -3289,6 +3388,13 @@ declare class Niivue {
3289
3388
  Frag: string;
3290
3389
  shader: Shader;
3291
3390
  };
3391
+ /**
3392
+ * Install a special shader for 2D slice views
3393
+ * @param fragmentShaderText - custom fragment shader.
3394
+ * @if not text is provided, the default shader will be used
3395
+ * @internal
3396
+ */
3397
+ setCustomSliceShader(fragmentShaderText?: string): void;
3292
3398
  /**
3293
3399
  * Define a new GLSL shader program to influence mesh coloration
3294
3400
  * @param fragmentShaderText - the GLSL source code for the custom fragment shader
@@ -3713,6 +3819,17 @@ declare class Niivue {
3713
3819
  * @internal
3714
3820
  */
3715
3821
  drawAngleText(): void;
3822
+ /**
3823
+ * Calculate and draw angle text for a completed angle.
3824
+ * @internal
3825
+ */
3826
+ drawAngleTextForAngle(angle: {
3827
+ firstLine: number[];
3828
+ secondLine: number[];
3829
+ sliceIndex: number;
3830
+ sliceType: SLICE_TYPE;
3831
+ slicePosition: number;
3832
+ }): void;
3716
3833
  /**
3717
3834
  * Calculate angle between two lines in degrees.
3718
3835
  * @internal
@@ -3723,11 +3840,93 @@ declare class Niivue {
3723
3840
  * @internal
3724
3841
  */
3725
3842
  resetAngleMeasurement(): void;
3843
+ /**
3844
+ * Get slice information for the current measurement/angle.
3845
+ * @internal
3846
+ */
3847
+ getCurrentSliceInfo(): {
3848
+ sliceIndex: number;
3849
+ sliceType: SLICE_TYPE;
3850
+ slicePosition: number;
3851
+ };
3852
+ /**
3853
+ * Get the current slice position based on slice type.
3854
+ * @internal
3855
+ */
3856
+ getCurrentSlicePosition(sliceType: SLICE_TYPE): number;
3857
+ /**
3858
+ * Check if a measurement/angle should be drawn on the current slice.
3859
+ * @internal
3860
+ */
3861
+ shouldDrawOnCurrentSlice(sliceIndex: number, sliceType: SLICE_TYPE, slicePosition: number): boolean;
3862
+ /**
3863
+ * Clear all persistent measurement lines from the canvas.
3864
+ * @example
3865
+ * ```js
3866
+ * nv.clearMeasurements()
3867
+ * ```
3868
+ */
3869
+ clearMeasurements(): void;
3870
+ /**
3871
+ * Clear all persistent angle measurements from the canvas.
3872
+ * @example
3873
+ * ```js
3874
+ * nv.clearAngles()
3875
+ * ```
3876
+ */
3877
+ clearAngles(): void;
3878
+ /**
3879
+ * Clear all persistent measurements and angles from the canvas.
3880
+ * @example
3881
+ * ```js
3882
+ * nv.clearAllMeasurements()
3883
+ * ```
3884
+ */
3885
+ clearAllMeasurements(): void;
3726
3886
  /**
3727
3887
  * Set the drag mode for mouse interactions.
3728
3888
  * @param mode - The drag mode to set ('none', 'contrast', 'measurement', 'angle', 'pan', 'slicer3D', 'callbackOnly', 'roiSelection')
3729
3889
  */
3730
3890
  setDragMode(mode: string | DRAG_MODE): void;
3891
+ /**
3892
+ * Set custom mouse event configuration for button mappings.
3893
+ * @param config - Mouse event configuration object
3894
+ * @example
3895
+ * ```js
3896
+ * nv.setMouseEventConfig({
3897
+ * leftButton: {
3898
+ * primary: DRAG_MODE.windowing,
3899
+ * withShift: DRAG_MODE.measurement,
3900
+ * withCtrl: DRAG_MODE.crosshair
3901
+ * },
3902
+ * rightButton: DRAG_MODE.crosshair,
3903
+ * centerButton: DRAG_MODE.pan
3904
+ * })
3905
+ * ```
3906
+ */
3907
+ setMouseEventConfig(config: MouseEventConfig): void;
3908
+ /**
3909
+ * Set custom touch event configuration for touch gesture mappings.
3910
+ * @param config - Touch event configuration object
3911
+ * @example
3912
+ * ```js
3913
+ * nv.setTouchEventConfig({
3914
+ * singleTouch: DRAG_MODE.windowing,
3915
+ * doubleTouch: DRAG_MODE.pan
3916
+ * })
3917
+ * ```
3918
+ */
3919
+ setTouchEventConfig(config: TouchEventConfig): void;
3920
+ /**
3921
+ * Get current mouse event configuration.
3922
+ * @returns Current mouse event configuration or undefined if using defaults
3923
+ */
3924
+ getMouseEventConfig(): MouseEventConfig | undefined;
3925
+ /**
3926
+ * Get current touch event configuration.
3927
+ * @returns Current touch event configuration or undefined if using defaults
3928
+ */
3929
+ getTouchEventConfig(): TouchEventConfig | undefined;
3731
3930
  /**
3732
3931
  * Draw a rectangle or outline at given position with specified color or default crosshair color.
3733
3932
  * @internal
@@ -3844,6 +4043,11 @@ declare class Niivue {
3844
4043
  * @internal
3845
4044
  */
3846
4045
  drawTextBelow(xy: number[], str: string, scale?: number, color?: number[] | null): void;
4046
+ /**
4047
+ * Draw text horizontally centered above the given coordinates.
4048
+ * @internal
4049
+ */
4050
+ drawTextAbove(xy: number[], str: string, scale?: number, color?: number[] | null): void;
3847
4051
  /**
3848
4052
  * Update texture interpolation mode (nearest or linear) for background or overlay layer.
3849
4053
  * @internal
@@ -4075,6 +4279,21 @@ declare class Niivue {
4075
4279
  * @internal
4076
4280
  */
4077
4281
  canvasPos2frac(canvasPos: number[]): vec3;
4282
+ /**
4283
+ * Convert fractional volume coordinates to canvas pixel coordinates.
4284
+ * Returns the first valid screen slice that contains the fractional coordinates.
4285
+ * @internal
4286
+ */
4287
+ /**
4288
+ * Convert fractional volume coordinates to canvas pixel coordinates with tile information.
4289
+ * Returns both canvas position and the tile index for validation.
4290
+ * @internal
4291
+ */
4292
+ frac2canvasPosWithTile(frac: vec3, preferredSliceType?: SLICE_TYPE): {
4293
+ pos: number[];
4294
+ tileIndex: number;
4295
+ } | null;
4296
+ frac2canvasPos(frac: vec3): number[] | null;
4078
4297
  /**
4079
4298
  * Calculates scaled slice dimensions and position within the canvas.
4080
4299
  * n.b. beware of similarly named `sliceScale` method.
@@ -4151,6 +4370,29 @@ declare class Niivue {
4151
4370
  * @internal
4152
4371
  */
4153
4372
  set gl(gl: WebGL2RenderingContext | null);
4373
+ /**
4374
+ * Find the first and last slices containing drawing data along a given axis
4375
+ * @param sliceType - The slice orientation (AXIAL, CORONAL, or SAGITTAL)
4376
+ * @returns Object containing first and last slice indices, or null if no data found
4377
+ */
4378
+ findDrawingBoundarySlices(sliceType: SLICE_TYPE): {
4379
+ first: number;
4380
+ last: number;
4381
+ } | null;
4382
+ /**
4383
+ * Interpolate between mask slices using geometric or intensity-guided methods
4384
+ * @param sliceIndexLow - Lower slice index (optional, will auto-detect if not provided)
4385
+ * @param sliceIndexHigh - Higher slice index (optional, will auto-detect if not provided)
4386
+ * @param options - Interpolation options
4387
+ */
4388
+ interpolateMaskSlices(sliceIndexLow?: number, sliceIndexHigh?: number, options?: {
4389
+ intensityWeight?: number;
4390
+ binaryThreshold?: number;
4391
+ intensitySigma?: number;
4392
+ applySmoothingToSlices?: boolean;
4393
+ useIntensityGuided?: boolean;
4394
+ sliceType?: SLICE_TYPE;
4395
+ }): void;
4154
4396
  }
4155
4397
 
4156
- export { COLORMAP_TYPE, type Connectome, type ConnectomeOptions, DEFAULT_OPTIONS, DRAG_MODE, DRAG_MODE_PRIMARY, DRAG_MODE_SECONDARY, type DicomLoader, type DicomLoaderInput, type DocumentData, type DragReleaseParams, type ExportDocumentData, INITIAL_SCENE_DATA, LabelAnchorPoint, LabelLineTerminator, LabelTextAlignment, type LegacyConnectome, type LegacyNodes, MULTIPLANAR_TYPE, type NVConfigOptions, type NVConnectomeEdge, type NVConnectomeNode, NVDocument, NVImage, NVImageFromUrlOptions, NVLabel3D, NVLabel3DStyle, NVMesh, NVMeshFromUrlOptions, NVMeshLayerDefaults, NVMeshLoaders, NVMeshUtilities, NVUtilities, type NiftiHeader, type NiiVueLocation, type NiiVueLocationValue, Niivue, type Point, SHOW_RENDER, SLICE_TYPE, type Scene, type SyncOpts, type Volume, cmapper, ColorTables as colortables };
4398
+ export { COLORMAP_TYPE, type CompletedAngle, type CompletedMeasurement, type Connectome, type ConnectomeOptions, DEFAULT_OPTIONS, DRAG_MODE, type DicomLoader, type DicomLoaderInput, type DocumentData, type DragReleaseParams, type ExportDocumentData, INITIAL_SCENE_DATA, LabelAnchorPoint, LabelLineTerminator, LabelTextAlignment, type LegacyConnectome, type LegacyNodes, MULTIPLANAR_TYPE, type MouseEventConfig, type NVConfigOptions, type NVConnectomeEdge, type NVConnectomeNode, NVDocument, NVImage, NVImageFromUrlOptions, NVLabel3D, NVLabel3DStyle, NVMesh, NVMeshFromUrlOptions, NVMeshLayerDefaults, NVMeshLoaders, NVMeshUtilities, NVUtilities, type NiftiHeader, type NiiVueLocation, type NiiVueLocationValue, Niivue, PEN_TYPE, type Point, SHOW_RENDER, SLICE_TYPE, type Scene, type SyncOpts, type TouchEventConfig, type Volume, cmapper, ColorTables as colortables };