@labelbee/lb-annotation 1.13.0 → 1.14.0-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/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -0
- package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -0
- package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -0
- package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -0
- package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +12 -0
- package/dist/constant/annotation.js +1 -1
- package/dist/constant/tool.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/ViewOperation.js +1 -1
- package/dist/core/toolOperation/basicToolOperation.js +1 -1
- package/dist/core/toolOperation/cuboidOperation.js +1 -0
- package/dist/core/toolOperation/cuboidToggleButtonClass.js +31 -0
- package/dist/types/constant/annotation.d.ts +45 -1
- package/dist/types/constant/tool.d.ts +6 -1
- package/dist/types/core/index.d.ts +1 -2
- package/dist/types/core/pointCloud/annotation.d.ts +11 -1
- package/dist/types/core/pointCloud/index.d.ts +11 -1
- package/dist/types/core/pointCloud/matrix.d.ts +1 -0
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/dist/types/core/scheduler.d.ts +7 -2
- package/dist/types/core/toolOperation/ViewOperation.d.ts +3 -2
- package/dist/types/core/toolOperation/basicToolOperation.d.ts +11 -1
- package/dist/types/core/toolOperation/cuboidOperation.d.ts +155 -0
- package/dist/types/core/toolOperation/cuboidToggleButtonClass.d.ts +38 -0
- package/dist/types/utils/MathUtils.d.ts +1 -1
- package/dist/types/utils/tool/AttributeUtils.d.ts +7 -0
- package/dist/types/utils/tool/AxisUtils.d.ts +50 -1
- package/dist/types/utils/tool/CuboidUtils.d.ts +267 -0
- package/dist/types/utils/tool/DrawUtils.d.ts +12 -0
- package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +4 -2
- package/dist/types/utils/tool/PolygonUtils.d.ts +5 -2
- package/dist/utils/MathUtils.js +2 -2
- package/dist/utils/tool/AttributeUtils.js +1 -1
- package/dist/utils/tool/AxisUtils.js +1 -1
- package/dist/utils/tool/CuboidUtils.js +1 -0
- package/dist/utils/tool/DrawUtils.js +3 -3
- package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -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__node__WorkerClass.js +11 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -0
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -0
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -0
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -0
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -0
- package/es/constant/annotation.js +1 -1
- package/es/constant/tool.js +1 -1
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/pointCloud/segmentation.js +50 -0
- package/es/core/scheduler.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/basicToolOperation.js +1 -1
- package/es/core/toolOperation/cuboidOperation.js +1 -0
- package/es/core/toolOperation/cuboidToggleButtonClass.js +31 -0
- package/es/core/toolOperation/scribbleTool2.js +249 -0
- package/es/utils/MathUtils.js +2 -2
- package/es/utils/tool/AttributeUtils.js +1 -1
- package/es/utils/tool/AxisUtils.js +1 -1
- package/es/utils/tool/CuboidUtils.js +1 -0
- package/es/utils/tool/DrawUtils.js +3 -3
- package/es/utils/tool/EnhanceCommonToolUtils.js +1 -1
- package/package.json +3 -3
|
@@ -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 };
|
package/es/utils/MathUtils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const
|
|
2
|
-
`);let l=0;for(let f=0;f<
|
|
1
|
+
import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=t.split(`
|
|
2
|
+
`);let l=0;for(let f=0;f<c.length;f++){const p=c[f].split("");let g="";for(let y=0;y<p.length;y++){const u=g+p[y],d=i.measureText(u).width;d>o&&y>0?(g=p[y],n+=r,l=o):(g=u,d>l&&(l=d))}f!==c.length-1&&(n+=r)}return{width:l,height:n+a,lineHeight:r,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=h.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,a={x:i.x-n.x,y:i.y-n.y},c=h.add(t,a);return h.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=h.add(n[t],o);const a=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,c=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=a,n[r]=c,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const a=h.getVector(o,n),c=h.len(a),l=a.y/c,f=a.x/c;return{x:c*M.cosAPlusB(l,f,r,i)+o.x,y:c*M.sinAPlusB(l,f,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=m.getPerpendicularFootOfLine(t,e);return m.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,a=Math.acos(n);return r>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?L(A({},r.annotation),{pointList:w.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=new F;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?L(A({},n.annotation),{pointList:w.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,a)=>{const{dropFoot:c}=w.getClosestPoint(n,a,T.Line,1,{isClose:!1});if(c!==n){const l=`${c.x} + ${c.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let a="";a=n.id,r.forEach((c,l)=>{if(c.id===a)return;const f=[...r];f.splice(l,1),c.pointList.forEach(p=>{i(p,f)})})}),{connectionPoints:t}}};let x=m;x.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},x.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},x.calcViewportBoundaries=(e,t=!1,o=R,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let a=e;t&&(a=B(e,o)),a.forEach(({x:u,y:P})=>{i.push(u),n.push(P)});let c=Math.min(...i),l=Math.max(...i),f=Math.min(...n),p=Math.max(...n);const g=l-c,y=p-f;if(g<r){const u=(r-g)/2;c-=u,l+=u}if(y<r){const u=(r-y)/2;f-=u,p+=u}return{top:f,bottom:p,left:c,right:l}},x.getFootOfPerpendicular=(e,t,o,s=!1,r=!1)=>{let i={x:0,y:0};const n=t.x-o.x,a=t.y-o.y;if(Math.abs(n)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=n*n+a*a,i.x=t.x+c*n,i.y=t.y+c*a;const l=m.getLineLength(e,i),f=2,p=Math.min(t.x,o.x),g=Math.max(t.x,o.x),y=Math.min(t.y,o.y),u=Math.max(t.y,o.y),P=!(m.isInRange(e.x,[p,g])||m.isInRange(e.y,[y,u])),d=e.x>g+f||e.x<p-f||e.y>u+f||e.y<y-f;return!r&&(s?P:d)?{footPoint:i,length:Infinity}:{footPoint:i,length:l}};var D=x;export{M as Trigonometric,D as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isNumber as I}from"lodash";import{
|
|
1
|
+
import{isNumber as I}from"lodash";import{ToolStyleUtils as O}from"@labelbee/lb-utils";import{NULL_COLOR as f,COLORS_ARRAY as c,ICON_ARRAY as d,NULL_ICON as E}from"../../constant/style.js";import{ETextType as s}from"../../constant/tool.js";import g from"../../locales/index.js";import{EMessage as p}from"../../locales/constants.js";import h from"../MathUtils.js";import y from"../../assets/attributeIcon/icon_canvasEdit_miss.svg.js";var w=Object.defineProperty,N=Object.defineProperties,P=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,x=(l,t,r)=>t in l?w(l,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[t]=r,b=(l,t)=>{for(var r in t||(t={}))R.call(t,r)&&x(l,r,t[r]);if(v)for(var r of v(t))T.call(t,r)&&x(l,r,t[r]);return l},m=(l,t)=>N(l,P(t));const _="^[0-9]+$",A="^[A-Za-z]+$";class M{static getAttributeIcon(t,r,e=!0){var n;const a=r.findIndex(o=>o.value===t);let i=(n=d[a%d.length])!=null?n:E;e||(i=y),i="";const u=new Image;return u.src=i,u}static checkString(t,r){let e="";switch(t){case s.Order:case s.NumberOnly:e=_;break;case s.EnglishOnly:e=A;break;case s.CustomFormat:e=r;break}return e}static checkTextAttibute(t,r){if(t===void 0||t==="")return!0;try{return new RegExp(r).test(t)}catch(e){return!1}}static getAttributeShowText(t,r=[]){var e,n;try{const a=r.findIndex(i=>i.value===t);return(n=(e=r[a])==null?void 0:e.key)!=null?n:t}catch(a){return t}}static getAttributeIndex(t,r){try{const e=r.findIndex(n=>n.value===t);return e>=8?e%8:e}catch(e){return-1}}static getAttributeColor(t,r){try{const e=this.getAttributeIndex(t,r);return e===-1?f:c[e%c.length]}catch(e){return f}}static getTextAttribute(t,r){try{if(r===s.Order){const e=t.map(a=>parseInt(a.textAttribute,10)).filter(a=>I(a)&&a<Number.MAX_SAFE_INTEGER&&a>=0);return e.sort((a,i)=>a-i),`${(e.pop()||0)+1}`}return""}catch(e){return""}}static textChange(t,r,e){return e.map(n=>n.id===r?m(b({},n),{textAttribute:t}):n)}static getErrorNotice(t,r){switch(t){case s.Order:case s.NumberOnly:return g.getMessagesByLocale(p.TextCheckNumberErrorNotice,r);case s.EnglishOnly:return g.getMessagesByLocale(p.TextCheckEnglishErrorNotice,r);case s.CustomFormat:return g.getMessagesByLocale(p.TextCheckCustomErrorNotice,r);default:return""}}static textAttributeValidate(t,r,e){try{return new RegExp(this.checkString(t,r)).test(e)}catch(n){}}static checkTextAttribute(t,r,e,n){let a=!1;return e.forEach(i=>{(i==null?void 0:i.textAttribute)===void 0||(i==null?void 0:i.textAttribute)===""||(n?i.id===n:!0)&&!this.textAttributeValidate(t,r,i.textAttribute)&&(a=!0)}),!!a}static changeTextAttributeInLog(t,r){return t==null?void 0:t.map(e=>e==null?void 0:e.map(n=>{if((r==null?void 0:r.findIndex(a=>(a==null?void 0:a.id)===(n==null?void 0:n.id)))>-1){const a=r==null?void 0:r.find(i=>(i==null?void 0:i.id)===(n==null?void 0:n.id));return m(b({},n),{textAttribute:a==null?void 0:a.textAttribute})}return n}))}static getTextIconSvg(t="",r,e=!1,n){var a;if(e===!0){const i=(r==null?void 0:r.findIndex(o=>(o==null?void 0:o.value)===t))%c.length+1,u=(a=r==null?void 0:r.find(o=>o.value===t))==null?void 0:a.color;if(u){const o=O.rgbaStringToHex(u);return this.generateIconAttribute({fill:o})}return d[i]}return n}static generateIconAttribute({fill:t,width:r=16,height:e=16,xmlns:n="http://www.w3.org/2000/svg",xlink:a="http://www.w3.org/1999/xlink"}){return`<span style={color:${t}}><svg xmlns=${n} xmlns:xlink=${a} width=${r} height=${e} viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill='currentColor'/></g></g></svg></span>`}static getAttributeByKeycode(t,r){var e;let n;return h.isInRange(t,[48,57])&&(n=t-48),h.isInRange(t,[96,105])&&(n=t-96),n===0?"":n?(e=r[n-1])==null?void 0:e.value:void 0}}export{A as REGEXP_ENGLISH,_ as REGEXP_NUMBER,M as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EToolName as
|
|
1
|
+
import{EToolName as u,ELineTypes as C}from"../../constant/tool.js";import y from"../MathUtils.js";import x from"./PolygonUtils.js";import _,{POINT_RADIUS as v}from"./LineToolUtils.js";import{getHighlightPoints as P,getHighlightLines as m,getCuboidHoverRange as L}from"./CuboidUtils.js";var B=Object.defineProperty,R=Object.defineProperties,D=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,w=(a,t,e)=>t in a?B(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))T.call(t,e)&&w(a,e,t[e]);if(O)for(var e of O(t))Z.call(t,e)&&w(a,e,t[e]);return a},c=(a,t)=>R(a,D(t));class I{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:r}=t;switch(e%360){case 90:return{x:n-r,y:o};case 180:return{x:s-o,y:n-r};case 270:return{x:r,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static changePlanePointByZoom(t,e,i={x:0,y:0}){return Object.entries(t).reduce((s,[n,o])=>{const r=I.changePointByZoom(o,e,i);return c(f({},s),{[n]:r})},{})}static changeCuboidByZoom(t,e,i={x:0,y:0}){return c(f({},t),{frontPoints:this.changePlanePointByZoom(t.frontPoints,e,i),backPoints:t.backPoints?this.changePlanePointByZoom(t.backPoints,e,i):t.backPoints})}static transformPlain2PointList({tl:t,tr:e,br:i,bl:s}){return[t,e,i,s]}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let r=s-e;r<s+e;r+=e/3)n.push({x:o,y:r});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static isCloseCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5}=i;for(let r=0;r<s.length;r++){const l=s[r];if(this.getIsInScope(t,l.point,n))return!0}const o=m(e);for(let r=0;r<o.length;r++){const l=o[r],{length:p}=y.getFootOfPerpendicular(t,l.p1,l.p2,!0);if(p<n)return!0}return!!x.isInPolygon(t,L(e))}static isCloseCuboidList(t,e,i={scope:5,zoom:1}){return e.some(s=>this.isCloseCuboid(t,s,i))}static returnClosePointOrLineInCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5,zoom:o=1}=i;for(let h=0;h<s.length;h++){const g=s[h];if(this.getIsInScope(t,g.point,n))return[{type:"point",points:[this.changePointByZoom(s[h].point,o)],originCuboid:e,positions:g.positions}]}let r=n;const l=m(e);let p;for(let h=0;h<l.length;h++){const g=l[h],{length:d}=y.getFootOfPerpendicular(t,g.p1,g.p2,!0);d<r&&(r=d,p=[{type:"line",points:this.changePointListByZoom([g.p1,g.p2],o),originCuboid:e,positions:g.positions}])}if(p)return p}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class b{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===u.Polygon}get isDependRect(){return this.dependToolName===u.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:y.withinRange(t.x,[i,i+n]),y:y.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===C.Curve?x.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return _.calcOptimalIntersection(i,o,s,v,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const r=this.getPolygonPointList(o,n);if(x.isInPolygon(t,r))return t;const p=r.concat(r[0]).map(g=>this.getRenderCoord(g)),h=this.getIntersection(t,e,p);return h?this.getAbsCoord(h==null?void 0:h.point):t}coordInsideImage(t){return this.coordInsideRect(t,c(f({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],r=[i,i+n];return y.isInRange(t.x,o)&&y.isInRange(t.y,r)}return y.isInRange(t.x,[0,this.basicImgInfo.width])&&y.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return x.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}export{b as CoordinateUtils,I as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cloneDeep as E}from"lodash";import{ECuboidPlain as a,ECuboidPosition as f,ECuboidDirection as w,EDragTarget as C,DIAGONAL_POINT as U,ECuboidLineDirection as O,CUBOID_ROW as X,CUBOID_COLUMN as Y}from"../../constant/annotation.js";import v from"./AxisUtils.js";import G from"../VectorUtils.js";import F from"./LineToolUtils.js";var V=Object.defineProperty,z=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,I=(n,t,i)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[t]=i,x=(n,t)=>{for(var i in t||(t={}))q.call(t,i)&&I(n,i,t[i]);if(D)for(var i of D(t))J.call(t,i)&&I(n,i,t[i]);return n},d=(n,t)=>z(n,Q(t));function m({tr:n,tl:t,br:i}){return{width:Math.abs(n.x-t.x),height:Math.abs(i.y-n.y),centerPoints:{x:(t.x+i.x)/2,y:(t.y+i.y)/2}}}function g({frontPoints:n,backPoints:t}){const{width:i,height:e,centerPoints:s}=m(n),{width:o,height:r,centerPoints:l}=m(t);return{frontCenter:s,backCenter:l,frontWidth:i,frontHeight:e,backWidth:o,backHeight:r,isLeftSide:l.x<s.x}}function S(n,t){return{tl:{x:Math.min(n.x,t.x),y:Math.min(n.y,t.y)},tr:{x:Math.max(n.x,t.x),y:Math.min(n.y,t.y)},bl:{x:Math.min(n.x,t.x),y:Math.max(n.y,t.y)},br:{x:Math.max(n.x,t.x),y:Math.max(n.y,t.y)}}}function _(n){const t=Object.values(n).reduce((o,r)=>r.x<o?r.x:o,Number.MAX_SAFE_INTEGER),i=Object.values(n).reduce((o,r)=>r.x>o?r.x:o,0),e=Object.values(n).reduce((o,r)=>r.y<o?r.y:o,Number.MAX_SAFE_INTEGER),s=Object.values(n).reduce((o,r)=>r.y>o?r.y:o,0);return{tl:{x:t,y:e},tr:{x:i,y:e},bl:{x:t,y:s},br:{x:i,y:s}}}function N(n){const[t,i]=n;if(X[t.position]===i.position)return O.Row;if(Y[t.position]===i.position)return O.Column}function M({coord:n,points:t}){const{width:i,height:e}=m(t);return{br:n,tr:{x:n.x,y:n.y-e},tl:{x:n.x-i,y:n.y-e},bl:{x:n.x-i,y:n.y}}}function j({coord:n,points:t}){const{width:i,height:e}=m(t);return{bl:n,tr:{x:n.x+i,y:n.y-e},tl:{x:n.x,y:n.y-e},br:{x:n.x+i,y:n.y}}}function H({frontPoints:n,backPoints:t}){const{isLeftSide:i}=g({frontPoints:n,backPoints:t});return i?{top:{p1:n.tl,p2:t.tl},bottom:{p1:n.bl,p2:t.bl}}:{top:{p1:n.tr,p2:t.tr},bottom:{p1:n.br,p2:t.br}}}function k({frontPoints:n,backPoints:t}){const{isLeftSide:i}=g({frontPoints:n,backPoints:t});let e=x({},t);const s=H({frontPoints:n,backPoints:t}),o=F.lineIntersection({pointA:s.bottom.p1,pointB:s.bottom.p2},{pointA:s.top.p1,pointB:s.top.p2});if(i){const r=F.lineIntersection({pointA:t.bl,pointB:t.br},{pointA:n.br,pointB:o});r&&(e=d(x({},t),{br:r,tr:{x:r.x,y:t.tl.y}}))}else{const r=F.lineIntersection({pointA:t.bl,pointB:t.br},{pointA:n.bl,pointB:o});r&&(e=d(x({},t),{bl:r,tl:{x:r.x,y:t.tr.y}}))}return{backPoints:e}}function R({frontPoints:n,backPoints:t}){const{isLeftSide:i,frontHeight:e,backHeight:s}=g({frontPoints:n,backPoints:t});let o=x({},t);return i?o=j({coord:t.bl,points:n}):o=M({coord:t.br,points:n}),e>s&&(o=k({frontPoints:n,backPoints:t}).backPoints),{frontPoints:n,backPoints:o}}function T({frontPoints:n,backPoints:t}){const{isLeftSide:i,frontHeight:e,backHeight:s,frontWidth:o,backWidth:r}=g({frontPoints:n,backPoints:t});let l=x({},n),p=t;return i||r>o?l=j({coord:n.bl,points:t}):l=M({coord:n.br,points:t}),e>s&&(l.tl.y=n.tl.y,l.tr.y=n.tr.y,p=k({backPoints:t,frontPoints:n}).backPoints),o>=r&&Object.keys(l).forEach(c=>{l[c].x=n[c].x}),{frontPoints:l,backPoints:p}}function K({frontPoints:n,backPoints:t}){return[{p1:n.bl,p2:t.bl},{p1:n.tl,p2:t.tl},{p1:n.tr,p2:t.tr},{p1:n.br,p2:t.br}]}function Z(n){const{frontPoints:t,backPoints:i}=n,{isLeftSide:e}=g(n),s=[{p1:t.tl,p2:t.tr,positions:[{plain:a.Front,position:f.TL},{plain:a.Front,position:f.TR}]},{p1:t.tr,p2:t.br,plain:a.Front,positions:[{plain:a.Front,position:f.TR},{plain:a.Front,position:f.BR}]},{p1:t.br,p2:t.bl,plain:a.Front,positions:[{plain:a.Front,position:f.BR},{plain:a.Front,position:f.BL}]},{p1:t.bl,p2:t.tl,plain:a.Front,positions:[{plain:a.Front,position:f.BL},{plain:a.Front,position:f.TL}]}];return e?[...s,{p1:i.tl,p2:i.bl,positions:[{plain:a.Back,position:f.TL},{plain:a.Back,position:f.BL}]}]:[...s,{p1:i.tr,p2:i.br,positions:[{plain:a.Back,position:f.TR},{plain:a.Back,position:f.BR}]}]}function $(n){const{backPoints:t}=n,{isLeftSide:i}=g(n),e=Object.entries(n.frontPoints).map(([s,o])=>({positions:[{plain:a.Front,position:s}],point:o}));return i?[{point:t.tl,positions:[{position:f.TL,plain:a.Back}]},{point:t.bl,positions:[{position:f.BL,plain:a.Back}]},...e]:[{point:t.tr,positions:[{position:f.TR,plain:a.Back}]},{point:t.br,positions:[{position:f.BR,plain:a.Back}]},...e]}function tt(n){const{frontPoints:t,backPoints:i}=n,{backCenter:e,frontCenter:s,frontHeight:o,frontWidth:r,backHeight:l,backWidth:p,isLeftSide:c}=g(n),u=Math.abs(r-p),y=Math.abs(o-l),P=Math.abs(s.x-e.x),B=Math.abs(s.y-e.y),h=P>u,b=B>y;return h||b?b&&!h?[t.tl,i.tl,i.tr,t.tr,t.br,t.bl]:h&&!b?c?[t.tl,t.tr,t.br,t.bl,i.bl,i.tl]:[t.tl,t.tr,i.tr,i.br,t.br,t.bl]:h&&b?c?[i.tl,i.tr,t.tr,t.br,t.bl,i.bl]:[t.tl,i.tl,i.tr,i.br,t.br,t.bl]:[]:[t.tl,t.tr,t.br,t.bl]}function W({offset:n,frontPoints:t,backPoints:i,positions:e}){let s=E(t),o=E(i);if((e==null?void 0:e.length)===2){const r=e.every(b=>b.plain===a.Front),l=!r,p=N([e[0],e[1]]),c=p===O.Row,u=p===O.Column;let y=n;c&&(y={x:0,y:n.y}),u&&(y={y:0,x:n.x}),r&&(e==null||e.forEach(({position:b})=>{const L=s,A=L[b];L[b]={x:A.x+y.x,y:A.y+y.y}}),s=_(s),o=_(o)),l&&Object.keys(o).forEach(b=>{o[b]={x:o[b].x+y.x,y:o[b].y+y.y}});const P=r?R:T,{frontPoints:B,backPoints:h}=P({frontPoints:s,backPoints:o});s=B,o=h}return{frontPoints:s,backPoints:o}}function nt({offset:n,cuboid:t,dragTarget:i,positions:e}){const{frontPoints:s,backPoints:o}=t;switch(i){case C.Cuboid:{const r=Object.entries(s).reduce((p,[c,u])=>d(x({},p),{[c]:{x:u.x+n.x,y:u.y+n.y}}),{}),l=Object.entries(o).reduce((p,[c,u])=>d(x({},p),{[c]:{x:u.x+n.x,y:u.y+n.y}}),{});return d(x({},t),{frontPoints:r,backPoints:l})}case C.Line:{const{frontPoints:r,backPoints:l}=W({offset:n,frontPoints:s,backPoints:o,positions:e});return d(x({},t),{frontPoints:r,backPoints:l})}case C.Point:{if(!(e==null?void 0:e[0]))return;const r=e[0],l=r.plain===a.Front,p=l?s:o;let c=p[r.position];const u=p[U[r.position]];if(!c||!u)return;c=G.add(c,n);const y=S(c,u),P=l?R:T;let B={frontPoints:s,backPoints:y};l&&(B={frontPoints:y,backPoints:o});const{frontPoints:h,backPoints:b}=P(B);return d(x({},t),{frontPoints:h,backPoints:b})}default:{console.error("No DragTarget");break}}}function it({direction:n,frontPoints:t,backPoints:i}){if(n&&t&&i){let e=t;switch(n){case w.Back:e=i;break;case w.Left:e={bl:i.bl,br:t.bl,tl:i.tl,tr:t.tl};break;case w.Right:e={bl:i.br,br:t.br,tl:i.tr,tr:t.tr};break;case w.Top:e={bl:i.tl,br:t.tl,tl:i.tr,tr:t.tr};break;default:e=t;break}return v.transformPlain2PointList(e)}}function et({cuboid:n,currentPos:t,zoom:i}){const{frontPoints:e}=n,s={width:40,height:74},o={x:(e.bl.x+e.tl.x)/2,y:(e.bl.y+e.tl.y)/2},r=s.width+10,l=s.height/2,p={x:o.x,y:o.y},c=v.getOffsetCoordinate(p,t,i);return{left:c.x-r,top:c.y-l}}function ot({cuboid:n,currentPos:t,zoom:i,leftOffset:e=16,topOffset:s=2}){const{frontPoints:o}=n,r={x:o.bl.x,y:o.bl.y},l=v.getOffsetCoordinate(r,t,i);return{left:l.x+e,top:l.y+s}}function rt({cuboid:n,config:t}){const{minHeight:i,minWidth:e}=t,{width:s,height:o}=m(n.frontPoints);return s>=e&&o>=i}export{R as getBackPointsByFrontPoints,K as getCuboidAllSideLine,g as getCuboidBasicInfo,nt as getCuboidDragMove,tt as getCuboidHoverRange,H as getCuboidShowingSideLine,ot as getCuboidTextAttributeOffset,T as getFrontPointsByBackPoints,Z as getHighlightLines,$ as getHighlightPoints,_ as getMaxExternalQuadrilateral,W as getNewPointsAfterOffset,S as getPlainPointsByDiagonalPoints,m as getPlanePointsBasicInfo,it as getPointListsByDirection,j as getPointsByBottomLeftPoint,M as getPointsByBottomRightPoint,k as getPointsByIntersection,et as getToggleDirectionButtonOffset,rt as isCuboidWithInLimits,N as judgeCuboidLineIsRowOrColumn};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ELineTypes as
|
|
2
|
-
`,""))!=null?
|
|
3
|
-
`);for(let a=0;a<c.length;a++){const
|
|
1
|
+
import{ELineTypes as u,SEGMENT_NUMBER as m,DEFAULT_FONT as E}from"../../constant/tool.js";import p from"./PolygonUtils.js";import C from"./UnitUtils.js";import S from"./AxisUtils.js";import{getCuboidAllSideLine as D,getPointListsByDirection as O}from"./CuboidUtils.js";var F=Object.defineProperty,W=Object.defineProperties,U=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,_=(r,t,i)=>t in r?F(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,T=(r,t)=>{for(var i in t||(t={}))M.call(t,i)&&_(r,i,t[i]);if(v)for(var i of v(t))I.call(t,i)&&_(r,i,t[i]);return r},b=(r,t)=>W(r,U(t));const R=1,L={x:0,y:0},$=0,g="",P=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=g,thickness:s=1,lineCap:c="round",lineDash:a}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=c,a&&o.setLineDash(a),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=g,thickness:l=1,lineCap:s="round",hiddenText:c=!1,lineDash:a}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(a)&&e.setLineDash(a),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),c===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const d=`${~~t.width} * ${~~t.height}`.length*7,y=0,w=Math.max(20,t.width-d);this.drawText(r,{x:t.x,y:t.y+t.height+20+y},t.textAttribute,{textMaxWidth:w})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=g}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,c)=>`${s}${c.keyName}: ${c.value.join(" \u3001 ")}
|
|
2
|
+
`,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=g,thickness:l=1,lineCap:s="round",lineType:c=u.Line,lineDash:a,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(a)?e.setLineDash(a):e.setLineDash([])})(),c===u.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=p.createSmoothCurvePointsFromPointList([...t],m),n!==void 0&&n>-1&&(t=t.slice((m+1)*n,(m+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const d=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&d.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),d.forEach(h=>{const x=t[h.i1],A=t[h.i2];e.beginPath(),e.moveTo(x.x,x.y),e.lineTo(A.x,A.y),e.stroke()}),e.restore();const y=4,w=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,y+w,o),this.drawSpecialPoint(r,h,y,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:c=1,color:a=g,fill:n=g}=e,f=C.deg2rad(l),d=C.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=a,o.fillStyle=n,o.lineWidth=c,o.arc(t.x,t.y,i,f,d,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=g}=e;o.save();const s=C.deg2rad(0),c=C.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,c,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const c=i*1.5,a=c*Math.sqrt(3)/2,n=c/2;o.moveTo(l,s-c),o.lineTo(l-a,s+n),o.lineTo(l+a,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=u.Line}=i;return e===!0&&(t=[...t,t[0]]),o===u.Curve&&(t=p.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,b(T({},i),{lineType:u.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=g,lineType:l=u.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===u.Curve&&(t=p.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...c]=t;return e.moveTo(s.x,s.y),c.forEach(a=>{e.lineTo(a.x,a.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:c,lineType:a}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:c,lineType:a});return this.drawPolygonWithFill(r,t,{color:o,lineType:a}),n}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=g,font:s=E,shadowColor:c="",shadowBlur:a=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:d=164,offsetX:y=0,offsetY:w=0,textAlign:h="start",lineHeight:x}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=c,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=a,this.wrapText(r,`${i}`,t.x+y,t.y+w,d,x),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=t.split(`
|
|
3
|
+
`);for(let a=0;a<c.length;a++){const n=c[a].split("");let f="";for(let d=0;d<n.length;d++){const y=f+n[d],h=s.measureText(y).width;o||(o=300),h>o&&d>0?(s.fillText(f,i,e),f=n[d],e+=l):f=y}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=g,thickness:l=1,lineCap:s="round",theta:c=30,headLen:a=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+c)*Math.PI/180,d=(n-c)*Math.PI/180,y=a*Math.cos(f),w=a*Math.sin(f),h=a*Math.cos(d),x=a*Math.sin(d);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+y,i.y+w),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+x),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:c,fillColor:a}=i,n={color:s,thickness:c};if(e){const d=S.transformPlain2PointList(e);P.drawPolygon(r,d,b(T({},n),{isClose:!0}));const y=D(t);y==null||y.forEach(w=>{P.drawLine(r,w.p1,w.p2,T({},n))})}const f=S.transformPlain2PointList(l);if(o&&e&&l){const d=O({direction:o,frontPoints:l,backPoints:e});d&&P.drawPolygonWithFill(r,d,{color:a})}P.drawPolygon(r,f,b(T({},n),{isClose:!0}))}};let k=P;k.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=R,currentPos:l=L,rotate:s=$,imgAttribute:c}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(c){const{contrast:a,saturation:n,brightness:f}=c;e.filter=`saturate(${n+100}%) contrast(${a+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{k as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EToolName as o,ECheckModel as n}from"../../constant/tool.js";import i from"../../core/toolOperation/ScribbleTool.js";import a from"../../core/toolOperation/
|
|
1
|
+
import{EToolName as o,ECheckModel as n}from"../../constant/tool.js";import i from"../../core/toolOperation/ScribbleTool.js";import a from"../../core/toolOperation/cuboidOperation.js";import p from"../../core/toolOperation/pointCloud2dOperation.js";import c from"../../core/toolOperation/checkOperation.js";import l from"../../core/toolOperation/polygonOperation.js";import{RectOperation as m}from"../../core/toolOperation/rectOperation.js";import s from"../../core/toolOperation/tagOperation.js";import O from"../../core/toolOperation/LineToolOperation.js";import u from"../../core/toolOperation/pointOperation.js";import T from"../../core/toolOperation/TextToolOperation.js";import f from"../../core/toolOperation/segmentByRect.js";import j from"./CommonToolUtils.js";const e=t=>{switch(t){case o.Rect:case o.RectTrack:return m;case o.SegmentByRect:return f;case o.Tag:return s;case o.Polygon:return l;case n.Check:return c;case o.Line:return O;case o.Point:return u;case o.Text:return T;case o.ScribbleTool:return i;case o.Cuboid:return a;case o.PointCloudPolygon:return p;default:throw new Error("not match tool")}};class r extends j{}r.getCurrentOperation=e;export{r as default,e as getCurrentOperation};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0-alpha.0",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -92,11 +92,11 @@
|
|
|
92
92
|
"typescript": "^4.2.3"
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@labelbee/lb-utils": "^1.
|
|
95
|
+
"@labelbee/lb-utils": "^1.7.0-alpha.0",
|
|
96
96
|
"@turf/turf": "5.1.6",
|
|
97
97
|
"color-rgba": "^2.3.0",
|
|
98
98
|
"lodash": "^4.17.20",
|
|
99
99
|
"three": ">=0.141.0"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "86c10122b654945d5bcb0d6208551d4996a276f1"
|
|
102
102
|
}
|