@labelbee/lb-annotation 1.20.0-alpha.1 → 1.20.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/pointCloud/index.js +1 -1
- package/dist/core/pointCloud/segmentation.js +1 -1
- package/dist/core/pointCloud/store/index.js +1 -1
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/dist/types/core/pointCloud/segmentation.d.ts +3 -0
- package/dist/types/utils/tool/DrawUtils.d.ts +3 -1
- package/dist/utils/tool/DrawUtils.js +3 -3
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/pointCloud/segmentation.js +1 -1
- package/es/core/pointCloud/store/index.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/utils/tool/DrawUtils.js +3 -3
- package/package.json +2 -2
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...s)=>__async(this,[...s],function*(a=this.currentPCDSrc,c){if(!a)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=a;const{points:d,color:p}=yield this.cacheInstance.loadPCDFile(a),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(p,3)),this.initCloudData(d);const u=new THREE__namespace.Points(m);this.renderPointCloud(u,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=s=>__async(this,[s],function*({mappingImgList:a,points:c}){const d=a.length===0?[]:yield Promise.all(a.map(u=>ImgUtils.default.load(u.url))),p=a.map((u,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:c,calib:u.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,x),x});return matrix.mergeHighlightList(p)}),this.loadPCDFileByBox=(s,a,c)=>__async(this,null,function*(){const d=(u,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=c!=null?c:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},a),{width:a.width+y,height:a.height+x,depth:a.depth+w}),u,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:p,color:m}=yield this.cacheInstance.loadPCDFile(s);d(p,m)}),this.generateRange=s=>{const a=this.createRange(s);this.scene.add(a)},this.generateBoxArrow=({width:s})=>{const a=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(s/2,0,0),d=2,p=16776960,m=new THREE__namespace.ArrowHelper(a,c,d,p);return m.visible=this.showDirection,m},this.generateBoxTrackID=s=>{if(!s.trackID)return;const a=new THREE__namespace.Texture(this.getTextCanvas(s.trackID.toString()));a.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:a,depthWrite:!1}),d=new THREE__namespace.Sprite(c);return d.scale.set(5,5,5),d.position.set(-s.width/2,0,s.depth/2+.5),d},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:a})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;s?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),a&&(c.material.uniforms.pointSize.value=a,this.pointsMaterialSize=a),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=h,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),n===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation({dom:this.container,store:this.store}),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:o,near:h,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=h,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,h=e.x-i/2-o,n=e.x-i/2+o,l=e.y+r/2+o,s=e.y-r/2-o,a=100,c=-100,d=500/a;return{left:h,right:n,top:l,bottom:s,near:a,far:c,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:h,depth:n,rotation:l}=t,s=this.getCameraVector(r,l,{width:o,height:h,depth:n},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,o,h;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array}if(window.Worker){const{zMin:n,zMax:l,polygonPointList:s}=matrix.getCuboidFromPointCloudBox(t),a=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:n,zMax:l,polygonPointList:s,color:i,position:a};return new Promise(d=>{const p=new filterBoxWorker;p.postMessage(c),p.onmessage=m=>{const{color:u,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(u,3)),x.computeBoundingSphere(),p.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,o=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(o);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(o);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(o);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(o);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(o);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(o,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),a=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(l).applyMatrix4(a).applyMatrix4(s)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),o=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,o);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(a=>matrix.getCuboidFromPointCloudBox(a)),l=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(s),highlightWorker.onmessage=a=>{const{color:c}=a.data,d=new THREE__namespace.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:o,z:h},width:n,height:l,depth:s,rotation:a}=i,{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(n,l,s),p=new THREE__namespace.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(a),d.translate(r,o,h);const m=new THREE__namespace.Mesh(d,p);e.add(m);const u=new THREE__namespace.PlaneGeometry(s,l);u.rotateY(Math.PI/2),u.rotateZ(a);const g=new THREE__namespace.Vector3(n/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(a);g.applyMatrix4(y),u.translate(r+g.x,o+g.y,h+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:c,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(u,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((c,d)=>c.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const o=.005,h=Math.floor(e.length*(1-o));e=e.slice(0,h),e.sort((c,d)=>c.x-d.x);const n=Math.floor(e.length*o),l=Math.floor(e.length*(1-o));e=e.slice(n,l),e.sort((c,d)=>c.y-d.y);const s=Math.floor(e.length*o),a=Math.floor(e.length*(1-o));return e=e.slice(s,a),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:l})=>{t.forEach((s,a)=>{const c=r[a+1],d=MathUtils.default.getFootOfPerpendicular({x:n,y:l},s,c,!1,!0).length;(!i[a]||d<i[a].distance)&&(i[a]={distance:d,point:{x:n,y:l}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,l)=>{const s=r[l],a=r[l+1],c=r[l+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:o[l].point,line1:[s,a],p2:o[l+1].point,line2:[a,c]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,h;const n=this.scene.children.find(u=>u.uuid===this.pointsUuid);let l=0,s=0,a=0,c=0,d=[],p=[];const m=((h=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array)||[];for(let u=0;u<m.length;u+=3){const g=m[u],y=m[u+1],x=m[u+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&p.push({x:g,y,z:x})}return p.length?(i&&(p=this.filterNoise(p),d=this.getFittedCoordinates(t,p)),p.sort((u,g)=>u.z-g.z),l=p[0].z-.01,s=p[p.length-1].z+.01,c=p.length,e&&(a=p.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:s,minZ:l,count:a,zCount:c,fittedCoordinates:d}):{maxZ:s,minZ:l,count:a,zCount:c,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e+h/2,y:i+o/2,z:r-n/2},s={x:e+h/2,y:i+o/2,z:r+n/2},a={x:e-h/2,y:i+o/2,z:r+n/2},c={x:e-h/2,y:i+o/2,z:r-n/2};return[l,s,a,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e-h/2,y:i+o/2,z:r+n/2},s={x:e-h/2,y:i+o/2,z:r-n/2},a={x:e-h/2,y:i-o/2,z:r-n/2},c={x:e-h/2,y:i-o/2,z:r+n/2};return[l,s,a,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e+h/2,y:i+o/2,z:r+n/2},s={x:e+h/2,y:i-o/2,z:r+n/2},a={x:e-h/2,y:i-o/2,z:r+n/2},c={x:e-h/2,y:i+o/2,z:r+n/2};return[l,s,a,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),n=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(o);return new THREE__namespace.Matrix4().multiply(n).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=i.map(c=>new THREE__namespace.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,a=this.containerHeight/o;return{polygon2d:l,zoom:Math.min(s,a)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,n={center:e,attribute:i,id:r,valid:o,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const a=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),d=this.containerHeight/(h*2);return{point2d:a,zoom:Math.min(c,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(h,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+h.x,y:n.center.y+h.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+h.x,y:n.center.y+h.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const h=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[l,s,a,c]=n,d=Math.max(Math.abs(l.x-a.x),Math.abs(l.x-s.x)),m=s.add(c).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,o=[],{count:h}=r;for(let n=0;n<h;n++){const l=r.getZ(n);o.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isInImage=matrix.isInImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point2dTo3D=matrix.point2dTo3D,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...s)=>__async(this,[...s],function*(a=this.currentPCDSrc,c){if(!a)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=a;const{points:d,color:p}=yield this.cacheInstance.loadPCDFile(a),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(p,3)),this.initCloudData(d);const u=new THREE__namespace.Points(m);this.renderPointCloud(u,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=s=>__async(this,[s],function*({mappingImgList:a,points:c}){const d=a.length===0?[]:yield Promise.all(a.map(u=>ImgUtils.default.load(u.url))),p=a.map((u,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:c,calib:u.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,x),x});return matrix.mergeHighlightList(p)}),this.loadPCDFileByBox=(s,a,c)=>__async(this,null,function*(){const d=(u,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=c!=null?c:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},a),{width:a.width+y,height:a.height+x,depth:a.depth+w}),u,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:p,color:m}=yield this.cacheInstance.loadPCDFile(s);d(p,m)}),this.generateRange=s=>{const a=this.createRange(s);this.scene.add(a)},this.generateBoxArrow=({width:s})=>{const a=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(s/2,0,0),d=2,p=16776960,m=new THREE__namespace.ArrowHelper(a,c,d,p);return m.visible=this.showDirection,m},this.generateBoxTrackID=s=>{if(!s.trackID)return;const a=new THREE__namespace.Texture(this.getTextCanvas(s.trackID.toString()));a.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:a,depthWrite:!1}),d=new THREE__namespace.Sprite(c);return d.scale.set(5,5,5),d.position.set(-s.width/2,0,s.depth/2+.5),d},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:a})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;s?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),a&&(c.material.uniforms.pointSize.value=a,this.pointsMaterialSize=a),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=h,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),n===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:o,near:h,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=h,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,h=e.x-i/2-o,n=e.x-i/2+o,l=e.y+r/2+o,s=e.y-r/2-o,a=100,c=-100,d=500/a;return{left:h,right:n,top:l,bottom:s,near:a,far:c,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:h,depth:n,rotation:l}=t,s=this.getCameraVector(r,l,{width:o,height:h,depth:n},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,o,h;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array}if(window.Worker){const{zMin:n,zMax:l,polygonPointList:s}=matrix.getCuboidFromPointCloudBox(t),a=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:n,zMax:l,polygonPointList:s,color:i,position:a};return new Promise(d=>{const p=new filterBoxWorker;p.postMessage(c),p.onmessage=m=>{const{color:u,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(u,3)),x.computeBoundingSphere(),p.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,o=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(o);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(o);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(o);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(o);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(o);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(o,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),a=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(l).applyMatrix4(a).applyMatrix4(s)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),o=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,o);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(a=>matrix.getCuboidFromPointCloudBox(a)),l=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(s),highlightWorker.onmessage=a=>{const{color:c}=a.data,d=new THREE__namespace.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:o,z:h},width:n,height:l,depth:s,rotation:a}=i,{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(n,l,s),p=new THREE__namespace.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(a),d.translate(r,o,h);const m=new THREE__namespace.Mesh(d,p);e.add(m);const u=new THREE__namespace.PlaneGeometry(s,l);u.rotateY(Math.PI/2),u.rotateZ(a);const g=new THREE__namespace.Vector3(n/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(a);g.applyMatrix4(y),u.translate(r+g.x,o+g.y,h+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:c,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(u,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((c,d)=>c.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const o=.005,h=Math.floor(e.length*(1-o));e=e.slice(0,h),e.sort((c,d)=>c.x-d.x);const n=Math.floor(e.length*o),l=Math.floor(e.length*(1-o));e=e.slice(n,l),e.sort((c,d)=>c.y-d.y);const s=Math.floor(e.length*o),a=Math.floor(e.length*(1-o));return e=e.slice(s,a),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:l})=>{t.forEach((s,a)=>{const c=r[a+1],d=MathUtils.default.getFootOfPerpendicular({x:n,y:l},s,c,!1,!0).length;(!i[a]||d<i[a].distance)&&(i[a]={distance:d,point:{x:n,y:l}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,l)=>{const s=r[l],a=r[l+1],c=r[l+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:o[l].point,line1:[s,a],p2:o[l+1].point,line2:[a,c]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,h;const n=this.scene.children.find(u=>u.uuid===this.pointsUuid);let l=0,s=0,a=0,c=0,d=[],p=[];const m=((h=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array)||[];for(let u=0;u<m.length;u+=3){const g=m[u],y=m[u+1],x=m[u+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&p.push({x:g,y,z:x})}return p.length?(i&&(p=this.filterNoise(p),d=this.getFittedCoordinates(t,p)),p.sort((u,g)=>u.z-g.z),l=p[0].z-.01,s=p[p.length-1].z+.01,c=p.length,e&&(a=p.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:s,minZ:l,count:a,zCount:c,fittedCoordinates:d}):{maxZ:s,minZ:l,count:a,zCount:c,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e+h/2,y:i+o/2,z:r-n/2},s={x:e+h/2,y:i+o/2,z:r+n/2},a={x:e-h/2,y:i+o/2,z:r+n/2},c={x:e-h/2,y:i+o/2,z:r-n/2};return[l,s,a,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e-h/2,y:i+o/2,z:r+n/2},s={x:e-h/2,y:i+o/2,z:r-n/2},a={x:e-h/2,y:i-o/2,z:r-n/2},c={x:e-h/2,y:i-o/2,z:r+n/2};return[l,s,a,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:n}=t,l={x:e+h/2,y:i+o/2,z:r+n/2},s={x:e+h/2,y:i-o/2,z:r+n/2},a={x:e-h/2,y:i-o/2,z:r+n/2},c={x:e-h/2,y:i+o/2,z:r+n/2};return[l,s,a,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),n=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(o);return new THREE__namespace.Matrix4().multiply(n).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=i.map(c=>new THREE__namespace.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,a=this.containerHeight/o;return{polygon2d:l,zoom:Math.min(s,a)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,n={center:e,attribute:i,id:r,valid:o,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const a=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),d=this.containerHeight/(h*2);return{point2d:a,zoom:Math.min(c,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(h,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+h.x,y:n.center.y+h.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+h.x,y:n.center.y+h.y,z:n.center.z-t.z},n=__spreadProps(__spreadValues({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const h=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[l,s,a,c]=n,d=Math.max(Math.abs(l.x-a.x),Math.abs(l.x-s.x)),m=s.add(c).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,o=[],{count:h}=r;for(let n=0;n<h;n++){const l=r.getZ(n);o.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isInImage=matrix.isInImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point2dTo3D=matrix.point2dTo3D,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),lassoSelector=require("./selector/lassoSelector.js"),circleSelector=require("./selector/circleSelector.js"),rectSelector=require("./selector/rectSelector.js");class PointCloudSegmentOperation{constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),lassoSelector=require("./selector/lassoSelector.js"),circleSelector=require("./selector/circleSelector.js"),rectSelector=require("./selector/rectSelector.js");class PointCloudSegmentOperation{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const o={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(o)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{var t;if([lbUtils.EPointCloudSegmentStatus.Ready,lbUtils.EPointCloudSegmentStatus.Check].includes(this.store.segmentStatus)){const{mouse:o,camera:i,raycaster:r}=this.store;r.setFromCamera(o,i);const s=r.intersectObjects(this.store.allSegmentPoints,!1)[0];this.emit("hoverSegmentInstance",{segmentData:this.store.segmentData.get((t=s==null?void 0:s.object)==null?void 0:t.name),currentSegmentStatus:this.store.segmentStatus}),s?this.store.highlightPoints(s.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new lassoSelector(this.store),this.rectSelector=new rectSelector(this.store),this.circleSelector=new circleSelector(this.store),this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this),this.emit=e.emit}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Rect(){this.currentTool=this.rectSelector,this.currentToolName="RectSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}exports.PointCloudSegmentOperation=PointCloudSegmentOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(h){if(h&&h.__esModule)return h;var t=Object.create(null);return h&&Object.keys(h).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return h[e]}})}}),t.default=h,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(h,t,e)=>t in h?__defProp(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,__spreadValues=(h,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(h,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(h,e,t[e]);return h},__spreadProps=(h,t)=>__defProps(h,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit:n,on:r,unbind:o,checkMode:m}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new THREE__namespace.Raycaster,this.mouse=new THREE__namespace.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=lbUtils.EPointCloudSegmentMode.Add,this.segmentCoverMode=lbUtils.EPointCloudSegmentCoverMode.Cover,this.segmentFocusMode=lbUtils.EPointCloudSegmentFocusMode.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=s=>{this.segmentData.forEach((c,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const d=s==null?void 0:s.filter(c=>{var u;return!this.hiddenAttributes.some(l=>l===c.attribute)&&c.id!==((u=this.cacheSegData)==null?void 0:u.id)});(d==null?void 0:d.length)!==0&&d.map(c=>(this.emit("addNewPointsCloud",c),c)),this.emit("reRender3d")},this.updateCoverPoints=(s=[])=>{this.segmentData.forEach((d,c)=>{var u;if(c!==((u=this.cacheSegData)==null?void 0:u.id)){const l=lbUtils.PointCloudUtils.splitPointsFromIndexes(d.indexes,s),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),d.indexes=l,d.points=new Float32Array(S);const p=this.scene.getObjectByName(c);p&&(p.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(new Float32Array(S),3)),p.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=n,this.on=r,this.unbind=o,this.checkMode=m,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSubAttribute=this.setSubAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return fsm.segmentStatus}get isReadyStatus(){return fsm.isReadyStatus}get isCheckStatus(){return fsm.isCheckStatus}get isEditStatus(){return fsm.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,subAttribute:i.subAttribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(o=>{n.push(i[o*3],i[o*3+1],i[o*3+2]),this.cloudData.set(`${i[o*3]}@${i[o*3+1]}@${i[o*3+2]}`,{visible:!0})});const r=__spreadProps(__spreadValues({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,r),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){fsm.statusToggle()}updateStatus2Edit(){fsm.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${DEFAULT_PREFIX}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===lbUtils.EPointCloudSegmentFocusMode.Focus&&this.emit("clearPointCloud"),t===lbUtils.EPointCloudSegmentFocusMode.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===lbUtils.EPointCloudSegmentFocusMode.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,i=this.originPoints;if(i){const a=i.length,n=[],r=[],o=[];for(let s=0;s<a;s+=3){const d=new THREE__namespace.Vector3(i[s],i[s+1],i[s+2]);d.project(this.camera);const c={x:0,y:0};if(c.x=Math.round(d.x*this.container.clientWidth/2+this.container.clientWidth/2),c.y=Math.round(-d.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(c,e)){const l=i[s],S=i[s+1],p=i[s+2],g=lbUtils.PointCloudUtils.getCloudKeys(l,S,p);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(g).visible=!1,n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3),this.cloudData.get(g).visible===!0&&r.push(s/3)),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(o.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const m=new Float32Array(n);this.updateStatusBySelector(m,r,o)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,r=a.length+t.length,o=new Float32Array(r);o.set(a,0),o.set(t,a.length);const m=[...new Set([...n,...e])];this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:o,coverPoints:m,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,subAttribute:{},points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(a,t),indexes:lbUtils.PointCloudUtils.splitPointsFromIndexes(n,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],n=t[i+1],r=t[i+2],o=lbUtils.PointCloudUtils.getCloudKeys(a,n,r),m=this.cloudData.get(o);Object.keys(e).forEach(s=>{m[s]=e[s]})}}clearStash(){if(this.isCheckStatus){this.resetSelectedSegmentStatus();return}if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let n=0;n<i.length;n++){const r=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[n],a[n+1],a[n+2]));r&&(r.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,fsm.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),fsm.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(i=>{i.attribute===t&&e.push(i.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=__spreadProps(__spreadValues({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}module.exports=PointCloudStore;
|
|
1
|
+
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(h){if(h&&h.__esModule)return h;var t=Object.create(null);return h&&Object.keys(h).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return h[e]}})}}),t.default=h,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(h,t,e)=>t in h?__defProp(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,__spreadValues=(h,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(h,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(h,e,t[e]);return h},__spreadProps=(h,t)=>__defProps(h,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit:n,on:r,unbind:o,checkMode:m}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new THREE__namespace.Raycaster,this.mouse=new THREE__namespace.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=lbUtils.EPointCloudSegmentMode.Add,this.segmentCoverMode=lbUtils.EPointCloudSegmentCoverMode.Cover,this.segmentFocusMode=lbUtils.EPointCloudSegmentFocusMode.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=s=>{this.segmentData.forEach((c,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const d=s==null?void 0:s.filter(c=>{var u;return!this.hiddenAttributes.some(l=>l===c.attribute)&&c.id!==((u=this.cacheSegData)==null?void 0:u.id)});(d==null?void 0:d.length)!==0&&d.map(c=>(this.emit("addNewPointsCloud",c),c)),this.emit("reRender3d")},this.updateCoverPoints=(s=[])=>{this.segmentData.forEach((d,c)=>{var u;if(c!==((u=this.cacheSegData)==null?void 0:u.id)){const l=lbUtils.PointCloudUtils.splitPointsFromIndexes(d.indexes,s),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),d.indexes=l,d.points=new Float32Array(S);const p=this.scene.getObjectByName(c);p&&(p.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(new Float32Array(S),3)),p.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=n,this.on=r,this.unbind=o,this.checkMode=m,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSubAttribute=this.setSubAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return fsm.segmentStatus}get isReadyStatus(){return fsm.isReadyStatus}get isCheckStatus(){return fsm.isCheckStatus}get isEditStatus(){return fsm.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,subAttribute:i.subAttribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(o=>{n.push(i[o*3],i[o*3+1],i[o*3+2]),this.cloudData.set(`${i[o*3]}@${i[o*3+1]}@${i[o*3+2]}`,{visible:!0})});const r=__spreadProps(__spreadValues({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,r),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){fsm.statusToggle()}updateStatus2Edit(){fsm.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${DEFAULT_PREFIX}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===lbUtils.EPointCloudSegmentFocusMode.Focus&&this.emit("clearPointCloud"),t===lbUtils.EPointCloudSegmentFocusMode.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===lbUtils.EPointCloudSegmentFocusMode.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,i=this.originPoints;if(i){const a=i.length,n=[],r=[],o=[];for(let s=0;s<a;s+=3){const d=new THREE__namespace.Vector3(i[s],i[s+1],i[s+2]);d.project(this.camera);const c={x:0,y:0};if(c.x=Math.round(d.x*this.container.clientWidth/2+this.container.clientWidth/2),c.y=Math.round(-d.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(c,e)){const l=i[s],S=i[s+1],p=i[s+2],g=lbUtils.PointCloudUtils.getCloudKeys(l,S,p);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(g).visible=!1,n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3),this.cloudData.get(g).visible===!0&&r.push(s/3)),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(o.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const m=new Float32Array(n);this.updateStatusBySelector(m,r,o)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,r=a.length+t.length,o=new Float32Array(r);o.set(a,0),o.set(t,a.length);const m=[...new Set([...n,...e])];this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:o,coverPoints:m,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,subAttribute:{},points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(a,t),indexes:lbUtils.PointCloudUtils.splitPointsFromIndexes(n,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],n=t[i+1],r=t[i+2],o=lbUtils.PointCloudUtils.getCloudKeys(a,n,r),m=this.cloudData.get(o);Object.keys(e).forEach(s=>{m[s]=e[s]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData()}this.resetSelectedSegmentStatus()}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let n=0;n<i.length;n++){const r=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[n],a[n+1],a[n+2]));r&&(r.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,fsm.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),fsm.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(i=>{i.attribute===t&&e.push(i.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=__spreadProps(__spreadValues({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}module.exports=PointCloudStore;
|
|
@@ -1 +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));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.getHoverRectID=i=>{var o,r;const l=this.getCoordinateUnderZoom(i),n=AxisUtils.default.changePointByZoom(l,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 h=0;h<this.annotations.length;h++){const a=this.annotations[h];switch(a.type){case"rect":{const d=a.annotation;if(RectUtils.isInRect(l,d,newScope,this.zoom)){const u=d.width*d.height;u<s&&(c=d.id,s=u)}break}case"polygon":{const d=a.annotation;if(PolygonUtils.isInPolygon(n,d.pointList)){const u=PolygonUtils.getPolygonArea(d.pointList);u<s&&(c=d.id,s=u)}break}}}return c};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=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:l}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:l},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()})}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){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=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}}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,l=(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 ${l}`})}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),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){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:l}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/l*o.innerZoom,height:r.height/l*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:l}=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),h=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:c,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,h):a=DrawUtils.drawPolygon(this.canvas,s,h),(n==null?void 0:n.showDirection)===!0&&((o=n==null?void 0:n.pointList)==null?void 0:o.length)>=2){let v=s[0],y=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(c===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=a[f],y=a[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,y,{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:p}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),u,l),p){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}),p,l)}}renderPolygon(t){var e,i,o,r,l;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:h=tool.ELineTypes.Line}=s,a=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,a,{color:m,lineType:h})}const d=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:h,strokeColor:n.stroke});let u=[];if(s.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,a,d):u=DrawUtils.drawPolygon(this.canvas,a,d),(s==null?void 0:s.showDirection)===!0&&((l=s==null?void 0:s.pointList)==null?void 0:l.length)>=2){let f=a[0],m=MathUtils.default.getLineCenterPoint([a[0],a[1]]);if(h===tool.ELineTypes.Curve){const P=Math.floor(tool.SEGMENT_NUMBER/2);f=u[P],m=u[P+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(a[0]),v,c),y){const f=a[a.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,c)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,l=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(${l[0]}, ${l[1]}, ${l[2]},${l[3]*.8})`,c=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:a}=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:h,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,{transferViewData:i}=matrix.pointCloudLidar2image(e,e.calib),o={fill:"transparent"},r=___default.default.pick(e,["stroke","thickness"]);i.forEach((l,n)=>{const c=__spreadValues(__spreadProps(__spreadValues({},r),{id:`${t.annotation.id}-${n}`,pointList:l.pointList}),o);switch(l.type){case"line":this.renderLine({type:"line",annotation:c});break;case"polygon":this.renderPolygon({type:"polygon",annotation:c});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,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const l={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:c}=CanvasUtils.createCanvas(l);n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:c,points:i,size:l}),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,l,n;const c=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,c);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:a=!1,isReference:d,hiddenRectSize:u=!1}=h,{zoom:p}=this,v=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:y,y:f,width:m,height:P}=v;if(h.id===this.mouseHoverID||c.fill){const x=rgba__default.default((o=(i=c==null?void 0:c.fill)!=null?i:c==null?void 0:c.stroke)!=null?o:DEFAULT_STROKE_COLOR),b=`rgba(${x[0]}, ${x[1]}, ${x[2]},${x[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,v,{color:b})}DrawUtils.drawRect(this.canvas,v,__spreadValues(__spreadProps(__spreadValues({},c),{hiddenText:!0}),this.getReferenceOptions(d)));const{headerText:w,bottomText:S}=this.getRenderText(h,h==null?void 0:h.hiddenText);w&&DrawUtils.drawText(this.canvas,{x:y,y:f-6},w,__spreadValues({textMaxWidth:300},s));const T=`${Math.round(m/p)} * ${Math.round(P/p)}`,I=T.length*7;if(!a&&!u&&DrawUtils.drawText(this.canvas,{x:y+m-I,y:f+P+15},T,s),S){const x=20,b=Math.max(20,m-I);DrawUtils.drawText(this.canvas,{x:y,y:f+P+x},h.textAttribute,__spreadValues({textMaxWidth:b},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,a=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),d=(r=c.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,a,d,c);const{headerText:u,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:a.x+d/2,y:a.y-d-4},u,__spreadValues({textAlign:"center"},s)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:a.x+d,y:a.y+d+24}),p,s);break}case"text":{const h=e.annotation,{text:a,x:d,y:u,textMaxWidth:p,color:v="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:m=tool.DEFAULT_FONT,position:P}=h,w=10,S=10,T=AxisUtils.default.changePointByZoom({x:d,y:u},this.zoom,this.currentPos),{width:I,height:x,fontHeight:b=0}=MathUtils.default.getTextArea(this.canvas,h.text,p,m,f);if(P==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:I+S*2,height:x+w*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:T.x+S,y:T.y+b+w},a,{color:v,lineHeight:f,font:m,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&&((n=(l=e.annotation).renderEnhance)==null||n.call(l,{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)}}}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));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.getHoverRectID=i=>{var o,r;const l=this.getCoordinateUnderZoom(i),n=AxisUtils.default.changePointByZoom(l,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 h=0;h<this.annotations.length;h++){const a=this.annotations[h];switch(a.type){case"rect":{const d=a.annotation;if(RectUtils.isInRect(l,d,newScope,this.zoom)){const u=d.width*d.height;u<s&&(c=d.id,s=u)}break}case"polygon":{const d=a.annotation;if(PolygonUtils.isInPolygon(n,d.pointList)){const u=PolygonUtils.getPolygonArea(d.pointList);u<s&&(c=d.id,s=u)}break}}}return c};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=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:l}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:l},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()})}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){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=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}}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,l=(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 ${l}`})}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),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){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:l}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/l*o.innerZoom,height:r.height/l*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:l}=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),h=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:c,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,h):a=DrawUtils.drawPolygon(this.canvas,s,h),(n==null?void 0:n.showDirection)===!0&&((o=n==null?void 0:n.pointList)==null?void 0:o.length)>=2){let v=s[0],y=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(c===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=a[f],y=a[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,y,{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:p}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),u,l),p){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}),p,l)}}renderPolygon(t){var e,i,o,r,l;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:h=tool.ELineTypes.Line}=s,a=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,a,{color:m,lineType:h})}const d=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:h,strokeColor:n.stroke});let u=[];if(s.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,a,d):u=DrawUtils.drawPolygon(this.canvas,a,d),(s==null?void 0:s.showDirection)===!0&&((l=s==null?void 0:s.pointList)==null?void 0:l.length)>=2){let f=a[0],m=MathUtils.default.getLineCenterPoint([a[0],a[1]]);if(h===tool.ELineTypes.Curve){const P=Math.floor(tool.SEGMENT_NUMBER/2);f=u[P],m=u[P+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(a[0]),v,c),y){const f=a[a.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,c)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,l=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(${l[0]}, ${l[1]}, ${l[2]},${l[3]*.8})`,c=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:a}=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:h,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,{transferViewData:i}=matrix.pointCloudLidar2image(e,e.calib),o={fill:"transparent"},r=___default.default.pick(e,["stroke","thickness"]);i.forEach((l,n)=>{const c=__spreadValues(__spreadProps(__spreadValues({},r),{id:`${t.annotation.id}-${n}`,pointList:l.pointList}),o);switch(l.type){case"line":this.renderLine({type:"line",annotation:c});break;case"polygon":this.renderPolygon({type:"polygon",annotation:c});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 l={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:c}=CanvasUtils.createCanvas(l);n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:c,points:i,size:l,defaultRGBA:t.defaultRGBA,pixelSize:13}),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,l,n;const c=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,c);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:a=!1,isReference:d,hiddenRectSize:u=!1}=h,{zoom:p}=this,v=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:y,y:f,width:m,height:P}=v;if(h.id===this.mouseHoverID||c.fill){const x=rgba__default.default((o=(i=c==null?void 0:c.fill)!=null?i:c==null?void 0:c.stroke)!=null?o:DEFAULT_STROKE_COLOR),b=`rgba(${x[0]}, ${x[1]}, ${x[2]},${x[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,v,{color:b})}DrawUtils.drawRect(this.canvas,v,__spreadValues(__spreadProps(__spreadValues({},c),{hiddenText:!0}),this.getReferenceOptions(d)));const{headerText:w,bottomText:S}=this.getRenderText(h,h==null?void 0:h.hiddenText);w&&DrawUtils.drawText(this.canvas,{x:y,y:f-6},w,__spreadValues({textMaxWidth:300},s));const T=`${Math.round(m/p)} * ${Math.round(P/p)}`,I=T.length*7;if(!a&&!u&&DrawUtils.drawText(this.canvas,{x:y+m-I,y:f+P+15},T,s),S){const x=20,b=Math.max(20,m-I);DrawUtils.drawText(this.canvas,{x:y,y:f+P+x},h.textAttribute,__spreadValues({textMaxWidth:b},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,a=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),d=(r=c.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,a,d,c);const{headerText:u,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:a.x+d/2,y:a.y-d-4},u,__spreadValues({textAlign:"center"},s)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:a.x+d,y:a.y+d+24}),p,s);break}case"text":{const h=e.annotation,{text:a,x:d,y:u,textMaxWidth:p,color:v="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:m=tool.DEFAULT_FONT,position:P}=h,w=10,S=10,T=AxisUtils.default.changePointByZoom({x:d,y:u},this.zoom,this.currentPos),{width:I,height:x,fontHeight:b=0}=MathUtils.default.getTextArea(this.canvas,h.text,p,m,f);if(P==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:I+S*2,height:x+w*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:T.x+S,y:T.y+b+w},a,{color:v,lineHeight:f,font:m,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&&((n=(l=e.annotation).renderEnhance)==null||n.call(l,{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)}}}module.exports=ViewOperation;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @author Laoluo <ron.f.luo@gmail.com>
|
|
4
4
|
* @createdate 2023-05-05
|
|
5
5
|
*/
|
|
6
|
+
import EventListener from '@/core/toolOperation/eventListener';
|
|
6
7
|
import LassoSelector from './selector/lassoSelector';
|
|
7
8
|
import PointCloudStore from './store';
|
|
8
9
|
import CircleSelector from './selector/circleSelector';
|
|
@@ -10,6 +11,7 @@ import RectSelector from './selector/rectSelector';
|
|
|
10
11
|
interface IProps {
|
|
11
12
|
dom: HTMLElement;
|
|
12
13
|
store: PointCloudStore;
|
|
14
|
+
emit: EventListener['emit'];
|
|
13
15
|
}
|
|
14
16
|
declare class PointCloudSegmentOperation {
|
|
15
17
|
private dom;
|
|
@@ -19,6 +21,7 @@ declare class PointCloudSegmentOperation {
|
|
|
19
21
|
lassoSelector: LassoSelector;
|
|
20
22
|
rectSelector: RectSelector;
|
|
21
23
|
circleSelector: CircleSelector;
|
|
24
|
+
private emit;
|
|
22
25
|
constructor(props: IProps);
|
|
23
26
|
getCoordinate(e: MouseEvent): {
|
|
24
27
|
x: number;
|
|
@@ -201,10 +201,12 @@ export default class DrawUtils {
|
|
|
201
201
|
* @param param0
|
|
202
202
|
* @returns
|
|
203
203
|
*/
|
|
204
|
-
static drawPixel({ canvas, points, size, }: {
|
|
204
|
+
static drawPixel({ canvas, points, size, defaultRGBA, pixelSize, }: {
|
|
205
205
|
canvas: HTMLCanvasElement;
|
|
206
206
|
points: IPixelPoints[];
|
|
207
207
|
size: ISize;
|
|
208
|
+
defaultRGBA?: string;
|
|
209
|
+
pixelSize?: number;
|
|
208
210
|
}): {
|
|
209
211
|
canvas: HTMLCanvasElement;
|
|
210
212
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var rgba=require("color-rgba"),lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),PolygonUtils=require("./PolygonUtils.js"),UnitUtils=require("./UnitUtils.js"),AxisUtils=require("./AxisUtils.js"),CuboidUtils=require("./CuboidUtils.js"),AttributeUtils=require("./AttributeUtils.js");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var 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=(r,t,i)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,__spreadValues=(r,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(r,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(r,i,t[i]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));const DEFAULT_ZOOM=1,DEFAULT_CURRENT_POS={x:0,y:0},DEFAULT_ROTATE=0,DEFAULT_COLOR="",_DrawUtils=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,thickness:s=1,lineCap:
|
|
2
|
-
`,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",lineType:
|
|
3
|
-
`);for(let
|
|
1
|
+
"use strict";var rgba=require("color-rgba"),lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),PolygonUtils=require("./PolygonUtils.js"),UnitUtils=require("./UnitUtils.js"),AxisUtils=require("./AxisUtils.js"),CuboidUtils=require("./CuboidUtils.js"),AttributeUtils=require("./AttributeUtils.js");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var 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=(r,t,i)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,__spreadValues=(r,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(r,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(r,i,t[i]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));const DEFAULT_ZOOM=1,DEFAULT_CURRENT_POS={x:0,y:0},DEFAULT_ROTATE=0,DEFAULT_COLOR="",_DrawUtils=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,thickness:s=1,lineCap:d="round",lineDash:n}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=d,n&&o.setLineDash(n),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",hiddenText:d=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),d===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,y=0,g=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+y},t.textAttribute,{textMaxWidth:g})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,d)=>`${s}${d.keyName}: ${d.value.join(" \u3001 ")}
|
|
2
|
+
`,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",lineType:d=tool.ELineTypes.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),d===tool.ELineTypes.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=PolygonUtils.createSmoothCurvePointsFromPointList([...t],tool.SEGMENT_NUMBER),a!==void 0&&a>-1&&(t=t.slice((tool.SEGMENT_NUMBER+1)*a,(tool.SEGMENT_NUMBER+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+2));const c=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&c.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),c.forEach(h=>{const u=t[h.i1],w=t[h.i2];e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(w.x,w.y),e.stroke()}),e.restore();const y=4,g=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,y+g,o),this.drawSpecialPoint(r,h,y,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:d=1,color:n=DEFAULT_COLOR,fill:a=DEFAULT_COLOR}=e,f=UnitUtils.deg2rad(l),c=UnitUtils.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=d,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),a&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR}=e;o.save();const s=UnitUtils.deg2rad(0),d=UnitUtils.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,d,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const d=i*1.5,n=d*Math.sqrt(3)/2,a=d/2;o.moveTo(l,s-d),o.lineTo(l-n,s+a),o.lineTo(l+n,s+a),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=tool.ELineTypes.Line}=i;return e===!0&&(t=[...t,t[0]]),o===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,__spreadProps(__spreadValues({},i),{lineType:tool.ELineTypes.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,lineType:l=tool.ELineTypes.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...d]=t;return e.moveTo(s.x,s.y),d.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:d,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:d,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,font:s=tool.DEFAULT_FONT,shadowColor:d="",shadowBlur:n=0,shadowOffsetX:a=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:y=0,offsetY:g=0,textAlign:h="start",lineHeight:u}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=d,o.shadowOffsetX=a,o.shadowOffsetY=f,o.shadowBlur=n,this.wrapText(r,`${i}`,t.x+y,t.y+g,c,u),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const d=t.split(`
|
|
3
|
+
`);for(let n=0;n<d.length;n++){const a=d[n].split("");let f="";for(let c=0;c<a.length;c++){const y=f+a[c],h=s.measureText(y).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=a[c],e+=l):f=y}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",theta:d=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(a+d)*Math.PI/180,c=(a-d)*Math.PI/180,y=n*Math.cos(f),g=n*Math.sin(f),h=n*Math.cos(c),u=n*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+y,i.y+g),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+u),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:d,fillColor:n}=i,a={color:s,thickness:d};if(e){const c=AxisUtils.default.transformPlain2PointList(e);_DrawUtils.drawPolygon(r,c,__spreadProps(__spreadValues({},a),{isClose:!0}));const y=CuboidUtils.getCuboidAllSideLine(t);y==null||y.forEach(g=>{_DrawUtils.drawLine(r,g.p1,g.p2,__spreadValues({},a))})}const f=AxisUtils.default.transformPlain2PointList(l);if(o&&e&&l){const c=CuboidUtils.getPointListsByDirection({direction:o,frontPoints:l,backPoints:e});c&&_DrawUtils.drawPolygonWithFill(r,c,{color:n})}_DrawUtils.drawPolygon(r,f,__spreadProps(__spreadValues({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:d,selectedID:n,headerText:a,bottomText:f}=e,{backPoints:c,frontPoints:y,textAttribute:g}=t,h=y.br.x-y.bl.x;_DrawUtils.drawCuboid(r,t,i);let u="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(u=`${t.order}`),t.attribute&&(u=`${u} ${AttributeUtils.default.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!d&&c&&u&&_DrawUtils.drawText(r,{x:c.tl.x,y:c.tl.y-5},a!=null?a:u,{color:o,textMaxWidth:300});const w=CuboidUtils.getCuboidTextAttributeOffset({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!d&&g&&t.id!==n){const x=Math.max(20,h*.8);_DrawUtils.drawText(r,{x:w.left,y:w.top},f!=null?f:g,{color:l,textMaxWidth:x})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const l=r.getContext("2d"),{width:s,height:d}=i,n=l.getImageData(0,0,s,d),[a,f,c,y]=rgba__default.default(e!=null?e:lbUtils.NULL_COLOR),g=u=>{n.data[u]=a,n.data[u+1]=f,n.data[u+2]=c,n.data[u+3]=Math.floor(255*y)},h=lbUtils.MathUtils.generateCoordinates(o);return t.forEach(u=>{for(const[w,x]of h){const C=(u.y+x)*(n.width*4)+(u.x+w)*4;g(C)}}),l.putImageData(n,0,0),{canvas:r}}};let DrawUtils=_DrawUtils;DrawUtils.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=DEFAULT_ZOOM,currentPos:l=DEFAULT_CURRENT_POS,rotate:s=DEFAULT_ROTATE,imgAttribute:d}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(d){const{contrast:n,saturation:a,brightness:f}=d;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()},module.exports=DrawUtils;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as C,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import F from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isInImage,lidar2image,mergeHighlightList,point2dTo3D,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,k=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,
|
|
1
|
+
import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as C,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import F from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isInImage,lidar2image,mergeHighlightList,point2dTo3D,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,k=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&k(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&k(w,e,t[e]);return w},S=(w,t)=>tt(w,et(t)),z=(w,t,e)=>new Promise((i,r)=>{var o=d=>{try{n(e.next(d))}catch(s){r(s)}},c=d=>{try{n(e.throw(d))}catch(s){r(s)}},n=d=>d.done?i(d.value):Promise.resolve(d.value).then(o,c);n((e=e.apply(w,t)).next())});const nt=30,L=new F({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:o="#4C4C4C",config:c,isSegment:n,checkMode:d}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(s,h="blue")=>{var l;const m=(l=s.id)!=null?l:I();this.removeObjectByName(m,"sphere");const{radius:p,widthSegments:f,heightSegments:u}=O,{center:g}=s,y=new a.Group,x=new a.SphereGeometry(p,f,u),M=new a.MeshBasicMaterial({color:h}),P=new a.Mesh(x,M);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=s=>{const{fill:h}=this.getColorFromConfig(s.attribute);this.addSphereToSense(s,h),this.render()},this.generateSpheres=s=>{s.forEach(h=>{const{fill:l}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(s,h=16777215)=>{var l;const m=(l=s.id)!=null?l:I();this.removeObjectByName(m,"box");const{center:p,width:f,height:u,depth:g,rotation:y}=s,x=new a.Group,M=new a.BoxGeometry(f,u,g),P=new a.MeshBasicMaterial({color:"blue"}),B=new a.Mesh(M,P),_=new a.BoxHelper(B,h),N=this.generateBoxArrow(s),D=this.generateBoxTrackID(s);D&&x.add(D),x.add(_),x.add(N),p&&x.position.set(p.x,p.y,p.z),y&&x.rotation.set(0,0,y),x.name=`box${m}`,this.scene.add(x)},this.applyCameraTarget=s=>{if(this.camera.type==="OrthographicCamera"&&s){const h=this.getOrthographicCameraTarget(s);this.updateCameraZoom(s.zoom),this.updateCamera(s.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
2
2
|
attribute vec3 dimensions;
|
|
3
3
|
varying vec3 vDimensions;
|
|
4
4
|
uniform float pointSize;
|
|
@@ -28,4 +28,4 @@ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...s)=>z(this,[...s],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(h),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(m);const p=new a.Points(f);this.renderPointCloud(p,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=s=>z(this,[s],function*({mappingImgList:h,points:l}){const m=h.length===0?[]:yield Promise.all(h.map(p=>W.load(p.url))),u=h.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=$({points:l,calib:p.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return Y(u)}),this.loadPCDFileByBox=(s,h,l)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:b=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(M({},h),{width:h.width+y,height:h.height+x,depth:h.depth+b}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:u,color:f}=yield this.cacheInstance.loadPCDFile(s);m(u,f)}),this.generateRange=s=>{const h=this.createRange(s);this.scene.add(h)},this.generateBoxArrow=({width:s})=>{const h=new a.Vector3(1,0,0),l=new a.Vector3(s/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(h,l,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=s=>{if(!s.trackID)return;const h=new a.Texture(this.getTextCanvas(s.trackID.toString()));h.needsUpdate=!0;const l=new a.SpriteMaterial({map:h,depthWrite:!1}),m=new a.Sprite(l);return m.scale.set(5,5,5),m.position.set(-s.width/2,0,s.depth/2+.5),m},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const m=l.material.uniforms.pointSize.value;s?l.material.uniforms.pointSize.value=Math.min(m*1.2,10):l.material.uniforms.pointSize.value=Math.max(m/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=c,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),n===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new X({dom:this.container,store:this.store}),this.pointCloudRender=new K(S(M({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return M({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:o,near:c,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=c,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(M({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,c=e.x-i/2-o,n=e.x-i/2+o,d=e.y+r/2+o,s=e.y-r/2-o,h=100,l=-100,m=500/h;return{left:c,right:n,top:d,bottom:s,near:h,far:l,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:c,depth:n,rotation:d}=t,s=this.getCameraVector(r,d,{width:o,height:c,depth:n},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,o,c;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array}if(window.Worker){const{zMin:n,zMax:d,polygonPointList:s}=A(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:n,zMax:d,polygonPointList:s,color:i,position:h};return new Promise(m=>{const u=new V;u.postMessage(l),u.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,o=nt){let c=v.frontViewMatrix4(o);switch(r){case C.Front:break;case C.Back:c=v.backViewMatrix4(o);break;case C.Left:c=v.leftViewMatrix4(o);break;case C.Right:c=v.rightViewMatrix4(o);break;case C.Top:c=v.topViewMatrix4(o);break;case C.LFT:c=v.leftFrontTopViewMatrix4(o,i);break;case C.RBT:c=v.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(c),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new a.Matrix4().makeTranslation(t.x,t.y,t.z),h=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(d).applyMatrix4(h).applyMatrix4(s)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),o=new a.LineBasicMaterial({color:16711680}),c=new a.Line(r,o);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(h=>A(h)),d=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(s),L.onmessage=h=>{const{color:l}=h.data,m=new a.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==l.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(l),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:o,z:c},width:n,height:d,depth:s,rotation:h}=i,{fill:l}=T.getColorFromConfig({attribute:i.attribute},S(M({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(n,d,s),u=new a.MeshBasicMaterial({color:l,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(h),m.translate(r,o,c);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(s,d);p.rotateY(Math.PI/2),p.rotateZ(h);const g=new a.Vector3(n/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(h);g.applyMatrix4(y),p.translate(r+g.x,o+g.y,c+g.z);const x=new a.MeshBasicMaterial({color:l,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),b=new a.Mesh(p,x);e.add(b)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((l,m)=>l.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:l})=>l>r.z+.1);const o=.005,c=Math.floor(e.length*(1-o));e=e.slice(0,c),e.sort((l,m)=>l.x-m.x);const n=Math.floor(e.length*o),d=Math.floor(e.length*(1-o));e=e.slice(n,d),e.sort((l,m)=>l.y-m.y);const s=Math.floor(e.length*o),h=Math.floor(e.length*(1-o));return e=e.slice(s,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:d})=>{t.forEach((s,h)=>{const l=r[h+1],m=H.getFootOfPerpendicular({x:n,y:d},s,l,!1,!0).length;(!i[h]||m<i[h].distance)&&(i[h]={distance:m,point:{x:n,y:d}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,d)=>{const s=r[d],h=r[d+1],l=r[d+2];return E.getIntersectionBySlope({p1:o[d].point,line1:[s,h],p2:o[d+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,c;const n=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,s=0,h=0,l=0,m=[],u=[];const f=((c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];R({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),m=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),d=u[0].z-.01,s=u[u.length-1].z+.01,l=u.length,e&&(h=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:m}):{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r-n/2},s={x:e+c/2,y:i+o/2,z:r+n/2},h={x:e-c/2,y:i+o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r-n/2};return[d,s,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e-c/2,y:i+o/2,z:r+n/2},s={x:e-c/2,y:i+o/2,z:r-n/2},h={x:e-c/2,y:i-o/2,z:r-n/2},l={x:e-c/2,y:i-o/2,z:r+n/2};return[d,s,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r+n/2},s={x:e+c/2,y:i-o/2,z:r+n/2},h={x:e-c/2,y:i-o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r+n/2};return[d,s,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,c=new a.Matrix4().makeTranslation(-e,-i,-r),n=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(o);return new a.Matrix4().multiply(n).multiply(d).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const d=i.map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,h=this.containerHeight/o;return{polygon2d:d,zoom:Math.min(s,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:c}=O,n={center:e,attribute:i,id:r,valid:o,width:c*2,height:c*2,depth:c*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new a.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const h=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(c*2),m=this.containerHeight/(c*2);return{point2d:h,zoom:Math.min(l,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),c=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(c,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(M({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(M({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const c=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(c)),[d,s,h,l]=n,m=Math.max(Math.abs(d.x-h.x),Math.abs(d.x-s.x)),f=s.add(l).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(M({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,o=[],{count:c}=r;for(let n=0;n<c;n++){const d=r.getZ(n);o.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...s)=>z(this,[...s],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:m,color:p}=yield this.cacheInstance.loadPCDFile(h),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(p,3)),this.initCloudData(m);const u=new a.Points(f);this.renderPointCloud(u,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=s=>z(this,[s],function*({mappingImgList:h,points:l}){const m=h.length===0?[]:yield Promise.all(h.map(u=>W.load(u.url))),p=h.map((u,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?y:[];const x=$({points:l,calib:u.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,x),x});return Y(p)}),this.loadPCDFileByBox=(s,h,l)=>z(this,null,function*(){const m=(u,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(b({},h),{width:h.width+y,height:h.height+x,depth:h.depth+M}),u,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:p,color:f}=yield this.cacheInstance.loadPCDFile(s);m(p,f)}),this.generateRange=s=>{const h=this.createRange(s);this.scene.add(h)},this.generateBoxArrow=({width:s})=>{const h=new a.Vector3(1,0,0),l=new a.Vector3(s/2,0,0),m=2,p=16776960,f=new a.ArrowHelper(h,l,m,p);return f.visible=this.showDirection,f},this.generateBoxTrackID=s=>{if(!s.trackID)return;const h=new a.Texture(this.getTextCanvas(s.trackID.toString()));h.needsUpdate=!0;const l=new a.SpriteMaterial({map:h,depthWrite:!1}),m=new a.Sprite(l);return m.scale.set(5,5,5),m.position.set(-s.width/2,0,s.depth/2+.5),m},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const m=l.material.uniforms.pointSize.value;s?l.material.uniforms.pointSize.value=Math.min(m*1.2,10):l.material.uniforms.pointSize.value=Math.max(m/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=c,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,n?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),n===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new X(b({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(S(b({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return b({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:o,near:c,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=c,this.camera.far=n,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(b({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,c=e.x-i/2-o,n=e.x-i/2+o,d=e.y+r/2+o,s=e.y-r/2-o,h=100,l=-100,m=500/h;return{left:c,right:n,top:d,bottom:s,near:h,far:l,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:c,depth:n,rotation:d}=t,s=this.getCameraVector(r,d,{width:o,height:c,depth:n},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,o,c;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array}if(window.Worker){const{zMin:n,zMax:d,polygonPointList:s}=A(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:n,zMax:d,polygonPointList:s,color:i,position:h};return new Promise(m=>{const p=new V;p.postMessage(l),p.onmessage=f=>{const{color:u,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(u,3)),x.computeBoundingSphere(),p.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,o=nt){let c=v.frontViewMatrix4(o);switch(r){case C.Front:break;case C.Back:c=v.backViewMatrix4(o);break;case C.Left:c=v.leftViewMatrix4(o);break;case C.Right:c=v.rightViewMatrix4(o);break;case C.Top:c=v.topViewMatrix4(o);break;case C.LFT:c=v.leftFrontTopViewMatrix4(o,i);break;case C.RBT:c=v.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(c),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new a.Matrix4().makeTranslation(t.x,t.y,t.z),h=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(d).applyMatrix4(h).applyMatrix4(s)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),o=new a.LineBasicMaterial({color:16711680}),c=new a.Line(r,o);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(h=>A(h)),d=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(s),L.onmessage=h=>{const{color:l}=h.data,m=new a.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==l.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(l),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:o,z:c},width:n,height:d,depth:s,rotation:h}=i,{fill:l}=T.getColorFromConfig({attribute:i.attribute},S(b({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(n,d,s),p=new a.MeshBasicMaterial({color:l,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(h),m.translate(r,o,c);const f=new a.Mesh(m,p);e.add(f);const u=new a.PlaneGeometry(s,d);u.rotateY(Math.PI/2),u.rotateZ(h);const g=new a.Vector3(n/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(h);g.applyMatrix4(y),u.translate(r+g.x,o+g.y,c+g.z);const x=new a.MeshBasicMaterial({color:l,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(u,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((l,m)=>l.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:l})=>l>r.z+.1);const o=.005,c=Math.floor(e.length*(1-o));e=e.slice(0,c),e.sort((l,m)=>l.x-m.x);const n=Math.floor(e.length*o),d=Math.floor(e.length*(1-o));e=e.slice(n,d),e.sort((l,m)=>l.y-m.y);const s=Math.floor(e.length*o),h=Math.floor(e.length*(1-o));return e=e.slice(s,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:d})=>{t.forEach((s,h)=>{const l=r[h+1],m=H.getFootOfPerpendicular({x:n,y:d},s,l,!1,!0).length;(!i[h]||m<i[h].distance)&&(i[h]={distance:m,point:{x:n,y:d}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,d)=>{const s=r[d],h=r[d+1],l=r[d+2];return E.getIntersectionBySlope({p1:o[d].point,line1:[s,h],p2:o[d+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,c;const n=this.scene.children.find(u=>u.uuid===this.pointsUuid);let d=0,s=0,h=0,l=0,m=[],p=[];const f=((c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array)||[];for(let u=0;u<f.length;u+=3){const g=f[u],y=f[u+1],x=f[u+2];R({x:g,y},t)&&(x||x===0)&&p.push({x:g,y,z:x})}return p.length?(i&&(p=this.filterNoise(p),m=this.getFittedCoordinates(t,p)),p.sort((u,g)=>u.z-g.z),d=p[0].z-.01,s=p[p.length-1].z+.01,l=p.length,e&&(h=p.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:m}):{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r-n/2},s={x:e+c/2,y:i+o/2,z:r+n/2},h={x:e-c/2,y:i+o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r-n/2};return[d,s,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e-c/2,y:i+o/2,z:r+n/2},s={x:e-c/2,y:i+o/2,z:r-n/2},h={x:e-c/2,y:i-o/2,z:r-n/2},l={x:e-c/2,y:i-o/2,z:r+n/2};return[d,s,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r+n/2},s={x:e+c/2,y:i-o/2,z:r+n/2},h={x:e-c/2,y:i-o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r+n/2};return[d,s,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,c=new a.Matrix4().makeTranslation(-e,-i,-r),n=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(o);return new a.Matrix4().multiply(n).multiply(d).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const d=i.map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,h=this.containerHeight/o;return{polygon2d:d,zoom:Math.min(s,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:c}=O,n={center:e,attribute:i,id:r,valid:o,width:c*2,height:c*2,depth:c*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new a.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const h=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(c*2),m=this.containerHeight/(c*2);return{point2d:h,zoom:Math.min(l,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),c=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(c,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(b({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(b({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const c=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(c)),[d,s,h,l]=n,m=Math.max(Math.abs(d.x-h.x),Math.abs(d.x-s.x)),f=s.add(l).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(b({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,o=[],{count:c}=r;for(let n=0;n<c;n++){const d=r.getZ(n);o.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EPointCloudSegmentStatus as i}from"@labelbee/lb-utils";import c from"./selector/lassoSelector.js";import
|
|
1
|
+
import{EPointCloudSegmentStatus as i}from"@labelbee/lb-utils";import c from"./selector/lassoSelector.js";import h from"./selector/circleSelector.js";import l from"./selector/rectSelector.js";class a{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const o={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(o)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{var t;if([i.Ready,i.Check].includes(this.store.segmentStatus)){const{mouse:o,camera:n,raycaster:r}=this.store;r.setFromCamera(o,n);const s=r.intersectObjects(this.store.allSegmentPoints,!1)[0];this.emit("hoverSegmentInstance",{segmentData:this.store.segmentData.get((t=s==null?void 0:s.object)==null?void 0:t.name),currentSegmentStatus:this.store.segmentStatus}),s?this.store.highlightPoints(s.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new c(this.store),this.rectSelector=new l(this.store),this.circleSelector=new h(this.store),this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this),this.emit=e.emit}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Rect(){this.currentTool=this.rectSelector,this.currentToolName="RectSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}export{a as PointCloudSegmentOperation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as v from"three";import{EPointCloudSegmentMode as y,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as P}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,D=(d,t)=>{for(var e in t||(t={}))k.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))B.call(t,e)&&w(d,e,t[e]);return d},b=(d,t)=>_(d,R(t));const H="LABELBEE_CANVAS_";class I{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=y.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var g;if(u!==((g=this.cacheSegData)==null?void 0:g.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(g=>g===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const g=P.splitPointsFromIndexes(c.indexes,i),S=[];g.forEach(l=>{S.push(this.originPoints[l*3],this.originPoints[l*3+1],this.originPoints[l*3+2])}),c.indexes=g,c.points=new Float32Array(S);const f=this.scene.getObjectByName(r);f&&(f.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),f.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=a,this.emit=n,this.on=o,this.unbind=h,this.checkMode=p,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSubAttribute=this.setSubAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,subAttribute:s.subAttribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const s=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(s[h*3],s[h*3+1],s[h*3+2]),this.cloudData.set(`${s[h*3]}@${s[h*3+1]}@${s[h*3+2]}`,{visible:!0})});const o=b(D({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",b(D({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${H}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,s){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${s} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,s=this.originPoints;if(s){const a=s.length,n=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const g=s[i],S=s[i+1],f=s[i+2],l=P.getCloudKeys(g,S,f);this.segmentMode===y.Remove&&(this.cloudData.get(l).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===y.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(l).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(l).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(l).visible===!1&&(this.cloudData.get(l).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===y.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case y.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=b(D({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,subAttribute:{},points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case y.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=b(D({},this.cacheSegData),{points:P.splitPointsFromPoints(a,t),indexes:P.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],o=t[s+2],h=P.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}clearStash(){if(this.isCheckStatus){this.resetSelectedSegmentStatus();return}if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const a=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const o=this.cloudData.get(P.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=b(D({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(D({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(s=>{s.attribute===t&&e.push(s.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=b(D({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}export{I as default};
|
|
1
|
+
import*as v from"three";import{EPointCloudSegmentMode as y,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as P}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,D=(d,t)=>{for(var e in t||(t={}))B.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))k.call(t,e)&&w(d,e,t[e]);return d},b=(d,t)=>_(d,R(t));const H="LABELBEE_CANVAS_";class I{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=y.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var g;if(u!==((g=this.cacheSegData)==null?void 0:g.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(g=>g===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const g=P.splitPointsFromIndexes(c.indexes,i),S=[];g.forEach(l=>{S.push(this.originPoints[l*3],this.originPoints[l*3+1],this.originPoints[l*3+2])}),c.indexes=g,c.points=new Float32Array(S);const f=this.scene.getObjectByName(r);f&&(f.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),f.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=a,this.emit=n,this.on=o,this.unbind=h,this.checkMode=p,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSubAttribute=this.setSubAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,subAttribute:s.subAttribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const s=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(s[h*3],s[h*3+1],s[h*3+2]),this.cloudData.set(`${s[h*3]}@${s[h*3+1]}@${s[h*3+2]}`,{visible:!0})});const o=b(D({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",b(D({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${H}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,s){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${s} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,s=this.originPoints;if(s){const a=s.length,n=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const g=s[i],S=s[i+1],f=s[i+2],l=P.getCloudKeys(g,S,f);this.segmentMode===y.Remove&&(this.cloudData.get(l).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===y.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(l).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(l).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(l).visible===!1&&(this.cloudData.get(l).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===y.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case y.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=b(D({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,subAttribute:{},points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case y.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=b(D({},this.cacheSegData),{points:P.splitPointsFromPoints(a,t),indexes:P.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],o=t[s+2],h=P.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData()}this.resetSelectedSegmentStatus()}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const a=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const o=this.cloudData.get(P.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=b(D({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(D({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(s=>{s.attribute===t&&e.push(s.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=b(D({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}export{I as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ImgPosUtils as B}from"@labelbee/lb-utils";import E from"lodash";import M from"color-rgba";import l from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/RectUtils.js";import U from"../../utils/tool/PolygonUtils.js";import C from"../../utils/MathUtils.js";import W from"../../utils/tool/RenderDomClass.js";import{ELineTypes as O,DEFAULT_FONT as j,SEGMENT_NUMBER as z}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as $,TEXT_ATTRIBUTE_OFFSET as L,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import V,{cropAndEnlarge as K}from"../../utils/ImgUtils.js";import X from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as G}from"./basicToolOperation.js";import{pointCloudLidar2image as q}from"../pointCloud/matrix.js";var Y=Object.defineProperty,J=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,N=(x,t,e)=>t in x?Y(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,m=(x,t)=>{for(var e in t||(t={}))tt.call(t,e)&&N(x,e,t[e]);if(F)for(var e of F(t))et.call(t,e)&&N(x,e,t[e]);return x},_=(x,t)=>J(x,Q(t));const ot=3,it=3,A="#6371FF";class nt extends G{constructor(t){super(_(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(c,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 d=0;d<this.annotations.length;d++){const a=this.annotations[d];switch(a.type){case"rect":{const u=a.annotation;if(Z.isInRect(c,u,ot,this.zoom)){const f=u.width*u.height;f<s&&(h=u.id,s=f)}break}case"polygon":{const u=a.annotation;if(U.isInPolygon(n,u.pointList)){const f=U.getPolygonArea(u.pointList);f<s&&(h=u.id,s=f)}break}}}return h};var e;this.style=(e=t.style)!=null?e:{stroke:A,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new W({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:c}=C.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},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=K(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);V.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}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){if(!E.isEqual(this.annotations,t)&&(this.annotations=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}}getSpecificStyle(t){const e=E.pick(t,["stroke","thickness","fill","radius"]),o=m(m({},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,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(m({},H),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+$.offsetX,y:e+$.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),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=C.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=B.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(_(m({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=T.changePointByZoom(t,this.zoom,this.currentPos);l.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),l.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:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=O.Line}=n,s=T.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),d=_(m(m({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=l.drawPolygonWithKeyPoint(this.canvas,s,d):a=l.drawPolygon(this.canvas,s,d),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let p=s[0],y=C.getLineCenterPoint([s[0],s[1]]);if(h===O.Curve){const g=Math.floor(z/2);p=a[g],y=a[g+1]}l.drawArrowByCanvas(this.canvas,p,y,{color:r.stroke,thickness:r.thickness}),l.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:v}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&l.drawText(this.canvas,this.appendOffset(s[0]),f,c),v){const p=s[s.length-1];l.drawText(this.canvas,this.appendOffset({x:p.x+L.x,y:p.y+L.y}),v,c)}}renderPolygon(t){var e,o,i,r,c;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:d=O.Line}=s,a=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=M((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:A),P=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;l.drawPolygonWithFill(this.canvas,a,{color:P,lineType:d})}const u=_(m(_(m({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:d,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=l.drawPolygonWithKeyPoint(this.canvas,a,u):f=l.drawPolygon(this.canvas,a,u),(s==null?void 0:s.showDirection)===!0&&((c=s==null?void 0:s.pointList)==null?void 0:c.length)>=2){let g=a[0],P=C.getLineCenterPoint([a[0],a[1]]);if(d===O.Curve){const w=Math.floor(z/2);g=f[w],P=f[w+1]}l.drawArrowByCanvas(this.canvas,g,P,{color:n.stroke,thickness:n.thickness}),l.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:p,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(p&&l.drawText(this.canvas,this.appendOffset(a[0]),p,h),y){const g=a[a.length-1];l.drawText(this.canvas,this.appendOffset({x:g.x+L.x,y:g.y+L.y}),y,h)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=M((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:A),n=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,h=i.stroke,s=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:d,bottomText:a}=this.getRenderText(r,r==null?void 0:r.hiddenText);l.drawCuboidWithText(this.canvas,s,{strokeColor:h,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:d,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,{transferViewData:o}=q(e,e.calib),i={fill:"transparent"},r=E.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const h=m(_(m({},r),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),i);switch(c.type){case"line":this.renderLine({type:"line",annotation:h});break;case"polygon":this.renderPolygon({type:"polygon",annotation:h});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,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){l.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:h}=X.createCanvas(c);n&&(o==null?void 0:o.length)>0&&(l.drawPixel({canvas:h,points:o,size:c}),l.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,c,n;const h=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,h);switch(e.type){case"rect":{const d=e.annotation,{hiddenText:a=!1,isReference:u,hiddenRectSize:f=!1}=d,{zoom:v}=this,p=T.changeRectByZoom(d,this.zoom,this.currentPos),{x:y,y:g,width:P,height:w}=p;if(d.id===this.mouseHoverID||h.fill){const b=M((i=(o=h==null?void 0:h.fill)!=null?o:h==null?void 0:h.stroke)!=null?i:A),k=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;l.drawRectWithFill(this.canvas,p,{color:k})}l.drawRect(this.canvas,p,m(_(m({},h),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:I,bottomText:D}=this.getRenderText(d,d==null?void 0:d.hiddenText);I&&l.drawText(this.canvas,{x:y,y:g-6},I,m({textMaxWidth:300},s));const S=`${Math.round(P/v)} * ${Math.round(w/v)}`,R=S.length*7;if(!a&&!f&&l.drawText(this.canvas,{x:y+P-R,y:g+w+15},S,s),D){const b=20,k=Math.max(20,P-R);l.drawText(this.canvas,{x:y,y:g+w+b},d.textAttribute,m({textMaxWidth:k},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const d=e.annotation,a=T.changePointByZoom(d,this.zoom,this.currentPos),u=(r=h.radius)!=null?r:it;l.drawCircle(this.canvas,a,u,h);const{headerText:f,bottomText:v}=this.getRenderText(d,d==null?void 0:d.hiddenText);f&&l.drawText(this.canvas,{x:a.x+u/2,y:a.y-u-4},f,m({textAlign:"center"},s)),v&&l.drawText(this.canvas,this.appendOffset({x:a.x+u,y:a.y+u+24}),v,s);break}case"text":{const d=e.annotation,{text:a,x:u,y:f,textMaxWidth:v,color:p="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:g=25,font:P=j,position:w}=d,I=10,D=10,S=T.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:R,height:b,fontHeight:k=0}=C.getTextArea(this.canvas,d.text,v,P,g);if(w==="rt")break;l.drawRectWithFill(this.canvas,{x:S.x,y:S.y,width:R+D*2,height:b+I*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),l.drawText(this.canvas,{x:S.x+D,y:S.y+k+I},a,{color:p,lineHeight:g,font:P,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&&((n=(c=e.annotation).renderEnhance)==null||n.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)}}}export{nt as default};
|
|
1
|
+
import{ImgPosUtils as N}from"@labelbee/lb-utils";import E from"lodash";import M from"color-rgba";import l from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/RectUtils.js";import z from"../../utils/tool/PolygonUtils.js";import C from"../../utils/MathUtils.js";import W from"../../utils/tool/RenderDomClass.js";import{ELineTypes as O,DEFAULT_FONT as j,SEGMENT_NUMBER as U}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as B,TEXT_ATTRIBUTE_OFFSET as L,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import V,{cropAndEnlarge as G}from"../../utils/ImgUtils.js";import K from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as X}from"./basicToolOperation.js";import{pointCloudLidar2image as q}from"../pointCloud/matrix.js";var Y=Object.defineProperty,J=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,F=(x,t,e)=>t in x?Y(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,m=(x,t)=>{for(var e in t||(t={}))tt.call(t,e)&&F(x,e,t[e]);if($)for(var e of $(t))et.call(t,e)&&F(x,e,t[e]);return x},_=(x,t)=>J(x,Q(t));const ot=3,it=3,A="#6371FF";class nt extends X{constructor(t){super(_(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(c,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 d=0;d<this.annotations.length;d++){const a=this.annotations[d];switch(a.type){case"rect":{const u=a.annotation;if(Z.isInRect(c,u,ot,this.zoom)){const f=u.width*u.height;f<s&&(h=u.id,s=f)}break}case"polygon":{const u=a.annotation;if(z.isInPolygon(n,u.pointList)){const f=z.getPolygonArea(u.pointList);f<s&&(h=u.id,s=f)}break}}}return h};var e;this.style=(e=t.style)!=null?e:{stroke:A,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new W({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:c}=C.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},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=G(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);V.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}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){if(!E.isEqual(this.annotations,t)&&(this.annotations=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}}getSpecificStyle(t){const e=E.pick(t,["stroke","thickness","fill","radius"]),o=m(m({},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,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(m({},H),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+B.offsetX,y:e+B.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),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=C.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=N.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(_(m({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=T.changePointByZoom(t,this.zoom,this.currentPos);l.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),l.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:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=O.Line}=n,s=T.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),d=_(m(m({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=l.drawPolygonWithKeyPoint(this.canvas,s,d):a=l.drawPolygon(this.canvas,s,d),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let p=s[0],y=C.getLineCenterPoint([s[0],s[1]]);if(h===O.Curve){const g=Math.floor(U/2);p=a[g],y=a[g+1]}l.drawArrowByCanvas(this.canvas,p,y,{color:r.stroke,thickness:r.thickness}),l.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:v}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&l.drawText(this.canvas,this.appendOffset(s[0]),f,c),v){const p=s[s.length-1];l.drawText(this.canvas,this.appendOffset({x:p.x+L.x,y:p.y+L.y}),v,c)}}renderPolygon(t){var e,o,i,r,c;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:d=O.Line}=s,a=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=M((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:A),P=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;l.drawPolygonWithFill(this.canvas,a,{color:P,lineType:d})}const u=_(m(_(m({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:d,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=l.drawPolygonWithKeyPoint(this.canvas,a,u):f=l.drawPolygon(this.canvas,a,u),(s==null?void 0:s.showDirection)===!0&&((c=s==null?void 0:s.pointList)==null?void 0:c.length)>=2){let g=a[0],P=C.getLineCenterPoint([a[0],a[1]]);if(d===O.Curve){const w=Math.floor(U/2);g=f[w],P=f[w+1]}l.drawArrowByCanvas(this.canvas,g,P,{color:n.stroke,thickness:n.thickness}),l.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:p,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(p&&l.drawText(this.canvas,this.appendOffset(a[0]),p,h),y){const g=a[a.length-1];l.drawText(this.canvas,this.appendOffset({x:g.x+L.x,y:g.y+L.y}),y,h)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=M((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:A),n=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,h=i.stroke,s=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:d,bottomText:a}=this.getRenderText(r,r==null?void 0:r.hiddenText);l.drawCuboidWithText(this.canvas,s,{strokeColor:h,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:d,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,{transferViewData:o}=q(e,e.calib),i={fill:"transparent"},r=E.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const h=m(_(m({},r),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),i);switch(c.type){case"line":this.renderLine({type:"line",annotation:h});break;case"polygon":this.renderPolygon({type:"polygon",annotation:h});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){l.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:h}=K.createCanvas(c);n&&(o==null?void 0:o.length)>0&&(l.drawPixel({canvas:h,points:o,size:c,defaultRGBA:t.defaultRGBA,pixelSize:13}),l.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,c,n;const h=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,h);switch(e.type){case"rect":{const d=e.annotation,{hiddenText:a=!1,isReference:u,hiddenRectSize:f=!1}=d,{zoom:v}=this,p=T.changeRectByZoom(d,this.zoom,this.currentPos),{x:y,y:g,width:P,height:w}=p;if(d.id===this.mouseHoverID||h.fill){const b=M((i=(o=h==null?void 0:h.fill)!=null?o:h==null?void 0:h.stroke)!=null?i:A),k=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;l.drawRectWithFill(this.canvas,p,{color:k})}l.drawRect(this.canvas,p,m(_(m({},h),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:I,bottomText:D}=this.getRenderText(d,d==null?void 0:d.hiddenText);I&&l.drawText(this.canvas,{x:y,y:g-6},I,m({textMaxWidth:300},s));const S=`${Math.round(P/v)} * ${Math.round(w/v)}`,R=S.length*7;if(!a&&!f&&l.drawText(this.canvas,{x:y+P-R,y:g+w+15},S,s),D){const b=20,k=Math.max(20,P-R);l.drawText(this.canvas,{x:y,y:g+w+b},d.textAttribute,m({textMaxWidth:k},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const d=e.annotation,a=T.changePointByZoom(d,this.zoom,this.currentPos),u=(r=h.radius)!=null?r:it;l.drawCircle(this.canvas,a,u,h);const{headerText:f,bottomText:v}=this.getRenderText(d,d==null?void 0:d.hiddenText);f&&l.drawText(this.canvas,{x:a.x+u/2,y:a.y-u-4},f,m({textAlign:"center"},s)),v&&l.drawText(this.canvas,this.appendOffset({x:a.x+u,y:a.y+u+24}),v,s);break}case"text":{const d=e.annotation,{text:a,x:u,y:f,textMaxWidth:v,color:p="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:g=25,font:P=j,position:w}=d,I=10,D=10,S=T.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:R,height:b,fontHeight:k=0}=C.getTextArea(this.canvas,d.text,v,P,g);if(w==="rt")break;l.drawRectWithFill(this.canvas,{x:S.x,y:S.y,width:R+D*2,height:b+I*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),l.drawText(this.canvas,{x:S.x+D,y:S.y+k+I},a,{color:p,lineHeight:g,font:P,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&&((n=(c=e.annotation).renderEnhance)==null||n.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)}}}export{nt as default};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
`,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=
|
|
3
|
-
`);for(let
|
|
1
|
+
import E from"color-rgba";import{NULL_COLOR as W,MathUtils as M}from"@labelbee/lb-utils";import{ELineTypes as P,SEGMENT_NUMBER as b,DEFAULT_FONT as U}from"../../constant/tool.js";import A from"./PolygonUtils.js";import T from"./UnitUtils.js";import v from"./AxisUtils.js";import{getCuboidAllSideLine as F,getPointListsByDirection as I,getCuboidTextAttributeOffset as R}from"./CuboidUtils.js";import L from"./AttributeUtils.js";var $=Object.defineProperty,j=Object.defineProperties,B=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,k=(r,t,i)=>t in r?$(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))N.call(t,i)&&k(r,i,t[i]);if(_)for(var i of _(t))X.call(t,i)&&k(r,i,t[i]);return r},S=(r,t)=>j(r,B(t));const Y=1,z={x:0,y:0},H=0,u="",x=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=u,thickness:s=1,lineCap:d="round",lineDash:n}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=d,n&&o.setLineDash(n),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=u,thickness:l=1,lineCap:s="round",hiddenText:d=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),d===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,w=0,y=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+w},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=u}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,d)=>`${s}${d.keyName}: ${d.value.join(" \u3001 ")}
|
|
2
|
+
`,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=u,thickness:l=1,lineCap:s="round",lineType:d=P.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),d===P.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=A.createSmoothCurvePointsFromPointList([...t],b),a!==void 0&&a>-1&&(t=t.slice((b+1)*a,(b+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+2));const c=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&c.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),c.forEach(h=>{const g=t[h.i1],C=t[h.i2];e.beginPath(),e.moveTo(g.x,g.y),e.lineTo(C.x,C.y),e.stroke()}),e.restore();const w=4,y=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,w+y,o),this.drawSpecialPoint(r,h,w,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:d=1,color:n=u,fill:a=u}=e,f=T.deg2rad(l),c=T.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=d,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),a&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=u}=e;o.save();const s=T.deg2rad(0),d=T.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,d,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const d=i*1.5,n=d*Math.sqrt(3)/2,a=d/2;o.moveTo(l,s-d),o.lineTo(l-n,s+a),o.lineTo(l+n,s+a),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=P.Line}=i;return e===!0&&(t=[...t,t[0]]),o===P.Curve&&(t=A.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,S(m({},i),{lineType:P.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=u,lineType:l=P.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===P.Curve&&(t=A.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...d]=t;return e.moveTo(s.x,s.y),d.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:d,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:d,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=u,font:s=U,shadowColor:d="",shadowBlur:n=0,shadowOffsetX:a=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:w=0,offsetY:y=0,textAlign:h="start",lineHeight:g}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=d,o.shadowOffsetX=a,o.shadowOffsetY=f,o.shadowBlur=n,this.wrapText(r,`${i}`,t.x+w,t.y+y,c,g),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const d=t.split(`
|
|
3
|
+
`);for(let n=0;n<d.length;n++){const a=d[n].split("");let f="";for(let c=0;c<a.length;c++){const w=f+a[c],h=s.measureText(w).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=a[c],e+=l):f=w}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=u,thickness:l=1,lineCap:s="round",theta:d=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(a+d)*Math.PI/180,c=(a-d)*Math.PI/180,w=n*Math.cos(f),y=n*Math.sin(f),h=n*Math.cos(c),g=n*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+w,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+g),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:d,fillColor:n}=i,a={color:s,thickness:d};if(e){const c=v.transformPlain2PointList(e);x.drawPolygon(r,c,S(m({},a),{isClose:!0}));const w=F(t);w==null||w.forEach(y=>{x.drawLine(r,y.p1,y.p2,m({},a))})}const f=v.transformPlain2PointList(l);if(o&&e&&l){const c=I({direction:o,frontPoints:l,backPoints:e});c&&x.drawPolygonWithFill(r,c,{color:n})}x.drawPolygon(r,f,S(m({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:d,selectedID:n,headerText:a,bottomText:f}=e,{backPoints:c,frontPoints:w,textAttribute:y}=t,h=w.br.x-w.bl.x;x.drawCuboid(r,t,i);let g="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.attribute&&(g=`${g} ${L.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!d&&c&&g&&x.drawText(r,{x:c.tl.x,y:c.tl.y-5},a!=null?a:g,{color:o,textMaxWidth:300});const C=R({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!d&&y&&t.id!==n){const p=Math.max(20,h*.8);x.drawText(r,{x:C.left,y:C.top},f!=null?f:y,{color:l,textMaxWidth:p})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const l=r.getContext("2d"),{width:s,height:d}=i,n=l.getImageData(0,0,s,d),[a,f,c,w]=E(e!=null?e:W),y=g=>{n.data[g]=a,n.data[g+1]=f,n.data[g+2]=c,n.data[g+3]=Math.floor(255*w)},h=M.generateCoordinates(o);return t.forEach(g=>{for(const[C,p]of h){const D=(g.y+p)*(n.width*4)+(g.x+C)*4;y(D)}}),l.putImageData(n,0,0),{canvas:r}}};let O=x;O.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=Y,currentPos:l=z,rotate:s=H,imgAttribute:d}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(d){const{contrast:n,saturation:a,brightness:f}=d;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{O as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.20.0-alpha.
|
|
3
|
+
"version": "1.20.0-alpha.3",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"typescript": "^4.2.3"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@labelbee/lb-utils": "1.13.0-alpha.
|
|
97
|
+
"@labelbee/lb-utils": "1.13.0-alpha.3",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|