@labelbee/lb-annotation 1.28.0-alpha.27 → 1.28.0-alpha.29

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.
@@ -1,4 +1,4 @@
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"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(b){if(b&&b.__esModule)return b;var t=Object.create(null);return b&&Object.keys(b).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return b[e]}})}}),t.default=b,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=(b,t,e)=>t in b?__defProp(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,__spreadValues=(b,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(b,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(b,e,t[e]);return b},__spreadProps=(b,t)=>__defProps(b,__getOwnPropDescs(t)),__async=(b,t,e)=>new Promise((i,r)=>{var s=c=>{try{o(e.next(c))}catch(u){r(u)}},a=c=>{try{o(e.throw(c))}catch(u){r(u)}},o=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,a);o((e=e.apply(b,t)).next())});const DEFAULT_DISTANCE=30;let highlightWorker=null;class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:o,checkMode:c,hiddenText:u=!1,view:f=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,h="blue")=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"sphere");const{radius:d,widthSegments:g,heightSegments:w}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:m}=n,x=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(d,g,w),C=new THREE__namespace.MeshBasicMaterial({color:h}),v=new THREE__namespace.Mesh(y,C);v.position.set(m.x,m.y,m.z),x.add(v),x.name=`sphere${p}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:h}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,h),this.render()},this.generateSpheres=n=>{n.forEach(h=>{const{fill:l}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(n,h=16777215)=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"box");const{center:d,width:g,height:w,depth:m,rotation:x}=n,y=new THREE__namespace.Group,C=new THREE__namespace.BoxGeometry(g,w,m),v=new THREE__namespace.MeshBasicMaterial({color:"blue"}),M=new THREE__namespace.Mesh(C,v),S=new THREE__namespace.BoxHelper(M,h),O=this.generateBoxArrow(n),P=this.generateBoxTrackID(n,h);P&&y.add(P);const B=this.generateBoxAttributeLabel(n,h);B&&y.add(B),y.add(S),y.add(O),d&&y.position.set(d.x,d.y,d.z),x&&y.rotation.set(0,0,x),y.name=`box${p}`;const L=new THREE__namespace.BoxGeometry(g,w,m),z=new THREE__namespace.MeshBasicMaterial({visible:!1}),A=new THREE__namespace.Mesh(L,z);y.add(A),y.userData={defaultColor:h,selectedID:p},this.scene.add(y)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const h=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,h)}},this.initShaderMaterial=()=>({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"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(b){if(b&&b.__esModule)return b;var t=Object.create(null);return b&&Object.keys(b).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return b[e]}})}}),t.default=b,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=(b,t,e)=>t in b?__defProp(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,__spreadValues=(b,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(b,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(b,e,t[e]);return b},__spreadProps=(b,t)=>__defProps(b,__getOwnPropDescs(t)),__async=(b,t,e)=>new Promise((i,r)=>{var s=c=>{try{o(e.next(c))}catch(d){r(d)}},h=c=>{try{o(e.throw(c))}catch(d){r(d)}},o=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,h);o((e=e.apply(b,t)).next())});const DEFAULT_DISTANCE=30;let highlightWorker=null;class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:c,hiddenText:d=!1,view:g=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.tipScopeObjectName="tipScope",this.highlightGroupName="highlightBoxes",this.cacheTipScopeList=[],this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,a="blue")=>{var l;const u=(l=n.id)!=null?l:uuid();this.removeObjectByName(u,"sphere");const{radius:p,widthSegments:f,heightSegments:w}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:m}=n,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(p,f,w),C=new THREE__namespace.MeshBasicMaterial({color:a}),v=new THREE__namespace.Mesh(x,C);v.position.set(m.x,m.y,m.z),y.add(v),y.name=`sphere${u}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:a}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,a),this.render()},this.generateSpheres=n=>{n.forEach(a=>{const{fill:l}=this.getColorFromConfig(a.attribute);this.addSphereToSense(a,l)}),this.render()},this.addBoxToSense=(n,a=16777215)=>{var l;const u=(l=n.id)!=null?l:uuid();this.removeObjectByName(u,"box");const{center:p,width:f,height:w,depth:m,rotation:y}=n,x=new THREE__namespace.Group,C=new THREE__namespace.BoxGeometry(f,w,m),v=new THREE__namespace.MeshBasicMaterial({color:"blue"}),M=new THREE__namespace.Mesh(C,v),B=new THREE__namespace.BoxHelper(M,a),O=this.generateBoxArrow(n),P=this.generateBoxTrackID(n,a);P&&x.add(P);const S=this.generateBoxAttributeLabel(n,a);S&&x.add(S),x.add(B),x.add(O),p&&x.position.set(p.x,p.y,p.z),y&&x.rotation.set(0,0,y),x.name=`box${u}`;const L=new THREE__namespace.BoxGeometry(f,w,m),T=new THREE__namespace.MeshBasicMaterial({visible:!1}),z=new THREE__namespace.Mesh(L,T);x.add(z),x.userData={defaultColor:a,selectedID:u},this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const a=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,a)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,6 +28,6 @@
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(h=this.currentPCDSrc,l){if(!h||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:p,color:d}=yield this.cacheInstance.loadPCDFile(h),g=new THREE__namespace.BufferGeometry;g.setAttribute("position",new THREE__namespace.BufferAttribute(p,3)),this.isSegment||g.setAttribute("dimensions",new THREE__namespace.BufferAttribute(d,3)),this.initCloudData(p);const w=new THREE__namespace.Points(g);this.renderPointCloud(w,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:h,points:l}){const p=m=>__async(this,null,function*(){try{return yield ImgUtils.default.load(m)}catch(x){return console.error("Error loading image:",x),null}}),d=h.length===0?[]:(yield Promise.all(h.map(m=>__async(this,null,function*(){let x=yield p(m.url);return!x&&m.fallbackUrl&&(x=yield p(m.fallbackUrl)),x})))).filter(m=>m!==null),g=h.map((m,x)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?y:[];const C=matrix.getHighlightIndexByPoints({points:l,calib:m.calib,width:d[x].width,height:d[x].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,C),C});return matrix.mergeHighlightList(g)}),this.filterPreResult=(n,h,l)=>__async(this,null,function*(){const{points:p}=yield this.cacheInstance.loadPCDFile(n),d=yield this.cacheInstance.loadIndexMap(n,p);return new Promise(g=>{const w=l.map(m=>{const x=MathUtils.default.calculatePointsInsideBox({indexMap:d,polygon:matrix.getCuboidFromPointCloudBox(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),y=x>=h.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},m),{valid:y,count:x})});g(w)})}),this.loadPCDFileByBox=(n,h,l)=>__async(this,null,function*(){const p=(w,m)=>__async(this,null,function*(){const{width:x=0,height:y=0,depth:C=0}=l!=null?l:{},v=yield this.filterPointsByBox(__spreadProps(__spreadValues({},h),{width:h.width+x,height:h.height+y,depth:h.depth+C}),w,m);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const M=new THREE__namespace.Points(v.geometry);M.name=this.pointCloudObjectName,this.scene.add(M),this.render()}),{points:d,color:g}=yield this.cacheInstance.loadPCDFile(n);p(d,g)}),this.generateRange=n=>{const h=this.createRange(n);this.scene.add(h)},this.generateBoxArrow=({width:n})=>{const h=new THREE__namespace.Vector3(1,0,0),l=new THREE__namespace.Vector3(n/2,0,0),p=2,d=new THREE__namespace.ArrowHelper(h,l,p,this.highlightColor);return d.visible=this.showDirection,d},this.generateLabel=(n,h,l)=>{const p=this.getTextCanvas(n),d=new THREE__namespace.Texture(p);d.minFilter=THREE__namespace.LinearFilter,d.magFilter=THREE__namespace.LinearFilter,d.needsUpdate=!0;const g=p.width/window.devicePixelRatio,w=p.height/window.devicePixelRatio,m=new THREE__namespace.SpriteMaterial({map:d,depthWrite:!1,color:l}),x=new THREE__namespace.Sprite(m);return x.scale.set(g/h,w/h,1),{sprite:x,canvasWidth:g,canvasHeight:w}},this.generateBoxTrackID=(n,h)=>{if(!n.trackID)return;const{sprite:l}=this.generateLabel(n.trackID.toString(),50,h);return l.position.set(-n.width/2,0,n.depth/2+.5),l},this.generateBoxAttributeLabel=(n,h)=>{if(!n.attribute||this.hiddenText)return;const l=this.findSubAttributeLabel(n,this.config),p=l?`${n.attribute}
32
- ${l}`:`${n.attribute}`,{sprite:d,canvasHeight:g}=this.generateLabel(p,100,h);return d.position.set(-n.width/2,0,-n.depth/2-g/150),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const p=l.material.uniforms.pointSize.value;n?l.material.uniforms.pointSize.value=Math.min(p*1.2,10):l.material.uniforms.pointSize.value=Math.max(p/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=c!=null?c:!1,this.hiddenText=u,this.view=f,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.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,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.filterBoxWorker=new filterBoxWorker,this.geometry=new THREE__namespace.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var h,l,p;const d=this.renderer.domElement.getBoundingClientRect(),g=n.originalEvent.clientX-d.left,w=n.originalEvent.clientY-d.top;this.pointer.x=g/d.width*2-1,this.pointer.y=-(w/d.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(y=>{y instanceof THREE__namespace.Group&&y.children.forEach(C=>{C instanceof THREE__namespace.Mesh?m.push(C):this.updateMaterialColor(C,y.userData.defaultColor)})});const x=this.raycaster.intersectObjects(m,!1);if(x.length>0){const y=x[0].object.parent;y==null||y.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(h=this.pipe)==null||h.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(y==null?void 0:y.userData.selectedID)}else(p=this.pipe)==null||p.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof THREE__namespace.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof THREE__namespace.BoxHelper||t instanceof THREE__namespace.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,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:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}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,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,c=e.y+r/2+s,u=e.y-r/2-s,f=100,n=-100,h=500/f;return{left:a,right:o,top:c,bottom:u,near:f,far:n,zoom:h}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:c}=t,u=this.getCameraVector(r,c,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:c,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),f=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:c,polygonPointList:u,color:i,position:f};return this.filterBoxWorker||(this.filterBoxWorker=new filterBoxWorker),new Promise(h=>{var l;(l=this.filterBoxWorker)==null||l.postMessage(n),this.filterBoxWorker.onmessage=p=>{const{color:d,position:g,num:w}=p.data;this.geometry.dispose(),this.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),this.geometry.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),h({geometry:this.geometry,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){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,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),c=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(c).applyMatrix4(f).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{highlightWorker&&(highlightWorker.terminate(),highlightWorker=null),highlightWorker=new highlightWorker$1({type:"module"}),highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),highlightWorker==null||highlightWorker.terminate(),highlightWorker=null},highlightWorker.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:a}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((c,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(g=>matrix.getCuboidFromPointCloudBox(g)),h=this.getAllAttributeColor(n),l=o.geometry.attributes.position.array,p=o.geometry.attributes.dimensions.array,d={cuboidList:n,position:l,color:p,colorList:h,highlightIndex:i,modifiedBoxIds:s,resetAreas:a};this.handleWebworker(d).then(g=>{const{color:w}=g;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==w.length){u(new Error("Error Path"));return}let m=w;(s.length||a.length)&&(m=w.map((C,v)=>C===-1?p[v]:C));const x=new THREE__namespace.BufferAttribute(m,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const y={color:m,view:this.view,currentPCDSrc:this.currentPCDSrc};c(y),this.workerLoading=!1,this.render()}).catch(g=>{this.workerLoading=!1,u(g)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:c,depth:u,rotation:f}=i,{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),h=new THREE__namespace.BoxGeometry(o,c,u),l=new THREE__namespace.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});h.rotateZ(f),h.translate(r,s,a);const p=new THREE__namespace.Mesh(h,l);e.add(p);const d=new THREE__namespace.PlaneGeometry(u,c);d.rotateY(Math.PI/2),d.rotateZ(f);const g=new THREE__namespace.Vector3(o/2,0,0),w=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(f);g.applyMatrix4(w),d.translate(r+g.x,s+g.y,a+g.z);const m=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new THREE__namespace.Mesh(d,m);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new THREE__namespace.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(a=>{const o=i.find(n=>n.value===a);if(!o||!o.subSelected)return;const{key:c,subSelected:u}=o,f=[];u.forEach(n=>{var h;const l=(h=t.subAttribute)==null?void 0:h[a],p=Array.isArray(l)?l:l==null?void 0:l.split(";");(p==null?void 0:p.includes(n.value))&&f.push(n.key)}),f.length>0&&(r&&(r+="\u3001"),r+=`${c}:${f.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const a=t.split(`
33
- `),o=Math.max(...a.map(n=>i.measureText(n).width)),c=Math.ceil(o),u=s*1.5,f=u*a.length;e.width=c*r,e.height=f*r,e.style.width=`${c}px`,e.style.height=`${f}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",a.forEach((n,h)=>{i.fillText(n,0,h*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,h)=>n.z-h.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((n,h)=>n.x-h.x);const o=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));e=e.slice(o,c),e.sort((n,h)=>n.y-h.y);const u=Math.floor(e.length*s),f=Math.floor(e.length*(1-s));return e=e.slice(u,f),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:c,y:u})=>{t.forEach((f,n)=>{const h=r[n+1],l=MathUtils.default.getFootOfPerpendicular({x:c,y:u},f,h,!1,!0).length;(!i[n]||l<i[n].distance)&&(i[n]={distance:l,point:{x:c,y:u}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((c,u)=>{const f=r[u],n=r[u+1],h=r[u+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[u].point,line1:[f,n],p2:s[u+1].point,line2:[n,h]})});return a.some(c=>!(Number.isFinite(c.x)&&Number.isFinite(c.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(d=>d.uuid===this.pointsUuid);let c=0,u=0,f=0,n=0,h=[],l=[];const p=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let d=0;d<p.length;d+=3){const g=p[d],w=p[d+1],m=p[d+2];polygonTool.isInPolygon({x:g,y:w},t)&&(m||m===0)&&l.push({x:g,y:w,z:m})}return l.length?(i&&(l=this.filterNoise(l),h=this.getFittedCoordinates(t,l)),l.sort((d,g)=>d.z-g.z),c=l[0].z-.01,u=l[l.length-1].z+.01,n=l.length,e&&(f=l.filter(({z:d})=>d>=e[0]&&d<=e[1]).length),{maxZ:u,minZ:c,count:f,zCount:n,fittedCoordinates:h}):{maxZ:u,minZ:c,count:f,zCount:n,fittedCoordinates:h}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,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,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e+a/2,y:i+s/2,z:r-o/2},u={x:e+a/2,y:i+s/2,z:r+o/2},f={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2};return[c,u,f,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e-a/2,y:i+s/2,z:r+o/2},u={x:e-a/2,y:i+s/2,z:r-o/2},f={x:e-a/2,y:i-s/2,z:r-o/2},n={x:e-a/2,y:i-s/2,z:r+o/2};return[c,u,f,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e+a/2,y:i+s/2,z:r+o/2},u={x:e+a/2,y:i-s/2,z:r+o/2},f={x:e-a/2,y:i-s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r+o/2};return[c,u,f,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),c=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(c).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 i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const c=i.map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,f=this.containerHeight/s;return{polygon2d:c,zoom:Math.min(u,f)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},c=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const f=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(a*2),h=this.containerHeight/(a*2);return{point2d:f,zoom:Math.min(n,h)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(c=>new THREE__namespace.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.getModelTransformationMatrix(t))).map(c=>({x:c.y,y:c.x})).map(c=>({x:-(c.x-this.containerWidth/2),y:-(c.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){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 o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[c,u,f,n]=o,h=Math.max(Math.abs(c.x-f.x),Math.abs(c.x-u.x)),p=u.add(n).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(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-p.x,y:r.center.y-p.y,z:r.center.z-i},width:h,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const c=r.getZ(o);s.push(c>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.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(a=this.currentPCDSrc,l,u){if(!a||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=a;const{points:p,color:f}=yield this.cacheInstance.loadPCDFile(a),w=new THREE__namespace.BufferGeometry;w.setAttribute("position",new THREE__namespace.BufferAttribute(p,3)),this.isSegment||w.setAttribute("dimensions",new THREE__namespace.BufferAttribute(f,3)),this.initCloudData(p);const m=new THREE__namespace.Points(w);this.renderPointCloud(m,l,u),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:a,points:l}){const u=m=>__async(this,null,function*(){try{return yield ImgUtils.default.load(m)}catch(y){return console.error("Error loading image:",y),null}}),p=a.length===0?[]:(yield Promise.all(a.map(m=>__async(this,null,function*(){let y=yield u(m.url);return!y&&m.fallbackUrl&&(y=yield u(m.fallbackUrl)),y})))).filter(m=>m!==null),f=a.map((m,y)=>{var x;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(x=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?x:[];const C=matrix.getHighlightIndexByPoints({points:l,calib:m.calib,width:p[y].width,height:p[y].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,C),C});return matrix.mergeHighlightList(f)}),this.filterPreResult=(n,a,l)=>__async(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),p=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(f=>{const w=l.map(m=>{const y=MathUtils.default.calculatePointsInsideBox({indexMap:p,polygon:matrix.getCuboidFromPointCloudBox(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),x=y>=a.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},m),{valid:x,count:y})});f(w)})}),this.loadPCDFileByBox=(n,a,l)=>__async(this,null,function*(){const u=(w,m)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:C=0}=l!=null?l:{},v=yield this.filterPointsByBox(__spreadProps(__spreadValues({},a),{width:a.width+y,height:a.height+x,depth:a.depth+C}),w,m);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const M=new THREE__namespace.Points(v.geometry);M.name=this.pointCloudObjectName,this.scene.add(M),this.render()}),{points:p,color:f}=yield this.cacheInstance.loadPCDFile(n);u(p,f)}),this.generateRange=n=>{const a=this.createRange(n);this.scene.add(a)},this.generateTipScopeList=n=>{this.cacheTipScopeList.forEach((a,l)=>{this.removeObjectByName(this.tipScopeObjectName+l)}),n.forEach((a,l)=>{const u=this.createTipScope(a,l);u&&this.scene.add(u)}),this.cacheTipScopeList=n},this.generateBoxArrow=({width:n})=>{const a=new THREE__namespace.Vector3(1,0,0),l=new THREE__namespace.Vector3(n/2,0,0),u=2,p=new THREE__namespace.ArrowHelper(a,l,u,this.highlightColor);return p.visible=this.showDirection,p},this.generateLabel=(n,a,l)=>{const u=this.getTextCanvas(n),p=new THREE__namespace.Texture(u);p.minFilter=THREE__namespace.LinearFilter,p.magFilter=THREE__namespace.LinearFilter,p.needsUpdate=!0;const f=u.width/window.devicePixelRatio,w=u.height/window.devicePixelRatio,m=new THREE__namespace.SpriteMaterial({map:p,depthWrite:!1,color:l}),y=new THREE__namespace.Sprite(m);return y.scale.set(f/a,w/a,1),{sprite:y,canvasWidth:f,canvasHeight:w}},this.generateBoxTrackID=(n,a)=>{if(!n.trackID)return;const{sprite:l}=this.generateLabel(n.trackID.toString(),50,a);return l.position.set(-n.width/2,0,n.depth/2+.5),l},this.generateBoxAttributeLabel=(n,a)=>{if(!n.attribute||this.hiddenText)return;const l=this.findSubAttributeLabel(n,this.config),u=l?`${n.attribute}
32
+ ${l}`:`${n.attribute}`,{sprite:p,canvasHeight:f}=this.generateLabel(u,100,a);return p.position.set(-n.width/2,0,-n.depth/2-f/150),p},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:a})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const u=l.material.uniforms.pointSize.value;n?l.material.uniforms.pointSize.value=Math.min(u*1.2,10):l.material.uniforms.pointSize.value=Math.max(u/1.2,1),a&&(l.material.uniforms.pointSize.value=a,this.pointsMaterialSize=a),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=c!=null?c:!1,this.hiddenText=d,this.view=g,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.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,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.filterBoxWorker=new filterBoxWorker,this.geometry=new THREE__namespace.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var a,l,u;const p=this.renderer.domElement.getBoundingClientRect(),f=n.originalEvent.clientX-p.left,w=n.originalEvent.clientY-p.top;this.pointer.x=f/p.width*2-1,this.pointer.y=-(w/p.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(x=>{x instanceof THREE__namespace.Group&&x.children.forEach(C=>{C instanceof THREE__namespace.Mesh?m.push(C):this.updateMaterialColor(C,x.userData.defaultColor)})});const y=this.raycaster.intersectObjects(m,!1);if(y.length>0){const x=y[0].object.parent;x==null||x.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(a=this.pipe)==null||a.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(x==null?void 0:x.userData.selectedID)}else(u=this.pipe)==null||u.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof THREE__namespace.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof THREE__namespace.BoxHelper||t instanceof THREE__namespace.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,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:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}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,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,c=e.y+r/2+s,d=e.y-r/2-s,g=100,n=-100,a=500/g;return{left:h,right:o,top:c,bottom:d,near:g,far:n,zoom:a}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:c}=t,d=this.getCameraVector(r,c,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(d,r),d)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:c,polygonPointList:d}=matrix.getCuboidFromPointCloudBox(t),g=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:c,polygonPointList:d,color:i,position:g};return this.filterBoxWorker||(this.filterBoxWorker=new filterBoxWorker),new Promise(a=>{var l;(l=this.filterBoxWorker)==null||l.postMessage(n),this.filterBoxWorker.onmessage=u=>{const{color:p,position:f,num:w}=u.data;this.geometry.dispose(),this.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(f,3)),this.geometry.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),a({geometry:this.geometry,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),c=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),d=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),g=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(c).applyMatrix4(g).applyMatrix4(d)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,s);return h.name=this.rangeObjectName,h}createTipScope(t,e){this.removeObjectByName(this.tipScopeObjectName+e);let i=null;const{scopeType:r,range:s}=t;if(r==="circle"){const o=new THREE__namespace.EllipseCurve(0,0,Number(s.radius),Number(s.radius),0,2*Math.PI,!1,0).getPoints(50),c=new THREE__namespace.BufferGeometry().setFromPoints(o),d=new THREE__namespace.LineBasicMaterial({color:16711680});i=new THREE__namespace.Line(c,d)}else if(r==="rect"){const{top:h=0,bottom:o=0,left:c=0,right:d=0}=s,g=c,n=-d,a=h,l=-o,u=new THREE__namespace.Shape;u.moveTo(a,g),u.lineTo(l,g),u.lineTo(l,n),u.lineTo(a,n),u.lineTo(a,g);const p=new THREE__namespace.BufferGeometry().setFromPoints(u.getPoints()),f=new THREE__namespace.LineBasicMaterial({color:16711680});i=new THREE__namespace.Line(p,f)}return i?(i.name=this.tipScopeObjectName+e,i):null}renderPointCloud(t,e,i){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const r=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),i&&this.generateTipScopeList(i),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{highlightWorker&&(highlightWorker.terminate(),highlightWorker=null),highlightWorker=new highlightWorker$1({type:"module"}),highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),highlightWorker==null||highlightWorker.terminate(),highlightWorker=null},highlightWorker.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:h}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((c,d)=>{if(window.Worker){const n=(e?[...e]:[]).map(f=>matrix.getCuboidFromPointCloudBox(f)),a=this.getAllAttributeColor(n),l=o.geometry.attributes.position.array,u=o.geometry.attributes.dimensions.array,p={cuboidList:n,position:l,color:u,colorList:a,highlightIndex:i,modifiedBoxIds:s,resetAreas:h};this.handleWebworker(p).then(f=>{const{color:w}=f;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==w.length){d(new Error("Error Path"));return}let m=w;(s.length||h.length)&&(m=w.map((C,v)=>C===-1?u[v]:C));const y=new THREE__namespace.BufferAttribute(m,3);this.highlightPCDSrc=void 0,y.needsUpdate=!0,o.geometry.setAttribute("dimensions",y),o.geometry.attributes.dimensions.needsUpdate=!0;const x={color:m,view:this.view,currentPCDSrc:this.currentPCDSrc};c(x),this.workerLoading=!1,this.render()}).catch(f=>{this.workerLoading=!1,d(f)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:c,depth:d,rotation:g}=i,{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),a=new THREE__namespace.BoxGeometry(o,c,d),l=new THREE__namespace.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});a.rotateZ(g),a.translate(r,s,h);const u=new THREE__namespace.Mesh(a,l);e.add(u);const p=new THREE__namespace.PlaneGeometry(d,c);p.rotateY(Math.PI/2),p.rotateZ(g);const f=new THREE__namespace.Vector3(o/2,0,0),w=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(g);f.applyMatrix4(w),p.translate(r+f.x,s+f.y,h+f.z);const m=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),y=new THREE__namespace.Mesh(p,m);e.add(y)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new THREE__namespace.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(h=>{const o=i.find(n=>n.value===h);if(!o||!o.subSelected)return;const{key:c,subSelected:d}=o,g=[];d.forEach(n=>{var a;const l=(a=t.subAttribute)==null?void 0:a[h],u=Array.isArray(l)?l:l==null?void 0:l.split(";");(u==null?void 0:u.includes(n.value))&&g.push(n.key)}),g.length>0&&(r&&(r+="\u3001"),r+=`${c}:${g.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const h=t.split(`
33
+ `),o=Math.max(...h.map(n=>i.measureText(n).width)),c=Math.ceil(o),d=s*1.5,g=d*h.length;e.width=c*r,e.height=g*r,e.style.width=`${c}px`,e.style.height=`${g}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((n,a)=>{i.fillText(n,0,a*d)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,a)=>n.z-a.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((n,a)=>n.x-a.x);const o=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));e=e.slice(o,c),e.sort((n,a)=>n.y-a.y);const d=Math.floor(e.length*s),g=Math.floor(e.length*(1-s));return e=e.slice(d,g),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:c,y:d})=>{t.forEach((g,n)=>{const a=r[n+1],l=MathUtils.default.getFootOfPerpendicular({x:c,y:d},g,a,!1,!0).length;(!i[n]||l<i[n].distance)&&(i[n]={distance:l,point:{x:c,y:d}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((c,d)=>{const g=r[d],n=r[d+1],a=r[d+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[d].point,line1:[g,n],p2:s[d+1].point,line2:[n,a]})});return h.some(c=>!(Number.isFinite(c.x)&&Number.isFinite(c.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let c=0,d=0,g=0,n=0,a=[],l=[];const u=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<u.length;p+=3){const f=u[p],w=u[p+1],m=u[p+2];polygonTool.isInPolygon({x:f,y:w},t)&&(m||m===0)&&l.push({x:f,y:w,z:m})}return l.length?(i&&(l=this.filterNoise(l),a=this.getFittedCoordinates(t,l)),l.sort((p,f)=>p.z-f.z),c=l[0].z-.01,d=l[l.length-1].z+.01,n=l.length,e&&(g=l.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:d,minZ:c,count:g,zCount:n,fittedCoordinates:a}):{maxZ:d,minZ:c,count:g,zCount:n,fittedCoordinates:a}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,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,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,c={x:e+h/2,y:i+s/2,z:r-o/2},d={x:e+h/2,y:i+s/2,z:r+o/2},g={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2};return[c,d,g,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,c={x:e-h/2,y:i+s/2,z:r+o/2},d={x:e-h/2,y:i+s/2,z:r-o/2},g={x:e-h/2,y:i-s/2,z:r-o/2},n={x:e-h/2,y:i-s/2,z:r+o/2};return[c,d,g,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,c={x:e+h/2,y:i+s/2,z:r+o/2},d={x:e+h/2,y:i-s/2,z:r+o/2},g={x:e-h/2,y:i-s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r+o/2};return[c,d,g,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),c=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(c).multiply(h)}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 i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const c=i.map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),d=this.containerWidth/r,g=this.containerHeight/s;return{polygon2d:c,zoom:Math.min(d,g)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},c=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),d=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=d;const g=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(h*2),a=this.containerHeight/(h*2);return{point2d:g,zoom:Math.min(n,a)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(c=>new THREE__namespace.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.getModelTransformationMatrix(t))).map(c=>({x:c.y,y:c.x})).map(c=>({x:-(c.x-this.containerWidth/2),y:-(c.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(f=>new THREE__namespace.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(h)),[c,d,g,n]=o,a=Math.max(Math.abs(c.x-g.x),Math.abs(c.x-d.x)),u=d.add(n).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(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-u.x,y:r.center.y-u.y,z:r.center.z-i},width:a,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const c=r.getZ(o);s.push(c>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.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -4,7 +4,7 @@
4
4
  * @author Ron <ron.f.luo@gmail.com>
5
5
  */
6
6
  import * as THREE from 'three';
7
- import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig, ICalib, IPointCloudBoxList } from '@labelbee/lb-utils';
7
+ import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig, ICalib, IPointCloudBoxList, ITipScopeParams } from '@labelbee/lb-utils';
8
8
  import { BufferAttribute, OrthographicCamera, PerspectiveCamera } from 'three';
9
9
  import { IPolygonPoint } from '@/types/tool/polygon';
10
10
  import { PCDLoader } from './PCDLoader';
@@ -71,7 +71,9 @@ export declare class PointCloud extends EventListener {
71
71
  private backgroundColor;
72
72
  private pointCloudObjectName;
73
73
  private rangeObjectName;
74
+ private tipScopeObjectName;
74
75
  private highlightGroupName;
76
+ private cacheTipScopeList;
75
77
  private cacheInstance;
76
78
  private showDirection;
77
79
  private currentPCDSrc?;
@@ -231,6 +233,8 @@ export declare class PointCloud extends EventListener {
231
233
  } | undefined>;
232
234
  getCameraVector(centerPoint: I3DSpaceCoord, rotationZ: number, volume: IVolume, perspectiveView?: EPerspectiveView, defaultDistance?: number): THREE.Vector3;
233
235
  createRange(radius: number): THREE.Line<THREE.BufferGeometry, THREE.LineBasicMaterial>;
236
+ /** Create prompt range */
237
+ createTipScope(tipScope: ITipScopeParams, index: number): THREE.Object3D<THREE.Event> | null;
234
238
  initShaderMaterial: () => {
235
239
  vertexShader: string;
236
240
  fragmentShader: string;
@@ -240,7 +244,7 @@ export declare class PointCloud extends EventListener {
240
244
  };
241
245
  };
242
246
  };
243
- renderPointCloud(points: THREE.Points, radius?: number): void;
247
+ renderPointCloud(points: THREE.Points, radius?: number, tipScopeList?: ITipScopeParams[]): void;
244
248
  clearAllBox(): void;
245
249
  clearAllSphere(): void;
246
250
  clearAllGroupByPrefix(prefix?: string): void;
@@ -252,7 +256,7 @@ export declare class PointCloud extends EventListener {
252
256
  * @param src
253
257
  * @param radius Render the range of circle
254
258
  */
255
- loadPCDFile: (src?: string | undefined, radius?: number) => Promise<void>;
259
+ loadPCDFile: (src?: string | undefined, radius?: number, tipScopeList?: ITipScopeParams[]) => Promise<void>;
256
260
  /**
257
261
  * Highlight PointCloud by MappingImgList.
258
262
  * @param param0
@@ -300,6 +304,7 @@ export declare class PointCloud extends EventListener {
300
304
  }>) => Promise<void>;
301
305
  setShowDirection(showDirection: boolean): void;
302
306
  generateRange: (radius: number) => void;
307
+ generateTipScopeList: (tipScopeList: ITipScopeParams[]) => void;
303
308
  generateBoxArrow: ({ width }: IPointCloudBox) => THREE.ArrowHelper;
304
309
  /**
305
310
  * Universal generation of label information
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as k,EPerspectiveView as v,PointCloudUtils as G,DEFAULT_SPHERE_PARAMS as D}from"@labelbee/lb-utils";import $ from"../../_virtual/highlightWorker.js";import _ from"../../_virtual/filterBoxWorker.js";import{isInPolygon as K}from"../../utils/tool/polygonTool.js";import E from"../../utils/uuid.js";import N from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as X}from"./PCDLoader.js";import{OrbitControls as q}from"./OrbitControls.js";import{PointCloudCache as Q}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as J,mergeHighlightList as tt}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as et}from"./segmentation.js";import it from"./store/index.js";import rt from"./render/index.js";import nt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var ot=Object.defineProperty,st=Object.defineProperties,at=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable,V=(M,t,e)=>t in M?ot(M,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):M[t]=e,P=(M,t)=>{for(var e in t||(t={}))ht.call(t,e)&&V(M,e,t[e]);if(F)for(var e of F(t))ct.call(t,e)&&V(M,e,t[e]);return M},O=(M,t)=>st(M,at(t)),z=(M,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(p){r(p)}},h=l=>{try{o(e.throw(l))}catch(p){r(p)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,h);o((e=e.apply(M,t)).next())});const lt=30;let B=null;class dt extends nt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:l,hiddenText:p=!1,view:y=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new a.Raycaster,this.pointer=new a.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var d;const g=(d=n.id)!=null?d:E();this.removeObjectByName(g,"sphere");const{radius:u,widthSegments:m,heightSegments:b}=D,{center:f}=n,x=new a.Group,w=new a.SphereGeometry(u,m,b),C=new a.MeshBasicMaterial({color:c}),S=new a.Mesh(w,C);S.position.set(f.x,f.y,f.z),x.add(S),x.name=`sphere${g}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:d}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,d)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var d;const g=(d=n.id)!=null?d:E();this.removeObjectByName(g,"box");const{center:u,width:m,height:b,depth:f,rotation:x}=n,w=new a.Group,C=new a.BoxGeometry(m,b,f),S=new a.MeshBasicMaterial({color:"blue"}),L=new a.Mesh(C,S),R=new a.BoxHelper(L,c),H=this.generateBoxArrow(n),I=this.generateBoxTrackID(n,c);I&&w.add(I);const T=this.generateBoxAttributeLabel(n,c);T&&w.add(T),w.add(R),w.add(H),u&&w.position.set(u.x,u.y,u.z),x&&w.rotation.set(0,0,x),w.name=`box${g}`;const W=new a.BoxGeometry(m,b,f),U=new a.MeshBasicMaterial({visible:!1}),Z=new a.Mesh(W,U);w.add(Z),w.userData={defaultColor:c,selectedID:g},this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as o from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as T,EPerspectiveView as M,PointCloudUtils as Z,DEFAULT_SPHERE_PARAMS as k}from"@labelbee/lb-utils";import $ from"../../_virtual/highlightWorker.js";import N from"../../_virtual/filterBoxWorker.js";import{isInPolygon as K}from"../../utils/tool/polygonTool.js";import _ from"../../utils/uuid.js";import E from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as X}from"./PCDLoader.js";import{OrbitControls as q}from"./OrbitControls.js";import{PointCloudCache as Q}from"./cache.js";import{getCuboidFromPointCloudBox as D,getHighlightIndexByPoints as J,mergeHighlightList as tt}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as et}from"./segmentation.js";import it from"./store/index.js";import rt from"./render/index.js";import nt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var ot=Object.defineProperty,st=Object.defineProperties,at=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable,V=(v,t,e)=>t in v?ot(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,P=(v,t)=>{for(var e in t||(t={}))ht.call(t,e)&&V(v,e,t[e]);if(F)for(var e of F(t))ct.call(t,e)&&V(v,e,t[e]);return v},L=(v,t)=>st(v,at(t)),O=(v,t,e)=>new Promise((i,r)=>{var a=l=>{try{s(e.next(l))}catch(u){r(u)}},c=l=>{try{s(e.throw(l))}catch(u){r(u)}},s=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,c);s((e=e.apply(v,t)).next())});const lt=30;let B=null;class dt extends nt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:c,isSegment:s,checkMode:l,hiddenText:u=!1,view:g=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.tipScopeObjectName="tipScope",this.highlightGroupName="highlightBoxes",this.cacheTipScopeList=[],this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new o.Raycaster,this.pointer=new o.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,h="blue")=>{var d;const p=(d=n.id)!=null?d:_();this.removeObjectByName(p,"sphere");const{radius:m,widthSegments:y,heightSegments:b}=k,{center:f}=n,x=new o.Group,w=new o.SphereGeometry(m,y,b),C=new o.MeshBasicMaterial({color:h}),S=new o.Mesh(w,C);S.position.set(f.x,f.y,f.z),x.add(S),x.name=`sphere${p}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:h}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,h),this.render()},this.generateSpheres=n=>{n.forEach(h=>{const{fill:d}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,d)}),this.render()},this.addBoxToSense=(n,h=16777215)=>{var d;const p=(d=n.id)!=null?d:_();this.removeObjectByName(p,"box");const{center:m,width:y,height:b,depth:f,rotation:x}=n,w=new o.Group,C=new o.BoxGeometry(y,b,f),S=new o.MeshBasicMaterial({color:"blue"}),z=new o.Mesh(C,S),R=new o.BoxHelper(z,h),H=this.generateBoxArrow(n),A=this.generateBoxTrackID(n,h);A&&w.add(A);const I=this.generateBoxAttributeLabel(n,h);I&&w.add(I),w.add(R),w.add(H),m&&w.position.set(m.x,m.y,m.z),x&&w.rotation.set(0,0,x),w.name=`box${p}`;const W=new o.BoxGeometry(y,b,f),G=new o.MeshBasicMaterial({visible:!1}),U=new o.Mesh(W,G);w.add(U),w.userData={defaultColor:h,selectedID:p},this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const h=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,6 +28,6 @@ import*as a from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(c=this.currentPCDSrc,d){if(!c||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:g,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new a.BufferGeometry;m.setAttribute("position",new a.BufferAttribute(g,3)),this.isSegment||m.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(g);const b=new a.Points(m);this.renderPointCloud(b,d),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:c,points:d}){const g=f=>z(this,null,function*(){try{return yield Y.load(f)}catch(x){return console.error("Error loading image:",x),null}}),u=c.length===0?[]:(yield Promise.all(c.map(f=>z(this,null,function*(){let x=yield g(f.url);return!x&&f.fallbackUrl&&(x=yield g(f.fallbackUrl)),x})))).filter(f=>f!==null),m=c.map((f,x)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(f.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(f.url))!=null?w:[];const C=J({points:d,calib:f.calib,width:u[x].width,height:u[x].height});return this.cacheInstance.cache2DHighlightIndex.set(f.url,C),C});return tt(m)}),this.filterPreResult=(n,c,d)=>z(this,null,function*(){const{points:g}=yield this.cacheInstance.loadPCDFile(n),u=yield this.cacheInstance.loadIndexMap(n,g);return new Promise(m=>{const b=d.map(f=>{const x=N.calculatePointsInsideBox({indexMap:u,polygon:A(f).polygonPointList,zScope:[f.center.z-f.depth/2,f.center.z+f.depth/2],box:f}),w=x>=c.lowerLimitPointsNumInBox;return O(P({},f),{valid:w,count:x})});m(b)})}),this.loadPCDFileByBox=(n,c,d)=>z(this,null,function*(){const g=(b,f)=>z(this,null,function*(){const{width:x=0,height:w=0,depth:C=0}=d!=null?d:{},S=yield this.filterPointsByBox(O(P({},c),{width:c.width+x,height:c.height+w,depth:c.depth+C}),b,f);if(!S){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const L=new a.Points(S.geometry);L.name=this.pointCloudObjectName,this.scene.add(L),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);g(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new a.Vector3(1,0,0),d=new a.Vector3(n/2,0,0),g=2,u=new a.ArrowHelper(c,d,g,this.highlightColor);return u.visible=this.showDirection,u},this.generateLabel=(n,c,d)=>{const g=this.getTextCanvas(n),u=new a.Texture(g);u.minFilter=a.LinearFilter,u.magFilter=a.LinearFilter,u.needsUpdate=!0;const m=g.width/window.devicePixelRatio,b=g.height/window.devicePixelRatio,f=new a.SpriteMaterial({map:u,depthWrite:!1,color:d}),x=new a.Sprite(f);return x.scale.set(m/c,b/c,1),{sprite:x,canvasWidth:m,canvasHeight:b}},this.generateBoxTrackID=(n,c)=>{if(!n.trackID)return;const{sprite:d}=this.generateLabel(n.trackID.toString(),50,c);return d.position.set(-n.width/2,0,n.depth/2+.5),d},this.generateBoxAttributeLabel=(n,c)=>{if(!n.attribute||this.hiddenText)return;const d=this.findSubAttributeLabel(n,this.config),g=d?`${n.attribute}
32
- ${d}`:`${n.attribute}`,{sprite:u,canvasHeight:m}=this.generateLabel(g,100,c);return u.position.set(-n.width/2,0,-n.depth/2-m/150),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const g=d.material.uniforms.pointSize.value;n?d.material.uniforms.pointSize.value=Math.min(g*1.2,10):d.material.uniforms.pointSize.value=Math.max(g/1.2,1),c&&(d.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=p,this.view=y,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new q(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new X,this.axesHelper=new a.AxesHelper(1e3),this.filterBoxWorker=new _,this.geometry=new a.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Q.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var c,d,g;const u=this.renderer.domElement.getBoundingClientRect(),m=n.originalEvent.clientX-u.left,b=n.originalEvent.clientY-u.top;this.pointer.x=m/u.width*2-1,this.pointer.y=-(b/u.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(w=>{w instanceof a.Group&&w.children.forEach(C=>{C instanceof a.Mesh?f.push(C):this.updateMaterialColor(C,w.userData.defaultColor)})});const x=this.raycaster.intersectObjects(f,!1);if(x.length>0){const w=x[0].object.parent;w==null||w.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(c=this.pipe)==null||c.setNeedUpdateCenter(!1),(d=this.pipe)==null||d.setSelectedIDs(w==null?void 0:w.userData.selectedID)}else(g=this.pipe)==null||g.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof a.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof a.BoxHelper||t instanceof a.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new it(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new et(P({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new rt(O(P({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return P({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,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:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}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 a.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 a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return j.getColorFromConfig({attribute:t},O(P({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,p=e.y-r/2-s,y=100,n=-100,c=500/y;return{left:h,right:o,top:l,bottom:p,near:y,far:n,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:l}=t,p=this.getCameraVector(r,l,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=D,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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 a.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 a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:p}=A(t),y=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:l,polygonPointList:p,color:i,position:y};return this.filterBoxWorker||(this.filterBoxWorker=new _),new Promise(c=>{var d;(d=this.filterBoxWorker)==null||d.postMessage(n),this.filterBoxWorker.onmessage=g=>{const{color:u,position:m,num:b}=g.data;this.geometry.dispose(),this.geometry.setAttribute("position",new a.Float32BufferAttribute(m,3)),this.geometry.setAttribute("color",new a.Float32BufferAttribute(u,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),c({geometry:this.geometry,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=v.Front,s=lt){let h=k.frontViewMatrix4(s);switch(r){case v.Front:break;case v.Back:h=k.backViewMatrix4(s);break;case v.Left:h=k.leftViewMatrix4(s);break;case v.Right:h=k.rightViewMatrix4(s);break;case v.Top:h=k.topViewMatrix4(s);break;case v.LFT:h=k.leftFrontTopViewMatrix4(s,i);break;case v.RBT:h=k.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),l=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new a.Matrix4().makeTranslation(t.x,t.y,t.z),y=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(y).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return z(this,null,function*(){return new Promise((e,i)=>{B&&(B.terminate(),B=null),B=new $({type:"module"}),B.postMessage(t),B.onmessage=r=>{e(r.data),B==null||B.terminate(),B=null},B.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return z(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:h}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,p)=>{if(window.Worker){const n=(e?[...e]:[]).map(m=>A(m)),c=this.getAllAttributeColor(n),d=o.geometry.attributes.position.array,g=o.geometry.attributes.dimensions.array,u={cuboidList:n,position:d,color:g,colorList:c,highlightIndex:i,modifiedBoxIds:s,resetAreas:h};this.handleWebworker(u).then(m=>{const{color:b}=m;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==b.length){p(new Error("Error Path"));return}let f=b;(s.length||h.length)&&(f=b.map((C,S)=>C===-1?g[S]:C));const x=new a.BufferAttribute(f,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const w={color:f,view:this.view,currentPCDSrc:this.currentPCDSrc};l(w),this.workerLoading=!1,this.render()}).catch(m=>{this.workerLoading=!1,p(m)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:l,depth:p,rotation:y}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},O(P({},this.config),{attributeConfigurable:!0}),{}),c=new a.BoxGeometry(o,l,p),d=new a.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(y),c.translate(r,s,h);const g=new a.Mesh(c,d);e.add(g);const u=new a.PlaneGeometry(p,l);u.rotateY(Math.PI/2),u.rotateZ(y);const m=new a.Vector3(o/2,0,0),b=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(y);m.applyMatrix4(b),u.translate(r+m.x,s+m.y,h+m.z);const f=new a.MeshBasicMaterial({color:n,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new a.Mesh(u,f);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new a.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(h=>{const o=i.find(n=>n.value===h);if(!o||!o.subSelected)return;const{key:l,subSelected:p}=o,y=[];p.forEach(n=>{var c;const d=(c=t.subAttribute)==null?void 0:c[h],g=Array.isArray(d)?d:d==null?void 0:d.split(";");(g==null?void 0:g.includes(n.value))&&y.push(n.key)}),y.length>0&&(r&&(r+="\u3001"),r+=`${l}:${y.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const h=t.split(`
33
- `),o=Math.max(...h.map(n=>i.measureText(n).width)),l=Math.ceil(o),p=s*1.5,y=p*h.length;e.width=l*r,e.height=y*r,e.style.width=`${l}px`,e.style.height=`${y}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((n,c)=>{i.fillText(n,0,c*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,c)=>n.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((n,c)=>n.x-c.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((n,c)=>n.y-c.y);const p=Math.floor(e.length*s),y=Math.floor(e.length*(1-s));return e=e.slice(p,y),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:p})=>{t.forEach((y,n)=>{const c=r[n+1],d=N.getFootOfPerpendicular({x:l,y:p},y,c,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:p}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((l,p)=>{const y=r[p],n=r[p+1],c=r[p+2];return G.getIntersectionBySlope({p1:s[p].point,line1:[y,n],p2:s[p+1].point,line2:[n,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(u=>u.uuid===this.pointsUuid);let l=0,p=0,y=0,n=0,c=[],d=[];const g=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let u=0;u<g.length;u+=3){const m=g[u],b=g[u+1],f=g[u+2];K({x:m,y:b},t)&&(f||f===0)&&d.push({x:m,y:b,z:f})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((u,m)=>u.z-m.z),l=d[0].z-.01,p=d[d.length-1].z+.01,n=d.length,e&&(y=d.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}):{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.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,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r-o/2},p={x:e+h/2,y:i+s/2,z:r+o/2},y={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2};return[l,p,y,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e-h/2,y:i+s/2,z:r+o/2},p={x:e-h/2,y:i+s/2,z:r-o/2},y={x:e-h/2,y:i-s/2,z:r-o/2},n={x:e-h/2,y:i-s/2,z:r+o/2};return[l,p,y,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r+o/2},p={x:e+h/2,y:i-s/2,z:r+o/2},y={x:e-h/2,y:i-s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r+o/2};return[l,p,y,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),l=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case v.Left:return this.getPolygonSidePoints(t);case v.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(n=>new a.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,y=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(p,y)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=D,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},l=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const y=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:y,zoom:Math.min(n,c)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=D,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=O(P({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=O(P({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(m=>new a.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(h)),[l,p,y,n]=o,c=Math.max(Math.abs(l.x-y.x),Math.abs(l.x-p.x)),g=p.add(n).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:O(P({},r),{center:{x:r.center.x-g.x,y:r.center.y-g.y,z:r.center.z-i},width:c,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{dt as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>O(this,[...n],function*(h=this.currentPCDSrc,d,p){if(!h||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:m,color:y}=yield this.cacheInstance.loadPCDFile(h),b=new o.BufferGeometry;b.setAttribute("position",new o.BufferAttribute(m,3)),this.isSegment||b.setAttribute("dimensions",new o.BufferAttribute(y,3)),this.initCloudData(m);const f=new o.Points(b);this.renderPointCloud(f,d,p),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>O(this,[n],function*({mappingImgList:h,points:d}){const p=f=>O(this,null,function*(){try{return yield Y.load(f)}catch(x){return console.error("Error loading image:",x),null}}),m=h.length===0?[]:(yield Promise.all(h.map(f=>O(this,null,function*(){let x=yield p(f.url);return!x&&f.fallbackUrl&&(x=yield p(f.fallbackUrl)),x})))).filter(f=>f!==null),y=h.map((f,x)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(f.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(f.url))!=null?w:[];const C=J({points:d,calib:f.calib,width:m[x].width,height:m[x].height});return this.cacheInstance.cache2DHighlightIndex.set(f.url,C),C});return tt(y)}),this.filterPreResult=(n,h,d)=>O(this,null,function*(){const{points:p}=yield this.cacheInstance.loadPCDFile(n),m=yield this.cacheInstance.loadIndexMap(n,p);return new Promise(y=>{const b=d.map(f=>{const x=E.calculatePointsInsideBox({indexMap:m,polygon:D(f).polygonPointList,zScope:[f.center.z-f.depth/2,f.center.z+f.depth/2],box:f}),w=x>=h.lowerLimitPointsNumInBox;return L(P({},f),{valid:w,count:x})});y(b)})}),this.loadPCDFileByBox=(n,h,d)=>O(this,null,function*(){const p=(b,f)=>O(this,null,function*(){const{width:x=0,height:w=0,depth:C=0}=d!=null?d:{},S=yield this.filterPointsByBox(L(P({},h),{width:h.width+x,height:h.height+w,depth:h.depth+C}),b,f);if(!S){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const z=new o.Points(S.geometry);z.name=this.pointCloudObjectName,this.scene.add(z),this.render()}),{points:m,color:y}=yield this.cacheInstance.loadPCDFile(n);p(m,y)}),this.generateRange=n=>{const h=this.createRange(n);this.scene.add(h)},this.generateTipScopeList=n=>{this.cacheTipScopeList.forEach((h,d)=>{this.removeObjectByName(this.tipScopeObjectName+d)}),n.forEach((h,d)=>{const p=this.createTipScope(h,d);p&&this.scene.add(p)}),this.cacheTipScopeList=n},this.generateBoxArrow=({width:n})=>{const h=new o.Vector3(1,0,0),d=new o.Vector3(n/2,0,0),p=2,m=new o.ArrowHelper(h,d,p,this.highlightColor);return m.visible=this.showDirection,m},this.generateLabel=(n,h,d)=>{const p=this.getTextCanvas(n),m=new o.Texture(p);m.minFilter=o.LinearFilter,m.magFilter=o.LinearFilter,m.needsUpdate=!0;const y=p.width/window.devicePixelRatio,b=p.height/window.devicePixelRatio,f=new o.SpriteMaterial({map:m,depthWrite:!1,color:d}),x=new o.Sprite(f);return x.scale.set(y/h,b/h,1),{sprite:x,canvasWidth:y,canvasHeight:b}},this.generateBoxTrackID=(n,h)=>{if(!n.trackID)return;const{sprite:d}=this.generateLabel(n.trackID.toString(),50,h);return d.position.set(-n.width/2,0,n.depth/2+.5),d},this.generateBoxAttributeLabel=(n,h)=>{if(!n.attribute||this.hiddenText)return;const d=this.findSubAttributeLabel(n,this.config),p=d?`${n.attribute}
32
+ ${d}`:`${n.attribute}`,{sprite:m,canvasHeight:y}=this.generateLabel(p,100,h);return m.position.set(-n.width/2,0,-n.depth/2-y/150),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:h})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const p=d.material.uniforms.pointSize.value;n?d.material.uniforms.pointSize.value=Math.min(p*1.2,10):d.material.uniforms.pointSize.value=Math.max(p/1.2,1),h&&(d.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new o.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=c,this.checkMode=l!=null?l:!1,this.hiddenText=u,this.view=g,i&&r?(this.isOrthographicCamera=!0,this.camera=new o.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new o.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new o.Scene,this.controls=new q(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new X,this.axesHelper=new o.AxesHelper(1e3),this.filterBoxWorker=new N,this.geometry=new o.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Q.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var h,d,p;const m=this.renderer.domElement.getBoundingClientRect(),y=n.originalEvent.clientX-m.left,b=n.originalEvent.clientY-m.top;this.pointer.x=y/m.width*2-1,this.pointer.y=-(b/m.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(w=>{w instanceof o.Group&&w.children.forEach(C=>{C instanceof o.Mesh?f.push(C):this.updateMaterialColor(C,w.userData.defaultColor)})});const x=this.raycaster.intersectObjects(f,!1);if(x.length>0){const w=x[0].object.parent;w==null||w.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(h=this.pipe)==null||h.setNeedUpdateCenter(!1),(d=this.pipe)==null||d.setSelectedIDs(w==null?void 0:w.userData.selectedID)}else(p=this.pipe)==null||p.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof o.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof o.BoxHelper||t instanceof o.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new it(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new et(P({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new rt(L(P({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return P({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new o.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:a,near:c,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=c,this.camera.far=s,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:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}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 o.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 o.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return j.getColorFromConfig({attribute:t},L(P({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,a=10,c=e.x-i/2-a,s=e.x-i/2+a,l=e.y+r/2+a,u=e.y-r/2-a,g=100,n=-100,h=500/g;return{left:c,right:s,top:l,bottom:u,near:g,far:n,zoom:h}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:c,depth:s,rotation:l}=t,u=this.getCameraVector(r,l,{width:a,height:c,depth:s},e);return i?(this.updateCamera(i,r),new o.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=k,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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 o.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 o.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new o.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,a,c;if(!e){const s=this.scene.getObjectByName(this.pointCloudObjectName);if(!s)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array}if(window.Worker){const{zMin:s,zMax:l,polygonPointList:u}=D(t),g=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:l,polygonPointList:u,color:i,position:g};return this.filterBoxWorker||(this.filterBoxWorker=new N),new Promise(h=>{var d;(d=this.filterBoxWorker)==null||d.postMessage(n),this.filterBoxWorker.onmessage=p=>{const{color:m,position:y,num:b}=p.data;this.geometry.dispose(),this.geometry.setAttribute("position",new o.Float32BufferAttribute(y,3)),this.geometry.setAttribute("color",new o.Float32BufferAttribute(m,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),h({geometry:this.geometry,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=M.Front,a=lt){let c=T.frontViewMatrix4(a);switch(r){case M.Front:break;case M.Back:c=T.backViewMatrix4(a);break;case M.Left:c=T.leftViewMatrix4(a);break;case M.Right:c=T.rightViewMatrix4(a);break;case M.Top:c=T.topViewMatrix4(a);break;case M.LFT:c=T.leftFrontTopViewMatrix4(a,i);break;case M.RBT:c=T.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),l=new o.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new o.Matrix4().makeTranslation(t.x,t.y,t.z),g=new o.Matrix4().makeRotationZ(e);return new o.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(g).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new o.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new o.BufferGeometry().setFromPoints(i),a=new o.LineBasicMaterial({color:16711680}),c=new o.Line(r,a);return c.name=this.rangeObjectName,c}createTipScope(t,e){this.removeObjectByName(this.tipScopeObjectName+e);let i=null;const{scopeType:r,range:a}=t;if(r==="circle"){const s=new o.EllipseCurve(0,0,Number(a.radius),Number(a.radius),0,2*Math.PI,!1,0).getPoints(50),l=new o.BufferGeometry().setFromPoints(s),u=new o.LineBasicMaterial({color:16711680});i=new o.Line(l,u)}else if(r==="rect"){const{top:c=0,bottom:s=0,left:l=0,right:u=0}=a,g=l,n=-u,h=c,d=-s,p=new o.Shape;p.moveTo(h,g),p.lineTo(d,g),p.lineTo(d,n),p.lineTo(h,n),p.lineTo(h,g);const m=new o.BufferGeometry().setFromPoints(p.getPoints()),y=new o.LineBasicMaterial({color:16711680});i=new o.Line(m,y)}return i?(i.name=this.tipScopeObjectName+e,i):null}renderPointCloud(t,e,i){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const r=new o.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),i&&this.generateTipScopeList(i),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return O(this,null,function*(){return new Promise((e,i)=>{B&&(B.terminate(),B=null),B=new $({type:"module"}),B.postMessage(t),B.onmessage=r=>{e(r.data),B==null||B.terminate(),B=null},B.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return O(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:a,resetAreas:c}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(y=>D(y)),h=this.getAllAttributeColor(n),d=s.geometry.attributes.position.array,p=s.geometry.attributes.dimensions.array,m={cuboidList:n,position:d,color:p,colorList:h,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(m).then(y=>{const{color:b}=y;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==b.length){u(new Error("Error Path"));return}let f=b;(a.length||c.length)&&(f=b.map((C,S)=>C===-1?p[S]:C));const x=new o.BufferAttribute(f,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,s.geometry.setAttribute("dimensions",x),s.geometry.attributes.dimensions.needsUpdate=!0;const w={color:f,view:this.view,currentPCDSrc:this.currentPCDSrc};l(w),this.workerLoading=!1,this.render()}).catch(y=>{this.workerLoading=!1,u(y)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new o.Group;t.forEach(i=>{const{center:{x:r,y:a,z:c},width:s,height:l,depth:u,rotation:g}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},L(P({},this.config),{attributeConfigurable:!0}),{}),h=new o.BoxGeometry(s,l,u),d=new o.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});h.rotateZ(g),h.translate(r,a,c);const p=new o.Mesh(h,d);e.add(p);const m=new o.PlaneGeometry(u,l);m.rotateY(Math.PI/2),m.rotateZ(g);const y=new o.Vector3(s/2,0,0),b=new o.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(g);y.applyMatrix4(b),m.translate(r+y.x,a+y.y,c+y.z);const f=new o.MeshBasicMaterial({color:n,side:o.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new o.Mesh(m,f);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new o.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const a=Object.keys(t.subAttribute);return a.length===0||a.forEach(c=>{const s=i.find(n=>n.value===c);if(!s||!s.subSelected)return;const{key:l,subSelected:u}=s,g=[];u.forEach(n=>{var h;const d=(h=t.subAttribute)==null?void 0:h[c],p=Array.isArray(d)?d:d==null?void 0:d.split(";");(p==null?void 0:p.includes(n.value))&&g.push(n.key)}),g.length>0&&(r&&(r+="\u3001"),r+=`${l}:${g.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const c=t.split(`
33
+ `),s=Math.max(...c.map(n=>i.measureText(n).width)),l=Math.ceil(s),u=a*1.5,g=u*c.length;e.width=l*r,e.height=g*r,e.style.width=`${l}px`,e.style.height=`${g}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.forEach((n,h)=>{i.fillText(n,0,h*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,h)=>n.z-h.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((n,h)=>n.x-h.x);const s=Math.floor(e.length*a),l=Math.floor(e.length*(1-a));e=e.slice(s,l),e.sort((n,h)=>n.y-h.y);const u=Math.floor(e.length*a),g=Math.floor(e.length*(1-a));return e=e.slice(u,g),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:u})=>{t.forEach((g,n)=>{const h=r[n+1],d=E.getFootOfPerpendicular({x:l,y:u},g,h,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:u}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],c=t.map((l,u)=>{const g=r[u],n=r[u+1],h=r[u+2];return Z.getIntersectionBySlope({p1:a[u].point,line1:[g,n],p2:a[u+1].point,line2:[n,h]})});return c.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,a,c;const s=this.scene.children.find(m=>m.uuid===this.pointsUuid);let l=0,u=0,g=0,n=0,h=[],d=[];const p=((c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array)||[];for(let m=0;m<p.length;m+=3){const y=p[m],b=p[m+1],f=p[m+2];K({x:y,y:b},t)&&(f||f===0)&&d.push({x:y,y:b,z:f})}return d.length?(i&&(d=this.filterNoise(d),h=this.getFittedCoordinates(t,d)),d.sort((m,y)=>m.z-y.z),l=d[0].z-.01,u=d[d.length-1].z+.01,n=d.length,e&&(g=d.filter(({z:m})=>m>=e[0]&&m<=e[1]).length),{maxZ:u,minZ:l,count:g,zCount:n,fittedCoordinates:h}):{maxZ:u,minZ:l,count:g,zCount:n,fittedCoordinates:h}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new o.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,i=this.containerHeight/2;return new o.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,l={x:e+c/2,y:i+a/2,z:r-s/2},u={x:e+c/2,y:i+a/2,z:r+s/2},g={x:e-c/2,y:i+a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r-s/2};return[l,u,g,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,l={x:e-c/2,y:i+a/2,z:r+s/2},u={x:e-c/2,y:i+a/2,z:r-s/2},g={x:e-c/2,y:i-a/2,z:r-s/2},n={x:e-c/2,y:i-a/2,z:r+s/2};return[l,u,g,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,l={x:e+c/2,y:i+a/2,z:r+s/2},u={x:e+c/2,y:i-a/2,z:r+s/2},g={x:e-c/2,y:i-a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r+s/2};return[l,u,g,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new o.Matrix4().makeTranslation(-e,-i,-r),s=new o.Matrix4().makeTranslation(e,i,r),l=new o.Matrix4().makeRotationZ(a);return new o.Matrix4().multiply(s).multiply(l).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case M.Left:return this.getPolygonSidePoints(t);case M.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:a}=t,c=new o.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new o.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const l=i.map(n=>new o.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,g=this.containerHeight/a;return{polygon2d:l,zoom:Math.min(u,g)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:c}=k,s={center:e,attribute:i,id:r,valid:a,width:c*2,height:c*2,depth:c*2,rotation:0},l=new o.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new o.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const g=new o.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(c*2),h=this.containerHeight/(c*2);return{point2d:g,zoom:Math.min(n,h)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=k,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},a=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(l=>new o.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),c=this.containerWidth/e,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(c,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new o.Matrix4().makeRotationZ(r.rotation),c=new o.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=L(P({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const a=new o.Matrix4().makeRotationZ(r.rotation),c=new o.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=L(P({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const c=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(y=>new o.Vector3(y.x,y.y,y.z)).map(y=>y.applyMatrix4(c)),[l,u,g,n]=s,h=Math.max(Math.abs(l.x-g.x),Math.abs(l.x-u.x)),p=u.add(n).applyMatrix3(new o.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new o.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new o.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:L(P({},r),{center:{x:r.center.x-p.x,y:r.center.y-p.y,z:r.center.z-i},width:h,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,a=[],{count:c}=r;for(let s=0;s<c;s++){const l=r.getZ(s);a.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new o.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{dt as PointCloud};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.28.0-alpha.27",
3
+ "version": "1.28.0-alpha.29",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -94,7 +94,7 @@
94
94
  "typescript": "^4.2.3"
95
95
  },
96
96
  "dependencies": {
97
- "@labelbee/lb-utils": "1.20.0-alpha.5",
97
+ "@labelbee/lb-utils": "1.20.0-alpha.7",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",