@labelbee/lb-annotation 1.13.1-alpha.0 → 1.13.1

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.
@@ -0,0 +1,131 @@
1
+ import * as THREE from 'three';
2
+ import { colorArr, toolStyleConverter } from '@labelbee/lb-utils';
3
+ import DrawUtils from '../../../utils/tool/DrawUtils.js';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ class PointCloudRender {
25
+ constructor({store, on, unbind, nextTick, config}) {
26
+ this.clearStash = () => {
27
+ var _a, _b;
28
+ const pointsGeo = this.scene.getObjectByName((_b = (_a = this.store.cacheSegData) == null ? void 0 : _a.id) != null ? _b : "");
29
+ if (pointsGeo) {
30
+ pointsGeo.removeFromParent();
31
+ this.render3d();
32
+ }
33
+ };
34
+ this.generateNewPoints = (segmentData) => {
35
+ const geometry = new THREE.BufferGeometry();
36
+ geometry.setAttribute("position", new THREE.BufferAttribute(segmentData.points, 3));
37
+ const pointsMaterial = new THREE.PointsMaterial({color: this.getCurrentColor(segmentData.attribute), size: 10});
38
+ const newPoints = new THREE.Points(geometry, pointsMaterial);
39
+ newPoints.name = segmentData.id;
40
+ this.store.scene.add(newPoints);
41
+ this.render3d();
42
+ };
43
+ this.updateNewPoints = (segmentData) => {
44
+ var _a;
45
+ const originPoints = this.store.scene.getObjectByName((_a = segmentData == null ? void 0 : segmentData.id) != null ? _a : "");
46
+ if (originPoints && segmentData) {
47
+ originPoints.geometry.setAttribute("position", new THREE.Float32BufferAttribute(segmentData.points, 3));
48
+ originPoints.material = new THREE.PointsMaterial({
49
+ color: this.getCurrentColor(segmentData.attribute),
50
+ size: 10
51
+ });
52
+ originPoints.geometry.attributes.position.needsUpdate = true;
53
+ this.render3d();
54
+ }
55
+ };
56
+ this.updatePointsColor = (segmentData = this.store.cacheSegData) => {
57
+ var _a;
58
+ const originPoints = this.store.scene.getObjectByName((_a = segmentData == null ? void 0 : segmentData.id) != null ? _a : "");
59
+ if (originPoints && segmentData) {
60
+ segmentData.attribute = this.store.currentAttribute;
61
+ originPoints.material = new THREE.PointsMaterial({
62
+ color: this.getCurrentColor(segmentData.attribute),
63
+ size: 10
64
+ });
65
+ this.render3d();
66
+ }
67
+ };
68
+ this.render3d = () => {
69
+ this.store.renderer.render(this.store.scene, this.store.camera);
70
+ };
71
+ this.store = store;
72
+ this.on = on;
73
+ this.unbind = unbind;
74
+ this.nextTick = nextTick;
75
+ this.config = config;
76
+ this.initMsg();
77
+ this.animate();
78
+ this.generateNewPoints = this.generateNewPoints.bind(this);
79
+ this.clearStash = this.clearStash.bind(this);
80
+ this.render3d = this.render3d.bind(this);
81
+ this.updateNewPoints = this.updateNewPoints.bind(this);
82
+ this.updatePointsColor = this.updatePointsColor.bind(this);
83
+ }
84
+ get scene() {
85
+ return this.store.scene;
86
+ }
87
+ getCurrentColor(attribute = this.store.currentAttribute) {
88
+ if (!attribute || !this.config) {
89
+ return colorArr[0].hexString;
90
+ }
91
+ const {fill} = toolStyleConverter.getColorFromConfig({attribute}, __spreadProps(__spreadValues({}, this.config), {attributeConfigurable: true}), {});
92
+ return fill;
93
+ }
94
+ initMsg() {
95
+ this.on("addNewPointsCloud", this.generateNewPoints);
96
+ this.on("updateNewPoints", this.updateNewPoints);
97
+ this.on("clearStashRender", this.clearStash);
98
+ this.on("reRender3d", this.render3d);
99
+ }
100
+ unbindMsg() {
101
+ this.unbind("addNewPointsCloud", this.generateNewPoints);
102
+ this.unbind("updateNewPoints", this.updateNewPoints);
103
+ this.unbind("clearStashRender", this.clearStash);
104
+ this.unbind("reRender3d", this.render3d);
105
+ }
106
+ get canvas2d() {
107
+ return this.store.canvas2d;
108
+ }
109
+ clearCanvasMouse() {
110
+ var _a, _b;
111
+ (_b = (_a = this.canvas2d) == null ? void 0 : _a.getContext("2d")) == null ? void 0 : _b.clearRect(0, 0, this.store.containerWidth, this.store.containerHeight);
112
+ }
113
+ renderCanvas2dPolygon() {
114
+ var _a;
115
+ if (((_a = this.store.polygon2d) == null ? void 0 : _a.length) > 0 && this.canvas2d) {
116
+ DrawUtils.drawPolygon(this.canvas2d, this.store.polygon2d, {
117
+ isClose: false,
118
+ color: this.getCurrentColor(),
119
+ thickness: 4
120
+ });
121
+ }
122
+ }
123
+ animate() {
124
+ requestAnimationFrame(this.animate.bind(this));
125
+ this.clearCanvasMouse();
126
+ this.renderCanvas2dPolygon();
127
+ this.nextTick();
128
+ }
129
+ }
130
+
131
+ export { PointCloudRender as default };
@@ -1,30 +1,73 @@
1
- import * as THREE from 'three';
1
+ import { EPointCloudSegmentStatus } from '@labelbee/lb-utils';
2
+ import LassoSelector from './selector/lassoSelector.js';
3
+ import CircleSelector from './selector/circleSelector.js';
2
4
 
