@cornerstonejs/tools 1.54.2 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +72 -74
- package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -1
- package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js +15 -7
- package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js.map +1 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +2 -1
- package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
- package/dist/cjs/tools/annotation/LivewireContourTool.js +5 -2
- package/dist/cjs/tools/annotation/LivewireContourTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +4 -0
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/SplineROITool.js +5 -2
- package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js +2 -3
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/cjs/tools/base/ContourBaseTool.d.ts +8 -0
- package/dist/cjs/tools/base/ContourBaseTool.js +13 -2
- package/dist/cjs/tools/base/ContourBaseTool.js.map +1 -1
- package/dist/cjs/tools/segmentation/BrushTool.js +1 -1
- package/dist/cjs/tools/segmentation/BrushTool.js.map +1 -1
- package/dist/cjs/tools/segmentation/strategies/BrushStrategy.d.ts +3 -2
- package/dist/cjs/tools/segmentation/strategies/BrushStrategy.js +11 -4
- package/dist/cjs/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
- package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js +9 -3
- package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
- package/dist/cjs/tools/segmentation/strategies/compositions/islandRemoval.js +1 -1
- package/dist/cjs/tools/segmentation/strategies/compositions/islandRemoval.js.map +1 -1
- package/dist/cjs/tools/segmentation/strategies/compositions/threshold.js +6 -2
- package/dist/cjs/tools/segmentation/strategies/compositions/threshold.js.map +1 -1
- package/dist/cjs/tools/segmentation/strategies/utils/getStrategyData.d.ts +2 -3
- package/dist/cjs/tools/segmentation/strategies/utils/getStrategyData.js +21 -6
- package/dist/cjs/tools/segmentation/strategies/utils/getStrategyData.js.map +1 -1
- package/dist/cjs/utilities/contours/updateContourPolyline.d.ts +5 -0
- package/dist/cjs/utilities/contours/updateContourPolyline.js +7 -2
- package/dist/cjs/utilities/contours/updateContourPolyline.js.map +1 -1
- package/dist/cjs/utilities/math/line/distanceToPointSquaredInfo.js.map +1 -1
- package/dist/cjs/utilities/math/polyline/decimate.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/decimate.js +73 -0
- package/dist/cjs/utilities/math/polyline/decimate.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/index.d.ts +2 -1
- package/dist/cjs/utilities/math/polyline/index.js +3 -1
- package/dist/cjs/utilities/math/polyline/index.js.map +1 -1
- package/dist/cjs/utilities/pointInShapeCallback.js +3 -1
- package/dist/cjs/utilities/pointInShapeCallback.js.map +1 -1
- package/dist/cjs/utilities/segmentation/floodFill.js +16 -22
- package/dist/cjs/utilities/segmentation/floodFill.js.map +1 -1
- package/dist/cjs/utilities/segmentation/getSegmentAtLabelmapBorder.js +3 -2
- package/dist/cjs/utilities/segmentation/getSegmentAtLabelmapBorder.js.map +1 -1
- package/dist/cjs/utilities/segmentation/getSegmentAtWorldPoint.js +3 -2
- package/dist/cjs/utilities/segmentation/getSegmentAtWorldPoint.js.map +1 -1
- package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +1 -1
- package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -1
- package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js +16 -8
- package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.js.map +1 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +2 -1
- package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
- package/dist/esm/tools/annotation/LivewireContourTool.js +5 -2
- package/dist/esm/tools/annotation/LivewireContourTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +4 -0
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/SplineROITool.js +5 -2
- package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js +2 -3
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/esm/tools/base/ContourBaseTool.js +10 -0
- package/dist/esm/tools/base/ContourBaseTool.js.map +1 -1
- package/dist/esm/tools/segmentation/BrushTool.js +1 -1
- package/dist/esm/tools/segmentation/BrushTool.js.map +1 -1
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +10 -3
- package/dist/esm/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
- package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js +9 -3
- package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
- package/dist/esm/tools/segmentation/strategies/compositions/islandRemoval.js +1 -1
- package/dist/esm/tools/segmentation/strategies/compositions/islandRemoval.js.map +1 -1
- package/dist/esm/tools/segmentation/strategies/compositions/threshold.js +6 -2
- package/dist/esm/tools/segmentation/strategies/compositions/threshold.js.map +1 -1
- package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.js +21 -6
- package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.js.map +1 -1
- package/dist/esm/utilities/contours/updateContourPolyline.js +6 -2
- package/dist/esm/utilities/contours/updateContourPolyline.js.map +1 -1
- package/dist/esm/utilities/math/line/distanceToPointSquaredInfo.js.map +1 -1
- package/dist/esm/utilities/math/polyline/decimate.js +47 -0
- package/dist/esm/utilities/math/polyline/decimate.js.map +1 -0
- package/dist/esm/utilities/math/polyline/index.js +2 -1
- package/dist/esm/utilities/math/polyline/index.js.map +1 -1
- package/dist/esm/utilities/pointInShapeCallback.js +3 -1
- package/dist/esm/utilities/pointInShapeCallback.js.map +1 -1
- package/dist/esm/utilities/segmentation/floodFill.js +16 -22
- package/dist/esm/utilities/segmentation/floodFill.js.map +1 -1
- package/dist/esm/utilities/segmentation/getSegmentAtLabelmapBorder.js +3 -2
- package/dist/esm/utilities/segmentation/getSegmentAtLabelmapBorder.js.map +1 -1
- package/dist/esm/utilities/segmentation/getSegmentAtWorldPoint.js +3 -2
- package/dist/esm/utilities/segmentation/getSegmentAtWorldPoint.js.map +1 -1
- package/dist/types/eventListeners/segmentation/imageChangeEventListener.d.ts.map +1 -1
- package/dist/types/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.d.ts.map +1 -1
- package/dist/types/tools/annotation/LivewireContourTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/planarFreehandROITool/drawLoop.d.ts.map +1 -1
- package/dist/types/tools/base/ContourBaseTool.d.ts +8 -0
- package/dist/types/tools/base/ContourBaseTool.d.ts.map +1 -1
- package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts +3 -2
- package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts.map +1 -1
- package/dist/types/tools/segmentation/strategies/compositions/dynamicThreshold.d.ts.map +1 -1
- package/dist/types/tools/segmentation/strategies/compositions/islandRemoval.d.ts.map +1 -1
- package/dist/types/tools/segmentation/strategies/compositions/threshold.d.ts.map +1 -1
- package/dist/types/tools/segmentation/strategies/utils/getStrategyData.d.ts +2 -3
- package/dist/types/tools/segmentation/strategies/utils/getStrategyData.d.ts.map +1 -1
- package/dist/types/utilities/contours/updateContourPolyline.d.ts +5 -0
- package/dist/types/utilities/contours/updateContourPolyline.d.ts.map +1 -1
- package/dist/types/utilities/math/line/distanceToPointSquaredInfo.d.ts.map +1 -1
- package/dist/types/utilities/math/polyline/decimate.d.ts +3 -0
- package/dist/types/utilities/math/polyline/decimate.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/index.d.ts +2 -1
- package/dist/types/utilities/math/polyline/index.d.ts.map +1 -1
- package/dist/types/utilities/pointInShapeCallback.d.ts.map +1 -1
- package/dist/types/utilities/segmentation/floodFill.d.ts.map +1 -1
- package/dist/types/utilities/segmentation/getSegmentAtLabelmapBorder.d.ts.map +1 -1
- package/dist/types/utilities/segmentation/getSegmentAtWorldPoint.d.ts.map +1 -1
- package/dist/umd/985.index.js +1 -1
- package/dist/umd/985.index.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +7 -3
- package/src/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.ts +1 -1
- package/src/eventListeners/segmentation/imageChangeEventListener.ts +28 -13
- package/src/stateManagement/segmentation/polySeg/Labelmap/computeAndAddLabelmapRepresentation.ts +1 -1
- package/src/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.ts +3 -1
- package/src/tools/annotation/LivewireContourTool.ts +15 -2
- package/src/tools/annotation/PlanarFreehandROITool.ts +12 -0
- package/src/tools/annotation/SplineROITool.ts +13 -2
- package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +2 -3
- package/src/tools/base/ContourBaseTool.ts +23 -0
- package/src/tools/segmentation/BrushTool.ts +1 -1
- package/src/tools/segmentation/strategies/BrushStrategy.ts +25 -4
- package/src/tools/segmentation/strategies/compositions/dynamicThreshold.ts +12 -2
- package/src/tools/segmentation/strategies/compositions/islandRemoval.ts +1 -2
- package/src/tools/segmentation/strategies/compositions/threshold.ts +8 -6
- package/src/tools/segmentation/strategies/utils/getStrategyData.ts +20 -5
- package/src/utilities/contours/updateContourPolyline.ts +23 -1
- package/src/utilities/math/line/distanceToPointSquaredInfo.ts +2 -1
- package/src/utilities/math/polyline/decimate.ts +105 -0
- package/src/utilities/math/polyline/index.ts +2 -0
- package/src/utilities/pointInShapeCallback.ts +2 -0
- package/src/utilities/segmentation/floodFill.ts +44 -31
- package/src/utilities/segmentation/getSegmentAtLabelmapBorder.ts +6 -5
- package/src/utilities/segmentation/getSegmentAtWorldPoint.ts +6 -5
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import * as mathLine from '../line';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_EPSILON = 0.1;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Ramer–Douglas–Peucker algorithm implementation to decimate a polyline
|
|
8
|
+
* to a similar polyline with fewer points
|
|
9
|
+
*
|
|
10
|
+
* https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
|
|
11
|
+
* https://rosettacode.org/wiki/Ramer-Douglas-Peucker_line_simplification
|
|
12
|
+
* https://karthaus.nl/rdp/
|
|
13
|
+
*
|
|
14
|
+
* @param polyline - Polyline to decimate
|
|
15
|
+
* @param epsilon - A maximum given distance 'epsilon' to decide if a point
|
|
16
|
+
* should or shouldn't be added the decimated polyline version. In each
|
|
17
|
+
* iteration the polyline is split into two polylines and the distance of each
|
|
18
|
+
* point from those new polylines are checked against the line that connects
|
|
19
|
+
* the first and last points.
|
|
20
|
+
* @returns Decimated polyline
|
|
21
|
+
*/
|
|
22
|
+
export default function decimate(
|
|
23
|
+
polyline: Types.Point2[],
|
|
24
|
+
epsilon = DEFAULT_EPSILON
|
|
25
|
+
) {
|
|
26
|
+
const numPoints = polyline.length;
|
|
27
|
+
|
|
28
|
+
// The polyline must have at least a start and end points
|
|
29
|
+
if (numPoints < 3) {
|
|
30
|
+
return polyline;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const epsilonSquared = epsilon * epsilon;
|
|
34
|
+
const partitionQueue = [[0, numPoints - 1]];
|
|
35
|
+
|
|
36
|
+
// Used a boolean array to set each point that will be in the decimated polyline
|
|
37
|
+
// because pre-allocated arrays are 3-4x faster than thousands of push() calls
|
|
38
|
+
// to add all points to a new array.
|
|
39
|
+
const polylinePointFlags = new Array(numPoints).fill(false);
|
|
40
|
+
|
|
41
|
+
// Start and end points are always added to the decimated polyline
|
|
42
|
+
let numDecimatedPoints = 2;
|
|
43
|
+
|
|
44
|
+
// Add start and end points to the decimated polyline
|
|
45
|
+
polylinePointFlags[0] = true;
|
|
46
|
+
polylinePointFlags[numPoints - 1] = true;
|
|
47
|
+
|
|
48
|
+
// Iterative approach using a queue instead of recursion to reduce the number
|
|
49
|
+
// of function calls (performance)
|
|
50
|
+
while (partitionQueue.length) {
|
|
51
|
+
const [startIndex, endIndex] = partitionQueue.pop();
|
|
52
|
+
|
|
53
|
+
// Return if there is no point between the start and end points
|
|
54
|
+
if (endIndex - startIndex === 1) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const startPoint = polyline[startIndex];
|
|
59
|
+
const endPoint = polyline[endIndex];
|
|
60
|
+
let maxDistSquared = -Infinity;
|
|
61
|
+
let maxDistIndex = -1;
|
|
62
|
+
|
|
63
|
+
// Search for the furthest point
|
|
64
|
+
for (let i = startIndex + 1; i < endIndex; i++) {
|
|
65
|
+
const currentPoint = polyline[i];
|
|
66
|
+
const distSquared = mathLine.distanceToPointSquared(
|
|
67
|
+
startPoint,
|
|
68
|
+
endPoint,
|
|
69
|
+
currentPoint
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (distSquared > maxDistSquared) {
|
|
73
|
+
maxDistSquared = distSquared;
|
|
74
|
+
maxDistIndex = i;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Do not add any of the points because the fursthest one is very close to
|
|
79
|
+
// the line based on the epsilon value
|
|
80
|
+
if (maxDistSquared < epsilonSquared) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Update the flag for the furthest point because it will be added to the
|
|
85
|
+
// decimated polyline
|
|
86
|
+
polylinePointFlags[maxDistIndex] = true;
|
|
87
|
+
numDecimatedPoints++;
|
|
88
|
+
|
|
89
|
+
// Partition the points into two parts using maxDistIndex as the pivot point
|
|
90
|
+
// and process both sides
|
|
91
|
+
partitionQueue.push([maxDistIndex, endIndex]);
|
|
92
|
+
partitionQueue.push([startIndex, maxDistIndex]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A pre-allocated array is 3-4x faster then multiple push() calls
|
|
96
|
+
const decimatedPolyline: Types.Point2[] = new Array(numDecimatedPoints);
|
|
97
|
+
|
|
98
|
+
for (let srcIndex = 0, dstIndex = 0; srcIndex < numPoints; srcIndex++) {
|
|
99
|
+
if (polylinePointFlags[srcIndex]) {
|
|
100
|
+
decimatedPolyline[dstIndex++] = polyline[srcIndex];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return decimatedPolyline;
|
|
105
|
+
}
|
|
@@ -9,6 +9,7 @@ import getNormal3 from './getNormal3';
|
|
|
9
9
|
import getNormal2 from './getNormal2';
|
|
10
10
|
import { mergePolylines, subtractPolylines } from './combinePolyline';
|
|
11
11
|
import intersectPolyline from './intersectPolyline';
|
|
12
|
+
import decimate from './decimate';
|
|
12
13
|
import getFirstLineSegmentIntersectionIndexes from './getFirstLineSegmentIntersectionIndexes';
|
|
13
14
|
import getLineSegmentIntersectionsIndexes from './getLineSegmentIntersectionsIndexes';
|
|
14
15
|
import getLineSegmentIntersectionsCoordinates from './getLineSegmentIntersectionsCoordinates';
|
|
@@ -30,6 +31,7 @@ export {
|
|
|
30
31
|
getNormal3,
|
|
31
32
|
getNormal2,
|
|
32
33
|
intersectPolyline,
|
|
34
|
+
decimate,
|
|
33
35
|
getFirstLineSegmentIntersectionIndexes,
|
|
34
36
|
getLineSegmentIntersectionsIndexes,
|
|
35
37
|
getLineSegmentIntersectionsCoordinates,
|
|
@@ -47,6 +47,7 @@ export default function pointInShapeCallback(
|
|
|
47
47
|
let iMin, iMax, jMin, jMax, kMin, kMax;
|
|
48
48
|
|
|
49
49
|
let scalarData;
|
|
50
|
+
const { numComps } = imageData as any;
|
|
50
51
|
|
|
51
52
|
// if getScalarData is a method on imageData
|
|
52
53
|
if ((imageData as Types.CPUImageData).getScalarData) {
|
|
@@ -103,6 +104,7 @@ export default function pointInShapeCallback(
|
|
|
103
104
|
);
|
|
104
105
|
|
|
105
106
|
const xMultiple =
|
|
107
|
+
numComps ||
|
|
106
108
|
scalarData.length / dimensions[2] / dimensions[1] / dimensions[0];
|
|
107
109
|
const yMultiple = dimensions[0] * xMultiple;
|
|
108
110
|
const zMultiple = dimensions[1] * yMultiple;
|
|
@@ -7,22 +7,25 @@ import { Types } from '@cornerstonejs/core';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* floodFill.js - Taken from MIT OSS lib - https://github.com/tuzz/n-dimensional-flood-fill
|
|
10
|
-
* Refactored to ES6.
|
|
10
|
+
* Refactored to ES6. Fixed the bounds/visits checks to use integer keys, restricting the
|
|
11
|
+
* total search spacing to +/- 32k in each dimension, but resulting in about a hundred time
|
|
12
|
+
* performance gain for larger regions since JavaScript does not have a hash map to allow the
|
|
13
|
+
* map to work on keys.
|
|
11
14
|
*
|
|
12
|
-
* @param
|
|
15
|
+
* @param getter The getter to the elements of your data structure,
|
|
13
16
|
* e.g. getter(x,y) for a 2D interprettation of your structure.
|
|
14
|
-
* @param
|
|
17
|
+
* @param seed The seed for your fill. The dimensionality is infered
|
|
15
18
|
* by the number of dimensions of the seed.
|
|
16
|
-
* @param
|
|
19
|
+
* @param options.onFlood - An optional callback to execute when each pixel is flooded.
|
|
17
20
|
* e.g. onFlood(x,y).
|
|
18
|
-
* @param
|
|
21
|
+
* @param options.onBoundary - An optional callback to execute whenever a boundary is reached.
|
|
19
22
|
* a boundary could be another segmentIndex, or the edge of your
|
|
20
23
|
* data structure (i.e. when your getter returns undefined).
|
|
21
|
-
* @param
|
|
24
|
+
* @param options.equals - An optional equality method for your datastructure.
|
|
22
25
|
* Default is simply value1 = value2.
|
|
23
|
-
* @param
|
|
26
|
+
* @param options.diagonals - Whether you allow flooding through diagonals. Defaults to false.
|
|
24
27
|
*
|
|
25
|
-
* @returns
|
|
28
|
+
* @returns Flood fill results
|
|
26
29
|
*/
|
|
27
30
|
function floodFill(
|
|
28
31
|
getter: FloodFillGetter,
|
|
@@ -31,14 +34,14 @@ function floodFill(
|
|
|
31
34
|
): FloodFillResult {
|
|
32
35
|
const onFlood = options.onFlood;
|
|
33
36
|
const onBoundary = options.onBoundary;
|
|
34
|
-
const equals = options.equals
|
|
37
|
+
const equals = options.equals;
|
|
35
38
|
const diagonals = options.diagonals || false;
|
|
36
39
|
const startNode = get(seed);
|
|
37
40
|
const permutations = prunedPermutations();
|
|
38
41
|
const stack = [];
|
|
39
42
|
const flooded = [];
|
|
40
|
-
const visits =
|
|
41
|
-
const bounds =
|
|
43
|
+
const visits = new Set();
|
|
44
|
+
const bounds = new Map();
|
|
42
45
|
|
|
43
46
|
stack.push({ currentArgs: seed });
|
|
44
47
|
|
|
@@ -68,18 +71,28 @@ function floodFill(
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Indicates if the key has been visited.
|
|
76
|
+
* @param key is a 2 or 3 element vector with values -32768...32767
|
|
77
|
+
*/
|
|
71
78
|
function visited(key) {
|
|
72
|
-
|
|
79
|
+
const [x, y, z = 0] = key;
|
|
80
|
+
// Use an integer key value for checking visited, since JavaScript does not
|
|
81
|
+
// provide a generic hash key indexed hash map.
|
|
82
|
+
const iKey = x + 32768 + 65536 * (y + 32768 + 65536 * (z + 32768));
|
|
83
|
+
return visits.has(iKey);
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
function markAsVisited(key) {
|
|
76
|
-
|
|
87
|
+
const [x, y, z = 0] = key;
|
|
88
|
+
const iKey = x + 32768 + 65536 * (y + 32768 + 65536 * (z + 32768));
|
|
89
|
+
visits.add(iKey);
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
function member(getArgs) {
|
|
80
|
-
const node =
|
|
93
|
+
const node = get(getArgs);
|
|
81
94
|
|
|
82
|
-
return
|
|
95
|
+
return equals ? equals(node, startNode) : node === startNode;
|
|
83
96
|
}
|
|
84
97
|
|
|
85
98
|
function markAsFlooded(getArgs) {
|
|
@@ -91,7 +104,11 @@ function floodFill(
|
|
|
91
104
|
}
|
|
92
105
|
|
|
93
106
|
function markAsBoundary(prevArgs) {
|
|
94
|
-
|
|
107
|
+
const [x, y, z = 0] = prevArgs;
|
|
108
|
+
// Use an integer key value for checking visited, since JavaScript does not
|
|
109
|
+
// provide a generic hash key indexed hash map.
|
|
110
|
+
const iKey = x + 32768 + 65536 * (y + 32768 + 65536 * (z + 32768));
|
|
111
|
+
bounds.set(iKey, prevArgs);
|
|
95
112
|
if (onBoundary) {
|
|
96
113
|
//@ts-ignore
|
|
97
114
|
onBoundary(...prevArgs);
|
|
@@ -119,13 +136,15 @@ function floodFill(
|
|
|
119
136
|
return getter(...getArgs);
|
|
120
137
|
}
|
|
121
138
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
// This is a significant performance hit - should be done as a wrapper
|
|
140
|
+
// only when needed.
|
|
141
|
+
// function safely(f, args) {
|
|
142
|
+
// try {
|
|
143
|
+
// return f(...args);
|
|
144
|
+
// } catch (error) {
|
|
145
|
+
// return;
|
|
146
|
+
// }
|
|
147
|
+
// }
|
|
129
148
|
|
|
130
149
|
function prunedPermutations() {
|
|
131
150
|
const permutations = permute(seed.length);
|
|
@@ -156,14 +175,8 @@ function floodFill(
|
|
|
156
175
|
}
|
|
157
176
|
|
|
158
177
|
function boundaries() {
|
|
159
|
-
const array =
|
|
160
|
-
|
|
161
|
-
for (const key in bounds) {
|
|
162
|
-
if (bounds[key] !== undefined) {
|
|
163
|
-
array.unshift(bounds[key]);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
178
|
+
const array = Array.from(bounds.values());
|
|
179
|
+
array.reverse();
|
|
167
180
|
return array;
|
|
168
181
|
}
|
|
169
182
|
}
|
|
@@ -84,12 +84,13 @@ export function getSegmentAtLabelmapBorder(
|
|
|
84
84
|
const indexIJK = utilities.transformWorldToIndex(imageData, worldPoint);
|
|
85
85
|
|
|
86
86
|
const dimensions = imageData.getDimensions();
|
|
87
|
-
const voxelManager =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
const voxelManager = (imageData.voxelManager ||
|
|
88
|
+
utilities.VoxelManager.createVolumeVoxelManager(
|
|
89
|
+
dimensions,
|
|
90
|
+
imageData.getPointData().getScalars().getData()
|
|
91
|
+
)) as utilities.VoxelManager<number>;
|
|
91
92
|
|
|
92
|
-
const segmentIndex = voxelManager.
|
|
93
|
+
const segmentIndex = voxelManager.getAtIJKPoint(indexIJK as Types.Point3);
|
|
93
94
|
|
|
94
95
|
const onEdge = isSegmentOnEdgeIJK(
|
|
95
96
|
indexIJK as Types.Point3,
|
|
@@ -110,12 +110,13 @@ export function getSegmentAtWorldForLabelmap(
|
|
|
110
110
|
const indexIJK = utilities.transformWorldToIndex(imageData, worldPoint);
|
|
111
111
|
|
|
112
112
|
const dimensions = imageData.getDimensions();
|
|
113
|
-
const voxelManager =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
const voxelManager = (imageData.voxelManager ||
|
|
114
|
+
utilities.VoxelManager.createVolumeVoxelManager(
|
|
115
|
+
dimensions,
|
|
116
|
+
imageData.getPointData().getScalars().getData()
|
|
117
|
+
)) as utilities.VoxelManager<number>;
|
|
117
118
|
|
|
118
|
-
const segmentIndex = voxelManager.
|
|
119
|
+
const segmentIndex = voxelManager.getAtIJKPoint(indexIJK as Types.Point3);
|
|
119
120
|
|
|
120
121
|
return segmentIndex;
|
|
121
122
|
}
|