@cornerstonejs/tools 2.0.0-beta.2 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/drawingSvg/getSvgDrawingHelper.js +1 -1
- package/dist/cjs/drawingSvg/getSvgDrawingHelper.js.map +1 -1
- package/dist/cjs/enums/Events.d.ts +1 -0
- package/dist/cjs/enums/Events.js +1 -0
- package/dist/cjs/enums/Events.js.map +1 -1
- package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDown.js +6 -1
- package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
- package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.d.ts +2 -0
- package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js +41 -0
- package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js.map +1 -0
- package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.d.ts +3 -0
- package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +39 -0
- package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -0
- package/dist/cjs/eventListeners/mouse/mouseDownListener.js +5 -1
- package/dist/cjs/eventListeners/mouse/mouseDownListener.js.map +1 -1
- package/dist/cjs/eventListeners/mouse/mouseMoveListener.js +5 -1
- package/dist/cjs/eventListeners/mouse/mouseMoveListener.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +5 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/store/ToolGroupManager/ToolGroup.d.ts +2 -0
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js +35 -0
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/cjs/synchronizers/callbacks/stackImageSyncCallback.js +1 -1
- package/dist/cjs/synchronizers/callbacks/stackImageSyncCallback.js.map +1 -1
- package/dist/cjs/tools/AdvancedMagnifyTool.d.ts +36 -0
- package/dist/cjs/tools/AdvancedMagnifyTool.js +448 -0
- package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -0
- package/dist/cjs/tools/AdvancedMagnifyViewport.d.ts +76 -0
- package/dist/cjs/tools/AdvancedMagnifyViewport.js +352 -0
- package/dist/cjs/tools/AdvancedMagnifyViewport.js.map +1 -0
- package/dist/cjs/tools/AdvancedMagnifyViewportManager.d.ts +36 -0
- package/dist/cjs/tools/AdvancedMagnifyViewportManager.js +133 -0
- package/dist/cjs/tools/AdvancedMagnifyViewportManager.js.map +1 -0
- package/dist/cjs/tools/MagnifyTool.js +2 -2
- package/dist/cjs/tools/MagnifyTool.js.map +1 -1
- package/dist/cjs/tools/OrientationMarkerTool.d.ts +88 -0
- package/dist/cjs/tools/OrientationMarkerTool.js +193 -0
- package/dist/cjs/tools/OrientationMarkerTool.js.map +1 -0
- package/dist/cjs/tools/OverlayGridTool.d.ts +31 -0
- package/dist/cjs/tools/OverlayGridTool.js +170 -0
- package/dist/cjs/tools/OverlayGridTool.js.map +1 -0
- package/dist/cjs/tools/ReferenceLinesTool.d.ts +3 -0
- package/dist/cjs/tools/ReferenceLinesTool.js +71 -2
- package/dist/cjs/tools/ReferenceLinesTool.js.map +1 -1
- package/dist/cjs/tools/annotation/AngleTool.js +2 -1
- package/dist/cjs/tools/annotation/AngleTool.js.map +1 -1
- package/dist/cjs/tools/annotation/BidirectionalTool.js +1 -1
- package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/cjs/tools/annotation/CircleROITool.d.ts +1 -2
- package/dist/cjs/tools/annotation/CircleROITool.js +8 -8
- package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/CobbAngleTool.d.ts +31 -5
- package/dist/cjs/tools/annotation/CobbAngleTool.js +268 -71
- package/dist/cjs/tools/annotation/CobbAngleTool.js.map +1 -1
- package/dist/cjs/tools/annotation/DragProbeTool.js +4 -3
- package/dist/cjs/tools/annotation/DragProbeTool.js.map +1 -1
- package/dist/cjs/tools/annotation/EllipticalROITool.d.ts +2 -3
- package/dist/cjs/tools/annotation/EllipticalROITool.js +20 -16
- package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/LengthTool.js +1 -1
- package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +1 -2
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +22 -9
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/ProbeTool.d.ts +1 -2
- package/dist/cjs/tools/annotation/ProbeTool.js +10 -9
- package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/cjs/tools/annotation/RectangleROITool.d.ts +1 -1
- package/dist/cjs/tools/annotation/RectangleROITool.js +9 -9
- package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/cjs/tools/base/AnnotationDisplayTool.js +4 -0
- package/dist/cjs/tools/base/AnnotationDisplayTool.js.map +1 -1
- package/dist/cjs/tools/base/AnnotationTool.d.ts +1 -1
- package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +3 -0
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/cjs/tools/index.d.ts +4 -1
- package/dist/cjs/tools/index.js +7 -1
- package/dist/cjs/tools/index.js.map +1 -1
- package/dist/cjs/types/EventTypes.d.ts +9 -1
- package/dist/cjs/types/IToolGroup.d.ts +3 -0
- package/dist/cjs/types/ToolAction.d.ts +8 -0
- package/dist/cjs/types/ToolAction.js +3 -0
- package/dist/cjs/types/ToolAction.js.map +1 -0
- package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +55 -0
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/utilities/getModalityUnit.js +5 -2
- package/dist/cjs/utilities/getModalityUnit.js.map +1 -1
- package/dist/cjs/utilities/index.d.ts +2 -2
- package/dist/cjs/utilities/index.js +4 -3
- package/dist/cjs/utilities/index.js.map +1 -1
- package/dist/cjs/utilities/math/angle/angleBetweenLines.d.ts +3 -1
- package/dist/cjs/utilities/math/angle/angleBetweenLines.js +18 -1
- package/dist/cjs/utilities/math/angle/angleBetweenLines.js.map +1 -1
- package/dist/cjs/utilities/stackPrefetch/index.d.ts +3 -2
- package/dist/cjs/utilities/stackPrefetch/index.js +8 -6
- package/dist/cjs/utilities/stackPrefetch/index.js.map +1 -1
- package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.d.ts +16 -0
- package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js +227 -0
- package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -0
- package/dist/cjs/utilities/stackPrefetch/stackPrefetch.d.ts +7 -1
- package/dist/cjs/utilities/stackPrefetch/stackPrefetch.js +23 -93
- package/dist/cjs/utilities/stackPrefetch/stackPrefetch.js.map +1 -1
- package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.d.ts +14 -0
- package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js +85 -0
- package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -0
- package/dist/esm/drawingSvg/getSvgDrawingHelper.js +1 -1
- package/dist/esm/drawingSvg/getSvgDrawingHelper.js.map +1 -1
- package/dist/esm/enums/Events.d.ts +1 -0
- package/dist/esm/enums/Events.js +1 -0
- package/dist/esm/enums/Events.js.map +1 -1
- package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js +6 -1
- package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
- package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.d.ts +2 -0
- package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js +35 -0
- package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js.map +1 -0
- package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.d.ts +3 -0
- package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +32 -0
- package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -0
- package/dist/esm/eventListeners/mouse/mouseDownListener.js +5 -1
- package/dist/esm/eventListeners/mouse/mouseDownListener.js.map +1 -1
- package/dist/esm/eventListeners/mouse/mouseMoveListener.js +5 -1
- package/dist/esm/eventListeners/mouse/mouseMoveListener.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/store/ToolGroupManager/ToolGroup.d.ts +2 -0
- package/dist/esm/store/ToolGroupManager/ToolGroup.js +35 -1
- package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/esm/synchronizers/callbacks/stackImageSyncCallback.js +1 -1
- package/dist/esm/synchronizers/callbacks/stackImageSyncCallback.js.map +1 -1
- package/dist/esm/tools/AdvancedMagnifyTool.d.ts +36 -0
- package/dist/esm/tools/AdvancedMagnifyTool.js +440 -0
- package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -0
- package/dist/esm/tools/AdvancedMagnifyViewport.d.ts +76 -0
- package/dist/esm/tools/AdvancedMagnifyViewport.js +346 -0
- package/dist/esm/tools/AdvancedMagnifyViewport.js.map +1 -0
- package/dist/esm/tools/AdvancedMagnifyViewportManager.d.ts +36 -0
- package/dist/esm/tools/AdvancedMagnifyViewportManager.js +128 -0
- package/dist/esm/tools/AdvancedMagnifyViewportManager.js.map +1 -0
- package/dist/esm/tools/MagnifyTool.js +2 -2
- package/dist/esm/tools/MagnifyTool.js.map +1 -1
- package/dist/esm/tools/OrientationMarkerTool.d.ts +88 -0
- package/dist/esm/tools/OrientationMarkerTool.js +185 -0
- package/dist/esm/tools/OrientationMarkerTool.js.map +1 -0
- package/dist/esm/tools/OverlayGridTool.d.ts +31 -0
- package/dist/esm/tools/OverlayGridTool.js +165 -0
- package/dist/esm/tools/OverlayGridTool.js.map +1 -0
- package/dist/esm/tools/ReferenceLinesTool.d.ts +3 -0
- package/dist/esm/tools/ReferenceLinesTool.js +71 -2
- package/dist/esm/tools/ReferenceLinesTool.js.map +1 -1
- package/dist/esm/tools/annotation/AngleTool.js +2 -1
- package/dist/esm/tools/annotation/AngleTool.js.map +1 -1
- package/dist/esm/tools/annotation/BidirectionalTool.js +1 -1
- package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/esm/tools/annotation/CircleROITool.d.ts +1 -2
- package/dist/esm/tools/annotation/CircleROITool.js +8 -8
- package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
- package/dist/esm/tools/annotation/CobbAngleTool.d.ts +31 -5
- package/dist/esm/tools/annotation/CobbAngleTool.js +275 -72
- package/dist/esm/tools/annotation/CobbAngleTool.js.map +1 -1
- package/dist/esm/tools/annotation/DragProbeTool.js +4 -3
- package/dist/esm/tools/annotation/DragProbeTool.js.map +1 -1
- package/dist/esm/tools/annotation/EllipticalROITool.d.ts +2 -3
- package/dist/esm/tools/annotation/EllipticalROITool.js +20 -16
- package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/esm/tools/annotation/LengthTool.js +1 -1
- package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.d.ts +1 -2
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +22 -9
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/ProbeTool.d.ts +1 -2
- package/dist/esm/tools/annotation/ProbeTool.js +10 -9
- package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/esm/tools/annotation/RectangleROITool.d.ts +1 -1
- package/dist/esm/tools/annotation/RectangleROITool.js +9 -9
- package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/esm/tools/base/AnnotationDisplayTool.js +3 -0
- package/dist/esm/tools/base/AnnotationDisplayTool.js.map +1 -1
- package/dist/esm/tools/base/AnnotationTool.d.ts +1 -1
- package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js +4 -1
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
- package/dist/esm/tools/index.d.ts +4 -1
- package/dist/esm/tools/index.js +4 -1
- package/dist/esm/tools/index.js.map +1 -1
- package/dist/esm/types/EventTypes.d.ts +9 -1
- package/dist/esm/types/IToolGroup.d.ts +3 -0
- package/dist/esm/types/ToolAction.d.ts +8 -0
- package/dist/esm/types/ToolAction.js +2 -0
- package/dist/esm/types/ToolAction.js.map +1 -0
- package/dist/esm/types/ToolSpecificAnnotationTypes.d.ts +55 -0
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utilities/getModalityUnit.js +5 -2
- package/dist/esm/utilities/getModalityUnit.js.map +1 -1
- package/dist/esm/utilities/index.d.ts +2 -2
- package/dist/esm/utilities/index.js +2 -2
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/math/angle/angleBetweenLines.d.ts +3 -1
- package/dist/esm/utilities/math/angle/angleBetweenLines.js +19 -2
- package/dist/esm/utilities/math/angle/angleBetweenLines.js.map +1 -1
- package/dist/esm/utilities/stackPrefetch/index.d.ts +3 -2
- package/dist/esm/utilities/stackPrefetch/index.js +3 -2
- package/dist/esm/utilities/stackPrefetch/index.js.map +1 -1
- package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.d.ts +16 -0
- package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +220 -0
- package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -0
- package/dist/esm/utilities/stackPrefetch/stackPrefetch.d.ts +7 -1
- package/dist/esm/utilities/stackPrefetch/stackPrefetch.js +12 -79
- package/dist/esm/utilities/stackPrefetch/stackPrefetch.js.map +1 -1
- package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.d.ts +14 -0
- package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js +77 -0
- package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/drawingSvg/getSvgDrawingHelper.ts +4 -1
- package/src/enums/Events.ts +9 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +11 -2
- package/src/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.ts +72 -0
- package/src/eventDispatchers/shared/getToolsWithActionsForMouseEvent.ts +66 -0
- package/src/eventListeners/mouse/mouseDownListener.ts +7 -1
- package/src/eventListeners/mouse/mouseMoveListener.ts +7 -1
- package/src/index.ts +6 -0
- package/src/store/ToolGroupManager/ToolGroup.ts +79 -2
- package/src/synchronizers/callbacks/stackImageSyncCallback.ts +1 -1
- package/src/tools/AdvancedMagnifyTool.ts +725 -0
- package/src/tools/AdvancedMagnifyViewport.ts +624 -0
- package/src/tools/AdvancedMagnifyViewportManager.ts +291 -0
- package/src/tools/MagnifyTool.ts +2 -2
- package/src/tools/OrientationMarkerTool.ts +235 -0
- package/src/tools/OverlayGridTool.ts +357 -0
- package/src/tools/ReferenceLinesTool.ts +131 -3
- package/src/tools/annotation/AngleTool.ts +4 -1
- package/src/tools/annotation/BidirectionalTool.ts +1 -1
- package/src/tools/annotation/CircleROITool.ts +13 -20
- package/src/tools/annotation/CobbAngleTool.ts +422 -99
- package/src/tools/annotation/DragProbeTool.ts +6 -13
- package/src/tools/annotation/EllipticalROITool.ts +28 -29
- package/src/tools/annotation/LengthTool.ts +1 -1
- package/src/tools/annotation/PlanarFreehandROITool.ts +35 -20
- package/src/tools/annotation/ProbeTool.ts +17 -30
- package/src/tools/annotation/RectangleROITool.ts +15 -19
- package/src/tools/base/AnnotationDisplayTool.ts +4 -0
- package/src/tools/base/AnnotationTool.ts +2 -1
- package/src/tools/displayTools/Contour/contourDisplay.ts +8 -0
- package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +1 -1
- package/src/tools/index.ts +6 -0
- package/src/types/EventTypes.ts +23 -0
- package/src/types/IToolGroup.ts +7 -0
- package/src/types/ToolAction.ts +54 -0
- package/src/types/ToolSpecificAnnotationTypes.ts +58 -0
- package/src/types/index.ts +2 -0
- package/src/utilities/getModalityUnit.ts +8 -2
- package/src/utilities/index.ts +2 -1
- package/src/utilities/math/angle/angleBetweenLines.ts +39 -9
- package/src/utilities/stackPrefetch/index.ts +3 -7
- package/src/utilities/stackPrefetch/stackContextPrefetch.ts +380 -0
- package/src/utilities/stackPrefetch/stackPrefetch.ts +29 -151
- package/src/utilities/stackPrefetch/stackPrefetchUtils.ts +114 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
import { vec2, vec3 } from 'gl-matrix';
|
|
2
|
+
import {
|
|
3
|
+
getEnabledElement,
|
|
4
|
+
eventTarget,
|
|
5
|
+
utilities as csUtils,
|
|
6
|
+
} from '@cornerstonejs/core';
|
|
7
|
+
import type { Types } from '@cornerstonejs/core';
|
|
8
|
+
import {
|
|
9
|
+
SegmentationRepresentations,
|
|
10
|
+
ToolModes,
|
|
11
|
+
Events as cstEvents,
|
|
12
|
+
} from '../enums';
|
|
13
|
+
import { ToolGroupManager, state } from '../store';
|
|
14
|
+
import { debounce } from '../utilities';
|
|
15
|
+
import { ToolModeChangedEventType } from '../types/EventTypes';
|
|
16
|
+
import { segmentation } from '..';
|
|
17
|
+
import { EventTypes, IToolGroup } from '../types';
|
|
18
|
+
import {
|
|
19
|
+
AnnotationTool,
|
|
20
|
+
AdvancedMagnifyTool,
|
|
21
|
+
SegmentationDisplayTool,
|
|
22
|
+
} from './';
|
|
23
|
+
import { distanceToPoint } from '../utilities/math/point';
|
|
24
|
+
|
|
25
|
+
const MAGNIFY_CLASSNAME = 'advancedMagnifyTool';
|
|
26
|
+
const MAGNIFY_VIEWPORT_INITIAL_RADIUS = 125;
|
|
27
|
+
|
|
28
|
+
// TODO: find a better to identify segmentation actors
|
|
29
|
+
const isSegmentation = (actor) => actor.uid !== actor.referenceId;
|
|
30
|
+
|
|
31
|
+
export type AutoPanCallbackData = {
|
|
32
|
+
points: {
|
|
33
|
+
currentPosition: {
|
|
34
|
+
canvas: Types.Point2;
|
|
35
|
+
world: Types.Point3;
|
|
36
|
+
};
|
|
37
|
+
newPosition: {
|
|
38
|
+
canvas: Types.Point2;
|
|
39
|
+
world: Types.Point3;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
delta: {
|
|
43
|
+
canvas: Types.Point2;
|
|
44
|
+
world: Types.Point3;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type AutoPanCallback = (data: AutoPanCallbackData) => void;
|
|
49
|
+
|
|
50
|
+
class AdvancedMagnifyViewport {
|
|
51
|
+
private _viewportId: string;
|
|
52
|
+
private _sourceEnabledElement: Types.IEnabledElement;
|
|
53
|
+
private _enabledElement: Types.IEnabledElement = null;
|
|
54
|
+
private _sourceToolGroup: IToolGroup = null;
|
|
55
|
+
private _magnifyToolGroup: IToolGroup = null;
|
|
56
|
+
private _isViewportReady = false;
|
|
57
|
+
private _radius = 0;
|
|
58
|
+
private _resized = false;
|
|
59
|
+
private _resizeViewportAsync: () => void;
|
|
60
|
+
private _canAutoPan = false;
|
|
61
|
+
private _autoPan: {
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
padding: number;
|
|
64
|
+
callback: AutoPanCallback;
|
|
65
|
+
};
|
|
66
|
+
public position: Types.Point2;
|
|
67
|
+
public zoomFactor: number;
|
|
68
|
+
public visible: boolean;
|
|
69
|
+
|
|
70
|
+
constructor({
|
|
71
|
+
magnifyViewportId,
|
|
72
|
+
sourceEnabledElement,
|
|
73
|
+
radius = MAGNIFY_VIEWPORT_INITIAL_RADIUS,
|
|
74
|
+
position = [0, 0],
|
|
75
|
+
zoomFactor,
|
|
76
|
+
autoPan,
|
|
77
|
+
}: {
|
|
78
|
+
magnifyViewportId?: string;
|
|
79
|
+
sourceEnabledElement: Types.IEnabledElement;
|
|
80
|
+
radius?: number;
|
|
81
|
+
position?: Types.Point2;
|
|
82
|
+
zoomFactor: number;
|
|
83
|
+
autoPan: {
|
|
84
|
+
enabled: boolean;
|
|
85
|
+
padding: number;
|
|
86
|
+
callback: AutoPanCallback;
|
|
87
|
+
};
|
|
88
|
+
}) {
|
|
89
|
+
// Private properties
|
|
90
|
+
this._viewportId = magnifyViewportId ?? csUtils.uuidv4();
|
|
91
|
+
this._sourceEnabledElement = sourceEnabledElement;
|
|
92
|
+
this._autoPan = autoPan;
|
|
93
|
+
|
|
94
|
+
// Pulic properties
|
|
95
|
+
this.radius = radius;
|
|
96
|
+
this.position = position;
|
|
97
|
+
this.zoomFactor = zoomFactor;
|
|
98
|
+
this.visible = true;
|
|
99
|
+
|
|
100
|
+
this._browserMouseDownCallback = this._browserMouseDownCallback.bind(this);
|
|
101
|
+
this._browserMouseUpCallback = this._browserMouseUpCallback.bind(this);
|
|
102
|
+
this._handleToolModeChanged = this._handleToolModeChanged.bind(this);
|
|
103
|
+
this._mouseDragCallback = this._mouseDragCallback.bind(this);
|
|
104
|
+
this._resizeViewportAsync = <() => void>(
|
|
105
|
+
debounce(this._resizeViewport.bind(this), 1)
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
this._initialize();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public get sourceEnabledElement() {
|
|
112
|
+
return this._sourceEnabledElement;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public get viewportId() {
|
|
116
|
+
return this._viewportId;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public get radius() {
|
|
120
|
+
return this._radius;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public set radius(radius: number) {
|
|
124
|
+
// Just moving the magnifying glass around may change its radius
|
|
125
|
+
// by very small amount due to floating number precision
|
|
126
|
+
if (Math.abs(this._radius - radius) > 0.00001) {
|
|
127
|
+
this._radius = radius;
|
|
128
|
+
this._resized = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public update() {
|
|
133
|
+
const { radius, position, visible } = this;
|
|
134
|
+
const { viewport } = this._enabledElement;
|
|
135
|
+
const { element } = viewport;
|
|
136
|
+
const size = 2 * radius;
|
|
137
|
+
const [x, y] = position;
|
|
138
|
+
|
|
139
|
+
if (this._resized) {
|
|
140
|
+
this._resizeViewportAsync();
|
|
141
|
+
this._resized = false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Object.assign(element.style, {
|
|
145
|
+
display: visible ? 'block' : 'hidden',
|
|
146
|
+
width: `${size}px`,
|
|
147
|
+
height: `${size}px`,
|
|
148
|
+
left: `${-radius}px`,
|
|
149
|
+
top: `${-radius}px`,
|
|
150
|
+
transform: `translate(${x}px, ${y}px)`,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (this._isViewportReady) {
|
|
154
|
+
this._syncViewports();
|
|
155
|
+
viewport.render();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public dispose() {
|
|
160
|
+
const { viewport } = this._enabledElement;
|
|
161
|
+
const { element } = viewport;
|
|
162
|
+
const renderingEngine = viewport.getRenderingEngine();
|
|
163
|
+
|
|
164
|
+
this._removeEventListeners(element);
|
|
165
|
+
renderingEngine.disableElement(viewport.id);
|
|
166
|
+
|
|
167
|
+
if (element.parentNode) {
|
|
168
|
+
element.parentNode.removeChild(element);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private _handleToolModeChanged(evt: ToolModeChangedEventType) {
|
|
173
|
+
const { _magnifyToolGroup: magnifyToolGroup } = this;
|
|
174
|
+
const { toolGroupId, toolName, mode, toolBindingsOptions } = evt.detail;
|
|
175
|
+
|
|
176
|
+
if (this._sourceToolGroup?.id !== toolGroupId) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
switch (mode) {
|
|
181
|
+
case ToolModes.Active:
|
|
182
|
+
magnifyToolGroup.setToolActive(toolName, toolBindingsOptions);
|
|
183
|
+
break;
|
|
184
|
+
case ToolModes.Passive:
|
|
185
|
+
magnifyToolGroup.setToolPassive(toolName);
|
|
186
|
+
break;
|
|
187
|
+
case ToolModes.Enabled:
|
|
188
|
+
magnifyToolGroup.setToolEnabled(toolName);
|
|
189
|
+
break;
|
|
190
|
+
case ToolModes.Disabled:
|
|
191
|
+
magnifyToolGroup.setToolDisabled(toolName);
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
throw new Error(`Unknow tool mode (${mode})`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Children elements need to inherit border-radius otherwise the canvas will
|
|
199
|
+
// trigger events when moving/dragging/clicking on the corners outside of the
|
|
200
|
+
// border (circle) region.
|
|
201
|
+
private _inheritBorderRadius(magnifyElement) {
|
|
202
|
+
const viewport = magnifyElement.querySelector('.viewport-element');
|
|
203
|
+
const canvas = magnifyElement.querySelector('.cornerstone-canvas');
|
|
204
|
+
|
|
205
|
+
viewport.style.borderRadius = 'inherit';
|
|
206
|
+
canvas.style.borderRadius = 'inherit';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private _createViewportNode(): HTMLDivElement {
|
|
210
|
+
const magnifyElement = document.createElement('div');
|
|
211
|
+
const { radius } = this;
|
|
212
|
+
const size = radius * 2;
|
|
213
|
+
|
|
214
|
+
magnifyElement.classList.add(MAGNIFY_CLASSNAME);
|
|
215
|
+
|
|
216
|
+
// Update the style and move the element out of the screen with "transforms"
|
|
217
|
+
// to make it "invisible" and preserving its size because when "display" is
|
|
218
|
+
// set to "none" both "offsetWidth" and "offsetHeight" returns zero. Another
|
|
219
|
+
// way would be setting "visibility" to "hidden" but "transforms" is used
|
|
220
|
+
// because it is already being updated when update() is called
|
|
221
|
+
Object.assign(magnifyElement.style, {
|
|
222
|
+
display: 'block',
|
|
223
|
+
width: `${size}px`,
|
|
224
|
+
height: `${size}px`,
|
|
225
|
+
position: 'absolute',
|
|
226
|
+
overflow: 'hidden',
|
|
227
|
+
borderRadius: '50%',
|
|
228
|
+
boxSizing: 'border-box',
|
|
229
|
+
left: `${-radius}px`,
|
|
230
|
+
top: `${-radius}px`,
|
|
231
|
+
transform: `translate(-1000px, -1000px)`,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return magnifyElement;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private _convertZoomFactorToParalellScale(
|
|
238
|
+
viewport,
|
|
239
|
+
magnifyViewport,
|
|
240
|
+
zoomFactor
|
|
241
|
+
) {
|
|
242
|
+
const { parallelScale } = viewport.getCamera();
|
|
243
|
+
const canvasRatio =
|
|
244
|
+
magnifyViewport.canvas.offsetWidth / viewport.canvas.offsetWidth;
|
|
245
|
+
|
|
246
|
+
return parallelScale * (1 / zoomFactor) * canvasRatio;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private _isStackViewport(
|
|
250
|
+
viewport: Types.IViewport
|
|
251
|
+
): viewport is Types.IStackViewport {
|
|
252
|
+
return 'setStack' in viewport;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private _isVolumeViewport(
|
|
256
|
+
viewport: Types.IViewport
|
|
257
|
+
): viewport is Types.IVolumeViewport {
|
|
258
|
+
return 'addVolumes' in viewport;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private _cloneToolGroups(
|
|
262
|
+
sourceViewport: Types.IViewport,
|
|
263
|
+
magnifyViewport: Types.IViewport
|
|
264
|
+
) {
|
|
265
|
+
const sourceActors = sourceViewport.getActors();
|
|
266
|
+
const magnifyToolGroupId = `${magnifyViewport.id}-toolGroup`;
|
|
267
|
+
const sourceToolGroup = ToolGroupManager.getToolGroupForViewport(
|
|
268
|
+
sourceViewport.id,
|
|
269
|
+
sourceViewport.renderingEngineId
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const magnifyToolGroup = sourceToolGroup.clone(
|
|
273
|
+
magnifyToolGroupId,
|
|
274
|
+
(toolName) => {
|
|
275
|
+
const toolInstance = sourceToolGroup.getToolInstance(toolName);
|
|
276
|
+
const isAnnotationTool =
|
|
277
|
+
toolInstance instanceof AnnotationTool &&
|
|
278
|
+
!(toolInstance instanceof AdvancedMagnifyTool);
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
isAnnotationTool || toolName === SegmentationDisplayTool.toolName
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
magnifyToolGroup.addViewport(
|
|
287
|
+
magnifyViewport.id,
|
|
288
|
+
magnifyViewport.renderingEngineId
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
sourceActors.filter(isSegmentation).forEach((actor) => {
|
|
292
|
+
segmentation.addSegmentationRepresentations(magnifyToolGroupId, [
|
|
293
|
+
{
|
|
294
|
+
segmentationId: actor.referenceId,
|
|
295
|
+
type: SegmentationRepresentations.Labelmap,
|
|
296
|
+
},
|
|
297
|
+
]);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
return { sourceToolGroup, magnifyToolGroup };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private _cloneStack(
|
|
304
|
+
sourceViewport: Types.IStackViewport,
|
|
305
|
+
magnifyViewport: Types.IStackViewport
|
|
306
|
+
): void {
|
|
307
|
+
const imageIds = sourceViewport.getImageIds();
|
|
308
|
+
|
|
309
|
+
magnifyViewport.setStack(imageIds).then(() => {
|
|
310
|
+
this._isViewportReady = true;
|
|
311
|
+
this.update();
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private _cloneVolumes(
|
|
316
|
+
sourceViewport: Types.IVolumeViewport,
|
|
317
|
+
magnifyViewport: Types.IVolumeViewport
|
|
318
|
+
): Types.IVolumeViewport {
|
|
319
|
+
const actors = sourceViewport.getActors();
|
|
320
|
+
const volumeInputArray: Types.IVolumeInput[] = actors
|
|
321
|
+
.filter((actor) => !isSegmentation(actor))
|
|
322
|
+
.map((actor) => ({ volumeId: actor.uid }));
|
|
323
|
+
|
|
324
|
+
magnifyViewport.setVolumes(volumeInputArray).then(() => {
|
|
325
|
+
this._isViewportReady = true;
|
|
326
|
+
this.update();
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
return magnifyViewport;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private _cloneViewport(sourceViewport, magnifyElement) {
|
|
333
|
+
const { viewportId: magnifyViewportId } = this;
|
|
334
|
+
const renderingEngine =
|
|
335
|
+
sourceViewport.getRenderingEngine() as Types.IRenderingEngine;
|
|
336
|
+
|
|
337
|
+
const { options: sourceViewportOptions } = sourceViewport;
|
|
338
|
+
const viewportInput = {
|
|
339
|
+
element: magnifyElement,
|
|
340
|
+
viewportId: magnifyViewportId,
|
|
341
|
+
type: sourceViewport.type,
|
|
342
|
+
defaultOptions: { ...sourceViewportOptions },
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
renderingEngine.enableElement(viewportInput);
|
|
346
|
+
|
|
347
|
+
const magnifyViewport = <Types.IViewport>(
|
|
348
|
+
renderingEngine.getViewport(magnifyViewportId)
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
if (this._isStackViewport(sourceViewport)) {
|
|
352
|
+
this._cloneStack(sourceViewport, magnifyViewport as Types.IStackViewport);
|
|
353
|
+
} else if (this._isVolumeViewport(sourceViewport)) {
|
|
354
|
+
this._cloneVolumes(
|
|
355
|
+
sourceViewport,
|
|
356
|
+
magnifyViewport as Types.IVolumeViewport
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Prevent handling events outside of the magnifying glass because it has rounded border
|
|
361
|
+
this._inheritBorderRadius(magnifyElement);
|
|
362
|
+
|
|
363
|
+
const toolGroups = this._cloneToolGroups(sourceViewport, magnifyViewport);
|
|
364
|
+
|
|
365
|
+
this._sourceToolGroup = toolGroups.sourceToolGroup;
|
|
366
|
+
this._magnifyToolGroup = toolGroups.magnifyToolGroup;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
private _cancelMouseEventCallback(evt): void {
|
|
370
|
+
evt.stopPropagation();
|
|
371
|
+
evt.preventDefault();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
private _browserMouseUpCallback(evt) {
|
|
375
|
+
const { element } = this._enabledElement.viewport;
|
|
376
|
+
|
|
377
|
+
document.removeEventListener('mouseup', this._browserMouseUpCallback);
|
|
378
|
+
|
|
379
|
+
// Restrict the scope of magnifying glass events again
|
|
380
|
+
element.addEventListener('mouseup', this._cancelMouseEventCallback);
|
|
381
|
+
element.addEventListener('mousemove', this._cancelMouseEventCallback);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
private _browserMouseDownCallback(evt) {
|
|
385
|
+
const { element } = this._enabledElement.viewport;
|
|
386
|
+
|
|
387
|
+
// Enable auto pan only when user clicks inside of the magnifying glass
|
|
388
|
+
// viewport otherwise it can move when interacting with annotations outside
|
|
389
|
+
// of the magnifying glass or when trying to move/resize it.
|
|
390
|
+
this._canAutoPan = !!evt.target?.closest('.advancedMagnifyTool');
|
|
391
|
+
|
|
392
|
+
// Wait for the mouseup event to restrict the scope of magnifying glass events again
|
|
393
|
+
document.addEventListener('mouseup', this._browserMouseUpCallback);
|
|
394
|
+
|
|
395
|
+
// Allow mouseup and mousemove events to make it possible to manipulate the
|
|
396
|
+
// tool when passing the mouse over the magnifying glass (dragging a handle).
|
|
397
|
+
// Just relying on state.isInteractingWithTool does not work because there
|
|
398
|
+
// is a 400ms delay to handle double click (see mouseDownListener) which
|
|
399
|
+
// makes the magnifying glass unresponsive for that amount of time.
|
|
400
|
+
element.removeEventListener('mouseup', this._cancelMouseEventCallback);
|
|
401
|
+
element.removeEventListener('mousemove', this._cancelMouseEventCallback);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
private _mouseDragCallback(evt: EventTypes.InteractionEventType) {
|
|
405
|
+
if (!state.isInteractingWithTool) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const { _autoPan: autoPan } = this;
|
|
410
|
+
|
|
411
|
+
if (!autoPan.enabled || !this._canAutoPan) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const { currentPoints } = evt.detail;
|
|
416
|
+
const { viewport } = this._enabledElement;
|
|
417
|
+
const { canvasToWorld } = viewport;
|
|
418
|
+
const { canvas: canvasCurrent } = currentPoints;
|
|
419
|
+
const { radius: magnifyRadius } = this;
|
|
420
|
+
const canvasCenter: Types.Point2 = [magnifyRadius, magnifyRadius];
|
|
421
|
+
const dist = distanceToPoint(canvasCenter, canvasCurrent);
|
|
422
|
+
const maxDist = magnifyRadius - autoPan.padding;
|
|
423
|
+
|
|
424
|
+
// No need to pan if it is not close to the border
|
|
425
|
+
if (dist <= maxDist) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const panDist = dist - maxDist;
|
|
430
|
+
const canvasDeltaPos = vec2.sub(
|
|
431
|
+
vec2.create(),
|
|
432
|
+
canvasCurrent,
|
|
433
|
+
canvasCenter
|
|
434
|
+
) as Types.Point2;
|
|
435
|
+
|
|
436
|
+
vec2.normalize(canvasDeltaPos, canvasDeltaPos);
|
|
437
|
+
vec2.scale(canvasDeltaPos, canvasDeltaPos, panDist);
|
|
438
|
+
|
|
439
|
+
const newCanvasPosition = vec2.add(
|
|
440
|
+
vec2.create(),
|
|
441
|
+
this.position,
|
|
442
|
+
canvasDeltaPos
|
|
443
|
+
) as Types.Point2;
|
|
444
|
+
const currentWorldPos = canvasToWorld(this.position);
|
|
445
|
+
const newWorldPos = canvasToWorld(newCanvasPosition);
|
|
446
|
+
const worldDeltaPos = vec3.sub(
|
|
447
|
+
vec3.create(),
|
|
448
|
+
newWorldPos,
|
|
449
|
+
currentWorldPos
|
|
450
|
+
) as Types.Point3;
|
|
451
|
+
|
|
452
|
+
const autoPanCallbackData: AutoPanCallbackData = {
|
|
453
|
+
points: {
|
|
454
|
+
currentPosition: {
|
|
455
|
+
canvas: this.position,
|
|
456
|
+
world: currentWorldPos,
|
|
457
|
+
},
|
|
458
|
+
newPosition: {
|
|
459
|
+
canvas: newCanvasPosition,
|
|
460
|
+
world: newWorldPos,
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
delta: {
|
|
464
|
+
canvas: canvasDeltaPos,
|
|
465
|
+
world: worldDeltaPos,
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
autoPan.callback(autoPanCallbackData);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
private _addBrowserEventListeners(element) {
|
|
473
|
+
// mousedown on document is handled in the capture phase because the other
|
|
474
|
+
// mousedown event listener added to the magnifying glass element does not
|
|
475
|
+
// allow the event to buble up and reach the document.
|
|
476
|
+
document.addEventListener(
|
|
477
|
+
'mousedown',
|
|
478
|
+
this._browserMouseDownCallback,
|
|
479
|
+
true
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
// All mouse events should not buble up avoiding the source viewport from
|
|
483
|
+
// handling those events resulting in unexpected behaviors.
|
|
484
|
+
element.addEventListener('mousedown', this._cancelMouseEventCallback);
|
|
485
|
+
element.addEventListener('mouseup', this._cancelMouseEventCallback);
|
|
486
|
+
element.addEventListener('mousemove', this._cancelMouseEventCallback);
|
|
487
|
+
element.addEventListener('dblclick', this._cancelMouseEventCallback);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
private _removeBrowserEventListeners(element) {
|
|
491
|
+
document.removeEventListener(
|
|
492
|
+
'mousedown',
|
|
493
|
+
this._browserMouseDownCallback,
|
|
494
|
+
true
|
|
495
|
+
);
|
|
496
|
+
document.removeEventListener('mouseup', this._browserMouseUpCallback);
|
|
497
|
+
|
|
498
|
+
element.removeEventListener('mousedown', this._cancelMouseEventCallback);
|
|
499
|
+
element.removeEventListener('mouseup', this._cancelMouseEventCallback);
|
|
500
|
+
element.removeEventListener('mousemove', this._cancelMouseEventCallback);
|
|
501
|
+
element.removeEventListener('dblclick', this._cancelMouseEventCallback);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
private _addEventListeners(element) {
|
|
505
|
+
eventTarget.addEventListener(
|
|
506
|
+
cstEvents.TOOL_MODE_CHANGED,
|
|
507
|
+
this._handleToolModeChanged
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
element.addEventListener(
|
|
511
|
+
cstEvents.MOUSE_MOVE,
|
|
512
|
+
this._mouseDragCallback as EventListener
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
element.addEventListener(
|
|
516
|
+
cstEvents.MOUSE_DRAG,
|
|
517
|
+
this._mouseDragCallback as EventListener
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
this._addBrowserEventListeners(element);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private _removeEventListeners(element) {
|
|
524
|
+
eventTarget.removeEventListener(
|
|
525
|
+
cstEvents.TOOL_MODE_CHANGED,
|
|
526
|
+
this._handleToolModeChanged
|
|
527
|
+
);
|
|
528
|
+
|
|
529
|
+
element.addEventListener(
|
|
530
|
+
cstEvents.MOUSE_MOVE,
|
|
531
|
+
this._mouseDragCallback as EventListener
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
element.addEventListener(
|
|
535
|
+
cstEvents.MOUSE_DRAG,
|
|
536
|
+
this._mouseDragCallback as EventListener
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
this._removeBrowserEventListeners(element);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
private _initialize() {
|
|
543
|
+
const { _sourceEnabledElement: sourceEnabledElement } = this;
|
|
544
|
+
const { viewport: sourceViewport } = sourceEnabledElement;
|
|
545
|
+
const { canvas: sourceCanvas } = sourceViewport;
|
|
546
|
+
const magnifyElement = this._createViewportNode();
|
|
547
|
+
|
|
548
|
+
sourceCanvas.parentNode.appendChild(magnifyElement);
|
|
549
|
+
|
|
550
|
+
this._addEventListeners(magnifyElement);
|
|
551
|
+
this._cloneViewport(sourceViewport, magnifyElement);
|
|
552
|
+
this._enabledElement = getEnabledElement(magnifyElement);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
private _syncViewportsCameras(sourceViewport, magnifyViewport) {
|
|
556
|
+
const worldPos = sourceViewport.canvasToWorld(this.position);
|
|
557
|
+
|
|
558
|
+
// Use the original viewport for the base for parallelScale
|
|
559
|
+
const parallelScale = this._convertZoomFactorToParalellScale(
|
|
560
|
+
sourceViewport,
|
|
561
|
+
magnifyViewport,
|
|
562
|
+
this.zoomFactor
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
const { focalPoint, position, viewPlaneNormal } =
|
|
566
|
+
magnifyViewport.getCamera();
|
|
567
|
+
|
|
568
|
+
const distance = Math.sqrt(
|
|
569
|
+
Math.pow(focalPoint[0] - position[0], 2) +
|
|
570
|
+
Math.pow(focalPoint[1] - position[1], 2) +
|
|
571
|
+
Math.pow(focalPoint[2] - position[2], 2)
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
const updatedFocalPoint = <Types.Point3>[
|
|
575
|
+
worldPos[0],
|
|
576
|
+
worldPos[1],
|
|
577
|
+
worldPos[2],
|
|
578
|
+
];
|
|
579
|
+
|
|
580
|
+
const updatedPosition = <Types.Point3>[
|
|
581
|
+
updatedFocalPoint[0] + distance * viewPlaneNormal[0],
|
|
582
|
+
updatedFocalPoint[1] + distance * viewPlaneNormal[1],
|
|
583
|
+
updatedFocalPoint[2] + distance * viewPlaneNormal[2],
|
|
584
|
+
];
|
|
585
|
+
|
|
586
|
+
magnifyViewport.setCamera({
|
|
587
|
+
parallelScale,
|
|
588
|
+
focalPoint: updatedFocalPoint,
|
|
589
|
+
position: updatedPosition,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
private _syncStackViewports(
|
|
594
|
+
sourceViewport: Types.IStackViewport,
|
|
595
|
+
magnifyViewport: Types.IStackViewport
|
|
596
|
+
) {
|
|
597
|
+
magnifyViewport.setImageIdIndex(sourceViewport.getCurrentImageIdIndex());
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
private _syncViewports() {
|
|
601
|
+
const { viewport: sourceViewport } = this._sourceEnabledElement;
|
|
602
|
+
const { viewport: magnifyViewport } = this._enabledElement;
|
|
603
|
+
const sourceProperties = sourceViewport.getProperties();
|
|
604
|
+
|
|
605
|
+
magnifyViewport.setProperties(sourceProperties);
|
|
606
|
+
this._syncViewportsCameras(sourceViewport, magnifyViewport);
|
|
607
|
+
|
|
608
|
+
if (this._isStackViewport(sourceViewport)) {
|
|
609
|
+
this._syncStackViewports(
|
|
610
|
+
sourceViewport as Types.IStackViewport,
|
|
611
|
+
magnifyViewport as Types.IStackViewport
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
private _resizeViewport() {
|
|
617
|
+
const { viewport } = this._enabledElement;
|
|
618
|
+
const renderingEngine = viewport.getRenderingEngine();
|
|
619
|
+
|
|
620
|
+
renderingEngine.resize();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export { AdvancedMagnifyViewport as default, AdvancedMagnifyViewport };
|