@labelbee/lb-annotation 1.21.0-dev.2 → 1.22.0-alpha.1
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/matrix.js +1 -1
- package/dist/core/toolOperation/SAMToolbarClass.js +2 -2
- package/dist/core/toolOperation/segmentBySAM.js +1 -1
- package/dist/index.js +1 -1
- package/dist/types/core/pointCloud/matrix.d.ts +6 -2
- package/dist/types/core/toolOperation/segmentBySAM.d.ts +1 -0
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/pointCloud/matrix.js +1 -1
- package/es/core/toolOperation/SAMToolbarClass.js +2 -2
- package/es/core/toolOperation/segmentBySAM.js +1 -1
- package/es/index.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=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:h,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=h!=null?h:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,h,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,h=-100,d=500/c;return{left:a,right:o,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(h),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:h}=c.data,d=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==h.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(h),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,a+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],u=[];const m=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,h=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r-o/2},n={x:e+a/2,y:i+s/2,z:r+o/2},c={x:e-a/2,y:i+s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r-o/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2},c={x:e-a/2,y:i-s/2,z:r-o/2},h={x:e-a/2,y:i-s/2,z:r+o/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r+o/2},n={x:e+a/2,y:i-s/2,z:r+o/2},c={x:e-a/2,y:i-s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r+o/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(h).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:h,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=h!=null?h:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,h,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,h=-100,d=500/c;return{left:a,right:o,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(h),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:h}=c.data,d=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==h.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(h),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,a+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],u=[];const m=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,h=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r-o/2},n={x:e+a/2,y:i+s/2,z:r+o/2},c={x:e-a/2,y:i+s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r-o/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2},c={x:e-a/2,y:i-s/2,z:r-o/2},h={x:e-a/2,y:i-s/2,z:r+o/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r+o/2},n={x:e+a/2,y:i-s/2,z:r+o/2},c={x:e-a/2,y:i-s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r+o/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(h).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,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 THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),uuid=require("../../utils/uuid.js");function _interopNamespace(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if(r!=="default"){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));function createThreeMatrix4(e){return new THREE__namespace.Matrix4().set(...e)}function transferKitti2Matrix(e,t,r){try{const n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(e),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),uuid=require("../../utils/uuid.js");function _interopNamespace(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if(r!=="default"){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));function createThreeMatrix4(e){return new THREE__namespace.Matrix4().set(...e)}function transferKitti2Matrix(e,t,r){try{const n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(e),o=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(t),i=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r),l=createThreeMatrix4(n),f=createThreeMatrix4(o),a=createThreeMatrix4(i);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function rotatePoint(e,t,r){var n;const o=new THREE__namespace.Vector3(e.x,e.y,(n=e==null?void 0:e.z)!=null?n:1),i=new THREE__namespace.Matrix4().makeRotationZ(r),l=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return o.clone().applyMatrix4(f).applyMatrix4(i).applyMatrix4(l)}function isMatrixValid(e,t,r){return!(e.length!==t||e.some(n=>n.length!==r))}const isFisheyeCalibValid=e=>{var t;return!!(((t=e.fisheyeDistortion)==null?void 0:t.length)>0&&isMatrixValid(e.P,3,4)&&isMatrixValid(e.T,3,4))},lidar2FisheyeImage=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:o}=t,i=new THREE__namespace.Vector4(e.x,e.y,e.z),l=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(o)),f=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r)),a=i.applyMatrix4(l),p=__pow(__pow(a.x,2)+__pow(a.y,2),.5),x=Math.atan(a.z/p),s=n.reduce((u,c,g)=>u+c*__pow(x,g),0);return a.x=a.x/p*s,a.y=a.y/p*s,a.z=1,a.applyMatrix4(f)};function lidar2image(e,t){const n=new THREE__namespace.Vector4(e.x,e.y,e.z).applyMatrix4(t);if(n.z<0)return;const o=1/n.z,i=new THREE__namespace.Matrix4().set(o,0,0,0,0,o,0,0,0,0,o,0,0,0,0,1);return n.applyMatrix4(i)}function getCuboidFromPointCloudBox(e){const{center:t,width:r,height:n,depth:o,rotation:i}=e,l=[{x:t.x+r/2,y:t.y-n/2},{x:t.x+r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y-n/2}].map(p=>{const x=rotatePoint(p,t,i);return{x:x.x,y:x.y}}),f=t.z+o/2,a=t.z-o/2;return __spreadProps(__spreadValues({},e),{polygonPointList:l,zMax:f,zMin:a})}function sortPoints(e){const t=e.slice();return t.sort((r,n)=>r.x===n.x?n.y-r.y:r.x-n.x),t}function crossProduct(e,t,r){const n=t.x-e.x,o=t.y-e.y,i=r.x-e.x,l=r.y-e.y;return n*l-i*o}function buildConvexHull(e){const t=sortPoints(e),r=[];for(let i=0;i<t.length;i++){for(;r.length>=2&&crossProduct(r[r.length-2],r[r.length-1],t[i])<=0;)r.pop();r.push(t[i])}const n=[];for(let i=t.length-1;i>=0;i--){for(;n.length>=2&&crossProduct(n[n.length-2],n[n.length-1],t[i])<=0;)n.pop();n.push(t[i])}return r.pop(),n.pop(),r.concat(n)}const point3DLidar2Image=(e,t)=>{var r;if(isFisheyeCalibValid(t))return lidar2FisheyeImage(e,t);const{P:n,R:o,T:i}=t,{composeMatrix4:l}=(r=transferKitti2Matrix(n,o,i))!=null?r:{};if(!!l)return lidar2image(e,l)},isInImage=({point:e,calib:t,width:r,height:n})=>{if(!t)return!1;const o=point3DLidar2Image(e,t);return o?o.x>=0&&o.x<=r&&o.y>=0&&o.y<=n:!1},getHighlightIndexByPoints=({points:e,calib:t,width:r,height:n})=>{const o=[];for(let i=0;i<e.length;i+=3){const l=e[i],f=e[i+1],a=e[i+2];isInImage({point:{x:l,y:f,z:a},calib:t,width:r,height:n})?o.push(1):o.push(0)}return o},mergeHighlightList=e=>{if(e.length===0)return[];const t=[];for(let r=0;r<e[0].length;r++){for(let n=0;n<e.length;n++)if(e[n][r]===1){t.push(1);break}t.length===r&&t.push(0)}return t};function pointCloudLidar2image(e,t,r={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:o}=r,i=lbUtils.PointCloudUtils.getAllViewData(e),l=isFisheyeCalibValid(t),{P:f,R:a,T:p}=t;let x;if(l===!1){const{composeMatrix4:u}=(n=transferKitti2Matrix(f,a,p))!=null?n:{};if(!u)return;x=u}const s=i.map(u=>({type:u.type,pointList:u.pointList.map(c=>rotatePoint(c,e.center,e.rotation)).map(c=>l?lidar2FisheyeImage(c,t):x&&lidar2image(c,x)).map(c=>{if(!!c)return{id:uuid(),x:c==null?void 0:c.x,y:c==null?void 0:c.y}}).filter(c=>c!==void 0)})).filter(u=>u.pointList.length!==0);s[0]&&s[0].pointList&&l&&(s[0].pointList=s[0].pointList.map(u=>__spreadProps(__spreadValues({},u),{specialEdge:!0})));let h=[];if(s.length===6&&o===!0){const u=s[0].pointList,c=s[1].pointList;h=buildConvexHull([...u,...c])}return{transferViewData:s,viewRangePointList:h}}function pointMappingLidar2image(e,t,r){var n;const o=isFisheyeCalibValid(t),{P:i,R:l,T:f}=t;let a;if(o===!1){const{composeMatrix4:s}=(n=transferKitti2Matrix(i,l,f))!=null?n:{};if(!s)return;a=s}const p=e.length/3,x={};for(let s=0;s<p;s++){const h={x:e[s*3],y:e[s*3+1],z:e[s*3+2]};let u;if(o?u=lidar2FisheyeImage(h,t):u=a&&lidar2image({x:e[s*3],y:e[s*3+1],z:e[s*3+2]},a),u){const c=Math.floor(u.x),g=Math.floor(u.y);if(c>r.width||g>r.height||c<0||g<0)continue;x[s]={x:c,y:g}}}return{pcdMapping:x}}function pointListLidar2Img(e,t,r){var n;if(!t||!r)return;const o=isFisheyeCalibValid(t),{P:i,R:l,T:f}=t;let a;if(o===!1){const{composeMatrix4:s}=(n=transferKitti2Matrix(i,l,f))!=null?n:{};if(!s)return;a=s}const p=[];if(e.forEach(s=>{let h;if(o?h=lidar2FisheyeImage(s,t):h=a&&lidar2image(s,a),h){const{x:u,y:c}=h;p.push({x:u,y:c})}}),p.some(s=>s.x>0&&s.x<r.width&&s.y>0&&s.y<r.height))return p}exports.createThreeMatrix4=createThreeMatrix4,exports.getCuboidFromPointCloudBox=getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=getHighlightIndexByPoints,exports.isFisheyeCalibValid=isFisheyeCalibValid,exports.isInImage=isInImage,exports.isMatrixValid=isMatrixValid,exports.lidar2FisheyeImage=lidar2FisheyeImage,exports.lidar2image=lidar2image,exports.mergeHighlightList=mergeHighlightList,exports.point3DLidar2Image=point3DLidar2Image,exports.pointCloudLidar2image=pointCloudLidar2image,exports.pointListLidar2Img=pointListLidar2Img,exports.pointMappingLidar2image=pointMappingLidar2image,exports.rotatePoint=rotatePoint,exports.transferKitti2Matrix=transferKitti2Matrix;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var AxisUtils=require("../../utils/tool/AxisUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,e)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues=(r,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(r,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(r,e,t[e]);return r};const TOOLBAR_SIZE={height:38},TOOLBAR_TOP_OFFSET=8,BUTTON_GROUP_STYLE={height:"22px",border:"1px solid #666fff",color:"#666fff",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",borderRadius:"4px",padding:"0 8px"};class SAMToolbarClass{constructor(t){const{container:e,toggleClickType:i,finish:o,reset:n,i18n:s}=t;this.container=e,this.onToggleClickType=i,this.onFinish=o,this.onReset=n,this.disabled=!1,this.i18n=s,this._toolbarDOM=this.initToolbarDOM(),this._radioGroupDOM=this.initRadioGroupDOM(),this._buttonGroupDOM=this.initButtonGroupDOM(),this.appendToContainer(),this.onClick=this.onClick.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.eventBinding(),this.onToggle("add")}appendToContainer(){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||(this.container.appendChild(this._toolbarDOM),this._toolbarDOM.appendChild(this._radioGroupDOM),this._toolbarDOM.appendChild(this._buttonGroupDOM))}clearToolbarDOM(){this._toolbarDOM&&this.container.contains(this._toolbarDOM)&&(this.eventUnbinding(),this.container.removeChild(this._toolbarDOM))}initToolbarDOM(){const t=document.createElement("div");return t.setAttribute("id","LABELBEE_SAM_TOOLBAR"),StyleUtils.setDOMStyle(t,{display:"flex",position:"absolute",fontSize:"14px",height:`${TOOLBAR_SIZE.height}px`,padding:"0 8px",borderRadius:"4px",backgroundColor:"#FFFFFF",zIndex:"10"}),t}initRadioGroupDOM(){const t=[{text:`${this.i18n.t("AddPoints")}(+)`,value:"add"},{text:`${this.i18n.t("RemovePoints")}(-)`,value:"remove"}],e=document.createElement("div");e.setAttribute("id","LABELBEE_SAM_TOOLBAR_RADIO_GROUP"),StyleUtils.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center"});let i="";return t.forEach(o=>{i+=`<label class="ant-radio-wrapper"
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var AxisUtils=require("../../utils/tool/AxisUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,e)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues=(r,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(r,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(r,e,t[e]);return r};const TOOLBAR_SIZE={height:38},TOOLBAR_TOP_OFFSET=8,BUTTON_GROUP_STYLE={height:"22px",border:"1px solid #666fff",color:"#666fff",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",borderRadius:"4px",padding:"0 8px"};class SAMToolbarClass{constructor(t){const{container:e,toggleClickType:i,finish:o,reset:n,i18n:s}=t;this.container=e,this.onToggleClickType=i,this.onFinish=o,this.onReset=n,this.disabled=!1,this.i18n=s,this._toolbarDOM=this.initToolbarDOM(),this._radioGroupDOM=this.initRadioGroupDOM(),this._buttonGroupDOM=this.initButtonGroupDOM(),this.appendToContainer(),this.onClick=this.onClick.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.eventBinding(),this.onToggle("add")}appendToContainer(){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||(this.container.appendChild(this._toolbarDOM),this._toolbarDOM.appendChild(this._radioGroupDOM),this._toolbarDOM.appendChild(this._buttonGroupDOM))}clearToolbarDOM(){this._toolbarDOM&&this.container.contains(this._toolbarDOM)&&(this.eventUnbinding(),this.container.removeChild(this._toolbarDOM))}initToolbarDOM(){const t=document.createElement("div");return t.setAttribute("id","LABELBEE_SAM_TOOLBAR"),StyleUtils.setDOMStyle(t,{display:"flex",position:"absolute",fontSize:"14px",height:`${TOOLBAR_SIZE.height}px`,padding:"0 8px",borderRadius:"4px",backgroundColor:"#FFFFFF",zIndex:"10"}),t}initRadioGroupDOM(){const t=[{text:`${this.i18n.t("AddPoints")}(+)`,value:"add"},{text:`${this.i18n.t("RemovePoints")}(-)`,value:"remove"}],e=document.createElement("div");e.setAttribute("id","LABELBEE_SAM_TOOLBAR_RADIO_GROUP"),StyleUtils.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center",flexShrink:0});let i="";return t.forEach(o=>{i+=`<label class="ant-radio-wrapper"
|
|
2
2
|
><span class="ant-radio"
|
|
3
3
|
><input
|
|
4
4
|
class="ant-radio-input"
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
value="${o.value}"
|
|
7
7
|
checked="" /><span class="ant-radio-inner"></span></span
|
|
8
8
|
><span data-value="${o.value}">${o.text}</span></label
|
|
9
|
-
>`}),e.innerHTML=i,e}initButtonGroupDOM(){const t=[{text:`${this.i18n.t("Reset")}`,value:"reset"},{text:`${this.i18n.t("Finish")}`,value:"finish"}],e=document.createElement("div");return e.setAttribute("id","LABELBEE_SAM_TOOLBAR_BUTTON_GROUP"),StyleUtils.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center",gap:"8px"}),t.forEach(i=>{const o=document.createElement("div");o.setAttribute("data-value",i.value),o.textContent=i.text;const n=__spreadValues({},BUTTON_GROUP_STYLE);i.value==="finish"&&Object.assign(n,{color:"white",backgroundColor:"#666fff"}),StyleUtils.setDOMStyle(o,n),e.appendChild(o)}),e}update(t){const{left:e,top:i}=t;!this._toolbarDOM||StyleUtils.setDOMStyle(this._toolbarDOM,{left:`${e}px`,top:`${i}px`})}onClick(t){var e,i;if(t.stopPropagation(),t.preventDefault(),!this.disabled){if((e=this._radioGroupDOM)==null?void 0:e.contains(t.target)){const o=t.target,n=o.getAttribute("value")||o.getAttribute("data-value");n&&this.onToggleClickType(n);return}if((i=this._buttonGroupDOM)==null?void 0:i.contains(t.target)){const n=t.target.getAttribute("data-value");n==="reset"&&this.onReset(),n==="finish"&&this.onFinish()}}}eventBinding(){var t,e;(t=this._toolbarDOM)==null||t.addEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.addEventListener("mouseup",this.onMouseUp)}onMouseUp(t){t.stopPropagation(),t.preventDefault()}eventUnbinding(){var t,e;(t=this._toolbarDOM)==null||t.removeEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.removeEventListener("mouseup",this.onMouseUp)}setDisabled(t){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||t===this.disabled||(this.disabled=t,StyleUtils.setDOMStyle(this._toolbarDOM,{filter:t?"grayscale(100%)":"none",cursor:t?"not-allowed":"default"}),StyleUtils.setDOMStyle(this._radioGroupDOM,{pointerEvents:t?"none":"auto"}),StyleUtils.setDOMStyle(this._buttonGroupDOM,{pointerEvents:t?"none":"auto"}))}onToggle(t){var e;(e=this._radioGroupDOM)==null||e.querySelectorAll("label").forEach(i=>{var o,n;const s=(o=i.querySelector("input"))==null?void 0:o.getAttribute("value");i.setAttribute("class",`ant-radio-wrapper${s===t?" ant-radio-wrapper-checked":""}`),(n=i.querySelector(".ant-radio"))==null||n.setAttribute("class",`ant-radio${s===t?" ant-radio-checked":""}`)})}}const getSAMToolbarOffset=({rect:r,currentPos:t,zoom:e})=>{const i=TOOLBAR_SIZE.height,o=AxisUtils.default.getOffsetCoordinate(r,t,e),n=o.x,s=o.y-i-TOOLBAR_TOP_OFFSET;return{left:n<0?0:n,top:s<0?0:s}};exports.default=SAMToolbarClass,exports.getSAMToolbarOffset=getSAMToolbarOffset;
|
|
9
|
+
>`}),e.innerHTML=i,e}initButtonGroupDOM(){const t=[{text:`${this.i18n.t("Reset")}`,value:"reset"},{text:`${this.i18n.t("Finish")}`,value:"finish"}],e=document.createElement("div");return e.setAttribute("id","LABELBEE_SAM_TOOLBAR_BUTTON_GROUP"),StyleUtils.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center",gap:"8px",flexShrink:0}),t.forEach(i=>{const o=document.createElement("div");o.setAttribute("data-value",i.value),o.textContent=i.text;const n=__spreadValues({},BUTTON_GROUP_STYLE);i.value==="finish"&&Object.assign(n,{color:"white",backgroundColor:"#666fff"}),StyleUtils.setDOMStyle(o,n),e.appendChild(o)}),e}update(t){const{left:e,top:i}=t;!this._toolbarDOM||StyleUtils.setDOMStyle(this._toolbarDOM,{left:`${e}px`,top:`${i}px`})}onClick(t){var e,i;if(t.stopPropagation(),t.preventDefault(),!this.disabled){if((e=this._radioGroupDOM)==null?void 0:e.contains(t.target)){const o=t.target,n=o.getAttribute("value")||o.getAttribute("data-value");n&&this.onToggleClickType(n);return}if((i=this._buttonGroupDOM)==null?void 0:i.contains(t.target)){const n=t.target.getAttribute("data-value");n==="reset"&&this.onReset(),n==="finish"&&this.onFinish()}}}eventBinding(){var t,e;(t=this._toolbarDOM)==null||t.addEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.addEventListener("mouseup",this.onMouseUp)}onMouseUp(t){t.stopPropagation(),t.preventDefault()}eventUnbinding(){var t,e;(t=this._toolbarDOM)==null||t.removeEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.removeEventListener("mouseup",this.onMouseUp)}setDisabled(t){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||t===this.disabled||(this.disabled=t,StyleUtils.setDOMStyle(this._toolbarDOM,{filter:t?"grayscale(100%)":"none",cursor:t?"not-allowed":"default"}),StyleUtils.setDOMStyle(this._radioGroupDOM,{pointerEvents:t?"none":"auto"}),StyleUtils.setDOMStyle(this._buttonGroupDOM,{pointerEvents:t?"none":"auto"}))}onToggle(t){var e;(e=this._radioGroupDOM)==null||e.querySelectorAll("label").forEach(i=>{var o,n;const s=(o=i.querySelector("input"))==null?void 0:o.getAttribute("value");i.setAttribute("class",`ant-radio-wrapper${s===t?" ant-radio-wrapper-checked":""}`),(n=i.querySelector(".ant-radio"))==null||n.setAttribute("class",`ant-radio${s===t?" ant-radio-checked":""}`)})}}const getSAMToolbarOffset=({rect:r,currentPos:t,zoom:e})=>{const i=TOOLBAR_SIZE.height,o=AxisUtils.default.getOffsetCoordinate(r,t,e),n=o.x,s=o.y-i-TOOLBAR_TOP_OFFSET;return{left:n<0?0:n,top:s<0?0:s}};exports.default=SAMToolbarClass,exports.getSAMToolbarOffset=getSAMToolbarOffset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var lbUtils=require("@labelbee/lb-utils"),keyCode=require("../../constant/keyCode.js"),RectUtils=require("../../utils/tool/RectUtils.js"),uuid=require("../../utils/uuid.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),SAMToolbarClass=require("./SAMToolbarClass.js"),segmentByRect=require("./segmentByRect.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(
|
|
1
|
+
"use strict";var lbUtils=require("@labelbee/lb-utils"),keyCode=require("../../constant/keyCode.js"),RectUtils=require("../../utils/tool/RectUtils.js"),uuid=require("../../utils/uuid.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),SAMToolbarClass=require("./SAMToolbarClass.js"),segmentByRect=require("./segmentByRect.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t)),__async=(n,t,e)=>new Promise((i,s)=>{var l=r=>{try{a(e.next(r))}catch(h){s(h)}},o=r=>{try{a(e.throw(r))}catch(h){s(h)}},a=r=>r.done?i(r.value):Promise.resolve(r.value).then(l,o);a((e=e.apply(n,t)).next())});class SegmentBySAM extends segmentByRect{constructor(t){super(t);this.segmentPrediction=e=>__async(this,null,function*(){var i,s,l,o,a,r,h,c;if(this.isRunSegment)return;const u=this.getCoordinateInOrigin(e),p={x:0,y:0,width:(s=(i=this.basicImgInfo)==null?void 0:i.width)!=null?s:0,height:(o=(l=this.basicImgInfo)==null?void 0:l.height)!=null?o:0};if(!RectUtils.isInRect(u,p,0,1)){(a=this.onOutSide)==null||a.call(this);return}if(this.clickType==="add"&&this.addPoints.push([u.x,u.y]),this.clickType==="remove"&&this.removePoints.push([u.x,u.y]),this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}(r=this.toolbarInstance)==null||r.setDisabled(!0);try{const v=yield this.runPrediction({addPoints:this.addPoints,removePoints:this.removePoints,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),f=v==null?void 0:v.filter(d=>{var g;return((g=d==null?void 0:d.pointList)==null?void 0:g.length)>2}).map(d=>__spreadProps(__spreadValues({},d),{id:uuid(),attribute:this.defaultAttribute}));this.predictionResult=f,(h=this.SAMHistory)==null||h.pushHistory(this.predictionResult)}finally{(c=this.toolbarInstance)==null||c.setDisabled(!1),this.isRunSegment=!1}}),this.clickType="add",this.addPoints=[],this.removePoints=[],this.predictionResult=[],this.onOutSide=t.onOutSide,this.onFinish=t.onFinish,this.SAMHistory=new ActionsHistory,this.clearPredictionInfo=this.clearPredictionInfo.bind(this),this.onLanguageChanged=this.onLanguageChanged.bind(this)}onKeydown(t){switch(super.onKeydown(t),t.keyCode){case keyCode.Minus:this.toggleClickType("remove");break;case keyCode.Equal:this.toggleClickType("add");break}}onMouseUp(t){var e;if(t.button===0&&((e=this.rectList)==null?void 0:e.length)){this.segmentPrediction(t);return}super.onMouseUp(t)}eventBinding(){super.eventBinding(),lbUtils.i18n.on("languageChanged",this.onLanguageChanged)}eventUnbinding(){super.eventUnbinding(),lbUtils.i18n.off("languageChanged",this.onLanguageChanged)}setOnOutSide(t){this.onOutSide=t}onMouseDown(t){var e;t.button===0&&((e=this.rectList)==null?void 0:e.length)||super.onMouseDown(t)}onLanguageChanged(){var t;(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,this.renderToolbar()}drawPredictionResult(){var t;const e=this.getColor(this.defaultAttribute);(t=this.predictionResult)==null||t.forEach(i=>{this.drawPolygon(i,e)})}drawPolygon(t,e){var i,s;const l=AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),o=StyleUtils.getStrokeAndFill(e,!0,{isHover:!0});DrawUtils.drawPolygonWithFillAndLine(this.canvas,l,{fillColor:o.fill,strokeColor:o.stroke,thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineType:lbUtils.ELineTypes.Line})}clearPredictionInfo(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,super.clearPredictionInfo(),this.render()}renderToolbar(){const t=this.rectList[0];if(!t)return;this.toolbarInstance||(this.toolbarInstance=new SAMToolbarClass.default({container:this.container,toggleClickType:i=>this.toggleClickType(i),finish:()=>{var i,s;(s=this.onFinish)==null||s.call(this,(i=this.predictionResult)!=null?i:[]),this.clearPredictionInfo()},reset:()=>this.reset(),i18n:lbUtils.i18n}));const e=SAMToolbarClass.getSAMToolbarOffset({rect:t,zoom:this.zoom,currentPos:this.currentPos});this.toolbarInstance.update(e)}toggleClickType(t){var e;this.clickType=t,(e=this.toolbarInstance)==null||e.onToggle(t),this.render()}setDefaultAttribute(t){var e,i;super.setDefaultAttribute(t),this.predictionResult=(i=(e=this.predictionResult)==null?void 0:e.map(s=>__spreadProps(__spreadValues({},s),{attribute:t})))!=null?i:[]}reset(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.SAMHistory)==null||t.empty(),this.render()}cursorText(){var t;let e=`\u2460 ${lbUtils.i18n.t("PleaseFrameTheObjectToBeDividedFirst")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(this.clickType==="add"&&(e=this.addPoints.length===0?`\u2461 ${lbUtils.i18n.t("ClickOnTheTargetObjectToSplitIt")}`:`\u2461 ${lbUtils.i18n.t("ClickTheTargetObjectAgainToIncreaseTheSegmentation")}`),this.clickType==="remove"&&(e=this.removePoints.length===0?`\u2461 ${lbUtils.i18n.t("ClickOnTheTargetObjectToDeleteTheSegmentation")}`:`\u2461 ${lbUtils.i18n.t("ClickAgainOnTheTargetObjectToDeleteTheSegmentation")}`)),this.isRunSegment&&(e=lbUtils.i18n.t("SplittingAlgorithmPrediction")),e}undo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.undo();this.predictionResult=e,this.render()}redo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.redo();this.predictionResult=e,this.render()}render(){var t,e;if(super.render(),(t=this.rectList)==null?void 0:t.length){this.renderToolbar(),this.drawPredictionResult();return}(e=this.toolbarInstance)==null||e.clearToolbarDOM(),this.toolbarInstance=void 0}}module.exports=SegmentBySAM;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),pointCloud2DRectOperation=require("./core/toolOperation/pointCloud2DRectOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),segmentByRect=require("./core/toolOperation/segmentByRect.js"),segmentBySAM=require("./core/toolOperation/segmentBySAM.js"),annotation=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),AttributeUtils=require("./utils/tool/AttributeUtils.js"),ActionsHistory=require("./utils/ActionsHistory.js"),EventBus=require("./utils/EventBus.js"),CanvasUtils=require("./utils/tool/CanvasUtils.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),StyleUtils=require("./utils/tool/StyleUtils.js"),cursorTextClass=require("./core/toolOperation/cursorTextClass.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js"),index$1=require("./core/pointCloud/index.js"),matrix=require("./core/pointCloud/matrix.js"),annotation$1=require("./core/pointCloud/annotation.js");function _interopNamespaceDefaultOnly(e){return Object.freeze({__proto__:null,default:e})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.PointCloud2DRectOperation=pointCloud2DRectOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.SegmentByRect=segmentByRect,exports.SegmentBySAM=segmentBySAM,exports.cAnnotation=annotation,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.CLIENT_TOOL_HEAD_TYPE=tool.CLIENT_TOOL_HEAD_TYPE,exports.CLIENT_TOOL_NAME=tool.CLIENT_TOOL_NAME,exports.DEFAULT_FONT=tool.DEFAULT_FONT,exports.DEFAULT_TEXT_MAX_WIDTH=tool.DEFAULT_TEXT_MAX_WIDTH,Object.defineProperty(exports,"EAnnotationMode",{enumerable:!0,get:function(){return tool.EAnnotationMode}}),Object.defineProperty(exports,"EAudioToolName",{enumerable:!0,get:function(){return tool.EAudioToolName}}),Object.defineProperty(exports,"EAuditStatus",{enumerable:!0,get:function(){return tool.EAuditStatus}}),Object.defineProperty(exports,"ECheckModel",{enumerable:!0,get:function(){return tool.ECheckModel}}),Object.defineProperty(exports,"EDependPattern",{enumerable:!0,get:function(){return tool.EDependPattern}}),Object.defineProperty(exports,"EDragTarget",{enumerable:!0,get:function(){return tool.EDragTarget}}),Object.defineProperty(exports,"EDrawPointPattern",{enumerable:!0,get:function(){return tool.EDrawPointPattern}}),Object.defineProperty(exports,"EFilterToolOperation",{enumerable:!0,get:function(){return tool.EFilterToolOperation}}),Object.defineProperty(exports,"ELineColor",{enumerable:!0,get:function(){return tool.ELineColor}}),Object.defineProperty(exports,"ELineTypes",{enumerable:!0,get:function(){return tool.ELineTypes}}),Object.defineProperty(exports,"EOperationMode",{enumerable:!0,get:function(){return tool.EOperationMode}}),Object.defineProperty(exports,"EPageOperator",{enumerable:!0,get:function(){return tool.EPageOperator}}),Object.defineProperty(exports,"EPointCloudName",{enumerable:!0,get:function(){return tool.EPointCloudName}}),Object.defineProperty(exports,"EPolygonPattern",{enumerable:!0,get:function(){return tool.EPolygonPattern}}),Object.defineProperty(exports,"ERectPattern",{enumerable:!0,get:function(){return tool.ERectPattern}}),Object.defineProperty(exports,"EScribblePattern",{enumerable:!0,get:function(){return tool.EScribblePattern}}),Object.defineProperty(exports,"ESelectedType",{enumerable:!0,get:function(){return tool.ESelectedType}}),Object.defineProperty(exports,"ETextType",{enumerable:!0,get:function(){return tool.ETextType}}),Object.defineProperty(exports,"EThumbnailOption",{enumerable:!0,get:function(){return tool.EThumbnailOption}}),Object.defineProperty(exports,"EToolName",{enumerable:!0,get:function(){return tool.EToolName}}),Object.defineProperty(exports,"EToolType",{enumerable:!0,get:function(){return tool.EToolType}}),Object.defineProperty(exports,"EVideoToolName",{enumerable:!0,get:function(){return tool.EVideoToolName}}),exports.OPERATION_LIST=tool.OPERATION_LIST,exports.SEGMENT_NUMBER=tool.SEGMENT_NUMBER,exports.TEXT_ATTRIBUTE_LINE_HEIGHT=tool.TEXT_ATTRIBUTE_LINE_HEIGHT,exports.TEXT_ATTRIBUTE_MAX_LENGTH=tool.TEXT_ATTRIBUTE_MAX_LENGTH,exports.TEXT_TYPE=tool.TEXT_TYPE,exports.TOOL_NAME=tool.TOOL_NAME,exports.TOOL_NAME_EN=tool.TOOL_NAME_EN,exports.cTool=tool,exports.edgeAdsorptionScope=tool.edgeAdsorptionScope,exports.editStepWidth=tool.editStepWidth,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils.default,exports.MathUtils=MathUtils.default,exports.AttributeUtils=AttributeUtils.default,exports.ActionsHistory=ActionsHistory,exports.EventBus=EventBus,exports.CanvasUtils=CanvasUtils,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.UnitUtils=UnitUtils,exports.StyleUtils=StyleUtils,exports.CursorTextClass=cursorTextClass,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.PointCloud=index$1.PointCloud,exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloudAnnotation=annotation$1.PointCloudAnnotation,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),pointCloud2DRectOperation=require("./core/toolOperation/pointCloud2DRectOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),segmentByRect=require("./core/toolOperation/segmentByRect.js"),segmentBySAM=require("./core/toolOperation/segmentBySAM.js"),annotation=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),AttributeUtils=require("./utils/tool/AttributeUtils.js"),ActionsHistory=require("./utils/ActionsHistory.js"),EventBus=require("./utils/EventBus.js"),CanvasUtils=require("./utils/tool/CanvasUtils.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),StyleUtils=require("./utils/tool/StyleUtils.js"),cursorTextClass=require("./core/toolOperation/cursorTextClass.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js"),index$1=require("./core/pointCloud/index.js"),matrix=require("./core/pointCloud/matrix.js"),annotation$1=require("./core/pointCloud/annotation.js");function _interopNamespaceDefaultOnly(e){return Object.freeze({__proto__:null,default:e})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.PointCloud2DRectOperation=pointCloud2DRectOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.SegmentByRect=segmentByRect,exports.SegmentBySAM=segmentBySAM,exports.cAnnotation=annotation,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.CLIENT_TOOL_HEAD_TYPE=tool.CLIENT_TOOL_HEAD_TYPE,exports.CLIENT_TOOL_NAME=tool.CLIENT_TOOL_NAME,exports.DEFAULT_FONT=tool.DEFAULT_FONT,exports.DEFAULT_TEXT_MAX_WIDTH=tool.DEFAULT_TEXT_MAX_WIDTH,Object.defineProperty(exports,"EAnnotationMode",{enumerable:!0,get:function(){return tool.EAnnotationMode}}),Object.defineProperty(exports,"EAudioToolName",{enumerable:!0,get:function(){return tool.EAudioToolName}}),Object.defineProperty(exports,"EAuditStatus",{enumerable:!0,get:function(){return tool.EAuditStatus}}),Object.defineProperty(exports,"ECheckModel",{enumerable:!0,get:function(){return tool.ECheckModel}}),Object.defineProperty(exports,"EDependPattern",{enumerable:!0,get:function(){return tool.EDependPattern}}),Object.defineProperty(exports,"EDragTarget",{enumerable:!0,get:function(){return tool.EDragTarget}}),Object.defineProperty(exports,"EDrawPointPattern",{enumerable:!0,get:function(){return tool.EDrawPointPattern}}),Object.defineProperty(exports,"EFilterToolOperation",{enumerable:!0,get:function(){return tool.EFilterToolOperation}}),Object.defineProperty(exports,"ELineColor",{enumerable:!0,get:function(){return tool.ELineColor}}),Object.defineProperty(exports,"ELineTypes",{enumerable:!0,get:function(){return tool.ELineTypes}}),Object.defineProperty(exports,"EOperationMode",{enumerable:!0,get:function(){return tool.EOperationMode}}),Object.defineProperty(exports,"EPageOperator",{enumerable:!0,get:function(){return tool.EPageOperator}}),Object.defineProperty(exports,"EPointCloudName",{enumerable:!0,get:function(){return tool.EPointCloudName}}),Object.defineProperty(exports,"EPolygonPattern",{enumerable:!0,get:function(){return tool.EPolygonPattern}}),Object.defineProperty(exports,"ERectPattern",{enumerable:!0,get:function(){return tool.ERectPattern}}),Object.defineProperty(exports,"EScribblePattern",{enumerable:!0,get:function(){return tool.EScribblePattern}}),Object.defineProperty(exports,"ESelectedType",{enumerable:!0,get:function(){return tool.ESelectedType}}),Object.defineProperty(exports,"ETextType",{enumerable:!0,get:function(){return tool.ETextType}}),Object.defineProperty(exports,"EThumbnailOption",{enumerable:!0,get:function(){return tool.EThumbnailOption}}),Object.defineProperty(exports,"EToolName",{enumerable:!0,get:function(){return tool.EToolName}}),Object.defineProperty(exports,"EToolType",{enumerable:!0,get:function(){return tool.EToolType}}),Object.defineProperty(exports,"EVideoToolName",{enumerable:!0,get:function(){return tool.EVideoToolName}}),exports.OPERATION_LIST=tool.OPERATION_LIST,exports.SEGMENT_NUMBER=tool.SEGMENT_NUMBER,exports.TEXT_ATTRIBUTE_LINE_HEIGHT=tool.TEXT_ATTRIBUTE_LINE_HEIGHT,exports.TEXT_ATTRIBUTE_MAX_LENGTH=tool.TEXT_ATTRIBUTE_MAX_LENGTH,exports.TEXT_TYPE=tool.TEXT_TYPE,exports.TOOL_NAME=tool.TOOL_NAME,exports.TOOL_NAME_EN=tool.TOOL_NAME_EN,exports.cTool=tool,exports.edgeAdsorptionScope=tool.edgeAdsorptionScope,exports.editStepWidth=tool.editStepWidth,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils.default,exports.MathUtils=MathUtils.default,exports.AttributeUtils=AttributeUtils.default,exports.ActionsHistory=ActionsHistory,exports.EventBus=EventBus,exports.CanvasUtils=CanvasUtils,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.UnitUtils=UnitUtils,exports.StyleUtils=StyleUtils,exports.CursorTextClass=cursorTextClass,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.PointCloud=index$1.PointCloud,exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloudAnnotation=annotation$1.PointCloudAnnotation,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The set of Matrix multiplication
|
|
3
3
|
*/
|
|
4
4
|
import * as THREE from 'three';
|
|
5
|
-
import { TMatrix4Tuple, IPointCloudBox, I3DSpaceCoord, TMatrix14Tuple, TMatrix13Tuple, IPolygonPoint, ICalib, IBasicBox3d } from '@labelbee/lb-utils';
|
|
5
|
+
import { TMatrix4Tuple, IPointCloudBox, I3DSpaceCoord, TMatrix14Tuple, TMatrix13Tuple, IPolygonPoint, ICalib, IBasicBox3d, ICoordinate } from '@labelbee/lb-utils';
|
|
6
6
|
export declare function createThreeMatrix4(matrix4: TMatrix4Tuple): THREE.Matrix4;
|
|
7
7
|
/**
|
|
8
8
|
* Transfer the Kitti format (defined by array) to Three Matrix (flatten array)
|
|
@@ -68,7 +68,7 @@ export declare function getCuboidFromPointCloudBox(boxParams: IPointCloudBox): {
|
|
|
68
68
|
[k: string]: string;
|
|
69
69
|
} | undefined;
|
|
70
70
|
count?: number | undefined;
|
|
71
|
-
newPointList?:
|
|
71
|
+
newPointList?: ICoordinate[] | undefined;
|
|
72
72
|
rects?: import("@labelbee/lb-utils").IPointCloudBoxRect[] | undefined;
|
|
73
73
|
width: number;
|
|
74
74
|
height: number;
|
|
@@ -128,3 +128,7 @@ export declare function pointMappingLidar2image(points: Float32Array, calib: ICa
|
|
|
128
128
|
};
|
|
129
129
|
};
|
|
130
130
|
} | undefined;
|
|
131
|
+
export declare function pointListLidar2Img(pointList3D: I3DSpaceCoord[], calib?: ICalib, filterSize?: {
|
|
132
|
+
width: number;
|
|
133
|
+
height: number;
|
|
134
|
+
}): ICoordinate[] | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as b,PointCloudUtils as F,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,
|
|
1
|
+
import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as b,PointCloudUtils as F,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,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,L=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,C=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&L(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&L(w,e,t[e]);return w},S=(w,t)=>tt(w,et(t)),z=(w,t,e)=>new Promise((i,r)=>{var s=d=>{try{o(e.next(d))}catch(n){r(n)}},h=d=>{try{o(e.throw(d))}catch(n){r(n)}},o=d=>d.done?i(d.value):Promise.resolve(d.value).then(s,h);o((e=e.apply(w,t)).next())});const nt=30,k=new E({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:d}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,l="blue")=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"sphere");const{radius:u,widthSegments:f,heightSegments:p}=O,{center:g}=n,y=new a.Group,x=new a.SphereGeometry(u,f,p),M=new a.MeshBasicMaterial({color:l}),P=new a.Mesh(x,M);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l),this.render()},this.generateSpheres=n=>{n.forEach(l=>{const{fill:c}=this.getColorFromConfig(l.attribute);this.addSphereToSense(l,c)}),this.render()},this.addBoxToSense=(n,l=16777215)=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"box");const{center:u,width:f,height:p,depth:g,rotation:y}=n,x=new a.Group,M=new a.BoxGeometry(f,p,g),P=new a.MeshBasicMaterial({color:"blue"}),B=new a.Mesh(M,P),_=new a.BoxHelper(B,l),N=this.generateBoxArrow(n),D=this.generateBoxTrackID(n);D&&x.add(D),x.add(_),x.add(N),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${m}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const l=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,l)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
2
2
|
attribute vec3 dimensions;
|
|
3
3
|
varying vec3 vDimensions;
|
|
4
4
|
uniform float pointSize;
|
|
@@ -28,4 +28,4 @@ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(m);const p=new a.Points(f);this.renderPointCloud(p,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:l,points:c}){const m=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),u=l.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=$({points:c,calib:p.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return Y(u)}),this.loadPCDFileByBox=(n,l,c)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=c!=null?c:{},P=yield this.filterPointsByBox(S(C({},l),{width:l.width+y,height:l.height+x,depth:l.depth+M}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:u,color:f}=yield this.cacheInstance.loadPCDFile(n);m(u,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(l,c,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),m=new a.Sprite(c);return m.scale.set(5,5,5),m.position.set(-n.width/2,0,n.depth/2+.5),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const m=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(m*1.2,10):c.material.uniforms.pointSize.value=Math.max(m/1.2,1),l&&(c.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new X(C({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(S(C({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return C({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(C({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,c=-100,m=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=A(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(m=>{const u=new V;u.postMessage(c),u.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,s=nt){let h=v.frontViewMatrix4(s);switch(r){case b.Front:break;case b.Back:h=v.backViewMatrix4(s);break;case b.Left:h=v.leftViewMatrix4(s);break;case b.Right:h=v.rightViewMatrix4(s);break;case b.Top:h=v.topViewMatrix4(s);break;case b.LFT:h=v.leftFrontTopViewMatrix4(s,i);break;case b.RBT:h=v.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(l=>A(l)),d=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(n),L.onmessage=l=>{const{color:c}=l.data,m=new a.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=T.getColorFromConfig({attribute:i.attribute},S(C({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(o,d,n),u=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(l),m.translate(r,s,h);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(o/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((c,m)=>c.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((c,m)=>c.x-m.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((c,m)=>c.y-m.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,c)=>{const m=r[c+1],u=H.getFootOfPerpendicular({x:d,y:n},l,m,!1,!0).length;(!i[c]||u<i[c].distance)&&(i[c]={distance:u,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],m=r[n+2];return F.getIntersectionBySlope({p1:s[n].point,line1:[l,c],p2:s[n+1].point,line2:[c,m]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,m=[],u=[];const f=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];R({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),m=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),d=u[0].z-.01,n=u[u.length-1].z+.01,c=u.length,e&&(l=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}):{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},l={x:e-h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},l={x:e-h/2,y:i-s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},l={x:e-h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case b.Left:return this.getPolygonSidePoints(t);case b.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new a.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),m=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[d,n,l,c]=o,m=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(C({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(m);const p=new a.Points(f);this.renderPointCloud(p,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:l,points:c}){const m=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),u=l.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=$({points:c,calib:p.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return Y(u)}),this.loadPCDFileByBox=(n,l,c)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=c!=null?c:{},P=yield this.filterPointsByBox(S(C({},l),{width:l.width+y,height:l.height+x,depth:l.depth+M}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:u,color:f}=yield this.cacheInstance.loadPCDFile(n);m(u,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(l,c,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),m=new a.Sprite(c);return m.scale.set(5,5,5),m.position.set(-n.width/2,0,n.depth/2+.5),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const m=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(m*1.2,10):c.material.uniforms.pointSize.value=Math.max(m/1.2,1),l&&(c.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new X(C({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(S(C({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return C({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(C({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,c=-100,m=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=A(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(m=>{const u=new V;u.postMessage(c),u.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,s=nt){let h=v.frontViewMatrix4(s);switch(r){case b.Front:break;case b.Back:h=v.backViewMatrix4(s);break;case b.Left:h=v.leftViewMatrix4(s);break;case b.Right:h=v.rightViewMatrix4(s);break;case b.Top:h=v.topViewMatrix4(s);break;case b.LFT:h=v.leftFrontTopViewMatrix4(s,i);break;case b.RBT:h=v.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(l=>A(l)),d=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};k.postMessage(n),k.onmessage=l=>{const{color:c}=l.data,m=new a.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=T.getColorFromConfig({attribute:i.attribute},S(C({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(o,d,n),u=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(l),m.translate(r,s,h);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(o/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((c,m)=>c.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((c,m)=>c.x-m.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((c,m)=>c.y-m.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,c)=>{const m=r[c+1],u=H.getFootOfPerpendicular({x:d,y:n},l,m,!1,!0).length;(!i[c]||u<i[c].distance)&&(i[c]={distance:u,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],m=r[n+2];return F.getIntersectionBySlope({p1:s[n].point,line1:[l,c],p2:s[n+1].point,line2:[c,m]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,m=[],u=[];const f=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];R({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),m=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),d=u[0].z-.01,n=u[u.length-1].z+.01,c=u.length,e&&(l=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}):{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},l={x:e-h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},l={x:e-h/2,y:i-s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},l={x:e-h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case b.Left:return this.getPolygonSidePoints(t);case b.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new a.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),m=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[d,n,l,c]=o,m=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(C({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as y from"three";import{MatrixUtils as M,PointCloudUtils as D}from"@labelbee/lb-utils";import H from"../../utils/uuid.js";var E=Object.defineProperty,j=Object.defineProperties,K=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,_=Math.pow,z=(r,t,e)=>t in r?E(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,C=(r,t)=>{for(var e in t||(t={}))k.call(t,e)&&z(r,e,t[e]);if(I)for(var e of I(t))A.call(t,e)&&z(r,e,t[e]);return r},R=(r,t)=>j(r,K(t));function g(r){return new y.Matrix4().set(...r)}function v(r,t,e){try{const n=M.transferMatrix34FromKitti2Three(r),o=M.transferMatrix33FromKitti2Three(t),i=M.transferMatrix34FromKitti2Three(e),l=g(n),f=g(o),a=g(i);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function T(r,t,e){var n;const o=new y.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),i=new y.Matrix4().makeRotationZ(e),l=new y.Matrix4().makeTranslation(t.x,t.y,t.z),f=new y.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return o.clone().applyMatrix4(f).applyMatrix4(i).applyMatrix4(l)}function L(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const m=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&L(r.P,3,4)&&L(r.T,3,4))},w=(r,t)=>{if(m(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:o}=t,i=new y.Vector4(r.x,r.y,r.z),l=g(M.transferMatrix34FromKitti2Three(o)),f=g(M.transferMatrix34FromKitti2Three(e)),a=i.applyMatrix4(l),x=_(_(a.x,2)+_(a.y,2),.5),h=Math.atan(a.z/x),s=n.reduce((u,c,d)=>u+c*_(h,d),0);return a.x=a.x/x*s,a.y=a.y/x*s,a.z=1,a.applyMatrix4(f)};function P(r,t){const n=new y.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const o=1/n.z,i=new y.Matrix4().set(o,0,0,0,0,o,0,0,0,0,o,0,0,0,0,1);return n.applyMatrix4(i)}function B(r){const{center:t,width:e,height:n,depth:o,rotation:i}=r,l=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(x=>{const h=T(x,t,i);return{x:h.x,y:h.y}}),f=t.z+o/2,a=t.z-o/2;return R(C({},r),{polygonPointList:l,zMax:f,zMin:a})}function U(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function F(r,t,e){const n=t.x-r.x,o=t.y-r.y,i=e.x-r.x,l=e.y-r.y;return n*l-i*o}function N(r){const t=U(r),e=[];for(let i=0;i<t.length;i++){for(;e.length>=2&&F(e[e.length-2],e[e.length-1],t[i])<=0;)e.pop();e.push(t[i])}const n=[];for(let i=t.length-1;i>=0;i--){for(;n.length>=2&&F(n[n.length-2],n[n.length-1],t[i])<=0;)n.pop();n.push(t[i])}return e.pop(),n.pop(),e.concat(n)}const O=(r,t)=>{var e;if(m(t))return w(r,t);const{P:n,R:o,T:i}=t,{composeMatrix4:l}=(e=v(n,o,i))!=null?e:{};if(!!l)return P(r,l)},V=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const o=O(r,t);return o?o.x>=0&&o.x<=e&&o.y>=0&&o.y<=n:!1},Z=({points:r,calib:t,width:e,height:n})=>{const o=[];for(let i=0;i<r.length;i+=3){const l=r[i],f=r[i+1],a=r[i+2];V({point:{x:l,y:f,z:a},calib:t,width:e,height:n})?o.push(1):o.push(0)}return o},q=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function G(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:o}=e,i=D.getAllViewData(r),l=m(t),{P:f,R:a,T:x}=t;let h;if(l===!1){const{composeMatrix4:u}=(n=v(f,a,x))!=null?n:{};if(!u)return;h=u}const s=i.map(u=>({type:u.type,pointList:u.pointList.map(c=>T(c,r.center,r.rotation)).map(c=>l?w(c,t):h&&P(c,h)).map(c=>{if(!!c)return{id:H(),x:c==null?void 0:c.x,y:c==null?void 0:c.y}}).filter(c=>c!==void 0)})).filter(u=>u.pointList.length!==0);s[0]&&s[0].pointList&&l&&(s[0].pointList=s[0].pointList.map(u=>R(C({},u),{specialEdge:!0})));let p=[];if(s.length===6&&o===!0){const u=s[0].pointList,c=s[1].pointList;p=N([...u,...c])}return{transferViewData:s,viewRangePointList:p}}function J(r,t,e){var n;const o=m(t),{P:i,R:l,T:f}=t;let a;if(o===!1){const{composeMatrix4:s}=(n=v(i,l,f))!=null?n:{};if(!s)return;a=s}const x=r.length/3,h={};for(let s=0;s<x;s++){const p={x:r[s*3],y:r[s*3+1],z:r[s*3+2]};let u;if(o?u=w(p,t):u=a&&P({x:r[s*3],y:r[s*3+1],z:r[s*3+2]},a),u){const c=Math.floor(u.x),d=Math.floor(u.y);if(c>e.width||d>e.height||c<0||d<0)continue;h[s]={x:c,y:d}}}return{pcdMapping:h}}function Q(r,t,e){var n;if(!t||!e)return;const o=m(t),{P:i,R:l,T:f}=t;let a;if(o===!1){const{composeMatrix4:s}=(n=v(i,l,f))!=null?n:{};if(!s)return;a=s}const x=[];if(r.forEach(s=>{let p;if(o?p=w(s,t):p=a&&P(s,a),p){const{x:u,y:c}=p;x.push({x:u,y:c})}}),x.some(s=>s.x>0&&s.x<e.width&&s.y>0&&s.y<e.height))return x}export{g as createThreeMatrix4,B as getCuboidFromPointCloudBox,Z as getHighlightIndexByPoints,m as isFisheyeCalibValid,V as isInImage,L as isMatrixValid,w as lidar2FisheyeImage,P as lidar2image,q as mergeHighlightList,O as point3DLidar2Image,G as pointCloudLidar2image,Q as pointListLidar2Img,J as pointMappingLidar2image,T as rotatePoint,v as transferKitti2Matrix};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import d from"../../utils/tool/AxisUtils.js";import s from"../../utils/tool/StyleUtils.js";var h=Object.defineProperty,l=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,u=(r,t,e)=>t in r?h(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,_=(r,t)=>{for(var e in t||(t={}))c.call(t,e)&&u(r,e,t[e]);if(l)for(var e of l(t))O.call(t,e)&&u(r,e,t[e]);return r};const p={height:38},f=8,v={height:"22px",border:"1px solid #666fff",color:"#666fff",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",borderRadius:"4px",padding:"0 8px"};class b{constructor(t){const{container:e,toggleClickType:i,finish:o,reset:n,i18n:a}=t;this.container=e,this.onToggleClickType=i,this.onFinish=o,this.onReset=n,this.disabled=!1,this.i18n=a,this._toolbarDOM=this.initToolbarDOM(),this._radioGroupDOM=this.initRadioGroupDOM(),this._buttonGroupDOM=this.initButtonGroupDOM(),this.appendToContainer(),this.onClick=this.onClick.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.eventBinding(),this.onToggle("add")}appendToContainer(){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||(this.container.appendChild(this._toolbarDOM),this._toolbarDOM.appendChild(this._radioGroupDOM),this._toolbarDOM.appendChild(this._buttonGroupDOM))}clearToolbarDOM(){this._toolbarDOM&&this.container.contains(this._toolbarDOM)&&(this.eventUnbinding(),this.container.removeChild(this._toolbarDOM))}initToolbarDOM(){const t=document.createElement("div");return t.setAttribute("id","LABELBEE_SAM_TOOLBAR"),s.setDOMStyle(t,{display:"flex",position:"absolute",fontSize:"14px",height:`${p.height}px`,padding:"0 8px",borderRadius:"4px",backgroundColor:"#FFFFFF",zIndex:"10"}),t}initRadioGroupDOM(){const t=[{text:`${this.i18n.t("AddPoints")}(+)`,value:"add"},{text:`${this.i18n.t("RemovePoints")}(-)`,value:"remove"}],e=document.createElement("div");e.setAttribute("id","LABELBEE_SAM_TOOLBAR_RADIO_GROUP"),s.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center"});let i="";return t.forEach(o=>{i+=`<label class="ant-radio-wrapper"
|
|
1
|
+
import d from"../../utils/tool/AxisUtils.js";import s from"../../utils/tool/StyleUtils.js";var h=Object.defineProperty,l=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,u=(r,t,e)=>t in r?h(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,_=(r,t)=>{for(var e in t||(t={}))c.call(t,e)&&u(r,e,t[e]);if(l)for(var e of l(t))O.call(t,e)&&u(r,e,t[e]);return r};const p={height:38},f=8,v={height:"22px",border:"1px solid #666fff",color:"#666fff",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",borderRadius:"4px",padding:"0 8px"};class b{constructor(t){const{container:e,toggleClickType:i,finish:o,reset:n,i18n:a}=t;this.container=e,this.onToggleClickType=i,this.onFinish=o,this.onReset=n,this.disabled=!1,this.i18n=a,this._toolbarDOM=this.initToolbarDOM(),this._radioGroupDOM=this.initRadioGroupDOM(),this._buttonGroupDOM=this.initButtonGroupDOM(),this.appendToContainer(),this.onClick=this.onClick.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.eventBinding(),this.onToggle("add")}appendToContainer(){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||(this.container.appendChild(this._toolbarDOM),this._toolbarDOM.appendChild(this._radioGroupDOM),this._toolbarDOM.appendChild(this._buttonGroupDOM))}clearToolbarDOM(){this._toolbarDOM&&this.container.contains(this._toolbarDOM)&&(this.eventUnbinding(),this.container.removeChild(this._toolbarDOM))}initToolbarDOM(){const t=document.createElement("div");return t.setAttribute("id","LABELBEE_SAM_TOOLBAR"),s.setDOMStyle(t,{display:"flex",position:"absolute",fontSize:"14px",height:`${p.height}px`,padding:"0 8px",borderRadius:"4px",backgroundColor:"#FFFFFF",zIndex:"10"}),t}initRadioGroupDOM(){const t=[{text:`${this.i18n.t("AddPoints")}(+)`,value:"add"},{text:`${this.i18n.t("RemovePoints")}(-)`,value:"remove"}],e=document.createElement("div");e.setAttribute("id","LABELBEE_SAM_TOOLBAR_RADIO_GROUP"),s.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center",flexShrink:0});let i="";return t.forEach(o=>{i+=`<label class="ant-radio-wrapper"
|
|
2
2
|
><span class="ant-radio"
|
|
3
3
|
><input
|
|
4
4
|
class="ant-radio-input"
|
|
@@ -6,4 +6,4 @@ import d from"../../utils/tool/AxisUtils.js";import s from"../../utils/tool/Styl
|
|
|
6
6
|
value="${o.value}"
|
|
7
7
|
checked="" /><span class="ant-radio-inner"></span></span
|
|
8
8
|
><span data-value="${o.value}">${o.text}</span></label
|
|
9
|
-
>`}),e.innerHTML=i,e}initButtonGroupDOM(){const t=[{text:`${this.i18n.t("Reset")}`,value:"reset"},{text:`${this.i18n.t("Finish")}`,value:"finish"}],e=document.createElement("div");return e.setAttribute("id","LABELBEE_SAM_TOOLBAR_BUTTON_GROUP"),s.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center",gap:"8px"}),t.forEach(i=>{const o=document.createElement("div");o.setAttribute("data-value",i.value),o.textContent=i.text;const n=_({},v);i.value==="finish"&&Object.assign(n,{color:"white",backgroundColor:"#666fff"}),s.setDOMStyle(o,n),e.appendChild(o)}),e}update(t){const{left:e,top:i}=t;!this._toolbarDOM||s.setDOMStyle(this._toolbarDOM,{left:`${e}px`,top:`${i}px`})}onClick(t){var e,i;if(t.stopPropagation(),t.preventDefault(),!this.disabled){if((e=this._radioGroupDOM)==null?void 0:e.contains(t.target)){const o=t.target,n=o.getAttribute("value")||o.getAttribute("data-value");n&&this.onToggleClickType(n);return}if((i=this._buttonGroupDOM)==null?void 0:i.contains(t.target)){const n=t.target.getAttribute("data-value");n==="reset"&&this.onReset(),n==="finish"&&this.onFinish()}}}eventBinding(){var t,e;(t=this._toolbarDOM)==null||t.addEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.addEventListener("mouseup",this.onMouseUp)}onMouseUp(t){t.stopPropagation(),t.preventDefault()}eventUnbinding(){var t,e;(t=this._toolbarDOM)==null||t.removeEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.removeEventListener("mouseup",this.onMouseUp)}setDisabled(t){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||t===this.disabled||(this.disabled=t,s.setDOMStyle(this._toolbarDOM,{filter:t?"grayscale(100%)":"none",cursor:t?"not-allowed":"default"}),s.setDOMStyle(this._radioGroupDOM,{pointerEvents:t?"none":"auto"}),s.setDOMStyle(this._buttonGroupDOM,{pointerEvents:t?"none":"auto"}))}onToggle(t){var e;(e=this._radioGroupDOM)==null||e.querySelectorAll("label").forEach(i=>{var o,n;const a=(o=i.querySelector("input"))==null?void 0:o.getAttribute("value");i.setAttribute("class",`ant-radio-wrapper${a===t?" ant-radio-wrapper-checked":""}`),(n=i.querySelector(".ant-radio"))==null||n.setAttribute("class",`ant-radio${a===t?" ant-radio-checked":""}`)})}}const M=({rect:r,currentPos:t,zoom:e})=>{const i=p.height,o=d.getOffsetCoordinate(r,t,e),n=o.x,a=o.y-i-f;return{left:n<0?0:n,top:a<0?0:a}};export{b as default,M as getSAMToolbarOffset};
|
|
9
|
+
>`}),e.innerHTML=i,e}initButtonGroupDOM(){const t=[{text:`${this.i18n.t("Reset")}`,value:"reset"},{text:`${this.i18n.t("Finish")}`,value:"finish"}],e=document.createElement("div");return e.setAttribute("id","LABELBEE_SAM_TOOLBAR_BUTTON_GROUP"),s.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center",gap:"8px",flexShrink:0}),t.forEach(i=>{const o=document.createElement("div");o.setAttribute("data-value",i.value),o.textContent=i.text;const n=_({},v);i.value==="finish"&&Object.assign(n,{color:"white",backgroundColor:"#666fff"}),s.setDOMStyle(o,n),e.appendChild(o)}),e}update(t){const{left:e,top:i}=t;!this._toolbarDOM||s.setDOMStyle(this._toolbarDOM,{left:`${e}px`,top:`${i}px`})}onClick(t){var e,i;if(t.stopPropagation(),t.preventDefault(),!this.disabled){if((e=this._radioGroupDOM)==null?void 0:e.contains(t.target)){const o=t.target,n=o.getAttribute("value")||o.getAttribute("data-value");n&&this.onToggleClickType(n);return}if((i=this._buttonGroupDOM)==null?void 0:i.contains(t.target)){const n=t.target.getAttribute("data-value");n==="reset"&&this.onReset(),n==="finish"&&this.onFinish()}}}eventBinding(){var t,e;(t=this._toolbarDOM)==null||t.addEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.addEventListener("mouseup",this.onMouseUp)}onMouseUp(t){t.stopPropagation(),t.preventDefault()}eventUnbinding(){var t,e;(t=this._toolbarDOM)==null||t.removeEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.removeEventListener("mouseup",this.onMouseUp)}setDisabled(t){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||t===this.disabled||(this.disabled=t,s.setDOMStyle(this._toolbarDOM,{filter:t?"grayscale(100%)":"none",cursor:t?"not-allowed":"default"}),s.setDOMStyle(this._radioGroupDOM,{pointerEvents:t?"none":"auto"}),s.setDOMStyle(this._buttonGroupDOM,{pointerEvents:t?"none":"auto"}))}onToggle(t){var e;(e=this._radioGroupDOM)==null||e.querySelectorAll("label").forEach(i=>{var o,n;const a=(o=i.querySelector("input"))==null?void 0:o.getAttribute("value");i.setAttribute("class",`ant-radio-wrapper${a===t?" ant-radio-wrapper-checked":""}`),(n=i.querySelector(".ant-radio"))==null||n.setAttribute("class",`ant-radio${a===t?" ant-radio-checked":""}`)})}}const M=({rect:r,currentPos:t,zoom:e})=>{const i=p.height,o=d.getOffsetCoordinate(r,t,e),n=o.x,a=o.y-i-f;return{left:n<0?0:n,top:a<0?0:a}};export{b as default,M as getSAMToolbarOffset};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i18n as r,ELineTypes as
|
|
1
|
+
import{i18n as r,ELineTypes as O}from"@labelbee/lb-utils";import f from"../../constant/keyCode.js";import S from"../../utils/tool/RectUtils.js";import w from"../../utils/uuid.js";import I from"../../utils/tool/DrawUtils.js";import C from"../../utils/tool/AxisUtils.js";import R from"../../utils/tool/StyleUtils.js";import A from"../../utils/ActionsHistory.js";import k,{getSAMToolbarOffset as L}from"./SAMToolbarClass.js";import j from"./segmentByRect.js";var M=Object.defineProperty,D=Object.defineProperties,U=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,y=(o,t,e)=>t in o?M(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,b=(o,t)=>{for(var e in t||(t={}))x.call(t,e)&&y(o,e,t[e]);if(m)for(var e of m(t))H.call(t,e)&&y(o,e,t[e]);return o},P=(o,t)=>D(o,U(t)),B=(o,t,e)=>new Promise((i,s)=>{var a=n=>{try{h(e.next(n))}catch(d){s(d)}},l=n=>{try{h(e.throw(n))}catch(d){s(d)}},h=n=>n.done?i(n.value):Promise.resolve(n.value).then(a,l);h((e=e.apply(o,t)).next())});class E extends j{constructor(t){super(t);this.segmentPrediction=e=>B(this,null,function*(){var i,s,a,l,h,n,d,g;if(this.isRunSegment)return;const u=this.getCoordinateInOrigin(e),_={x:0,y:0,width:(s=(i=this.basicImgInfo)==null?void 0:i.width)!=null?s:0,height:(l=(a=this.basicImgInfo)==null?void 0:a.height)!=null?l:0};if(!S.isInRect(u,_,0,1)){(h=this.onOutSide)==null||h.call(this);return}if(this.clickType==="add"&&this.addPoints.push([u.x,u.y]),this.clickType==="remove"&&this.removePoints.push([u.x,u.y]),this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}(n=this.toolbarInstance)==null||n.setDisabled(!0);try{const v=yield this.runPrediction({addPoints:this.addPoints,removePoints:this.removePoints,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),T=v==null?void 0:v.filter(c=>{var p;return((p=c==null?void 0:c.pointList)==null?void 0:p.length)>2}).map(c=>P(b({},c),{id:w(),attribute:this.defaultAttribute}));this.predictionResult=T,(d=this.SAMHistory)==null||d.pushHistory(this.predictionResult)}finally{(g=this.toolbarInstance)==null||g.setDisabled(!1),this.isRunSegment=!1}}),this.clickType="add",this.addPoints=[],this.removePoints=[],this.predictionResult=[],this.onOutSide=t.onOutSide,this.onFinish=t.onFinish,this.SAMHistory=new A,this.clearPredictionInfo=this.clearPredictionInfo.bind(this),this.onLanguageChanged=this.onLanguageChanged.bind(this)}onKeydown(t){switch(super.onKeydown(t),t.keyCode){case f.Minus:this.toggleClickType("remove");break;case f.Equal:this.toggleClickType("add");break}}onMouseUp(t){var e;if(t.button===0&&((e=this.rectList)==null?void 0:e.length)){this.segmentPrediction(t);return}super.onMouseUp(t)}eventBinding(){super.eventBinding(),r.on("languageChanged",this.onLanguageChanged)}eventUnbinding(){super.eventUnbinding(),r.off("languageChanged",this.onLanguageChanged)}setOnOutSide(t){this.onOutSide=t}onMouseDown(t){var e;t.button===0&&((e=this.rectList)==null?void 0:e.length)||super.onMouseDown(t)}onLanguageChanged(){var t;(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,this.renderToolbar()}drawPredictionResult(){var t;const e=this.getColor(this.defaultAttribute);(t=this.predictionResult)==null||t.forEach(i=>{this.drawPolygon(i,e)})}drawPolygon(t,e){var i,s;const a=C.changePointListByZoom(t.pointList,this.zoom,this.currentPos),l=R.getStrokeAndFill(e,!0,{isHover:!0});I.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:l.fill,strokeColor:l.stroke,thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineType:O.Line})}clearPredictionInfo(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,super.clearPredictionInfo(),this.render()}renderToolbar(){const t=this.rectList[0];if(!t)return;this.toolbarInstance||(this.toolbarInstance=new k({container:this.container,toggleClickType:i=>this.toggleClickType(i),finish:()=>{var i,s;(s=this.onFinish)==null||s.call(this,(i=this.predictionResult)!=null?i:[]),this.clearPredictionInfo()},reset:()=>this.reset(),i18n:r}));const e=L({rect:t,zoom:this.zoom,currentPos:this.currentPos});this.toolbarInstance.update(e)}toggleClickType(t){var e;this.clickType=t,(e=this.toolbarInstance)==null||e.onToggle(t),this.render()}setDefaultAttribute(t){var e,i;super.setDefaultAttribute(t),this.predictionResult=(i=(e=this.predictionResult)==null?void 0:e.map(s=>P(b({},s),{attribute:t})))!=null?i:[]}reset(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.SAMHistory)==null||t.empty(),this.render()}cursorText(){var t;let e=`\u2460 ${r.t("PleaseFrameTheObjectToBeDividedFirst")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(this.clickType==="add"&&(e=this.addPoints.length===0?`\u2461 ${r.t("ClickOnTheTargetObjectToSplitIt")}`:`\u2461 ${r.t("ClickTheTargetObjectAgainToIncreaseTheSegmentation")}`),this.clickType==="remove"&&(e=this.removePoints.length===0?`\u2461 ${r.t("ClickOnTheTargetObjectToDeleteTheSegmentation")}`:`\u2461 ${r.t("ClickAgainOnTheTargetObjectToDeleteTheSegmentation")}`)),this.isRunSegment&&(e=r.t("SplittingAlgorithmPrediction")),e}undo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.undo();this.predictionResult=e,this.render()}redo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.redo();this.predictionResult=e,this.render()}render(){var t,e;if(super.render(),(t=this.rectList)==null?void 0:t.length){this.renderToolbar(),this.drawPredictionResult();return}(e=this.toolbarInstance)==null||e.clearToolbarDOM(),this.toolbarInstance=void 0}}export{E as default};
|
package/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";export{default as SegmentByRect}from"./core/toolOperation/segmentByRect.js";export{default as SegmentBySAM}from"./core/toolOperation/segmentBySAM.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as CanvasUtils}from"./utils/tool/CanvasUtils.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{default as CursorTextClass}from"./core/toolOperation/cursorTextClass.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
|
|
1
|
+
export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";export{default as SegmentByRect}from"./core/toolOperation/segmentByRect.js";export{default as SegmentBySAM}from"./core/toolOperation/segmentBySAM.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as CanvasUtils}from"./utils/tool/CanvasUtils.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{default as CursorTextClass}from"./core/toolOperation/cursorTextClass.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0-alpha.1",
|
|
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.14.0-
|
|
97
|
+
"@labelbee/lb-utils": "1.14.0-alpha.1",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|