@labelbee/lb-annotation 1.8.0 → 1.9.0-alpha.2

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 (96) hide show
  1. package/README.md +65 -0
  2. package/dist/index.js +20 -9
  3. package/dist/types/constant/tool.d.ts +3 -1
  4. package/dist/types/core/index.d.ts +24 -4
  5. package/dist/types/core/pointCloud/OrbitControls.d.ts +60 -0
  6. package/dist/types/core/pointCloud/PCDLoader.d.ts +11 -0
  7. package/dist/types/core/pointCloud/annotation.d.ts +47 -0
  8. package/dist/types/core/pointCloud/cache.d.ts +16 -0
  9. package/dist/types/core/pointCloud/index.d.ts +325 -0
  10. package/dist/types/core/scheduler.d.ts +71 -0
  11. package/dist/types/core/toolOperation/basicToolOperation.d.ts +20 -2
  12. package/dist/types/core/toolOperation/eventListener.d.ts +2 -2
  13. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +80 -0
  14. package/dist/types/core/toolOperation/polygonOperation.d.ts +21 -7
  15. package/dist/types/core/toolOperation/segmentByRect.d.ts +31 -0
  16. package/dist/types/index.d.ts +9 -3
  17. package/dist/types/newCore/CanvasScheduler.d.ts +31 -0
  18. package/dist/types/newCore/index.d.ts +1 -0
  19. package/dist/types/utils/MathUtils.d.ts +6 -0
  20. package/dist/types/utils/tool/CommonToolUtils.d.ts +0 -13
  21. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +20 -0
  22. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
  23. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -0
  24. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -0
  25. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -0
  26. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -0
  27. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -0
  28. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -0
  29. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -0
  30. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -0
  31. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -0
  32. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -0
  33. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -0
  34. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -0
  35. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -0
  36. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -0
  37. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -0
  38. package/es/constant/annotation.js +68 -0
  39. package/es/constant/annotationTask.js +25 -0
  40. package/es/constant/defaultConfig.js +260 -0
  41. package/es/constant/keyCode.js +36 -0
  42. package/es/constant/style.js +67 -0
  43. package/es/constant/tool.js +183 -0
  44. package/es/core/index.js +145 -0
  45. package/es/core/pointCloud/OrbitControls.js +661 -0
  46. package/es/core/pointCloud/PCDLoader.js +238 -0
  47. package/es/core/pointCloud/annotation.js +98 -0
  48. package/es/core/pointCloud/cache.js +42 -0
  49. package/es/core/pointCloud/index.js +771 -0
  50. package/es/core/scheduler.js +184 -0
  51. package/es/core/toolOperation/LineToolOperation.js +1369 -0
  52. package/es/core/toolOperation/TextToolOperation.js +129 -0
  53. package/es/core/toolOperation/ViewOperation.js +410 -0
  54. package/es/core/toolOperation/basicToolOperation.js +817 -0
  55. package/es/core/toolOperation/checkOperation.js +206 -0
  56. package/es/core/toolOperation/eventListener.js +35 -0
  57. package/es/core/toolOperation/measureOperation.js +39 -0
  58. package/es/core/toolOperation/pointCloud2dOperation.js +197 -0
  59. package/es/core/toolOperation/pointOperation.js +603 -0
  60. package/es/core/toolOperation/polygonOperation.js +1201 -0
  61. package/es/core/toolOperation/rectOperation.js +1170 -0
  62. package/es/core/toolOperation/segmentByRect.js +172 -0
  63. package/es/core/toolOperation/tagOperation.js +215 -0
  64. package/es/core/toolOperation/textAttributeClass.js +201 -0
  65. package/es/index.js +25 -14
  66. package/es/locales/constants.js +21 -0
  67. package/es/locales/en_US/message.js +22 -0
  68. package/es/locales/index.js +17 -0
  69. package/es/locales/zh_CN/message.js +22 -0
  70. package/es/newCore/CanvasScheduler.js +31 -0
  71. package/es/utils/ActionsHistory.js +78 -0
  72. package/es/utils/ImgUtils.js +20 -0
  73. package/es/utils/MathUtils.js +283 -0
  74. package/es/utils/VectorUtils.js +23 -0
  75. package/es/utils/tool/AttributeUtils.js +196 -0
  76. package/es/utils/tool/AxisUtils.js +254 -0
  77. package/es/utils/tool/CanvasUtils.js +60 -0
  78. package/es/utils/tool/CommonToolUtils.js +172 -0
  79. package/es/utils/tool/CurrentOperation.js +35 -0
  80. package/es/utils/tool/DblClickEventListener.js +100 -0
  81. package/es/utils/tool/DrawUtils.js +424 -0
  82. package/es/utils/tool/EnhanceCommonToolUtils.js +39 -0
  83. package/es/utils/tool/ImgPosUtils.js +56 -0
  84. package/es/utils/tool/LineToolUtils.js +255 -0
  85. package/es/utils/tool/MarkerUtils.js +9 -0
  86. package/es/utils/tool/PolygonUtils.js +458 -0
  87. package/es/utils/tool/RectUtils.js +153 -0
  88. package/es/utils/tool/RenderDomClass.js +68 -0
  89. package/es/utils/tool/RenderDomUtils.js +29 -0
  90. package/es/utils/tool/StyleUtils.js +29 -0
  91. package/es/utils/tool/TagUtils.js +127 -0
  92. package/es/utils/tool/UnitUtils.js +10 -0
  93. package/es/utils/tool/ZoomUtils.js +70 -0
  94. package/es/utils/tool/polygonTool.js +126 -0
  95. package/es/utils/uuid.js +24 -0
  96. package/package.json +6 -4
