UNPKG

@cornerstonejs/core

Version:
67 lines (66 loc) 2.37 kB
import { normalizeVideoViewState } from './videoViewportCamera.js'; const DEFAULT_SELECTOR = { rotation: true, zoom: true, pan: true, }; function hasOwn(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } export function getVideoProjectionPresentation(snapshot, selector) { const target = {}; const videoSelector = selector ?? DEFAULT_SELECTOR; const zoom = snapshot.presentation.zoom ?? 1; if (videoSelector.rotation) { target.rotation = snapshot.presentation.rotation ?? 0; } if (videoSelector.zoom) { target.zoom = zoom; } if (videoSelector.pan) { const pan = snapshot.presentation.rawPan; target.pan = [pan[0] / zoom, pan[1] / zoom]; } return target; } export function withVideoProjectionPresentation(snapshot, presentation, options = {}) { const viewState = snapshot.viewState ?? {}; const hasZoom = hasOwn(presentation, 'zoom'); const hasPan = hasOwn(presentation, 'pan'); const hasRotation = hasOwn(presentation, 'rotation'); const nextZoom = Math.max(presentation.zoom ?? snapshot.presentation.zoom ?? viewState.scale ?? 1, 0.001); let resolvedView = snapshot.resolvedView; let nextViewState = normalizeVideoViewState({ ...viewState, ...(hasRotation ? { rotation: presentation.rotation ?? 0 } : {}), }); if (hasZoom) { if (resolvedView) { resolvedView = resolvedView.withZoom(nextZoom, options.anchorCanvas); nextViewState = normalizeVideoViewState({ ...resolvedView.state?.viewState, ...(hasRotation ? { rotation: presentation.rotation ?? 0 } : {}), }); } else { nextViewState = normalizeVideoViewState({ ...nextViewState, scale: nextZoom, scaleMode: 'fit', }); } } if (hasPan && presentation.pan) { const targetPan = [ presentation.pan[0] * nextZoom, presentation.pan[1] * nextZoom, ]; if (resolvedView) { nextViewState = normalizeVideoViewState({ ...resolvedView.withPan(targetPan).state?.viewState, ...(hasRotation ? { rotation: presentation.rotation ?? 0 } : {}), }); } } return nextViewState; }