@labelbee/lb-annotation 1.14.0-alpha.0 → 1.14.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.
- package/dist/constant/defaultConfig.js +1 -1
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/pointCloud/index.js +2 -2
- package/dist/core/scheduler.js +1 -1
- package/dist/core/toolOperation/LineToolOperation.js +1 -1
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/dist/core/toolOperation/cuboidOperation.js +1 -1
- package/dist/core/toolOperation/pointOperation.js +1 -1
- package/dist/index.js +1 -1
- package/dist/types/core/pointCloud/annotation.d.ts +8 -3
- package/dist/types/core/pointCloud/index.d.ts +34 -4
- package/dist/types/core/pointCloud/matrix.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +12 -1
- package/dist/types/core/toolOperation/LineToolOperation.d.ts +11 -0
- package/dist/types/core/toolOperation/cuboidOperation.d.ts +21 -2
- package/dist/types/core/toolOperation/pointOperation.d.ts +6 -1
- package/dist/types/core/toolOperation/textAttributeClass.d.ts +9 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/utils/tool/CuboidUtils.d.ts +1 -1
- package/dist/types/utils/tool/DrawUtils.d.ts +19 -1
- package/dist/utils/tool/AxisUtils.js +1 -1
- package/dist/utils/tool/CuboidUtils.js +1 -1
- package/dist/utils/tool/DrawUtils.js +3 -3
- package/es/constant/defaultConfig.js +1 -1
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/scheduler.js +1 -1
- package/es/core/toolOperation/LineToolOperation.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/cuboidOperation.js +1 -1
- package/es/core/toolOperation/pointOperation.js +1 -1
- package/es/index.js +1 -1
- package/es/utils/tool/AttributeUtils.js +1 -1
- package/es/utils/tool/AxisUtils.js +1 -1
- package/es/utils/tool/CuboidUtils.js +1 -1
- package/es/utils/tool/DrawUtils.js +3 -3
- package/package.json +3 -3
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
- package/es/core/pointCloud/segmentation.js +0 -50
- package/es/core/toolOperation/scribbleTool2.js +0 -249
|
@@ -1,249 +0,0 @@
|
|
|
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 };
|