@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
|
@@ -9,10 +9,14 @@ import {
|
|
|
9
9
|
getConfiguration as getCoreConfiguration,
|
|
10
10
|
} from '@cornerstonejs/core';
|
|
11
11
|
import { addToolState, getToolState } from './state';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import {
|
|
13
|
+
getStackData,
|
|
14
|
+
requestType,
|
|
15
|
+
priority,
|
|
16
|
+
getPromiseRemovedHandler,
|
|
17
|
+
nearestIndex,
|
|
18
|
+
range,
|
|
19
|
+
} from './stackPrefetchUtils';
|
|
16
20
|
|
|
17
21
|
let configuration = {
|
|
18
22
|
maxImagesToPrefetch: Infinity,
|
|
@@ -28,66 +32,6 @@ let configuration = {
|
|
|
28
32
|
let resetPrefetchTimeout;
|
|
29
33
|
const resetPrefetchDelay = 10;
|
|
30
34
|
|
|
31
|
-
function range(lowEnd, highEnd) {
|
|
32
|
-
// Javascript version of Python's range function
|
|
33
|
-
// http://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-an-array-based-on-suppl
|
|
34
|
-
lowEnd = Math.round(lowEnd) || 0;
|
|
35
|
-
highEnd = Math.round(highEnd) || 0;
|
|
36
|
-
|
|
37
|
-
const arr = [];
|
|
38
|
-
let c = highEnd - lowEnd + 1;
|
|
39
|
-
|
|
40
|
-
if (c <= 0) {
|
|
41
|
-
return arr;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
while (c--) {
|
|
45
|
-
arr[c] = highEnd--;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return arr;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function nearestIndex(arr, x) {
|
|
52
|
-
// Return index of nearest values in array
|
|
53
|
-
// http://stackoverflow.com/questions/25854212/return-index-of-nearest-values-in-an-array
|
|
54
|
-
let low = 0;
|
|
55
|
-
let high = arr.length - 1;
|
|
56
|
-
|
|
57
|
-
arr.forEach((v, idx) => {
|
|
58
|
-
if (v < x) {
|
|
59
|
-
low = Math.max(idx, low);
|
|
60
|
-
} else if (v > x) {
|
|
61
|
-
high = Math.min(idx, high);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return { low, high };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getStackData(element) {
|
|
69
|
-
const enabledElement = getEnabledElement(element);
|
|
70
|
-
|
|
71
|
-
if (!enabledElement) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
'stackPrefetch: element must be a valid Cornerstone enabled element'
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const { viewport } = enabledElement;
|
|
78
|
-
|
|
79
|
-
if (!(viewport instanceof StackViewport)) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
'stackPrefetch: element must be a StackViewport, VolumeViewport stackPrefetch not yet implemented'
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
currentImageIdIndex: viewport.getCurrentImageIdIndex(),
|
|
87
|
-
imageIds: viewport.getImageIds(),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
35
|
function prefetch(element) {
|
|
92
36
|
// Get the stackPrefetch tool data
|
|
93
37
|
const stackPrefetchData = getToolState(element);
|
|
@@ -99,18 +43,15 @@ function prefetch(element) {
|
|
|
99
43
|
const stackPrefetch = stackPrefetchData || {};
|
|
100
44
|
const stack = getStackData(element);
|
|
101
45
|
|
|
102
|
-
if (!stack
|
|
46
|
+
if (!stack?.imageIds?.length) {
|
|
103
47
|
console.warn('CornerstoneTools.stackPrefetch: No images in stack.');
|
|
104
48
|
return;
|
|
105
49
|
}
|
|
106
50
|
|
|
51
|
+
const { currentImageIdIndex } = stack;
|
|
52
|
+
|
|
107
53
|
// If all the requests are complete, disable the stackPrefetch tool
|
|
108
|
-
|
|
109
|
-
!stackPrefetch.indicesToRequest ||
|
|
110
|
-
!stackPrefetch.indicesToRequest.length
|
|
111
|
-
) {
|
|
112
|
-
stackPrefetch.enabled = false;
|
|
113
|
-
}
|
|
54
|
+
stackPrefetch.enabled &&= stackPrefetch.indicesToRequest?.length;
|
|
114
55
|
|
|
115
56
|
// Make sure the tool is still enabled
|
|
116
57
|
if (stackPrefetch.enabled === false) {
|
|
@@ -140,9 +81,20 @@ function prefetch(element) {
|
|
|
140
81
|
return;
|
|
141
82
|
}
|
|
142
83
|
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
84
|
+
const distance = Math.abs(currentImageIdIndex - imageIdIndex);
|
|
85
|
+
// For nearby objects, ensure the last accessed time is updated
|
|
86
|
+
// by using getImageLoadObject.
|
|
87
|
+
// For more distant objects, just check if available, but dont
|
|
88
|
+
// change the access time.
|
|
89
|
+
// This allows throwing data that hasn't been accessed and is not
|
|
90
|
+
// nearby.
|
|
91
|
+
const imageCached =
|
|
92
|
+
distance < 6
|
|
93
|
+
? cache.getImageLoadObject(imageId)
|
|
94
|
+
: cache.isLoaded(imageId);
|
|
95
|
+
|
|
96
|
+
if (imageCached) {
|
|
97
|
+
// Already in cache
|
|
146
98
|
removeFromList(imageIdIndex);
|
|
147
99
|
}
|
|
148
100
|
});
|
|
@@ -173,41 +125,8 @@ function prefetch(element) {
|
|
|
173
125
|
const imageIdIndex = stack.imageIds.indexOf(image.imageId);
|
|
174
126
|
|
|
175
127
|
removeFromList(imageIdIndex);
|
|
176
|
-
|
|
177
|
-
// triggerEvent(element, EVENTS.STACK_PREFETCH_IMAGE_LOADED, {
|
|
178
|
-
// element,
|
|
179
|
-
// imageId: image.imageId,
|
|
180
|
-
// imageIndex: imageIdIndex,
|
|
181
|
-
// stackPrefetch,
|
|
182
|
-
// stack,
|
|
183
|
-
// });
|
|
184
|
-
|
|
185
|
-
// If there are no more images to fetch
|
|
186
|
-
// if (
|
|
187
|
-
// !(
|
|
188
|
-
// stackPrefetch.indicesToRequest &&
|
|
189
|
-
// stackPrefetch.indicesToRequest.length > 0
|
|
190
|
-
// )
|
|
191
|
-
// ) {
|
|
192
|
-
// triggerEvent(element, EVENTS.STACK_PREFETCH_DONE, {
|
|
193
|
-
// element,
|
|
194
|
-
// stackPrefetch,
|
|
195
|
-
// stack,
|
|
196
|
-
// });
|
|
197
|
-
// }
|
|
198
128
|
}
|
|
199
129
|
|
|
200
|
-
// Retrieve the errorLoadingHandler if one exists
|
|
201
|
-
// const errorLoadingHandler =
|
|
202
|
-
// loadHandlerManager.getErrorLoadingHandler(element);
|
|
203
|
-
|
|
204
|
-
// function failCallback(error) {
|
|
205
|
-
// logger.log('prefetch errored: %o', error);
|
|
206
|
-
// if (errorLoadingHandler) {
|
|
207
|
-
// errorLoadingHandler(element, imageId, error, 'stackPrefetch');
|
|
208
|
-
// }
|
|
209
|
-
// }
|
|
210
|
-
|
|
211
130
|
// Prefetch images around the current image (before and after)
|
|
212
131
|
let lowerIndex = nearest.low;
|
|
213
132
|
let higherIndex = nearest.high;
|
|
@@ -277,49 +196,6 @@ function prefetch(element) {
|
|
|
277
196
|
});
|
|
278
197
|
}
|
|
279
198
|
|
|
280
|
-
function getPromiseRemovedHandler(element) {
|
|
281
|
-
return function (e) {
|
|
282
|
-
const eventData = e.detail;
|
|
283
|
-
|
|
284
|
-
// When an imagePromise has been pushed out of the cache, re-add its index
|
|
285
|
-
// It to the indicesToRequest list so that it will be retrieved later if the
|
|
286
|
-
// CurrentImageIdIndex is changed to an image nearby
|
|
287
|
-
let stackData;
|
|
288
|
-
|
|
289
|
-
try {
|
|
290
|
-
// It will throw an exception in some cases (eg: thumbnails)
|
|
291
|
-
stackData = getStackData(element);
|
|
292
|
-
} catch (error) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (!stackData || !stackData.imageIds || stackData.imageIds.length === 0) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const stack = stackData;
|
|
301
|
-
const imageIdIndex = stack.imageIds.indexOf(eventData.imageId);
|
|
302
|
-
|
|
303
|
-
// Make sure the image that was removed is actually in this stack
|
|
304
|
-
// Before adding it to the indicesToRequest array
|
|
305
|
-
if (imageIdIndex < 0) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const stackPrefetchData = getToolState(element);
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
!stackPrefetchData ||
|
|
313
|
-
!stackPrefetchData.indicesToRequest ||
|
|
314
|
-
!stackPrefetchData.indicesToRequest.length
|
|
315
|
-
) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
stackPrefetchData.indicesToRequest.push(imageIdIndex);
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
|
|
323
199
|
function onImageUpdated(e) {
|
|
324
200
|
// Start prefetching again (after a delay)
|
|
325
201
|
// When the user has scrolled to a new image
|
|
@@ -408,4 +284,6 @@ function setConfiguration(config) {
|
|
|
408
284
|
configuration = config;
|
|
409
285
|
}
|
|
410
286
|
|
|
411
|
-
|
|
287
|
+
const stackPrefetch = { enable, disable, getConfiguration, setConfiguration };
|
|
288
|
+
|
|
289
|
+
export default stackPrefetch;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getEnabledElement, StackViewport, Enums } from '@cornerstonejs/core';
|
|
2
|
+
import { getToolState } from './state';
|
|
3
|
+
|
|
4
|
+
export const requestType = Enums.RequestType.Prefetch;
|
|
5
|
+
export const priority = 0;
|
|
6
|
+
|
|
7
|
+
export function range(lowEnd, highEnd) {
|
|
8
|
+
// Javascript version of Python's range function
|
|
9
|
+
// http://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-an-array-based-on-suppl
|
|
10
|
+
lowEnd = Math.round(lowEnd) || 0;
|
|
11
|
+
highEnd = Math.round(highEnd) || 0;
|
|
12
|
+
|
|
13
|
+
const arr = [];
|
|
14
|
+
let c = highEnd - lowEnd + 1;
|
|
15
|
+
|
|
16
|
+
if (c <= 0) {
|
|
17
|
+
return arr;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
while (c--) {
|
|
21
|
+
arr[c] = highEnd--;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return arr;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function nearestIndex(arr, x) {
|
|
28
|
+
// Return index of nearest values in array
|
|
29
|
+
// http://stackoverflow.com/questions/25854212/return-index-of-nearest-values-in-an-array
|
|
30
|
+
let low = 0;
|
|
31
|
+
let high = arr.length - 1;
|
|
32
|
+
|
|
33
|
+
arr.forEach((v, idx) => {
|
|
34
|
+
if (v < x) {
|
|
35
|
+
low = Math.max(idx, low);
|
|
36
|
+
} else if (v > x) {
|
|
37
|
+
high = Math.min(idx, high);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return { low, high };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getStackData(element) {
|
|
45
|
+
const enabledElement = getEnabledElement(element);
|
|
46
|
+
|
|
47
|
+
if (!enabledElement) {
|
|
48
|
+
// Can be not valid if the data is changed part way through prefetch
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { viewport } = enabledElement;
|
|
53
|
+
|
|
54
|
+
if (!(viewport instanceof StackViewport)) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'stackPrefetch: element must be a StackViewport, VolumeViewport stackPrefetch not yet implemented'
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
currentImageIdIndex: viewport.getCurrentImageIdIndex(),
|
|
62
|
+
imageIds: viewport.getImageIds(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getPromiseRemovedHandler(element) {
|
|
67
|
+
return function (e) {
|
|
68
|
+
const eventData = e.detail;
|
|
69
|
+
|
|
70
|
+
// When an imagePromise has been pushed out of the cache, re-add its index
|
|
71
|
+
// It to the indicesToRequest list so that it will be retrieved later if the
|
|
72
|
+
// CurrentImageIdIndex is changed to an image nearby
|
|
73
|
+
let stackData;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
// It will throw an exception in some cases (eg: thumbnails)
|
|
77
|
+
stackData = getStackData(element);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!stackData || !stackData.imageIds || stackData.imageIds.length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const stack = stackData;
|
|
87
|
+
const imageIdIndex = stack.imageIds.indexOf(eventData.imageId);
|
|
88
|
+
|
|
89
|
+
// Make sure the image that was removed is actually in this stack
|
|
90
|
+
// Before adding it to the indicesToRequest array
|
|
91
|
+
if (imageIdIndex < 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const stackPrefetchData = getToolState(element);
|
|
96
|
+
|
|
97
|
+
if (
|
|
98
|
+
!stackPrefetchData ||
|
|
99
|
+
!stackPrefetchData.data ||
|
|
100
|
+
!stackPrefetchData.data.length
|
|
101
|
+
) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
stackPrefetchData.indicesToRequest.push(imageIdIndex);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const clearFromImageIds = (stack) => {
|
|
110
|
+
const imageIdSet = new Set<string>(stack.imageIds);
|
|
111
|
+
return (requestDetails) =>
|
|
112
|
+
requestDetails.type !== requestType ||
|
|
113
|
+
!imageIdSet.has(requestDetails.additionalDetails.imageId);
|
|
114
|
+
};
|