dwv. App

new App()

Main application class.

Example
// create the dwv app
var app = new dwv.App();
// initialise
app.init({
  dataViewConfigs: {'*': [{divId: 'layerGroup0'}]}
});
// 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.

callbackobject

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

addNewImage(image, meta) → {number}

Add a new image.

Parameters:
NameTypeDescription
imagedwv.image.Image

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.

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
eventobject

The key down event.

fitToContainer()

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

getActiveLayerGroup() → {dwv.gui.LayerGroup}

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

Returns:

The layer group.

Type: 
dwv.gui.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

getDataViewConfig() → {object}

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

Returns:

The configuration list.

Type: 
object

getDrawLayersByDataIndex(index) → {Array}

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

getElement(_name) → {object}

Get a HTML element associated to the application.

Parameters:
NameTypeDescription
_namestring

The name or id to find.

Deprecated
  • Yes
Returns:

The found element or null.

Type: 
object

getImage(index) → {dwv.image.Image}

Get the image.

Parameters:
NameTypeDescription
indexnumber

The data index.

Returns:

The associated image.

Type: 
dwv.image.Image

getLastImage() → {dwv.image.Image}

Get the last loaded image.

Returns:

The image.

Type: 
dwv.image.Image

getLayerGroupByDivId(divId) → {dwv.gui.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: 
dwv.gui.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

getState() → {object}

Get the JSON state of the app.

Returns:

The state of the app as a JSON object.

Type: 
object

getStyle() → {object}

Get the app style.

Returns:

The app style.

Type: 
object

getToolboxController() → {object}

Get the toolbox controller.

Returns:

The controller.

Type: 
object

getViewLayersByDataIndex(index) → {Array}

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

init(opt)

Initialise the application.

Parameters:
NameTypeDescription
optobject

The application option with:

  • dataViewConfigs: data indexed object containing the data view configurations in the form of a list of objects containing:
    • divId: the HTML div id
    • orientation: optional 'axial', 'coronal' or 'sagittal' orientation string (default undefined keeps the original slice order)
  • binders: array of layerGroup binders
  • tools: tool name indexed object containing individual tool configurations in the form of a list of objects containing:
    • options: array of tool options
  • viewOnFirstLoadItem: boolean flag to trigger the first data render after the first loaded data or not
  • defaultCharacterSet: the default chraracter set string used for DICOM parsing
Example
// create the dwv app
var app = new dwv.App();
// initialise
app.init({
  dataViewConfigs: {'*': [{divId: 'layerGroup0'}]},
  viewOnFirstLoadItem: false
});
// render button
var button = document.createElement('button');
button.id = 'render';
button.disabled = true;
button.appendChild(document.createTextNode('render'));
document.body.appendChild(button);
app.addEventListener('load', function () {
  var 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

The list of files to load.

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, options)

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

Parameters:
NameTypeDescription
urlsArray

The list of urls to load.

optionsobject

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
eventobject

The key down event.

redo()

Redo the last action

removeEventListener(type, callback)

Remove an event listener from this class.

Parameters:
NameTypeDescription
typestring

The event type.

callbackobject

The method 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(colourMap)

Set the colour map.

Parameters:
NameTypeDescription
colourMapstring

The colour map name.

setDataViewConfig(configs)

Set the data view configuration (see the init options for details).

Parameters:
NameTypeDescription
configsobject

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.

imgdwv.image.Image

The associated image.

setLastImage(img)

Set the last image.

Parameters:
NameTypeDescription
imgdwv.image.Image

The associated image.

setLayerGroupsBinders(list)

Set the layer groups binders.

Parameters:
NameTypeDescription
listArray

The binders list.

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.

(inner) addViewLayer(dataIndex, dataViewConfig)

Add a view layer.

Parameters:
NameTypeDescription
dataIndexnumber

The data index.

dataViewConfigobject

The data view config.

(inner) createLayerGroups(dataViewConfigs)

Create layer groups according to a data view config: adds them to stage and bind them.

Parameters:
NameTypeDescription
dataViewConfigsobject

The data view config.

(inner) getViewConfigs(dataIndex) → {Array}

Get the layer group configuration from a data index. Defaults to div id 'layerGroup' if no association object has been set.

Parameters:
NameTypeDescription
dataIndexnumber

The data index.

Returns:

The list of associated configs.

Type: 
Array

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.