@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
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { ImgConversionUtils } from '@labelbee/lb-utils';
|
|
2
|
+
import AxisUtils from '../../utils/tool/AxisUtils.js';
|
|
3
|
+
import DrawUtils from '../../utils/tool/DrawUtils.js';
|
|
4
|
+
import { EToolName, EScribblePattern } from '../../constant/tool.js';
|
|
5
|
+
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
6
|
+
import AttributeUtils from '../../utils/tool/AttributeUtils.js';
|
|
7
|
+
import { BasicToolOperation } from './basicToolOperation.js';
|
|
8
|
+
|
|
9
|
+
const DEFAULT_PEN_SIZE = 20;
|
|
10
|
+
const DEFAULT_COLOR = "white";
|
|
11
|
+
class ScribbleTool extends BasicToolOperation {
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(props);
|
|
14
|
+
this.toolName = EToolName.ScribbleTool;
|
|
15
|
+
this.action = EScribblePattern.Scribble;
|
|
16
|
+
this.getOriginCoordinate = (e) => {
|
|
17
|
+
return AxisUtils.changePointByZoom(this.getCoordinateUnderZoom(e), 1 / this.zoom);
|
|
18
|
+
};
|
|
19
|
+
this.onMouseDown = (e) => {
|
|
20
|
+
if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
this.initCacheCanvas(this.imgNode);
|
|
24
|
+
this.mouseEvents("onMouseDown").call(this, e);
|
|
25
|
+
};
|
|
26
|
+
this.onMouseMove = (e) => {
|
|
27
|
+
if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
this.mouseEvents("onMouseMove").call(this, e);
|
|
31
|
+
};
|
|
32
|
+
this.onMouseUp = (e) => {
|
|
33
|
+
if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
this.mouseEvents("onMouseUp").call(this, e);
|
|
37
|
+
};
|
|
38
|
+
this.mouseEvents = (eventType) => {
|
|
39
|
+
const events = {
|
|
40
|
+
[EScribblePattern.Scribble]: {
|
|
41
|
+
onMouseMove: this.onScribbleMove,
|
|
42
|
+
onMouseUp: this.onScribbleEnd,
|
|
43
|
+
onMouseDown: this.onScribbleStart
|
|
44
|
+
},
|
|
45
|
+
[EScribblePattern.Erase]: {
|
|
46
|
+
onMouseMove: this.onEraseMove,
|
|
47
|
+
onMouseUp: this.onEraseEnd,
|
|
48
|
+
onMouseDown: this.onEraseStart
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return events[this.action][eventType];
|
|
52
|
+
};
|
|
53
|
+
this.setPattern = (pattern) => {
|
|
54
|
+
this.action = pattern;
|
|
55
|
+
};
|
|
56
|
+
this.penSize = DEFAULT_PEN_SIZE;
|
|
57
|
+
}
|
|
58
|
+
get color() {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
return (_b = (_a = this == null ? void 0 : this.defaultAttributeInfo) == null ? void 0 : _a.color) != null ? _b : DEFAULT_COLOR;
|
|
61
|
+
}
|
|
62
|
+
get penSizeWithZoom() {
|
|
63
|
+
return this.penSize / this.zoom;
|
|
64
|
+
}
|
|
65
|
+
setPenSize(size) {
|
|
66
|
+
this.penSize = size;
|
|
67
|
+
}
|
|
68
|
+
initCacheCanvas(imgNode) {
|
|
69
|
+
if (this.cacheCanvas || !imgNode) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const {canvas, ctx} = ImgConversionUtils.createCanvas(imgNode);
|
|
73
|
+
this.cacheCanvas = canvas;
|
|
74
|
+
this.cacheContext = ctx;
|
|
75
|
+
}
|
|
76
|
+
updateCacheCanvasSize(imgNode) {
|
|
77
|
+
if (this.cacheCanvas) {
|
|
78
|
+
this.cacheCanvas.width = imgNode.width;
|
|
79
|
+
this.cacheCanvas.height = imgNode.height;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
updateUrl2CacheContext(url) {
|
|
83
|
+
ImgConversionUtils.createImgDom(url).then((img) => {
|
|
84
|
+
if (!this.cacheContext) {
|
|
85
|
+
this.initCacheCanvas(img);
|
|
86
|
+
}
|
|
87
|
+
if (this.cacheContext) {
|
|
88
|
+
this.cacheContext.save();
|
|
89
|
+
this.clearResult();
|
|
90
|
+
this.cacheContext.drawImage(img, 0, 0, img.width, img.height);
|
|
91
|
+
this.cacheContext.restore();
|
|
92
|
+
this.render();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
setImgNode(imgNode, basicImgInfo) {
|
|
97
|
+
super.setImgNode(imgNode, basicImgInfo);
|
|
98
|
+
if (this.cacheCanvas) {
|
|
99
|
+
this.updateCacheCanvasSize(imgNode);
|
|
100
|
+
} else {
|
|
101
|
+
this.initCacheCanvas(imgNode);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
setResult(data) {
|
|
105
|
+
var _a;
|
|
106
|
+
const {url} = (_a = data == null ? void 0 : data[0]) != null ? _a : {};
|
|
107
|
+
this.history.initRecord([url], !!url);
|
|
108
|
+
this.clearResult();
|
|
109
|
+
if (!url) {
|
|
110
|
+
this.render();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.updateUrl2CacheContext(url);
|
|
114
|
+
}
|
|
115
|
+
onKeyDown(e) {
|
|
116
|
+
if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const {keyCode} = e;
|
|
120
|
+
const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
|
|
121
|
+
if (keyCode2Attribute !== void 0) {
|
|
122
|
+
this.setDefaultAttribute(keyCode2Attribute);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
eventBinding() {
|
|
126
|
+
super.eventBinding();
|
|
127
|
+
}
|
|
128
|
+
setDefaultAttribute(attributeValue) {
|
|
129
|
+
const attributeInfo = this.config.attributeList.find((v) => v.value === attributeValue);
|
|
130
|
+
if (attributeInfo) {
|
|
131
|
+
this.defaultAttribute = attributeInfo.value;
|
|
132
|
+
this.defaultAttributeInfo = attributeInfo;
|
|
133
|
+
this.emit("changeAttributeSidebar");
|
|
134
|
+
this.render();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
clearStatusAfterLeave() {
|
|
138
|
+
this.onScribbleEnd();
|
|
139
|
+
this.startPoint = void 0;
|
|
140
|
+
}
|
|
141
|
+
onMouseLeave() {
|
|
142
|
+
super.onMouseLeave();
|
|
143
|
+
this.clearStatusAfterLeave();
|
|
144
|
+
}
|
|
145
|
+
onScribbleStart(e) {
|
|
146
|
+
if (!this.cacheContext) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.cacheContext.save();
|
|
150
|
+
this.cacheContext.beginPath();
|
|
151
|
+
this.cacheContext.strokeStyle = this.color;
|
|
152
|
+
this.cacheContext.lineWidth = this.penSizeWithZoom;
|
|
153
|
+
this.cacheContext.lineCap = "round";
|
|
154
|
+
this.cacheContext.lineJoin = "round";
|
|
155
|
+
const originCoordinate = AxisUtils.changePointByZoom(this.getCoordinateUnderZoom(e), 1 / this.zoom);
|
|
156
|
+
this.cacheContext.moveTo(originCoordinate.x, originCoordinate.y);
|
|
157
|
+
this.startPoint = originCoordinate;
|
|
158
|
+
}
|
|
159
|
+
onScribbleMove(e) {
|
|
160
|
+
if (e.buttons === 1 && this.cacheContext && this.startPoint) {
|
|
161
|
+
const originCoordinate = this.getOriginCoordinate(e);
|
|
162
|
+
this.cacheContext.lineTo(originCoordinate.x, originCoordinate.y);
|
|
163
|
+
this.cacheContext.stroke();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
onScribbleEnd() {
|
|
167
|
+
var _a, _b, _c;
|
|
168
|
+
if (this.startPoint) {
|
|
169
|
+
(_a = this.cacheContext) == null ? void 0 : _a.closePath();
|
|
170
|
+
(_b = this.cacheContext) == null ? void 0 : _b.restore();
|
|
171
|
+
this.startPoint = void 0;
|
|
172
|
+
this.history.pushHistory((_c = this.cacheCanvas) == null ? void 0 : _c.toDataURL("image/png", 0));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
eraseArc(e) {
|
|
176
|
+
var _a;
|
|
177
|
+
if (this.cacheContext) {
|
|
178
|
+
const originCoordinate = this.getOriginCoordinate(e);
|
|
179
|
+
this.cacheContext.save();
|
|
180
|
+
this.cacheContext.beginPath();
|
|
181
|
+
this.cacheContext.arc(originCoordinate.x, originCoordinate.y, this.penSizeWithZoom / 2, 0, Math.PI * 2, false);
|
|
182
|
+
this.cacheContext.clip();
|
|
183
|
+
this.cacheContext.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
|
|
184
|
+
(_a = this.cacheContext) == null ? void 0 : _a.restore();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
onEraseStart(e) {
|
|
188
|
+
if (!this.cacheContext || e.buttons !== 1) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
this.eraseArc(e);
|
|
192
|
+
}
|
|
193
|
+
onEraseMove(e) {
|
|
194
|
+
if (!this.cacheContext || e.buttons !== 1) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.eraseArc(e);
|
|
198
|
+
}
|
|
199
|
+
onEraseEnd() {
|
|
200
|
+
}
|
|
201
|
+
exportData() {
|
|
202
|
+
var _a;
|
|
203
|
+
const imgBase64 = (_a = this.cacheCanvas) == null ? void 0 : _a.toDataURL("image/png", 0);
|
|
204
|
+
return [[], this.basicImgInfo, {imgBase64}];
|
|
205
|
+
}
|
|
206
|
+
clearCacheCanvas() {
|
|
207
|
+
var _a;
|
|
208
|
+
(_a = this.cacheContext) == null ? void 0 : _a.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
|
|
209
|
+
this.render();
|
|
210
|
+
}
|
|
211
|
+
clearResult() {
|
|
212
|
+
this.clearCacheCanvas();
|
|
213
|
+
}
|
|
214
|
+
renderPoint(radius) {
|
|
215
|
+
DrawUtils.drawCircleWithFill(this.canvas, this.coord, radius, {color: this.color});
|
|
216
|
+
}
|
|
217
|
+
render() {
|
|
218
|
+
super.render();
|
|
219
|
+
if (!this.ctx || !this.cacheCanvas) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.ctx.save();
|
|
223
|
+
this.ctx.globalAlpha = 0.5;
|
|
224
|
+
DrawUtils.drawImg(this.canvas, this.cacheCanvas, {
|
|
225
|
+
zoom: this.zoom,
|
|
226
|
+
currentPos: this.currentPos,
|
|
227
|
+
rotate: this.rotate
|
|
228
|
+
});
|
|
229
|
+
this.ctx.restore();
|
|
230
|
+
if (this.forbidOperation || this.forbidCursorLine) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
this.renderPoint(this.penSize / 2);
|
|
234
|
+
}
|
|
235
|
+
undo() {
|
|
236
|
+
const url = this.history.undo();
|
|
237
|
+
if (url && this.cacheCanvas) {
|
|
238
|
+
this.updateUrl2CacheContext(url);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
redo() {
|
|
242
|
+
const url = this.history.redo();
|
|
243
|
+
if (url && this.cacheCanvas) {
|
|
244
|
+
this.updateUrl2CacheContext(url);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { ScribbleTool as default };
|
|
@@ -1 +1,172 @@
|
|
|
1
|
-
import{i18n
|
|
1
|
+
import { i18n } from '@labelbee/lb-utils';
|
|
2
|
+
import AxisUtils from '../../utils/tool/AxisUtils.js';
|
|
3
|
+
import { RectOperation } from './rectOperation.js';
|
|
4
|
+
import EKeyCode from '../../constant/keyCode.js';
|
|
5
|
+
|
|
6
|
+
var __async = (__this, __arguments, generator) => {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
var fulfilled = (value) => {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var rejected = (value) => {
|
|
16
|
+
try {
|
|
17
|
+
step(generator.throw(value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
23
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
class SegmentByRect extends RectOperation {
|
|
27
|
+
constructor(props) {
|
|
28
|
+
super(props);
|
|
29
|
+
this.onKeydown = (e) => {
|
|
30
|
+
switch (e.keyCode) {
|
|
31
|
+
case EKeyCode.Esc:
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
e.stopPropagation();
|
|
34
|
+
this.clearPredictionInfo();
|
|
35
|
+
break;
|
|
36
|
+
case EKeyCode.Z:
|
|
37
|
+
if (e.ctrlKey) {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
e.stopPropagation();
|
|
40
|
+
this.rectList = [];
|
|
41
|
+
this.render();
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
this.segmentPrediction = (e) => __async(this, null, function* () {
|
|
47
|
+
const coord = this.getCoordinateUnderZoom(e);
|
|
48
|
+
this.isRunSegment = true;
|
|
49
|
+
this.render();
|
|
50
|
+
if (!this.runPrediction) {
|
|
51
|
+
this.emit("messageError", "You needs to set runPrediction function");
|
|
52
|
+
this.clearPredictionInfo();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
yield this.runPrediction({
|
|
56
|
+
point: coord,
|
|
57
|
+
rect: {
|
|
58
|
+
x: this.rectList[0].x,
|
|
59
|
+
y: this.rectList[0].y,
|
|
60
|
+
w: this.rectList[0].width,
|
|
61
|
+
h: this.rectList[0].height
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
this.clearPredictionInfo();
|
|
65
|
+
});
|
|
66
|
+
this.isRunSegment = false;
|
|
67
|
+
this.runPrediction = props.runPrediction;
|
|
68
|
+
}
|
|
69
|
+
setRunPrediction(runPrediction) {
|
|
70
|
+
this.runPrediction = runPrediction;
|
|
71
|
+
}
|
|
72
|
+
eventBinding() {
|
|
73
|
+
document.addEventListener("keydown", (e) => this.onKeydown(e));
|
|
74
|
+
super.eventBinding();
|
|
75
|
+
}
|
|
76
|
+
clearPredictionInfo() {
|
|
77
|
+
this.rectList = [];
|
|
78
|
+
this.isShowCursor = false;
|
|
79
|
+
this.coord = {x: -1, y: -1};
|
|
80
|
+
this.drawingRect = void 0;
|
|
81
|
+
this.isRunSegment = false;
|
|
82
|
+
this.clearCanvas();
|
|
83
|
+
this.render();
|
|
84
|
+
}
|
|
85
|
+
onMouseUp(e) {
|
|
86
|
+
if (this.isRunSegment) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (e.button === 0 && this.rectList.length === 1 && !this.isRunSegment) {
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
this.segmentPrediction(e);
|
|
92
|
+
this.clearActiveStatus();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
super.onMouseUp(e);
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
onMouseDown(e) {
|
|
99
|
+
if (this.isRunSegment) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
super.onMouseDown(e);
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
renderCursorLine() {
|
|
106
|
+
var _a;
|
|
107
|
+
if (!this.ctx) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const {ctx} = this;
|
|
111
|
+
const padding = 10;
|
|
112
|
+
const lineWidth = 1;
|
|
113
|
+
const {x, y} = this.coord;
|
|
114
|
+
ctx.save();
|
|
115
|
+
ctx.strokeStyle = "white";
|
|
116
|
+
ctx.setLineDash([6]);
|
|
117
|
+
ctx.lineWidth = lineWidth;
|
|
118
|
+
ctx.strokeRect(x - padding, y - padding, padding * 2, padding * 2);
|
|
119
|
+
ctx.restore();
|
|
120
|
+
let text = `\u2460 ${i18n.t("FramingOfObjectToBeDivided")}`;
|
|
121
|
+
const isEn = i18n.language === "en";
|
|
122
|
+
let rectWidth = isEn ? 326 : 186;
|
|
123
|
+
if (((_a = this.rectList) == null ? void 0 : _a.length) === 1) {
|
|
124
|
+
text = `\u2461 ${i18n.t("ClickOnTarget")}`;
|
|
125
|
+
rectWidth = isEn ? 232 : 142;
|
|
126
|
+
const radius = 2;
|
|
127
|
+
ctx.save();
|
|
128
|
+
ctx.strokeStyle = "white";
|
|
129
|
+
const margin = lineWidth + padding;
|
|
130
|
+
ctx.beginPath();
|
|
131
|
+
ctx.moveTo(x + margin + radius * 2, y + margin + radius);
|
|
132
|
+
ctx.arc(x + margin + radius, y + margin + radius, radius, 0, Math.PI * 2, true);
|
|
133
|
+
ctx.stroke();
|
|
134
|
+
ctx.restore();
|
|
135
|
+
}
|
|
136
|
+
if (this.isRunSegment) {
|
|
137
|
+
rectWidth = isEn ? 316 : 136;
|
|
138
|
+
text = i18n.t("SplittingAlgorithmPrediction");
|
|
139
|
+
}
|
|
140
|
+
ctx.save();
|
|
141
|
+
ctx.fillStyle = this.style.strokeColor;
|
|
142
|
+
ctx.fillRect(x + padding, y - padding * 4 - 1, rectWidth, 32);
|
|
143
|
+
ctx.restore();
|
|
144
|
+
ctx.save();
|
|
145
|
+
ctx.font = "14px Source Han Sans CN";
|
|
146
|
+
ctx.fillStyle = "white";
|
|
147
|
+
ctx.fillText(text, x + padding + 14, y - padding * 2);
|
|
148
|
+
ctx.restore();
|
|
149
|
+
super.renderCursorLine();
|
|
150
|
+
}
|
|
151
|
+
renderDrawingRect(rect, zoom, isZoom = false) {
|
|
152
|
+
if (this.ctx && rect) {
|
|
153
|
+
const transformRect = AxisUtils.changeRectByZoom(rect, isZoom ? zoom : this.zoom, this.currentPos);
|
|
154
|
+
const {x, y, width, height} = transformRect;
|
|
155
|
+
this.ctx.save();
|
|
156
|
+
this.ctx.lineCap = "butt";
|
|
157
|
+
this.ctx.lineWidth = this.style.strokeWidth;
|
|
158
|
+
this.ctx.strokeStyle = "white";
|
|
159
|
+
this.ctx.strokeRect(x, y, width, height);
|
|
160
|
+
this.ctx.strokeStyle = this.style.strokeColor;
|
|
161
|
+
this.ctx.setLineDash([6]);
|
|
162
|
+
this.ctx.strokeRect(x, y, width, height);
|
|
163
|
+
this.ctx.restore();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
renderTextAttribute() {
|
|
167
|
+
}
|
|
168
|
+
renderSelectedRect() {
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { SegmentByRect as default };
|
|
@@ -1,5 +1,184 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
2
|
+
import TagUtil from '../../utils/tool/TagUtils.js';
|
|
3
|
+
import uuid from '../../utils/uuid.js';
|
|
4
|
+
import { BasicToolOperation } from './basicToolOperation.js';
|
|
5
|
+
|
|
6
|
+
class TagOperation extends BasicToolOperation {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.getInitResultList = (dataSourceStep, basicResultList) => {
|
|
10
|
+
if (!(dataSourceStep === 0 || dataSourceStep === void 0) && basicResultList.length === 0) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
return TagUtil.getDefaultTagResult(this.config.inputList, basicResultList);
|
|
14
|
+
};
|
|
15
|
+
this.setLabel = (i, j) => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
if (this.isImgError) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!this.basicResult && this.dependToolName) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const labelInfoSet = this.config.inputList;
|
|
24
|
+
if (!labelInfoSet[i]) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const {subSelected} = labelInfoSet[i];
|
|
28
|
+
if (i < labelInfoSet.length && labelInfoSet[i].subSelected && subSelected && j < subSelected.length) {
|
|
29
|
+
const key = labelInfoSet[i].value;
|
|
30
|
+
let value = (_a = subSelected[j]) == null ? void 0 : _a.value;
|
|
31
|
+
const isMulti = (_b = labelInfoSet[i]) == null ? void 0 : _b.isMulti;
|
|
32
|
+
const basicTagResult = this.tagResult.filter((v) => {
|
|
33
|
+
const basicSourceID = `${v.sourceID}`;
|
|
34
|
+
return CommonToolUtils.isSameSourceID(basicSourceID, this.sourceID);
|
|
35
|
+
})[0];
|
|
36
|
+
if (basicTagResult) {
|
|
37
|
+
let times = 0;
|
|
38
|
+
const {result} = basicTagResult;
|
|
39
|
+
if (basicTagResult.sourceID === 0) {
|
|
40
|
+
basicTagResult.sourceID = "0";
|
|
41
|
+
}
|
|
42
|
+
for (const oldKey in basicTagResult.result) {
|
|
43
|
+
if (oldKey === labelInfoSet[i].value) {
|
|
44
|
+
times++;
|
|
45
|
+
if (isMulti === true) {
|
|
46
|
+
const keyList = result[oldKey].split(";").filter((v) => v !== "");
|
|
47
|
+
const index = keyList.indexOf(value);
|
|
48
|
+
if (index === -1) {
|
|
49
|
+
keyList.push(value);
|
|
50
|
+
} else {
|
|
51
|
+
keyList.splice(index, 1);
|
|
52
|
+
}
|
|
53
|
+
value = keyList.join(";");
|
|
54
|
+
}
|
|
55
|
+
if (value === "") {
|
|
56
|
+
if (Object.keys(result).length === 1) {
|
|
57
|
+
this.tagResult = this.tagResult.filter((v) => {
|
|
58
|
+
const basicSourceID = `${v.sourceID}`;
|
|
59
|
+
return CommonToolUtils.isDifferSourceID(basicSourceID, this.sourceID);
|
|
60
|
+
});
|
|
61
|
+
} else if (Object.keys(result).length > 1) {
|
|
62
|
+
delete result[oldKey];
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
result[oldKey] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (times === 0) {
|
|
70
|
+
Object.assign(basicTagResult.result, {[key]: value});
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
this.tagResult = [
|
|
74
|
+
{
|
|
75
|
+
sourceID: this.sourceID,
|
|
76
|
+
id: uuid(8, 62),
|
|
77
|
+
result: {
|
|
78
|
+
[key]: value
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
this.render();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
this.clearResult = (sendMessage = true, value) => {
|
|
87
|
+
if (value) {
|
|
88
|
+
this.tagResult = this.tagResult.map((v) => {
|
|
89
|
+
if (v == null ? void 0 : v.result[value]) {
|
|
90
|
+
delete v.result[value];
|
|
91
|
+
}
|
|
92
|
+
return v;
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
this.tagResult = [];
|
|
96
|
+
}
|
|
97
|
+
this.render();
|
|
98
|
+
};
|
|
99
|
+
this.config = CommonToolUtils.jsonParser(props.config);
|
|
100
|
+
this.tagResult = [];
|
|
101
|
+
this.labelSelectedList = [];
|
|
102
|
+
this.setShowDefaultCursor(true);
|
|
103
|
+
}
|
|
104
|
+
destroy() {
|
|
105
|
+
this.clearTag();
|
|
106
|
+
super.destroy();
|
|
107
|
+
}
|
|
108
|
+
setResult(tagResult) {
|
|
109
|
+
this.tagResult = tagResult;
|
|
110
|
+
this.render();
|
|
111
|
+
}
|
|
112
|
+
get currentPageResult() {
|
|
113
|
+
return [this.currentTagResult];
|
|
114
|
+
}
|
|
115
|
+
get currentTagResult() {
|
|
116
|
+
var _a;
|
|
117
|
+
return (_a = this.tagResult.filter((v) => {
|
|
118
|
+
const basicSourceID = `${v.sourceID}`;
|
|
119
|
+
return CommonToolUtils.isSameSourceID(basicSourceID, this.sourceID);
|
|
120
|
+
})[0]) != null ? _a : {};
|
|
121
|
+
}
|
|
122
|
+
get sourceID() {
|
|
123
|
+
return CommonToolUtils.getSourceID(this.basicResult);
|
|
124
|
+
}
|
|
125
|
+
onKeyDown(e) {
|
|
126
|
+
if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
let {keyCode} = e;
|
|
130
|
+
if (keyCode) {
|
|
131
|
+
if (keyCode <= 57 && keyCode >= 49 || keyCode <= 105 && keyCode >= 97) {
|
|
132
|
+
if (keyCode > 57) {
|
|
133
|
+
keyCode -= 97;
|
|
134
|
+
} else {
|
|
135
|
+
keyCode -= 49;
|
|
136
|
+
}
|
|
137
|
+
if (this.config.inputList.length === 1) {
|
|
138
|
+
this.labelSelectedList = [0, keyCode];
|
|
139
|
+
this.setLabel(0, keyCode);
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
this.labelSelectedList = [];
|
|
142
|
+
this.render();
|
|
143
|
+
}, 500);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (this.labelSelectedList.length === 1) {
|
|
147
|
+
this.labelSelectedList = [this.labelSelectedList[0], keyCode];
|
|
148
|
+
this.setLabel(this.labelSelectedList[0], keyCode);
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
this.labelSelectedList = [];
|
|
151
|
+
this.render();
|
|
152
|
+
}, 500);
|
|
153
|
+
} else {
|
|
154
|
+
this.labelSelectedList = [keyCode];
|
|
155
|
+
this.emit("expend");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
clearTag() {
|
|
161
|
+
var _a;
|
|
162
|
+
const parentNode = (_a = this.canvas) == null ? void 0 : _a.parentNode;
|
|
163
|
+
const oldDom = window.self.document.getElementById("tagToolTag");
|
|
164
|
+
if (oldDom && parentNode && parentNode.contains(oldDom)) {
|
|
165
|
+
parentNode == null ? void 0 : parentNode.removeChild(oldDom);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
renderTag() {
|
|
169
|
+
var _a, _b, _c, _d, _e, _f;
|
|
170
|
+
this.clearTag();
|
|
171
|
+
if (!(((_a = this.tagResult) == null ? void 0 : _a.length) > 0)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const dom = document.createElement("div");
|
|
175
|
+
const tagInfoList = TagUtil.getTagNameList((_c = (_b = this.currentTagResult) == null ? void 0 : _b.result) != null ? _c : {}, this.config.inputList);
|
|
176
|
+
dom.innerHTML = (_d = tagInfoList.reduce((acc, cur) => {
|
|
177
|
+
return `${acc}${cur.keyName}: ${cur.value.join(` \u3001 `)}
|
|
178
|
+
`;
|
|
179
|
+
}, "")) != null ? _d : "";
|
|
180
|
+
dom.setAttribute("id", "tagToolTag");
|
|
181
|
+
dom.setAttribute("style", `
|
|
3
182
|
position: absolute;
|
|
4
183
|
top: 0;
|
|
5
184
|
right: 0;
|
|
@@ -16,4 +195,21 @@ import c from"../../utils/tool/CommonToolUtils.js";import m from"../../utils/too
|
|
|
16
195
|
background: rgba(102, 111, 255, 1);
|
|
17
196
|
opacity: 0.6;
|
|
18
197
|
clear: both;
|
|
19
|
-
`)
|
|
198
|
+
`);
|
|
199
|
+
(_f = (_e = this.canvas) == null ? void 0 : _e.parentNode) == null ? void 0 : _f.appendChild(dom);
|
|
200
|
+
}
|
|
201
|
+
render() {
|
|
202
|
+
this.renderTag();
|
|
203
|
+
super.render();
|
|
204
|
+
this.emit("render");
|
|
205
|
+
}
|
|
206
|
+
exportData() {
|
|
207
|
+
let {tagResult} = this;
|
|
208
|
+
if (this.isImgError) {
|
|
209
|
+
tagResult = [];
|
|
210
|
+
}
|
|
211
|
+
return [tagResult, this.basicImgInfo];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export { TagOperation as default };
|