@cornerstonejs/core 5.17.0 → 5.17.2
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/esm/RenderingEngine/BaseRenderingEngine.d.ts +1 -0
- package/dist/esm/RenderingEngine/BaseRenderingEngine.js +7 -0
- package/dist/esm/RenderingEngine/BaseVolumeViewport.d.ts +1 -0
- package/dist/esm/RenderingEngine/BaseVolumeViewport.js +18 -1
- package/dist/esm/RenderingEngine/ContextPoolRenderingEngine.js +5 -3
- package/dist/esm/RenderingEngine/GenericViewport/Planar/CpuImageSliceRenderPath.js +3 -3
- package/dist/esm/RenderingEngine/TiledRenderingEngine.js +5 -2
- package/dist/esm/RenderingEngine/helpers/actorsWaitingForStorage.d.ts +3 -0
- package/dist/esm/RenderingEngine/helpers/actorsWaitingForStorage.js +5 -0
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLImageResliceMapper.js +8 -1
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLTexture.js +98 -1
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLVolumeMapper.js +8 -1
- package/dist/esm/utilities/CompositeVoxelManager.d.ts +10 -0
- package/dist/esm/utilities/CompositeVoxelManager.js +237 -6
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +5 -5
|
@@ -39,6 +39,7 @@ declare abstract class BaseRenderingEngine {
|
|
|
39
39
|
private setCustomViewports;
|
|
40
40
|
protected _getViewportsAsArray(): IViewport[];
|
|
41
41
|
protected _notifyFidelityOfRenderedViewports(viewports: IViewport[]): void;
|
|
42
|
+
protected _waitsForStorage(viewport: IViewport, renderStart: number): boolean;
|
|
42
43
|
private _setViewportsToBeRenderedNextFrame;
|
|
43
44
|
private _render;
|
|
44
45
|
private _resetViewport;
|
|
@@ -7,6 +7,7 @@ import { coreLog } from '../utilities/logger.js';
|
|
|
7
7
|
import ViewportType from '../enums/ViewportType.js';
|
|
8
8
|
import viewportTypeUsesCustomRenderingPipeline, { viewportUsesCustomRenderingPipeline, } from './helpers/viewportTypeUsesCustomRenderingPipeline.js';
|
|
9
9
|
import getOrCreateCanvas from './helpers/getOrCreateCanvas.js';
|
|
10
|
+
import { skippedDrawSince } from './helpers/actorsWaitingForStorage.js';
|
|
10
11
|
import { setElementTouchActionNone, restoreElementTouchAction, } from './helpers/elementTouchAction.js';
|
|
11
12
|
import { getShouldUseCPURendering, getUseGenericViewport, isCornerstoneInitialized, getConfiguration, } from '../init.js';
|
|
12
13
|
import { getViewportClassForInput } from './helpers/viewportTypeToViewportClass.js';
|
|
@@ -301,6 +302,12 @@ class BaseRenderingEngine {
|
|
|
301
302
|
viewport.notifyFidelityStateChanged();
|
|
302
303
|
});
|
|
303
304
|
}
|
|
305
|
+
_waitsForStorage(viewport, renderStart) {
|
|
306
|
+
const actors = viewport.getActors?.();
|
|
307
|
+
return (Array.isArray(actors) &&
|
|
308
|
+
actors.length > 0 &&
|
|
309
|
+
actors.every((entry) => entry?.actor && skippedDrawSince(entry.actor, renderStart)));
|
|
310
|
+
}
|
|
304
311
|
_setViewportsToBeRenderedNextFrame(viewportIds) {
|
|
305
312
|
viewportIds.forEach((viewportId) => {
|
|
306
313
|
this._needsRender.add(viewportId);
|
|
@@ -22,6 +22,7 @@ declare abstract class BaseVolumeViewport extends Viewport {
|
|
|
22
22
|
private _fidelityRecords;
|
|
23
23
|
private _fidelityRecordListenersAttached;
|
|
24
24
|
private _fidelityRecordsDisposed;
|
|
25
|
+
private _fidelityNotifyFrame;
|
|
25
26
|
canReportFidelity(): boolean;
|
|
26
27
|
protected collectFidelityLines(): FidelityLine[];
|
|
27
28
|
private ensureFidelityRecordInvalidation;
|
|
@@ -54,6 +54,10 @@ class BaseVolumeViewport extends Viewport {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
this._fidelityRecordListenersAttached = true;
|
|
57
|
+
const cancelFrame = () => {
|
|
58
|
+
cancelAnimationFrame(this._fidelityNotifyFrame);
|
|
59
|
+
this._fidelityNotifyFrame = 0;
|
|
60
|
+
};
|
|
57
61
|
const invalidate = (evt) => {
|
|
58
62
|
const { volumeId } = evt.detail;
|
|
59
63
|
if (volumeId) {
|
|
@@ -62,7 +66,18 @@ class BaseVolumeViewport extends Viewport {
|
|
|
62
66
|
else {
|
|
63
67
|
this._fidelityRecords.clear();
|
|
64
68
|
}
|
|
65
|
-
|
|
69
|
+
if (evt.type !== Events.IMAGE_VOLUME_MODIFIED) {
|
|
70
|
+
cancelFrame();
|
|
71
|
+
this.notifyFidelityStateChanged();
|
|
72
|
+
}
|
|
73
|
+
else if (!this._fidelityNotifyFrame) {
|
|
74
|
+
this._fidelityNotifyFrame = requestAnimationFrame(() => {
|
|
75
|
+
this._fidelityNotifyFrame = 0;
|
|
76
|
+
if (!this._fidelityRecordsDisposed && !this.isDisabled) {
|
|
77
|
+
this.notifyFidelityStateChanged();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
66
81
|
};
|
|
67
82
|
const cleanUp = (evt) => {
|
|
68
83
|
if (evt.detail?.element !==
|
|
@@ -72,6 +87,7 @@ class BaseVolumeViewport extends Viewport {
|
|
|
72
87
|
eventTarget.removeEventListener(Events.IMAGE_VOLUME_MODIFIED, invalidate);
|
|
73
88
|
eventTarget.removeEventListener(Events.IMAGE_VOLUME_LOADING_COMPLETED, invalidate);
|
|
74
89
|
eventTarget.removeEventListener(Events.ELEMENT_DISABLED, cleanUp);
|
|
90
|
+
cancelFrame();
|
|
75
91
|
this._fidelityRecords.clear();
|
|
76
92
|
this._fidelityRecordsDisposed = true;
|
|
77
93
|
};
|
|
@@ -90,6 +106,7 @@ class BaseVolumeViewport extends Viewport {
|
|
|
90
106
|
this._fidelityRecords = new Map();
|
|
91
107
|
this._fidelityRecordListenersAttached = false;
|
|
92
108
|
this._fidelityRecordsDisposed = false;
|
|
109
|
+
this._fidelityNotifyFrame = 0;
|
|
93
110
|
this.setRotation = (rotation) => {
|
|
94
111
|
const panFit = this.getPan(this.fitToCanvasCamera);
|
|
95
112
|
const pan = this.getPan();
|
|
@@ -24,6 +24,7 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
|
|
|
24
24
|
this._animationFrameHandle = null;
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
+
const renderStart = performance.now();
|
|
27
28
|
const eventDetails = viewportsToRender.map((viewport) => {
|
|
28
29
|
const eventDetail = this.renderViewportUsingCustomOrVtkPipeline(viewport);
|
|
29
30
|
viewport.setRendered();
|
|
@@ -32,12 +33,13 @@ class ContextPoolRenderingEngine extends BaseRenderingEngine {
|
|
|
32
33
|
});
|
|
33
34
|
this._animationFrameSet = false;
|
|
34
35
|
this._animationFrameHandle = null;
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const waiting = viewportsToRender.map((vp) => this._waitsForStorage(vp, renderStart));
|
|
37
|
+
eventDetails.forEach((eventDetail, index) => {
|
|
38
|
+
if (eventDetail?.element && !waiting[index]) {
|
|
37
39
|
triggerEvent(eventDetail.element, Events.IMAGE_RENDERED, eventDetail);
|
|
38
40
|
}
|
|
39
41
|
});
|
|
40
|
-
this._notifyFidelityOfRenderedViewports(viewportsToRender);
|
|
42
|
+
this._notifyFidelityOfRenderedViewports(viewportsToRender.filter((_vp, index) => !waiting[index]));
|
|
41
43
|
};
|
|
42
44
|
if (!this.useCPURendering) {
|
|
43
45
|
this.ensureContextPool();
|
|
@@ -6,7 +6,7 @@ import canvasToPixel from '../../helpers/cpuFallback/rendering/canvasToPixel.js'
|
|
|
6
6
|
import correctShift from '../../helpers/cpuFallback/rendering/correctShift.js';
|
|
7
7
|
import getDefaultViewport from '../../helpers/cpuFallback/rendering/getDefaultViewport.js';
|
|
8
8
|
import { getDefaultImageVOIRange } from '../../helpers/planarImageRendering.js';
|
|
9
|
-
import
|
|
9
|
+
import fitToWindow from '../../helpers/cpuFallback/rendering/fitToWindow.js';
|
|
10
10
|
import drawImageSync from '../../helpers/cpuFallback/drawImageSync.js';
|
|
11
11
|
import { resolveCPUFallbackColormap } from '../../helpers/cpuFallback/colors/index.js';
|
|
12
12
|
import { InterpolationType, MetadataModules, ViewportType, Events, ViewportStatus, } from '../../../enums/index.js';
|
|
@@ -43,7 +43,7 @@ export class CpuImageSliceRenderPath {
|
|
|
43
43
|
renderingTools: {},
|
|
44
44
|
viewport: defaultViewport,
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
fitToWindow(enabledElement);
|
|
47
47
|
enabledElement.transform = calculateTransform(enabledElement);
|
|
48
48
|
rendering = {
|
|
49
49
|
renderMode: ActorRenderMode.CPU_IMAGE,
|
|
@@ -201,12 +201,12 @@ export class CpuImageSliceRenderPath {
|
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
resize(ctx, rendering, dataId) {
|
|
204
|
-
resizeEnabledElement(rendering.enabledElement, true);
|
|
205
204
|
const image = rendering.enabledElement.image;
|
|
206
205
|
const camera = ctx.viewport.getViewState();
|
|
207
206
|
if (!image) {
|
|
208
207
|
return;
|
|
209
208
|
}
|
|
209
|
+
fitToWindow(rendering.enabledElement);
|
|
210
210
|
const projection = resolvePlanarRenderPathProjection({
|
|
211
211
|
ctx,
|
|
212
212
|
dataId,
|
|
@@ -15,6 +15,7 @@ class TiledRenderingEngine extends BaseRenderingEngine {
|
|
|
15
15
|
super(id);
|
|
16
16
|
this._renderFlaggedViewports = () => {
|
|
17
17
|
this._throwIfDestroyed();
|
|
18
|
+
const renderStart = performance.now();
|
|
18
19
|
if (this.offscreenMultiRenderWindow) {
|
|
19
20
|
this.performVtkDrawCall();
|
|
20
21
|
}
|
|
@@ -25,8 +26,10 @@ class TiledRenderingEngine extends BaseRenderingEngine {
|
|
|
25
26
|
const viewport = viewports[i];
|
|
26
27
|
if (this._needsRender.has(viewport.id)) {
|
|
27
28
|
const eventDetail = this.renderViewportUsingCustomOrVtkPipeline(viewport);
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
if (!this._waitsForStorage(viewport, renderStart)) {
|
|
30
|
+
eventDetailArray.push(eventDetail);
|
|
31
|
+
renderedViewports.push(viewport);
|
|
32
|
+
}
|
|
30
33
|
viewport.setRendered();
|
|
31
34
|
this._needsRender.delete(viewport.id);
|
|
32
35
|
if (this._needsRender.size === 0) {
|
|
@@ -7,6 +7,7 @@ import { getImageDataHash, getTransferFunctionsHash, } from '@kitware/vtk.js/Ren
|
|
|
7
7
|
import vtkOpenGLTexture from '@kitware/vtk.js/Rendering/OpenGL/Texture.js';
|
|
8
8
|
import { getCanUseNorm16Texture } from '../../init.js';
|
|
9
9
|
import takeBoundScalarTexture from './takeBoundScalarTexture.js';
|
|
10
|
+
import actorsWaitingForStorage from '../helpers/actorsWaitingForStorage.js';
|
|
10
11
|
const { vtkErrorMacro } = macro;
|
|
11
12
|
function findLabelOutlineProperties(actor, currentValidInputs) {
|
|
12
13
|
const labelmapProperties = [];
|
|
@@ -86,7 +87,13 @@ function vtkStreamingOpenGLImageResliceMapper(publicAPI, model) {
|
|
|
86
87
|
: (firstScalars?.getNumberOfComponents?.() ?? 1);
|
|
87
88
|
publicAPI.updateResliceGeometry();
|
|
88
89
|
publicAPI.renderPieceStart(ren, actor);
|
|
89
|
-
|
|
90
|
+
if (model.scalarTextures?.some((texture) => texture?.isInitializing?.())) {
|
|
91
|
+
actorsWaitingForStorage.set(actor, performance.now());
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
actorsWaitingForStorage.delete(actor);
|
|
95
|
+
publicAPI.renderPieceDraw(ren, actor);
|
|
96
|
+
}
|
|
90
97
|
publicAPI.renderPieceFinish(ren, actor);
|
|
91
98
|
publicAPI.invokeEvent({ type: 'EndEvent' });
|
|
92
99
|
};
|
|
@@ -12,6 +12,9 @@ import autoLoad from '../../utilities/autoLoad.js';
|
|
|
12
12
|
import { getConfiguration } from '../../init.js';
|
|
13
13
|
const DEFAULT_MAX_SLICES_PER_RENDER = 16;
|
|
14
14
|
const DEFAULT_MAX_MILLISECONDS_PER_RENDER = 8;
|
|
15
|
+
const INIT_FENCE_MIN_BYTES = 256 * 1024 * 1024;
|
|
16
|
+
const INIT_FENCE_DEADLINE_MS = 3000;
|
|
17
|
+
const INIT_FENCE_POLL_MS = 16;
|
|
15
18
|
function reducedTextureFillBudget() {
|
|
16
19
|
const budget = getConfiguration()?.rendering?.reducedTextureFill;
|
|
17
20
|
return {
|
|
@@ -51,15 +54,95 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
|
|
|
51
54
|
publicAPI.create3DFromRaw = (options) => {
|
|
52
55
|
const created = superCreate3DFromRaw(options);
|
|
53
56
|
if (created && !options.data) {
|
|
57
|
+
model.writtenSlices = new Uint8Array(options.depth);
|
|
58
|
+
startStorageInit(options.dataType, options.numComps);
|
|
54
59
|
publicAPI.markAllFramesUpdated();
|
|
55
60
|
}
|
|
56
61
|
return created;
|
|
57
62
|
};
|
|
63
|
+
function startStorageInit(dataType, numComps) {
|
|
64
|
+
releaseInitFence();
|
|
65
|
+
const gl = model.context;
|
|
66
|
+
if (typeof gl?.fenceSync !== 'function' ||
|
|
67
|
+
!(model.allocatedGPUMemoryInBytes >= INIT_FENCE_MIN_BYTES)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let pixData;
|
|
71
|
+
try {
|
|
72
|
+
const Constructor = getConstructorFromType(dataType, false);
|
|
73
|
+
[pixData] = publicAPI.updateArrayDataTypeForGL(dataType, [
|
|
74
|
+
new Constructor(numComps || 1),
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
model._openGLRenderWindow.activateTexture(publicAPI);
|
|
81
|
+
publicAPI.bind();
|
|
82
|
+
gl.texSubImage3D(model.target, 0, 0, 0, 0, 1, 1, 1, model.format, model.openGLDataType, pixData);
|
|
83
|
+
publicAPI.deactivate();
|
|
84
|
+
const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
85
|
+
if (!sync) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const fence = {
|
|
89
|
+
gl,
|
|
90
|
+
sync,
|
|
91
|
+
deadline: performance.now() + INIT_FENCE_DEADLINE_MS,
|
|
92
|
+
};
|
|
93
|
+
model.initFence = fence;
|
|
94
|
+
gl.flush();
|
|
95
|
+
model.initFenceTimer = setTimeout(() => pollInitFence(fence), INIT_FENCE_POLL_MS);
|
|
96
|
+
}
|
|
97
|
+
function releaseInitFence(keepPoll = false) {
|
|
98
|
+
const fence = model.initFence;
|
|
99
|
+
if (!keepPoll) {
|
|
100
|
+
clearTimeout(model.initFenceTimer);
|
|
101
|
+
model.initFenceTimer = null;
|
|
102
|
+
}
|
|
103
|
+
model.initFence = null;
|
|
104
|
+
if (fence && !fence.gl.isContextLost()) {
|
|
105
|
+
fence.gl.deleteSync(fence.sync);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function pollInitFence(fence) {
|
|
109
|
+
if (model.deleted || (model.initFence && model.initFence !== fence)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (publicAPI.isInitializing()) {
|
|
113
|
+
model.initFenceTimer = setTimeout(() => pollInitFence(fence), INIT_FENCE_POLL_MS);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
publicAPI.modified();
|
|
117
|
+
if (model.volumeId) {
|
|
118
|
+
autoLoad(model.volumeId);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
publicAPI.isInitializing = () => {
|
|
122
|
+
const fence = model.initFence;
|
|
123
|
+
if (!fence) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const { gl, sync, deadline } = fence;
|
|
127
|
+
if (!gl.isContextLost() &&
|
|
128
|
+
performance.now() < deadline &&
|
|
129
|
+
gl.getSyncParameter(sync, gl.SYNC_STATUS) !== gl.SIGNALED) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
releaseInitFence(true);
|
|
133
|
+
return false;
|
|
134
|
+
};
|
|
58
135
|
const superReleaseGraphicsResources = publicAPI.releaseGraphicsResources;
|
|
59
136
|
publicAPI.releaseGraphicsResources = (rwin) => {
|
|
60
137
|
const window = model._openGLRenderWindow;
|
|
138
|
+
releaseInitFence();
|
|
61
139
|
superReleaseGraphicsResources(rwin ?? (window?.isDeleted?.() ? undefined : window));
|
|
62
140
|
};
|
|
141
|
+
const superDelete = publicAPI.delete;
|
|
142
|
+
publicAPI.delete = () => {
|
|
143
|
+
releaseInitFence();
|
|
144
|
+
superDelete();
|
|
145
|
+
};
|
|
63
146
|
const superUpdate = publicAPI.updateVolumeInfoForGL;
|
|
64
147
|
publicAPI.updateVolumeInfoForGL = (dataType, numComps) => {
|
|
65
148
|
const isScalingApplied = superUpdate(dataType, numComps);
|
|
@@ -73,7 +156,7 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
|
|
|
73
156
|
return;
|
|
74
157
|
}
|
|
75
158
|
const volume = cache.getVolume(volumeId);
|
|
76
|
-
if (!volume) {
|
|
159
|
+
if (!volume || publicAPI.isInitializing()) {
|
|
77
160
|
return;
|
|
78
161
|
}
|
|
79
162
|
model._openGLRenderWindow.activateTexture(publicAPI);
|
|
@@ -225,6 +308,11 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
|
|
|
225
308
|
autoLoad(model.volumeId);
|
|
226
309
|
}, 0);
|
|
227
310
|
}
|
|
311
|
+
function markWritten(slice) {
|
|
312
|
+
if (model.writtenSlices) {
|
|
313
|
+
model.writtenSlices[slice] = 1;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
228
316
|
function updateTextureFromComposite(volume) {
|
|
229
317
|
const { grid } = model;
|
|
230
318
|
const [width, height, depth] = grid.dimensions;
|
|
@@ -278,6 +366,10 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
|
|
|
278
366
|
}
|
|
279
367
|
data = slab.getScalarData();
|
|
280
368
|
}
|
|
369
|
+
if (!hasData && model.writtenSlices && !model.writtenSlices[slice]) {
|
|
370
|
+
model.updatedFrames[slice] = null;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
281
373
|
if (volume.dataType !== data.constructor.name) {
|
|
282
374
|
data = convertDataType(data, volume.dataType);
|
|
283
375
|
}
|
|
@@ -288,6 +380,7 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
|
|
|
288
380
|
gl.texSubImage3D(model.target, 0, 0, 0, slice, width, height, 1, model.format, model.openGLDataType, pixData);
|
|
289
381
|
publicAPI.deactivate();
|
|
290
382
|
model.updatedFrames[slice] = null;
|
|
383
|
+
markWritten(slice);
|
|
291
384
|
slicesHandled++;
|
|
292
385
|
if (hasData) {
|
|
293
386
|
slicesWithData++;
|
|
@@ -375,6 +468,9 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
|
|
|
375
468
|
const imageId = imageIds[i];
|
|
376
469
|
const image = cache.getImage(imageId);
|
|
377
470
|
let data;
|
|
471
|
+
if (!image && model.writtenSlices && !model.writtenSlices[i]) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
378
474
|
if (!image) {
|
|
379
475
|
constructor = getConstructorFromType(volume.dataType, true);
|
|
380
476
|
data = new constructor(model.width * model.height);
|
|
@@ -394,6 +490,7 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
|
|
|
394
490
|
let zOffset = i;
|
|
395
491
|
gl.texSubImage3D(model.target, 0, 0, 0, zOffset, model.width, model.height, 1, model.format, model.openGLDataType, pixData);
|
|
396
492
|
publicAPI.deactivate();
|
|
493
|
+
markWritten(i);
|
|
397
494
|
}
|
|
398
495
|
if (model.generateMipmap) {
|
|
399
496
|
model.context.generateMipmap(model.target);
|
|
@@ -11,6 +11,7 @@ import { getCanUseNorm16Texture } from '../../init.js';
|
|
|
11
11
|
import cache from '../../cache/cache.js';
|
|
12
12
|
import canUseFloatOpacityTexture from './canUseFloatOpacityTexture.js';
|
|
13
13
|
import takeBoundScalarTexture from './takeBoundScalarTexture.js';
|
|
14
|
+
import actorsWaitingForStorage from '../helpers/actorsWaitingForStorage.js';
|
|
14
15
|
import { coreLog } from '../../utilities/logger.js';
|
|
15
16
|
import { volumeTextureBytes } from '../../utilities/getBufferConfiguration.js';
|
|
16
17
|
import { voxelGridWithinLimits } from '../../utilities/voxelGrid/index.js';
|
|
@@ -122,7 +123,13 @@ function vtkStreamingOpenGLVolumeMapper(publicAPI, model) {
|
|
|
122
123
|
return;
|
|
123
124
|
}
|
|
124
125
|
publicAPI.renderPieceStart(ren, actor);
|
|
125
|
-
|
|
126
|
+
if (model.scalarTextures.some((texture) => texture?.isInitializing?.())) {
|
|
127
|
+
actorsWaitingForStorage.set(actor, performance.now());
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
actorsWaitingForStorage.delete(actor);
|
|
131
|
+
publicAPI.renderPieceDraw(ren, actor);
|
|
132
|
+
}
|
|
126
133
|
publicAPI.renderPieceFinish(ren, actor);
|
|
127
134
|
};
|
|
128
135
|
publicAPI.buildBufferObjects = (ren, actor) => {
|
|
@@ -31,6 +31,15 @@ export type CompositeVoxelManagerOptions<T> = {
|
|
|
31
31
|
delivered?: DeliveredRegion[];
|
|
32
32
|
id?: string;
|
|
33
33
|
};
|
|
34
|
+
type Coverage = {
|
|
35
|
+
covered: number;
|
|
36
|
+
lowest: ImageQualityStatus;
|
|
37
|
+
highest: ImageQualityStatus;
|
|
38
|
+
deliveries: number;
|
|
39
|
+
exact: boolean;
|
|
40
|
+
};
|
|
41
|
+
declare function coverageOfRegion(deliveries: DeliveredRegion[], region: BoundsIJK): Coverage;
|
|
42
|
+
export { coverageOfRegion };
|
|
34
43
|
export default class CompositeVoxelManager<T> implements IVoxelManager<T> {
|
|
35
44
|
private readonly representations;
|
|
36
45
|
private readonly primaryRepresentation;
|
|
@@ -62,6 +71,7 @@ export default class CompositeVoxelManager<T> implements IVoxelManager<T> {
|
|
|
62
71
|
private sourceOfDerivation;
|
|
63
72
|
setDeliveredQuality(representation: VoxelRepresentation<T>, bounds: BoundsIJK, quality: ImageQualityStatus): boolean;
|
|
64
73
|
private deliveryIndexOf;
|
|
74
|
+
private coverageOf;
|
|
65
75
|
getRegionQuality(representation: VoxelRepresentation<T>, region?: BoundsIJK): VoxelQualityRecord;
|
|
66
76
|
fillGrid(grid: VoxelGrid, target: IVoxelManager<T>, statistic?: VoxelStatistic): number;
|
|
67
77
|
getQuality(selector?: VoxelRepresentationSelector): VoxelQualityRecord;
|
|
@@ -85,6 +85,180 @@ function coverageOfRegion(deliveries, region) {
|
|
|
85
85
|
}
|
|
86
86
|
return coverage;
|
|
87
87
|
}
|
|
88
|
+
function countBelow(sorted, value) {
|
|
89
|
+
let low = 0;
|
|
90
|
+
let high = sorted.length;
|
|
91
|
+
while (low < high) {
|
|
92
|
+
const middle = (low + high) >> 1;
|
|
93
|
+
if (sorted[middle] < value) {
|
|
94
|
+
low = middle + 1;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
high = middle;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return low;
|
|
101
|
+
}
|
|
102
|
+
function firstRunEndingAtOrAfter(runs, k) {
|
|
103
|
+
let low = 0;
|
|
104
|
+
let high = runs.length;
|
|
105
|
+
while (low < high) {
|
|
106
|
+
const middle = (low + high) >> 1;
|
|
107
|
+
if (runs[middle].end < k) {
|
|
108
|
+
low = middle + 1;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
high = middle;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return low;
|
|
115
|
+
}
|
|
116
|
+
function addRun(runs, start, end, quality) {
|
|
117
|
+
if (!(quality > 0)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const first = firstRunEndingAtOrAfter(runs, start - 1);
|
|
121
|
+
let last = first;
|
|
122
|
+
const pieces = [];
|
|
123
|
+
let cursor = start;
|
|
124
|
+
const push = (from, to, value) => {
|
|
125
|
+
const previous = pieces[pieces.length - 1];
|
|
126
|
+
if (previous && previous.end + 1 === from && previous.quality === value) {
|
|
127
|
+
previous.end = to;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
pieces.push({ start: from, end: to, quality: value });
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
for (; last < runs.length && runs[last].start <= end + 1; last++) {
|
|
134
|
+
const run = runs[last];
|
|
135
|
+
if (run.start < start) {
|
|
136
|
+
push(run.start, Math.min(run.end, start - 1), run.quality);
|
|
137
|
+
}
|
|
138
|
+
const from = Math.max(run.start, start);
|
|
139
|
+
const to = Math.min(run.end, end);
|
|
140
|
+
if (from <= to) {
|
|
141
|
+
if (cursor < from) {
|
|
142
|
+
push(cursor, from - 1, quality);
|
|
143
|
+
}
|
|
144
|
+
push(from, to, Math.max(run.quality, quality));
|
|
145
|
+
cursor = to + 1;
|
|
146
|
+
}
|
|
147
|
+
if (run.end > end) {
|
|
148
|
+
if (cursor <= end) {
|
|
149
|
+
push(cursor, end, quality);
|
|
150
|
+
cursor = end + 1;
|
|
151
|
+
}
|
|
152
|
+
push(Math.max(run.start, end + 1), run.end, run.quality);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (cursor <= end) {
|
|
156
|
+
push(cursor, end, quality);
|
|
157
|
+
}
|
|
158
|
+
runs.splice(first, last - first, ...pieces);
|
|
159
|
+
}
|
|
160
|
+
function footprintKey(bounds) {
|
|
161
|
+
return `${bounds[0][0]},${bounds[0][1]},${bounds[1][0]},${bounds[1][1]}`;
|
|
162
|
+
}
|
|
163
|
+
function addToCoverage(coverage, delivery) {
|
|
164
|
+
const { bounds } = delivery;
|
|
165
|
+
const key = footprintKey(bounds);
|
|
166
|
+
let footprint = coverage.get(key);
|
|
167
|
+
if (!footprint) {
|
|
168
|
+
footprint = {
|
|
169
|
+
i: [bounds[0][0], bounds[0][1]],
|
|
170
|
+
j: [bounds[1][0], bounds[1][1]],
|
|
171
|
+
members: new Set(),
|
|
172
|
+
starts: [],
|
|
173
|
+
ends: [],
|
|
174
|
+
length: 0,
|
|
175
|
+
runs: [],
|
|
176
|
+
};
|
|
177
|
+
coverage.set(key, footprint);
|
|
178
|
+
}
|
|
179
|
+
const [start, end] = bounds[2];
|
|
180
|
+
footprint.members.add(delivery);
|
|
181
|
+
footprint.starts.splice(countBelow(footprint.starts, start), 0, start);
|
|
182
|
+
footprint.ends.splice(countBelow(footprint.ends, end), 0, end);
|
|
183
|
+
footprint.length += Math.max(0, end - start + 1);
|
|
184
|
+
if (footprint.runs) {
|
|
185
|
+
addRun(footprint.runs, start, end, delivery.quality);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function removeFromCoverage(coverage, delivery) {
|
|
189
|
+
const key = footprintKey(delivery.bounds);
|
|
190
|
+
const footprint = coverage.get(key);
|
|
191
|
+
if (!footprint?.members.delete(delivery)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (!footprint.members.size) {
|
|
195
|
+
coverage.delete(key);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const [start, end] = delivery.bounds[2];
|
|
199
|
+
footprint.starts.splice(countBelow(footprint.starts, start), 1);
|
|
200
|
+
footprint.ends.splice(countBelow(footprint.ends, end), 1);
|
|
201
|
+
footprint.length -= Math.max(0, end - start + 1);
|
|
202
|
+
footprint.runs = undefined;
|
|
203
|
+
}
|
|
204
|
+
function raiseInCoverage(coverage, delivery) {
|
|
205
|
+
const runs = coverage.get(footprintKey(delivery.bounds))?.runs;
|
|
206
|
+
if (runs) {
|
|
207
|
+
addRun(runs, delivery.bounds[2][0], delivery.bounds[2][1], delivery.quality);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function coverageFromIncremental(coverage, region) {
|
|
211
|
+
const result = {
|
|
212
|
+
covered: 0,
|
|
213
|
+
lowest: undefined,
|
|
214
|
+
highest: undefined,
|
|
215
|
+
deliveries: 0,
|
|
216
|
+
exact: true,
|
|
217
|
+
};
|
|
218
|
+
if (coverage.size === 0 || volumeOfBounds(region) === 0) {
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
if (coverage.size > 1) {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
const footprint = coverage.values().next().value;
|
|
225
|
+
const width = Math.min(footprint.i[1], region[0][1]) -
|
|
226
|
+
Math.max(footprint.i[0], region[0][0]) +
|
|
227
|
+
1;
|
|
228
|
+
const height = Math.min(footprint.j[1], region[1][1]) -
|
|
229
|
+
Math.max(footprint.j[0], region[1][0]) +
|
|
230
|
+
1;
|
|
231
|
+
if (width <= 0 || height <= 0) {
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
const [kStart, kEnd] = region[2];
|
|
235
|
+
const met = countBelow(footprint.starts, kEnd + 1) - countBelow(footprint.ends, kStart);
|
|
236
|
+
if (met <= 0) {
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
const cells = 9 * (2 * met + 1);
|
|
240
|
+
if (cells > MAX_COVERAGE_CELLS ||
|
|
241
|
+
Math.min(footprint.length, met * cells) > MAX_COVERAGE_WORK) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
if (!footprint.runs) {
|
|
245
|
+
footprint.runs = [];
|
|
246
|
+
for (const delivery of footprint.members) {
|
|
247
|
+
addRun(footprint.runs, delivery.bounds[2][0], delivery.bounds[2][1], delivery.quality);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const { runs } = footprint;
|
|
251
|
+
let slices = 0;
|
|
252
|
+
for (let index = firstRunEndingAtOrAfter(runs, kStart); index < runs.length && runs[index].start <= kEnd; index++) {
|
|
253
|
+
const { start, end, quality } = runs[index];
|
|
254
|
+
slices += Math.min(end, kEnd) - Math.max(start, kStart) + 1;
|
|
255
|
+
result.lowest = Math.min(result.lowest ?? quality, quality);
|
|
256
|
+
result.highest = Math.max(result.highest ?? quality, quality);
|
|
257
|
+
}
|
|
258
|
+
result.covered = slices * width * height;
|
|
259
|
+
result.deliveries = met;
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
88
262
|
function withStatus(record) {
|
|
89
263
|
record.status = imageQualityStatusOfRecord(record);
|
|
90
264
|
return record;
|
|
@@ -101,6 +275,20 @@ function withinCeiling(grid, ceiling) {
|
|
|
101
275
|
}
|
|
102
276
|
return true;
|
|
103
277
|
}
|
|
278
|
+
const MAX_MAPPED_COVERAGES = 8;
|
|
279
|
+
function exactGridKey(grid) {
|
|
280
|
+
return [grid.dimensions, grid.spacing, grid.origin, grid.direction]
|
|
281
|
+
.map((values) => Array.from(values).join(','))
|
|
282
|
+
.join('|');
|
|
283
|
+
}
|
|
284
|
+
function mappedCopy(mapped, delivery) {
|
|
285
|
+
const copy = {
|
|
286
|
+
bounds: mapBoundsBetweenGrids(mapped.source, mapped.target, delivery.bounds),
|
|
287
|
+
quality: delivery.quality,
|
|
288
|
+
};
|
|
289
|
+
mapped.copies.set(delivery, copy);
|
|
290
|
+
return copy;
|
|
291
|
+
}
|
|
104
292
|
function boundsKey(bounds) {
|
|
105
293
|
return `${bounds[0][0]},${bounds[0][1]},${bounds[1][0]},${bounds[1][1]},${bounds[2][0]},${bounds[2][1]}`;
|
|
106
294
|
}
|
|
@@ -114,17 +302,51 @@ function addToDeliveryIndex(index, delivery) {
|
|
|
114
302
|
}
|
|
115
303
|
bucket.add(delivery);
|
|
116
304
|
}
|
|
305
|
+
addToCoverage(index.coverage, delivery);
|
|
306
|
+
for (const mapped of index.mapped.values()) {
|
|
307
|
+
addToCoverage(mapped.coverage, mappedCopy(mapped, delivery));
|
|
308
|
+
}
|
|
117
309
|
}
|
|
118
310
|
function removeFromDeliveryIndex(index, delivery) {
|
|
119
311
|
index.byBounds.delete(boundsKey(delivery.bounds));
|
|
120
312
|
for (let k = delivery.bounds[2][0]; k <= delivery.bounds[2][1]; k++) {
|
|
121
313
|
index.bySlice.get(k)?.delete(delivery);
|
|
122
314
|
}
|
|
315
|
+
removeFromCoverage(index.coverage, delivery);
|
|
316
|
+
for (const mapped of index.mapped.values()) {
|
|
317
|
+
removeFromCoverage(mapped.coverage, mapped.copies.get(delivery));
|
|
318
|
+
mapped.copies.delete(delivery);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function raiseInDeliveryIndex(index, delivery) {
|
|
322
|
+
raiseInCoverage(index.coverage, delivery);
|
|
323
|
+
for (const mapped of index.mapped.values()) {
|
|
324
|
+
const copy = mapped.copies.get(delivery);
|
|
325
|
+
copy.quality = delivery.quality;
|
|
326
|
+
raiseInCoverage(mapped.coverage, copy);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function mappedCoverageOf(index, delivered, source, target) {
|
|
330
|
+
const key = `${exactGridKey(source)}>${exactGridKey(target)}`;
|
|
331
|
+
let mapped = index.mapped.get(key);
|
|
332
|
+
if (!mapped) {
|
|
333
|
+
if (index.mapped.size >= MAX_MAPPED_COVERAGES) {
|
|
334
|
+
index.mapped.clear();
|
|
335
|
+
}
|
|
336
|
+
mapped = { source, target, coverage: new Map(), copies: new Map() };
|
|
337
|
+
for (const delivery of delivered) {
|
|
338
|
+
addToCoverage(mapped.coverage, mappedCopy(mapped, delivery));
|
|
339
|
+
}
|
|
340
|
+
index.mapped.set(key, mapped);
|
|
341
|
+
}
|
|
342
|
+
return mapped.coverage;
|
|
123
343
|
}
|
|
124
344
|
function buildDeliveryIndex(delivered) {
|
|
125
345
|
const index = {
|
|
126
346
|
byBounds: new Map(),
|
|
127
347
|
bySlice: new Map(),
|
|
348
|
+
coverage: new Map(),
|
|
349
|
+
mapped: new Map(),
|
|
128
350
|
};
|
|
129
351
|
for (const delivery of delivered) {
|
|
130
352
|
addToDeliveryIndex(index, delivery);
|
|
@@ -134,6 +356,7 @@ function buildDeliveryIndex(delivered) {
|
|
|
134
356
|
function boxReductionOf(statistic) {
|
|
135
357
|
return (requireVoxelStatistic(statistic).boxReduction ?? VoxelReductions.BoxAverage);
|
|
136
358
|
}
|
|
359
|
+
export { coverageOfRegion };
|
|
137
360
|
export default class CompositeVoxelManager {
|
|
138
361
|
constructor({ primary, grid, statistic = VoxelStatistics.Average, quality, delivered, id, }) {
|
|
139
362
|
this.representations = [];
|
|
@@ -284,6 +507,7 @@ export default class CompositeVoxelManager {
|
|
|
284
507
|
return false;
|
|
285
508
|
}
|
|
286
509
|
existing.quality = quality;
|
|
510
|
+
raiseInDeliveryIndex(index, existing);
|
|
287
511
|
return true;
|
|
288
512
|
}
|
|
289
513
|
const containers = index.bySlice.get(bounds[2][0]);
|
|
@@ -333,6 +557,11 @@ export default class CompositeVoxelManager {
|
|
|
333
557
|
}
|
|
334
558
|
return index;
|
|
335
559
|
}
|
|
560
|
+
coverageOf(delivered, region) {
|
|
561
|
+
return ((delivered &&
|
|
562
|
+
coverageFromIncremental(this.deliveryIndexOf(delivered).coverage, region)) ??
|
|
563
|
+
coverageOfRegion(delivered, region));
|
|
564
|
+
}
|
|
336
565
|
getRegionQuality(representation, region) {
|
|
337
566
|
const { grid } = representation;
|
|
338
567
|
const target = region
|
|
@@ -358,7 +587,7 @@ export default class CompositeVoxelManager {
|
|
|
358
587
|
if (representation.derivedFrom) {
|
|
359
588
|
return withStatus(this.qualityOfDerived(representation, target, record));
|
|
360
589
|
}
|
|
361
|
-
const coverage =
|
|
590
|
+
const coverage = this.coverageOf(representation.delivered, target);
|
|
362
591
|
let { covered } = coverage;
|
|
363
592
|
record.deliveries = coverage.deliveries;
|
|
364
593
|
record.lowest = coverage.lowest;
|
|
@@ -402,7 +631,7 @@ export default class CompositeVoxelManager {
|
|
|
402
631
|
const { grid, delivered, quality } = representation.derivedFrom;
|
|
403
632
|
const sourceBounds = intersectBounds(mapBoundsBetweenGrids(representation.grid, grid, target), boundsOfGrid(grid));
|
|
404
633
|
const sourceVoxels = volumeOfBounds(sourceBounds);
|
|
405
|
-
const coverage =
|
|
634
|
+
const coverage = this.coverageOf(delivered, sourceBounds);
|
|
406
635
|
record.deliveries = coverage.deliveries;
|
|
407
636
|
record.lowest = coverage.lowest;
|
|
408
637
|
record.highest = coverage.highest;
|
|
@@ -417,10 +646,12 @@ export default class CompositeVoxelManager {
|
|
|
417
646
|
record.missing = 0;
|
|
418
647
|
return withStatus(record);
|
|
419
648
|
}
|
|
420
|
-
const boxes =
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
649
|
+
const boxes = (delivered &&
|
|
650
|
+
coverageFromIncremental(mappedCoverageOf(this.deliveryIndexOf(delivered), delivered, grid, representation.grid), target)) ??
|
|
651
|
+
coverageOfRegion((delivered ?? []).map((delivery) => ({
|
|
652
|
+
bounds: mapBoundsBetweenGrids(grid, representation.grid, delivery.bounds),
|
|
653
|
+
quality: delivery.quality,
|
|
654
|
+
})), target);
|
|
424
655
|
record.missing = record.voxels - boxes.covered;
|
|
425
656
|
record.exact = record.exact && boxes.exact;
|
|
426
657
|
return withStatus(record);
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.17.
|
|
1
|
+
export declare const version = "5.17.2";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.17.
|
|
1
|
+
export const version = '5.17.2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/core",
|
|
3
|
-
"version": "5.17.
|
|
3
|
+
"version": "5.17.2",
|
|
4
4
|
"description": "Cornerstone3D Core",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -85,18 +85,18 @@
|
|
|
85
85
|
"prepublishOnly": "pnpm run build"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@cornerstonejs/utils": "5.17.
|
|
88
|
+
"@cornerstonejs/utils": "5.17.2",
|
|
89
89
|
"@kitware/vtk.js": "36.4.1",
|
|
90
90
|
"comlink": "4.4.2",
|
|
91
91
|
"gl-matrix": "3.4.3",
|
|
92
92
|
"loglevel": "1.9.2"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
|
-
"@cornerstonejs/metadata": "5.17.
|
|
95
|
+
"@cornerstonejs/metadata": "5.17.2"
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
98
|
-
"@cornerstonejs/metadata": "5.17.
|
|
99
|
-
"@cornerstonejs/utils": "5.17.
|
|
98
|
+
"@cornerstonejs/metadata": "5.17.2",
|
|
99
|
+
"@cornerstonejs/utils": "5.17.2"
|
|
100
100
|
},
|
|
101
101
|
"contributors": [
|
|
102
102
|
{
|