App

Main application class.

Constructor

new App()

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'
]);

Methods

abortAllLoads()

Abort all the current loads.

abortLoad(dataId)

Abort an individual data load.

Parameters:
NameTypeDescription
dataIdstring

The data to stop loading.

addAndRenderAnnotationData(data, divId, refDataId)

Add new data and render it with a simple new data view config.

Parameters:
NameTypeDescription
dataDicomData

The data to add.

divIdstring

The div where to draw.

refDataIdstring

The reference data id.

addData(data) → {string}

Add a new DicomData.

Parameters:
NameTypeDescription
dataDicomData

The new data.

Returns:

The data id.

Type: 
string

addDataViewConfig(dataId, config)

Add a data view config.

Parameters:
NameTypeDescription
dataIdstring

The data id.

configViewConfig

The view configuration.

addDrawLayer(dataId, viewConfig)

Add a draw layer.

Parameters:
NameTypeDescription
dataIdstring

The data id.

viewConfigViewConfig

The data view config.

addEventListener(type, callback)

Add an event listener to this class.

Parameters:
NameTypeDescription
typestring

The event type.

callbackfunction

The function associated with the provided event type, will be called with the fired event.

addToUndoStack(cmd)

Add a command to the undo stack.

Parameters:
NameTypeDescription
cmdobject

The command to add.

applyJsonState(jsonState, dataId)

Apply a JSON state to this app.

Parameters:
NameTypeDescription
jsonStatestring

The state of the app as a JSON string.

dataIdstring

The state data id.

Deprecated
  • Since v0.34, please switch to DICOM SR for annotations.

canScroll() → {boolean}

Can the data (of the active view of the active layer) be scrolled?

Deprecated
  • Since v0.33, please use the ViewController equivalent directly instead.
Returns:

True if the data has a third dimension greater than one.

Type: 
boolean

canWindowLevel() → {boolean}

Can window and level be applied to the data (of the active view of the active layer)?

Deprecated
  • Since v0.33, please use the ViewController equivalent directly instead.
Returns:

True if the data is monochrome.

Type: 
boolean

createAnnotationData(refDataId) → {DicomData}

Create new annotation data based on the data of the active view layer.

Parameters:
NameTypeDescription
refDataIdstring

The reference data id.

Returns:

The new data.

Type: 
DicomData

defaultOnKeydown(event)

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:
NameTypeDescription
eventKeyboardEvent

The key down event.

fitToContainer()

Fit the display to the data of each layer group. To be called once the image is loaded.

getActiveLayerGroup() → {LayerGroup|undefined}

Get the active layer group. The layer is available after the first loaded item.

Returns:

The layer group.

Type: 
LayerGroup | undefined

getAddedScale() → {Scalar3D}

Get the active layer group scale on top of the base scale.

Returns:

The scale as {x,y,z}.

Type: 
Scalar3D

getBaseScale() → {Scalar3D}

Get the base scale of the active layer group.

Returns:

The scale as {x,y,z}.

Type: 
Scalar3D

getCurrentStackIndex() → {number}

Get the current undo stack index.

Returns:

The stack index.

Type: 
number

getData(dataId) → {DicomData|undefined}

Get a DicomData.

Parameters:
NameTypeDescription
dataIdstring

The data id.

Returns:

The data.

Type: 
DicomData | undefined

getDataIds() → {Array.<string>}

Get the list of ids in the data storage.

Returns:

The list of data ids.

Type: 
Array.<string>

getDataIdsFromSopUids(uids) → {Array.<string>}

Get the list of dataIds that contain the input UIDs.

Parameters:
NameTypeDescription
uidsArray.<string>

A list of UIDs.

Returns:

The list of dataIds that contain the UIDs.

Type: 
Array.<string>

getDataViewConfigs() → {Object.<string, Array.<ViewConfig>>}

Get the data view config. Carefull, returns a reference, do not modify without resetting.

Returns:

The configuration list.

Type: 
Object.<string, Array.<ViewConfig>>

getDrawLayers(callbackFnopt) → {Array.<DrawLayer>}

Get a list of draw layers according to an input callback function.

Parameters:
NameTypeAttributesDescription
callbackFnfunction<optional>

A function that takes a DrawLayer as input and returns a boolean. If undefined, returns all draw layers.

Returns:

The layers that satisfy the callbackFn.

Type: 
Array.<DrawLayer>

getDrawLayersByDataId(dataId) → {Array.<DrawLayer>}

Get the draw layers associated to a data id. The layer are available after the first loaded item.

Parameters:
NameTypeDescription
dataIdstring

The data id.

Returns:

The layers.

Type: 
Array.<DrawLayer>

getImage(dataId) → {Image|undefined}

Get the image.

Parameters:
NameTypeDescription
dataIdstring

