@labelbee/lb-annotation 1.20.0-alpha.6 → 1.20.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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(f){if(f&&f.__esModule)return f;var t=Object.create(null);return f&&Object.keys(f).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return f[e]}})}}),t.default=f,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=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t)),__async=(f,t,e)=>new Promise((i,r)=>{var o=l=>{try{n(e.next(l))}catch(s){r(s)}},h=l=>{try{n(e.throw(l))}catch(s){r(s)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(o,h);n((e=e.apply(f,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:o="#4C4C4C",config:h,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.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(s,a="blue")=>{var c;const d=(c=s.id)!=null?c:uuid();this.removeObjectByName(d,"sphere");const{radius:p,widthSegments:m,heightSegments:u}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=s,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(p,m,u),w=new THREE__namespace.MeshBasicMaterial({color:a}),b=new THREE__namespace.Mesh(x,w);b.position.set(g.x,g.y,g.z),y.add(b),y.name=`sphere${d}`,this.scene.add(y)},this.generateSphere=s=>{const{fill:a}=this.getColorFromConfig(s.attribute);this.addSphereToSense(s,a),this.render()},this.generateSpheres=s=>{s.forEach(a=>{const{fill:c}=this.getColorFromConfig(a.attribute);this.addSphereToSense(a,c)}),this.render()},this.addBoxToSense=(s,a=16777215)=>{var c;const d=(c=s.id)!=null?c:uuid();this.removeObjectByName(d,"box");const{center:p,width:m,height:u,depth:g,rotation:y}=s,x=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(m,u,g),b=new THREE__namespace.MeshBasicMaterial({color:"blue"}),C=new THREE__namespace.Mesh(w,b),v=new THREE__namespace.BoxHelper(C,a),M=this.generateBoxArrow(s),P=this.generateBoxTrackID(s);P&&x.add(P),x.add(v),x.add(M),p&&x.position.set(p.x,p.y,p.z),y&&x.rotation.set(0,0,y),x.name=`box${d}`,this.scene.add(x)},this.applyCameraTarget=s=>{if(this.camera.type==="OrthographicCamera"&&s){const a=this.getOrthographicCameraTarget(s);this.updateCameraZoom(s.zoom),this.updateCamera(s.position,a)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(f){if(f&&f.__esModule)return f;var t=Object.create(null);return f&&Object.keys(f).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return f[e]}})}}),t.default=f,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=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t)),__async=(f,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(n){r(n)}},a=l=>{try{o(e.throw(l))}catch(n){r(n)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,a);o((e=e.apply(f,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:o,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.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:p}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=n,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(u,m,p),w=new THREE__namespace.MeshBasicMaterial({color:c}),b=new THREE__namespace.Mesh(x,w);b.position.set(g.x,g.y,g.z),y.add(b),y.name=`sphere${d}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:h}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,h)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"box");const{center:u,width:m,height:p,depth:g,rotation:y}=n,x=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(m,p,g),b=new THREE__namespace.MeshBasicMaterial({color:"blue"}),C=new THREE__namespace.Mesh(w,b),P=new THREE__namespace.BoxHelper(C,c),M=this.generateBoxArrow(n),v=this.generateBoxTrackID(n);v&&x.add(v),x.add(P),x.add(M),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${d}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,4 @@
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...s)=>__async(this,[...s],function*(a=this.currentPCDSrc,c){if(!a)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=a;const{points:d,color:p}=yield this.cacheInstance.loadPCDFile(a),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(p,3)),this.initCloudData(d);const u=new THREE__namespace.Points(m);this.renderPointCloud(u,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=s=>__async(this,[s],function*({mappingImgList:a,points:c}){const d=a.length===0?[]:yield Promise.all(a.map(u=>ImgUtils.default.load(u.url))),p=a.map((u,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:c,calib:u.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,x),x});return matrix.mergeHighlightList(p)}),this.loadPCDFileByBox=(s,a,c)=>__async(this,null,function*(){const d=(u,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=c!=null?c:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},a),{width:a.width+y,height:a.height+x,depth:a.depth+w}),u,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:p,color:m}=yield this.cacheInstance.loadPCDFile(s);d(p,m)}),this.generateRange=s=>{const a=this.createRange(s);this.scene.add(a)},this.generateBoxArrow=({width:s})=>{const a=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(s/2,0,0),d=2,p=16776960,m=new THREE__namespace.ArrowHelper(a,c,d,p);return m.visible=this.showDirection,m},this.generateBoxTrackID=s=>{if(!s.trackID)return;const a=new THREE__namespace.Texture(this.getTextCanvas(s.trackID.toString()));a.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:a,depthWrite:!1}),d=new THREE__namespace.Sprite(c);return d.scale.set(5,5,5),d.position.set(-s.width/2,0,s.depth/2+.5),d},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:a})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;s?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),a&&(c.material.uniforms.pointSize.value=a,this.pointsMaterialSize=a),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=h,this.checkMode=l!=null?l:!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(__spreadValues({dom:this.container,store:this.store},this.eventBus)),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}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode},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:o,near:h,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=h,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()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,h=e.x-i/2-o,n=e.x-i/2+o,l=e.y+r/2+o,s=e.y-r/2-o,a=100,c=-100,d=500/a;return{left:h,right:n,top:l,bottom:s,near:a,far:c,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:h,depth:n,rotation:l}=t,s=this.getCameraVector(r,l,{width:o,height:h,depth:n},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}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,o,h;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=(h=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array}if(window.Worker){const{zMin:n,zMax:l,polygonPointList:s}=matrix.getCuboidFromPointCloudBox(t),a=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:n,zMax:l,polygonPointList:s,color:i,position:a};return new Promise(d=>{const p=new filterBoxWorker;p.postMessage(c),p.onmessage=m=>{const{color:u,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(u,3)),x.computeBoundingSphere(),p.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,o=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(o);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(o);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(o);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(o);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(o);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(o,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),a=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(l).applyMatrix4(a).applyMatrix4(s)}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),o=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,o);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(a=>matrix.getCuboidFromPointCloudBox(a)),l=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(s),highlightWorker.onmessage=a=>{const{color:c}=a.data,d=new THREE__namespace.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:o,z:h},width:n,height:l,depth:s,rotation:a}=i,{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(n,l,s),p=new THREE__namespace.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(a),d.translate(r,o,h);const m=new THREE__namespace.Mesh(d,p);e.add(m);const u=new THREE__namespace.PlaneGeometry(s,l);u.rotateY(Math.PI/2),u.rotateZ(a);const g=new THREE__namespace.Vector3(n/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(a);g.applyMatrix4(y),u.translate(r+g.x,o+g.y,h+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:c,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(u,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new 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((c,d)=>c.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const o=.005,h=Math.floor(e.length*(1-o));e=e.slice(0,h),e.sort((c,d)=>c.x-d.x);const n=Math.floor(e.length*o),l=Math.floor(e.length*(1-o));e=e.slice(n,l),e.sort((c,d)=>c.y-d.y);const s=Math.floor(e.length*o),a=Math.floor(e.length*(1-o));return e=e.slice(s,a),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:l})=>{t.forEach((s,a)=>{const c=r[a+1],d=MathUtils.default.getFootOfPerpendicular({x:n,y:l},s,c,!1,!0).length;(!i[a]||d<i[a].distance)&&(i[a]={distance:d,point:{x:n,y:l}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,l)=>{const s=r[l],a=r[l+1],c=r[l+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:o[l].point,line1:[s,a],p2:o[l+1].point,line2:[a,c]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,h;const n=this.scene.children.find(u=>u.uuid===this.pointsUuid);let l=0,s=0,a=0,c=0,d=[],p=[];const m=((h=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array)||[];for(let u=0;u<m.length;u+=3){const g=m[u],y=m[u+1],x=m[u+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&p.push({x:g,y,z:x})}return p.length?(i&&(p=this.filterNoise(p),d=this.getFittedCoordinates(t,p)),p.sort((u,g)=>u.z-g.z),l=p[0].z-.01,s=p[p.length-1].z+.01,c=p.length,e&&(a=p.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:s,minZ:l,count:a,zCount:c,fittedCoordinates:d}):{maxZ:s,minZ:l,count:a,zCount:c,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:o,width:h,depth:n}=t,l={x:e+h/2,y:i+o/2,z:r-n/2},s={x:e+h/2,y:i+o/2,z:r+n/2},a={x:e-h/2,y:i+o/2,z:r+n/2},c={x:e-h/2,y:i+o/2,z:r-n/2};return[l,s,a,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e-h/2,y:i+o/2,z:r+n/2},s={x:e-h/2,y:i+o/2,z:r-n/2},a={x:e-h/2,y:i-o/2,z:r-n/2},c={x:e-h/2,y:i-o/2,z:r+n/2};return[l,s,a,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e+h/2,y:i+o/2,z:r+n/2},s={x:e+h/2,y:i-o/2,z:r+n/2},a={x:e-h/2,y:i-o/2,z:r+n/2},c={x:e-h/2,y:i+o/2,z:r+n/2};return[l,s,a,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),n=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(o);return new THREE__namespace.Matrix4().multiply(n).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=i.map(c=>new THREE__namespace.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,a=this.containerHeight/o;return{polygon2d:l,zoom:Math.min(s,a)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,n={center:e,attribute:i,id:r,valid:o,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const a=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),d=this.containerHeight/(h*2);return{point2d:a,zoom:Math.min(c,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)},o=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(h,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+h.x,y:n.center.y+h.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+h.x,y:n.center.y+h.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const h=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[l,s,a,c]=n,d=Math.max(Math.abs(l.x-a.x),Math.abs(l.x-s.x)),m=s.add(c).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,o=[],{count:h}=r;for(let n=0;n<h;n++){const l=r.getZ(n);o.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),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,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:h,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=h!=null?h:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,h,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!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,o?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(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,h=-100,d=500/c;return{left:a,right:o,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(h),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,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 o=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=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(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}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,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:h}=c.data,d=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==h.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(h),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,a+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new 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((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],u=[];const m=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,h=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,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:o}=t,l={x:e+a/2,y:i+s/2,z:r-o/2},n={x:e+a/2,y:i+s/2,z:r+o/2},c={x:e-a/2,y:i+s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r-o/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2},c={x:e-a/2,y:i-s/2,z:r-o/2},h={x:e-a/2,y:i-s/2,z:r+o/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r+o/2},n={x:e+a/2,y:i-s/2,z:r+o/2},c={x:e-a/2,y:i-s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r+o/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,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(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(h).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 o=0;o<a;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -1 +1 @@
1
- "use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),DrawUtils=require("../../../utils/tool/DrawUtils.js");function _interopNamespace(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if(t!=="default"){var o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloudRender{constructor({store:e,on:t,unbind:o,nextTick:l,config:d}){this.clearStash=()=>{var i,s;const n=this.scene.getObjectByName((s=(i=this.store.cacheSegData)==null?void 0:i.id)!=null?s:"");n&&(n.removeFromParent(),this.render3d())},this.generateNewPoints=i=>{const s=new THREE__namespace.BufferGeometry;s.setAttribute("position",new THREE__namespace.BufferAttribute(i.points,3));const n=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),a=new THREE__namespace.Points(s,n);a.name=i.id,this.store.scene.add(a),this.render3d()},this.updateNewPoints=i=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(n.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(i.points,3)),n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),n.geometry.attributes.position.needsUpdate=!0,n.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(i=this.store.cacheSegData)=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(i.attribute=this.store.currentAttribute,n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=o,this.nextTick=l,this.config=d,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.config)return lbUtils.colorArr[0].hexString;const{fill:t}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:e},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&DrawUtils.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const o=this.scene.children[t];o.type==="Points"&&o.name!==this.store.pointCloudObjectName&&o.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}module.exports=PointCloudRender;
1
+ "use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),DrawUtils=require("../../../utils/tool/DrawUtils.js");function _interopNamespace(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if(t!=="default"){var o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloudRender{constructor({store:e,on:t,unbind:o,nextTick:l}){this.clearStash=()=>{var i,s;const n=this.scene.getObjectByName((s=(i=this.store.cacheSegData)==null?void 0:i.id)!=null?s:"");n&&(n.removeFromParent(),this.render3d())},this.generateNewPoints=i=>{const s=new THREE__namespace.BufferGeometry;s.setAttribute("position",new THREE__namespace.BufferAttribute(i.points,3));const n=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),a=new THREE__namespace.Points(s,n);a.name=i.id,this.store.scene.add(a),this.render3d()},this.updateNewPoints=i=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(n.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(i.points,3)),n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),n.geometry.attributes.position.needsUpdate=!0,n.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(i=this.store.cacheSegData)=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(i.attribute=this.store.currentAttribute,n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=o,this.nextTick=l,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.store.config)return lbUtils.colorArr[0].hexString;const{fill:t}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:e},__spreadProps(__spreadValues({},this.store.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&DrawUtils.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const o=this.scene.children[t];o.type==="Points"&&o.name!==this.store.pointCloudObjectName&&o.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}module.exports=PointCloudRender;
@@ -1 +1 @@
1
- "use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(h){if(h&&h.__esModule)return h;var t=Object.create(null);return h&&Object.keys(h).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return h[e]}})}}),t.default=h,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(h,t,e)=>t in h?__defProp(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,__spreadValues=(h,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(h,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(h,e,t[e]);return h},__spreadProps=(h,t)=>__defProps(h,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit: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((c,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const d=s==null?void 0:s.filter(c=>{var u;return!this.hiddenAttributes.some(l=>l===c.attribute)&&c.id!==((u=this.cacheSegData)==null?void 0:u.id)});(d==null?void 0:d.length)!==0&&d.map(c=>(this.emit("addNewPointsCloud",c),c)),this.emit("reRender3d")},this.updateCoverPoints=(s=[])=>{this.segmentData.forEach((d,c)=>{var u;if(c!==((u=this.cacheSegData)==null?void 0:u.id)){const l=lbUtils.PointCloudUtils.splitPointsFromIndexes(d.indexes,s),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),d.indexes=l,d.points=new Float32Array(S);const p=this.scene.getObjectByName(c);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.setSubAttribute=this.setSubAttribute.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,subAttribute:i.subAttribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),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 d=new THREE__namespace.Vector3(i[s],i[s+1],i[s+2]);d.project(this.camera);const c={x:0,y:0};if(c.x=Math.round(d.x*this.container.clientWidth/2+this.container.clientWidth/2),c.y=Math.round(-d.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(c,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,subAttribute:{},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.resetSelectedSegmentStatus()}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"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(i=>{i.attribute===t&&e.push(i.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=__spreadProps(__spreadValues({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}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:s,emit:n,on:r,unbind:o,checkMode:p,config:a}){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 m=this.scene.getObjectByName(u);m&&m.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),m=[];l.forEach(D=>{m.push(this.originPoints[D*3],this.originPoints[D*3+1],this.originPoints[D*3+2])}),c.indexes=l,c.points=new Float32Array(m);const g=this.scene.getObjectByName(d);g&&(g.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(new Float32Array(m),3)),g.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=s,this.emit=n,this.on=r,this.unbind=o,this.checkMode=p,this.config=a,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.setSubAttribute=this.setSubAttribute.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,subAttribute:i.subAttribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),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(s=>{const n=[];s.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({},s),{points:new Float32Array(n)});this.segmentData.set(s.id,r),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},s),{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}setConfig(t){this.config=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 s=1;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,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 s=i.length,n=[],r=[],o=[];for(let a=0;a<s;a+=3){const S=new THREE__namespace.Vector3(i[a],i[a+1],i[a+2]);S.project(this.camera);const c={x:0,y:0};if(c.x=Math.round(S.x*this.container.clientWidth/2+this.container.clientWidth/2),c.y=Math.round(-S.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(c,e)){const u=i[a],l=i[a+1],m=i[a+2],g=lbUtils.PointCloudUtils.getCloudKeys(u,l,m);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(g).visible=!1,n.push(i[a],i[a+1],i[a+2]),o.push(a/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(n.push(i[a],i[a+1],i[a+2]),o.push(a/3),this.cloudData.get(g).visible===!0&&r.push(a/3)),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(i[a],i[a+1],i[a+2]),o.push(a/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 p=new Float32Array(n);this.updateStatusBySelector(p,r,o)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:s,coverPoints:n=new Float32Array([])}=this.cacheSegData,r=s.length+t.length,o=new Float32Array(r);o.set(s,0),o.set(t,s.length);const p=[...new Set([...n,...e])];this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:o,coverPoints:p,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,subAttribute:{},points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:s,indexes:n}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(s,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 s=t[i],n=t[i+1],r=t[i+2],o=lbUtils.PointCloudUtils.getCloudKeys(s,n,r),p=this.cloudData.get(o);Object.keys(e).forEach(a=>{p[a]=e[a]})}}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.resetSelectedSegmentStatus()}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const s=e.geometry.attributes.position.array;for(let n=0;n<i.length;n++){const r=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(s[n],s[n+1],s[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 s=this.scene.getObjectByName(i);s&&(s==null?void 0:s.material)&&(s.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(i=>{i.attribute===t&&e.push(i.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=__spreadProps(__spreadValues({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}module.exports=PointCloudStore;
@@ -41,6 +41,7 @@ export interface IPointCloudDelegate extends IEventBus {
41
41
  camera: THREE.OrthographicCamera | THREE.PerspectiveCamera;
42
42
  container: HTMLElement;
43
43
  checkMode: boolean;
44
+ config?: IPointCloudConfig;
44
45
  }
45
46
  export declare class PointCloud extends EventListener {
46
47
  renderer: THREE.WebGLRenderer;
@@ -105,6 +106,7 @@ export declare class PointCloud extends EventListener {
105
106
  camera: THREE.OrthographicCamera | THREE.PerspectiveCamera;
106
107
  renderer: THREE.WebGLRenderer;
107
108
  checkMode: boolean;
109
+ config: IPointCloudConfig | undefined;
108
110
  };
109
111
  get DEFAULT_INIT_CAMERA_POSITION(): THREE.Vector3;
110
112
  get containerWidth(): number;
@@ -4,22 +4,20 @@
4
4
  * @createdate 2023-05-05
5
5
  */
6
6
  import * as THREE from 'three';
7
- import { IPointCloudConfig, IPointCloudSegmentation } from '@labelbee/lb-utils';
7
+ import { IPointCloudSegmentation } from '@labelbee/lb-utils';
8
8
  import EventListener from '@/core/toolOperation/eventListener';
9
9
  import PointCloudStore from '../store';
10
10
  import { IEventBus } from '..';
11
11
  interface IPointCloudRenderProps extends IEventBus {
12
12
  store: PointCloudStore;
13
13
  nextTick: () => void;
14
- config?: IPointCloudConfig;
15
14
  }
16
15
  declare class PointCloudRender {
17
16
  store: PointCloudStore;
18
17
  nextTick: () => void;
19
18
  on: EventListener['on'];
20
19
  unbind: EventListener['unbind'];
21
- config?: IPointCloudConfig;
22
- constructor({ store, on, unbind, nextTick, config }: IPointCloudRenderProps);
20
+ constructor({ store, on, unbind, nextTick }: IPointCloudRenderProps);
23
21
  get scene(): THREE.Scene;
24
22
  getCurrentColor(attribute?: string): string;
25
23
  initMsg(): void;
@@ -4,7 +4,7 @@
4
4
  * @createdate 2023-05-05
5
5
  */
6
6
  import * as THREE from 'three';
7
- import { EPointCloudSegmentCoverMode, EPointCloudSegmentFocusMode, EPointCloudSegmentMode, IPointCloudSegmentation } from '@labelbee/lb-utils';
7
+ import { EPointCloudSegmentCoverMode, EPointCloudSegmentFocusMode, EPointCloudSegmentMode, IPointCloudConfig, IPointCloudSegmentation } from '@labelbee/lb-utils';
8
8
  import { IPointCloudDelegate } from '..';
9
9
  export type ThreePoints = THREE.Points<THREE.BufferGeometry, THREE.PointsMaterial>;
10
10
  /**
@@ -44,10 +44,11 @@ declare class PointCloudStore {
44
44
  highlightAttribute: string;
45
45
  hiddenAttributes: string[];
46
46
  pointCloudObjectName: string;
47
+ config?: IPointCloudConfig;
47
48
  private emit;
48
49
  private on;
49
50
  private unbind;
50
- constructor({ container, scene, camera, renderer, emit, on, unbind, checkMode }: IPointCloudDelegate);
51
+ constructor({ container, scene, camera, renderer, emit, on, unbind, checkMode, config }: IPointCloudDelegate);
51
52
  initMsg(): void;
52
53
  unbindMsg(): void;
53
54
  get containerWidth(): number;
@@ -79,6 +80,7 @@ declare class PointCloudStore {
79
80
  setupRaycaster(): void;
80
81
  setHoverPointsID(id: string): void;
81
82
  setSegmentMode(mode: EPointCloudSegmentMode): void;
83
+ setConfig(config: IPointCloudConfig): void;
82
84
  setSegmentCoverMode(coverMode: EPointCloudSegmentCoverMode): void;
83
85
  setSegmentFocusMode(focusMode: EPointCloudSegmentFocusMode): void;
84
86
  switchSegmentHideMode(hideSegment: boolean): void;
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as C,PointCloudUtils as F,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,k=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&k(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&k(w,e,t[e]);return w},S=(w,t)=>tt(w,et(t)),z=(w,t,e)=>new Promise((i,r)=>{var o=d=>{try{n(e.next(d))}catch(s){r(s)}},c=d=>{try{n(e.throw(d))}catch(s){r(s)}},n=d=>d.done?i(d.value):Promise.resolve(d.value).then(o,c);n((e=e.apply(w,t)).next())});const nt=30,L=new E({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:o="#4C4C4C",config:c,isSegment:n,checkMode:d}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(s,h="blue")=>{var l;const m=(l=s.id)!=null?l:I();this.removeObjectByName(m,"sphere");const{radius:p,widthSegments:f,heightSegments:u}=O,{center:g}=s,y=new a.Group,x=new a.SphereGeometry(p,f,u),M=new a.MeshBasicMaterial({color:h}),P=new a.Mesh(x,M);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=s=>{const{fill:h}=this.getColorFromConfig(s.attribute);this.addSphereToSense(s,h),this.render()},this.generateSpheres=s=>{s.forEach(h=>{const{fill:l}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(s,h=16777215)=>{var l;const m=(l=s.id)!=null?l:I();this.removeObjectByName(m,"box");const{center:p,width:f,height:u,depth:g,rotation:y}=s,x=new a.Group,M=new a.BoxGeometry(f,u,g),P=new a.MeshBasicMaterial({color:"blue"}),B=new a.Mesh(M,P),_=new a.BoxHelper(B,h),N=this.generateBoxArrow(s),D=this.generateBoxTrackID(s);D&&x.add(D),x.add(_),x.add(N),p&&x.position.set(p.x,p.y,p.z),y&&x.rotation.set(0,0,y),x.name=`box${m}`,this.scene.add(x)},this.applyCameraTarget=s=>{if(this.camera.type==="OrthographicCamera"&&s){const h=this.getOrthographicCameraTarget(s);this.updateCameraZoom(s.zoom),this.updateCamera(s.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as b,PointCloudUtils as F,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,k=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,C=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&k(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&k(w,e,t[e]);return w},S=(w,t)=>tt(w,et(t)),z=(w,t,e)=>new Promise((i,r)=>{var s=d=>{try{o(e.next(d))}catch(n){r(n)}},h=d=>{try{o(e.throw(d))}catch(n){r(n)}},o=d=>d.done?i(d.value):Promise.resolve(d.value).then(s,h);o((e=e.apply(w,t)).next())});const nt=30,L=new E({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:d}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,l="blue")=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"sphere");const{radius:u,widthSegments:f,heightSegments:p}=O,{center:g}=n,y=new a.Group,x=new a.SphereGeometry(u,f,p),M=new a.MeshBasicMaterial({color:l}),P=new a.Mesh(x,M);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l),this.render()},this.generateSpheres=n=>{n.forEach(l=>{const{fill:c}=this.getColorFromConfig(l.attribute);this.addSphereToSense(l,c)}),this.render()},this.addBoxToSense=(n,l=16777215)=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"box");const{center:u,width:f,height:p,depth:g,rotation:y}=n,x=new a.Group,M=new a.BoxGeometry(f,p,g),P=new a.MeshBasicMaterial({color:"blue"}),B=new a.Mesh(M,P),_=new a.BoxHelper(B,l),N=this.generateBoxArrow(n),D=this.generateBoxTrackID(n);D&&x.add(D),x.add(_),x.add(N),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${m}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const l=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,l)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,4 @@ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...s)=>z(this,[...s],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:m,color:p}=yield this.cacheInstance.loadPCDFile(h),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(p,3)),this.initCloudData(m);const u=new a.Points(f);this.renderPointCloud(u,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=s=>z(this,[s],function*({mappingImgList:h,points:l}){const m=h.length===0?[]:yield Promise.all(h.map(u=>W.load(u.url))),p=h.map((u,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?y:[];const x=$({points:l,calib:u.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,x),x});return Y(p)}),this.loadPCDFileByBox=(s,h,l)=>z(this,null,function*(){const m=(u,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(b({},h),{width:h.width+y,height:h.height+x,depth:h.depth+M}),u,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:p,color:f}=yield this.cacheInstance.loadPCDFile(s);m(p,f)}),this.generateRange=s=>{const h=this.createRange(s);this.scene.add(h)},this.generateBoxArrow=({width:s})=>{const h=new a.Vector3(1,0,0),l=new a.Vector3(s/2,0,0),m=2,p=16776960,f=new a.ArrowHelper(h,l,m,p);return f.visible=this.showDirection,f},this.generateBoxTrackID=s=>{if(!s.trackID)return;const h=new a.Texture(this.getTextCanvas(s.trackID.toString()));h.needsUpdate=!0;const l=new a.SpriteMaterial({map:h,depthWrite:!1}),m=new a.Sprite(l);return m.scale.set(5,5,5),m.position.set(-s.width/2,0,s.depth/2+.5),m},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const m=l.material.uniforms.pointSize.value;s?l.material.uniforms.pointSize.value=Math.min(m*1.2,10):l.material.uniforms.pointSize.value=Math.max(m/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=c,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),n===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(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 X(b({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(S(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}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return 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 a.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:o,near:c,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=c,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 a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(b({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,c=e.x-i/2-o,n=e.x-i/2+o,d=e.y+r/2+o,s=e.y-r/2-o,h=100,l=-100,m=500/h;return{left:c,right:n,top:d,bottom:s,near:h,far:l,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:c,depth:n,rotation:d}=t,s=this.getCameraVector(r,d,{width:o,height:c,depth:n},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,o,c;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=(c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array}if(window.Worker){const{zMin:n,zMax:d,polygonPointList:s}=A(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:n,zMax:d,polygonPointList:s,color:i,position:h};return new Promise(m=>{const p=new V;p.postMessage(l),p.onmessage=f=>{const{color:u,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(u,3)),x.computeBoundingSphere(),p.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,o=nt){let c=v.frontViewMatrix4(o);switch(r){case C.Front:break;case C.Back:c=v.backViewMatrix4(o);break;case C.Left:c=v.leftViewMatrix4(o);break;case C.Right:c=v.rightViewMatrix4(o);break;case C.Top:c=v.topViewMatrix4(o);break;case C.LFT:c=v.leftFrontTopViewMatrix4(o,i);break;case C.RBT:c=v.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(c),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new a.Matrix4().makeTranslation(t.x,t.y,t.z),h=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(d).applyMatrix4(h).applyMatrix4(s)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),o=new a.LineBasicMaterial({color:16711680}),c=new a.Line(r,o);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(h=>A(h)),d=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(s),L.onmessage=h=>{const{color:l}=h.data,m=new a.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==l.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(l),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:o,z:c},width:n,height:d,depth:s,rotation:h}=i,{fill:l}=T.getColorFromConfig({attribute:i.attribute},S(b({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(n,d,s),p=new a.MeshBasicMaterial({color:l,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(h),m.translate(r,o,c);const f=new a.Mesh(m,p);e.add(f);const u=new a.PlaneGeometry(s,d);u.rotateY(Math.PI/2),u.rotateZ(h);const g=new a.Vector3(n/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(h);g.applyMatrix4(y),u.translate(r+g.x,o+g.y,c+g.z);const x=new a.MeshBasicMaterial({color:l,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(u,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.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,m)=>l.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:l})=>l>r.z+.1);const o=.005,c=Math.floor(e.length*(1-o));e=e.slice(0,c),e.sort((l,m)=>l.x-m.x);const n=Math.floor(e.length*o),d=Math.floor(e.length*(1-o));e=e.slice(n,d),e.sort((l,m)=>l.y-m.y);const s=Math.floor(e.length*o),h=Math.floor(e.length*(1-o));return e=e.slice(s,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:d})=>{t.forEach((s,h)=>{const l=r[h+1],m=H.getFootOfPerpendicular({x:n,y:d},s,l,!1,!0).length;(!i[h]||m<i[h].distance)&&(i[h]={distance:m,point:{x:n,y:d}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,d)=>{const s=r[d],h=r[d+1],l=r[d+2];return F.getIntersectionBySlope({p1:o[d].point,line1:[s,h],p2:o[d+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,c;const n=this.scene.children.find(u=>u.uuid===this.pointsUuid);let d=0,s=0,h=0,l=0,m=[],p=[];const f=((c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array)||[];for(let u=0;u<f.length;u+=3){const g=f[u],y=f[u+1],x=f[u+2];R({x:g,y},t)&&(x||x===0)&&p.push({x:g,y,z:x})}return p.length?(i&&(p=this.filterNoise(p),m=this.getFittedCoordinates(t,p)),p.sort((u,g)=>u.z-g.z),d=p[0].z-.01,s=p[p.length-1].z+.01,l=p.length,e&&(h=p.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:m}):{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r-n/2},s={x:e+c/2,y:i+o/2,z:r+n/2},h={x:e-c/2,y:i+o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r-n/2};return[d,s,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e-c/2,y:i+o/2,z:r+n/2},s={x:e-c/2,y:i+o/2,z:r-n/2},h={x:e-c/2,y:i-o/2,z:r-n/2},l={x:e-c/2,y:i-o/2,z:r+n/2};return[d,s,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r+n/2},s={x:e+c/2,y:i-o/2,z:r+n/2},h={x:e-c/2,y:i-o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r+n/2};return[d,s,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,c=new a.Matrix4().makeTranslation(-e,-i,-r),n=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(o);return new a.Matrix4().multiply(n).multiply(d).multiply(c)}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:o}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const d=i.map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,h=this.containerHeight/o;return{polygon2d:d,zoom:Math.min(s,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:c}=O,n={center:e,attribute:i,id:r,valid:o,width:c*2,height:c*2,depth:c*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new a.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const h=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(c*2),m=this.containerHeight/(c*2);return{point2d:h,zoom:Math.min(l,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),c=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(c,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(b({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(b({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const c=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(c)),[d,s,h,l]=n,m=Math.max(Math.abs(d.x-h.x),Math.abs(d.x-s.x)),f=s.add(l).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(b({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,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,o=[],{count:c}=r;for(let n=0;n<c;n++){const d=r.getZ(n);o.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(m);const p=new a.Points(f);this.renderPointCloud(p,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:l,points:c}){const m=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),u=l.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=$({points:c,calib:p.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return Y(u)}),this.loadPCDFileByBox=(n,l,c)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=c!=null?c:{},P=yield this.filterPointsByBox(S(C({},l),{width:l.width+y,height:l.height+x,depth:l.depth+M}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:u,color:f}=yield this.cacheInstance.loadPCDFile(n);m(u,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(l,c,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),m=new a.Sprite(c);return m.scale.set(5,5,5),m.position.set(-n.width/2,0,n.depth/2+.5),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const m=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(m*1.2,10):c.material.uniforms.pointSize.value=Math.max(m/1.2,1),l&&(c.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(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 X(C({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(S(C({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return C({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(C({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,c=-100,m=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=A(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(m=>{const u=new V;u.postMessage(c),u.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,s=nt){let h=v.frontViewMatrix4(s);switch(r){case b.Front:break;case b.Back:h=v.backViewMatrix4(s);break;case b.Left:h=v.leftViewMatrix4(s);break;case b.Right:h=v.rightViewMatrix4(s);break;case b.Top:h=v.topViewMatrix4(s);break;case b.LFT:h=v.leftFrontTopViewMatrix4(s,i);break;case b.RBT:h=v.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(l=>A(l)),d=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(n),L.onmessage=l=>{const{color:c}=l.data,m=new a.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=T.getColorFromConfig({attribute:i.attribute},S(C({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(o,d,n),u=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(l),m.translate(r,s,h);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(o/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.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((c,m)=>c.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((c,m)=>c.x-m.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((c,m)=>c.y-m.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,c)=>{const m=r[c+1],u=H.getFootOfPerpendicular({x:d,y:n},l,m,!1,!0).length;(!i[c]||u<i[c].distance)&&(i[c]={distance:u,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],m=r[n+2];return F.getIntersectionBySlope({p1:s[n].point,line1:[l,c],p2:s[n+1].point,line2:[c,m]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,m=[],u=[];const f=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];R({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),m=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),d=u[0].z-.01,n=u[u.length-1].z+.01,c=u.length,e&&(l=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}):{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},l={x:e-h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},l={x:e-h/2,y:i-s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},l={x:e-h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case b.Left:return this.getPolygonSidePoints(t);case b.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new a.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),m=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[d,n,l,c]=o,m=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(C({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
@@ -1 +1 @@
1
- import*as o from"three";import{colorArr as g,toolStyleConverter as p}from"@labelbee/lb-utils";import P from"../../../utils/tool/DrawUtils.js";var m=Object.defineProperty,b=Object.defineProperties,f=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,S=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,h=(n,e,t)=>e in n?m(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,w=(n,e)=>{for(var t in e||(e={}))S.call(e,t)&&h(n,t,e[t]);if(d)for(var t of d(e))v.call(e,t)&&h(n,t,e[t]);return n},C=(n,e)=>b(n,f(e));class _{constructor({store:e,on:t,unbind:a,nextTick:c,config:u}){this.clearStash=()=>{var r,s;const i=this.scene.getObjectByName((s=(r=this.store.cacheSegData)==null?void 0:r.id)!=null?s:"");i&&(i.removeFromParent(),this.render3d())},this.generateNewPoints=r=>{const s=new o.BufferGeometry;s.setAttribute("position",new o.BufferAttribute(r.points,3));const i=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),l=new o.Points(s,i);l.name=r.id,this.store.scene.add(l),this.render3d()},this.updateNewPoints=r=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(i.geometry.setAttribute("position",new o.Float32BufferAttribute(r.points,3)),i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),i.geometry.attributes.position.needsUpdate=!0,i.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(r=this.store.cacheSegData)=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(r.attribute=this.store.currentAttribute,i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=a,this.nextTick=c,this.config=u,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.config)return g[0].hexString;const{fill:t}=p.getColorFromConfig({attribute:e},C(w({},this.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&P.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const a=this.scene.children[t];a.type==="Points"&&a.name!==this.store.pointCloudObjectName&&a.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}export{_ as default};
1
+ import*as o from"three";import{colorArr as u,toolStyleConverter as g}from"@labelbee/lb-utils";import p from"../../../utils/tool/DrawUtils.js";var P=Object.defineProperty,m=Object.defineProperties,b=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,h=(n,e,t)=>e in n?P(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,v=(n,e)=>{for(var t in e||(e={}))f.call(e,t)&&h(n,t,e[t]);if(d)for(var t of d(e))S.call(e,t)&&h(n,t,e[t]);return n},w=(n,e)=>m(n,b(e));class C{constructor({store:e,on:t,unbind:a,nextTick:c}){this.clearStash=()=>{var r,s;const i=this.scene.getObjectByName((s=(r=this.store.cacheSegData)==null?void 0:r.id)!=null?s:"");i&&(i.removeFromParent(),this.render3d())},this.generateNewPoints=r=>{const s=new o.BufferGeometry;s.setAttribute("position",new o.BufferAttribute(r.points,3));const i=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),l=new o.Points(s,i);l.name=r.id,this.store.scene.add(l),this.render3d()},this.updateNewPoints=r=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(i.geometry.setAttribute("position",new o.Float32BufferAttribute(r.points,3)),i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),i.geometry.attributes.position.needsUpdate=!0,i.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(r=this.store.cacheSegData)=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(r.attribute=this.store.currentAttribute,i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=a,this.nextTick=c,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.store.config)return u[0].hexString;const{fill:t}=g.getColorFromConfig({attribute:e},w(v({},this.store.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("deleteSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&p.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const a=this.scene.children[t];a.type==="Points"&&a.name!==this.store.pointCloudObjectName&&a.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}export{C as default};
@@ -1 +1 @@
1
- import*as v from"three";import{EPointCloudSegmentMode as y,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as P}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,D=(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 H="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=y.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 g;if(u!==((g=this.cacheSegData)==null?void 0:g.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(g=>g===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 g=P.splitPointsFromIndexes(c.indexes,i),S=[];g.forEach(l=>{S.push(this.originPoints[l*3],this.originPoints[l*3+1],this.originPoints[l*3+2])}),c.indexes=g,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.setSubAttribute=this.setSubAttribute.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,subAttribute:s.subAttribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),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(D({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",b(D({},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(`${H}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===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 g=s[i],S=s[i+1],f=s[i+2],l=P.getCloudKeys(g,S,f);this.segmentMode===y.Remove&&(this.cloudData.get(l).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===y.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(l).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(l).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(l).visible===!1&&(this.cloudData.get(l).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===y.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case y.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(D({},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,subAttribute:{},points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case y.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=b(D({},this.cacheSegData),{points:P.splitPointsFromPoints(a,t),indexes:P.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],o=t[s+2],h=P.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.resetSelectedSegmentStatus()}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(P.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(D({},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(D({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(s=>{s.attribute===t&&e.push(s.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=b(D({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}export{I as default};
1
+ import*as v from"three";import{EPointCloudSegmentMode as f,EPointCloudSegmentCoverMode as M,EPointCloudSegmentFocusMode as C,PointCloudUtils as P}from"@labelbee/lb-utils";import{isInPolygon as F}from"../../../utils/tool/polygonTool.js";import O from"../../../utils/uuid.js";import p from"./fsm.js";var _=Object.defineProperty,R=Object.defineProperties,B=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,E=(c,t,e)=>t in c?_(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,b=(c,t)=>{for(var e in t||(t={}))k.call(t,e)&&E(c,e,t[e]);if(w)for(var e of w(t))H.call(t,e)&&E(c,e,t[e]);return c},y=(c,t)=>R(c,B(t));const I="LABELBEE_CANVAS_";class j{constructor({container:t,scene:e,camera:s,renderer:i,emit:n,on:o,unbind:h,checkMode:D,config:a}){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=f.Add,this.segmentCoverMode=M.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=S=>{this.segmentData.forEach((d,u)=>{var g;if(u!==((g=this.cacheSegData)==null?void 0:g.id)){const m=this.scene.getObjectByName(u);m&&m.removeFromParent()}});const r=S==null?void 0:S.filter(d=>{var u;return!this.hiddenAttributes.some(g=>g===d.attribute)&&d.id!==((u=this.cacheSegData)==null?void 0:u.id)});(r==null?void 0:r.length)!==0&&r.map(d=>(this.emit("addNewPointsCloud",d),d)),this.emit("reRender3d")},this.updateCoverPoints=(S=[])=>{this.segmentData.forEach((r,d)=>{var u;if(d!==((u=this.cacheSegData)==null?void 0:u.id)){const g=P.splitPointsFromIndexes(r.indexes,S),m=[];g.forEach(A=>{m.push(this.originPoints[A*3],this.originPoints[A*3+1],this.originPoints[A*3+2])}),r.indexes=g,r.points=new Float32Array(m);const l=this.scene.getObjectByName(d);l&&(l.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(m),3)),l.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=i,this.emit=n,this.on=o,this.unbind=h,this.checkMode=D,this.config=a,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.setSubAttribute=this.setSubAttribute.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 p.segmentStatus}get isReadyStatus(){return p.isReadyStatus}get isCheckStatus(){return p.isCheckStatus}get isEditStatus(){return p.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,subAttribute:s.subAttribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),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(i=>{const n=[];i.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=y(b({},i),{points:new Float32Array(n)});this.segmentData.set(i.id,o),this.emit("addNewPointsCloud",y(b({},i),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){p.statusToggle()}updateStatus2Edit(){p.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}setConfig(t){this.config=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 i=1;t.style.position="absolute",t.width=e.width*i,t.height=e.height*i,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 i=s.length,n=[],o=[],h=[];for(let a=0;a<i;a+=3){const S=new v.Vector3(s[a],s[a+1],s[a+2]);S.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(S.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-S.y*this.container.clientHeight/2+this.container.clientHeight/2),F(r,e)){const u=s[a],g=s[a+1],m=s[a+2],l=P.getCloudKeys(u,g,m);this.segmentMode===f.Remove&&(this.cloudData.get(l).visible=!1,n.push(s[a],s[a+1],s[a+2]),h.push(a/3)),this.segmentMode===f.Add&&(this.segmentCoverMode===M.Cover&&(n.push(s[a],s[a+1],s[a+2]),h.push(a/3),this.cloudData.get(l).visible===!0&&o.push(a/3)),this.segmentCoverMode===M.Uncover&&this.cloudData.get(l).visible===!1&&(n.push(s[a],s[a+1],s[a+2]),h.push(a/3)),this.cloudData.get(l).visible===!1&&(this.cloudData.get(l).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===f.Remove)return;const D=new Float32Array(n);this.updateStatusBySelector(D,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case f.Add:if(this.cacheSegData){const{points:i,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=i.length+t.length,h=new Float32Array(o);h.set(i,0),h.set(t,i.length);const D=[...new Set([...n,...e])];this.cacheSegData=y(b({},this.cacheSegData),{points:h,coverPoints:D,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:O(),attribute:this.currentAttribute,subAttribute:{},points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case f.Remove:if(this.cacheSegData){const{points:i,indexes:n}=this.cacheSegData;this.cacheSegData=y(b({},this.cacheSegData),{points:P.splitPointsFromPoints(i,t),indexes:P.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const i=t[s],n=t[s+1],o=t[s+2],h=P.getCloudKeys(i,n,o),D=this.cloudData.get(h);Object.keys(e).forEach(a=>{D[a]=e[a]})}}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.resetSelectedSegmentStatus()}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const i=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const o=this.cloudData.get(P.getCloudKeys(i[n],i[n+1],i[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,p.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=y(b({},t),{points:new Float32Array(t.points)}),p.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=y(b({},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 i=this.scene.getObjectByName(s);i&&(i==null?void 0:i.material)&&(i.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(s=>{s.attribute===t&&e.push(s.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=y(b({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}export{j as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.20.0-alpha.6",
3
+ "version": "1.20.0-alpha.8",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",