@labelbee/lb-annotation 1.28.0-alpha.11 → 1.28.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/pointCloud/index.js +4 -4
- package/dist/types/core/pointCloud/annotation.d.ts +2 -1
- package/dist/types/core/pointCloud/index.d.ts +9 -4
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +4 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:s,extraProps:m,config:f,checkMode:v,toolName:u,proxyMode:L}){this.updateLineList=a=>{const d=(a!=null?a:[]).map(l=>{var o;const i=(o=l.pointList)==null?void 0:o.map(r=>__spreadValues({i:r},lbUtils.PointCloudUtils.transferWorld2Canvas(r,this.toolInstance.size)));return __spreadProps(__spreadValues({},l),{pointList:i})});this.toolScheduler.updateDataByToolName(tool.EToolName.Line,d)},this.updatePolygonList=(a,d,l=!0)=>{let o=a.map(i=>{var r;const{polygon2d:P}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(i);return{id:i.id,sourceID:"",pointList:P,isRect:!0,valid:(r=i.valid)!=null?r:!0,attribute:i.attribute,trackID:i==null?void 0:i.trackID}});d&&(o=o.concat(d.map(i=>{var r;return __spreadProps(__spreadValues({},i),{pointList:(r=i==null?void 0:i.pointList)==null?void 0:r.map(P=>lbUtils.PointCloudUtils.transferWorld2Canvas(P,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,o,l)},this.updatePointList=(a,d=!0)=>{const l=a==null?void 0:a.map(o=>{var i;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(o);return __spreadProps(__spreadValues({},r),{id:o.id,sourceID:"",valid:(i=o.valid)!=null?i:!0,attribute:o.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l,d)};const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:s,extraProps:m,config:f,checkMode:v,toolName:u,proxyMode:L,view:O}){this.updateLineList=a=>{const d=(a!=null?a:[]).map(l=>{var o;const i=(o=l.pointList)==null?void 0:o.map(r=>__spreadValues({i:r},lbUtils.PointCloudUtils.transferWorld2Canvas(r,this.toolInstance.size)));return __spreadProps(__spreadValues({},l),{pointList:i})});this.toolScheduler.updateDataByToolName(tool.EToolName.Line,d)},this.updatePolygonList=(a,d,l=!0)=>{let o=a.map(i=>{var r;const{polygon2d:P}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(i);return{id:i.id,sourceID:"",pointList:P,isRect:!0,valid:(r=i.valid)!=null?r:!0,attribute:i.attribute,trackID:i==null?void 0:i.trackID}});d&&(o=o.concat(d.map(i=>{var r;return __spreadProps(__spreadValues({},i),{pointList:(r=i==null?void 0:i.pointList)==null?void 0:r.map(P=>lbUtils.PointCloudUtils.transferWorld2Canvas(P,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,o,l)},this.updatePointList=(a,d=!0)=>{const l=a==null?void 0:a.map(o=>{var i;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(o);return __spreadProps(__spreadValues({},r),{id:o.id,sourceID:"",valid:(i=o.valid)!=null?i:!0,attribute:o.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l,d)};const y=lbUtils.PointCloudUtils.getDefaultOrthographicParams(t),S=createEmptyImage(t),c=new Image;c.src=S;const h=new scheduler.ToolScheduler({container:e,size:t,toolName:u,proxyMode:L}),I=new CanvasScheduler.CanvasScheduler({container:e}),g=new index.PointCloud({container:e,noAppend:!0,isOrthographicCamera:!0,orthographicParams:y,view:O});s&&g.loadPCDFile(s),I.createCanvas(g.renderer.domElement);const C={size:t,config:JSON.stringify(__spreadProps(__spreadValues({},f),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:c,checkMode:v};m&&Object.assign(C,m);let p=[];scheduler.HybridToolUtils.isSingleTool(u)?p=[u]:p=u,p.forEach((a,d)=>{let l;if(a===tool.EToolName.PointCloudPolygon){const o=h.createOperation(a,c,C);o.eventBinding(),o.setPattern(tool.EPolygonPattern.Rect),this.toolInstance=o,this.toolInstance.eventBinding(),this.pointCloud2dOperation=o}else l=h.createOperation(a,c,__spreadProps(__spreadValues({},C),{textConfigurable:!1}));d===p.length-1&&(this.toolInstance||(this.toolInstance=l,this.toolInstance.eventBinding()))}),this.pointCloudInstance=g,this.canvasScheduler=I,this.toolScheduler=h,this.config=f}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=__spreadProps(__spreadValues({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(lbUtils.PointCloudUtils.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const e=createEmptyImage(t),s=new Image;s.src=e,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const e=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),s=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(e,s)}addLineListOnTopView(t){const e=lbUtils.PointCloudUtils.getLineListFromResultList(t);this.updateLineList(e)}addPointListOnTopView(t){const e=lbUtils.PointCloudUtils.getSphereParamsFromResultList(t);this.updatePointList(e)}updateData(t,e,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(e),this.addLineListOnTopView(e),this.addPointListOnTopView(e))}switchToCanvas(t){const e=this.toolScheduler.switchToCanvas(t);return e?(this.toolInstance.eventUnbinding(),e.eventBinding(),this.toolInstance=e,e):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(b){if(b&&b.__esModule)return b;var t=Object.create(null);return b&&Object.keys(b).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return b[e]}})}}),t.default=b,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(b,t,e)=>t in b?__defProp(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,__spreadValues=(b,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(b,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(b,e,t[e]);return b},__spreadProps=(b,t)=>__defProps(b,__getOwnPropDescs(t)),__async=(b,t,e)=>new Promise((i,r)=>{var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(b){if(b&&b.__esModule)return b;var t=Object.create(null);return b&&Object.keys(b).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return b[e]}})}}),t.default=b,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(b,t,e)=>t in b?__defProp(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,__spreadValues=(b,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(b,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(b,e,t[e]);return b},__spreadProps=(b,t)=>__defProps(b,__getOwnPropDescs(t)),__async=(b,t,e)=>new Promise((i,r)=>{var s=c=>{try{o(e.next(c))}catch(u){r(u)}},a=c=>{try{o(e.throw(c))}catch(u){r(u)}},o=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,a);o((e=e.apply(b,t)).next())});const DEFAULT_DISTANCE=30;let highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:o,checkMode:c,hiddenText:u=!1,view:f=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,h="blue")=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"sphere");const{radius:d,widthSegments:g,heightSegments:w}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:m}=n,x=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(d,g,w),C=new THREE__namespace.MeshBasicMaterial({color:h}),v=new THREE__namespace.Mesh(y,C);v.position.set(m.x,m.y,m.z),x.add(v),x.name=`sphere${p}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:h}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,h),this.render()},this.generateSpheres=n=>{n.forEach(h=>{const{fill:l}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(n,h=16777215)=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"box");const{center:d,width:g,height:w,depth:m,rotation:x}=n,y=new THREE__namespace.Group,C=new THREE__namespace.BoxGeometry(g,w,m),v=new THREE__namespace.MeshBasicMaterial({color:"blue"}),M=new THREE__namespace.Mesh(C,v),S=new THREE__namespace.BoxHelper(M,h),O=this.generateBoxArrow(n),P=this.generateBoxTrackID(n,h);P&&y.add(P);const B=this.generateBoxAttributeLabel(n,h);B&&y.add(B),y.add(S),y.add(O),d&&y.position.set(d.x,d.y,d.z),x&&y.rotation.set(0,0,x),y.name=`box${p}`;const L=new THREE__namespace.BoxGeometry(g,w,m),z=new THREE__namespace.MeshBasicMaterial({visible:!1}),A=new THREE__namespace.Mesh(L,z);y.add(A),y.userData={defaultColor:h,selectedID:p},this.scene.add(y)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const h=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
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=(...
|
|
32
|
-
${c}`:`${o.attribute}`,{sprite:p,canvasHeight:m}=this.generateLabel(d,100,n);return p.position.set(-o.width/2,0,-o.depth/2-m/150),p},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:n})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;o?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),n&&(c.material.uniforms.pointSize.value=n,this.pointsMaterialSize=n),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",o=>{var n,c,d;const p=this.renderer.domElement.getBoundingClientRect(),m=o.originalEvent.clientX-p.left,f=o.originalEvent.clientY-p.top;this.pointer.x=m/p.width*2-1,this.pointer.y=-(f/p.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(w=>{w instanceof THREE__namespace.Mesh?g.push(w):this.updateMaterialColor(w,y.userData.defaultColor)})});const x=this.raycaster.intersectObjects(g,!1);if(x.length>0){const y=x[0].object.parent;y==null||y.children.forEach(w=>{this.updateMaterialColor(w,this.highlightColor)}),(n=this.pipe)==null||n.setNeedUpdateCenter(!1),(c=this.pipe)==null||c.setSelectedIDs(y==null?void 0:y.userData.selectedID)}else(d=this.pipe)==null||d.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof THREE__namespace.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof THREE__namespace.BoxHelper||t instanceof THREE__namespace.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom: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,o=100,n=-100,c=500/o;return{left:h,right:s,top:l,bottom:u,near:o,far:n,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),o=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:l,polygonPointList:u,color:i,position:o};return this.filterBoxWorker||(this.filterBoxWorker=new filterBoxWorker),new Promise(c=>{var d;(d=this.filterBoxWorker)==null||d.postMessage(n),this.filterBoxWorker.onmessage=p=>{const{color:m,position:f,num:g}=p.data;this.geometry.dispose(),this.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(f,3)),this.geometry.setAttribute("color",new THREE__namespace.Float32BufferAttribute(m,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),c({geometry:this.geometry,num:g})}})}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),o=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(o).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 n=(e?[...e]:[]).map(f=>matrix.getCuboidFromPointCloudBox(f)),c=this.getAllAttributeColor(n),d=s.geometry.attributes.position.array,p=s.geometry.attributes.dimensions.array,m={cuboidList:n,position:d,color:p,colorList:c,highlightIndex:i,modifiedBoxIds:a,resetAreas:h};this.handleWebworker(m).then(f=>{const{color:g}=f;let x=g;(a.length||h.length)&&(x=g.map((w,C)=>w===-1?p[C]:w));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:o}=i,{fill:n}=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:n,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(o),c.translate(r,a,h);const p=new THREE__namespace.Mesh(c,d);e.add(p);const m=new THREE__namespace.PlaneGeometry(u,l);m.rotateY(Math.PI/2),m.rotateZ(o);const f=new THREE__namespace.Vector3(s/2,0,0),g=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(o);f.applyMatrix4(g),m.translate(r+f.x,a+f.y,h+f.z);const x=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),y=new THREE__namespace.Mesh(m,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,o=[];u.forEach(n=>{var c;const d=(c=t.subAttribute)==null?void 0:c[h],p=Array.isArray(d)?d:d==null?void 0:d.split(";");(p==null?void 0:p.includes(n.value))&&o.push(n.key)}),o.length>0&&(r&&(r+="\u3001"),r+=`${l}:${o.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const h=t.split(`
|
|
33
|
-
`),
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(h=this.currentPCDSrc,l){if(!h||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:p,color:d}=yield this.cacheInstance.loadPCDFile(h),g=new THREE__namespace.BufferGeometry;g.setAttribute("position",new THREE__namespace.BufferAttribute(p,3)),this.isSegment||g.setAttribute("dimensions",new THREE__namespace.BufferAttribute(d,3)),this.initCloudData(p);const w=new THREE__namespace.Points(g);this.renderPointCloud(w,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:h,points:l}){const p=m=>__async(this,null,function*(){try{return yield ImgUtils.default.load(m)}catch(x){return console.error("Error loading image:",x),null}}),d=h.length===0?[]:(yield Promise.all(h.map(m=>__async(this,null,function*(){let x=yield p(m.url);return!x&&m.fallbackUrl&&(x=yield p(m.fallbackUrl)),x})))).filter(m=>m!==null),g=h.map((m,x)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?y:[];const C=matrix.getHighlightIndexByPoints({points:l,calib:m.calib,width:d[x].width,height:d[x].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,C),C});return matrix.mergeHighlightList(g)}),this.filterPreResult=(n,h,l)=>__async(this,null,function*(){const{points:p}=yield this.cacheInstance.loadPCDFile(n),d=yield this.cacheInstance.loadIndexMap(n,p);return new Promise(g=>{const w=l.map(m=>{const x=MathUtils.default.calculatePointsInsideBox({indexMap:d,polygon:matrix.getCuboidFromPointCloudBox(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),y=x>=h.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},m),{valid:y,count:x})});g(w)})}),this.loadPCDFileByBox=(n,h,l)=>__async(this,null,function*(){const p=(w,m)=>__async(this,null,function*(){const{width:x=0,height:y=0,depth:C=0}=l!=null?l:{},v=yield this.filterPointsByBox(__spreadProps(__spreadValues({},h),{width:h.width+x,height:h.height+y,depth:h.depth+C}),w,m);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const M=new THREE__namespace.Points(v.geometry);M.name=this.pointCloudObjectName,this.scene.add(M),this.render()}),{points:d,color:g}=yield this.cacheInstance.loadPCDFile(n);p(d,g)}),this.generateRange=n=>{const h=this.createRange(n);this.scene.add(h)},this.generateBoxArrow=({width:n})=>{const h=new THREE__namespace.Vector3(1,0,0),l=new THREE__namespace.Vector3(n/2,0,0),p=2,d=new THREE__namespace.ArrowHelper(h,l,p,this.highlightColor);return d.visible=this.showDirection,d},this.generateLabel=(n,h,l)=>{const p=this.getTextCanvas(n),d=new THREE__namespace.Texture(p);d.minFilter=THREE__namespace.LinearFilter,d.magFilter=THREE__namespace.LinearFilter,d.needsUpdate=!0;const g=p.width/window.devicePixelRatio,w=p.height/window.devicePixelRatio,m=new THREE__namespace.SpriteMaterial({map:d,depthWrite:!1,color:l}),x=new THREE__namespace.Sprite(m);return x.scale.set(g/h,w/h,1),{sprite:x,canvasWidth:g,canvasHeight:w}},this.generateBoxTrackID=(n,h)=>{if(!n.trackID)return;const{sprite:l}=this.generateLabel(n.trackID.toString(),50,h);return l.position.set(-n.width/2,0,n.depth/2+.5),l},this.generateBoxAttributeLabel=(n,h)=>{if(!n.attribute||this.hiddenText)return;const l=this.findSubAttributeLabel(n,this.config),p=l?`${n.attribute}
|
|
32
|
+
${l}`:`${n.attribute}`,{sprite:d,canvasHeight:g}=this.generateLabel(p,100,h);return d.position.set(-n.width/2,0,-n.depth/2-g/150),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const p=l.material.uniforms.pointSize.value;n?l.material.uniforms.pointSize.value=Math.min(p*1.2,10):l.material.uniforms.pointSize.value=Math.max(p/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=c!=null?c:!1,this.hiddenText=u,this.view=f,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.filterBoxWorker=new filterBoxWorker,this.geometry=new THREE__namespace.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var h,l,p;const d=this.renderer.domElement.getBoundingClientRect(),g=n.originalEvent.clientX-d.left,w=n.originalEvent.clientY-d.top;this.pointer.x=g/d.width*2-1,this.pointer.y=-(w/d.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(y=>{y instanceof THREE__namespace.Group&&y.children.forEach(C=>{C instanceof THREE__namespace.Mesh?m.push(C):this.updateMaterialColor(C,y.userData.defaultColor)})});const x=this.raycaster.intersectObjects(m,!1);if(x.length>0){const y=x[0].object.parent;y==null||y.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(h=this.pipe)==null||h.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(y==null?void 0:y.userData.selectedID)}else(p=this.pipe)==null||p.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof THREE__namespace.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof THREE__namespace.BoxHelper||t instanceof THREE__namespace.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,c=e.y+r/2+s,u=e.y-r/2-s,f=100,n=-100,h=500/f;return{left:a,right:o,top:c,bottom:u,near:f,far:n,zoom:h}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:c}=t,u=this.getCameraVector(r,c,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:c,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),f=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:c,polygonPointList:u,color:i,position:f};return this.filterBoxWorker||(this.filterBoxWorker=new filterBoxWorker),new Promise(h=>{var l;(l=this.filterBoxWorker)==null||l.postMessage(n),this.filterBoxWorker.onmessage=p=>{const{color:d,position:g,num:w}=p.data;this.geometry.dispose(),this.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),this.geometry.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),h({geometry:this.geometry,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),c=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(c).applyMatrix4(f).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{highlightWorker.terminate(),highlightWorker=new highlightWorker$1({type:"module"}),highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),highlightWorker.terminate()},highlightWorker.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:a}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((c,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(g=>matrix.getCuboidFromPointCloudBox(g)),h=this.getAllAttributeColor(n),l=o.geometry.attributes.position.array,p=o.geometry.attributes.dimensions.array,d={cuboidList:n,position:l,color:p,colorList:h,highlightIndex:i,modifiedBoxIds:s,resetAreas:a};this.handleWebworker(d).then(g=>{const{color:w}=g;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==w.length){u(new Error("Error Path"));return}let m=w;(s.length||a.length)&&(m=w.map((C,v)=>C===-1?p[v]:C));const x=new THREE__namespace.BufferAttribute(m,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const y={color:m,view:this.view,currentPCDSrc:this.currentPCDSrc};c(y),this.workerLoading=!1,this.render()}).catch(g=>{this.workerLoading=!1,u(g)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:c,depth:u,rotation:f}=i,{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),h=new THREE__namespace.BoxGeometry(o,c,u),l=new THREE__namespace.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});h.rotateZ(f),h.translate(r,s,a);const p=new THREE__namespace.Mesh(h,l);e.add(p);const d=new THREE__namespace.PlaneGeometry(u,c);d.rotateY(Math.PI/2),d.rotateZ(f);const g=new THREE__namespace.Vector3(o/2,0,0),w=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(f);g.applyMatrix4(w),d.translate(r+g.x,s+g.y,a+g.z);const m=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new THREE__namespace.Mesh(d,m);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new THREE__namespace.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(a=>{const o=i.find(n=>n.value===a);if(!o||!o.subSelected)return;const{key:c,subSelected:u}=o,f=[];u.forEach(n=>{var h;const l=(h=t.subAttribute)==null?void 0:h[a],p=Array.isArray(l)?l:l==null?void 0:l.split(";");(p==null?void 0:p.includes(n.value))&&f.push(n.key)}),f.length>0&&(r&&(r+="\u3001"),r+=`${c}:${f.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const a=t.split(`
|
|
33
|
+
`),o=Math.max(...a.map(n=>i.measureText(n).width)),c=Math.ceil(o),u=s*1.5,f=u*a.length;e.width=c*r,e.height=f*r,e.style.width=`${c}px`,e.style.height=`${f}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",a.forEach((n,h)=>{i.fillText(n,0,h*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,h)=>n.z-h.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((n,h)=>n.x-h.x);const o=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));e=e.slice(o,c),e.sort((n,h)=>n.y-h.y);const u=Math.floor(e.length*s),f=Math.floor(e.length*(1-s));return e=e.slice(u,f),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:c,y:u})=>{t.forEach((f,n)=>{const h=r[n+1],l=MathUtils.default.getFootOfPerpendicular({x:c,y:u},f,h,!1,!0).length;(!i[n]||l<i[n].distance)&&(i[n]={distance:l,point:{x:c,y:u}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((c,u)=>{const f=r[u],n=r[u+1],h=r[u+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[u].point,line1:[f,n],p2:s[u+1].point,line2:[n,h]})});return a.some(c=>!(Number.isFinite(c.x)&&Number.isFinite(c.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(d=>d.uuid===this.pointsUuid);let c=0,u=0,f=0,n=0,h=[],l=[];const p=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let d=0;d<p.length;d+=3){const g=p[d],w=p[d+1],m=p[d+2];polygonTool.isInPolygon({x:g,y:w},t)&&(m||m===0)&&l.push({x:g,y:w,z:m})}return l.length?(i&&(l=this.filterNoise(l),h=this.getFittedCoordinates(t,l)),l.sort((d,g)=>d.z-g.z),c=l[0].z-.01,u=l[l.length-1].z+.01,n=l.length,e&&(f=l.filter(({z:d})=>d>=e[0]&&d<=e[1]).length),{maxZ:u,minZ:c,count:f,zCount:n,fittedCoordinates:h}):{maxZ:u,minZ:c,count:f,zCount:n,fittedCoordinates:h}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e+a/2,y:i+s/2,z:r-o/2},u={x:e+a/2,y:i+s/2,z:r+o/2},f={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2};return[c,u,f,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e-a/2,y:i+s/2,z:r+o/2},u={x:e-a/2,y:i+s/2,z:r-o/2},f={x:e-a/2,y:i-s/2,z:r-o/2},n={x:e-a/2,y:i-s/2,z:r+o/2};return[c,u,f,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e+a/2,y:i+s/2,z:r+o/2},u={x:e+a/2,y:i-s/2,z:r+o/2},f={x:e-a/2,y:i-s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r+o/2};return[c,u,f,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),c=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(c).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const c=i.map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,f=this.containerHeight/s;return{polygon2d:c,zoom:Math.min(u,f)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},c=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const f=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(a*2),h=this.containerHeight/(a*2);return{point2d:f,zoom:Math.min(n,h)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(c=>new THREE__namespace.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.getModelTransformationMatrix(t))).map(c=>({x:c.y,y:c.x})).map(c=>({x:-(c.x-this.containerWidth/2),y:-(c.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[c,u,f,n]=o,h=Math.max(Math.abs(c.x-f.x),Math.abs(c.x-u.x)),p=u.add(n).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-p.x,y:r.center.y-p.y,z:r.center.z-i},width:h,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const c=r.getZ(o);s.push(c>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
@@ -23,6 +23,7 @@ interface IPointCloudAnnotationProps {
|
|
|
23
23
|
checkMode?: boolean;
|
|
24
24
|
toolName: THybridToolName;
|
|
25
25
|
proxyMode?: boolean;
|
|
26
|
+
view?: string;
|
|
26
27
|
}
|
|
27
28
|
export declare class PointCloudAnnotation implements IPointCloudAnnotationOperation {
|
|
28
29
|
pointCloudInstance: PointCloud;
|
|
@@ -31,7 +32,7 @@ export declare class PointCloudAnnotation implements IPointCloudAnnotationOperat
|
|
|
31
32
|
toolScheduler: ToolScheduler;
|
|
32
33
|
toolInstance: any;
|
|
33
34
|
config: IPointCloudConfig;
|
|
34
|
-
constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName, proxyMode, }: IPointCloudAnnotationProps);
|
|
35
|
+
constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName, proxyMode, view, }: IPointCloudAnnotationProps);
|
|
35
36
|
updateConfig(config: IPointCloudConfig): void;
|
|
36
37
|
updateAttributeList(attributeList: IInputList[]): void;
|
|
37
38
|
/**
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as THREE from 'three';
|
|
7
7
|
import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig, ICalib, IPointCloudBoxList } from '@labelbee/lb-utils';
|
|
8
|
-
import { OrthographicCamera, PerspectiveCamera } from 'three';
|
|
8
|
+
import { BufferAttribute, OrthographicCamera, PerspectiveCamera } from 'three';
|
|
9
9
|
import { IPolygonPoint } from '@/types/tool/polygon';
|
|
10
10
|
import { PCDLoader } from './PCDLoader';
|
|
11
11
|
import { OrbitControls } from './OrbitControls';
|
|
@@ -30,6 +30,7 @@ interface IProps {
|
|
|
30
30
|
isSegment?: boolean;
|
|
31
31
|
checkMode?: boolean;
|
|
32
32
|
hiddenText?: boolean;
|
|
33
|
+
view?: string;
|
|
33
34
|
}
|
|
34
35
|
interface IPipeTypes {
|
|
35
36
|
setSelectedIDs: (ids?: string[] | string) => void;
|
|
@@ -92,8 +93,9 @@ export declare class PointCloud extends EventListener {
|
|
|
92
93
|
private filterBoxWorker;
|
|
93
94
|
private geometry;
|
|
94
95
|
private highlightColor;
|
|
96
|
+
private view;
|
|
95
97
|
constructor({ container, noAppend, isOrthographicCamera, orthographicParams, backgroundColor, // GRAY_BACKGROUND
|
|
96
|
-
config, isSegment, checkMode, hiddenText, }: IProps);
|
|
98
|
+
config, isSegment, checkMode, hiddenText, view, }: IProps);
|
|
97
99
|
setHighlightColor(selectedId?: string): void;
|
|
98
100
|
private updateMaterialColor;
|
|
99
101
|
setHandlerPipe(pipe: IPipeTypes): void;
|
|
@@ -274,14 +276,17 @@ export declare class PointCloud extends EventListener {
|
|
|
274
276
|
highlightOriginPointCloud(pointCloudBoxList?: IPointCloudBox[], highlightIndex?: number[], config?: {
|
|
275
277
|
modifiedBoxIds: string[];
|
|
276
278
|
resetAreas: ICoordinate[][];
|
|
277
|
-
}): Promise<
|
|
279
|
+
}): Promise<{
|
|
280
|
+
color: BufferAttribute[];
|
|
281
|
+
currentPCDSrc: string | undefined;
|
|
282
|
+
} | undefined>;
|
|
278
283
|
/**
|
|
279
284
|
* Clean all highlightBox
|
|
280
285
|
*/
|
|
281
286
|
clearHighlightBoxes(): void;
|
|
282
287
|
clearHighlightBoxesAndRender(): void;
|
|
283
288
|
highlightBoxes(boxes: IPointCloudBox[]): void;
|
|
284
|
-
updateColor(color: any[]): void;
|
|
289
|
+
updateColor(color: any[], src?: string): void;
|
|
285
290
|
/**
|
|
286
291
|
* Load PCD File by box
|
|
287
292
|
* @param src
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PointCloudUtils as c}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as
|
|
1
|
+
import{PointCloudUtils as c}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as j}from"../../constant/tool.js";import{CanvasScheduler as B}from"../../newCore/CanvasScheduler.js";import{PointCloud as E}from"./index.js";import{ToolScheduler as V,HybridToolUtils as x}from"../scheduler.js";var F=Object.defineProperty,N=Object.defineProperties,U=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,S=(n,t,o)=>t in n?F(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,u=(n,t)=>{for(var o in t||(t={}))J.call(t,o)&&S(n,o,t[o]);if(w)for(var o of w(t))W.call(t,o)&&S(n,o,t[o]);return n},p=(n,t)=>N(n,U(t));const _=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class k{constructor({size:t,container:o,pcdPath:s,extraProps:O,config:v,checkMode:b,toolName:h,proxyMode:D,view:T}){this.updateLineList=a=>{const d=(a!=null?a:[]).map(l=>{var e;const i=(e=l.pointList)==null?void 0:e.map(r=>u({i:r},c.transferWorld2Canvas(r,this.toolInstance.size)));return p(u({},l),{pointList:i})});this.toolScheduler.updateDataByToolName(C.Line,d)},this.updatePolygonList=(a,d,l=!0)=>{let e=a.map(i=>{var r;const{polygon2d:L}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(i);return{id:i.id,sourceID:"",pointList:L,isRect:!0,valid:(r=i.valid)!=null?r:!0,attribute:i.attribute,trackID:i==null?void 0:i.trackID}});d&&(e=e.concat(d.map(i=>{var r;return p(u({},i),{pointList:(r=i==null?void 0:i.pointList)==null?void 0:r.map(L=>c.transferWorld2Canvas(L,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,e,l)},this.updatePointList=(a,d=!0)=>{const l=a==null?void 0:a.map(e=>{var i;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(e);return p(u({},r),{id:e.id,sourceID:"",valid:(i=e.valid)!=null?i:!0,attribute:e.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l,d)};const R=c.getDefaultOrthographicParams(t),A=_(t),g=new Image;g.src=A;const f=new V({container:o,size:t,toolName:h,proxyMode:D}),y=new B({container:o}),P=new E({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:R,view:T});s&&P.loadPCDFile(s),y.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(u({},v),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:b};O&&Object.assign(I,O);let m=[];x.isSingleTool(h)?m=[h]:m=h,m.forEach((a,d)=>{let l;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(j.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else l=f.createOperation(a,g,p(u({},I),{textConfigurable:!1}));d===m.length-1&&(this.toolInstance||(this.toolInstance=l,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=y,this.toolScheduler=f,this.config=v}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(u({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(c.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=_(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const o=c.getBoxParamsFromResultList(t),s=c.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=c.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=c.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{k as PointCloudAnnotation};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as a from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as O,EPerspectiveView as v,PointCloudUtils as $,DEFAULT_SPHERE_PARAMS as D}from"@labelbee/lb-utils";import _ from"../../_virtual/highlightWorker.js";import E from"../../_virtual/filterBoxWorker.js";import{isInPolygon as K}from"../../utils/tool/polygonTool.js";import N from"../../utils/uuid.js";import F from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as X}from"./PCDLoader.js";import{OrbitControls as q}from"./OrbitControls.js";import{PointCloudCache as Q}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as J,mergeHighlightList as tt}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as et}from"./segmentation.js";import it from"./store/index.js";import rt from"./render/index.js";import nt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var ot=Object.defineProperty,st=Object.defineProperties,at=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable,R=(M,t,e)=>t in M?ot(M,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):M[t]=e,P=(M,t)=>{for(var e in t||(t={}))ht.call(t,e)&&R(M,e,t[e]);if(V)for(var e of V(t))ct.call(t,e)&&R(M,e,t[e]);return M},z=(M,t)=>st(M,at(t)),S=(M,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(p){r(p)}},h=l=>{try{o(e.throw(l))}catch(p){r(p)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,h);o((e=e.apply(M,t)).next())});const lt=30;let k=new _({type:"module"});class dt extends nt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:l,hiddenText:p=!1,view:y=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new a.Raycaster,this.pointer=new a.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var d;const g=(d=n.id)!=null?d:N();this.removeObjectByName(g,"sphere");const{radius:u,widthSegments:m,heightSegments:b}=D,{center:f}=n,x=new a.Group,w=new a.SphereGeometry(u,m,b),C=new a.MeshBasicMaterial({color:c}),B=new a.Mesh(w,C);B.position.set(f.x,f.y,f.z),x.add(B),x.name=`sphere${g}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:d}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,d)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var d;const g=(d=n.id)!=null?d:N();this.removeObjectByName(g,"box");const{center:u,width:m,height:b,depth:f,rotation:x}=n,w=new a.Group,C=new a.BoxGeometry(m,b,f),B=new a.MeshBasicMaterial({color:"blue"}),L=new a.Mesh(C,B),H=new a.BoxHelper(L,c),W=this.generateBoxArrow(n),I=this.generateBoxTrackID(n,c);I&&w.add(I);const T=this.generateBoxAttributeLabel(n,c);T&&w.add(T),w.add(H),w.add(W),u&&w.position.set(u.x,u.y,u.z),x&&w.rotation.set(0,0,x),w.name=`box${g}`;const U=new a.BoxGeometry(m,b,f),Z=new a.MeshBasicMaterial({visible:!1}),G=new a.Mesh(U,Z);w.add(G),w.userData={defaultColor:c,selectedID:g},this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
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 T,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=(...
|
|
32
|
-
${l}`:`${o.attribute}`,{sprite:g,canvasHeight:f}=this.generateLabel(u,100,n);return g.position.set(-o.width/2,0,-o.depth/2-f/150),g},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:n})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const u=l.material.uniforms.pointSize.value;o?l.material.uniforms.pointSize.value=Math.min(u*1.2,10):l.material.uniforms.pointSize.value=Math.max(u/1.2,1),n&&(l.material.uniforms.pointSize.value=n,this.pointsMaterialSize=n),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 Y,this.axesHelper=new h.AxesHelper(1e3),this.filterBoxWorker=new _,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",o=>{var n,l,u;const g=this.renderer.domElement.getBoundingClientRect(),f=o.originalEvent.clientX-g.left,y=o.originalEvent.clientY-g.top;this.pointer.x=f/g.width*2-1,this.pointer.y=-(y/g.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(b=>{b instanceof h.Group&&b.children.forEach(w=>{w instanceof h.Mesh?m.push(w):this.updateMaterialColor(w,b.userData.defaultColor)})});const x=this.raycaster.intersectObjects(m,!1);if(x.length>0){const b=x[0].object.parent;b==null||b.children.forEach(w=>{this.updateMaterialColor(w,this.highlightColor)}),(n=this.pipe)==null||n.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(b==null?void 0:b.userData.selectedID)}else(u=this.pipe)==null||u.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof h.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof h.BoxHelper||t instanceof h.Sprite)&&t.material.color.set(e)}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 T.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,o=100,n=-100,l=500/o;return{left:c,right:s,top:d,bottom:p,near:o,far:n,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}=k,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new 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}=L(t),o=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:d,polygonPointList:p,color:i,position:o};return this.filterBoxWorker||(this.filterBoxWorker=new _),new Promise(l=>{var u;(u=this.filterBoxWorker)==null||u.postMessage(n),this.filterBoxWorker.onmessage=g=>{const{color:f,position:y,num:m}=g.data;this.geometry.dispose(),this.geometry.setAttribute("position",new h.Float32BufferAttribute(y,3)),this.geometry.setAttribute("color",new h.Float32BufferAttribute(f,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),l({geometry:this.geometry,num:m})}})}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),o=new h.Matrix4().makeRotationZ(e);return new h.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(d).applyMatrix4(o).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 n=(e?[...e]:[]).map(y=>L(y)),l=this.getAllAttributeColor(n),u=s.geometry.attributes.position.array,g=s.geometry.attributes.dimensions.array,f={cuboidList:n,position:u,color:g,colorList:l,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(f).then(y=>{const{color:m}=y;let x=m;(a.length||c.length)&&(x=m.map((w,P)=>w===-1?g[P]:w));const b=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,b.needsUpdate=!0,s.geometry.setAttribute("dimensions",b),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:o}=i,{fill:n}=T.getColorFromConfig({attribute:i.attribute},S(v({},this.config),{attributeConfigurable:!0}),{}),l=new h.BoxGeometry(s,d,p),u=new h.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});l.rotateZ(o),l.translate(r,a,c);const g=new h.Mesh(l,u);e.add(g);const f=new h.PlaneGeometry(p,d);f.rotateY(Math.PI/2),f.rotateZ(o);const y=new h.Vector3(s/2,0,0),m=new h.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(o);y.applyMatrix4(m),f.translate(r+y.x,a+y.y,c+y.z);const x=new h.MeshBasicMaterial({color:n,side:h.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),b=new h.Mesh(f,x);e.add(b)}),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,o=[];p.forEach(n=>{var l;const u=(l=t.subAttribute)==null?void 0:l[c],g=Array.isArray(u)?u:u==null?void 0:u.split(";");(g==null?void 0:g.includes(n.value))&&o.push(n.key)}),o.length>0&&(r&&(r+="\u3001"),r+=`${d}:${o.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const c=t.split(`
|
|
33
|
-
`),
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>S(this,[...n],function*(c=this.currentPCDSrc,d){if(!c||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:g,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new a.BufferGeometry;m.setAttribute("position",new a.BufferAttribute(g,3)),this.isSegment||m.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(g);const b=new a.Points(m);this.renderPointCloud(b,d),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>S(this,[n],function*({mappingImgList:c,points:d}){const g=f=>S(this,null,function*(){try{return yield Y.load(f)}catch(x){return console.error("Error loading image:",x),null}}),u=c.length===0?[]:(yield Promise.all(c.map(f=>S(this,null,function*(){let x=yield g(f.url);return!x&&f.fallbackUrl&&(x=yield g(f.fallbackUrl)),x})))).filter(f=>f!==null),m=c.map((f,x)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(f.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(f.url))!=null?w:[];const C=J({points:d,calib:f.calib,width:u[x].width,height:u[x].height});return this.cacheInstance.cache2DHighlightIndex.set(f.url,C),C});return tt(m)}),this.filterPreResult=(n,c,d)=>S(this,null,function*(){const{points:g}=yield this.cacheInstance.loadPCDFile(n),u=yield this.cacheInstance.loadIndexMap(n,g);return new Promise(m=>{const b=d.map(f=>{const x=F.calculatePointsInsideBox({indexMap:u,polygon:A(f).polygonPointList,zScope:[f.center.z-f.depth/2,f.center.z+f.depth/2],box:f}),w=x>=c.lowerLimitPointsNumInBox;return z(P({},f),{valid:w,count:x})});m(b)})}),this.loadPCDFileByBox=(n,c,d)=>S(this,null,function*(){const g=(b,f)=>S(this,null,function*(){const{width:x=0,height:w=0,depth:C=0}=d!=null?d:{},B=yield this.filterPointsByBox(z(P({},c),{width:c.width+x,height:c.height+w,depth:c.depth+C}),b,f);if(!B){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const L=new a.Points(B.geometry);L.name=this.pointCloudObjectName,this.scene.add(L),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);g(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new a.Vector3(1,0,0),d=new a.Vector3(n/2,0,0),g=2,u=new a.ArrowHelper(c,d,g,this.highlightColor);return u.visible=this.showDirection,u},this.generateLabel=(n,c,d)=>{const g=this.getTextCanvas(n),u=new a.Texture(g);u.minFilter=a.LinearFilter,u.magFilter=a.LinearFilter,u.needsUpdate=!0;const m=g.width/window.devicePixelRatio,b=g.height/window.devicePixelRatio,f=new a.SpriteMaterial({map:u,depthWrite:!1,color:d}),x=new a.Sprite(f);return x.scale.set(m/c,b/c,1),{sprite:x,canvasWidth:m,canvasHeight:b}},this.generateBoxTrackID=(n,c)=>{if(!n.trackID)return;const{sprite:d}=this.generateLabel(n.trackID.toString(),50,c);return d.position.set(-n.width/2,0,n.depth/2+.5),d},this.generateBoxAttributeLabel=(n,c)=>{if(!n.attribute||this.hiddenText)return;const d=this.findSubAttributeLabel(n,this.config),g=d?`${n.attribute}
|
|
32
|
+
${d}`:`${n.attribute}`,{sprite:u,canvasHeight:m}=this.generateLabel(g,100,c);return u.position.set(-n.width/2,0,-n.depth/2-m/150),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const g=d.material.uniforms.pointSize.value;n?d.material.uniforms.pointSize.value=Math.min(g*1.2,10):d.material.uniforms.pointSize.value=Math.max(g/1.2,1),c&&(d.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=p,this.view=y,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new q(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new X,this.axesHelper=new a.AxesHelper(1e3),this.filterBoxWorker=new E,this.geometry=new a.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Q.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var c,d,g;const u=this.renderer.domElement.getBoundingClientRect(),m=n.originalEvent.clientX-u.left,b=n.originalEvent.clientY-u.top;this.pointer.x=m/u.width*2-1,this.pointer.y=-(b/u.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(w=>{w instanceof a.Group&&w.children.forEach(C=>{C instanceof a.Mesh?f.push(C):this.updateMaterialColor(C,w.userData.defaultColor)})});const x=this.raycaster.intersectObjects(f,!1);if(x.length>0){const w=x[0].object.parent;w==null||w.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(c=this.pipe)==null||c.setNeedUpdateCenter(!1),(d=this.pipe)==null||d.setSelectedIDs(w==null?void 0:w.userData.selectedID)}else(g=this.pipe)==null||g.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof a.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof a.BoxHelper||t instanceof a.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new it(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new et(P({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new rt(z(P({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return P({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return j.getColorFromConfig({attribute:t},z(P({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,p=e.y-r/2-s,y=100,n=-100,c=500/y;return{left:h,right:o,top:l,bottom:p,near:y,far:n,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:l}=t,p=this.getCameraVector(r,l,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=D,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:p}=A(t),y=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:l,polygonPointList:p,color:i,position:y};return this.filterBoxWorker||(this.filterBoxWorker=new E),new Promise(c=>{var d;(d=this.filterBoxWorker)==null||d.postMessage(n),this.filterBoxWorker.onmessage=g=>{const{color:u,position:m,num:b}=g.data;this.geometry.dispose(),this.geometry.setAttribute("position",new a.Float32BufferAttribute(m,3)),this.geometry.setAttribute("color",new a.Float32BufferAttribute(u,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),c({geometry:this.geometry,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=v.Front,s=lt){let h=O.frontViewMatrix4(s);switch(r){case v.Front:break;case v.Back:h=O.backViewMatrix4(s);break;case v.Left:h=O.leftViewMatrix4(s);break;case v.Right:h=O.rightViewMatrix4(s);break;case v.Top:h=O.topViewMatrix4(s);break;case v.LFT:h=O.leftFrontTopViewMatrix4(s,i);break;case v.RBT:h=O.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),l=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new a.Matrix4().makeTranslation(t.x,t.y,t.z),y=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(y).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return S(this,null,function*(){return new Promise((e,i)=>{k.terminate(),k=new _({type:"module"}),k.postMessage(t),k.onmessage=r=>{e(r.data),k.terminate()},k.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return S(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:h}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,p)=>{if(window.Worker){const n=(e?[...e]:[]).map(m=>A(m)),c=this.getAllAttributeColor(n),d=o.geometry.attributes.position.array,g=o.geometry.attributes.dimensions.array,u={cuboidList:n,position:d,color:g,colorList:c,highlightIndex:i,modifiedBoxIds:s,resetAreas:h};this.handleWebworker(u).then(m=>{const{color:b}=m;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==b.length){p(new Error("Error Path"));return}let f=b;(s.length||h.length)&&(f=b.map((C,B)=>C===-1?g[B]:C));const x=new a.BufferAttribute(f,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const w={color:f,view:this.view,currentPCDSrc:this.currentPCDSrc};l(w),this.workerLoading=!1,this.render()}).catch(m=>{this.workerLoading=!1,p(m)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:l,depth:p,rotation:y}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},z(P({},this.config),{attributeConfigurable:!0}),{}),c=new a.BoxGeometry(o,l,p),d=new a.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(y),c.translate(r,s,h);const g=new a.Mesh(c,d);e.add(g);const u=new a.PlaneGeometry(p,l);u.rotateY(Math.PI/2),u.rotateZ(y);const m=new a.Vector3(o/2,0,0),b=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(y);m.applyMatrix4(b),u.translate(r+m.x,s+m.y,h+m.z);const f=new a.MeshBasicMaterial({color:n,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new a.Mesh(u,f);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new a.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(h=>{const o=i.find(n=>n.value===h);if(!o||!o.subSelected)return;const{key:l,subSelected:p}=o,y=[];p.forEach(n=>{var c;const d=(c=t.subAttribute)==null?void 0:c[h],g=Array.isArray(d)?d:d==null?void 0:d.split(";");(g==null?void 0:g.includes(n.value))&&y.push(n.key)}),y.length>0&&(r&&(r+="\u3001"),r+=`${l}:${y.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const h=t.split(`
|
|
33
|
+
`),o=Math.max(...h.map(n=>i.measureText(n).width)),l=Math.ceil(o),p=s*1.5,y=p*h.length;e.width=l*r,e.height=y*r,e.style.width=`${l}px`,e.style.height=`${y}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((n,c)=>{i.fillText(n,0,c*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,c)=>n.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((n,c)=>n.x-c.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((n,c)=>n.y-c.y);const p=Math.floor(e.length*s),y=Math.floor(e.length*(1-s));return e=e.slice(p,y),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:p})=>{t.forEach((y,n)=>{const c=r[n+1],d=F.getFootOfPerpendicular({x:l,y:p},y,c,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:p}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((l,p)=>{const y=r[p],n=r[p+1],c=r[p+2];return $.getIntersectionBySlope({p1:s[p].point,line1:[y,n],p2:s[p+1].point,line2:[n,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(u=>u.uuid===this.pointsUuid);let l=0,p=0,y=0,n=0,c=[],d=[];const g=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let u=0;u<g.length;u+=3){const m=g[u],b=g[u+1],f=g[u+2];K({x:m,y:b},t)&&(f||f===0)&&d.push({x:m,y:b,z:f})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((u,m)=>u.z-m.z),l=d[0].z-.01,p=d[d.length-1].z+.01,n=d.length,e&&(y=d.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}):{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r-o/2},p={x:e+h/2,y:i+s/2,z:r+o/2},y={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2};return[l,p,y,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e-h/2,y:i+s/2,z:r+o/2},p={x:e-h/2,y:i+s/2,z:r-o/2},y={x:e-h/2,y:i-s/2,z:r-o/2},n={x:e-h/2,y:i-s/2,z:r+o/2};return[l,p,y,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r+o/2},p={x:e+h/2,y:i-s/2,z:r+o/2},y={x:e-h/2,y:i-s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r+o/2};return[l,p,y,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),l=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case v.Left:return this.getPolygonSidePoints(t);case v.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(n=>new a.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,y=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(p,y)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=D,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},l=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const y=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:y,zoom:Math.min(n,c)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=D,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=z(P({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=z(P({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(m=>new a.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(h)),[l,p,y,n]=o,c=Math.max(Math.abs(l.x-y.x),Math.abs(l.x-p.x)),g=p.add(n).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:z(P({},r),{center:{x:r.center.x-g.x,y:r.center.y-g.y,z:r.center.z-i},width:c,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{dt as PointCloud};
|