@cornerstonejs/core 5.8.2 → 5.10.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.
Files changed (94) hide show
  1. package/dist/esm/RenderingEngine/BaseRenderingEngine.js +4 -2
  2. package/dist/esm/RenderingEngine/BaseVolumeViewport.d.ts +1 -0
  3. package/dist/esm/RenderingEngine/BaseVolumeViewport.js +13 -3
  4. package/dist/esm/RenderingEngine/ContextPoolRenderingEngine.js +3 -1
  5. package/dist/esm/RenderingEngine/GenericViewport/DefaultRenderPathResolver.js +3 -1
  6. package/dist/esm/RenderingEngine/GenericViewport/Planar/DefaultPlanarDataProvider.js +3 -1
  7. package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewport.js +3 -1
  8. package/dist/esm/RenderingEngine/GenericViewport/Planar/PlanarViewportLegacyAdapter.js +3 -1
  9. package/dist/esm/RenderingEngine/GenericViewport/Planar/planarViewReference.js +1 -1
  10. package/dist/esm/RenderingEngine/GenericViewport/genericViewportReferenceCompatibility.js +3 -2
  11. package/dist/esm/RenderingEngine/RenderingEngine.js +3 -1
  12. package/dist/esm/RenderingEngine/StackViewport.js +8 -4
  13. package/dist/esm/RenderingEngine/TiledRenderingEngine.js +3 -1
  14. package/dist/esm/RenderingEngine/VideoViewport.d.ts +1 -0
  15. package/dist/esm/RenderingEngine/VideoViewport.js +18 -12
  16. package/dist/esm/RenderingEngine/Viewport.d.ts +1 -0
  17. package/dist/esm/RenderingEngine/Viewport.js +17 -10
  18. package/dist/esm/RenderingEngine/VolumeViewport.js +4 -2
  19. package/dist/esm/RenderingEngine/WSIViewport.js +1 -2
  20. package/dist/esm/RenderingEngine/helpers/addImageSlicesToViewports.js +3 -1
  21. package/dist/esm/RenderingEngine/helpers/addVolumesToViewports.js +3 -1
  22. package/dist/esm/RenderingEngine/helpers/attachWebGLContextEvents.js +3 -1
  23. package/dist/esm/RenderingEngine/helpers/cpuFallback/rendering/renderPseudoColorImage.js +3 -1
  24. package/dist/esm/RenderingEngine/helpers/getCameraVectors.js +3 -1
  25. package/dist/esm/RenderingEngine/helpers/stats/StatsOverlay.js +3 -1
  26. package/dist/esm/RenderingEngine/helpers/volumeNewImageEventDispatcher.js +3 -1
  27. package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLVolumeMapper.js +3 -1
  28. package/dist/esm/cache/cache.js +16 -14
  29. package/dist/esm/cache/classes/BaseStreamingImageVolume.js +4 -2
  30. package/dist/esm/eventTarget.js +3 -1
  31. package/dist/esm/init.js +12 -6
  32. package/dist/esm/loaders/ProgressiveRetrieveImages.js +3 -1
  33. package/dist/esm/loaders/cornerstoneStreamingImageVolumeLoader.js +4 -2
  34. package/dist/esm/loaders/fillNearbyFrames.js +3 -1
  35. package/dist/esm/loaders/imageLoader.d.ts +1 -0
  36. package/dist/esm/loaders/imageLoader.js +36 -7
  37. package/dist/esm/requestPool/requestPoolManager.js +3 -1
  38. package/dist/esm/types/Cornerstone3DConfig.d.ts +4 -1
  39. package/dist/esm/types/IViewport.d.ts +2 -0
  40. package/dist/esm/utilities/ProgressiveIterator.js +4 -2
  41. package/dist/esm/utilities/RLEVoxelMap.d.ts +2 -2
  42. package/dist/esm/utilities/RLEVoxelMap.js +12 -6
  43. package/dist/esm/utilities/VoxelManager.d.ts +9 -2
  44. package/dist/esm/utilities/VoxelManager.js +65 -14
  45. package/dist/esm/utilities/calculateSpacingBetweenImageIds.js +5 -3
  46. package/dist/esm/utilities/calculateViewportsSpatialRegistration.js +4 -2
  47. package/dist/esm/utilities/deepEqual.js +3 -1
  48. package/dist/esm/utilities/eventListener/TargetEventListeners.js +3 -1
  49. package/dist/esm/utilities/getBufferConfiguration.js +3 -1
  50. package/dist/esm/utilities/getEffectiveSpacingAlongDirection.d.ts +6 -0
  51. package/dist/esm/utilities/getEffectiveSpacingAlongDirection.js +11 -0
  52. package/dist/esm/utilities/getImageSliceDataForVolumeViewport.js +3 -1
  53. package/dist/esm/utilities/getVolumeSliceRangeInfo.js +3 -1
  54. package/dist/esm/utilities/index.d.ts +5 -1
  55. package/dist/esm/utilities/index.js +5 -1
  56. package/dist/esm/utilities/loadImageToCanvas.js +3 -1
  57. package/dist/esm/utilities/logger.d.ts +2 -1
  58. package/dist/esm/utilities/logger.js +2 -1
  59. package/dist/esm/utilities/resolveApplicationUrl.d.ts +3 -0
  60. package/dist/esm/utilities/resolveApplicationUrl.js +31 -0
  61. package/dist/esm/utilities/snapFocalPointToSlice.js +7 -1
  62. package/dist/esm/utilities/updatePlaneRestriction.d.ts +2 -2
  63. package/dist/esm/utilities/updatePlaneRestriction.js +47 -19
  64. package/dist/esm/utilities/voxelSlab/getVoxelThicknessAlongNormal.d.ts +6 -0
  65. package/dist/esm/utilities/voxelSlab/getVoxelThicknessAlongNormal.js +10 -0
  66. package/dist/esm/utilities/voxelSlab/index.d.ts +10 -0
  67. package/dist/esm/utilities/voxelSlab/index.js +7 -0
  68. package/dist/esm/utilities/voxelSlab/indexSpaceSlab.d.ts +29 -0
  69. package/dist/esm/utilities/voxelSlab/indexSpaceSlab.js +121 -0
  70. package/dist/esm/utilities/voxelSlab/isPlaneDepthViewable.d.ts +2 -0
  71. package/dist/esm/utilities/voxelSlab/isPlaneDepthViewable.js +12 -0
  72. package/dist/esm/utilities/voxelSlab/iterateVoxelsInShape.d.ts +20 -0
  73. package/dist/esm/utilities/voxelSlab/iterateVoxelsInShape.js +91 -0
  74. package/dist/esm/utilities/voxelSlab/sampleVoxelsInShape.d.ts +16 -0
  75. package/dist/esm/utilities/voxelSlab/sampleVoxelsInShape.js +24 -0
  76. package/dist/esm/utilities/voxelSlab/shapes/createEllipseShape.d.ts +22 -0
  77. package/dist/esm/utilities/voxelSlab/shapes/createEllipseShape.js +90 -0
  78. package/dist/esm/utilities/voxelSlab/shapes/createPolylineShape.d.ts +10 -0
  79. package/dist/esm/utilities/voxelSlab/shapes/createPolylineShape.js +170 -0
  80. package/dist/esm/utilities/voxelSlab/shapes/createRectangleShape.d.ts +14 -0
  81. package/dist/esm/utilities/voxelSlab/shapes/createRectangleShape.js +69 -0
  82. package/dist/esm/utilities/voxelSlab/shapes/index.d.ts +8 -0
  83. package/dist/esm/utilities/voxelSlab/shapes/index.js +4 -0
  84. package/dist/esm/utilities/voxelSlab/shapes/shapeGeometry.d.ts +28 -0
  85. package/dist/esm/utilities/voxelSlab/shapes/shapeGeometry.js +99 -0
  86. package/dist/esm/utilities/voxelSlab/slabMembership.d.ts +11 -0
  87. package/dist/esm/utilities/voxelSlab/slabMembership.js +42 -0
  88. package/dist/esm/utilities/wasmBasePath.d.ts +3 -0
  89. package/dist/esm/utilities/wasmBasePath.js +12 -0
  90. package/dist/esm/version.d.ts +1 -1
  91. package/dist/esm/version.js +1 -1
  92. package/dist/esm/webWorkerManager/webWorkerManager.js +6 -6
  93. package/package.json +6 -7
  94. package/LICENSE +0 -21
