@labelbee/lb-annotation 1.27.0-alpha.69 → 1.27.0-alpha.70

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(w){if(w&&w.__esModule)return w;var t=Object.create(null);return w&&Object.keys(w).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(w,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return w[e]}})}}),t.default=w,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=(w,t,e)=>t in w?__defProp(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,__spreadValues=(w,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(w,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(w,e,t[e]);return w},__spreadProps=(w,t)=>__defProps(w,__getOwnPropDescs(t)),__async=(w,t,e)=>new Promise((i,r)=>{var a=l=>{try{s(e.next(l))}catch(u){r(u)}},h=l=>{try{s(e.throw(l))}catch(u){r(u)}},s=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,h);s((e=e.apply(w,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:h,isSegment:s,checkMode:l,hiddenText:u=!1}){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.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,o="blue")=>{var c;const d=(c=n.id)!=null?c:uuid();this.removeObjectByName(d,"sphere");const{radius:m,widthSegments:g,heightSegments:x}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:p}=n,f=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(m,g,x),b=new THREE__namespace.MeshBasicMaterial({color:o}),C=new THREE__namespace.Mesh(y,b);C.position.set(p.x,p.y,p.z),f.add(C),f.name=`sphere${d}`,this.scene.add(f)},this.generateSphere=n=>{const{fill:o}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,o),this.render()},this.generateSpheres=n=>{n.forEach(o=>{const{fill:c}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,c)}),this.render()},this.addBoxToSense=(n,o=16777215)=>{var c;const d=(c=n.id)!=null?c:uuid();this.removeObjectByName(d,"box");const{center:m,width:g,height:x,depth:p,rotation:f}=n,y=new THREE__namespace.Group,b=new THREE__namespace.BoxGeometry(g,x,p),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),v=new THREE__namespace.Mesh(b,C),B=new THREE__namespace.BoxHelper(v,o),O=this.generateBoxArrow(n),M=this.generateBoxTrackID(n);M&&y.add(M);const P=this.generateBoxAttributeLabel(n);P&&y.add(P),y.add(B),y.add(O),m&&y.position.set(m.x,m.y,m.z),f&&y.rotation.set(0,0,f),y.name=`box${d}`;const z=new THREE__namespace.BoxGeometry(g,x,p),L=new THREE__namespace.MeshBasicMaterial({visible:!1}),S=new THREE__namespace.Mesh(z,L);S.userData={selectedID:d},y.add(S),this.scene.add(y)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const o=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,o)}},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(w){if(w&&w.__esModule)return w;var t=Object.create(null);return w&&Object.keys(w).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(w,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return w[e]}})}}),t.default=w,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=(w,t,e)=>t in w?__defProp(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,__spreadValues=(w,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(w,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(w,e,t[e]);return w},__spreadProps=(w,t)=>__defProps(w,__getOwnPropDescs(t)),__async=(w,t,e)=>new Promise((i,r)=>{var a=l=>{try{s(e.next(l))}catch(u){r(u)}},h=l=>{try{s(e.throw(l))}catch(u){r(u)}},s=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,h);s((e=e.apply(w,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:h,isSegment:s,checkMode:l,hiddenText:u=!1}){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.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,o="blue")=>{var c;const d=(c=n.id)!=null?c:uuid();this.removeObjectByName(d,"sphere");const{radius:m,widthSegments:p,heightSegments:f}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=n,x=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(m,p,f),b=new THREE__namespace.MeshBasicMaterial({color:o}),C=new THREE__namespace.Mesh(y,b);C.position.set(g.x,g.y,g.z),x.add(C),x.name=`sphere${d}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:o}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,o),this.render()},this.generateSpheres=n=>{n.forEach(o=>{const{fill:c}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,c)}),this.render()},this.addBoxToSense=(n,o=16777215)=>{var c;const d=(c=n.id)!=null?c:uuid();this.removeObjectByName(d,"box");const{center:m,width:p,height:f,depth:g,rotation:x}=n,y=new THREE__namespace.Group,b=new THREE__namespace.BoxGeometry(p,f,g),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),v=new THREE__namespace.Mesh(b,C),B=new THREE__namespace.BoxHelper(v,o),O=this.generateBoxArrow(n),M=this.generateBoxTrackID(n);M&&y.add(M);const P=this.generateBoxAttributeLabel(n);P&&y.add(P),y.add(B),y.add(O),m&&y.position.set(m.x,m.y,m.z),x&&y.rotation.set(0,0,x),y.name=`box${d}`;const z=new THREE__namespace.BoxGeometry(p,f,g),L=new THREE__namespace.MeshBasicMaterial({visible:!1}),S=new THREE__namespace.Mesh(z,L);S.userData={selectedID:d},y.add(S),this.scene.add(y)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const o=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,o)}},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*(o=this.currentPCDSrc,c){if(!o)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=o;const{points:d,color:m}=yield this.cacheInstance.loadPCDFile(o),g=new THREE__namespace.BufferGeometry;g.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||g.setAttribute("dimensions",new THREE__namespace.BufferAttribute(m,3)),this.initCloudData(d);const x=new THREE__namespace.Points(g);this.renderPointCloud(x,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:o,points:c}){const d=p=>__async(this,null,function*(){try{return yield ImgUtils.default.load(p)}catch(f){return console.error("Error loading image:",f),null}}),m=o.length===0?[]:(yield Promise.all(o.map(p=>__async(this,null,function*(){let f=yield d(p.url);return!f&&p.fallbackUrl&&(f=yield d(p.fallbackUrl)),f})))).filter(p=>p!==null),g=o.map((p,f)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const b=matrix.getHighlightIndexByPoints({points:c,calib:p.calib,width:m[f].width,height:m[f].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,b),b});return matrix.mergeHighlightList(g)}),this.filterPreResult=(n,o,c)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),m=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(g=>{const x=c.map(p=>{const f=MathUtils.default.calculatePointsInsideBox({indexMap:m,polygon:matrix.getCuboidFromPointCloudBox(p).polygonPointList,zScope:[p.center.z-p.depth/2,p.center.z+p.depth/2],box:p}),y=f>=o.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},p),{valid:y,count:f})});g(x)})}),this.loadPCDFileByBox=(n,o,c)=>__async(this,null,function*(){const d=(x,p)=>__async(this,null,function*(){const{width:f=0,height:y=0,depth:b=0}=c!=null?c:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+f,height:o.height+y,depth:o.depth+b}),x,p);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const v=new THREE__namespace.Points(C.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:m,color:g}=yield this.cacheInstance.loadPCDFile(n);d(m,g)}),this.generateRange=n=>{const o=this.createRange(n);this.scene.add(o)},this.generateBoxArrow=({width:n})=>{const o=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(n/2,0,0),d=2,m=16776960,g=new THREE__namespace.ArrowHelper(o,c,d,m);return g.visible=this.showDirection,g},this.generateLabel=(n,o)=>{const c=this.getTextCanvas(n),d=new THREE__namespace.Texture(c);d.minFilter=THREE__namespace.LinearFilter,d.magFilter=THREE__namespace.LinearFilter,d.needsUpdate=!0;const m=c.width/window.devicePixelRatio,g=c.height/window.devicePixelRatio,x=new THREE__namespace.SpriteMaterial({map:d,depthWrite:!1}),p=new THREE__namespace.Sprite(x);return p.scale.set(m/o,g/o,1),{sprite:p,canvasWidth:m,canvasHeight:g}},this.generateBoxTrackID=n=>{if(!n.trackID)return;const{sprite:o}=this.generateLabel(n.trackID.toString(),50);return o.position.set(-n.width/2,0,n.depth/2+.5),o},this.generateBoxAttributeLabel=n=>{if(!n.attribute||this.hiddenText)return;const o=this.findSubAttributeLabel(n,this.config),c=o?`${n.attribute}
32
- ${o}`:`${n.attribute}`,{sprite:d,canvasHeight:m}=this.generateLabel(c,100);return d.position.set(-n.width/2,0,-n.depth/2-m/150),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:o})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),o&&(c.material.uniforms.pointSize.value=o,this.pointsMaterialSize=o),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=u,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,s?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var o,c,d;const m=this.renderer.domElement.getBoundingClientRect(),g=n.originalEvent.clientX-m.left,x=n.originalEvent.clientY-m.top;this.pointer.x=g/m.width*2-1,this.pointer.y=-(x/m.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const p=[];this.scene.children.forEach(y=>{y instanceof THREE__namespace.Group&&y.children.forEach(b=>{b instanceof THREE__namespace.Mesh&&p.push(b)})});const f=this.raycaster.intersectObjects(p,!1);if(f.length>0){const y=f[0].object;(o=this.pipe)==null||o.setNeedUpdateCenter(!1),(c=this.pipe)==null||c.setSelectedIDs(y.userData.selectedID)}else(d=this.pipe)==null||d.setSelectedIDs(void 0)})}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:a,near:h,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=h,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 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,a=10,h=e.x-i/2-a,s=e.x-i/2+a,l=e.y+r/2+a,u=e.y-r/2-a,n=100,o=-100,c=500/n;return{left:h,right:s,top:l,bottom:u,near:n,far:o,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:h,depth:s,rotation:l}=t,u=this.getCameraVector(r,l,{width:a,height:h,depth:s},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,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 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,a,h;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=(h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array}if(window.Worker){const{zMin:s,zMax:l,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),n=e;i=i!=null?i:new Float32Array([]);const o={boxParams:t,zMin:s,zMax:l,polygonPointList:u,color:i,position:n};return new Promise(c=>{const d=new filterBoxWorker;d.postMessage(o),d.onmessage=m=>{const{color:g,position:x,num:p}=m.data,f=new THREE__namespace.BufferGeometry;f.setAttribute("position",new THREE__namespace.Float32BufferAttribute(x,3)),f.setAttribute("color",new THREE__namespace.Float32BufferAttribute(g,3)),f.computeBoundingSphere(),d.terminate(),c({geometry:f,num:p})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,a=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(a);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(a);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(a);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(a);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(a);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(a,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),n=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(n).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),a=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,a);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){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],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:h}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,u)=>{if(window.Worker){const o=(e?[...e]:[]).map(x=>matrix.getCuboidFromPointCloudBox(x)),c=this.getAllAttributeColor(o),d=s.geometry.attributes.position.array,m=s.geometry.attributes.dimensions.array,g={cuboidList:o,position:d,color:m,colorList:c,highlightIndex:i,modifiedBoxIds:a,resetAreas:h};this.handleWebworker(g).then(x=>{const{color:p}=x;let f=p;(a.length||h.length)&&(f=p.map((b,C)=>b===-1?m[C]:b));const y=new THREE__namespace.BufferAttribute(f,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==p.length){u(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,f),this.highlightPCDSrc=void 0,y.needsUpdate=!0,s.geometry.setAttribute("dimensions",y),s.geometry.attributes.dimensions.needsUpdate=!0,l(f),this.render()}).catch(x=>{u(x)})}})})}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:a,z:h},width:s,height:l,depth:u,rotation:n}=i,{fill:o}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),c=new THREE__namespace.BoxGeometry(s,l,u),d=new THREE__namespace.MeshBasicMaterial({color:o,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(n),c.translate(r,a,h);const m=new THREE__namespace.Mesh(c,d);e.add(m);const g=new THREE__namespace.PlaneGeometry(u,l);g.rotateY(Math.PI/2),g.rotateZ(n);const x=new THREE__namespace.Vector3(s/2,0,0),p=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(n);x.applyMatrix4(p),g.translate(r+x.x,a+x.y,h+x.z);const f=new THREE__namespace.MeshBasicMaterial({color:o,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),y=new THREE__namespace.Mesh(g,f);e.add(y)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.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(h=>{const s=i.find(n=>n.value===h);if(!s||!s.subSelected)return;const{key:l,subSelected:u}=s;u.forEach(n=>{var o;const c=(o=t.subAttribute)==null?void 0:o[h];(c==null?void 0:c.includes(n.value))&&(r&&(r+="\u3001"),r+=`${l}:${n.key}`)})}),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 h=t.split(`
33
- `),s=Math.max(...h.map(o=>i.measureText(o).width)),l=Math.ceil(s),u=a*1.5,n=u*h.length;e.width=l*r,e.height=n*r,e.style.width=`${l}px`,e.style.height=`${n}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((o,c)=>{i.fillText(o,0,c*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((o,c)=>o.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:o})=>o>r.z+.1);const a=.005,h=Math.floor(e.length*(1-a));e=e.slice(0,h),e.sort((o,c)=>o.x-c.x);const s=Math.floor(e.length*a),l=Math.floor(e.length*(1-a));e=e.slice(s,l),e.sort((o,c)=>o.y-c.y);const u=Math.floor(e.length*a),n=Math.floor(e.length*(1-a));return e=e.slice(u,n),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:u})=>{t.forEach((n,o)=>{const c=r[o+1],d=MathUtils.default.getFootOfPerpendicular({x:l,y:u},n,c,!1,!0).length;(!i[o]||d<i[o].distance)&&(i[o]={distance:d,point:{x:l,y:u}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],h=t.map((l,u)=>{const n=r[u],o=r[u+1],c=r[u+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:a[u].point,line1:[n,o],p2:a[u+1].point,line2:[o,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,a,h;const s=this.scene.children.find(g=>g.uuid===this.pointsUuid);let l=0,u=0,n=0,o=0,c=[],d=[];const m=((h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array)||[];for(let g=0;g<m.length;g+=3){const x=m[g],p=m[g+1],f=m[g+2];polygonTool.isInPolygon({x,y:p},t)&&(f||f===0)&&d.push({x,y:p,z:f})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((g,x)=>g.z-x.z),l=d[0].z-.01,u=d[d.length-1].z+.01,o=d.length,e&&(n=d.filter(({z:g})=>g>=e[0]&&g<=e[1]).length),{maxZ:u,minZ:l,count:n,zCount:o,fittedCoordinates:c}):{maxZ:u,minZ:l,count:n,zCount:o,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 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:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r-s/2},u={x:e+h/2,y:i+a/2,z:r+s/2},n={x:e-h/2,y:i+a/2,z:r+s/2},o={x:e-h/2,y:i+a/2,z:r-s/2};return[l,u,n,o]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e-h/2,y:i+a/2,z:r+s/2},u={x:e-h/2,y:i+a/2,z:r-s/2},n={x:e-h/2,y:i-a/2,z:r-s/2},o={x:e-h/2,y:i-a/2,z:r+s/2};return[l,u,n,o]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r+s/2},u={x:e+h/2,y:i-a/2,z:r+s/2},n={x:e-h/2,y:i-a/2,z:r+s/2},o={x:e-h/2,y:i+a/2,z:r+s/2};return[l,u,n,o]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),s=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(a);return new THREE__namespace.Matrix4().multiply(s).multiply(l).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:a}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const l=i.map(o=>new THREE__namespace.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,n=this.containerHeight/a;return{polygon2d:l,zoom:Math.min(u,n)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,s={center:e,attribute:i,id:r,valid:a,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const n=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),o=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:n,zoom:Math.min(o,c)/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)},a=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.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,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(h,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},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 THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},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 h=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(x=>new THREE__namespace.Vector3(x.x,x.y,x.z)).map(x=>x.applyMatrix4(h)),[l,u,n,o]=s,c=Math.max(Math.abs(l.x-n.x),Math.abs(l.x-u.x)),m=u.add(o).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-m.x,y:r.center.y-m.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,a=[],{count:h}=r;for(let s=0;s<h;s++){const l=r.getZ(s);a.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(a,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*(o=this.currentPCDSrc,c){if(!o)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=o;const{points:d,color:m}=yield this.cacheInstance.loadPCDFile(o),p=new THREE__namespace.BufferGeometry;p.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||p.setAttribute("dimensions",new THREE__namespace.BufferAttribute(m,3)),this.initCloudData(d);const f=new THREE__namespace.Points(p);this.renderPointCloud(f,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:o,points:c}){const d=g=>__async(this,null,function*(){try{return yield ImgUtils.default.load(g)}catch(x){return console.error("Error loading image:",x),null}}),m=o.length===0?[]:(yield Promise.all(o.map(g=>__async(this,null,function*(){let x=yield d(g.url);return!x&&g.fallbackUrl&&(x=yield d(g.fallbackUrl)),x})))).filter(g=>g!==null),p=o.map((g,x)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(g.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(g.url))!=null?y:[];const b=matrix.getHighlightIndexByPoints({points:c,calib:g.calib,width:m[x].width,height:m[x].height});return this.cacheInstance.cache2DHighlightIndex.set(g.url,b),b});return matrix.mergeHighlightList(p)}),this.filterPreResult=(n,o,c)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),m=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(p=>{const f=c.map(g=>{const x=MathUtils.default.calculatePointsInsideBox({indexMap:m,polygon:matrix.getCuboidFromPointCloudBox(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),y=x>=o.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},g),{valid:y,count:x})});p(f)})}),this.loadPCDFileByBox=(n,o,c)=>__async(this,null,function*(){const d=(f,g)=>__async(this,null,function*(){const{width:x=0,height:y=0,depth:b=0}=c!=null?c:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+x,height:o.height+y,depth:o.depth+b}),f,g);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const v=new THREE__namespace.Points(C.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:m,color:p}=yield this.cacheInstance.loadPCDFile(n);d(m,p)}),this.generateRange=n=>{const o=this.createRange(n);this.scene.add(o)},this.generateBoxArrow=({width:n})=>{const o=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(n/2,0,0),d=2,m=16776960,p=new THREE__namespace.ArrowHelper(o,c,d,m);return p.visible=this.showDirection,p},this.generateLabel=(n,o)=>{const c=this.getTextCanvas(n),d=new THREE__namespace.Texture(c);d.minFilter=THREE__namespace.LinearFilter,d.magFilter=THREE__namespace.LinearFilter,d.needsUpdate=!0;const m=c.width/window.devicePixelRatio,p=c.height/window.devicePixelRatio,f=new THREE__namespace.SpriteMaterial({map:d,depthWrite:!1}),g=new THREE__namespace.Sprite(f);return g.scale.set(m/o,p/o,1),{sprite:g,canvasWidth:m,canvasHeight:p}},this.generateBoxTrackID=n=>{if(!n.trackID)return;const{sprite:o}=this.generateLabel(n.trackID.toString(),50);return o.position.set(-n.width/2,0,n.depth/2+.5),o},this.generateBoxAttributeLabel=n=>{if(!n.attribute||this.hiddenText)return;const o=this.findSubAttributeLabel(n,this.config),c=o?`${n.attribute}
32
+ ${o}`:`${n.attribute}`,{sprite:d,canvasHeight:m}=this.generateLabel(c,100);return d.position.set(-n.width/2,0,-n.depth/2-m/150),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:o})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),o&&(c.material.uniforms.pointSize.value=o,this.pointsMaterialSize=o),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=u,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,s?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(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var o,c,d;const m=this.renderer.domElement.getBoundingClientRect(),p=n.originalEvent.clientX-m.left,f=n.originalEvent.clientY-m.top;this.pointer.x=p/m.width*2-1,this.pointer.y=-(f/m.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const g=[];this.scene.children.forEach(y=>{y instanceof THREE__namespace.Group&&y.children.forEach(b=>{b instanceof THREE__namespace.Mesh&&g.push(b)})});const x=this.raycaster.intersectObjects(g,!1);if(x.length>0){const y=x[0].object;(o=this.pipe)==null||o.setNeedUpdateCenter(!1),(c=this.pipe)==null||c.setSelectedIDs(y.userData.selectedID)}else(d=this.pipe)==null||d.setSelectedIDs(void 0)})}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:a,near:h,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=h,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 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,a=10,h=e.x-i/2-a,s=e.x-i/2+a,l=e.y+r/2+a,u=e.y-r/2-a,n=100,o=-100,c=500/n;return{left:h,right:s,top:l,bottom:u,near:n,far:o,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:h,depth:s,rotation:l}=t,u=this.getCameraVector(r,l,{width:a,height:h,depth:s},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,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 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,a,h;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=(h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array}if(window.Worker){const{zMin:s,zMax:l,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),n=e;i=i!=null?i:new Float32Array([]);const o={boxParams:t,zMin:s,zMax:l,polygonPointList:u,color:i,position:n};return this.filterBoxWorker?new Promise(c=>{this.filterBoxWorker.postMessage(o),this.filterBoxWorker.onmessage=d=>{const{color:m,position:p,num:f}=d.data;this.geometry.dispose(),this.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(p,3)),this.geometry.setAttribute("color",new THREE__namespace.Float32BufferAttribute(m,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker.terminate(),c({geometry:this.geometry,num:f})}}):Promise.resolve(void 0)}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,a=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(a);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(a);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(a);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(a);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(a);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(a,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),n=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(n).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),a=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,a);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){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],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:h}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,u)=>{if(window.Worker){const o=(e?[...e]:[]).map(f=>matrix.getCuboidFromPointCloudBox(f)),c=this.getAllAttributeColor(o),d=s.geometry.attributes.position.array,m=s.geometry.attributes.dimensions.array,p={cuboidList:o,position:d,color:m,colorList:c,highlightIndex:i,modifiedBoxIds:a,resetAreas:h};this.handleWebworker(p).then(f=>{const{color:g}=f;let x=g;(a.length||h.length)&&(x=g.map((b,C)=>b===-1?m[C]:b));const y=new THREE__namespace.BufferAttribute(x,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==g.length){u(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,x),this.highlightPCDSrc=void 0,y.needsUpdate=!0,s.geometry.setAttribute("dimensions",y),s.geometry.attributes.dimensions.needsUpdate=!0,l(x),this.render()}).catch(f=>{u(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:a,z:h},width:s,height:l,depth:u,rotation:n}=i,{fill:o}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),c=new THREE__namespace.BoxGeometry(s,l,u),d=new THREE__namespace.MeshBasicMaterial({color:o,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(n),c.translate(r,a,h);const m=new THREE__namespace.Mesh(c,d);e.add(m);const p=new THREE__namespace.PlaneGeometry(u,l);p.rotateY(Math.PI/2),p.rotateZ(n);const f=new THREE__namespace.Vector3(s/2,0,0),g=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(n);f.applyMatrix4(g),p.translate(r+f.x,a+f.y,h+f.z);const x=new THREE__namespace.MeshBasicMaterial({color:o,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),y=new THREE__namespace.Mesh(p,x);e.add(y)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.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(h=>{const s=i.find(n=>n.value===h);if(!s||!s.subSelected)return;const{key:l,subSelected:u}=s;u.forEach(n=>{var o;const c=(o=t.subAttribute)==null?void 0:o[h];(c==null?void 0:c.includes(n.value))&&(r&&(r+="\u3001"),r+=`${l}:${n.key}`)})}),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 h=t.split(`
33
+ `),s=Math.max(...h.map(o=>i.measureText(o).width)),l=Math.ceil(s),u=a*1.5,n=u*h.length;e.width=l*r,e.height=n*r,e.style.width=`${l}px`,e.style.height=`${n}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((o,c)=>{i.fillText(o,0,c*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((o,c)=>o.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:o})=>o>r.z+.1);const a=.005,h=Math.floor(e.length*(1-a));e=e.slice(0,h),e.sort((o,c)=>o.x-c.x);const s=Math.floor(e.length*a),l=Math.floor(e.length*(1-a));e=e.slice(s,l),e.sort((o,c)=>o.y-c.y);const u=Math.floor(e.length*a),n=Math.floor(e.length*(1-a));return e=e.slice(u,n),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:u})=>{t.forEach((n,o)=>{const c=r[o+1],d=MathUtils.default.getFootOfPerpendicular({x:l,y:u},n,c,!1,!0).length;(!i[o]||d<i[o].distance)&&(i[o]={distance:d,point:{x:l,y:u}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],h=t.map((l,u)=>{const n=r[u],o=r[u+1],c=r[u+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:a[u].point,line1:[n,o],p2:a[u+1].point,line2:[o,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,a,h;const s=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,u=0,n=0,o=0,c=[],d=[];const m=((h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array)||[];for(let p=0;p<m.length;p+=3){const f=m[p],g=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:f,y:g},t)&&(x||x===0)&&d.push({x:f,y:g,z:x})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((p,f)=>p.z-f.z),l=d[0].z-.01,u=d[d.length-1].z+.01,o=d.length,e&&(n=d.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:u,minZ:l,count:n,zCount:o,fittedCoordinates:c}):{maxZ:u,minZ:l,count:n,zCount:o,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 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:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r-s/2},u={x:e+h/2,y:i+a/2,z:r+s/2},n={x:e-h/2,y:i+a/2,z:r+s/2},o={x:e-h/2,y:i+a/2,z:r-s/2};return[l,u,n,o]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e-h/2,y:i+a/2,z:r+s/2},u={x:e-h/2,y:i+a/2,z:r-s/2},n={x:e-h/2,y:i-a/2,z:r-s/2},o={x:e-h/2,y:i-a/2,z:r+s/2};return[l,u,n,o]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r+s/2},u={x:e+h/2,y:i-a/2,z:r+s/2},n={x:e-h/2,y:i-a/2,z:r+s/2},o={x:e-h/2,y:i+a/2,z:r+s/2};return[l,u,n,o]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),s=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(a);return new THREE__namespace.Matrix4().multiply(s).multiply(l).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:a}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const l=i.map(o=>new THREE__namespace.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,n=this.containerHeight/a;return{polygon2d:l,zoom:Math.min(u,n)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,s={center:e,attribute:i,id:r,valid:a,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const n=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),o=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:n,zoom:Math.min(o,c)/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)},a=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.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,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(h,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},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 THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},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 h=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(f=>new THREE__namespace.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(h)),[l,u,n,o]=s,c=Math.max(Math.abs(l.x-n.x),Math.abs(l.x-u.x)),m=u.add(o).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-m.x,y:r.center.y-m.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,a=[],{count:h}=r;for(let s=0;s<h;s++){const l=r.getZ(s);a.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(a,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;
@@ -89,6 +89,8 @@ export declare class PointCloud extends EventListener {
89
89
  private pointer;
90
90
  private pipe?;
91
91
  private hiddenText;
92
+ private filterBoxWorker;
93
+ private geometry;
92
94
  constructor({ container, noAppend, isOrthographicCamera, orthographicParams, backgroundColor, // GRAY_BACKGROUND
93
95
  config, isSegment, checkMode, hiddenText, }: IProps);
94
96
  setHandlerPipe(pipe: IPipeTypes): void;
@@ -1,4 +1,4 @@
1
- import*as h from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as z,EPerspectiveView as M,PointCloudUtils as U,DEFAULT_SPHERE_PARAMS as L}from"@labelbee/lb-utils";import Z from"../../_virtual/highlightWorker.js";import G from"../../_virtual/filterBoxWorker.js";import{isInPolygon as $}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 K}from"./PCDLoader.js";import{OrbitControls as X}from"./OrbitControls.js";import{PointCloudCache as q}from"./cache.js";import{getCuboidFromPointCloudBox as I,getHighlightIndexByPoints as Q,mergeHighlightList as J}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 tt}from"./segmentation.js";import et from"./store/index.js";import it from"./render/index.js";import rt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var nt=Object.defineProperty,ot=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,F=(C,t,e)=>t in C?nt(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,v=(C,t)=>{for(var e in t||(t={}))at.call(t,e)&&F(C,e,t[e]);if(N)for(var e of N(t))ht.call(t,e)&&F(C,e,t[e]);return C},S=(C,t)=>ot(C,st(t)),B=(C,t,e)=>new Promise((i,r)=>{var a=d=>{try{s(e.next(d))}catch(p){r(p)}},c=d=>{try{s(e.throw(d))}catch(p){r(p)}},s=d=>d.done?i(d.value):Promise.resolve(d.value).then(a,c);s((e=e.apply(C,t)).next())});const ct=30,D=new Z({type:"module"});class lt extends rt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:c,isSegment:s,checkMode:d,hiddenText:p=!1}){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 h.Raycaster,this.pointer=new h.Vector2,this.hiddenText=!1,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,o="blue")=>{var l;const u=(l=n.id)!=null?l:_();this.removeObjectByName(u,"sphere");const{radius:f,widthSegments:m,heightSegments:x}=L,{center:g}=n,y=new h.Group,w=new h.SphereGeometry(f,m,x),b=new h.MeshBasicMaterial({color:o}),P=new h.Mesh(w,b);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${u}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:o}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,o),this.render()},this.generateSpheres=n=>{n.forEach(o=>{const{fill:l}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,l)}),this.render()},this.addBoxToSense=(n,o=16777215)=>{var l;const u=(l=n.id)!=null?l:_();this.removeObjectByName(u,"box");const{center:f,width:m,height:x,depth:g,rotation:y}=n,w=new h.Group,b=new h.BoxGeometry(m,x,g),P=new h.MeshBasicMaterial({color:"blue"}),O=new h.Mesh(b,P),V=new h.BoxHelper(O,o),R=this.generateBoxArrow(n),T=this.generateBoxTrackID(n);T&&w.add(T);const A=this.generateBoxAttributeLabel(n);A&&w.add(A),w.add(V),w.add(R),f&&w.position.set(f.x,f.y,f.z),y&&w.rotation.set(0,0,y),w.name=`box${u}`;const H=new h.BoxGeometry(m,x,g),W=new h.MeshBasicMaterial({visible:!1}),k=new h.Mesh(H,W);k.userData={selectedID:u},w.add(k),this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const o=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,o)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as h from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as z,EPerspectiveView as M,PointCloudUtils as U,DEFAULT_SPHERE_PARAMS as L}from"@labelbee/lb-utils";import Z from"../../_virtual/highlightWorker.js";import G from"../../_virtual/filterBoxWorker.js";import{isInPolygon as $}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 K}from"./PCDLoader.js";import{OrbitControls as X}from"./OrbitControls.js";import{PointCloudCache as q}from"./cache.js";import{getCuboidFromPointCloudBox as k,getHighlightIndexByPoints as Q,mergeHighlightList as J}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 tt}from"./segmentation.js";import et from"./store/index.js";import it from"./render/index.js";import rt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var nt=Object.defineProperty,ot=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,F=(C,t,e)=>t in C?nt(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,v=(C,t)=>{for(var e in t||(t={}))at.call(t,e)&&F(C,e,t[e]);if(N)for(var e of N(t))ht.call(t,e)&&F(C,e,t[e]);return C},S=(C,t)=>ot(C,st(t)),B=(C,t,e)=>new Promise((i,r)=>{var a=d=>{try{s(e.next(d))}catch(p){r(p)}},c=d=>{try{s(e.throw(d))}catch(p){r(p)}},s=d=>d.done?i(d.value):Promise.resolve(d.value).then(a,c);s((e=e.apply(C,t)).next())});const ct=30,I=new Z({type:"module"});class lt extends rt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:c,isSegment:s,checkMode:d,hiddenText:p=!1}){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 h.Raycaster,this.pointer=new h.Vector2,this.hiddenText=!1,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,o="blue")=>{var l;const u=(l=n.id)!=null?l:_();this.removeObjectByName(u,"sphere");const{radius:f,widthSegments:g,heightSegments:y}=L,{center:m}=n,x=new h.Group,w=new h.SphereGeometry(f,g,y),b=new h.MeshBasicMaterial({color:o}),P=new h.Mesh(w,b);P.position.set(m.x,m.y,m.z),x.add(P),x.name=`sphere${u}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:o}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,o),this.render()},this.generateSpheres=n=>{n.forEach(o=>{const{fill:l}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,l)}),this.render()},this.addBoxToSense=(n,o=16777215)=>{var l;const u=(l=n.id)!=null?l:_();this.removeObjectByName(u,"box");const{center:f,width:g,height:y,depth:m,rotation:x}=n,w=new h.Group,b=new h.BoxGeometry(g,y,m),P=new h.MeshBasicMaterial({color:"blue"}),O=new h.Mesh(b,P),V=new h.BoxHelper(O,o),R=this.generateBoxArrow(n),D=this.generateBoxTrackID(n);D&&w.add(D);const T=this.generateBoxAttributeLabel(n);T&&w.add(T),w.add(V),w.add(R),f&&w.position.set(f.x,f.y,f.z),x&&w.rotation.set(0,0,x),w.name=`box${u}`;const H=new h.BoxGeometry(g,y,m),W=new h.MeshBasicMaterial({visible:!1}),A=new h.Mesh(H,W);A.userData={selectedID:u},w.add(A),this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const o=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,o)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,6 +28,6 @@ import*as h 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)=>B(this,[...n],function*(o=this.currentPCDSrc,l){if(!o)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=o;const{points:u,color:f}=yield this.cacheInstance.loadPCDFile(o),m=new h.BufferGeometry;m.setAttribute("position",new h.BufferAttribute(u,3)),this.isSegment||m.setAttribute("dimensions",new h.BufferAttribute(f,3)),this.initCloudData(u);const x=new h.Points(m);this.renderPointCloud(x,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>B(this,[n],function*({mappingImgList:o,points:l}){const u=g=>B(this,null,function*(){try{return yield Y.load(g)}catch(y){return console.error("Error loading image:",y),null}}),f=o.length===0?[]:(yield Promise.all(o.map(g=>B(this,null,function*(){let y=yield u(g.url);return!y&&g.fallbackUrl&&(y=yield u(g.fallbackUrl)),y})))).filter(g=>g!==null),m=o.map((g,y)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(g.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(g.url))!=null?w:[];const b=Q({points:l,calib:g.calib,width:f[y].width,height:f[y].height});return this.cacheInstance.cache2DHighlightIndex.set(g.url,b),b});return J(m)}),this.filterPreResult=(n,o,l)=>B(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),f=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(m=>{const x=l.map(g=>{const y=E.calculatePointsInsideBox({indexMap:f,polygon:I(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),w=y>=o.lowerLimitPointsNumInBox;return S(v({},g),{valid:w,count:y})});m(x)})}),this.loadPCDFileByBox=(n,o,l)=>B(this,null,function*(){const u=(x,g)=>B(this,null,function*(){const{width:y=0,height:w=0,depth:b=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(v({},o),{width:o.width+y,height:o.height+w,depth:o.depth+b}),x,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const O=new h.Points(P.geometry);O.name=this.pointCloudObjectName,this.scene.add(O),this.render()}),{points:f,color:m}=yield this.cacheInstance.loadPCDFile(n);u(f,m)}),this.generateRange=n=>{const o=this.createRange(n);this.scene.add(o)},this.generateBoxArrow=({width:n})=>{const o=new h.Vector3(1,0,0),l=new h.Vector3(n/2,0,0),u=2,f=16776960,m=new h.ArrowHelper(o,l,u,f);return m.visible=this.showDirection,m},this.generateLabel=(n,o)=>{const l=this.getTextCanvas(n),u=new h.Texture(l);u.minFilter=h.LinearFilter,u.magFilter=h.LinearFilter,u.needsUpdate=!0;const f=l.width/window.devicePixelRatio,m=l.height/window.devicePixelRatio,x=new h.SpriteMaterial({map:u,depthWrite:!1}),g=new h.Sprite(x);return g.scale.set(f/o,m/o,1),{sprite:g,canvasWidth:f,canvasHeight:m}},this.generateBoxTrackID=n=>{if(!n.trackID)return;const{sprite:o}=this.generateLabel(n.trackID.toString(),50);return o.position.set(-n.width/2,0,n.depth/2+.5),o},this.generateBoxAttributeLabel=n=>{if(!n.attribute||this.hiddenText)return;const o=this.findSubAttributeLabel(n,this.config),l=o?`${n.attribute}
32
- ${o}`:`${n.attribute}`,{sprite:u,canvasHeight:f}=this.generateLabel(l,100);return u.position.set(-n.width/2,0,-n.depth/2-f/150),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:o})=>{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),o&&(l.material.uniforms.pointSize.value=o,this.pointsMaterialSize=o),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new h.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=c,this.checkMode=d!=null?d:!1,this.hiddenText=p,i&&r?(this.isOrthographicCamera=!0,this.camera=new h.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new h.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new h.Scene,this.controls=new X(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new K,this.axesHelper=new h.AxesHelper(1e3),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 o,l,u;const f=this.renderer.domElement.getBoundingClientRect(),m=n.originalEvent.clientX-f.left,x=n.originalEvent.clientY-f.top;this.pointer.x=m/f.width*2-1,this.pointer.y=-(x/f.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const g=[];this.scene.children.forEach(w=>{w instanceof h.Group&&w.children.forEach(b=>{b instanceof h.Mesh&&g.push(b)})});const y=this.raycaster.intersectObjects(g,!1);if(y.length>0){const w=y[0].object;(o=this.pipe)==null||o.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(w.userData.selectedID)}else(u=this.pipe)==null||u.setSelectedIDs(void 0)})}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new et(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 tt(v({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new it(S(v({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 v({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 h.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 h.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 h.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},S(v({},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,d=e.y+r/2+a,p=e.y-r/2-a,n=100,o=-100,l=500/n;return{left:c,right:s,top:d,bottom:p,near:n,far:o,zoom:l}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:c,depth:s,rotation:d}=t,p=this.getCameraVector(r,d,{width:a,height:c,depth:s},e);return i?(this.updateCamera(i,r),new h.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=L,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 h.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 h.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new h.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:d,polygonPointList:p}=I(t),n=e;i=i!=null?i:new Float32Array([]);const o={boxParams:t,zMin:s,zMax:d,polygonPointList:p,color:i,position:n};return new Promise(l=>{const u=new G;u.postMessage(o),u.onmessage=f=>{const{color:m,position:x,num:g}=f.data,y=new h.BufferGeometry;y.setAttribute("position",new h.Float32BufferAttribute(x,3)),y.setAttribute("color",new h.Float32BufferAttribute(m,3)),y.computeBoundingSphere(),u.terminate(),l({geometry:y,num:g})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=M.Front,a=ct){let c=z.frontViewMatrix4(a);switch(r){case M.Front:break;case M.Back:c=z.backViewMatrix4(a);break;case M.Left:c=z.leftViewMatrix4(a);break;case M.Right:c=z.rightViewMatrix4(a);break;case M.Top:c=z.topViewMatrix4(a);break;case M.LFT:c=z.leftFrontTopViewMatrix4(a,i);break;case M.RBT:c=z.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),d=new h.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new h.Matrix4().makeTranslation(t.x,t.y,t.z),n=new h.Matrix4().makeRotationZ(e);return new h.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(d).applyMatrix4(n).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new h.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new h.BufferGeometry().setFromPoints(i),a=new h.LineBasicMaterial({color:16711680}),c=new h.Line(r,a);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new h.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],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return B(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,D.postMessage(t),D.onmessage=r=>{e(r.data),this.workerLoading=!1},D.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return B(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:c}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((d,p)=>{if(window.Worker){const o=(e?[...e]:[]).map(x=>I(x)),l=this.getAllAttributeColor(o),u=s.geometry.attributes.position.array,f=s.geometry.attributes.dimensions.array,m={cuboidList:o,position:u,color:f,colorList:l,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(m).then(x=>{const{color:g}=x;let y=g;(a.length||c.length)&&(y=g.map((b,P)=>b===-1?f[P]:b));const w=new h.BufferAttribute(y,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==g.length){p(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,y),this.highlightPCDSrc=void 0,w.needsUpdate=!0,s.geometry.setAttribute("dimensions",w),s.geometry.attributes.dimensions.needsUpdate=!0,d(y),this.render()}).catch(x=>{p(x)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new h.Group;t.forEach(i=>{const{center:{x:r,y:a,z:c},width:s,height:d,depth:p,rotation:n}=i,{fill:o}=j.getColorFromConfig({attribute:i.attribute},S(v({},this.config),{attributeConfigurable:!0}),{}),l=new h.BoxGeometry(s,d,p),u=new h.MeshBasicMaterial({color:o,transparent:!0,opacity:.2,depthTest:!1});l.rotateZ(n),l.translate(r,a,c);const f=new h.Mesh(l,u);e.add(f);const m=new h.PlaneGeometry(p,d);m.rotateY(Math.PI/2),m.rotateZ(n);const x=new h.Vector3(s/2,0,0),g=new h.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(n);x.applyMatrix4(g),m.translate(r+x.x,a+x.y,c+x.z);const y=new h.MeshBasicMaterial({color:o,side:h.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new h.Mesh(m,y);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new h.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.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:d,subSelected:p}=s;p.forEach(n=>{var o;const l=(o=t.subAttribute)==null?void 0:o[c];(l==null?void 0:l.includes(n.value))&&(r&&(r+="\u3001"),r+=`${d}:${n.key}`)})}),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(o=>i.measureText(o).width)),d=Math.ceil(s),p=a*1.5,n=p*c.length;e.width=d*r,e.height=n*r,e.style.width=`${d}px`,e.style.height=`${n}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.forEach((o,l)=>{i.fillText(o,0,l*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((o,l)=>o.z-l.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:o})=>o>r.z+.1);const a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((o,l)=>o.x-l.x);const s=Math.floor(e.length*a),d=Math.floor(e.length*(1-a));e=e.slice(s,d),e.sort((o,l)=>o.y-l.y);const p=Math.floor(e.length*a),n=Math.floor(e.length*(1-a));return e=e.slice(p,n),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:p})=>{t.forEach((n,o)=>{const l=r[o+1],u=E.getFootOfPerpendicular({x:d,y:p},n,l,!1,!0).length;(!i[o]||u<i[o].distance)&&(i[o]={distance:u,point:{x:d,y:p}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],c=t.map((d,p)=>{const n=r[p],o=r[p+1],l=r[p+2];return U.getIntersectionBySlope({p1:a[p].point,line1:[n,o],p2:a[p+1].point,line2:[o,l]})});return c.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,a,c;const s=this.scene.children.find(m=>m.uuid===this.pointsUuid);let d=0,p=0,n=0,o=0,l=[],u=[];const f=((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<f.length;m+=3){const x=f[m],g=f[m+1],y=f[m+2];$({x,y:g},t)&&(y||y===0)&&u.push({x,y:g,z:y})}return u.length?(i&&(u=this.filterNoise(u),l=this.getFittedCoordinates(t,u)),u.sort((m,x)=>m.z-x.z),d=u[0].z-.01,p=u[u.length-1].z+.01,o=u.length,e&&(n=u.filter(({z:m})=>m>=e[0]&&m<=e[1]).length),{maxZ:p,minZ:d,count:n,zCount:o,fittedCoordinates:l}):{maxZ:p,minZ:d,count:n,zCount:o,fittedCoordinates:l}}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 h.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 h.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,d={x:e+c/2,y:i+a/2,z:r-s/2},p={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},o={x:e-c/2,y:i+a/2,z:r-s/2};return[d,p,n,o]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e-c/2,y:i+a/2,z:r+s/2},p={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},o={x:e-c/2,y:i-a/2,z:r+s/2};return[d,p,n,o]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r+s/2},p={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},o={x:e-c/2,y:i+a/2,z:r+s/2};return[d,p,n,o]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new h.Matrix4().makeTranslation(-e,-i,-r),s=new h.Matrix4().makeTranslation(e,i,r),d=new h.Matrix4().makeRotationZ(a);return new h.Matrix4().multiply(s).multiply(d).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 h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new h.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const d=i.map(o=>new h.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,n=this.containerHeight/a;return{polygon2d:d,zoom:Math.min(p,n)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:c}=L,s={center:e,attribute:i,id:r,valid:a,width:c*2,height:c*2,depth:c*2,rotation:0},d=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new h.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const n=new h.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),o=this.containerWidth/(c*2),l=this.containerHeight/(c*2);return{point2d:n,zoom:Math.min(o,l)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=L,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(d=>new h.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.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 h.Matrix4().makeRotationZ(r.rotation),c=new h.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=S(v({},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 h.Matrix4().makeRotationZ(r.rotation),c=new h.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=S(v({},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(x=>new h.Vector3(x.x,x.y,x.z)).map(x=>x.applyMatrix4(c)),[d,p,n,o]=s,l=Math.max(Math.abs(d.x-n.x),Math.abs(d.x-p.x)),f=p.add(o).applyMatrix3(new h.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new h.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new h.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(v({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:l,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 d=r.getZ(s);a.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new h.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{lt as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>B(this,[...n],function*(o=this.currentPCDSrc,l){if(!o)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=o;const{points:u,color:f}=yield this.cacheInstance.loadPCDFile(o),g=new h.BufferGeometry;g.setAttribute("position",new h.BufferAttribute(u,3)),this.isSegment||g.setAttribute("dimensions",new h.BufferAttribute(f,3)),this.initCloudData(u);const y=new h.Points(g);this.renderPointCloud(y,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>B(this,[n],function*({mappingImgList:o,points:l}){const u=m=>B(this,null,function*(){try{return yield Y.load(m)}catch(x){return console.error("Error loading image:",x),null}}),f=o.length===0?[]:(yield Promise.all(o.map(m=>B(this,null,function*(){let x=yield u(m.url);return!x&&m.fallbackUrl&&(x=yield u(m.fallbackUrl)),x})))).filter(m=>m!==null),g=o.map((m,x)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?w:[];const b=Q({points:l,calib:m.calib,width:f[x].width,height:f[x].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,b),b});return J(g)}),this.filterPreResult=(n,o,l)=>B(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),f=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(g=>{const y=l.map(m=>{const x=E.calculatePointsInsideBox({indexMap:f,polygon:k(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),w=x>=o.lowerLimitPointsNumInBox;return S(v({},m),{valid:w,count:x})});g(y)})}),this.loadPCDFileByBox=(n,o,l)=>B(this,null,function*(){const u=(y,m)=>B(this,null,function*(){const{width:x=0,height:w=0,depth:b=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(v({},o),{width:o.width+x,height:o.height+w,depth:o.depth+b}),y,m);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const O=new h.Points(P.geometry);O.name=this.pointCloudObjectName,this.scene.add(O),this.render()}),{points:f,color:g}=yield this.cacheInstance.loadPCDFile(n);u(f,g)}),this.generateRange=n=>{const o=this.createRange(n);this.scene.add(o)},this.generateBoxArrow=({width:n})=>{const o=new h.Vector3(1,0,0),l=new h.Vector3(n/2,0,0),u=2,f=16776960,g=new h.ArrowHelper(o,l,u,f);return g.visible=this.showDirection,g},this.generateLabel=(n,o)=>{const l=this.getTextCanvas(n),u=new h.Texture(l);u.minFilter=h.LinearFilter,u.magFilter=h.LinearFilter,u.needsUpdate=!0;const f=l.width/window.devicePixelRatio,g=l.height/window.devicePixelRatio,y=new h.SpriteMaterial({map:u,depthWrite:!1}),m=new h.Sprite(y);return m.scale.set(f/o,g/o,1),{sprite:m,canvasWidth:f,canvasHeight:g}},this.generateBoxTrackID=n=>{if(!n.trackID)return;const{sprite:o}=this.generateLabel(n.trackID.toString(),50);return o.position.set(-n.width/2,0,n.depth/2+.5),o},this.generateBoxAttributeLabel=n=>{if(!n.attribute||this.hiddenText)return;const o=this.findSubAttributeLabel(n,this.config),l=o?`${n.attribute}
32
+ ${o}`:`${n.attribute}`,{sprite:u,canvasHeight:f}=this.generateLabel(l,100);return u.position.set(-n.width/2,0,-n.depth/2-f/150),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:o})=>{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),o&&(l.material.uniforms.pointSize.value=o,this.pointsMaterialSize=o),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new h.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=c,this.checkMode=d!=null?d:!1,this.hiddenText=p,i&&r?(this.isOrthographicCamera=!0,this.camera=new h.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new h.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new h.Scene,this.controls=new X(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new K,this.axesHelper=new h.AxesHelper(1e3),this.filterBoxWorker=new G,this.geometry=new h.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 o,l,u;const f=this.renderer.domElement.getBoundingClientRect(),g=n.originalEvent.clientX-f.left,y=n.originalEvent.clientY-f.top;this.pointer.x=g/f.width*2-1,this.pointer.y=-(y/f.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(w=>{w instanceof h.Group&&w.children.forEach(b=>{b instanceof h.Mesh&&m.push(b)})});const x=this.raycaster.intersectObjects(m,!1);if(x.length>0){const w=x[0].object;(o=this.pipe)==null||o.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(w.userData.selectedID)}else(u=this.pipe)==null||u.setSelectedIDs(void 0)})}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new et(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 tt(v({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new it(S(v({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 v({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 h.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 h.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 h.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},S(v({},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,d=e.y+r/2+a,p=e.y-r/2-a,n=100,o=-100,l=500/n;return{left:c,right:s,top:d,bottom:p,near:n,far:o,zoom:l}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:c,depth:s,rotation:d}=t,p=this.getCameraVector(r,d,{width:a,height:c,depth:s},e);return i?(this.updateCamera(i,r),new h.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=L,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 h.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 h.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new h.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:d,polygonPointList:p}=k(t),n=e;i=i!=null?i:new Float32Array([]);const o={boxParams:t,zMin:s,zMax:d,polygonPointList:p,color:i,position:n};return this.filterBoxWorker?new Promise(l=>{this.filterBoxWorker.postMessage(o),this.filterBoxWorker.onmessage=u=>{const{color:f,position:g,num:y}=u.data;this.geometry.dispose(),this.geometry.setAttribute("position",new h.Float32BufferAttribute(g,3)),this.geometry.setAttribute("color",new h.Float32BufferAttribute(f,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker.terminate(),l({geometry:this.geometry,num:y})}}):Promise.resolve(void 0)}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=M.Front,a=ct){let c=z.frontViewMatrix4(a);switch(r){case M.Front:break;case M.Back:c=z.backViewMatrix4(a);break;case M.Left:c=z.leftViewMatrix4(a);break;case M.Right:c=z.rightViewMatrix4(a);break;case M.Top:c=z.topViewMatrix4(a);break;case M.LFT:c=z.leftFrontTopViewMatrix4(a,i);break;case M.RBT:c=z.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),d=new h.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new h.Matrix4().makeTranslation(t.x,t.y,t.z),n=new h.Matrix4().makeRotationZ(e);return new h.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(d).applyMatrix4(n).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new h.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new h.BufferGeometry().setFromPoints(i),a=new h.LineBasicMaterial({color:16711680}),c=new h.Line(r,a);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new h.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],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return B(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,I.postMessage(t),I.onmessage=r=>{e(r.data),this.workerLoading=!1},I.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return B(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:c}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((d,p)=>{if(window.Worker){const o=(e?[...e]:[]).map(y=>k(y)),l=this.getAllAttributeColor(o),u=s.geometry.attributes.position.array,f=s.geometry.attributes.dimensions.array,g={cuboidList:o,position:u,color:f,colorList:l,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(g).then(y=>{const{color:m}=y;let x=m;(a.length||c.length)&&(x=m.map((b,P)=>b===-1?f[P]:b));const w=new h.BufferAttribute(x,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==m.length){p(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,x),this.highlightPCDSrc=void 0,w.needsUpdate=!0,s.geometry.setAttribute("dimensions",w),s.geometry.attributes.dimensions.needsUpdate=!0,d(x),this.render()}).catch(y=>{p(y)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new h.Group;t.forEach(i=>{const{center:{x:r,y:a,z:c},width:s,height:d,depth:p,rotation:n}=i,{fill:o}=j.getColorFromConfig({attribute:i.attribute},S(v({},this.config),{attributeConfigurable:!0}),{}),l=new h.BoxGeometry(s,d,p),u=new h.MeshBasicMaterial({color:o,transparent:!0,opacity:.2,depthTest:!1});l.rotateZ(n),l.translate(r,a,c);const f=new h.Mesh(l,u);e.add(f);const g=new h.PlaneGeometry(p,d);g.rotateY(Math.PI/2),g.rotateZ(n);const y=new h.Vector3(s/2,0,0),m=new h.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(n);y.applyMatrix4(m),g.translate(r+y.x,a+y.y,c+y.z);const x=new h.MeshBasicMaterial({color:o,side:h.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new h.Mesh(g,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new h.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.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:d,subSelected:p}=s;p.forEach(n=>{var o;const l=(o=t.subAttribute)==null?void 0:o[c];(l==null?void 0:l.includes(n.value))&&(r&&(r+="\u3001"),r+=`${d}:${n.key}`)})}),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(o=>i.measureText(o).width)),d=Math.ceil(s),p=a*1.5,n=p*c.length;e.width=d*r,e.height=n*r,e.style.width=`${d}px`,e.style.height=`${n}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.forEach((o,l)=>{i.fillText(o,0,l*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((o,l)=>o.z-l.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:o})=>o>r.z+.1);const a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((o,l)=>o.x-l.x);const s=Math.floor(e.length*a),d=Math.floor(e.length*(1-a));e=e.slice(s,d),e.sort((o,l)=>o.y-l.y);const p=Math.floor(e.length*a),n=Math.floor(e.length*(1-a));return e=e.slice(p,n),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:p})=>{t.forEach((n,o)=>{const l=r[o+1],u=E.getFootOfPerpendicular({x:d,y:p},n,l,!1,!0).length;(!i[o]||u<i[o].distance)&&(i[o]={distance:u,point:{x:d,y:p}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],c=t.map((d,p)=>{const n=r[p],o=r[p+1],l=r[p+2];return U.getIntersectionBySlope({p1:a[p].point,line1:[n,o],p2:a[p+1].point,line2:[o,l]})});return c.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,a,c;const s=this.scene.children.find(g=>g.uuid===this.pointsUuid);let d=0,p=0,n=0,o=0,l=[],u=[];const f=((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 g=0;g<f.length;g+=3){const y=f[g],m=f[g+1],x=f[g+2];$({x:y,y:m},t)&&(x||x===0)&&u.push({x:y,y:m,z:x})}return u.length?(i&&(u=this.filterNoise(u),l=this.getFittedCoordinates(t,u)),u.sort((g,y)=>g.z-y.z),d=u[0].z-.01,p=u[u.length-1].z+.01,o=u.length,e&&(n=u.filter(({z:g})=>g>=e[0]&&g<=e[1]).length),{maxZ:p,minZ:d,count:n,zCount:o,fittedCoordinates:l}):{maxZ:p,minZ:d,count:n,zCount:o,fittedCoordinates:l}}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 h.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 h.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,d={x:e+c/2,y:i+a/2,z:r-s/2},p={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},o={x:e-c/2,y:i+a/2,z:r-s/2};return[d,p,n,o]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e-c/2,y:i+a/2,z:r+s/2},p={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},o={x:e-c/2,y:i-a/2,z:r+s/2};return[d,p,n,o]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r+s/2},p={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},o={x:e-c/2,y:i+a/2,z:r+s/2};return[d,p,n,o]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new h.Matrix4().makeTranslation(-e,-i,-r),s=new h.Matrix4().makeTranslation(e,i,r),d=new h.Matrix4().makeRotationZ(a);return new h.Matrix4().multiply(s).multiply(d).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 h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new h.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const d=i.map(o=>new h.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,n=this.containerHeight/a;return{polygon2d:d,zoom:Math.min(p,n)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:c}=L,s={center:e,attribute:i,id:r,valid:a,width:c*2,height:c*2,depth:c*2,rotation:0},d=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new h.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const n=new h.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),o=this.containerWidth/(c*2),l=this.containerHeight/(c*2);return{point2d:n,zoom:Math.min(o,l)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=L,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(d=>new h.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.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 h.Matrix4().makeRotationZ(r.rotation),c=new h.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=S(v({},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 h.Matrix4().makeRotationZ(r.rotation),c=new h.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=S(v({},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 h.Vector3(y.x,y.y,y.z)).map(y=>y.applyMatrix4(c)),[d,p,n,o]=s,l=Math.max(Math.abs(d.x-n.x),Math.abs(d.x-p.x)),f=p.add(o).applyMatrix3(new h.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new h.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new h.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(v({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:l,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 d=r.getZ(s);a.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new h.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{lt as PointCloud};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.27.0-alpha.69",
3
+ "version": "1.27.0-alpha.70",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",