@labelbee/lb-annotation 1.21.0-alpha.1 → 1.21.0-dev.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.
Files changed (36) hide show
  1. package/dist/constant/keyCode.js +1 -1
  2. package/dist/core/pointCloud/index.js +1 -1
  3. package/dist/core/pointCloud/matrix.js +1 -1
  4. package/dist/core/toolOperation/SAMToolbarClass.js +9 -0
  5. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  6. package/dist/core/toolOperation/cursorTextClass.js +1 -0
  7. package/dist/core/toolOperation/segmentByRect.js +1 -1
  8. package/dist/core/toolOperation/segmentBySAM.js +1 -0
  9. package/dist/index.js +1 -1
  10. package/dist/types/constant/keyCode.d.ts +3 -1
  11. package/dist/types/core/pointCloud/matrix.d.ts +2 -6
  12. package/dist/types/core/toolOperation/SAMToolbarClass.d.ts +40 -0
  13. package/dist/types/core/toolOperation/basicToolOperation.d.ts +1 -0
  14. package/dist/types/core/toolOperation/cursorTextClass.d.ts +12 -0
  15. package/dist/types/core/toolOperation/segmentByRect.d.ts +11 -4
  16. package/dist/types/core/toolOperation/segmentBySAM.d.ts +39 -0
  17. package/dist/types/index.d.ts +5 -1
  18. package/dist/types/utils/tool/CanvasUtils.d.ts +1 -1
  19. package/dist/types/utils/tool/PolygonUtils.d.ts +12 -0
  20. package/dist/types/utils/tool/StyleUtils.d.ts +9 -0
  21. package/dist/utils/tool/CanvasUtils.js +1 -1
  22. package/dist/utils/tool/PolygonUtils.js +1 -1
  23. package/dist/utils/tool/StyleUtils.js +1 -1
  24. package/es/constant/keyCode.js +1 -1
  25. package/es/core/pointCloud/index.js +2 -2
  26. package/es/core/pointCloud/matrix.js +1 -1
  27. package/es/core/toolOperation/SAMToolbarClass.js +9 -0
  28. package/es/core/toolOperation/basicToolOperation.js +1 -1
  29. package/es/core/toolOperation/cursorTextClass.js +1 -0
  30. package/es/core/toolOperation/segmentByRect.js +1 -1
  31. package/es/core/toolOperation/segmentBySAM.js +1 -0
  32. package/es/index.js +1 -1
  33. package/es/utils/tool/CanvasUtils.js +1 -1
  34. package/es/utils/tool/PolygonUtils.js +1 -1
  35. package/es/utils/tool/StyleUtils.js +1 -1
  36. package/package.json +2 -2
