Class: Niivue
Defined in: niivue/index.ts:364
Niivue can be attached to a canvas. An instance of Niivue contains methods for loading and rendering NIFTI image data in a WebGL 2.0 context.
Example
let niivue = new Niivue({ crosshairColor: [0, 1, 0, 0.5], textHeight: 0.5 }); // a see-through green crosshair, and larger text labels
Constructors
Constructor
new Niivue(options: Partial<NVConfigOptions>): Niivue;
Defined in: niivue/index.ts:891
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
options | Partial <NVConfigOptions > | DEFAULT_OPTIONS | options object to set modifiable Niivue properties |
Returns
Niivue
Properties
Property | Type | Default value | Description | Defined in |
---|---|---|---|---|
_gl | WebGL2RenderingContext | null | - | niivue/index.ts:377 |
back | NVImage | null | - | niivue/index.ts:516 |
backgroundMasksOverlays | number | 0 | - | niivue/index.ts:456 |
blurShader | Shader | null | - | niivue/index.ts:443 |
bmpShader | Shader | null | - | niivue/index.ts:430 |
bmpTexture | WebGLTexture | null | - | niivue/index.ts:431 |
bmpTextureWH | number | 1.0 | - | niivue/index.ts:433 |
canvas | HTMLCanvasElement | null | - | niivue/index.ts:376 |
circleShader? | Shader | undefined | - | niivue/index.ts:428 |
clickToSegmentGrowingBitmap | Uint8Array | null | - | niivue/index.ts:394 |
clickToSegmentIsGrowing | boolean | false | - | niivue/index.ts:393 |
clickToSegmentXY | number [] | undefined | - | niivue/index.ts:395 |
CLIP_PLANE_ID | number | 1 | - | niivue/index.ts:545 |
colorbarHeight | number | 0 | - | niivue/index.ts:397 |
colorbarShader? | Shader | undefined | - | niivue/index.ts:423 |
colormapLists | ColormapListEntry [] | [] | - | niivue/index.ts:381 |
colormapTexture | WebGLTexture | null | - | niivue/index.ts:380 |
crosshairs3D | NiivueObject3D | null | - | niivue/index.ts:449 |
cuboidVertexBuffer? | WebGLBuffer | undefined | - | niivue/index.ts:534 |
currentClipPlaneIndex | number | 0 | - | niivue/index.ts:541 |
currentDrawUndoBitmap | number | undefined | - | niivue/index.ts:886 |
customLayout | object [] | [] | - | niivue/index.ts:557 |
customSliceShader | Shader | null | - | niivue/index.ts:424 |
deferredMeshes | LoadFromUrlParams [] | [] | - | niivue/index.ts:519 |
deferredVolumes | ImageFromUrlOptions [] | [] | - | niivue/index.ts:518 |
dicomLoader | DicomLoader | null | - | niivue/index.ts:367 |
DISTANCE_FROM_CAMERA | number | -0.54 | - | niivue/index.ts:547 |
document | NVDocument | undefined | - | niivue/index.ts:845 |
dragModes | object | undefined | - | niivue/index.ts:623 |
dragModes.angle | DRAG_MODE | DRAG_MODE.angle | - | niivue/index.ts:626 |
dragModes.callbackOnly | DRAG_MODE | DRAG_MODE.callbackOnly | - | niivue/index.ts:630 |
dragModes.contrast | DRAG_MODE | DRAG_MODE.contrast | - | niivue/index.ts:624 |
dragModes.measurement | DRAG_MODE | DRAG_MODE.measurement | - | niivue/index.ts:625 |
dragModes.none | DRAG_MODE | DRAG_MODE.none | - | niivue/index.ts:627 |
dragModes.pan | DRAG_MODE | DRAG_MODE.pan | - | niivue/index.ts:628 |
dragModes.slicer3D | DRAG_MODE | DRAG_MODE.slicer3D | - | niivue/index.ts:629 |
drawFillOverwrites | boolean | true | - | niivue/index.ts:400 |
drawLut | LUT | undefined | - | niivue/index.ts:390 |
drawOpacity | number | 0.8 | - | niivue/index.ts:391 |
drawPenAxCorSag | number | -1 | - | niivue/index.ts:399 |
drawPenFillPts | number [][] | [] | - | niivue/index.ts:401 |
drawPenLocation | number [] | undefined | - | niivue/index.ts:398 |
drawRimOpacity | number | -1.0 | - | niivue/index.ts:392 |
drawShapePreviewBitmap | Uint8Array | null | - | niivue/index.ts:403 |
drawShapeStartLocation | number [] | undefined | - | niivue/index.ts:402 |
drawTexture | WebGLTexture | null | - | niivue/index.ts:387 |
drawUndoBitmaps | Uint8Array [] | [] | - | niivue/index.ts:389 |
extentsMax? | vec3 | undefined | - | niivue/index.ts:461 |
extentsMin? | vec3 | undefined | - | niivue/index.ts:460 |
fiberShader? | Shader | undefined | - | niivue/index.ts:426 |
fontShader | Shader | null | - | niivue/index.ts:425 |
fontTexture | WebGLTexture | null | - | niivue/index.ts:427 |
furthestFromPivot | number | 10.0 | - | niivue/index.ts:539 |
furthestVertexFromOrigin | number | 100 | - | niivue/index.ts:520 |
genericVAO | WebGLVertexArrayObject | null | - | niivue/index.ts:447 |
gradientTexture | WebGLTexture | null | - | niivue/index.ts:383 |
gradientTextureAmount | number | 0.0 | - | niivue/index.ts:384 |
graph | Graph | undefined | - | niivue/index.ts:548 |
growCutShader? | Shader | undefined | - | niivue/index.ts:434 |
initialized | boolean | false | - | niivue/index.ts:885 |
isBusy | boolean | false | - | niivue/index.ts:378 |
lastCalled | number | undefined | - | niivue/index.ts:542 |
line3DShader? | Shader | undefined | - | niivue/index.ts:415 |
lineShader? | Shader | undefined | - | niivue/index.ts:414 |
loaders | object | {} | - | niivue/index.ts:365 |
matCapTexture | WebGLTexture | null | - | niivue/index.ts:429 |
mediaUrlMap | Map < | NVMesh | NVImage , string > | undefined | - | niivue/index.ts:884 |
meshShaders | object [] | undefined | - | niivue/index.ts:563 |
mousePos | number [] | undefined | - | niivue/index.ts:523 |
needsRefresh | boolean | false | - | niivue/index.ts:379 |
onAzimuthElevationChange | (azimuth : number , elevation : number ) => void | undefined | callback function to run when the user changes the rotation of the 3D rendering Example niivue.onAzimuthElevationChange = (azimuth, elevation) => { console.log('azimuth: ', azimuth) console.log('elevation: ', elevation) } | niivue/index.ts:808 |
onClickToSegment | (data : object ) => void | undefined | callback function when clickToSegment is enabled and the user clicks on the image. data contains the volume of the segmented region in mm3 and mL Example niivue.onClickToSegment = (data) => { console.log('clicked to segment') console.log('volume mm3: ', data.mm3) console.log('volume mL: ', data.mL) } | niivue/index.ts:689 |
onClipPlaneChange | (clipPlane : number []) => void | undefined | callback function to run when the user changes the clip plane Example niivue.onClipPlaneChange = (clipPlane) => { console.log('clipPlane: ', clipPlane) } | niivue/index.ts:817 |
onColormapChange | () => void | undefined | - | niivue/index.ts:732 |
onCustomMeshShaderAdded | (fragmentShaderText : string , name : string ) => void | undefined | - | niivue/index.ts:818 |
onDebug | () => void | undefined | callback function to run when niivue reports a debug message Example niivue.onDebug = (debug) => { console.log('debug: ', debug) } | niivue/index.ts:759 |
onDicomLoaderFinishedWithImages | (files : | NVImage [] | NVMesh []) => void | undefined | - | niivue/index.ts:822 |
onDocumentLoaded | (document : NVDocument ) => void | undefined | callback function to run when the user loads a new NiiVue document Example niivue.onDocumentLoaded = (document) => { console.log('document: ', document) } | niivue/index.ts:831 |
onDragRelease | (params : DragReleaseParams ) => void | undefined | callback function to run when the right mouse button is released after dragging Example niivue.onDragRelease = () => { console.log('drag ended') } | niivue/index.ts:648 |
onError | () => void | undefined | callback function to run when niivue reports an error Example niivue.onError = (error) => { console.log('error: ', error) } | niivue/index.ts:729 |
onFrameChange | (volume : NVImage , index : number ) => void | undefined | callback function to run when the user changes the volume when a 4D image is loaded Example niivue.onFrameChange = (volume, frameNumber) => { console.log('frame changed') console.log('volume: ', volume) console.log('frameNumber: ', frameNumber) } | niivue/index.ts:720 |
onImageLoaded | (volume : NVImage ) => void | undefined | callback function to run when a new volume is loaded Example niivue.onImageLoaded = (volume) => { console.log('volume loaded') console.log('volume: ', volume) } | niivue/index.ts:699 |
onInfo | () => void | undefined | callback function to run when niivue reports detailed info Example niivue.onInfo = (info) => { console.log('info: ', info) } | niivue/index.ts:741 |
onIntensityChange | (volume : NVImage ) => void | undefined | callback function to run when the user changes the intensity range with the selection box action (right click) Example niivue.onIntensityChange = (volume) => { console.log('intensity changed') console.log('volume: ', volume) } | niivue/index.ts:678 |
onLocationChange | (location : unknown ) => void | undefined | callback function to run when the crosshair location changes Example niivue.onLocationChange = (data) => { console.log('location changed') console.log('mm: ', data.mm) console.log('vox: ', data.vox) console.log('frac: ', data.frac) console.log('values: ', data.values) } | niivue/index.ts:669 |
onMeshAdded | () => void | undefined | - | niivue/index.ts:794 |
onMeshAddedFromUrl | (meshOptions : LoadFromUrlParams , mesh : NVMesh ) => void | undefined | callback function to run when a mesh is added from a url Example niivue.onMeshAddedFromUrl = (meshOptions, mesh) => { console.log('mesh added from url') console.log('meshOptions: ', meshOptions) console.log('mesh: ', mesh) } | niivue/index.ts:791 |
onMeshLoaded | (mesh : NVMesh ) => void | undefined | callback function to run when a new mesh is loaded Example niivue.onMeshLoaded = (mesh) => { console.log('mesh loaded') console.log('mesh: ', mesh) } | niivue/index.ts:709 |
onMeshPropertyChanged | (meshIndex : number , key : string , val : unknown ) => void | undefined | - | niivue/index.ts:820 |
onMeshShaderChanged | (meshIndex : number , shaderIndex : number ) => void | undefined | - | niivue/index.ts:819 |
onMeshWithUrlRemoved | (url : string ) => void | undefined | - | niivue/index.ts:795 |
onMouseUp | (data : Partial <UIData >) => void | undefined | callback function to run when the left mouse button is released Example niivue.onMouseUp = () => { console.log('mouse up') } | niivue/index.ts:657 |
onOptsChange | (propertyName : keyof NVConfigOptions , newValue : | string | number | boolean | number [] | Float32Array | MouseEventConfig | TouchEventConfig | number [] | [[number , number ], [number , number ]], oldValue : | string | number | boolean | number [] | Float32Array | MouseEventConfig | TouchEventConfig | number [] | [[number , number ], [number , number ]]) => void | undefined | Callback for when any configuration option changes. | niivue/index.ts:839 |
onVolumeAddedFromUrl | (imageOptions : ImageFromUrlOptions , volume : NVImage ) => void | undefined | callback function to run when a volume is added from a url Example niivue.onVolumeAddedFromUrl = (imageOptions, volume) => { console.log('volume added from url') console.log('imageOptions: ', imageOptions) console.log('volume: ', volume) } | niivue/index.ts:770 |
onVolumeUpdated | () => void | undefined | callback function to run when updateGLVolume is called (most users will not need to use Example niivue.onVolumeUpdated = () => { console.log('volume updated') } | niivue/index.ts:780 |
onVolumeWithUrlRemoved | (url : string ) => void | undefined | - | niivue/index.ts:771 |
onWarn | () => void | undefined | callback function to run when niivue reports a warning Example niivue.onWarn = (warn) => { console.log('warn: ', warn) } | niivue/index.ts:750 |
onZoom3DChange | (zoom : number ) => void | undefined | - | niivue/index.ts:798 |
orientCubeShader? | Shader | undefined | - | niivue/index.ts:409 |
orientCubeShaderVAO | WebGLVertexArrayObject | null | - | niivue/index.ts:410 |
orientShaderAtlasI | Shader | null | - | niivue/index.ts:436 |
orientShaderAtlasU | Shader | null | - | niivue/index.ts:435 |
orientShaderF | Shader | null | - | niivue/index.ts:439 |
orientShaderI | Shader | null | - | niivue/index.ts:438 |
orientShaderPAQD | Shader | null | - | niivue/index.ts:441 |
orientShaderRGBU | Shader | null | - | niivue/index.ts:440 |
orientShaderU | Shader | null | - | niivue/index.ts:437 |
otherNV | Niivue [] | null | - | niivue/index.ts:536 |
overlayAlphaShader | number | 1 | - | niivue/index.ts:458 |
overlayOutlineWidth | number | 0 | - | niivue/index.ts:457 |
overlays | NVImage [] | [] | - | niivue/index.ts:517 |
overlayTexture | WebGLTexture | null | - | niivue/index.ts:404 |
overlayTextureID | WebGLTexture | null | - | niivue/index.ts:405 |
paqdTexture | WebGLTexture | null | - | niivue/index.ts:388 |
passThroughShader? | Shader | undefined | - | niivue/index.ts:416 |
pickingImageShader? | Shader | undefined | - | niivue/index.ts:422 |
pickingMeshShader? | Shader | undefined | - | niivue/index.ts:421 |
pivot3D | number [] | undefined | - | niivue/index.ts:538 |
position? | vec3 | undefined | - | niivue/index.ts:459 |
readyForSync | boolean | false | - | niivue/index.ts:479 |
rectOutlineShader? | Shader | undefined | - | niivue/index.ts:412 |
rectShader? | Shader | undefined | - | niivue/index.ts:411 |
renderDrawAmbientOcclusion | number | 0.4 | - | niivue/index.ts:396 |
renderGradientShader? | Shader | undefined | - | niivue/index.ts:417 |
renderGradientValues | boolean | false | - | niivue/index.ts:386 |
renderGradientValuesShader? | Shader | undefined | - | niivue/index.ts:418 |
renderShader? | Shader | undefined | - | niivue/index.ts:413 |
renderSliceShader? | Shader | undefined | - | niivue/index.ts:419 |
renderVolumeShader? | Shader | undefined | - | niivue/index.ts:420 |
screenSlices | object [] | [] | - | niivue/index.ts:524 |
selectedObjectId | number | -1 | - | niivue/index.ts:544 |
slice2DShader? | Shader | undefined | - | niivue/index.ts:407 |
sliceMMShader? | Shader | undefined | - | niivue/index.ts:406 |
sliceTypeAxial | SLICE_TYPE | SLICE_TYPE.AXIAL | - | niivue/index.ts:634 |
sliceTypeCoronal | SLICE_TYPE | SLICE_TYPE.CORONAL | - | niivue/index.ts:635 |
sliceTypeMultiplanar | SLICE_TYPE | SLICE_TYPE.MULTIPLANAR | - | niivue/index.ts:637 |
sliceTypeRender | SLICE_TYPE | SLICE_TYPE.RENDER | - | niivue/index.ts:638 |
sliceTypeSagittal | SLICE_TYPE | SLICE_TYPE.SAGITTAL | - | niivue/index.ts:636 |
sliceV1Shader? | Shader | undefined | - | niivue/index.ts:408 |
sobelBlurShader | Shader | null | - | niivue/index.ts:444 |
sobelFirstOrderShader | Shader | null | - | niivue/index.ts:445 |
sobelSecondOrderShader | Shader | null | - | niivue/index.ts:446 |
surfaceShader | Shader | null | - | niivue/index.ts:442 |
syncOpts | SyncOpts | undefined | - | niivue/index.ts:467 |
thumbnailVisible | boolean | false | - | niivue/index.ts:432 |
uiData | UIData | undefined | - | niivue/index.ts:482 |
unusedVAO | any | null | - | niivue/index.ts:448 |
useCustomGradientTexture | boolean | false | - | niivue/index.ts:385 |
volScale | number [] | [] | - | niivue/index.ts:521 |
VOLUME_ID | number | 254 | - | niivue/index.ts:546 |
volumeObject3D | NiivueObject3D | null | - | niivue/index.ts:537 |
volumeTexture | WebGLTexture | null | - | niivue/index.ts:382 |
vox | number [] | [] | - | niivue/index.ts:522 |
Accessors
drawBitmap
Get Signature
get drawBitmap(): Uint8Array;
Defined in: niivue/index.ts:981
Returns
Uint8Array
Set Signature
set drawBitmap(drawBitmap: Uint8Array): void;
Defined in: niivue/index.ts:985
Parameters
Parameter | Type |
---|---|
drawBitmap | Uint8Array |
Returns
void
isAlphaClipDark
Get Signature
get isAlphaClipDark(): boolean;
Defined in: niivue/index.ts:871
Get whether voxels below minimum intensity are drawn as dark or transparent.
Returns
boolean
True if dark voxels are opaque, false if transparent.
Set Signature
set isAlphaClipDark(newVal: boolean): void;
Defined in: niivue/index.ts:880
Set whether voxels below minimum intensity are drawn as dark or transparent.
See
Parameters
Parameter | Type | Description |
---|---|---|
newVal | boolean | True to make dark voxels opaque, false for transparent. |
Returns
void
meshes
Get Signature
get meshes(): NVMesh[];
Defined in: niivue/index.ts:973
Returns
NVMesh
[]
Set Signature
set meshes(meshes: NVMesh[]): void;
Defined in: niivue/index.ts:977
Parameters
Parameter | Type |
---|---|
meshes | NVMesh [] |
Returns
void
opts
Get Signature
get opts(): NVConfigOptions;
Defined in: niivue/index.ts:853
Get the current visualization options.
Returns
scene
Get Signature
get scene(): Scene;
Defined in: niivue/index.ts:848
Get the current scene configuration.
Returns
sliceMosaicString
Get Signature
get sliceMosaicString(): string;
Defined in: niivue/index.ts:858
Get the slice mosaic layout string.
Returns
string
Set Signature
set sliceMosaicString(newSliceMosaicString: string): void;
Defined in: niivue/index.ts:863
Set the slice mosaic layout string.
Parameters
Parameter | Type |
---|---|
newSliceMosaicString | string |
Returns
void
volScaleMultiplier
Get Signature
get volScaleMultiplier(): number;
Defined in: niivue/index.ts:989
Returns
number
Set Signature
set volScaleMultiplier(scale: number): void;
Defined in: niivue/index.ts:993
Parameters
Parameter | Type |
---|---|
scale | number |
Returns
void
volumes
Get Signature
get volumes(): NVImage[];
Defined in: niivue/index.ts:965
Returns
NVImage
[]
Set Signature
set volumes(volumes: NVImage[]): void;
Defined in: niivue/index.ts:969
Parameters
Parameter | Type |
---|---|
volumes | NVImage [] |
Returns
void
Methods
addColormap()
addColormap(key: string, cmap: ColorMap): void;
Defined in: niivue/index.ts:8849
create a new colormap
Parameters
Parameter | Type | Description |
---|---|---|
key | string | name of new colormap |
cmap | ColorMap | colormap properties (Red, Green, Blue, Alpha and Indices) |
Returns
void
See
addLabel()
addLabel(
text: string,
style: NVLabel3DStyle,
points?: number[] | number[][],
anchor?: LabelAnchorPoint,
onClick?: (label: NVLabel3D) => void): NVLabel3D;
Defined in: niivue/index.ts:13229
Add a 3D Label
Parameters
Parameter | Type | Description |
---|---|---|
text | string | the text content of the label |
style | NVLabel3DStyle | visual styling options for the label (e.g., color, scale, line width) |
points? | number [] | number [][] | a 3D point [x, y, z] or array of points to anchor the label in space |
anchor? | LabelAnchorPoint | optional label anchor position (e.g., top-left, center, etc.) |
onClick? | (label : NVLabel3D ) => void | optional callback function to invoke when the label is clicked |
Returns
NVLabel3D
the created NVLabel3D
instance
See
addMesh()
addMesh(mesh: NVMesh): void;
Defined in: niivue/index.ts:3558
add a new mesh to the canvas
Parameters
Parameter | Type | Description |
---|---|---|
mesh | NVMesh | the new mesh to add to the canvas |
Returns
void
Example
niivue = new Niivue();
niivue.addMesh(NVMesh.loadFromUrl({ url: "../someURL.gii" }));
See
addMeshesFromUrl()
addMeshesFromUrl(meshOptions: LoadFromUrlParams[]): Promise<NVMesh[]>;
Defined in: niivue/index.ts:5433
Add mesh and notify subscribers
Parameters
Parameter | Type |
---|---|
meshOptions | LoadFromUrlParams [] |
Returns
Promise
<NVMesh
[]>
addMeshFromUrl()
addMeshFromUrl(meshOptions: LoadFromUrlParams): Promise<NVMesh>;
Defined in: niivue/index.ts:5412
Add mesh and notify subscribers
Parameters
Parameter | Type |
---|---|
meshOptions | LoadFromUrlParams |
Returns
Promise
<NVMesh
>
addVolume()
addVolume(volume: NVImage): void;
Defined in: niivue/index.ts:3541
add a new volume to the canvas
Parameters
Parameter | Type | Description |
---|---|---|
volume | NVImage | the new volume to add to the canvas |
Returns
void
Example
niivue = new Niivue();
niivue.addVolume(NVImage.loadFromUrl({ url: "../someURL.nii.gz" }));
See
addVolumeFromUrl()
addVolumeFromUrl(imageOptions: ImageFromUrlOptions): Promise<NVImage>;
Defined in: niivue/index.ts:2746
Add an image and notify subscribers
Parameters
Parameter | Type |
---|---|
imageOptions | ImageFromUrlOptions |
Returns
Promise
<NVImage
>
See
addVolumesFromUrl()
addVolumesFromUrl(imageOptionsArray: ImageFromUrlOptions[]): Promise<NVImage[]>;
Defined in: niivue/index.ts:2758
Parameters
Parameter | Type |
---|---|
imageOptionsArray | ImageFromUrlOptions [] |
Returns
Promise
<NVImage
[]>
attachTo()
attachTo(id: string, isAntiAlias: any): Promise<Niivue>;
Defined in: niivue/index.ts:1041
attach the Niivue instance to the webgl2 canvas by element id
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
id | string | undefined | the id of an html canvas element |
isAntiAlias | any | null | determines if anti-aliasing is requested (if not specified, AA usage depends on hardware) |
Returns
Promise
<Niivue
>
Examples
niivue = new Niivue().attachTo("gl");
await niivue.attachTo("gl");
See
attachToCanvas()
attachToCanvas(canvas: HTMLCanvasElement, isAntiAlias: boolean): Promise<Niivue>;
Defined in: niivue/index.ts:1055
attach the Niivue instance to a canvas element directly
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
canvas | HTMLCanvasElement | undefined | the canvas element reference |
isAntiAlias | boolean | null | - |
Returns
Promise
<Niivue
>
Example
niivue = new Niivue();
await niivue.attachToCanvas(document.getElementById(id));
See
binarize()
binarize(volume: NVImage): void;
Defined in: niivue/index.ts:3751
Binarize a volume by converting all non-zero voxels to 1
Parameters
Parameter | Type | Description |
---|---|---|
volume | NVImage | the image volume to modify in place |
Returns
void
See
broadcastTo()
broadcastTo(otherNV: Niivue | Niivue[], syncOpts: object): void;
Defined in: niivue/index.ts:1148
Sync the scene controls (orientation, crosshair location, etc.) from one Niivue instance to others. useful for using one canvas to drive another.
Parameters
Parameter | Type | Description |
---|---|---|
otherNV | Niivue | Niivue [] | the other Niivue instance(s) |
syncOpts | { 2d : boolean ; 3d : boolean ; } | - |
syncOpts.2d | boolean | - |
syncOpts.3d | boolean | - |
Returns
void
Example
niivue1 = new Niivue();
niivue2 = new Niivue();
niivue3 = new Niivue();
niivue1.broadcastTo(niivue2);
niivue1.broadcastTo([niivue2, niivue3]);
See
calculateMvpMatrix()
calculateMvpMatrix(
_unused: unknown,
leftTopWidthHeight: number[],
azimuth: number,
elevation: number,
flipX: boolean): mat4[];
Defined in: niivue/index.ts:12410
Build MVP, Model, and Normal matrices for rendering.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
_unused | unknown | undefined | reserved |
leftTopWidthHeight | number [] | ... | viewport rectangle [x, y, w, h] in device pixels |
azimuth | number | undefined | azimuth rotation in degrees |
elevation | number | undefined | elevation rotation in degrees |
flipX | boolean | true | whether to mirror the X axis (default true for radiological convention) |
Returns
mat4
[]
cleanup()
cleanup(): void;
Defined in: niivue/index.ts:934
Clean up event listeners and observers Call this when the Niivue instance is no longer needed. This will be called when the canvas is detached from the DOM
Returns
void
Example
niivue.cleanup();
clearAllMeasurements()
clearAllMeasurements(): void;
Defined in: niivue/index.ts:10941
Clear all persistent measurements and angles from the canvas.
Returns
void
Example
nv.clearAllMeasurements();
clearAngles()
clearAngles(): void;
Defined in: niivue/index.ts:10929
Clear all persistent angle measurements from the canvas.
Returns
void
Example
nv.clearAngles();
clearBounds()
clearBounds(mask: number, ltwh?: [number, number, number, number]): void;
Defined in: niivue/index.ts:15102
Clear a rectangular region of this instance's canvas.
Parameters
Parameter | Type | Description |
---|---|---|
mask | number | bitmask of buffers to clear (default: color+depth). |
ltwh? | [number , number , number , number ] | optional [x, y, w, h] region in device px (GL coords, bottom-left). If not provided, clears the full instance bounds (getBoundsRegion). For multiplanar panels, pass the panel’s own [x,y,w,h]. |
Returns
void
clearCustomLayout()
clearCustomLayout(): void;
Defined in: niivue/index.ts:3377
Clear custom layout and rely on built-in layouts
Returns
void
clearMeasurements()
clearMeasurements(): void;
Defined in: niivue/index.ts:10917
Clear all persistent measurement lines from the canvas.
Returns
void
Example
nv.clearMeasurements();
cloneVolume()
cloneVolume(index: number): NVImage;
Defined in: niivue/index.ts:4933
clone a volume and return a new volume
Parameters
Parameter | Type | Description |
---|---|---|
index | number | the index of the volume to clone |
Returns
new volume to work with, but that volume is not added to the canvas
Example
niivue = new Niivue();
niivue.cloneVolume(0);
closeDrawing()
closeDrawing(): void;
Defined in: niivue/index.ts:6754
close drawing: make sure you have saved any changes before calling this!
Returns
void
Example
niivue.closeDrawing();
See
colormap()
colormap(lutName: string, isInvert: boolean): Uint8ClampedArray;
Defined in: niivue/index.ts:9773
Retrieve a colormap with optional inversion
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
lutName | string | '' | name of the lookup table (LUT) colormap |
isInvert | boolean | false | whether to invert the colormap |
Returns
Uint8ClampedArray
the RGBA colormap as a Uint8ClampedArray
See
colormaps()
colormaps(): string[];
Defined in: niivue/index.ts:8839
query all available color maps that can be applied to volumes
Returns
string
[]
an array of colormap strings
Example
niivue = new Niivue();
colormaps = niivue.colormaps();
See
conform()
conform(
volume: NVImage,
toRAS: boolean,
isLinear: boolean,
asFloat32: boolean,
isRobustMinMax: boolean): Promise<NVImage>;
Defined in: niivue/index.ts:9476
FreeSurfer-style conform reslices any image to a 256x256x256 volume with 1mm voxels
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
volume | NVImage | undefined | input volume to be re-oriented, intensity-scaled and resliced |
toRAS | boolean | false | reslice to row, column slices to right-anterior-superior not left-inferior-anterior (default false). |
isLinear | boolean | true | reslice with linear rather than nearest-neighbor interpolation (default true). |
asFloat32 | boolean | false | use Float32 datatype rather than Uint8 (default false). |
isRobustMinMax | boolean | false | clamp intensity with robust min max (~2%..98%) instead of FreeSurfer (0%..99.99%) (default false). |
Returns
Promise
<NVImage
>
See
createConnectedLabelImage()
createConnectedLabelImage(
id: string,
conn: number,
binarize: boolean,
onlyLargestClusterPerClass: boolean): Promise<NVImage>;
Defined in: niivue/index.ts:9188
Create a connected component label map from a volume
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
id | string | undefined | ID of the input volume |
conn | number | 26 | connectivity for clustering (6 = faces, 18 = faces + edges, 26 = faces + edges + corners) |
binarize | boolean | false | whether to binarize the volume before labeling |
onlyLargestClusterPerClass | boolean | false | retain only the largest cluster for each label |
Returns
Promise
<NVImage
>
a new NVImage with labeled clusters, using random colormap
See
createCustomMeshShader()
createCustomMeshShader(fragmentShaderText: string, name: string): object;
Defined in: niivue/index.ts:7332
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
fragmentShaderText | string | undefined | custom fragment shader. |
name | string | 'Custom' | title for new shader. |
Returns
object
created custom mesh shader
Name | Type | Defined in |
---|---|---|
Frag | string | niivue/index.ts:7336 |
Name | string | niivue/index.ts:7336 |
shader | Shader | niivue/index.ts:7336 |
createEmptyDrawing()
createEmptyDrawing(): void;
Defined in: niivue/index.ts:5631
generate a blank canvas for the pen tool
Returns
void
Example
niivue.createEmptyDrawing();
See
createNiftiArray()
createNiftiArray(
dims: number[],
pixDims: number[],
affine: number[],
datatypeCode: NiiDataType,
img: Uint8Array): Promise<Uint8Array>;
Defined in: niivue/index.ts:9432
Create a binary NIfTI file as a Uint8Array, including header and image data
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
dims | number [] | ... | image dimensions [x, y, z] |
pixDims | number [] | ... | voxel dimensions in mm [x, y, z] |
affine | number [] | ... | 4×4 affine transformation matrix in row-major order |
datatypeCode | NiiDataType | NiiDataType.DT_UINT8 | NIfTI datatype code (e.g., DT_UINT8, DT_FLOAT32) |
img | Uint8Array | ... | image data buffer (optional) |
Returns
Promise
<Uint8Array
>
a Uint8Array representing a complete NIfTI file
See
createOnLocationChange()
createOnLocationChange(axCorSag: number): void;
Defined in: niivue/index.ts:13106
Internal utility to generate human-readable location strings for the onLocationChange callback
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
axCorSag | number | NaN | optional axis index for coordinate interpretation (NaN by default) |
Returns
void
Remarks
Computes string representation of current crosshair position in mm (and frame if 4D).
See
decimateHierarchicalMesh()
decimateHierarchicalMesh(mesh: number, order: number): boolean;
Defined in: niivue/index.ts:4171
reduce complexity of FreeSurfer mesh
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
mesh | number | undefined | identity of mesh to change |
order | number | 3 | decimation order 0..6 |
Returns
boolean
boolean false if mesh is not hierarchical or of lower order
Example
niivue.decimateHierarchicalMesh(niivue.meshes[0].id, 4);
See
doSyncGamma()
doSyncGamma(otherNV: Niivue): void;
Defined in: niivue/index.ts:1177
Parameters
Parameter | Type |
---|---|
otherNV | Niivue |
Returns
void
drawGrowCut()
drawGrowCut(): void;
Defined in: niivue/index.ts:5697
dilate drawing so all voxels are colored. works on drawing with multiple colors
Returns
void
Example
niivue.drawGrowCut();
See
drawingBinaryDilationWithSeed()
drawingBinaryDilationWithSeed(seedXYZ: number[], neighbors: 6 | 18 | 26): void;
Defined in: niivue/index.ts:6029
Performs a 1-voxel binary dilation on a connected cluster within the drawing mask using the drawFloodFillCore function.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
seedXYZ | number [] | undefined | voxel index of the seed voxel in the mask array. |
neighbors | 6 | 18 | 26 | 6 | Number of neighbors to consider for connectivity and dilation (6, 18, or 26). |
Returns
void
drawMosaic()
drawMosaic(mosaicStr: string): void;
Defined in: niivue/index.ts:14722
display a lightbox or montage view
Parameters
Parameter | Type | Description |
---|---|---|
mosaicStr | string | specifies orientation (A,C,S) and location of slices. |
Returns
void
Example
niivue.setSliceMosaicString("A -10 0 20");
See
drawOtsu()
drawOtsu(levels: number): void;
Defined in: niivue/index.ts:3910
remove dark voxels in air
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
levels | number | 2 | (2-4) segment brain into this many types. For example drawOtsu(2) will create a binary drawing where bright voxels are colored and dark voxels are clear. |
Returns
void
Example
niivue.drawOtsu(3);
See
drawUndo()
drawUndo(): void;
Defined in: niivue/index.ts:3631
Restore drawing to previous state
Returns
void
Example
niivue.drawUndo();
See
eventInBounds()
eventInBounds(evt: MouseEvent | Touch | TouchEvent): boolean;
Defined in: niivue/index.ts:14965
Returns true if a mouse/touch event happened inside this instance’s bounds.
Parameters
Parameter | Type |
---|---|
evt | MouseEvent | Touch | TouchEvent |
Returns
boolean
findDrawingBoundarySlices()
findDrawingBoundarySlices(sliceType: SLICE_TYPE): object;
Defined in: niivue/index.ts:15773
Find the first and last slices containing drawing data along a given axis
Parameters
Parameter | Type | Description |
---|---|---|
sliceType | SLICE_TYPE | The slice orientation (AXIAL, CORONAL, or SAGITTAL) |
Returns
object
Object containing first and last slice indices, or null if no data found
Name | Type | Defined in |
---|---|---|
first | number | niivue/index.ts:15773 |
last | number | niivue/index.ts:15773 |
frac2canvasPos()
frac2canvasPos(frac: vec3): number[];
Defined in: niivue/index.ts:14186
Parameters
Parameter | Type |
---|---|
frac | vec3 |
Returns
number
[]
generateHTML()
generateHTML(canvasId: string, esm: string): Promise<string>;
Defined in: niivue/index.ts:5128
generates HTML of current scene
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
canvasId | string | 'gl1' | id of canvas NiiVue will be attached to |
esm | string | undefined | bundled version of NiiVue |
Returns
Promise
<string
>
HTML with javascript of the current scene
Example
const template = `<html><body><canvas id="gl1"></canvas><script type="module" async>
%%javascript%%</script></body></html>`;
nv1.generateHTML("page.html", esm);
generateLoadDocumentJavaScript()
generateLoadDocumentJavaScript(canvasId: string, esm: string): Promise<string>;
Defined in: niivue/index.ts:5087
generates JavaScript to load the current scene as a document
Parameters
Parameter | Type | Description |
---|---|---|
canvasId | string | id of canvas NiiVue will be attached to |
esm | string | bundled version of NiiVue |
Returns
Promise
<string
>
Example
const javascript = this.generateLoadDocumentJavaScript("gl1");
const html = `<html><body><canvas id="gl1"></canvas><script type="module" async>
${javascript}</script></body></html>`;
See
getCustomLayout()
getCustomLayout(): object[];
Defined in: niivue/index.ts:3386
Get the current custom layout if set
Returns
object
[]
The current custom layout or null if using built-in layouts
getDescriptives()
getDescriptives(options: object): Descriptive;
Defined in: niivue/index.ts:7948
basic statistics for selected voxel-based image
Parameters
Parameter | Type | Description |
---|---|---|
options | { drawingIsMask? : boolean ; endVox? : number []; layer? : number ; masks? : number []; roiIsMask? : boolean ; startVox? : number []; } | an object containing the following properties: - layer: selects image to describe - masks: optional binary images to filter voxels - drawingIsMask: a boolean indicating if the drawing is used as a mask - roiIsMask: a boolean indicating if the ROI is used as a mask - startVox: the starting voxel coordinates - endVox: the ending voxel coordinates |
options.drawingIsMask? | boolean | - |
options.endVox? | number [] | - |
options.layer? | number | - |
options.masks? | number [] | - |
options.roiIsMask? | boolean | - |
options.startVox? | number [] | - |
Returns
Descriptive
numeric values to describe image or regions of images
Example
niivue.getDescriptives({
layer: 0,
masks: [],
drawingIsMask: true, // drawingIsMask and roiIsMask are mutually exclusive
roiIsMask: false,
startVox: [10, 20, 30], // ignored if roiIsMask is false
endVox: [40, 50, 60], // ignored if roiIsMask is false
});
See
getDicomLoader()
getDicomLoader(): DicomLoader;
Defined in: niivue/index.ts:3028
Get the currently assigned DICOM loader.
Returns
getFrame4D()
getFrame4D(id: string): number;
Defined in: niivue/index.ts:9753
determine active 3D volume from 4D time series
Parameters
Parameter | Type | Description |
---|---|---|
id | string | the ID of the 4D NVImage |
Returns
number
currently selected volume (indexed from 0)
Example
nv1.getFrame4D(nv1.volumes[0].id);
See
getGradientTextureData()
getGradientTextureData(): Float32Array;
Defined in: niivue/index.ts:7729
Get the gradient texture produced by gradientGL as a TypedArray
Returns
Float32Array
Float32Array containing the gradient texture data, or null if no gradient texture exists
Example
niivue = new Niivue();
niivue.loadVolumes([{ url: "./someImage.nii" }]);
// ... after volume is loaded and gradient is computed
const gradientData = niivue.getGradientTextureData();
if (gradientData) {
console.log("Gradient texture dimensions:", gradientData.length);
}
See
getMeshIndexByID()
getMeshIndexByID(id: string | number): number;
Defined in: niivue/index.ts:4104
Returns the index of a mesh given its ID or index.
Parameters
Parameter | Type | Description |
---|---|---|
id | string | number | The mesh ID as a string, or an index number. |
Returns
number
The mesh index, or -1 if not found or out of range.
getMouseEventConfig()
getMouseEventConfig(): MouseEventConfig;
Defined in: niivue/index.ts:11038
Get current mouse event configuration.
Returns
Current mouse event configuration or undefined if using defaults
getOverlayIndexByID()
getOverlayIndexByID(id: string): number;
Defined in: niivue/index.ts:4250
get the index of an overlay by its unique id. unique ids are assigned to the NVImage.id property when a new NVImage is created.
Parameters
Parameter | Type | Description |
---|---|---|
id | string | the id string to search for |
Returns
number
See
NiiVue#getVolumeIndexByID
Example
niivue = new Niivue();
niivue.getOverlayIndexByID(someVolume.id);
getRadiologicalConvention()
getRadiologicalConvention(): boolean;
Defined in: niivue/index.ts:3484
Detect if display is using radiological or neurological convention.
Returns
boolean
radiological convention status
Example
let rc = niivue.getRadiologicalConvention();
getTouchEventConfig()
getTouchEventConfig(): TouchEventConfig;
Defined in: niivue/index.ts:11046
Get current touch event configuration.
Returns
Current touch event configuration or undefined if using defaults
getVolumeIndexByID()
getVolumeIndexByID(id: string): number;
Defined in: niivue/index.ts:3572
get the index of a volume by its unique id. unique ids are assigned to the NVImage.id property when a new NVImage is created.