@cornerstonejs/core 5.16.0 → 5.17.1
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 +2 -0
- package/dist/esm/RenderingEngine/BaseRenderingEngine.js +25 -0
- package/dist/esm/RenderingEngine/BaseVolumeViewport.d.ts +11 -1
- package/dist/esm/RenderingEngine/BaseVolumeViewport.js +101 -2
- package/dist/esm/RenderingEngine/ContextPoolRenderingEngine.js +5 -2
- package/dist/esm/RenderingEngine/GenericViewport/GenericViewport.d.ts +11 -1
- package/dist/esm/RenderingEngine/GenericViewport/GenericViewport.js +63 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/CpuImageSliceRenderPath.js +19 -1
- package/dist/esm/RenderingEngine/GenericViewport/Planar/CpuVolumeSliceRenderPath.d.ts +1 -1
- package/dist/esm/RenderingEngine/GenericViewport/Planar/CpuVolumeSliceRenderPath.js +12 -3
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarMountedData.js +4 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarRenderPathDecisionService.d.ts +6 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarRenderPathDecisionService.js +42 -13
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewReferenceController.d.ts +1 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewReferenceController.js +39 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewport.d.ts +9 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewport.js +65 -6
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewportLegacyAdapter.d.ts +1 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewportLegacyAdapter.js +3 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewportTypes.d.ts +1 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/VtkImageMapperRenderPath.js +18 -1
- package/dist/esm/RenderingEngine/GenericViewport/Planar/VtkVolumeSliceRenderPath.d.ts +8 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/VtkVolumeSliceRenderPath.js +49 -30
- package/dist/esm/RenderingEngine/GenericViewport/Planar/planarAcquiredFrames.d.ts +6 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/planarAcquiredFrames.js +185 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/planarImageEvents.d.ts +6 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/planarImageEvents.js +16 -0
- package/dist/esm/RenderingEngine/GenericViewport/Planar/planarRuntimeTypes.d.ts +3 -1
- package/dist/esm/RenderingEngine/GenericViewport/ViewportArchitectureTypes.d.ts +17 -2
- package/dist/esm/RenderingEngine/GenericViewport/Volume3D/VolumeViewport3DLegacyAdapter.d.ts +1 -0
- package/dist/esm/RenderingEngine/GenericViewport/Volume3D/VolumeViewport3DLegacyAdapter.js +13 -0
- package/dist/esm/RenderingEngine/GenericViewport/Volume3D/VtkVolume3DRenderPath.d.ts +5 -0
- package/dist/esm/RenderingEngine/GenericViewport/Volume3D/VtkVolume3DRenderPath.js +49 -34
- package/dist/esm/RenderingEngine/GenericViewport/Volume3D/viewport3D.d.ts +4 -1
- package/dist/esm/RenderingEngine/GenericViewport/Volume3D/viewport3D.js +15 -0
- package/dist/esm/RenderingEngine/GenericViewport/Volume3D/viewport3DTypes.d.ts +2 -1
- package/dist/esm/RenderingEngine/GenericViewport/renderingFidelity.d.ts +16 -0
- package/dist/esm/RenderingEngine/GenericViewport/renderingFidelity.js +15 -0
- package/dist/esm/RenderingEngine/StackViewport.d.ts +3 -0
- package/dist/esm/RenderingEngine/StackViewport.js +7 -0
- package/dist/esm/RenderingEngine/TiledRenderingEngine.js +7 -1
- package/dist/esm/RenderingEngine/Viewport.d.ts +8 -1
- package/dist/esm/RenderingEngine/Viewport.js +26 -0
- package/dist/esm/RenderingEngine/VolumeViewport3D.js +5 -9
- package/dist/esm/RenderingEngine/helpers/actorsWaitingForStorage.d.ts +3 -0
- package/dist/esm/RenderingEngine/helpers/actorsWaitingForStorage.js +5 -0
- package/dist/esm/RenderingEngine/helpers/createVolumeActor.d.ts +2 -1
- package/dist/esm/RenderingEngine/helpers/createVolumeActor.js +15 -1
- package/dist/esm/RenderingEngine/helpers/createVolumeMapper.d.ts +15 -1
- package/dist/esm/RenderingEngine/helpers/createVolumeMapper.js +41 -8
- package/dist/esm/RenderingEngine/helpers/createVolumeSliceActor.d.ts +2 -1
- package/dist/esm/RenderingEngine/helpers/createVolumeSliceActor.js +16 -4
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/attachFidelityIndicator.d.ts +7 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/attachFidelityIndicator.js +396 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/buildViewportFidelityState.d.ts +4 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/buildViewportFidelityState.js +138 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/collectFidelityLines.d.ts +30 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/collectFidelityLines.js +138 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/displaySpacingOfViewport.d.ts +33 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/displaySpacingOfViewport.js +67 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityDetailsText.d.ts +3 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityDetailsText.js +108 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityIndicatorState.d.ts +34 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityIndicatorState.js +135 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityIndicatorStyles.d.ts +2 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityIndicatorStyles.js +67 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityLabel.d.ts +3 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/fidelityLabel.js +6 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/index.d.ts +9 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/index.js +9 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/isLabelmapActorEntry.d.ts +2 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/isLabelmapActorEntry.js +3 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/notifyFidelityStateChanged.d.ts +9 -0
- package/dist/esm/RenderingEngine/helpers/fidelityIndicator/notifyFidelityStateChanged.js +21 -0
- package/dist/esm/RenderingEngine/helpers/legacyActorTextureSet.d.ts +3 -0
- package/dist/esm/RenderingEngine/helpers/legacyActorTextureSet.js +54 -0
- package/dist/esm/RenderingEngine/helpers/resolveVolumeTexture.d.ts +14 -0
- package/dist/esm/RenderingEngine/helpers/resolveVolumeTexture.js +22 -0
- package/dist/esm/RenderingEngine/helpers/setDefaultVolumeVOI.js +6 -4
- package/dist/esm/RenderingEngine/helpers/stats/RenderModesPanel.d.ts +13 -6
- package/dist/esm/RenderingEngine/helpers/stats/RenderModesPanel.js +98 -5
- package/dist/esm/RenderingEngine/helpers/stats/StatsOverlay.d.ts +3 -0
- package/dist/esm/RenderingEngine/helpers/stats/StatsOverlay.js +70 -0
- package/dist/esm/RenderingEngine/helpers/stats/constants.d.ts +21 -1
- package/dist/esm/RenderingEngine/helpers/stats/constants.js +21 -1
- package/dist/esm/RenderingEngine/helpers/volumeRenderStrategy.d.ts +43 -0
- package/dist/esm/RenderingEngine/helpers/volumeRenderStrategy.js +153 -0
- package/dist/esm/RenderingEngine/helpers/volumeStrategyLifecycle.d.ts +31 -0
- package/dist/esm/RenderingEngine/helpers/volumeStrategyLifecycle.js +104 -0
- package/dist/esm/RenderingEngine/vtkClasses/canUseFloatOpacityTexture.d.ts +1 -1
- package/dist/esm/RenderingEngine/vtkClasses/canUseFloatOpacityTexture.js +2 -5
- package/dist/esm/RenderingEngine/vtkClasses/takeBoundScalarTexture.d.ts +1 -0
- package/dist/esm/RenderingEngine/vtkClasses/takeBoundScalarTexture.js +12 -0
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLImageResliceMapper.js +11 -2
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLTexture.js +393 -7
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLVolumeMapper.d.ts +4 -0
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLVolumeMapper.js +48 -3
- package/dist/esm/cache/cache.d.ts +3 -0
- package/dist/esm/cache/cache.js +21 -13
- package/dist/esm/cache/classes/BaseStreamingImageVolume.d.ts +12 -5
- package/dist/esm/cache/classes/BaseStreamingImageVolume.js +117 -18
- package/dist/esm/cache/classes/ImageVolume.d.ts +44 -2
- package/dist/esm/cache/classes/ImageVolume.js +169 -9
- package/dist/esm/cache/classes/StreamingDynamicImageVolume.d.ts +1 -2
- package/dist/esm/cache/classes/StreamingDynamicImageVolume.js +4 -0
- package/dist/esm/cache/classes/VolumeTextureSet.d.ts +42 -0
- package/dist/esm/cache/classes/VolumeTextureSet.js +66 -0
- package/dist/esm/cache/index.d.ts +5 -1
- package/dist/esm/cache/index.js +3 -1
- package/dist/esm/cache/volumeTextureStore.d.ts +46 -0
- package/dist/esm/cache/volumeTextureStore.js +181 -0
- package/dist/esm/enums/Events.d.ts +3 -0
- package/dist/esm/enums/Events.js +3 -0
- package/dist/esm/enums/VoxelDataSources.d.ts +5 -0
- package/dist/esm/enums/VoxelDataSources.js +15 -0
- package/dist/esm/enums/VoxelReductions.d.ts +5 -0
- package/dist/esm/enums/VoxelReductions.js +15 -0
- package/dist/esm/enums/VoxelStatistics.d.ts +5 -0
- package/dist/esm/enums/VoxelStatistics.js +13 -0
- package/dist/esm/enums/index.d.ts +4 -1
- package/dist/esm/enums/index.js +4 -1
- package/dist/esm/index.d.ts +13 -3
- package/dist/esm/index.js +7 -3
- package/dist/esm/init.d.ts +4 -2
- package/dist/esm/init.js +23 -2
- package/dist/esm/loaders/ProgressiveRetrieveImages.d.ts +5 -1
- package/dist/esm/loaders/ProgressiveRetrieveImages.js +21 -4
- package/dist/esm/loaders/configuration/coarseInterleavedRetrieve.d.ts +5 -0
- package/dist/esm/loaders/configuration/coarseInterleavedRetrieve.js +58 -0
- package/dist/esm/loaders/volumeLoader.js +8 -2
- package/dist/esm/types/Cornerstone3DConfig.d.ts +13 -1
- package/dist/esm/types/EventTypes.d.ts +8 -1
- package/dist/esm/types/IActor.d.ts +1 -0
- package/dist/esm/types/IImage.d.ts +1 -0
- package/dist/esm/types/IVoxelManager.d.ts +88 -2
- package/dist/esm/types/ImageLoadRequests.d.ts +2 -2
- package/dist/esm/types/ViewportFidelity.d.ts +33 -0
- package/dist/esm/types/ViewportFidelity.js +0 -0
- package/dist/esm/types/VolumeProps.d.ts +2 -0
- package/dist/esm/types/VoxelGrid.d.ts +23 -0
- package/dist/esm/types/VoxelGrid.js +0 -0
- package/dist/esm/types/VoxelQuality.d.ts +38 -0
- package/dist/esm/types/VoxelQuality.js +0 -0
- package/dist/esm/types/VoxelQualityRegistry.d.ts +34 -0
- package/dist/esm/types/VoxelQualityRegistry.js +0 -0
- package/dist/esm/types/VoxelStatistic.d.ts +29 -0
- package/dist/esm/types/VoxelStatistic.js +0 -0
- package/dist/esm/types/VoxelStatisticRegistry.d.ts +13 -0
- package/dist/esm/types/VoxelStatisticRegistry.js +0 -0
- package/dist/esm/types/index.d.ts +9 -2
- package/dist/esm/utilities/CompositeVoxelManager.d.ts +150 -0
- package/dist/esm/utilities/CompositeVoxelManager.js +854 -0
- package/dist/esm/utilities/VoxelManager.d.ts +16 -14
- package/dist/esm/utilities/VoxelManager.js +140 -33
- package/dist/esm/utilities/getBufferConfiguration.d.ts +2 -1
- package/dist/esm/utilities/getBufferConfiguration.js +9 -1
- package/dist/esm/utilities/getVolumeSliceRangeInfo.js +2 -1
- package/dist/esm/utilities/getVolumeViewportScrollInfo.js +5 -1
- package/dist/esm/utilities/gpuSettingsPresets.d.ts +19 -0
- package/dist/esm/utilities/gpuSettingsPresets.js +77 -0
- package/dist/esm/utilities/index.d.ts +4 -1
- package/dist/esm/utilities/index.js +4 -1
- package/dist/esm/utilities/isAcquisitionPlaneNormal.d.ts +2 -0
- package/dist/esm/utilities/isAcquisitionPlaneNormal.js +9 -0
- package/dist/esm/utilities/renderingCapabilities.d.ts +0 -1
- package/dist/esm/utilities/renderingCapabilities.js +5 -14
- package/dist/esm/utilities/voxelGrid/averagePlane.d.ts +3 -0
- package/dist/esm/utilities/voxelGrid/averagePlane.js +44 -0
- package/dist/esm/utilities/voxelGrid/boxAverageReductionFactors.d.ts +6 -0
- package/dist/esm/utilities/voxelGrid/boxAverageReductionFactors.js +45 -0
- package/dist/esm/utilities/voxelGrid/boxSpan.d.ts +12 -0
- package/dist/esm/utilities/voxelGrid/boxSpan.js +41 -0
- package/dist/esm/utilities/voxelGrid/boxStatistic.d.ts +22 -0
- package/dist/esm/utilities/voxelGrid/boxStatistic.js +117 -0
- package/dist/esm/utilities/voxelGrid/deriveBoxAverageGrid.d.ts +3 -0
- package/dist/esm/utilities/voxelGrid/deriveBoxAverageGrid.js +33 -0
- package/dist/esm/utilities/voxelGrid/foregroundMajorityPlane.d.ts +5 -0
- package/dist/esm/utilities/voxelGrid/foregroundMajorityPlane.js +44 -0
- package/dist/esm/utilities/voxelGrid/index.d.ts +9 -0
- package/dist/esm/utilities/voxelGrid/index.js +9 -0
- package/dist/esm/utilities/voxelGrid/reducedDimensions.d.ts +4 -0
- package/dist/esm/utilities/voxelGrid/reducedDimensions.js +17 -0
- package/dist/esm/utilities/voxelGrid/resolveReduction.d.ts +10 -0
- package/dist/esm/utilities/voxelGrid/resolveReduction.js +17 -0
- package/dist/esm/utilities/voxelGrid/sliceReductions.d.ts +7 -0
- package/dist/esm/utilities/voxelGrid/sliceReductions.js +168 -0
- package/dist/esm/utilities/voxelGrid/voxelGridKey.d.ts +4 -0
- package/dist/esm/utilities/voxelGrid/voxelGridKey.js +47 -0
- package/dist/esm/utilities/voxelGrid/voxelGridSize.d.ts +5 -0
- package/dist/esm/utilities/voxelGrid/voxelGridSize.js +17 -0
- package/dist/esm/utilities/voxelGrid/voxelGridTransforms.d.ts +16 -0
- package/dist/esm/utilities/voxelGrid/voxelGridTransforms.js +145 -0
- package/dist/esm/utilities/voxelGrid/voxelQuality.d.ts +19 -0
- package/dist/esm/utilities/voxelGrid/voxelQuality.js +106 -0
- package/dist/esm/utilities/voxelGrid/voxelStatistics.d.ts +20 -0
- package/dist/esm/utilities/voxelGrid/voxelStatistics.js +141 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
import ImageQualityStatus from '../enums/ImageQualityStatus.js';
|
|
2
|
+
import VoxelDataSources from '../enums/VoxelDataSources.js';
|
|
3
|
+
import VoxelReductions from '../enums/VoxelReductions.js';
|
|
4
|
+
import VoxelStatistics from '../enums/VoxelStatistics.js';
|
|
5
|
+
import { boundsOfFrame, boundsOfGrid, containsBounds, gridCoversRegion, imageQualityStatusOfRecord, intersectBounds, isDefaultSelectionStatistic, mapBoundsBetweenGrids, mapIndexToNearestVoxel, requireVoxelStatistic, volumeOfBounds, voxelGridKey, voxelGridsEqual, } from './voxelGrid/index.js';
|
|
6
|
+
const MAX_COVERAGE_CELLS = 1 << 20;
|
|
7
|
+
const MAX_COVERAGE_WORK = 1 << 23;
|
|
8
|
+
function edgesOfAxis(boxes, region, axis) {
|
|
9
|
+
const edges = new Set([region[axis][0], region[axis][1] + 1]);
|
|
10
|
+
for (const box of boxes) {
|
|
11
|
+
edges.add(box[axis][0]);
|
|
12
|
+
edges.add(box[axis][1] + 1);
|
|
13
|
+
}
|
|
14
|
+
return [...edges].sort((a, b) => a - b);
|
|
15
|
+
}
|
|
16
|
+
function coverageOfRegion(deliveries, region) {
|
|
17
|
+
const coverage = {
|
|
18
|
+
covered: 0,
|
|
19
|
+
lowest: undefined,
|
|
20
|
+
highest: undefined,
|
|
21
|
+
deliveries: 0,
|
|
22
|
+
exact: true,
|
|
23
|
+
};
|
|
24
|
+
const clipped = [];
|
|
25
|
+
for (const delivery of deliveries ?? []) {
|
|
26
|
+
const bounds = intersectBounds(delivery.bounds, region);
|
|
27
|
+
if (volumeOfBounds(bounds) > 0) {
|
|
28
|
+
clipped.push({ bounds, quality: delivery.quality });
|
|
29
|
+
coverage.deliveries++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (clipped.length === 0) {
|
|
33
|
+
return coverage;
|
|
34
|
+
}
|
|
35
|
+
const boxes = clipped.map((delivery) => delivery.bounds);
|
|
36
|
+
const edges = [0, 1, 2].map((axis) => edgesOfAxis(boxes, region, axis));
|
|
37
|
+
const counts = edges.map((axisEdges) => axisEdges.length - 1);
|
|
38
|
+
const indexOfEdge = edges.map((axisEdges) => new Map(axisEdges.map((edge, index) => [edge, index])));
|
|
39
|
+
const cellCount = counts[0] * counts[1] * counts[2];
|
|
40
|
+
const spans = clipped.map((delivery) => ({
|
|
41
|
+
from: [0, 1, 2].map((axis) => indexOfEdge[axis].get(delivery.bounds[axis][0])),
|
|
42
|
+
to: [0, 1, 2].map((axis) => indexOfEdge[axis].get(delivery.bounds[axis][1] + 1)),
|
|
43
|
+
}));
|
|
44
|
+
const work = spans.reduce((total, { from, to }) => total + (to[0] - from[0]) * (to[1] - from[1]) * (to[2] - from[2]), 0);
|
|
45
|
+
if (cellCount > MAX_COVERAGE_CELLS || work > MAX_COVERAGE_WORK) {
|
|
46
|
+
for (const delivery of clipped) {
|
|
47
|
+
const volume = volumeOfBounds(delivery.bounds);
|
|
48
|
+
coverage.covered = Math.max(coverage.covered, volume);
|
|
49
|
+
coverage.lowest = Math.min(coverage.lowest ?? delivery.quality, delivery.quality);
|
|
50
|
+
coverage.highest = Math.max(coverage.highest ?? delivery.quality, delivery.quality);
|
|
51
|
+
}
|
|
52
|
+
coverage.exact = false;
|
|
53
|
+
return coverage;
|
|
54
|
+
}
|
|
55
|
+
const cells = new Array(cellCount).fill(0);
|
|
56
|
+
for (let index = 0; index < clipped.length; index++) {
|
|
57
|
+
const delivery = clipped[index];
|
|
58
|
+
const { from, to } = spans[index];
|
|
59
|
+
for (let k = from[2]; k < to[2]; k++) {
|
|
60
|
+
for (let j = from[1]; j < to[1]; j++) {
|
|
61
|
+
for (let i = from[0]; i < to[0]; i++) {
|
|
62
|
+
const cell = i + j * counts[0] + k * counts[0] * counts[1];
|
|
63
|
+
if (delivery.quality > cells[cell]) {
|
|
64
|
+
cells[cell] = delivery.quality;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (let k = 0; k < counts[2]; k++) {
|
|
71
|
+
for (let j = 0; j < counts[1]; j++) {
|
|
72
|
+
for (let i = 0; i < counts[0]; i++) {
|
|
73
|
+
const quality = cells[i + j * counts[0] + k * counts[0] * counts[1]];
|
|
74
|
+
if (quality === 0) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
coverage.covered +=
|
|
78
|
+
(edges[0][i + 1] - edges[0][i]) *
|
|
79
|
+
(edges[1][j + 1] - edges[1][j]) *
|
|
80
|
+
(edges[2][k + 1] - edges[2][k]);
|
|
81
|
+
coverage.lowest = Math.min(coverage.lowest ?? quality, quality);
|
|
82
|
+
coverage.highest = Math.max(coverage.highest ?? quality, quality);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return coverage;
|
|
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
|
+
}
|
|
262
|
+
function withStatus(record) {
|
|
263
|
+
record.status = imageQualityStatusOfRecord(record);
|
|
264
|
+
return record;
|
|
265
|
+
}
|
|
266
|
+
function voxelVolume(grid) {
|
|
267
|
+
return grid.spacing[0] * grid.spacing[1] * grid.spacing[2];
|
|
268
|
+
}
|
|
269
|
+
function withinCeiling(grid, ceiling) {
|
|
270
|
+
const tolerance = 1e-6;
|
|
271
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
272
|
+
if (grid.spacing[axis] < ceiling[axis] - tolerance) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return true;
|
|
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
|
+
}
|
|
292
|
+
function boundsKey(bounds) {
|
|
293
|
+
return `${bounds[0][0]},${bounds[0][1]},${bounds[1][0]},${bounds[1][1]},${bounds[2][0]},${bounds[2][1]}`;
|
|
294
|
+
}
|
|
295
|
+
function addToDeliveryIndex(index, delivery) {
|
|
296
|
+
index.byBounds.set(boundsKey(delivery.bounds), delivery);
|
|
297
|
+
for (let k = delivery.bounds[2][0]; k <= delivery.bounds[2][1]; k++) {
|
|
298
|
+
let bucket = index.bySlice.get(k);
|
|
299
|
+
if (!bucket) {
|
|
300
|
+
bucket = new Set();
|
|
301
|
+
index.bySlice.set(k, bucket);
|
|
302
|
+
}
|
|
303
|
+
bucket.add(delivery);
|
|
304
|
+
}
|
|
305
|
+
addToCoverage(index.coverage, delivery);
|
|
306
|
+
for (const mapped of index.mapped.values()) {
|
|
307
|
+
addToCoverage(mapped.coverage, mappedCopy(mapped, delivery));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function removeFromDeliveryIndex(index, delivery) {
|
|
311
|
+
index.byBounds.delete(boundsKey(delivery.bounds));
|
|
312
|
+
for (let k = delivery.bounds[2][0]; k <= delivery.bounds[2][1]; k++) {
|
|
313
|
+
index.bySlice.get(k)?.delete(delivery);
|
|
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;
|
|
343
|
+
}
|
|
344
|
+
function buildDeliveryIndex(delivered) {
|
|
345
|
+
const index = {
|
|
346
|
+
byBounds: new Map(),
|
|
347
|
+
bySlice: new Map(),
|
|
348
|
+
coverage: new Map(),
|
|
349
|
+
mapped: new Map(),
|
|
350
|
+
};
|
|
351
|
+
for (const delivery of delivered) {
|
|
352
|
+
addToDeliveryIndex(index, delivery);
|
|
353
|
+
}
|
|
354
|
+
return index;
|
|
355
|
+
}
|
|
356
|
+
function boxReductionOf(statistic) {
|
|
357
|
+
return (requireVoxelStatistic(statistic).boxReduction ?? VoxelReductions.BoxAverage);
|
|
358
|
+
}
|
|
359
|
+
export { coverageOfRegion };
|
|
360
|
+
export default class CompositeVoxelManager {
|
|
361
|
+
constructor({ primary, grid, statistic = VoxelStatistics.Average, quality, delivered, id, }) {
|
|
362
|
+
this.representations = [];
|
|
363
|
+
this.deliveryIndexes = new WeakMap();
|
|
364
|
+
this.getAtIJK = (i, j, k) => {
|
|
365
|
+
const value = this.primary.getAtIJK(i, j, k);
|
|
366
|
+
if (value !== undefined && value !== null) {
|
|
367
|
+
return value;
|
|
368
|
+
}
|
|
369
|
+
if (this.representations.length === 1) {
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
return this.valueFromSources(this.coveringRepresentations().filter((representation) => representation !== this.primaryRepresentation), this.grid, [i, j, k]);
|
|
373
|
+
};
|
|
374
|
+
this.getAtIJKPoint = (point) => this.getAtIJK(point[0], point[1], point[2]);
|
|
375
|
+
this.getAtIndex = (index) => this.getAtIJKPoint(this.toIJK(index));
|
|
376
|
+
this.setAtIJK = (i, j, k, v) => this.primary.setAtIJK(i, j, k, v);
|
|
377
|
+
this.setAtIJKPoint = (point, v) => this.primary.setAtIJKPoint(point, v);
|
|
378
|
+
this.setAtIndex = (index, v) => this.primary.setAtIndex(index, v);
|
|
379
|
+
this.forEach = (callback, options) => this.primary.forEach(callback, options);
|
|
380
|
+
this.getSliceData = (args) => this.primary.getSliceData(args);
|
|
381
|
+
this.getMiddleSliceData = () => this.primary.getMiddleSliceData();
|
|
382
|
+
this.primary = primary;
|
|
383
|
+
this.compositeId = id || `composite-${primary.id}`;
|
|
384
|
+
this.primaryRepresentation = {
|
|
385
|
+
grid,
|
|
386
|
+
statistic,
|
|
387
|
+
voxelManager: primary,
|
|
388
|
+
quality,
|
|
389
|
+
delivered,
|
|
390
|
+
};
|
|
391
|
+
this.representations.push(this.primaryRepresentation);
|
|
392
|
+
}
|
|
393
|
+
get grid() {
|
|
394
|
+
return this.primaryRepresentation.grid;
|
|
395
|
+
}
|
|
396
|
+
getRepresentations() {
|
|
397
|
+
return [...this.representations];
|
|
398
|
+
}
|
|
399
|
+
addRepresentation(representation) {
|
|
400
|
+
const key = voxelGridKey(representation.grid, representation.statistic);
|
|
401
|
+
const existing = this.representations.findIndex((candidate) => voxelGridKey(candidate.grid, candidate.statistic) === key);
|
|
402
|
+
if (existing >= 0) {
|
|
403
|
+
this.representations[existing] = representation;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
this.representations.push(representation);
|
|
407
|
+
}
|
|
408
|
+
return representation;
|
|
409
|
+
}
|
|
410
|
+
getRepresentation(grid, statistic = VoxelStatistics.Average) {
|
|
411
|
+
const key = voxelGridKey(grid, statistic);
|
|
412
|
+
return this.representations.find((candidate) => voxelGridKey(candidate.grid, candidate.statistic) === key);
|
|
413
|
+
}
|
|
414
|
+
selectRepresentation({ region, statistic, ceiling, } = {}) {
|
|
415
|
+
const candidates = this.candidatesFor(region, statistic);
|
|
416
|
+
if (candidates.length === 0) {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
const atOrBelowCeiling = ceiling
|
|
420
|
+
? candidates.filter((candidate) => withinCeiling(candidate.grid, ceiling))
|
|
421
|
+
: candidates;
|
|
422
|
+
if (atOrBelowCeiling.length > 0) {
|
|
423
|
+
return this.finest(atOrBelowCeiling, region);
|
|
424
|
+
}
|
|
425
|
+
return this.coarsest(candidates, region);
|
|
426
|
+
}
|
|
427
|
+
coveringRepresentations(region, statistic) {
|
|
428
|
+
return this.candidatesFor(region, statistic).sort((a, b) => voxelVolume(a.grid) - voxelVolume(b.grid));
|
|
429
|
+
}
|
|
430
|
+
getGridQuality(grid, { statistic = VoxelStatistics.Average, region, } = {}) {
|
|
431
|
+
const existing = this.getRepresentation(grid, statistic);
|
|
432
|
+
if (existing) {
|
|
433
|
+
return this.getRegionQuality(existing, region);
|
|
434
|
+
}
|
|
435
|
+
const source = this.sourceOfDerivation(this.grid, { statistic });
|
|
436
|
+
if (!source) {
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
const reducesAnAxis = !voxelGridsEqual(grid, source.grid);
|
|
440
|
+
return this.getRegionQuality({
|
|
441
|
+
grid,
|
|
442
|
+
statistic,
|
|
443
|
+
voxelManager: undefined,
|
|
444
|
+
reduction: reducesAnAxis
|
|
445
|
+
? boxReductionOf(statistic)
|
|
446
|
+
: VoxelReductions.None,
|
|
447
|
+
source: VoxelDataSources.ClientDerived,
|
|
448
|
+
derivedFrom: {
|
|
449
|
+
grid: source.grid,
|
|
450
|
+
delivered: source.delivered,
|
|
451
|
+
quality: source.quality,
|
|
452
|
+
},
|
|
453
|
+
}, region);
|
|
454
|
+
}
|
|
455
|
+
acceptData({ grid, voxelManager, imageIds, statistic = VoxelStatistics.Average, quality = ImageQualityStatus.FULL_RESOLUTION, bounds, frameIndex, reduction, source, }) {
|
|
456
|
+
const existing = this.getRepresentation(grid, statistic);
|
|
457
|
+
const production = {
|
|
458
|
+
reduction: reduction ?? existing?.reduction ?? VoxelReductions.None,
|
|
459
|
+
source: source ?? existing?.source ?? VoxelDataSources.DirectLoad,
|
|
460
|
+
};
|
|
461
|
+
const deliveredBounds = bounds ??
|
|
462
|
+
(frameIndex === undefined ? undefined : boundsOfFrame(grid, frameIndex));
|
|
463
|
+
if (!deliveredBounds) {
|
|
464
|
+
return this.addRepresentation({
|
|
465
|
+
grid,
|
|
466
|
+
statistic,
|
|
467
|
+
voxelManager: voxelManager ?? existing?.voxelManager,
|
|
468
|
+
imageIds: imageIds ?? existing?.imageIds,
|
|
469
|
+
quality,
|
|
470
|
+
delivered: existing?.delivered,
|
|
471
|
+
...production,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
const representation = existing ??
|
|
475
|
+
this.addRepresentation({
|
|
476
|
+
grid,
|
|
477
|
+
statistic,
|
|
478
|
+
voxelManager,
|
|
479
|
+
imageIds,
|
|
480
|
+
delivered: [],
|
|
481
|
+
...production,
|
|
482
|
+
});
|
|
483
|
+
representation.reduction = production.reduction;
|
|
484
|
+
representation.source = production.source;
|
|
485
|
+
if (voxelManager && representation.voxelManager !== voxelManager) {
|
|
486
|
+
representation.voxelManager = voxelManager;
|
|
487
|
+
}
|
|
488
|
+
if (imageIds) {
|
|
489
|
+
representation.imageIds = imageIds;
|
|
490
|
+
}
|
|
491
|
+
this.setDeliveredQuality(representation, deliveredBounds, quality);
|
|
492
|
+
return representation;
|
|
493
|
+
}
|
|
494
|
+
sourceOfDerivation(grid, { statistic }) {
|
|
495
|
+
return (this.getRepresentation(grid, statistic) ||
|
|
496
|
+
this.getRepresentation(grid, this.primaryRepresentation.statistic));
|
|
497
|
+
}
|
|
498
|
+
setDeliveredQuality(representation, bounds, quality) {
|
|
499
|
+
if (!representation.delivered) {
|
|
500
|
+
representation.delivered = [];
|
|
501
|
+
}
|
|
502
|
+
const { delivered } = representation;
|
|
503
|
+
const index = this.deliveryIndexOf(delivered);
|
|
504
|
+
const existing = index.byBounds.get(boundsKey(bounds));
|
|
505
|
+
if (existing) {
|
|
506
|
+
if (existing.quality >= quality) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
existing.quality = quality;
|
|
510
|
+
raiseInDeliveryIndex(index, existing);
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
const containers = index.bySlice.get(bounds[2][0]);
|
|
514
|
+
if (containers) {
|
|
515
|
+
for (const delivery of containers) {
|
|
516
|
+
if (delivery.quality >= quality &&
|
|
517
|
+
containsBounds(delivery.bounds, bounds)) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const contained = new Set();
|
|
523
|
+
for (let k = bounds[2][0]; k <= bounds[2][1]; k++) {
|
|
524
|
+
const bucket = index.bySlice.get(k);
|
|
525
|
+
if (!bucket) {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
for (const delivery of bucket) {
|
|
529
|
+
if (delivery.quality <= quality &&
|
|
530
|
+
containsBounds(bounds, delivery.bounds)) {
|
|
531
|
+
contained.add(delivery);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (contained.size) {
|
|
536
|
+
for (const delivery of contained) {
|
|
537
|
+
removeFromDeliveryIndex(index, delivery);
|
|
538
|
+
}
|
|
539
|
+
let write = 0;
|
|
540
|
+
for (let read = 0; read < delivered.length; read++) {
|
|
541
|
+
if (!contained.has(delivered[read])) {
|
|
542
|
+
delivered[write++] = delivered[read];
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
delivered.length = write;
|
|
546
|
+
}
|
|
547
|
+
const delivery = { bounds, quality };
|
|
548
|
+
delivered.push(delivery);
|
|
549
|
+
addToDeliveryIndex(index, delivery);
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
deliveryIndexOf(delivered) {
|
|
553
|
+
let index = this.deliveryIndexes.get(delivered);
|
|
554
|
+
if (!index) {
|
|
555
|
+
index = buildDeliveryIndex(delivered);
|
|
556
|
+
this.deliveryIndexes.set(delivered, index);
|
|
557
|
+
}
|
|
558
|
+
return index;
|
|
559
|
+
}
|
|
560
|
+
coverageOf(delivered, region) {
|
|
561
|
+
return ((delivered &&
|
|
562
|
+
coverageFromIncremental(this.deliveryIndexOf(delivered).coverage, region)) ??
|
|
563
|
+
coverageOfRegion(delivered, region));
|
|
564
|
+
}
|
|
565
|
+
getRegionQuality(representation, region) {
|
|
566
|
+
const { grid } = representation;
|
|
567
|
+
const target = region
|
|
568
|
+
? intersectBounds(mapBoundsBetweenGrids(this.grid, grid, region), boundsOfGrid(grid))
|
|
569
|
+
: boundsOfGrid(grid);
|
|
570
|
+
const voxels = volumeOfBounds(target);
|
|
571
|
+
const record = {
|
|
572
|
+
grid,
|
|
573
|
+
reduction: representation.reduction ?? VoxelReductions.None,
|
|
574
|
+
source: representation.source ?? VoxelDataSources.DirectLoad,
|
|
575
|
+
lowest: undefined,
|
|
576
|
+
highest: undefined,
|
|
577
|
+
voxels,
|
|
578
|
+
missing: voxels,
|
|
579
|
+
deliveries: 0,
|
|
580
|
+
exact: true,
|
|
581
|
+
status: ImageQualityStatus.FAR_REPLICATE,
|
|
582
|
+
};
|
|
583
|
+
if (voxels === 0) {
|
|
584
|
+
record.missing = 0;
|
|
585
|
+
return withStatus(record);
|
|
586
|
+
}
|
|
587
|
+
if (representation.derivedFrom) {
|
|
588
|
+
return withStatus(this.qualityOfDerived(representation, target, record));
|
|
589
|
+
}
|
|
590
|
+
const coverage = this.coverageOf(representation.delivered, target);
|
|
591
|
+
let { covered } = coverage;
|
|
592
|
+
record.deliveries = coverage.deliveries;
|
|
593
|
+
record.lowest = coverage.lowest;
|
|
594
|
+
record.highest = coverage.highest;
|
|
595
|
+
record.exact = coverage.exact;
|
|
596
|
+
if (covered < voxels && representation.quality !== undefined) {
|
|
597
|
+
record.lowest = Math.min(record.lowest ?? representation.quality, representation.quality);
|
|
598
|
+
record.highest = Math.max(record.highest ?? representation.quality, representation.quality);
|
|
599
|
+
covered = voxels;
|
|
600
|
+
}
|
|
601
|
+
record.missing = voxels - covered;
|
|
602
|
+
return withStatus(record);
|
|
603
|
+
}
|
|
604
|
+
fillGrid(grid, target, statistic = VoxelStatistics.Average) {
|
|
605
|
+
const sources = this.coveringRepresentations(undefined, statistic);
|
|
606
|
+
if (!sources.includes(this.primaryRepresentation)) {
|
|
607
|
+
sources.unshift(this.primaryRepresentation);
|
|
608
|
+
}
|
|
609
|
+
let written = 0;
|
|
610
|
+
for (let k = 0; k < grid.dimensions[2]; k++) {
|
|
611
|
+
for (let j = 0; j < grid.dimensions[1]; j++) {
|
|
612
|
+
for (let i = 0; i < grid.dimensions[0]; i++) {
|
|
613
|
+
const value = this.valueFromSources(sources, grid, [i, j, k]);
|
|
614
|
+
if (value === undefined) {
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
target.setAtIJK(i, j, k, value);
|
|
618
|
+
written++;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return written;
|
|
623
|
+
}
|
|
624
|
+
getQuality(selector = {}) {
|
|
625
|
+
const selected = this.selectRepresentation(selector);
|
|
626
|
+
return selected
|
|
627
|
+
? this.getRegionQuality(selected, selector.region)
|
|
628
|
+
: undefined;
|
|
629
|
+
}
|
|
630
|
+
qualityOfDerived(representation, target, record) {
|
|
631
|
+
const { grid, delivered, quality } = representation.derivedFrom;
|
|
632
|
+
const sourceBounds = intersectBounds(mapBoundsBetweenGrids(representation.grid, grid, target), boundsOfGrid(grid));
|
|
633
|
+
const sourceVoxels = volumeOfBounds(sourceBounds);
|
|
634
|
+
const coverage = this.coverageOf(delivered, sourceBounds);
|
|
635
|
+
record.deliveries = coverage.deliveries;
|
|
636
|
+
record.lowest = coverage.lowest;
|
|
637
|
+
record.highest = coverage.highest;
|
|
638
|
+
record.exact = coverage.exact;
|
|
639
|
+
if (sourceVoxels === 0) {
|
|
640
|
+
record.missing = record.voxels;
|
|
641
|
+
return withStatus(record);
|
|
642
|
+
}
|
|
643
|
+
if (coverage.covered < sourceVoxels && quality !== undefined) {
|
|
644
|
+
record.lowest = Math.min(record.lowest ?? quality, quality);
|
|
645
|
+
record.highest = Math.max(record.highest ?? quality, quality);
|
|
646
|
+
record.missing = 0;
|
|
647
|
+
return withStatus(record);
|
|
648
|
+
}
|
|
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);
|
|
655
|
+
record.missing = record.voxels - boxes.covered;
|
|
656
|
+
record.exact = record.exact && boxes.exact;
|
|
657
|
+
return withStatus(record);
|
|
658
|
+
}
|
|
659
|
+
candidatesFor(region, statistic) {
|
|
660
|
+
return this.representations.filter((candidate) => {
|
|
661
|
+
if (statistic) {
|
|
662
|
+
if (candidate.statistic !== statistic) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
else if (!isDefaultSelectionStatistic(candidate.statistic)) {
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
if (!region) {
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
return gridCoversRegion(this.grid, region, candidate.grid);
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
finest(representations, region) {
|
|
676
|
+
return representations.reduce((best, candidate) => this.better(candidate, best, -1, region) ? candidate : best);
|
|
677
|
+
}
|
|
678
|
+
coarsest(representations, region) {
|
|
679
|
+
return representations.reduce((best, candidate) => this.better(candidate, best, 1, region) ? candidate : best);
|
|
680
|
+
}
|
|
681
|
+
better(candidate, best, direction, region) {
|
|
682
|
+
const difference = voxelVolume(candidate.grid) - voxelVolume(best.grid);
|
|
683
|
+
if (Math.abs(difference) > 1e-9) {
|
|
684
|
+
return Math.sign(difference) === direction;
|
|
685
|
+
}
|
|
686
|
+
const candidateQuality = this.getRegionQuality(candidate, region);
|
|
687
|
+
const bestQuality = this.getRegionQuality(best, region);
|
|
688
|
+
if (candidateQuality.missing !== bestQuality.missing) {
|
|
689
|
+
return candidateQuality.missing < bestQuality.missing;
|
|
690
|
+
}
|
|
691
|
+
return (candidateQuality.lowest ?? 0) > (bestQuality.lowest ?? 0);
|
|
692
|
+
}
|
|
693
|
+
valueFromSources(sources, grid, ijk) {
|
|
694
|
+
for (const source of sources) {
|
|
695
|
+
const sourceIJK = mapIndexToNearestVoxel(grid, source.grid, ijk);
|
|
696
|
+
const { dimensions } = source.voxelManager;
|
|
697
|
+
if (sourceIJK[0] < 0 ||
|
|
698
|
+
sourceIJK[1] < 0 ||
|
|
699
|
+
sourceIJK[2] < 0 ||
|
|
700
|
+
sourceIJK[0] >= dimensions[0] ||
|
|
701
|
+
sourceIJK[1] >= dimensions[1] ||
|
|
702
|
+
sourceIJK[2] >= dimensions[2]) {
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
const value = source.voxelManager.getAtIJK(...sourceIJK);
|
|
706
|
+
if (value !== undefined && value !== null) {
|
|
707
|
+
return value;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return undefined;
|
|
711
|
+
}
|
|
712
|
+
get id() {
|
|
713
|
+
return this.compositeId;
|
|
714
|
+
}
|
|
715
|
+
get dimensions() {
|
|
716
|
+
return this.primary.dimensions;
|
|
717
|
+
}
|
|
718
|
+
get numberOfComponents() {
|
|
719
|
+
return this.primary.numberOfComponents;
|
|
720
|
+
}
|
|
721
|
+
get width() {
|
|
722
|
+
return this.primary.width;
|
|
723
|
+
}
|
|
724
|
+
set width(width) {
|
|
725
|
+
this.primary.width = width;
|
|
726
|
+
}
|
|
727
|
+
get frameSize() {
|
|
728
|
+
return this.primary.frameSize;
|
|
729
|
+
}
|
|
730
|
+
set frameSize(frameSize) {
|
|
731
|
+
this.primary.frameSize = frameSize;
|
|
732
|
+
}
|
|
733
|
+
get map() {
|
|
734
|
+
return this.primary.map;
|
|
735
|
+
}
|
|
736
|
+
set map(map) {
|
|
737
|
+
this.primary.map = map;
|
|
738
|
+
}
|
|
739
|
+
get sourceVoxelManager() {
|
|
740
|
+
return this.primary.sourceVoxelManager;
|
|
741
|
+
}
|
|
742
|
+
set sourceVoxelManager(voxelManager) {
|
|
743
|
+
this.primary.sourceVoxelManager = voxelManager;
|
|
744
|
+
}
|
|
745
|
+
get points() {
|
|
746
|
+
return this.primary.points;
|
|
747
|
+
}
|
|
748
|
+
get modifiedSlices() {
|
|
749
|
+
return this.primary.modifiedSlices;
|
|
750
|
+
}
|
|
751
|
+
get isInObject() {
|
|
752
|
+
return this.primary.isInObject;
|
|
753
|
+
}
|
|
754
|
+
set isInObject(isInObject) {
|
|
755
|
+
this.primary.isInObject = isInObject;
|
|
756
|
+
}
|
|
757
|
+
get sizeInBytes() {
|
|
758
|
+
return this.primary.sizeInBytes;
|
|
759
|
+
}
|
|
760
|
+
get bytePerVoxel() {
|
|
761
|
+
return this.primary.bytePerVoxel;
|
|
762
|
+
}
|
|
763
|
+
get _get() {
|
|
764
|
+
return this.primary._get;
|
|
765
|
+
}
|
|
766
|
+
get _set() {
|
|
767
|
+
return this.primary._set;
|
|
768
|
+
}
|
|
769
|
+
get _getConstructor() {
|
|
770
|
+
return this.primary._getConstructor;
|
|
771
|
+
}
|
|
772
|
+
get _getScalarDataLength() {
|
|
773
|
+
return this.primary._getScalarDataLength;
|
|
774
|
+
}
|
|
775
|
+
get _getScalarData() {
|
|
776
|
+
return this.primary._getScalarData;
|
|
777
|
+
}
|
|
778
|
+
get _updateScalarData() {
|
|
779
|
+
return this.primary._updateScalarData;
|
|
780
|
+
}
|
|
781
|
+
get _getSliceData() {
|
|
782
|
+
return this.primary._getSliceData;
|
|
783
|
+
}
|
|
784
|
+
get getCompleteScalarDataArray() {
|
|
785
|
+
return this.primary.getCompleteScalarDataArray;
|
|
786
|
+
}
|
|
787
|
+
get setCompleteScalarDataArray() {
|
|
788
|
+
return this.primary.setCompleteScalarDataArray;
|
|
789
|
+
}
|
|
790
|
+
get invalidateCache() {
|
|
791
|
+
return this.primary.invalidateCache;
|
|
792
|
+
}
|
|
793
|
+
get getRange() {
|
|
794
|
+
return this.primary.getRange;
|
|
795
|
+
}
|
|
796
|
+
toIJK(index) {
|
|
797
|
+
return this.primary.toIJK(index);
|
|
798
|
+
}
|
|
799
|
+
toIndex(ijk) {
|
|
800
|
+
return this.primary.toIndex(ijk);
|
|
801
|
+
}
|
|
802
|
+
getDefaultBounds() {
|
|
803
|
+
return this.primary.getDefaultBounds();
|
|
804
|
+
}
|
|
805
|
+
getBoundsIJK() {
|
|
806
|
+
return this.primary.getBoundsIJK();
|
|
807
|
+
}
|
|
808
|
+
setBounds(bounds) {
|
|
809
|
+
this.primary.setBounds(bounds);
|
|
810
|
+
}
|
|
811
|
+
clearBounds() {
|
|
812
|
+
this.primary.clearBounds();
|
|
813
|
+
}
|
|
814
|
+
rleForEach(callback, options) {
|
|
815
|
+
this.primary.rleForEach(callback, options);
|
|
816
|
+
}
|
|
817
|
+
getScalarData(storeScalarData) {
|
|
818
|
+
return this.primary.getScalarData(storeScalarData);
|
|
819
|
+
}
|
|
820
|
+
setScalarData(newScalarData) {
|
|
821
|
+
this.primary.setScalarData(newScalarData);
|
|
822
|
+
}
|
|
823
|
+
getWritableScalarData() {
|
|
824
|
+
return this.primary.getWritableScalarData();
|
|
825
|
+
}
|
|
826
|
+
setFromScalarData(scalarData) {
|
|
827
|
+
this.primary.setFromScalarData(scalarData);
|
|
828
|
+
}
|
|
829
|
+
getScalarDataLength() {
|
|
830
|
+
return this.primary.getScalarDataLength();
|
|
831
|
+
}
|
|
832
|
+
getConstructor() {
|
|
833
|
+
return this.primary.getConstructor();
|
|
834
|
+
}
|
|
835
|
+
getArrayOfModifiedSlices() {
|
|
836
|
+
return this.primary.getArrayOfModifiedSlices();
|
|
837
|
+
}
|
|
838
|
+
resetModifiedSlices() {
|
|
839
|
+
this.primary.resetModifiedSlices();
|
|
840
|
+
}
|
|
841
|
+
addPoint(point) {
|
|
842
|
+
this.primary.addPoint(point);
|
|
843
|
+
}
|
|
844
|
+
getPoints() {
|
|
845
|
+
return this.primary.getPoints();
|
|
846
|
+
}
|
|
847
|
+
getMinMax() {
|
|
848
|
+
return this.primary.getMinMax();
|
|
849
|
+
}
|
|
850
|
+
clear() {
|
|
851
|
+
this.primary.clear();
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
export { CompositeVoxelManager };
|