@labelbee/lb-annotation 1.28.0-alpha.23 → 1.28.0-alpha.25

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,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(b){if(b&&b.__esModule)return b;var t=Object.create(null);return b&&Object.keys(b).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return b[e]}})}}),t.default=b,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=(b,t,e)=>t in b?__defProp(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,__spreadValues=(b,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(b,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(b,e,t[e]);return b},__spreadProps=(b,t)=>__defProps(b,__getOwnPropDescs(t)),__async=(b,t,e)=>new Promise((i,r)=>{var s=c=>{try{o(e.next(c))}catch(u){r(u)}},a=c=>{try{o(e.throw(c))}catch(u){r(u)}},o=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,a);o((e=e.apply(b,t)).next())});const DEFAULT_DISTANCE=30;let highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:o,checkMode:c,hiddenText:u=!1,view:f=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,h="blue")=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"sphere");const{radius:d,widthSegments:g,heightSegments:w}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:m}=n,x=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(d,g,w),C=new THREE__namespace.MeshBasicMaterial({color:h}),v=new THREE__namespace.Mesh(y,C);v.position.set(m.x,m.y,m.z),x.add(v),x.name=`sphere${p}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:h}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,h),this.render()},this.generateSpheres=n=>{n.forEach(h=>{const{fill:l}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(n,h=16777215)=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"box");const{center:d,width:g,height:w,depth:m,rotation:x}=n,y=new THREE__namespace.Group,C=new THREE__namespace.BoxGeometry(g,w,m),v=new THREE__namespace.MeshBasicMaterial({color:"blue"}),M=new THREE__namespace.Mesh(C,v),S=new THREE__namespace.BoxHelper(M,h),O=this.generateBoxArrow(n),P=this.generateBoxTrackID(n,h);P&&y.add(P);const B=this.generateBoxAttributeLabel(n,h);B&&y.add(B),y.add(S),y.add(O),d&&y.position.set(d.x,d.y,d.z),x&&y.rotation.set(0,0,x),y.name=`box${p}`;const L=new THREE__namespace.BoxGeometry(g,w,m),z=new THREE__namespace.MeshBasicMaterial({visible:!1}),A=new THREE__namespace.Mesh(L,z);y.add(A),y.userData={defaultColor:h,selectedID:p},this.scene.add(y)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const h=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(b){if(b&&b.__esModule)return b;var t=Object.create(null);return b&&Object.keys(b).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(b,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return b[e]}})}}),t.default=b,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=(b,t,e)=>t in b?__defProp(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,__spreadValues=(b,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(b,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(b,e,t[e]);return b},__spreadProps=(b,t)=>__defProps(b,__getOwnPropDescs(t)),__async=(b,t,e)=>new Promise((i,r)=>{var s=c=>{try{o(e.next(c))}catch(u){r(u)}},a=c=>{try{o(e.throw(c))}catch(u){r(u)}},o=c=>c.done?i(c.value):Promise.resolve(c.value).then(s,a);o((e=e.apply(b,t)).next())});const DEFAULT_DISTANCE=30;let highlightWorker=null;class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:o,checkMode:c,hiddenText:u=!1,view:f=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,h="blue")=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"sphere");const{radius:d,widthSegments:g,heightSegments:w}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:m}=n,x=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(d,g,w),C=new THREE__namespace.MeshBasicMaterial({color:h}),v=new THREE__namespace.Mesh(y,C);v.position.set(m.x,m.y,m.z),x.add(v),x.name=`sphere${p}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:h}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,h),this.render()},this.generateSpheres=n=>{n.forEach(h=>{const{fill:l}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(n,h=16777215)=>{var l;const p=(l=n.id)!=null?l:uuid();this.removeObjectByName(p,"box");const{center:d,width:g,height:w,depth:m,rotation:x}=n,y=new THREE__namespace.Group,C=new THREE__namespace.BoxGeometry(g,w,m),v=new THREE__namespace.MeshBasicMaterial({color:"blue"}),M=new THREE__namespace.Mesh(C,v),S=new THREE__namespace.BoxHelper(M,h),O=this.generateBoxArrow(n),P=this.generateBoxTrackID(n,h);P&&y.add(P);const B=this.generateBoxAttributeLabel(n,h);B&&y.add(B),y.add(S),y.add(O),d&&y.position.set(d.x,d.y,d.z),x&&y.rotation.set(0,0,x),y.name=`box${p}`;const L=new THREE__namespace.BoxGeometry(g,w,m),z=new THREE__namespace.MeshBasicMaterial({visible:!1}),A=new THREE__namespace.Mesh(L,z);y.add(A),y.userData={defaultColor:h,selectedID:p},this.scene.add(y)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const h=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -29,5 +29,5 @@
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
31
  }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(h=this.currentPCDSrc,l){if(!h||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:p,color:d}=yield this.cacheInstance.loadPCDFile(h),g=new THREE__namespace.BufferGeometry;g.setAttribute("position",new THREE__namespace.BufferAttribute(p,3)),this.isSegment||g.setAttribute("dimensions",new THREE__namespace.BufferAttribute(d,3)),this.initCloudData(p);const w=new THREE__namespace.Points(g);this.renderPointCloud(w,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:h,points:l}){const p=m=>__async(this,null,function*(){try{return yield ImgUtils.default.load(m)}catch(x){return console.error("Error loading image:",x),null}}),d=h.length===0?[]:(yield Promise.all(h.map(m=>__async(this,null,function*(){let x=yield p(m.url);return!x&&m.fallbackUrl&&(x=yield p(m.fallbackUrl)),x})))).filter(m=>m!==null),g=h.map((m,x)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?y:[];const C=matrix.getHighlightIndexByPoints({points:l,calib:m.calib,width:d[x].width,height:d[x].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,C),C});return matrix.mergeHighlightList(g)}),this.filterPreResult=(n,h,l)=>__async(this,null,function*(){const{points:p}=yield this.cacheInstance.loadPCDFile(n),d=yield this.cacheInstance.loadIndexMap(n,p);return new Promise(g=>{const w=l.map(m=>{const x=MathUtils.default.calculatePointsInsideBox({indexMap:d,polygon:matrix.getCuboidFromPointCloudBox(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),y=x>=h.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},m),{valid:y,count:x})});g(w)})}),this.loadPCDFileByBox=(n,h,l)=>__async(this,null,function*(){const p=(w,m)=>__async(this,null,function*(){const{width:x=0,height:y=0,depth:C=0}=l!=null?l:{},v=yield this.filterPointsByBox(__spreadProps(__spreadValues({},h),{width:h.width+x,height:h.height+y,depth:h.depth+C}),w,m);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const M=new THREE__namespace.Points(v.geometry);M.name=this.pointCloudObjectName,this.scene.add(M),this.render()}),{points:d,color:g}=yield this.cacheInstance.loadPCDFile(n);p(d,g)}),this.generateRange=n=>{const h=this.createRange(n);this.scene.add(h)},this.generateBoxArrow=({width:n})=>{const h=new THREE__namespace.Vector3(1,0,0),l=new THREE__namespace.Vector3(n/2,0,0),p=2,d=new THREE__namespace.ArrowHelper(h,l,p,this.highlightColor);return d.visible=this.showDirection,d},this.generateLabel=(n,h,l)=>{const p=this.getTextCanvas(n),d=new THREE__namespace.Texture(p);d.minFilter=THREE__namespace.LinearFilter,d.magFilter=THREE__namespace.LinearFilter,d.needsUpdate=!0;const g=p.width/window.devicePixelRatio,w=p.height/window.devicePixelRatio,m=new THREE__namespace.SpriteMaterial({map:d,depthWrite:!1,color:l}),x=new THREE__namespace.Sprite(m);return x.scale.set(g/h,w/h,1),{sprite:x,canvasWidth:g,canvasHeight:w}},this.generateBoxTrackID=(n,h)=>{if(!n.trackID)return;const{sprite:l}=this.generateLabel(n.trackID.toString(),50,h);return l.position.set(-n.width/2,0,n.depth/2+.5),l},this.generateBoxAttributeLabel=(n,h)=>{if(!n.attribute||this.hiddenText)return;const l=this.findSubAttributeLabel(n,this.config),p=l?`${n.attribute}
32
- ${l}`:`${n.attribute}`,{sprite:d,canvasHeight:g}=this.generateLabel(p,100,h);return d.position.set(-n.width/2,0,-n.depth/2-g/150),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const p=l.material.uniforms.pointSize.value;n?l.material.uniforms.pointSize.value=Math.min(p*1.2,10):l.material.uniforms.pointSize.value=Math.max(p/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=c!=null?c:!1,this.hiddenText=u,this.view=f,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.filterBoxWorker=new filterBoxWorker,this.geometry=new THREE__namespace.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var h,l,p;const d=this.renderer.domElement.getBoundingClientRect(),g=n.originalEvent.clientX-d.left,w=n.originalEvent.clientY-d.top;this.pointer.x=g/d.width*2-1,this.pointer.y=-(w/d.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(y=>{y instanceof THREE__namespace.Group&&y.children.forEach(C=>{C instanceof THREE__namespace.Mesh?m.push(C):this.updateMaterialColor(C,y.userData.defaultColor)})});const x=this.raycaster.intersectObjects(m,!1);if(x.length>0){const y=x[0].object.parent;y==null||y.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(h=this.pipe)==null||h.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(y==null?void 0:y.userData.selectedID)}else(p=this.pipe)==null||p.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof THREE__namespace.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof THREE__namespace.BoxHelper||t instanceof THREE__namespace.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,c=e.y+r/2+s,u=e.y-r/2-s,f=100,n=-100,h=500/f;return{left:a,right:o,top:c,bottom:u,near:f,far:n,zoom:h}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:c}=t,u=this.getCameraVector(r,c,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:c,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),f=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:c,polygonPointList:u,color:i,position:f};return this.filterBoxWorker||(this.filterBoxWorker=new filterBoxWorker),new Promise(h=>{var l;(l=this.filterBoxWorker)==null||l.postMessage(n),this.filterBoxWorker.onmessage=p=>{const{color:d,position:g,num:w}=p.data;this.geometry.dispose(),this.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),this.geometry.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),h({geometry:this.geometry,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),c=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(c).applyMatrix4(f).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{highlightWorker.terminate(),highlightWorker=new highlightWorker$1({type:"module"}),highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),highlightWorker.terminate()},highlightWorker.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:a}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((c,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(g=>matrix.getCuboidFromPointCloudBox(g)),h=this.getAllAttributeColor(n),l=o.geometry.attributes.position.array,p=o.geometry.attributes.dimensions.array,d={cuboidList:n,position:l,color:p,colorList:h,highlightIndex:i,modifiedBoxIds:s,resetAreas:a};this.handleWebworker(d).then(g=>{const{color:w}=g;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==w.length){u(new Error("Error Path"));return}let m=w;(s.length||a.length)&&(m=w.map((C,v)=>C===-1?p[v]:C));const x=new THREE__namespace.BufferAttribute(m,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const y={color:m,view:this.view,currentPCDSrc:this.currentPCDSrc};c(y),this.workerLoading=!1,this.render()}).catch(g=>{this.workerLoading=!1,u(g)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:c,depth:u,rotation:f}=i,{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),h=new THREE__namespace.BoxGeometry(o,c,u),l=new THREE__namespace.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});h.rotateZ(f),h.translate(r,s,a);const p=new THREE__namespace.Mesh(h,l);e.add(p);const d=new THREE__namespace.PlaneGeometry(u,c);d.rotateY(Math.PI/2),d.rotateZ(f);const g=new THREE__namespace.Vector3(o/2,0,0),w=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(f);g.applyMatrix4(w),d.translate(r+g.x,s+g.y,a+g.z);const m=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new THREE__namespace.Mesh(d,m);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new THREE__namespace.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(a=>{const o=i.find(n=>n.value===a);if(!o||!o.subSelected)return;const{key:c,subSelected:u}=o,f=[];u.forEach(n=>{var h;const l=(h=t.subAttribute)==null?void 0:h[a],p=Array.isArray(l)?l:l==null?void 0:l.split(";");(p==null?void 0:p.includes(n.value))&&f.push(n.key)}),f.length>0&&(r&&(r+="\u3001"),r+=`${c}:${f.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const a=t.split(`
32
+ ${l}`:`${n.attribute}`,{sprite:d,canvasHeight:g}=this.generateLabel(p,100,h);return d.position.set(-n.width/2,0,-n.depth/2-g/150),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const p=l.material.uniforms.pointSize.value;n?l.material.uniforms.pointSize.value=Math.min(p*1.2,10):l.material.uniforms.pointSize.value=Math.max(p/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=c!=null?c:!1,this.hiddenText=u,this.view=f,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.filterBoxWorker=new filterBoxWorker,this.geometry=new THREE__namespace.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var h,l,p;const d=this.renderer.domElement.getBoundingClientRect(),g=n.originalEvent.clientX-d.left,w=n.originalEvent.clientY-d.top;this.pointer.x=g/d.width*2-1,this.pointer.y=-(w/d.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(y=>{y instanceof THREE__namespace.Group&&y.children.forEach(C=>{C instanceof THREE__namespace.Mesh?m.push(C):this.updateMaterialColor(C,y.userData.defaultColor)})});const x=this.raycaster.intersectObjects(m,!1);if(x.length>0){const y=x[0].object.parent;y==null||y.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(h=this.pipe)==null||h.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(y==null?void 0:y.userData.selectedID)}else(p=this.pipe)==null||p.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof THREE__namespace.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof THREE__namespace.BoxHelper||t instanceof THREE__namespace.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,c=e.y+r/2+s,u=e.y-r/2-s,f=100,n=-100,h=500/f;return{left:a,right:o,top:c,bottom:u,near:f,far:n,zoom:h}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:c}=t,u=this.getCameraVector(r,c,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:c,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),f=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:c,polygonPointList:u,color:i,position:f};return this.filterBoxWorker||(this.filterBoxWorker=new filterBoxWorker),new Promise(h=>{var l;(l=this.filterBoxWorker)==null||l.postMessage(n),this.filterBoxWorker.onmessage=p=>{const{color:d,position:g,num:w}=p.data;this.geometry.dispose(),this.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),this.geometry.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),h({geometry:this.geometry,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),c=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(c).applyMatrix4(f).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{highlightWorker&&(highlightWorker.terminate(),highlightWorker=null),highlightWorker=new highlightWorker$1({type:"module"}),highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),highlightWorker==null||highlightWorker.terminate(),highlightWorker=null},highlightWorker.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:a}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((c,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(g=>matrix.getCuboidFromPointCloudBox(g)),h=this.getAllAttributeColor(n),l=o.geometry.attributes.position.array,p=o.geometry.attributes.dimensions.array,d={cuboidList:n,position:l,color:p,colorList:h,highlightIndex:i,modifiedBoxIds:s,resetAreas:a};this.handleWebworker(d).then(g=>{const{color:w}=g;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==w.length){u(new Error("Error Path"));return}let m=w;(s.length||a.length)&&(m=w.map((C,v)=>C===-1?p[v]:C));const x=new THREE__namespace.BufferAttribute(m,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const y={color:m,view:this.view,currentPCDSrc:this.currentPCDSrc};c(y),this.workerLoading=!1,this.render()}).catch(g=>{this.workerLoading=!1,u(g)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:c,depth:u,rotation:f}=i,{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),h=new THREE__namespace.BoxGeometry(o,c,u),l=new THREE__namespace.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});h.rotateZ(f),h.translate(r,s,a);const p=new THREE__namespace.Mesh(h,l);e.add(p);const d=new THREE__namespace.PlaneGeometry(u,c);d.rotateY(Math.PI/2),d.rotateZ(f);const g=new THREE__namespace.Vector3(o/2,0,0),w=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(f);g.applyMatrix4(w),d.translate(r+g.x,s+g.y,a+g.z);const m=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new THREE__namespace.Mesh(d,m);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new THREE__namespace.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(a=>{const o=i.find(n=>n.value===a);if(!o||!o.subSelected)return;const{key:c,subSelected:u}=o,f=[];u.forEach(n=>{var h;const l=(h=t.subAttribute)==null?void 0:h[a],p=Array.isArray(l)?l:l==null?void 0:l.split(";");(p==null?void 0:p.includes(n.value))&&f.push(n.key)}),f.length>0&&(r&&(r+="\u3001"),r+=`${c}:${f.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const a=t.split(`
33
33
  `),o=Math.max(...a.map(n=>i.measureText(n).width)),c=Math.ceil(o),u=s*1.5,f=u*a.length;e.width=c*r,e.height=f*r,e.style.width=`${c}px`,e.style.height=`${f}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",a.forEach((n,h)=>{i.fillText(n,0,h*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,h)=>n.z-h.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((n,h)=>n.x-h.x);const o=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));e=e.slice(o,c),e.sort((n,h)=>n.y-h.y);const u=Math.floor(e.length*s),f=Math.floor(e.length*(1-s));return e=e.slice(u,f),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:c,y:u})=>{t.forEach((f,n)=>{const h=r[n+1],l=MathUtils.default.getFootOfPerpendicular({x:c,y:u},f,h,!1,!0).length;(!i[n]||l<i[n].distance)&&(i[n]={distance:l,point:{x:c,y:u}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((c,u)=>{const f=r[u],n=r[u+1],h=r[u+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[u].point,line1:[f,n],p2:s[u+1].point,line2:[n,h]})});return a.some(c=>!(Number.isFinite(c.x)&&Number.isFinite(c.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(d=>d.uuid===this.pointsUuid);let c=0,u=0,f=0,n=0,h=[],l=[];const p=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let d=0;d<p.length;d+=3){const g=p[d],w=p[d+1],m=p[d+2];polygonTool.isInPolygon({x:g,y:w},t)&&(m||m===0)&&l.push({x:g,y:w,z:m})}return l.length?(i&&(l=this.filterNoise(l),h=this.getFittedCoordinates(t,l)),l.sort((d,g)=>d.z-g.z),c=l[0].z-.01,u=l[l.length-1].z+.01,n=l.length,e&&(f=l.filter(({z:d})=>d>=e[0]&&d<=e[1]).length),{maxZ:u,minZ:c,count:f,zCount:n,fittedCoordinates:h}):{maxZ:u,minZ:c,count:f,zCount:n,fittedCoordinates:h}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e+a/2,y:i+s/2,z:r-o/2},u={x:e+a/2,y:i+s/2,z:r+o/2},f={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2};return[c,u,f,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e-a/2,y:i+s/2,z:r+o/2},u={x:e-a/2,y:i+s/2,z:r-o/2},f={x:e-a/2,y:i-s/2,z:r-o/2},n={x:e-a/2,y:i-s/2,z:r+o/2};return[c,u,f,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,c={x:e+a/2,y:i+s/2,z:r+o/2},u={x:e+a/2,y:i-s/2,z:r+o/2},f={x:e-a/2,y:i-s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r+o/2};return[c,u,f,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),c=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(c).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const c=i.map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,f=this.containerHeight/s;return{polygon2d:c,zoom:Math.min(u,f)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},c=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const f=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(a*2),h=this.containerHeight/(a*2);return{point2d:f,zoom:Math.min(n,h)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(c=>new THREE__namespace.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.getModelTransformationMatrix(t))).map(c=>({x:c.y,y:c.x})).map(c=>({x:-(c.x-this.containerWidth/2),y:-(c.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[c,u,f,n]=o,h=Math.max(Math.abs(c.x-f.x),Math.abs(c.x-u.x)),p=u.add(n).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-p.x,y:r.center.y-p.y,z:r.center.z-i},width:h,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const c=r.getZ(o);s.push(c>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),TagUtils=require("../../utils/tool/TagUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js"),lbUtils=require("@labelbee/lb-utils");function _interopDefaultLegacy(f){return f&&typeof f=="object"&&"default"in f?f:{default:f}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{isOffscreenCanvas:!0}));this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(n=>n.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>RectUtils.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(h=>({size:h.width*h.height,id:h.id})).sort((h,o)=>h.size-o.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=TagUtils.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var h;if(a.id===this.selectedRectID){const o=(h=a==null?void 0:a.subAttribute)!=null?h:s;return __spreadProps(__spreadValues({},a),{subAttribute:o})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new Selection(this)}renderPointCloud2DHighlight(){}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return __spreadProps(__spreadValues({},i),{subAttribute:__spreadProps(__spreadValues({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:h}=MathUtils.default.getFootOfPerpendicular(n,a.begin,a.end);h<scope+10&&(e=s)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(n,e))),[]);return MathUtils.default.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),h={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(h,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const o=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(o)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(l=>!RectUtils.isInRect(l,o))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:o,width:l,height:c}=a;let d=this.rectList.filter(u=>u.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let u=h,g=o,R=l,b=c;switch(this.hoverRectPointIndex){case 0:{u=l-s.x<0?h+l:h+s.x,g=c-s.y<0?o+c:o+s.y,R=Math.abs(s.x-l),b=Math.abs(s.y-c);break}case 1:{u=l+s.x>0?h:h+l+s.x,g=c-s.y<0?o+c:o+s.y,R=Math.abs(l+s.x),b=Math.abs(c-s.y);break}case 2:{u=l+s.x>0?h:h+l+s.x,g=c+s.y>0?o:o+c+s.y,R=Math.abs(l+s.x),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=l-s.x<0?h+l:h+s.x,g=c+s.y>0?o:o+c+s.y,R=Math.abs(s.x-l),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}d=__spreadProps(__spreadValues({},d),{x:u,y:g,width:R,height:b})}break;case tool.EDragTarget.Line:{let u=h,g=o,R=l,b=c;switch(this.hoverRectEdgeIndex){case 0:{g=c-s.y<0?o+c:o+s.y,b=Math.abs(s.y-c);break}case 1:{u=l+s.x>0?h:h+l+s.x,R=Math.abs(l+s.x);break}case 2:{g=c+s.y>0?o:o+c+s.y,b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=l-s.x<0?h+l:h+s.x,R=Math.abs(s.x-l);break}default:return}d=__spreadProps(__spreadValues({},d),{x:u,y:g,width:R,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(d,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,g=this.basicResult.y*this.zoom,R=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(d.x<u-.01||d.y<g-.01||d.width>u+R-d.x+.01||d.height>g+b-d.y+.01)return;if(d.x<u&&(d.x=u),d.y<g&&(d.y=g),d.width>u+R-d.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(d.width=u+R-d.x);break;default:return}if(d.height>g+b-d.y)switch(this.dragInfo.dragTarget){}}else if(d.x<0&&(d.x=0),d.y<0&&(d.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(d.x+d.width>((r=this.imgInfo)==null?void 0:r.width)+.01||d.y+d.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(u=>u.id===d.id?RectUtils.getRectUnderZoom(d,1/this.zoom):u)),this.render()}onMouseMove(t){requestAnimationFrame(()=>{var e,i;const r=Date.now();if(r-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=r,super.onMouseMove(t,!1)||this.forbidMouseOperation||!this.imgInfo))return;const n=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changeDrawOutsideTarget(n,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(s),this.render();return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const l=this.getHoverRectEdgeIndex(t);if(l!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=l,this.render();return}}}const a=this.getHoverRectID(t),h=this.hoverRectID;if(this.hoverRectID=a,a!==h&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:l}=this.firstClickCoord,{width:c,height:d}=this.drawingRect;if(c=Math.abs(o-s.x),d=Math.abs(l-s.y),s.x<o&&(o=s.x),s.y<l&&(l=s.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:l,width:c,height:d}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;s.x<0&&(c=Math.abs(this.firstClickCoord.x),o=0),s.y<0&&(d=Math.abs(this.firstClickCoord.y),l=0),this.imgInfo&&(o+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-o)),l+d>this.imgInfo.height&&(d=Math.abs(this.imgInfo.height-l)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:l,width:c,height:d}),this.render()}if(this.isDrag&&!this.dragInfo){this.render("drag");return}this.render("move")})}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){const e=this.rectList.some(i=>i==null?void 0:i.valid);this.setRectList(this.rectList.map(i=>i.id===t?__spreadProps(__spreadValues({},i),{valid:!i.valid}):(this.selection.isIdSelected(i.id)&&(i.valid=!e),i)),!0),this.render(),this.emit("updateResult")}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),h=AxisUtils.default.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(h.x<0&&(h.x=0),h.y<0&&(h.y=0)),this.drawingRect=__spreadProps(__spreadValues({},h),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.rectList.filter(l=>CommonToolUtils.isSameSourceID(l.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:o}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const o=TagUtils.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{subAttribute:o})}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},h),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}checkSize({width:t,height:e,minWidth:i,minHeight:r,isAttributeConfig:n=!1}){return Math.round(t)<i||Math.round(e)<r?(this.emit("messageInfo",lbUtils.i18n.t(n?"TheSizeOfTheDrawingBoxIsSmallerThanTheMinimumDrawingSizeInTheMainPropertyConfiguration":"TheDrawFrameSizeIsSmallerThanTheMinimumDrawSizeInTheStepConfiguration")),this.clearDrawingStatus(),this.render(),!1):!0}addDrawingRectToRectList(){var t,e,i;if(!this.drawingRect)return;let{width:r,height:n}=this.drawingRect;r/=this.zoom,n/=this.zoom;const{attribute:s}=this.drawingRect;let a={minWidth:this.config.minWidth,minHeight:this.config.minHeight};if(s&&this.config.attributeConfigurable){const l=(i=((e=(t=this.config)==null?void 0:t.attributeList)!=null?e:[]).find(c=>c.value===s))==null?void 0:i.limit;l&&(a=__spreadProps(__spreadValues({},l),{isAttributeConfig:!0}))}if(!this.checkSize(__spreadValues({width:r,height:n},a)))return;const h=this.getDrawingRectWithRectList();this.setRectList(h,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),h=this.rectList.find(o=>o.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),h&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(h.attribute)),this.hoverRectID="",(h==null?void 0:h.label)&&this.hasMarkerConfig){const o=CommonToolUtils.getCurrentMarkerIndex(h.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),h}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedIDs.length>0&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect(t);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(o=>CanvasUtils.inViewPort({x:o.x,y:o.y},a));const h=CommonToolUtils.getNextSelectedRectID(s,i,this.selectedRectID);h&&(this.setSelectedRectID(h.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(h.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect: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:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:n,height:s,attribute:a,valid:h}=e,o=n*this.zoom*.6,l=AxisUtils.default.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),d=h?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:o,container:this.container,icon:this.getTextIconSvg(a),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+u,color:d,width:o})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,h)=>{var o,l;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===h?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===h){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),d=t.valid===!1?(o=c==null?void 0:c.invalid)==null?void 0:o.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=d,e.moveTo(r[h].x*this.zoom+this.currentPos.x,r[h].y*this.zoom+this.currentPos.y),e.lineTo(r[(h+1)%n].x*this.zoom+this.currentPos.x,r[(h+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1,r=!1){var n,s,a,h,o,l;if(this.ctx&&t){const{ctx:c,style:d}=this,{hiddenText:u=!1}=d;c.save();const{strokeColor:g,fillColor:R,textColor:b}=this.getRenderStyle(t);c.font="lighter 14px Arial";let x="";((n=this.config)==null?void 0:n.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(x=`${t.order}`),t.label&&this.hasMarkerConfig&&(x=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(x=`${x} ${AttributeUtils.default.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((a=this.config)==null?void 0:a.secondaryAttributeConfigurable)&&((h=this.config)==null?void 0:h.subAttributeList)&&TagUtils.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(I=>{x+=`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),TagUtils=require("../../utils/tool/TagUtils.js"),lbUtils=require("@labelbee/lb-utils"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(f){return f&&typeof f=="object"&&"default"in f?f:{default:f}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{isOffscreenCanvas:!0}));this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(n=>n.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>RectUtils.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(h=>({size:h.width*h.height,id:h.id})).sort((h,o)=>h.size-o.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=TagUtils.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var h;if(a.id===this.selectedRectID){const o=(h=a==null?void 0:a.subAttribute)!=null?h:s;return __spreadProps(__spreadValues({},a),{subAttribute:o})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new Selection(this)}renderPointCloud2DHighlight(){}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return __spreadProps(__spreadValues({},i),{subAttribute:__spreadProps(__spreadValues({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:h}=MathUtils.default.getFootOfPerpendicular(n,a.begin,a.end);h<scope+10&&(e=s)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(n,e))),[]);return MathUtils.default.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),h={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(h,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const o=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(o)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(l=>!RectUtils.isInRect(l,o))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:o,width:l,height:c}=a;let d=this.rectList.filter(u=>u.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let u=h,g=o,R=l,b=c;switch(this.hoverRectPointIndex){case 0:{u=l-s.x<0?h+l:h+s.x,g=c-s.y<0?o+c:o+s.y,R=Math.abs(s.x-l),b=Math.abs(s.y-c);break}case 1:{u=l+s.x>0?h:h+l+s.x,g=c-s.y<0?o+c:o+s.y,R=Math.abs(l+s.x),b=Math.abs(c-s.y);break}case 2:{u=l+s.x>0?h:h+l+s.x,g=c+s.y>0?o:o+c+s.y,R=Math.abs(l+s.x),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=l-s.x<0?h+l:h+s.x,g=c+s.y>0?o:o+c+s.y,R=Math.abs(s.x-l),b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}d=__spreadProps(__spreadValues({},d),{x:u,y:g,width:R,height:b})}break;case tool.EDragTarget.Line:{let u=h,g=o,R=l,b=c;switch(this.hoverRectEdgeIndex){case 0:{g=c-s.y<0?o+c:o+s.y,b=Math.abs(s.y-c);break}case 1:{u=l+s.x>0?h:h+l+s.x,R=Math.abs(l+s.x);break}case 2:{g=c+s.y>0?o:o+c+s.y,b=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=l-s.x<0?h+l:h+s.x,R=Math.abs(s.x-l);break}default:return}d=__spreadProps(__spreadValues({},d),{x:u,y:g,width:R,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(d,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,g=this.basicResult.y*this.zoom,R=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(d.x<u-.01||d.y<g-.01||d.width>u+R-d.x+.01||d.height>g+b-d.y+.01)return;if(d.x<u&&(d.x=u),d.y<g&&(d.y=g),d.width>u+R-d.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(d.width=u+R-d.x);break;default:return}if(d.height>g+b-d.y)switch(this.dragInfo.dragTarget){}}else if(d.x<0&&(d.x=0),d.y<0&&(d.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(d.x+d.width>((r=this.imgInfo)==null?void 0:r.width)+.01||d.y+d.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(u=>u.id===d.id?RectUtils.getRectUnderZoom(d,1/this.zoom):u)),this.render()}onMouseMove(t){requestAnimationFrame(()=>{var e,i;const r=Date.now();if(r-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=r,super.onMouseMove(t,!1)||this.forbidMouseOperation||!this.imgInfo))return;const n=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changeDrawOutsideTarget(n,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(s),this.render();return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const l=this.getHoverRectEdgeIndex(t);if(l!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=l,this.render();return}}}const a=this.getHoverRectID(t),h=this.hoverRectID;if(this.hoverRectID=a,a!==h&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:l}=this.firstClickCoord,{width:c,height:d}=this.drawingRect;if(c=Math.abs(o-s.x),d=Math.abs(l-s.y),s.x<o&&(o=s.x),s.y<l&&(l=s.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:l,width:c,height:d}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;s.x<0&&(c=Math.abs(this.firstClickCoord.x),o=0),s.y<0&&(d=Math.abs(this.firstClickCoord.y),l=0),this.imgInfo&&(o+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-o)),l+d>this.imgInfo.height&&(d=Math.abs(this.imgInfo.height-l)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:l,width:c,height:d}),this.render()}if(this.isDrag&&!this.dragInfo){this.render("drag");return}this.render("move")})}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){const e=this.rectList.some(i=>i==null?void 0:i.valid);this.setRectList(this.rectList.map(i=>i.id===t?__spreadProps(__spreadValues({},i),{valid:!i.valid}):(this.selection.isIdSelected(i.id)&&(i.valid=!e),i)),!0),this.render(),this.emit("updateResult")}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),h=AxisUtils.default.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(h.x<0&&(h.x=0),h.y<0&&(h.y=0)),this.drawingRect=__spreadProps(__spreadValues({},h),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.rectList.filter(l=>CommonToolUtils.isSameSourceID(l.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:o}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const o=TagUtils.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{subAttribute:o})}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},h),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}checkSize({width:t,height:e,minWidth:i,minHeight:r,isAttributeConfig:n=!1}){return Math.round(t)<i||Math.round(e)<r?(this.emit("messageInfo",lbUtils.i18n.t(n?"TheSizeOfTheDrawingBoxIsSmallerThanTheMinimumDrawingSizeInTheMainPropertyConfiguration":"TheDrawFrameSizeIsSmallerThanTheMinimumDrawSizeInTheStepConfiguration")),this.clearDrawingStatus(),this.render(),!1):!0}addDrawingRectToRectList(){var t,e,i;if(!this.drawingRect)return;let{width:r,height:n}=this.drawingRect;r/=this.zoom,n/=this.zoom;const{attribute:s}=this.drawingRect;let a={minWidth:this.config.minWidth,minHeight:this.config.minHeight};if(s&&this.config.attributeConfigurable){const l=(i=((e=(t=this.config)==null?void 0:t.attributeList)!=null?e:[]).find(c=>c.value===s))==null?void 0:i.limit;l&&(a=__spreadProps(__spreadValues({},l),{isAttributeConfig:!0}))}if(!this.checkSize(__spreadValues({width:r,height:n},a)))return;const h=this.getDrawingRectWithRectList();this.setRectList(h,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),h=this.rectList.find(o=>o.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),h&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(h.attribute)),this.hoverRectID="",(h==null?void 0:h.label)&&this.hasMarkerConfig){const o=CommonToolUtils.getCurrentMarkerIndex(h.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),h}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedIDs.length>0&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect(t);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(o=>CanvasUtils.inViewPort({x:o.x,y:o.y},a));const h=CommonToolUtils.getNextSelectedRectID(s,i,this.selectedRectID);h&&(this.setSelectedRectID(h.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(h.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect: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:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:n,height:s,attribute:a,valid:h}=e,o=n*this.zoom*.6,l=AxisUtils.default.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),d=h?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:o,container:this.container,icon:this.getTextIconSvg(a),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+u,color:d,width:o})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,h)=>{var o,l;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===h?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===h){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),d=t.valid===!1?(o=c==null?void 0:c.invalid)==null?void 0:o.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=d,e.moveTo(r[h].x*this.zoom+this.currentPos.x,r[h].y*this.zoom+this.currentPos.y),e.lineTo(r[(h+1)%n].x*this.zoom+this.currentPos.x,r[(h+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1,r=!1){var n,s,a,h,o,l;if(this.ctx&&t){const{ctx:c,style:d}=this,{hiddenText:u=!1}=d;c.save();const{strokeColor:g,fillColor:R,textColor:b}=this.getRenderStyle(t);c.font="lighter 14px Arial";let x="";((n=this.config)==null?void 0:n.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(x=`${t.order}`),t.label&&this.hasMarkerConfig&&(x=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(x=`${x} ${AttributeUtils.default.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((a=this.config)==null?void 0:a.secondaryAttributeConfigurable)&&((h=this.config)==null?void 0:h.subAttributeList)&&TagUtils.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(I=>{x+=`
2
2
  ${I.keyName}: ${I.value.join("\u3001")}`}));const v=AxisUtils.default.changeRectByZoom(t,i?e:this.zoom,this.currentPos);u||DrawUtils.drawText(this.canvas,{x:v.x,y:v.y-6},x,__spreadProps(__spreadValues({color:g,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:g,position:{x:v.x-5,y:v.y-16}});const D=(l=(o=this.style)==null?void 0:o.width)!=null?l:2,S=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||S||t.id===this.selectedRectID||this.isMultiMoveMode||r)&&DrawUtils.drawRectWithFill(this.canvas,v,{color:R}),DrawUtils.drawRect(this.canvas,v,{color:g,thickness:D,hiddenText:!0,lineDash:t.lineDash}),c.restore();let m=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(m=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const y=m.length*7;if(u||DrawUtils.drawText(this.canvas,{x:v.x+v.width-y,y:v.y+v.height+15},m,__spreadValues({color:b,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!u&&t.textAttribute&&t.id!==this.selectedRectID){const w=0,I=Math.max(20,v.width-y);DrawUtils.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+w},t.textAttribute,__spreadValues({color:b,font:"italic normal 900 14px Arial",textMaxWidth:I},annotation.DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),r&&r.forEach(n=>{this.renderDrawingRect(n),this.renderSelectedRect(n),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),this.renderPointCloud2DHighlight()}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.default.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(t){t!=="move"&&this.renderStaticRect(),this.renderCreatingRect()}render(t){!this.ctx||(t!=="move"&&super.render(),t!=="drag"&&this.renderRect(t),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){this.clearOffscreenCanvas();const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.offscreenCanvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.offscreenCanvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.offscreenCanvas,{x:e,y:i},1,{color:"white"})}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(i=>this.selection.isIdSelected(i.id)?__spreadProps(__spreadValues({},i),{attribute:this.defaultAttribute}):i),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearDrawingStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}clearActiveStatus(){this.clearDrawingStatus(),this.setSelectedRectID(void 0),this.setOperationMode(tool.EOperationMode.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}setHoverRectID(t){this.hoverRectID=t}}exports.RectOperation=RectOperation,exports.default=RectOperation;
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as O,EPerspectiveView as v,PointCloudUtils as $,DEFAULT_SPHERE_PARAMS as D}from"@labelbee/lb-utils";import _ from"../../_virtual/highlightWorker.js";import E from"../../_virtual/filterBoxWorker.js";import{isInPolygon as K}from"../../utils/tool/polygonTool.js";import N from"../../utils/uuid.js";import F from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as X}from"./PCDLoader.js";import{OrbitControls as q}from"./OrbitControls.js";import{PointCloudCache as Q}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as J,mergeHighlightList as tt}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as et}from"./segmentation.js";import it from"./store/index.js";import rt from"./render/index.js";import nt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var ot=Object.defineProperty,st=Object.defineProperties,at=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable,R=(M,t,e)=>t in M?ot(M,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):M[t]=e,P=(M,t)=>{for(var e in t||(t={}))ht.call(t,e)&&R(M,e,t[e]);if(V)for(var e of V(t))ct.call(t,e)&&R(M,e,t[e]);return M},z=(M,t)=>st(M,at(t)),S=(M,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(p){r(p)}},h=l=>{try{o(e.throw(l))}catch(p){r(p)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,h);o((e=e.apply(M,t)).next())});const lt=30;let k=new _({type:"module"});class dt extends nt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:l,hiddenText:p=!1,view:y=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new a.Raycaster,this.pointer=new a.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var d;const g=(d=n.id)!=null?d:N();this.removeObjectByName(g,"sphere");const{radius:u,widthSegments:m,heightSegments:b}=D,{center:f}=n,x=new a.Group,w=new a.SphereGeometry(u,m,b),C=new a.MeshBasicMaterial({color:c}),B=new a.Mesh(w,C);B.position.set(f.x,f.y,f.z),x.add(B),x.name=`sphere${g}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:d}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,d)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var d;const g=(d=n.id)!=null?d:N();this.removeObjectByName(g,"box");const{center:u,width:m,height:b,depth:f,rotation:x}=n,w=new a.Group,C=new a.BoxGeometry(m,b,f),B=new a.MeshBasicMaterial({color:"blue"}),L=new a.Mesh(C,B),H=new a.BoxHelper(L,c),W=this.generateBoxArrow(n),I=this.generateBoxTrackID(n,c);I&&w.add(I);const T=this.generateBoxAttributeLabel(n,c);T&&w.add(T),w.add(H),w.add(W),u&&w.position.set(u.x,u.y,u.z),x&&w.rotation.set(0,0,x),w.name=`box${g}`;const U=new a.BoxGeometry(m,b,f),Z=new a.MeshBasicMaterial({visible:!1}),G=new a.Mesh(U,Z);w.add(G),w.userData={defaultColor:c,selectedID:g},this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as a from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as k,EPerspectiveView as v,PointCloudUtils as G,DEFAULT_SPHERE_PARAMS as D}from"@labelbee/lb-utils";import $ from"../../_virtual/highlightWorker.js";import _ from"../../_virtual/filterBoxWorker.js";import{isInPolygon as K}from"../../utils/tool/polygonTool.js";import E from"../../utils/uuid.js";import N from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as X}from"./PCDLoader.js";import{OrbitControls as q}from"./OrbitControls.js";import{PointCloudCache as Q}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as J,mergeHighlightList as tt}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as et}from"./segmentation.js";import it from"./store/index.js";import rt from"./render/index.js";import nt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var ot=Object.defineProperty,st=Object.defineProperties,at=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable,V=(M,t,e)=>t in M?ot(M,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):M[t]=e,P=(M,t)=>{for(var e in t||(t={}))ht.call(t,e)&&V(M,e,t[e]);if(F)for(var e of F(t))ct.call(t,e)&&V(M,e,t[e]);return M},O=(M,t)=>st(M,at(t)),z=(M,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(p){r(p)}},h=l=>{try{o(e.throw(l))}catch(p){r(p)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,h);o((e=e.apply(M,t)).next())});const lt=30;let B=null;class dt extends nt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:l,hiddenText:p=!1,view:y=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new a.Raycaster,this.pointer=new a.Vector2,this.hiddenText=!1,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var d;const g=(d=n.id)!=null?d:E();this.removeObjectByName(g,"sphere");const{radius:u,widthSegments:m,heightSegments:b}=D,{center:f}=n,x=new a.Group,w=new a.SphereGeometry(u,m,b),C=new a.MeshBasicMaterial({color:c}),S=new a.Mesh(w,C);S.position.set(f.x,f.y,f.z),x.add(S),x.name=`sphere${g}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:d}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,d)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var d;const g=(d=n.id)!=null?d:E();this.removeObjectByName(g,"box");const{center:u,width:m,height:b,depth:f,rotation:x}=n,w=new a.Group,C=new a.BoxGeometry(m,b,f),S=new a.MeshBasicMaterial({color:"blue"}),L=new a.Mesh(C,S),R=new a.BoxHelper(L,c),H=this.generateBoxArrow(n),I=this.generateBoxTrackID(n,c);I&&w.add(I);const T=this.generateBoxAttributeLabel(n,c);T&&w.add(T),w.add(R),w.add(H),u&&w.position.set(u.x,u.y,u.z),x&&w.rotation.set(0,0,x),w.name=`box${g}`;const W=new a.BoxGeometry(m,b,f),U=new a.MeshBasicMaterial({visible:!1}),Z=new a.Mesh(W,U);w.add(Z),w.userData={defaultColor:c,selectedID:g},this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,6 +28,6 @@ import*as a from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>S(this,[...n],function*(c=this.currentPCDSrc,d){if(!c||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:g,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new a.BufferGeometry;m.setAttribute("position",new a.BufferAttribute(g,3)),this.isSegment||m.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(g);const b=new a.Points(m);this.renderPointCloud(b,d),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>S(this,[n],function*({mappingImgList:c,points:d}){const g=f=>S(this,null,function*(){try{return yield Y.load(f)}catch(x){return console.error("Error loading image:",x),null}}),u=c.length===0?[]:(yield Promise.all(c.map(f=>S(this,null,function*(){let x=yield g(f.url);return!x&&f.fallbackUrl&&(x=yield g(f.fallbackUrl)),x})))).filter(f=>f!==null),m=c.map((f,x)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(f.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(f.url))!=null?w:[];const C=J({points:d,calib:f.calib,width:u[x].width,height:u[x].height});return this.cacheInstance.cache2DHighlightIndex.set(f.url,C),C});return tt(m)}),this.filterPreResult=(n,c,d)=>S(this,null,function*(){const{points:g}=yield this.cacheInstance.loadPCDFile(n),u=yield this.cacheInstance.loadIndexMap(n,g);return new Promise(m=>{const b=d.map(f=>{const x=F.calculatePointsInsideBox({indexMap:u,polygon:A(f).polygonPointList,zScope:[f.center.z-f.depth/2,f.center.z+f.depth/2],box:f}),w=x>=c.lowerLimitPointsNumInBox;return z(P({},f),{valid:w,count:x})});m(b)})}),this.loadPCDFileByBox=(n,c,d)=>S(this,null,function*(){const g=(b,f)=>S(this,null,function*(){const{width:x=0,height:w=0,depth:C=0}=d!=null?d:{},B=yield this.filterPointsByBox(z(P({},c),{width:c.width+x,height:c.height+w,depth:c.depth+C}),b,f);if(!B){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const L=new a.Points(B.geometry);L.name=this.pointCloudObjectName,this.scene.add(L),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);g(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new a.Vector3(1,0,0),d=new a.Vector3(n/2,0,0),g=2,u=new a.ArrowHelper(c,d,g,this.highlightColor);return u.visible=this.showDirection,u},this.generateLabel=(n,c,d)=>{const g=this.getTextCanvas(n),u=new a.Texture(g);u.minFilter=a.LinearFilter,u.magFilter=a.LinearFilter,u.needsUpdate=!0;const m=g.width/window.devicePixelRatio,b=g.height/window.devicePixelRatio,f=new a.SpriteMaterial({map:u,depthWrite:!1,color:d}),x=new a.Sprite(f);return x.scale.set(m/c,b/c,1),{sprite:x,canvasWidth:m,canvasHeight:b}},this.generateBoxTrackID=(n,c)=>{if(!n.trackID)return;const{sprite:d}=this.generateLabel(n.trackID.toString(),50,c);return d.position.set(-n.width/2,0,n.depth/2+.5),d},this.generateBoxAttributeLabel=(n,c)=>{if(!n.attribute||this.hiddenText)return;const d=this.findSubAttributeLabel(n,this.config),g=d?`${n.attribute}
32
- ${d}`:`${n.attribute}`,{sprite:u,canvasHeight:m}=this.generateLabel(g,100,c);return u.position.set(-n.width/2,0,-n.depth/2-m/150),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const g=d.material.uniforms.pointSize.value;n?d.material.uniforms.pointSize.value=Math.min(g*1.2,10):d.material.uniforms.pointSize.value=Math.max(g/1.2,1),c&&(d.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=p,this.view=y,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new q(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new X,this.axesHelper=new a.AxesHelper(1e3),this.filterBoxWorker=new E,this.geometry=new a.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Q.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var c,d,g;const u=this.renderer.domElement.getBoundingClientRect(),m=n.originalEvent.clientX-u.left,b=n.originalEvent.clientY-u.top;this.pointer.x=m/u.width*2-1,this.pointer.y=-(b/u.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(w=>{w instanceof a.Group&&w.children.forEach(C=>{C instanceof a.Mesh?f.push(C):this.updateMaterialColor(C,w.userData.defaultColor)})});const x=this.raycaster.intersectObjects(f,!1);if(x.length>0){const w=x[0].object.parent;w==null||w.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(c=this.pipe)==null||c.setNeedUpdateCenter(!1),(d=this.pipe)==null||d.setSelectedIDs(w==null?void 0:w.userData.selectedID)}else(g=this.pipe)==null||g.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof a.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof a.BoxHelper||t instanceof a.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new it(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new et(P({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new rt(z(P({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return P({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return j.getColorFromConfig({attribute:t},z(P({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,p=e.y-r/2-s,y=100,n=-100,c=500/y;return{left:h,right:o,top:l,bottom:p,near:y,far:n,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:l}=t,p=this.getCameraVector(r,l,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=D,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:p}=A(t),y=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:l,polygonPointList:p,color:i,position:y};return this.filterBoxWorker||(this.filterBoxWorker=new E),new Promise(c=>{var d;(d=this.filterBoxWorker)==null||d.postMessage(n),this.filterBoxWorker.onmessage=g=>{const{color:u,position:m,num:b}=g.data;this.geometry.dispose(),this.geometry.setAttribute("position",new a.Float32BufferAttribute(m,3)),this.geometry.setAttribute("color",new a.Float32BufferAttribute(u,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),c({geometry:this.geometry,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=v.Front,s=lt){let h=O.frontViewMatrix4(s);switch(r){case v.Front:break;case v.Back:h=O.backViewMatrix4(s);break;case v.Left:h=O.leftViewMatrix4(s);break;case v.Right:h=O.rightViewMatrix4(s);break;case v.Top:h=O.topViewMatrix4(s);break;case v.LFT:h=O.leftFrontTopViewMatrix4(s,i);break;case v.RBT:h=O.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),l=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new a.Matrix4().makeTranslation(t.x,t.y,t.z),y=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(y).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return S(this,null,function*(){return new Promise((e,i)=>{k.terminate(),k=new _({type:"module"}),k.postMessage(t),k.onmessage=r=>{e(r.data),k.terminate()},k.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return S(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:h}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,p)=>{if(window.Worker){const n=(e?[...e]:[]).map(m=>A(m)),c=this.getAllAttributeColor(n),d=o.geometry.attributes.position.array,g=o.geometry.attributes.dimensions.array,u={cuboidList:n,position:d,color:g,colorList:c,highlightIndex:i,modifiedBoxIds:s,resetAreas:h};this.handleWebworker(u).then(m=>{const{color:b}=m;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==b.length){p(new Error("Error Path"));return}let f=b;(s.length||h.length)&&(f=b.map((C,B)=>C===-1?g[B]:C));const x=new a.BufferAttribute(f,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const w={color:f,view:this.view,currentPCDSrc:this.currentPCDSrc};l(w),this.workerLoading=!1,this.render()}).catch(m=>{this.workerLoading=!1,p(m)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:l,depth:p,rotation:y}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},z(P({},this.config),{attributeConfigurable:!0}),{}),c=new a.BoxGeometry(o,l,p),d=new a.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(y),c.translate(r,s,h);const g=new a.Mesh(c,d);e.add(g);const u=new a.PlaneGeometry(p,l);u.rotateY(Math.PI/2),u.rotateZ(y);const m=new a.Vector3(o/2,0,0),b=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(y);m.applyMatrix4(b),u.translate(r+m.x,s+m.y,h+m.z);const f=new a.MeshBasicMaterial({color:n,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new a.Mesh(u,f);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new a.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(h=>{const o=i.find(n=>n.value===h);if(!o||!o.subSelected)return;const{key:l,subSelected:p}=o,y=[];p.forEach(n=>{var c;const d=(c=t.subAttribute)==null?void 0:c[h],g=Array.isArray(d)?d:d==null?void 0:d.split(";");(g==null?void 0:g.includes(n.value))&&y.push(n.key)}),y.length>0&&(r&&(r+="\u3001"),r+=`${l}:${y.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const h=t.split(`
33
- `),o=Math.max(...h.map(n=>i.measureText(n).width)),l=Math.ceil(o),p=s*1.5,y=p*h.length;e.width=l*r,e.height=y*r,e.style.width=`${l}px`,e.style.height=`${y}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((n,c)=>{i.fillText(n,0,c*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,c)=>n.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((n,c)=>n.x-c.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((n,c)=>n.y-c.y);const p=Math.floor(e.length*s),y=Math.floor(e.length*(1-s));return e=e.slice(p,y),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:p})=>{t.forEach((y,n)=>{const c=r[n+1],d=F.getFootOfPerpendicular({x:l,y:p},y,c,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:p}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((l,p)=>{const y=r[p],n=r[p+1],c=r[p+2];return $.getIntersectionBySlope({p1:s[p].point,line1:[y,n],p2:s[p+1].point,line2:[n,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(u=>u.uuid===this.pointsUuid);let l=0,p=0,y=0,n=0,c=[],d=[];const g=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let u=0;u<g.length;u+=3){const m=g[u],b=g[u+1],f=g[u+2];K({x:m,y:b},t)&&(f||f===0)&&d.push({x:m,y:b,z:f})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((u,m)=>u.z-m.z),l=d[0].z-.01,p=d[d.length-1].z+.01,n=d.length,e&&(y=d.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}):{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r-o/2},p={x:e+h/2,y:i+s/2,z:r+o/2},y={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2};return[l,p,y,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e-h/2,y:i+s/2,z:r+o/2},p={x:e-h/2,y:i+s/2,z:r-o/2},y={x:e-h/2,y:i-s/2,z:r-o/2},n={x:e-h/2,y:i-s/2,z:r+o/2};return[l,p,y,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r+o/2},p={x:e+h/2,y:i-s/2,z:r+o/2},y={x:e-h/2,y:i-s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r+o/2};return[l,p,y,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),l=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case v.Left:return this.getPolygonSidePoints(t);case v.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(n=>new a.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,y=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(p,y)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=D,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},l=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const y=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:y,zoom:Math.min(n,c)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=D,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=z(P({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=z(P({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(m=>new a.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(h)),[l,p,y,n]=o,c=Math.max(Math.abs(l.x-y.x),Math.abs(l.x-p.x)),g=p.add(n).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:z(P({},r),{center:{x:r.center.x-g.x,y:r.center.y-g.y,z:r.center.z-i},width:c,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{dt as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(c=this.currentPCDSrc,d){if(!c||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:g,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new a.BufferGeometry;m.setAttribute("position",new a.BufferAttribute(g,3)),this.isSegment||m.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(g);const b=new a.Points(m);this.renderPointCloud(b,d),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:c,points:d}){const g=f=>z(this,null,function*(){try{return yield Y.load(f)}catch(x){return console.error("Error loading image:",x),null}}),u=c.length===0?[]:(yield Promise.all(c.map(f=>z(this,null,function*(){let x=yield g(f.url);return!x&&f.fallbackUrl&&(x=yield g(f.fallbackUrl)),x})))).filter(f=>f!==null),m=c.map((f,x)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(f.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(f.url))!=null?w:[];const C=J({points:d,calib:f.calib,width:u[x].width,height:u[x].height});return this.cacheInstance.cache2DHighlightIndex.set(f.url,C),C});return tt(m)}),this.filterPreResult=(n,c,d)=>z(this,null,function*(){const{points:g}=yield this.cacheInstance.loadPCDFile(n),u=yield this.cacheInstance.loadIndexMap(n,g);return new Promise(m=>{const b=d.map(f=>{const x=N.calculatePointsInsideBox({indexMap:u,polygon:A(f).polygonPointList,zScope:[f.center.z-f.depth/2,f.center.z+f.depth/2],box:f}),w=x>=c.lowerLimitPointsNumInBox;return O(P({},f),{valid:w,count:x})});m(b)})}),this.loadPCDFileByBox=(n,c,d)=>z(this,null,function*(){const g=(b,f)=>z(this,null,function*(){const{width:x=0,height:w=0,depth:C=0}=d!=null?d:{},S=yield this.filterPointsByBox(O(P({},c),{width:c.width+x,height:c.height+w,depth:c.depth+C}),b,f);if(!S){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const L=new a.Points(S.geometry);L.name=this.pointCloudObjectName,this.scene.add(L),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);g(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new a.Vector3(1,0,0),d=new a.Vector3(n/2,0,0),g=2,u=new a.ArrowHelper(c,d,g,this.highlightColor);return u.visible=this.showDirection,u},this.generateLabel=(n,c,d)=>{const g=this.getTextCanvas(n),u=new a.Texture(g);u.minFilter=a.LinearFilter,u.magFilter=a.LinearFilter,u.needsUpdate=!0;const m=g.width/window.devicePixelRatio,b=g.height/window.devicePixelRatio,f=new a.SpriteMaterial({map:u,depthWrite:!1,color:d}),x=new a.Sprite(f);return x.scale.set(m/c,b/c,1),{sprite:x,canvasWidth:m,canvasHeight:b}},this.generateBoxTrackID=(n,c)=>{if(!n.trackID)return;const{sprite:d}=this.generateLabel(n.trackID.toString(),50,c);return d.position.set(-n.width/2,0,n.depth/2+.5),d},this.generateBoxAttributeLabel=(n,c)=>{if(!n.attribute||this.hiddenText)return;const d=this.findSubAttributeLabel(n,this.config),g=d?`${n.attribute}
32
+ ${d}`:`${n.attribute}`,{sprite:u,canvasHeight:m}=this.generateLabel(g,100,c);return u.position.set(-n.width/2,0,-n.depth/2-m/150),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const g=d.material.uniforms.pointSize.value;n?d.material.uniforms.pointSize.value=Math.min(g*1.2,10):d.material.uniforms.pointSize.value=Math.max(g/1.2,1),c&&(d.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=p,this.view=y,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new q(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new X,this.axesHelper=new a.AxesHelper(1e3),this.filterBoxWorker=new _,this.geometry=new a.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Q.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var c,d,g;const u=this.renderer.domElement.getBoundingClientRect(),m=n.originalEvent.clientX-u.left,b=n.originalEvent.clientY-u.top;this.pointer.x=m/u.width*2-1,this.pointer.y=-(b/u.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(w=>{w instanceof a.Group&&w.children.forEach(C=>{C instanceof a.Mesh?f.push(C):this.updateMaterialColor(C,w.userData.defaultColor)})});const x=this.raycaster.intersectObjects(f,!1);if(x.length>0){const w=x[0].object.parent;w==null||w.children.forEach(C=>{this.updateMaterialColor(C,this.highlightColor)}),(c=this.pipe)==null||c.setNeedUpdateCenter(!1),(d=this.pipe)==null||d.setSelectedIDs(w==null?void 0:w.userData.selectedID)}else(g=this.pipe)==null||g.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof a.Group))return;const i=t&&e.name===`box${t}`?this.highlightColor:e.userData.defaultColor;e.children.forEach(r=>{this.updateMaterialColor(r,i)})})}updateMaterialColor(t,e){(t instanceof a.BoxHelper||t instanceof a.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new it(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new et(P({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new rt(O(P({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return P({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return j.getColorFromConfig({attribute:t},O(P({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,p=e.y-r/2-s,y=100,n=-100,c=500/y;return{left:h,right:o,top:l,bottom:p,near:y,far:n,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:l}=t,p=this.getCameraVector(r,l,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=D,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:p}=A(t),y=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:o,zMax:l,polygonPointList:p,color:i,position:y};return this.filterBoxWorker||(this.filterBoxWorker=new _),new Promise(c=>{var d;(d=this.filterBoxWorker)==null||d.postMessage(n),this.filterBoxWorker.onmessage=g=>{const{color:u,position:m,num:b}=g.data;this.geometry.dispose(),this.geometry.setAttribute("position",new a.Float32BufferAttribute(m,3)),this.geometry.setAttribute("color",new a.Float32BufferAttribute(u,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),c({geometry:this.geometry,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=v.Front,s=lt){let h=k.frontViewMatrix4(s);switch(r){case v.Front:break;case v.Back:h=k.backViewMatrix4(s);break;case v.Left:h=k.leftViewMatrix4(s);break;case v.Right:h=k.rightViewMatrix4(s);break;case v.Top:h=k.topViewMatrix4(s);break;case v.LFT:h=k.leftFrontTopViewMatrix4(s,i);break;case v.RBT:h=k.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),l=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new a.Matrix4().makeTranslation(t.x,t.y,t.z),y=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(y).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return z(this,null,function*(){return new Promise((e,i)=>{B&&(B.terminate(),B=null),B=new $({type:"module"}),B.postMessage(t),B.onmessage=r=>{e(r.data),B==null||B.terminate(),B=null},B.onerror=r=>{i(r)}})})}highlightOriginPointCloud(t){return z(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:s,resetAreas:h}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,p)=>{if(window.Worker){const n=(e?[...e]:[]).map(m=>A(m)),c=this.getAllAttributeColor(n),d=o.geometry.attributes.position.array,g=o.geometry.attributes.dimensions.array,u={cuboidList:n,position:d,color:g,colorList:c,highlightIndex:i,modifiedBoxIds:s,resetAreas:h};this.handleWebworker(u).then(m=>{const{color:b}=m;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==b.length){p(new Error("Error Path"));return}let f=b;(s.length||h.length)&&(f=b.map((C,S)=>C===-1?g[S]:C));const x=new a.BufferAttribute(f,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,o.geometry.setAttribute("dimensions",x),o.geometry.attributes.dimensions.needsUpdate=!0;const w={color:f,view:this.view,currentPCDSrc:this.currentPCDSrc};l(w),this.workerLoading=!1,this.render()}).catch(m=>{this.workerLoading=!1,p(m)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:l,depth:p,rotation:y}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},O(P({},this.config),{attributeConfigurable:!0}),{}),c=new a.BoxGeometry(o,l,p),d=new a.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(y),c.translate(r,s,h);const g=new a.Mesh(c,d);e.add(g);const u=new a.PlaneGeometry(p,l);u.rotateY(Math.PI/2),u.rotateZ(y);const m=new a.Vector3(o/2,0,0),b=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(y);m.applyMatrix4(b),u.translate(r+m.x,s+m.y,h+m.z);const f=new a.MeshBasicMaterial({color:n,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new a.Mesh(u,f);e.add(x)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t,e=""){if(e&&e!==this.currentPCDSrc)return;const i=this.scene.getObjectByName(this.pointCloudObjectName);if(i){const r=new a.BufferAttribute(t,3);i.geometry.setAttribute("dimensions",r),i.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const s=Object.keys(t.subAttribute);return s.length===0||s.forEach(h=>{const o=i.find(n=>n.value===h);if(!o||!o.subSelected)return;const{key:l,subSelected:p}=o,y=[];p.forEach(n=>{var c;const d=(c=t.subAttribute)==null?void 0:c[h],g=Array.isArray(d)?d:d==null?void 0:d.split(";");(g==null?void 0:g.includes(n.value))&&y.push(n.key)}),y.length>0&&(r&&(r+="\u3001"),r+=`${l}:${y.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,s=50;if(i){i.font=`${s}px bold`;const h=t.split(`
33
+ `),o=Math.max(...h.map(n=>i.measureText(n).width)),l=Math.ceil(o),p=s*1.5,y=p*h.length;e.width=l*r,e.height=y*r,e.style.width=`${l}px`,e.style.height=`${y}px`,i.scale(r,r),i.font=`${s}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((n,c)=>{i.fillText(n,0,c*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,c)=>n.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((n,c)=>n.x-c.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((n,c)=>n.y-c.y);const p=Math.floor(e.length*s),y=Math.floor(e.length*(1-s));return e=e.slice(p,y),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:p})=>{t.forEach((y,n)=>{const c=r[n+1],d=N.getFootOfPerpendicular({x:l,y:p},y,c,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:p}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((l,p)=>{const y=r[p],n=r[p+1],c=r[p+2];return G.getIntersectionBySlope({p1:s[p].point,line1:[y,n],p2:s[p+1].point,line2:[n,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(u=>u.uuid===this.pointsUuid);let l=0,p=0,y=0,n=0,c=[],d=[];const g=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let u=0;u<g.length;u+=3){const m=g[u],b=g[u+1],f=g[u+2];K({x:m,y:b},t)&&(f||f===0)&&d.push({x:m,y:b,z:f})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((u,m)=>u.z-m.z),l=d[0].z-.01,p=d[d.length-1].z+.01,n=d.length,e&&(y=d.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}):{maxZ:p,minZ:l,count:y,zCount:n,fittedCoordinates:c}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r-o/2},p={x:e+h/2,y:i+s/2,z:r+o/2},y={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2};return[l,p,y,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e-h/2,y:i+s/2,z:r+o/2},p={x:e-h/2,y:i+s/2,z:r-o/2},y={x:e-h/2,y:i-s/2,z:r-o/2},n={x:e-h/2,y:i-s/2,z:r+o/2};return[l,p,y,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r+o/2},p={x:e+h/2,y:i-s/2,z:r+o/2},y={x:e-h/2,y:i-s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r+o/2};return[l,p,y,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),l=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,v.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case v.Left:return this.getPolygonSidePoints(t);case v.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(n=>new a.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,y=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(p,y)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=D,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},l=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const y=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:y,zoom:Math.min(n,c)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=D,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=O(P({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=O(P({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(m=>new a.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(h)),[l,p,y,n]=o,c=Math.max(Math.abs(l.x-y.x),Math.abs(l.x-p.x)),g=p.add(n).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:O(P({},r),{center:{x:r.center.x-g.x,y:r.center.y-g.y,z:r.center.z-i},width:c,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{dt as PointCloud};
@@ -1,2 +1,2 @@
1
- import $ from"lodash";import{distance as X}from"@turf/turf";import j from"../../utils/MathUtils.js";import y from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/RectUtils.js";import P from"../../utils/tool/TagUtils.js";import{EDragStatus as p,ESortDirection as W,DEFAULT_TEXT_SHADOW as z}from"../../constant/annotation.js";import{EDragTarget as S,EOperationMode as Y}from"../../constant/tool.js";import A from"../../constant/keyCode.js";import O from"../../locales/index.js";import{EMessage as U}from"../../locales/constants.js";import L from"../../utils/tool/AttributeUtils.js";import Z from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import D from"../../utils/tool/DrawUtils.js";import q from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as H}from"../../utils/tool/polygonTool.js";import G from"../../utils/uuid.js";import{BasicToolOperation as J}from"./basicToolOperation.js";import Q from"./textAttributeClass.js";import tt from"./Selection.js";import{i18n as et}from"@labelbee/lb-utils";var it=Object.defineProperty,st=Object.defineProperties,rt=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,N=(w,t,e)=>t in w?it(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,u=(w,t)=>{for(var e in t||(t={}))nt.call(t,e)&&N(w,e,t[e]);if(B)for(var e of B(t))ot.call(t,e)&&N(w,e,t[e]);return w},f=(w,t)=>st(w,rt(t));const k=6;class V extends J{constructor(t){super(f(u({},t),{isOffscreenCanvas:!0}));this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(n=>n.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=k,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&I.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>I.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(h=>({size:h.width*h.height,id:h.id})).sort((h,o)=>h.size-o.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=P.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var h;if(a.id===this.selectedRectID){const o=(h=a==null?void 0:a.subAttribute)!=null?h:s;return f(u({},a),{subAttribute:o})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(L.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new tt(this)}renderPointCloud2DHighlight(){}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;L.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",L.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?f(u({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return f(u({},i),{subAttribute:f(u({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?y.returnClosePointIndex(this.getCoordinateUnderZoom(t),I.getRectPointList(this.selectedRect,this.zoom),k+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=I.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:h}=j.getFootOfPerpendicular(n,a.begin,a.end);h<k+10&&(e=s)}return e}getTextIconSvg(t=""){return L.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=S.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=S.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=S.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=p.Start}}}appendOffsetRect(t,e){return f(u({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...I.getRectPointList(this.appendOffsetRect(n,e))),[]);return j.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),h={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return I.isRectNotInPolygon(h,H(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const o=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(o)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!I.isInRect(d,o))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=$.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>f(u({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>f(u({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=p.Move,this.dragInfo.dragTarget===S.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=I.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:o,width:d,height:c}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case S.Point:{let g=h,b=o,m=d,x=c;switch(this.hoverRectPointIndex){case 0:{g=d-s.x<0?h+d:h+s.x,b=c-s.y<0?o+c:o+s.y,m=Math.abs(s.x-d),x=Math.abs(s.y-c);break}case 1:{g=d+s.x>0?h:h+d+s.x,b=c-s.y<0?o+c:o+s.y,m=Math.abs(d+s.x),x=Math.abs(c-s.y);break}case 2:{g=d+s.x>0?h:h+d+s.x,b=c+s.y>0?o:o+c+s.y,m=Math.abs(d+s.x),x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{g=d-s.x<0?h+d:h+s.x,b=c+s.y>0?o:o+c+s.y,m=Math.abs(s.x-d),x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}l=f(u({},l),{x:g,y:b,width:m,height:x})}break;case S.Line:{let g=h,b=o,m=d,x=c;switch(this.hoverRectEdgeIndex){case 0:{b=c-s.y<0?o+c:o+s.y,x=Math.abs(s.y-c);break}case 1:{g=d+s.x>0?h:h+d+s.x,m=Math.abs(d+s.x);break}case 2:{b=c+s.y>0?o:o+c+s.y,x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{g=d-s.x<0?h+d:h+s.x,m=Math.abs(s.x-d);break}default:return}l=f(u({},l),{x:g,y:b,width:m,height:x});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&I.isRectNotInPolygon(l,H(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,m=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<b-.01||l.width>g+m-l.x+.01||l.height>b+x-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<b&&(l.y=b),l.width>g+m-l.x)switch(this.dragInfo.dragTarget){case S.Point:case S.Line:s.x>0&&s.y>0&&(l.width=g+m-l.x);break;default:return}if(l.height>b+x-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?I.getRectUnderZoom(l,1/this.zoom):g)),this.render()}onMouseMove(t){requestAnimationFrame(()=>{var e,i;const r=Date.now();if(r-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=r,super.onMouseMove(t,!1)||this.forbidMouseOperation||!this.imgInfo))return;const n=this.getCoordinateUnderZoom(t),s=y.changeDrawOutsideTarget(n,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(s),this.render();return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const d=this.getHoverRectEdgeIndex(t);if(d!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=d,this.render();return}}}const a=this.getHoverRectID(t),h=this.hoverRectID;if(this.hoverRectID=a,a!==h&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:d}=this.firstClickCoord,{width:c,height:l}=this.drawingRect;if(c=Math.abs(o-s.x),l=Math.abs(d-s.y),s.x<o&&(o=s.x),s.y<d&&(d=s.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&I.isRectNotInPolygon(f(u({},this.drawingRect),{x:o,y:d,width:c,height:l}),H(this.basicResult.pointList,this.zoom)))return;s.x<0&&(c=Math.abs(this.firstClickCoord.x),o=0),s.y<0&&(l=Math.abs(this.firstClickCoord.y),d=0),this.imgInfo&&(o+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-o)),d+l>this.imgInfo.height&&(l=Math.abs(this.imgInfo.height-d)))}this.drawingRect=f(u({},this.drawingRect),{x:o,y:d,width:c,height:l}),this.render()}if(this.isDrag&&!this.dragInfo){this.render("drag");return}this.render("move")})}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){const e=this.rectList.some(i=>i==null?void 0:i.valid);this.setRectList(this.rectList.map(i=>i.id===t?f(u({},i),{valid:!i.valid}):(this.selection.isIdSelected(i.id)&&(i.valid=!e),i)),!0),this.render(),this.emit("updateResult")}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),h=y.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(h.x<0&&(h.x=0),h.y<0&&(h.y=0)),this.drawingRect=f(u({},h),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:G(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",O.getMessagesByLocale(U.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=L.getTextAttribute(this.rectList.filter(d=>R.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{textAttribute:o}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const o=P.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=f(u({},this.drawingRect),{subAttribute:o})}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=u({},h),this.firstCurrentPos=u({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}checkSize({width:t,height:e,minWidth:i,minHeight:r,isAttributeConfig:n=!1}){return Math.round(t)<i||Math.round(e)<r?(this.emit("messageInfo",et.t(n?"TheSizeOfTheDrawingBoxIsSmallerThanTheMinimumDrawingSizeInTheMainPropertyConfiguration":"TheDrawFrameSizeIsSmallerThanTheMinimumDrawSizeInTheStepConfiguration")),this.clearDrawingStatus(),this.render(),!1):!0}addDrawingRectToRectList(){var t,e,i;if(!this.drawingRect)return;let{width:r,height:n}=this.drawingRect;r/=this.zoom,n/=this.zoom;const{attribute:s}=this.drawingRect;let a={minWidth:this.config.minWidth,minHeight:this.config.minHeight};if(s&&this.config.attributeConfigurable){const d=(i=((e=(t=this.config)==null?void 0:t.attributeList)!=null?e:[]).find(c=>c.value===s))==null?void 0:i.limit;d&&(a=f(u({},d),{isAttributeConfig:!0}))}if(!this.checkSize(u({width:r,height:n},a)))return;const h=this.getDrawingRectWithRectList();this.setRectList(h,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,f(u({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),h=this.rectList.find(o=>o.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&X((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),h&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(h.attribute)),this.hoverRectID="",(h==null?void 0:h.label)&&this.hasMarkerConfig){const o=R.getCurrentMarkerIndex(h.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),h}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",u({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===p.Move){this.dragInfo=void 0,this.dragStatus=p.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case A.Ctrl:this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case A.F:this.selectedIDs.length>0&&this.setRectValidAndRender(this.selectedRectID);break;case A.Z:this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deleteSelectedRect(t);break;case A.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=W.ascend;t.shiftKey&&(i=W.descend);const[r,n]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=Z.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(o=>Z.inViewPort({x:o.x,y:o.y},a));const h=R.getNextSelectedRectID(s,i,this.selectedRectID);h&&(this.setSelectedRectID(h.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(h.attribute));break}default:{if(this.config.attributeConfigurable){const i=L.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case A.Ctrl:this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=I.getRectUnderZoom(this.drawingRect,1/e),r=y.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=I.getRectUnderZoom(i,this.zoom),this.firstClickCoord=y.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect: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:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:n,height:s,attribute:a,valid:h}=e,o=n*this.zoom*.6,d=y.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),l=h?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new Q({width:o,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+g,color:l,width:o})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=I.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,h)=>{var o,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===h?i=k+6:i=k,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===h){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),l=t.valid===!1?(o=c==null?void 0:c.invalid)==null?void 0:o.stroke:(d=c==null?void 0:c.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[h].x*this.zoom+this.currentPos.x,r[h].y*this.zoom+this.currentPos.y),e.lineTo(r[(h+1)%n].x*this.zoom+this.currentPos.x,r[(h+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1,r=!1){var n,s,a,h,o,d;if(this.ctx&&t){const{ctx:c,style:l}=this,{hiddenText:g=!1}=l;c.save();const{strokeColor:b,fillColor:m,textColor:x}=this.getRenderStyle(t);c.font="lighter 14px Arial";let C="";((n=this.config)==null?void 0:n.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(C=`${t.order}`),t.label&&this.hasMarkerConfig&&(C=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${q.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(C=`${C} ${L.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((a=this.config)==null?void 0:a.secondaryAttributeConfigurable)&&((h=this.config)==null?void 0:h.subAttributeList)&&P.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(T=>{C+=`
2
- ${T.keyName}: ${T.value.join("\u3001")}`}));const v=y.changeRectByZoom(t,i?e:this.zoom,this.currentPos);g||D.drawText(this.canvas,{x:v.x,y:v.y-6},C,f(u({color:b,font:"normal normal 900 14px SourceHanSansCN-Regular"},z),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&D.drawHighlightFlag({canvas:this.canvas,color:b,position:{x:v.x-5,y:v.y-16}});const K=(d=(o=this.style)==null?void 0:o.width)!=null?d:2,F=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||F||t.id===this.selectedRectID||this.isMultiMoveMode||r)&&D.drawRectWithFill(this.canvas,v,{color:m}),D.drawRect(this.canvas,v,{color:b,thickness:K,hiddenText:!0,lineDash:t.lineDash}),c.restore();let M=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(M=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const E=M.length*7;if(g||D.drawText(this.canvas,{x:v.x+v.width-E,y:v.y+v.height+15},M,u({color:x,font:"normal normal 600 14px Arial"},z)),!g&&t.textAttribute&&t.id!==this.selectedRectID){const _=0,T=Math.max(20,v.width-E);D.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+_},t.textAttribute,u({color:x,font:"italic normal 900 14px Arial",textMaxWidth:T},z))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,y.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),r&&r.forEach(n=>{this.renderDrawingRect(n),this.renderSelectedRect(n),e.selectedRender&&e.selectedRender(this.canvas,y.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),this.renderPointCloud2DHighlight()}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,y.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(t){t!=="move"&&this.renderStaticRect(),this.renderCreatingRect()}render(t){!this.ctx||(t!=="move"&&super.render(),t!=="drag"&&this.renderRect(t),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){this.clearOffscreenCanvas();const{x:e,y:i}=this.coord;D.drawLine(this.offscreenCanvas,{x:0,y:i},{x:1e4,y:i},{color:t}),D.drawLine(this.offscreenCanvas,{x:e,y:0},{x:e,y:1e4},{color:t}),D.drawCircleWithFill(this.offscreenCanvas,{x:e,y:i},1,{color:"white"})}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(i=>this.selection.isIdSelected(i.id)?f(u({},i),{attribute:this.defaultAttribute}):i),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearDrawingStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=p.Wait}clearActiveStatus(){this.clearDrawingStatus(),this.setSelectedRectID(void 0),this.setOperationMode(Y.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",O.getMessagesByLocale(U.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",O.getMessagesByLocale(U.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}setHoverRectID(t){this.hoverRectID=t}}export{V as RectOperation,V as default};
1
+ import $ from"lodash";import{distance as X}from"@turf/turf";import j from"../../utils/MathUtils.js";import y from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/RectUtils.js";import P from"../../utils/tool/TagUtils.js";import{i18n as Y}from"@labelbee/lb-utils";import{EDragStatus as p,ESortDirection as W,DEFAULT_TEXT_SHADOW as z}from"../../constant/annotation.js";import{EDragTarget as S,EOperationMode as q}from"../../constant/tool.js";import A from"../../constant/keyCode.js";import O from"../../locales/index.js";import{EMessage as U}from"../../locales/constants.js";import L from"../../utils/tool/AttributeUtils.js";import Z from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import D from"../../utils/tool/DrawUtils.js";import G from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as H}from"../../utils/tool/polygonTool.js";import J from"../../utils/uuid.js";import{BasicToolOperation as Q}from"./basicToolOperation.js";import tt from"./textAttributeClass.js";import et from"./Selection.js";var it=Object.defineProperty,st=Object.defineProperties,rt=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,N=(w,t,e)=>t in w?it(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,u=(w,t)=>{for(var e in t||(t={}))nt.call(t,e)&&N(w,e,t[e]);if(B)for(var e of B(t))ot.call(t,e)&&N(w,e,t[e]);return w},f=(w,t)=>st(w,rt(t));const k=6;class V extends Q{constructor(t){super(f(u({},t),{isOffscreenCanvas:!0}));this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(n=>n.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=k,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&I.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>I.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(h=>({size:h.width*h.height,id:h.id})).sort((h,o)=>h.size-o.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=P.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var h;if(a.id===this.selectedRectID){const o=(h=a==null?void 0:a.subAttribute)!=null?h:s;return f(u({},a),{subAttribute:o})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(L.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new et(this)}renderPointCloud2DHighlight(){}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;L.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",L.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?f(u({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return f(u({},i),{subAttribute:f(u({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?y.returnClosePointIndex(this.getCoordinateUnderZoom(t),I.getRectPointList(this.selectedRect,this.zoom),k+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=I.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:h}=j.getFootOfPerpendicular(n,a.begin,a.end);h<k+10&&(e=s)}return e}getTextIconSvg(t=""){return L.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=S.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=S.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=S.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=p.Start}}}appendOffsetRect(t,e){return f(u({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...I.getRectPointList(this.appendOffsetRect(n,e))),[]);return j.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),h={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return I.isRectNotInPolygon(h,H(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const o=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(o)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!I.isInRect(d,o))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=$.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>f(u({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>f(u({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=p.Move,this.dragInfo.dragTarget===S.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=I.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:o,width:d,height:c}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case S.Point:{let g=h,b=o,m=d,x=c;switch(this.hoverRectPointIndex){case 0:{g=d-s.x<0?h+d:h+s.x,b=c-s.y<0?o+c:o+s.y,m=Math.abs(s.x-d),x=Math.abs(s.y-c);break}case 1:{g=d+s.x>0?h:h+d+s.x,b=c-s.y<0?o+c:o+s.y,m=Math.abs(d+s.x),x=Math.abs(c-s.y);break}case 2:{g=d+s.x>0?h:h+d+s.x,b=c+s.y>0?o:o+c+s.y,m=Math.abs(d+s.x),x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{g=d-s.x<0?h+d:h+s.x,b=c+s.y>0?o:o+c+s.y,m=Math.abs(s.x-d),x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}l=f(u({},l),{x:g,y:b,width:m,height:x})}break;case S.Line:{let g=h,b=o,m=d,x=c;switch(this.hoverRectEdgeIndex){case 0:{b=c-s.y<0?o+c:o+s.y,x=Math.abs(s.y-c);break}case 1:{g=d+s.x>0?h:h+d+s.x,m=Math.abs(d+s.x);break}case 2:{b=c+s.y>0?o:o+c+s.y,x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{g=d-s.x<0?h+d:h+s.x,m=Math.abs(s.x-d);break}default:return}l=f(u({},l),{x:g,y:b,width:m,height:x});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&I.isRectNotInPolygon(l,H(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,m=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<b-.01||l.width>g+m-l.x+.01||l.height>b+x-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<b&&(l.y=b),l.width>g+m-l.x)switch(this.dragInfo.dragTarget){case S.Point:case S.Line:s.x>0&&s.y>0&&(l.width=g+m-l.x);break;default:return}if(l.height>b+x-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?I.getRectUnderZoom(l,1/this.zoom):g)),this.render()}onMouseMove(t){requestAnimationFrame(()=>{var e,i;const r=Date.now();if(r-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=r,super.onMouseMove(t,!1)||this.forbidMouseOperation||!this.imgInfo))return;const n=this.getCoordinateUnderZoom(t),s=y.changeDrawOutsideTarget(n,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(s),this.render();return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const d=this.getHoverRectEdgeIndex(t);if(d!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=d,this.render();return}}}const a=this.getHoverRectID(t),h=this.hoverRectID;if(this.hoverRectID=a,a!==h&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:d}=this.firstClickCoord,{width:c,height:l}=this.drawingRect;if(c=Math.abs(o-s.x),l=Math.abs(d-s.y),s.x<o&&(o=s.x),s.y<d&&(d=s.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&I.isRectNotInPolygon(f(u({},this.drawingRect),{x:o,y:d,width:c,height:l}),H(this.basicResult.pointList,this.zoom)))return;s.x<0&&(c=Math.abs(this.firstClickCoord.x),o=0),s.y<0&&(l=Math.abs(this.firstClickCoord.y),d=0),this.imgInfo&&(o+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-o)),d+l>this.imgInfo.height&&(l=Math.abs(this.imgInfo.height-d)))}this.drawingRect=f(u({},this.drawingRect),{x:o,y:d,width:c,height:l}),this.render()}if(this.isDrag&&!this.dragInfo){this.render("drag");return}this.render("move")})}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){const e=this.rectList.some(i=>i==null?void 0:i.valid);this.setRectList(this.rectList.map(i=>i.id===t?f(u({},i),{valid:!i.valid}):(this.selection.isIdSelected(i.id)&&(i.valid=!e),i)),!0),this.render(),this.emit("updateResult")}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),h=y.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(h.x<0&&(h.x=0),h.y<0&&(h.y=0)),this.drawingRect=f(u({},h),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",O.getMessagesByLocale(U.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=L.getTextAttribute(this.rectList.filter(d=>R.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{textAttribute:o}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const o=P.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=f(u({},this.drawingRect),{subAttribute:o})}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=u({},h),this.firstCurrentPos=u({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}checkSize({width:t,height:e,minWidth:i,minHeight:r,isAttributeConfig:n=!1}){return Math.round(t)<i||Math.round(e)<r?(this.emit("messageInfo",Y.t(n?"TheSizeOfTheDrawingBoxIsSmallerThanTheMinimumDrawingSizeInTheMainPropertyConfiguration":"TheDrawFrameSizeIsSmallerThanTheMinimumDrawSizeInTheStepConfiguration")),this.clearDrawingStatus(),this.render(),!1):!0}addDrawingRectToRectList(){var t,e,i;if(!this.drawingRect)return;let{width:r,height:n}=this.drawingRect;r/=this.zoom,n/=this.zoom;const{attribute:s}=this.drawingRect;let a={minWidth:this.config.minWidth,minHeight:this.config.minHeight};if(s&&this.config.attributeConfigurable){const d=(i=((e=(t=this.config)==null?void 0:t.attributeList)!=null?e:[]).find(c=>c.value===s))==null?void 0:i.limit;d&&(a=f(u({},d),{isAttributeConfig:!0}))}if(!this.checkSize(u({width:r,height:n},a)))return;const h=this.getDrawingRectWithRectList();this.setRectList(h,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,f(u({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),h=this.rectList.find(o=>o.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&X((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),h&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(h.attribute)),this.hoverRectID="",(h==null?void 0:h.label)&&this.hasMarkerConfig){const o=R.getCurrentMarkerIndex(h.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),h}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",u({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===p.Move){this.dragInfo=void 0,this.dragStatus=p.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case A.Ctrl:this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case A.F:this.selectedIDs.length>0&&this.setRectValidAndRender(this.selectedRectID);break;case A.Z:this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deleteSelectedRect(t);break;case A.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=W.ascend;t.shiftKey&&(i=W.descend);const[r,n]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=Z.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(o=>Z.inViewPort({x:o.x,y:o.y},a));const h=R.getNextSelectedRectID(s,i,this.selectedRectID);h&&(this.setSelectedRectID(h.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(h.attribute));break}default:{if(this.config.attributeConfigurable){const i=L.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case A.Ctrl:this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=I.getRectUnderZoom(this.drawingRect,1/e),r=y.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=I.getRectUnderZoom(i,this.zoom),this.firstClickCoord=y.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect: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:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:n,height:s,attribute:a,valid:h}=e,o=n*this.zoom*.6,d=y.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),l=h?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new tt({width:o,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+g,color:l,width:o})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=I.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,h)=>{var o,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===h?i=k+6:i=k,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===h){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),l=t.valid===!1?(o=c==null?void 0:c.invalid)==null?void 0:o.stroke:(d=c==null?void 0:c.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[h].x*this.zoom+this.currentPos.x,r[h].y*this.zoom+this.currentPos.y),e.lineTo(r[(h+1)%n].x*this.zoom+this.currentPos.x,r[(h+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1,r=!1){var n,s,a,h,o,d;if(this.ctx&&t){const{ctx:c,style:l}=this,{hiddenText:g=!1}=l;c.save();const{strokeColor:b,fillColor:m,textColor:x}=this.getRenderStyle(t);c.font="lighter 14px Arial";let C="";((n=this.config)==null?void 0:n.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(C=`${t.order}`),t.label&&this.hasMarkerConfig&&(C=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${G.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(C=`${C} ${L.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((a=this.config)==null?void 0:a.secondaryAttributeConfigurable)&&((h=this.config)==null?void 0:h.subAttributeList)&&P.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(T=>{C+=`
2
+ ${T.keyName}: ${T.value.join("\u3001")}`}));const v=y.changeRectByZoom(t,i?e:this.zoom,this.currentPos);g||D.drawText(this.canvas,{x:v.x,y:v.y-6},C,f(u({color:b,font:"normal normal 900 14px SourceHanSansCN-Regular"},z),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&D.drawHighlightFlag({canvas:this.canvas,color:b,position:{x:v.x-5,y:v.y-16}});const K=(d=(o=this.style)==null?void 0:o.width)!=null?d:2,F=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||F||t.id===this.selectedRectID||this.isMultiMoveMode||r)&&D.drawRectWithFill(this.canvas,v,{color:m}),D.drawRect(this.canvas,v,{color:b,thickness:K,hiddenText:!0,lineDash:t.lineDash}),c.restore();let M=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(M=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const E=M.length*7;if(g||D.drawText(this.canvas,{x:v.x+v.width-E,y:v.y+v.height+15},M,u({color:x,font:"normal normal 600 14px Arial"},z)),!g&&t.textAttribute&&t.id!==this.selectedRectID){const _=0,T=Math.max(20,v.width-E);D.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+_},t.textAttribute,u({color:x,font:"italic normal 900 14px Arial",textMaxWidth:T},z))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,y.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),r&&r.forEach(n=>{this.renderDrawingRect(n),this.renderSelectedRect(n),e.selectedRender&&e.selectedRender(this.canvas,y.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),this.renderPointCloud2DHighlight()}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,y.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(t){t!=="move"&&this.renderStaticRect(),this.renderCreatingRect()}render(t){!this.ctx||(t!=="move"&&super.render(),t!=="drag"&&this.renderRect(t),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){this.clearOffscreenCanvas();const{x:e,y:i}=this.coord;D.drawLine(this.offscreenCanvas,{x:0,y:i},{x:1e4,y:i},{color:t}),D.drawLine(this.offscreenCanvas,{x:e,y:0},{x:e,y:1e4},{color:t}),D.drawCircleWithFill(this.offscreenCanvas,{x:e,y:i},1,{color:"white"})}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(i=>this.selection.isIdSelected(i.id)?f(u({},i),{attribute:this.defaultAttribute}):i),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearDrawingStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=p.Wait}clearActiveStatus(){this.clearDrawingStatus(),this.setSelectedRectID(void 0),this.setOperationMode(q.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",O.getMessagesByLocale(U.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",O.getMessagesByLocale(U.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}setHoverRectID(t){this.hoverRectID=t}}export{V as RectOperation,V as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.28.0-alpha.23",
3
+ "version": "1.28.0-alpha.25",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",