@labelbee/lb-annotation 1.27.0-alpha.54 → 1.27.0-alpha.55

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(y){if(y&&y.__esModule)return y;var t=Object.create(null);return y&&Object.keys(y).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(y,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return y[e]}})}}),t.default=y,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=(y,t,e)=>t in y?__defProp(y,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):y[t]=e,__spreadValues=(y,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(y,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(y,e,t[e]);return y},__spreadProps=(y,t)=>__defProps(y,__getOwnPropDescs(t)),__async=(y,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(y,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.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,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:p,widthSegments:x,heightSegments:g}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:u}=n,m=new THREE__namespace.Group,f=new THREE__namespace.SphereGeometry(p,x,g),w=new THREE__namespace.MeshBasicMaterial({color:c}),C=new THREE__namespace.Mesh(f,w);C.position.set(u.x,u.y,u.z),m.add(C),m.name=`sphere${d}`,this.scene.add(m)},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:p,width:x,height:g,depth:u,rotation:m}=n,f=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(x,g,u),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),b=new THREE__namespace.Mesh(w,C),M=new THREE__namespace.BoxHelper(b,c),S=this.generateBoxArrow(n),v=this.generateBoxTrackID(n);v&&f.add(v),f.add(M),f.add(S),p&&f.position.set(p.x,p.y,p.z),m&&f.rotation.set(0,0,m),f.name=`box${d}`;const B=new THREE__namespace.BoxGeometry(x,g,u),O=new THREE__namespace.MeshBasicMaterial({visible:!1}),P=new THREE__namespace.Mesh(B,O);P.userData={selectedID:d},f.add(P),this.scene.add(f)},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:`
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(w){if(w&&w.__esModule)return w;var t=Object.create(null);return w&&Object.keys(w).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(w,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return w[e]}})}}),t.default=w,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=(w,t,e)=>t in w?__defProp(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,__spreadValues=(w,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(w,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(w,e,t[e]);return w},__spreadProps=(w,t)=>__defProps(w,__getOwnPropDescs(t)),__async=(w,t,e)=>new Promise((i,r)=>{var a=l=>{try{s(e.next(l))}catch(u){r(u)}},h=l=>{try{s(e.throw(l))}catch(u){r(u)}},s=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,h);s((e=e.apply(w,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:a="#4C4C4C",config:h,isSegment:s,checkMode:l,hiddenText:u=!1}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,this.hiddenText=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,n="blue")=>{var c;const d=(c=o.id)!=null?c:uuid();this.removeObjectByName(d,"sphere");const{radius:x,widthSegments:p,heightSegments:f}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=o,m=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(x,p,f),b=new THREE__namespace.MeshBasicMaterial({color:n}),C=new THREE__namespace.Mesh(y,b);C.position.set(g.x,g.y,g.z),m.add(C),m.name=`sphere${d}`,this.scene.add(m)},this.generateSphere=o=>{const{fill:n}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,n),this.render()},this.generateSpheres=o=>{o.forEach(n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c)}),this.render()},this.addBoxToSense=(o,n=16777215)=>{var c;const d=(c=o.id)!=null?c:uuid();this.removeObjectByName(d,"box");const{center:x,width:p,height:f,depth:g,rotation:m}=o,y=new THREE__namespace.Group,b=new THREE__namespace.BoxGeometry(p,f,g),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),v=new THREE__namespace.Mesh(b,C),B=new THREE__namespace.BoxHelper(v,n),O=this.generateBoxArrow(o),M=this.generateBoxTrackID(o);M&&y.add(M);const P=this.generateBoxAttributeLabel(o);P&&y.add(P),y.add(B),y.add(O),x&&y.position.set(x.x,x.y,x.z),m&&y.rotation.set(0,0,m),y.name=`box${d}`;const z=new THREE__namespace.BoxGeometry(p,f,g),L=new THREE__namespace.MeshBasicMaterial({visible:!1}),S=new THREE__namespace.Mesh(z,L);S.userData={selectedID:d},y.add(S),this.scene.add(y)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const n=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,n)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,6 @@
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:p}=yield this.cacheInstance.loadPCDFile(c),x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||x.setAttribute("dimensions",new THREE__namespace.BufferAttribute(p,3)),this.initCloudData(d);const g=new THREE__namespace.Points(x);this.renderPointCloud(g,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=u=>__async(this,null,function*(){try{return yield ImgUtils.default.load(u)}catch(m){return console.error("Error loading image:",m),null}}),p=c.length===0?[]:(yield Promise.all(c.map(u=>__async(this,null,function*(){let m=yield d(u.url);return!m&&u.fallbackUrl&&(m=yield d(u.fallbackUrl)),m})))).filter(u=>u!==null),x=c.map((u,m)=>{var f;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(f=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?f:[];const w=matrix.getHighlightIndexByPoints({points:h,calib:u.calib,width:p[m].width,height:p[m].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,w),w});return matrix.mergeHighlightList(x)}),this.filterPreResult=(n,c,h)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),p=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(x=>{const g=h.map(u=>{const m=MathUtils.default.calculatePointsInsideBox({indexMap:p,polygon:matrix.getCuboidFromPointCloudBox(u).polygonPointList,zScope:[u.center.z-u.depth/2,u.center.z+u.depth/2],box:u}),f=m>=c.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},u),{valid:f,count:m})});x(g)})}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(g,u)=>__async(this,null,function*(){const{width:m=0,height:f=0,depth:w=0}=h!=null?h:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+m,height:c.height+f,depth:c.depth+w}),g,u);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const b=new THREE__namespace.Points(C.geometry);b.name=this.pointCloudObjectName,this.scene.add(b),this.render()}),{points:p,color:x}=yield this.cacheInstance.loadPCDFile(n);d(p,x)}),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,p=16776960,x=new THREE__namespace.ArrowHelper(c,h,d,p);return x.visible=this.showDirection,x},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),this.controls.addEventListener("rightClick",n=>{var c,h;const d=this.renderer.domElement.getBoundingClientRect(),p=n.originalEvent.clientX-d.left,x=n.originalEvent.clientY-d.top;this.pointer.x=p/d.width*2-1,this.pointer.y=-(x/d.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const g=[];this.scene.children.forEach(m=>{m instanceof THREE__namespace.Group&&m.children.forEach(f=>{f instanceof THREE__namespace.Mesh&&g.push(f)})});const u=this.raycaster.intersectObjects(g,!1);if(u.length>0){const m=u[0].object;(c=this.pipe)==null||c.setNeedUpdateCenter(!1),(h=this.pipe)==null||h.setSelectedIDs([m.userData.selectedID])}})}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,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 p=new filterBoxWorker;p.postMessage(h),p.onmessage=x=>{const{color:g,position:u,num:m}=x.data,f=new THREE__namespace.BufferGeometry;f.setAttribute("position",new THREE__namespace.Float32BufferAttribute(u,3)),f.setAttribute("color",new THREE__namespace.Float32BufferAttribute(g,3)),f.computeBoundingSphere(),p.terminate(),d({geometry:f,num:m})}})}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)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:s,resetAreas:a}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,n)=>{if(window.Worker){const h=(e?[...e]:[]).map(u=>matrix.getCuboidFromPointCloudBox(u)),d=this.getAllAttributeColor(h),p=o.geometry.attributes.position.array,x=o.geometry.attributes.dimensions.array,g={cuboidList:h,position:p,color:x,colorList:d,highlightIndex:i,modifiedBoxIds:s,resetAreas:a};this.handleWebworker(g).then(u=>{const{color:m}=u;let f=m;(s.length||a.length)&&(f=m.map((C,b)=>C===-1?x[b]:C));const w=new THREE__namespace.BufferAttribute(f,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==m.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,f),this.highlightPCDSrc=void 0,w.needsUpdate=!0,o.geometry.setAttribute("dimensions",w),o.geometry.attributes.dimensions.needsUpdate=!0,l(f),this.render()}).catch(u=>{n(u)})}})})}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),p=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const x=new THREE__namespace.Mesh(d,p);e.add(x);const g=new THREE__namespace.PlaneGeometry(n,l);g.rotateY(Math.PI/2),g.rotateZ(c);const u=new THREE__namespace.Vector3(o/2,0,0),m=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);u.applyMatrix4(m),g.translate(r+u.x,s+u.y,a+u.z);const f=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(g,f);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],p=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||p<i[h].distance)&&(i[h]={distance:p,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(g=>g.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],p=[];const x=((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 g=0;g<x.length;g+=3){const u=x[g],m=x[g+1],f=x[g+2];polygonTool.isInPolygon({x:u,y:m},t)&&(f||f===0)&&p.push({x:u,y:m,z:f})}return p.length?(i&&(p=this.filterNoise(p),d=this.getFittedCoordinates(t,p)),p.sort((g,u)=>g.z-u.z),l=p[0].z-.01,n=p[p.length-1].z+.01,h=p.length,e&&(c=p.filter(({z:g})=>g>=e[0]&&g<=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(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),x=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-x.x,y:r.center.y-x.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.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...o)=>__async(this,[...o],function*(n=this.currentPCDSrc,c){if(!n)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=n;const{points:d,color:x}=yield this.cacheInstance.loadPCDFile(n),p=new THREE__namespace.BufferGeometry;p.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||p.setAttribute("dimensions",new THREE__namespace.BufferAttribute(x,3)),this.initCloudData(d);const f=new THREE__namespace.Points(p);this.renderPointCloud(f,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=o=>__async(this,[o],function*({mappingImgList:n,points:c}){const d=g=>__async(this,null,function*(){try{return yield ImgUtils.default.load(g)}catch(m){return console.error("Error loading image:",m),null}}),x=n.length===0?[]:(yield Promise.all(n.map(g=>__async(this,null,function*(){let m=yield d(g.url);return!m&&g.fallbackUrl&&(m=yield d(g.fallbackUrl)),m})))).filter(g=>g!==null),p=n.map((g,m)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(g.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(g.url))!=null?y:[];const b=matrix.getHighlightIndexByPoints({points:c,calib:g.calib,width:x[m].width,height:x[m].height});return this.cacheInstance.cache2DHighlightIndex.set(g.url,b),b});return matrix.mergeHighlightList(p)}),this.filterPreResult=(o,n,c)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(o),x=yield this.cacheInstance.loadIndexMap(o,d);return new Promise(p=>{const f=c.map(g=>{const m=MathUtils.default.calculatePointsInsideBox({indexMap:x,polygon:matrix.getCuboidFromPointCloudBox(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),y=m>=n.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},g),{valid:y,count:m})});p(f)})}),this.loadPCDFileByBox=(o,n,c)=>__async(this,null,function*(){const d=(f,g)=>__async(this,null,function*(){const{width:m=0,height:y=0,depth:b=0}=c!=null?c:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},n),{width:n.width+m,height:n.height+y,depth:n.depth+b}),f,g);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const v=new THREE__namespace.Points(C.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:x,color:p}=yield this.cacheInstance.loadPCDFile(o);d(x,p)}),this.generateRange=o=>{const n=this.createRange(o);this.scene.add(n)},this.generateBoxArrow=({width:o})=>{const n=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(o/2,0,0),d=2,x=16776960,p=new THREE__namespace.ArrowHelper(n,c,d,x);return p.visible=this.showDirection,p},this.generateLabel=(o,n)=>{const c=this.getTextCanvas(o),d=new THREE__namespace.Texture(c);d.minFilter=THREE__namespace.LinearFilter,d.magFilter=THREE__namespace.LinearFilter,d.needsUpdate=!0;const x=c.width/window.devicePixelRatio,p=c.height/window.devicePixelRatio,f=new THREE__namespace.SpriteMaterial({map:d,depthWrite:!1}),g=new THREE__namespace.Sprite(f);return g.scale.set(x/n,p/n,1),{sprite:g,canvasWidth:x,canvasHeight:p}},this.generateBoxTrackID=o=>{if(!o.trackID)return;const{sprite:n}=this.generateLabel(o.trackID.toString(),50);return n.position.set(-o.width/2,0,o.depth/2+.5),n},this.generateBoxAttributeLabel=o=>{if(!o.attribute||this.hiddenText)return;const n=this.findSubAttributeLabel(o,this.config),c=n?`${o.attribute}
32
+ ${n}`:`${o.attribute}`,{sprite:d,canvasWidth:x,canvasHeight:p}=this.generateLabel(c,100);return d.position.set(-o.width/2,o.height/2-x/200,-o.depth/2-p/150),d},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:n})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;o?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),n&&(c.material.uniforms.pointSize.value=n,this.pointsMaterialSize=n),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=u,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",o=>{var n,c;const d=this.renderer.domElement.getBoundingClientRect(),x=o.originalEvent.clientX-d.left,p=o.originalEvent.clientY-d.top;this.pointer.x=x/d.width*2-1,this.pointer.y=-(p/d.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(m=>{m instanceof THREE__namespace.Group&&m.children.forEach(y=>{y instanceof THREE__namespace.Mesh&&f.push(y)})});const g=this.raycaster.intersectObjects(f,!1);if(g.length>0){const m=g[0].object;(n=this.pipe)==null||n.setNeedUpdateCenter(!1),(c=this.pipe)==null||c.setSelectedIDs([m.userData.selectedID])}})}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:a,near:h,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=h,this.camera.far=s,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,a=10,h=e.x-i/2-a,s=e.x-i/2+a,l=e.y+r/2+a,u=e.y-r/2-a,o=100,n=-100,c=500/o;return{left:h,right:s,top:l,bottom:u,near:o,far:n,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:h,depth:s,rotation:l}=t,u=this.getCameraVector(r,l,{width:a,height:h,depth:s},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,a,h;if(!e){const s=this.scene.getObjectByName(this.pointCloudObjectName);if(!s)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array}if(window.Worker){const{zMin:s,zMax:l,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),o=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:l,polygonPointList:u,color:i,position:o};return new Promise(c=>{const d=new filterBoxWorker;d.postMessage(n),d.onmessage=x=>{const{color:p,position:f,num:g}=x.data,m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.Float32BufferAttribute(f,3)),m.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),m.computeBoundingSphere(),d.terminate(),c({geometry:m,num:g})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,a=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(a);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(a);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(a);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(a);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(a);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(a,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),o=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(o).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),a=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,a);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:h}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(f=>matrix.getCuboidFromPointCloudBox(f)),c=this.getAllAttributeColor(n),d=s.geometry.attributes.position.array,x=s.geometry.attributes.dimensions.array,p={cuboidList:n,position:d,color:x,colorList:c,highlightIndex:i,modifiedBoxIds:a,resetAreas:h};this.handleWebworker(p).then(f=>{const{color:g}=f;let m=g;(a.length||h.length)&&(m=g.map((b,C)=>b===-1?x[C]:b));const y=new THREE__namespace.BufferAttribute(m,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==g.length){u(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,m),this.highlightPCDSrc=void 0,y.needsUpdate=!0,s.geometry.setAttribute("dimensions",y),s.geometry.attributes.dimensions.needsUpdate=!0,l(m),this.render()}).catch(f=>{u(f)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:a,z:h},width:s,height:l,depth:u,rotation:o}=i,{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),c=new THREE__namespace.BoxGeometry(s,l,u),d=new THREE__namespace.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(o),c.translate(r,a,h);const x=new THREE__namespace.Mesh(c,d);e.add(x);const p=new THREE__namespace.PlaneGeometry(u,l);p.rotateY(Math.PI/2),p.rotateZ(o);const f=new THREE__namespace.Vector3(s/2,0,0),g=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(o);f.applyMatrix4(g),p.translate(r+f.x,a+f.y,h+f.z);const m=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),y=new THREE__namespace.Mesh(p,m);e.add(y)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const a=Object.keys(t.subAttribute);return a.length===0||a.forEach(h=>{const s=i.find(n=>n.value===h);if(!s||!s.subSelected)return;const{key:l,subSelected:u}=s,o=u.find(n=>{var c;return n.value===((c=t.subAttribute)==null?void 0:c[h])});o&&(r&&(r+="\u3001"),r+=`${l}:${o.key}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const h=t.split(`
33
+ `),s=Math.max(...h.map(n=>i.measureText(n).width)),l=Math.ceil(s),u=a*1.5,o=u*h.length;e.width=l*r,e.height=o*r,e.style.width=`${l}px`,e.style.height=`${o}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((n,c)=>{i.fillText(n,0,c*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,c)=>n.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const a=.005,h=Math.floor(e.length*(1-a));e=e.slice(0,h),e.sort((n,c)=>n.x-c.x);const s=Math.floor(e.length*a),l=Math.floor(e.length*(1-a));e=e.slice(s,l),e.sort((n,c)=>n.y-c.y);const u=Math.floor(e.length*a),o=Math.floor(e.length*(1-a));return e=e.slice(u,o),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:u})=>{t.forEach((o,n)=>{const c=r[n+1],d=MathUtils.default.getFootOfPerpendicular({x:l,y:u},o,c,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:u}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],h=t.map((l,u)=>{const o=r[u],n=r[u+1],c=r[u+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:a[u].point,line1:[o,n],p2:a[u+1].point,line2:[n,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,a,h;const s=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,u=0,o=0,n=0,c=[],d=[];const x=((h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array)||[];for(let p=0;p<x.length;p+=3){const f=x[p],g=x[p+1],m=x[p+2];polygonTool.isInPolygon({x:f,y:g},t)&&(m||m===0)&&d.push({x:f,y:g,z:m})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((p,f)=>p.z-f.z),l=d[0].z-.01,u=d[d.length-1].z+.01,n=d.length,e&&(o=d.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:u,minZ:l,count:o,zCount:n,fittedCoordinates:c}):{maxZ:u,minZ:l,count:o,zCount:n,fittedCoordinates:c}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new 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:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r-s/2},u={x:e+h/2,y:i+a/2,z:r+s/2},o={x:e-h/2,y:i+a/2,z:r+s/2},n={x:e-h/2,y:i+a/2,z:r-s/2};return[l,u,o,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e-h/2,y:i+a/2,z:r+s/2},u={x:e-h/2,y:i+a/2,z:r-s/2},o={x:e-h/2,y:i-a/2,z:r-s/2},n={x:e-h/2,y:i-a/2,z:r+s/2};return[l,u,o,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r+s/2},u={x:e+h/2,y:i-a/2,z:r+s/2},o={x:e-h/2,y:i-a/2,z:r+s/2},n={x:e-h/2,y:i+a/2,z:r+s/2};return[l,u,o,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),s=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(a);return new THREE__namespace.Matrix4().multiply(s).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:a}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const l=i.map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,o=this.containerHeight/a;return{polygon2d:l,zoom:Math.min(u,o)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,s={center:e,attribute:i,id:r,valid:a,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const o=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:o,zoom:Math.min(n,c)/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)},a=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=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,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(h,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const a=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const h=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(f=>new THREE__namespace.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(h)),[l,u,o,n]=s,c=Math.max(Math.abs(l.x-o.x),Math.abs(l.x-u.x)),x=u.add(n).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-x.x,y:r.center.y-x.y,z:r.center.z-i},width:c,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,a=[],{count:h}=r;for(let s=0;s<h;s++){const l=r.getZ(s);a.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(g){return g&&typeof g=="object"&&"default"in g?g:{default:g}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,o)=>{var r=c=>{try{n(e.next(c))}catch(s){o(s)}},a=c=>{try{n(e.throw(c))}catch(s){o(s)}},n=c=>c.done?i(c.value):Promise.resolve(c.value).then(r,a);n((e=e.apply(g,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.needUpdatePosition=!0,this.posTimer=null,this.convexHullGroup={},this.getHoverRectID=i=>{var o,r;const a=this.getCoordinateUnderZoom(i),n=AxisUtils.default.changePointByZoom(a,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let c="",s=Number.MAX_SAFE_INTEGER;for(let u=0;u<this.annotations.length;u++){const h=this.annotations[u];switch(h.type){case"rect":{const l=h.annotation;if(RectUtils.isInRect(a,l,newScope,this.zoom)){const d=l.width*l.height;d<s&&(c=l.id,s=d)}break}case"polygon":{const l=h.annotation;if(PolygonUtils.isInPolygon(n,l.pointList)){const d=PolygonUtils.getPolygonArea(l.pointList);d<s&&(c=l.id,s=d)}break}}}return c};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.convexHullGroup=PolygonUtils.createConvexHullGroup(t.annotations),this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:a}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onRightClick(t){const e=this.getClickTargetId(t);!e||(this.needUpdatePosition=!1,this.posTimer&&clearTimeout(this.posTimer),this.emit("onRightClick",{event:t,targetId:e}),this.posTimer=setTimeout(()=>{this.needUpdatePosition=!0},1e3))}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.convexHullGroup=PolygonUtils.createConvexHullGroup(t),this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}setConfig(t){this.config=t}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,a=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";return!t||e===!0?{headerText:i,bottomText:o}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute),(t==null?void 0:t.subAttributeText)&&(i+=t==null?void 0:t.subAttributeText),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){if(!this.needUpdatePosition)return;const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/a*o.innerZoom,height:r.height/a*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:c=tool.ELineTypes.Line}=n,s=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos),u=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:c,strokeColor:r.stroke});let h=[];if(n.showKeyPoint?h=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,u):h=DrawUtils.drawPolygon(this.canvas,s,u),(n==null?void 0:n.showDirection)===!0&&((o=n==null?void 0:n.pointList)==null?void 0:o.length)>=2){let v=s[0],p=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(c===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=h[f],p=h[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,p,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:d,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(d&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),d,a),y){const v=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:v.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:v.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderPolygon(t){var e,i,o,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:u=tool.ELineTypes.Line}=s,h=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const f=rgba__default.default((r=(o=n==null?void 0:n.fill)!=null?o:n==null?void 0:n.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,h,{color:m,lineType:u})}const l=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:u,strokeColor:n.stroke});let d=[];if(s.showKeyPoint?d=DrawUtils.drawPolygonWithKeyPoint(this.canvas,h,l):d=DrawUtils.drawPolygon(this.canvas,h,l),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let f=h[0],m=MathUtils.default.getLineCenterPoint([h[0],h[1]]);if(u===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=d[x],m=d[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,h[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(h[0]),v,c),p){const f=h[h.length-2];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,c)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,a=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,c=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:u,bottomText:h}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:c,fillColor:n,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:u,bottomText:h})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},a=___default.default.pick(i,["stroke","thickness"]);o.forEach((n,c)=>{const s=__spreadValues(__spreadProps(__spreadValues({},a),{id:`${t.annotation.id}-${c}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:c}=CanvasUtils.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:c,points:i,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),DrawUtils.drawImg(this.canvas,c,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:c})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,a,n,c,s;const u=this.getSpecificStyle(e.annotation),h=this.getFontStyle(e.annotation,u);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:d=!1,isReference:y,hiddenRectSize:v=!1}=l,{zoom:p}=this,f=AxisUtils.default.changeRectByZoom(l,this.zoom,this.currentPos),{x:m,y:x,width:w,height:b}=f,P=rgba__default.default((o=(i=u==null?void 0:u.fill)!=null?i:u==null?void 0:u.stroke)!=null?o:DEFAULT_STROKE_COLOR),S=`rgba(${P[0]}, ${P[1]}, ${P[2]},${P[3]*.8})`;(l.id===this.mouseHoverID||u.fill)&&DrawUtils.drawRectWithFill(this.canvas,f,{color:S}),DrawUtils.drawRect(this.canvas,f,__spreadValues(__spreadProps(__spreadValues({},u),{hiddenText:!0}),this.getReferenceOptions(y))),(l==null?void 0:l.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:S,position:{x:m-16,y:x-16}});const{headerText:C,bottomText:T}=this.getRenderText(l,l==null?void 0:l.hiddenText);C&&DrawUtils.drawText(this.canvas,{x:m,y:x-6},C,__spreadValues({textMaxWidth:300},h));const I=`${Math.round(w/p)} * ${Math.round(b/p)}`,k=I.length*7;if(!d&&!v&&DrawUtils.drawText(this.canvas,{x:m+w-k,y:x+b+15},I,h),T){const R=20,E=Math.max(20,w-k);DrawUtils.drawText(this.canvas,{x:m,y:x+b+R},l.textAttribute,__spreadValues({textMaxWidth:E},h))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,d=AxisUtils.default.changePointByZoom(l,this.zoom,this.currentPos),y=(r=u.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,d,y,u);const{headerText:v,bottomText:p}=this.getRenderText(l,l==null?void 0:l.hiddenText);v&&DrawUtils.drawText(this.canvas,{x:d.x+y/2,y:d.y-y-4},v,__spreadValues({textAlign:"center"},h)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:d.x+y,y:d.y+y+24}),p,h);break}case"text":{const l=e.annotation,{text:d,x:y,y:v,textMaxWidth:p,color:f="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:x=25,font:w=tool.DEFAULT_FONT,position:b,offset:P}=l,S=10,C=10,T=AxisUtils.default.changePointByZoom({x:y,y:v},this.zoom,this.currentPos);P&&(T.x+=(a=P.x)!=null?a:0,T.y+=(n=P.y)!=null?n:0);const{width:I,height:k,fontHeight:R=0}=MathUtils.default.getTextArea(this.canvas,l.text,p,w,x);if(b==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:I+C*2,height:k+S*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),DrawUtils.drawText(this.canvas,{x:T.x+C,y:T.y+R+S},d,{color:f,lineHeight:x,font:w,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}getClickTargetId(t){const e=this.getCoordinateUnderZoom(t),i=AxisUtils.default.changePointByZoom(e,1/this.zoom);for(const o in this.convexHullGroup){if(!Object.prototype.hasOwnProperty.call(this.convexHullGroup,o))continue;const r=this.convexHullGroup[o].convexHull;if(PolygonUtils.isInPolygon(i,r))return o}}}module.exports=ViewOperation;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(g){return g&&typeof g=="object"&&"default"in g?g:{default:g}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,o)=>{var r=l=>{try{n(e.next(l))}catch(s){o(s)}},a=l=>{try{n(e.throw(l))}catch(s){o(s)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(r,a);n((e=e.apply(g,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.needUpdatePosition=!0,this.posTimer=null,this.convexHullGroup={},this.pointCloudBoxList=[],this.hiddenText=!1,this.getHoverRectID=i=>{var o,r;const a=this.getCoordinateUnderZoom(i),n=AxisUtils.default.changePointByZoom(a,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let l="",s=Number.MAX_SAFE_INTEGER;for(let d=0;d<this.annotations.length;d++){const c=this.annotations[d];switch(c.type){case"rect":{const h=c.annotation;if(RectUtils.isInRect(a,h,newScope,this.zoom)){const u=h.width*h.height;u<s&&(l=h.id,s=u)}break}case"polygon":{const h=c.annotation;if(PolygonUtils.isInPolygon(n,h.pointList)){const u=PolygonUtils.getPolygonArea(h.pointList);u<s&&(l=h.id,s=u)}break}}}return l};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.convexHullGroup=PolygonUtils.createConvexHullGroup(t.annotations),this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:a}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onRightClick(t){const e=this.getClickTargetId(t);!e||(this.needUpdatePosition=!1,this.posTimer&&clearTimeout(this.posTimer),this.emit("onRightClick",{event:t,targetId:e}),this.posTimer=setTimeout(()=>{this.needUpdatePosition=!0},1e3))}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.convexHullGroup=PolygonUtils.createConvexHullGroup(t),this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}setPointCloudBoxList(t){this.pointCloudBoxList=t}setHiddenText(t){this.hiddenText=t,this.render()}setConfig(t){this.config=t}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,a=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";return!t||e===!0?{headerText:i,bottomText:o}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute),(t==null?void 0:t.subAttributeText)&&(i+=t==null?void 0:t.subAttributeText),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){if(!this.needUpdatePosition)return;const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/a*o.innerZoom,height:r.height/a*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}renderAttribute(){___default.default.chunk(this.annotations,6).forEach(e=>{var i,o;const r=e.find(c=>c.type==="polygon");if(!r)return;const{fontStyle:a}=this.getRenderStyle(r),n=r.annotation,l=(i=this.pointCloudBoxList)==null?void 0:i.find(c=>c.id===n.id),s=this.hiddenText?"":l==null?void 0:l.attribute,d=AxisUtils.default.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);s&&DrawUtils.drawText(this.canvas,this.appendOffset(d[0]),s,a)})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:l=tool.ELineTypes.Line}=n,s=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos),d=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:l,strokeColor:r.stroke});let c=[];if(n.showKeyPoint?c=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,d):c=DrawUtils.drawPolygon(this.canvas,s,d),(n==null?void 0:n.showDirection)===!0&&((o=n==null?void 0:n.pointList)==null?void 0:o.length)>=2){let v=s[0],p=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(l===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=c[f],p=c[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,p,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:u,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),u,a),y){const v=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:v.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:v.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderPolygon(t){var e,i,o,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:l}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:d=tool.ELineTypes.Line}=s,c=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const f=rgba__default.default((r=(o=n==null?void 0:n.fill)!=null?o:n==null?void 0:n.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,c,{color:m,lineType:d})}const h=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:d,strokeColor:n.stroke});let u=[];if(s.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,c,h):u=DrawUtils.drawPolygon(this.canvas,c,h),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let f=c[0],m=MathUtils.default.getLineCenterPoint([c[0],c[1]]);if(d===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=u[x],m=u[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,c[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(c[0]),v,l),p){const f=c[c.length-2];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,l)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,a=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,l=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:d,bottomText:c}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:l,fillColor:n,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:d,bottomText:c})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},a=___default.default.pick(i,["stroke","thickness"]);o.forEach((n,l)=>{const s=__spreadValues(__spreadProps(__spreadValues({},a),{id:`${t.annotation.id}-${l}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:l}=CanvasUtils.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:l,points:i,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),DrawUtils.drawImg(this.canvas,l,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:l})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,a,n,l,s;const d=this.getSpecificStyle(e.annotation),c=this.getFontStyle(e.annotation,d);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:u=!1,isReference:y,hiddenRectSize:v=!1}=h,{zoom:p}=this,f=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:m,y:x,width:w,height:b}=f,P=rgba__default.default((o=(i=d==null?void 0:d.fill)!=null?i:d==null?void 0:d.stroke)!=null?o:DEFAULT_STROKE_COLOR),C=`rgba(${P[0]}, ${P[1]}, ${P[2]},${P[3]*.8})`;(h.id===this.mouseHoverID||d.fill)&&DrawUtils.drawRectWithFill(this.canvas,f,{color:C}),DrawUtils.drawRect(this.canvas,f,__spreadValues(__spreadProps(__spreadValues({},d),{hiddenText:!0}),this.getReferenceOptions(y))),(h==null?void 0:h.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:C,position:{x:m-16,y:x-16}});const{headerText:S,bottomText:T}=this.getRenderText(h,h==null?void 0:h.hiddenText);S&&DrawUtils.drawText(this.canvas,{x:m,y:x-6},S,__spreadValues({textMaxWidth:300},c));const k=`${Math.round(w/p)} * ${Math.round(b/p)}`,I=k.length*7;if(!u&&!v&&DrawUtils.drawText(this.canvas,{x:m+w-I,y:x+b+15},k,c),T){const R=20,E=Math.max(20,w-I);DrawUtils.drawText(this.canvas,{x:m,y:x+b+R},h.textAttribute,__spreadValues({textMaxWidth:E},c))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,u=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),y=(r=d.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,u,y,d);const{headerText:v,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);v&&DrawUtils.drawText(this.canvas,{x:u.x+y/2,y:u.y-y-4},v,__spreadValues({textAlign:"center"},c)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:u.x+y,y:u.y+y+24}),p,c);break}case"text":{const h=e.annotation,{text:u,x:y,y:v,textMaxWidth:p,color:f="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:x=25,font:w=tool.DEFAULT_FONT,position:b,offset:P}=h,C=10,S=10,T=AxisUtils.default.changePointByZoom({x:y,y:v},this.zoom,this.currentPos);P&&(T.x+=(a=P.x)!=null?a:0,T.y+=(n=P.y)!=null?n:0);const{width:k,height:I,fontHeight:R=0}=MathUtils.default.getTextArea(this.canvas,h.text,p,w,x);if(b==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:k+S*2,height:I+C*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),DrawUtils.drawText(this.canvas,{x:T.x+S,y:T.y+R+C},u,{color:f,lineHeight:x,font:w,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(l=e.annotation).renderEnhance)==null||s.call(l,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints(),this.renderAttribute()}catch(t){console.error("ViewOperation Render Error",t)}}getClickTargetId(t){const e=this.getCoordinateUnderZoom(t),i=AxisUtils.default.changePointByZoom(e,1/this.zoom);for(const o in this.convexHullGroup){if(!Object.prototype.hasOwnProperty.call(this.convexHullGroup,o))continue;const r=this.convexHullGroup[o].convexHull;if(PolygonUtils.isInPolygon(i,r))return o}}}module.exports=ViewOperation;
@@ -4,7 +4,7 @@
4
4
  * @author Ron <ron.f.luo@gmail.com>
5
5
  */
6
6
  import * as THREE from 'three';
7
- import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig, ICalib } from '@labelbee/lb-utils';
7
+ import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig, ICalib, IPointCloudBoxList } from '@labelbee/lb-utils';
8
8
  import { OrthographicCamera, PerspectiveCamera } from 'three';
9
9
  import { IPolygonPoint } from '@/types/tool/polygon';
10
10
  import { PCDLoader } from './PCDLoader';
@@ -29,6 +29,7 @@ interface IProps {
29
29
  config?: IPointCloudConfig;
30
30
  isSegment?: boolean;
31
31
  checkMode?: boolean;
32
+ hiddenText?: boolean;
32
33
  }
33
34
  interface IPipeTypes {
34
35
  setSelectedIDs: (ids?: string[] | string) => void;
@@ -87,8 +88,9 @@ export declare class PointCloud extends EventListener {
87
88
  private raycaster;
88
89
  private pointer;
89
90
  private pipe?;
91
+ private hiddenText;
90
92
  constructor({ container, noAppend, isOrthographicCamera, orthographicParams, backgroundColor, // GRAY_BACKGROUND
91
- config, isSegment, checkMode, }: IProps);
93
+ config, isSegment, checkMode, hiddenText, }: IProps);
92
94
  setHandlerPipe(pipe: IPipeTypes): void;
93
95
  initSegment(): void;
94
96
  orbiterStart(): void;
@@ -289,8 +291,38 @@ export declare class PointCloud extends EventListener {
289
291
  setShowDirection(showDirection: boolean): void;
290
292
  generateRange: (radius: number) => void;
291
293
  generateBoxArrow: ({ width }: IPointCloudBox) => THREE.ArrowHelper;
294
+ /**
295
+ * Universal generation of label information
296
+ * @param text generation text
297
+ * @param scaleFactor scale size
298
+ * @returns { sprite, canvasWidth, canvasHeight }
299
+ */
300
+ generateLabel: (text: string, scaleFactor: number) => {
301
+ sprite: THREE.Sprite;
302
+ canvasWidth: number;
303
+ canvasHeight: number;
304
+ };
305
+ /**
306
+ * Generate label information for ID
307
+ * @param boxParams
308
+ * @returns sprite
309
+ */
292
310
  generateBoxTrackID: (boxParams: IPointCloudBox) => THREE.Sprite | undefined;
311
+ /**
312
+ * Generate label information for secondary attributes
313
+ * @param boxParams
314
+ * @returns sprite
315
+ */
316
+ generateBoxAttributeLabel: (boxParams: IPointCloudBox) => THREE.Sprite | undefined;
317
+ /**
318
+ * Splicing sub attribute content
319
+ * @param boxParams
320
+ * @param config
321
+ * @returns
322
+ */
323
+ findSubAttributeLabel(boxParams: IPointCloudBox, config?: IPointCloudConfig): string;
293
324
  getTextCanvas(text: string): HTMLCanvasElement;
325
+ updateHiddenTextAndRender(hiddenText: boolean, pointCloudBoxList: IPointCloudBoxList): void;
294
326
  /**
295
327
  * Filter road points and noise in all directions
296
328
  * 1. The first 5% of the z-axis is used as the road coordinate
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 查看模式 - 支持简单数据注入查看
3
3
  */
4
- import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, TAnnotationViewPixelPoints, IBasicStyle, TAnnotationViewCuboid } from '@labelbee/lb-utils';
4
+ import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, TAnnotationViewPixelPoints, IBasicStyle, TAnnotationViewCuboid, IPointCloudBoxList } from '@labelbee/lb-utils';
5
5
  import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
6
6
  interface IViewOperationProps extends IBasicToolOperationProps {
7
7
  style: IBasicStyle;
@@ -30,6 +30,8 @@ export default class ViewOperation extends BasicToolOperation {
30
30
  private needUpdatePosition;
31
31
  private posTimer;
32
32
  private convexHullGroup;
33
+ private pointCloudBoxList?;
34
+ private hiddenText?;
33
35
  constructor(props: IViewOperationProps);
34
36
  clearConnectionPoints(): void;
35
37
  /**
@@ -54,6 +56,8 @@ export default class ViewOperation extends BasicToolOperation {
54
56
  onMouseMove(e: MouseEvent): void;
55
57
  getHoverRectID: (e: MouseEvent) => string | undefined;
56
58
  updateData(annotations: TAnnotationViewData[]): Promise<void>;
59
+ setPointCloudBoxList(pointCloudBoxList: IPointCloudBoxList): void;
60
+ setHiddenText(hiddenText: boolean): void;
57
61
  setConfig(config: {
58
62
  [a: string]: any;
59
63
  } | string): void;
@@ -96,6 +100,11 @@ export default class ViewOperation extends BasicToolOperation {
96
100
  */
97
101
  focusPositionByPointList(pointList: ICoordinate[]): void;
98
102
  renderConnectionPoints(): void;
103
+ /**
104
+ * Separate rendering of sub attribute content
105
+ * The principle is the same as other tools for rendering sub attribute content
106
+ */
107
+ renderAttribute(): void;
99
108
  getRenderStyle(annotation: TAnnotationViewData): {
100
109
  style: {
101
110
  radius: any;
@@ -1,4 +1,4 @@
1
- import*as s from"three";import{toolStyleConverter as L,PerspectiveShiftUtils as S,EPerspectiveView as b,PointCloudUtils as H,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import W from"../../_virtual/highlightWorker.js";import U from"../../_virtual/filterBoxWorker.js";import{isInPolygon as Z}from"../../utils/tool/polygonTool.js";import A from"../../utils/uuid.js";import j from"../../utils/MathUtils.js";import G from"../../utils/ImgUtils.js";import{PCDLoader as $}from"./PCDLoader.js";import{OrbitControls as Y}from"./OrbitControls.js";import{PointCloudCache as X}from"./cache.js";import{getCuboidFromPointCloudBox as D,getHighlightIndexByPoints as q,mergeHighlightList as K}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as Q}from"./segmentation.js";import J from"./store/index.js";import tt from"./render/index.js";import et from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var it=Object.defineProperty,rt=Object.defineProperties,nt=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,N=(C,t,e)=>t in C?it(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,P=(C,t)=>{for(var e in t||(t={}))ot.call(t,e)&&N(C,e,t[e]);if(_)for(var e of _(t))st.call(t,e)&&N(C,e,t[e]);return C},B=(C,t)=>rt(C,nt(t)),v=(C,t,e)=>new Promise((i,r)=>{var a=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(a,h);o((e=e.apply(C,t)).next())});const at=30,I=new W({type:"module"});class ht extends et{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#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.workerLoading=!1,this.raycaster=new s.Raycaster,this.pointer=new s.Vector2,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 u=(c=n.id)!=null?c:A();this.removeObjectByName(u,"sphere");const{radius:p,widthSegments:x,heightSegments:g}=O,{center:m}=n,f=new s.Group,y=new s.SphereGeometry(p,x,g),w=new s.MeshBasicMaterial({color:l}),M=new s.Mesh(y,w);M.position.set(m.x,m.y,m.z),f.add(M),f.name=`sphere${u}`,this.scene.add(f)},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 u=(c=n.id)!=null?c:A();this.removeObjectByName(u,"box");const{center:p,width:x,height:g,depth:m,rotation:f}=n,y=new s.Group,w=new s.BoxGeometry(x,g,m),M=new s.MeshBasicMaterial({color:"blue"}),z=new s.Mesh(w,M),E=new s.BoxHelper(z,l),F=this.generateBoxArrow(n),k=this.generateBoxTrackID(n);k&&y.add(k),y.add(E),y.add(F),p&&y.position.set(p.x,p.y,p.z),f&&y.rotation.set(0,0,f),y.name=`box${u}`;const V=new s.BoxGeometry(x,g,m),R=new s.MeshBasicMaterial({visible:!1}),T=new s.Mesh(V,R);T.userData={selectedID:u},y.add(T),this.scene.add(y)},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:`
1
+ import*as h from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as z,EPerspectiveView as C,PointCloudUtils as U,DEFAULT_SPHERE_PARAMS as L}from"@labelbee/lb-utils";import Z from"../../_virtual/highlightWorker.js";import G from"../../_virtual/filterBoxWorker.js";import{isInPolygon as $}from"../../utils/tool/polygonTool.js";import _ from"../../utils/uuid.js";import N from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as K}from"./PCDLoader.js";import{OrbitControls as X}from"./OrbitControls.js";import{PointCloudCache as q}from"./cache.js";import{getCuboidFromPointCloudBox as I,getHighlightIndexByPoints as Q,mergeHighlightList as J}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as tt}from"./segmentation.js";import et from"./store/index.js";import it from"./render/index.js";import rt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var nt=Object.defineProperty,ot=Object.defineProperties,st=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,F=(b,t,e)=>t in b?nt(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,v=(b,t)=>{for(var e in t||(t={}))at.call(t,e)&&F(b,e,t[e]);if(E)for(var e of E(t))ht.call(t,e)&&F(b,e,t[e]);return b},S=(b,t)=>ot(b,st(t)),B=(b,t,e)=>new Promise((i,r)=>{var a=d=>{try{s(e.next(d))}catch(p){r(p)}},c=d=>{try{s(e.throw(d))}catch(p){r(p)}},s=d=>d.done?i(d.value):Promise.resolve(d.value).then(a,c);s((e=e.apply(b,t)).next())});const ct=30,D=new Z({type:"module"});class lt extends rt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:c,isSegment:s,checkMode:d,hiddenText:p=!1}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new h.Raycaster,this.pointer=new h.Vector2,this.hiddenText=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,n="blue")=>{var l;const u=(l=o.id)!=null?l:_();this.removeObjectByName(u,"sphere");const{radius:x,widthSegments:g,heightSegments:y}=L,{center:m}=o,f=new h.Group,w=new h.SphereGeometry(x,g,y),M=new h.MeshBasicMaterial({color:n}),P=new h.Mesh(w,M);P.position.set(m.x,m.y,m.z),f.add(P),f.name=`sphere${u}`,this.scene.add(f)},this.generateSphere=o=>{const{fill:n}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,n),this.render()},this.generateSpheres=o=>{o.forEach(n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l)}),this.render()},this.addBoxToSense=(o,n=16777215)=>{var l;const u=(l=o.id)!=null?l:_();this.removeObjectByName(u,"box");const{center:x,width:g,height:y,depth:m,rotation:f}=o,w=new h.Group,M=new h.BoxGeometry(g,y,m),P=new h.MeshBasicMaterial({color:"blue"}),O=new h.Mesh(M,P),V=new h.BoxHelper(O,n),R=this.generateBoxArrow(o),T=this.generateBoxTrackID(o);T&&w.add(T);const k=this.generateBoxAttributeLabel(o);k&&w.add(k),w.add(V),w.add(R),x&&w.position.set(x.x,x.y,x.z),f&&w.rotation.set(0,0,f),w.name=`box${u}`;const H=new h.BoxGeometry(g,y,m),W=new h.MeshBasicMaterial({visible:!1}),A=new h.Mesh(H,W);A.userData={selectedID:u},w.add(A),this.scene.add(w)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const n=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,n)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,6 @@ import*as s from"three";import{toolStyleConverter as L,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=(...n)=>v(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:u,color:p}=yield this.cacheInstance.loadPCDFile(l),x=new s.BufferGeometry;x.setAttribute("position",new s.BufferAttribute(u,3)),this.isSegment||x.setAttribute("dimensions",new s.BufferAttribute(p,3)),this.initCloudData(u);const g=new s.Points(x);this.renderPointCloud(g,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>v(this,[n],function*({mappingImgList:l,points:c}){const u=m=>v(this,null,function*(){try{return yield G.load(m)}catch(f){return console.error("Error loading image:",f),null}}),p=l.length===0?[]:(yield Promise.all(l.map(m=>v(this,null,function*(){let f=yield u(m.url);return!f&&m.fallbackUrl&&(f=yield u(m.fallbackUrl)),f})))).filter(m=>m!==null),x=l.map((m,f)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?y:[];const w=q({points:c,calib:m.calib,width:p[f].width,height:p[f].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,w),w});return K(x)}),this.filterPreResult=(n,l,c)=>v(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),p=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(x=>{const g=c.map(m=>{const f=j.calculatePointsInsideBox({indexMap:p,polygon:D(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),y=f>=l.lowerLimitPointsNumInBox;return B(P({},m),{valid:y,count:f})});x(g)})}),this.loadPCDFileByBox=(n,l,c)=>v(this,null,function*(){const u=(g,m)=>v(this,null,function*(){const{width:f=0,height:y=0,depth:w=0}=c!=null?c:{},M=yield this.filterPointsByBox(B(P({},l),{width:l.width+f,height:l.height+y,depth:l.depth+w}),g,m);if(!M){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const z=new s.Points(M.geometry);z.name=this.pointCloudObjectName,this.scene.add(z),this.render()}),{points:p,color:x}=yield this.cacheInstance.loadPCDFile(n);u(p,x)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new s.Vector3(1,0,0),c=new s.Vector3(n/2,0,0),u=2,p=16776960,x=new s.ArrowHelper(l,c,u,p);return x.visible=this.showDirection,x},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new s.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new s.SpriteMaterial({map:l,depthWrite:!1}),u=new s.Sprite(c);return u.scale.set(5,5,5),u.position.set(-n.width/2,0,n.depth/2+.5),u},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 u=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(u*1.2,10):c.material.uniforms.pointSize.value=Math.max(u/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 s.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new s.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new s.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new s.Scene,this.controls=new Y(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new $,this.axesHelper=new s.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=X.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var l,c;const u=this.renderer.domElement.getBoundingClientRect(),p=n.originalEvent.clientX-u.left,x=n.originalEvent.clientY-u.top;this.pointer.x=p/u.width*2-1,this.pointer.y=-(x/u.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const g=[];this.scene.children.forEach(f=>{f instanceof s.Group&&f.children.forEach(y=>{y instanceof s.Mesh&&g.push(y)})});const m=this.raycaster.intersectObjects(g,!1);if(m.length>0){const f=m[0].object;(l=this.pipe)==null||l.setNeedUpdateCenter(!1),(c=this.pipe)==null||c.setSelectedIDs([f.userData.selectedID])}})}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new J(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 Q(P({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new tt(B(P({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return P({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new s.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:a,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,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 s.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 s.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return L.getColorFromConfig({attribute:t},B(P({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,a=10,h=e.x-i/2-a,o=e.x-i/2+a,d=e.y+r/2+a,n=e.y-r/2-a,l=100,c=-100,u=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:a,height:h,depth:o},e);return i?(this.updateCamera(i,r),new s.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new s.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 s.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new s.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,a,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=(a=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=D(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(u=>{const p=new U;p.postMessage(c),p.onmessage=x=>{const{color:g,position:m,num:f}=x.data,y=new s.BufferGeometry;y.setAttribute("position",new s.Float32BufferAttribute(m,3)),y.setAttribute("color",new s.Float32BufferAttribute(g,3)),y.computeBoundingSphere(),p.terminate(),u({geometry:y,num:f})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,a=at){let h=S.frontViewMatrix4(a);switch(r){case b.Front:break;case b.Back:h=S.backViewMatrix4(a);break;case b.Left:h=S.leftViewMatrix4(a);break;case b.Right:h=S.rightViewMatrix4(a);break;case b.Top:h=S.topViewMatrix4(a);break;case b.LFT:h=S.leftFrontTopViewMatrix4(a,i);break;case b.RBT:h=S.rightBackTopViewMatrix4(a,i);break}const o=this.createThreeMatrix4(h),d=new s.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new s.Matrix4().makeTranslation(t.x,t.y,t.z),l=new s.Matrix4().makeRotationZ(e);return new s.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 s.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new s.BufferGeometry().setFromPoints(i),a=new s.LineBasicMaterial({color:16711680}),h=new s.Line(r,a);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new s.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return v(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,I.postMessage(t),I.onmessage=r=>{e(r.data),this.workerLoading=!1},I.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return v(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:h}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((d,n)=>{if(window.Worker){const c=(e?[...e]:[]).map(m=>D(m)),u=this.getAllAttributeColor(c),p=o.geometry.attributes.position.array,x=o.geometry.attributes.dimensions.array,g={cuboidList:c,position:p,color:x,colorList:u,highlightIndex:i,modifiedBoxIds:a,resetAreas:h};this.handleWebworker(g).then(m=>{const{color:f}=m;let y=f;(a.length||h.length)&&(y=f.map((M,z)=>M===-1?x[z]:M));const w=new s.BufferAttribute(y,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==f.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,y),this.highlightPCDSrc=void 0,w.needsUpdate=!0,o.geometry.setAttribute("dimensions",w),o.geometry.attributes.dimensions.needsUpdate=!0,d(y),this.render()}).catch(m=>{n(m)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new s.Group;t.forEach(i=>{const{center:{x:r,y:a,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=L.getColorFromConfig({attribute:i.attribute},B(P({},this.config),{attributeConfigurable:!0}),{}),u=new s.BoxGeometry(o,d,n),p=new s.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});u.rotateZ(l),u.translate(r,a,h);const x=new s.Mesh(u,p);e.add(x);const g=new s.PlaneGeometry(n,d);g.rotateY(Math.PI/2),g.rotateZ(l);const m=new s.Vector3(o/2,0,0),f=new s.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);m.applyMatrix4(f),g.translate(r+m.x,a+m.y,h+m.z);const y=new s.MeshBasicMaterial({color:c,side:s.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new s.Mesh(g,y);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 s.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,u)=>c.z-u.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const a=.005,h=Math.floor(e.length*(1-a));e=e.slice(0,h),e.sort((c,u)=>c.x-u.x);const o=Math.floor(e.length*a),d=Math.floor(e.length*(1-a));e=e.slice(o,d),e.sort((c,u)=>c.y-u.y);const n=Math.floor(e.length*a),l=Math.floor(e.length*(1-a));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 u=r[c+1],p=j.getFootOfPerpendicular({x:d,y:n},l,u,!1,!0).length;(!i[c]||p<i[c].distance)&&(i[c]={distance:p,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],u=r[n+2];return H.getIntersectionBySlope({p1:a[n].point,line1:[l,c],p2:a[n+1].point,line2:[c,u]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,a,h;const o=this.scene.children.find(g=>g.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,u=[],p=[];const x=((h=(a=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array)||[];for(let g=0;g<x.length;g+=3){const m=x[g],f=x[g+1],y=x[g+2];Z({x:m,y:f},t)&&(y||y===0)&&p.push({x:m,y:f,z:y})}return p.length?(i&&(p=this.filterNoise(p),u=this.getFittedCoordinates(t,p)),p.sort((g,m)=>g.z-m.z),d=p[0].z-.01,n=p[p.length-1].z+.01,c=p.length,e&&(l=p.filter(({z:g})=>g>=e[0]&&g<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:u}):{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:u}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new s.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 s.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:o}=t,d={x:e+h/2,y:i+a/2,z:r-o/2},n={x:e+h/2,y:i+a/2,z:r+o/2},l={x:e-h/2,y:i+a/2,z:r+o/2},c={x:e-h/2,y:i+a/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:o}=t,d={x:e-h/2,y:i+a/2,z:r+o/2},n={x:e-h/2,y:i+a/2,z:r-o/2},l={x:e-h/2,y:i-a/2,z:r-o/2},c={x:e-h/2,y:i-a/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:o}=t,d={x:e+h/2,y:i+a/2,z:r+o/2},n={x:e+h/2,y:i-a/2,z:r+o/2},l={x:e-h/2,y:i-a/2,z:r+o/2},c={x:e-h/2,y:i+a/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,h=new s.Matrix4().makeTranslation(-e,-i,-r),o=new s.Matrix4().makeTranslation(e,i,r),d=new s.Matrix4().makeRotationZ(a);return new s.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:a}=t,h=new s.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new s.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new s.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/a;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:a,width:h*2,height:h*2,depth:h*2,rotation:0},d=new s.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new s.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new s.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),u=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},a=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(d=>new s.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:a,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new s.Matrix4().makeRotationZ(r.rotation),h=new s.Vector3(-t.x,0,0).applyMatrix4(a);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=B(P({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const a=new s.Matrix4().makeRotationZ(r.rotation),h=new s.Vector3(0,-t.x,0).applyMatrix4(a);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=B(P({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const h=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(m=>new s.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(h)),[d,n,l,c]=o,u=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),x=n.add(c).applyMatrix3(new s.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new s.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new s.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:B(P({},r),{center:{x:r.center.x-x.x,y:r.center.y-x.y,z:r.center.z-i},width:u,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,a=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);a.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new s.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ht as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...o)=>B(this,[...o],function*(n=this.currentPCDSrc,l){if(!n)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=n;const{points:u,color:x}=yield this.cacheInstance.loadPCDFile(n),g=new h.BufferGeometry;g.setAttribute("position",new h.BufferAttribute(u,3)),this.isSegment||g.setAttribute("dimensions",new h.BufferAttribute(x,3)),this.initCloudData(u);const y=new h.Points(g);this.renderPointCloud(y,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=o=>B(this,[o],function*({mappingImgList:n,points:l}){const u=m=>B(this,null,function*(){try{return yield Y.load(m)}catch(f){return console.error("Error loading image:",f),null}}),x=n.length===0?[]:(yield Promise.all(n.map(m=>B(this,null,function*(){let f=yield u(m.url);return!f&&m.fallbackUrl&&(f=yield u(m.fallbackUrl)),f})))).filter(m=>m!==null),g=n.map((m,f)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?w:[];const M=Q({points:l,calib:m.calib,width:x[f].width,height:x[f].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,M),M});return J(g)}),this.filterPreResult=(o,n,l)=>B(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(o),x=yield this.cacheInstance.loadIndexMap(o,u);return new Promise(g=>{const y=l.map(m=>{const f=N.calculatePointsInsideBox({indexMap:x,polygon:I(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),w=f>=n.lowerLimitPointsNumInBox;return S(v({},m),{valid:w,count:f})});g(y)})}),this.loadPCDFileByBox=(o,n,l)=>B(this,null,function*(){const u=(y,m)=>B(this,null,function*(){const{width:f=0,height:w=0,depth:M=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(v({},n),{width:n.width+f,height:n.height+w,depth:n.depth+M}),y,m);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const O=new h.Points(P.geometry);O.name=this.pointCloudObjectName,this.scene.add(O),this.render()}),{points:x,color:g}=yield this.cacheInstance.loadPCDFile(o);u(x,g)}),this.generateRange=o=>{const n=this.createRange(o);this.scene.add(n)},this.generateBoxArrow=({width:o})=>{const n=new h.Vector3(1,0,0),l=new h.Vector3(o/2,0,0),u=2,x=16776960,g=new h.ArrowHelper(n,l,u,x);return g.visible=this.showDirection,g},this.generateLabel=(o,n)=>{const l=this.getTextCanvas(o),u=new h.Texture(l);u.minFilter=h.LinearFilter,u.magFilter=h.LinearFilter,u.needsUpdate=!0;const x=l.width/window.devicePixelRatio,g=l.height/window.devicePixelRatio,y=new h.SpriteMaterial({map:u,depthWrite:!1}),m=new h.Sprite(y);return m.scale.set(x/n,g/n,1),{sprite:m,canvasWidth:x,canvasHeight:g}},this.generateBoxTrackID=o=>{if(!o.trackID)return;const{sprite:n}=this.generateLabel(o.trackID.toString(),50);return n.position.set(-o.width/2,0,o.depth/2+.5),n},this.generateBoxAttributeLabel=o=>{if(!o.attribute||this.hiddenText)return;const n=this.findSubAttributeLabel(o,this.config),l=n?`${o.attribute}
32
+ ${n}`:`${o.attribute}`,{sprite:u,canvasWidth:x,canvasHeight:g}=this.generateLabel(l,100);return u.position.set(-o.width/2,o.height/2-x/200,-o.depth/2-g/150),u},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:n})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const u=l.material.uniforms.pointSize.value;o?l.material.uniforms.pointSize.value=Math.min(u*1.2,10):l.material.uniforms.pointSize.value=Math.max(u/1.2,1),n&&(l.material.uniforms.pointSize.value=n,this.pointsMaterialSize=n),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new h.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=c,this.checkMode=d!=null?d:!1,this.hiddenText=p,i&&r?(this.isOrthographicCamera=!0,this.camera=new h.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new h.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new h.Scene,this.controls=new X(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new K,this.axesHelper=new h.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=q.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",o=>{var n,l;const u=this.renderer.domElement.getBoundingClientRect(),x=o.originalEvent.clientX-u.left,g=o.originalEvent.clientY-u.top;this.pointer.x=x/u.width*2-1,this.pointer.y=-(g/u.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const y=[];this.scene.children.forEach(f=>{f instanceof h.Group&&f.children.forEach(w=>{w instanceof h.Mesh&&y.push(w)})});const m=this.raycaster.intersectObjects(y,!1);if(m.length>0){const f=m[0].object;(n=this.pipe)==null||n.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs([f.userData.selectedID])}})}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new et(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new tt(v({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new it(S(v({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return v({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new h.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:a,near:c,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=c,this.camera.far=s,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new h.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new h.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return j.getColorFromConfig({attribute:t},S(v({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,a=10,c=e.x-i/2-a,s=e.x-i/2+a,d=e.y+r/2+a,p=e.y-r/2-a,o=100,n=-100,l=500/o;return{left:c,right:s,top:d,bottom:p,near:o,far:n,zoom:l}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:c,depth:s,rotation:d}=t,p=this.getCameraVector(r,d,{width:a,height:c,depth:s},e);return i?(this.updateCamera(i,r),new h.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=L,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new h.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new h.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new h.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,a,c;if(!e){const s=this.scene.getObjectByName(this.pointCloudObjectName);if(!s)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array}if(window.Worker){const{zMin:s,zMax:d,polygonPointList:p}=I(t),o=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:d,polygonPointList:p,color:i,position:o};return new Promise(l=>{const u=new G;u.postMessage(n),u.onmessage=x=>{const{color:g,position:y,num:m}=x.data,f=new h.BufferGeometry;f.setAttribute("position",new h.Float32BufferAttribute(y,3)),f.setAttribute("color",new h.Float32BufferAttribute(g,3)),f.computeBoundingSphere(),u.terminate(),l({geometry:f,num:m})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,a=ct){let c=z.frontViewMatrix4(a);switch(r){case C.Front:break;case C.Back:c=z.backViewMatrix4(a);break;case C.Left:c=z.leftViewMatrix4(a);break;case C.Right:c=z.rightViewMatrix4(a);break;case C.Top:c=z.topViewMatrix4(a);break;case C.LFT:c=z.leftFrontTopViewMatrix4(a,i);break;case C.RBT:c=z.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),d=new h.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new h.Matrix4().makeTranslation(t.x,t.y,t.z),o=new h.Matrix4().makeRotationZ(e);return new h.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(d).applyMatrix4(o).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new h.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new h.BufferGeometry().setFromPoints(i),a=new h.LineBasicMaterial({color:16711680}),c=new h.Line(r,a);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new h.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return B(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,D.postMessage(t),D.onmessage=r=>{e(r.data),this.workerLoading=!1},D.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return B(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:c}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((d,p)=>{if(window.Worker){const n=(e?[...e]:[]).map(y=>I(y)),l=this.getAllAttributeColor(n),u=s.geometry.attributes.position.array,x=s.geometry.attributes.dimensions.array,g={cuboidList:n,position:u,color:x,colorList:l,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(g).then(y=>{const{color:m}=y;let f=m;(a.length||c.length)&&(f=m.map((M,P)=>M===-1?x[P]:M));const w=new h.BufferAttribute(f,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==m.length){p(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,f),this.highlightPCDSrc=void 0,w.needsUpdate=!0,s.geometry.setAttribute("dimensions",w),s.geometry.attributes.dimensions.needsUpdate=!0,d(f),this.render()}).catch(y=>{p(y)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new h.Group;t.forEach(i=>{const{center:{x:r,y:a,z:c},width:s,height:d,depth:p,rotation:o}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},S(v({},this.config),{attributeConfigurable:!0}),{}),l=new h.BoxGeometry(s,d,p),u=new h.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});l.rotateZ(o),l.translate(r,a,c);const x=new h.Mesh(l,u);e.add(x);const g=new h.PlaneGeometry(p,d);g.rotateY(Math.PI/2),g.rotateZ(o);const y=new h.Vector3(s/2,0,0),m=new h.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(o);y.applyMatrix4(m),g.translate(r+y.x,a+y.y,c+y.z);const f=new h.MeshBasicMaterial({color:n,side:h.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new h.Mesh(g,f);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 h.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const a=Object.keys(t.subAttribute);return a.length===0||a.forEach(c=>{const s=i.find(n=>n.value===c);if(!s||!s.subSelected)return;const{key:d,subSelected:p}=s,o=p.find(n=>{var l;return n.value===((l=t.subAttribute)==null?void 0:l[c])});o&&(r&&(r+="\u3001"),r+=`${d}:${o.key}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const c=t.split(`
33
+ `),s=Math.max(...c.map(n=>i.measureText(n).width)),d=Math.ceil(s),p=a*1.5,o=p*c.length;e.width=d*r,e.height=o*r,e.style.width=`${d}px`,e.style.height=`${o}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.forEach((n,l)=>{i.fillText(n,0,l*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,l)=>n.z-l.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((n,l)=>n.x-l.x);const s=Math.floor(e.length*a),d=Math.floor(e.length*(1-a));e=e.slice(s,d),e.sort((n,l)=>n.y-l.y);const p=Math.floor(e.length*a),o=Math.floor(e.length*(1-a));return e=e.slice(p,o),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:p})=>{t.forEach((o,n)=>{const l=r[n+1],u=N.getFootOfPerpendicular({x:d,y:p},o,l,!1,!0).length;(!i[n]||u<i[n].distance)&&(i[n]={distance:u,point:{x:d,y:p}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],c=t.map((d,p)=>{const o=r[p],n=r[p+1],l=r[p+2];return U.getIntersectionBySlope({p1:a[p].point,line1:[o,n],p2:a[p+1].point,line2:[n,l]})});return c.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,a,c;const s=this.scene.children.find(g=>g.uuid===this.pointsUuid);let d=0,p=0,o=0,n=0,l=[],u=[];const x=((c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array)||[];for(let g=0;g<x.length;g+=3){const y=x[g],m=x[g+1],f=x[g+2];$({x:y,y:m},t)&&(f||f===0)&&u.push({x:y,y:m,z:f})}return u.length?(i&&(u=this.filterNoise(u),l=this.getFittedCoordinates(t,u)),u.sort((g,y)=>g.z-y.z),d=u[0].z-.01,p=u[u.length-1].z+.01,n=u.length,e&&(o=u.filter(({z:g})=>g>=e[0]&&g<=e[1]).length),{maxZ:p,minZ:d,count:o,zCount:n,fittedCoordinates:l}):{maxZ:p,minZ:d,count:o,zCount:n,fittedCoordinates:l}}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 h.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 h.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r-s/2},p={x:e+c/2,y:i+a/2,z:r+s/2},o={x:e-c/2,y:i+a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r-s/2};return[d,p,o,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e-c/2,y:i+a/2,z:r+s/2},p={x:e-c/2,y:i+a/2,z:r-s/2},o={x:e-c/2,y:i-a/2,z:r-s/2},n={x:e-c/2,y:i-a/2,z:r+s/2};return[d,p,o,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r+s/2},p={x:e+c/2,y:i-a/2,z:r+s/2},o={x:e-c/2,y:i-a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r+s/2};return[d,p,o,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new h.Matrix4().makeTranslation(-e,-i,-r),s=new h.Matrix4().makeTranslation(e,i,r),d=new h.Matrix4().makeRotationZ(a);return new h.Matrix4().multiply(s).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:a}=t,c=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new h.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const d=i.map(n=>new h.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,o=this.containerHeight/a;return{polygon2d:d,zoom:Math.min(p,o)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:c}=L,s={center:e,attribute:i,id:r,valid:a,width:c*2,height:c*2,depth:c*2,rotation:0},d=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new h.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const o=new h.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(c*2),l=this.containerHeight/(c*2);return{point2d:o,zoom:Math.min(n,l)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=L,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},a=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(d=>new h.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,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(c,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new h.Matrix4().makeRotationZ(r.rotation),c=new h.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=S(v({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const a=new h.Matrix4().makeRotationZ(r.rotation),c=new h.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=S(v({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const c=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(y=>new h.Vector3(y.x,y.y,y.z)).map(y=>y.applyMatrix4(c)),[d,p,o,n]=s,l=Math.max(Math.abs(d.x-o.x),Math.abs(d.x-p.x)),x=p.add(n).applyMatrix3(new h.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new h.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new h.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(v({},r),{center:{x:r.center.x-x.x,y:r.center.y-x.y,z:r.center.z-i},width:l,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,a=[],{count:c}=r;for(let s=0;s<c;s++){const d=r.getZ(s);a.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new h.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{lt as PointCloud};
@@ -1 +1 @@
1
- import{ImgPosUtils as W}from"@labelbee/lb-utils";import B from"lodash";import $ from"color-rgba";import c from"../../utils/tool/DrawUtils.js";import b from"../../utils/tool/AxisUtils.js";import G from"../../utils/tool/RectUtils.js";import D from"../../utils/tool/PolygonUtils.js";import O from"../../utils/MathUtils.js";import V from"../../utils/tool/RenderDomClass.js";import{ELineTypes as U,DEFAULT_FONT as K,SEGMENT_NUMBER as F}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as H,TEXT_ATTRIBUTE_OFFSET as E,DEFAULT_TEXT_SHADOW as X}from"../../constant/annotation.js";import q,{cropAndEnlarge as Y}from"../../utils/ImgUtils.js";import J from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as Q}from"./basicToolOperation.js";import{pointCloudLidar2image as tt}from"../pointCloud/matrix.js";var et=Object.defineProperty,ot=Object.defineProperties,it=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,Z=(x,t,e)=>t in x?et(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,p=(x,t)=>{for(var e in t||(t={}))nt.call(t,e)&&Z(x,e,t[e]);if(N)for(var e of N(t))st.call(t,e)&&Z(x,e,t[e]);return x},C=(x,t)=>ot(x,it(t)),rt=(x,t,e)=>new Promise((o,i)=>{var r=h=>{try{n(e.next(h))}catch(s){i(s)}},a=h=>{try{n(e.throw(h))}catch(s){i(s)}},n=h=>h.done?o(h.value):Promise.resolve(h.value).then(r,a);n((e=e.apply(x,t)).next())});const at=3,lt=3,z="#6371FF";class ct extends Q{constructor(t){super(C(p({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.needUpdatePosition=!0,this.posTimer=null,this.convexHullGroup={},this.getHoverRectID=o=>{var i,r;const a=this.getCoordinateUnderZoom(o),n=b.changePointByZoom(a,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let h="",s=Number.MAX_SAFE_INTEGER;for(let f=0;f<this.annotations.length;f++){const d=this.annotations[f];switch(d.type){case"rect":{const l=d.annotation;if(G.isInRect(a,l,at,this.zoom)){const u=l.width*l.height;u<s&&(h=l.id,s=u)}break}case"polygon":{const l=d.annotation;if(D.isInPolygon(n,l.pointList)){const u=D.getPolygonArea(l.pointList);u<s&&(h=l.id,s=u)}break}}}return h};var e;this.style=(e=t.style)!=null?e:{stroke:z,thickness:3},this.annotations=t.annotations,this.convexHullGroup=D.createConvexHullGroup(t.annotations),this.loading=!1,this.renderDomInstance=new V({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:a}=O.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const o=Y(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);q.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}onRightClick(t){const e=this.getClickTargetId(t);!e||(this.needUpdatePosition=!1,this.posTimer&&clearTimeout(this.posTimer),this.emit("onRightClick",{event:t,targetId:e}),this.posTimer=setTimeout(()=>{this.needUpdatePosition=!0},1e3))}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){return rt(this,null,function*(){if(!B.isEqual(this.annotations,t)&&(this.annotations=t,this.convexHullGroup=D.createConvexHullGroup(t),this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,o=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const i=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:o}),this.staticImgNode=i}})}setConfig(t){this.config=t}getSpecificStyle(t){const e=B.pick(t,["stroke","thickness","fill","radius"]),o=p(p({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,a=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return C(p({},X),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+H.offsetX,y:e+H.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),(t==null?void 0:t.subAttributeText)&&(o+=t==null?void 0:t.subAttributeText),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){if(!this.needUpdatePosition)return;const e=O.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=W.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(C(p({},r),{width:r.width/a*i.innerZoom,height:r.height/a*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=b.changePointByZoom(t,this.zoom,this.currentPos);c.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),c.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=U.Line}=n,s=b.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),f=C(p(p({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:r.stroke});let d=[];if(n.showKeyPoint?d=c.drawPolygonWithKeyPoint(this.canvas,s,f):d=c.drawPolygon(this.canvas,s,f),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let m=s[0],v=O.getLineCenterPoint([s[0],s[1]]);if(h===U.Curve){const g=Math.floor(F/2);m=d[g],v=d[g+1]}c.drawArrowByCanvas(this.canvas,m,v,{color:r.stroke,thickness:r.thickness}),c.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:u,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&c.drawText(this.canvas,this.appendOffset(s[0]),u,a),y){const m=s[s.length-1];c.drawText(this.canvas,this.appendOffset({x:m.x+E.x,y:m.y+E.y}),y,a)}}renderPolygon(t){var e,o,i,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:h}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:f=U.Line}=s,d=b.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=$((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:z),P=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;c.drawPolygonWithFill(this.canvas,d,{color:P,lineType:f})}const l=C(p(C(p({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:f,strokeColor:n.stroke});let u=[];if(s.showKeyPoint?u=c.drawPolygonWithKeyPoint(this.canvas,d,l):u=c.drawPolygon(this.canvas,d,l),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let g=d[0],P=O.getLineCenterPoint([d[0],d[1]]);if(f===U.Curve){const w=Math.floor(F/2);g=u[w],P=u[w+1]}c.drawArrowByCanvas(this.canvas,g,P,{color:n.stroke,thickness:n.thickness}),c.drawCircle(this.canvas,d[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:m,bottomText:v}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(m&&c.drawText(this.canvas,this.appendOffset(d[0]),m,h),v){const g=d[d.length-2];c.drawText(this.canvas,this.appendOffset({x:g.x+E.x,y:g.y+E.y}),v,h)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,a=$((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:z),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,h=i.stroke,s=b.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:f,bottomText:d}=this.getRenderText(r,r==null?void 0:r.hiddenText);c.drawCuboidWithText(this.canvas,s,{strokeColor:h,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:f,bottomText:d})}renderBox3d(t){var e;if(t.type!=="box3d")return;const o=t.annotation,{transferViewData:i}=(e=tt(o,o.calib))!=null?e:{};if(!i)return;const r={fill:"transparent"},a=B.pick(o,["stroke","thickness"]);i.forEach((n,h)=>{const s=p(C(p({},a),{id:`${t.annotation.id}-${h}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const o=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(o.length>0)){console.warn("Empty pixelPoints");return}const i=this.imgNode.src+o.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){c.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:h}=J.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(o==null?void 0:o.length)>0&&(c.drawPixel({canvas:h,points:o,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),c.drawImg(this.canvas,h,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:h})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,a,n,h,s;const f=this.getSpecificStyle(e.annotation),d=this.getFontStyle(e.annotation,f);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:u=!1,isReference:y,hiddenRectSize:m=!1}=l,{zoom:v}=this,g=b.changeRectByZoom(l,this.zoom,this.currentPos),{x:P,y:w,width:k,height:I}=g,T=$((i=(o=f==null?void 0:f.fill)!=null?o:f==null?void 0:f.stroke)!=null?i:z),S=`rgba(${T[0]}, ${T[1]}, ${T[2]},${T[3]*.8})`;(l.id===this.mouseHoverID||f.fill)&&c.drawRectWithFill(this.canvas,g,{color:S}),c.drawRect(this.canvas,g,p(C(p({},f),{hiddenText:!0}),this.getReferenceOptions(y))),(l==null?void 0:l.isHighlight)&&c.drawHighlightFlag({canvas:this.canvas,color:S,position:{x:P-16,y:w-16}});const{headerText:R,bottomText:_}=this.getRenderText(l,l==null?void 0:l.hiddenText);R&&c.drawText(this.canvas,{x:P,y:w-6},R,p({textMaxWidth:300},d));const A=`${Math.round(k/v)} * ${Math.round(I/v)}`,L=A.length*7;if(!u&&!m&&c.drawText(this.canvas,{x:P+k-L,y:w+I+15},A,d),_){const M=20,j=Math.max(20,k-L);c.drawText(this.canvas,{x:P,y:w+I+M},l.textAttribute,p({textMaxWidth:j},d))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,u=b.changePointByZoom(l,this.zoom,this.currentPos),y=(r=f.radius)!=null?r:lt;c.drawCircle(this.canvas,u,y,f);const{headerText:m,bottomText:v}=this.getRenderText(l,l==null?void 0:l.hiddenText);m&&c.drawText(this.canvas,{x:u.x+y/2,y:u.y-y-4},m,p({textAlign:"center"},d)),v&&c.drawText(this.canvas,this.appendOffset({x:u.x+y,y:u.y+y+24}),v,d);break}case"text":{const l=e.annotation,{text:u,x:y,y:m,textMaxWidth:v,color:g="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:w=25,font:k=K,position:I,offset:T}=l,S=10,R=10,_=b.changePointByZoom({x:y,y:m},this.zoom,this.currentPos);T&&(_.x+=(a=T.x)!=null?a:0,_.y+=(n=T.y)!=null?n:0);const{width:A,height:L,fontHeight:M=0}=O.getTextArea(this.canvas,l.text,v,k,w);if(I==="rt")break;c.drawRectWithFill(this.canvas,{x:_.x,y:_.y,width:A+R*2,height:L+S*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),c.drawText(this.canvas,{x:_.x+R,y:_.y+M+S},u,{color:g,lineHeight:w,font:k,textMaxWidth:v});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(h=e.annotation).renderEnhance)==null||s.call(h,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}getClickTargetId(t){const e=this.getCoordinateUnderZoom(t),o=b.changePointByZoom(e,1/this.zoom);for(const i in this.convexHullGroup){if(!Object.prototype.hasOwnProperty.call(this.convexHullGroup,i))continue;const r=this.convexHullGroup[i].convexHull;if(D.isInPolygon(o,r))return i}}}export{ct as default};
1
+ import{ImgPosUtils as W}from"@labelbee/lb-utils";import B from"lodash";import H from"color-rgba";import h from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import G from"../../utils/tool/RectUtils.js";import D from"../../utils/tool/PolygonUtils.js";import L from"../../utils/MathUtils.js";import V from"../../utils/tool/RenderDomClass.js";import{ELineTypes as E,DEFAULT_FONT as K,SEGMENT_NUMBER as $}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as F,TEXT_ATTRIBUTE_OFFSET as U,DEFAULT_TEXT_SHADOW as X}from"../../constant/annotation.js";import q,{cropAndEnlarge as Y}from"../../utils/ImgUtils.js";import J from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as Q}from"./basicToolOperation.js";import{pointCloudLidar2image as tt}from"../pointCloud/matrix.js";var et=Object.defineProperty,ot=Object.defineProperties,it=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,Z=(x,t,e)=>t in x?et(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,p=(x,t)=>{for(var e in t||(t={}))nt.call(t,e)&&Z(x,e,t[e]);if(N)for(var e of N(t))st.call(t,e)&&Z(x,e,t[e]);return x},_=(x,t)=>ot(x,it(t)),rt=(x,t,e)=>new Promise((o,i)=>{var r=l=>{try{n(e.next(l))}catch(s){i(s)}},a=l=>{try{n(e.throw(l))}catch(s){i(s)}},n=l=>l.done?o(l.value):Promise.resolve(l.value).then(r,a);n((e=e.apply(x,t)).next())});const at=3,lt=3,z="#6371FF";class ct extends Q{constructor(t){super(_(p({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.needUpdatePosition=!0,this.posTimer=null,this.convexHullGroup={},this.pointCloudBoxList=[],this.hiddenText=!1,this.getHoverRectID=o=>{var i,r;const a=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(a,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let l="",s=Number.MAX_SAFE_INTEGER;for(let u=0;u<this.annotations.length;u++){const c=this.annotations[u];switch(c.type){case"rect":{const d=c.annotation;if(G.isInRect(a,d,at,this.zoom)){const f=d.width*d.height;f<s&&(l=d.id,s=f)}break}case"polygon":{const d=c.annotation;if(D.isInPolygon(n,d.pointList)){const f=D.getPolygonArea(d.pointList);f<s&&(l=d.id,s=f)}break}}}return l};var e;this.style=(e=t.style)!=null?e:{stroke:z,thickness:3},this.annotations=t.annotations,this.convexHullGroup=D.createConvexHullGroup(t.annotations),this.loading=!1,this.renderDomInstance=new V({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:a}=L.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const o=Y(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);q.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}onRightClick(t){const e=this.getClickTargetId(t);!e||(this.needUpdatePosition=!1,this.posTimer&&clearTimeout(this.posTimer),this.emit("onRightClick",{event:t,targetId:e}),this.posTimer=setTimeout(()=>{this.needUpdatePosition=!0},1e3))}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){return rt(this,null,function*(){if(!B.isEqual(this.annotations,t)&&(this.annotations=t,this.convexHullGroup=D.createConvexHullGroup(t),this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,o=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const i=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:o}),this.staticImgNode=i}})}setPointCloudBoxList(t){this.pointCloudBoxList=t}setHiddenText(t){this.hiddenText=t,this.render()}setConfig(t){this.config=t}getSpecificStyle(t){const e=B.pick(t,["stroke","thickness","fill","radius"]),o=p(p({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,a=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(p({},X),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+F.offsetX,y:e+F.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),(t==null?void 0:t.subAttributeText)&&(o+=t==null?void 0:t.subAttributeText),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){if(!this.needUpdatePosition)return;const e=L.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=W.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(_(p({},r),{width:r.width/a*i.innerZoom,height:r.height/a*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=T.changePointByZoom(t,this.zoom,this.currentPos);h.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),h.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}renderAttribute(){B.chunk(this.annotations,6).forEach(e=>{var o,i;const r=e.find(c=>c.type==="polygon");if(!r)return;const{fontStyle:a}=this.getRenderStyle(r),n=r.annotation,l=(o=this.pointCloudBoxList)==null?void 0:o.find(c=>c.id===n.id),s=this.hiddenText?"":l==null?void 0:l.attribute,u=T.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos);s&&h.drawText(this.canvas,this.appendOffset(u[0]),s,a)})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:l=E.Line}=n,s=T.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),u=_(p(p({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:l,strokeColor:r.stroke});let c=[];if(n.showKeyPoint?c=h.drawPolygonWithKeyPoint(this.canvas,s,u):c=h.drawPolygon(this.canvas,s,u),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let v=s[0],m=L.getLineCenterPoint([s[0],s[1]]);if(l===E.Curve){const g=Math.floor($/2);v=c[g],m=c[g+1]}h.drawArrowByCanvas(this.canvas,v,m,{color:r.stroke,thickness:r.thickness}),h.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&h.drawText(this.canvas,this.appendOffset(s[0]),f,a),y){const v=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:v.x+U.x,y:v.y+U.y}),y,a)}}renderPolygon(t){var e,o,i,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:l}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:u=E.Line}=s,c=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=H((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:z),P=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;h.drawPolygonWithFill(this.canvas,c,{color:P,lineType:u})}const d=_(p(_(p({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:u,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=h.drawPolygonWithKeyPoint(this.canvas,c,d):f=h.drawPolygon(this.canvas,c,d),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let g=c[0],P=L.getLineCenterPoint([c[0],c[1]]);if(u===E.Curve){const w=Math.floor($/2);g=f[w],P=f[w+1]}h.drawArrowByCanvas(this.canvas,g,P,{color:n.stroke,thickness:n.thickness}),h.drawCircle(this.canvas,c[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:m}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&h.drawText(this.canvas,this.appendOffset(c[0]),v,l),m){const g=c[c.length-2];h.drawText(this.canvas,this.appendOffset({x:g.x+U.x,y:g.y+U.y}),m,l)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,a=H((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:z),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,l=i.stroke,s=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:u,bottomText:c}=this.getRenderText(r,r==null?void 0:r.hiddenText);h.drawCuboidWithText(this.canvas,s,{strokeColor:l,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:u,bottomText:c})}renderBox3d(t){var e;if(t.type!=="box3d")return;const o=t.annotation,{transferViewData:i}=(e=tt(o,o.calib))!=null?e:{};if(!i)return;const r={fill:"transparent"},a=B.pick(o,["stroke","thickness"]);i.forEach((n,l)=>{const s=p(_(p({},a),{id:`${t.annotation.id}-${l}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const o=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(o.length>0)){console.warn("Empty pixelPoints");return}const i=this.imgNode.src+o.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){h.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:l}=J.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(o==null?void 0:o.length)>0&&(h.drawPixel({canvas:l,points:o,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),h.drawImg(this.canvas,l,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:l})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,a,n,l,s;const u=this.getSpecificStyle(e.annotation),c=this.getFontStyle(e.annotation,u);switch(e.type){case"rect":{const d=e.annotation,{hiddenText:f=!1,isReference:y,hiddenRectSize:v=!1}=d,{zoom:m}=this,g=T.changeRectByZoom(d,this.zoom,this.currentPos),{x:P,y:w,width:k,height:S}=g,b=H((i=(o=u==null?void 0:u.fill)!=null?o:u==null?void 0:u.stroke)!=null?i:z),I=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;(d.id===this.mouseHoverID||u.fill)&&h.drawRectWithFill(this.canvas,g,{color:I}),h.drawRect(this.canvas,g,p(_(p({},u),{hiddenText:!0}),this.getReferenceOptions(y))),(d==null?void 0:d.isHighlight)&&h.drawHighlightFlag({canvas:this.canvas,color:I,position:{x:P-16,y:w-16}});const{headerText:R,bottomText:C}=this.getRenderText(d,d==null?void 0:d.hiddenText);R&&h.drawText(this.canvas,{x:P,y:w-6},R,p({textMaxWidth:300},c));const O=`${Math.round(k/m)} * ${Math.round(S/m)}`,A=O.length*7;if(!f&&!v&&h.drawText(this.canvas,{x:P+k-A,y:w+S+15},O,c),C){const M=20,j=Math.max(20,k-A);h.drawText(this.canvas,{x:P,y:w+S+M},d.textAttribute,p({textMaxWidth:j},c))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const d=e.annotation,f=T.changePointByZoom(d,this.zoom,this.currentPos),y=(r=u.radius)!=null?r:lt;h.drawCircle(this.canvas,f,y,u);const{headerText:v,bottomText:m}=this.getRenderText(d,d==null?void 0:d.hiddenText);v&&h.drawText(this.canvas,{x:f.x+y/2,y:f.y-y-4},v,p({textAlign:"center"},c)),m&&h.drawText(this.canvas,this.appendOffset({x:f.x+y,y:f.y+y+24}),m,c);break}case"text":{const d=e.annotation,{text:f,x:y,y:v,textMaxWidth:m,color:g="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:w=25,font:k=K,position:S,offset:b}=d,I=10,R=10,C=T.changePointByZoom({x:y,y:v},this.zoom,this.currentPos);b&&(C.x+=(a=b.x)!=null?a:0,C.y+=(n=b.y)!=null?n:0);const{width:O,height:A,fontHeight:M=0}=L.getTextArea(this.canvas,d.text,m,k,w);if(S==="rt")break;h.drawRectWithFill(this.canvas,{x:C.x,y:C.y,width:O+R*2,height:A+I*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),h.drawText(this.canvas,{x:C.x+R,y:C.y+M+I},f,{color:g,lineHeight:w,font:k,textMaxWidth:m});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(l=e.annotation).renderEnhance)==null||s.call(l,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints(),this.renderAttribute()}catch(t){console.error("ViewOperation Render Error",t)}}getClickTargetId(t){const e=this.getCoordinateUnderZoom(t),o=T.changePointByZoom(e,1/this.zoom);for(const i in this.convexHullGroup){if(!Object.prototype.hasOwnProperty.call(this.convexHullGroup,i))continue;const r=this.convexHullGroup[i].convexHull;if(D.isInPolygon(o,r))return i}}}export{ct as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.27.0-alpha.54",
3
+ "version": "1.27.0-alpha.55",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",