@labelbee/lb-annotation 1.14.0-alpha.3 → 1.14.0-alpha.6

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