@@ -1 +1 @@
1
- "use strict";var EKeyCode;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace"})(EKeyCode||(EKeyCode={}));var EKeyCode$1=EKeyCode;module.exports=EKeyCode$1;
1
+ "use strict";var EKeyCode;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace",t[t.Minus=189]="Minus",t[t.Equal=187]="Equal"})(EKeyCode||(EKeyCode={}));var EKeyCode$1=EKeyCode;module.exports=EKeyCode$1;
@@ -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.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:h,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=h!=null?h:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,h,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,h=-100,d=500/c;return{left:a,right:o,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(h),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:h}=c.data,d=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==h.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(h),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,a+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],u=[];const m=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,h=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r-o/2},n={x:e+a/2,y:i+s/2,z:r+o/2},c={x:e-a/2,y:i+s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r-o/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2},c={x:e-a/2,y:i-s/2,z:r-o/2},h={x:e-a/2,y:i-s/2,z:r+o/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r+o/2},n={x:e+a/2,y:i-s/2,z:r+o/2},c={x:e-a/2,y:i-s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r+o/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(h).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -1 +1 @@
1
- "use strict";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
+ "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),i=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(t),o=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r),l=createThreeMatrix4(n),p=createThreeMatrix4(i),a=createThreeMatrix4(o);return{composeMatrix4:a.clone().premultiply(p).premultiply(l),PM:l,RM:p,TM:a}}catch(n){console.error(n)}}function rotatePoint(e,t,r){var n;const i=new THREE__namespace.Vector3(e.x,e.y,(n=e==null?void 0:e.z)!=null?n:1),o=new THREE__namespace.Matrix4().makeRotationZ(r),l=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),p=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(p).applyMatrix4(o).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:i}=t,o=new THREE__namespace.Vector4(e.x,e.y,e.z),l=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(i)),p=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r)),a=o.applyMatrix4(l),x=__pow(__pow(a.x,2)+__pow(a.y,2),.5),f=Math.atan(a.z/x),s=n.reduce((u,c,y)=>u+c*__pow(f,y),0);return a.x=a.x/x*s,a.y=a.y/x*s,a.z=1,a.applyMatrix4(p)};function lidar2image(e,t){const n=new THREE__namespace.Vector4(e.x,e.y,e.z).applyMatrix4(t);if(n.z<0)return;const i=1/n.z,o=new THREE__namespace.Matrix4().set(i,0,0,0,0,i,0,0,0,0,i,0,0,0,0,1);return n.applyMatrix4(o)}function getCuboidFromPointCloudBox(e){const{center:t,width:r,height:n,depth:i,rotation:o}=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(x=>{const f=rotatePoint(x,t,o);return{x:f.x,y:f.y}}),p=t.z+i/2,a=t.z-i/2;return __spreadProps(__spreadValues({},e),{polygonPointList:l,zMax:p,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,i=t.y-e.y,o=r.x-e.x,l=r.y-e.y;return n*l-o*i}function buildConvexHull(e){const t=sortPoints(e),r=[];for(let o=0;o<t.length;o++){for(;r.length>=2&&crossProduct(r[r.length-2],r[r.length-1],t[o])<=0;)r.pop();r.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&crossProduct(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}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:i,T:o}=t,{composeMatrix4:l}=(r=transferKitti2Matrix(n,i,o))!=null?r:{};if(!!l)return lidar2image(e,l)},isInImage=({point:e,calib:t,width:r,height:n})=>{if(!t)return!1;const i=point3DLidar2Image(e,t);return i?i.x>=0&&i.x<=r&&i.y>=0&&i.y<=n:!1},getHighlightIndexByPoints=({points:e,calib:t,width:r,height:n})=>{const i=[];for(let o=0;o<e.length;o+=3){const l=e[o],p=e[o+1],a=e[o+2];isInImage({point:{x:l,y:p,z:a},calib:t,width:r,height:n})?i.push(1):i.push(0)}return i},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:i}=r,o=lbUtils.PointCloudUtils.getAllViewData(e),l=isFisheyeCalibValid(t),{P:p,R:a,T:x}=t;let f;if(l===!1){const{composeMatrix4:u}=(n=transferKitti2Matrix(p,a,x))!=null?n:{};if(!u)return;f=u}const s=o.map(u=>({type:u.type,pointList:u.pointList.map(c=>rotatePoint(c,e.center,e.rotation)).map(c=>l?lidar2FisheyeImage(c,t):f&&lidar2image(c,f)).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&&i===!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 i=isFisheyeCalibValid(t),{P:o,R:l,T:p}=t;let a;if(i===!1){const{composeMatrix4:s}=(n=transferKitti2Matrix(o,l,p))!=null?n:{};if(!s)return;a=s}const x=e.length/3,f={};for(let s=0;s<x;s++){const h={x:e[s*3],y:e[s*3+1],z:e[s*3+2]};let u;if(i?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),y=Math.floor(u.y);if(c>r.width||y>r.height||c<0||y<0)continue;f[s]={x:c,y}}}return{pcdMapping:f}}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.pointMappingLidar2image=pointMappingLidar2image,exports.rotatePoint=rotatePoint,exports.transferKitti2Matrix=transferKitti2Matrix;
@@ -0,0 +1,9 @@
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"
2
+ ><span class="ant-radio"
3
+ ><input
4
+ class="ant-radio-input"
5
+ type="radio"
6
+ value="${o.value}"
7
+ checked="" /><span class="ant-radio-inner"></span></span
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;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t)),__async=(c,t,e)=>new Promise((i,s)=>{var o=r=>{try{n(e.next(r))}catch(a){s(a)}},h=r=>{try{n(e.throw(r))}catch(a){s(a)}},n=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,h);n((e=e.apply(c,t)).next())});const DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.initImgPos=()=>__async(this,null,function*(){var l,d;if(!this.imgNode)return;const u=(l=this._imgAttribute)==null?void 0:l.zoomRatio,g=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:m,imgInfo:b,zoom:f}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(b),this.setZoom(f),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",f,m,b)}),this.getCurrentPos=l=>{const{_firstClickCoordinate:d,currentPosStorage:u}=this;try{let g;return d&&u?g={y:u.y+l.y-d.y,x:u.x+l.x-d.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(l,d,u)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const b=ZoomUtils.wheelChangePos(m,l,d,g,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!b)return;const{currentPos:f,ratio:w,zoom:I,imgInfo:y}=b;this.setZoom(I),this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(y),this.zoomInfo.ratio=w,this.emit("renderZoom",I,f,y)},this.zoomChanged=(l,d=annotation.EGrowthMode.Linear)=>{const u=ZoomUtils.zoomChanged(this.zoom,l,d);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=l=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,l),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var e,i,s,o,h,n,r,a,v,C;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(e=t.staticMode)!=null?e:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(i=t.imgNode)==null?void 0:i.width)!=null?s:0,height:(h=(o=t.imgNode)==null?void 0:o.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(n=t.forbidOperation)!=null?n:!1,this.forbidBasicResultRender=(r=t.forbidBasicResultRender)!=null?r:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(a=t.style)!=null?a:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(v=t.imgAttribute)!=null?v:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=annotation.ELang.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,e,i){const s=this.pixelRatio;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}createCanvas(t,e=!0){var i,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10),e&&(this.container.hasChildNodes()?(this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(n))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,e=this.size){var i;if(!t||!e)return;const{min:s}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:e,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(i=this._imgAttribute)==null?void 0:i.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const e=this.canvas.getBoundingClientRect();return{x:(t.clientX-e.left-this.currentPos.x)/this.zoom,y:(t.clientY-e.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var e;return AttributeUtils.default.getTextIconSvg(t,(e=this.config)==null?void 0:e.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:e,y:i}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-i,y:e}:{x:e,y:i}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&i&&h){let n=t;switch(h){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const a=MathUtils.default.calcViewportBoundaries(t.pointList);n={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const r=lbUtils.ImgPosUtils.getBasicRecPos(i,n,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);r&&(this.setCurrentPos(r.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},o),{width:o.width/this.innerZoom*r.innerZoom,height:o.height/this.innerZoom*r.innerZoom})),this.setZoom(r.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>this.zoomInfo.min&&(o=-1),s<0&&this.zoom<this.zoomInfo.max&&(o=1),this.wheelChangePos(i,o),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:e,style:this.style})}getLineColor(t=""){var e,i,s,o,h,n,r,a;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const l=AttributeUtils.default.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return((n=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(u=>u.value===t))==null?void 0:n.color)?(a=(r=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:r.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[l]:""}const{color:v,lineColor:C}=this.style;return v&&C?C[v]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t)),__async=(c,t,e)=>new Promise((i,s)=>{var o=n=>{try{r(e.next(n))}catch(a){s(a)}},h=n=>{try{r(e.throw(n))}catch(a){s(a)}},r=n=>n.done?i(n.value):Promise.resolve(n.value).then(o,h);r((e=e.apply(c,t)).next())});const LANGUAGE_MAP={[annotation.ELang.Zh]:"cn",[annotation.ELang.US]:"en"},DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.initImgPos=()=>__async(this,null,function*(){var d,l;if(!this.imgNode)return;const u=(d=this._imgAttribute)==null?void 0:d.zoomRatio,g=(l=this._imgAttribute)==null?void 0:l.isOriginalSize,{currentPos:m,imgInfo:b,zoom:f}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(b),this.setZoom(f),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",f,m,b)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:l,currentPosStorage:u}=this;try{let g;return l&&u?g={y:u.y+d.y-l.y,x:u.x+d.x-l.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(d,l,u)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&l===-1)return;const b=ZoomUtils.wheelChangePos(m,d,l,g,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!b)return;const{currentPos:f,ratio:w,zoom:y,imgInfo:P}=b;this.setZoom(y),this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(P),this.zoomInfo.ratio=w,this.emit("renderZoom",y,f,P)},this.zoomChanged=(d,l=annotation.EGrowthMode.Linear)=>{const u=ZoomUtils.zoomChanged(this.zoom,d,l);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var e,i,s,o,h,r,n,a,v,C,I;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(e=t.staticMode)!=null?e:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(i=t.imgNode)==null?void 0:i.width)!=null?s:0,height:(h=(o=t.imgNode)==null?void 0:o.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(a=t.style)!=null?a:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(v=t.imgAttribute)!=null?v:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(I=t==null?void 0:t.language)!=null?I:annotation.ELang.Zh,lbUtils.i18n.changeLanguage(LANGUAGE_MAP[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const e=LANGUAGE_MAP[t];lbUtils.i18n.changeLanguage(e)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,e,i){const s=this.pixelRatio;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}createCanvas(t,e=!0){var i,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,10),e&&(this.container.hasChildNodes()?(this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(r))),this.canvas=r,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,e=this.size){var i;if(!t||!e)return;const{min:s}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:e,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(i=this._imgAttribute)==null?void 0:i.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const e=this.canvas.getBoundingClientRect();return{x:(t.clientX-e.left-this.currentPos.x)/this.zoom,y:(t.clientY-e.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var e;return AttributeUtils.default.getTextIconSvg(t,(e=this.config)==null?void 0:e.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:e,y:i}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-i,y:e}:{x:e,y:i}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&i&&h){let r=t;switch(h){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const a=MathUtils.default.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=lbUtils.ImgPosUtils.getBasicRecPos(i,r,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},o),{width:o.width/this.innerZoom*n.innerZoom,height:o.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>this.zoomInfo.min&&(o=-1),s<0&&this.zoom<this.zoomInfo.max&&(o=1),this.wheelChangePos(i,o),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:e,style:this.style})}getLineColor(t=""){var e,i,s,o,h,r,n,a;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const I=AttributeUtils.default.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(l=>l.value===t))==null?void 0:r.color)?(a=(n=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[I]:""}const{color:v,lineColor:C}=this.style;return v&&C?C[v]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
@@ -0,0 +1 @@
1
+ "use strict";var StyleUtils=require("../../utils/tool/StyleUtils.js");const TEXT_HEIGHT=30,MARGIN=10;class CursorTextClass{constructor(t){const{container:e}=t;this.container=e,this._textDOM=this.initTextDOM(),this.appendToContainer()}initTextDOM(){const t=document.createElement("div");return StyleUtils.setDOMStyle(t,{display:"none",position:"absolute",fontSize:"14px",height:`${TEXT_HEIGHT}px`,lineHeight:`${TEXT_HEIGHT}px`,padding:"0 8px",borderRadius:"2px",backgroundColor:"#FFFFFF",zIndex:"10",color:"white",whiteSpace:"nowrap"}),t}appendToContainer(){!this._textDOM||this.container.appendChild(this._textDOM)}clearTextDOM(){this._textDOM&&this.container.contains(this._textDOM)&&this.container.removeChild(this._textDOM)}update(t,e,i){const{left:n,top:o}=t;!this._textDOM||(StyleUtils.setDOMStyle(this._textDOM,{display:"block",left:`${n+MARGIN}px`,top:`${o-TEXT_HEIGHT-MARGIN}px`,backgroundColor:e}),this._textDOM.innerHTML=i)}}module.exports=CursorTextClass;
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),AxisUtils=require("../../utils/tool/AxisUtils.js"),rectOperation=require("./rectOperation.js"),keyCode=require("../../constant/keyCode.js"),__async=(u,e,t)=>new Promise((i,c)=>{var r=s=>{try{o(t.next(s))}catch(h){c(h)}},n=s=>{try{o(t.throw(s))}catch(h){c(h)}},o=s=>s.done?i(s.value):Promise.resolve(s.value).then(r,n);o((t=t.apply(u,e)).next())});class SegmentByRect extends rectOperation.RectOperation{constructor(e){super(e);this.onKeydown=t=>{switch(t.keyCode){case keyCode.Esc:t.preventDefault(),t.stopPropagation(),this.clearPredictionInfo();break;case keyCode.Z:t.ctrlKey&&(t.preventDefault(),t.stopPropagation(),this.rectList=[],this.render());break}},this.segmentPrediction=t=>__async(this,null,function*(){const i=this.getCoordinateUnderZoom(t);if(this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}yield this.runPrediction({point:i,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),this.clearPredictionInfo()}),this.isRunSegment=!1,this.runPrediction=e.runPrediction}setRunPrediction(e){this.runPrediction=e}eventBinding(){document.addEventListener("keydown",e=>this.onKeydown(e)),super.eventBinding()}clearPredictionInfo(){this.rectList=[],this.isShowCursor=!1,this.coord={x:-1,y:-1},this.drawingRect=void 0,this.isRunSegment=!1,this.clearCanvas(),this.render()}onMouseUp(e){if(!this.isRunSegment){if(e.button===0&&this.rectList.length===1&&!this.isRunSegment){e.stopPropagation(),this.segmentPrediction(e),this.clearActiveStatus();return}super.onMouseUp(e)}}onMouseDown(e){this.isRunSegment||super.onMouseDown(e)}renderCursorLine(){var e;if(!this.ctx)return;const{ctx:t}=this,i=10,c=1,{x:r,y:n}=this.coord;t.save(),t.strokeStyle="white",t.setLineDash([6]),t.lineWidth=c,t.strokeRect(r-i,n-i,i*2,i*2),t.restore();let o=`\u2460 ${lbUtils.i18n.t("FramingOfObjectToBeDivided")}`;const s=lbUtils.i18n.language==="en";let h=s?326:186;if(((e=this.rectList)==null?void 0:e.length)===1){o=`\u2461 ${lbUtils.i18n.t("ClickOnTarget")}`,h=s?232:142;const a=2;t.save(),t.strokeStyle="white";const l=c+i;t.beginPath(),t.moveTo(r+l+a*2,n+l+a),t.arc(r+l+a,n+l+a,a,0,Math.PI*2,!0),t.stroke(),t.restore()}this.isRunSegment&&(h=s?316:136,o=lbUtils.i18n.t("SplittingAlgorithmPrediction")),t.save(),t.fillStyle=this.style.strokeColor,t.fillRect(r+i,n-i*4-1,h,32),t.restore(),t.save(),t.font="14px Source Han Sans CN",t.fillStyle="white",t.fillText(o,r+i+14,n-i*2),t.restore(),super.renderCursorLine()}renderDrawingRect(e,t,i=!1){if(this.ctx&&e){const c=AxisUtils.default.changeRectByZoom(e,i?t:this.zoom,this.currentPos),{x:r,y:n,width:o,height:s}=c;this.ctx.save(),this.ctx.lineCap="butt",this.ctx.lineWidth=this.style.strokeWidth,this.ctx.strokeStyle="white",this.ctx.strokeRect(r,n,o,s),this.ctx.strokeStyle=this.style.strokeColor,this.ctx.setLineDash([6]),this.ctx.strokeRect(r,n,o,s),this.ctx.restore()}}renderTextAttribute(){}renderSelectedRect(){}}module.exports=SegmentByRect;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),AxisUtils=require("../../utils/tool/AxisUtils.js"),rectOperation=require("./rectOperation.js"),keyCode=require("../../constant/keyCode.js"),cursorTextClass=require("./cursorTextClass.js"),__async=(u,t,e)=>new Promise((s,r)=>{var h=i=>{try{o(e.next(i))}catch(c){r(c)}},n=i=>{try{o(e.throw(i))}catch(c){r(c)}},o=i=>i.done?s(i.value):Promise.resolve(i.value).then(h,n);o((e=e.apply(u,t)).next())});class SegmentByRect extends rectOperation.RectOperation{constructor(t){super(t);this.segmentPrediction=e=>__async(this,null,function*(){const s=this.getCoordinateInOrigin(e);if(this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}yield this.runPrediction({point:s,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),this.clearPredictionInfo()}),this.isRunSegment=!1,this.runPrediction=t.runPrediction}setRunPrediction(t){this.runPrediction=t}eventBinding(){document.addEventListener("keydown",t=>this.onKeydown(t)),super.eventBinding()}onKeydown(t){switch(t.keyCode){case keyCode.Esc:t.preventDefault(),t.stopPropagation(),this.clearPredictionInfo();break;case keyCode.Z:t.ctrlKey&&(t.preventDefault(),t.stopPropagation(),this.rectList=[],this.render());break}}clearPredictionInfo(){var t;this.rectList=[],this.isShowCursor=!1,this.coord={x:-1,y:-1},this.drawingRect=void 0,this.isRunSegment=!1,(t=this.cursorTextInstance)==null||t.clearTextDOM(),this.cursorTextInstance=void 0,this.clearCanvas(),this.render()}onMouseUp(t){if(!this.isRunSegment){if(t.button===0&&this.rectList.length===1&&!this.isRunSegment){t.stopPropagation(),this.segmentPrediction(t),this.clearActiveStatus();return}super.onMouseUp(t)}}onMouseDown(t){this.isRunSegment||super.onMouseDown(t)}renderCursorLine(){if(!this.ctx)return;const{ctx:t}=this,e=10,s=1,{x:r,y:h}=this.coord,n=this.getLineColor(this.defaultAttribute);t.save(),t.strokeStyle="white",t.setLineDash([6]),t.lineWidth=s,t.strokeRect(r-e,h-e,e*2,e*2),t.restore(),this.renderCursorText(),super.renderCursorLine(n)}renderDrawingRect(t,e,s=!1){var r;if(this.ctx&&t){const h=AxisUtils.default.changeRectByZoom(t,s?e:this.zoom,this.currentPos),{x:n,y:o,width:i,height:c}=h,a=(r=e!=null?e:this.zoom)!=null?r:1;this.ctx.save(),this.ctx.lineCap="butt";const d=this.style.strokeWidth,l=10;this.ctx.lineWidth=d,this.ctx.strokeStyle="white",this.ctx.setLineDash([]),this.ctx.strokeRect(n,o,i,c),this.ctx.strokeStyle=this.getLineColor(this.defaultAttribute),this.ctx.setLineDash([l*a]),this.ctx.strokeRect(n,o,i,c),this.ctx.restore()}}cursorText(){var t;let e=`\u2460 ${lbUtils.i18n.t("FramingOfObjectToBeDivided")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(e=`\u2461 ${lbUtils.i18n.t("ClickOnTarget")}`),this.isRunSegment&&(e=lbUtils.i18n.t("SplittingAlgorithmPrediction")),e}renderTextAttribute(){}renderSelectedRect(){}renderCursorText(){var t;if(this.coord.x<0||this.coord.y<0){(t=this.cursorTextInstance)==null||t.clearTextDOM(),this.cursorTextInstance=void 0;return}this.cursorTextInstance||(this.cursorTextInstance=new cursorTextClass({container:this.container}));const e={left:this.coord.x,top:this.coord.y};this.cursorTextInstance.update(e,this.getLineColor(this.defaultAttribute),this.cursorText())}}module.exports=SegmentByRect;
@@ -0,0 +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=(s,t,e)=>t in s?__defProp(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,__spreadValues=(s,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(s,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(s,e,t[e]);return s},__spreadProps=(s,t)=>__defProps(s,__getOwnPropDescs(t)),__async=(s,t,e)=>new Promise((i,r)=>{var a=o=>{try{n(e.next(o))}catch(d){r(d)}},l=o=>{try{n(e.throw(o))}catch(d){r(d)}},n=o=>o.done?i(o.value):Promise.resolve(o.value).then(a,l);n((e=e.apply(s,t)).next())});class SegmentBySAM extends segmentByRect{constructor(t){super(t);this.segmentPrediction=e=>__async(this,null,function*(){var i,r,a,l;if(this.isRunSegment)return;const n=this.getCoordinateInOrigin(e);if(!RectUtils.isInRect(n,this.rectList[0],0,1)){(i=this.onOutSide)==null||i.call(this);return}if(this.clickType==="add"&&this.addPoints.push([n.x,n.y]),this.clickType==="remove"&&this.removePoints.push([n.x,n.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 d=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}}),c=d==null?void 0:d.filter(h=>{var u;return((u=h==null?void 0:h.pointList)==null?void 0:u.length)>2}).map(h=>__spreadProps(__spreadValues({},h),{id:uuid(),attribute:this.defaultAttribute}));this.predictionResult=c,(a=this.SAMHistory)==null||a.pushHistory(this.predictionResult)}finally{(l=this.toolbarInstance)==null||l.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,r;const a=AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),l=StyleUtils.getStrokeAndFill(e,!0,{isHover:!0});DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:l.fill,strokeColor:l.stroke,thickness:(r=(i=this.style)==null?void 0:i.width)!=null?r: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,r;(r=this.onFinish)==null||r.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()}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"),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"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),StyleUtils=require("./utils/tool/StyleUtils.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.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.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.UnitUtils=UnitUtils,exports.StyleUtils=StyleUtils,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;
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;
@@ -33,6 +33,8 @@ declare enum EKeyCode {
33
33
  Alt = 18,
34
34
  Shift = 16,
35
35
  Tab = 9,
36
- BackSpace = 8
36
+ BackSpace = 8,
37
+ Minus = 189,
38
+ Equal = 187
37
39
  }
38
40
  export default EKeyCode;
@@ -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, ICoordinate } from '@labelbee/lb-utils';
5
+ import { TMatrix4Tuple, IPointCloudBox, I3DSpaceCoord, TMatrix14Tuple, TMatrix13Tuple, IPolygonPoint, ICalib, IBasicBox3d } 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?: ICoordinate[] | undefined;
71
+ newPointList?: import("@labelbee/lb-utils").ICoordinate[] | undefined;
72
72
  rects?: import("@labelbee/lb-utils").IPointCloudBoxRect[] | undefined;
73
73
  width: number;
74
74
  height: number;
@@ -128,7 +128,3 @@ 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;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file SAM交互工具栏,显示在框的左上方,提供增加、删减、重置、完成功能
3
+ * @author lihuaqi <lihuaqi@sensetime.com>
4
+ * @date 2023年10月8日
5
+ */
6
+ export default class SAMToolbarClass {
7
+ private container;
8
+ private disabled;
9
+ private _toolbarDOM?;
10
+ private _radioGroupDOM?;
11
+ private _buttonGroupDOM?;
12
+ private i18n;
13
+ private onToggleClickType;
14
+ private onReset;
15
+ private onFinish;
16
+ constructor(props: any);
17
+ appendToContainer(): void;
18
+ clearToolbarDOM(): void;
19
+ initToolbarDOM(): HTMLDivElement;
20
+ initRadioGroupDOM(): HTMLDivElement;
21
+ initButtonGroupDOM(): HTMLDivElement;
22
+ update(position: {
23
+ left: number;
24
+ top: number;
25
+ }): void;
26
+ onClick(e: MouseEvent): void;
27
+ eventBinding(): void;
28
+ onMouseUp(e: MouseEvent): void;
29
+ eventUnbinding(): void;
30
+ setDisabled(disabled: boolean): void;
31
+ onToggle(type: 'add' | 'remove'): void;
32
+ }
33
+ export declare const getSAMToolbarOffset: ({ rect, currentPos, zoom, }: {
34
+ rect: IRect;
35
+ currentPos: ICoordinate;
36
+ zoom: number;
37
+ }) => {
38
+ left: number;
39
+ top: number;
40
+ };
@@ -27,6 +27,7 @@ interface IBasicToolOperationProps {
27
27
  max: number;
28
28
  ratio: number;
29
29
  };
30
+ language?: ELang;
30
31
  }
31
32
  /**
32
33
  * 参考显示数据
@@ -0,0 +1,12 @@
1
+ export default class CursorTextClass {
2
+ private container;
3
+ private _textDOM?;
4
+ constructor(props: any);
5
+ initTextDOM(): HTMLDivElement;
6
+ appendToContainer(): void;
7
+ clearTextDOM(): void;
8
+ update(position: {
9
+ left: number;
10
+ top: number;
11
+ }, color: string, text: string): void;
12
+ }
@@ -1,31 +1,38 @@
1
+ import { IPolygonData } from '@labelbee/lb-utils';
1
2
  import { RectOperation } from './rectOperation';
2
3
  import type { IRectOperationProps } from './rectOperation';
4
+ import { ISAMCoordinate } from './segmentBySAM';
3
5
  type TRunPrediction = (params: {
4
- point: ICoordinate;
6
+ point?: ICoordinate;
7
+ addPoints?: ISAMCoordinate[];
8
+ removePoints?: ISAMCoordinate[];
5
9
  rect: {
6
10
  x: number;
7
11
  y: number;
8
12
  w: number;
9
13
  h: number;
10
14
  };
11
- }) => Promise<unknown>;
12
- interface ISegmentByRectProps extends IRectOperationProps {
15
+ }) => Promise<IPolygonData[]>;
16
+ export interface ISegmentByRectProps extends IRectOperationProps {
13
17
  runPrediction: TRunPrediction;
14
18
  }
15
19
  declare class SegmentByRect extends RectOperation {
20
+ private cursorTextInstance?;
16
21
  isRunSegment: boolean;
17
22
  runPrediction: TRunPrediction;
18
23
  constructor(props: ISegmentByRectProps);
19
24
  setRunPrediction(runPrediction: TRunPrediction): void;
20
25
  eventBinding(): void;
21
- onKeydown: (e: KeyboardEvent) => void;
26
+ onKeydown(e: KeyboardEvent): void;
22
27
  clearPredictionInfo(): void;
23
28
  onMouseUp(e: MouseEvent): undefined;
24
29
  onMouseDown(e: MouseEvent): undefined;
25
30
  renderCursorLine(): void;
26
31
  renderDrawingRect(rect: IRect, zoom: number, isZoom?: boolean): void;
32
+ cursorText(): string;
27
33
  renderTextAttribute(): void;
28
34
  renderSelectedRect(): void;
29
35
  segmentPrediction: (e: MouseEvent) => Promise<void>;
36
+ renderCursorText(): void;
30
37
  }
31
38
  export default SegmentByRect;
@@ -0,0 +1,39 @@
1
+ import { IPolygonData } from '@labelbee/lb-utils';
2
+ import SegmentByRect, { ISegmentByRectProps } from './segmentByRect';
3
+ export interface ISegmentBySAMProps extends ISegmentByRectProps {
4
+ onOutSide: () => void;
5
+ onFinish: (result: IPolygonData[]) => void;
6
+ }
7
+ export type ISAMCoordinate = [x: number, y: number];
8
+ declare class SegmentBySAM extends SegmentByRect {
9
+ private clickType;
10
+ private addPoints;
11
+ private removePoints;
12
+ private toolbarInstance?;
13
+ private predictionResult;
14
+ private SAMHistory;
15
+ onOutSide: () => void;
16
+ onFinish: (result: IPolygonData[]) => void;
17
+ constructor(props: any);
18
+ onKeydown(e: KeyboardEvent): void;
19
+ onMouseUp(e: MouseEvent): undefined;
20
+ eventBinding(): void;
21
+ eventUnbinding(): void;
22
+ setOnOutSide(onOutSide: () => void): void;
23
+ segmentPrediction: (e: MouseEvent) => Promise<void>;
24
+ onMouseDown(e: MouseEvent): undefined;
25
+ onLanguageChanged(): void;
26
+ drawPredictionResult(): void;
27
+ drawPolygon(data: IPolygonData, currentColor: IToolColorStyle): void;
28
+ clearPredictionInfo(): void;
29
+ renderToolbar(): void;
30
+ toggleClickType(type: 'add' | 'remove'): void;
31
+ reset(): void;
32
+ cursorText(): string;
33
+ /** 撤销 */
34
+ undo(): void;
35
+ /** 重做 */
36
+ redo(): void;
37
+ render(): void;
38
+ }
39
+ export default SegmentBySAM;
@@ -10,6 +10,8 @@ import { BasicToolOperation } from './core/toolOperation/basicToolOperation';
10
10
  import ViewOperation from './core/toolOperation/ViewOperation';
11
11
  import ScribbleTool from './core/toolOperation/ScribbleTool';
12
12
  import PointCloud2dOperation from './core/toolOperation/pointCloud2dOperation';
13
+ import SegmentByRect from './core/toolOperation/segmentByRect';
14
+ import SegmentBySAM from './core/toolOperation/segmentBySAM';
13
15
  import * as cAnnotation from './constant/annotation';
14
16
  import * as cAnnotationTask from './constant/annotationTask';
15
17
  import * as cKeyCode from './constant/keyCode';
@@ -27,13 +29,15 @@ import MathUtils from './utils/MathUtils';
27
29
  import AttributeUtils from './utils/tool/AttributeUtils';
28
30
  import ActionsHistory from './utils/ActionsHistory';
29
31
  import EventBus from './utils/EventBus';
32
+ import CanvasUtils from './utils/tool/CanvasUtils';
30
33
  import DblClickEventListener from './utils/tool/DblClickEventListener';
31
34
  import AnnotationEngine from './core';
32
35
  import UnitUtils from './utils/tool/UnitUtils';
33
36
  import StyleUtils from './utils/tool/StyleUtils';
37
+ import CursorTextClass from './core/toolOperation/cursorTextClass';
34
38
  declare const CommonToolUtils: typeof EnhanceCommonToolUtils;
35
39
  declare const toolUtils: typeof EnhanceCommonToolUtils;
36
- export { RectOperation, TagOperation, PointOperation, LineToolOperation, PolygonOperation, TextToolOperation, BasicToolOperation, PointCloud2DRectOperation, MeasureOperation, ViewOperation, PointCloud2dOperation, cAnnotation, cAnnotationTask, cKeyCode, cStyle, cTool, toolUtils, DblClickEventListener, CommonToolUtils, uuid, MarkerUtils, RectUtils, AxisUtils, TagUtils, DrawUtils, ImgUtils, MathUtils, AttributeUtils, AnnotationEngine, ScribbleTool, UnitUtils, StyleUtils, ActionsHistory, EventBus, };
40
+ export { RectOperation, TagOperation, PointOperation, LineToolOperation, PolygonOperation, TextToolOperation, BasicToolOperation, PointCloud2DRectOperation, MeasureOperation, ViewOperation, PointCloud2dOperation, SegmentByRect, SegmentBySAM, CursorTextClass, cAnnotation, cAnnotationTask, cKeyCode, cStyle, cTool, toolUtils, DblClickEventListener, CommonToolUtils, uuid, MarkerUtils, RectUtils, AxisUtils, TagUtils, DrawUtils, ImgUtils, MathUtils, AttributeUtils, CanvasUtils, AnnotationEngine, ScribbleTool, UnitUtils, StyleUtils, ActionsHistory, EventBus, };
37
41
  export * from './newCore';
38
42
  export * from './constant/tool';
39
43
  export * from './core/pointCloud';
@@ -43,7 +43,7 @@ export default class CanvasUtils {
43
43
  * @returns
44
44
  */
45
45
  static getPixelRatio: (context: any) => number;
46
- static createCanvas(size: ISize): {
46
+ static createCanvas(size: ISize, color?: string): {
47
47
  canvas: HTMLCanvasElement;
48
48
  ctx: CanvasRenderingContext2D | null;
49
49
  };