@@ -0,0 +1,255 @@
1
+ import { EToolName, ELineTypes } from '../../constant/tool.js';
2
+ import { createSmoothCurvePointsFromPointList } from './polygonTool.js';
3
+ import PolygonUtils from './PolygonUtils.js';
4
+ import MathUtils from '../MathUtils.js';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __defProps = Object.defineProperties;
8
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
9
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var EStatus;
26
+ (function(EStatus2) {
27
+ EStatus2[EStatus2["Create"] = 0] = "Create";
28
+ EStatus2[EStatus2["Active"] = 1] = "Active";
29
+ EStatus2[EStatus2["Edit"] = 1] = "Edit";
30
+ EStatus2[EStatus2["None"] = 2] = "None";
31
+ })(EStatus || (EStatus = {}));
32
+ var EColor;
33
+ (function(EColor2) {
34
+ EColor2["ActiveArea"] = "#B3B8FF";
35
+ })(EColor || (EColor = {}));
36
+ const SEGMENT_NUMBER = 16;
37
+ const POINT_RADIUS = 3;
38
+ const _LineToolUtils = class {
39
+ static isInLine(checkPoint, point1, point2, scope = 3) {
40
+ const {length} = MathUtils.getFootOfPerpendicular(checkPoint, point1, point2);
41
+ if (length < scope) {
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+ };
47
+ let LineToolUtils = _LineToolUtils;
48
+ LineToolUtils.setSpecialEdgeStyle = (ctx) => {
49
+ ctx.lineCap = "butt";
50
+ ctx.setLineDash([10, 10]);
51
+ };
52
+ LineToolUtils.setReferenceCtx = (ctx) => {
53
+ ctx.lineCap = "butt";
54
+ ctx.setLineDash([6]);
55
+ };
56
+ LineToolUtils.calcOptimalIntersection = (pointList, matchLine, matchPoint, pointRadius, zoom) => {
57
+ let optimalIntersection;
58
+ let minDistance = Infinity;
59
+ let scopeIntersection;
60
+ const matchLineOnExistLine = pointList.find((p, index) => {
61
+ if (index === 0) {
62
+ return;
63
+ }
64
+ const pointAOnLine = _LineToolUtils.isInLine(matchLine.pointA, p, pointList[index - 1]);
65
+ const pointBOnLine = _LineToolUtils.isInLine(matchLine.pointB, p, pointList[index - 1]);
66
+ return pointAOnLine && pointBOnLine;
67
+ });
68
+ if (matchLineOnExistLine) {
69
+ return {point: matchPoint};
70
+ }
71
+ pointList.forEach((point, index) => {
72
+ if (index === 0) {
73
+ return;
74
+ }
75
+ const line2 = {
76
+ pointA: pointList[index - 1],
77
+ pointB: point
78
+ };
79
+ const intersection = _LineToolUtils.lineIntersection(matchLine, line2);
80
+ if (intersection && matchLine) {
81
+ const {onLine2, onLine1, x, y} = intersection;
82
+ const distance = _LineToolUtils.calcDistance(matchPoint, intersection);
83
+ const matchPointInLine = _LineToolUtils.isOnLine(matchLine.pointB.x, matchLine.pointB.y, point.x, point.y, pointList[index - 1].x, pointList[index - 1].y);
84
+ if (matchPointInLine) {
85
+ const intersectionDistance = _LineToolUtils.calcDistance(matchPoint, intersection);
86
+ if (intersectionDistance < pointRadius / zoom) {
87
+ const cPoint = matchLine.pointB;
88
+ const {footPoint, length} = MathUtils.getFootOfPerpendicular(cPoint, line2.pointA, line2.pointB, true);
89
+ if (length !== void 0) {
90
+ const distPointA = _LineToolUtils.calcDistance(line2.pointA, footPoint);
91
+ const distPointB = _LineToolUtils.calcDistance(line2.pointB, footPoint);
92
+ scopeIntersection = {
93
+ point: footPoint,
94
+ minDistance: length
95
+ };
96
+ if (length === Infinity) {
97
+ scopeIntersection.point = distPointA > distPointB ? line2.pointB : line2.pointA;
98
+ }
99
+ }
100
+ }
101
+ return;
102
+ }
103
+ if (distance < minDistance && onLine2 && onLine1) {
104
+ minDistance = distance;
105
+ optimalIntersection = {
106
+ x,
107
+ y
108
+ };
109
+ }
110
+ }
111
+ });
112
+ if (optimalIntersection) {
113
+ return {point: optimalIntersection, minDistance};
114
+ }
115
+ if (scopeIntersection) {
116
+ return scopeIntersection;
117
+ }
118
+ return void 0;
119
+ };
120
+ LineToolUtils.lineIntersection = (lineA, lineB) => {
121
+ let onLine1 = false;
122
+ let onLine2 = false;
123
+ const lineADiff = _LineToolUtils.getAxisDiff(lineA);
124
+ const lineBDiff = _LineToolUtils.getAxisDiff(lineB);
125
+ const denominator = lineBDiff.y * lineADiff.x - lineBDiff.x * lineADiff.y;
126
+ if (denominator === 0) {
127
+ return false;
128
+ }
129
+ let a = lineA.pointA.y - lineB.pointA.y;
130
+ let b = lineA.pointA.x - lineB.pointA.x;
131
+ const numerator1 = (lineB.pointB.x - lineB.pointA.x) * a - (lineB.pointB.y - lineB.pointA.y) * b;
132
+ const numerator2 = (lineA.pointB.x - lineA.pointA.x) * a - (lineA.pointB.y - lineA.pointA.y) * b;
133
+ a = numerator1 / denominator;
134
+ b = numerator2 / denominator;
135
+ if (a > 0 && a < 1) {
136
+ onLine1 = true;
137
+ }
138
+ if (b > 0 && b < 1) {
139
+ onLine2 = true;
140
+ }
141
+ const x = lineA.pointA.x + a * (lineA.pointB.x - lineA.pointA.x);
142
+ const y = lineA.pointA.y + a * (lineA.pointB.y - lineA.pointA.y);
143
+ return {x, y, onLine1, onLine2};
144
+ };
145
+ LineToolUtils.getAxisDiff = (line) => {
146
+ return {
147
+ x: line.pointB.x - line.pointA.x,
148
+ y: line.pointB.y - line.pointA.y
149
+ };
150
+ };
151
+ LineToolUtils.calcDistance = (point1, point2) => {
152
+ return Math.sqrt(Math.pow(Math.abs(point1.x - point2.x), 2) + Math.pow(Math.abs(point1.y - point2.y), 2));
153
+ };
154
+ LineToolUtils.drawCurveLine = (ctx, points, config, applyLineWidth = true, isReference = false, hoverEdgeIndex) => {
155
+ const pointList = createSmoothCurvePointsFromPointList(points, SEGMENT_NUMBER);
156
+ ctx.save();
157
+ ctx.lineCap = "round";
158
+ ctx.lineJoin = "round";
159
+ ctx.strokeStyle = config.color;
160
+ if (applyLineWidth) {
161
+ ctx.lineWidth = config.lineWidth;
162
+ }
163
+ if (isReference) {
164
+ _LineToolUtils.setReferenceCtx(ctx);
165
+ }
166
+ points.forEach((point, index) => {
167
+ const specialEdge = point == null ? void 0 : point.specialEdge;
168
+ const curveLinePoints = pointList.splice(0, SEGMENT_NUMBER + 1);
169
+ ctx.save();
170
+ ctx.beginPath();
171
+ if (hoverEdgeIndex === index) {
172
+ ctx.lineWidth = 4;
173
+ }
174
+ curveLinePoints.forEach(({x, y}, pointIndex) => {
175
+ const fn = pointIndex > 0 ? "lineTo" : "moveTo";
176
+ if (specialEdge) {
177
+ _LineToolUtils.setSpecialEdgeStyle(ctx);
178
+ }
179
+ ctx[fn](x, y);
180
+ });
181
+ ctx.stroke();
182
+ ctx.restore();
183
+ });
184
+ ctx.restore();
185
+ };
186
+ LineToolUtils.calcTwoPointDistance = (pointA, pointB) => Math.sqrt(Math.pow(pointA.x - pointB.x, 2) + Math.pow(pointA.y - pointB.y, 2));
187
+ LineToolUtils.pointOverTarget = (axis, preAxis, dependToolName, dependData, dependConfig, imageSize, pointRadius, zoom, getRenderAxis, getAbsAxis) => {
188
+ const absAxis = axis;
189
+ if (!preAxis) {
190
+ return axis;
191
+ }
192
+ if (dependToolName === EToolName.Polygon) {
193
+ const polygonPointList = _LineToolUtils.getPolygonPointList(dependData, dependConfig);
194
+ if (polygonPointList.length === 0) {
195
+ return absAxis;
196
+ }
197
+ const inPolygon = PolygonUtils.isInPolygon(axis, polygonPointList);
198
+ if (inPolygon) {
199
+ return absAxis;
200
+ }
201
+ const pointList = polygonPointList.concat(polygonPointList[0]).map((i) => getRenderAxis(i));
202
+ const pointA = getRenderAxis(preAxis);
203
+ const pointB = getRenderAxis(axis);
204
+ const line1 = {
205
+ pointA,
206
+ pointB
207
+ };
208
+ const intersection = _LineToolUtils.calcOptimalIntersection(pointList, line1, pointA, pointRadius, zoom);
209
+ if (intersection) {
210
+ const intersectionAbsAxis = getAbsAxis(intersection == null ? void 0 : intersection.point);
211
+ absAxis.x = intersectionAbsAxis.x;
212
+ absAxis.y = intersectionAbsAxis.y;
213
+ } else {
214
+ return preAxis;
215
+ }
216
+ return absAxis;
217
+ }
218
+ if (dependToolName === EToolName.Rect) {
219
+ const {x, y, width, height} = dependData;
220
+ absAxis.x = MathUtils.withinRange(absAxis.x, [x, x + width]);
221
+ absAxis.y = MathUtils.withinRange(absAxis.y, [y, y + height]);
222
+ return absAxis;
223
+ }
224
+ absAxis.x = MathUtils.withinRange(absAxis.x, [0, imageSize.width]);
225
+ absAxis.y = MathUtils.withinRange(absAxis.y, [0, imageSize.height]);
226
+ return absAxis;
227
+ };
228
+ LineToolUtils.getPolygonPointList = (dependData, dependConfig) => {
229
+ const {pointList} = dependData;
230
+ const {lineType} = dependConfig;
231
+ return lineType === ELineTypes.Line ? pointList : PolygonUtils.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
232
+ return [...acc, cur.x, cur.y];
233
+ }, []), 0.5, true, 20);
234
+ };
235
+ LineToolUtils.isOnLine = (x, y, endX, endY, px, py) => {
236
+ const f = (someX) => {
237
+ return (endY - y) / (endX - x) * (someX - x) + y;
238
+ };
239
+ return Math.abs(f(px) - py) < 1e-6 && px >= x && px <= endX;
240
+ };
241
+ LineToolUtils.inArea = ({top, left, right, bottom}, {x, y}) => y >= top && y <= bottom && x >= left && x <= right;
242
+ LineToolUtils.getVHPoint = (lastPoint, nextPoint, absNextPoint, renderLastPoint) => {
243
+ const angle = _LineToolUtils.getAngle(lastPoint, absNextPoint);
244
+ if (Math.abs(angle) < 45) {
245
+ return __spreadProps(__spreadValues({}, nextPoint), {y: renderLastPoint.y});
246
+ }
247
+ return __spreadProps(__spreadValues({}, nextPoint), {x: renderLastPoint.x});
248
+ };
249
+ LineToolUtils.getAngle = (startPoint, endPoint) => {
250
+ const diffX = endPoint.x - startPoint.x;
251
+ const diffY = endPoint.y - startPoint.y;
252
+ return 360 * Math.atan(diffY / diffX) / (2 * Math.PI);
253
+ };
254
+
255
+ export { EColor, EStatus, POINT_RADIUS, SEGMENT_NUMBER, LineToolUtils as default };
@@ -0,0 +1,9 @@
1
+ import AttributeUtils from './AttributeUtils.js';
2
+
3
+ class MarkerUtils {
4
+ static getMarkerShowText(marker, markerList = []) {
5
+ return AttributeUtils.getAttributeShowText(marker, markerList);
6
+ }
7
+ }
8
+
9
+ export { MarkerUtils as default };