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.

addWindowPresets(presets)

Add window presets to the existing ones.

Parameters:
NameTypeDescription
presetsobject

The window presets.

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

Get the colour map of the image.

Returns:

The colour map name.

Type: 
string

getCurrentImageUid() → {string}

Get the SOP image UID of the current image.

Returns:

The UID.

Type: 
string

getCurrentIndex() → {Index}

Get the current index.

Returns:

The current index.

Type: 
Index

getCurrentPosition() → {Point}

Get the current position.

Returns:

The current position.

Type: 
Point

getCurrentWindowPresetName() → {string}

Get the current window level preset name.

Returns:

The preset name.

Type: 
string

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(positionopt) → {Point3D}

Get the first origin or at a given position.

Parameters:
NameTypeAttributesDescription
positionPoint<optional>

Optional position.

Returns:

The origin.

Type: 
Point3D

getOriginForImageUid(uid) → {Point3D|undefined}

Get the image origin for a image UID.

Parameters:
NameTypeDescription
uidstring

The UID.

Returns:

The origin.

Type: 
Point3D | undefined

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

getWindowLevel() → {WindowLevel}

Get the window/level.

Returns:

The window and level.

Type: 
WindowLevel

getWindowLevelMinMax() → {WindowLevel}

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

getWindowPresets() → {object}

Get the window presets.

Returns:

The window presets.

Type: 
object

getWindowPresetsNames() → {Array.<string>}

Get the window presets names.

Returns:

The list of window presets names.

Type: 
Array.<string>

includesImageUid(uid) → {boolean}

Check if the image includes an UID.

Parameters:
NameTypeDescription
uidstring

The UID.

Returns:

True if present.

Type: 
boolean

init()

Initialise the view: set initial index.

isAquisitionOrientation() → {boolean}

Is this view in the same orientation as the image aquisition.

Returns:

True if in aquisition plane.

Type: 
boolean

isPositionInBounds(positionopt) → {boolean}

Check if the current position (default) or the provided position is in bounds.

Parameters:
NameTypeAttributesDescription
positionPoint<optional>

Optional position.

Returns:

True is the position is in bounds.

Type: 
boolean

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(name)

Set the colour map of the image.

Parameters:
NameTypeDescription
namestring

The colour map name.

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, silentopt) → {boolean}

Set the current position.

Parameters:
NameTypeAttributesDescription
positionPoint

The new position.

silentboolean<optional>

Flag to fire event or not.

Returns:

False if not in bounds.

Type: 
boolean

setImage(inImage)

Set the associated image.

Parameters:
NameTypeDescription
inImageImage

The associated image.

setInitialIndex()

Set the initial index to the middle position.

setOrientation(mat33)

Set the view orientation.

Parameters:
NameTypeDescription
mat33Matrix33

The orientation matrix.

setWindowLevel(wl, nameopt, silentopt)

Set the view window/level.

Parameters:
NameTypeAttributesDescription
wlWindowLevel

The window and level.

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
Properties
NameTypeDescription
typestring

The event type.

colourmapchange

Color change event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

valueArray

The changed value.

positionchange

Position change event.

Type:
  • object
Properties
NameTypeDescription
valueArray

The changed value as [index, pixelValue].

diffDimsArray.<number>

An array of modified indices.

wlchange

Window/level change event.

Type:
  • object
Properties
NameTypeDescription
typestring

The event type.

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
typestring

The event type.

namestring

The name of the preset.