View

View class.

Need to set the window lookup table once created (either directly or with helper methods).

Constructor

new View(image)

Parameters:
NameTypeDescription
imageImage

The associated image.

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());
  // create the view
  const view = dwv.createView(dicomParser.getDicomElements(), image);
  // setup canvas
  const canvas = document.createElement('canvas');
  canvas.width = 256;
  canvas.height = 256;
  const ctx = canvas.getContext("2d");
  // update the image data
  const imageData = ctx.createImageData(256, 256);
  view.generateImageData(imageData);
  ctx.putImageData(imageData, 0, 0);
  // update html
  const div = document.getElementById('dwv');
  div.appendChild(canvas);;
};
// 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();

Classes

View

Methods

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.

addWindowLut(wlut)

Add the window LUT to the list.

Parameters:
NameTypeDescription
wlutWindowLut

The window LUT of the image.

addWindowPresets(presets)

Add window presets to the existing ones.

Parameters:
NameTypeDescription
presetsobject

The window presets.

canSetPosition(position) → {boolean}

Check is the provided position can be set.

Parameters:
NameTypeDescription
positionPoint

The position.

Returns:

True is the position is in bounds.

Type: 
boolean

decrementIndex(dim, silent) → {boolean}

Decrement the provided dimension.

Parameters:
NameTypeDescription
dimnumber

The dimension to increment.

silentboolean

Do not send event.

Returns:

False if not in bounds.

Type: 
boolean

decrementScrollIndex(silent) → {boolean}

Decrement the scroll dimension index.

Parameters:
NameTypeDescription
silentboolean

Do not send event.

Returns:

False if not in bounds.

Type: 
boolean

generateImageData(data, index)

Generate display image data to be given to a canvas.

Parameters:
NameTypeDescription
dataImageData

The iamge data to fill in.

indexIndex

Optional index at which to generate, otherwise generates at current index.

getAlphaFunction() → {alphaFn}

Get the alpha function.

Returns:

The function.

Type: 
alphaFn

getColourMap() → {ColourMap}

Get the colour map of the image.

Returns:

The colour map of the image.

Type: 
ColourMap

getCurrentIndex() → {Index}

Get the current index.

Returns:

The current index.

Type: 
Index

getCurrentPosition() → {Point}

Get the current position.

Returns:

The current position.

Type: 
Point

getCurrentWindowLut(rsiopt) → {WindowLut}

Get the window LUT of the image. Warning: can be undefined in no window/level was set.

Parameters:
NameTypeAttributesDescription
rsiobject<optional>

Optional image rsi, will take the one of the current slice otherwise.

Returns:

The window LUT of the image.

Type: 
WindowLut

getImage() → {Image}

Get the associated image.

Returns:

The associated image.

Type: 
Image

getOrientation() → {Matrix33}

Get the view orientation.

Returns:

The orientation matrix.

Type: 
Matrix33

getOrigin(position) → {Point}

Get the origin at a given position.

Parameters:
NameTypeDescription
positionPoint

The position.

Returns:

The origin.

Type: 
Point

getPlaybackMilliseconds(recommendedDisplayFrameRate) → {number}

Get the milliseconds per frame from frame rate.

Parameters:
NameTypeDescription
recommendedDisplayFrameRatenumber

Recommended Display Frame Rate.

Returns:

The milliseconds per frame.

Type: 
number

getScrollIndex() → {number}

Get the scroll dimension index.

Returns:

The index.

Type: 
number

getWindowLevelMinMax() → {WindowCenterAndWidth}

Get the image window/level that covers the full data range. Warning: uses the latest set rescale LUT or the default linear one.

Returns:

A min/max window level.

Type: 
WindowCenterAndWidth

getWindowPresets() → {object}

Get the window presets.

Returns:

The window presets.

Type: 
object

getWindowPresetsNames() → {object}

Get the window presets names.

Returns:

The list of window presets names.

Type: 
object

incrementIndex(dim, silent) → {boolean}

Increment the provided dimension.

Parameters:
NameTypeDescription
dimnumber

The dimension to increment.

silentboolean

Do not send event.

Returns:

False if not in bounds.

Type: 
boolean

incrementScrollIndex(silent) → {boolean}

Increment the scroll dimension index.

Parameters:
NameTypeDescription
silentboolean

Do not send event.

Returns:

False if not in bounds.

Type: 
boolean

init()

Initialise the view: set initial index.

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.

setAlphaFunction(func)

Set alpha function.

Parameters:
NameTypeDescription
funcalphaFn

The function.

setColourMap(map)

Set the colour map of the image.

Parameters:
NameTypeDescription
mapColourMap

The colour map of the image.

setCurrentIndex(index, silentopt) → {boolean}

Set the current index.

Parameters:
NameTypeAttributesDescription
indexIndex

The new index.

silentboolean<optional>

Flag to fire event or not.

Returns:

False if not in bounds.

Type: 
boolean

setCurrentPosition(position, silent) → {boolean}

Set the current position.

Parameters:
NameTypeDescription
positionPoint

The new position.

silentboolean

Flag to fire event or not.

Returns:

False if not in bounds

Type: 
boolean

setDefaultColourMap(map)

Set the default colour map.

Parameters:
NameTypeDescription
mapColourMap

The colour map.

setImage(inImage)

Set the associated image.

Parameters:
NameTypeDescription
inImageImage

The associated image.

setInitialIndex()

Set the initial index to 0.

setOrientation(mat33)

Set the view orientation.

Parameters:
NameTypeDescription
mat33Matrix33

The orientation matrix.

setWindowLevel(center, width, nameopt, silentopt)

Set the view window/level.

Parameters:
NameTypeAttributesDescription
centernumber

The window center.

widthnumber

The window width.

namestring<optional>

Associated preset name, defaults to 'manual'. Warning: uses the latest set rescale LUT or the default linear one.

silentboolean<optional>

Flag to launch events with skipGenerate.

setWindowLevelMinMax()

Set the image window/level to cover the full data range. Warning: uses the latest set rescale LUT or the default linear one.

setWindowLevelPreset(name, silentopt)

Set the window level to the preset with the input name.

Parameters:
NameTypeAttributesDescription
namestring

The name of the preset to activate.

silentboolean<optional>

Flag to launch events with skipGenerate.

setWindowLevelPresetById(id, silentopt)

Set the window level to the preset with the input id.

Parameters:
NameTypeAttributesDescription
idnumber

The id of the preset to activate.

silentboolean<optional>

Flag to launch events with skipGenerate.

setWindowPresets(presets)

Set the window presets.

Parameters:
NameTypeDescription
presetsobject

The window presets.

Events

alphafuncchange

Alpha func change event.

Type:
  • object

colourchange

Color change event.

Type:
  • object
Properties
NameTypeDescription
valueArray

The changed value.

wcnumber

The new window center value.

wwnumber

The new window wdth value.

positionchange

Position change event.

Type:
  • object
Properties
NameTypeDescription
valueArray

The changed value as [index, pixelValue].

diffDimsArray

An array of modified indices.

wlchange

Window/level change event.

Type:
  • object
Properties
NameTypeDescription
valueArray

The changed value.

wcnumber

The new window center value.

wwnumber

The new window wdth value.

skipGenerateboolean

Flag to skip view generation.

wlpresetadd

Window/level add preset event.

Type:
  • object
Properties
NameTypeDescription
namestring

The name of the preset.