The data id.

Deprecated
  • Since v0.34, please use the getData method.
Returns:

The associated image.

Type: 
Image | undefined

getLayerGroupByDivId(divId) → {LayerGroup}

Get a layer group by div id. The layer is available after the first loaded item.

Parameters:
NameTypeDescription
divIdstring

The div id.

Returns:

The layer group.

Type: 
LayerGroup

getMetaData(dataId) → {Object.<string, DataElement>|undefined}

Get the meta data.

Parameters:
NameTypeDescription
dataIdstring

The data id.

Returns:

The list of meta data.

Type: 
Object.<string, DataElement> | undefined

getNumberOfLayerGroups() → {number}

Get the number of layer groups.

Returns:

The number of groups.

Type: 
number

getOffset() → {Scalar3D}

Get the layer offset of the active layer group.

Returns:

The offset as {x,y,z}.

Type: 
Scalar3D

getOverlayData(dataId) → {OverlayData|undefined}

Get the overlay data for a data id.

Parameters:
NameTypeDescription
dataIdstring

The data id.

Returns:

The overlay data.

Type: 
OverlayData | undefined

getStackSize() → {number}

Get the undo stack size.

Returns:

The size of the stack.

Type: 
number

getStyle() → {object}

Get the app style.

Returns:

The app style.

Type: 
object

getToolboxController() → {ToolboxController}

Get the toolbox controller.

Returns:

The controller.

Type: 
ToolboxController

getViewConfig(dataId, groupDivId, excludeStarConfigopt) → {ViewConfig|undefined}

Get the layer group configuration for a data id and group div id.

Parameters:
NameTypeAttributesDescription
dataIdstring

The data id.

groupDivIdstring

The layer group div id.

excludeStarConfigboolean<optional>

Exclude the star config (default to false).

Returns:

The associated config.

Type: 
ViewConfig | undefined

getViewConfigs(dataId, excludeStarConfigopt) → {Array.<ViewConfig>}

Get the layer group configuration from a data id.

Parameters:
NameTypeAttributesDescription
dataIdstring

The data id.

excludeStarConfigboolean<optional>

Exclude the star config (default to false).

Returns:

The list of associated configs.

Type: 
Array.<ViewConfig>

getViewLayers(callbackFnopt) → {Array.<ViewLayer>}

Get a list of view layers according to an input callback function.

Parameters:
NameTypeAttributesDescription
callbackFnfunction<optional>

A function that takes a ViewLayer as input and returns a boolean. If undefined, returns all view layers.

Returns:

The layers that satisfy the callbackFn.

Type: 
Array.<ViewLayer>

getViewLayersByDataId(dataId) → {Array.<ViewLayer>}

Get the view layers associated to a data id. The layer are available after the first loaded item.

Parameters:
NameTypeDescription
dataIdstring

The data id.

Returns:

The layers.

Type: 
Array.<ViewLayer>

init(opt)

Initialise the application.

Parameters:
NameTypeDescription
optAppOptions

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'
]);

initWLDisplay()

Init the Window/Level display (of the active layer of the active layer group).

Deprecated
  • Since v0.33, please set the opacity of the desired view layer directly.

loadFiles(files)

Load a list of files. Can be image files or a state file.

Parameters:
NameTypeDescription
filesArray.<File>

The list of files to load.

loadFromUri(uri, optionsopt)

Load from an input uri.

Parameters:
NameTypeAttributesDescription
uristring

The input uri, for example: 'window.location.href'.

optionsobject<optional>

Optional url request options.

loadImageObject(data)

Load a list of ArrayBuffers.

Parameters:
NameTypeDescription
dataArray

The list of ArrayBuffers to load in the form of [{name: "", filename: "", data: data}].

loadURLs(urls, optionsopt)

Load a list of URLs. Can be image files or a state file.

Parameters:
NameTypeAttributesDescription
urlsArray.<string>

The list of urls to load.

optionsobject<optional>

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.

onKeydown(event)

Key down callback. Meant to be used in tools.

Parameters:
NameTypeDescription
eventKeyboardEvent

The key down event.

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.

redo()

Redo the last action.

removeDataViewConfig(dataId, divId)

Remove a data view config.

Parameters:
NameTypeDescription
dataIdstring

The data id.

divIdstring

The div id.

removeEventListener(type, callback)

Remove an event listener from this class.

Parameters:
NameTypeDescription
typestring

The event type.

callbackfunction

The function associated with the provided event type.

removeFromUndoStack(name) → {boolean}

Remove a command from the undo stack.

Parameters:
NameTypeDescription
namestring

The name of the command to remove.

Returns:

True if the command was found and removed.

Type: 
boolean

render(dataId, viewConfigsopt)

Render the current data.