3
5
  class PointCloudSegmentOperation {
4
6
  constructor(props) {
5
- this.pointer = new THREE.Vector2();
6
- this.onMouseMove = (e) => {
7
- const coord = this.getCoordinate(e);
8
- this.pointer.x = coord.x / this.dom.clientWidth * 2 - 1;
9
- this.pointer.y = -(coord.y / this.dom.clientHeight) * 2 + 1;
10
- this.emitRender();
7
+ this.onMouseMove = (iev) => {
8
+ if (this.store.isCheckStatus || this.store.isReadyStatus) {
9
+ this.store.updateMouse({x: iev.offsetX, y: iev.offsetY});
10
+ }
11
+ if (this.isForbid) {
12
+ return;
13
+ }
14
+ const ev = {
15
+ offsetX: iev.offsetX,
16
+ offsetY: iev.offsetY,
17
+ button: iev.buttons
18
+ };
19
+ this.currentTool.mouseMove(ev);
20
+ };
21
+ this.onMouseDown = (iev) => {
22
+ if (this.isForbid) {
23
+ return;
24
+ }
25
+ this.currentTool.mouseDown(iev);
26
+ };
27
+ this.onMouseUp = (iev) => {
28
+ if (this.isForbid || this.store.orbiting === true) {
29
+ return;
30
+ }
31
+ if (this.baseMouseDown(iev)) {
32
+ return;
33
+ }
34
+ this.currentTool.mouseUp(iev);
35
+ };
36
+ this.baseMouseDown = (e) => {
37
+ switch (e.button) {
38
+ case 0:
39
+ if (this.store.isReadyStatus || this.store.isCheckStatus) {
40
+ this.store.checkPoints();
41
+ return true;
42
+ }
43
+ break;
44
+ }
45
+ };
46
+ this._raycasting = () => {
47
+ if ([EPointCloudSegmentStatus.Ready, EPointCloudSegmentStatus.Check].includes(this.store.segmentStatus)) {
48
+ const {mouse, camera, raycaster} = this.store;
49
+ raycaster.setFromCamera(mouse, camera);
50
+ const intersects = raycaster.intersectObjects(this.store.allSegmentPoints, false);
51
+ const intersect = intersects[0];
52
+ if (intersect) {
53
+ this.store.highlightPoints(intersect.object);
54
+ } else {
55
+ this.store.resetAllSegDataSizeAndRender();
56
+ this.store.resetHoverPointsID();
57
+ }
58
+ }
11
59
  };
12
60
  this.dom = props.dom;
13
- this.raycaster = new THREE.Raycaster();
14
- this.dom.addEventListener("pointermove", this.onMouseMove);
15
- const geometry = new THREE.BufferGeometry();
16
- const pointsMaterial = new THREE.PointsMaterial({size: 10, color: "red"});
17
- geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array([0, 0, 0]), 3));
18
- this._highlight_Point = new THREE.Points(geometry, pointsMaterial);
19
- this.emitRender = props.render;
20
- const geometry2 = new THREE.BufferGeometry();
21
- const pointsMaterial2 = new THREE.PointsMaterial({size: 5, color: "white"});
22
- geometry2.setAttribute("position", new THREE.BufferAttribute(new Float32Array([0, 0, 0]), 3));
23
- this._temp = new THREE.Points(geometry2, pointsMaterial2);
24
- }
25
- addMorePoint(scene) {
26
- scene.add(this._highlight_Point);
27
- scene.add(this._temp);
61
+ this.store = props.store;
62
+ this.lassoSelector = new LassoSelector(this.store);
63
+ this.circleSelector = new CircleSelector(this.store);
64
+ this.currentTool = this.circleSelector;
65
+ this.currentToolName = "CircleSelector";
66
+ this.dom.addEventListener("pointermove", this.onMouseMove.bind(this));
67
+ this.dom.addEventListener("pointerdown", this.onMouseDown.bind(this));
68
+ this.dom.addEventListener("pointerup", this.onMouseUp.bind(this));
69
+ this.updateSelector2Lasso = this.updateSelector2Lasso.bind(this);
70
+ this.updateSelector2Circle = this.updateSelector2Circle.bind(this);
28
71
  }
29
72
  getCoordinate(e) {
30
73
  const bounding = this.dom.getBoundingClientRect();
@@ -33,17 +76,19 @@ class PointCloudSegmentOperation {
33
76
  y: e.clientY - bounding.top
34
77
  };
35
78
  }
36
- render({camera, scene}) {
37
- this.raycaster.setFromCamera(this.pointer, camera);
38
- const intersects = this.raycaster.intersectObjects(scene.children, false);
39
- console.log("intersects", intersects[0]);
40
- const default_Point = new THREE.Vector3(0, 0, 0);
41
- if (intersects.length > 0) {
42
- const intersect = intersects[0];
43
- this._highlight_Point.position.copy(intersect.point);
44
- } else {
45
- this._highlight_Point.position.copy(default_Point);
46
- }
79
+ get forbidOperation() {
80
+ return this.store.forbidOperation;
81
+ }
82
+ get isForbid() {
83
+ return this.forbidOperation;
84
+ }
85
+ updateSelector2Lasso() {
86
+ this.currentTool = this.lassoSelector;
87
+ this.currentToolName = "LassoSelector";
88
+ }
89
+ updateSelector2Circle() {
90
+ this.currentTool = this.circleSelector;
91
+ this.currentToolName = "CircleSelector";
47
92
  }
48
93
  }
49
94
 
