App
Source: application.js:222
Main application class.
Example
import {App, AppOptions, ViewConfig} from '//esm.sh/dwv';
// create the dwv app
const app = new App();
// initialise
const viewConfig0 = new ViewConfig('layerGroup0');
const viewConfigs = {'*': [viewConfig0]};
const options = new AppOptions(viewConfigs);
app.init(options);
// load dicom data
app.loadURLs([
'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'
]);Constructor
new App(): AppInstance Methods
getDataController(): DataController
Get the data controller.
Returns
DataController— The data controller.
getData(dataId: string): DicomData | undefined
Get a DicomData.
Since v0.37, please use via app.getDataController.
Parameters
dataId(string) — The data id.
Returns
DicomData| undefined— The data.
getImage(dataId: string): Image | undefined
Get the image.
Since v0.34, please use the getData method.
Parameters
dataId(string) — The data id.
Returns
Image| undefined— The associated image.
setImage(dataId: string, img: Image)
Set the image at the given id.
Since v0.37, please use via app.getDataController.
Parameters
dataId(string) — The data id.img(Image) — The associated image.
getNextDataId(): string
Get the next data id.
Since v0.37, please use via app.getDataController.
Returns
string— The data id.
addData(dataId: string, data: DicomData): boolean
Add a new DicomData.
Since v0.37, please use via app.getDataController.
Parameters
dataId(string) — The data id.data(DicomData) — The new data.
Returns
boolean— False if the data cannot be added.
getMetaData(
dataId: string,
): Record.<string, DataElement> | undefined
Get the meta data.
Since v0.37, please use via app.getDataController.
Parameters
dataId(string) — The data id.
Returns
Record.<string,DataElement> | undefined— The list of meta data.
getDataIds(): Array.<string>
Get the list of ids in the data storage.
Since v0.37, please use via app.getDataController.
Returns
Array.<string>— The list of data ids.
getDataIdsFromSopUids(uids: Array.<string>): Array.<string>
Get the list of dataIds that contain the input UIDs.
Since v0.37, please use via app.getDataController.
Parameters
uids(Array.<string>) — A list of UIDs.
Returns
Array.<string>— The list of dataIds that contain the UIDs.
getDataIdFromSeriesUid(uid: string): string
Get the first data id with the given SeriesInstanceUID.
Since v0.37, please use via app.getDataController.
Parameters
uid(string) — The SeriesInstanceUID.
Returns
string— The data id.
canScroll(): boolean
Can the data (of the active view of the active layer) be scrolled?
Since v0.33, please use the ViewController equivalent directly instead.
Returns
boolean— True if the data has a third dimension greater than one.
canWindowLevel(): boolean
Can window and level be applied to the data (of the active view of the active layer)?
Since v0.33, please use the ViewController equivalent directly instead.
Returns
boolean— True if the data is monochrome.
getAddedScale(): Scalar3D
Get the active layer group scale on top of the base scale.
Since v0.37, please access from the active layer group.
Returns
Scalar3D— The scale as {x,y,z}.
getBaseScale(): Scalar3D
Get the base scale of the active layer group.
Since v0.37, please access from the active layer group.
Returns
Scalar3D— The scale as {x,y,z}.
getOffset(): Scalar3D
Get the layer offset of the active layer group.
Since v0.37, please access from the active layer group.
Returns
Scalar3D— The offset as {x,y,z}.
getToolboxController(): ToolboxController
Get the toolbox controller.
Returns
ToolboxController— The controller.
getStageController(): StageController
Get the stage controller.
Returns
StageController— The stage controller.
getUndoController(): UndoController
Get the undo controller.
Returns
UndoController— The undo controller.
getActiveLayerGroup(): LayerGroup | undefined
Get the active layer group. The layer is available after the first loaded item.
Since v0.37, use `app.getStageController().getActiveLayerGroup()` instead.
Returns
LayerGroup| undefined— The layer group.
setActiveLayerGroup(index: number)
Set the active layer group.
Since v0.37, use `app.getStageController().setActiveLayerGroup()` instead.
Parameters
index(number) — The layer group index.
getViewLayersByDataId(dataId: string): Array.<ViewLayer>
Get the view layers associated to a data id. The layer are available after the first loaded item.
Since v0.37, use `app.getStageController().getViewLayersByDataId()` instead.
Parameters
dataId(string) — The data id.
Returns
Array.<ViewLayer>— The layers.
getViewLayers(callbackFn?: function): Array.<ViewLayer>
Get a list of view layers according to an input callback function.
Since v0.37, use `app.getStageController().getViewLayers()` instead.
Parameters
callbackFn(function, optional) — A function that takes a ViewLayer as input and returns a boolean. If undefined, returns all view layers.
Returns
Array.<ViewLayer>— The layers that satisfy the callbackFn.
getDrawLayersByDataId(dataId: string): Array.<DrawLayer>
Get the draw layers associated to a data id. The layer are available after the first loaded item.
Since v0.37, use `app.getStageController().getDrawLayersByDataId()` instead.
Parameters
dataId(string) — The data id.
Returns
Array.<DrawLayer>— The layers.
getDrawLayers(callbackFn?: function): Array.<DrawLayer>
Get a list of draw layers according to an input callback function.
Since v0.37, use `app.getStageController().getDrawLayers()` instead.
Parameters
callbackFn(function, optional) — A function that takes a DrawLayer as input and returns a boolean. If undefined, returns all draw layers.
Returns
Array.<DrawLayer>— The layers that satisfy the callbackFn.
getLayerGroupByDivId(divId: string): LayerGroup | undefined
Get a layer group by div id. The layer is available after the first loaded item.
Since v0.37, use `app.getStageController().getLayerGroupByDivId()` instead.
Parameters
divId(string) — The div id.
Returns
LayerGroup| undefined— The layer group.
getNumberOfLayerGroups(): number
Get the number of layer groups.
Since v0.37, use `app.getStageController().getNumberOfLayerGroups()` instead.
Returns
number— The number of groups.
getStyle(): object
Get the app style.
Returns
object— The app style.
addToUndoStack(cmd: Command)
Add a command to the undo stack.
Since v0.37, please use via app.getUndoController.
Parameters
cmd(Command) — The command to add.
Fires
UndoStack#event:undoadd
removeFromUndoStack(name: string): boolean
Remove a command from the undo stack.
Since v0.37, please use via app.getUndoController.
Parameters
name(string) — The name of the command to remove.
Returns
boolean— True if the command was found and removed.
Fires
UndoStack#event:undoremove
init(opt: AppOptions)
Initialise the application.
Parameters
opt(AppOptions) — The application options.
Example
import {App, AppOptions, ViewConfig} from '//esm.sh/dwv';
// create the dwv app
const app = new App();
// initialise
const viewConfig0 = new ViewConfig('layerGroup0');
const viewConfigs = {'*': [viewConfig0]};
const options = new 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.getStageController().render(0);
};
});
// load dicom data
app.loadURLs([
'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'
]);reset()
Reset the application.
resetLayout()
Reset the layout of the application.
Since v0.35, prefer resetZoomPan.
resetZoomPan()
Reset the zoom and pan of the stage.
Since v0.37, use `app.getStageController().resetZoomPan()` instead.
resetViews()
Reset the position and window level of the stage.
Since v0.37, use `app.getStageController().resetViews()` instead.
loadFiles(files: Array.<File>): string
Load a list of image files.
Parameters
files(Array.<File>) — The list of files to load.
Returns
string— The data ID, '-1' if problem.
Fires
App#event:loadstartApp#event:loadprogressApp#event:loaditemApp#event:loadendApp#event:errorApp#event:abort
loadURLs(urls: Array.<string>, options?: object): string
Load a list of image URLs.
Parameters
urls(Array.<string>) — The list of urls to load.options(object, optional) — The options object, can contain:
Returns
string— The data ID, '-1' if problem.
Fires
App#event:loadstartApp#event:loadprogressApp#event:loaditemApp#event:loadendApp#event:errorApp#event:abort
loadFromUri(uri: string, options?: object)
Load from an input uri.
Since v0.36, please extract the file list and pass it to loadURLs. State from uri is no longer supported.
Parameters
uri(string) — The input uri, for example: 'window.location.href'.options(object, optional) — Optional url request options.
loadImageObject(data: Array): string
Load a list of ArrayBuffers.
Parameters
data(Array) — The list of ArrayBuffers to load in the form of [{name: "", filename: "", data: data}].
Returns
string— The data ID.
Fires
App#event:loadstartApp#event:loadprogressApp#event:loaditemApp#event:loadendApp#event:errorApp#event:abort
abortAllLoads()
Abort all the current loads.
abortLoad(dataId: string)
Abort an individual data load.
Parameters
dataId(string) — The data to stop loading.
fitToContainer()
Fit the display to the data of each layer group. To be called once the image is loaded.
Since v0.37, use `app.getStageController().fitToContainer()` instead.
initWLDisplay()
Init the Window/Level display (of the active layer of the active layer group).
Since v0.33, please set the opacity of the desired view layer directly.
setImageSmoothing(flag: boolean)
Set the imageSmoothing flag value. Default is false.
Since v0.37, use `app.getStageController().setImageSmoothing()` instead.
Parameters
flag(boolean) — True to enable smoothing.
getViewConfigs(
dataId: string,
excludeStarConfig?: boolean,
): Array.<ViewConfig>
Get the layer group configuration from a data id.
Since v0.37, use `app.getStageController().getViewConfigs()` instead.
Parameters
dataId(string) — The data id.excludeStarConfig(boolean, optional) — Exclude the star config (default to false).
Returns
Array.<ViewConfig>— The list of associated configs.
getViewConfig(
dataId: string,
groupDivId: string,
excludeStarConfig?: boolean,
): ViewConfig | undefined
Get the layer group configuration for a data id and group div id.
Since v0.37, use `app.getStageController().getViewConfig()` instead.
Parameters
dataId(string) — The data id.groupDivId(string) — The layer group div id.excludeStarConfig(boolean, optional) — Exclude the star config (default to false).
Returns
ViewConfig| undefined— The associated config.
getDataViewConfigs(): Record.<string, Array.<ViewConfig>>
Get the data view config. Careful, returns a reference; do not modify without resetting.
Since v0.37, use `app.getStageController().getDataViewConfigs()` instead.
Returns
Record.<string, Array.<ViewConfig>>— The configuration list.
setDataViewConfigs(configs: Record.<string, Array.<ViewConfig>>)
Set the data view configuration. Resets the stage and recreates all the views.
Since v0.37, use `app.getStageController().setDataViewConfigs()` instead.
Parameters
configs(Record.<string, Array.<ViewConfig>>) — The configuration list.
addDataViewConfig(
dataId: string,
config: ViewConfig,
doRender?: boolean,
)
Add a data view config.
Since v0.37, use `app.getStageController().addDataViewConfig()` instead.
Parameters
dataId(string) — The data id.config(ViewConfig) — The view configuration.doRender(boolean, optional) — Render data after configuration add. Defaults to true.
removeDataViewConfig(dataId: string, divId: string)
Remove a data view config. Removes the associated layer if found, removes the layer group if empty.
Since v0.37, use `app.getStageController().removeDataViewConfig()` instead.
Parameters
dataId(string) — The data id.divId(string) — The div id.
updateDataViewConfig(
dataId: string,
divId: string,
config: ViewConfig,
)
Update an existing data view config. Removes and re-creates the layer if found.
Since v0.37, use `app.getStageController().updateDataViewConfig()` instead.
Parameters
dataId(string) — The data id.divId(string) — The div id.config(ViewConfig) — The view configuration.
setLayerGroupsBinders(list: Array.<string>)
Set the layer groups binders.
Parameters
list(Array.<string>) — The list of binder names.
render(dataId: string, viewConfigs?: Array.<ViewConfig>)
Render the current data.
Since v0.37, use `app.getStageController().render()` instead.
Parameters
dataId(string) — The data id to render.viewConfigs(Array.<ViewConfig>, optional) — The list of configs to render.
zoom(step: number, cx: number, cy: number)
Zoom the layers of the active layer group.
Since v0.37, please access from the active layer group.
Parameters
step(number) — The step to add to the current zoom.cx(number) — The zoom center X coordinate.cy(number) — The zoom center Y coordinate.
translate(tx: number, ty: number)
Apply a translation to the layers of the active layer group.
Since v0.37, please access from the active layer group.
Parameters
tx(number) — The translation along X.ty(number) — The translation along Y.
resampleMatch(dataIdTarget: string, dataIdSource: string)
Resample one image to match the orientation of another.
Parameters
dataIdTarget(string) — The target image id to resample.dataIdSource(string) — The source image id to copy the orientation from.
resample(dataIdTarget: string, orientation: Matrix33)
Resample an image to match an arbitrary orientation.
Parameters
dataIdTarget(string) — The target image id to resample.orientation(Matrix33) — The orientation to resample to.
revertResample(dataIdTarget: string)
Revert an image back to its original orientation.
Parameters
dataIdTarget(string) — The target image id to revert.
setOpacity(alpha: number)
Set the active view layer (of the active layer group) opacity.
Since v0.33, pplease set the opacity of the desired view layer directly.
Parameters
alpha(number) — The opacity ([0:1] range).
onResize()
Handle resize: fit the display to the window. To be called once the image is loaded. Can be connected to a window 'resize' event.
onKeydown(event: object)
Key down callback. Meant to be used in tools.
Parameters
event(object) — The KeyboardEvent down event augmented with a context.
Fires
App#event:keydown
defaultOnKeydown(event: KeyboardEvent)
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.
Applies to the active view of the active layer group.
Parameters
event(KeyboardEvent) — The key down event.
Fires
UndoStack#event:undoUndoStack#event:redo
resetDisplay()
Reset the display.
resetZoom()
Reset the app zoom.
setColourMap(name: string)
Set the colour map of the active view of the active layer group.
Since v0.33, please use the ViewController equivalent directly instead.
Parameters
name(string) — The colour map name.
setWindowLevelPreset(preset: string)
Set the window/level preset of the active view of the active layer group.
Since v0.33, please use the ViewController equivalent directly instead.
Parameters
preset(string) — The window/level preset.
setTool(tool: string)
Set the tool.
Parameters
tool(string) — The tool.
setToolFeatures(list: object)
Set the tool live features.
Parameters
list(object) — The list of features.
undo()
Undo the last action.
Since v0.37, please use via app.getUndoController.
Fires
UndoStack#event:undo
redo()
Redo the last action.
Since v0.37, please use via app.getUndoController.
Fires
UndoStack#event:redo
getStackSize(): number
Get the undo stack size.
Since v0.37, please use via app.getUndoController.
Returns
number— The size of the stack.
getCurrentStackIndex(): number
Get the current undo stack index.
Since v0.37, please use via app.getUndoController.
Returns
number— The stack index.
getInfoData(dataId: string): InfoData | undefined
Get the info data for a data id.
Parameters
dataId(string) — The data id.
Returns
InfoData| undefined— The info data.
toggleInfoDataListeners(dataId: string)
Toggle info data listeners.
Parameters
dataId(string) — The data id.
createAnnotationData(refDataId: string): DicomData
Create new annotation data based on the data of the active view layer.
Parameters
refDataId(string) — The reference data id.
Returns
DicomData— The new data.
addAndRenderAnnotationData(
data: DicomData,
divId: string,
refDataId: string,
)
Add new data and render it with a simple new data view config.
Parameters
data(DicomData) — The data to add.divId(string) — The div where to draw.refDataId(string) — The reference data id.
Events
loadstart: CustomEvent
Load start event.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: string for an url, File for a file.
loadprogress: CustomEvent
Load progress event.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: string for an url, File for a file.detail.loaded(number) — The loaded percentage.detail.total(number) — The total percentage.
loaditem: CustomEvent
Load item event: fired when an item has been successfully loaded.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: string for an url, File for a file.detail.data(object) — The loaded meta data.detail.isfirstitem(boolean) — True if the item is the first one loaded for the data id.
load: CustomEvent
Load event: fired when a load finishes successfully.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: string for an url, File for a file.
loadend: CustomEvent
Load end event: fired when the load finishes, successfully or not.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: string for an url, File for a file.
error: CustomEvent
Load error event.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: string for an url, File for a file.detail.error(object) — The error.detail.target(object) — The event target.
timeout: CustomEvent
Load timeout event.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: an url as a string.detail.target(object) — The event target.
abort: CustomEvent
Load abort event.
Properties
detail(object) — The event detail.detail.dataid(string) — The data id.detail.source(*) — The load source: string for an url, File for a file.
keydown: CustomEvent
Key down event.
Properties
detail(object) — The event detail.detail.key(string) — The key value.detail.code(string) — The code value.detail.ctrlKey(boolean) — True if ctrl key is down.detail.altKey(boolean) — True if alt key is down.detail.shiftKey(boolean) — True if shift key is down.detail.context(string) — The tool where the event originated.
viewlayeradd: CustomEvent
Add view layer event.
Properties
detail(object) — The event detail.detail.layerid(string) — The layer id.detail.layergroupid(string) — The layer group id.detail.dataid(string) — The data id.
drawlayeradd: CustomEvent
Add draw layer event.
Properties
detail(object) — The event detail.detail.layerid(string) — The layer id.detail.layergroupid(string) — The layer group id.detail.dataid(string) — The data id.
opacitychange: CustomEvent
Opacity change event.
Properties
detail(object) — The event detail.detail.srclayerid(string) — The source layer id.detail.dataid(string) — The data id.detail.value(Array) — The changed value.
opacitychange: CustomEvent
Opacity change event.
Properties
detail(object) — The event detail.detail.srclayerid(string) — The source layer id.detail.dataid(string) — The data id.detail.value(Array) — The changed value.
renderstart: CustomEvent
Render start event.
Properties
detail(object) — The event detail.detail.srclayerid(string) — The source layer id.detail.dataid(string) — The data id.detail.layerid(string) — The layer id.
renderend: CustomEvent
Render end event.
Properties
detail(object) — The event detail.detail.srclayerid(string) — The source layer id.detail.dataid(string) — The data id.detail.layerid(string) — The layer id.