@labelbee/lb-annotation 1.16.0-alpha.6 → 1.16.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/pointCloud/index.js +1 -1
- package/dist/core/pointCloud/store/index.js +1 -1
- package/dist/types/core/pointCloud/annotation.d.ts +0 -13
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/pointCloud/store/index.js +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,o)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,__spreadValues=(n,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(n,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(n,o,t[o]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:o,pcdPath:s,extraProps:P,config:m,checkMode:v,toolName:u,proxyMode:I}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(d=>__spreadValues({i:d},lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size)));return __spreadProps(__spreadValues({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(tool.EToolName.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:d}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:d,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return __spreadProps(__spreadValues({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(d=>lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return __spreadProps(__spreadValues({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l)};const L=lbUtils.PointCloudUtils.getDefaultOrthographicParams(t),O=createEmptyImage(t),c=new Image;c.src=O;const h=new scheduler.ToolScheduler({container:o,size:t,toolName:u,proxyMode:I}),f=new CanvasScheduler.CanvasScheduler({container:o}),g=new index.PointCloud({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:L});s&&g.loadPCDFile(s),f.createCanvas(g.renderer.domElement);const C={size:t,config:JSON.stringify(__spreadProps(__spreadValues({},m),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:c,checkMode:v};P&&Object.assign(C,P);let p=[];scheduler.HybridToolUtils.isSingleTool(u)?p=[u]:p=u,p.forEach((a,l)=>{let i;if(a===tool.EToolName.PointCloudPolygon){const e=h.createOperation(a,c,C);e.eventBinding(),e.setPattern(tool.EPolygonPattern.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=h.createOperation(a,c,__spreadProps(__spreadValues({},C),{textConfigurable:!1}));l===p.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=g,this.canvasScheduler=f,this.toolScheduler=h,this.config=m}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=__spreadProps(__spreadValues({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(lbUtils.PointCloudUtils.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=createEmptyImage(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),s=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=lbUtils.PointCloudUtils.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=lbUtils.PointCloudUtils.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
|
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...o)=>__async(this,[...o],function*(c=this.currentPCDSrc,l){if(!c)return;this.clearPointCloud(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,l)}),this.loadPCDFileByBox=(o,c,l)=>__async(this,null,function*(){const d=(p,f)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:C=0}=l!=null?l:{},w=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+C}),p,f);if(!w){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const b=new THREE__namespace.Points(w.geometry);b.name=this.pointCloudObjectName,this.scene.add(b),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(o);d(u,m)}),this.generateRange=o=>{const c=this.createRange(o);this.scene.add(c)},this.generateBoxArrow=({width:o})=>{const c=new THREE__namespace.Vector3(1,0,0),l=new THREE__namespace.Vector3(o/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,l,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=o=>{if(!o.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(o.trackID.toString()));c.needsUpdate=!0;const l=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(l);return d.scale.set(5,5,5),d.position.set(-o.width/2,0,o.depth/2+.5),d},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:c})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const d=l.material.uniforms.pointSize.value;o?l.material.uniforms.pointSize.value=Math.min(d*1.2,10):l.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(l.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=h!=null?h:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,n?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(),n===!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,checkMode:this.checkMode},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:r,bottom:s,near:a,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}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:r}=t,s=10,a=e.x-i/2-s,n=e.x-i/2+s,h=e.y+r/2+s,o=e.y-r/2-s,c=100,l=-100,d=500/c;return{left:a,right:n,top:h,bottom:o,near:c,far:l,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:n,rotation:h}=t,o=this.getCameraVector(r,h,{width:s,height:a,depth:n},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(o,r),o)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:n,zMax:h,polygonPointList:o}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:n,zMax:h,polygonPointList:o,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(l),u.onmessage=m=>{const{color:p,position:f,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(f,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const n=this.createThreeMatrix4(a),h=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),o=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(h).applyMatrix4(c).applyMatrix4(o)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,r)=>{if(window.Worker){const a=(t?[...t]:[]).map(o=>matrix.getCuboidFromPointCloudBox(o)),n=this.getAllAttributeColor(a),h={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:n};highlightWorker.postMessage(h),highlightWorker.onmessage=o=>{const{color:c}=o.data,l=new THREE__namespace.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==c.length){r(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,l.needsUpdate=!0,e.geometry.setAttribute("dimensions",l),e.geometry.attributes.dimensions.needsUpdate=!0,i(c),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),r=e[i];e=e.filter(({z:l})=>l>r.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 n=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));e=e.slice(n,h),e.sort((l,d)=>l.y-d.y);const o=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(o,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:h})=>{t.forEach((o,c)=>{const l=r[c+1],d=MathUtils.default.getFootOfPerpendicular({x:n,y:h},o,l,!1,!0).length;(!i[c]||d<i[c].distance)&&(i[c]={distance:d,point:{x:n,y:h}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((n,h)=>{const o=r[h],c=r[h+1],l=r[h+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[h].point,line1:[o,c],p2:s[h+1].point,line2:[c,l]})})}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const n=this.scene.children.find(p=>p.uuid===this.pointsUuid);let h=0,o=0,c=0,l=0,d=[],u=[];const m=((a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const f=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:f,y},t)&&(x||x===0)&&u.push({x:f,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,f)=>p.z-f.z),h=u[0].z-.01,o=u[u.length-1].z+.01,l=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:o,minZ:h,count:c,zCount:l,fittedCoordinates:d}):{maxZ:o,minZ:h,count:c,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:r},height:s,width:a,depth:n}=t,h={x:e+a/2,y:i+s/2,z:r-n/2},o={x:e+a/2,y:i+s/2,z:r+n/2},c={x:e-a/2,y:i+s/2,z:r+n/2},l={x:e-a/2,y:i+s/2,z:r-n/2};return[h,o,c,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,h={x:e-a/2,y:i+s/2,z:r+n/2},o={x:e-a/2,y:i+s/2,z:r-n/2},c={x:e-a/2,y:i-s/2,z:r-n/2},l={x:e-a/2,y:i-s/2,z:r+n/2};return[h,o,c,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,h={x:e+a/2,y:i+s/2,z:r+n/2},o={x:e+a/2,y:i-s/2,z:r+n/2},c={x:e-a/2,y:i-s/2,z:r+n/2},l={x:e-a/2,y:i+s/2,z:r+n/2};return[h,o,c,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),n=new THREE__namespace.Matrix4().makeTranslation(e,i,r),h=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(n).multiply(h).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const h=i.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),o=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:h,zoom:Math.min(o,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,n={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const c=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:c,zoom:Math.min(l,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.getModelTransformationMatrix(t))).map(h=>({x:h.y,y:h.x})).map(h=>({x:-(h.x-this.containerWidth/2),y:-(h.y-this.containerHeight/2)})),a=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:n.width+e,height:n.height,depth:n.depth+i}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:n.width,height:n.height+e,depth:n.depth+i}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(f=>new THREE__namespace.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(a)),[h,o,c,l]=n,d=Math.max(Math.abs(h.x-c.x),Math.abs(h.x-o.x)),m=o.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(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let n=0;n<a;n++){const h=r.getZ(n);s.push(h>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
31
|
+
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...o)=>__async(this,[...o],function*(c=this.currentPCDSrc,l){if(!c)return;this.clearPointCloud(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,l)}),this.loadPCDFileByBox=(o,c,l)=>__async(this,null,function*(){const d=(p,f)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:C=0}=l!=null?l:{},w=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+C}),p,f);if(!w){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const b=new THREE__namespace.Points(w.geometry);b.name=this.pointCloudObjectName,this.scene.add(b),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(o);d(u,m)}),this.generateRange=o=>{const c=this.createRange(o);this.scene.add(c)},this.generateBoxArrow=({width:o})=>{const c=new THREE__namespace.Vector3(1,0,0),l=new THREE__namespace.Vector3(o/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,l,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=o=>{if(!o.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(o.trackID.toString()));c.needsUpdate=!0;const l=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(l);return d.scale.set(5,5,5),d.position.set(-o.width/2,0,o.depth/2+.5),d},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:c})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const d=l.material.uniforms.pointSize.value;o?l.material.uniforms.pointSize.value=Math.min(d*1.2,10):l.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(l.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=h!=null?h:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),n===!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,checkMode:this.checkMode},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}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:r}=t,s=10,a=e.x-i/2-s,n=e.x-i/2+s,h=e.y+r/2+s,o=e.y-r/2-s,c=100,l=-100,d=500/c;return{left:a,right:n,top:h,bottom:o,near:c,far:l,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:n,rotation:h}=t,o=this.getCameraVector(r,h,{width:s,height:a,depth:n},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(o,r),o)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:n,zMax:h,polygonPointList:o}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:n,zMax:h,polygonPointList:o,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(l),u.onmessage=m=>{const{color:p,position:f,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(f,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const n=this.createThreeMatrix4(a),h=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),o=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(h).applyMatrix4(c).applyMatrix4(o)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,r)=>{if(window.Worker){const a=(t?[...t]:[]).map(o=>matrix.getCuboidFromPointCloudBox(o)),n=this.getAllAttributeColor(a),h={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:n};highlightWorker.postMessage(h),highlightWorker.onmessage=o=>{const{color:c}=o.data,l=new THREE__namespace.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==c.length){r(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,l.needsUpdate=!0,e.geometry.setAttribute("dimensions",l),e.geometry.attributes.dimensions.needsUpdate=!0,i(c),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),r=e[i];e=e.filter(({z:l})=>l>r.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 n=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));e=e.slice(n,h),e.sort((l,d)=>l.y-d.y);const o=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(o,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:h})=>{t.forEach((o,c)=>{const l=r[c+1],d=MathUtils.default.getFootOfPerpendicular({x:n,y:h},o,l,!1,!0).length;(!i[c]||d<i[c].distance)&&(i[c]={distance:d,point:{x:n,y:h}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((n,h)=>{const o=r[h],c=r[h+1],l=r[h+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[h].point,line1:[o,c],p2:s[h+1].point,line2:[c,l]})})}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const n=this.scene.children.find(p=>p.uuid===this.pointsUuid);let h=0,o=0,c=0,l=0,d=[],u=[];const m=((a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const f=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:f,y},t)&&(x||x===0)&&u.push({x:f,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,f)=>p.z-f.z),h=u[0].z-.01,o=u[u.length-1].z+.01,l=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:o,minZ:h,count:c,zCount:l,fittedCoordinates:d}):{maxZ:o,minZ:h,count:c,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:r},height:s,width:a,depth:n}=t,h={x:e+a/2,y:i+s/2,z:r-n/2},o={x:e+a/2,y:i+s/2,z:r+n/2},c={x:e-a/2,y:i+s/2,z:r+n/2},l={x:e-a/2,y:i+s/2,z:r-n/2};return[h,o,c,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,h={x:e-a/2,y:i+s/2,z:r+n/2},o={x:e-a/2,y:i+s/2,z:r-n/2},c={x:e-a/2,y:i-s/2,z:r-n/2},l={x:e-a/2,y:i-s/2,z:r+n/2};return[h,o,c,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,h={x:e+a/2,y:i+s/2,z:r+n/2},o={x:e+a/2,y:i-s/2,z:r+n/2},c={x:e-a/2,y:i-s/2,z:r+n/2},l={x:e-a/2,y:i+s/2,z:r+n/2};return[h,o,c,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),n=new THREE__namespace.Matrix4().makeTranslation(e,i,r),h=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(n).multiply(h).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const h=i.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),o=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:h,zoom:Math.min(o,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,n={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const c=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:c,zoom:Math.min(l,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.getModelTransformationMatrix(t))).map(h=>({x:h.y,y:h.x})).map(h=>({x:-(h.x-this.containerWidth/2),y:-(h.y-this.containerHeight/2)})),a=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:n.width+e,height:n.height,depth:n.depth+i}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:n.width,height:n.height+e,depth:n.depth+i}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(f=>new THREE__namespace.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(a)),[h,o,c,l]=n,d=Math.max(Math.abs(h.x-c.x),Math.abs(h.x-o.x)),m=o.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(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let n=0;n<a;n++){const h=r.getZ(n);s.push(h>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"),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:r,unbind:h,checkMode:m}){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.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=s=>{this.segmentData.forEach((d,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=s==null?void 0:s.filter(d=>{var u;return!this.hiddenAttributes.some(l=>l===d.attribute)&&d.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(d=>(this.emit("addNewPointsCloud",d),d)),this.emit("reRender3d")},this.updateCoverPoints=(s=[])=>{this.segmentData.forEach((c,d)=>{var u;if(d!==((u=this.cacheSegData)==null?void 0:u.id)){const l=lbUtils.PointCloudUtils.splitPointsFromIndexes(c.indexes,s),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const p=this.scene.getObjectByName(d);p&&(p.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(new Float32Array(S),3)),p.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=r,this.unbind=h,this.checkMode=m,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 r=__spreadProps(__spreadValues({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,r),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=[],r=[],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 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),polygonTool.isInPolygon(d,e)){const l=i[s],S=i[s+1],p=i[s+2],g=lbUtils.PointCloudUtils.getCloudKeys(l,S,p);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(g).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(g).visible===!0&&r.push(s/3)),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(i[s],i[s+1],i[s+2]),h.push(s/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const m=new Float32Array(n);this.updateStatusBySelector(m,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,r=a.length+t.length,h=new Float32Array(r);h.set(a,0),h.set(t,a.length);const m=[...new Set([...n,...e])];this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:h,coverPoints:m,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],r=t[i+2],h=lbUtils.PointCloudUtils.getCloudKeys(a,n,r),m=this.cloudData.get(h);Object.keys(e).forEach(s=>{m[s]=e[s]})}}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 r=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[n],a[n+1],a[n+2]));r&&(r.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;
|
|
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:n,on:r,unbind:o,checkMode:m}){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.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=s=>{this.segmentData.forEach((d,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=s==null?void 0:s.filter(d=>{var u;return!this.hiddenAttributes.some(l=>l===d.attribute)&&d.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(d=>(this.emit("addNewPointsCloud",d),d)),this.emit("reRender3d")},this.updateCoverPoints=(s=[])=>{this.segmentData.forEach((c,d)=>{var u;if(d!==((u=this.cacheSegData)==null?void 0:u.id)){const l=lbUtils.PointCloudUtils.splitPointsFromIndexes(c.indexes,s),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const p=this.scene.getObjectByName(d);p&&(p.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(new Float32Array(S),3)),p.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=r,this.unbind=o,this.checkMode=m,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(o=>{n.push(i[o*3],i[o*3+1],i[o*3+2]),this.cloudData.set(`${i[o*3]}@${i[o*3+1]}@${i[o*3+2]}`,{visible:!0})});const r=__spreadProps(__spreadValues({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,r),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=[],r=[],o=[];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 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),polygonTool.isInPolygon(d,e)){const l=i[s],S=i[s+1],p=i[s+2],g=lbUtils.PointCloudUtils.getCloudKeys(l,S,p);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(g).visible=!1,n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3),this.cloudData.get(g).visible===!0&&r.push(s/3)),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(o.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const m=new Float32Array(n);this.updateStatusBySelector(m,r,o)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,r=a.length+t.length,o=new Float32Array(r);o.set(a,0),o.set(t,a.length);const m=[...new Set([...n,...e])];this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:o,coverPoints:m,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],r=t[i+2],o=lbUtils.PointCloudUtils.getCloudKeys(a,n,r),m=this.cloudData.get(o);Object.keys(e).forEach(s=>{m[s]=e[s]})}}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 r=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[n],a[n+1],a[n+2]));r&&(r.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;
|
|
@@ -34,19 +34,6 @@ export declare class PointCloudAnnotation implements IPointCloudAnnotationOperat
|
|
|
34
34
|
constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName, proxyMode, }: IPointCloudAnnotationProps);
|
|
35
35
|
updateConfig(config: IPointCloudConfig): void;
|
|
36
36
|
updateAttributeList(attributeList: IInputList[]): void;
|
|
37
|
-
/**
|
|
38
|
-
* Get default boundary by size.
|
|
39
|
-
* @param size
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
getDefaultOrthographic(size: ISize): {
|
|
43
|
-
left: number;
|
|
44
|
-
right: number;
|
|
45
|
-
top: number;
|
|
46
|
-
bottom: number;
|
|
47
|
-
near: number;
|
|
48
|
-
far: number;
|
|
49
|
-
};
|
|
50
37
|
/**
|
|
51
38
|
* Init size when the viewport updated.
|
|
52
39
|
* @param size
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PointCloudUtils as
|
|
1
|
+
import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,c=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},p=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class J{constructor({size:t,container:o,pcdPath:s,extraProps:L,config:O,checkMode:_,toolName:h,proxyMode:b}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(u=>c({i:u},d.transferWorld2Canvas(u,this.toolInstance.size)));return p(c({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(C.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:u}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:u,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return p(c({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(u=>d.transferWorld2Canvas(u,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return p(c({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l)};const D=d.getDefaultOrthographicParams(t),T=S(t),g=new Image;g.src=T;const f=new B({container:o,size:t,toolName:h,proxyMode:b}),v=new A({container:o}),P=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});s&&P.loadPCDFile(s),v.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(c({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:_};L&&Object.assign(I,L);let m=[];E.isSingleTool(h)?m=[h]:m=h,m.forEach((a,l)=>{let i;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=f.createOperation(a,g,p(c({},I),{textConfigurable:!1}));l===m.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=v,this.toolScheduler=f,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(c({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(d.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=S(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=d.getBoxParamsFromResultList(t),s=d.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=d.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=d.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{J as PointCloudAnnotation};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as c from"three";import{toolStyleConverter as O,PerspectiveShiftUtils as M,EPerspectiveView as C,PointCloudUtils as N,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import F from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import A from"../../utils/uuid.js";import W from"../../utils/MathUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as
|
|
1
|
+
import*as c from"three";import{toolStyleConverter as O,PerspectiveShiftUtils as M,EPerspectiveView as C,PointCloudUtils as N,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import F from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import A from"../../utils/uuid.js";import W from"../../utils/MathUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as H}from"./cache.js";import{getCuboidFromPointCloudBox as k}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as G}from"./segmentation.js";import $ from"./store/index.js";import X from"./render/index.js";import Y from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var q=Object.defineProperty,K=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,j=(w,t,e)=>t in w?q(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))J.call(t,e)&&j(w,e,t[e]);if(_)for(var e of _(t))tt.call(t,e)&&j(w,e,t[e]);return w},P=(w,t)=>K(w,Q(t)),T=(w,t,e)=>new Promise((i,r)=>{var s=l=>{try{n(e.next(l))}catch(o){r(o)}},a=l=>{try{n(e.throw(l))}catch(o){r(o)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,a);n((e=e.apply(w,t)).next())});const et=30,L=new V({type:"module"});class it extends Y{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:n,checkMode:l}){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.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,h="blue")=>{var d;const u=(d=o.id)!=null?d:A();this.removeObjectByName(u,"sphere");const{radius:m,widthSegments:g,heightSegments:p}=z,{center:f}=o,x=new c.Group,y=new c.SphereGeometry(m,g,p),S=new c.MeshBasicMaterial({color:h}),v=new c.Mesh(y,S);v.position.set(f.x,f.y,f.z),x.add(v),x.name=`sphere${u}`,this.scene.add(x)},this.generateSphere=o=>{const{fill:h}=O.getColorFromConfig({attribute:o.attribute},P(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(o,h),this.render()},this.generateSpheres=o=>{o.forEach(h=>{const{fill:d}=O.getColorFromConfig({attribute:h.attribute},P(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(h,d)}),this.render()},this.addBoxToSense=(o,h=16777215)=>{var d;const u=(d=o.id)!=null?d:A();this.removeObjectByName(u,"box");const{center:m,width:g,height:p,depth:f,rotation:x}=o,y=new c.Group,S=new c.BoxGeometry(g,p,f),v=new c.MeshBasicMaterial({color:"blue"}),B=new c.Mesh(S,v),I=new c.BoxHelper(B,h),E=this.generateBoxArrow(o),D=this.generateBoxTrackID(o);D&&y.add(D),y.add(I),y.add(E),m&&y.position.set(m.x,m.y,m.z),x&&y.rotation.set(0,0,x),y.name=`box${u}`,this.scene.add(y)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const h=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
2
2
|
attribute vec3 dimensions;
|
|
3
3
|
varying vec3 vDimensions;
|
|
4
4
|
uniform float pointSize;
|
|
@@ -28,4 +28,4 @@ import*as c from"three";import{toolStyleConverter as O,PerspectiveShiftUtils as
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...o)=>T(this,[...o],function*(h=this.currentPCDSrc,d){if(!h)return;this.clearPointCloud(),this.currentPCDSrc=h;const{points:u,color:m}=yield this.cacheInstance.loadPCDFile(h),g=new c.BufferGeometry;g.setAttribute("position",new c.BufferAttribute(u,3)),this.isSegment||g.setAttribute("dimensions",new c.BufferAttribute(m,3)),this.initCloudData(u);const p=new c.Points(g);this.renderPointCloud(p,d)}),this.loadPCDFileByBox=(o,h,d)=>T(this,null,function*(){const u=(p,f)=>T(this,null,function*(){const{width:x=0,height:y=0,depth:S=0}=d!=null?d:{},v=yield this.filterPointsByBox(P(b({},h),{width:h.width+x,height:h.height+y,depth:h.depth+S}),p,f);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const B=new c.Points(v.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:m,color:g}=yield this.cacheInstance.loadPCDFile(o);u(m,g)}),this.generateRange=o=>{const h=this.createRange(o);this.scene.add(h)},this.generateBoxArrow=({width:o})=>{const h=new c.Vector3(1,0,0),d=new c.Vector3(o/2,0,0),u=2,m=16776960,g=new c.ArrowHelper(h,d,u,m);return g.visible=this.showDirection,g},this.generateBoxTrackID=o=>{if(!o.trackID)return;const h=new c.Texture(this.getTextCanvas(o.trackID.toString()));h.needsUpdate=!0;const d=new c.SpriteMaterial({map:h,depthWrite:!1}),u=new c.Sprite(d);return u.scale.set(5,5,5),u.position.set(-o.width/2,0,o.depth/2+.5),u},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:h})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const u=d.material.uniforms.pointSize.value;o?d.material.uniforms.pointSize.value=Math.min(u*1.2,10):d.material.uniforms.pointSize.value=Math.max(u/1.2,1),h&&(d.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new H(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new Z,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=U.getInstance(),n===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new $(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 G({dom:this.container,store:this.store}),this.pointCloudRender=new X(P(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,checkMode:this.checkMode},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:r,bottom:s,near:a,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new c.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=O.getColorFromConfig({attribute:i.attribute},P(b({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,n=e.x-i/2+s,l=e.y+r/2+s,o=e.y-r/2-s,h=100,d=-100,u=500/h;return{left:a,right:n,top:l,bottom:o,near:h,far:d,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:n,rotation:l}=t,o=this.getCameraVector(r,l,{width:s,height:a,depth:n},e);return i?(this.updateCamera(i,r),new c.Vector3(i.x,i.y,i.z)):(this.updateCamera(o,r),o)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=z,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new 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 r,s,a;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:n,zMax:l,polygonPointList:o}=k(t),h=e;i=i!=null?i:new Float32Array([]);const d={boxParams:t,zMin:n,zMax:l,polygonPointList:o,color:i,position:h};return new Promise(u=>{const m=new F;m.postMessage(d),m.onmessage=g=>{const{color:p,position:f,num:x}=g.data,y=new c.BufferGeometry;y.setAttribute("position",new c.Float32BufferAttribute(f,3)),y.setAttribute("color",new c.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),m.terminate(),u({geometry:y,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,s=et){let a=M.frontViewMatrix4(s);switch(r){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 n=this.createThreeMatrix4(a),l=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),o=new c.Matrix4().makeTranslation(t.x,t.y,t.z),h=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(l).applyMatrix4(h).applyMatrix4(o)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new c.BufferGeometry().setFromPoints(i),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new c.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,r)=>{if(window.Worker){const a=(t?[...t]:[]).map(o=>k(o)),n=this.getAllAttributeColor(a),l={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:n};L.postMessage(l),L.onmessage=o=>{const{color:h}=o.data,d=new c.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==h.length){r(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,e.geometry.setAttribute("dimensions",d),e.geometry.attributes.dimensions.needsUpdate=!0,i(h),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),r=e[i];e=e.filter(({z:d})=>d>r.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 n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(n,l),e.sort((d,u)=>d.y-u.y);const o=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));return e=e.slice(o,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:l})=>{t.forEach((o,h)=>{const d=r[h+1],u=W.getFootOfPerpendicular({x:n,y:l},o,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:n,y:l}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((n,l)=>{const o=r[l],h=r[l+1],d=r[l+2];return N.getIntersectionBySlope({p1:s[l].point,line1:[o,h],p2:s[l+1].point,line2:[h,d]})})}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const n=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,o=0,h=0,d=0,u=[],m=[];const g=((a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<g.length;p+=3){const f=g[p],x=g[p+1],y=g[p+2];R({x:f,y:x},t)&&(y||y===0)&&m.push({x:f,y:x,z:y})}return m.length?(i&&(m=this.filterNoise(m),u=this.getFittedCoordinates(t,m)),m.sort((p,f)=>p.z-f.z),l=m[0].z-.01,o=m[m.length-1].z+.01,d=m.length,e&&(h=m.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:o,minZ:l,count:h,zCount:d,fittedCoordinates:u}):{maxZ:o,minZ:l,count:h,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:r},height:s,width:a,depth:n}=t,l={x:e+a/2,y:i+s/2,z:r-n/2},o={x:e+a/2,y:i+s/2,z:r+n/2},h={x:e-a/2,y:i+s/2,z:r+n/2},d={x:e-a/2,y:i+s/2,z:r-n/2};return[l,o,h,d]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,l={x:e-a/2,y:i+s/2,z:r+n/2},o={x:e-a/2,y:i+s/2,z:r-n/2},h={x:e-a/2,y:i-s/2,z:r-n/2},d={x:e-a/2,y:i-s/2,z:r+n/2};return[l,o,h,d]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,l={x:e+a/2,y:i+s/2,z:r+n/2},o={x:e+a/2,y:i-s/2,z:r+n/2},h={x:e-a/2,y:i-s/2,z:r+n/2},d={x:e-a/2,y:i+s/2,z:r+n/2};return[l,o,h,d]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-i,-r),n=new c.Matrix4().makeTranslation(e,i,r),l=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(n).multiply(l).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:r,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=i.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),o=this.containerWidth/r,h=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(o,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=z,n={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new c.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const h=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),u=this.containerHeight/(a*2);return{point2d:h,zoom:Math.min(d,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=z,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new c.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new c.Matrix4().makeRotationZ(r.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=P(b({},n),{width:n.width+e,height:n.height,depth:n.depth+i}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const s=new c.Matrix4().makeRotationZ(r.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=P(b({},n),{width:n.width,height:n.height+e,depth:n.depth+i}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(f=>new c.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(a)),[l,o,h,d]=n,u=Math.max(Math.abs(l.x-h.x),Math.abs(l.x-o.x)),g=o.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(r.center.x,r.center.y,r.center.z));return{newBoxParams:P(b({},r),{center:{x:r.center.x-g.x,y:r.center.y-g.y,z:r.center.z-i},width:u,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let n=0;n<a;n++){const l=r.getZ(n);s.push(l>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{it as PointCloud};
|
|
31
|
+
}`,uniforms:{pointSize:{value:1.2}}}),this.loadPCDFile=(...o)=>T(this,[...o],function*(h=this.currentPCDSrc,d){if(!h)return;this.clearPointCloud(),this.currentPCDSrc=h;const{points:u,color:m}=yield this.cacheInstance.loadPCDFile(h),g=new c.BufferGeometry;g.setAttribute("position",new c.BufferAttribute(u,3)),this.isSegment||g.setAttribute("dimensions",new c.BufferAttribute(m,3)),this.initCloudData(u);const p=new c.Points(g);this.renderPointCloud(p,d)}),this.loadPCDFileByBox=(o,h,d)=>T(this,null,function*(){const u=(p,f)=>T(this,null,function*(){const{width:x=0,height:y=0,depth:S=0}=d!=null?d:{},v=yield this.filterPointsByBox(P(b({},h),{width:h.width+x,height:h.height+y,depth:h.depth+S}),p,f);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const B=new c.Points(v.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:m,color:g}=yield this.cacheInstance.loadPCDFile(o);u(m,g)}),this.generateRange=o=>{const h=this.createRange(o);this.scene.add(h)},this.generateBoxArrow=({width:o})=>{const h=new c.Vector3(1,0,0),d=new c.Vector3(o/2,0,0),u=2,m=16776960,g=new c.ArrowHelper(h,d,u,m);return g.visible=this.showDirection,g},this.generateBoxTrackID=o=>{if(!o.trackID)return;const h=new c.Texture(this.getTextCanvas(o.trackID.toString()));h.needsUpdate=!0;const d=new c.SpriteMaterial({map:h,depthWrite:!1}),u=new c.Sprite(d);return u.scale.set(5,5,5),u.position.set(-o.width/2,0,o.depth/2+.5),u},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:h})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const u=d.material.uniforms.pointSize.value;o?d.material.uniforms.pointSize.value=Math.min(u*1.2,10):d.material.uniforms.pointSize.value=Math.max(u/1.2,1),h&&(d.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new U(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=H.getInstance(),n===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new $(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 G({dom:this.container,store:this.store}),this.pointCloudRender=new X(P(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,checkMode:this.checkMode},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-.01,0,1e3)}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:r,bottom:s,near:a,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new c.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=O.getColorFromConfig({attribute:i.attribute},P(b({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,n=e.x-i/2+s,l=e.y+r/2+s,o=e.y-r/2-s,h=100,d=-100,u=500/h;return{left:a,right:n,top:l,bottom:o,near:h,far:d,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:n,rotation:l}=t,o=this.getCameraVector(r,l,{width:s,height:a,depth:n},e);return i?(this.updateCamera(i,r),new c.Vector3(i.x,i.y,i.z)):(this.updateCamera(o,r),o)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=z,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new 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 r,s,a;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:n,zMax:l,polygonPointList:o}=k(t),h=e;i=i!=null?i:new Float32Array([]);const d={boxParams:t,zMin:n,zMax:l,polygonPointList:o,color:i,position:h};return new Promise(u=>{const m=new F;m.postMessage(d),m.onmessage=g=>{const{color:p,position:f,num:x}=g.data,y=new c.BufferGeometry;y.setAttribute("position",new c.Float32BufferAttribute(f,3)),y.setAttribute("color",new c.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),m.terminate(),u({geometry:y,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,s=et){let a=M.frontViewMatrix4(s);switch(r){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 n=this.createThreeMatrix4(a),l=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),o=new c.Matrix4().makeTranslation(t.x,t.y,t.z),h=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(l).applyMatrix4(h).applyMatrix4(o)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new c.BufferGeometry().setFromPoints(i),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new c.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,r)=>{if(window.Worker){const a=(t?[...t]:[]).map(o=>k(o)),n=this.getAllAttributeColor(a),l={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.dimensions.array,colorList:n};L.postMessage(l),L.onmessage=o=>{const{color:h}=o.data,d=new c.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==h.length){r(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,e.geometry.setAttribute("dimensions",d),e.geometry.attributes.dimensions.needsUpdate=!0,i(h),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),r=e[i];e=e.filter(({z:d})=>d>r.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 n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(n,l),e.sort((d,u)=>d.y-u.y);const o=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));return e=e.slice(o,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:l})=>{t.forEach((o,h)=>{const d=r[h+1],u=W.getFootOfPerpendicular({x:n,y:l},o,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:n,y:l}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((n,l)=>{const o=r[l],h=r[l+1],d=r[l+2];return N.getIntersectionBySlope({p1:s[l].point,line1:[o,h],p2:s[l+1].point,line2:[h,d]})})}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const n=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,o=0,h=0,d=0,u=[],m=[];const g=((a=(s=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<g.length;p+=3){const f=g[p],x=g[p+1],y=g[p+2];R({x:f,y:x},t)&&(y||y===0)&&m.push({x:f,y:x,z:y})}return m.length?(i&&(m=this.filterNoise(m),u=this.getFittedCoordinates(t,m)),m.sort((p,f)=>p.z-f.z),l=m[0].z-.01,o=m[m.length-1].z+.01,d=m.length,e&&(h=m.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:o,minZ:l,count:h,zCount:d,fittedCoordinates:u}):{maxZ:o,minZ:l,count:h,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:r},height:s,width:a,depth:n}=t,l={x:e+a/2,y:i+s/2,z:r-n/2},o={x:e+a/2,y:i+s/2,z:r+n/2},h={x:e-a/2,y:i+s/2,z:r+n/2},d={x:e-a/2,y:i+s/2,z:r-n/2};return[l,o,h,d]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,l={x:e-a/2,y:i+s/2,z:r+n/2},o={x:e-a/2,y:i+s/2,z:r-n/2},h={x:e-a/2,y:i-s/2,z:r-n/2},d={x:e-a/2,y:i-s/2,z:r+n/2};return[l,o,h,d]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:n}=t,l={x:e+a/2,y:i+s/2,z:r+n/2},o={x:e+a/2,y:i-s/2,z:r+n/2},h={x:e-a/2,y:i-s/2,z:r+n/2},d={x:e-a/2,y:i+s/2,z:r+n/2};return[l,o,h,d]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-i,-r),n=new c.Matrix4().makeTranslation(e,i,r),l=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(n).multiply(l).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:r,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=i.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),o=this.containerWidth/r,h=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(o,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=z,n={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new c.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const h=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),u=this.containerHeight/(a*2);return{point2d:h,zoom:Math.min(d,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=z,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new c.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new c.Matrix4().makeRotationZ(r.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=P(b({},n),{width:n.width+e,height:n.height,depth:n.depth+i}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const s=new c.Matrix4().makeRotationZ(r.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let n=r;return n.center={x:n.center.x+a.x,y:n.center.y+a.y,z:n.center.z-t.z},n=P(b({},n),{width:n.width,height:n.height+e,depth:n.depth+i}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(f=>new c.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(a)),[l,o,h,d]=n,u=Math.max(Math.abs(l.x-h.x),Math.abs(l.x-o.x)),g=o.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(r.center.x,r.center.y,r.center.z));return{newBoxParams:P(b({},r),{center:{x:r.center.x-g.x,y:r.center.y-g.y,z:r.center.z-i},width:u,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let n=0;n<a;n++){const l=r.getZ(n);s.push(l>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{it as PointCloud};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as v from"three";import{EPointCloudSegmentMode as D,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as y}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,P=(d,t)=>{for(var e in t||(t={}))x.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))B.call(t,e)&&w(d,e,t[e]);return d},f=(d,t)=>_(d,R(t));const k="LABELBEE_CANVAS_";class I{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=D.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(l=>l===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const l=y.splitPointsFromIndexes(c.indexes,i),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const b=this.scene.getObjectByName(r);b&&(b.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),b.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=o,this.unbind=h,this.checkMode=p,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 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 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 o=f(P({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",f(P({},a),{points:new Float32Array(n)}))}),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===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.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=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const l=s[i],S=s[i+1],b=s[i+2],g=y.getCloudKeys(l,S,b);this.segmentMode===D.Remove&&(this.cloudData.get(g).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===D.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(g).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===D.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case D.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=f(P({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case D.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=f(P({},this.cacheSegData),{points:y.splitPointsFromPoints(a,t),indexes:y.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],o=t[s+2],h=y.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}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 o=this.cloudData.get(y.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.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=f(P({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=f(P({},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{I as default};
|
|
1
|
+
import*as v from"three";import{EPointCloudSegmentMode as D,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as y}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,P=(d,t)=>{for(var e in t||(t={}))B.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))k.call(t,e)&&w(d,e,t[e]);return d},b=(d,t)=>_(d,R(t));const I="LABELBEE_CANVAS_";class j{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=D.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(l=>l===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const l=y.splitPointsFromIndexes(c.indexes,i),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const f=this.scene.getObjectByName(r);f&&(f.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),f.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=o,this.unbind=h,this.checkMode=p,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 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 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]),this.cloudData.set(`${s[h*3]}@${s[h*3+1]}@${s[h*3+2]}`,{visible:!0})});const o=b(P({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",b(P({},a),{points:new Float32Array(n)}))}),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(`${I}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===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.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=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const l=s[i],S=s[i+1],f=s[i+2],g=y.getCloudKeys(l,S,f);this.segmentMode===D.Remove&&(this.cloudData.get(g).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===D.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(g).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===D.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case D.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=b(P({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case D.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=b(P({},this.cacheSegData),{points:y.splitPointsFromPoints(a,t),indexes:y.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],o=t[s+2],h=y.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}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 o=this.cloudData.get(y.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.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=b(P({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(P({},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{j 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.8",
|
|
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.6",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|