UNPKG

@cornerstonejs/core

Version:
48 lines (47 loc) 1.49 kB
const DEFAULT_SELECTOR = { rotation: true, zoom: true, }; function hasOwn(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } export function getWSIProjectionPresentation(snapshot, selector) { const target = {}; const wsiSelector = selector ?? DEFAULT_SELECTOR; if (wsiSelector.zoom) { target.zoom = snapshot.presentation.zoom; } if (wsiSelector.rotation) { target.rotation = snapshot.presentation.rotation; } return target; } export function withWSIProjectionPresentation(snapshot, presentation, options = {}) { const hasZoom = hasOwn(presentation, 'zoom'); const hasRotation = hasOwn(presentation, 'rotation'); const nextZoom = Math.max(presentation.zoom ?? snapshot.presentation.zoom ?? snapshot.viewState.zoom ?? 1, 0.001); let nextViewState = { ...snapshot.viewState, centerIndex: snapshot.viewState.centerIndex ? [snapshot.viewState.centerIndex[0], snapshot.viewState.centerIndex[1]] : undefined, }; if (hasZoom) { if (snapshot.resolvedView) { nextViewState = { ...snapshot.resolvedView.withZoom(nextZoom, options.anchorCanvas).state .viewState, }; } else { nextViewState.zoom = nextZoom; } } if (hasRotation) { nextViewState.rotation = presentation.rotation ?? 0; } return nextViewState; }