@labelbee/lb-annotation 1.16.0-alpha.1 → 1.16.0-alpha.3
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/index.js +31 -11
- package/dist/core/pointCloud/render/index.js +1 -1
- package/dist/core/pointCloud/store/index.js +1 -1
- package/dist/types/core/pointCloud/index.d.ts +11 -2
- package/dist/types/core/pointCloud/store/index.d.ts +4 -1
- package/es/core/pointCloud/index.js +31 -11
- package/es/core/pointCloud/render/index.js +1 -1
- package/es/core/pointCloud/store/index.js +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,31 @@
|
|
|
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(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
#include <clipping_planes_fragment>`)},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)),u.setAttribute("color",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:m=0,height:x=0,depth:y=0}=h!=null?h:{},w=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+m,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.size;r?h.material.size=Math.min(l*1.2,10):h.material.size=Math.max(l/1.2,1),c&&(h.material.size=c,this.pointsMaterialSize=c),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()}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:m,num:x}=f.data,y=new THREE__namespace.BufferGeometry;y.setAttribute("position",new THREE__namespace.Float32BufferAttribute(m,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.PointsMaterial({vertexColors:!0});i.onBeforeCompile=this.overridePointShader,i.size=this.pointsMaterialSize,e&&this.generateRange(e),this.pointsUuid=t.uuid,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})}}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.color.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("color",l),i(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);i.needsUpdate=!0,e.geometry.setAttribute("color",i),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 m=f[p],x=f[p+1],y=f[p+2];polygonTool.isInPolygon({x:m,y:x},t)&&(y||y===0)&&u.push({x:m,y:x,z:y})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,m)=>p.z-m.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(m=>new THREE__namespace.Vector3(m.x,m.y,m.z)).map(m=>m.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;
|
|
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=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);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=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
|
+
attribute vec3 dimensions;
|
|
3
|
+
varying vec3 vDimensions;
|
|
4
|
+
uniform float pointSize;
|
|
5
|
+
attribute float visibility;
|
|
6
|
+
|
|
7
|
+
void main() {
|
|
8
|
+
// Pass the vertex coordinates to the fragment shader
|
|
9
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
10
|
+
|
|
11
|
+
// Pass the dimensions to the fragment shader
|
|
12
|
+
vDimensions = dimensions;
|
|
13
|
+
gl_PointSize = pointSize;
|
|
14
|
+
|
|
15
|
+
if (visibility < 0.5) {
|
|
16
|
+
gl_Position = vec4(0.0, 0.0, 0.0, 1.0); // Invalid Position.
|
|
17
|
+
}
|
|
18
|
+
}`,fragmentShader:`
|
|
19
|
+
varying vec3 vDimensions;
|
|
20
|
+
void main() {
|
|
21
|
+
// Calculate color based on dimensions
|
|
22
|
+
vec3 color = vec3(vDimensions.x, vDimensions.y, vDimensions.z);
|
|
23
|
+
|
|
24
|
+
// If vDimensions is default value, the color change to white-rgb(255,255,255)
|
|
25
|
+
if (vDimensions.x == 0.0 && vDimensions.y == 0.0 && vDimensions.z == 0.0) {
|
|
26
|
+
color = vec3(255, 255, 255);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Output the final color
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),DrawUtils=require("../../../utils/tool/DrawUtils.js");function _interopNamespace(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if(t!=="default"){var o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}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=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloudRender{constructor({store:e,on:t,unbind:o,nextTick:l,config:d}){this.clearStash=()=>{var i,s;const n=this.scene.getObjectByName((s=(i=this.store.cacheSegData)==null?void 0:i.id)!=null?s:"");n&&(n.removeFromParent(),this.render3d())},this.generateNewPoints=i=>{const s=new THREE__namespace.BufferGeometry;s.setAttribute("position",new THREE__namespace.BufferAttribute(i.points,3));const n=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),a=new THREE__namespace.Points(s,n);a.name=i.id,this.store.scene.add(a),this.render3d()},this.updateNewPoints=i=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(n.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(i.points,3)),n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),n.geometry.attributes.position.needsUpdate=!0,n.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(i=this.store.cacheSegData)=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(i.attribute=this.store.currentAttribute,n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=o,this.nextTick=l,this.config=d,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.config)return lbUtils.colorArr[0].hexString;const{fill:t}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:e},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("
|
|
1
|
+
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),DrawUtils=require("../../../utils/tool/DrawUtils.js");function _interopNamespace(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if(t!=="default"){var o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}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=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloudRender{constructor({store:e,on:t,unbind:o,nextTick:l,config:d}){this.clearStash=()=>{var i,s;const n=this.scene.getObjectByName((s=(i=this.store.cacheSegData)==null?void 0:i.id)!=null?s:"");n&&(n.removeFromParent(),this.render3d())},this.generateNewPoints=i=>{const s=new THREE__namespace.BufferGeometry;s.setAttribute("position",new THREE__namespace.BufferAttribute(i.points,3));const n=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),a=new THREE__namespace.Points(s,n);a.name=i.id,this.store.scene.add(a),this.render3d()},this.updateNewPoints=i=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(n.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(i.points,3)),n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),n.geometry.attributes.position.needsUpdate=!0,n.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(i=this.store.cacheSegData)=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(i.attribute=this.store.currentAttribute,n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=o,this.nextTick=l,this.config=d,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.config)return lbUtils.colorArr[0].hexString;const{fill:t}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:e},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&DrawUtils.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const o=this.scene.children[t];o.type==="Points"&&o.name!==this.store.pointCloudObjectName&&o.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}module.exports=PointCloudRender;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(h){if(h&&h.__esModule)return h;var t=Object.create(null);return h&&Object.keys(h).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return h[e]}})}}),t.default=h,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=(h,t,e)=>t in h?__defProp(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,__spreadValues=(h,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(h,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(h,e,t[e]);return h},__spreadProps=(h,t)=>__defProps(h,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit:o,on:d,unbind:s}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new THREE__namespace.Raycaster,this.mouse=new THREE__namespace.Vector2,this.cloudData=new Map,this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=lbUtils.EPointCloudSegmentMode.Add,this.segmentCoverMode=lbUtils.EPointCloudSegmentCoverMode.Cover,this.segmentFocusMode=lbUtils.EPointCloudSegmentFocusMode.Unfocus,this.hideSegment=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=l=>{this.segmentData.forEach((u,c)=>{var g;if(c!==((g=this.cacheSegData)==null?void 0:g.id)){const S=this.scene.getObjectByName(c);S&&S.removeFromParent()}});const r=l==null?void 0:l.filter(u=>{var c;return!this.hiddenAttributes.some(g=>g===u.attribute)&&u.id!==((c=this.cacheSegData)==null?void 0:c.id)});(r==null?void 0:r.length)!==0&&r.map(u=>(this.emit("addNewPointsCloud",u),u)),this.emit("reRender3d")},this.updateCoverPoints=(l=new Float32Array([]))=>{this.segmentData.forEach((r,u)=>{var c;if(u!==((c=this.cacheSegData)==null?void 0:c.id)){const g=lbUtils.PointCloudUtils.splitPointsFromPoints(r.points,l);r.points=g;const S=this.scene.getObjectByName(u);S&&(S.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),S.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=o,this.on=d,this.unbind=s,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentData=this.clearSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("clearSelectedSegmentData",this.clearSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("clearSelectedSegmentData",this.clearSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return fsm.segmentStatus}get isReadyStatus(){return fsm.isReadyStatus}get isCheckStatus(){return fsm.isCheckStatus}get isEditStatus(){return fsm.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const o=[];a.indexes.forEach(s=>{o.push(i[s*3],i[s*3+1],i[s*3+2])});const d=__spreadProps(__spreadValues({},a),{points:new Float32Array(o)});this.segmentData.set(a.id,d),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},a),{points:new Float32Array(o)}))}),this.syncSegmentData()}statusToggle(){fsm.statusToggle()}updateStatus2Edit(){fsm.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${DEFAULT_PREFIX}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===lbUtils.EPointCloudSegmentFocusMode.Focus&&this.emit("clearPointCloud"),t===lbUtils.EPointCloudSegmentFocusMode.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===lbUtils.EPointCloudSegmentFocusMode.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){var e,i,a;if(!this.isReadyStatus&&!this.isEditStatus)return;const o=t,d=this.scene.getObjectByName(this.pointCloudObjectName),s=(a=(i=(e=d==null?void 0:d.geometry)==null?void 0:e.attributes)==null?void 0:i.position)==null?void 0:a.array;if(s){const l=s.length,r=[],u=[],c=[];for(let n=0;n<l;n+=3){const p=new THREE__namespace.Vector3(s[n],s[n+1],s[n+2]);p.project(this.camera);const D={x:0,y:0};if(D.x=Math.round(p.x*this.container.clientWidth/2+this.container.clientWidth/2),D.y=Math.round(-p.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(D,o)){const y=s[n],P=s[n+1],b=s[n+2],m=lbUtils.PointCloudUtils.getCloudKeys(y,P,b);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(m).visible=!1,r.push(s[n],s[n+1],s[n+2]),c.push(n/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(r.push(s[n],s[n+1],s[n+2]),c.push(n/3),this.cloudData.get(m).visible===!0&&u.push(s[n],s[n+1],s[n+2])),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(m).visible===!1&&(r.push(s[n],s[n+1],s[n+2]),c.push(n/3)),this.cloudData.get(m).visible===!1&&(this.cloudData.get(m).visible=!0))}}if(c.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const g=new Float32Array(r),S=new Float32Array(u);this.updateStatusBySelector(g,S,c)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:o=new Float32Array([])}=this.cacheSegData,d=a.length+t.length,s=new Float32Array(d);s.set(a,0),s.set(t,a.length);const l=o.length+e.length,r=new Float32Array(l);r.set(o,0),r.set(e,o.length),this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:s,coverPoints:r,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:a,indexes:o}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(a,t),indexes:lbUtils.PointCloudUtils.splitPointsFromIndexes(o,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],o=t[i+1],d=t[i+2],s=lbUtils.PointCloudUtils.getCloudKeys(a,o,d),l=this.cloudData.get(s);Object.keys(e).forEach(r=>{l[r]=e[r]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}clearSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let o=0;o<i.length;o++){const d=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[o],a[o+1],a[o+2]));d&&(d.visible=!1)}this.cacheSegData=void 0,fsm.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}}}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),fsm.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}module.exports=PointCloudStore;
|
|
1
|
+
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(o){if(o&&o.__esModule)return o;var t=Object.create(null);return o&&Object.keys(o).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return o[e]}})}}),t.default=o,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=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit:n,on:d,unbind:h}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new THREE__namespace.Raycaster,this.mouse=new THREE__namespace.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=lbUtils.EPointCloudSegmentMode.Add,this.segmentCoverMode=lbUtils.EPointCloudSegmentCoverMode.Cover,this.segmentFocusMode=lbUtils.EPointCloudSegmentFocusMode.Unfocus,this.hideSegment=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=l=>{this.segmentData.forEach((s,c)=>{var u;if(c!==((u=this.cacheSegData)==null?void 0:u.id)){const g=this.scene.getObjectByName(c);g&&g.removeFromParent()}});const r=l==null?void 0:l.filter(s=>{var c;return!this.hiddenAttributes.some(u=>u===s.attribute)&&s.id!==((c=this.cacheSegData)==null?void 0:c.id)});(r==null?void 0:r.length)!==0&&r.map(s=>(this.emit("addNewPointsCloud",s),s)),this.emit("reRender3d")},this.updateCoverPoints=(l=new Float32Array([]))=>{this.segmentData.forEach((r,s)=>{var c;if(s!==((c=this.cacheSegData)==null?void 0:c.id)){const u=lbUtils.PointCloudUtils.splitPointsFromPoints(r.points,l);r.points=u;const g=this.scene.getObjectByName(s);g&&(g.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(u,3)),g.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=n,this.on=d,this.unbind=h,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return fsm.segmentStatus}get isReadyStatus(){return fsm.isReadyStatus}get isCheckStatus(){return fsm.isCheckStatus}get isEditStatus(){return fsm.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(i[h*3],i[h*3+1],i[h*3+2])});const d=__spreadProps(__spreadValues({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,d),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){fsm.statusToggle()}updateStatus2Edit(){fsm.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${DEFAULT_PREFIX}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===lbUtils.EPointCloudSegmentFocusMode.Focus&&this.emit("clearPointCloud"),t===lbUtils.EPointCloudSegmentFocusMode.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===lbUtils.EPointCloudSegmentFocusMode.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,i=this.originPoints;if(i){const a=i.length,n=[],d=[],h=[];for(let s=0;s<a;s+=3){const c=new THREE__namespace.Vector3(i[s],i[s+1],i[s+2]);c.project(this.camera);const u={x:0,y:0};if(u.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),u.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(u,e)){const m=i[s],p=i[s+1],D=i[s+2],S=lbUtils.PointCloudUtils.getCloudKeys(m,p,D);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(S).visible=!1,n.push(i[s],i[s+1],i[s+2]),h.push(s/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(n.push(i[s],i[s+1],i[s+2]),h.push(s/3),this.cloudData.get(S).visible===!0&&d.push(i[s],i[s+1],i[s+2])),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(S).visible===!1&&(n.push(i[s],i[s+1],i[s+2]),h.push(s/3)),this.cloudData.get(S).visible===!1&&(this.cloudData.get(S).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const l=new Float32Array(n),r=new Float32Array(d);this.updateStatusBySelector(l,r,h)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,d=a.length+t.length,h=new Float32Array(d);h.set(a,0),h.set(t,a.length);const l=n.length+e.length,r=new Float32Array(l);r.set(n,0),r.set(e,n.length),this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:h,coverPoints:r,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(a,t),indexes:lbUtils.PointCloudUtils.splitPointsFromIndexes(n,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],n=t[i+1],d=t[i+2],h=lbUtils.PointCloudUtils.getCloudKeys(a,n,d),l=this.cloudData.get(h);Object.keys(e).forEach(r=>{l[r]=e[r]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let n=0;n<i.length;n++){const d=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[n],a[n+1],a[n+2]));d&&(d.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,fsm.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),fsm.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}module.exports=PointCloudStore;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as THREE from 'three';
|
|
7
7
|
import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig } from '@labelbee/lb-utils';
|
|
8
|
-
import { OrthographicCamera, PerspectiveCamera
|
|
8
|
+
import { OrthographicCamera, PerspectiveCamera } from 'three';
|
|
9
9
|
import { IPolygonPoint } from '@/types/tool/polygon';
|
|
10
10
|
import { PCDLoader } from './PCDLoader';
|
|
11
11
|
import { OrbitControls } from './OrbitControls';
|
|
@@ -73,6 +73,7 @@ export declare class PointCloud extends EventListener {
|
|
|
73
73
|
*/
|
|
74
74
|
private highlightPCDSrc?;
|
|
75
75
|
private segmentOperation?;
|
|
76
|
+
private isSegment;
|
|
76
77
|
constructor({ container, noAppend, isOrthographicCamera, orthographicParams, backgroundColor, // GRAY_BACKGROUND
|
|
77
78
|
config, isSegment, }: IProps);
|
|
78
79
|
initSegment(): void;
|
|
@@ -203,7 +204,15 @@ export declare class PointCloud extends EventListener {
|
|
|
203
204
|
} | undefined>;
|
|
204
205
|
getCameraVector(centerPoint: I3DSpaceCoord, rotationZ: number, volume: IVolume, perspectiveView?: EPerspectiveView, defaultDistance?: number): THREE.Vector3;
|
|
205
206
|
createRange(radius: number): THREE.Line<THREE.BufferGeometry, THREE.LineBasicMaterial>;
|
|
206
|
-
|
|
207
|
+
initShaderMaterial: () => {
|
|
208
|
+
vertexShader: string;
|
|
209
|
+
fragmentShader: string;
|
|
210
|
+
uniforms: {
|
|
211
|
+
pointSize: {
|
|
212
|
+
value: number;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
};
|
|
207
216
|
renderPointCloud(points: THREE.Points, radius?: number): void;
|
|
208
217
|
clearPointCloud(): void;
|
|
209
218
|
clearPointCloudAndRender(): void;
|
|
@@ -26,6 +26,7 @@ declare class PointCloudStore {
|
|
|
26
26
|
mouse: THREE.Vector2;
|
|
27
27
|
/** Data Store */
|
|
28
28
|
cloudData: Map<any, any>;
|
|
29
|
+
originPoints: Float32Array;
|
|
29
30
|
segmentData: Map<string, IPointCloudSegmentation>;
|
|
30
31
|
cacheSegData?: IPointCloudSegmentation;
|
|
31
32
|
/** Raycaster Hover PointsID */
|
|
@@ -78,6 +79,7 @@ declare class PointCloudStore {
|
|
|
78
79
|
setSegmentFocusMode(focusMode: EPointCloudSegmentFocusMode): void;
|
|
79
80
|
switchSegmentHideMode(hideSegment: boolean): void;
|
|
80
81
|
setHiddenAttributes(attributes: string[]): void;
|
|
82
|
+
setOriginPoints(originPoints: Float32Array): void;
|
|
81
83
|
updateCanvasBasicStyle(canvas: HTMLCanvasElement, size: ISize, zIndex: number): void;
|
|
82
84
|
syncPolygon2d(polygon2d: ICoordinate[]): void;
|
|
83
85
|
getPointsInPolygon(originPolygon: ICoordinate[]): void;
|
|
@@ -91,7 +93,8 @@ declare class PointCloudStore {
|
|
|
91
93
|
[key: string]: any;
|
|
92
94
|
}): void;
|
|
93
95
|
clearStash(): void;
|
|
94
|
-
|
|
96
|
+
deleteSelectedSegmentData(id?: string): void;
|
|
97
|
+
resetSelectedSegmentStatus(): void;
|
|
95
98
|
updateCheck2Edit(): void;
|
|
96
99
|
checkPoints(): void;
|
|
97
100
|
/**
|
|
@@ -1,11 +1,31 @@
|
|
|
1
|
-
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(...r)=>O(this,[...r],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.currentPCDSrc=h;const{points:d,color:p}=yield this.cacheInstance.loadPCDFile(h),u=new c.BufferGeometry;u.setAttribute("position",new c.BufferAttribute(d,3)),u.setAttribute("color",new c.BufferAttribute(p,3)),this.initCloudData(d);const f=new c.Points(u);this.renderPointCloud(f,l)}),this.loadPCDFileByBox=(r,h,l)=>O(this,null,function*(){const d=(f,m)=>O(this,null,function*(){const{width:g=0,height:y=0,depth:x=0}=l!=null?l:{},P=yield this.filterPointsByBox(M(b({},h),{width:h.width+g,height:h.height+y,depth:h.depth+x}),f,m);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:p,color:u}=yield this.cacheInstance.loadPCDFile(r);d(p,u)}),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,p=16776960,u=new c.ArrowHelper(h,l,d,p);return u.visible=this.showDirection,u},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.size;r?l.material.size=Math.min(d*1.2,10):l.material.size=Math.max(d/1.2,1),h&&(l.material.size=h,this.pointsMaterialSize=h),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()}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 $(M(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},M(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,p=500/l;return{left:a,right:o,top:r,bottom:h,near:l,far:d,zoom:p}}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(p=>{const u=new F;u.postMessage(d),u.onmessage=f=>{const{color:m,position:g,num:y}=f.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(g,3)),x.setAttribute("color",new c.Float32BufferAttribute(m,3)),x.computeBoundingSphere(),u.terminate(),p({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,n=C.Front,s=tt){let a=v.frontViewMatrix4(s);switch(n){case C.Front:break;case C.Back:a=v.backViewMatrix4(s);break;case C.Left:a=v.leftViewMatrix4(s);break;case C.Right:a=v.rightViewMatrix4(s);break;case C.Top:a=v.topViewMatrix4(s);break;case C.LFT:a=v.leftFrontTopViewMatrix4(s,i);break;case C.RBT:a=v.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.PointsMaterial({vertexColors:!0});i.onBeforeCompile=this.overridePointShader,i.size=this.pointsMaterialSize,e&&this.generateRange(e),this.pointsUuid=t.uuid,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})}}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.color.array,colorList:o};j.postMessage(r),j.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("color",d),i(l),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new c.BufferAttribute(t,3);i.needsUpdate=!0,e.geometry.setAttribute("color",i),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,p)=>d.z-p.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,p)=>d.x-p.x);const o=Math.floor(e.length*s),r=Math.floor(e.length*(1-s));e=e.slice(o,r),e.sort((d,p)=>d.y-p.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],p=R.getFootOfPerpendicular({x:o,y:r},h,d,!1,!0).length;(!i[l]||p<i[l].distance)&&(i[l]={distance:p,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 V.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(m=>m.uuid===this.pointsUuid);let r=0,h=0,l=0,d=0,p=[],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 m=0;m<f.length;m+=3){const g=f[m],y=f[m+1],x=f[m+2];N({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),p=this.getFittedCoordinates(t,u)),u.sort((m,g)=>m.z-g.z),r=u[0].z-.01,h=u[u.length-1].z+.01,d=u.length,e&&(l=u.filter(({z:m})=>m>=e[0]&&m<=e[1]).length),{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:p}):{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:p}}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),p=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,p)/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=M(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=M(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,p=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:M(b({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-i},width:p,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};
|
|
1
|
+
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as M,EPerspectiveView as C,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import F from"../../_virtual/filterBoxWorker.js";import{isInPolygon as N}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 V({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);const{radius:u,widthSegments:m,heightSegments:f}=z,{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=d,this.scene.add(g)},this.generateSphere=r=>{const{fill:h}=B.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}=B.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);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=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
|
+
attribute vec3 dimensions;
|
|
3
|
+
varying vec3 vDimensions;
|
|
4
|
+
uniform float pointSize;
|
|
5
|
+
attribute float visibility;
|
|
6
|
+
|
|
7
|
+
void main() {
|
|
8
|
+
// Pass the vertex coordinates to the fragment shader
|
|
9
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
10
|
+
|
|
11
|
+
// Pass the dimensions to the fragment shader
|
|
12
|
+
vDimensions = dimensions;
|
|
13
|
+
gl_PointSize = pointSize;
|
|
14
|
+
|
|
15
|
+
if (visibility < 0.5) {
|
|
16
|
+
gl_Position = vec4(0.0, 0.0, 0.0, 1.0); // Invalid Position.
|
|
17
|
+
}
|
|
18
|
+
}`,fragmentShader:`
|
|
19
|
+
varying vec3 vDimensions;
|
|
20
|
+
void main() {
|
|
21
|
+
// Calculate color based on dimensions
|
|
22
|
+
vec3 color = vec3(vDimensions.x, vDimensions.y, vDimensions.z);
|
|
23
|
+
|
|
24
|
+
// If vDimensions is default value, the color change to white-rgb(255,255,255)
|
|
25
|
+
if (vDimensions.x == 0.0 && vDimensions.y == 0.0 && vDimensions.z == 0.0) {
|
|
26
|
+
color = vec3(255, 255, 255);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Output the final color
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as o from"three";import{colorArr as g,toolStyleConverter as p}from"@labelbee/lb-utils";import P from"../../../utils/tool/DrawUtils.js";var m=Object.defineProperty,b=Object.defineProperties,f=Object.getOwnPropertyDescriptors,
|
|
1
|
+
import*as o from"three";import{colorArr as g,toolStyleConverter as p}from"@labelbee/lb-utils";import P from"../../../utils/tool/DrawUtils.js";var m=Object.defineProperty,b=Object.defineProperties,f=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,S=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,h=(n,e,t)=>e in n?m(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,w=(n,e)=>{for(var t in e||(e={}))S.call(e,t)&&h(n,t,e[t]);if(d)for(var t of d(e))v.call(e,t)&&h(n,t,e[t]);return n},C=(n,e)=>b(n,f(e));class _{constructor({store:e,on:t,unbind:a,nextTick:c,config:u}){this.clearStash=()=>{var r,s;const i=this.scene.getObjectByName((s=(r=this.store.cacheSegData)==null?void 0:r.id)!=null?s:"");i&&(i.removeFromParent(),this.render3d())},this.generateNewPoints=r=>{const s=new o.BufferGeometry;s.setAttribute("position",new o.BufferAttribute(r.points,3));const i=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),l=new o.Points(s,i);l.name=r.id,this.store.scene.add(l),this.render3d()},this.updateNewPoints=r=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(i.geometry.setAttribute("position",new o.Float32BufferAttribute(r.points,3)),i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),i.geometry.attributes.position.needsUpdate=!0,i.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(r=this.store.cacheSegData)=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(r.attribute=this.store.currentAttribute,i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=a,this.nextTick=c,this.config=u,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.config)return g[0].hexString;const{fill:t}=p.getColorFromConfig({attribute:e},C(w({},this.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&P.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const a=this.scene.children[t];a.type==="Points"&&a.name!==this.store.pointCloudObjectName&&a.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}export{_ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as P from"three";import{EPointCloudSegmentMode as p,EPointCloudSegmentCoverMode as M,EPointCloudSegmentFocusMode as f,PointCloudUtils as D}from"@labelbee/lb-utils";import{isInPolygon as B}from"../../../utils/tool/polygonTool.js";import j from"../../../utils/uuid.js";import m from"./fsm.js";var R=Object.defineProperty,N=Object.defineProperties,x=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,E=(l,t,e)=>t in l?R(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,y=(l,t)=>{for(var e in t||(t={}))H.call(t,e)&&E(l,e,t[e]);if(w)for(var e of w(t))I.call(t,e)&&E(l,e,t[e]);return l},b=(l,t)=>N(l,x(t));const k="LABELBEE_CANVAS_";class z{constructor({container:t,scene:e,camera:i,renderer:a,emit:o,on:c,unbind:s}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new P.Raycaster,this.mouse=new P.Vector2,this.cloudData=new Map,this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=p.Add,this.segmentCoverMode=M.Cover,this.segmentFocusMode=f.Unfocus,this.hideSegment=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=u=>{this.segmentData.forEach((d,r)=>{var g;if(r!==((g=this.cacheSegData)==null?void 0:g.id)){const S=this.scene.getObjectByName(r);S&&S.removeFromParent()}});const h=u==null?void 0:u.filter(d=>{var r;return!this.hiddenAttributes.some(g=>g===d.attribute)&&d.id!==((r=this.cacheSegData)==null?void 0:r.id)});(h==null?void 0:h.length)!==0&&h.map(d=>(this.emit("addNewPointsCloud",d),d)),this.emit("reRender3d")},this.updateCoverPoints=(u=new Float32Array([]))=>{this.segmentData.forEach((h,d)=>{var r;if(d!==((r=this.cacheSegData)==null?void 0:r.id)){const g=D.splitPointsFromPoints(h.points,u);h.points=g;const S=this.scene.getObjectByName(d);S&&(S.geometry.setAttribute("position",new P.Float32BufferAttribute(g,3)),S.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=o,this.on=c,this.unbind=s,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentData=this.clearSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("clearSelectedSegmentData",this.clearSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("clearSelectedSegmentData",this.clearSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const o=[];a.indexes.forEach(s=>{o.push(i[s*3],i[s*3+1],i[s*3+2])});const c=b(y({},a),{points:new Float32Array(o)});this.segmentData.set(a.id,c),this.emit("addNewPointsCloud",b(y({},a),{points:new Float32Array(o)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${k}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===f.Focus&&this.emit("clearPointCloud"),t===f.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===f.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){var e,i,a;if(!this.isReadyStatus&&!this.isEditStatus)return;const o=t,c=this.scene.getObjectByName(this.pointCloudObjectName),s=(a=(i=(e=c==null?void 0:c.geometry)==null?void 0:e.attributes)==null?void 0:i.position)==null?void 0:a.array;if(s){const u=s.length,h=[],d=[],r=[];for(let n=0;n<u;n+=3){const C=new P.Vector3(s[n],s[n+1],s[n+2]);C.project(this.camera);const A={x:0,y:0};if(A.x=Math.round(C.x*this.container.clientWidth/2+this.container.clientWidth/2),A.y=Math.round(-C.y*this.container.clientHeight/2+this.container.clientHeight/2),B(A,o)){const F=s[n],_=s[n+1],O=s[n+2],v=D.getCloudKeys(F,_,O);this.segmentMode===p.Remove&&(this.cloudData.get(v).visible=!1,h.push(s[n],s[n+1],s[n+2]),r.push(n/3)),this.segmentMode===p.Add&&(this.segmentCoverMode===M.Cover&&(h.push(s[n],s[n+1],s[n+2]),r.push(n/3),this.cloudData.get(v).visible===!0&&d.push(s[n],s[n+1],s[n+2])),this.segmentCoverMode===M.Uncover&&this.cloudData.get(v).visible===!1&&(h.push(s[n],s[n+1],s[n+2]),r.push(n/3)),this.cloudData.get(v).visible===!1&&(this.cloudData.get(v).visible=!0))}}if(r.length===0||!this.cacheSegData&&this.segmentMode===p.Remove)return;const g=new Float32Array(h),S=new Float32Array(d);this.updateStatusBySelector(g,S,r)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case p.Add:if(this.cacheSegData){const{points:a,coverPoints:o=new Float32Array([])}=this.cacheSegData,c=a.length+t.length,s=new Float32Array(c);s.set(a,0),s.set(t,a.length);const u=o.length+e.length,h=new Float32Array(u);h.set(o,0),h.set(e,o.length),this.cacheSegData=b(y({},this.cacheSegData),{points:s,coverPoints:h,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:j(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case p.Remove:if(this.cacheSegData){const{points:a,indexes:o}=this.cacheSegData;this.cacheSegData=b(y({},this.cacheSegData),{points:D.splitPointsFromPoints(a,t),indexes:D.splitPointsFromIndexes(o,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],o=t[i+1],c=t[i+2],s=D.getCloudKeys(a,o,c),u=this.cloudData.get(s);Object.keys(e).forEach(h=>{u[h]=e[h]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}clearSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let o=0;o<i.length;o++){const c=this.cloudData.get(D.getCloudKeys(a[o],a[o+1],a[o+2]));c&&(c.visible=!1)}this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}}}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(y({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(y({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}export{z as default};
|
|
1
|
+
import*as b from"three";import{EPointCloudSegmentMode as m,EPointCloudSegmentCoverMode as v,EPointCloudSegmentFocusMode as f,PointCloudUtils as p}from"@labelbee/lb-utils";import{isInPolygon as F}from"../../../utils/tool/polygonTool.js";import O from"../../../utils/uuid.js";import g from"./fsm.js";var _=Object.defineProperty,R=Object.defineProperties,B=Object.getOwnPropertyDescriptors,C=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,A=(l,t,e)=>t in l?_(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,D=(l,t)=>{for(var e in t||(t={}))j.call(t,e)&&A(l,e,t[e]);if(C)for(var e of C(t))x.call(t,e)&&A(l,e,t[e]);return l},y=(l,t)=>R(l,B(t));const H="LABELBEE_CANVAS_";class k{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:r,unbind:h}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new b.Raycaster,this.mouse=new b.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=m.Add,this.segmentCoverMode=v.Cover,this.segmentFocusMode=f.Unfocus,this.hideSegment=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=u=>{this.segmentData.forEach((i,c)=>{var d;if(c!==((d=this.cacheSegData)==null?void 0:d.id)){const S=this.scene.getObjectByName(c);S&&S.removeFromParent()}});const o=u==null?void 0:u.filter(i=>{var c;return!this.hiddenAttributes.some(d=>d===i.attribute)&&i.id!==((c=this.cacheSegData)==null?void 0:c.id)});(o==null?void 0:o.length)!==0&&o.map(i=>(this.emit("addNewPointsCloud",i),i)),this.emit("reRender3d")},this.updateCoverPoints=(u=new Float32Array([]))=>{this.segmentData.forEach((o,i)=>{var c;if(i!==((c=this.cacheSegData)==null?void 0:c.id)){const d=p.splitPointsFromPoints(o.points,u);o.points=d;const S=this.scene.getObjectByName(i);S&&(S.geometry.setAttribute("position",new b.Float32BufferAttribute(d,3)),S.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=a,this.emit=n,this.on=r,this.unbind=h,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return g.segmentStatus}get isReadyStatus(){return g.isReadyStatus}get isCheckStatus(){return g.isCheckStatus}get isEditStatus(){return g.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const s=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(s[h*3],s[h*3+1],s[h*3+2])});const r=y(D({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,r),this.emit("addNewPointsCloud",y(D({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){g.statusToggle()}updateStatus2Edit(){g.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${H}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===f.Focus&&this.emit("clearPointCloud"),t===f.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===f.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,s){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${s} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,s=this.originPoints;if(s){const a=s.length,n=[],r=[],h=[];for(let i=0;i<a;i+=3){const c=new b.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const d={x:0,y:0};if(d.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),d.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),F(d,e)){const M=s[i],w=s[i+1],E=s[i+2],P=p.getCloudKeys(M,w,E);this.segmentMode===m.Remove&&(this.cloudData.get(P).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===m.Add&&(this.segmentCoverMode===v.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(P).visible===!0&&r.push(s[i],s[i+1],s[i+2])),this.segmentCoverMode===v.Uncover&&this.cloudData.get(P).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(P).visible===!1&&(this.cloudData.get(P).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===m.Remove)return;const u=new Float32Array(n),o=new Float32Array(r);this.updateStatusBySelector(u,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case m.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,r=a.length+t.length,h=new Float32Array(r);h.set(a,0),h.set(t,a.length);const u=n.length+e.length,o=new Float32Array(u);o.set(n,0),o.set(e,n.length),this.cacheSegData=y(D({},this.cacheSegData),{points:h,coverPoints:o,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:O(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case m.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=y(D({},this.cacheSegData),{points:p.splitPointsFromPoints(a,t),indexes:p.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],r=t[s+2],h=p.getCloudKeys(a,n,r),u=this.cloudData.get(h);Object.keys(e).forEach(o=>{u[o]=e[o]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const a=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const r=this.cloudData.get(p.getCloudKeys(a[n],a[n+1],a[n+2]));r&&(r.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,g.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=y(D({},t),{points:new Float32Array(t.points)}),g.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=y(D({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}export{k as default};
|
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.3",
|
|
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.3",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|