dwv
Version:
DICOM Web Viewer.
1,676 lines (1,648 loc) • 113 kB
TypeScript
/**
* Add tags to the dictionary.
*
* @param {string} group The group key.
* @param {object} tags The tags to add.
*/
export declare function addTagsToDictionary(group: string, tags: object): void;
/**
* List of ViewConfigs indexed by dataIds.
*
* @typedef {Object<string, ViewConfig[]>} DataViewConfigs
*/
/**
* Main application class.
*
* @example
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new dwv.AppOptions(viewConfigs);
* app.init(options);
* // load dicom data
* app.loadURLs([
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'
* ]);
*/
export declare class App {
/**
* Get the image.
*
* @param {number} index The data index.
* @returns {Image} The associated image.
*/
getImage(index: number): Image_2;
/**
* Get the last loaded image.
*
* @returns {Image} The image.
*/
getLastImage(): Image_2;
/**
* Set the image at the given index.
*
* @param {number} index The data index.
* @param {Image} img The associated image.
*/
setImage(index: number, img: Image_2): void;
/**
* Set the last image.
*
* @param {Image} img The associated image.
*/
setLastImage(img: Image_2): void;
/**
* Add a new image.
*
* @param {Image} image The new image.
* @param {object} meta The image meta.
* @returns {number} The new image id.
*/
addNewImage(image: Image_2, meta: object): number;
/**
* Get the meta data.
*
* @param {number} index The data index.
* @returns {object} The list of meta data.
*/
getMetaData(index: number): object;
/**
* Get the number of loaded data.
*
* @returns {number} The number.
*/
getNumberOfLoadedData(): number;
/**
* Can the data be scrolled?
*
* @returns {boolean} True if the data has a third dimension greater than one.
*/
canScroll(): boolean;
/**
* Can window and level be applied to the data?
*
* @returns {boolean} True if the data is monochrome.
*/
canWindowLevel(): boolean;
/**
* Get the layer scale on top of the base scale.
*
* @returns {object} The scale as {x,y}.
*/
getAddedScale(): object;
/**
* Get the base scale.
*
* @returns {object} The scale as {x,y}.
*/
getBaseScale(): object;
/**
* Get the layer offset.
*
* @returns {object} The offset.
*/
getOffset(): object;
/**
* Get the toolbox controller.
*
* @returns {ToolboxController} The controller.
*/
getToolboxController(): ToolboxController;
/**
* Get the active layer group.
* The layer is available after the first loaded item.
*
* @returns {LayerGroup} The layer group.
*/
getActiveLayerGroup(): LayerGroup;
/**
* Get the view layers associated to a data index.
* The layer are available after the first loaded item.
*
* @param {number} index The data index.
* @returns {ViewLayer[]} The layers.
*/
getViewLayersByDataIndex(index: number): ViewLayer[];
/**
* Get the draw layers associated to a data index.
* The layer are available after the first loaded item.
*
* @param {number} index The data index.
* @returns {DrawLayer[]} The layers.
*/
getDrawLayersByDataIndex(index: number): DrawLayer[];
/**
* Get a layer group by div id.
* The layer is available after the first loaded item.
*
* @param {string} divId The div id.
* @returns {LayerGroup} The layer group.
*/
getLayerGroupByDivId(divId: string): LayerGroup;
/**
* Get the number of layer groups.
*
* @returns {number} The number of groups.
*/
getNumberOfLayerGroups(): number;
/**
* Get the app style.
*
* @returns {object} The app style.
*/
getStyle(): object;
/**
* Add a command to the undo stack.
*
* @param {object} cmd The command to add.
* @fires UndoStack#undoadd
* @function
*/
addToUndoStack: (cmd: object) => void;
/**
* Initialise the application.
*
* @param {AppOptions} opt The application options
* @example
* // create the dwv app
* const app = new dwv.App();
* // initialise
* const viewConfig0 = new dwv.ViewConfig('layerGroup0');
* const viewConfigs = {'*': [viewConfig0]};
* const options = new dwv.AppOptions(viewConfigs);
* options.viewOnFirstLoadItem = false;
* app.init(options);
* // render button
* const button = document.createElement('button');
* button.id = 'render';
* button.disabled = true;
* button.appendChild(document.createTextNode('render'));
* document.body.appendChild(button);
* app.addEventListener('load', function () {
* const button = document.getElementById('render');
* button.disabled = false;
* button.onclick = function () {
* // render data #0
* app.render(0);
* };
* });
* // load dicom data
* app.loadURLs([
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'
* ]);
*/
init(opt: AppOptions): void;
/**
* Reset the application.
*/
reset(): void;
/**
* Reset the layout of the application.
*/
resetLayout(): void;
/**
* Add an event listener to this class.
*
* @param {string} type The event type.
* @param {Function} callback The function associated with the provided
* event type, will be called with the fired event.
*/
addEventListener(type: string, callback: Function): void;
/**
* Remove an event listener from this class.
*
* @param {string} type The event type.
* @param {Function} callback The function associated with the provided
* event type.
*/
removeEventListener(type: string, callback: Function): void;
/**
* Load a list of files. Can be image files or a state file.
*
* @param {File[]} files The list of files to load.
* @fires App#loadstart
* @fires App#loadprogress
* @fires App#loaditem
* @fires App#loadend
* @fires App#loaderror
* @fires App#loadabort
* @function
*/
loadFiles: (files: File[]) => void;
/**
* Load a list of URLs. Can be image files or a state file.
*
* @param {string[]} urls The list of urls to load.
* @param {object} [options] The options object, can contain:
* - requestHeaders: an array of {name, value} to use as request headers
* - withCredentials: boolean xhr.withCredentials flag to pass to the request
* - batchSize: the size of the request url batch
* @fires App#loadstart
* @fires App#loadprogress
* @fires App#loaditem
* @fires App#loadend
* @fires App#loaderror
* @fires App#loadabort
* @function
*/
loadURLs: (urls: string[], options?: object) => void;
/**
* Load from an input uri.
*
* @param {string} uri The input uri, for example: 'window.location.href'.
* @param {object} [options] Optional url request options.
* @function
*/
loadFromUri: (uri: string, options?: object) => void;
/**
* Load a list of ArrayBuffers.
*
* @param {Array} data The list of ArrayBuffers to load
* in the form of [{name: "", filename: "", data: data}].
* @fires App#loadstart
* @fires App#loadprogress
* @fires App#loaditem
* @fires App#loadend
* @fires App#loaderror
* @fires App#loadabort
* @function
*/
loadImageObject: (data: any[]) => void;
/**
* Abort the current load.
*/
abortLoad(): void;
/**
* Fit the display to the data of each layer group.
* To be called once the image is loaded.
*/
fitToContainer(): void;
/**
* Init the Window/Level display
*/
initWLDisplay(): void;
/**
* Get the data view config.
* Carefull, returns a reference, do not modify without resetting.
*
* @returns {Object<string, ViewConfig[]>} The configuration list.
*/
getDataViewConfigs(): {
[x: string]: ViewConfig[];
};
/**
* Set the data view configuration.
* Resets the stage and recreates all the views.
*
* @param {Object<string, ViewConfig[]>} configs The configuration list.
*/
setDataViewConfigs(configs: {
[x: string]: ViewConfig[];
}): void;
/**
* Set the layer groups binders.
*
* @param {Array} list The list of binder names.
*/
setLayerGroupsBinders(list: any[]): void;
/**
* Render the current data.
*
* @param {number} dataIndex The data index to render.
*/
render(dataIndex: number): void;
/**
* Zoom to the layers.
*
* @param {number} step The step to add to the current zoom.
* @param {number} cx The zoom center X coordinate.
* @param {number} cy The zoom center Y coordinate.
*/
zoom(step: number, cx: number, cy: number): void;
/**
* Apply a translation to the layers.
*
* @param {number} tx The translation along X.
* @param {number} ty The translation along Y.
*/
translate(tx: number, ty: number): void;
/**
* Set the image layer opacity.
*
* @param {number} alpha The opacity ([0:1] range).
*/
setOpacity(alpha: number): void;
/**
* Set the drawings on the current stage.
*
* @param {Array} drawings An array of drawings.
* @param {Array} drawingsDetails An array of drawings details.
*/
setDrawings(drawings: any[], drawingsDetails: any[]): void;
/**
* Get the JSON state of the app.
*
* @returns {string} The state of the app as a JSON string.
*/
getJsonState(): string;
/**
* Apply a JSON state to this app.
*
* @param {string} jsonState The state of the app as a JSON string.
*/
applyJsonState(jsonState: string): void;
/**
* Handle resize: fit the display to the window.
* To be called once the image is loaded.
* Can be connected to a window 'resize' event.
*
* @function
*/
onResize: () => void;
/**
* Key down callback. Meant to be used in tools.
*
* @param {KeyboardEvent} event The key down event.
* @fires App#keydown
* @function
*/
onKeydown: (event: KeyboardEvent) => void;
/**
* Key down event handler example.
* - CRTL-Z: undo
* - CRTL-Y: redo
* - CRTL-ARROW_LEFT: next element on fourth dim
* - CRTL-ARROW_UP: next element on third dim
* - CRTL-ARROW_RIGHT: previous element on fourth dim
* - CRTL-ARROW_DOWN: previous element on third dim
*
* @param {KeyboardEvent} event The key down event.
* @fires UndoStack#undo
* @fires UndoStack#redo
* @function
*/
defaultOnKeydown: (event: KeyboardEvent) => void;
/**
* Reset the display
*/
resetDisplay(): void;
/**
* Reset the app zoom.s
*/
resetZoom(): void;
/**
* Set the colour map.
*
* @param {string} name The colour map name.
*/
setColourMap(name: string): void;
/**
* Set the window/level preset.
*
* @param {object} preset The window/level preset.
*/
setWindowLevelPreset(preset: object): void;
/**
* Set the tool
*
* @param {string} tool The tool.
*/
setTool(tool: string): void;
/**
* Set the tool live features.
*
* @param {object} list The list of features.
*/
setToolFeatures(list: object): void;
/**
* Undo the last action
*
* @fires UndoStack#undo
*/
undo(): void;
/**
* Redo the last action
*
* @fires UndoStack#redo
*/
redo(): void;
/**
* Get the undo stack size.
*
* @returns {number} The size of the stack.
*/
getStackSize(): number;
/**
* Get the current undo stack index.
*
* @returns {number} The stack index.
*/
getCurrentStackIndex(): number;
#private;
}
/**
* Application options.
*/
export declare class AppOptions {
/**
* @param {Object<string, ViewConfig[]>} dataViewConfigs DataId
* indexed object containing the data view configurations.
*/
constructor(dataViewConfigs: {
[x: string]: ViewConfig[];
});
/**
* DataId indexed object containing the data view configurations.
*
* @type {Object<string, ViewConfig[]>}
*/
dataViewConfigs: {
[x: string]: ViewConfig[];
};
/**
* Tool name indexed object containing individual tool configurations.
*
* @type {Object<string, ToolConfig>|undefined}
*/
tools: {
[x: string]: ToolConfig;
} | undefined;
/**
* Optional array of layerGroup binder names.
*
* @type {string[]|undefined}
*/
binders: string[] | undefined;
/**
* Optional boolean flag to trigger the first data render
* after the first loaded data or not. Defaults to true;
*
* @type {boolean|undefined}
*/
viewOnFirstLoadItem: boolean | undefined;
/**
* Optional default chraracter set string used for DICOM parsing if
* not passed in DICOM file.
* Valid values: https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings
*
* @type {string|undefined}
*/
defaultCharacterSet: string | undefined;
}
/**
* Build a multipart message.
* See: https://en.wikipedia.org/wiki/MIME#Multipart_messages
* See: https://hg.orthanc-server.com/orthanc-dicomweb/file/tip/Resources/Samples/JavaScript/stow-rs.js
*
* @param {Array} parts The message parts as an array of object containing
* content headers and messages as the data property (as returned by parse).
* @param {string} boundary The message boundary.
* @returns {Uint8Array} The full multipart message.
*/
export declare function buildMultipart(parts: any[], boundary: string): Uint8Array;
/**
* Colour map: red, green and blue components
* to associate with intensity values.
*/
export declare class ColourMap {
/**
* @param {number[]} red Red component.
* @param {number[]} green Green component.
* @param {number[]} blue Blue component.
*/
constructor(red: number[], green: number[], blue: number[]);
/**
* Red component: 256 values in the [0, 255] range.
*
* @type {number[]}
*/
red: number[];
/**
* Green component: 256 values in the [0, 255] range.
*
* @type {number[]}
*/
green: number[];
/**
* Blue component: 256 values in the [0, 255] range.
*
* @type {number[]}
*/
blue: number[];
}
/**
* Create an Image from DICOM elements.
*
* @param {object} elements The DICOM elements.
* @returns {Image} The Image object.
*/
export declare function createImage(elements: object): Image_2;
/**
* Create a mask Image from DICOM elements.
*
* @param {object} elements The DICOM elements.
* @returns {Image} The mask Image object.
*/
export declare function createMaskImage(elements: object): Image_2;
/**
* Create a View from DICOM elements and image.
*
* @param {object} elements The DICOM elements.
* @param {Image} image The associated image.
* @returns {View} The View object.
*/
export declare function createView(elements: object, image: Image_2): View;
export declare namespace customUI {
/**
* Open a dialogue to edit roi data. Defaults to window.prompt.
*
* @param {object} data The roi data.
* @param {Function} callback The callback to launch on dialogue exit.
*/
export function openRoiDialog(data: any, callback: Function): void;
}
/**
* DICOM data element.
*/
export declare class DataElement {
/**
* @param {string} vr The element VR (Value Representation).
*/
constructor(vr: string);
/**
* The element Value Representation.
*
* @type {string}
*/
vr: string;
/**
* The element value.
*
* @type {Array}
*/
value: any[];
/**
* The element dicom tag.
*
* @type {Tag}
*/
tag: Tag;
/**
* The element Value Length.
*
* @type {number}
*/
vl: number;
/**
* Flag to know if defined or undefined sequence length.
*
* @type {boolean}
*/
undefinedLength: boolean;
/**
* The element start offset.
*
* @type {number}
*/
startOffset: number;
/**
* The element end offset.
*
* @type {number}
*/
endOffset: number;
/**
* The sequence items.
*
* @type {Array}
*/
items: any[];
}
/**
* Decoder scripts to be passed to web workers for image decoding.
*/
export declare const decoderScripts: {
jpeg2000: string;
'jpeg-lossless': string;
'jpeg-baseline': string;
rle: string;
};
/**
* List of default window level presets.
*
* @type {Object.<string, Object.<string, {center: number, width: number}>>}
*/
export declare const defaultPresets: {
[x: string]: {
[x: string]: {
center: number;
width: number;
};
};
};
/**
* DicomParser class.
*
* @example
* // XMLHttpRequest onload callback
* const onload = function (event) {
* // setup the dicom parser
* const dicomParser = new dwv.DicomParser();
* // parse the buffer
* dicomParser.parse(event.target.response);
* // get the dicom tags
* const tags = dicomParser.getDicomElements();
* // display the modality
* const div = document.getElementById('dwv');
* div.appendChild(document.createTextNode(
* 'Modality: ' + tags['00080060'].value[0]
* ));
* };
* // DICOM file request
* const request = new XMLHttpRequest();
* const url = 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm';
* request.open('GET', url);
* request.responseType = 'arraybuffer';
* request.onload = onload;
* request.send();
*/
export declare class DicomParser {
/**
* Get the default character set.
*
* @returns {string} The default character set.
*/
getDefaultCharacterSet(): string;
/**
* Set the default character set.
*
* @param {string} characterSet The input character set.
*/
setDefaultCharacterSet(characterSet: string): void;
/**
* Set the text decoder character set.
*
* @param {string} characterSet The input character set.
*/
setDecoderCharacterSet(characterSet: string): void;
/**
* Get the DICOM data elements.
*
* @returns {Object<string, DataElement>} The data elements.
*/
getDicomElements(): {
[x: string]: DataElement;
};
/**
* Parse the complete DICOM file (given as input to the class).
* Fills in the member object 'dataElements'.
*
* @param {ArrayBuffer} buffer The input array buffer.
*/
parse(buffer: ArrayBuffer): void;
#private;
}
/**
* DICOM writer.
*
* @example
* // add link to html
* const link = document.createElement("a");
* link.appendChild(document.createTextNode("download"));
* const div = document.getElementById("dwv");
* div.appendChild(link);
* // XMLHttpRequest onload callback
* const onload = function (event) {
* const parser = new dwv.DicomParser();
* parser.parse(event.target.response);
* // create writer
* const writer = new dwv.DicomWriter();
* // get buffer using default rules
* const dicomBuffer = writer.getBuffer(parser.getDicomElements());
* // create blob
* const blob = new Blob([dicomBuffer], {type: 'application/dicom'});
* // add blob to download link
* link.href = URL.createObjectURL(blob);
* link.download = "anonym.dcm";
* };
* // DICOM file request
* const request = new XMLHttpRequest();
* const url = 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm';
* request.open('GET', url);
* request.responseType = 'arraybuffer';
* request.onload = onload;
* request.send();
*/
export declare class DicomWriter {
/**
* Set the use UN VR for private sequence flag.
*
* @param {boolean} flag True to use UN VR.
*/
setUseUnVrForPrivateSq(flag: boolean): void;
/**
* Set the writing rules.
* List of writer rules indexed by either `default`, tagName or groupName.
* Each DICOM element will be checked to see if a rule is applicable.
* First checked by tagName and then by groupName,
* if nothing is found the default rule is applied.
*
* @param {Object<string, WriterRule>} rules The input rules.
*/
setRules(rules: {
[x: string]: WriterRule;
}): void;
/**
* Use a TextEncoder instead of the default text decoder.
*/
useSpecialTextEncoder(): void;
/**
* Use default anonymisation rules.
*/
useDefaultAnonymisationRules(): void;
/**
* Get the element to write according to the class rules.
* Priority order: tagName, groupName, default.
*
* @param {DataElement} element The element to check
* @returns {DataElement|null} The element to write, can be null.
*/
getElementToWrite(element: DataElement): DataElement | null;
/**
* Get the ArrayBuffer corresponding to input DICOM elements.
*
* @param {Object<string, DataElement>} dataElements The elements to write.
* @returns {ArrayBuffer} The elements as a buffer.
*/
getBuffer(dataElements: {
[x: string]: DataElement;
}): ArrayBuffer;
#private;
}
/**
* Draw layer.
*/
export declare class DrawLayer {
/**
* @param {HTMLDivElement} containerDiv The layer div, its id will be used
* as this layer id.
*/
constructor(containerDiv: HTMLDivElement);
/**
* Get the associated data index.
*
* @returns {number} The index.
*/
getDataIndex(): number;
/**
* Get the Konva stage.
*
* @returns {object} The stage.
*/
getKonvaStage(): object;
/**
* Get the Konva layer.
*
* @returns {object} The layer.
*/
getKonvaLayer(): object;
/**
* Get the draw controller.
*
* @returns {object} The controller.
*/
getDrawController(): object;
/**
* Set the plane helper.
*
* @param {object} helper The helper.
*/
setPlaneHelper(helper: object): void;
/**
* Get the id of the layer.
*
* @returns {string} The string id.
*/
getId(): string;
/**
* Get the layer base size (without scale).
*
* @returns {object} The size as {x,y}.
*/
getBaseSize(): object;
/**
* Get the layer opacity.
*
* @returns {number} The opacity ([0:1] range).
*/
getOpacity(): number;
/**
* Set the layer opacity.
*
* @param {number} alpha The opacity ([0:1] range).
*/
setOpacity(alpha: number): void;
/**
* Add a flip offset along the layer X axis.
*/
addFlipOffsetX(): void;
/**
* Add a flip offset along the layer Y axis.
*/
addFlipOffsetY(): void;
/**
* Set the layer scale.
*
* @param {object} newScale The scale as {x,y}.
* @param {Point3D} [center] The scale center.
*/
setScale(newScale: object, center?: Point3D): void;
/**
* Set the layer offset.
*
* @param {object} newOffset The offset as {x,y}.
*/
setOffset(newOffset: object): void;
/**
* Set the base layer offset. Updates the layer offset.
*
* @param {Vector3D} scrollOffset The scroll offset vector.
* @param {Vector3D} planeOffset The plane offset vector.
* @returns {boolean} True if the offset was updated.
*/
setBaseOffset(scrollOffset: Vector3D, planeOffset: Vector3D): boolean;
/**
* Display the layer.
*
* @param {boolean} flag Whether to display the layer or not.
*/
display(flag: boolean): void;
/**
* Check if the layer is visible.
*
* @returns {boolean} True if the layer is visible.
*/
isVisible(): boolean;
/**
* Draw the content (imageData) of the layer.
* The imageData variable needs to be set
*/
draw(): void;
/**
* Initialise the layer: set the canvas and context
*
* @param {object} size The image size as {x,y}.
* @param {object} spacing The image spacing as {x,y}.
* @param {number} index The associated data index.
*/
initialise(size: object, spacing: object, index: number): void;
/**
* Fit the layer to its parent container.
*
* @param {number} fitScale1D The 1D fit scale.
* @param {object} fitSize The fit size as {x,y}.
* @param {object} fitOffset The fit offset as {x,y}.
*/
fitToContainer(fitScale1D: number, fitSize: object, fitOffset: object): void;
/**
* Check the visibility of a given group.
*
* @param {string} id The id of the group.
* @returns {boolean} True if the group is visible.
*/
isGroupVisible(id: string): boolean;
/**
* Toggle the visibility of a given group.
*
* @param {string} id The id of the group.
* @returns {boolean} False if the group cannot be found.
*/
toggleGroupVisibility(id: string): boolean;
/**
* Delete a Draw from the stage.
*
* @param {string} id The id of the group to delete.
* @param {object} exeCallback The callback to call once the
* DeleteCommand has been executed.
*/
deleteDraw(id: string, exeCallback: object): void;
/**
* Delete all Draws from the stage.
*
* @param {object} exeCallback The callback to call once the
* DeleteCommand has been executed.
*/
deleteDraws(exeCallback: object): void;
/**
* Enable and listen to container interaction events.
*/
bindInteraction(): void;
/**
* Disable and stop listening to container interaction events.
*/
unbindInteraction(): void;
/**
* Set the current position.
*
* @param {Point} position The new position.
* @param {Index} index The new index.
* @returns {boolean} True if the position was updated.
*/
setCurrentPosition(position: Point, index: Index): boolean;
/**
* Add an event listener to this class.
*
* @param {string} type The event type.
* @param {Function} callback The function associated with the provided
* event type, will be called with the fired event.
*/
addEventListener(type: string, callback: Function): void;
/**
* Remove an event listener from this class.
*
* @param {string} type The event type.
* @param {Function} callback The function associated with the provided
* event type.
*/
removeEventListener(type: string, callback: Function): void;
#private;
}
/**
* 2D/3D Geometry class.
*/
export declare class Geometry {
/**
* @param {Point3D} origin The object origin (a 3D point).
* @param {Size} size The object size.
* @param {Spacing} spacing The object spacing.
* @param {Matrix33} [orientation] The object orientation (3*3 matrix,
* default to 3*3 identity).
* @param {number} [time] Optional time index.
*/
constructor(origin: Point3D, size: Size, spacing: Spacing, orientation?: Matrix33, time?: number);
/**
* Get the time value that was passed at construction.
*
* @returns {number} The time value.
*/
getInitialTime(): number;
/**
* Get the total number of slices.
* Can be different from what is stored in the size object
* during a volume with time points creation process.
*
* @returns {number} The total count.
*/
getCurrentTotalNumberOfSlices(): number;
/**
* Check if a time point has associated slices.
*
* @param {number} time The time point to check.
* @returns {boolean} True if slices are present.
*/
hasSlicesAtTime(time: number): boolean;
/**
* Get the number of slices stored for time points preceding
* the input one.
*
* @param {number} time The time point to check.
* @returns {number|undefined} The count.
*/
getCurrentNumberOfSlicesBeforeTime(time: number): number | undefined;
/**
* Get the object origin.
* This should be the lowest origin to ease calculations (?).
*
* @returns {Point3D} The object origin.
*/
getOrigin(): Point3D;
/**
* Get the object origins.
*
* @returns {Array} The object origins.
*/
getOrigins(): any[];
/**
* Check if a point is in the origin list.
*
* @param {Point3D} point3D The point to check.
* @param {number} tol The comparison tolerance
* default to Number.EPSILON.
* @returns {boolean} True if in list.
*/
includesOrigin(point3D: Point3D, tol: number): boolean;
/**
* Get the object size.
* Warning: the size comes as stored in DICOM, meaning that it could
* be oriented.
*
* @param {Matrix33} [viewOrientation] The view orientation (optional)
* @returns {Size} The object size.
*/
getSize(viewOrientation?: Matrix33): Size;
/**
* Get the object spacing.
* Warning: the spacing comes as stored in DICOM, meaning that it could
* be oriented.
*
* @param {Matrix33} [viewOrientation] The view orientation (optional)
* @returns {Spacing} The object spacing.
*/
getSpacing(viewOrientation?: Matrix33): Spacing;
/**
* Get the image spacing in real world.
*
* @returns {Spacing} The object spacing.
*/
getRealSpacing(): Spacing;
/**
* Get the object orientation.
*
* @returns {Matrix33} The object orientation.
*/
getOrientation(): Matrix33;
/**
* Get the slice position of a point in the current slice layout.
* Slice indices increase with decreasing origins (high index -> low origin),
* this simplified the handling of reconstruction since it means
* the displayed data is in the same 'direction' as the extracted data.
* As seen in the getOrigin method, the main origin is the lowest one.
* This implies that the index to world and reverse method do some flipping
* magic...
*
* @param {Point3D} point The point to evaluate.
* @param {number} time Optional time index.
* @returns {number} The slice index.
*/
getSliceIndex(point: Point3D, time: number): number;
/**
* Append an origin to the geometry.
*
* @param {Point3D} origin The origin to append.
* @param {number} index The index at which to append.
* @param {number} [time] Optional time index.
*/
appendOrigin(origin: Point3D, index: number, time?: number): void;
/**
* Append a frame to the geometry.
*
* @param {Point3D} origin The origin to append.
* @param {number} time Optional time index.
*/
appendFrame(origin: Point3D, time: number): void;
/**
* Get a string representation of the geometry.
*
* @returns {string} The geometry as a string.
*/
toString(): string;
/**
* Check for equality.
*
* @param {Geometry} rhs The object to compare to.
* @returns {boolean} True if both objects are equal.
*/
equals(rhs: Geometry): boolean;
/**
* Check that a point is within bounds.
*
* @param {Point} point The point to check.
* @returns {boolean} True if the given coordinates are within bounds.
*/
isInBounds(point: Point): boolean;
/**
* Check that a index is within bounds.
*
* @param {Index} index The index to check.
* @param {Array} [dirs] Optional list of directions to check.
* @returns {boolean} True if the given coordinates are within bounds.
*/
isIndexInBounds(index: Index, dirs?: any[]): boolean;
/**
* Convert an index into world coordinates.
*
* @param {Index} index The index to convert.
* @returns {Point} The corresponding point.
*/
indexToWorld(index: Index): Point;
/**
* Convert a 3D point into world coordinates.
*
* @param {Point3D} point The 3D point to convert.
* @returns {Point3D} The corresponding world 3D point.
*/
pointToWorld(point: Point3D): Point3D;
/**
* Convert world coordinates into an index.
*
* @param {Point} point The point to convert.
* @returns {Index} The corresponding index.
*/
worldToIndex(point: Point): Index;
/**
* Convert world coordinates into an point.
*
* @param {Point} point The world point to convert.
* @returns {Point3D} The corresponding point.
*/
worldToPoint(point: Point): Point3D;
#private;
}
/**
* List of DICOM data elements indexed via a 8 character string formed from
* the group and element numbers.
*
* @typedef {Object<string, DataElement>} DataElements
*/
/**
* Get the version of the library.
*
* @returns {string} The version of the library.
*/
export declare function getDwvVersion(): string;
/**
* Get the DICOM elements from a 'simple' DICOM json tags object.
* The json is a simplified version of the oficial DICOM json with
* tag names instead of keys and direct values (no value property) for
* simple tags. See synthetic test data (in tests/dicom) for examples.
*
* @param {Object<string, any>} jsonTags The DICOM
* json tags object.
* @returns {Object<string, DataElement>} The DICOM elements.
*/
export declare function getElementsFromJSONTags(jsonTags: {
[x: string]: any;
}): {
[x: string]: DataElement;
};
/**
* Get the name of an image orientation patient.
*
* @param {Array} orientation The image orientation patient.
* @returns {string} The orientation name: axial, coronal or sagittal.
*/
export declare function getOrientationName(orientation: any[]): string;
/**
* Get the PixelData Tag.
*
* @returns {Tag} The tag.
*/
export declare function getPixelDataTag(): Tag;
/**
* Get patient orientation label in the reverse direction.
*
* @param {string} ori Patient Orientation value.
* @returns {string} Reverse Orientation Label.
*/
export declare function getReverseOrientation(ori: string): string;
/**
* Split a group-element key used to store DICOM elements.
*
* @param {string} key The key in form "00280102" as generated by tag::getKey.
* @returns {Tag} The DICOM tag.
*/
export declare function getTagFromKey(key: string): Tag;
/**
* Get the appropriate TypedArray in function of arguments.
*
* @param {number} bitsAllocated The number of bites used to store
* the data: [8, 16, 32].
* @param {number} pixelRepresentation The pixel representation,
* 0:unsigned;1:signed.
* @param {number} size The size of the new array.
* @returns {Uint8Array|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array}
* The good typed array.
*/
export declare function getTypedArray(bitsAllocated: number, pixelRepresentation: number, size: number): Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array;
/**
* Get a UID for a DICOM tag.
* Note: Use https://github.com/uuidjs/uuid?
*
* @see http://dicom.nema.org/dicom/2013/output/chtml/part05/chapter_9.html
* @see http://dicomiseasy.blogspot.com/2011/12/chapter-4-dicom-objects-in-chapter-3.html
* @see https://stackoverflow.com/questions/46304306/how-to-generate-unique-dicom-uid
* @param {string} tagName The input tag.
* @returns {string} The corresponding UID.
*/
export declare function getUID(tagName: string): string;
/**
* Check that an input buffer includes the DICOM prefix 'DICM'
* after the 128 bytes preamble.
* Ref: [DICOM File Meta]{@link https://dicom.nema.org/dicom/2013/output/chtml/part10/chapter_7.html#sect_7.1}
*
* @param {ArrayBuffer} buffer The buffer to check.
* @returns {boolean} True if the buffer includes the prefix.
*/
export declare function hasDicomPrefix(buffer: ArrayBuffer): boolean;
export declare namespace i18n {
/**
* Get the translated text.
*
* @param {string} key The key to the text entry.
* @returns {string|undefined} The translated text.
*/
export function t(key: string): string;
}
/**
* Image class.
* Usable once created, optional are:
* - rescale slope and intercept (default 1:0),
* - photometric interpretation (default MONOCHROME2),
* - planar configuration (default RGBRGB...).
*
* @example
* // XMLHttpRequest onload callback
* const onload = function (event) {
* // parse the dicom buffer
* const dicomParser = new dwv.DicomParser();
* dicomParser.parse(event.target.response);
* // create the image object
* const image = dwv.createImage(dicomParser.getDicomElements());
* // result div
* const div = document.getElementById('dwv');
* // display the image size
* const size = image.getGeometry().getSize();
* div.appendChild(document.createTextNode(
* 'Size: ' + size.toString() +
* ' (should be 256,256,1)'));
* // break line
* div.appendChild(document.createElement('br'));
* // display a pixel value
* div.appendChild(document.createTextNode(
* 'Pixel @ [128,40,0]: ' +
* image.getRescaledValue(128,40,0) +
* ' (should be 101)'));
* };
* // DICOM file request
* const request = new XMLHttpRequest();
* const url = 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm';
* request.open('GET', url);
* request.responseType = 'arraybuffer';
* request.onload = onload;
* request.send();
*/
declare class Image_2 {
/**
* @param {Geometry} geometry The geometry of the image.
* @param {TypedArray} buffer The image data as a one dimensional buffer.
* @param {Array} [imageUids] An array of Uids indexed to slice number.
*/
constructor(geometry: Geometry, buffer: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, imageUids?: any[]);
/**
* Get the image UID at a given index.
*
* @param {Index} [index] The index at which to get the id.
* @returns {string} The UID.
*/
getImageUid(index?: Index): string;
/**
* Get the geometry of the image.
*
* @returns {Geometry} The geometry.
*/
getGeometry(): Geometry;
/**
* Get the data buffer of the image.
*
* @todo dangerous...
* @returns {TypedArray} The data buffer of the image.
*/
getBuffer(): Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array;
/**
* Can the image values be quantified?
*
* @returns {boolean} True if only one component.
*/
canQuantify(): boolean;
/**
* Can window and level be applied to the data?
*
* @returns {boolean} True if the data is monochrome.
*/
canWindowLevel(): boolean;
/**
* Can the data be scrolled?
*
* @param {Matrix33} viewOrientation The view orientation.
* @returns {boolean} True if the data has a third dimension greater than one
* after applying the view orientation.
*/
canScroll(viewOrientation: Matrix33): boolean;
/**
* Get the secondary offset: an offset that takes into account
* the slice and above dimension numbers.
*
* @param {Index} index The index.
* @returns {number} The offset.
*/
getSecondaryOffset(index: Index): number;
/**
* Get the rescale slope and intercept.
*
* @param {Index} [index] The index (only needed for non constant rsi).
* @returns {object} The rescale slope and intercept.
*/
getRescaleSlopeAndIntercept(index?: Index): object;
/**
* Set the rescale slope and intercept.
*
* @param {object} inRsi The input rescale slope and intercept.
* @param {number} [offset] The rsi offset (only needed for non constant rsi).
*/
setRescaleSlopeAndIntercept(inRsi: object, offset?: number): void;
/**
* Are all the RSIs identity (1,0).
*
* @returns {boolean} True if they are.
*/
isIdentityRSI(): boolean;
/**
* Are all the RSIs equal.
*
* @returns {boolean} True if they are.
*/
isConstantRSI(): boolean;
/**
* Get the photometricInterpretation of the image.
*
* @returns {string} The photometricInterpretation of the image.
*/
getPhotometricInterpretation(): string;
/**
* Set the photometricInterpretation of the image.
*
* @param {string} interp The photometricInterpretation of the image.
*/
setPhotometricInterpretation(interp: string): void;
/**
* Get the planarConfiguration of the image.
*
* @returns {number} The planarConfiguration of the image.
*/
getPlanarConfiguration(): number;
/**
* Set the planarConfiguration of the image.
*
* @param {number} config The planarConfiguration of the image.
*/
setPlanarConfiguration(config: number): void;
/**
* Get the numberOfComponents of the image.
*
* @returns {number} The numberOfComponents of the image.
*/
getNumberOfComponents(): number;
/**
* Get the meta information of the image.
*
* @returns {object} The meta information of the image.
*/
getMeta(): object;
/**
* Set the meta information of the image.
*
* @param {object} rhs The meta information of the image.
*/
setMeta(rhs: object): void;
/**
* Get value at offset. Warning: No size check...
*
* @param {number} offset The desired offset.
* @returns {number} The value at offset.
*/
getValueAtOffset(offset: number): number;
/**
* Get the offsets where the buffer equals the input value.
* Loops through the whole volume, can get long for big data...
*
* @param {number|object} value The value to check.
* @returns {Array} The list of offsets.
*/
getOffsets(value: number | object): any[];
/**
* Check if the input values are in the buffer.
* Could loop through the whole volume, can get long for big data...
*
* @param {Array} values The values to check.
* @returns {Array} A list of booleans for each input value,
* set to true if the value is present in the buffer.
*/
hasValues(values: any[]): any[];
/**
* Clone the image.
*
* @returns {Image} A clone of this image.
*/
clone(): Image_2;
/**
* Append a slice to the image.
*
* @param {Image} rhs The slice to append.
*/
appendSlice(rhs: Image_2): void;
/**
* Append a frame buffer to the image.
*
* @param {object} frameBuffer The frame buffer to append.
* @param {number} frameIndex The frame index.
*/
appendFrameBuffer(frameBuffer: object, frameIndex: number): void;
/**
* Append a frame to the image.
*
* @param {number} time The frame time value.
* @param {Point3D} origin The origin of the frame.
*/
appendFrame(time: number, origin: Point3D): void;
/**
* Get the data range.
*
* @returns {object} The data range.
*/
getDataRange(): object;
/**
* Get the rescaled data range.
*
* @returns {object} The rescaled data range.
*/
getRescaledDataRange(): object;
/**
* Get the histogram.
*
* @returns {Array} The histogram.
*/
getHistogram(): any[];
/**
* Add an event listener to this class.
*
* @param {string} type The event type.
* @param {Function} callback The function associated with the provided
* event type, will be called with the fired event.
*/
addEventListener(type: string, callback: Function): void;
/**
* Remove an event listener from this class.
*
* @param {string} type The event type.
* @param {Function} callback The function associated with the provided
* event type.
*/
removeEventListener(type: string, callback: Function): void;
/**
* Set the inner buffer values at given offsets.
*
* @param {Array} offsets List of offsets where to set the data.
* @param {object} value The value to set at the given offsets.
* @fires Image#imagechange
*/
setAtOffsets(offsets: any[], value: object): void;
/**
* Set the inner buffer values at given offsets.
*
* @param {Array} offsetsLists List of offset lists where to set the data.
* @param {object} value The value to set at the given offsets.
* @returns {Array} A list of objects representing the original values before
* replacing them.
* @fires Image#imagechange
*/
setAtOffsetsAndGetOriginals(offsetsLists: any[], value: object): any[];
/**
* Set the inner buffer values at given offsets.
*
* @param {Array} offsetsLists List of offset lists where to set the data.
* @param {object|Array} value The value to set at the given offsets.
* @fires Image#imagechange
*/
setAtOffsetsWithIterator(offsetsLists: any[], value: object | any[]): void;
/**
* Get the value of the image at a specific coordinate.
*
* @param {number} i The X index.
* @param {number} j The Y index.
* @param {number} k The Z index.
* @param {number} f The frame number.
* @returns {number} The value at the desired position.
* Warning: No size check...
*/
getValue(i: number, j: number, k: number, f: number): number;
/**
* Get the value of the image at a specific index.
*
* @param {Index} index The index.
* @returns {number} The value at the desired position.
* Warning: No size check...
*/
getValueAtIndex(index: Index): number;
/**
* Get the rescaled value of the image at a specific position.
*
* @param {number} i The X index.
* @param {number} j The Y index.
* @param {number} k The Z index.
* @param {number} f The frame number.
* @returns {number} The rescaled value at the desired position.
* Warning: No size check...
*/
getRescaledValue(i: number, j: number, k: number, f: number): number;
/**
* Get the rescaled value of the image at a specific index.
*
* @param {Index} index The index.
* @returns {number} The rescaled value at the desired position.
* Warning: No size check...
*/
getRescaledValueAtIndex(index: Index): number;
/**
* Get the rescaled value of the image at a specific offset.
*
* @param {number} offset The desired offset.
* @returns {number} The rescaled value at the desired offset.
* Warning: No size check...
*/
getRescaledValueAtOffset(offset: number): number;
/**
* Calculate the data range of the image.
* WARNING: for speed reasons, only calculated on the first frame...
*
* @returns {object} The range {min, max}.
*/
calculateDataRange(): object;
/**
* Calculate the rescaled data range of the image.
* WARNING: for speed reasons, only calculated on the first frame...
*
* @returns {object} The range {min, max}.
*/
calculateRescaledDataRange(): object;
/**
* Calculate the histogram of the image.
*
* @returns {object} The histogram, data range and rescaled data range.
*/
calculateHistogram(): object;
/**
* Convolute the image with a given 2D kernel.
*
* Note: Uses raw buffer values.
*
* @param {Array} weights The weights of the 2D kernel as a 3x3 matrix.
* @returns {Image} The convoluted image.
*/
convolute2D(weights: any[]): Image_2;
/**
* Convolute an image buffer with a given 2D kernel.
*
* Note: Uses raw buffer values.
*
* @param {Array} weights The weights of the 2D kernel as a 3x3 matrix.
* @param {TypedArray} buffer The buffer to convolute.
* @param {number} startOffset The index to start at.
*/
convoluteBuffer(weights: any[], buffer: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, startOffset: number): void;
/**
* Transform an image using a specific operator.
* WARNING: no size check!
*
* @param {Function} operator The operator to use when transforming.
* @returns {Image} The transformed image.
* Note: Uses the raw buffer values.
*/
transform(operator: Function): Image_2;
/**
* Compose this image with another one and using a specific operator.
* WARNING: no size check!
*
* @param {Image} rhs The image to compose with.
* @param {Function} operator The operator to use when composing.
* @returns {Image} The composed image.
* Note: Uses the raw buffer values.
*/
compose(rhs: Image_2, operator: Function): Image_2;
#private;
}
export { Image_2 as Image }
/**
* Immutable index.
* Warning: the input array is NOT cloned, modifying it will
* modify the index values.
*/
export declare class Index {
/**
* @param {number[]} values The index values.
*/
constructor(values: number[]);
/**
* Get the index value at the given array index.
*
* @param {number} i The index to get.
* @returns {number|undefined} The value or undefined if not in range.
*/
get(i: number): number | undefined;
/**
* Get the length of the index.
*
* @returns {number} The length.
*/
length(): number;