@@ -0,0 +1,10 @@
1
+ export { default as getVoxelThicknessAlongNormal } from './getVoxelThicknessAlongNormal.js';
2
+ export { SLAB_RELATIVE_EPSILON, getSlabEpsilon, resolveReferencePlaneThickness, getMembershipHalfWidth, getDisplayHalfWidth, signedDistanceToPlane, isWithinSlab, isVoxelCenterInSlab, projectPointOntoPlane, asUnitNormal, } from './slabMembership.js';
3
+ export { getIndexSpaceNormal, pickOuterAxis, buildIndexSpaceSlab, depthAtIndex, getDepthRun, getSlabAxisBound, } from './indexSpaceSlab.js';
4
+ export type { IndexSpaceSlab, VolumeGeometry } from './indexSpaceSlab.js';
5
+ export { isPlaneDepthViewable } from './isPlaneDepthViewable.js';
6
+ export { iterateVoxelsInShape, collectVoxelsInShape, } from './iterateVoxelsInShape.js';
7
+ export type { VoxelInShape, ShapeRunProvider, VoxelsInShapeOptions, } from './iterateVoxelsInShape.js';
8
+ export { sampleVoxelsInShape } from './sampleVoxelsInShape.js';
9
+ export type { VoxelSample, VoxelsInShapeSamplingOptions, VoxelValueSource, } from './sampleVoxelsInShape.js';
10
+ export * from './shapes/index.js';
@@ -0,0 +1,7 @@
1
+ export { default as getVoxelThicknessAlongNormal } from './getVoxelThicknessAlongNormal.js';
2
+ export { SLAB_RELATIVE_EPSILON, getSlabEpsilon, resolveReferencePlaneThickness, getMembershipHalfWidth, getDisplayHalfWidth, signedDistanceToPlane, isWithinSlab, isVoxelCenterInSlab, projectPointOntoPlane, asUnitNormal, } from './slabMembership.js';
3
+ export { getIndexSpaceNormal, pickOuterAxis, buildIndexSpaceSlab, depthAtIndex, getDepthRun, getSlabAxisBound, } from './indexSpaceSlab.js';
4
+ export { isPlaneDepthViewable } from './isPlaneDepthViewable.js';
5
+ export { iterateVoxelsInShape, collectVoxelsInShape, } from './iterateVoxelsInShape.js';
6
+ export { sampleVoxelsInShape } from './sampleVoxelsInShape.js';
7
+ export * from './shapes/index.js';
@@ -0,0 +1,29 @@
1
+ import type { mat3 } from 'gl-matrix';
2
+ import type { BoundsIJK, IImageVolume, Point2, Point3 } from '../../types/index.js';
3
+ export type VolumeGeometry = IImageVolume | {
4
+ direction: mat3;
5
+ spacing: Point3;
6
+ origin: Point3;
7
+ dimensions: Point3;
8
+ };
9
+ export interface IndexSpaceSlab {
10
+ g: Point3;
11
+ c0: number;
12
+ voxelThickness: number;
13
+ referencePlaneThickness: number;
14
+ halfWidth: number;
15
+ outerAxis: 0 | 1 | 2;
16
+ rowAxis: 0 | 1 | 2;
17
+ columnAxis: 0 | 1 | 2;
18
+ }
19
+ export declare function getIndexSpaceNormal(volume: VolumeGeometry, normal: Point3): Point3;
20
+ export declare function pickOuterAxis(g: Point3): 0 | 1 | 2;
21
+ export declare function buildIndexSpaceSlab(volume: VolumeGeometry, planePoint: Point3, normal: Point3, referencePlaneThickness?: number | null, options?: {
22
+ columnAxis?: 0 | 1 | 2;
23
+ }): IndexSpaceSlab;
24
+ export declare function depthAtIndex(slab: IndexSpaceSlab, ijk: Point3): number;
25
+ export declare function getDepthRun(slab: IndexSpaceSlab, outerIndex: number, rowIndex: number, clampTo?: Point2): Point2 | null;
26
+ export declare function getSlabAxisBound(slab: IndexSpaceSlab, axis: 0 | 1 | 2, bounds: BoundsIJK, fixed?: {
27
+ axis: 0 | 1 | 2;
28
+ index: number;
29
+ }): Point2 | null;
@@ -0,0 +1,121 @@
1
+ import { vec3 } from 'gl-matrix';
2
+ import getVoxelThicknessAlongNormal from './getVoxelThicknessAlongNormal.js';
3
+ import { getMembershipHalfWidth, getSlabEpsilon, resolveReferencePlaneThickness, } from './slabMembership.js';
4
+ export function getIndexSpaceNormal(volume, normal) {
5
+ const { direction, spacing } = volume;
6
+ const iVector = direction.slice(0, 3);
7
+ const jVector = direction.slice(3, 6);
8
+ const kVector = direction.slice(6, 9);
9
+ return [
10
+ spacing[0] * vec3.dot(iVector, normal),
11
+ spacing[1] * vec3.dot(jVector, normal),
12
+ spacing[2] * vec3.dot(kVector, normal),
13
+ ];
14
+ }
15
+ export function pickOuterAxis(g) {
16
+ const magnitudes = [Math.abs(g[0]), Math.abs(g[1]), Math.abs(g[2])];
17
+ let best = 0;
18
+ for (const axis of [1, 2]) {
19
+ if (magnitudes[axis] > magnitudes[best]) {
20
+ best = axis;
21
+ }
22
+ }
23
+ return best;
24
+ }
25
+ export function buildIndexSpaceSlab(volume, planePoint, normal, referencePlaneThickness, options = {}) {
26
+ const { origin } = volume;
27
+ const g = getIndexSpaceNormal(volume, normal);
28
+ const voxelThickness = getVoxelThicknessAlongNormal(volume, normal);
29
+ const thickness = resolveReferencePlaneThickness(referencePlaneThickness, voxelThickness);
30
+ const c0 = (origin[0] - planePoint[0]) * normal[0] +
31
+ (origin[1] - planePoint[1]) * normal[1] +
32
+ (origin[2] - planePoint[2]) * normal[2];
33
+ const halfWidth = getMembershipHalfWidth(thickness, voxelThickness) -
34
+ getSlabEpsilon(voxelThickness);
35
+ const outerAxis = pickOuterAxis(g);
36
+ const remaining = [0, 1, 2].filter((axis) => axis !== outerAxis);
37
+ let columnAxis = remaining[0];
38
+ let rowAxis = remaining[1];
39
+ if (options.columnAxis !== undefined) {
40
+ if (options.columnAxis === outerAxis) {
41
+ throw new Error(`columnAxis ${options.columnAxis} cannot also be the outer axis`);
42
+ }
43
+ columnAxis = options.columnAxis;
44
+ rowAxis = remaining[0] === columnAxis ? remaining[1] : remaining[0];
45
+ }
46
+ return {
47
+ g,
48
+ c0,
49
+ voxelThickness,
50
+ referencePlaneThickness: thickness,
51
+ halfWidth,
52
+ outerAxis,
53
+ rowAxis,
54
+ columnAxis,
55
+ };
56
+ }
57
+ export function depthAtIndex(slab, ijk) {
58
+ const { g, c0 } = slab;
59
+ return ijk[0] * g[0] + ijk[1] * g[1] + ijk[2] * g[2] + c0;
60
+ }
61
+ function integersWithProductInOpenInterval(coeff, lo, hi) {
62
+ if (lo >= hi) {
63
+ return null;
64
+ }
65
+ if (coeff === 0) {
66
+ return lo < 0 && 0 < hi ? [-Infinity, Infinity] : null;
67
+ }
68
+ const a = lo / coeff;
69
+ const b = hi / coeff;
70
+ const lowExclusive = coeff > 0 ? a : b;
71
+ const highExclusive = coeff > 0 ? b : a;
72
+ const min = Math.floor(lowExclusive) + 1;
73
+ const max = Math.ceil(highExclusive) - 1;
74
+ return min > max ? null : [min, max];
75
+ }
76
+ function clampRange(range, clampTo) {
77
+ if (!range) {
78
+ return null;
79
+ }
80
+ if (!clampTo) {
81
+ return Number.isFinite(range[0]) && Number.isFinite(range[1])
82
+ ? range
83
+ : null;
84
+ }
85
+ const min = Math.max(range[0], clampTo[0]);
86
+ const max = Math.min(range[1], clampTo[1]);
87
+ return min > max ? null : [min, max];
88
+ }
89
+ export function getDepthRun(slab, outerIndex, rowIndex, clampTo) {
90
+ const { g, c0, halfWidth, outerAxis, rowAxis, columnAxis } = slab;
91
+ if (!(halfWidth > 0)) {
92
+ return null;
93
+ }
94
+ const base = outerIndex * g[outerAxis] + rowIndex * g[rowAxis] + c0;
95
+ return clampRange(integersWithProductInOpenInterval(g[columnAxis], -halfWidth - base, halfWidth - base), clampTo);
96
+ }
97
+ export function getSlabAxisBound(slab, axis, bounds, fixed) {
98
+ const { g, c0, halfWidth } = slab;
99
+ if (!(halfWidth > 0)) {
100
+ return null;
101
+ }
102
+ let slackLow = 0;
103
+ let slackHigh = 0;
104
+ let base = c0;
105
+ for (const other of [0, 1, 2]) {
106
+ if (other === axis) {
107
+ continue;
108
+ }
109
+ if (fixed && other === fixed.axis) {
110
+ base += fixed.index * g[other];
111
+ continue;
112
+ }
113
+ const contributions = [
114
+ bounds[other][0] * g[other],
115
+ bounds[other][1] * g[other],
116
+ ];
117
+ slackLow += Math.min(contributions[0], contributions[1]);
118
+ slackHigh += Math.max(contributions[0], contributions[1]);
119
+ }
120
+ return clampRange(integersWithProductInOpenInterval(g[axis], -halfWidth - slackHigh - base, halfWidth - slackLow - base), bounds[axis]);
121
+ }
@@ -0,0 +1,2 @@
1
+ import type { Point3 } from '../../types/index.js';
2
+ export declare function isPlaneDepthViewable(planePoint: Point3, focalPoint: Point3, viewPlaneNormal: Point3, referencePlaneThickness?: number, viewportSlabThickness?: number): boolean;
@@ -0,0 +1,12 @@
1
+ import { vec3 } from 'gl-matrix';
2
+ import { isEqual } from '../isEqual.js';
3
+ import { getDisplayHalfWidth, SLAB_RELATIVE_EPSILON } from './slabMembership.js';
4
+ export function isPlaneDepthViewable(planePoint, focalPoint, viewPlaneNormal, referencePlaneThickness, viewportSlabThickness = 0) {
5
+ const pointVector = vec3.sub(vec3.create(), planePoint, focalPoint);
6
+ const depth = vec3.dot(pointVector, viewPlaneNormal);
7
+ if (!Number.isFinite(referencePlaneThickness)) {
8
+ return isEqual(0, depth);
9
+ }
10
+ const halfWidth = getDisplayHalfWidth(viewportSlabThickness, referencePlaneThickness);
11
+ return (Math.abs(depth) < halfWidth - Math.abs(halfWidth) * SLAB_RELATIVE_EPSILON);
12
+ }
@@ -0,0 +1,20 @@
1
+ import type { BoundsIJK, Point2, Point3 } from '../../types/index.js';
2
+ import type { IndexSpaceSlab, VolumeGeometry } from './indexSpaceSlab.js';
3
+ export interface VoxelInShape {
4
+ ijk: Point3;
5
+ center: Point3;
6
+ depth: number;
7
+ }
8
+ export type ShapeRunProvider = (outerIndex: number, rowIndex: number, depthRun: Point2, slab: IndexSpaceSlab) => Iterable<Point2>;
9
+ export interface VoxelsInShapeOptions {
10
+ volume: VolumeGeometry;
11
+ planePoint: Point3;
12
+ viewPlaneNormal: Point3;
13
+ referencePlaneThickness?: number | null;
14
+ bounds?: BoundsIJK;
15
+ getShapeRuns?: ShapeRunProvider;
16
+ isInShape?: (center: Point3, ijk: Point3) => boolean;
17
+ columnAxis?: 0 | 1 | 2;
18
+ }
19
+ export declare function iterateVoxelsInShape(options: VoxelsInShapeOptions): Generator<VoxelInShape, void, undefined>;
20
+ export declare function collectVoxelsInShape(options: VoxelsInShapeOptions): Point3[];
@@ -0,0 +1,91 @@
1
+ import { buildIndexSpaceSlab, getDepthRun, getSlabAxisBound, } from './indexSpaceSlab.js';
2
+ import { signedDistanceToPlane } from './slabMembership.js';
3
+ export function* iterateVoxelsInShape(options) {
4
+ const { volume, planePoint, viewPlaneNormal: normal, referencePlaneThickness, getShapeRuns, isInShape, columnAxis: forcedColumnAxis, } = options;
5
+ const { dimensions, direction, spacing, origin } = volume;
6
+ const slab = buildIndexSpaceSlab(volume, planePoint, normal, referencePlaneThickness, { columnAxis: forcedColumnAxis });
7
+ const { outerAxis, rowAxis, columnAxis } = slab;
8
+ const volumeBounds = [0, 1, 2].map((axis) => [
9
+ 0,
10
+ dimensions[axis] - 1,
11
+ ]);
12
+ const requestedBounds = options.bounds;
13
+ const bounds = requestedBounds
14
+ ? [0, 1, 2].map((axis) => [
15
+ Math.max(requestedBounds[axis][0], volumeBounds[axis][0]),
16
+ Math.min(requestedBounds[axis][1], volumeBounds[axis][1]),
17
+ ])
18
+ : volumeBounds;
19
+ if (bounds.some(([min, max]) => min > max)) {
20
+ return;
21
+ }
22
+ const axisStep = [0, 1, 2].map((axis) => {
23
+ const unit = direction.slice(axis * 3, axis * 3 + 3);
24
+ return [
25
+ unit[0] * spacing[axis],
26
+ unit[1] * spacing[axis],
27
+ unit[2] * spacing[axis],
28
+ ];
29
+ });
30
+ const outerRange = getSlabAxisBound(slab, outerAxis, bounds);
31
+ if (!outerRange) {
32
+ return;
33
+ }
34
+ const ijk = [0, 0, 0];
35
+ const center = [0, 0, 0];
36
+ const visit = { ijk, center, depth: 0 };
37
+ const columnStep = axisStep[columnAxis];
38
+ for (let outer = outerRange[0]; outer <= outerRange[1]; outer++) {
39
+ const rowRange = getSlabAxisBound(slab, rowAxis, bounds, {
40
+ axis: outerAxis,
41
+ index: outer,
42
+ });
43
+ if (!rowRange) {
44
+ continue;
45
+ }
46
+ const outerStep = axisStep[outerAxis];
47
+ const rowStep = axisStep[rowAxis];
48
+ for (let row = rowRange[0]; row <= rowRange[1]; row++) {
49
+ const depthRun = getDepthRun(slab, outer, row, bounds[columnAxis]);
50
+ if (!depthRun) {
51
+ continue;
52
+ }
53
+ const shapeRuns = getShapeRuns
54
+ ? getShapeRuns(outer, row, depthRun, slab)
55
+ : [depthRun];
56
+ ijk[outerAxis] = outer;
57
+ ijk[rowAxis] = row;
58
+ for (const shapeRun of shapeRuns) {
59
+ const runMin = Math.max(shapeRun[0], depthRun[0]);
60
+ const runMax = Math.min(shapeRun[1], depthRun[1]);
61
+ if (runMin > runMax) {
62
+ continue;
63
+ }
64
+ for (let axis = 0; axis < 3; axis++) {
65
+ center[axis] =
66
+ origin[axis] +
67
+ outer * outerStep[axis] +
68
+ row * rowStep[axis] +
69
+ runMin * columnStep[axis];
70
+ }
71
+ for (let column = runMin; column <= runMax; column++) {
72
+ ijk[columnAxis] = column;
73
+ if (!isInShape || isInShape(center, ijk)) {
74
+ visit.depth = signedDistanceToPlane(center, planePoint, normal);
75
+ yield visit;
76
+ }
77
+ center[0] += columnStep[0];
78
+ center[1] += columnStep[1];
79
+ center[2] += columnStep[2];
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ export function collectVoxelsInShape(options) {
86
+ const collected = [];
87
+ for (const { ijk } of iterateVoxelsInShape(options)) {
88
+ collected.push([ijk[0], ijk[1], ijk[2]]);
89
+ }
90
+ return collected;
91
+ }
@@ -0,0 +1,16 @@
1
+ import type { Point3 } from '../../types/index.js';
2
+ import type { VoxelsInShapeOptions } from './iterateVoxelsInShape.js';
3
+ export interface VoxelSample {
4
+ value: number;
5
+ pointLPS: Point3;
6
+ pointIJK: Point3;
7
+ }
8
+ export interface VoxelValueSource {
9
+ getAtIJKPoint(ijk: Point3): number | undefined | null;
10
+ }
11
+ export interface VoxelsInShapeSamplingOptions extends VoxelsInShapeOptions {
12
+ voxelManager: VoxelValueSource;
13
+ onSample?: (sample: VoxelSample) => void;
14
+ storePointData?: boolean;
15
+ }
16
+ export declare function sampleVoxelsInShape(options: VoxelsInShapeSamplingOptions): VoxelSample[];
@@ -0,0 +1,24 @@
1
+ import { iterateVoxelsInShape } from './iterateVoxelsInShape.js';
2
+ export function sampleVoxelsInShape(options) {
3
+ const { voxelManager, onSample, storePointData, ...iteration } = options;
4
+ const samples = [];
5
+ if (!voxelManager) {
6
+ return samples;
7
+ }
8
+ for (const { ijk, center } of iterateVoxelsInShape(iteration)) {
9
+ const value = voxelManager.getAtIJKPoint(ijk);
10
+ if (value === undefined || value === null) {
11
+ continue;
12
+ }
13
+ const sample = {
14
+ value,
15
+ pointLPS: [center[0], center[1], center[2]],
16
+ pointIJK: [ijk[0], ijk[1], ijk[2]],
17
+ };
18
+ onSample?.(sample);
19
+ if (storePointData) {
20
+ samples.push(sample);
21
+ }
22
+ }
23
+ return samples;
24
+ }
@@ -0,0 +1,22 @@
1
+ import type { Point3 } from '../../../types/index.js';
2
+ import type { VolumeGeometry } from '../indexSpaceSlab.js';
3
+ import type { VoxelSlabShape } from './shapeGeometry.js';
4
+ export interface EllipseShapeOptions {
5
+ volume: VolumeGeometry;
6
+ planePoint: Point3;
7
+ viewPlaneNormal: Point3;
8
+ centerWorld: Point3;
9
+ majorAxis: Point3;
10
+ majorRadius: number;
11
+ minorRadius: number;
12
+ depthRadius?: number;
13
+ }
14
+ export declare function createEllipseShape(options: EllipseShapeOptions): VoxelSlabShape;
15
+ export declare function createCircleShape(options: {
16
+ volume: VolumeGeometry;
17
+ planePoint: Point3;
18
+ viewPlaneNormal: Point3;
19
+ centerWorld: Point3;
20
+ radius: number;
21
+ depthRadius?: number;
22
+ }): VoxelSlabShape;
@@ -0,0 +1,90 @@
1
+ import { vec3 } from 'gl-matrix';
2
+ import getVoxelThicknessAlongNormal from '../getVoxelThicknessAlongNormal.js';
3
+ import { projectPointOntoPlane } from '../slabMembership.js';
4
+ import { createColumnLineResolver, createPlaneBasis, SHAPE_BOUNDARY_EPSILON, solveQuadraticLeqZero, toIntegerRun, } from './shapeGeometry.js';
5
+ const UNIT_BOUNDARY = 1 + SHAPE_BOUNDARY_EPSILON;
6
+ export function createEllipseShape(options) {
7
+ const { volume, planePoint, viewPlaneNormal: normal, majorAxis, majorRadius, minorRadius, depthRadius, } = options;
8
+ if (!(majorRadius > 0) || !(minorRadius > 0)) {
9
+ throw new Error('Ellipse radii must be positive');
10
+ }
11
+ if (depthRadius !== undefined && !(depthRadius > 0)) {
12
+ throw new Error('Ellipse depthRadius must be positive when supplied');
13
+ }
14
+ const basis = createPlaneBasis(normal, majorAxis);
15
+ const isSolid = depthRadius !== undefined;
16
+ const voxelThickness = getVoxelThicknessAlongNormal(volume, basis.n);
17
+ const depthSemiAxis = isSolid
18
+ ? depthRadius + voxelThickness / 2
19
+ : 0;
20
+ const center = isSolid
21
+ ? [...options.centerWorld]
22
+ : projectPointOntoPlane(options.centerWorld, planePoint, basis.n);
23
+ const scaledAxes = [
24
+ { axis: basis.u, inverseRadius: 1 / majorRadius },
25
+ { axis: basis.v, inverseRadius: 1 / minorRadius },
26
+ ];
27
+ if (isSolid) {
28
+ scaledAxes.push({ axis: basis.n, inverseRadius: 1 / depthSemiAxis });
29
+ }
30
+ const resolveColumnLine = createColumnLineResolver(volume, basis.n);
31
+ function containsPoint(point) {
32
+ const tested = isSolid
33
+ ? point
34
+ : projectPointOntoPlane(point, planePoint, basis.n);
35
+ let total = 0;
36
+ for (const { axis, inverseRadius } of scaledAxes) {
37
+ const offset = (tested[0] - center[0]) * axis[0] +
38
+ (tested[1] - center[1]) * axis[1] +
39
+ (tested[2] - center[2]) * axis[2];
40
+ const scaled = offset * inverseRadius;
41
+ total += scaled * scaled;
42
+ }
43
+ return total <= UNIT_BOUNDARY;
44
+ }
45
+ function* getRuns(outerIndex, rowIndex, _depthRun, slab) {
46
+ const line = resolveColumnLine(slab, outerIndex, rowIndex);
47
+ const lineBase = isSolid ? line.base : line.projectedBase;
48
+ const lineStep = isSolid ? line.step : line.projectedStep;
49
+ let a = 0;
50
+ let b = 0;
51
+ let c = -UNIT_BOUNDARY;
52
+ for (const { axis, inverseRadius } of scaledAxes) {
53
+ const offset = ((lineBase[0] - center[0]) * axis[0] +
54
+ (lineBase[1] - center[1]) * axis[1] +
55
+ (lineBase[2] - center[2]) * axis[2]) *
56
+ inverseRadius;
57
+ const slope = (lineStep[0] * axis[0] +
58
+ lineStep[1] * axis[1] +
59
+ lineStep[2] * axis[2]) *
60
+ inverseRadius;
61
+ a += slope * slope;
62
+ b += 2 * offset * slope;
63
+ c += offset * offset;
64
+ }
65
+ const run = toIntegerRun(solveQuadraticLeqZero(a, b, c));
66
+ if (run) {
67
+ yield run;
68
+ }
69
+ }
70
+ return {
71
+ containsPoint,
72
+ getRuns,
73
+ getRequiredThickness: () => (isSolid ? depthSemiAxis * 2 : 0),
74
+ };
75
+ }
76
+ export function createCircleShape(options) {
77
+ const { viewPlaneNormal: normal } = options;
78
+ const candidate = Math.abs(normal[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0];
79
+ const majorAxis = vec3.cross(vec3.create(), normal, candidate);
80
+ return createEllipseShape({
81
+ volume: options.volume,
82
+ planePoint: options.planePoint,
83
+ viewPlaneNormal: normal,
84
+ centerWorld: options.centerWorld,
85
+ majorAxis,
86
+ majorRadius: options.radius,
87
+ minorRadius: options.radius,
88
+ depthRadius: options.depthRadius,
89
+ });
90
+ }
@@ -0,0 +1,10 @@
1
+ import type { Point3 } from '../../../types/index.js';
2
+ import type { VolumeGeometry } from '../indexSpaceSlab.js';
3
+ import type { VoxelSlabShape } from './shapeGeometry.js';
4
+ export interface PolylineShapeOptions {
5
+ volume: VolumeGeometry;
6
+ planePoint?: Point3;
7
+ viewPlaneNormal: Point3;
8
+ polyline: Point3[] | Point3[][];
9
+ }
10
+ export declare function createPolylineShape(options: PolylineShapeOptions): VoxelSlabShape;
@@ -0,0 +1,170 @@
1
+ import { vec3 } from 'gl-matrix';
2
+ import { projectPointOntoPlane } from '../slabMembership.js';
3
+ import { SHAPE_BOUNDARY_EPSILON, createColumnLineResolver, createPlaneBasis, toIntegerRun, } from './shapeGeometry.js';
4
+ export function createPolylineShape(options) {
5
+ const { volume, viewPlaneNormal: normal, polyline } = options;
6
+ if (!polyline?.length) {
7
+ throw new Error('A polyline shape needs an outline');
8
+ }
9
+ const inputRings = Array.isArray(polyline[0]?.[0])
10
+ ? polyline
11
+ : [polyline];
12
+ if (inputRings.some((ring) => !ring?.length || ring.length < 3)) {
13
+ throw new Error('Every polyline ring needs at least three points');
14
+ }
15
+ const planePoint = options.planePoint ?? inputRings[0][0];
16
+ const candidate = Math.abs(normal[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0];
17
+ const basis = createPlaneBasis(normal, vec3.cross(vec3.create(), normal, candidate));
18
+ const toPlanePoint = (point) => [
19
+ (point[0] - planePoint[0]) * basis.u[0] +
20
+ (point[1] - planePoint[1]) * basis.u[1] +
21
+ (point[2] - planePoint[2]) * basis.u[2],
22
+ (point[0] - planePoint[0]) * basis.v[0] +
23
+ (point[1] - planePoint[1]) * basis.v[1] +
24
+ (point[2] - planePoint[2]) * basis.v[2],
25
+ ];
26
+ const toPlaneDirection = (vector) => [
27
+ vector[0] * basis.u[0] + vector[1] * basis.u[1] + vector[2] * basis.u[2],
28
+ vector[0] * basis.v[0] + vector[1] * basis.v[1] + vector[2] * basis.v[2],
29
+ ];
30
+ const rings = inputRings.map((ring) => ring.map((point) => toPlanePoint(projectPointOntoPlane(point, planePoint, basis.n))));
31
+ let extent = 0;
32
+ for (const ring of rings) {
33
+ for (const [x, y] of ring) {
34
+ extent = Math.max(extent, Math.abs(x), Math.abs(y));
35
+ }
36
+ }
37
+ const boundarySlack = Math.max(extent, 1) * SHAPE_BOUNDARY_EPSILON;
38
+ function distanceToOutline(planePoint2) {
39
+ let best = Infinity;
40
+ for (const ring of rings) {
41
+ const distance = distanceToRing(ring, planePoint2);
42
+ if (distance < best) {
43
+ best = distance;
44
+ }
45
+ }
46
+ return best;
47
+ }
48
+ function distanceToRing(ring, [x, y]) {
49
+ let best = Infinity;
50
+ const vertexCount = ring.length;
51
+ for (let i = 0, j = vertexCount - 1; i < vertexCount; j = i++) {
52
+ const [xi, yi] = ring[i];
53
+ const [xj, yj] = ring[j];
54
+ const edgeX = xj - xi;
55
+ const edgeY = yj - yi;
56
+ const lengthSquared = edgeX * edgeX + edgeY * edgeY;
57
+ let t = 0;
58
+ if (lengthSquared > 0) {
59
+ t = ((x - xi) * edgeX + (y - yi) * edgeY) / lengthSquared;
60
+ t = t < 0 ? 0 : t > 1 ? 1 : t;
61
+ }
62
+ const dx = x - (xi + t * edgeX);
63
+ const dy = y - (yi + t * edgeY);
64
+ const distance = Math.hypot(dx, dy);
65
+ if (distance < best) {
66
+ best = distance;
67
+ }
68
+ }
69
+ return best;
70
+ }
71
+ const resolveColumnLine = createColumnLineResolver(volume, basis.n);
72
+ function containsPlanePoint([x, y]) {
73
+ let inside = false;
74
+ for (const ring of rings) {
75
+ const vertexCount = ring.length;
76
+ for (let i = 0, j = vertexCount - 1; i < vertexCount; j = i++) {
77
+ const [xi, yi] = ring[i];
78
+ const [xj, yj] = ring[j];
79
+ if (yi > y !== yj > y) {
80
+ const crossingX = xi + ((y - yi) / (yj - yi)) * (xj - xi);
81
+ if (x < crossingX) {
82
+ inside = !inside;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ return inside || distanceToOutline([x, y]) <= boundarySlack;
88
+ }
89
+ function containsPoint(point) {
90
+ return containsPlanePoint(toPlanePoint(projectPointOntoPlane(point, planePoint, basis.n)));
91
+ }
92
+ function* getRuns(outerIndex, rowIndex, depthRun, slab) {
93
+ const line = resolveColumnLine(slab, outerIndex, rowIndex);
94
+ const origin2 = toPlanePoint(line.projectedBase);
95
+ const direction2 = toPlaneDirection(line.projectedStep);
96
+ const directionLengthSquared = direction2[0] * direction2[0] + direction2[1] * direction2[1];
97
+ if (directionLengthSquared <= 0) {
98
+ if (containsPlanePoint(origin2)) {
99
+ yield [depthRun[0], depthRun[1]];
100
+ }
101
+ return;
102
+ }
103
+ const directionLength = Math.sqrt(directionLengthSquared);
104
+ const slack = boundarySlack / directionLength;
105
+ const perpendicularScale = 1 / directionLength;
106
+ const columnOf = ([x, y]) => ((x - origin2[0]) * direction2[0] + (y - origin2[1]) * direction2[1]) /
107
+ directionLengthSquared;
108
+ const sideOf = ([x, y]) => direction2[0] * (y - origin2[1]) - direction2[1] * (x - origin2[0]);
109
+ const intervals = [];
110
+ const crossings = [];
111
+ for (const ring of rings) {
112
+ const vertexCount = ring.length;
113
+ let previousIndex = vertexCount - 1;
114
+ let previousSide = sideOf(ring[previousIndex]);
115
+ for (let i = 0; i < vertexCount; i++) {
116
+ const side = sideOf(ring[i]);
117
+ const previousOnLine = Math.abs(previousSide) * perpendicularScale <= boundarySlack;
118
+ const currentOnLine = Math.abs(side) * perpendicularScale <= boundarySlack;
119
+ if (previousOnLine && currentOnLine) {
120
+ const a = columnOf(ring[previousIndex]);
121
+ const b = columnOf(ring[i]);
122
+ intervals.push(a <= b ? [a - slack, b + slack] : [b - slack, a + slack]);
123
+ }
124
+ else if (currentOnLine) {
125
+ const at = columnOf(ring[i]);
126
+ intervals.push([at - slack, at + slack]);
127
+ }
128
+ if (previousSide > 0 !== side > 0) {
129
+ const t = previousSide / (previousSide - side);
130
+ const crossingX = ring[previousIndex][0] + t * (ring[i][0] - ring[previousIndex][0]);
131
+ const crossingY = ring[previousIndex][1] + t * (ring[i][1] - ring[previousIndex][1]);
132
+ crossings.push(columnOf([crossingX, crossingY]));
133
+ }
134
+ previousIndex = i;
135
+ previousSide = side;
136
+ }
137
+ }
138
+ crossings.sort((a, b) => a - b);
139
+ for (let pair = 0; pair + 1 < crossings.length; pair += 2) {
140
+ intervals.push([crossings[pair] - slack, crossings[pair + 1] + slack]);
141
+ }
142
+ if (!intervals.length) {
143
+ return;
144
+ }
145
+ intervals.sort((a, b) => a[0] - b[0]);
146
+ let [low, high] = intervals[0];
147
+ for (let index = 1; index < intervals.length; index++) {
148
+ const [nextLow, nextHigh] = intervals[index];
149
+ if (nextLow <= high) {
150
+ high = Math.max(high, nextHigh);
151
+ continue;
152
+ }
153
+ const run = toIntegerRun([low, high]);
154
+ if (run) {
155
+ yield run;
156
+ }
157
+ low = nextLow;
158
+ high = nextHigh;
159
+ }
160
+ const finalRun = toIntegerRun([low, high]);
161
+ if (finalRun) {
162
+ yield finalRun;
163
+ }
164
+ }
165
+ return {
166
+ containsPoint,
167
+ getRuns,
168
+ getRequiredThickness: () => 0,
169
+ };
170
+ }
@@ -0,0 +1,14 @@
1
+ import type { Point3 } from '../../../types/index.js';
2
+ import type { VolumeGeometry } from '../indexSpaceSlab.js';
3
+ import type { VoxelSlabShape } from './shapeGeometry.js';
4
+ export interface RectangleShapeOptions {
5
+ volume: VolumeGeometry;
6
+ planePoint: Point3;
7
+ viewPlaneNormal: Point3;
8
+ centerWorld: Point3;
9
+ majorAxis: Point3;
10
+ majorHalfLength: number;
11
+ minorHalfLength: number;
12
+ depthHalfLength?: number;
13
+ }
14
+ export declare function createRectangleShape(options: RectangleShapeOptions): VoxelSlabShape;