@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/MathUtilsWorker.js +8 -1
- package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
- package/dist/_virtual/filterBoxWorker.js +8 -1
- package/dist/_virtual/highlightWorker.js +8 -1
- package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
- package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
- package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
- package/dist/constant/annotation.js +127 -1
- package/dist/constant/annotationTask.js +30 -1
- package/dist/constant/defaultConfig.js +266 -1
- package/dist/constant/keyCode.js +38 -1
- package/dist/constant/style.js +98 -1
- package/dist/constant/tool.js +236 -1
- package/dist/core/index.js +150 -1
- package/dist/core/pointCloud/OrbitControls.js +665 -1
- package/dist/core/pointCloud/PCDLoader.js +260 -2
- package/dist/core/pointCloud/annotation.js +215 -1
- package/dist/core/pointCloud/cache.js +53 -1
- package/dist/core/pointCloud/index.js +991 -5
- package/dist/core/pointCloud/matrix.js +138 -1
- package/dist/core/pointCloud/segmentation.js +144 -0
- package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
- package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
- package/dist/core/scheduler.js +233 -1
- package/dist/core/toolOperation/LineToolOperation.js +1434 -1
- package/dist/core/toolOperation/ScribbleTool.js +292 -1
- package/dist/core/toolOperation/TextToolOperation.js +131 -1
- package/dist/core/toolOperation/ViewOperation.js +556 -1
- package/dist/core/toolOperation/basicToolOperation.js +881 -1
- package/dist/core/toolOperation/checkOperation.js +208 -1
- package/dist/core/toolOperation/cuboidOperation.js +754 -1
- package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
- package/dist/core/toolOperation/eventListener.js +37 -1
- package/dist/core/toolOperation/measureOperation.js +41 -1
- package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
- package/dist/core/toolOperation/pointOperation.js +696 -1
- package/dist/core/toolOperation/polygonOperation.js +1251 -1
- package/dist/core/toolOperation/rectOperation.js +1233 -1
- package/dist/core/toolOperation/segmentByRect.js +174 -1
- package/dist/core/toolOperation/tagOperation.js +201 -3
- package/dist/core/toolOperation/textAttributeClass.js +182 -16
- package/dist/index.js +185 -1
- package/dist/locales/constants.js +24 -1
- package/dist/locales/en_US/message.js +25 -1
- package/dist/locales/index.js +19 -1
- package/dist/locales/zh_CN/message.js +25 -1
- package/dist/newCore/CanvasScheduler.js +35 -1
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
- package/dist/utils/ActionsHistory.js +84 -1
- package/dist/utils/ImgUtils.js +23 -1
- package/dist/utils/MathUtils.js +385 -2
- package/dist/utils/VectorUtils.js +25 -1
- package/dist/utils/tool/AttributeUtils.js +218 -1
- package/dist/utils/tool/AxisUtils.js +340 -1
- package/dist/utils/tool/CanvasUtils.js +62 -1
- package/dist/utils/tool/CommonToolUtils.js +174 -1
- package/dist/utils/tool/CuboidUtils.js +704 -1
- package/dist/utils/tool/DblClickEventListener.js +102 -1
- package/dist/utils/tool/DrawUtils.js +492 -3
- package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
- package/dist/utils/tool/ImgPosUtils.js +58 -1
- package/dist/utils/tool/LineToolUtils.js +261 -1
- package/dist/utils/tool/MarkerUtils.js +56 -1
- package/dist/utils/tool/PolygonUtils.js +460 -1
- package/dist/utils/tool/RectUtils.js +155 -1
- package/dist/utils/tool/RenderDomClass.js +57 -7
- package/dist/utils/tool/RenderDomUtils.js +21 -4
- package/dist/utils/tool/StyleUtils.js +31 -1
- package/dist/utils/tool/TagUtils.js +129 -1
- package/dist/utils/tool/UnitUtils.js +12 -1
- package/dist/utils/tool/ZoomUtils.js +72 -1
- package/dist/utils/tool/polygonTool.js +133 -1
- package/dist/utils/uuid.js +26 -1
- package/es/_virtual/MathUtilsWorker.js +6 -1
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/_virtual/filterBoxWorker.js +6 -1
- package/es/_virtual/highlightWorker.js +6 -1
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
- package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
- package/es/constant/annotation.js +113 -1
- package/es/constant/annotationTask.js +25 -1
- package/es/constant/defaultConfig.js +260 -1
- package/es/constant/keyCode.js +36 -1
- package/es/constant/style.js +74 -1
- package/es/constant/tool.js +220 -1
- package/es/core/index.js +148 -1
- package/es/core/pointCloud/OrbitControls.js +661 -1
- package/es/core/pointCloud/PCDLoader.js +256 -2
- package/es/core/pointCloud/annotation.js +211 -1
- package/es/core/pointCloud/cache.js +49 -1
- package/es/core/pointCloud/index.js +962 -5
- package/es/core/pointCloud/matrix.js +109 -1
- package/es/core/pointCloud/segmentation.js +120 -0
- package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
- package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
- package/es/core/scheduler.js +228 -1
- package/es/core/toolOperation/LineToolOperation.js +1421 -1
- package/es/core/toolOperation/ScribbleTool.js +290 -1
- package/es/core/toolOperation/TextToolOperation.js +129 -1
- package/es/core/toolOperation/ViewOperation.js +549 -1
- package/es/core/toolOperation/basicToolOperation.js +877 -1
- package/es/core/toolOperation/checkOperation.js +206 -1
- package/es/core/toolOperation/cuboidOperation.js +752 -1
- package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
- package/es/core/toolOperation/eventListener.js +35 -1
- package/es/core/toolOperation/measureOperation.js +39 -1
- package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
- package/es/core/toolOperation/pointOperation.js +690 -1
- package/es/core/toolOperation/polygonOperation.js +1245 -1
- package/es/core/toolOperation/rectOperation.js +1228 -1
- package/es/core/toolOperation/scribbleTool2.js +249 -0
- package/es/core/toolOperation/segmentByRect.js +172 -1
- package/es/core/toolOperation/tagOperation.js +199 -3
- package/es/core/toolOperation/textAttributeClass.js +180 -16
- package/es/index.js +46 -1
- package/es/locales/constants.js +22 -1
- package/es/locales/en_US/message.js +23 -1
- package/es/locales/index.js +17 -1
- package/es/locales/zh_CN/message.js +23 -1
- package/es/newCore/CanvasScheduler.js +31 -1
- package/es/utils/ActionsHistory.js +78 -1
- package/es/utils/ImgUtils.js +21 -1
- package/es/utils/MathUtils.js +380 -2
- package/es/utils/VectorUtils.js +23 -1
- package/es/utils/tool/AttributeUtils.js +212 -1
- package/es/utils/tool/AxisUtils.js +335 -1
- package/es/utils/tool/CanvasUtils.js +60 -1
- package/es/utils/tool/CommonToolUtils.js +172 -1
- package/es/utils/tool/CuboidUtils.js +680 -1
- package/es/utils/tool/DblClickEventListener.js +100 -1
- package/es/utils/tool/DrawUtils.js +490 -3
- package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
- package/es/utils/tool/ImgPosUtils.js +56 -1
- package/es/utils/tool/LineToolUtils.js +255 -1
- package/es/utils/tool/MarkerUtils.js +54 -1
- package/es/utils/tool/PolygonUtils.js +458 -1
- package/es/utils/tool/RectUtils.js +153 -1
- package/es/utils/tool/RenderDomClass.js +55 -7
- package/es/utils/tool/RenderDomUtils.js +19 -4
- package/es/utils/tool/StyleUtils.js +29 -1
- package/es/utils/tool/TagUtils.js +127 -1
- package/es/utils/tool/UnitUtils.js +10 -1
- package/es/utils/tool/ZoomUtils.js +70 -1
- package/es/utils/tool/polygonTool.js +126 -1
- package/es/utils/uuid.js +24 -1
- package/package.json +7 -5
|
@@ -1,11 +1,968 @@
|
|
|
1
|
-
import*
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { toolStyleConverter, PerspectiveShiftUtils, EPerspectiveView, PointCloudUtils, DEFAULT_SPHERE_PARAMS } from '@labelbee/lb-utils';
|
|
3
|
+
import WorkerFactory from '../../_virtual/highlightWorker.js';
|
|
4
|
+
import WorkerFactory$1 from '../../_virtual/filterBoxWorker.js';
|
|
5
|
+
import { isInPolygon } from '../../utils/tool/polygonTool.js';
|
|
6
|
+
import uuid from '../../utils/uuid.js';
|
|
7
|
+
import MathUtils from '../../utils/MathUtils.js';
|
|
8
|
+
import { PCDLoader } from './PCDLoader.js';
|
|
9
|
+
import { OrbitControls } from './OrbitControls.js';
|
|
10
|
+
import { PointCloudCache } from './cache.js';
|
|
11
|
+
import { getCuboidFromPointCloudBox } from './matrix.js';
|
|
12
|
+
export { createThreeMatrix4, getCuboidFromPointCloudBox, lidar2image, pointCloudLidar2image, rotatePoint, transferKitti2Matrix } from './matrix.js';
|
|
13
|
+
import '../../constant/tool.js';
|
|
14
|
+
import '../scheduler.js';
|
|
15
|
+
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __defProps = Object.defineProperties;
|
|
18
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
19
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
20
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
21
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
22
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
23
|
+
var __spreadValues = (a, b) => {
|
|
24
|
+
for (var prop in b || (b = {}))
|
|
25
|
+
if (__hasOwnProp.call(b, prop))
|
|
26
|
+
__defNormalProp(a, prop, b[prop]);
|
|
27
|
+
if (__getOwnPropSymbols)
|
|
28
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
29
|
+
if (__propIsEnum.call(b, prop))
|
|
30
|
+
__defNormalProp(a, prop, b[prop]);
|
|
31
|
+
}
|
|
32
|
+
return a;
|
|
33
|
+
};
|
|
34
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
35
|
+
var __async = (__this, __arguments, generator) => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
var fulfilled = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.next(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var rejected = (value) => {
|
|
45
|
+
try {
|
|
46
|
+
step(generator.throw(value));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
52
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const DEFAULT_DISTANCE = 30;
|
|
56
|
+
const highlightWorker = new WorkerFactory({type: "module"});
|
|
57
|
+
class PointCloud {
|
|
58
|
+
constructor({
|
|
59
|
+
container,
|
|
60
|
+
noAppend,
|
|
61
|
+
isOrthographicCamera,
|
|
62
|
+
orthographicParams,
|
|
63
|
+
backgroundColor = "#4C4C4C",
|
|
64
|
+
config
|
|
65
|
+
}) {
|
|
66
|
+
this.zAxisLimit = 10;
|
|
67
|
+
this.initCameraPosition = this.DEFAULT_INIT_CAMERA_POSITION;
|
|
68
|
+
this.isOrthographicCamera = false;
|
|
69
|
+
this.pointsUuid = "";
|
|
70
|
+
this.pointCloudObjectName = "pointCloud";
|
|
71
|
+
this.rangeObjectName = "range";
|
|
72
|
+
this.showDirection = true;
|
|
73
|
+
this.addSphereToSense = (sphereParams, color = "blue") => {
|
|
74
|
+
var _a;
|
|
75
|
+
const id = (_a = sphereParams.id) != null ? _a : uuid();
|
|
76
|
+
this.removeObjectByName(id);
|
|
77
|
+
const {radius, widthSegments, heightSegments} = DEFAULT_SPHERE_PARAMS;
|
|
78
|
+
const {center} = sphereParams;
|
|
79
|
+
const group = new THREE.Group();
|
|
80
|
+
const spGeo = new THREE.SphereGeometry(radius, widthSegments, heightSegments);
|
|
81
|
+
const spMaterial = new THREE.MeshBasicMaterial({color});
|
|
82
|
+
const sphere = new THREE.Mesh(spGeo, spMaterial);
|
|
83
|
+
sphere.position.set(center.x, center.y, center.z);
|
|
84
|
+
group.add(sphere);
|
|
85
|
+
group.name = id;
|
|
86
|
+
this.scene.add(group);
|
|
87
|
+
};
|
|
88
|
+
this.generateSphere = (sphereParams) => {
|
|
89
|
+
const {fill} = toolStyleConverter.getColorFromConfig({attribute: sphereParams.attribute}, __spreadProps(__spreadValues({}, this.config), {attributeConfigurable: true}), {});
|
|
90
|
+
this.addSphereToSense(sphereParams, fill);
|
|
91
|
+
this.render();
|
|
92
|
+
};
|
|
93
|
+
this.generateSpheres = (spheres) => {
|
|
94
|
+
spheres.forEach((sphere) => {
|
|
95
|
+
const {fill} = toolStyleConverter.getColorFromConfig({attribute: sphere.attribute}, __spreadProps(__spreadValues({}, this.config), {attributeConfigurable: true}), {});
|
|
96
|
+
this.addSphereToSense(sphere, fill);
|
|
97
|
+
});
|
|
98
|
+
this.render();
|
|
99
|
+
};
|
|
100
|
+
this.AddBoxToSense = (boxParams, color = 16777215) => {
|
|
101
|
+
var _a;
|
|
102
|
+
const id = (_a = boxParams.id) != null ? _a : uuid();
|
|
103
|
+
this.removeObjectByName(id);
|
|
104
|
+
const {center, width, height, depth, rotation} = boxParams;
|
|
105
|
+
const group = new THREE.Group();
|
|
106
|
+
const geometry = new THREE.BoxGeometry(width, height, depth);
|
|
107
|
+
const material = new THREE.MeshBasicMaterial({color: "blue"});
|
|
108
|
+
const cube = new THREE.Mesh(geometry, material);
|
|
109
|
+
const box = new THREE.BoxHelper(cube, color);
|
|
110
|
+
const arrow = this.generateBoxArrow(boxParams);
|
|
111
|
+
group.add(box);
|
|
112
|
+
group.add(arrow);
|
|
113
|
+
if (center) {
|
|
114
|
+
group.position.set(center.x, center.y, center.z);
|
|
115
|
+
}
|
|
116
|
+
if (rotation) {
|
|
117
|
+
group.rotation.set(0, 0, rotation);
|
|
118
|
+
}
|
|
119
|
+
group.name = id;
|
|
120
|
+
this.scene.add(group);
|
|
121
|
+
};
|
|
122
|
+
this.applyCameraTarget = (camera) => {
|
|
123
|
+
if (this.camera.type !== "OrthographicCamera") {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (camera) {
|
|
127
|
+
const cameraTarget = this.getOrthographicCameraTarget(camera);
|
|
128
|
+
this.updateCameraZoom(camera.zoom);
|
|
129
|
+
this.updateCamera(camera.position, cameraTarget);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
this.overridePointShader = (shader) => {
|
|
133
|
+
shader.vertexShader = `
|
|
2
134
|
attribute float sizes;
|
|
3
135
|
attribute float visibility;
|
|
4
136
|
varying float vVisible;
|
|
5
|
-
${
|
|
137
|
+
${shader.vertexShader}`.replace(`gl_PointSize = size;`, `gl_PointSize = size;
|
|
6
138
|
vVisible = visibility;
|
|
7
|
-
`)
|
|
139
|
+
`);
|
|
140
|
+
shader.fragmentShader = `
|
|
8
141
|
varying float vVisible;
|
|
9
|
-
${
|
|
142
|
+
${shader.fragmentShader}`.replace(`#include <clipping_planes_fragment>`, `
|
|
10
143
|
if (vVisible < 0.5) discard;
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>S(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:l}=yield this.cacheInstance.loadPCDFile(i),d=new c.BufferGeometry;d.setAttribute("position",new c.BufferAttribute(h,3)),d.setAttribute("color",new c.BufferAttribute(l,3));const p=new c.Points(d);this.renderPointCloud(p,o)}),this.loadPCDFileByBox=(i,o,h)=>S(this,null,function*(){const l=(g,x)=>S(this,null,function*(){const{width:u=0,height:m=0,depth:C=0}=h!=null?h:{},y=yield this.filterPointsByBox(P(M({},o),{width:o.width+u,height:o.height+m,depth:o.depth+C}),g,x);if(!y){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new c.Points(y.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:d,color:p}=yield this.cacheInstance.loadPCDFile(i);l(d,p)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new c.Vector3(1,0,0),h=new c.Vector3(i/2,0,0),l=2,d=16776960,p=new c.ArrowHelper(o,h,l,d);return p.visible=this.showDirection,p},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new c.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const h=new c.SpriteMaterial({map:o,depthWrite:!1}),l=new c.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const h=o.material.size;i?o.material.size=Math.min(h*1.2,10):o.material.size=Math.max(h/1.2,1),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new R(this.camera,this.renderer.domElement),this.pcdLoader=new E,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=W.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new c.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=B.getColorFromConfig({attribute:r.attribute},P(M({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,p=500/l;return{left:a,right:i,top:o,bottom:h,near:l,far:d,zoom:p}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:a,depth:i,rotation:o}=t,h=this.getCameraVector(n,o,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,n),new c.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,n),h)}updateCameraBySphere(t,e){const{center:r}=t,{radius:n}=z,s=this.getCameraVector(r,0,{width:n*2,height:n*2,depth:n*2},e);return this.updateCamera(s,r),s}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateOrthoCameraBySphere(t,e){const r=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new c.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:h}=A(t),l=e;r=r!=null?r:new Float32Array([]);const d={boxParams:t,zMin:i,zMax:o,polygonPointList:h,color:r,position:l};return new Promise(p=>{const g=new L;g.postMessage(d),g.onmessage=x=>{const{color:u,position:m,num:C}=x.data,y=new c.BufferGeometry;y.setAttribute("position",new c.Float32BufferAttribute(m,3)),y.setAttribute("color",new c.Float32BufferAttribute(u,3)),y.computeBoundingSphere(),g.terminate(),p({geometry:y,num:C})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=w.Front,s=X){let a=b.frontViewMatrix4(s);switch(n){case w.Front:break;case w.Back:a=b.backViewMatrix4(s);break;case w.Left:a=b.leftViewMatrix4(s);break;case w.Right:a=b.rightViewMatrix4(s);break;case w.Top:a=b.topViewMatrix4(s);break;case w.LFT:a=b.leftFrontTopViewMatrix4(s,r);break;case w.RBT:a=b.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new c.BufferGeometry().setFromPoints(r),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new c.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>A(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};j.postMessage(i),j.onmessage=o=>{const{color:h}=o.data,l=new c.BufferAttribute(h,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0),l.needsUpdate=!0,e.geometry.setAttribute("color",l),r(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new c.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((d,p)=>d.z-p.z);const r=Math.floor(e.length*.05),n=e[r];e=e.filter(({z:d})=>d>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((d,p)=>d.x-p.x);const i=Math.floor(e.length*s),o=Math.floor(e.length*(1-s));e=e.slice(i,o),e.sort((d,p)=>d.y-p.y);const h=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(h,l),e.length>100?e:t}getFittedCoordinates(t,e){const r=[];let n=[...t,t[0]];e.forEach(({x:i,y:o})=>{t.forEach((h,l)=>{const d=n[l+1],p=F.getFootOfPerpendicular({x:i,y:o},h,d,!1,!0).length;(!r[l]||p<r[l].distance)&&(r[l]={distance:p,point:{x:i,y:o}})})}),n=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,o)=>{const h=n[o],l=n[o+1],d=n[o+2];return k.getIntersectionBySlope({p1:s[o].point,k1:(h.y-l.y)/(h.x-l.x),p2:s[o+1].point,k2:(l.y-d.y)/(l.x-d.x)})})}getSensesPointZAxisInPolygon(t,e,r){var n,s,a;const i=this.scene.children.find(u=>u.uuid===this.pointsUuid);let o=0,h=0,l=0,d=0,p=[],g=[];const x=((a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let u=0;u<x.length;u+=3){const m=x[u],C=x[u+1],y=x[u+2];N({x:m,y:C},t)&&(y||y===0)&&g.push({x:m,y:C,z:y})}return g.length?(r&&(g=this.filterNoise(g),p=this.getFittedCoordinates(t,g)),g.sort((u,m)=>u.z-m.z),o=g[0].z-.01,h=g[g.length-1].z+.01,d=g.length,e&&(l=g.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:h,minZ:o,count:l,zCount:d,fittedCoordinates:p}):{maxZ:h,minZ:o,count:l,zCount:d,fittedCoordinates:p}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new c.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new c.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},h={x:e+a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2},d={x:e-a/2,y:r+s/2,z:n-i/2};return[o,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n-i/2},d={x:e-a/2,y:r-s/2,z:n+i/2};return[o,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e+a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r-s/2,z:n+i/2},d={x:e-a/2,y:r+s/2,z:n+i/2};return[o,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-r,-n),i=new c.Matrix4().makeTranslation(e,r,n),o=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,w.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,w.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case w.Left:return this.getPolygonSidePoints(t);case w.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(h,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:n,valid:s}=t,{radius:a}=z,i={center:e,attribute:r,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},o=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(o).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=h;const l=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),p=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,p)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:r}=z,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new c.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=P(M({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=P(M({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(m=>new c.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(a)),[o,h,l,d]=i,p=Math.max(Math.abs(o.x-l.x),Math.abs(o.x-h.x)),x=h.add(d).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:P(M({},n),{center:{x:n.center.x-x.x,y:n.center.y-x.y,z:n.center.z-r},width:p,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{Y as PointCloud};
|
|
144
|
+
#include <clipping_planes_fragment>`);
|
|
145
|
+
};
|
|
146
|
+
this.loadPCDFile = (src, radius) => __async(this, null, function* () {
|
|
147
|
+
this.clearPointCloud();
|
|
148
|
+
this.currentPCDSrc = src;
|
|
149
|
+
const {points, color} = yield this.cacheInstance.loadPCDFile(src);
|
|
150
|
+
const geometry = new THREE.BufferGeometry();
|
|
151
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(points, 3));
|
|
152
|
+
geometry.setAttribute("color", new THREE.BufferAttribute(color, 3));
|
|
153
|
+
const newPoints = new THREE.Points(geometry);
|
|
154
|
+
this.renderPointCloud(newPoints, radius);
|
|
155
|
+
});
|
|
156
|
+
this.loadPCDFileByBox = (src, boxParams, scope) => __async(this, null, function* () {
|
|
157
|
+
const cb = (points2, color2) => __async(this, null, function* () {
|
|
158
|
+
const {width = 0, height = 0, depth = 0} = scope != null ? scope : {};
|
|
159
|
+
const filterData = yield this.filterPointsByBox(__spreadProps(__spreadValues({}, boxParams), {
|
|
160
|
+
width: boxParams.width + width,
|
|
161
|
+
height: boxParams.height + height,
|
|
162
|
+
depth: boxParams.depth + depth
|
|
163
|
+
}), points2, color2);
|
|
164
|
+
if (!filterData) {
|
|
165
|
+
console.error("filter Error");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this.clearPointCloud();
|
|
169
|
+
this.currentPCDSrc = src;
|
|
170
|
+
const newPoints = new THREE.Points(filterData.geometry);
|
|
171
|
+
newPoints.name = this.pointCloudObjectName;
|
|
172
|
+
this.scene.add(newPoints);
|
|
173
|
+
this.render();
|
|
174
|
+
});
|
|
175
|
+
const {points, color} = yield this.cacheInstance.loadPCDFile(src);
|
|
176
|
+
cb(points, color);
|
|
177
|
+
});
|
|
178
|
+
this.generateRange = (radius) => {
|
|
179
|
+
const circle = this.createRange(radius);
|
|
180
|
+
this.scene.add(circle);
|
|
181
|
+
};
|
|
182
|
+
this.generateBoxArrow = ({width}) => {
|
|
183
|
+
const dir = new THREE.Vector3(1, 0, 0);
|
|
184
|
+
const origin = new THREE.Vector3(width / 2, 0, 0);
|
|
185
|
+
const arrowLen = 2;
|
|
186
|
+
const hex = 16776960;
|
|
187
|
+
const arrowHelper = new THREE.ArrowHelper(dir, origin, arrowLen, hex);
|
|
188
|
+
arrowHelper.visible = this.showDirection;
|
|
189
|
+
return arrowHelper;
|
|
190
|
+
};
|
|
191
|
+
this.generateBoxTrackID = (boxParams) => {
|
|
192
|
+
if (!boxParams.trackID) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const texture = new THREE.Texture(this.getTextCanvas(boxParams.trackID.toString()));
|
|
196
|
+
texture.needsUpdate = true;
|
|
197
|
+
const sprite = new THREE.SpriteMaterial({map: texture, depthWrite: false});
|
|
198
|
+
const boxID = new THREE.Sprite(sprite);
|
|
199
|
+
boxID.scale.set(5, 5, 5);
|
|
200
|
+
boxID.position.set(-boxParams.width / 2, 0, boxParams.depth / 2 + 0.5);
|
|
201
|
+
return boxID;
|
|
202
|
+
};
|
|
203
|
+
this.applyZAxisPoints = (zAxisLimit) => {
|
|
204
|
+
this.zAxisLimit = zAxisLimit;
|
|
205
|
+
this.filterZAxisPoints();
|
|
206
|
+
this.render();
|
|
207
|
+
};
|
|
208
|
+
this.updatePointSize = (zoomIn) => {
|
|
209
|
+
const points = this.scene.getObjectByName(this.pointCloudObjectName);
|
|
210
|
+
if (!points) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const preSize = points.material.size;
|
|
214
|
+
if (zoomIn) {
|
|
215
|
+
points.material.size = Math.min(preSize * 1.2, 10);
|
|
216
|
+
} else {
|
|
217
|
+
points.material.size = Math.max(preSize / 1.2, 1);
|
|
218
|
+
}
|
|
219
|
+
this.render();
|
|
220
|
+
};
|
|
221
|
+
this.container = container;
|
|
222
|
+
this.renderer = new THREE.WebGLRenderer({antialias: true});
|
|
223
|
+
this.backgroundColor = backgroundColor;
|
|
224
|
+
this.config = config;
|
|
225
|
+
if (isOrthographicCamera && orthographicParams) {
|
|
226
|
+
this.isOrthographicCamera = true;
|
|
227
|
+
this.camera = new THREE.OrthographicCamera(orthographicParams.left, orthographicParams.right, orthographicParams.top, orthographicParams.bottom, orthographicParams.near, orthographicParams.far);
|
|
228
|
+
} else {
|
|
229
|
+
this.camera = new THREE.PerspectiveCamera(30, this.containerWidth / this.containerHeight, 1, 1e3);
|
|
230
|
+
}
|
|
231
|
+
this.initCamera();
|
|
232
|
+
this.scene = new THREE.Scene();
|
|
233
|
+
this.controls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
234
|
+
this.pcdLoader = new PCDLoader();
|
|
235
|
+
this.axesHelper = new THREE.AxesHelper(1e3);
|
|
236
|
+
this.scene.add(this.camera);
|
|
237
|
+
if (!noAppend) {
|
|
238
|
+
container.appendChild(this.renderer.domElement);
|
|
239
|
+
}
|
|
240
|
+
this.init();
|
|
241
|
+
this.cacheInstance = PointCloudCache.getInstance();
|
|
242
|
+
}
|
|
243
|
+
get DEFAULT_INIT_CAMERA_POSITION() {
|
|
244
|
+
return new THREE.Vector3(-0.01, 0, 10);
|
|
245
|
+
}
|
|
246
|
+
get containerWidth() {
|
|
247
|
+
return this.container.clientWidth;
|
|
248
|
+
}
|
|
249
|
+
get containerHeight() {
|
|
250
|
+
return this.container.clientHeight;
|
|
251
|
+
}
|
|
252
|
+
setInitCameraPosition(vector) {
|
|
253
|
+
this.initCameraPosition = vector;
|
|
254
|
+
}
|
|
255
|
+
setConfig(config) {
|
|
256
|
+
this.config = config;
|
|
257
|
+
}
|
|
258
|
+
initOrthographicCamera(orthographicParams) {
|
|
259
|
+
if (this.camera.type !== "OrthographicCamera") {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const {left, right, top, bottom, near, far} = orthographicParams;
|
|
263
|
+
this.camera.left = left;
|
|
264
|
+
this.camera.right = right;
|
|
265
|
+
this.camera.top = top;
|
|
266
|
+
this.camera.bottom = bottom;
|
|
267
|
+
this.camera.near = near;
|
|
268
|
+
this.camera.far = far;
|
|
269
|
+
this.camera.updateProjectionMatrix();
|
|
270
|
+
}
|
|
271
|
+
initPerspectiveCamera() {
|
|
272
|
+
if (this.camera.type !== "PerspectiveCamera") {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
this.camera.fov = 30;
|
|
276
|
+
this.camera.aspect = this.containerWidth / this.containerHeight;
|
|
277
|
+
this.camera.near = 1;
|
|
278
|
+
this.camera.far = 1e3;
|
|
279
|
+
this.camera.updateProjectionMatrix();
|
|
280
|
+
}
|
|
281
|
+
initCamera() {
|
|
282
|
+
const {camera} = this;
|
|
283
|
+
if (this.isOrthographicCamera) {
|
|
284
|
+
const {x, y, z} = this.initCameraPosition;
|
|
285
|
+
camera.position.set(x, y, z);
|
|
286
|
+
} else {
|
|
287
|
+
camera.position.set(-1, 0, 500);
|
|
288
|
+
}
|
|
289
|
+
camera.up.set(0, 0, 1);
|
|
290
|
+
}
|
|
291
|
+
initControls() {
|
|
292
|
+
const {controls} = this;
|
|
293
|
+
controls.addEventListener("change", () => {
|
|
294
|
+
this.render();
|
|
295
|
+
});
|
|
296
|
+
this.setDefaultControls();
|
|
297
|
+
}
|
|
298
|
+
setDefaultControls() {
|
|
299
|
+
const {controls} = this;
|
|
300
|
+
const centerPoint = [0, 0, 0];
|
|
301
|
+
controls.target = new THREE.Vector3(...centerPoint);
|
|
302
|
+
controls.addEventListener("change", () => {
|
|
303
|
+
this.render();
|
|
304
|
+
});
|
|
305
|
+
controls.maxPolarAngle = Math.PI / 2;
|
|
306
|
+
controls.update();
|
|
307
|
+
}
|
|
308
|
+
initRenderer() {
|
|
309
|
+
const {renderer} = this;
|
|
310
|
+
renderer.setPixelRatio(window.devicePixelRatio);
|
|
311
|
+
renderer.setSize(this.containerWidth, this.containerHeight);
|
|
312
|
+
}
|
|
313
|
+
init() {
|
|
314
|
+
const {scene} = this;
|
|
315
|
+
scene.background = new THREE.Color(this.backgroundColor);
|
|
316
|
+
this.initControls();
|
|
317
|
+
this.initRenderer();
|
|
318
|
+
}
|
|
319
|
+
removeObjectByName(name) {
|
|
320
|
+
const oldBox = this.scene.getObjectByName(name);
|
|
321
|
+
if (oldBox) {
|
|
322
|
+
oldBox.removeFromParent();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
generateBox(boxParams, color = 16777215) {
|
|
326
|
+
const newColor = color;
|
|
327
|
+
this.AddBoxToSense(boxParams, newColor);
|
|
328
|
+
this.render();
|
|
329
|
+
}
|
|
330
|
+
getAllAttributeColor(boxes) {
|
|
331
|
+
return boxes.reduce((acc, box) => {
|
|
332
|
+
acc[box.attribute] = toolStyleConverter.getColorFromConfig({attribute: box.attribute}, __spreadProps(__spreadValues({}, this.config), {attributeConfigurable: true}), {});
|
|
333
|
+
return acc;
|
|
334
|
+
}, {});
|
|
335
|
+
}
|
|
336
|
+
generateBoxes(boxes) {
|
|
337
|
+
boxes.forEach((box) => {
|
|
338
|
+
this.generateBox(box);
|
|
339
|
+
});
|
|
340
|
+
this.render();
|
|
341
|
+
}
|
|
342
|
+
getOrthographicCamera(boxParams) {
|
|
343
|
+
const {center, width, height} = boxParams;
|
|
344
|
+
const offset = 10;
|
|
345
|
+
const left = center.x - width / 2 - offset;
|
|
346
|
+
const right = center.x - width / 2 + offset;
|
|
347
|
+
const top = center.y + height / 2 + offset;
|
|
348
|
+
const bottom = center.y - height / 2 - offset;
|
|
349
|
+
const near = 100;
|
|
350
|
+
const far = -100;
|
|
351
|
+
const zoom = 500 / near;
|
|
352
|
+
return {
|
|
353
|
+
left,
|
|
354
|
+
right,
|
|
355
|
+
top,
|
|
356
|
+
bottom,
|
|
357
|
+
near,
|
|
358
|
+
far,
|
|
359
|
+
zoom
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
updateCameraZoom(zoom) {
|
|
363
|
+
this.camera.zoom = zoom;
|
|
364
|
+
this.camera.updateProjectionMatrix();
|
|
365
|
+
}
|
|
366
|
+
updateCameraByBox(boxParams, perspectiveView, customCameraVector) {
|
|
367
|
+
const {center, width, height, depth, rotation} = boxParams;
|
|
368
|
+
const cameraPositionVector = this.getCameraVector(center, rotation, {width, height, depth}, perspectiveView);
|
|
369
|
+
if (customCameraVector) {
|
|
370
|
+
this.updateCamera(customCameraVector, center);
|
|
371
|
+
return new THREE.Vector3(customCameraVector.x, customCameraVector.y, customCameraVector.z);
|
|
372
|
+
}
|
|
373
|
+
this.updateCamera(cameraPositionVector, center);
|
|
374
|
+
return cameraPositionVector;
|
|
375
|
+
}
|
|
376
|
+
updateCameraBySphere(sphereParams, perspectiveView) {
|
|
377
|
+
const {center} = sphereParams;
|
|
378
|
+
const {radius} = DEFAULT_SPHERE_PARAMS;
|
|
379
|
+
const cameraPositionVector = this.getCameraVector(center, 0, {width: radius * 2, height: radius * 2, depth: radius * 2}, perspectiveView);
|
|
380
|
+
this.updateCamera(cameraPositionVector, center);
|
|
381
|
+
return cameraPositionVector;
|
|
382
|
+
}
|
|
383
|
+
updateOrthoCamera(boxParams, perspectiveView) {
|
|
384
|
+
const cameraPositionVector = this.updateCameraByBox(boxParams, perspectiveView);
|
|
385
|
+
this.camera.zoom = 1;
|
|
386
|
+
this.camera.updateProjectionMatrix();
|
|
387
|
+
return {
|
|
388
|
+
cameraPositionVector
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
updateOrthoCameraBySphere(sphereParams, perspectiveView) {
|
|
392
|
+
const cameraPositionVector = this.updateCameraBySphere(sphereParams, perspectiveView);
|
|
393
|
+
this.camera.zoom = 1;
|
|
394
|
+
this.camera.updateProjectionMatrix();
|
|
395
|
+
return {
|
|
396
|
+
cameraPositionVector
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
updateTopCamera() {
|
|
400
|
+
this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION);
|
|
401
|
+
this.camera.zoom = 1;
|
|
402
|
+
this.initCamera();
|
|
403
|
+
this.setDefaultControls();
|
|
404
|
+
this.camera.updateProjectionMatrix();
|
|
405
|
+
this.render();
|
|
406
|
+
}
|
|
407
|
+
updateCamera(position, target) {
|
|
408
|
+
this.camera.position.set(position.x, position.y, position.z);
|
|
409
|
+
this.controls.target = new THREE.Vector3(target.x, target.y, target.z);
|
|
410
|
+
this.controls.update();
|
|
411
|
+
}
|
|
412
|
+
resetCamera() {
|
|
413
|
+
this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION, {x: 0, y: 0, z: 0});
|
|
414
|
+
}
|
|
415
|
+
getOrthographicCameraTarget(camera) {
|
|
416
|
+
const direction = new THREE.Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
417
|
+
const target = camera.position.clone().add(direction);
|
|
418
|
+
return target;
|
|
419
|
+
}
|
|
420
|
+
createThreeMatrix4(matrix4) {
|
|
421
|
+
return new THREE.Matrix4().set(...matrix4);
|
|
422
|
+
}
|
|
423
|
+
filterPointsByBox(boxParams, points, color) {
|
|
424
|
+
var _a, _b, _c;
|
|
425
|
+
if (!points) {
|
|
426
|
+
const originPoints = this.scene.getObjectByName(this.pointCloudObjectName);
|
|
427
|
+
if (!originPoints) {
|
|
428
|
+
console.error("There is no corresponding point cloud object");
|
|
429
|
+
return Promise.resolve(void 0);
|
|
430
|
+
}
|
|
431
|
+
points = (_c = (_b = (_a = originPoints == null ? void 0 : originPoints.geometry) == null ? void 0 : _a.attributes) == null ? void 0 : _b.position) == null ? void 0 : _c.array;
|
|
432
|
+
}
|
|
433
|
+
if (window.Worker) {
|
|
434
|
+
const {zMin, zMax, polygonPointList} = getCuboidFromPointCloudBox(boxParams);
|
|
435
|
+
const position = points;
|
|
436
|
+
color = color != null ? color : new Float32Array([]);
|
|
437
|
+
const params = {
|
|
438
|
+
boxParams,
|
|
439
|
+
zMin,
|
|
440
|
+
zMax,
|
|
441
|
+
polygonPointList,
|
|
442
|
+
color,
|
|
443
|
+
position
|
|
444
|
+
};
|
|
445
|
+
return new Promise((resolve) => {
|
|
446
|
+
const filterBoxWorker = new WorkerFactory$1();
|
|
447
|
+
filterBoxWorker.postMessage(params);
|
|
448
|
+
filterBoxWorker.onmessage = (e) => {
|
|
449
|
+
const {color: newColor, position: newPosition, num} = e.data;
|
|
450
|
+
const geometry = new THREE.BufferGeometry();
|
|
451
|
+
geometry.setAttribute("position", new THREE.Float32BufferAttribute(newPosition, 3));
|
|
452
|
+
geometry.setAttribute("color", new THREE.Float32BufferAttribute(newColor, 3));
|
|
453
|
+
geometry.computeBoundingSphere();
|
|
454
|
+
filterBoxWorker.terminate();
|
|
455
|
+
resolve({geometry, num});
|
|
456
|
+
};
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
return Promise.resolve(void 0);
|
|
460
|
+
}
|
|
461
|
+
getCameraVector(centerPoint, rotationZ, volume, perspectiveView = EPerspectiveView.Front, defaultDistance = DEFAULT_DISTANCE) {
|
|
462
|
+
let TcMatrix4 = PerspectiveShiftUtils.frontViewMatrix4(defaultDistance);
|
|
463
|
+
switch (perspectiveView) {
|
|
464
|
+
case EPerspectiveView.Front:
|
|
465
|
+
break;
|
|
466
|
+
case EPerspectiveView.Back:
|
|
467
|
+
TcMatrix4 = PerspectiveShiftUtils.backViewMatrix4(defaultDistance);
|
|
468
|
+
break;
|
|
469
|
+
case EPerspectiveView.Left:
|
|
470
|
+
TcMatrix4 = PerspectiveShiftUtils.leftViewMatrix4(defaultDistance);
|
|
471
|
+
break;
|
|
472
|
+
case EPerspectiveView.Right:
|
|
473
|
+
TcMatrix4 = PerspectiveShiftUtils.rightViewMatrix4(defaultDistance);
|
|
474
|
+
break;
|
|
475
|
+
case EPerspectiveView.Top:
|
|
476
|
+
TcMatrix4 = PerspectiveShiftUtils.topViewMatrix4(defaultDistance);
|
|
477
|
+
break;
|
|
478
|
+
case EPerspectiveView.LFT:
|
|
479
|
+
TcMatrix4 = PerspectiveShiftUtils.leftFrontTopViewMatrix4(defaultDistance, volume);
|
|
480
|
+
break;
|
|
481
|
+
case EPerspectiveView.RBT:
|
|
482
|
+
TcMatrix4 = PerspectiveShiftUtils.rightBackTopViewMatrix4(defaultDistance, volume);
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
const Tc = this.createThreeMatrix4(TcMatrix4);
|
|
486
|
+
const TFrom = new THREE.Matrix4().makeTranslation(-centerPoint.x, -centerPoint.y, -centerPoint.z);
|
|
487
|
+
const TBack = new THREE.Matrix4().makeTranslation(centerPoint.x, centerPoint.y, centerPoint.z);
|
|
488
|
+
const Rz = new THREE.Matrix4().makeRotationZ(rotationZ);
|
|
489
|
+
const centerVector = new THREE.Vector3(centerPoint.x, centerPoint.y, centerPoint.z);
|
|
490
|
+
const cameraVector = centerVector.clone().applyMatrix4(Tc).applyMatrix4(TFrom).applyMatrix4(Rz).applyMatrix4(TBack);
|
|
491
|
+
return cameraVector;
|
|
492
|
+
}
|
|
493
|
+
createRange(radius) {
|
|
494
|
+
this.removeObjectByName(this.rangeObjectName);
|
|
495
|
+
const curve = new THREE.EllipseCurve(0, 0, radius, radius, 0, 2 * Math.PI, false, 0);
|
|
496
|
+
const points = curve.getPoints(50);
|
|
497
|
+
const geometry = new THREE.BufferGeometry().setFromPoints(points);
|
|
498
|
+
const material = new THREE.LineBasicMaterial({color: 16711680});
|
|
499
|
+
const ellipse = new THREE.Line(geometry, material);
|
|
500
|
+
ellipse.name = this.rangeObjectName;
|
|
501
|
+
return ellipse;
|
|
502
|
+
}
|
|
503
|
+
renderPointCloud(points, radius) {
|
|
504
|
+
points.name = this.pointCloudObjectName;
|
|
505
|
+
const pointsMaterial = new THREE.PointsMaterial({
|
|
506
|
+
vertexColors: true
|
|
507
|
+
});
|
|
508
|
+
pointsMaterial.onBeforeCompile = this.overridePointShader;
|
|
509
|
+
pointsMaterial.size = 1.2;
|
|
510
|
+
if (radius) {
|
|
511
|
+
this.generateRange(radius);
|
|
512
|
+
}
|
|
513
|
+
this.pointsUuid = points.uuid;
|
|
514
|
+
points.material = pointsMaterial;
|
|
515
|
+
this.filterZAxisPoints(points);
|
|
516
|
+
this.scene.add(points);
|
|
517
|
+
this.render();
|
|
518
|
+
}
|
|
519
|
+
clearPointCloud() {
|
|
520
|
+
this.removeObjectByName(this.pointCloudObjectName);
|
|
521
|
+
}
|
|
522
|
+
clearPointCloudAndRender() {
|
|
523
|
+
this.clearPointCloud();
|
|
524
|
+
this.render();
|
|
525
|
+
}
|
|
526
|
+
highlightOriginPointCloud(pointCloudBoxList) {
|
|
527
|
+
const oldPointCloud = this.scene.getObjectByName(this.pointCloudObjectName);
|
|
528
|
+
if (!oldPointCloud) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
this.highlightPCDSrc = this.currentPCDSrc;
|
|
532
|
+
return new Promise((resolve) => {
|
|
533
|
+
if (window.Worker) {
|
|
534
|
+
const newPointCloudBoxList = pointCloudBoxList ? [...pointCloudBoxList] : [];
|
|
535
|
+
const cuboidList = newPointCloudBoxList.map((v) => getCuboidFromPointCloudBox(v));
|
|
536
|
+
const colorList = this.getAllAttributeColor(cuboidList);
|
|
537
|
+
const params = {
|
|
538
|
+
cuboidList,
|
|
539
|
+
position: oldPointCloud.geometry.attributes.position.array,
|
|
540
|
+
color: oldPointCloud.geometry.attributes.color.array,
|
|
541
|
+
colorList
|
|
542
|
+
};
|
|
543
|
+
highlightWorker.postMessage(params);
|
|
544
|
+
highlightWorker.onmessage = (e) => {
|
|
545
|
+
const {color} = e.data;
|
|
546
|
+
const colorAttribute = new THREE.BufferAttribute(color, 3);
|
|
547
|
+
if (this.highlightPCDSrc) {
|
|
548
|
+
this.cacheInstance.updateColor(this.highlightPCDSrc, color);
|
|
549
|
+
this.highlightPCDSrc = void 0;
|
|
550
|
+
}
|
|
551
|
+
colorAttribute.needsUpdate = true;
|
|
552
|
+
oldPointCloud.geometry.setAttribute("color", colorAttribute);
|
|
553
|
+
resolve(color);
|
|
554
|
+
this.render();
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
updateColor(color) {
|
|
560
|
+
const oldPointCloud = this.scene.getObjectByName(this.pointCloudObjectName);
|
|
561
|
+
if (oldPointCloud) {
|
|
562
|
+
const colorAttribute = new THREE.BufferAttribute(color, 3);
|
|
563
|
+
colorAttribute.needsUpdate = true;
|
|
564
|
+
oldPointCloud.geometry.setAttribute("color", colorAttribute);
|
|
565
|
+
this.render();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
setShowDirection(showDirection) {
|
|
569
|
+
this.showDirection = showDirection;
|
|
570
|
+
this.scene.children.forEach((v) => {
|
|
571
|
+
if (v.type === "Group") {
|
|
572
|
+
v.children.forEach((object) => {
|
|
573
|
+
if (object.type === "ArrowHelper") {
|
|
574
|
+
object.visible = showDirection;
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
this.render();
|
|
580
|
+
}
|
|
581
|
+
getTextCanvas(text) {
|
|
582
|
+
const canvas = document.createElement("canvas");
|
|
583
|
+
const ctx = canvas.getContext("2d");
|
|
584
|
+
if (ctx) {
|
|
585
|
+
ctx.font = `${50}px " bold`;
|
|
586
|
+
ctx.fillStyle = "white";
|
|
587
|
+
ctx.textAlign = "center";
|
|
588
|
+
ctx.textBaseline = "middle";
|
|
589
|
+
ctx.fillText(text, canvas.width / 2, canvas.height / 2);
|
|
590
|
+
}
|
|
591
|
+
return canvas;
|
|
592
|
+
}
|
|
593
|
+
filterNoise(innerPointList) {
|
|
594
|
+
let newPointList = [...innerPointList];
|
|
595
|
+
newPointList.sort((a, b) => a.z - b.z);
|
|
596
|
+
const startIndexZ = Math.floor(newPointList.length * 0.05);
|
|
597
|
+
const roadPoint = newPointList[startIndexZ];
|
|
598
|
+
newPointList = newPointList.filter(({z}) => z > roadPoint.z + 0.1);
|
|
599
|
+
const noisePercent = 5e-3;
|
|
600
|
+
const endIndexZ = Math.floor(newPointList.length * (1 - noisePercent));
|
|
601
|
+
newPointList = newPointList.slice(0, endIndexZ);
|
|
602
|
+
newPointList.sort((a, b) => a.x - b.x);
|
|
603
|
+
const startIndexX = Math.floor(newPointList.length * noisePercent);
|
|
604
|
+
const endIndexX = Math.floor(newPointList.length * (1 - noisePercent));
|
|
605
|
+
newPointList = newPointList.slice(startIndexX, endIndexX);
|
|
606
|
+
newPointList.sort((a, b) => a.y - b.y);
|
|
607
|
+
const startIndexY = Math.floor(newPointList.length * noisePercent);
|
|
608
|
+
const endIndexY = Math.floor(newPointList.length * (1 - noisePercent));
|
|
609
|
+
newPointList = newPointList.slice(startIndexY, endIndexY);
|
|
610
|
+
return newPointList.length > 100 ? newPointList : innerPointList;
|
|
611
|
+
}
|
|
612
|
+
getFittedCoordinates(polygon, innerPointList) {
|
|
613
|
+
const minDistanceList = [];
|
|
614
|
+
let _polygon = [...polygon, polygon[0]];
|
|
615
|
+
innerPointList.forEach(({x, y}) => {
|
|
616
|
+
polygon.forEach((p1, index) => {
|
|
617
|
+
const p2 = _polygon[index + 1];
|
|
618
|
+
const distance = MathUtils.getFootOfPerpendicular({x, y}, p1, p2, false, true).length;
|
|
619
|
+
if (!minDistanceList[index] || distance < minDistanceList[index].distance) {
|
|
620
|
+
minDistanceList[index] = {distance, point: {x, y}};
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
_polygon = [polygon[polygon.length - 1], ...polygon, polygon[0]];
|
|
625
|
+
const _minDistanceList = [minDistanceList[minDistanceList.length - 1], ...minDistanceList];
|
|
626
|
+
const fittedCoordinates = polygon.map((_, index) => {
|
|
627
|
+
const p1 = _polygon[index];
|
|
628
|
+
const p2 = _polygon[index + 1];
|
|
629
|
+
const p3 = _polygon[index + 2];
|
|
630
|
+
return PointCloudUtils.getIntersectionBySlope({
|
|
631
|
+
p1: _minDistanceList[index].point,
|
|
632
|
+
k1: (p1.y - p2.y) / (p1.x - p2.x),
|
|
633
|
+
p2: _minDistanceList[index + 1].point,
|
|
634
|
+
k2: (p2.y - p3.y) / (p2.x - p3.x)
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
return fittedCoordinates;
|
|
638
|
+
}
|
|
639
|
+
getSensesPointZAxisInPolygon(polygon, zScope, intelligentFit) {
|
|
640
|
+
var _a, _b, _c;
|
|
641
|
+
const points = this.scene.children.find((i) => i.uuid === this.pointsUuid);
|
|
642
|
+
let minZ = 0;
|
|
643
|
+
let maxZ = 0;
|
|
644
|
+
let count = 0;
|
|
645
|
+
let zCount = 0;
|
|
646
|
+
let fittedCoordinates = [];
|
|
647
|
+
let innerPointList = [];
|
|
648
|
+
const pointPosArray = ((_c = (_b = (_a = points == null ? void 0 : points.geometry) == null ? void 0 : _a.attributes) == null ? void 0 : _b.position) == null ? void 0 : _c.array) || [];
|
|
649
|
+
for (let idx = 0; idx < pointPosArray.length; idx += 3) {
|
|
650
|
+
const x = pointPosArray[idx];
|
|
651
|
+
const y = pointPosArray[idx + 1];
|
|
652
|
+
const z = pointPosArray[idx + 2];
|
|
653
|
+
const inPolygon = isInPolygon({x, y}, polygon);
|
|
654
|
+
if (inPolygon && (z || z === 0)) {
|
|
655
|
+
innerPointList.push({x, y, z});
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (!innerPointList.length) {
|
|
659
|
+
return {maxZ, minZ, count, zCount, fittedCoordinates};
|
|
660
|
+
}
|
|
661
|
+
if (intelligentFit) {
|
|
662
|
+
innerPointList = this.filterNoise(innerPointList);
|
|
663
|
+
fittedCoordinates = this.getFittedCoordinates(polygon, innerPointList);
|
|
664
|
+
}
|
|
665
|
+
innerPointList.sort((a, b) => a.z - b.z);
|
|
666
|
+
minZ = innerPointList[0].z - 0.01;
|
|
667
|
+
maxZ = innerPointList[innerPointList.length - 1].z + 0.01;
|
|
668
|
+
zCount = innerPointList.length;
|
|
669
|
+
if (zScope) {
|
|
670
|
+
count = innerPointList.filter(({z}) => z >= zScope[0] && z <= zScope[1]).length;
|
|
671
|
+
}
|
|
672
|
+
return {maxZ, minZ, count, zCount, fittedCoordinates};
|
|
673
|
+
}
|
|
674
|
+
getBasicCoordinate2Canvas(vector) {
|
|
675
|
+
const w = this.containerWidth / 2;
|
|
676
|
+
const h = this.containerHeight / 2;
|
|
677
|
+
return {
|
|
678
|
+
x: vector.x * w + w,
|
|
679
|
+
y: vector.y * h + h,
|
|
680
|
+
z: vector.z
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
get basicCoordinate2CanvasMatrix4() {
|
|
684
|
+
const w = this.containerWidth / 2;
|
|
685
|
+
const h = this.containerHeight / 2;
|
|
686
|
+
return new THREE.Matrix4().set(w, 0, 0, w, 0, h, 0, h, 0, 0, 1, 0, 0, 0, 0, 1);
|
|
687
|
+
}
|
|
688
|
+
getCanvas2BasicCoordinate(vector) {
|
|
689
|
+
const w = this.containerWidth / 2;
|
|
690
|
+
const h = this.containerHeight / 2;
|
|
691
|
+
return new THREE.Vector3(vector.x / w - w / 2, -(vector.y / h - h / 2), 1);
|
|
692
|
+
}
|
|
693
|
+
getPolygonSidePoints(boxParams) {
|
|
694
|
+
const {
|
|
695
|
+
center: {x, y, z},
|
|
696
|
+
height,
|
|
697
|
+
width,
|
|
698
|
+
depth
|
|
699
|
+
} = boxParams;
|
|
700
|
+
const lfb = {
|
|
701
|
+
x: x + width / 2,
|
|
702
|
+
y: y + height / 2,
|
|
703
|
+
z: z - depth / 2
|
|
704
|
+
};
|
|
705
|
+
const lft = {
|
|
706
|
+
x: x + width / 2,
|
|
707
|
+
y: y + height / 2,
|
|
708
|
+
z: z + depth / 2
|
|
709
|
+
};
|
|
710
|
+
const lbt = {
|
|
711
|
+
x: x - width / 2,
|
|
712
|
+
y: y + height / 2,
|
|
713
|
+
z: z + depth / 2
|
|
714
|
+
};
|
|
715
|
+
const lbb = {
|
|
716
|
+
x: x - width / 2,
|
|
717
|
+
y: y + height / 2,
|
|
718
|
+
z: z - depth / 2
|
|
719
|
+
};
|
|
720
|
+
const vectorList = [lfb, lft, lbt, lbb];
|
|
721
|
+
return vectorList;
|
|
722
|
+
}
|
|
723
|
+
getPolygonBackPoints(boxParams) {
|
|
724
|
+
const {
|
|
725
|
+
center: {x, y, z},
|
|
726
|
+
height,
|
|
727
|
+
width,
|
|
728
|
+
depth
|
|
729
|
+
} = boxParams;
|
|
730
|
+
const lbt = {
|
|
731
|
+
x: x - width / 2,
|
|
732
|
+
y: y + height / 2,
|
|
733
|
+
z: z + depth / 2
|
|
734
|
+
};
|
|
735
|
+
const lbb = {
|
|
736
|
+
x: x - width / 2,
|
|
737
|
+
y: y + height / 2,
|
|
738
|
+
z: z - depth / 2
|
|
739
|
+
};
|
|
740
|
+
const rbb = {
|
|
741
|
+
x: x - width / 2,
|
|
742
|
+
y: y - height / 2,
|
|
743
|
+
z: z - depth / 2
|
|
744
|
+
};
|
|
745
|
+
const rbt = {
|
|
746
|
+
x: x - width / 2,
|
|
747
|
+
y: y - height / 2,
|
|
748
|
+
z: z + depth / 2
|
|
749
|
+
};
|
|
750
|
+
const vectorList = [lbt, lbb, rbb, rbt];
|
|
751
|
+
return vectorList;
|
|
752
|
+
}
|
|
753
|
+
getPolygonTopPoints(boxParams) {
|
|
754
|
+
const {
|
|
755
|
+
center: {x, y, z},
|
|
756
|
+
height,
|
|
757
|
+
width,
|
|
758
|
+
depth
|
|
759
|
+
} = boxParams;
|
|
760
|
+
const lft = {
|
|
761
|
+
x: x + width / 2,
|
|
762
|
+
y: y + height / 2,
|
|
763
|
+
z: z + depth / 2
|
|
764
|
+
};
|
|
765
|
+
const rft = {
|
|
766
|
+
x: x + width / 2,
|
|
767
|
+
y: y - height / 2,
|
|
768
|
+
z: z + depth / 2
|
|
769
|
+
};
|
|
770
|
+
const rbt = {
|
|
771
|
+
x: x - width / 2,
|
|
772
|
+
y: y - height / 2,
|
|
773
|
+
z: z + depth / 2
|
|
774
|
+
};
|
|
775
|
+
const lbt = {
|
|
776
|
+
x: x - width / 2,
|
|
777
|
+
y: y + height / 2,
|
|
778
|
+
z: z + depth / 2
|
|
779
|
+
};
|
|
780
|
+
const vectorList = [lft, rft, rbt, lbt];
|
|
781
|
+
return vectorList;
|
|
782
|
+
}
|
|
783
|
+
getModelTransformationMatrix(boxParams) {
|
|
784
|
+
const {
|
|
785
|
+
center: {x, y, z},
|
|
786
|
+
rotation
|
|
787
|
+
} = boxParams;
|
|
788
|
+
const TFrom = new THREE.Matrix4().makeTranslation(-x, -y, -z);
|
|
789
|
+
const TBack = new THREE.Matrix4().makeTranslation(x, y, z);
|
|
790
|
+
const Rz = new THREE.Matrix4().makeRotationZ(rotation);
|
|
791
|
+
return new THREE.Matrix4().multiply(TBack).multiply(Rz).multiply(TFrom);
|
|
792
|
+
}
|
|
793
|
+
getBoxSidePolygon2DCoordinate(boxParams) {
|
|
794
|
+
return this.getBoxPolygon2DCoordinate(boxParams, EPerspectiveView.Left);
|
|
795
|
+
}
|
|
796
|
+
getBoxBackPolygon2DCoordinate(boxParams) {
|
|
797
|
+
return this.getBoxPolygon2DCoordinate(boxParams, EPerspectiveView.Back);
|
|
798
|
+
}
|
|
799
|
+
getSphereSidePoint2DCoordinate(sphereParams) {
|
|
800
|
+
return this.getSpherePoint2DCoordinate(sphereParams);
|
|
801
|
+
}
|
|
802
|
+
getSphereBackPoint2DCoordinate(sphereParams) {
|
|
803
|
+
return this.getSpherePoint2DCoordinate(sphereParams);
|
|
804
|
+
}
|
|
805
|
+
boxParams2ViewPolygon(boxParams, perspectiveView) {
|
|
806
|
+
switch (perspectiveView) {
|
|
807
|
+
case EPerspectiveView.Left:
|
|
808
|
+
return this.getPolygonSidePoints(boxParams);
|
|
809
|
+
case EPerspectiveView.Back:
|
|
810
|
+
return this.getPolygonBackPoints(boxParams);
|
|
811
|
+
default: {
|
|
812
|
+
return this.getPolygonTopPoints(boxParams);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
getBoxPolygon2DCoordinate(boxParams, perspectiveView) {
|
|
817
|
+
const vectorList = this.boxParams2ViewPolygon(boxParams, perspectiveView);
|
|
818
|
+
const {width, height} = boxParams;
|
|
819
|
+
const projectMatrix = new THREE.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix);
|
|
820
|
+
const boxSideMatrix = new THREE.Matrix4().premultiply(this.getModelTransformationMatrix(boxParams)).premultiply(projectMatrix).premultiply(this.basicCoordinate2CanvasMatrix4);
|
|
821
|
+
this.sideMatrix = boxSideMatrix;
|
|
822
|
+
const polygon2d = vectorList.map((vector) => new THREE.Vector3(vector.x, vector.y, vector.z)).map((vector) => vector.applyMatrix4(this.sideMatrix));
|
|
823
|
+
const wZoom = this.containerWidth / width;
|
|
824
|
+
const hZoom = this.containerHeight / height;
|
|
825
|
+
return {
|
|
826
|
+
polygon2d,
|
|
827
|
+
zoom: Math.min(wZoom, hZoom) / 2
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
getSpherePoint2DCoordinate(sphereParams) {
|
|
831
|
+
const {center, attribute, id, valid} = sphereParams;
|
|
832
|
+
const {radius} = DEFAULT_SPHERE_PARAMS;
|
|
833
|
+
const transParams = {
|
|
834
|
+
center,
|
|
835
|
+
attribute,
|
|
836
|
+
id,
|
|
837
|
+
valid,
|
|
838
|
+
width: radius * 2,
|
|
839
|
+
height: radius * 2,
|
|
840
|
+
depth: radius * 2,
|
|
841
|
+
rotation: 0
|
|
842
|
+
};
|
|
843
|
+
const projectMatrix = new THREE.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix);
|
|
844
|
+
const boxSideMatrix = new THREE.Matrix4().premultiply(this.getModelTransformationMatrix(transParams)).premultiply(projectMatrix).premultiply(this.basicCoordinate2CanvasMatrix4);
|
|
845
|
+
this.sideMatrix = boxSideMatrix;
|
|
846
|
+
const point2d = new THREE.Vector3(center.x, center.y, center.z).applyMatrix4(this.sideMatrix);
|
|
847
|
+
const wZoom = this.containerWidth / (radius * 2);
|
|
848
|
+
const hZoom = this.containerHeight / (radius * 2);
|
|
849
|
+
return {
|
|
850
|
+
point2d,
|
|
851
|
+
zoom: Math.min(wZoom, hZoom) / 2
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
getSphereTopPoint2DCoordinate(sphereParams) {
|
|
855
|
+
const {center} = sphereParams;
|
|
856
|
+
const {radius} = DEFAULT_SPHERE_PARAMS;
|
|
857
|
+
const point2d = {
|
|
858
|
+
x: -(center.y - this.containerWidth / 2),
|
|
859
|
+
y: -(center.x - this.containerHeight / 2)
|
|
860
|
+
};
|
|
861
|
+
const wZoom = this.containerWidth / (radius * 2);
|
|
862
|
+
const hZoom = this.containerHeight / (radius * 2);
|
|
863
|
+
return {
|
|
864
|
+
point2d,
|
|
865
|
+
zoom: Math.min(wZoom, hZoom) / 2
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
getBoxTopPolygon2DCoordinate(boxParams) {
|
|
869
|
+
const {width, height} = boxParams;
|
|
870
|
+
const vectorList = this.getPolygonTopPoints(boxParams);
|
|
871
|
+
const polygon2d = vectorList.map((vector) => new THREE.Vector3(vector.x, vector.y, vector.z)).map((vector) => vector.applyMatrix4(this.getModelTransformationMatrix(boxParams))).map((vector) => {
|
|
872
|
+
return {
|
|
873
|
+
x: vector.y,
|
|
874
|
+
y: vector.x
|
|
875
|
+
};
|
|
876
|
+
}).map((vector) => {
|
|
877
|
+
return {
|
|
878
|
+
x: -(vector.x - this.containerWidth / 2),
|
|
879
|
+
y: -(vector.y - this.containerHeight / 2)
|
|
880
|
+
};
|
|
881
|
+
});
|
|
882
|
+
const wZoom = this.containerWidth / width;
|
|
883
|
+
const hZoom = this.containerHeight / height;
|
|
884
|
+
return {
|
|
885
|
+
polygon2d,
|
|
886
|
+
zoom: Math.min(wZoom, hZoom) / 2
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
getNewBoxBySideUpdate(offsetCenterPoint, offsetWidth, offsetDepth, selectedPointCloudBox) {
|
|
890
|
+
const Rz = new THREE.Matrix4().makeRotationZ(selectedPointCloudBox.rotation);
|
|
891
|
+
const offsetVector = new THREE.Vector3(-offsetCenterPoint.x, 0, 0).applyMatrix4(Rz);
|
|
892
|
+
let newBoxParams = selectedPointCloudBox;
|
|
893
|
+
newBoxParams.center = {
|
|
894
|
+
x: newBoxParams.center.x + offsetVector.x,
|
|
895
|
+
y: newBoxParams.center.y + offsetVector.y,
|
|
896
|
+
z: newBoxParams.center.z - offsetCenterPoint.z
|
|
897
|
+
};
|
|
898
|
+
newBoxParams = __spreadProps(__spreadValues({}, newBoxParams), {
|
|
899
|
+
width: newBoxParams.width + offsetWidth,
|
|
900
|
+
height: newBoxParams.height,
|
|
901
|
+
depth: newBoxParams.depth + offsetDepth
|
|
902
|
+
});
|
|
903
|
+
return {newBoxParams};
|
|
904
|
+
}
|
|
905
|
+
getNewBoxByBackUpdate(offsetCenterPoint, offsetWidth, offsetDepth, selectedPointCloudBox) {
|
|
906
|
+
const Rz = new THREE.Matrix4().makeRotationZ(selectedPointCloudBox.rotation);
|
|
907
|
+
const offsetVector = new THREE.Vector3(0, -offsetCenterPoint.x, 0).applyMatrix4(Rz);
|
|
908
|
+
let newBoxParams = selectedPointCloudBox;
|
|
909
|
+
newBoxParams.center = {
|
|
910
|
+
x: newBoxParams.center.x + offsetVector.x,
|
|
911
|
+
y: newBoxParams.center.y + offsetVector.y,
|
|
912
|
+
z: newBoxParams.center.z - offsetCenterPoint.z
|
|
913
|
+
};
|
|
914
|
+
newBoxParams = __spreadProps(__spreadValues({}, newBoxParams), {
|
|
915
|
+
width: newBoxParams.width,
|
|
916
|
+
height: newBoxParams.height + offsetWidth,
|
|
917
|
+
depth: newBoxParams.depth + offsetDepth
|
|
918
|
+
});
|
|
919
|
+
return {newBoxParams};
|
|
920
|
+
}
|
|
921
|
+
getNewBoxBySideUpdateByPoints(pointList, offsetHeight, offsetZ, selectedPointCloudBox) {
|
|
922
|
+
var _a;
|
|
923
|
+
const invertMatrix = (_a = this.sideMatrix) == null ? void 0 : _a.invert();
|
|
924
|
+
if (!this.sideMatrix || !invertMatrix) {
|
|
925
|
+
console.error("No sideMatrix");
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
this.camera.zoom = 1;
|
|
929
|
+
this.camera.updateProjectionMatrix();
|
|
930
|
+
const polygonWorld = pointList.map((vector) => new THREE.Vector3(vector.x, vector.y, vector.z)).map((vector) => vector.applyMatrix4(invertMatrix));
|
|
931
|
+
const [p1v, p2v, p3v, p4v] = polygonWorld;
|
|
932
|
+
const width = Math.max(Math.abs(p1v.x - p3v.x), Math.abs(p1v.x - p2v.x));
|
|
933
|
+
const centerVector = p2v.add(p4v).applyMatrix3(new THREE.Matrix3().set(1 / 2, 0, 0, 0, 1 / 2, 0, 0, 0, 1 / 2));
|
|
934
|
+
const offsetVector = centerVector.clone().applyMatrix3(new THREE.Matrix3().set(-1, 0, 0, 0, -1, 0, 0, 0, -1)).add(new THREE.Vector3(selectedPointCloudBox.center.x, selectedPointCloudBox.center.y, selectedPointCloudBox.center.z));
|
|
935
|
+
const newBoxParams = __spreadProps(__spreadValues({}, selectedPointCloudBox), {
|
|
936
|
+
center: {
|
|
937
|
+
x: selectedPointCloudBox.center.x - offsetVector.x,
|
|
938
|
+
y: selectedPointCloudBox.center.y - offsetVector.y,
|
|
939
|
+
z: selectedPointCloudBox.center.z - offsetZ
|
|
940
|
+
},
|
|
941
|
+
width,
|
|
942
|
+
height: selectedPointCloudBox.height,
|
|
943
|
+
depth: selectedPointCloudBox.depth + offsetHeight,
|
|
944
|
+
rotation: selectedPointCloudBox.rotation
|
|
945
|
+
});
|
|
946
|
+
return {newBoxParams};
|
|
947
|
+
}
|
|
948
|
+
filterZAxisPoints(pcdPoints) {
|
|
949
|
+
const points = pcdPoints || this.scene.children.find((i) => i.uuid === this.pointsUuid);
|
|
950
|
+
if (points) {
|
|
951
|
+
const {attributes} = points.geometry;
|
|
952
|
+
const {position} = attributes;
|
|
953
|
+
const visibility = [];
|
|
954
|
+
const {count} = position;
|
|
955
|
+
for (let i = 0; i < count; i++) {
|
|
956
|
+
const z = position.getZ(i);
|
|
957
|
+
visibility.push(z > this.zAxisLimit ? 0 : 1);
|
|
958
|
+
}
|
|
959
|
+
points.geometry.setAttribute("visibility", new THREE.Float32BufferAttribute(visibility, 1));
|
|
960
|
+
points.geometry.attributes.visibility.needsUpdate = true;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
render() {
|
|
964
|
+
this.renderer.render(this.scene, this.camera);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
export { PointCloud };
|