Parameters:
NameTypeAttributesDescription
dataIdstring

The data id to render.

viewConfigsArray.<ViewConfig><optional>

The list of configs to render.

reset()

Reset the application.

resetDisplay()

Reset the display.

resetLayout()

Reset the layout of the application.

resetZoom()

Reset the app zoom.

setActiveLayerGroup(index)

Set the active layer group.

Parameters:
NameTypeDescription
indexnumber

The layer group index.

setColourMap(name)

Set the colour map of the active view of the active layer group.

Parameters:
NameTypeDescription
namestring

The colour map name.

Deprecated
  • Since v0.33, please use the ViewController equivalent directly instead.

setDataViewConfigs(configs)

Set the data view configuration. Resets the stage and recreates all the views.

Parameters:
NameTypeDescription
configsObject.<string, Array.<ViewConfig>>

The configuration list.

setDrawings(drawings, drawingsDetails, dataId)

Set the drawings of the active layer group.

Parameters:
NameTypeDescription
drawingsArray

An array of drawings.

drawingsDetailsArray

An array of drawings details.

dataIdstring

The converted data id.

Deprecated
  • Since v0.34, please switch to DICOM SR annotations.

setImage(dataId, img)

Set the image at the given id.

Parameters:
NameTypeDescription
dataIdstring

The data id.

imgImage

The associated image.

setImageSmoothing(flag)

Set the imageSmoothing flag value. Default is false.

Parameters:
NameTypeDescription
flagboolean

True to enable smoothing.

setLayerGroupsBinders(list)

Set the layer groups binders.

Parameters:
NameTypeDescription
listArray.<string>

The list of binder names.

setOpacity(alpha)

Set the active view layer (of the active layer group) opacity.

Parameters:
NameTypeDescription
alphanumber

The opacity ([0:1] range).

Deprecated
  • Since v0.33, pplease set the opacity of the desired view layer directly.

setTool(tool)

Set the tool.

Parameters:
NameTypeDescription
toolstring

The tool.

setToolFeatures(list)

Set the tool live features.

Parameters:
NameTypeDescription
listobject

The list of features.

setWindowLevelPreset(preset)

Set the window/level preset of the active view of the active layer group.

Parameters:
NameTypeDescription
presetstring

The window/level preset.

Deprecated
  • Since v0.33, please use the ViewController equivalent directly instead.

toggleOverlayListeners(dataId)

Toggle overlay listeners.

Parameters:
NameTypeDescription
dataIdstring

The data id.

translate(tx, ty)

Apply a translation to the layers of the active layer group.

Parameters:
NameTypeDescription
txnumber

The translation along X.

tynumber

The translation along Y.

undo()

Undo the last action.

updateDataViewConfig(dataId, divId, config)

Update an existing data view config. Removes and re-creates the layer if found.

Parameters:
NameTypeDescription
dataIdstring

The data id.

divIdstring

The div id.

configViewConfig

The view configuration.

zoom(step, cx, cy)

Zoom the layers of the active layer group.

Parameters:
NameTypeDescription
stepnumber

The step to add to the current zoom.

cxnumber

The zoom center X coordinate.

cynumber

The zoom center Y coordinate.

Events

abort

Load abort event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type: abort.

loadTypestring

The load type: image or state.

source*

The load source: string for an url, File for a file.

drawlayeradd

Add draw layer event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

layeridstring

The layer id.

layergroupidstring

The layer group id.

dataidstring

The data id.

error

Load error event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type: error.

loadTypestring

The load type: image or state.

source*

The load source: string for an url, File for a file.

errorobject

The error.

targetobject

The event target.

keydown

Key down event.

Type:
  • KeyboardEvent
Properties
NameTypeDescription
typestring

The event type: keydown.

contextstring

The tool where the event originated.

load

Load event: fired when a load finishes successfully.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type: load.

loadTypestring

The load type: image or state.

loadend

Main load end event: fired when the load finishes, successfully or not.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type: loadend.

loadTypestring

The load type: image or state.

source*

The load source: string for an url, File for a file.

loaditem

Load item event: fired when a load item is successfull.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

loadTypestring

The load type: image or state.

source*

The load source: string for an url, File for a file.

dataobject

The loaded meta data.

loadprogress

Load progress event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type: loadprogress.

loadTypestring

The load type: image or state.

source*

The load source: string for an url, File for a file.

loadednumber

The loaded percentage.

totalnumber

The total percentage.

loadstart

Load start event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type: loadstart.

loadTypestring

The load type: image or state.

source*

The load source: string for an url, File for a file.

opacitychange

Opacity change event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

renderend

Render end event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

renderstart

Render start event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

viewlayeradd

Add view layer event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

layeridstring

The layer id.

layergroupidstring

The layer group id.

dataidstring

The data id.