View
Source: view.js:103
View class.
Need to set the window lookup table once created (either directly or with helper methods).
Example
import {DicomParser, demoCreateImage, demoCreateView} from '//esm.sh/dwv';
// XMLHttpRequest onload callback
const onload = function (event) {
// parse the dicom buffer
const dicomParser = new DicomParser();
dicomParser.parse(event.target.response);
// create the image object
const image = demoCreateImage(dicomParser.getDicomElements());
// create the view
const view = demoCreateView(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();Constructor
new View(image: Image): ViewParameters
image(Image) — The associated image.
Instance Methods
getImage(): Image
Get the associated image.
Returns
Image— The associated image.
setImage(image: Image)
Set the associated image.
Parameters
image(Image) — The associated image.
isMask(): boolean
Check is the associated image is a mask.
Returns
boolean— True if the associated image is a mask.
setMaskViewHelper(helper: MaskSegmentViewHelper)
Set the mask segment view helper to handle hidden segments.
Parameters
helper(MaskSegmentViewHelper) — The helper.
getSegmentHighlight(): Object | undefined
Get the segment highlight.
Returns
Object | undefined— The highlighted segment number and its opacity factor.
setSegmentHighlight(segmentNumber?: number, opacity?: number)
Set the segment highlight: the opacity of the given segment is multiplied by the input factor. Only one segment can be highlighted at a time. This only has an effect on segmentation views.
Parameters
segmentNumber(number, optional) — The segment number, undefined to remove the highlight.opacity(number, optional) — The opacity factor (between 0 and 1), defaults to 1.
Fires
View#event:segmenthighlightchange
getOrientation(): Matrix33
Get the view orientation.
Returns
Matrix33— The orientation matrix.
setOrientation(mat33: Matrix33)
Set the view orientation.
Parameters
mat33(Matrix33) — The orientation matrix.
getFillOpacity(): number
Get the fill opacity relative to the global opacity.
Returns
number— The fill opacity (between 0 and 1).
setFillOpacity(opacity: number)
Set the fill opacity relative to the global opacity. This only has an effect on segmentation views, or any other alpha function that makes use of it.
Parameters
opacity(number) — The fill opacity (between 0 and 1).
getContourThickness(): number
Get the thickness of the contour in pixels.
Returns
number— The contour thickness (0 <= integer <= MAX_CONTOUR_SIZE).
setContourThickness(thickness: number)
Set the thickness of the contour in pixels. This only has an effect on segmentation views, or any other alpha function that makes use of it.
Parameters
thickness(number) — The contour thickness (0 <= integer <= MAX_CONTOUR_SIZE).
getPlaybackMilliseconds(
recommendedDisplayFrameRate: number,
): number
Get the milliseconds per frame from frame rate.
Parameters
recommendedDisplayFrameRate(number) — Recommended Display Frame Rate.
Returns
number— The milliseconds per frame.
getAlphaFunction(): alphaFn
Get the alpha function.
Returns
alphaFn— The function.
setAlphaFunction(func: alphaFn)
Set alpha function.
Parameters
func(alphaFn) — The function.
Fires
View#event:alphafuncchange
getWindowPresets(): Record.<string, WindowPreset>
Get the window presets.
Returns
Record.<string,WindowPreset>— The window presets.
getWindowPresetsNames(): Array.<string>
Get the window presets names.
Returns
Array.<string>— The list of window presets names.
setWindowPresets(presets: Record.<string, WindowPreset>)
Set the window presets.
Parameters
presets(Record.<string, WindowPreset>) — The window presets.
addWindowPresets(presets: Record.<string, WindowPreset>)
Add window presets to the existing ones.
Parameters
presets(Record.<string, WindowPreset>) — The window presets.
getCurrentWindowPresetName(): string | undefined
Get the current window level preset name.
Returns
string | undefined— The preset name.
getColourMap(): string
Get the colour map of the image.
Returns
string— The colour map name.
setColourMap(name: string)
Set the colour map of the image.
Parameters
name(string) — The colour map name.
Fires
View#event:colourmapchange
getCurrentPosition(): Point | undefined
Get the current position.
Returns
Point| undefined— The current position.
getCurrentIndex(): Index | undefined
Get the current index.
Returns
Index| undefined— The current index.
getCurrentImageUid(): string
Get the SOP image UID of the current image.
Returns
string— The UID.
getOriginForImageUid(uid: string): Point3D | undefined
Get the image origin for a image UID.
Parameters
uid(string) — The UID.
Returns
Point3D| undefined— The origin.
includesImageUid(uid: string): boolean
Check if the image includes an UID.
Parameters
uid(string) — The UID.
Returns
boolean— True if present.
isPositionInBounds(position?: Point): boolean
Check if the current position (default) or the provided position is in bounds.
Parameters
position(Point, optional) — Optional position.
Returns
boolean— True is the position is in bounds.
getOrigin(position?: Point): Point3D
Get the first origin or at a given position.
Parameters
position(Point, optional) — Optional position.
Returns
Point3D— The origin.
setCurrentIndex(index: Index, silent?: boolean): boolean
Set the current position via an index.
Parameters
index(Index) — The new index.silent(boolean, optional) — Flag to fire event or not.
Returns
boolean— False if not in bounds.
Fires
View#event:positionchange
setCurrentPosition(inPosition: Point, silent?: boolean): boolean
Set current position.
Parameters
inPosition(Point) — The new position.silent(boolean, optional) — Flag to fire event or not.
Returns
boolean— False if not in bounds.
Fires
View#event:positionchange
setWindowLevel(wl: WindowLevel, name?: string, silent?: boolean)
Set the view window/level.
Parameters
wl(WindowLevel) — The window and level.name(string, optional) — Associated preset name, defaults to 'manual'. Warning: uses the latest set rescale LUT or the default linear one.silent(boolean, optional) — Flag to launch events with skipGenerate.
Fires
View#event:wlchange
getWindowLevel(): WindowLevel
Get the window/level.
Returns
WindowLevel— The window and level.
setWindowLevelPreset(name: string, silent?: boolean)
Set the window level to the preset with the input name.
Parameters
name(string) — The name of the preset to activate.silent(boolean, optional) — Flag to launch events with skipGenerate.
setWindowLevelPresetById(id: number, silent?: boolean)
Set the window level to the preset with the input id.
Parameters
id(number) — The id of the preset to activate.silent(boolean, optional) — Flag to launch events with skipGenerate.
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
WindowLevel— A min/max window level.
setWindowLevelMinMax()
Set the image window/level to cover the full data range. Warning: uses the latest set rescale LUT or the default linear one.
generateImageData(data: ImageData, index: Index)
Generate display image data to be given to a canvas.
Parameters
data(ImageData) — The iamge data to fill in.index(Index) — Optional index at which to generate, otherwise generates at current index.
getScrollDimIndex(): number
Get the scroll dimension index.
Returns
number— The index.
isAquisitionOrientation(): boolean
Is this view in the same orientation as the image aquisition.
Returns
boolean— True if in aquisition plane.
Events
segmenthighlightchange: CustomEvent
Segment highlight change event. Not propagated to the app (not part of viewEventNames) since it can be fired at each frame of a highlight animation.
maskviewchange: CustomEvent
Mask view change event.
Properties
detail(object) — The event detail.detail.value(Array) — The changed value.
alphafuncchange: CustomEvent
Alpha func change event.
Properties
detail(object) — The event detail.
wlpresetadd: CustomEvent
Window/level add preset event.
Properties
detail(object) — The event detail.detail.name(string) — The name of the preset.
colourmapchange: CustomEvent
Color change event.
Properties
detail(object) — The event detail.detail.value(Array) — The changed value.
positionchange: CustomEvent
Position change event.
Properties
detail(object) — The event detail.detail.value(Array) — The changed value as [index, pixelValue].detail.diffDims(Array.<number>) — An array of modified indices.
wlchange: CustomEvent
Window/level change event.
Properties
detail(object) — The event detail.detail.value(Array) — The changed value.detail.wc(number) — The new window center value.detail.ww(number) — The new window width value.detail.skipGenerate(boolean) — Flag to skip view generation.