@cornerstonejs/tools 1.19.1 → 1.19.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/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
- package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.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/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/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
- package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.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/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/tools/displayTools/Labelmap/labelmapDisplay.ts +1 -1
- package/src/utilities/index.ts +2 -1
- 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,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
|
+
};
|