@labelbee/lb-annotation 1.20.0-alpha.2 → 1.20.0-alpha.4
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/toolOperation/ViewOperation.js +1 -1
- package/dist/types/core/pointCloud/segmentation.d.ts +3 -0
- package/dist/types/core/toolOperation/ViewOperation.d.ts +6 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/pointCloud/segmentation.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- 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 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;
|
|
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(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}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=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t)),__async=(v,t,e)=>new Promise((i,o)=>{var r=a=>{try{n(e.next(a))}catch(s){o(s)}},l=a=>{try{n(e.throw(a))}catch(s){o(s)}},n=a=>a.done?i(a.value):Promise.resolve(a.value).then(r,l);n((e=e.apply(v,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.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 a="",s=Number.MAX_SAFE_INTEGER;for(let h=0;h<this.annotations.length;h++){const c=this.annotations[h];switch(c.type){case"rect":{const d=c.annotation;if(RectUtils.isInRect(l,d,newScope,this.zoom)){const u=d.width*d.height;u<s&&(a=d.id,s=u)}break}case"polygon":{const d=c.annotation;if(PolygonUtils.isInPolygon(n,d.pointList)){const u=PolygonUtils.getPolygonArea(d.pointList);u<s&&(a=d.id,s=u)}break}}}return a};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){return __async(this,null,function*(){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:a=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:a,strokeColor:r.stroke});let c=[];if(n.showKeyPoint?c=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,h):c=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 g=s[0],y=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(a===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);g=c[f],y=c[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,g,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 g=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:g.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:g.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:a}=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,c=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const f=rgba__default.default((r=(o=n==null?void 0:n.fill)!=null?o:n==null?void 0:n.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,c,{color:m,lineType: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,c,d):u=DrawUtils.drawPolygon(this.canvas,c,d),(s==null?void 0:s.showDirection)===!0&&((l=s==null?void 0:s.pointList)==null?void 0:l.length)>=2){let f=c[0],m=MathUtils.default.getLineCenterPoint([c[0],c[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,c[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(g&&DrawUtils.drawText(this.canvas,this.appendOffset(c[0]),g,a),y){const f=c[c.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,a)}}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})`,a=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:c}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:a,fillColor:n,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:h,bottomText:c})}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 a=__spreadValues(__spreadProps(__spreadValues({},r),{id:`${t.annotation.id}-${n}`,pointList:l.pointList}),o);switch(l.type){case"line":this.renderLine({type:"line",annotation:a});break;case"polygon":this.renderPolygon({type:"polygon",annotation:a});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:a}=CanvasUtils.createCanvas(l),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:a,points:i,size:l,defaultRGBA:t.defaultRGBA,pixelSize:s}),DrawUtils.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:a})}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 a=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:c=!1,isReference:d,hiddenRectSize:u=!1}=h,{zoom:p}=this,g=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:y,y:f,width:m,height:P}=g;if(h.id===this.mouseHoverID||a.fill){const x=rgba__default.default((o=(i=a==null?void 0:a.fill)!=null?i:a==null?void 0:a.stroke)!=null?o:DEFAULT_STROKE_COLOR),b=`rgba(${x[0]}, ${x[1]}, ${x[2]},${x[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,g,{color:b})}DrawUtils.drawRect(this.canvas,g,__spreadValues(__spreadProps(__spreadValues({},a),{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(!c&&!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,c=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),d=(r=a.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,c,d,a);const{headerText:u,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:c.x+d/2,y:c.y-d-4},u,__spreadValues({textAlign:"center"},s)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:c.x+d,y:c.y+d+24}),p,s);break}case"text":{const h=e.annotation,{text:c,x:d,y:u,textMaxWidth:p,color:g="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},c,{color:g,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;
|
|
@@ -41,10 +41,15 @@ export default class ViewOperation extends BasicToolOperation {
|
|
|
41
41
|
valid: boolean;
|
|
42
42
|
rotate: number;
|
|
43
43
|
}>): void;
|
|
44
|
+
/**
|
|
45
|
+
* TODO: New Pattern.
|
|
46
|
+
*
|
|
47
|
+
* 1. crop the canvas.
|
|
48
|
+
*/
|
|
44
49
|
generateStaticImgNode(): void;
|
|
45
50
|
onMouseMove(e: MouseEvent): void;
|
|
46
51
|
getHoverRectID: (e: MouseEvent) => string | undefined;
|
|
47
|
-
updateData(annotations: TAnnotationViewData[]): void
|
|
52
|
+
updateData(annotations: TAnnotationViewData[]): Promise<void>;
|
|
48
53
|
/**
|
|
49
54
|
* 获取当前结果的标注类型
|
|
50
55
|
* @param obj
|
|
@@ -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{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
|
+
import{ImgPosUtils as N}from"@labelbee/lb-utils";import E from"lodash";import M from"color-rgba";import h 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=(v,t,e)=>t in v?Y(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,m=(v,t)=>{for(var e in t||(t={}))tt.call(t,e)&&F(v,e,t[e]);if($)for(var e of $(t))et.call(t,e)&&F(v,e,t[e]);return v},_=(v,t)=>J(v,Q(t)),ot=(v,t,e)=>new Promise((o,i)=>{var r=a=>{try{n(e.next(a))}catch(s){i(s)}},l=a=>{try{n(e.throw(a))}catch(s){i(s)}},n=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,l);n((e=e.apply(v,t)).next())});const it=3,nt=3,A="#6371FF";class st extends X{constructor(t){super(_(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const l=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(l,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",s=Number.MAX_SAFE_INTEGER;for(let d=0;d<this.annotations.length;d++){const c=this.annotations[d];switch(c.type){case"rect":{const u=c.annotation;if(Z.isInRect(l,u,it,this.zoom)){const f=u.width*u.height;f<s&&(a=u.id,s=f)}break}case"polygon":{const u=c.annotation;if(z.isInPolygon(n,u.pointList)){const f=z.getPolygonArea(u.pointList);f<s&&(a=u.id,s=f)}break}}}return a};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:l}=C.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:l},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){return ot(this,null,function*(){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,l=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(m({},H),{color:e.stroke,font:`normal normal 600 ${r}px ${l}`})}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:l}=this.innerPosAndZoom;r&&this.setImgInfo(_(m({},r),{width:r.width/l*i.innerZoom,height:r.height/l*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=T.changePointByZoom(t,this.zoom,this.currentPos);h.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),h.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}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:l}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=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:a,strokeColor:r.stroke});let c=[];if(n.showKeyPoint?c=h.drawPolygonWithKeyPoint(this.canvas,s,d):c=h.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],P=C.getLineCenterPoint([s[0],s[1]]);if(a===O.Curve){const g=Math.floor(U/2);p=c[g],P=c[g+1]}h.drawArrowByCanvas(this.canvas,p,P,{color:r.stroke,thickness:r.thickness}),h.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&h.drawText(this.canvas,this.appendOffset(s[0]),f,l),y){const p=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:p.x+L.x,y:p.y+L.y}),y,l)}}renderPolygon(t){var e,o,i,r,l;if(t.type!=="polygon")return;const{style:n,fontStyle:a}=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,c=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=M((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:A),x=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;h.drawPolygonWithFill(this.canvas,c,{color:x,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=h.drawPolygonWithKeyPoint(this.canvas,c,u):f=h.drawPolygon(this.canvas,c,u),(s==null?void 0:s.showDirection)===!0&&((l=s==null?void 0:s.pointList)==null?void 0:l.length)>=2){let g=c[0],x=C.getLineCenterPoint([c[0],c[1]]);if(d===O.Curve){const w=Math.floor(U/2);g=f[w],x=f[w+1]}h.drawArrowByCanvas(this.canvas,g,x,{color:n.stroke,thickness:n.thickness}),h.drawCircle(this.canvas,c[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:p,bottomText:P}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(p&&h.drawText(this.canvas,this.appendOffset(c[0]),p,a),P){const g=c[c.length-1];h.drawText(this.canvas,this.appendOffset({x:g.x+L.x,y:g.y+L.y}),P,a)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,l=M((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:A),n=`rgba(${l[0]}, ${l[1]}, ${l[2]},${l[3]*.8})`,a=i.stroke,s=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:d,bottomText:c}=this.getRenderText(r,r==null?void 0:r.hiddenText);h.drawCuboidWithText(this.canvas,s,{strokeColor:a,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:d,bottomText:c})}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((l,n)=>{const a=m(_(m({},r),{id:`${t.annotation.id}-${n}`,pointList:l.pointList}),i);switch(l.type){case"line":this.renderLine({type:"line",annotation:a});break;case"polygon":this.renderPolygon({type:"polygon",annotation:a});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const o=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(o.length>0)){console.warn("Empty pixelPoints");return}const i=this.imgNode.src+o.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){h.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const l={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:a}=K.createCanvas(l),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(o==null?void 0:o.length)>0&&(h.drawPixel({canvas:a,points:o,size:l,defaultRGBA:t.defaultRGBA,pixelSize:s}),h.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:a})}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,l,n;const a=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const d=e.annotation,{hiddenText:c=!1,isReference:u,hiddenRectSize:f=!1}=d,{zoom:y}=this,p=T.changeRectByZoom(d,this.zoom,this.currentPos),{x:P,y:g,width:x,height:w}=p;if(d.id===this.mouseHoverID||a.fill){const b=M((i=(o=a==null?void 0:a.fill)!=null?o:a==null?void 0:a.stroke)!=null?i:A),k=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;h.drawRectWithFill(this.canvas,p,{color:k})}h.drawRect(this.canvas,p,m(_(m({},a),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:I,bottomText:D}=this.getRenderText(d,d==null?void 0:d.hiddenText);I&&h.drawText(this.canvas,{x:P,y:g-6},I,m({textMaxWidth:300},s));const S=`${Math.round(x/y)} * ${Math.round(w/y)}`,R=S.length*7;if(!c&&!f&&h.drawText(this.canvas,{x:P+x-R,y:g+w+15},S,s),D){const b=20,k=Math.max(20,x-R);h.drawText(this.canvas,{x:P,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,c=T.changePointByZoom(d,this.zoom,this.currentPos),u=(r=a.radius)!=null?r:nt;h.drawCircle(this.canvas,c,u,a);const{headerText:f,bottomText:y}=this.getRenderText(d,d==null?void 0:d.hiddenText);f&&h.drawText(this.canvas,{x:c.x+u/2,y:c.y-u-4},f,m({textAlign:"center"},s)),y&&h.drawText(this.canvas,this.appendOffset({x:c.x+u,y:c.y+u+24}),y,s);break}case"text":{const d=e.annotation,{text:c,x:u,y:f,textMaxWidth:y,color:p="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:g=25,font:x=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,y,x,g);if(w==="rt")break;h.drawRectWithFill(this.canvas,{x:S.x,y:S.y,width:R+D*2,height:b+I*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),h.drawText(this.canvas,{x:S.x+D,y:S.y+k+I},c,{color:p,lineHeight:g,font:x,textMaxWidth:y});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)}}}export{st 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.4",
|
|
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.4",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|