@@ -0,0 +1,23 @@
1
+ import Sse3dSelector from './Sse3dSelector.js';
2
+
3
+ class Sse3dLassoSelector extends Sse3dSelector {
4
+ mouseDown(ev) {
5
+ if (ev.which === 3) {
6
+ this.pushPoint(ev.offsetX, ev.offsetY);
7
+ }
8
+ }
9
+ mouseUp(ev) {
10
+ if (ev.which === 3) {
11
+ this.scene.store.getPointsInPolygon(this.polygon);
12
+ this.polygon = [];
13
+ this.scene.store.syncPolygon2d([]);
14
+ }
15
+ }
16
+ mouseDrag(ev) {
17
+ if (ev.which === 3) {
18
+ this.pushPoint(ev.offsetX, ev.offsetY);
19
+ }
20
+ }
21
+ }
22
+
23
+ export { Sse3dLassoSelector as default };
@@ -0,0 +1,15 @@
1
+ class Sse3dSelector {
2
+ constructor(scene) {
3
+ this.scene = scene;
4
+ this.polygon = [];
5
+ }
6
+ pushPoint(x, y) {
7
+ this.polygon.push([x, y]);
8
+ this.scene.store.syncPolygon2d(this.polygon);
9
+ }
10
+ deactivate() {
11
+ this.polygon = [];
12
+ }
13
+ }
14
+
15
+ export { Sse3dSelector as default };
@@ -0,0 +1,39 @@
1
+ import DefaultSelector from './selector.js';
2
+
3
+ class CircleSelector extends DefaultSelector {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.radius = 20;
7
+ }
8
+ mouseDown(ev) {
9
+ if (ev.button === 2) {
10
+ this.pushPoint(ev.offsetX, ev.offsetY);
11
+ this.startX = ev.offsetX;
12
+ this.startY = ev.offsetY;
13
+ }
14
+ }
15
+ mouseUp(ev) {
16
+ if (ev.button === 2) {
17
+ this.store.getPointsInPolygon(this.polygon2d);
18
+ this.polygon2d.length = 0;
19
+ this.startX = this.startY = NaN;
20
+ }
21
+ }
22
+ mouseMove(ev) {
23
+ if (ev.button === 2 && this.startX && this.startY) {
24
+ this.polygon2d.length = 0;
25
+ const precision = 64;
26
+ const PI2 = Math.PI * 2;
27
+ const ox = this.startX;
28
+ const oy = this.startY;
29
+ const nx = ev.offsetX;
30
+ const ny = ev.offsetY;
31
+ const r = Math.sqrt((nx - ox) * (nx - ox) + (ny - oy) * (ny - oy));
32
+ for (let a = 0; a < PI2; a += PI2 / precision) {
33
+ this.pushPoint(ox + r * Math.cos(a), oy - r * Math.sin(a));
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ export { CircleSelector as default };
@@ -0,0 +1,22 @@
1
+ import DefaultSelector from './selector.js';
2
+
3
+ class LassoSelector extends DefaultSelector {
4
+ mouseDown(ev) {
5
+ if (ev.button === 2) {
6
+ this.pushPoint(ev.offsetX, ev.offsetY);
7
+ }
8
+ }
9
+ mouseUp(ev) {
10
+ if (ev.button === 2) {
11
+ this.store.getPointsInPolygon(this.polygon2d);
12
+ this.updatePolygon2d([]);
13
+ }
14
+ }
15
+ mouseMove(ev) {
16
+ if (ev.button === 2) {
17
+ this.pushPoint(ev.offsetX, ev.offsetY);
18
+ }
19
+ }
20
+ }
21
+
22
+ export { LassoSelector as default };
@@ -0,0 +1,16 @@
1
+ class DefaultSelector {
2
+ constructor(store) {
3
+ this.store = store;
4
+ this.polygon2d = [];
5
+ }
6
+ pushPoint(x, y) {
7
+ this.polygon2d.push({x, y});
8
+ this.store.syncPolygon2d(this.polygon2d);
9
+ }
10
+ updatePolygon2d(polygon2d) {
11
+ this.polygon2d = polygon2d;
12
+ this.store.syncPolygon2d(this.polygon2d);
13
+ }
14
+ }
15
+
16
+ export { DefaultSelector as default };
@@ -0,0 +1,41 @@
1
+ import { EPointCloudSegmentStatus } from '@labelbee/lb-utils';
2
+
3
+ class PointCloudFSM {
4
+ constructor() {
5
+ this.segmentStatus = EPointCloudSegmentStatus.Ready;
6
+ }
7
+ statusToggle() {
8
+ switch (this.segmentStatus) {
9
+ case EPointCloudSegmentStatus.Ready:
10
+ this.segmentStatus = EPointCloudSegmentStatus.Check;
11
+ break;
12
+ case EPointCloudSegmentStatus.Check:
13
+ this.segmentStatus = EPointCloudSegmentStatus.Edit;
14
+ break;
15
+ case EPointCloudSegmentStatus.Edit:
16
+ this.segmentStatus = EPointCloudSegmentStatus.Ready;
17
+ break;
18
+ default: {
19
+ console.error("Error Status in PointCloudSegmentFSM");
20
+ }
21
+ }
22
+ }
23
+ updateStatus2Edit() {
24
+ this.segmentStatus = EPointCloudSegmentStatus.Edit;
25
+ }
26
+ updateStatus2Check() {
27
+ this.segmentStatus = EPointCloudSegmentStatus.Check;
28
+ }
29
+ get isReadyStatus() {
30
+ return this.segmentStatus === EPointCloudSegmentStatus.Ready;
31
+ }
32
+ get isCheckStatus() {
33
+ return this.segmentStatus === EPointCloudSegmentStatus.Check;
34
+ }
35
+ get isEditStatus() {
36
+ return this.segmentStatus === EPointCloudSegmentStatus.Edit;
37
+ }
38
+ }
39
+ const instance = new PointCloudFSM();
40
+
41
+ export { instance as default };
@@ -0,0 +1,376 @@
1
+ import * as THREE from 'three';
2
+ import { EPointCloudSegmentMode, EPointCloudSegmentCoverMode, PointCloudUtils } from '@labelbee/lb-utils';
3
+ import { isInPolygon } from '../../../utils/tool/polygonTool.js';
4
+ import uuid from '../../../utils/uuid.js';
5
+ import instance from './fsm.js';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __defProps = Object.defineProperties;
9
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ const DEFAULT_PREFIX = "LABELBEE_CANVAS_";
27
+ class PointCloudStore {
28
+ constructor({container, scene, camera, renderer, emit, on, unbind}) {
29
+ this.canvas2d = null;
30
+ this.polygon2d = [];
31
+ this.forbidOperation = false;
32
+ this.raycaster = new THREE.Raycaster();
33
+ this.mouse = new THREE.Vector2();
34
+ this.cloudData = new Map();
35
+ this.segmentData = new Map();
36
+ this.hoverPointsID = "";
37
+ this.segmentMode = EPointCloudSegmentMode.Add;
38
+ this.segmentCoverMode = EPointCloudSegmentCoverMode.Cover;
39
+ this.updatePointCloud = false;
40
+ this.addPointCloud = false;
41
+ this.orbiting = false;
42
+ this.currentAttribute = "";
43
+ this.pointCloudObjectName = "pointCloud";
44
+ this.updateCoverPoints = (coverPoints = new Float32Array([])) => {
45
+ this.segmentData.forEach((seg, id) => {
46
+ var _a;
47
+ if (id !== ((_a = this.cacheSegData) == null ? void 0 : _a.id)) {
48
+ const newPoints = this.splitPointsFromPoints(seg.points, coverPoints);
49
+ seg.points = newPoints;
50
+ const originPoints = this.scene.getObjectByName(id);
51
+ if (originPoints) {
52
+ originPoints.geometry.setAttribute("position", new THREE.Float32BufferAttribute(newPoints, 3));
53
+ originPoints.geometry.attributes.position.needsUpdate = true;
54
+ }
55
+ }
56
+ });
57
+ this.emit("reRender3d");
58
+ };
59
+ this.container = container;
60
+ this.scene = scene;
61
+ this.camera = camera;
62
+ this.renderer = renderer;
63
+ this.emit = emit;
64
+ this.on = on;
65
+ this.unbind = unbind;
66
+ this.createCanvas2d();
67
+ this.clearStash = this.clearStash.bind(this);
68
+ this.addStash2Store = this.addStash2Store.bind(this);
69
+ this.updateCheck2Edit = this.updateCheck2Edit.bind(this);
70
+ this.setAttribute = this.setAttribute.bind(this);
71
+ this.setSegmentMode = this.setSegmentMode.bind(this);
72
+ this.setSegmentCoverMode = this.setSegmentCoverMode.bind(this);
73
+ this.initMsg();
74
+ this.setupRaycaster();
75
+ }
76
+ initMsg() {
77
+ this.on("clearStash", this.clearStash);
78
+ this.on("addStash2Store", this.addStash2Store);
79
+ this.on("updateCheck2Edit", this.updateCheck2Edit);
80
+ this.on("setSegmentMode", this.setSegmentMode);
81
+ this.on("setSegmentCoverMode", this.setSegmentCoverMode);
82
+ }
83
+ unbindMsg() {
84
+ this.unbind("clearStash", this.clearStash);
85
+ this.unbind("addStash2Store", this.addStash2Store);
86
+ this.unbind("updateCheck2Edit", this.updateCheck2Edit);
87
+ this.unbind("setSegmentMode", this.setSegmentMode);
88
+ this.unbind("setSegmentCoverMode", this.setSegmentCoverMode);
89
+ }
90
+ get containerWidth() {
91
+ return this.container.clientWidth;
92
+ }
93
+ get containerHeight() {
94
+ return this.container.clientHeight;
95
+ }
96
+ get allSegmentPoints() {
97
+ return this.scene.children.filter((v) => v.type === "Points" && v.name !== this.pointCloudObjectName);
98
+ }
99
+ get segmentStatus() {
100
+ return instance.segmentStatus;
101
+ }
102
+ get isReadyStatus() {
103
+ return instance.isReadyStatus;
104
+ }
105
+ get isCheckStatus() {
106
+ return instance.isCheckStatus;
107
+ }
108
+ get isEditStatus() {
109
+ return instance.isEditStatus;
110
+ }
111
+ statusToggle() {
112
+ instance.statusToggle();
113
+ }
114
+ updateStatus2Edit() {
115
+ instance.updateStatus2Edit();
116
+ }
117
+ createCanvas(id) {
118
+ const canvas = document.createElement("canvas");
119
+ canvas.id = id;
120
+ this.updateCanvasBasicStyle(canvas, {width: this.containerWidth, height: this.containerHeight}, 10);
121
+ return canvas;
122
+ }
123
+ createCanvas2d() {
124
+ this.canvas2d = this.createCanvas(`${DEFAULT_PREFIX}2d`);
125
+ this.container.appendChild(this.canvas2d);
126
+ }
127
+ setupRaycaster() {
128
+ this.raycaster.params = {
129
+ Mesh: {},
130
+ Line: {threshold: 1},
131
+ LOD: {},
132
+ Points: {threshold: 0.2},
133
+ Sprite: {}
134
+ };
135
+ }
136
+ setHoverPointsID(id) {
137
+ this.hoverPointsID = id;
138
+ }
139
+ setSegmentMode(mode) {
140
+ this.segmentMode = mode;
141
+ }
142
+ setSegmentCoverMode(coverMode) {
143
+ this.segmentCoverMode = coverMode;
144
+ }
145
+ updateCanvasBasicStyle(canvas, size, zIndex) {
146
+ const pixel = 1;
147
+ canvas.style.position = "absolute";
148
+ canvas.width = size.width * pixel;
149
+ canvas.height = size.height * pixel;
150
+ canvas.style.width = `${size.width}px`;
151
+ canvas.style.height = `${size.height}px`;
152
+ canvas.style.left = "0";
153
+ canvas.style.top = "0";
154
+ canvas.style.zIndex = `${zIndex} `;
155
+ }
156
+ syncPolygon2d(polygon2d) {
157
+ this.polygon2d = polygon2d;
158
+ }
159
+ getPointsInPolygon(originPolygon) {
160
+ var _a, _b, _c;
161
+ const polygon = originPolygon;
162
+ const originPoints = this.scene.getObjectByName(this.pointCloudObjectName);
163
+ const cloudDataArrayLike = (_c = (_b = (_a = originPoints == null ? void 0 : originPoints.geometry) == null ? void 0 : _a.attributes) == null ? void 0 : _b.position) == null ? void 0 : _c.array;
164
+ if (cloudDataArrayLike) {
165
+ const len = cloudDataArrayLike.length;
166
+ const vertices = [];
167
+ const covers = [];
168
+ for (let i = 0; i < len; i += 3) {
169
+ const vector3d = new THREE.Vector3(cloudDataArrayLike[i], cloudDataArrayLike[i + 1], cloudDataArrayLike[i + 2]);
170
+ vector3d.project(this.camera);
171
+ const projection = {x: 0, y: 0};
172
+ projection.x = Math.round(vector3d.x * this.container.clientWidth / 2 + this.container.clientWidth / 2);
173
+ projection.y = Math.round(-vector3d.y * this.container.clientHeight / 2 + this.container.clientHeight / 2);
174
+ const isIn = isInPolygon(projection, polygon);
175
+ if (isIn) {
176
+ const x = cloudDataArrayLike[i];
177
+ const y = cloudDataArrayLike[i + 1];
178
+ const z = cloudDataArrayLike[i + 2];
179
+ const key = PointCloudUtils.getCloudKeys(x, y, z);
180
+ if (this.segmentMode === EPointCloudSegmentMode.Remove) {
181
+ this.cloudData.get(key).visible = false;
182
+ vertices.push(cloudDataArrayLike[i], cloudDataArrayLike[i + 1], cloudDataArrayLike[i + 2]);
183
+ }
184
+ if (this.segmentMode === EPointCloudSegmentMode.Add) {
185
+ if (this.segmentCoverMode === EPointCloudSegmentCoverMode.Cover) {
186
+ vertices.push(cloudDataArrayLike[i], cloudDataArrayLike[i + 1], cloudDataArrayLike[i + 2]);
187
+ if (this.cloudData.get(key).visible === true) {
188
+ covers.push(cloudDataArrayLike[i], cloudDataArrayLike[i + 1], cloudDataArrayLike[i + 2]);
189
+ }
190
+ }
191
+ if (this.segmentCoverMode === EPointCloudSegmentCoverMode.Uncover) {
192
+ if (this.cloudData.get(key).visible === false) {
193
+ vertices.push(cloudDataArrayLike[i], cloudDataArrayLike[i + 1], cloudDataArrayLike[i + 2]);
194
+ }
195
+ }
196
+ if (this.cloudData.get(key).visible === false) {
197
+ this.cloudData.get(key).visible = true;
198
+ }
199
+ }
200
+ }
201
+ }
202
+ const verticesArray = new Float32Array(vertices);
203
+ const coversArray = new Float32Array(covers);
204
+ this.updateStatusBySelector(verticesArray, coversArray);
205
+ }
206
+ }
207
+ updateStatusBySelector(verticesArray, coversArray) {
208
+ switch (this.segmentMode) {
209
+ case EPointCloudSegmentMode.Add:
210
+ if (this.cacheSegData) {
211
+ const {points, coverPoints = new Float32Array([])} = this.cacheSegData;
212
+ const combinedLength = points.length + verticesArray.length;
213
+ const combined = new Float32Array(combinedLength);
214
+ combined.set(points, 0);
215
+ combined.set(verticesArray, points.length);
216
+ const coverCombinedLength = coverPoints.length + coversArray.length;
217
+ const coverCombined = new Float32Array(coverCombinedLength);
218
+ coverCombined.set(coverPoints, 0);
219
+ coverCombined.set(coversArray, coverPoints.length);
220
+ this.cacheSegData = __spreadProps(__spreadValues({}, this.cacheSegData), {
221
+ points: combined,
222
+ coverPoints: coverCombined
223
+ });
224
+ this.emit("updateNewPoints", this.cacheSegData);
225
+ } else {
226
+ this.cacheSegData = {
227
+ id: uuid(),
228
+ attribute: this.currentAttribute,
229
+ points: verticesArray,
230
+ coverPoints: coversArray
231
+ };
232
+ this.emit("addNewPointsCloud", this.cacheSegData);
233
+ }
234
+ break;
235
+ case EPointCloudSegmentMode.Remove:
236
+ if (this.cacheSegData) {
237
+ const {points} = this.cacheSegData;
238
+ this.cacheSegData = __spreadProps(__spreadValues({}, this.cacheSegData), {
239
+ points: this.splitPointsFromPoints(points, verticesArray)
240
+ });
241
+ this.emit("updateNewPoints", this.cacheSegData);
242
+ }
243
+ break;
244
+ }
245
+ this.updateStatus2Edit();
246
+ this.emit("syncPointCloudStatus", {
247
+ segmentStatus: this.segmentStatus,
248
+ cacheSegData: this.cacheSegData
249
+ });
250
+ }
251
+ splitPointsFromPoints(originPoints, splitPoints) {
252
+ const splitMap = new Map();
253
+ for (let i = 0; i < splitPoints.length; i += 3) {
254
+ splitMap.set(PointCloudUtils.getCloudKeys(splitPoints[i], splitPoints[i + 1], splitPoints[i + 2]), 1);
255
+ }
256
+ const result = [];
257
+ for (let i = 0; i < originPoints.length; i += 3) {
258
+ const key = PointCloudUtils.getCloudKeys(originPoints[i], originPoints[i + 1], originPoints[i + 2]);
259
+ if (!splitMap.has(key)) {
260
+ result.push(originPoints[i], originPoints[i + 1], originPoints[i + 2]);
261
+ }
262
+ }
263
+ return new Float32Array(result);
264
+ }
265
+ syncPointCloudStatus() {
266
+ this.statusToggle();
267
+ const {segmentStatus, cacheSegData} = this;
268
+ this.emit("syncPointCloudStatus", {segmentStatus, cacheSegData});
269
+ }
270
+ addStash2Store() {
271
+ if (this.isEditStatus && this.cacheSegData) {
272
+ if (this.cacheSegData.coverPoints && this.cacheSegData.coverPoints.length !== 0) {
273
+ this.updateCoverPoints(this.cacheSegData.coverPoints);
274
+ }
275
+ delete this.cacheSegData.coverPoints;
276
+ this.segmentData.set(this.cacheSegData.id, this.cacheSegData);
277
+ this.cacheSegData = void 0;
278
+ this.syncPointCloudStatus();
279
+ }
280
+ }
281
+ updateCloudDataStatus(points, status) {
282
+ for (let i = 0; i < points.length; i += 3) {
283
+ const x = points[i];
284
+ const y = points[i + 1];
285
+ const z = points[i + 2];
286
+ const key = PointCloudUtils.getCloudKeys(x, y, z);
287
+ const data = this.cloudData.get(key);
288
+ Object.keys(status).forEach((k) => {
289
+ data[k] = status[k];
290
+ });
291
+ }
292
+ }
293
+ clearStash() {
294
+ if (this.isEditStatus && this.cacheSegData) {
295
+ this.updateCloudDataStatus(this.cacheSegData.points, {visible: false});
296
+ if (this.segmentData.has(this.cacheSegData.id)) {
297
+ const originSegmentData = this.segmentData.get(this.cacheSegData.id);
298
+ if (originSegmentData) {
299
+ this.emit("updateNewPoints", originSegmentData);
300
+ this.updateCloudDataStatus(originSegmentData == null ? void 0 : originSegmentData.points, {visible: true});
301
+ }
302
+ } else {
303
+ this.emit("clearStashRender");
304
+ }
305
+ this.cacheSegData = void 0;
306
+ this.syncPointCloudStatus();
307
+ }
308
+ }
309
+ updateCheck2Edit() {
310
+ if (this.isCheckStatus) {
311
+ this.syncPointCloudStatus();
312
+ }
313
+ }
314
+ checkPoints() {
315
+ const hoverPoints = this.segmentData.get(this.hoverPointsID);
316
+ if (hoverPoints) {
317
+ this.cacheSegData = __spreadProps(__spreadValues({}, hoverPoints), {
318
+ points: new Float32Array(hoverPoints.points)
319
+ });
320
+ instance.updateStatus2Check();
321
+ this.emit("syncPointCloudStatus", {
322
+ segmentStatus: this.segmentStatus,
323
+ cacheSegData: this.cacheSegData
324
+ });
325
+ }
326
+ }
327
+ editPoints() {
328
+ const hoverPoints = this.segmentData.get(this.hoverPointsID);
329
+ if (hoverPoints) {
330
+ this.cacheSegData = __spreadProps(__spreadValues({}, hoverPoints), {
331
+ points: new Float32Array(hoverPoints.points)
332
+ });
333
+ this.emit("updateNewPoints");
334
+ this.syncPointCloudStatus();
335
+ }
336
+ }
337
+ setForbidOperation(forbidOperation) {
338
+ this.forbidOperation = forbidOperation;
339
+ }
340
+ updateMouse(offset) {
341
+ const x = offset.x / this.containerWidth * 2 - 1;
342
+ const y = -(offset.y / this.containerHeight) * 2 + 1;
343
+ this.mouse.setX(x);
344
+ this.mouse.setY(y);
345
+ }
346
+ resetAllSegDataSize() {
347
+ this.allSegmentPoints.forEach((points) => {
348
+ var _a;
349
+ if (((_a = this.cacheSegData) == null ? void 0 : _a.id) === points.name) {
350
+ return;
351
+ }
352
+ points.material.size = 5;
353
+ });
354
+ }
355
+ resetHoverPointsID() {
356
+ this.hoverPointsID = "";
357
+ }
358
+ resetAllSegDataSizeAndRender() {
359
+ this.resetAllSegDataSize();
360
+ this.emit("reRender3d");
361
+ }
362
+ highlightPoints(newPoints) {
363
+ if (!(this.isCheckStatus || this.isReadyStatus)) {
364
+ return;
365
+ }
366
+ this.resetAllSegDataSize();
367
+ newPoints.material.size = 10;
368
+ this.hoverPointsID = newPoints.name;
369
+ this.emit("reRender3d");
370
+ }
371
+ setAttribute(attribute) {
372
+ this.currentAttribute = attribute;
373
+ }
374
+ }
375
+
376
+ export { PointCloudStore as default };
@@ -0,0 +1,101 @@
1
+ import _ from 'lodash';
2
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
3
+
4
+ class Selection {
5
+ constructor(toolInstance) {
6
+ if (!toolInstance) {
7
+ console.error("MultipleSelect is require a tool instance");
8
+ }
9
+ this._selectedIDs = [];
10
+ this.toolInstance = toolInstance;
11
+ }
12
+ get selectedIDs() {
13
+ return this._selectedIDs;
14
+ }
15
+ get selectedID() {
16
+ return this._selectedIDs.length === 1 ? this._selectedIDs[0] : void 0;
17
+ }
18
+ get visibleDataList() {
19
+ const {dataList, attributeLockList, basicResult} = this.toolInstance;
20
+ const [showingDataList] = CommonToolUtils.getRenderResultList(dataList, CommonToolUtils.getSourceID(basicResult), attributeLockList);
21
+ return showingDataList;
22
+ }
23
+ get dataList() {
24
+ return this.toolInstance.dataList;
25
+ }
26
+ set selectedIDs(selectedIDs) {
27
+ var _a;
28
+ (_a = this.toolInstance._textAttributeInstance) == null ? void 0 : _a.selectedIDsChanged(this.selectedIDs, selectedIDs);
29
+ this._selectedIDs = selectedIDs;
30
+ this.toolInstance.render();
31
+ }
32
+ updateSelectedIDs(selectedID) {
33
+ if (!selectedID) {
34
+ this._selectedIDs = [];
35
+ return;
36
+ }
37
+ if (this.selectedIDs.includes(selectedID)) {
38
+ this.selectedIDs = this.selectedIDs.filter((id) => id !== selectedID);
39
+ } else {
40
+ this.selectedIDs = [...this.selectedIDs, selectedID];
41
+ }
42
+ }
43
+ setSelectedIDs(id, isAppend = false) {
44
+ if (isAppend) {
45
+ this.updateSelectedIDs(id);
46
+ return;
47
+ }
48
+ this.selectedIDs = id ? [id] : [];
49
+ }
50
+ hardSetSelectedIDs(ids) {
51
+ this.selectedIDs = ids;
52
+ }
53
+ selectAll() {
54
+ this.selectedIDs = this.visibleDataList.map((i) => i.id);
55
+ this.toolInstance.render();
56
+ }
57
+ toStashDataList() {
58
+ if (this.selectedIDs.length > 0) {
59
+ this.stashDataList = _.cloneDeep(this.dataList.filter((i) => this.selectedIDs.includes(i.id)));
60
+ }
61
+ }
62
+ toUnStashDataList() {
63
+ if (this.stashDataList) {
64
+ const _stashDataList = this.stashDataList;
65
+ this.stashDataList = void 0;
66
+ return _stashDataList;
67
+ }
68
+ return void 0;
69
+ }
70
+ mergeStashData(setDataList) {
71
+ const stashList = this.toUnStashDataList();
72
+ if (!stashList) {
73
+ return;
74
+ }
75
+ const mergedDataList = _(this.dataList).keyBy("id").merge(_.keyBy(stashList, "id")).values().value();
76
+ setDataList(mergedDataList);
77
+ this.toolInstance.render();
78
+ }
79
+ isIdSelected(id) {
80
+ return this.selectedIDs.includes(id);
81
+ }
82
+ triggerKeyboardEvent(e, setDataList) {
83
+ if (e.ctrlKey) {
84
+ if (e.key === "v") {
85
+ this.mergeStashData(setDataList);
86
+ return true;
87
+ }
88
+ if (e.key === "a") {
89
+ this.selectAll();
90
+ return true;
91
+ }
92
+ if (e.key === "c") {
93
+ this.toStashDataList();
94
+ return true;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ }
100
+
101
+ export { Selection as default };
@@ -1,7 +1,7 @@
1
1
  import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
2
2
  import AxisUtils from '../../utils/tool/AxisUtils.js';
3
3
  import uuid from '../../utils/uuid.js';
4
- import { getCuboidHoverRange, getPlainPointsByDiagonalPoints, getPointsByBottomRightPoint, getCuboidDragMove, isCuboidWithInLimits, getHighlightPoints, getCuboidTextAttributeOffset, getToggleDirectionButtonOffset } from '../../utils/tool/CuboidUtils.js';
4
+ import { getCuboidHoverRange, getPlainPointsByDiagonalPoints, getPointsByBottomRightPoint, getCuboidDragMove, isCuboidWithInLimits, getHighlightPoints, getHighlightLines, getToggleDirectionButtonOffset, getCuboidTextAttributeOffset } from '../../utils/tool/CuboidUtils.js';
5
5
  import PolygonUtils from '../../utils/tool/PolygonUtils.js';
6
6
  import { EDragStatus, EDragTarget, ECuboidDirection } from '../../constant/annotation.js';
7
7
  import AttributeUtils from '../../utils/tool/AttributeUtils.js';
@@ -75,6 +75,10 @@ class CuboidOperation extends BasicToolOperation {
75
75
  this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
76
76
  this.updateSelectedTextAttribute = this.updateSelectedTextAttribute.bind(this);
77
77
  }
78
+ get selectedText() {
79
+ var _a, _b;
80
+ return (_b = (_a = this.selectedCuboid) == null ? void 0 : _a.textAttribute) != null ? _b : "";
81
+ }
78
82
  destroy() {
79
83
  super.destroy();
80
84
  if (this._textAttributeInstance) {
@@ -123,18 +127,20 @@ class CuboidOperation extends BasicToolOperation {
123
127
  return cuboid;
124
128
  });
125
129
  }
126
- getColorToRender(attribute, valid) {
130
+ getStylesToRender(attribute, valid) {
131
+ var _a, _b;
127
132
  const toolColor = this.getColor(attribute);
128
133
  const strokeColor = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
129
134
  const fillColor = valid ? toolColor == null ? void 0 : toolColor.valid.fill : toolColor == null ? void 0 : toolColor.invalid.fill;
130
- return {strokeColor, toolColor, fillColor};
135
+ const lineWidth = (_b = (_a = this.style) == null ? void 0 : _a.width) != null ? _b : 2;
136
+ return {strokeColor, toolColor, fillColor, lineWidth};
131
137
  }
132
138
  getCurrentSelectedData() {
133
139
  const {selectedCuboid} = this;
134
140
  if (!selectedCuboid) {
135
141
  return;
136
142
  }
137
- const {strokeColor: color} = this.getColorToRender(selectedCuboid.attribute, selectedCuboid.valid);
143
+ const {strokeColor: color} = this.getStylesToRender(selectedCuboid.attribute, selectedCuboid.valid);
138
144
  return {
139
145
  width: TEXT_MAX_WIDTH,
140
146
  textAttribute: selectedCuboid.textAttribute,
@@ -155,7 +161,7 @@ class CuboidOperation extends BasicToolOperation {
155
161
  }
156
162
  }
157
163
  setResult(cuboidList) {
158
- this.clearDrawingStatus();
164
+ this.clearActiveStatus();
159
165
  this.setCuboidList(cuboidList);
160
166
  this.render();
161
167
  }
@@ -164,7 +170,8 @@ class CuboidOperation extends BasicToolOperation {
164
170
  }
165
171
  clearResult() {
166
172
  this.setCuboidList([], true);
167
- this.setSelectedID(void 0);
173
+ this.deleteSelectedID();
174
+ this.render();
168
175
  }
169
176
  exportData() {
170
177
  const {cuboidList} = this;
@@ -247,6 +254,15 @@ class CuboidOperation extends BasicToolOperation {
247
254
  this.render();
248
255
  }
249
256
  break;
257
+ case EKeyCode.Delete:
258
+ if (this.selectedID) {
259
+ this.deleteCuboid(this.selectedID);
260
+ }
261
+ break;
262
+ case EKeyCode.Z:
263
+ this.setIsHidden(!this.isHidden);
264
+ this.render();
265
+ break;
250
266
  case EKeyCode.F:
251
267
  if (this.selectedID) {
252
268
  this.setCuboidValidAndRender(this.selectedID);
@@ -445,6 +461,13 @@ class CuboidOperation extends BasicToolOperation {
445
461
  };
446
462
  this.firstClickCoord = __spreadValues({}, coordinate);
447
463
  this.drawingStatus = 2;
464
+ if (this.config.textConfigurable) {
465
+ let textAttribute = "";
466
+ textAttribute = AttributeUtils.getTextAttribute(this.cuboidList.filter((cuboid) => CommonToolUtils.isSameSourceID(cuboid.sourceID, basicSourceID)), this.config.textCheckType);
467
+ this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
468
+ textAttribute
469
+ });
470
+ }
448
471
  }
449
472
  closeNewDrawingFrontPlane() {
450
473
  this.drawingStatus = 3;
@@ -464,12 +487,19 @@ class CuboidOperation extends BasicToolOperation {
464
487
  this.clearDrawingStatus();
465
488
  this.render();
466
489
  }
490
+ deleteSelectedID() {
491
+ this.setSelectedID("");
492
+ }
467
493
  clearDrawingStatus() {
468
494
  if (this.drawingCuboid) {
469
495
  this.drawingCuboid = void 0;
470
496
  this.drawingStatus = 1;
471
497
  }
472
498
  }
499
+ clearActiveStatus() {
500
+ this.clearDrawingStatus();
501
+ this.deleteSelectedID();
502
+ }
473
503
  rightMouseUp(e) {
474
504
  const {hoverID, hoverCuboid} = this.getHoverData(e);
475
505
  this.setSelectedID(hoverID);
@@ -481,60 +511,42 @@ class CuboidOperation extends BasicToolOperation {
481
511
  }
482
512
  this.render();
483
513
  }
484
- renderSingleCuboid(cuboid) {
485
- var _a, _b, _c, _d;
514
+ renderHighlightCuboidCom(cuboid) {
486
515
  const transformCuboid = AxisUtils.changeCuboidByZoom(cuboid, this.zoom, this.currentPos);
487
516
  const isHover = transformCuboid.id === this.hoverID;
488
517
  const isSelected = transformCuboid.id === this.selectedID;
489
- const {strokeColor, fillColor} = this.getColorToRender(transformCuboid.attribute, transformCuboid.valid);
490
- const textColor = strokeColor;
491
- const lineWidth = (_b = (_a = this.style) == null ? void 0 : _a.width) != null ? _b : 2;
492
- const {hiddenText = false} = this.style;
518
+ const {strokeColor, lineWidth} = this.getStylesToRender(transformCuboid.attribute, transformCuboid.valid);
493
519
  const defaultStyle = {
494
520
  color: strokeColor,
495
521
  thickness: lineWidth
496
522
  };
497
- const {backPoints, frontPoints, textAttribute} = transformCuboid;
498
- const frontPointsSizeWidth = frontPoints.br.x - frontPoints.bl.x;
499
- DrawUtils.drawCuboid(this.canvas, transformCuboid, {strokeColor, fillColor, thickness: lineWidth});
500
523
  if (isHover || isSelected) {
501
524
  const hoverPointList = getHighlightPoints(transformCuboid);
502
525
  hoverPointList.forEach((data) => {
503
526
  DrawUtils.drawCircleWithFill(this.canvas, data.point, 5, __spreadValues({}, defaultStyle));
504
527
  });
505
528
  if (isSelected) {
529
+ const highlightLine = getHighlightLines(transformCuboid);
530
+ highlightLine.forEach((line) => {
531
+ DrawUtils.drawLine(this.canvas, line.p1, line.p2, {color: strokeColor, thickness: lineWidth + 2});
532
+ });
506
533
  hoverPointList.forEach((data) => {
507
534
  DrawUtils.drawCircleWithFill(this.canvas, data.point, 3, {color: "white"});
508
535
  });
509
536
  }
510
537
  }
511
- let showText = "";
512
- if (((_c = this.config) == null ? void 0 : _c.isShowOrder) && transformCuboid.order && (transformCuboid == null ? void 0 : transformCuboid.order) > 0) {
513
- showText = `${transformCuboid.order}`;
514
- }
515
- if (transformCuboid.attribute) {
516
- showText = `${showText} ${AttributeUtils.getAttributeShowText(transformCuboid.attribute, (_d = this.config) == null ? void 0 : _d.attributeList)}`;
517
- }
518
- if (!hiddenText && backPoints) {
519
- DrawUtils.drawText(this.canvas, {x: backPoints.tl.x, y: backPoints.tl.y - 5}, showText, {
520
- color: strokeColor,
521
- textMaxWidth: 300
522
- });
523
- }
524
- const textPosition = getCuboidTextAttributeOffset({
525
- cuboid,
526
- currentPos: this.currentPos,
527
- zoom: this.zoom,
528
- topOffset: 16,
529
- leftOffset: 0
538
+ }
539
+ renderSingleCuboid(cuboid) {
540
+ var _a, _b;
541
+ const transformCuboid = AxisUtils.changeCuboidByZoom(cuboid, this.zoom, this.currentPos);
542
+ const {strokeColor, fillColor} = this.getStylesToRender(transformCuboid.attribute, transformCuboid.valid);
543
+ const lineWidth = (_b = (_a = this.style) == null ? void 0 : _a.width) != null ? _b : 2;
544
+ const {hiddenText = false} = this.style;
545
+ DrawUtils.drawCuboidWithText(this.canvas, transformCuboid, {strokeColor, fillColor, thickness: lineWidth}, {
546
+ config: this.config,
547
+ hiddenText,
548
+ selectedID: this.selectedID
530
549
  });
531
- if (!hiddenText && textAttribute && cuboid.id !== this.selectedID) {
532
- const textWidth = Math.max(20, frontPointsSizeWidth * 0.8);
533
- DrawUtils.drawText(this.canvas, {x: textPosition.left, y: textPosition.top}, textAttribute, {
534
- color: textColor,
535
- textMaxWidth: textWidth
536
- });
537
- }
538
550
  this.renderTextAttribute();
539
551
  }
540
552
  setDefaultAttribute(defaultAttribute) {
@@ -544,6 +556,13 @@ class CuboidOperation extends BasicToolOperation {
544
556
  this.changeStyle(defaultAttribute);
545
557
  this.emit("changeAttributeSidebar");
546
558
  const {selectedCuboid} = this;
559
+ if (this._textAttributeInstance) {
560
+ if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(this.defaultAttribute)) {
561
+ this._textAttributeInstance.clearTextAttribute();
562
+ } else {
563
+ this._textAttributeInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
564
+ }
565
+ }
547
566
  if (selectedCuboid) {
548
567
  this.setCuboidList(this.cuboidList.map((v) => {
549
568
  if (v.id === this.selectedID) {
@@ -555,6 +574,7 @@ class CuboidOperation extends BasicToolOperation {
555
574
  }));
556
575
  this.history.pushHistory(this.cuboidList);
557
576
  this.render();
577
+ return;
558
578
  }
559
579
  if (this.drawingCuboid) {
560
580
  this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
@@ -562,22 +582,15 @@ class CuboidOperation extends BasicToolOperation {
562
582
  });
563
583
  this.render();
564
584
  }
565
- if (this._textAttributeInstance) {
566
- if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(this.defaultAttribute)) {
567
- this._textAttributeInstance.clearTextAttribute();
568
- return;
569
- }
570
- this._textAttributeInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
571
- }
572
585
  }
573
586
  }
574
587
  renderToggleButton() {
575
588
  const {selectedCuboid} = this;
576
- if (!this.ctx || this.config.textConfigurable !== true || !selectedCuboid) {
589
+ if (!this.ctx || !selectedCuboid) {
577
590
  return;
578
591
  }
579
592
  const {attribute, valid} = selectedCuboid;
580
- const {strokeColor: color} = this.getColorToRender(attribute, valid);
593
+ const {strokeColor: color} = this.getStylesToRender(attribute, valid);
581
594
  if (!this.toggleButtonInstance) {
582
595
  this.toggleButtonInstance = new CuboidToggleButtonClass({
583
596
  container: this.container,
@@ -602,7 +615,7 @@ class CuboidOperation extends BasicToolOperation {
602
615
  if (!this.ctx || this.config.textConfigurable === false || !selectedCuboid) {
603
616
  return;
604
617
  }
605
- const {strokeColor: color} = this.getColorToRender(selectedCuboid.attribute, selectedCuboid.valid);
618
+ const {strokeColor: color} = this.getStylesToRender(selectedCuboid.attribute, selectedCuboid.valid);
606
619
  const {attribute, textAttribute, frontPoints} = selectedCuboid;
607
620
  const offset = getCuboidTextAttributeOffset({
608
621
  cuboid: selectedCuboid,
@@ -636,13 +649,16 @@ class CuboidOperation extends BasicToolOperation {
636
649
  }
637
650
  }
638
651
  renderStatic() {
639
- this.cuboidList.forEach((cuboid) => this.renderSingleCuboid(cuboid));
652
+ if (!this.isHidden) {
653
+ this.currentShowList.forEach((cuboid) => this.renderSingleCuboid(cuboid));
654
+ }
640
655
  }
641
656
  renderSelected() {
642
657
  var _a;
643
658
  const {selectedCuboid} = this;
644
659
  if (selectedCuboid) {
645
660
  this.renderSingleCuboid(selectedCuboid);
661
+ this.renderHighlightCuboidCom(selectedCuboid);
646
662
  this.renderToggleButton();
647
663
  } else {
648
664
  (_a = this.toggleButtonInstance) == null ? void 0 : _a.clearCuboidButtonDOM();
@@ -677,7 +693,7 @@ class CuboidOperation extends BasicToolOperation {
677
693
  }
678
694
  (_a = this.highlightInfo) == null ? void 0 : _a.forEach((data) => {
679
695
  var _a2, _b;
680
- const {strokeColor} = this.getColorToRender(data.originCuboid.attribute, data.originCuboid.valid);
696
+ const {strokeColor} = this.getStylesToRender(data.originCuboid.attribute, data.originCuboid.valid);
681
697
  const thickness = 8;
682
698
  switch (data.type) {
683
699
  case "point":
@@ -489,78 +489,95 @@ function getNewPointsAfterOffset({
489
489
  backPoints: newBackPoints
490
490
  };
491
491
  }
492
+ function moveCuboidByCuboid({offset, cuboid}) {
493
+ const {frontPoints, backPoints} = cuboid;
494
+ const newFrontPoints = Object.entries(frontPoints).reduce((acc, [key, point]) => {
495
+ return __spreadProps(__spreadValues({}, acc), {
496
+ [key]: {
497
+ x: point.x + offset.x,
498
+ y: point.y + offset.y
499
+ }
500
+ });
501
+ }, {});
502
+ const newBackPoints = Object.entries(backPoints).reduce((acc, [key, point]) => {
503
+ return __spreadProps(__spreadValues({}, acc), {
504
+ [key]: {
505
+ x: point.x + offset.x,
506
+ y: point.y + offset.y
507
+ }
508
+ });
509
+ }, {});
510
+ return {
511
+ frontPoints: newFrontPoints,
512
+ backPoints: newBackPoints
513
+ };
514
+ }
515
+ function moveCuboidByLine({
516
+ offset,
517
+ cuboid,
518
+ positions
519
+ }) {
520
+ const {frontPoints, backPoints} = cuboid;
521
+ return getNewPointsAfterOffset({
522
+ offset,
523
+ frontPoints,
524
+ backPoints,
525
+ positions
526
+ });
527
+ }
528
+ function moveCuboidByPoints({
529
+ offset,
530
+ cuboid,
531
+ positions
532
+ }) {
533
+ if (!(positions == null ? void 0 : positions[0])) {
534
+ return;
535
+ }
536
+ const {frontPoints, backPoints} = cuboid;
537
+ const pointPosition = positions[0];
538
+ const isFrontPlain = pointPosition.plain === ECuboidPlain.Front;
539
+ const movePoints = isFrontPlain ? frontPoints : backPoints;
540
+ let movePoint = movePoints[pointPosition.position];
541
+ const diagonalPoint = movePoints[DIAGONAL_POINT[pointPosition.position]];
542
+ if (!movePoint || !diagonalPoint) {
543
+ return;
544
+ }
545
+ movePoint = Vector.add(movePoint, offset);
546
+ const newPlainsPoints = getPlainPointsByDiagonalPoints(movePoint, diagonalPoint);
547
+ const getNewPlainPoints = isFrontPlain ? getBackPointsByFrontPoints : getFrontPointsByBackPoints;
548
+ let payload = {
549
+ frontPoints,
550
+ backPoints: newPlainsPoints
551
+ };
552
+ if (isFrontPlain) {
553
+ payload = {
554
+ frontPoints: newPlainsPoints,
555
+ backPoints
556
+ };
557
+ }
558
+ return getNewPlainPoints(payload);
559
+ }
492
560
  function getCuboidDragMove({
493
561
  offset,
494
562
  cuboid,
495
563
  dragTarget,
496
564
  positions
497
565
  }) {
498
- const {frontPoints, backPoints} = cuboid;
499
566
  switch (dragTarget) {
500
567
  case EDragTarget.Cuboid: {
501
- const newFrontPoints = Object.entries(frontPoints).reduce((acc, [key, point]) => {
502
- return __spreadProps(__spreadValues({}, acc), {
503
- [key]: {
504
- x: point.x + offset.x,
505
- y: point.y + offset.y
506
- }
507
- });
508
- }, {});
509
- const newBackPoints = Object.entries(backPoints).reduce((acc, [key, point]) => {
510
- return __spreadProps(__spreadValues({}, acc), {
511
- [key]: {
512
- x: point.x + offset.x,
513
- y: point.y + offset.y
514
- }
515
- });
516
- }, {});
517
- return __spreadProps(__spreadValues({}, cuboid), {
518
- frontPoints: newFrontPoints,
519
- backPoints: newBackPoints
520
- });
568
+ const newCuboidPoints = moveCuboidByCuboid({offset, cuboid});
569
+ return __spreadValues(__spreadValues({}, cuboid), newCuboidPoints);
521
570
  }
522
571
  case EDragTarget.Line: {
523
- const {frontPoints: newFrontPoints, backPoints: newBackPoints} = getNewPointsAfterOffset({
524
- offset,
525
- frontPoints,
526
- backPoints,
527
- positions
528
- });
529
- return __spreadProps(__spreadValues({}, cuboid), {
530
- frontPoints: newFrontPoints,
531
- backPoints: newBackPoints
532
- });
572
+ const newCuboidPoints = moveCuboidByLine({offset, cuboid, positions});
573
+ return __spreadValues(__spreadValues({}, cuboid), newCuboidPoints);
533
574
  }
534
575
  case EDragTarget.Point: {
535
- if (!(positions == null ? void 0 : positions[0])) {
536
- return;
537
- }
538
- const pointPosition = positions[0];
539
- const isFrontPlain = pointPosition.plain === ECuboidPlain.Front;
540
- const movePoints = isFrontPlain ? frontPoints : backPoints;
541
- let movePoint = movePoints[pointPosition.position];
542
- const diagonalPoint = movePoints[DIAGONAL_POINT[pointPosition.position]];
543
- if (!movePoint || !diagonalPoint) {
544
- return;
576
+ const newCuboidPoints = moveCuboidByPoints({cuboid, offset, positions});
577
+ if (newCuboidPoints) {
578
+ return __spreadValues(__spreadValues({}, cuboid), newCuboidPoints);
545
579
  }
546
- movePoint = Vector.add(movePoint, offset);
547
- const newPlainsPoints = getPlainPointsByDiagonalPoints(movePoint, diagonalPoint);
548
- const getNewPlainPoints = isFrontPlain ? getBackPointsByFrontPoints : getFrontPointsByBackPoints;
549
- let payload = {
550
- frontPoints,
551
- backPoints: newPlainsPoints
552
- };
553
- if (isFrontPlain) {
554
- payload = {
555
- frontPoints: newPlainsPoints,
556
- backPoints
557
- };
558
- }
559
- const {frontPoints: newFrontPoints, backPoints: newBackPoints} = getNewPlainPoints(payload);
560
- return __spreadProps(__spreadValues({}, cuboid), {
561
- frontPoints: newFrontPoints,
562
- backPoints: newBackPoints
563
- });
580
+ break;
564
581
  }
565
582
  default: {
566
583
  console.error("No DragTarget");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.13.1-alpha.0",
3
+ "version": "1.13.1",
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.6.1-alpha.0",
95
+ "@labelbee/lb-utils": "^1.6.1",
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": "d97831322bbab5c86cb12a1abadd0a34d351ab9f"
101
+ "gitHead": "c95b85c66f2aa6de4a53a2745765c043e7ab113d"
102
102
  }
File without changes