@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.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.
- package/dist/_virtual/MathUtilsWorker.js +8 -1
- package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
- package/dist/_virtual/filterBoxWorker.js +8 -1
- package/dist/_virtual/highlightWorker.js +8 -1
- package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
- package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
- package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
- package/dist/constant/annotation.js +127 -1
- package/dist/constant/annotationTask.js +30 -1
- package/dist/constant/defaultConfig.js +266 -1
- package/dist/constant/keyCode.js +38 -1
- package/dist/constant/style.js +98 -1
- package/dist/constant/tool.js +236 -1
- package/dist/core/index.js +150 -1
- package/dist/core/pointCloud/OrbitControls.js +665 -1
- package/dist/core/pointCloud/PCDLoader.js +260 -2
- package/dist/core/pointCloud/annotation.js +215 -1
- package/dist/core/pointCloud/cache.js +53 -1
- package/dist/core/pointCloud/index.js +991 -5
- package/dist/core/pointCloud/matrix.js +138 -1
- package/dist/core/pointCloud/segmentation.js +144 -0
- package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
- package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
- package/dist/core/scheduler.js +233 -1
- package/dist/core/toolOperation/LineToolOperation.js +1434 -1
- package/dist/core/toolOperation/ScribbleTool.js +292 -1
- package/dist/core/toolOperation/TextToolOperation.js +131 -1
- package/dist/core/toolOperation/ViewOperation.js +556 -1
- package/dist/core/toolOperation/basicToolOperation.js +881 -1
- package/dist/core/toolOperation/checkOperation.js +208 -1
- package/dist/core/toolOperation/cuboidOperation.js +754 -1
- package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
- package/dist/core/toolOperation/eventListener.js +37 -1
- package/dist/core/toolOperation/measureOperation.js +41 -1
- package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
- package/dist/core/toolOperation/pointOperation.js +696 -1
- package/dist/core/toolOperation/polygonOperation.js +1251 -1
- package/dist/core/toolOperation/rectOperation.js +1233 -1
- package/dist/core/toolOperation/segmentByRect.js +174 -1
- package/dist/core/toolOperation/tagOperation.js +201 -3
- package/dist/core/toolOperation/textAttributeClass.js +182 -16
- package/dist/index.js +185 -1
- package/dist/locales/constants.js +24 -1
- package/dist/locales/en_US/message.js +25 -1
- package/dist/locales/index.js +19 -1
- package/dist/locales/zh_CN/message.js +25 -1
- package/dist/newCore/CanvasScheduler.js +35 -1
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
- package/dist/utils/ActionsHistory.js +84 -1
- package/dist/utils/ImgUtils.js +23 -1
- package/dist/utils/MathUtils.js +385 -2
- package/dist/utils/VectorUtils.js +25 -1
- package/dist/utils/tool/AttributeUtils.js +218 -1
- package/dist/utils/tool/AxisUtils.js +340 -1
- package/dist/utils/tool/CanvasUtils.js +62 -1
- package/dist/utils/tool/CommonToolUtils.js +174 -1
- package/dist/utils/tool/CuboidUtils.js +704 -1
- package/dist/utils/tool/DblClickEventListener.js +102 -1
- package/dist/utils/tool/DrawUtils.js +492 -3
- package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
- package/dist/utils/tool/ImgPosUtils.js +58 -1
- package/dist/utils/tool/LineToolUtils.js +261 -1
- package/dist/utils/tool/MarkerUtils.js +56 -1
- package/dist/utils/tool/PolygonUtils.js +460 -1
- package/dist/utils/tool/RectUtils.js +155 -1
- package/dist/utils/tool/RenderDomClass.js +57 -7
- package/dist/utils/tool/RenderDomUtils.js +21 -4
- package/dist/utils/tool/StyleUtils.js +31 -1
- package/dist/utils/tool/TagUtils.js +129 -1
- package/dist/utils/tool/UnitUtils.js +12 -1
- package/dist/utils/tool/ZoomUtils.js +72 -1
- package/dist/utils/tool/polygonTool.js +133 -1
- package/dist/utils/uuid.js +26 -1
- package/es/_virtual/MathUtilsWorker.js +6 -1
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/_virtual/filterBoxWorker.js +6 -1
- package/es/_virtual/highlightWorker.js +6 -1
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
- package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
- package/es/constant/annotation.js +113 -1
- package/es/constant/annotationTask.js +25 -1
- package/es/constant/defaultConfig.js +260 -1
- package/es/constant/keyCode.js +36 -1
- package/es/constant/style.js +74 -1
- package/es/constant/tool.js +220 -1
- package/es/core/index.js +148 -1
- package/es/core/pointCloud/OrbitControls.js +661 -1
- package/es/core/pointCloud/PCDLoader.js +256 -2
- package/es/core/pointCloud/annotation.js +211 -1
- package/es/core/pointCloud/cache.js +49 -1
- package/es/core/pointCloud/index.js +962 -5
- package/es/core/pointCloud/matrix.js +109 -1
- package/es/core/pointCloud/segmentation.js +120 -0
- package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
- package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
- package/es/core/scheduler.js +228 -1
- package/es/core/toolOperation/LineToolOperation.js +1421 -1
- package/es/core/toolOperation/ScribbleTool.js +290 -1
- package/es/core/toolOperation/TextToolOperation.js +129 -1
- package/es/core/toolOperation/ViewOperation.js +549 -1
- package/es/core/toolOperation/basicToolOperation.js +877 -1
- package/es/core/toolOperation/checkOperation.js +206 -1
- package/es/core/toolOperation/cuboidOperation.js +752 -1
- package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
- package/es/core/toolOperation/eventListener.js +35 -1
- package/es/core/toolOperation/measureOperation.js +39 -1
- package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
- package/es/core/toolOperation/pointOperation.js +690 -1
- package/es/core/toolOperation/polygonOperation.js +1245 -1
- package/es/core/toolOperation/rectOperation.js +1228 -1
- package/es/core/toolOperation/scribbleTool2.js +249 -0
- package/es/core/toolOperation/segmentByRect.js +172 -1
- package/es/core/toolOperation/tagOperation.js +199 -3
- package/es/core/toolOperation/textAttributeClass.js +180 -16
- package/es/index.js +46 -1
- package/es/locales/constants.js +22 -1
- package/es/locales/en_US/message.js +23 -1
- package/es/locales/index.js +17 -1
- package/es/locales/zh_CN/message.js +23 -1
- package/es/newCore/CanvasScheduler.js +31 -1
- package/es/utils/ActionsHistory.js +78 -1
- package/es/utils/ImgUtils.js +21 -1
- package/es/utils/MathUtils.js +380 -2
- package/es/utils/VectorUtils.js +23 -1
- package/es/utils/tool/AttributeUtils.js +212 -1
- package/es/utils/tool/AxisUtils.js +335 -1
- package/es/utils/tool/CanvasUtils.js +60 -1
- package/es/utils/tool/CommonToolUtils.js +172 -1
- package/es/utils/tool/CuboidUtils.js +680 -1
- package/es/utils/tool/DblClickEventListener.js +100 -1
- package/es/utils/tool/DrawUtils.js +490 -3
- package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
- package/es/utils/tool/ImgPosUtils.js +56 -1
- package/es/utils/tool/LineToolUtils.js +255 -1
- package/es/utils/tool/MarkerUtils.js +54 -1
- package/es/utils/tool/PolygonUtils.js +458 -1
- package/es/utils/tool/RectUtils.js +153 -1
- package/es/utils/tool/RenderDomClass.js +55 -7
- package/es/utils/tool/RenderDomUtils.js +19 -4
- package/es/utils/tool/StyleUtils.js +29 -1
- package/es/utils/tool/TagUtils.js +127 -1
- package/es/utils/tool/UnitUtils.js +10 -1
- package/es/utils/tool/ZoomUtils.js +70 -1
- package/es/utils/tool/polygonTool.js +126 -1
- package/es/utils/uuid.js +24 -1
- package/package.json +7 -5
|
@@ -1 +1,460 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var turf = require('@turf/turf');
|
|
4
|
+
var annotation = require('../../constant/annotation.js');
|
|
5
|
+
var CommonToolUtils = require('./CommonToolUtils.js');
|
|
6
|
+
var tool = require('../../constant/tool.js');
|
|
7
|
+
var AxisUtils = require('./AxisUtils.js');
|
|
8
|
+
var MathUtils = require('../MathUtils.js');
|
|
9
|
+
var LineToolUtils = require('./LineToolUtils.js');
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
16
|
+
var __spreadValues = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
class PolygonUtils {
|
|
28
|
+
static getHoverPolygonID(checkPoint, polygonPoints, scope = 3, lineType = tool.ELineTypes.Line) {
|
|
29
|
+
let hoverPolygonID = "";
|
|
30
|
+
let minSize = Infinity;
|
|
31
|
+
const axisList = AxisUtils["default"].axisArea(checkPoint, scope);
|
|
32
|
+
polygonPoints.forEach((p) => {
|
|
33
|
+
if (p.pointList) {
|
|
34
|
+
axisList.forEach((v) => {
|
|
35
|
+
const size = this.calcPolygonSize(p.pointList);
|
|
36
|
+
if (this.isInPolygon(v, p.pointList, lineType) && size < minSize) {
|
|
37
|
+
hoverPolygonID = p.id;
|
|
38
|
+
minSize = size;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return hoverPolygonID;
|
|
44
|
+
}
|
|
45
|
+
static calcPolygonSize(pointList = []) {
|
|
46
|
+
if ((pointList == null ? void 0 : pointList.length) <= 2) {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
const len = pointList.length;
|
|
50
|
+
const size = pointList.reduce((acc, cur, index, src) => {
|
|
51
|
+
const nextVal = src[(index + 1) % len];
|
|
52
|
+
return acc + cur.x * nextVal.y - nextVal.x * cur.y;
|
|
53
|
+
}, 0);
|
|
54
|
+
return Math.abs(size) / 2;
|
|
55
|
+
}
|
|
56
|
+
static isInPolygon(checkPoint, polygonPoints, lineType = tool.ELineTypes.Line) {
|
|
57
|
+
let counter = 0;
|
|
58
|
+
let i;
|
|
59
|
+
let xinters;
|
|
60
|
+
let p1;
|
|
61
|
+
let p2;
|
|
62
|
+
polygonPoints = [...polygonPoints];
|
|
63
|
+
if (lineType === tool.ELineTypes.Curve) {
|
|
64
|
+
polygonPoints = this.createSmoothCurvePoints(polygonPoints.reduce((acc, cur) => {
|
|
65
|
+
return [...acc, cur.x, cur.y];
|
|
66
|
+
}, []), 0.5, true, 20);
|
|
67
|
+
}
|
|
68
|
+
[p1] = polygonPoints;
|
|
69
|
+
const pointCount = polygonPoints.length;
|
|
70
|
+
for (i = 1; i <= pointCount; i++) {
|
|
71
|
+
p2 = polygonPoints[i % pointCount];
|
|
72
|
+
if (checkPoint.x > Math.min(p1.x, p2.x) && checkPoint.x <= Math.max(p1.x, p2.x)) {
|
|
73
|
+
if (checkPoint.y <= Math.max(p1.y, p2.y)) {
|
|
74
|
+
if (p1.x !== p2.x) {
|
|
75
|
+
xinters = (checkPoint.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
|
|
76
|
+
if (p1.y === p2.y || checkPoint.y <= xinters) {
|
|
77
|
+
counter++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
p1 = p2;
|
|
83
|
+
}
|
|
84
|
+
if (counter % 2 === 0) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
static createSmoothCurvePointsFromPointList(pointList, numberOfSegments = tool.SEGMENT_NUMBER) {
|
|
90
|
+
const newPoints = this.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
|
|
91
|
+
return [...acc, cur.x, cur.y];
|
|
92
|
+
}, []), 0.5, false, numberOfSegments);
|
|
93
|
+
return newPoints.map((p, i) => {
|
|
94
|
+
var _a;
|
|
95
|
+
const pos = i / (tool.SEGMENT_NUMBER + 1);
|
|
96
|
+
const v = Math.floor(pos);
|
|
97
|
+
const data = (_a = pointList[v]) != null ? _a : {};
|
|
98
|
+
if (v === pos) {
|
|
99
|
+
return __spreadValues(__spreadValues({}, data), p);
|
|
100
|
+
}
|
|
101
|
+
return __spreadValues({
|
|
102
|
+
specialEdge: data.specialEdge
|
|
103
|
+
}, p);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
static createSmoothCurvePoints(points, tension = 0.5, closed = false, numberOfSegments = tool.SEGMENT_NUMBER) {
|
|
107
|
+
if (points.length < 4) {
|
|
108
|
+
return points;
|
|
109
|
+
}
|
|
110
|
+
const result = [];
|
|
111
|
+
const ps = points.slice(0);
|
|
112
|
+
let x;
|
|
113
|
+
let y;
|
|
114
|
+
let t1x;
|
|
115
|
+
let t2x;
|
|
116
|
+
let t1y;
|
|
117
|
+
let t2y;
|
|
118
|
+
let c1;
|
|
119
|
+
let c2;
|
|
120
|
+
let c3;
|
|
121
|
+
let c4;
|
|
122
|
+
let st;
|
|
123
|
+
let t;
|
|
124
|
+
let i;
|
|
125
|
+
if (closed) {
|
|
126
|
+
ps.unshift(points[points.length - 1]);
|
|
127
|
+
ps.unshift(points[points.length - 2]);
|
|
128
|
+
ps.unshift(points[points.length - 1]);
|
|
129
|
+
ps.unshift(points[points.length - 2]);
|
|
130
|
+
ps.push(points[0]);
|
|
131
|
+
ps.push(points[1]);
|
|
132
|
+
} else {
|
|
133
|
+
ps.unshift(points[1]);
|
|
134
|
+
ps.unshift(points[0]);
|
|
135
|
+
ps.push(points[points.length - 2]);
|
|
136
|
+
ps.push(points[points.length - 1]);
|
|
137
|
+
}
|
|
138
|
+
for (i = 2; i < ps.length - 4; i += 2) {
|
|
139
|
+
t1x = (ps[i + 2] - ps[i - 2]) * tension;
|
|
140
|
+
t2x = (ps[i + 4] - ps[i - 0]) * tension;
|
|
141
|
+
t1y = (ps[i + 3] - ps[i - 1]) * tension;
|
|
142
|
+
t2y = (ps[i + 5] - ps[i + 1]) * tension;
|
|
143
|
+
for (t = 0; t <= numberOfSegments; t++) {
|
|
144
|
+
st = t / numberOfSegments;
|
|
145
|
+
c1 = 2 * Math.pow(st, 3) - 3 * Math.pow(st, 2) + 1;
|
|
146
|
+
c2 = -(2 * Math.pow(st, 3)) + 3 * Math.pow(st, 2);
|
|
147
|
+
c3 = Math.pow(st, 3) - 2 * Math.pow(st, 2) + st;
|
|
148
|
+
c4 = Math.pow(st, 3) - Math.pow(st, 2);
|
|
149
|
+
x = c1 * ps[i] + c2 * ps[i + 2] + c3 * t1x + c4 * t2x;
|
|
150
|
+
y = c1 * ps[i + 1] + c2 * ps[i + 3] + c3 * t1y + c4 * t2y;
|
|
151
|
+
result.push(x);
|
|
152
|
+
result.push(y);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const formatResult = [];
|
|
156
|
+
for (let j = 0; j < result.length - 1; j += 2) {
|
|
157
|
+
formatResult.push({
|
|
158
|
+
x: result[j],
|
|
159
|
+
y: result[j + 1]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (closed) {
|
|
163
|
+
for (let m = 0; m < numberOfSegments + 1; m++) {
|
|
164
|
+
const d = formatResult.shift();
|
|
165
|
+
formatResult.push(d);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return formatResult;
|
|
169
|
+
}
|
|
170
|
+
static getPolygonByID(polygonList, id) {
|
|
171
|
+
return polygonList.find((p) => p.id === id);
|
|
172
|
+
}
|
|
173
|
+
static getPolygonByIDs(polygonList, ids) {
|
|
174
|
+
if (ids && (ids == null ? void 0 : ids.length) > 0) {
|
|
175
|
+
return polygonList.filter((p) => ids.includes(p.id));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
static getHoverEdgeIndex(checkPoint, pointList, lineType = tool.ELineTypes.Line, scope = 3) {
|
|
179
|
+
let points = [...pointList];
|
|
180
|
+
if (lineType === tool.ELineTypes.Curve) {
|
|
181
|
+
points = this.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
|
|
182
|
+
return [...acc, cur.x, cur.y];
|
|
183
|
+
}, []), 0.5, true, tool.SEGMENT_NUMBER);
|
|
184
|
+
} else if (lineType === tool.ELineTypes.Line) {
|
|
185
|
+
points.push(points[0]);
|
|
186
|
+
}
|
|
187
|
+
let edgeIndex = -1;
|
|
188
|
+
let minLength = scope;
|
|
189
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
190
|
+
const {length} = MathUtils["default"].getFootOfPerpendicular(checkPoint, points[i], points[i + 1]);
|
|
191
|
+
if (length < minLength) {
|
|
192
|
+
edgeIndex = i;
|
|
193
|
+
minLength = length;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (edgeIndex === -1) {
|
|
197
|
+
return -1;
|
|
198
|
+
}
|
|
199
|
+
if (lineType === tool.ELineTypes.Curve) {
|
|
200
|
+
return Math.floor(edgeIndex / tool.SEGMENT_NUMBER);
|
|
201
|
+
}
|
|
202
|
+
return edgeIndex;
|
|
203
|
+
}
|
|
204
|
+
static getClosestPoint(coordinate, polygonList, lineType = tool.ELineTypes.Line, range = 3, option) {
|
|
205
|
+
var _a;
|
|
206
|
+
let hasClosed = false;
|
|
207
|
+
const isClose = (_a = option == null ? void 0 : option.isClose) != null ? _a : true;
|
|
208
|
+
let closestPolygonID = "";
|
|
209
|
+
let closestEdgeIndex = -1;
|
|
210
|
+
let min = Infinity;
|
|
211
|
+
let dropFoot = coordinate;
|
|
212
|
+
const numberOfSegments = 20;
|
|
213
|
+
let isCloseNode = false;
|
|
214
|
+
polygonList.forEach((v) => {
|
|
215
|
+
if (isCloseNode) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!v.pointList) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
switch (lineType) {
|
|
222
|
+
case tool.ELineTypes.Line:
|
|
223
|
+
{
|
|
224
|
+
const allLine = CommonToolUtils.findAllLine(v.pointList, isClose);
|
|
225
|
+
allLine.forEach((line, lineIndex) => {
|
|
226
|
+
if (isCloseNode) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let {length, footPoint} = MathUtils["default"].getFootOfPerpendicular(coordinate, line.point1, line.point2);
|
|
230
|
+
const twoPointDistance1 = MathUtils["default"].getLineLength(line.point1, coordinate);
|
|
231
|
+
const twoPointDistance2 = MathUtils["default"].getLineLength(line.point2, coordinate);
|
|
232
|
+
if (twoPointDistance1 < range * 2) {
|
|
233
|
+
footPoint = line.point1;
|
|
234
|
+
length = twoPointDistance1;
|
|
235
|
+
isCloseNode = true;
|
|
236
|
+
}
|
|
237
|
+
if (twoPointDistance2 < range * 2) {
|
|
238
|
+
footPoint = line.point2;
|
|
239
|
+
length = twoPointDistance2;
|
|
240
|
+
isCloseNode = true;
|
|
241
|
+
}
|
|
242
|
+
if (length < min && length < range) {
|
|
243
|
+
closestPolygonID = v.id;
|
|
244
|
+
closestEdgeIndex = lineIndex;
|
|
245
|
+
min = length;
|
|
246
|
+
dropFoot = footPoint;
|
|
247
|
+
hasClosed = true;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
break;
|
|
252
|
+
case tool.ELineTypes.Curve:
|
|
253
|
+
{
|
|
254
|
+
const points = this.createSmoothCurvePoints(v.pointList.reduce((acc, cur) => {
|
|
255
|
+
return [...acc, cur.x, cur.y];
|
|
256
|
+
}, []), 0.5, isClose, numberOfSegments);
|
|
257
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
258
|
+
const {length, footPoint} = MathUtils["default"].getFootOfPerpendicular(coordinate, points[i], points[i + 1]);
|
|
259
|
+
if (length < min && length < range) {
|
|
260
|
+
closestPolygonID = v.id;
|
|
261
|
+
closestEdgeIndex = Math.floor(i / (numberOfSegments + 1));
|
|
262
|
+
min = length;
|
|
263
|
+
dropFoot = footPoint;
|
|
264
|
+
hasClosed = true;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
return {dropFoot, closestEdgeIndex, closestPolygonID, hasClosed};
|
|
272
|
+
}
|
|
273
|
+
static isPointListInPolygon(pointList, polygonPoints, lineType = tool.ELineTypes.Line) {
|
|
274
|
+
return pointList.every((v) => this.isInPolygon(v, polygonPoints, lineType));
|
|
275
|
+
}
|
|
276
|
+
static isPointListOutSidePolygon(pointList, polygonPoints, lineType = tool.ELineTypes.Line) {
|
|
277
|
+
return pointList.some((v) => !this.isInPolygon(v, polygonPoints, lineType));
|
|
278
|
+
}
|
|
279
|
+
static getPolygonArea(pointList) {
|
|
280
|
+
let total = 0;
|
|
281
|
+
for (let i = 0, l = pointList.length; i < l; i++) {
|
|
282
|
+
const addX = pointList[i].x;
|
|
283
|
+
const addY = pointList[i === pointList.length - 1 ? 0 : i + 1].y;
|
|
284
|
+
const subX = pointList[i === pointList.length - 1 ? 0 : i + 1].x;
|
|
285
|
+
const subY = pointList[i].y;
|
|
286
|
+
total += addX * addY * 0.5;
|
|
287
|
+
total -= subX * subY * 0.5;
|
|
288
|
+
}
|
|
289
|
+
return Math.abs(total);
|
|
290
|
+
}
|
|
291
|
+
static updatePolygonByRotate(direction, angle = 1, pointList) {
|
|
292
|
+
let rotate = 1;
|
|
293
|
+
if (direction === annotation.ERotateDirection.Anticlockwise) {
|
|
294
|
+
rotate = -1;
|
|
295
|
+
}
|
|
296
|
+
rotate *= angle;
|
|
297
|
+
return MathUtils["default"].rotateRectPointList(rotate, pointList);
|
|
298
|
+
}
|
|
299
|
+
static deletePolygonLastPoint(acc, cur, index, array) {
|
|
300
|
+
if (index === array.length - 1) {
|
|
301
|
+
return acc;
|
|
302
|
+
}
|
|
303
|
+
return [
|
|
304
|
+
...acc,
|
|
305
|
+
{
|
|
306
|
+
x: cur[0],
|
|
307
|
+
y: cur[1]
|
|
308
|
+
}
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
static concatBeginAndEnd(array) {
|
|
312
|
+
if (array.length < 1) {
|
|
313
|
+
return array;
|
|
314
|
+
}
|
|
315
|
+
return [...array, array[0]];
|
|
316
|
+
}
|
|
317
|
+
static segmentPolygonByPolygon(pointList, polygonList) {
|
|
318
|
+
var _a, _b;
|
|
319
|
+
try {
|
|
320
|
+
let selectedPolygon = turf.polygon([[...PolygonUtils.concatBeginAndEnd(pointList.map((v) => [v.x, v.y]))]]);
|
|
321
|
+
polygonList.forEach((v) => {
|
|
322
|
+
const backgroundPolygon = turf.polygon([[...PolygonUtils.concatBeginAndEnd(v.pointList.map((p) => [p.x, p.y]))]]);
|
|
323
|
+
const diff = turf.difference(selectedPolygon, backgroundPolygon);
|
|
324
|
+
if (diff) {
|
|
325
|
+
selectedPolygon = diff;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
const resultList = (_b = (_a = selectedPolygon == null ? void 0 : selectedPolygon.geometry) == null ? void 0 : _a.coordinates.map((p) => {
|
|
329
|
+
var _a2;
|
|
330
|
+
if (((_a2 = selectedPolygon == null ? void 0 : selectedPolygon.geometry) == null ? void 0 : _a2.type) === "MultiPolygon") {
|
|
331
|
+
return p[0].reduce(PolygonUtils.deletePolygonLastPoint, []);
|
|
332
|
+
}
|
|
333
|
+
return p.reduce(PolygonUtils.deletePolygonLastPoint, []);
|
|
334
|
+
})) != null ? _b : [];
|
|
335
|
+
return resultList.reduce((acc, pointLists) => {
|
|
336
|
+
const len = pointLists.length;
|
|
337
|
+
const newPointList = pointLists.filter((point, i) => {
|
|
338
|
+
const nextIndex = (i + 1) % len;
|
|
339
|
+
if (AxisUtils["default"].getIsInScope(point, pointLists[nextIndex], 1)) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
return true;
|
|
343
|
+
});
|
|
344
|
+
if (newPointList.length < 3) {
|
|
345
|
+
return acc;
|
|
346
|
+
}
|
|
347
|
+
return [...acc, newPointList];
|
|
348
|
+
}, []);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
console.error(error);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
static getPolygonPointList(selectedPolygonID, polygonList) {
|
|
354
|
+
const p = polygonList.find((v) => v.id === selectedPolygonID);
|
|
355
|
+
if (p && p.pointList && p.pointList.length > 0) {
|
|
356
|
+
return p.pointList;
|
|
357
|
+
}
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
static getWrapPolygonIndex(pointList, polygonList) {
|
|
361
|
+
return polygonList.findIndex((p) => PolygonUtils.isPointListInPolygon(pointList, p.pointList));
|
|
362
|
+
}
|
|
363
|
+
static clipPolygonFromWrapPolygon(pointList, wrapPointList) {
|
|
364
|
+
const wrapDirection = PolygonUtils.isPolygonClosewise(wrapPointList);
|
|
365
|
+
const selectedDirection = PolygonUtils.isPolygonClosewise(pointList);
|
|
366
|
+
const linkIndex = PolygonUtils.getClosePointDistanceFromPolygon(pointList[0], wrapPointList);
|
|
367
|
+
const linkPoint = wrapPointList[linkIndex];
|
|
368
|
+
let newPointList = [
|
|
369
|
+
...wrapPointList.slice(0, linkIndex),
|
|
370
|
+
linkPoint,
|
|
371
|
+
...pointList,
|
|
372
|
+
pointList[0],
|
|
373
|
+
...wrapPointList.slice(linkIndex, wrapPointList.length)
|
|
374
|
+
];
|
|
375
|
+
if (wrapDirection === selectedDirection) {
|
|
376
|
+
newPointList = [
|
|
377
|
+
...wrapPointList.slice(0, linkIndex),
|
|
378
|
+
linkPoint,
|
|
379
|
+
pointList[0],
|
|
380
|
+
...pointList.reverse(),
|
|
381
|
+
...wrapPointList.slice(linkIndex, wrapPointList.length)
|
|
382
|
+
];
|
|
383
|
+
}
|
|
384
|
+
return newPointList;
|
|
385
|
+
}
|
|
386
|
+
static isPolygonClosewise(p) {
|
|
387
|
+
const n = p.length;
|
|
388
|
+
let i;
|
|
389
|
+
let j;
|
|
390
|
+
let k;
|
|
391
|
+
let count = 0;
|
|
392
|
+
let z;
|
|
393
|
+
if (n < 3) {
|
|
394
|
+
return 0;
|
|
395
|
+
}
|
|
396
|
+
for (i = 0; i < n; i++) {
|
|
397
|
+
j = (i + 1) % n;
|
|
398
|
+
k = (i + 2) % n;
|
|
399
|
+
z = (p[j].x - p[i].x) * (p[k].y - p[j].y);
|
|
400
|
+
z -= (p[j].y - p[i].y) * (p[k].x - p[j].x);
|
|
401
|
+
if (z < 0) {
|
|
402
|
+
count--;
|
|
403
|
+
} else if (z > 0) {
|
|
404
|
+
count++;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (count > 0) {
|
|
408
|
+
return 1;
|
|
409
|
+
}
|
|
410
|
+
if (count < 0) {
|
|
411
|
+
return -1;
|
|
412
|
+
}
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
static getClosePointDistanceFromPolygon(point, pointList) {
|
|
416
|
+
let minLen = Number.MAX_SAFE_INTEGER;
|
|
417
|
+
let index = -1;
|
|
418
|
+
pointList.forEach((p, i) => {
|
|
419
|
+
const distance = LineToolUtils["default"].calcDistance(point, p);
|
|
420
|
+
if (distance < minLen) {
|
|
421
|
+
minLen = distance;
|
|
422
|
+
index = i;
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
return index;
|
|
426
|
+
}
|
|
427
|
+
static combinePolygonWithPolygon(selectedPolygon, combinedPolygon) {
|
|
428
|
+
var _a, _b;
|
|
429
|
+
try {
|
|
430
|
+
const turfSelectedPolygon = turf.polygon([
|
|
431
|
+
[...PolygonUtils.concatBeginAndEnd(selectedPolygon.pointList.map((v) => [v.x, v.y]))]
|
|
432
|
+
]);
|
|
433
|
+
const turfCombinedPolygon = turf.polygon([
|
|
434
|
+
[...PolygonUtils.concatBeginAndEnd(combinedPolygon.pointList.map((v) => [v.x, v.y]))]
|
|
435
|
+
]);
|
|
436
|
+
const unionPolygon = turf.union(turfSelectedPolygon, turfCombinedPolygon);
|
|
437
|
+
const unionList = [];
|
|
438
|
+
const newPolygon = selectedPolygon;
|
|
439
|
+
if (((_b = (_a = unionPolygon == null ? void 0 : unionPolygon.geometry) == null ? void 0 : _a.coordinates) == null ? void 0 : _b.length) === 1) {
|
|
440
|
+
unionList.push(combinedPolygon.id);
|
|
441
|
+
const pointList = unionPolygon == null ? void 0 : unionPolygon.geometry.coordinates.map((p) => {
|
|
442
|
+
var _a2;
|
|
443
|
+
if (((_a2 = unionPolygon == null ? void 0 : unionPolygon.geometry) == null ? void 0 : _a2.type) === "MultiPolygon") {
|
|
444
|
+
return p[0].reduce(PolygonUtils.deletePolygonLastPoint, []);
|
|
445
|
+
}
|
|
446
|
+
return p.reduce(PolygonUtils.deletePolygonLastPoint, []);
|
|
447
|
+
})[0];
|
|
448
|
+
newPolygon.pointList = pointList;
|
|
449
|
+
}
|
|
450
|
+
return {
|
|
451
|
+
newPolygon,
|
|
452
|
+
unionList
|
|
453
|
+
};
|
|
454
|
+
} catch (e) {
|
|
455
|
+
console.error(e);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
module.exports = PolygonUtils;
|
|
@@ -1 +1,155 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var AxisUtils = require('./AxisUtils.js');
|
|
4
|
+
var CommonToolUtils = require('./CommonToolUtils.js');
|
|
5
|
+
var polygonTool = require('./polygonTool.js');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defProps = Object.defineProperties;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
class RectUtils {
|
|
27
|
+
static composeResult(result, currentStep, resultList, stepList, basicImgInfo) {
|
|
28
|
+
try {
|
|
29
|
+
const data = JSON.parse(result);
|
|
30
|
+
const currentStepInfo = CommonToolUtils.getCurrentStepInfo(currentStep, stepList);
|
|
31
|
+
const {dataSourceStep} = currentStepInfo;
|
|
32
|
+
const stepName = `step_${currentStepInfo.step}`;
|
|
33
|
+
Object.assign(data, basicImgInfo);
|
|
34
|
+
if (data[stepName]) {
|
|
35
|
+
const info = data[stepName];
|
|
36
|
+
if (info.result) {
|
|
37
|
+
info.result = resultList;
|
|
38
|
+
return JSON.stringify(data);
|
|
39
|
+
}
|
|
40
|
+
return JSON.stringify(__spreadProps(__spreadValues({}, data), {
|
|
41
|
+
[stepName]: __spreadProps(__spreadValues({}, data[stepName]), {
|
|
42
|
+
result: resultList
|
|
43
|
+
})
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
return JSON.stringify(__spreadProps(__spreadValues({}, data), {
|
|
47
|
+
[stepName]: {
|
|
48
|
+
dataSourceStep,
|
|
49
|
+
toolName: currentStepInfo.tool,
|
|
50
|
+
result: resultList
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
static changeCoordinateByRotate(rect, rotate, imgSize) {
|
|
58
|
+
const {x, y, width, height} = rect;
|
|
59
|
+
const leftTopCoordinate = AxisUtils["default"].changeCoordinateByRotate({x, y}, rotate, imgSize);
|
|
60
|
+
switch (rotate % 360) {
|
|
61
|
+
case 90:
|
|
62
|
+
return __spreadProps(__spreadValues({}, rect), {
|
|
63
|
+
x: leftTopCoordinate.x - height,
|
|
64
|
+
y: leftTopCoordinate.y,
|
|
65
|
+
width: height,
|
|
66
|
+
height: width
|
|
67
|
+
});
|
|
68
|
+
case 180:
|
|
69
|
+
return __spreadProps(__spreadValues({}, rect), {
|
|
70
|
+
x: leftTopCoordinate.x - width,
|
|
71
|
+
y: leftTopCoordinate.y - height
|
|
72
|
+
});
|
|
73
|
+
case 270:
|
|
74
|
+
return __spreadProps(__spreadValues({}, rect), {
|
|
75
|
+
x: leftTopCoordinate.x,
|
|
76
|
+
y: leftTopCoordinate.y - width,
|
|
77
|
+
width: height,
|
|
78
|
+
height: width
|
|
79
|
+
});
|
|
80
|
+
default:
|
|
81
|
+
return rect;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
static translateRect2Points(rect) {
|
|
85
|
+
const {x, y, width, height} = rect;
|
|
86
|
+
return [
|
|
87
|
+
{
|
|
88
|
+
x,
|
|
89
|
+
y
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
x: x + width,
|
|
93
|
+
y
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
x: x + width,
|
|
97
|
+
y: y + height
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
x,
|
|
101
|
+
y: y + height
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
static translatePoints2Rect(points, basicRect) {
|
|
106
|
+
if (points.length !== 4) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const {x, y} = points[0];
|
|
110
|
+
const width = points[1].x - points[0].x;
|
|
111
|
+
const height = points[2].y - points[1].y;
|
|
112
|
+
return __spreadProps(__spreadValues({}, basicRect), {
|
|
113
|
+
x,
|
|
114
|
+
y,
|
|
115
|
+
width,
|
|
116
|
+
height
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
static getRectPointList(rect, zoom = 1) {
|
|
120
|
+
return [
|
|
121
|
+
{x: rect.x * zoom, y: rect.y * zoom},
|
|
122
|
+
{x: (rect.x + rect.width) * zoom, y: rect.y * zoom},
|
|
123
|
+
{x: (rect.x + rect.width) * zoom, y: (rect.y + rect.height) * zoom},
|
|
124
|
+
{x: rect.x * zoom, y: (rect.y + rect.height) * zoom}
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
static getRectEdgeList(rect, zoom = 1) {
|
|
128
|
+
const pointList = this.getRectPointList(rect, zoom);
|
|
129
|
+
const len = pointList.length;
|
|
130
|
+
return pointList.map((v, i) => {
|
|
131
|
+
return {
|
|
132
|
+
begin: v,
|
|
133
|
+
end: pointList[(i + 1) % len]
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
static isInRect(coordinate, rect, scope = 0, zoom = 1) {
|
|
138
|
+
return coordinate.x >= rect.x * zoom - scope && coordinate.x <= (rect.x + rect.width) * zoom + scope && coordinate.y >= rect.y * zoom - scope && coordinate.y <= (rect.y + rect.height) * zoom + scope;
|
|
139
|
+
}
|
|
140
|
+
static getRectUnderZoom(rect, zoom = 1) {
|
|
141
|
+
const {x, y, width, height} = rect;
|
|
142
|
+
return __spreadProps(__spreadValues({}, rect), {
|
|
143
|
+
x: x * zoom,
|
|
144
|
+
y: y * zoom,
|
|
145
|
+
width: width * zoom,
|
|
146
|
+
height: height * zoom
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
static isRectNotInPolygon(rect, polygonPointList) {
|
|
150
|
+
const rectPointList = this.getRectPointList(rect);
|
|
151
|
+
return rectPointList.some((p) => !polygonTool.isInPolygon(p, polygonPointList));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = RectUtils;
|