@labelbee/lb-annotation 1.16.0-alpha.3 → 1.16.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),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(m){if(m&&m.__esModule)return m;var t=Object.create(null);return m&&Object.keys(m).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return m[e]}})}}),t.default=m,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(m,t,e)=>t in m?__defProp(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,__spreadValues=(m,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(m,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(m,e,t[e]);return m},__spreadProps=(m,t)=>__defProps(m,__getOwnPropDescs(t)),__async=(m,t,e)=>new Promise((i,n)=>{var s=r=>{try{o(e.next(r))}catch(c){n(c)}},a=r=>{try{o(e.throw(r))}catch(c){n(c)}},o=r=>r.done?i(r.value):Promise.resolve(r.value).then(s,a);o((e=e.apply(m,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:n,backgroundColor:s="#4C4C4C",config:a,isSegment:o}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(r,c="blue")=>{var h;const l=(h=r.id)!=null?h:uuid();this.removeObjectByName(l);const{radius:d,widthSegments:u,heightSegments:f}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:p}=r,g=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(d,u,f),y=new THREE__namespace.MeshBasicMaterial({color:c}),w=new THREE__namespace.Mesh(x,y);w.position.set(p.x,p.y,p.z),g.add(w),g.name
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),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(m){if(m&&m.__esModule)return m;var t=Object.create(null);return m&&Object.keys(m).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return m[e]}})}}),t.default=m,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(m,t,e)=>t in m?__defProp(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,__spreadValues=(m,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(m,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(m,e,t[e]);return m},__spreadProps=(m,t)=>__defProps(m,__getOwnPropDescs(t)),__async=(m,t,e)=>new Promise((i,n)=>{var s=r=>{try{o(e.next(r))}catch(c){n(c)}},a=r=>{try{o(e.throw(r))}catch(c){n(c)}},o=r=>r.done?i(r.value):Promise.resolve(r.value).then(s,a);o((e=e.apply(m,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:n,backgroundColor:s="#4C4C4C",config:a,isSegment:o}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(r,c="blue")=>{var h;const l=(h=r.id)!=null?h:uuid();this.removeObjectByName(l,"sphere");const{radius:d,widthSegments:u,heightSegments:f}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:p}=r,g=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(d,u,f),y=new THREE__namespace.MeshBasicMaterial({color:c}),w=new THREE__namespace.Mesh(x,y);w.position.set(p.x,p.y,p.z),g.add(w),g.name=`sphere-${l}`,this.scene.add(g)},this.generateSphere=r=>{const{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(r,c),this.render()},this.generateSpheres=r=>{r.forEach(c=>{const{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:c.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(c,h)}),this.render()},this.addBoxToSense=(r,c=16777215)=>{var h;const l=(h=r.id)!=null?h:uuid();this.removeObjectByName(l,"box");const{center:d,width:u,height:f,depth:p,rotation:g}=r,x=new THREE__namespace.Group,y=new THREE__namespace.BoxGeometry(u,f,p),w=new THREE__namespace.MeshBasicMaterial({color:"blue"}),C=new THREE__namespace.Mesh(y,w),v=new THREE__namespace.BoxHelper(C,c),P=this.generateBoxArrow(r),b=this.generateBoxTrackID(r);b&&x.add(b),x.add(v),x.add(P),d&&x.position.set(d.x,d.y,d.z),g&&x.rotation.set(0,0,g),x.name=`box-${l}`,this.scene.add(x)},this.applyCameraTarget=r=>{if(this.camera.type==="OrthographicCamera"&&r){const c=this.getOrthographicCameraTarget(r);this.updateCameraZoom(r.zoom),this.updateCamera(r.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
2
2
|
attribute vec3 dimensions;
|
|
3
3
|
varying vec3 vDimensions;
|
|
4
4
|
uniform float pointSize;
|
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...r)=>__async(this,[...r],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.currentPCDSrc=c;const{points:l,color:d}=yield this.cacheInstance.loadPCDFile(c),u=new THREE__namespace.BufferGeometry;u.setAttribute("position",new THREE__namespace.BufferAttribute(l,3)),this.isSegment||u.setAttribute("dimensions",new THREE__namespace.BufferAttribute(d,3)),this.initCloudData(l);const f=new THREE__namespace.Points(u);this.renderPointCloud(f,h)}),this.loadPCDFileByBox=(r,c,h)=>__async(this,null,function*(){const l=(f,p)=>__async(this,null,function*(){const{width:g=0,height:x=0,depth:y=0}=h!=null?h:{},w=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+g,height:c.height+x,depth:c.depth+y}),f,p);if(!w){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=r;const C=new THREE__namespace.Points(w.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:d,color:u}=yield this.cacheInstance.loadPCDFile(r);l(d,u)}),this.generateRange=r=>{const c=this.createRange(r);this.scene.add(c)},this.generateBoxArrow=({width:r})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(r/2,0,0),l=2,d=16776960,u=new THREE__namespace.ArrowHelper(c,h,l,d);return u.visible=this.showDirection,u},this.generateBoxTrackID=r=>{if(!r.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(r.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),l=new THREE__namespace.Sprite(h);return l.scale.set(5,5,5),l.position.set(-r.width/2,0,r.depth/2+.5),l},this.applyZAxisPoints=r=>{this.zAxisLimit=r,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:r,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const l=h.material.uniforms.pointSize.value;r?h.material.uniforms.pointSize.value=Math.min(l*1.2,10):h.material.uniforms.pointSize.value=Math.max(l/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,i&&n?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.axesHelper),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)}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({dom:this.container,store:this.store}),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),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}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.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("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},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:n,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=n,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:n}=this.initCameraPosition;t.position.set(e,i,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:n}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,r=e.y+n/2+s,c=e.y-n/2-s,h=100,l=-100,d=500/h;return{left:a,right:o,top:r,bottom:c,near:h,far:l,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:n,width:s,height:a,depth:o,rotation:r}=t,c=this.getCameraVector(n,r,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,n),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(c,n),c)}updateCameraBySphere(t,e){const{center:i}=t,{radius:n}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:n*2,height:n*2,depth:n*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 n,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=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:r,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:o,zMax:r,polygonPointList:c,color:i,position:h};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(l),u.onmessage=f=>{const{color:p,position:g,num:x}=f.data,y=new THREE__namespace.BufferGeometry;y.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),y.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),u.terminate(),d({geometry:y,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,n=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(n){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),r=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(r).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const 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()}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],n=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${n}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,n)=>{if(window.Worker){const a=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),o=this.getAllAttributeColor(a),r={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:o};highlightWorker.postMessage(r),highlightWorker.onmessage=c=>{const{color:h}=c.data,l=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==h.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,l.needsUpdate=!0,e.geometry.setAttribute("dimensions",l),e.geometry.attributes.dimensions.needsUpdate=!0,i(h),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()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((l,d)=>l.z-d.z);const i=Math.floor(e.length*.05),n=e[i];e=e.filter(({z:l})=>l>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((l,d)=>l.x-d.x);const o=Math.floor(e.length*s),r=Math.floor(e.length*(1-s));e=e.slice(o,r),e.sort((l,d)=>l.y-d.y);const c=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));return e=e.slice(c,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let n=[...t,t[0]];e.forEach(({x:o,y:r})=>{t.forEach((c,h)=>{const l=n[h+1],d=MathUtils.default.getFootOfPerpendicular({x:o,y:r},c,l,!1,!0).length;(!i[h]||d<i[h].distance)&&(i[h]={distance:d,point:{x:o,y:r}})})}),n=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((o,r)=>{const c=n[r],h=n[r+1],l=n[r+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[r].point,line1:[c,h],p2:s[r+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var n,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let r=0,c=0,h=0,l=0,d=[],u=[];const f=((a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],x=f[p+1],y=f[p+2];polygonTool.isInPolygon({x:g,y:x},t)&&(y||y===0)&&u.push({x:g,y:x,z:y})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),r=u[0].z-.01,c=u[u.length-1].z+.01,l=u.length,e&&(h=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:c,minZ:r,count:h,zCount:l,fittedCoordinates:d}):{maxZ:c,minZ:r,count:h,zCount:l,fittedCoordinates:d}}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:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n-o/2},c={x:e+a/2,y:i+s/2,z:n+o/2},h={x:e-a/2,y:i+s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n-o/2};return[r,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e-a/2,y:i+s/2,z:n+o/2},c={x:e-a/2,y:i+s/2,z:n-o/2},h={x:e-a/2,y:i-s/2,z:n-o/2},l={x:e-a/2,y:i-s/2,z:n+o/2};return[r,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n+o/2},c={x:e+a/2,y:i-s/2,z:n+o/2},h={x:e-a/2,y:i-s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n+o/2};return[r,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-n),o=new THREE__namespace.Matrix4().makeTranslation(e,i,n),r=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(r).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:n,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 r=i.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/n,h=this.containerHeight/s;return{polygon2d:r,zoom:Math.min(c,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:n,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},r=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),c=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(r).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=c;const h=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:h,zoom:Math.min(l,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(r=>new THREE__namespace.Vector3(r.x,r.y,r.z)).map(r=>r.applyMatrix4(this.getModelTransformationMatrix(t))).map(r=>({x:r.y,y:r.x})).map(r=>({x:-(r.x-this.containerWidth/2),y:-(r.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,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=n;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+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=n;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:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[r,c,h,l]=o,d=Math.max(Math.abs(r.x-h.x),Math.abs(r.x-c.x)),f=c.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:__spreadProps(__spreadValues({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-i},width:d,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:n}=i,s=[],{count:a}=n;for(let o=0;o<a;o++){const r=n.getZ(o);s.push(r>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
31
|
+
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...r)=>__async(this,[...r],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.currentPCDSrc=c;const{points:l,color:d}=yield this.cacheInstance.loadPCDFile(c),u=new THREE__namespace.BufferGeometry;u.setAttribute("position",new THREE__namespace.BufferAttribute(l,3)),this.isSegment||u.setAttribute("dimensions",new THREE__namespace.BufferAttribute(d,3)),this.initCloudData(l);const f=new THREE__namespace.Points(u);this.renderPointCloud(f,h)}),this.loadPCDFileByBox=(r,c,h)=>__async(this,null,function*(){const l=(f,p)=>__async(this,null,function*(){const{width:g=0,height:x=0,depth:y=0}=h!=null?h:{},w=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+g,height:c.height+x,depth:c.depth+y}),f,p);if(!w){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=r;const C=new THREE__namespace.Points(w.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:d,color:u}=yield this.cacheInstance.loadPCDFile(r);l(d,u)}),this.generateRange=r=>{const c=this.createRange(r);this.scene.add(c)},this.generateBoxArrow=({width:r})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(r/2,0,0),l=2,d=16776960,u=new THREE__namespace.ArrowHelper(c,h,l,d);return u.visible=this.showDirection,u},this.generateBoxTrackID=r=>{if(!r.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(r.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),l=new THREE__namespace.Sprite(h);return l.scale.set(5,5,5),l.position.set(-r.width/2,0,r.depth/2+.5),l},this.applyZAxisPoints=r=>{this.zAxisLimit=r,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:r,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const l=h.material.uniforms.pointSize.value;r?h.material.uniforms.pointSize.value=Math.min(l*1.2,10):h.material.uniforms.pointSize.value=Math.max(l/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,i&&n?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.axesHelper),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)}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({dom:this.container,store:this.store}),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),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}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.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("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},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:n,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=n,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:n}=this.initCameraPosition;t.position.set(e,i,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:n}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,r=e.y+n/2+s,c=e.y-n/2-s,h=100,l=-100,d=500/h;return{left:a,right:o,top:r,bottom:c,near:h,far:l,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:n,width:s,height:a,depth:o,rotation:r}=t,c=this.getCameraVector(n,r,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,n),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(c,n),c)}updateCameraBySphere(t,e){const{center:i}=t,{radius:n}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:n*2,height:n*2,depth:n*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 n,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=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:r,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:o,zMax:r,polygonPointList:c,color:i,position:h};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(l),u.onmessage=f=>{const{color:p,position:g,num:x}=f.data,y=new THREE__namespace.BufferGeometry;y.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),y.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),u.terminate(),d({geometry:y,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,n=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(n){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),r=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(r).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const 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 n=e[i];n.type==="Group"&&n.name.startsWith(t)&&this.removeObjectByName(n.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],n=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${n}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,n)=>{if(window.Worker){const a=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),o=this.getAllAttributeColor(a),r={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:o};highlightWorker.postMessage(r),highlightWorker.onmessage=c=>{const{color:h}=c.data,l=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==h.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,l.needsUpdate=!0,e.geometry.setAttribute("dimensions",l),e.geometry.attributes.dimensions.needsUpdate=!0,i(h),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()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((l,d)=>l.z-d.z);const i=Math.floor(e.length*.05),n=e[i];e=e.filter(({z:l})=>l>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((l,d)=>l.x-d.x);const o=Math.floor(e.length*s),r=Math.floor(e.length*(1-s));e=e.slice(o,r),e.sort((l,d)=>l.y-d.y);const c=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));return e=e.slice(c,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let n=[...t,t[0]];e.forEach(({x:o,y:r})=>{t.forEach((c,h)=>{const l=n[h+1],d=MathUtils.default.getFootOfPerpendicular({x:o,y:r},c,l,!1,!0).length;(!i[h]||d<i[h].distance)&&(i[h]={distance:d,point:{x:o,y:r}})})}),n=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((o,r)=>{const c=n[r],h=n[r+1],l=n[r+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[r].point,line1:[c,h],p2:s[r+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var n,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let r=0,c=0,h=0,l=0,d=[],u=[];const f=((a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],x=f[p+1],y=f[p+2];polygonTool.isInPolygon({x:g,y:x},t)&&(y||y===0)&&u.push({x:g,y:x,z:y})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),r=u[0].z-.01,c=u[u.length-1].z+.01,l=u.length,e&&(h=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:c,minZ:r,count:h,zCount:l,fittedCoordinates:d}):{maxZ:c,minZ:r,count:h,zCount:l,fittedCoordinates:d}}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:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n-o/2},c={x:e+a/2,y:i+s/2,z:n+o/2},h={x:e-a/2,y:i+s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n-o/2};return[r,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e-a/2,y:i+s/2,z:n+o/2},c={x:e-a/2,y:i+s/2,z:n-o/2},h={x:e-a/2,y:i-s/2,z:n-o/2},l={x:e-a/2,y:i-s/2,z:n+o/2};return[r,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n+o/2},c={x:e+a/2,y:i-s/2,z:n+o/2},h={x:e-a/2,y:i-s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n+o/2};return[r,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-n),o=new THREE__namespace.Matrix4().makeTranslation(e,i,n),r=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(r).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:n,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 r=i.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/n,h=this.containerHeight/s;return{polygon2d:r,zoom:Math.min(c,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:n,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},r=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),c=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(r).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=c;const h=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:h,zoom:Math.min(l,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(r=>new THREE__namespace.Vector3(r.x,r.y,r.z)).map(r=>r.applyMatrix4(this.getModelTransformationMatrix(t))).map(r=>({x:r.y,y:r.x})).map(r=>({x:-(r.x-this.containerWidth/2),y:-(r.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,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=n;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+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=n;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:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[r,c,h,l]=o,d=Math.max(Math.abs(r.x-h.x),Math.abs(r.x-c.x)),f=c.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:__spreadProps(__spreadValues({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-i},width:d,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:n}=i,s=[],{count:a}=n;for(let o=0;o<a;o++){const r=n.getZ(o);s.push(r>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
@@ -121,7 +121,7 @@ export declare class PointCloud extends EventListener {
|
|
|
121
121
|
setDefaultControls(): void;
|
|
122
122
|
initRenderer(): void;
|
|
123
123
|
init(): void;
|
|
124
|
-
removeObjectByName(name: string): void;
|
|
124
|
+
removeObjectByName(name: string, prefix?: string): void;
|
|
125
125
|
/**
|
|
126
126
|
* Render box by params
|
|
127
127
|
* @param boxParams
|
|
@@ -214,6 +214,9 @@ export declare class PointCloud extends EventListener {
|
|
|
214
214
|
};
|
|
215
215
|
};
|
|
216
216
|
renderPointCloud(points: THREE.Points, radius?: number): void;
|
|
217
|
+
clearAllBox(): void;
|
|
218
|
+
clearAllSphere(): void;
|
|
219
|
+
clearAllGroupByPrefix(prefix?: string): void;
|
|
217
220
|
clearPointCloud(): void;
|
|
218
221
|
clearPointCloudAndRender(): void;
|
|
219
222
|
initCloudData(points: Float32Array): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as c from"three";import{toolStyleConverter as
|
|
1
|
+
import*as c from"three";import{toolStyleConverter as z,PerspectiveShiftUtils as M,EPerspectiveView as C,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as B}from"@labelbee/lb-utils";import N from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as F}from"../../utils/tool/polygonTool.js";import D from"../../utils/uuid.js";import R from"../../utils/MathUtils.js";import{PCDLoader as W}from"./PCDLoader.js";import{OrbitControls as Z}from"./OrbitControls.js";import{PointCloudCache as H}from"./cache.js";import{getCuboidFromPointCloudBox as A}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as U}from"./segmentation.js";import G from"./store/index.js";import $ from"./render/index.js";import X from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var Y=Object.defineProperty,q=Object.defineProperties,K=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,j=(w,t,e)=>t in w?Y(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))Q.call(t,e)&&j(w,e,t[e]);if(_)for(var e of _(t))J.call(t,e)&&j(w,e,t[e]);return w},v=(w,t)=>q(w,K(t)),O=(w,t,e)=>new Promise((i,n)=>{var s=r=>{try{o(e.next(r))}catch(h){n(h)}},a=r=>{try{o(e.throw(r))}catch(h){n(h)}},o=r=>r.done?i(r.value):Promise.resolve(r.value).then(s,a);o((e=e.apply(w,t)).next())});const tt=30,k=new N({type:"module"});class et extends X{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:n,backgroundColor:s="#4C4C4C",config:a,isSegment:o}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(r,h="blue")=>{var l;const d=(l=r.id)!=null?l:D();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:f}=B,{center:p}=r,g=new c.Group,y=new c.SphereGeometry(u,m,f),x=new c.MeshBasicMaterial({color:h}),P=new c.Mesh(y,x);P.position.set(p.x,p.y,p.z),g.add(P),g.name=`sphere-${d}`,this.scene.add(g)},this.generateSphere=r=>{const{fill:h}=z.getColorFromConfig({attribute:r.attribute},v(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(r,h),this.render()},this.generateSpheres=r=>{r.forEach(h=>{const{fill:l}=z.getColorFromConfig({attribute:h.attribute},v(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(r,h=16777215)=>{var l;const d=(l=r.id)!=null?l:D();this.removeObjectByName(d,"box");const{center:u,width:m,height:f,depth:p,rotation:g}=r,y=new c.Group,x=new c.BoxGeometry(m,f,p),P=new c.MeshBasicMaterial({color:"blue"}),S=new c.Mesh(x,P),L=new c.BoxHelper(S,h),I=this.generateBoxArrow(r),T=this.generateBoxTrackID(r);T&&y.add(T),y.add(L),y.add(I),u&&y.position.set(u.x,u.y,u.z),g&&y.rotation.set(0,0,g),y.name=`box-${d}`,this.scene.add(y)},this.applyCameraTarget=r=>{if(this.camera.type==="OrthographicCamera"&&r){const h=this.getOrthographicCameraTarget(r);this.updateCameraZoom(r.zoom),this.updateCamera(r.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
2
2
|
attribute vec3 dimensions;
|
|
3
3
|
varying vec3 vDimensions;
|
|
4
4
|
uniform float pointSize;
|
|
@@ -28,4 +28,4 @@ import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...r)=>O(this,[...r],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.currentPCDSrc=h;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(h),m=new c.BufferGeometry;m.setAttribute("position",new c.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new c.BufferAttribute(u,3)),this.initCloudData(d);const f=new c.Points(m);this.renderPointCloud(f,l)}),this.loadPCDFileByBox=(r,h,l)=>O(this,null,function*(){const d=(f,p)=>O(this,null,function*(){const{width:g=0,height:y=0,depth:x=0}=l!=null?l:{},P=yield this.filterPointsByBox(v(b({},h),{width:h.width+g,height:h.height+y,depth:h.depth+x}),f,p);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=r;const S=new c.Points(P.geometry);S.name=this.pointCloudObjectName,this.scene.add(S),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(r);d(u,m)}),this.generateRange=r=>{const h=this.createRange(r);this.scene.add(h)},this.generateBoxArrow=({width:r})=>{const h=new c.Vector3(1,0,0),l=new c.Vector3(r/2,0,0),d=2,u=16776960,m=new c.ArrowHelper(h,l,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=r=>{if(!r.trackID)return;const h=new c.Texture(this.getTextCanvas(r.trackID.toString()));h.needsUpdate=!0;const l=new c.SpriteMaterial({map:h,depthWrite:!1}),d=new c.Sprite(l);return d.scale.set(5,5,5),d.position.set(-r.width/2,0,r.depth/2+.5),d},this.applyZAxisPoints=r=>{this.zAxisLimit=r,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:r,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const d=l.material.uniforms.pointSize.value;r?l.material.uniforms.pointSize.value=Math.min(d*1.2,10):l.material.uniforms.pointSize.value=Math.max(d/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 c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,i&&n?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new Z(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new W,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.axesHelper),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=H.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new G(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 U({dom:this.container,store:this.store}),this.pointCloudRender=new $(v(b({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),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}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.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("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 b({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:n,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=n,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:n}=this.initCameraPosition;t.position.set(e,i,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new c.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=B.getColorFromConfig({attribute:i.attribute},v(b({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:n}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,r=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,u=500/l;return{left:a,right:o,top:r,bottom:h,near:l,far:d,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:n,width:s,height:a,depth:o,rotation:r}=t,h=this.getCameraVector(n,r,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,n),new c.Vector3(i.x,i.y,i.z)):(this.updateCamera(h,n),h)}updateCameraBySphere(t,e){const{center:i}=t,{radius:n}=z,s=this.getCameraVector(i,0,{width:n*2,height:n*2,depth:n*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 c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new c.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e,i){var n,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=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:r,polygonPointList:h}=A(t),l=e;i=i!=null?i:new Float32Array([]);const d={boxParams:t,zMin:o,zMax:r,polygonPointList:h,color:i,position:l};return new Promise(u=>{const m=new F;m.postMessage(d),m.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(g,3)),x.setAttribute("color",new c.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),m.terminate(),u({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,n=C.Front,s=tt){let a=M.frontViewMatrix4(s);switch(n){case C.Front:break;case C.Back:a=M.backViewMatrix4(s);break;case C.Left:a=M.leftViewMatrix4(s);break;case C.Right:a=M.rightViewMatrix4(s);break;case C.Top:a=M.topViewMatrix4(s);break;case C.LFT:a=M.leftFrontTopViewMatrix4(s,i);break;case C.RBT:a=M.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),r=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(r).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new c.BufferGeometry().setFromPoints(i),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new c.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}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],n=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${n}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,n)=>{if(window.Worker){const a=(t?[...t]:[]).map(h=>A(h)),o=this.getAllAttributeColor(a),r={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:o};k.postMessage(r),k.onmessage=h=>{const{color:l}=h.data,d=new c.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==l.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,d.needsUpdate=!0,e.geometry.setAttribute("dimensions",d),e.geometry.attributes.dimensions.needsUpdate=!0,i(l),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new c.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()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((d,u)=>d.z-u.z);const i=Math.floor(e.length*.05),n=e[i];e=e.filter(({z:d})=>d>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((d,u)=>d.x-u.x);const o=Math.floor(e.length*s),r=Math.floor(e.length*(1-s));e=e.slice(o,r),e.sort((d,u)=>d.y-u.y);const h=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(h,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let n=[...t,t[0]];e.forEach(({x:o,y:r})=>{t.forEach((h,l)=>{const d=n[l+1],u=R.getFootOfPerpendicular({x:o,y:r},h,d,!1,!0).length;(!i[l]||u<i[l].distance)&&(i[l]={distance:u,point:{x:o,y:r}})})}),n=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((o,r)=>{const h=n[r],l=n[r+1],d=n[r+2];return E.getIntersectionBySlope({p1:s[r].point,line1:[h,l],p2:s[r+1].point,line2:[l,d]})})}getSensesPointZAxisInPolygon(t,e,i){var n,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let r=0,h=0,l=0,d=0,u=[],m=[];const f=((a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];N({x:g,y},t)&&(x||x===0)&&m.push({x:g,y,z:x})}return m.length?(i&&(m=this.filterNoise(m),u=this.getFittedCoordinates(t,m)),m.sort((p,g)=>p.z-g.z),r=m[0].z-.01,h=m[m.length-1].z+.01,d=m.length,e&&(l=m.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:u}):{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:u}}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 c.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new c.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n-o/2},h={x:e+a/2,y:i+s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n+o/2},d={x:e-a/2,y:i+s/2,z:n-o/2};return[r,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e-a/2,y:i+s/2,z:n+o/2},h={x:e-a/2,y:i+s/2,z:n-o/2},l={x:e-a/2,y:i-s/2,z:n-o/2},d={x:e-a/2,y:i-s/2,z:n+o/2};return[r,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n+o/2},h={x:e+a/2,y:i-s/2,z:n+o/2},l={x:e-a/2,y:i-s/2,z:n+o/2},d={x:e-a/2,y:i+s/2,z:n+o/2};return[r,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:n},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-i,-n),o=new c.Matrix4().makeTranslation(e,i,n),r=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(o).multiply(r).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const r=i.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:r,zoom:Math.min(h,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:n,valid:s}=t,{radius:a}=z,o={center:e,attribute:i,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},r=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(r).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=h;const l=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),u=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=z,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(r=>new c.Vector3(r.x,r.y,r.z)).map(r=>r.applyMatrix4(this.getModelTransformationMatrix(t))).map(r=>({x:r.y,y:r.x})).map(r=>({x:-(r.x-this.containerWidth/2),y:-(r.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,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=v(b({},o),{width:o.width+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=v(b({},o),{width:o.width,height:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new c.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[r,h,l,d]=o,u=Math.max(Math.abs(r.x-l.x),Math.abs(r.x-h.x)),f=h.add(d).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:v(b({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-i},width:u,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:n}=i,s=[],{count:a}=n;for(let o=0;o<a;o++){const r=n.getZ(o);s.push(r>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{et as PointCloud};
|
|
31
|
+
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...r)=>O(this,[...r],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.currentPCDSrc=h;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(h),m=new c.BufferGeometry;m.setAttribute("position",new c.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new c.BufferAttribute(u,3)),this.initCloudData(d);const f=new c.Points(m);this.renderPointCloud(f,l)}),this.loadPCDFileByBox=(r,h,l)=>O(this,null,function*(){const d=(f,p)=>O(this,null,function*(){const{width:g=0,height:y=0,depth:x=0}=l!=null?l:{},P=yield this.filterPointsByBox(v(b({},h),{width:h.width+g,height:h.height+y,depth:h.depth+x}),f,p);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=r;const S=new c.Points(P.geometry);S.name=this.pointCloudObjectName,this.scene.add(S),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(r);d(u,m)}),this.generateRange=r=>{const h=this.createRange(r);this.scene.add(h)},this.generateBoxArrow=({width:r})=>{const h=new c.Vector3(1,0,0),l=new c.Vector3(r/2,0,0),d=2,u=16776960,m=new c.ArrowHelper(h,l,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=r=>{if(!r.trackID)return;const h=new c.Texture(this.getTextCanvas(r.trackID.toString()));h.needsUpdate=!0;const l=new c.SpriteMaterial({map:h,depthWrite:!1}),d=new c.Sprite(l);return d.scale.set(5,5,5),d.position.set(-r.width/2,0,r.depth/2+.5),d},this.applyZAxisPoints=r=>{this.zAxisLimit=r,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:r,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const d=l.material.uniforms.pointSize.value;r?l.material.uniforms.pointSize.value=Math.min(d*1.2,10):l.material.uniforms.pointSize.value=Math.max(d/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 c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,i&&n?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new Z(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new W,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.axesHelper),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=H.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new G(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 U({dom:this.container,store:this.store}),this.pointCloudRender=new $(v(b({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),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}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.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("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 b({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:n,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=n,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:n}=this.initCameraPosition;t.position.set(e,i,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new c.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=z.getColorFromConfig({attribute:i.attribute},v(b({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:n}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,r=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,u=500/l;return{left:a,right:o,top:r,bottom:h,near:l,far:d,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:n,width:s,height:a,depth:o,rotation:r}=t,h=this.getCameraVector(n,r,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,n),new c.Vector3(i.x,i.y,i.z)):(this.updateCamera(h,n),h)}updateCameraBySphere(t,e){const{center:i}=t,{radius:n}=B,s=this.getCameraVector(i,0,{width:n*2,height:n*2,depth:n*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 c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new c.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e,i){var n,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=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:r,polygonPointList:h}=A(t),l=e;i=i!=null?i:new Float32Array([]);const d={boxParams:t,zMin:o,zMax:r,polygonPointList:h,color:i,position:l};return new Promise(u=>{const m=new V;m.postMessage(d),m.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(g,3)),x.setAttribute("color",new c.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),m.terminate(),u({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,n=C.Front,s=tt){let a=M.frontViewMatrix4(s);switch(n){case C.Front:break;case C.Back:a=M.backViewMatrix4(s);break;case C.Left:a=M.leftViewMatrix4(s);break;case C.Right:a=M.rightViewMatrix4(s);break;case C.Top:a=M.topViewMatrix4(s);break;case C.LFT:a=M.leftFrontTopViewMatrix4(s,i);break;case C.RBT:a=M.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),r=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(r).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new c.BufferGeometry().setFromPoints(i),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new c.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 n=e[i];n.type==="Group"&&n.name.startsWith(t)&&this.removeObjectByName(n.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],n=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${n}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,n)=>{if(window.Worker){const a=(t?[...t]:[]).map(h=>A(h)),o=this.getAllAttributeColor(a),r={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:o};k.postMessage(r),k.onmessage=h=>{const{color:l}=h.data,d=new c.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==l.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,d.needsUpdate=!0,e.geometry.setAttribute("dimensions",d),e.geometry.attributes.dimensions.needsUpdate=!0,i(l),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new c.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()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((d,u)=>d.z-u.z);const i=Math.floor(e.length*.05),n=e[i];e=e.filter(({z:d})=>d>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((d,u)=>d.x-u.x);const o=Math.floor(e.length*s),r=Math.floor(e.length*(1-s));e=e.slice(o,r),e.sort((d,u)=>d.y-u.y);const h=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(h,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let n=[...t,t[0]];e.forEach(({x:o,y:r})=>{t.forEach((h,l)=>{const d=n[l+1],u=R.getFootOfPerpendicular({x:o,y:r},h,d,!1,!0).length;(!i[l]||u<i[l].distance)&&(i[l]={distance:u,point:{x:o,y:r}})})}),n=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((o,r)=>{const h=n[r],l=n[r+1],d=n[r+2];return E.getIntersectionBySlope({p1:s[r].point,line1:[h,l],p2:s[r+1].point,line2:[l,d]})})}getSensesPointZAxisInPolygon(t,e,i){var n,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let r=0,h=0,l=0,d=0,u=[],m=[];const f=((a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];F({x:g,y},t)&&(x||x===0)&&m.push({x:g,y,z:x})}return m.length?(i&&(m=this.filterNoise(m),u=this.getFittedCoordinates(t,m)),m.sort((p,g)=>p.z-g.z),r=m[0].z-.01,h=m[m.length-1].z+.01,d=m.length,e&&(l=m.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:u}):{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:u}}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 c.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new c.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n-o/2},h={x:e+a/2,y:i+s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n+o/2},d={x:e-a/2,y:i+s/2,z:n-o/2};return[r,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e-a/2,y:i+s/2,z:n+o/2},h={x:e-a/2,y:i+s/2,z:n-o/2},l={x:e-a/2,y:i-s/2,z:n-o/2},d={x:e-a/2,y:i-s/2,z:n+o/2};return[r,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n+o/2},h={x:e+a/2,y:i-s/2,z:n+o/2},l={x:e-a/2,y:i-s/2,z:n+o/2},d={x:e-a/2,y:i+s/2,z:n+o/2};return[r,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:n},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-i,-n),o=new c.Matrix4().makeTranslation(e,i,n),r=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(o).multiply(r).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const r=i.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:r,zoom:Math.min(h,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:n,valid:s}=t,{radius:a}=B,o={center:e,attribute:i,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},r=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(r).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=h;const l=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),u=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=B,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(r=>new c.Vector3(r.x,r.y,r.z)).map(r=>r.applyMatrix4(this.getModelTransformationMatrix(t))).map(r=>({x:r.y,y:r.x})).map(r=>({x:-(r.x-this.containerWidth/2),y:-(r.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,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=v(b({},o),{width:o.width+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=v(b({},o),{width:o.width,height:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new c.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[r,h,l,d]=o,u=Math.max(Math.abs(r.x-l.x),Math.abs(r.x-h.x)),f=h.add(d).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:v(b({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-i},width:u,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:n}=i,s=[],{count:a}=n;for(let o=0;o<a;o++){const r=n.getZ(o);s.push(r>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{et as PointCloud};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.16.0-alpha.
|
|
3
|
+
"version": "1.16.0-alpha.4",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"typescript": "^4.2.3"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@labelbee/lb-utils": "1.8.0-alpha.
|
|
97
|
+
"@labelbee/lb-utils": "1.8.0-alpha.4",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|