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

abortLoad()

Abort the current load.

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.

addNewImage(image, meta) → {number}

Add a new image.

Parameters:
NameTypeDescription
imageImage

The new image.

metaobject

The image meta.

Returns:

The new image id.

Type: 
number

addToUndoStack(cmd)

Add a command to the undo stack.

Parameters:
NameTypeDescription
cmdobject

The command to add.

applyJsonState(jsonState)

Apply a JSON state to this app.

Parameters:
NameTypeDescription
jsonStatestring

The state of the app as a JSON string.

canScroll() → {boolean}

Can the data be scrolled?

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?

Returns:

True if the data is monochrome.

Type: 
boolean

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
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}

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

Returns:

The layer group.

Type: 
LayerGroup

getAddedScale() → {object}

Get the layer scale on top of the base scale.

Returns:

The scale as {x,y}.

Type: 
object

getBaseScale() → {object}

Get the base scale.

Returns:

The scale as {x,y}.

Type: 
object

getCurrentStackIndex() → {number}

Get the current undo stack index.

Returns:

The stack index.

Type: 
number

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>>

getDrawLayersByDataIndex(index) → {Array.<DrawLayer>}

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

Parameters:
NameTypeDescription
indexnumber

The data index.

Returns:

The layers.

Type: 
Array.<DrawLayer>

getImage(index) → {Image}

Get the image.

Parameters:
NameTypeDescription
indexnumber

The data index.

Returns:

The associated image.

Type: 
Image

getJsonState() → {string}

Get the JSON state of the app.

Returns:

The state of the app as a JSON string.

Type: 
string

getLastImage() → {Image}

Get the last loaded image.

Returns:

The image.

Type: 
Image

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(index) → {object}

Get the meta data.

Parameters:
NameTypeDescription
indexnumber

The data index.

Returns:

The list of meta data.

Type: 
object

getNumberOfLayerGroups() → {number}

Get the number of layer groups.

Returns:

The number of groups.

Type: 
number

getNumberOfLoadedData() → {number}

Get the number of loaded data.

Returns:

The number.

Type: 
number

getOffset() → {object}

Get the layer offset.

Returns:

The offset.

Type: 
object

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

getViewLayersByDataIndex(index) → {Array.<ViewLayer>}

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

Parameters:
NameTypeDescription
indexnumber

The data index.

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

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

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.

render(dataIndex)

Render the current data.

Parameters:
NameTypeDescription
dataIndexnumber

The data index to render.

reset()

Reset the application.

resetDisplay()

Reset the display

resetLayout()

Reset the layout of the application.

resetZoom()

Reset the app zoom.s

setColourMap(name)

Set the colour map.

Parameters:
NameTypeDescription
namestring

The colour map name.

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)

Set the drawings on the current stage.

Parameters:
NameTypeDescription
drawingsArray

An array of drawings.

drawingsDetailsArray

An array of drawings details.

setImage(index, img)

Set the image at the given index.

Parameters:
NameTypeDescription
indexnumber

The data index.

imgImage

The associated image.

setLastImage(img)

Set the last image.

Parameters:
NameTypeDescription
imgImage

The associated image.

setLayerGroupsBinders(list)

Set the layer groups binders.

Parameters:
NameTypeDescription
listArray

The list of binder names.

setOpacity(alpha)

Set the image layer opacity.

Parameters:
NameTypeDescription
alphanumber

The opacity ([0:1] range).

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.

Parameters:
NameTypeDescription
presetobject

The window/level preset.

translate(tx, ty)

Apply a translation to the layers.

Parameters:
NameTypeDescription
txnumber

The translation along X.

tynumber

The translation along Y.

undo()

Undo the last action

zoom(step, cx, cy)

Zoom to the layers.

Parameters:
NameTypeDescription
stepnumber

The step to add to the current zoom.

cxnumber

The zoom center X coordinate.

cynumber

The zoom center Y coordinate.

Events

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.

loadabort

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.

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.

loaderror

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.

loaditem

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

Type:
  • object
Properties
NameTypeDescription
typestring

The event type: loaditem.

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.