@cornerstonejs/tools 0.66.7 → 0.67.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/tools/annotation/PlanarFreehandROITool.d.ts +5 -2
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +221 -22
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +1 -0
- package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js +20 -6
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js +2 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js +6 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js.map +1 -1
- package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +1 -0
- package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.d.ts +3 -1
- package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.js +51 -1
- package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.js.map +1 -1
- package/dist/cjs/utilities/math/polyline/planarFreehandROIInternalTypes.d.ts +1 -0
- package/dist/cjs/utilities/math/polyline/pointInPolyline.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/pointInPolyline.js +14 -0
- package/dist/cjs/utilities/math/polyline/pointInPolyline.js.map +1 -0
- package/dist/esm/tools/annotation/PlanarFreehandROITool.d.ts +5 -2
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +219 -22
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +1 -0
- package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js +20 -6
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js +2 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js +6 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js.map +1 -1
- package/dist/esm/types/ToolSpecificAnnotationTypes.d.ts +1 -0
- package/dist/esm/utilities/math/polyline/getIntersectionWithPolyline.d.ts +3 -1
- package/dist/esm/utilities/math/polyline/getIntersectionWithPolyline.js +49 -1
- package/dist/esm/utilities/math/polyline/getIntersectionWithPolyline.js.map +1 -1
- package/dist/esm/utilities/math/polyline/planarFreehandROIInternalTypes.d.ts +1 -0
- package/dist/esm/utilities/math/polyline/pointInPolyline.d.ts +2 -0
- package/dist/esm/utilities/math/polyline/pointInPolyline.js +11 -0
- package/dist/esm/utilities/math/polyline/pointInPolyline.js.map +1 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/tools/annotation/PlanarFreehandROITool.ts +356 -36
- package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +1 -0
- package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +39 -14
- package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +2 -1
- package/src/tools/annotation/planarFreehandROITool/openContourEndEditLoop.ts +14 -2
- package/src/types/ToolSpecificAnnotationTypes.ts +1 -0
- package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +94 -1
- package/src/utilities/math/polyline/planarFreehandROIInternalTypes.ts +1 -0
- package/src/utilities/math/polyline/pointInPolyline.ts +17 -0
|
@@ -6,6 +6,65 @@ import type { Types } from '@cornerstonejs/core';
|
|
|
6
6
|
* Credit and details: geeksforgeeks.org/check-if-two-given-line-segments-intersect/
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
function getAllIntersectionsWithPolyline(
|
|
10
|
+
points: Types.Point2[],
|
|
11
|
+
p1: Types.Point2,
|
|
12
|
+
q1: Types.Point2,
|
|
13
|
+
closed = true
|
|
14
|
+
): Types.Point2[] {
|
|
15
|
+
let initialI;
|
|
16
|
+
let j;
|
|
17
|
+
const intersections: Types.Point2[] = [];
|
|
18
|
+
|
|
19
|
+
if (closed) {
|
|
20
|
+
j = points.length - 1;
|
|
21
|
+
initialI = 0;
|
|
22
|
+
} else {
|
|
23
|
+
j = 0;
|
|
24
|
+
initialI = 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (let i = initialI; i < points.length; i++) {
|
|
28
|
+
const p2 = points[j];
|
|
29
|
+
const q2 = points[i];
|
|
30
|
+
|
|
31
|
+
if (doesIntersect(p1, q1, p2, q2)) {
|
|
32
|
+
intersections.push([j, i]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
j = i;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return intersections;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns all intersections points
|
|
43
|
+
* between a line and a polyline
|
|
44
|
+
*/
|
|
45
|
+
function getIntersectionCoordinatesWithPolyline(
|
|
46
|
+
points: Types.Point2[],
|
|
47
|
+
p1: Types.Point2,
|
|
48
|
+
q1: Types.Point2,
|
|
49
|
+
closed = true
|
|
50
|
+
): Types.Point2[] {
|
|
51
|
+
const result = [];
|
|
52
|
+
const polylineIndexes = getAllIntersectionsWithPolyline(
|
|
53
|
+
points,
|
|
54
|
+
p1,
|
|
55
|
+
q1,
|
|
56
|
+
closed
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < polylineIndexes.length; i++) {
|
|
60
|
+
const p2 = points[polylineIndexes[i][0]];
|
|
61
|
+
const q2 = points[polylineIndexes[i][1]];
|
|
62
|
+
const intersection = getIntersection(p1, q1, p2, q2);
|
|
63
|
+
result.push(intersection);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
9
68
|
/**
|
|
10
69
|
* Checks whether the line (`p1`,`q1`) intersects any of the other lines in the
|
|
11
70
|
* `points`, and returns the first value.
|
|
@@ -179,4 +238,38 @@ function onSegment(p: Types.Point2, q: Types.Point2, r: Types.Point2): boolean {
|
|
|
179
238
|
return false;
|
|
180
239
|
}
|
|
181
240
|
|
|
182
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Gets the intersection between the line (`p1`,`q1`) and the line (`p2`,`q2`)
|
|
243
|
+
* http://jsfiddle.net/justin_c_rounds/Gd2S2/light/
|
|
244
|
+
* https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
|
|
245
|
+
*/
|
|
246
|
+
function getIntersection(
|
|
247
|
+
p1: Types.Point2,
|
|
248
|
+
q1: Types.Point2,
|
|
249
|
+
p2: Types.Point2,
|
|
250
|
+
q2: Types.Point2
|
|
251
|
+
): Types.Point2 {
|
|
252
|
+
const denominator =
|
|
253
|
+
(q2[1] - p2[1]) * (q1[0] - p1[0]) - (q2[0] - p2[0]) * (q1[1] - p1[1]);
|
|
254
|
+
if (denominator == 0) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
let a = p1[1] - p2[1];
|
|
258
|
+
let b = p1[0] - p2[0];
|
|
259
|
+
const numerator1 = (q2[0] - p2[0]) * a - (q2[1] - p2[1]) * b;
|
|
260
|
+
const numerator2 = (q1[0] - p1[0]) * a - (q1[1] - p1[1]) * b;
|
|
261
|
+
a = numerator1 / denominator;
|
|
262
|
+
b = numerator2 / denominator;
|
|
263
|
+
|
|
264
|
+
const resultX = p1[0] + a * (q1[0] - p1[0]);
|
|
265
|
+
const resultY = p1[1] + a * (q1[1] - p1[1]);
|
|
266
|
+
|
|
267
|
+
return [resultX, resultY];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export {
|
|
271
|
+
getAllIntersectionsWithPolyline,
|
|
272
|
+
getFirstIntersectionWithPolyline,
|
|
273
|
+
getClosestIntersectionWithPolyline,
|
|
274
|
+
getIntersectionCoordinatesWithPolyline,
|
|
275
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import { getAllIntersectionsWithPolyline } from './getIntersectionWithPolyline';
|
|
3
|
+
|
|
4
|
+
export default function pointInPolyline(
|
|
5
|
+
points: Types.Point2[],
|
|
6
|
+
point: Types.Point2,
|
|
7
|
+
pointEnd: Types.Point2
|
|
8
|
+
): boolean {
|
|
9
|
+
const intersections = getAllIntersectionsWithPolyline(points, point, [
|
|
10
|
+
point[0],
|
|
11
|
+
pointEnd[1],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
if (intersections.length % 2 === 0) return false;
|
|
15
|
+
|
|
16
|
+
return true;
|
|
17
|
+
}
|