@labelbee/lb-annotation 1.8.0 → 1.8.1-alpha.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/index.js +9 -9
- package/dist/types/core/toolOperation/ViewOperation.d.ts +31 -0
- package/dist/types/utils/MathUtils.d.ts +3 -0
- package/dist/types/utils/tool/DrawUtils.d.ts +14 -13
- package/es/.DS_Store +0 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +1 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +1 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +1 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +2 -0
- package/es/_virtual/filterBoxWorker.js +1 -0
- package/es/_virtual/highlightWorker.js +1 -0
- package/es/_virtual/worker.js +6 -0
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editLV.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editQING.svg.js +3 -0
- package/es/constant/annotation.js +68 -0
- package/es/constant/annotationTask.js +25 -0
- package/es/constant/defaultConfig.js +260 -0
- package/es/constant/keyCode.js +36 -0
- package/es/constant/style.js +67 -0
- package/es/constant/tool.js +181 -0
- package/es/core/index.js +134 -0
- package/es/core/pointCloud/OrbitControls.js +1 -0
- package/es/core/pointCloud/PCDLoader.js +2 -0
- package/es/core/pointCloud/annotation.js +1 -0
- package/es/core/pointCloud/cache.js +1 -0
- package/es/core/pointCloud/index.js +11 -0
- package/es/core/scheduler.js +1 -0
- package/es/core/toolOperation/LineToolOperation.js +1369 -0
- package/es/core/toolOperation/TextToolOperation.js +129 -0
- package/es/core/toolOperation/ViewOperation.js +414 -0
- package/es/core/toolOperation/basicToolOperation.js +796 -0
- package/es/core/toolOperation/checkOperation.js +206 -0
- package/es/core/toolOperation/eventListener.js +35 -0
- package/es/core/toolOperation/measureOperation.js +39 -0
- package/es/core/toolOperation/pointCloud2dOperation.js +1 -0
- package/es/core/toolOperation/pointOperation.js +603 -0
- package/es/core/toolOperation/polygonOperation.js +1160 -0
- package/es/core/toolOperation/rectOperation.js +1166 -0
- package/es/core/toolOperation/segmentByRect.js +1 -0
- package/es/core/toolOperation/tagOperation.js +215 -0
- package/es/core/toolOperation/textAttributeClass.js +201 -0
- package/es/index.js +13 -13
- package/es/locales/constants.js +21 -0
- package/es/locales/en_US/message.js +22 -0
- package/es/locales/index.js +17 -0
- package/es/locales/zh_CN/message.js +22 -0
- package/es/newCore/CanvasScheduler.js +1 -0
- package/es/utils/ActionsHistory.js +78 -0
- package/es/utils/ImgUtils.js +20 -0
- package/es/utils/MathUtils.js +339 -0
- package/es/utils/VectorUtils.js +23 -0
- package/es/utils/tool/AttributeUtils.js +196 -0
- package/es/utils/tool/AxisUtils.js +254 -0
- package/es/utils/tool/CanvasUtils.js +60 -0
- package/es/utils/tool/CommonToolUtils.js +201 -0
- package/es/utils/tool/CurrentOperation.js +35 -0
- package/es/utils/tool/DblClickEventListener.js +100 -0
- package/es/utils/tool/DrawUtils.js +424 -0
- package/es/utils/tool/EnhanceCommonToolUtils.js +1 -0
- package/es/utils/tool/ImgPosUtils.js +56 -0
- package/es/utils/tool/LineToolUtils.js +255 -0
- package/es/utils/tool/MarkerUtils.js +9 -0
- package/es/utils/tool/PolygonUtils.js +453 -0
- package/es/utils/tool/RectUtils.js +153 -0
- package/es/utils/tool/RenderDomClass.js +68 -0
- package/es/utils/tool/RenderDomUtils.js +29 -0
- package/es/utils/tool/StyleUtils.js +29 -0
- package/es/utils/tool/TagUtils.js +127 -0
- package/es/utils/tool/UnitUtils.js +10 -0
- package/es/utils/tool/ZoomUtils.js +70 -0
- package/es/utils/tool/polygonTool.js +126 -0
- package/es/utils/uuid.js +24 -0
- package/package.json +2 -3
- package/LICENSE +0 -203
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { ELineTypes, SEGMENT_NUMBER, DEFAULT_FONT } from '../../constant/tool.js';
|
|
2
|
+
import PolygonUtils from './PolygonUtils.js';
|
|
3
|
+
import UnitUtils from './UnitUtils.js';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defProps = Object.defineProperties;
|
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
const DEFAULT_ZOOM = 1;
|
|
25
|
+
const DEFAULT_CURRENT_POS = {
|
|
26
|
+
x: 0,
|
|
27
|
+
y: 0
|
|
28
|
+
};
|
|
29
|
+
const DEFAULT_ROTATE = 0;
|
|
30
|
+
const DEFAULT_COLOR = "";
|
|
31
|
+
class DrawUtils {
|
|
32
|
+
static drawLine(canvas, startPoint, endPoint, options = {}) {
|
|
33
|
+
const ctx = canvas.getContext("2d");
|
|
34
|
+
const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round"} = options;
|
|
35
|
+
ctx.save();
|
|
36
|
+
ctx.strokeStyle = color;
|
|
37
|
+
ctx.lineWidth = thickness;
|
|
38
|
+
ctx.lineCap = lineCap;
|
|
39
|
+
ctx.beginPath();
|
|
40
|
+
ctx.moveTo(startPoint.x, startPoint.y);
|
|
41
|
+
ctx.lineTo(endPoint.x + 1, endPoint.y + 1);
|
|
42
|
+
ctx.stroke();
|
|
43
|
+
ctx.restore();
|
|
44
|
+
}
|
|
45
|
+
static drawRect(canvas, rect, options = {}) {
|
|
46
|
+
const ctx = canvas.getContext("2d");
|
|
47
|
+
const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", hiddenText = false, lineDash} = options;
|
|
48
|
+
ctx.save();
|
|
49
|
+
ctx.strokeStyle = color;
|
|
50
|
+
ctx.lineWidth = thickness;
|
|
51
|
+
ctx.lineCap = lineCap;
|
|
52
|
+
if (Array.isArray(lineDash)) {
|
|
53
|
+
ctx.setLineDash(lineDash);
|
|
54
|
+
}
|
|
55
|
+
ctx.fillStyle = color;
|
|
56
|
+
ctx.strokeRect(rect.x, rect.y, rect.width, rect.height);
|
|
57
|
+
if (hiddenText === false) {
|
|
58
|
+
let showText = "";
|
|
59
|
+
if (rect.attribute) {
|
|
60
|
+
showText = `${showText} ${rect.attribute}`;
|
|
61
|
+
}
|
|
62
|
+
this.drawText(canvas, {x: rect.x, y: rect.y - 5}, showText);
|
|
63
|
+
if (rect.textAttribute) {
|
|
64
|
+
const text = `${~~rect.width} * ${~~rect.height}`;
|
|
65
|
+
const textSizeWidth = text.length * 7;
|
|
66
|
+
const marginTop = 0;
|
|
67
|
+
const textWidth = Math.max(20, rect.width - textSizeWidth);
|
|
68
|
+
this.drawText(canvas, {x: rect.x, y: rect.y + rect.height + 20 + marginTop}, rect.textAttribute, {
|
|
69
|
+
textMaxWidth: textWidth
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
ctx.restore();
|
|
74
|
+
}
|
|
75
|
+
static drawRectWithFill(canvas, rect, options = {}) {
|
|
76
|
+
const ctx = canvas.getContext("2d");
|
|
77
|
+
const {color = DEFAULT_COLOR} = options;
|
|
78
|
+
ctx.save();
|
|
79
|
+
ctx.fillStyle = color;
|
|
80
|
+
ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
81
|
+
ctx.restore();
|
|
82
|
+
}
|
|
83
|
+
static drawTagByDom(parent, text, id) {
|
|
84
|
+
const parentNode = parent;
|
|
85
|
+
if (!((text == null ? void 0 : text.length) > 0)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const dom = document.createElement("div");
|
|
89
|
+
dom.innerHTML = text;
|
|
90
|
+
dom.setAttribute("id", id);
|
|
91
|
+
parentNode == null ? void 0 : parentNode.appendChild(dom);
|
|
92
|
+
return dom;
|
|
93
|
+
}
|
|
94
|
+
static drawTag(canvas, tagList) {
|
|
95
|
+
var _a;
|
|
96
|
+
const parentNode = canvas == null ? void 0 : canvas.parentNode;
|
|
97
|
+
const oldDom = window.self.document.getElementById("tagToolTag");
|
|
98
|
+
if (oldDom && parentNode && parentNode.contains(oldDom)) {
|
|
99
|
+
parentNode == null ? void 0 : parentNode.removeChild(oldDom);
|
|
100
|
+
}
|
|
101
|
+
if (!((tagList == null ? void 0 : tagList.length) > 0)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const dom = document.createElement("div");
|
|
105
|
+
dom.innerHTML = (_a = tagList.reduce((acc, cur) => {
|
|
106
|
+
return `${acc}${cur.keyName}: ${cur.value.join(` \u3001 `)}
|
|
107
|
+
`;
|
|
108
|
+
}, "")) != null ? _a : "";
|
|
109
|
+
dom.setAttribute("id", "tagToolTag");
|
|
110
|
+
parentNode == null ? void 0 : parentNode.appendChild(dom);
|
|
111
|
+
return dom;
|
|
112
|
+
}
|
|
113
|
+
static drawLineWithPointList(canvas, pointList, options = {}) {
|
|
114
|
+
if (pointList.length < 2) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const ctx = canvas.getContext("2d");
|
|
118
|
+
const {
|
|
119
|
+
color = DEFAULT_COLOR,
|
|
120
|
+
thickness = 1,
|
|
121
|
+
lineCap = "round",
|
|
122
|
+
lineType = ELineTypes.Line,
|
|
123
|
+
lineDash,
|
|
124
|
+
hoverEdgeIndex
|
|
125
|
+
} = options;
|
|
126
|
+
ctx.save();
|
|
127
|
+
const setStyle = () => {
|
|
128
|
+
ctx.strokeStyle = color;
|
|
129
|
+
ctx.lineWidth = thickness;
|
|
130
|
+
ctx.lineCap = lineCap;
|
|
131
|
+
if (Array.isArray(lineDash)) {
|
|
132
|
+
ctx.setLineDash(lineDash);
|
|
133
|
+
} else {
|
|
134
|
+
ctx.setLineDash([]);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
setStyle();
|
|
138
|
+
if (lineType === ELineTypes.Curve) {
|
|
139
|
+
if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
|
|
140
|
+
pointList.push(pointList[0]);
|
|
141
|
+
}
|
|
142
|
+
pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList], SEGMENT_NUMBER);
|
|
143
|
+
if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
|
|
144
|
+
pointList = pointList.slice((SEGMENT_NUMBER + 1) * hoverEdgeIndex, (SEGMENT_NUMBER + 1) * (hoverEdgeIndex + 1));
|
|
145
|
+
}
|
|
146
|
+
} else if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
|
|
147
|
+
pointList = [...pointList, pointList[0]];
|
|
148
|
+
pointList = pointList.slice(hoverEdgeIndex, hoverEdgeIndex + 2);
|
|
149
|
+
}
|
|
150
|
+
const specialEdgeList = [];
|
|
151
|
+
ctx.beginPath();
|
|
152
|
+
ctx.moveTo(pointList[0].x, pointList[0].y);
|
|
153
|
+
for (let i = 0; i < pointList.length - 1; i++) {
|
|
154
|
+
if (pointList[i].specialEdge) {
|
|
155
|
+
specialEdgeList.push({
|
|
156
|
+
i1: i,
|
|
157
|
+
i2: i + 1
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
ctx.lineTo(pointList[i + 1].x, pointList[i + 1].y);
|
|
161
|
+
}
|
|
162
|
+
ctx.stroke();
|
|
163
|
+
ctx.save();
|
|
164
|
+
ctx.lineWidth = thickness * 0.8;
|
|
165
|
+
ctx.lineCap = "butt";
|
|
166
|
+
ctx.strokeStyle = "white";
|
|
167
|
+
ctx.setLineDash([3, 3]);
|
|
168
|
+
specialEdgeList.forEach((v) => {
|
|
169
|
+
const point1 = pointList[v.i1];
|
|
170
|
+
const point2 = pointList[v.i2];
|
|
171
|
+
ctx.beginPath();
|
|
172
|
+
ctx.moveTo(point1.x, point1.y);
|
|
173
|
+
ctx.lineTo(point2.x, point2.y);
|
|
174
|
+
ctx.stroke();
|
|
175
|
+
});
|
|
176
|
+
ctx.restore();
|
|
177
|
+
const DEFAULT_SPECIAL_POINT_RADIUS = 4;
|
|
178
|
+
const DEFAULT_BORDER = 2;
|
|
179
|
+
pointList.forEach((p) => {
|
|
180
|
+
if (p.specialPoint) {
|
|
181
|
+
this.drawSpecialPoint(canvas, p, DEFAULT_SPECIAL_POINT_RADIUS + DEFAULT_BORDER, color);
|
|
182
|
+
this.drawSpecialPoint(canvas, p, DEFAULT_SPECIAL_POINT_RADIUS, "white");
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
ctx.restore();
|
|
186
|
+
return pointList;
|
|
187
|
+
}
|
|
188
|
+
static drawCircle(canvas, anchorPoint, radius, options = {}) {
|
|
189
|
+
const ctx = canvas.getContext("2d");
|
|
190
|
+
const {
|
|
191
|
+
startAngleDeg = 0,
|
|
192
|
+
endAngleDeg = 360,
|
|
193
|
+
thickness = 1,
|
|
194
|
+
color = DEFAULT_COLOR,
|
|
195
|
+
fill = DEFAULT_COLOR
|
|
196
|
+
} = options;
|
|
197
|
+
const startAngleRad = UnitUtils.deg2rad(startAngleDeg);
|
|
198
|
+
const endAngleRad = UnitUtils.deg2rad(endAngleDeg);
|
|
199
|
+
ctx.save();
|
|
200
|
+
ctx.beginPath();
|
|
201
|
+
ctx.strokeStyle = color;
|
|
202
|
+
ctx.fillStyle = fill;
|
|
203
|
+
ctx.lineWidth = thickness;
|
|
204
|
+
ctx.arc(anchorPoint.x, anchorPoint.y, radius, startAngleRad, endAngleRad, false);
|
|
205
|
+
ctx.stroke();
|
|
206
|
+
if (fill) {
|
|
207
|
+
ctx.fill();
|
|
208
|
+
}
|
|
209
|
+
ctx.closePath();
|
|
210
|
+
ctx.restore();
|
|
211
|
+
}
|
|
212
|
+
static drawCircleWithFill(canvas, anchorPoint, radius = 3, options = {}) {
|
|
213
|
+
const ctx = canvas.getContext("2d");
|
|
214
|
+
const {color = DEFAULT_COLOR} = options;
|
|
215
|
+
ctx.save();
|
|
216
|
+
const startAngleRad = UnitUtils.deg2rad(0);
|
|
217
|
+
const endAngleRad = UnitUtils.deg2rad(360);
|
|
218
|
+
ctx.fillStyle = color;
|
|
219
|
+
ctx.beginPath();
|
|
220
|
+
ctx.arc(anchorPoint.x, anchorPoint.y, radius, startAngleRad, endAngleRad, false);
|
|
221
|
+
ctx.fill();
|
|
222
|
+
ctx.restore();
|
|
223
|
+
}
|
|
224
|
+
static drawSpecialPoint(canvas, point, pointRadius = 6, fillStyle) {
|
|
225
|
+
const ctx = canvas.getContext("2d");
|
|
226
|
+
const {x, y} = point;
|
|
227
|
+
ctx.save();
|
|
228
|
+
ctx.beginPath();
|
|
229
|
+
ctx.fillStyle = fillStyle;
|
|
230
|
+
const newPointRadius = pointRadius * 1.5;
|
|
231
|
+
const xl = newPointRadius * Math.sqrt(3) / 2;
|
|
232
|
+
const yl = newPointRadius / 2;
|
|
233
|
+
ctx.moveTo(x, y - newPointRadius);
|
|
234
|
+
ctx.lineTo(x - xl, y + yl);
|
|
235
|
+
ctx.lineTo(x + xl, y + yl);
|
|
236
|
+
ctx.closePath();
|
|
237
|
+
ctx.fill();
|
|
238
|
+
ctx.restore();
|
|
239
|
+
}
|
|
240
|
+
static drawPolygon(canvas, pointList, options = {}) {
|
|
241
|
+
const {isClose = false, lineType = ELineTypes.Line} = options;
|
|
242
|
+
if (isClose === true) {
|
|
243
|
+
pointList = [...pointList, pointList[0]];
|
|
244
|
+
}
|
|
245
|
+
if (lineType === ELineTypes.Curve) {
|
|
246
|
+
pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList]);
|
|
247
|
+
}
|
|
248
|
+
this.drawLineWithPointList(canvas, pointList, __spreadProps(__spreadValues({}, options), {
|
|
249
|
+
lineType: ELineTypes.Line
|
|
250
|
+
}));
|
|
251
|
+
return pointList;
|
|
252
|
+
}
|
|
253
|
+
static drawPolygonWithFill(canvas, pointList, options = {}) {
|
|
254
|
+
if (pointList.length < 2) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const ctx = canvas.getContext("2d");
|
|
258
|
+
const {color = DEFAULT_COLOR, lineType = ELineTypes.Line} = options;
|
|
259
|
+
ctx.save();
|
|
260
|
+
ctx.fillStyle = color;
|
|
261
|
+
ctx.beginPath();
|
|
262
|
+
if (lineType === ELineTypes.Curve) {
|
|
263
|
+
pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList, pointList[0]]);
|
|
264
|
+
}
|
|
265
|
+
const [startPoint, ...otherPointList] = pointList;
|
|
266
|
+
ctx.moveTo(startPoint.x, startPoint.y);
|
|
267
|
+
otherPointList.forEach((point) => {
|
|
268
|
+
ctx.lineTo(point.x, point.y);
|
|
269
|
+
});
|
|
270
|
+
ctx.fill();
|
|
271
|
+
ctx.restore();
|
|
272
|
+
return pointList;
|
|
273
|
+
}
|
|
274
|
+
static drawPolygonWithFillAndLine(canvas, pointList, options = {}) {
|
|
275
|
+
const {strokeColor, fillColor, thickness, lineCap, isClose, lineType} = options;
|
|
276
|
+
const newPointList = this.drawPolygon(canvas, pointList, {
|
|
277
|
+
color: strokeColor,
|
|
278
|
+
thickness,
|
|
279
|
+
lineCap,
|
|
280
|
+
isClose,
|
|
281
|
+
lineType
|
|
282
|
+
});
|
|
283
|
+
this.drawPolygonWithFill(canvas, pointList, {color: fillColor, lineType});
|
|
284
|
+
return newPointList;
|
|
285
|
+
}
|
|
286
|
+
static drawPolygonWithKeyPoint(canvas, pointList, options = {}) {
|
|
287
|
+
const {pointColor = "white", strokeColor} = options;
|
|
288
|
+
const newPointList = this.drawPolygon(canvas, pointList, options);
|
|
289
|
+
newPointList.forEach((point) => {
|
|
290
|
+
this.drawCircleWithFill(canvas, point, 4, {color: strokeColor});
|
|
291
|
+
this.drawCircleWithFill(canvas, point, 3, {color: pointColor});
|
|
292
|
+
});
|
|
293
|
+
return newPointList;
|
|
294
|
+
}
|
|
295
|
+
static drawSelectedPolygonWithFillAndLine(canvas, pointList, options = {}) {
|
|
296
|
+
const {pointColor = "white", strokeColor} = options;
|
|
297
|
+
const newPointList = this.drawPolygonWithFillAndLine(canvas, pointList, options);
|
|
298
|
+
newPointList.forEach((point) => {
|
|
299
|
+
this.drawCircleWithFill(canvas, point, 4, {color: strokeColor});
|
|
300
|
+
this.drawCircleWithFill(canvas, point, 3, {color: pointColor});
|
|
301
|
+
});
|
|
302
|
+
return newPointList;
|
|
303
|
+
}
|
|
304
|
+
static drawText(canvas, startPoint, text, options = {}) {
|
|
305
|
+
if (!text) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const ctx = canvas.getContext("2d");
|
|
309
|
+
const {
|
|
310
|
+
color = DEFAULT_COLOR,
|
|
311
|
+
font = DEFAULT_FONT,
|
|
312
|
+
shadowColor = "",
|
|
313
|
+
shadowBlur = 0,
|
|
314
|
+
shadowOffsetX = 0,
|
|
315
|
+
shadowOffsetY = 0,
|
|
316
|
+
textMaxWidth = 164,
|
|
317
|
+
offsetX = 0,
|
|
318
|
+
offsetY = 0,
|
|
319
|
+
textAlign = "start",
|
|
320
|
+
lineHeight
|
|
321
|
+
} = options;
|
|
322
|
+
ctx.save();
|
|
323
|
+
ctx.textAlign = textAlign;
|
|
324
|
+
ctx.fillStyle = color != null ? color : "white";
|
|
325
|
+
ctx.font = font;
|
|
326
|
+
ctx.shadowColor = shadowColor;
|
|
327
|
+
ctx.shadowOffsetX = shadowOffsetX;
|
|
328
|
+
ctx.shadowOffsetY = shadowOffsetY;
|
|
329
|
+
ctx.shadowBlur = shadowBlur;
|
|
330
|
+
this.wrapText(canvas, `${text}`, startPoint.x + offsetX, startPoint.y + offsetY, textMaxWidth, lineHeight);
|
|
331
|
+
ctx.restore();
|
|
332
|
+
}
|
|
333
|
+
static wrapText(canvas, text, x, y, maxWidth, lineHeight) {
|
|
334
|
+
if (typeof text !== "string" || typeof x !== "number" || typeof y !== "number") {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const context = canvas.getContext("2d");
|
|
338
|
+
if (typeof maxWidth === "undefined") {
|
|
339
|
+
maxWidth = canvas && canvas.width || 300;
|
|
340
|
+
}
|
|
341
|
+
if (typeof lineHeight === "undefined") {
|
|
342
|
+
lineHeight = canvas && parseInt(window.getComputedStyle(canvas).lineHeight, 10) || parseInt(window.getComputedStyle(document.body).lineHeight, 10);
|
|
343
|
+
}
|
|
344
|
+
const arrParagraph = text.split("\n");
|
|
345
|
+
for (let i = 0; i < arrParagraph.length; i++) {
|
|
346
|
+
const arrText = arrParagraph[i].split("");
|
|
347
|
+
let line = "";
|
|
348
|
+
for (let n = 0; n < arrText.length; n++) {
|
|
349
|
+
const testLine = line + arrText[n];
|
|
350
|
+
const metrics = context.measureText(testLine);
|
|
351
|
+
const testWidth = metrics.width;
|
|
352
|
+
if (!maxWidth) {
|
|
353
|
+
maxWidth = 300;
|
|
354
|
+
}
|
|
355
|
+
if (testWidth > maxWidth && n > 0) {
|
|
356
|
+
context.fillText(line, x, y);
|
|
357
|
+
line = arrText[n];
|
|
358
|
+
y += lineHeight;
|
|
359
|
+
} else {
|
|
360
|
+
line = testLine;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
context.fillText(line, x, y);
|
|
364
|
+
y += lineHeight;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
static drawArrow(ctx, startPoint, endPoint, options = {}) {
|
|
368
|
+
const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", theta = 30, headLen = 10} = options;
|
|
369
|
+
const angle = Math.atan2(startPoint.y - endPoint.y, startPoint.x - endPoint.x) * 180 / Math.PI;
|
|
370
|
+
const angle1 = (angle + theta) * Math.PI / 180;
|
|
371
|
+
const angle2 = (angle - theta) * Math.PI / 180;
|
|
372
|
+
const topX = headLen * Math.cos(angle1);
|
|
373
|
+
const topY = headLen * Math.sin(angle1);
|
|
374
|
+
const botX = headLen * Math.cos(angle2);
|
|
375
|
+
const botY = headLen * Math.sin(angle2);
|
|
376
|
+
ctx.save();
|
|
377
|
+
ctx.strokeStyle = color;
|
|
378
|
+
ctx.lineWidth = thickness;
|
|
379
|
+
ctx.lineCap = lineCap;
|
|
380
|
+
ctx.beginPath();
|
|
381
|
+
ctx.moveTo(endPoint.x + topX, endPoint.y + topY);
|
|
382
|
+
ctx.lineTo(endPoint.x, endPoint.y);
|
|
383
|
+
ctx.lineTo(endPoint.x + botX, endPoint.y + botY);
|
|
384
|
+
ctx.stroke();
|
|
385
|
+
ctx.restore();
|
|
386
|
+
}
|
|
387
|
+
static drawArrowByCanvas(canvas, startPoint, endPoint, options = {}) {
|
|
388
|
+
const ctx = canvas.getContext("2d");
|
|
389
|
+
this.drawArrow(ctx, startPoint, endPoint, options);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
DrawUtils.drawImg = (canvas, imgNode, options = {}) => {
|
|
393
|
+
const ctx = canvas.getContext("2d");
|
|
394
|
+
const {zoom = DEFAULT_ZOOM, currentPos = DEFAULT_CURRENT_POS, rotate = DEFAULT_ROTATE, imgAttribute} = options;
|
|
395
|
+
ctx.save();
|
|
396
|
+
switch (rotate) {
|
|
397
|
+
case 0:
|
|
398
|
+
ctx.translate(currentPos.x, currentPos.y);
|
|
399
|
+
break;
|
|
400
|
+
case 90:
|
|
401
|
+
ctx.translate(currentPos.x + imgNode.height * zoom, currentPos.y);
|
|
402
|
+
ctx.rotate(90 * Math.PI / 180);
|
|
403
|
+
break;
|
|
404
|
+
case 180:
|
|
405
|
+
ctx.translate(currentPos.x + imgNode.width * zoom, currentPos.y + imgNode.height * zoom);
|
|
406
|
+
ctx.rotate(Math.PI);
|
|
407
|
+
break;
|
|
408
|
+
case 270:
|
|
409
|
+
ctx.translate(currentPos.x, currentPos.y + imgNode.width * zoom);
|
|
410
|
+
ctx.rotate(270 * Math.PI / 180);
|
|
411
|
+
break;
|
|
412
|
+
default:
|
|
413
|
+
ctx.translate(currentPos.x, currentPos.y);
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
if (imgAttribute) {
|
|
417
|
+
const {contrast, saturation, brightness} = imgAttribute;
|
|
418
|
+
ctx.filter = `saturate(${saturation + 100}%) contrast(${contrast + 100}%) brightness(${brightness + 100}%)`;
|
|
419
|
+
}
|
|
420
|
+
ctx.drawImage(imgNode, 0, 0, imgNode.width * zoom, imgNode.height * zoom);
|
|
421
|
+
ctx.restore();
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
export { DrawUtils as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EToolName as o,ECheckModel as n}from"../../constant/tool.js";import a from"../../core/toolOperation/checkOperation.js";import i from"../../core/toolOperation/polygonOperation.js";import{RectOperation as p}from"../../core/toolOperation/rectOperation.js";import c from"../../core/toolOperation/tagOperation.js";import m from"../../core/toolOperation/LineToolOperation.js";import s from"../../core/toolOperation/pointOperation.js";import l from"../../core/toolOperation/TextToolOperation.js";import O from"../../core/toolOperation/segmentByRect.js";import T from"./CommonToolUtils.js";const e=t=>{switch(t){case o.Rect:case o.RectTrack:return p;case o.SegmentByRect:return O;case o.Tag:return c;case o.Polygon:return i;case n.Check:return a;case o.Line:return m;case o.Point:return s;case o.Text:return l;default:throw new Error("not match tool")}};class r extends T{}r.getCurrentOperation=e;export{r as default,e as getCurrentOperation};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class ImgPosUtils {
|
|
2
|
+
static getInitImgPos(canvasSize, imgSize, rotate = 0, zoomRatio = 1, isOriginalSize = false) {
|
|
3
|
+
if (rotate === 90 || rotate === 270) {
|
|
4
|
+
imgSize = {
|
|
5
|
+
width: imgSize.height,
|
|
6
|
+
height: imgSize.width
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
const wScale = canvasSize.width * zoomRatio / imgSize.width;
|
|
10
|
+
const hScale = canvasSize.height * zoomRatio / imgSize.height;
|
|
11
|
+
let scale = isOriginalSize ? 1 : Math.min(wScale, hScale);
|
|
12
|
+
const currentPos = {
|
|
13
|
+
x: (canvasSize.width - imgSize.width * scale) / 2,
|
|
14
|
+
y: (canvasSize.height - imgSize.height * scale) / 2
|
|
15
|
+
};
|
|
16
|
+
const width = imgSize.width * scale;
|
|
17
|
+
const height = imgSize.height * scale;
|
|
18
|
+
if (isOriginalSize) {
|
|
19
|
+
scale = 1;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
zoom: scale,
|
|
23
|
+
currentPos,
|
|
24
|
+
imgInfo: {width, height}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static getBasicRecPos(imgNode, basicRect, size, shrinkRatio = 0.9, zoomRatio = 1, isOriginalSize = false) {
|
|
28
|
+
if (basicRect && imgNode) {
|
|
29
|
+
const {x, y, height, width} = basicRect;
|
|
30
|
+
let initZoom = size.height / height;
|
|
31
|
+
if (width / height > size.width / size.height) {
|
|
32
|
+
initZoom = size.width / width;
|
|
33
|
+
}
|
|
34
|
+
const zoom = isOriginalSize ? 1 : initZoom * shrinkRatio * zoomRatio;
|
|
35
|
+
const viewCenter = {
|
|
36
|
+
x: size.width / 2,
|
|
37
|
+
y: size.height / 2
|
|
38
|
+
};
|
|
39
|
+
const imgCenter = {
|
|
40
|
+
x: (x + width / 2) * zoom,
|
|
41
|
+
y: (y + height / 2) * zoom
|
|
42
|
+
};
|
|
43
|
+
const currentPos = {
|
|
44
|
+
x: viewCenter.x - imgCenter.x,
|
|
45
|
+
y: viewCenter.y - imgCenter.y
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
currentPos,
|
|
49
|
+
innerZoom: zoom
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { ImgPosUtils as default };
|