@labelbee/lb-annotation 1.9.0-alpha.11 → 1.9.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),pointCloud2dOperation=require("../toolOperation/pointCloud2dOperation.js");const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:o,pcdPath:e,polygonOperationProps:l}){this.updatePolygonList=(g,c)=>{let r=g.map(p=>{const{polygon2d:m}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(p);return{id:p.id,sourceID:"",pointList:m,isRect:!0}});c&&(r=r.concat(c)),this.pointCloud2dOperation.setResult(r)};const h=this.getDefaultOrthographic(t),C=createEmptyImage(t),d=new Image;d.src=C;const a=new CanvasScheduler.CanvasScheduler({container:o}),s=new index.PointCloud({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:h});e&&s.loadPCDFile(e),a.createCanvas(s.renderer.domElement);const u={container:o,size:t,config:'{ "textConfigurable": false }',imgNode:d,isAppend:!1};l&&Object.assign(u,l);const i=new pointCloud2dOperation(u);i.eventBinding(),i.setPattern(tool.EPolygonPattern.Rect),a.createCanvas(i.canvas,{size:t}),this.pointCloud2dOperation=i,this.pointCloudInstance=s,this.canvasScheduler=a}getDefaultOrthographic(t){return{left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100}}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(t)),this.pointCloudInstance.render();const o=createEmptyImage(t),e=new Image;e.src=o,e.onload=()=>{this.pointCloud2dOperation.setImgNode(e),this.pointCloud2dOperation.setCanvasSize(t),this.pointCloud2dOperation.initImgPos()}}addPolygonListOnTopView(t){const o=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),e=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(o,e)}updateData(t,o,e){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,e==null?void 0:e.radius),this.addPolygonListOnTopView(o))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),pointCloud2dOperation=require("../toolOperation/pointCloud2dOperation.js");const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:o,pcdPath:e,polygonOperationProps:d}){this.updatePolygonList=(m,p)=>{let r=m.map(l=>{var h;const{polygon2d:P}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(l);return{id:l.id,sourceID:"",pointList:P,isRect:!0,valid:(h=l.valid)!=null?h:!0}});p&&(r=r.concat(p)),this.pointCloud2dOperation.setResult(r)};const C=this.getDefaultOrthographic(t),g=createEmptyImage(t),u=new Image;u.src=g;const a=new CanvasScheduler.CanvasScheduler({container:o}),s=new index.PointCloud({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:C});e&&s.loadPCDFile(e),a.createCanvas(s.renderer.domElement);const c={container:o,size:t,config:'{ "textConfigurable": false }',imgNode:u,isAppend:!1};d&&Object.assign(c,d);const i=new pointCloud2dOperation(c);i.eventBinding(),i.setPattern(tool.EPolygonPattern.Rect),a.createCanvas(i.canvas,{size:t}),this.pointCloud2dOperation=i,this.pointCloudInstance=s,this.canvasScheduler=a}getDefaultOrthographic(t){return{left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100}}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(t)),this.pointCloudInstance.render();const o=createEmptyImage(t),e=new Image;e.src=o,e.onload=()=>{this.pointCloud2dOperation.setImgNode(e),this.pointCloud2dOperation.setCanvasSize(t),this.pointCloud2dOperation.initImgPos()}}addPolygonListOnTopView(t){const o=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),e=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(o,e)}updateData(t,o,e){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,e==null?void 0:e.radius),this.addPolygonListOnTopView(o))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js");function _interopNamespace(p){if(p&&p.__esModule)return p;var t=Object.create(null);return p&&Object.keys(p).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(p,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return p[e]}})}}),t.default=p,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(p,t,e)=>t in p?__defProp(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,__spreadValues=(p,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(p,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(p,e,t[e]);return p},__spreadProps=(p,t)=>__defProps(p,__getOwnPropDescs(t)),__async=(p,t,e)=>new Promise((i,r)=>{var s=a=>{try{o(e.next(a))}catch(c){r(c)}},n=a=>{try{o(e.throw(a))}catch(c){r(c)}},o=a=>a.done?i(a.value):Promise.resolve(a.value).then(s,n);o((e=e.apply(p,t)).next())});const DEFAULT_DISTANCE=30;new highlightWorker;class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="black"}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(n,o=16777215)=>{var a;const c=(a=n.id)!=null?a:uuid();this.removeObjectByName(c);const{center:h,width:l,height:d,depth:m,rotation:y}=n,u=new THREE__namespace.Group,x=new THREE__namespace.BoxGeometry(l,d,m),g=new THREE__namespace.MeshBasicMaterial({color:"blue"}),w=new THREE__namespace.Mesh(x,g),f=new THREE__namespace.BoxHelper(w,o),M=this.generateBoxArrow(n);u.add(f),u.add(M),u.position.set(h.x,h.y,h.z),u.rotation.set(0,0,y),u.name=c,this.scene.add(u)},this.overridePointShader=n=>{n.vertexShader=`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js");function _interopNamespace(p){if(p&&p.__esModule)return p;var t=Object.create(null);return p&&Object.keys(p).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(p,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return p[e]}})}}),t.default=p,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(p,t,e)=>t in p?__defProp(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,__spreadValues=(p,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(p,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(p,e,t[e]);return p},__spreadProps=(p,t)=>__defProps(p,__getOwnPropDescs(t)),__async=(p,t,e)=>new Promise((i,o)=>{var s=a=>{try{r(e.next(a))}catch(c){o(c)}},n=a=>{try{r(e.throw(a))}catch(c){o(c)}},r=a=>a.done?i(a.value):Promise.resolve(a.value).then(s,n);r((e=e.apply(p,t)).next())});const DEFAULT_DISTANCE=30;new highlightWorker;class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:o,backgroundColor:s="black"}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(n,r=16777215)=>{var a;const c=(a=n.id)!=null?a:uuid();this.removeObjectByName(c);const{center:h,width:l,height:d,depth:y,rotation:x}=n,m=new THREE__namespace.Group,u=new THREE__namespace.BoxGeometry(l,d,y),g=new THREE__namespace.MeshBasicMaterial({color:"blue"}),w=new THREE__namespace.Mesh(u,g),f=new THREE__namespace.BoxHelper(w,r),M=this.generateBoxArrow(n);m.add(f),m.add(M),m.position.set(h.x,h.y,h.z),m.rotation.set(0,0,x),m.name=c,this.scene.add(m)},this.overridePointShader=n=>{n.vertexShader=`
2
2
  attribute float sizes;
3
3
  attribute float visibility;
4
4
  varying float vVisible;
@@ -8,4 +8,4 @@
8
8
  varying float vVisible;
9
9
  ${n.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
10
10
  if (vVisible < 0.5) discard;
11
- #include <clipping_planes_fragment>`)},this.loadPCDFile=(n,o)=>__async(this,null,function*(){const a=yield this.cacheInstance.loadPCDFile(n);a.name=this.pointCloudObjectName,this.renderPointCloud(a,o)}),this.loadPCDFileByBox=(n,o,a)=>__async(this,null,function*(){const c=l=>__async(this,null,function*(){const{width:d=0,height:m=0,depth:y=0}=a!=null?a:{},u=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+d,height:o.height+m,depth:o.depth+y}),l);if(!u){console.error("filter Error");return}this.clearPointCloud();const x=new THREE__namespace.Points(u.geometry,l.material);x.name=this.pointCloudObjectName,this.scene.add(x),this.render()}),h=yield this.cacheInstance.loadPCDFile(n);c(h)}),this.generateBoxArrow=({width:n})=>{const o=new THREE__namespace.Vector3(1,0,0),a=new THREE__namespace.Vector3(n/2,0,0),c=2,h=16776960,l=new THREE__namespace.ArrowHelper(o,a,c,h);return l.visible=this.showDirection,l},this.generateBoxTrackID=n=>{if(!n.trackID)return;const o=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));o.needsUpdate=!0;const a=new THREE__namespace.SpriteMaterial({map:o,depthWrite:!1}),c=new THREE__namespace.Sprite(a);return c.scale.set(5,5,5),c.position.set(-n.width/2,0,n.depth/2+.5),c},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=n=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const a=o.material.size;n?o.material.size=Math.min(a*1.2,10):o.material.size=Math.max(a/1.2,1),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,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,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()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-1,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:n,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=n,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){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}transferKitti2Matrix(t,e,i){const r=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(t),s=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(e),n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(i),o=this.createThreeMatrix4(r),a=this.createThreeMatrix4(s),c=this.createThreeMatrix4(n);return{composeMatrix4:c.clone().premultiply(a).premultiply(o),PM:o,RM:a,TM:c}}pointCloudLidar2image(t,e){const i=lbUtils.PointCloudUtils.getAllViewData(t),{P:r,R:s,T:n}=e,{composeMatrix4:o}=this.transferKitti2Matrix(r,s,n);return i.map(c=>({type:c.type,pointList:c.pointList.map(h=>this.rotatePoint(h,t.center,t.rotation)).map(h=>this.lidar2image(h,o)).filter(h=>h!==void 0)})).filter(c=>c.pointList.length!==0)}lidar2image(t,e){const r=new THREE__namespace.Vector4(t.x,t.y,t.z).applyMatrix4(e);if(r.z<0)return;const s=1/r.z,n=new THREE__namespace.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return r.applyMatrix4(n)}generateBox(t,e=16777215){this.AddBoxToSense(t,e),this.render()}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,n=e.x-i/2-s,o=e.x-i/2+s,a=e.y+r/2+s,c=e.y-r/2-s,h=100,l=-100,d=500/h;return{left:n,right:o,top:a,bottom:c,near:h,far:l,zoom:d}}updateCameraByBox(t,e){const{center:i,width:r,height:s,depth:n,rotation:o}=t,a=this.getCameraVector(i,o,{width:r,height:s,depth:n},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}rotatePoint(t,e,i){var r;const s=new THREE__namespace.Vector3(t.x,t.y,(r=t==null?void 0:t.z)!=null?r:1),n=new THREE__namespace.Matrix4().makeRotationZ(i),o=new THREE__namespace.Matrix4().makeTranslation(e.x,e.y,e.z),a=new THREE__namespace.Matrix4().makeTranslation(-e.x,-e.y,-e.z);return s.clone().applyMatrix4(a).applyMatrix4(n).applyMatrix4(o)}getCuboidFromPointCloudBox(t){const{center:e,width:i,height:r,depth:s,rotation:n}=t,o=[{x:e.x+i/2,y:e.y-r/2},{x:e.x+i/2,y:e.y+r/2},{x:e.x-i/2,y:e.y+r/2},{x:e.x-i/2,y:e.y-r/2}].map(h=>{const l=this.rotatePoint(h,e,n);return{x:l.x,y:l.y}}),a=e.z+s/2,c=e.z-s/2;return{polygonPointList:o,zMax:a,zMin:c}}filterPointsByBox(t,e){if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=i}if(window.Worker){const{zMin:i,zMax:r,polygonPointList:s}=this.getCuboidFromPointCloudBox(t),n=e.geometry.attributes.position.array,o=e.geometry.attributes.color.array,a={boxParams:t,zMin:i,zMax:r,polygonPointList:s,color:o,position:n};return new Promise(c=>{const h=new filterBoxWorker;h.postMessage(a),h.onmessage=l=>{const{color:d,position:m,num:y}=l.data,u=new THREE__namespace.BufferGeometry;u.setAttribute("position",new THREE__namespace.Float32BufferAttribute(m,3)),u.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),u.computeBoundingSphere(),h.terminate(),c({geometry:u,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let n=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:n=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:n=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:n=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:n=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:n=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:n=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(n),a=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(a).applyMatrix4(h).applyMatrix4(c)}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}),n=new THREE__namespace.Line(r,s);return n.name=this.rangeObjectName,n}renderPointCloud(t,e){t.material.size=1,t.name=this.pointCloudObjectName;const i=new THREE__namespace.PointsMaterial({vertexColors:!0});if(i.onBeforeCompile=this.overridePointShader,e){const s=this.createRange(e);this.scene.add(s)}this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t);const r=this.scene.getObjectByName(this.pointCloudObjectName);r?(r.geometry.attributes.color=t.geometry.attributes.color,r.geometry.attributes.position=t.geometry.attributes.position,r.geometry.attributes.color.needsUpdate=!0,r.geometry.attributes.position.needsUpdate=!0,r.uuid=t.uuid):this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){}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}getSensesPointZAxisInPolygon(t,e){const i=this.scene.children.find(a=>a.uuid===this.pointsUuid);let r=0,s=0,n=0,o=0;if(i&&(i==null?void 0:i.geometry)){const a=i==null?void 0:i.geometry.attributes.position;for(let c=0;c<a.count;c++){const h=c*3,l=a.getX(h),d=a.getY(h),m=a.getZ(h);polygonTool.isInPolygon({x:l,y:d},t)&&m&&(s=Math.max(m,s),r=Math.min(m,r),o++,e&&m>=e[0]&&m<=e[1]&&n++)}}return{maxZ:s,minZ:r,count:n,zCount:o}}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:n,depth:o}=t,a={x:e+n/2,y:i+s/2,z:r-o/2},c={x:e+n/2,y:i+s/2,z:r+o/2},h={x:e-n/2,y:i+s/2,z:r+o/2},l={x:e-n/2,y:i+s/2,z:r-o/2};return[a,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:n,depth:o}=t,a={x:e-n/2,y:i+s/2,z:r+o/2},c={x:e-n/2,y:i+s/2,z:r-o/2},h={x:e-n/2,y:i-s/2,z:r-o/2},l={x:e-n/2,y:i-s/2,z:r+o/2};return[a,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:n,depth:o}=t,a={x:e+n/2,y:i+s/2,z:r+o/2},c={x:e+n/2,y:i-s/2,z:r+o/2},h={x:e-n/2,y:i-s/2,z:r+o/2},l={x:e-n/2,y:i+s/2,z:r+o/2};return[a,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,n=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),a=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(a).multiply(n)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}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,n=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(n).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const a=i.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/r,h=this.containerHeight/s;return{polygon2d:a,zoom:Math.min(c,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(a=>new THREE__namespace.Vector3(a.x,a.y,a.z)).map(a=>a.applyMatrix4(this.getModelTransformationMatrix(t))).map(a=>({x:a.y,y:a.x})).map(a=>({x:-(a.x-this.containerWidth/2),y:-(a.y-this.containerHeight/2)})),n=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(n,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),n=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+n.x,y:o.center.y+n.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),n=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+n.x,y:o.center.y+n.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const n=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!n){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(x=>new THREE__namespace.Vector3(x.x,x.y,x.z)).map(x=>x.applyMatrix4(n)),[a,c,h,l]=o,d=Math.max(Math.abs(a.x-h.x),Math.abs(a.x-c.x)),y=c.add(l).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-y.x,y:r.center.y-y.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:n}=r;for(let o=0;o<n;o++){const a=r.getZ(o);s.push(a>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.PointCloud=PointCloud;
11
+ #include <clipping_planes_fragment>`)},this.loadPCDFile=(n,r)=>__async(this,null,function*(){this.clearPointCloud();const a=yield this.cacheInstance.loadPCDFile(n);a.name=this.pointCloudObjectName,this.renderPointCloud(a,r)}),this.loadPCDFileByBox=(n,r,a)=>__async(this,null,function*(){const c=l=>__async(this,null,function*(){const{width:d=0,height:y=0,depth:x=0}=a!=null?a:{},m=yield this.filterPointsByBox(__spreadProps(__spreadValues({},r),{width:r.width+d,height:r.height+y,depth:r.depth+x}),l);if(!m){console.error("filter Error");return}this.clearPointCloud();const u=new THREE__namespace.Points(m.geometry,l.material);u.name=this.pointCloudObjectName,this.scene.add(u),this.render()}),h=yield this.cacheInstance.loadPCDFile(n);c(h)}),this.generateBoxArrow=({width:n})=>{const r=new THREE__namespace.Vector3(1,0,0),a=new THREE__namespace.Vector3(n/2,0,0),c=2,h=16776960,l=new THREE__namespace.ArrowHelper(r,a,c,h);return l.visible=this.showDirection,l},this.generateBoxTrackID=n=>{if(!n.trackID)return;const r=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));r.needsUpdate=!0;const a=new THREE__namespace.SpriteMaterial({map:r,depthWrite:!1}),c=new THREE__namespace.Sprite(a);return c.scale.set(5,5,5),c.position.set(-n.width/2,0,n.depth/2+.5),c},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=n=>{const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!r)return;const a=r.material.size;n?r.material.size=Math.min(a*1.2,10):r.material.size=Math.max(a/1.2,1),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,i&&o?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(o.left,o.right,o.top,o.bottom,o.near,o.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,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()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-1,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:o,bottom:s,near:n,far:r}=t;this.camera.left=e,this.camera.right=i,this.camera.top=o,this.camera.bottom=s,this.camera.near=n,this.camera.far=r,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:o}=this.initCameraPosition;t.position.set(e,i,o)}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){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}transferKitti2Matrix(t,e,i){const o=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(t),s=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(e),n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(i),r=this.createThreeMatrix4(o),a=this.createThreeMatrix4(s),c=this.createThreeMatrix4(n);return{composeMatrix4:c.clone().premultiply(a).premultiply(r),PM:r,RM:a,TM:c}}pointCloudLidar2image(t,e){const i=lbUtils.PointCloudUtils.getAllViewData(t),{P:o,R:s,T:n}=e,{composeMatrix4:r}=this.transferKitti2Matrix(o,s,n);return i.map(c=>({type:c.type,pointList:c.pointList.map(h=>this.rotatePoint(h,t.center,t.rotation)).map(h=>this.lidar2image(h,r)).filter(h=>h!==void 0)})).filter(c=>c.pointList.length!==0)}lidar2image(t,e){const o=new THREE__namespace.Vector4(t.x,t.y,t.z).applyMatrix4(e);if(o.z<0)return;const s=1/o.z,n=new THREE__namespace.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return o.applyMatrix4(n)}generateBox(t,e=16777215){this.AddBoxToSense(t,e),this.render()}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:o}=t,s=10,n=e.x-i/2-s,r=e.x-i/2+s,a=e.y+o/2+s,c=e.y-o/2-s,h=100,l=-100,d=500/h;return{left:n,right:r,top:a,bottom:c,near:h,far:l,zoom:d}}updateCameraByBox(t,e){const{center:i,width:o,height:s,depth:n,rotation:r}=t,a=this.getCameraVector(i,r,{width:o,height:s,depth:n},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}rotatePoint(t,e,i){var o;const s=new THREE__namespace.Vector3(t.x,t.y,(o=t==null?void 0:t.z)!=null?o:1),n=new THREE__namespace.Matrix4().makeRotationZ(i),r=new THREE__namespace.Matrix4().makeTranslation(e.x,e.y,e.z),a=new THREE__namespace.Matrix4().makeTranslation(-e.x,-e.y,-e.z);return s.clone().applyMatrix4(a).applyMatrix4(n).applyMatrix4(r)}getCuboidFromPointCloudBox(t){const{center:e,width:i,height:o,depth:s,rotation:n}=t,r=[{x:e.x+i/2,y:e.y-o/2},{x:e.x+i/2,y:e.y+o/2},{x:e.x-i/2,y:e.y+o/2},{x:e.x-i/2,y:e.y-o/2}].map(h=>{const l=this.rotatePoint(h,e,n);return{x:l.x,y:l.y}}),a=e.z+s/2,c=e.z-s/2;return{polygonPointList:r,zMax:a,zMin:c}}filterPointsByBox(t,e){if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=i}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:s}=this.getCuboidFromPointCloudBox(t),n=e.geometry.attributes.position.array,r=e.geometry.attributes.color.array,a={boxParams:t,zMin:i,zMax:o,polygonPointList:s,color:r,position:n};return new Promise(c=>{const h=new filterBoxWorker;h.postMessage(a),h.onmessage=l=>{const{color:d,position:y,num:x}=l.data,m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.Float32BufferAttribute(y,3)),m.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),m.computeBoundingSphere(),h.terminate(),c({geometry:m,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,o=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let n=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(o){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:n=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:n=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:n=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:n=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:n=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:n=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const r=this.createThreeMatrix4(n),a=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(r).applyMatrix4(a).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),o=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),n=new THREE__namespace.Line(o,s);return n.name=this.rangeObjectName,n}renderPointCloud(t,e){t.material.size=1,t.name=this.pointCloudObjectName;const i=new THREE__namespace.PointsMaterial({vertexColors:!0});if(i.onBeforeCompile=this.overridePointShader,e){const o=this.createRange(e);this.scene.add(o)}this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){}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}getSensesPointZAxisInPolygon(t,e){const i=this.scene.children.find(a=>a.uuid===this.pointsUuid);let o=0,s=0,n=0,r=0;if(i&&(i==null?void 0:i.geometry)){const a=i==null?void 0:i.geometry.attributes.position.array;for(let c=0;c<a.length;c+=3){const h=a[c],l=a[c+1],d=a[c+2];polygonTool.isInPolygon({x:h,y:l},t)&&d&&(s=Math.max(d,s),o=Math.min(d,o),r++,e&&d>=e[0]&&d<=e[1]&&n++)}}return{maxZ:s,minZ:o,count:n,zCount:r}}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:o},height:s,width:n,depth:r}=t,a={x:e+n/2,y:i+s/2,z:o-r/2},c={x:e+n/2,y:i+s/2,z:o+r/2},h={x:e-n/2,y:i+s/2,z:o+r/2},l={x:e-n/2,y:i+s/2,z:o-r/2};return[a,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:o},height:s,width:n,depth:r}=t,a={x:e-n/2,y:i+s/2,z:o+r/2},c={x:e-n/2,y:i+s/2,z:o-r/2},h={x:e-n/2,y:i-s/2,z:o-r/2},l={x:e-n/2,y:i-s/2,z:o+r/2};return[a,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:o},height:s,width:n,depth:r}=t,a={x:e+n/2,y:i+s/2,z:o+r/2},c={x:e+n/2,y:i-s/2,z:o+r/2},h={x:e-n/2,y:i-s/2,z:o+r/2},l={x:e-n/2,y:i+s/2,z:o+r/2};return[a,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:o},rotation:s}=t,n=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-o),r=new THREE__namespace.Matrix4().makeTranslation(e,i,o),a=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(r).multiply(a).multiply(n)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}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:o,height:s}=t,n=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),r=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(n).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=r;const a=i.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/o,h=this.containerHeight/s;return{polygon2d:a,zoom:Math.min(c,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(a=>new THREE__namespace.Vector3(a.x,a.y,a.z)).map(a=>a.applyMatrix4(this.getModelTransformationMatrix(t))).map(a=>({x:a.y,y:a.x})).map(a=>({x:-(a.x-this.containerWidth/2),y:-(a.y-this.containerHeight/2)})),n=this.containerWidth/e,r=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(n,r)/2}}getNewBoxBySideUpdate(t,e,i,o){const s=new THREE__namespace.Matrix4().makeRotationZ(o.rotation),n=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let r=o;return r.center={x:r.center.x+n.x,y:r.center.y+n.y,z:r.center.z-t.z},r=__spreadProps(__spreadValues({},r),{width:r.width+e,height:r.height,depth:r.depth+i}),{newBoxParams:r}}getNewBoxByBackUpdate(t,e,i,o){const s=new THREE__namespace.Matrix4().makeRotationZ(o.rotation),n=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let r=o;return r.center={x:r.center.x+n.x,y:r.center.y+n.y,z:r.center.z-t.z},r=__spreadProps(__spreadValues({},r),{width:r.width,height:r.height+e,depth:r.depth+i}),{newBoxParams:r}}getNewBoxBySideUpdateByPoints(t,e,i,o){var s;const n=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!n){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const r=t.map(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(n)),[a,c,h,l]=r,d=Math.max(Math.abs(a.x-h.x),Math.abs(a.x-c.x)),x=c.add(l).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(o.center.x,o.center.y,o.center.z));return{newBoxParams:__spreadProps(__spreadValues({},o),{center:{x:o.center.x-x.x,y:o.center.y-x.y,z:o.center.z-i},width:d,height:o.height,depth:o.depth+e,rotation:o.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:o}=i,s=[],{count:n}=o;for(let r=0;r<n;r++){const a=o.getZ(r);s.push(a>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.PointCloud=PointCloud;
@@ -1 +1 @@
1
- "use strict";var annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),polygonOperation=require("./polygonOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var r;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=StyleUtils.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,s;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(s=t.forbidAddNew)!=null?s:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var s,i,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=StyleUtils.getStrokeAndFill(a,e.valid),d=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(s=this.style)==null?void 0:s.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(d)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const s=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>__spreadProps(__spreadValues({},n),{pointList:AxisUtils.default.changePointListByZoom(n.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(s,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var r,n,a,l;return __spreadProps(__spreadValues({},i),{x:(n=(r=i.pointList[0])==null?void 0:r.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),s=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(s)return this.setSelectedIDs([s.id]),this.render(),[s.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,s;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(s=this._textAttributInstance)==null||s.clearTextAttribute(),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,s;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(s=this.basicCtx)==null||s.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}}module.exports=PointCloud2dOperation;
1
+ "use strict";var annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),polygonOperation=require("./polygonOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__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},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var o;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=StyleUtils.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,s;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(s=t.forbidAddNew)!=null?s:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var s,i,o;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=StyleUtils.getStrokeAndFill(a,e.valid),d=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(s=this.style)==null?void 0:s.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(d)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const s=this.getCoordinateUnderZoom(t),o=this.currentPolygonListByPattern.map(n=>__spreadProps(__spreadValues({},n),{pointList:AxisUtils.default.changePointListByZoom(n.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(s,o,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var o,n,a,l;return __spreadProps(__spreadValues({},i),{x:(n=(o=i.pointList[0])==null?void 0:o.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),s=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(s)return this.setSelectedIDs([s.id]),this.render(),[s.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,s;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(s=this._textAttributInstance)==null||s.clearTextAttribute(),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,s;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(s=this.basicCtx)==null||s.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}module.exports=PointCloud2dOperation;
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const n=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:n},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),n=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(n,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:o}=PolygonUtils.getClosestPoint(n,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),l=AxisUtils.default.changePointByZoom(o&&t.altKey===!1&&i?o:n,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>i.id===t?__spreadProps(__spreadValues({},i),{valid:!i.valid}):i);this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=CommonToolUtils.getSourceID(this.basicResult),n=[...this.polygonList];if(this.editPolygonID){const r=n.find(o=>o.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=uuid(8,62);let o={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(n.filter(l=>CommonToolUtils.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),o=__spreadProps(__spreadValues({},o),{textAttribute:l})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(o=__spreadProps(__spreadValues({},o),{isRect:!0})),n.push(o),i=o,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(n),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(n),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(n=>__spreadProps(__spreadValues({},n),{pointList:AxisUtils.default.changePointListByZoom(n.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),n=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,n,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const n=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,c,d,a;return __spreadProps(__spreadValues({},l),{x:(c=(h=l.pointList[0])==null?void 0:h.x)!=null?c:0,y:(a=(d=l.pointList[0])==null?void 0:d.y)!=null?a:0})}).filter(l=>CanvasUtils.inViewPort({x:l.x,y:l.y},n)),o=CommonToolUtils.getNextSelectedRectID(r,t,this.selectedID);if(o){this.setSelectedID(o.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygon(this.selectedID),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:n}=this.config;if(n&&i.pointList.length>=n){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${n}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,n=this.getCoordinateUnderZoom(t);let r=[0],o=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(o=annotation.EDragTarget.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(o=annotation.EDragTarget.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:n,dragTarget:o,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let n=[...this.polygonList];if(s===-1){const r=PolygonUtils.segmentPolygonByPolygon(e,i);if(!r)return;const o=r.shift();if(!o)return;let l="",h=!0;const c=CommonToolUtils.getSourceID(this.basicResult);let d="";n=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(l=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,d=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:o})):a}),r.length>0&&r.forEach((a,u)=>{n.push({sourceID:c,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:l,textAttribute:d})})}else n[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,n[s].pointList),n=n.filter(r=>r.id!==this.selectedID);this.setPolygonList(n),this.history.pushHistory(n),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),n=this.currentShowList.find(h=>h.id===i);if(!n||!s)return;const r=PolygonUtils.combinePolygonWithPolygon(s,n);if(!r)return;const{newPolygon:o,unionList:l}=r;if(l.length===1&&o){const h=this.polygonList.filter(c=>!l.includes(c.id)).map(c=>c.id===this.selectedID?o:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let o=!1;switch(this.dependToolName){case tool.EToolName.Rect:{o=t.filter(l=>!RectUtils.isInRect(l,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{o=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return o}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:n}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||n>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:n,dragTarget:r,changePointIndex:o}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-n.x)/this.zoom,y:(l.y-n.y)/this.zoom};if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o&&[annotation.EDragTarget.Line].includes(r)){const d=MathUtils.default.getArrayIndex(o[0]-2,4),a=MathUtils.default.getArrayIndex(o[0]-1,4),u=[s[d],s[a]];h=MathUtils.default.getRectPerpendicularOffset(n,l,u),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=annotation.EDragStatus.Move,r){case annotation.EDragTarget.Plane:i=i.map((d,a)=>__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((d,a)=>o&&o.includes(a)?__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}):d);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&r===annotation.EDragTarget.Point&&o&&(i=MathUtils.default.getPointListFromPointOffset(s,o[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const c=this.polygonList.map(d=>{if(d.id===this.selectedID){const a=__spreadProps(__spreadValues({},d),{pointList:i});return d.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(a,{isRect:!1}),a}return d});this.setPolygonList(c),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const n=this.getHoverID(t);this.hoverID!==n&&(this.hoverID=n,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:n,textAttribute:r}=e,{x:o,y:l}=i[i.length-1],h=TEXT_MAX_WIDTH,c=AxisUtils.default.getOffsetCoordinate({x:o,y:l},this.currentPos,this.zoom),d=this.getColor(s),a=n?d==null?void 0:d.valid.stroke:d==null?void 0:d.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:c.x,top:c.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,n,r,o;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,c=this.getColor(h),d=StyleUtils.getStrokeAndFill(c,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:d.fill,strokeColor:d.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType});let u=`${(r=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((o=this.config)==null?void 0:o.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},l,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const n=this.getColor(s.attribute),r=StyleUtils.getStrokeAndFill(n,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let o=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(o=`${s.order} ${o}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),o,__spreadValues({color:r.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const n=this.getColor(this.defaultAttribute),r=StyleUtils.getStrokeAndFill(n,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let o=[...this.drawingPointList],l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&o.length===2)o=MathUtils.default.getRectangleByRightAngle(l,o);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(l=h)}o.push(l)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(o,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const o=this.selectedPolygon;if(!o)return;const l=StyleUtils.getStrokeAndFill(n,o.valid,{isSelected:!0}),h=o==null?void 0:o.pointList[this.hoverPointIndex];if(h){const{x:c,y:d}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:c,y:d},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const o=this.selectedPolygon;if(!o)return;const l=StyleUtils.getStrokeAndFill(n,o.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(o.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,n=186,r=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:n,height:r},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:n/2+s,offsetY:-(r/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),l=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=uuid(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(l=>CommonToolUtils.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:l})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,c,d,a;return __spreadProps(__spreadValues({},l),{x:(c=(h=l.pointList[0])==null?void 0:h.x)!=null?c:0,y:(a=(d=l.pointList[0])==null?void 0:d.y)!=null?a:0})}).filter(l=>CanvasUtils.inViewPort({x:l.x,y:l.y},o)),n=CommonToolUtils.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygon(this.selectedID),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(n=annotation.EDragTarget.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=annotation.EDragTarget.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=PolygonUtils.segmentPolygonByPolygon(e,i);if(!r)return;const n=r.shift();if(!n)return;let l="",h=!0;const c=CommonToolUtils.getSourceID(this.basicResult);let d="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(l=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,d=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),r.length>0&&r.forEach((a,u)=>{o.push({sourceID:c,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:l,textAttribute:d})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=PolygonUtils.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(c=>!l.includes(c.id)).map(c=>c.id===this.selectedID?n:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(l=>!RectUtils.isInRect(l,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(r)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),a=MathUtils.default.getArrayIndex(n[0]-1,4),u=[s[d],s[a]];h=MathUtils.default.getRectPerpendicularOffset(o,l,u),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=annotation.EDragStatus.Move,r){case annotation.EDragTarget.Plane:i=i.map((d,a)=>__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((d,a)=>n&&n.includes(a)?__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}):d);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&r===annotation.EDragTarget.Point&&n&&(i=MathUtils.default.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const c=this.polygonList.map(d=>{if(d.id===this.selectedID){const a=__spreadProps(__spreadValues({},d),{pointList:i});return d.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(a,{isRect:!1}),a}return d});this.setPolygonList(c),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:n,y:l}=i[i.length-1],h=TEXT_MAX_WIDTH,c=AxisUtils.default.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),d=this.getColor(s),a=o?d==null?void 0:d.valid.stroke:d==null?void 0:d.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:c.x,top:c.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,c=this.getColor(h),d=StyleUtils.getStrokeAndFill(c,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:d.fill,strokeColor:d.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(r=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},l,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=StyleUtils.getStrokeAndFill(o,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:r.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(l=h)}n.push(l)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:c,y:d}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:c,y:d},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,r=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
@@ -80,6 +80,16 @@ declare class PointCloud2dOperation extends PolygonOperation {
80
80
  * @param size
81
81
  */
82
82
  setCanvasSize(size: ISize): void;
83
+ /**
84
+ * If the operation is triggered internally, it will emit validUpdate.
85
+ *
86
+ * The Invalid update needs to be added a params.
87
+ * @override
88
+ * @param id
89
+ * @param forbidEmit
90
+ * @returns
91
+ */
92
+ setPolygonValidAndRender(id: string, isUpdate?: boolean): void;
83
93
  }
84
94
  export default PointCloud2dOperation;
85
95
  export { IPointCloud2dOperationProps };
@@ -1 +1 @@
1
- import{PointCloudUtils as h}from"@labelbee/lb-utils";import{EPolygonPattern as O}from"../../constant/tool.js";import{CanvasScheduler as I}from"../../newCore/CanvasScheduler.js";import{PointCloud as w}from"./index.js";import y from"../toolOperation/pointCloud2dOperation.js";const g=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""};class D{constructor({size:t,container:o,pcdPath:n,polygonOperationProps:l}){this.updatePolygonList=(f,c)=>{let r=f.map(u=>{const{polygon2d:P}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(u);return{id:u.id,sourceID:"",pointList:P,isRect:!0}});c&&(r=r.concat(c)),this.pointCloud2dOperation.setResult(r)};const C=this.getDefaultOrthographic(t),m=g(t),d=new Image;d.src=m;const a=new I({container:o}),s=new w({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:C});n&&s.loadPCDFile(n),a.createCanvas(s.renderer.domElement);const p={container:o,size:t,config:'{ "textConfigurable": false }',imgNode:d,isAppend:!1};l&&Object.assign(p,l);const e=new y(p);e.eventBinding(),e.setPattern(O.Rect),a.createCanvas(e.canvas,{size:t}),this.pointCloud2dOperation=e,this.pointCloudInstance=s,this.canvasScheduler=a}getDefaultOrthographic(t){return{left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100}}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(t)),this.pointCloudInstance.render();const o=g(t),n=new Image;n.src=o,n.onload=()=>{this.pointCloud2dOperation.setImgNode(n),this.pointCloud2dOperation.setCanvasSize(t),this.pointCloud2dOperation.initImgPos()}}addPolygonListOnTopView(t){const o=h.getBoxParamsFromResultList(t),n=h.getPolygonListFromResultList(t);this.updatePolygonList(o,n)}updateData(t,o,n){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,n==null?void 0:n.radius),this.addPolygonListOnTopView(o))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{D as PointCloudAnnotation};
1
+ import{PointCloudUtils as g}from"@labelbee/lb-utils";import{EPolygonPattern as I}from"../../constant/tool.js";import{CanvasScheduler as v}from"../../newCore/CanvasScheduler.js";import{PointCloud as w}from"./index.js";import y from"../toolOperation/pointCloud2dOperation.js";const C=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""};class D{constructor({size:t,container:o,pcdPath:n,polygonOperationProps:d}){this.updatePolygonList=(P,u)=>{let l=P.map(r=>{var h;const{polygon2d:O}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(r);return{id:r.id,sourceID:"",pointList:O,isRect:!0,valid:(h=r.valid)!=null?h:!0}});u&&(l=l.concat(u)),this.pointCloud2dOperation.setResult(l)};const m=this.getDefaultOrthographic(t),f=C(t),p=new Image;p.src=f;const a=new v({container:o}),s=new w({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:m});n&&s.loadPCDFile(n),a.createCanvas(s.renderer.domElement);const c={container:o,size:t,config:'{ "textConfigurable": false }',imgNode:p,isAppend:!1};d&&Object.assign(c,d);const e=new y(c);e.eventBinding(),e.setPattern(I.Rect),a.createCanvas(e.canvas,{size:t}),this.pointCloud2dOperation=e,this.pointCloudInstance=s,this.canvasScheduler=a}getDefaultOrthographic(t){return{left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100}}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(t)),this.pointCloudInstance.render();const o=C(t),n=new Image;n.src=o,n.onload=()=>{this.pointCloud2dOperation.setImgNode(n),this.pointCloud2dOperation.setCanvasSize(t),this.pointCloud2dOperation.initImgPos()}}addPolygonListOnTopView(t){const o=g.getBoxParamsFromResultList(t),n=g.getPolygonListFromResultList(t);this.updatePolygonList(o,n)}updateData(t,o,n){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,n==null?void 0:n.radius),this.addPolygonListOnTopView(o))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{D as PointCloudAnnotation};
@@ -1,11 +1,11 @@
1
- import*as c from"three";import{MatrixUtils as C,PointCloudUtils as k,PerspectiveShiftUtils as f,EPerspectiveView as y}from"@labelbee/lb-utils";import _ from"../../_virtual/highlightWorker.js";import A from"../../_virtual/filterBoxWorker.js";import{isInPolygon as j}from"../../utils/tool/polygonTool.js";import L from"../../utils/uuid.js";import{PCDLoader as S}from"./PCDLoader.js";import{OrbitControls as N}from"./OrbitControls.js";import{PointCloudCache as I}from"./cache.js";var D=Object.defineProperty,F=Object.defineProperties,R=Object.getOwnPropertyDescriptors,z=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,P=(x,t,e)=>t in x?D(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,M=(x,t)=>{for(var e in t||(t={}))E.call(t,e)&&P(x,e,t[e]);if(z)for(var e of z(t))W.call(t,e)&&P(x,e,t[e]);return x},b=(x,t)=>F(x,R(t)),v=(x,t,e)=>new Promise((i,r)=>{var a=s=>{try{o(e.next(s))}catch(h){r(h)}},n=s=>{try{o(e.throw(s))}catch(h){r(h)}},o=s=>s.done?i(s.value):Promise.resolve(s.value).then(a,n);o((e=e.apply(x,t)).next())});const H=30;new _;class U{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="black"}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(n,o=16777215)=>{var s;const h=(s=n.id)!=null?s:L();this.removeObjectByName(h);const{center:l,width:p,height:d,depth:u,rotation:w}=n,m=new c.Group,g=new c.BoxGeometry(p,d,u),B=new c.MeshBasicMaterial({color:"blue"}),T=new c.Mesh(g,B),V=new c.BoxHelper(T,o),O=this.generateBoxArrow(n);m.add(V),m.add(O),m.position.set(l.x,l.y,l.z),m.rotation.set(0,0,w),m.name=h,this.scene.add(m)},this.overridePointShader=n=>{n.vertexShader=`
1
+ import*as c from"three";import{MatrixUtils as v,PointCloudUtils as k,PerspectiveShiftUtils as f,EPerspectiveView as y}from"@labelbee/lb-utils";import _ from"../../_virtual/highlightWorker.js";import A from"../../_virtual/filterBoxWorker.js";import{isInPolygon as j}from"../../utils/tool/polygonTool.js";import L from"../../utils/uuid.js";import{PCDLoader as S}from"./PCDLoader.js";import{OrbitControls as I}from"./OrbitControls.js";import{PointCloudCache as N}from"./cache.js";var D=Object.defineProperty,F=Object.defineProperties,R=Object.getOwnPropertyDescriptors,b=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,P=(x,t,e)=>t in x?D(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,M=(x,t)=>{for(var e in t||(t={}))E.call(t,e)&&P(x,e,t[e]);if(b)for(var e of b(t))W.call(t,e)&&P(x,e,t[e]);return x},C=(x,t)=>F(x,R(t)),z=(x,t,e)=>new Promise((i,n)=>{var s=a=>{try{r(e.next(a))}catch(h){n(h)}},o=a=>{try{r(e.throw(a))}catch(h){n(h)}},r=a=>a.done?i(a.value):Promise.resolve(a.value).then(s,o);r((e=e.apply(x,t)).next())});const H=30;new _;class Z{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:n,backgroundColor:s="black"}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(o,r=16777215)=>{var a;const h=(a=o.id)!=null?a:L();this.removeObjectByName(h);const{center:l,width:p,height:d,depth:w,rotation:g}=o,m=new c.Group,u=new c.BoxGeometry(p,d,w),B=new c.MeshBasicMaterial({color:"blue"}),T=new c.Mesh(u,B),V=new c.BoxHelper(T,r),O=this.generateBoxArrow(o);m.add(V),m.add(O),m.position.set(l.x,l.y,l.z),m.rotation.set(0,0,g),m.name=h,this.scene.add(m)},this.overridePointShader=o=>{o.vertexShader=`
2
2
  attribute float sizes;
3
3
  attribute float visibility;
4
4
  varying float vVisible;
5
- ${n.vertexShader}`.replace("gl_PointSize = size;",`gl_PointSize = size;
5
+ ${o.vertexShader}`.replace("gl_PointSize = size;",`gl_PointSize = size;
6
6
  vVisible = visibility;
7
- `),n.fragmentShader=`
7
+ `),o.fragmentShader=`
8
8
  varying float vVisible;
9
- ${n.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
9
+ ${o.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
10
10
  if (vVisible < 0.5) discard;
11
- #include <clipping_planes_fragment>`)},this.loadPCDFile=(n,o)=>v(this,null,function*(){const s=yield this.cacheInstance.loadPCDFile(n);s.name=this.pointCloudObjectName,this.renderPointCloud(s,o)}),this.loadPCDFileByBox=(n,o,s)=>v(this,null,function*(){const h=p=>v(this,null,function*(){const{width:d=0,height:u=0,depth:w=0}=s!=null?s:{},m=yield this.filterPointsByBox(b(M({},o),{width:o.width+d,height:o.height+u,depth:o.depth+w}),p);if(!m){console.error("filter Error");return}this.clearPointCloud();const g=new c.Points(m.geometry,p.material);g.name=this.pointCloudObjectName,this.scene.add(g),this.render()}),l=yield this.cacheInstance.loadPCDFile(n);h(l)}),this.generateBoxArrow=({width:n})=>{const o=new c.Vector3(1,0,0),s=new c.Vector3(n/2,0,0),h=2,l=16776960,p=new c.ArrowHelper(o,s,h,l);return p.visible=this.showDirection,p},this.generateBoxTrackID=n=>{if(!n.trackID)return;const o=new c.Texture(this.getTextCanvas(n.trackID.toString()));o.needsUpdate=!0;const s=new c.SpriteMaterial({map:o,depthWrite:!1}),h=new c.Sprite(s);return h.scale.set(5,5,5),h.position.set(-n.width/2,0,n.depth/2+.5),h},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=n=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const s=o.material.size;n?o.material.size=Math.min(s*1.2,10):o.material.size=Math.max(s/1.2,1),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=a,i&&r?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new N(this.camera,this.renderer.domElement),this.pcdLoader=new S,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=I.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-1,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:a,near:n,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=n,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 c.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 c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}transferKitti2Matrix(t,e,i){const r=C.transferMatrix34FromKitti2Three(t),a=C.transferMatrix33FromKitti2Three(e),n=C.transferMatrix34FromKitti2Three(i),o=this.createThreeMatrix4(r),s=this.createThreeMatrix4(a),h=this.createThreeMatrix4(n);return{composeMatrix4:h.clone().premultiply(s).premultiply(o),PM:o,RM:s,TM:h}}pointCloudLidar2image(t,e){const i=k.getAllViewData(t),{P:r,R:a,T:n}=e,{composeMatrix4:o}=this.transferKitti2Matrix(r,a,n);return i.map(h=>({type:h.type,pointList:h.pointList.map(l=>this.rotatePoint(l,t.center,t.rotation)).map(l=>this.lidar2image(l,o)).filter(l=>l!==void 0)})).filter(h=>h.pointList.length!==0)}lidar2image(t,e){const r=new c.Vector4(t.x,t.y,t.z).applyMatrix4(e);if(r.z<0)return;const a=1/r.z,n=new c.Matrix4().set(a,0,0,0,0,a,0,0,0,0,a,0,0,0,0,1);return r.applyMatrix4(n)}generateBox(t,e=16777215){this.AddBoxToSense(t,e),this.render()}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,a=10,n=e.x-i/2-a,o=e.x-i/2+a,s=e.y+r/2+a,h=e.y-r/2-a,l=100,p=-100,d=500/l;return{left:n,right:o,top:s,bottom:h,near:l,far:p,zoom:d}}updateCameraByBox(t,e){const{center:i,width:r,height:a,depth:n,rotation:o}=t,s=this.getCameraVector(i,o,{width:r,height:a,depth:n},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}}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 c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new c.Matrix4().set(...t)}rotatePoint(t,e,i){var r;const a=new c.Vector3(t.x,t.y,(r=t==null?void 0:t.z)!=null?r:1),n=new c.Matrix4().makeRotationZ(i),o=new c.Matrix4().makeTranslation(e.x,e.y,e.z),s=new c.Matrix4().makeTranslation(-e.x,-e.y,-e.z);return a.clone().applyMatrix4(s).applyMatrix4(n).applyMatrix4(o)}getCuboidFromPointCloudBox(t){const{center:e,width:i,height:r,depth:a,rotation:n}=t,o=[{x:e.x+i/2,y:e.y-r/2},{x:e.x+i/2,y:e.y+r/2},{x:e.x-i/2,y:e.y+r/2},{x:e.x-i/2,y:e.y-r/2}].map(l=>{const p=this.rotatePoint(l,e,n);return{x:p.x,y:p.y}}),s=e.z+a/2,h=e.z-a/2;return{polygonPointList:o,zMax:s,zMin:h}}filterPointsByBox(t,e){if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=i}if(window.Worker){const{zMin:i,zMax:r,polygonPointList:a}=this.getCuboidFromPointCloudBox(t),n=e.geometry.attributes.position.array,o=e.geometry.attributes.color.array,s={boxParams:t,zMin:i,zMax:r,polygonPointList:a,color:o,position:n};return new Promise(h=>{const l=new A;l.postMessage(s),l.onmessage=p=>{const{color:d,position:u,num:w}=p.data,m=new c.BufferGeometry;m.setAttribute("position",new c.Float32BufferAttribute(u,3)),m.setAttribute("color",new c.Float32BufferAttribute(d,3)),m.computeBoundingSphere(),l.terminate(),h({geometry:m,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=y.Front,a=H){let n=f.frontViewMatrix4(a);switch(r){case y.Front:break;case y.Back:n=f.backViewMatrix4(a);break;case y.Left:n=f.leftViewMatrix4(a);break;case y.Right:n=f.rightViewMatrix4(a);break;case y.Top:n=f.topViewMatrix4(a);break;case y.LFT:n=f.leftFrontTopViewMatrix4(a,i);break;case y.RBT:n=f.rightBackTopViewMatrix4(a,i);break}const o=this.createThreeMatrix4(n),s=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(s).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new c.BufferGeometry().setFromPoints(i),a=new c.LineBasicMaterial({color:16711680}),n=new c.Line(r,a);return n.name=this.rangeObjectName,n}renderPointCloud(t,e){t.material.size=1,t.name=this.pointCloudObjectName;const i=new c.PointsMaterial({vertexColors:!0});if(i.onBeforeCompile=this.overridePointShader,e){const a=this.createRange(e);this.scene.add(a)}this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t);const r=this.scene.getObjectByName(this.pointCloudObjectName);r?(r.geometry.attributes.color=t.geometry.attributes.color,r.geometry.attributes.position=t.geometry.attributes.position,r.geometry.attributes.color.needsUpdate=!0,r.geometry.attributes.position.needsUpdate=!0,r.uuid=t.uuid):this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){}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}getSensesPointZAxisInPolygon(t,e){const i=this.scene.children.find(s=>s.uuid===this.pointsUuid);let r=0,a=0,n=0,o=0;if(i&&(i==null?void 0:i.geometry)){const s=i==null?void 0:i.geometry.attributes.position;for(let h=0;h<s.count;h++){const l=h*3,p=s.getX(l),d=s.getY(l),u=s.getZ(l);j({x:p,y:d},t)&&u&&(a=Math.max(u,a),r=Math.min(u,r),o++,e&&u>=e[0]&&u<=e[1]&&n++)}}return{maxZ:a,minZ:r,count:n,zCount:o}}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 c.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 c.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:a,width:n,depth:o}=t,s={x:e+n/2,y:i+a/2,z:r-o/2},h={x:e+n/2,y:i+a/2,z:r+o/2},l={x:e-n/2,y:i+a/2,z:r+o/2},p={x:e-n/2,y:i+a/2,z:r-o/2};return[s,h,l,p]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:n,depth:o}=t,s={x:e-n/2,y:i+a/2,z:r+o/2},h={x:e-n/2,y:i+a/2,z:r-o/2},l={x:e-n/2,y:i-a/2,z:r-o/2},p={x:e-n/2,y:i-a/2,z:r+o/2};return[s,h,l,p]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:n,depth:o}=t,s={x:e+n/2,y:i+a/2,z:r+o/2},h={x:e+n/2,y:i-a/2,z:r+o/2},l={x:e-n/2,y:i-a/2,z:r+o/2},p={x:e-n/2,y:i+a/2,z:r+o/2};return[s,h,l,p]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,n=new c.Matrix4().makeTranslation(-e,-i,-r),o=new c.Matrix4().makeTranslation(e,i,r),s=new c.Matrix4().makeRotationZ(a);return new c.Matrix4().multiply(o).multiply(s).multiply(n)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,y.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,y.Back)}boxParams2ViewPolygon(t,e){switch(e){case y.Left:return this.getPolygonSidePoints(t);case y.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:a}=t,n=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(n).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const s=i.map(p=>new c.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(this.sideMatrix)),h=this.containerWidth/r,l=this.containerHeight/a;return{polygon2d:s,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(s=>new c.Vector3(s.x,s.y,s.z)).map(s=>s.applyMatrix4(this.getModelTransformationMatrix(t))).map(s=>({x:s.y,y:s.x})).map(s=>({x:-(s.x-this.containerWidth/2),y:-(s.y-this.containerHeight/2)})),n=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(n,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new c.Matrix4().makeRotationZ(r.rotation),n=new c.Vector3(-t.x,0,0).applyMatrix4(a);let o=r;return o.center={x:o.center.x+n.x,y:o.center.y+n.y,z:o.center.z-t.z},o=b(M({},o),{width:o.width+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const a=new c.Matrix4().makeRotationZ(r.rotation),n=new c.Vector3(0,-t.x,0).applyMatrix4(a);let o=r;return o.center={x:o.center.x+n.x,y:o.center.y+n.y,z:o.center.z-t.z},o=b(M({},o),{width:o.width,height:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const n=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!n){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new c.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(n)),[s,h,l,p]=o,d=Math.max(Math.abs(s.x-l.x),Math.abs(s.x-h.x)),w=h.add(p).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:b(M({},r),{center:{x:r.center.x-w.x,y:r.center.y-w.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,a=[],{count:n}=r;for(let o=0;o<n;o++){const s=r.getZ(o);a.push(s>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{U as PointCloud};
11
+ #include <clipping_planes_fragment>`)},this.loadPCDFile=(o,r)=>z(this,null,function*(){this.clearPointCloud();const a=yield this.cacheInstance.loadPCDFile(o);a.name=this.pointCloudObjectName,this.renderPointCloud(a,r)}),this.loadPCDFileByBox=(o,r,a)=>z(this,null,function*(){const h=p=>z(this,null,function*(){const{width:d=0,height:w=0,depth:g=0}=a!=null?a:{},m=yield this.filterPointsByBox(C(M({},r),{width:r.width+d,height:r.height+w,depth:r.depth+g}),p);if(!m){console.error("filter Error");return}this.clearPointCloud();const u=new c.Points(m.geometry,p.material);u.name=this.pointCloudObjectName,this.scene.add(u),this.render()}),l=yield this.cacheInstance.loadPCDFile(o);h(l)}),this.generateBoxArrow=({width:o})=>{const r=new c.Vector3(1,0,0),a=new c.Vector3(o/2,0,0),h=2,l=16776960,p=new c.ArrowHelper(r,a,h,l);return p.visible=this.showDirection,p},this.generateBoxTrackID=o=>{if(!o.trackID)return;const r=new c.Texture(this.getTextCanvas(o.trackID.toString()));r.needsUpdate=!0;const a=new c.SpriteMaterial({map:r,depthWrite:!1}),h=new c.Sprite(a);return h.scale.set(5,5,5),h.position.set(-o.width/2,0,o.depth/2+.5),h},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=o=>{const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!r)return;const a=r.material.size;o?r.material.size=Math.min(a*1.2,10):r.material.size=Math.max(a/1.2,1),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,i&&n?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new I(this.camera,this.renderer.domElement),this.pcdLoader=new S,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=N.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-1,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:n,bottom:s,near:o,far:r}=t;this.camera.left=e,this.camera.right=i,this.camera.top=n,this.camera.bottom=s,this.camera.near=o,this.camera.far=r,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:n}=this.initCameraPosition;t.position.set(e,i,n)}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 c.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 c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}transferKitti2Matrix(t,e,i){const n=v.transferMatrix34FromKitti2Three(t),s=v.transferMatrix33FromKitti2Three(e),o=v.transferMatrix34FromKitti2Three(i),r=this.createThreeMatrix4(n),a=this.createThreeMatrix4(s),h=this.createThreeMatrix4(o);return{composeMatrix4:h.clone().premultiply(a).premultiply(r),PM:r,RM:a,TM:h}}pointCloudLidar2image(t,e){const i=k.getAllViewData(t),{P:n,R:s,T:o}=e,{composeMatrix4:r}=this.transferKitti2Matrix(n,s,o);return i.map(h=>({type:h.type,pointList:h.pointList.map(l=>this.rotatePoint(l,t.center,t.rotation)).map(l=>this.lidar2image(l,r)).filter(l=>l!==void 0)})).filter(h=>h.pointList.length!==0)}lidar2image(t,e){const n=new c.Vector4(t.x,t.y,t.z).applyMatrix4(e);if(n.z<0)return;const s=1/n.z,o=new c.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return n.applyMatrix4(o)}generateBox(t,e=16777215){this.AddBoxToSense(t,e),this.render()}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:n}=t,s=10,o=e.x-i/2-s,r=e.x-i/2+s,a=e.y+n/2+s,h=e.y-n/2-s,l=100,p=-100,d=500/l;return{left:o,right:r,top:a,bottom:h,near:l,far:p,zoom:d}}updateCameraByBox(t,e){const{center:i,width:n,height:s,depth:o,rotation:r}=t,a=this.getCameraVector(i,r,{width:n,height:s,depth:o},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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 c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new c.Matrix4().set(...t)}rotatePoint(t,e,i){var n;const s=new c.Vector3(t.x,t.y,(n=t==null?void 0:t.z)!=null?n:1),o=new c.Matrix4().makeRotationZ(i),r=new c.Matrix4().makeTranslation(e.x,e.y,e.z),a=new c.Matrix4().makeTranslation(-e.x,-e.y,-e.z);return s.clone().applyMatrix4(a).applyMatrix4(o).applyMatrix4(r)}getCuboidFromPointCloudBox(t){const{center:e,width:i,height:n,depth:s,rotation:o}=t,r=[{x:e.x+i/2,y:e.y-n/2},{x:e.x+i/2,y:e.y+n/2},{x:e.x-i/2,y:e.y+n/2},{x:e.x-i/2,y:e.y-n/2}].map(l=>{const p=this.rotatePoint(l,e,o);return{x:p.x,y:p.y}}),a=e.z+s/2,h=e.z-s/2;return{polygonPointList:r,zMax:a,zMin:h}}filterPointsByBox(t,e){if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=i}if(window.Worker){const{zMin:i,zMax:n,polygonPointList:s}=this.getCuboidFromPointCloudBox(t),o=e.geometry.attributes.position.array,r=e.geometry.attributes.color.array,a={boxParams:t,zMin:i,zMax:n,polygonPointList:s,color:r,position:o};return new Promise(h=>{const l=new A;l.postMessage(a),l.onmessage=p=>{const{color:d,position:w,num:g}=p.data,m=new c.BufferGeometry;m.setAttribute("position",new c.Float32BufferAttribute(w,3)),m.setAttribute("color",new c.Float32BufferAttribute(d,3)),m.computeBoundingSphere(),l.terminate(),h({geometry:m,num:g})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,n=y.Front,s=H){let o=f.frontViewMatrix4(s);switch(n){case y.Front:break;case y.Back:o=f.backViewMatrix4(s);break;case y.Left:o=f.leftViewMatrix4(s);break;case y.Right:o=f.rightViewMatrix4(s);break;case y.Top:o=f.topViewMatrix4(s);break;case y.LFT:o=f.leftFrontTopViewMatrix4(s,i);break;case y.RBT:o=f.rightBackTopViewMatrix4(s,i);break}const r=this.createThreeMatrix4(o),a=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(r).applyMatrix4(a).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new c.BufferGeometry().setFromPoints(i),s=new c.LineBasicMaterial({color:16711680}),o=new c.Line(n,s);return o.name=this.rangeObjectName,o}renderPointCloud(t,e){t.material.size=1,t.name=this.pointCloudObjectName;const i=new c.PointsMaterial({vertexColors:!0});if(i.onBeforeCompile=this.overridePointShader,e){const n=this.createRange(e);this.scene.add(n)}this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){}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}getSensesPointZAxisInPolygon(t,e){const i=this.scene.children.find(a=>a.uuid===this.pointsUuid);let n=0,s=0,o=0,r=0;if(i&&(i==null?void 0:i.geometry)){const a=i==null?void 0:i.geometry.attributes.position.array;for(let h=0;h<a.length;h+=3){const l=a[h],p=a[h+1],d=a[h+2];j({x:l,y:p},t)&&d&&(s=Math.max(d,s),n=Math.min(d,n),r++,e&&d>=e[0]&&d<=e[1]&&o++)}}return{maxZ:s,minZ:n,count:o,zCount:r}}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 c.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 c.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:n},height:s,width:o,depth:r}=t,a={x:e+o/2,y:i+s/2,z:n-r/2},h={x:e+o/2,y:i+s/2,z:n+r/2},l={x:e-o/2,y:i+s/2,z:n+r/2},p={x:e-o/2,y:i+s/2,z:n-r/2};return[a,h,l,p]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:n},height:s,width:o,depth:r}=t,a={x:e-o/2,y:i+s/2,z:n+r/2},h={x:e-o/2,y:i+s/2,z:n-r/2},l={x:e-o/2,y:i-s/2,z:n-r/2},p={x:e-o/2,y:i-s/2,z:n+r/2};return[a,h,l,p]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:n},height:s,width:o,depth:r}=t,a={x:e+o/2,y:i+s/2,z:n+r/2},h={x:e+o/2,y:i-s/2,z:n+r/2},l={x:e-o/2,y:i-s/2,z:n+r/2},p={x:e-o/2,y:i+s/2,z:n+r/2};return[a,h,l,p]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:n},rotation:s}=t,o=new c.Matrix4().makeTranslation(-e,-i,-n),r=new c.Matrix4().makeTranslation(e,i,n),a=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(r).multiply(a).multiply(o)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,y.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,y.Back)}boxParams2ViewPolygon(t,e){switch(e){case y.Left:return this.getPolygonSidePoints(t);case y.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,o=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),r=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(o).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=r;const a=i.map(p=>new c.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:a,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(a=>new c.Vector3(a.x,a.y,a.z)).map(a=>a.applyMatrix4(this.getModelTransformationMatrix(t))).map(a=>({x:a.y,y:a.x})).map(a=>({x:-(a.x-this.containerWidth/2),y:-(a.y-this.containerHeight/2)})),o=this.containerWidth/e,r=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(o,r)/2}}getNewBoxBySideUpdate(t,e,i,n){const s=new c.Matrix4().makeRotationZ(n.rotation),o=new c.Vector3(-t.x,0,0).applyMatrix4(s);let r=n;return r.center={x:r.center.x+o.x,y:r.center.y+o.y,z:r.center.z-t.z},r=C(M({},r),{width:r.width+e,height:r.height,depth:r.depth+i}),{newBoxParams:r}}getNewBoxByBackUpdate(t,e,i,n){const s=new c.Matrix4().makeRotationZ(n.rotation),o=new c.Vector3(0,-t.x,0).applyMatrix4(s);let r=n;return r.center={x:r.center.x+o.x,y:r.center.y+o.y,z:r.center.z-t.z},r=C(M({},r),{width:r.width,height:r.height+e,depth:r.depth+i}),{newBoxParams:r}}getNewBoxBySideUpdateByPoints(t,e,i,n){var s;const o=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!o){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const r=t.map(u=>new c.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(o)),[a,h,l,p]=r,d=Math.max(Math.abs(a.x-l.x),Math.abs(a.x-h.x)),g=h.add(p).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:C(M({},n),{center:{x:n.center.x-g.x,y:n.center.y-g.y,z:n.center.z-i},width:d,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:n}=i,s=[],{count:o}=n;for(let r=0;r<o;r++){const a=n.getZ(r);s.push(a>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{Z as PointCloud};
@@ -1 +1 @@
1
- import{ESortDirection as v}from"../../constant/annotation.js";import{EPolygonPattern as u}from"../../constant/tool.js";import c from"../../utils/tool/AxisUtils.js";import m from"../../utils/tool/CommonToolUtils.js";import d from"../../utils/tool/DrawUtils.js";import g from"../../utils/tool/PolygonUtils.js";import p from"../../utils/tool/StyleUtils.js";import I from"./polygonOperation.js";var _=Object.defineProperty,S=Object.defineProperties,L=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,P=(s,t,e)=>t in s?_(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,y=(s,t)=>{for(var e in t||(t={}))w.call(t,e)&&P(s,e,t[e]);if(f)for(var e of f(t))C.call(t,e)&&P(s,e,t[e]);return s},D=(s,t)=>S(s,L(t));class b extends I{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var r;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=p.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=c.changePointListByZoom(i.pointList,this.zoom,this.currentPos);d.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,o;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(o=t.forbidAddNew)!=null?o:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return g.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var o,i,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=p.getStrokeAndFill(a,e.valid),h=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);d.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(o=this.style)==null?void 0:o.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||d.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===u.Rect?t.isRect===!0:this.pattern===u.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const o=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>D(y({},n),{pointList:c.changePointListByZoom(n.pointList,this.zoom)}));return g.getHoverPolygonID(o,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=v.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var r,n,a,l;return D(y({},i),{x:(n=(r=i.pointList[0])==null?void 0:r.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),o=m.getNextSelectedRectID(e,t,this.selectedID);if(o)return this.setSelectedIDs([o.id]),this.render(),[o.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,o;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(o=this._textAttributInstance)==null||o.clearTextAttribute(),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,o;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(o=this.basicCtx)==null||o.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}}export{b as default};
1
+ import{ESortDirection as v}from"../../constant/annotation.js";import{EPolygonPattern as u}from"../../constant/tool.js";import d from"../../utils/tool/AxisUtils.js";import m from"../../utils/tool/CommonToolUtils.js";import c from"../../utils/tool/DrawUtils.js";import g from"../../utils/tool/PolygonUtils.js";import p from"../../utils/tool/StyleUtils.js";import I from"./polygonOperation.js";var _=Object.defineProperty,S=Object.defineProperties,L=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,P=(o,t,e)=>t in o?_(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,y=(o,t)=>{for(var e in t||(t={}))w.call(t,e)&&P(o,e,t[e]);if(f)for(var e of f(t))C.call(t,e)&&P(o,e,t[e]);return o},D=(o,t)=>S(o,L(t));class b extends I{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var r;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=p.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=d.changePointListByZoom(i.pointList,this.zoom,this.currentPos);c.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,s;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(s=t.forbidAddNew)!=null?s:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return g.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var s,i,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=p.getStrokeAndFill(a,e.valid),h=d.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);c.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(s=this.style)==null?void 0:s.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||c.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===u.Rect?t.isRect===!0:this.pattern===u.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const s=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>D(y({},n),{pointList:d.changePointListByZoom(n.pointList,this.zoom)}));return g.getHoverPolygonID(s,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=v.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var r,n,a,l;return D(y({},i),{x:(n=(r=i.pointList[0])==null?void 0:r.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),s=m.getNextSelectedRectID(e,t,this.selectedID);if(s)return this.setSelectedIDs([s.id]),this.render(),[s.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,s;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(s=this._textAttributInstance)==null||s.clearTextAttribute(),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,s;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(s=this.basicCtx)==null||s.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}export{b as default};
@@ -1 +1 @@
1
- import{i18n as A}from"@labelbee/lb-utils";import D from"../../utils/MathUtils.js";import z from"../../utils/tool/RectUtils.js";import{ERotateDirection as N,EDragStatus as x,ESortDirection as E,EDragTarget as b,TEXT_ATTRIBUTE_OFFSET as U,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as H,EToolName as O}from"../../constant/tool.js";import T from"../../locales/index.js";import{EMessage as _}from"../../locales/constants.js";import W from"../../utils/ActionsHistory.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import u from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import y from"../../utils/tool/PolygonUtils.js";import C from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var V=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,F=(L,t,e)=>t in L?V(L,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):L[t]=e,f=(L,t)=>{for(var e in t||(t={}))q.call(t,e)&&F(L,e,t[e]);if(Z)for(var e of Z(t))G.call(t,e)&&F(L,e,t[e]);return L},m=(L,t)=>X(L,Y(t));const j=164;class J extends K{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=u.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new W,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return y.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>m(f({},t),{pointList:c.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?f(f({},i),t):i)}rotatePolygon(t=1,e=N.Clockwise,i=this.selectedID){if(!i)return;const s=y.getPolygonByID(this.polygonList,i);if(!s)return;const n=y.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:n},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${T.getMessagesByLocale(_.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),n=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(c.returnClosePointIndex(n,c.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:o}=y.getClosestPoint(n,this.polygonListUnderZoom,this.config.lineType,R),l=c.changePointByZoom(o&&t.altKey===!1&&i?o:n,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${T.getMessagesByLocale(_.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>i.id===t?m(f({},i),{valid:!i.valid}):i);this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=u.getSourceID(this.basicResult),n=[...this.polygonList];if(this.editPolygonID){const r=n.find(o=>o.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=M(8,62);let o={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(n.filter(l=>u.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=v.getTextAttribute(this.polygonList.filter(h=>u.isSameSourceID(h.sourceID,s)),this.config.textCheckType),o=m(f({},o),{textAttribute:l})}this.pattern===w.Rect&&t===!0&&(o=m(f({},o),{isRect:!0})),n.push(o),i=o,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(n),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(n),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(n=>m(f({},n),{pointList:c.changePointListByZoom(n.pointList,this.zoom)}));return y.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),n=c.changePointListByZoom(i.pointList,this.zoom);return y.getHoverEdgeIndex(s,n,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=c.changePointListByZoom(e.pointList,this.zoom);return c.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${T.getMessagesByLocale(_.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${T.getMessagesByLocale(_.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=E.ascend;t.shiftKey&&(e=E.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const n=B.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,g,a,d;return m(f({},l),{x:(g=(h=l.pointList[0])==null?void 0:h.x)!=null?g:0,y:(d=(a=l.pointList[0])==null?void 0:a.y)!=null?d:0})}).filter(l=>B.inViewPort({x:l.x,y:l.y},n)),o=u.getNextSelectedRectID(r,t,this.selectedID);if(o){this.setSelectedID(o.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Space:this.spaceKeydown();break;case p.Esc:this.drawingPointList=[],this.editPolygonID="";break;case p.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case p.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deletePolygon(this.selectedID),this.render();break;case p.Ctrl:this.isCtrl=!0;break;case p.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case p.Tab:{this.onTabKeyDown(t);break}case p.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.isCtrl=!1;break;case p.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;const{dropFoot:s}=y.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:n}=this.config;if(n&&i.pointList.length>=n){this.emit("messageInfo",`${T.getMessagesByLocale(_.UpperLimitErrorNotice,this.lang)}${n}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,c.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,n=this.getCoordinateUnderZoom(t);let r=[0],o=b.Plane;this.dragStatus=x.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(o=b.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(o=b.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:n,dragTarget:o,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==H.Line)return;const e=y.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=y.getWrapPolygonIndex(e,i);let n=[...this.polygonList];if(s===-1){const r=y.segmentPolygonByPolygon(e,i);if(!r)return;const o=r.shift();if(!o)return;let l="",h=!0;const g=u.getSourceID(this.basicResult);let a="";n=this.polygonList.map(d=>{var I,S;return d.id===this.selectedID?(l=d.attribute,h=(I=d==null?void 0:d.valid)!=null?I:!0,a=(S=d==null?void 0:d.textAttribute)!=null?S:"",m(f({},d),{pointList:o})):d}),r.length>0&&r.forEach((d,I)=>{n.push({sourceID:g,id:M(8,62),pointList:d,valid:h,order:u.getMaxOrder(this.currentShowList)+1+I,attribute:l,textAttribute:a})})}else n[s].pointList=y.clipPolygonFromWrapPolygon(e,n[s].pointList),n=n.filter(r=>r.id!==this.selectedID);this.setPolygonList(n),this.history.pushHistory(n),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",A.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==H.Line){this.emit("messageInfo",A.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),n=this.currentShowList.find(h=>h.id===i);if(!n||!s)return;const r=y.combinePolygonWithPolygon(s,n);if(!r)return;const{newPolygon:o,unionList:l}=r;if(l.length===1&&o){const h=this.polygonList.filter(g=>!l.includes(g.id)).map(g=>g.id===this.selectedID?o:g);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",A.t("CombineSuccess"))}else this.emit("messageInfo",A.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let o=!1;switch(this.dependToolName){case O.Rect:{o=t.filter(l=>!z.isInRect(l,this.basicResult)).length>0;break}case O.Polygon:{o=y.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return o}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:n}=D.calcViewportBoundaries(c.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||n>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:n,dragTarget:r,changePointIndex:o}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-n.x)/this.zoom,y:(l.y-n.y)/this.zoom};if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&o&&[b.Line].includes(r)){const a=D.getArrayIndex(o[0]-2,4),d=D.getArrayIndex(o[0]-1,4),I=[s[a],s[d]];h=D.getRectPerpendicularOffset(n,l,I),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=x.Move,r){case b.Plane:i=i.map((a,d)=>m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}));break;case b.Point:case b.Line:i=i.map((a,d)=>o&&o.includes(d)?m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}):a);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&r===b.Point&&o&&(i=D.getPointListFromPointOffset(s,o[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const g=this.polygonList.map(a=>{if(a.id===this.selectedID){const d=m(f({},a),{pointList:i});return a.isRect===!0&&this.pattern===w.Normal&&Object.assign(d,{isRect:!1}),d}return a});this.setPolygonList(g),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const n=this.getHoverID(t);this.hoverID!==n&&(this.hoverID=n,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===x.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return v.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:j,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;v.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",v.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:n,textAttribute:r}=e,{x:o,y:l}=i[i.length-1],h=j,g=c.getOffsetCoordinate({x:o,y:l},this.currentPos,this.zoom),a=this.getColor(s),d=n?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new $({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:g.x,top:g.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,n,r,o;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,g=this.getColor(h),a=C.getStrokeAndFill(g,e.valid),d=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:a.fill,strokeColor:a.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType});let I=`${(r=v.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((o=this.config)==null?void 0:o.isShowOrder)&&(e==null?void 0:e.order)>0&&(I=`${e.order} ${I}`),P.drawText(this.canvas,d[0],I,f({color:a.stroke},k));const S=d[d.length-1];P.drawText(this.canvas,{x:S.x+U.x,y:S.y+U.y},l,f({color:a.stroke},k))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const n=this.getColor(s.attribute),r=C.getStrokeAndFill(n,s.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let o=`${(e=v.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(o=`${s.order} ${o}`),P.drawText(this.canvas,c.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),o,f({color:r.stroke},k)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=C.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,c.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const n=this.getColor(this.defaultAttribute),r=C.getStrokeAndFill(n,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let o=[...this.drawingPointList],l=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&o.length===2)o=D.getRectangleByRightAngle(l,o);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=y.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(l=h)}o.push(l)}P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(o,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const o=this.selectedPolygon;if(!o)return;const l=C.getStrokeAndFill(n,o.valid,{isSelected:!0}),h=o==null?void 0:o.pointList[this.hoverPointIndex];if(h){const{x:g,y:a}=c.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:g,y:a},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const o=this.selectedPolygon;if(!o)return;const l=C.getStrokeAndFill(n,o.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.changePointListByZoom(o.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,n=186,r=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:n,height:r},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},A.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:n/2+s,offsetY:-(r/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}export{J as default};
1
+ import{i18n as A}from"@labelbee/lb-utils";import D from"../../utils/MathUtils.js";import z from"../../utils/tool/RectUtils.js";import{ERotateDirection as N,EDragStatus as x,ESortDirection as E,EDragTarget as b,TEXT_ATTRIBUTE_OFFSET as U,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as H,EToolName as O}from"../../constant/tool.js";import T from"../../locales/index.js";import{EMessage as _}from"../../locales/constants.js";import W from"../../utils/ActionsHistory.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import u from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import y from"../../utils/tool/PolygonUtils.js";import C from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var V=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,F=(L,t,e)=>t in L?V(L,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):L[t]=e,f=(L,t)=>{for(var e in t||(t={}))q.call(t,e)&&F(L,e,t[e]);if(Z)for(var e of Z(t))G.call(t,e)&&F(L,e,t[e]);return L},m=(L,t)=>X(L,Y(t));const j=164;class J extends K{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=u.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new W,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return y.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>m(f({},t),{pointList:c.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?f(f({},i),t):i)}rotatePolygon(t=1,e=N.Clockwise,i=this.selectedID){if(!i)return;const s=y.getPolygonByID(this.polygonList,i);if(!s)return;const o=y.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${T.getMessagesByLocale(_.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(c.returnClosePointIndex(o,c.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=y.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),l=c.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${T.getMessagesByLocale(_.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return m(f({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=u.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=M(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(o.filter(l=>u.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=v.getTextAttribute(this.polygonList.filter(h=>u.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=m(f({},n),{textAttribute:l})}this.pattern===w.Rect&&t===!0&&(n=m(f({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>m(f({},o),{pointList:c.changePointListByZoom(o.pointList,this.zoom)}));return y.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=c.changePointListByZoom(i.pointList,this.zoom);return y.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=c.changePointListByZoom(e.pointList,this.zoom);return c.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${T.getMessagesByLocale(_.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${T.getMessagesByLocale(_.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=E.ascend;t.shiftKey&&(e=E.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=B.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,g,a,d;return m(f({},l),{x:(g=(h=l.pointList[0])==null?void 0:h.x)!=null?g:0,y:(d=(a=l.pointList[0])==null?void 0:a.y)!=null?d:0})}).filter(l=>B.inViewPort({x:l.x,y:l.y},o)),n=u.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Space:this.spaceKeydown();break;case p.Esc:this.drawingPointList=[],this.editPolygonID="";break;case p.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case p.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deletePolygon(this.selectedID),this.render();break;case p.Ctrl:this.isCtrl=!0;break;case p.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case p.Tab:{this.onTabKeyDown(t);break}case p.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.isCtrl=!1;break;case p.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;const{dropFoot:s}=y.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${T.getMessagesByLocale(_.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,c.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=b.Plane;this.dragStatus=x.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(n=b.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=b.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==H.Line)return;const e=y.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=y.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=y.segmentPolygonByPolygon(e,i);if(!r)return;const n=r.shift();if(!n)return;let l="",h=!0;const g=u.getSourceID(this.basicResult);let a="";o=this.polygonList.map(d=>{var I,S;return d.id===this.selectedID?(l=d.attribute,h=(I=d==null?void 0:d.valid)!=null?I:!0,a=(S=d==null?void 0:d.textAttribute)!=null?S:"",m(f({},d),{pointList:n})):d}),r.length>0&&r.forEach((d,I)=>{o.push({sourceID:g,id:M(8,62),pointList:d,valid:h,order:u.getMaxOrder(this.currentShowList)+1+I,attribute:l,textAttribute:a})})}else o[s].pointList=y.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",A.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==H.Line){this.emit("messageInfo",A.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=y.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(g=>!l.includes(g.id)).map(g=>g.id===this.selectedID?n:g);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",A.t("CombineSuccess"))}else this.emit("messageInfo",A.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case O.Rect:{n=t.filter(l=>!z.isInRect(l,this.basicResult)).length>0;break}case O.Polygon:{n=y.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=D.calcViewportBoundaries(c.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[b.Line].includes(r)){const a=D.getArrayIndex(n[0]-2,4),d=D.getArrayIndex(n[0]-1,4),I=[s[a],s[d]];h=D.getRectPerpendicularOffset(o,l,I),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=x.Move,r){case b.Plane:i=i.map((a,d)=>m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}));break;case b.Point:case b.Line:i=i.map((a,d)=>n&&n.includes(d)?m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}):a);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&r===b.Point&&n&&(i=D.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const g=this.polygonList.map(a=>{if(a.id===this.selectedID){const d=m(f({},a),{pointList:i});return a.isRect===!0&&this.pattern===w.Normal&&Object.assign(d,{isRect:!1}),d}return a});this.setPolygonList(g),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===x.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return v.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:j,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;v.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",v.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:n,y:l}=i[i.length-1],h=j,g=c.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),a=this.getColor(s),d=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new $({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:g.x,top:g.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,g=this.getColor(h),a=C.getStrokeAndFill(g,e.valid),d=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:a.fill,strokeColor:a.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let I=`${(r=v.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(I=`${e.order} ${I}`),P.drawText(this.canvas,d[0],I,f({color:a.stroke},k));const S=d[d.length-1];P.drawText(this.canvas,{x:S.x+U.x,y:S.y+U.y},l,f({color:a.stroke},k))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=C.getStrokeAndFill(o,s.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=v.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),P.drawText(this.canvas,c.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,f({color:r.stroke},k)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=C.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,c.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=C.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&n.length===2)n=D.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=y.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(l=h)}n.push(l)}P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=C.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:g,y:a}=c.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:g,y:a},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=C.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,r=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},A.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}export{J as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.9.0-alpha.11",
3
+ "version": "1.9.0-alpha.13",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -92,11 +92,10 @@
92
92
  "typescript": "^4.2.3"
93
93
  },
94
94
  "dependencies": {
95
- "@labelbee/lb-utils": "^1.3.0-alpha.11",
95
+ "@labelbee/lb-utils": "^1.3.0-alpha.12",
96
96
  "@turf/turf": "5.1.6",
97
97
  "color-rgba": "^2.3.0",
98
98
  "lodash": "^4.17.20",
99
99
  "three": ">=0.141.0"
100
- },
101
- "gitHead": "2476ee3089282e14e354a7bcb5f7398d61f0c9e9"
100
+ }
102
101
  }
package/LICENSE DELETED
@@ -1,203 +0,0 @@
1
- Copyright 2018-2023 OpenMMLab. All rights reserved.
2
-
3
- Apache License
4
- Version 2.0, January 2004
5
- http://www.apache.org/licenses/
6
-
7
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
-
9
- 1. Definitions.
10
-
11
- "License" shall mean the terms and conditions for use, reproduction,
12
- and distribution as defined by Sections 1 through 9 of this document.
13
-
14
- "Licensor" shall mean the copyright owner or entity authorized by
15
- the copyright owner that is granting the License.
16
-
17
- "Legal Entity" shall mean the union of the acting entity and all
18
- other entities that control, are controlled by, or are under common
19
- control with that entity. For the purposes of this definition,
20
- "control" means (i) the power, direct or indirect, to cause the
21
- direction or management of such entity, whether by contract or
22
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
- outstanding shares, or (iii) beneficial ownership of such entity.
24
-
25
- "You" (or "Your") shall mean an individual or Legal Entity
26
- exercising permissions granted by this License.
27
-
28
- "Source" form shall mean the preferred form for making modifications,
29
- including but not limited to software source code, documentation
30
- source, and configuration files.
31
-
32
- "Object" form shall mean any form resulting from mechanical
33
- transformation or translation of a Source form, including but
34
- not limited to compiled object code, generated documentation,
35
- and conversions to other media types.
36
-
37
- "Work" shall mean the work of authorship, whether in Source or
38
- Object form, made available under the License, as indicated by a
39
- copyright notice that is included in or attached to the work
40
- (an example is provided in the Appendix below).
41
-
42
- "Derivative Works" shall mean any work, whether in Source or Object
43
- form, that is based on (or derived from) the Work and for which the
44
- editorial revisions, annotations, elaborations, or other modifications
45
- represent, as a whole, an original work of authorship. For the purposes
46
- of this License, Derivative Works shall not include works that remain
47
- separable from, or merely link (or bind by name) to the interfaces of,
48
- the Work and Derivative Works thereof.
49
-
50
- "Contribution" shall mean any work of authorship, including
51
- the original version of the Work and any modifications or additions
52
- to that Work or Derivative Works thereof, that is intentionally
53
- submitted to Licensor for inclusion in the Work by the copyright owner
54
- or by an individual or Legal Entity authorized to submit on behalf of
55
- the copyright owner. For the purposes of this definition, "submitted"
56
- means any form of electronic, verbal, or written communication sent
57
- to the Licensor or its representatives, including but not limited to
58
- communication on electronic mailing lists, source code control systems,
59
- and issue tracking systems that are managed by, or on behalf of, the
60
- Licensor for the purpose of discussing and improving the Work, but
61
- excluding communication that is conspicuously marked or otherwise
62
- designated in writing by the copyright owner as "Not a Contribution."
63
-
64
- "Contributor" shall mean Licensor and any individual or Legal Entity
65
- on behalf of whom a Contribution has been received by Licensor and
66
- subsequently incorporated within the Work.
67
-
68
- 2. Grant of Copyright License. Subject to the terms and conditions of
69
- this License, each Contributor hereby grants to You a perpetual,
70
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
- copyright license to reproduce, prepare Derivative Works of,
72
- publicly display, publicly perform, sublicense, and distribute the
73
- Work and such Derivative Works in Source or Object form.
74
-
75
- 3. Grant of Patent License. Subject to the terms and conditions of
76
- this License, each Contributor hereby grants to You a perpetual,
77
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
- (except as stated in this section) patent license to make, have made,
79
- use, offer to sell, sell, import, and otherwise transfer the Work,
80
- where such license applies only to those patent claims licensable
81
- by such Contributor that are necessarily infringed by their
82
- Contribution(s) alone or by combination of their Contribution(s)
83
- with the Work to which such Contribution(s) was submitted. If You
84
- institute patent litigation against any entity (including a
85
- cross-claim or counterclaim in a lawsuit) alleging that the Work
86
- or a Contribution incorporated within the Work constitutes direct
87
- or contributory patent infringement, then any patent licenses
88
- granted to You under this License for that Work shall terminate
89
- as of the date such litigation is filed.
90
-
91
- 4. Redistribution. You may reproduce and distribute copies of the
92
- Work or Derivative Works thereof in any medium, with or without
93
- modifications, and in Source or Object form, provided that You
94
- meet the following conditions:
95
-
96
- (a) You must give any other recipients of the Work or
97
- Derivative Works a copy of this License; and
98
-
99
- (b) You must cause any modified files to carry prominent notices
100
- stating that You changed the files; and
101
-
102
- (c) You must retain, in the Source form of any Derivative Works
103
- that You distribute, all copyright, patent, trademark, and
104
- attribution notices from the Source form of the Work,
105
- excluding those notices that do not pertain to any part of
106
- the Derivative Works; and
107
-
108
- (d) If the Work includes a "NOTICE" text file as part of its
109
- distribution, then any Derivative Works that You distribute must
110
- include a readable copy of the attribution notices contained
111
- within such NOTICE file, excluding those notices that do not
112
- pertain to any part of the Derivative Works, in at least one
113
- of the following places: within a NOTICE text file distributed
114
- as part of the Derivative Works; within the Source form or
115
- documentation, if provided along with the Derivative Works; or,
116
- within a display generated by the Derivative Works, if and
117
- wherever such third-party notices normally appear. The contents
118
- of the NOTICE file are for informational purposes only and
119
- do not modify the License. You may add Your own attribution
120
- notices within Derivative Works that You distribute, alongside
121
- or as an addendum to the NOTICE text from the Work, provided
122
- that such additional attribution notices cannot be construed
123
- as modifying the License.
124
-
125
- You may add Your own copyright statement to Your modifications and
126
- may provide additional or different license terms and conditions
127
- for use, reproduction, or distribution of Your modifications, or
128
- for any such Derivative Works as a whole, provided Your use,
129
- reproduction, and distribution of the Work otherwise complies with
130
- the conditions stated in this License.
131
-
132
- 5. Submission of Contributions. Unless You explicitly state otherwise,
133
- any Contribution intentionally submitted for inclusion in the Work
134
- by You to the Licensor shall be under the terms and conditions of
135
- this License, without any additional terms or conditions.
136
- Notwithstanding the above, nothing herein shall supersede or modify
137
- the terms of any separate license agreement you may have executed
138
- with Licensor regarding such Contributions.
139
-
140
- 6. Trademarks. This License does not grant permission to use the trade
141
- names, trademarks, service marks, or product names of the Licensor,
142
- except as required for reasonable and customary use in describing the
143
- origin of the Work and reproducing the content of the NOTICE file.
144
-
145
- 7. Disclaimer of Warranty. Unless required by applicable law or
146
- agreed to in writing, Licensor provides the Work (and each
147
- Contributor provides its Contributions) on an "AS IS" BASIS,
148
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
- implied, including, without limitation, any warranties or conditions
150
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
- PARTICULAR PURPOSE. You are solely responsible for determining the
152
- appropriateness of using or redistributing the Work and assume any
153
- risks associated with Your exercise of permissions under this License.
154
-
155
- 8. Limitation of Liability. In no event and under no legal theory,
156
- whether in tort (including negligence), contract, or otherwise,
157
- unless required by applicable law (such as deliberate and grossly
158
- negligent acts) or agreed to in writing, shall any Contributor be
159
- liable to You for damages, including any direct, indirect, special,
160
- incidental, or consequential damages of any character arising as a
161
- result of this License or out of the use or inability to use the
162
- Work (including but not limited to damages for loss of goodwill,
163
- work stoppage, computer failure or malfunction, or any and all
164
- other commercial damages or losses), even if such Contributor
165
- has been advised of the possibility of such damages.
166
-
167
- 9. Accepting Warranty or Additional Liability. While redistributing
168
- the Work or Derivative Works thereof, You may choose to offer,
169
- and charge a fee for, acceptance of support, warranty, indemnity,
170
- or other liability obligations and/or rights consistent with this
171
- License. However, in accepting such obligations, You may act only
172
- on Your own behalf and on Your sole responsibility, not on behalf
173
- of any other Contributor, and only if You agree to indemnify,
174
- defend, and hold each Contributor harmless for any liability
175
- incurred by, or claims asserted against, such Contributor by reason
176
- of your accepting any such warranty or additional liability.
177
-
178
- END OF TERMS AND CONDITIONS
179
-
180
- APPENDIX: How to apply the Apache License to your work.
181
-
182
- To apply the Apache License to your work, attach the following
183
- boilerplate notice, with the fields enclosed by brackets "[]"
184
- replaced with your own identifying information. (Don't include
185
- the brackets!) The text should be enclosed in the appropriate
186
- comment syntax for the file format. We also recommend that a
187
- file or class name and description of purpose be included on the
188
- same "printed page" as the copyright notice for easier
189
- identification within third-party archives.
190
-
191
- Copyright 2018-2023 OpenMMLab.
192
-
193
- Licensed under the Apache License, Version 2.0 (the "License");
194
- you may not use this file except in compliance with the License.
195
- You may obtain a copy of the License at
196
-
197
- http://www.apache.org/licenses/LICENSE-2.0
198
-
199
- Unless required by applicable law or agreed to in writing, software
200
- distributed under the License is distributed on an "AS IS" BASIS,
201
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
- See the License for the specific language governing permissions and
203
- limitations under the License.