@labelbee/lb-annotation 1.28.0-alpha.3 → 1.28.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/_virtual/highlightWorker.js +1 -1
  2. package/dist/constant/tool.js +1 -1
  3. package/dist/core/pointCloud/annotation.js +1 -1
  4. package/dist/core/pointCloud/index.js +4 -4
  5. package/dist/core/pointCloud/matrix.js +1 -1
  6. package/dist/core/scheduler.js +1 -1
  7. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  8. package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
  9. package/dist/core/toolOperation/pointOperation.js +1 -1
  10. package/dist/core/toolOperation/polygonOperation.js +1 -1
  11. package/dist/core/toolOperation/rectOperation.js +2 -2
  12. package/dist/index.js +1 -1
  13. package/dist/types/constant/tool.d.ts +7 -0
  14. package/dist/types/core/pointCloud/QuadTree25D.d.ts +78 -0
  15. package/dist/types/core/pointCloud/annotation.d.ts +4 -3
  16. package/dist/types/core/pointCloud/index.d.ts +17 -8
  17. package/dist/types/core/scheduler.d.ts +1 -1
  18. package/dist/types/core/toolOperation/ScribbleTool.d.ts +1 -9
  19. package/dist/types/core/toolOperation/basicToolOperation.d.ts +8 -1
  20. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +19 -0
  21. package/dist/types/core/toolOperation/pointOperation.d.ts +1 -0
  22. package/dist/types/core/toolOperation/polygonOperation.d.ts +17 -13
  23. package/dist/types/core/toolOperation/rectOperation.d.ts +14 -4
  24. package/dist/types/utils/tool/AxisUtils.d.ts +3 -27
  25. package/dist/utils/tool/AxisUtils.js +1 -1
  26. package/dist/utils/tool/DrawUtils.js +1 -1
  27. package/dist/utils/tool/PolygonUtils.js +1 -1
  28. package/dist/utils/tool/TagUtils.js +1 -1
  29. package/dist/utils/tool/polygonTool.js +1 -1
  30. package/es/_virtual/highlightWorker.js +1 -1
  31. package/es/constant/tool.js +1 -1
  32. package/es/core/pointCloud/annotation.js +1 -1
  33. package/es/core/pointCloud/index.js +4 -4
  34. package/es/core/pointCloud/matrix.js +1 -1
  35. package/es/core/scheduler.js +1 -1
  36. package/es/core/toolOperation/basicToolOperation.js +1 -1
  37. package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
  38. package/es/core/toolOperation/pointOperation.js +1 -1
  39. package/es/core/toolOperation/polygonOperation.js +1 -1
  40. package/es/core/toolOperation/rectOperation.js +2 -2
  41. package/es/index.js +1 -1
  42. package/es/utils/tool/AxisUtils.js +1 -1
  43. package/es/utils/tool/DrawUtils.js +3 -3
  44. package/es/utils/tool/PolygonUtils.js +1 -1
  45. package/es/utils/tool/TagUtils.js +1 -1
  46. package/es/utils/tool/polygonTool.js +1 -1
  47. package/package.json +4 -4
@@ -1 +1 @@
1
- import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,c=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},p=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class J{constructor({size:t,container:o,pcdPath:s,extraProps:L,config:O,checkMode:_,toolName:h,proxyMode:b}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(u=>c({i:u},d.transferWorld2Canvas(u,this.toolInstance.size)));return p(c({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(C.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:u}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:u,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return p(c({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(u=>d.transferWorld2Canvas(u,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return p(c({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l)};const D=d.getDefaultOrthographicParams(t),T=S(t),g=new Image;g.src=T;const f=new B({container:o,size:t,toolName:h,proxyMode:b}),v=new A({container:o}),P=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});s&&P.loadPCDFile(s),v.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(c({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:_};L&&Object.assign(I,L);let m=[];E.isSingleTool(h)?m=[h]:m=h,m.forEach((a,l)=>{let i;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=f.createOperation(a,g,p(c({},I),{textConfigurable:!1}));l===m.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=v,this.toolScheduler=f,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(c({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(d.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=S(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const o=d.getBoxParamsFromResultList(t),s=d.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=d.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=d.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{J as PointCloudAnnotation};
1
+ import{PointCloudUtils as c}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as j}from"../../constant/tool.js";import{CanvasScheduler as B}from"../../newCore/CanvasScheduler.js";import{PointCloud as E}from"./index.js";import{ToolScheduler as V,HybridToolUtils as x}from"../scheduler.js";var F=Object.defineProperty,N=Object.defineProperties,U=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,S=(n,t,o)=>t in n?F(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,u=(n,t)=>{for(var o in t||(t={}))J.call(t,o)&&S(n,o,t[o]);if(w)for(var o of w(t))W.call(t,o)&&S(n,o,t[o]);return n},p=(n,t)=>N(n,U(t));const _=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class k{constructor({size:t,container:o,pcdPath:s,extraProps:O,config:v,checkMode:b,toolName:h,proxyMode:D,view:T}){this.updateLineList=a=>{const d=(a!=null?a:[]).map(l=>{var e;const i=(e=l.pointList)==null?void 0:e.map(r=>u({i:r},c.transferWorld2Canvas(r,this.toolInstance.size)));return p(u({},l),{pointList:i})});this.toolScheduler.updateDataByToolName(C.Line,d)},this.updatePolygonList=(a,d,l=!0)=>{let e=a.map(i=>{var r;const{polygon2d:L}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(i);return{id:i.id,sourceID:"",pointList:L,isRect:!0,valid:(r=i.valid)!=null?r:!0,attribute:i.attribute,trackID:i==null?void 0:i.trackID}});d&&(e=e.concat(d.map(i=>{var r;return p(u({},i),{pointList:(r=i==null?void 0:i.pointList)==null?void 0:r.map(L=>c.transferWorld2Canvas(L,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,e,l)},this.updatePointList=(a,d=!0)=>{const l=a==null?void 0:a.map(e=>{var i;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(e);return p(u({},r),{id:e.id,sourceID:"",valid:(i=e.valid)!=null?i:!0,attribute:e.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l,d)};const R=c.getDefaultOrthographicParams(t),A=_(t),g=new Image;g.src=A;const f=new V({container:o,size:t,toolName:h,proxyMode:D}),y=new B({container:o}),P=new E({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:R,view:T});s&&P.loadPCDFile(s),y.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(u({},v),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:b};O&&Object.assign(I,O);let m=[];x.isSingleTool(h)?m=[h]:m=h,m.forEach((a,d)=>{let l;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(j.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else l=f.createOperation(a,g,p(u({},I),{textConfigurable:!1}));d===m.length-1&&(this.toolInstance||(this.toolInstance=l,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=y,this.toolScheduler=f,this.config=v}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(u({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(c.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=_(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const o=c.getBoxParamsFromResultList(t),s=c.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=c.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=c.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{k as PointCloudAnnotation};
@@ -1,4 +1,4 @@
1
- import*as h from"three";import{toolStyleConverter as A,PerspectiveShiftUtils as z,EPerspectiveView as M,PointCloudUtils as Z,DEFAULT_SPHERE_PARAMS as k}from"@labelbee/lb-utils";import G from"../../_virtual/highlightWorker.js";import _ from"../../_virtual/filterBoxWorker.js";import{isInPolygon as $}from"../../utils/tool/polygonTool.js";import j from"../../utils/uuid.js";import E from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as K}from"./PCDLoader.js";import{OrbitControls as X}from"./OrbitControls.js";import{PointCloudCache as q}from"./cache.js";import{getCuboidFromPointCloudBox as T,getHighlightIndexByPoints as Q,mergeHighlightList as J}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 tt}from"./segmentation.js";import et from"./store/index.js";import it from"./render/index.js";import rt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var nt=Object.defineProperty,ot=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,F=(C,t,e)=>t in C?nt(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,v=(C,t)=>{for(var e in t||(t={}))at.call(t,e)&&F(C,e,t[e]);if(N)for(var e of N(t))ht.call(t,e)&&F(C,e,t[e]);return C},S=(C,t)=>ot(C,st(t)),B=(C,t,e)=>new Promise((i,r)=>{var a=d=>{try{s(e.next(d))}catch(u){r(u)}},c=d=>{try{s(e.throw(d))}catch(u){r(u)}},s=d=>d.done?i(d.value):Promise.resolve(d.value).then(a,c);s((e=e.apply(C,t)).next())});const ct=30,D=new G({type:"module"});class lt extends rt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:c,isSegment:s,checkMode:d,hiddenText:u=!1}){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 h.Raycaster,this.pointer=new h.Vector2,this.hiddenText=!1,this.filterBoxWorkerTimer=null,this.highlightColor=16776960,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,n="blue")=>{var l;const p=(l=o.id)!=null?l:j();this.removeObjectByName(p,"sphere");const{radius:g,widthSegments:f,heightSegments:y}=k,{center:m}=o,x=new h.Group,w=new h.SphereGeometry(g,f,y),b=new h.MeshBasicMaterial({color:n}),P=new h.Mesh(w,b);P.position.set(m.x,m.y,m.z),x.add(P),x.name=`sphere${p}`,this.scene.add(x)},this.generateSphere=o=>{const{fill:n}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,n),this.render()},this.generateSpheres=o=>{o.forEach(n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l)}),this.render()},this.addBoxToSense=(o,n=16777215)=>{var l;const p=(l=o.id)!=null?l:j();this.removeObjectByName(p,"box");const{center:g,width:f,height:y,depth:m,rotation:x}=o,w=new h.Group,b=new h.BoxGeometry(f,y,m),P=new h.MeshBasicMaterial({color:"blue"}),O=new h.Mesh(b,P),V=new h.BoxHelper(O,n),W=this.generateBoxArrow(o),L=this.generateBoxTrackID(o,n);L&&w.add(L);const I=this.generateBoxAttributeLabel(o,n);I&&w.add(I),w.add(V),w.add(W),g&&w.position.set(g.x,g.y,g.z),x&&w.rotation.set(0,0,x),w.name=`box${p}`;const R=new h.BoxGeometry(f,y,m),H=new h.MeshBasicMaterial({visible:!1}),U=new h.Mesh(R,H);w.add(U),w.userData={defaultColor:n,selectedID:p},this.scene.add(w)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const n=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,n)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as o from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as T,EPerspectiveView as M,PointCloudUtils as Z,DEFAULT_SPHERE_PARAMS as k}from"@labelbee/lb-utils";import $ from"../../_virtual/highlightWorker.js";import N from"../../_virtual/filterBoxWorker.js";import{isInPolygon as K}from"../../utils/tool/polygonTool.js";import _ from"../../utils/uuid.js";import E 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 D,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=(v,t,e)=>t in v?ot(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,P=(v,t)=>{for(var e in t||(t={}))ht.call(t,e)&&V(v,e,t[e]);if(F)for(var e of F(t))ct.call(t,e)&&V(v,e,t[e]);return v},L=(v,t)=>st(v,at(t)),O=(v,t,e)=>new Promise((i,r)=>{var a=l=>{try{s(e.next(l))}catch(u){r(u)}},c=l=>{try{s(e.throw(l))}catch(u){r(u)}},s=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,c);s((e=e.apply(v,t)).next())});const lt=30;let B=null;class dt extends nt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:c,isSegment:s,checkMode:l,hiddenText:u=!1,view:g=""}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.tipScopeObjectName="tipScope",this.highlightGroupName="highlightBoxes",this.cacheTipScopeList=[],this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new o.Raycaster,this.pointer=new o.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 d;const p=(d=n.id)!=null?d:_();this.removeObjectByName(p,"sphere");const{radius:m,widthSegments:y,heightSegments:b}=k,{center:f}=n,x=new o.Group,w=new o.SphereGeometry(m,y,b),C=new o.MeshBasicMaterial({color:h}),S=new o.Mesh(w,C);S.position.set(f.x,f.y,f.z),x.add(S),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:d}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,d)}),this.render()},this.addBoxToSense=(n,h=16777215)=>{var d;const p=(d=n.id)!=null?d:_();this.removeObjectByName(p,"box");const{center:m,width:y,height:b,depth:f,rotation:x}=n,w=new o.Group,C=new o.BoxGeometry(y,b,f),S=new o.MeshBasicMaterial({color:"blue"}),z=new o.Mesh(C,S),R=new o.BoxHelper(z,h),H=this.generateBoxArrow(n),A=this.generateBoxTrackID(n,h);A&&w.add(A);const I=this.generateBoxAttributeLabel(n,h);I&&w.add(I),w.add(R),w.add(H),m&&w.position.set(m.x,m.y,m.z),x&&w.rotation.set(0,0,x),w.name=`box${p}`;const W=new o.BoxGeometry(y,b,f),G=new o.MeshBasicMaterial({visible:!1}),U=new o.Mesh(W,G);w.add(U),w.userData={defaultColor:h,selectedID:p},this.scene.add(w)},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;
@@ -28,6 +28,6 @@ import*as h from"three";import{toolStyleConverter as A,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=(...o)=>B(this,[...o],function*(n=this.currentPCDSrc,l){if(!n)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=n;const{points:p,color:g}=yield this.cacheInstance.loadPCDFile(n),f=new h.BufferGeometry;f.setAttribute("position",new h.BufferAttribute(p,3)),this.isSegment||f.setAttribute("dimensions",new h.BufferAttribute(g,3)),this.initCloudData(p);const y=new h.Points(f);this.renderPointCloud(y,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=o=>B(this,[o],function*({mappingImgList:n,points:l}){const p=m=>B(this,null,function*(){try{return yield Y.load(m)}catch(x){return console.error("Error loading image:",x),null}}),g=n.length===0?[]:(yield Promise.all(n.map(m=>B(this,null,function*(){let x=yield p(m.url);return!x&&m.fallbackUrl&&(x=yield p(m.fallbackUrl)),x})))).filter(m=>m!==null),f=n.map((m,x)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?w:[];const b=Q({points:l,calib:m.calib,width:g[x].width,height:g[x].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,b),b});return J(f)}),this.filterPreResult=(o,n,l)=>B(this,null,function*(){const{points:p}=yield this.cacheInstance.loadPCDFile(o),g=yield this.cacheInstance.loadIndexMap(o,p);return new Promise(f=>{const y=l.map(m=>{const x=E.calculatePointsInsideBox({indexMap:g,polygon:T(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),w=x>=n.lowerLimitPointsNumInBox;return S(v({},m),{valid:w,count:x})});f(y)})}),this.loadPCDFileByBox=(o,n,l)=>B(this,null,function*(){const p=(y,m)=>B(this,null,function*(){const{width:x=0,height:w=0,depth:b=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(v({},n),{width:n.width+x,height:n.height+w,depth:n.depth+b}),y,m);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const O=new h.Points(P.geometry);O.name=this.pointCloudObjectName,this.scene.add(O),this.render()}),{points:g,color:f}=yield this.cacheInstance.loadPCDFile(o);p(g,f)}),this.generateRange=o=>{const n=this.createRange(o);this.scene.add(n)},this.generateBoxArrow=({width:o})=>{const n=new h.Vector3(1,0,0),l=new h.Vector3(o/2,0,0),p=2,g=new h.ArrowHelper(n,l,p,this.highlightColor);return g.visible=this.showDirection,g},this.generateLabel=(o,n,l)=>{const p=this.getTextCanvas(o),g=new h.Texture(p);g.minFilter=h.LinearFilter,g.magFilter=h.LinearFilter,g.needsUpdate=!0;const f=p.width/window.devicePixelRatio,y=p.height/window.devicePixelRatio,m=new h.SpriteMaterial({map:g,depthWrite:!1,color:l}),x=new h.Sprite(m);return x.scale.set(f/n,y/n,1),{sprite:x,canvasWidth:f,canvasHeight:y}},this.generateBoxTrackID=(o,n)=>{if(!o.trackID)return;const{sprite:l}=this.generateLabel(o.trackID.toString(),50,n);return l.position.set(-o.width/2,0,o.depth/2+.5),l},this.generateBoxAttributeLabel=(o,n)=>{if(!o.attribute||this.hiddenText)return;const l=this.findSubAttributeLabel(o,this.config),p=l?`${o.attribute}
32
- ${l}`:`${o.attribute}`,{sprite:g,canvasHeight:f}=this.generateLabel(p,100,n);return g.position.set(-o.width/2,0,-o.depth/2-f/150),g},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:n})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const p=l.material.uniforms.pointSize.value;o?l.material.uniforms.pointSize.value=Math.min(p*1.2,10):l.material.uniforms.pointSize.value=Math.max(p/1.2,1),n&&(l.material.uniforms.pointSize.value=n,this.pointsMaterialSize=n),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new h.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=c,this.checkMode=d!=null?d:!1,this.hiddenText=u,i&&r?(this.isOrthographicCamera=!0,this.camera=new h.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new h.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new h.Scene,this.controls=new X(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new K,this.axesHelper=new h.AxesHelper(1e3),this.filterBoxWorker=new _,this.geometry=new h.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=q.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",o=>{var n,l,p;const g=this.renderer.domElement.getBoundingClientRect(),f=o.originalEvent.clientX-g.left,y=o.originalEvent.clientY-g.top;this.pointer.x=f/g.width*2-1,this.pointer.y=-(y/g.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const m=[];this.scene.children.forEach(w=>{w instanceof h.Group&&w.children.forEach(b=>{b instanceof h.Mesh?m.push(b):this.updateMaterialColor(b,w.userData.defaultColor)})});const x=this.raycaster.intersectObjects(m,!1);if(x.length>0){const w=x[0].object.parent;w==null||w.children.forEach(b=>{this.updateMaterialColor(b,this.highlightColor)}),(n=this.pipe)==null||n.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(w==null?void 0:w.userData.selectedID)}else(p=this.pipe)==null||p.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof h.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 h.BoxHelper||t instanceof h.Sprite)&&t.material.color.set(e)}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new et(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 tt(v({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new it(S(v({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 v({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 h.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:a,near:c,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=c,this.camera.far=s,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 h.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 h.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return A.getColorFromConfig({attribute:t},S(v({},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,a=10,c=e.x-i/2-a,s=e.x-i/2+a,d=e.y+r/2+a,u=e.y-r/2-a,o=100,n=-100,l=500/o;return{left:c,right:s,top:d,bottom:u,near:o,far:n,zoom:l}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:c,depth:s,rotation:d}=t,u=this.getCameraVector(r,d,{width:a,height:c,depth:s},e);return i?(this.updateCamera(i,r),new h.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=k,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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 h.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 h.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new h.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,a,c;if(!e){const s=this.scene.getObjectByName(this.pointCloudObjectName);if(!s)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array}if(window.Worker){const{zMin:s,zMax:d,polygonPointList:u}=T(t),o=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:d,polygonPointList:u,color:i,position:o};return this.filterBoxWorker||(this.filterBoxWorker=new _),new Promise(l=>{var p;(p=this.filterBoxWorker)==null||p.postMessage(n),this.filterBoxWorker.onmessage=g=>{const{color:f,position:y,num:m}=g.data;this.geometry.dispose(),this.geometry.setAttribute("position",new h.Float32BufferAttribute(y,3)),this.geometry.setAttribute("color",new h.Float32BufferAttribute(f,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorkerTimer&&clearTimeout(this.filterBoxWorkerTimer),this.filterBoxWorkerTimer=setTimeout(()=>{this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null)},3e3),l({geometry:this.geometry,num:m})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=M.Front,a=ct){let c=z.frontViewMatrix4(a);switch(r){case M.Front:break;case M.Back:c=z.backViewMatrix4(a);break;case M.Left:c=z.leftViewMatrix4(a);break;case M.Right:c=z.rightViewMatrix4(a);break;case M.Top:c=z.topViewMatrix4(a);break;case M.LFT:c=z.leftFrontTopViewMatrix4(a,i);break;case M.RBT:c=z.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),d=new h.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new h.Matrix4().makeTranslation(t.x,t.y,t.z),o=new h.Matrix4().makeRotationZ(e);return new h.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(d).applyMatrix4(o).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new h.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new h.BufferGeometry().setFromPoints(i),a=new h.LineBasicMaterial({color:16711680}),c=new h.Line(r,a);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new h.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],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return B(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,D.postMessage(t),D.onmessage=r=>{e(r.data),this.workerLoading=!1},D.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return B(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:c}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((d,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(y=>T(y)),l=this.getAllAttributeColor(n),p=s.geometry.attributes.position.array,g=s.geometry.attributes.dimensions.array,f={cuboidList:n,position:p,color:g,colorList:l,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(f).then(y=>{const{color:m}=y;let x=m;(a.length||c.length)&&(x=m.map((b,P)=>b===-1?g[P]:b));const w=new h.BufferAttribute(x,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==m.length){u(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,x),this.highlightPCDSrc=void 0,w.needsUpdate=!0,s.geometry.setAttribute("dimensions",w),s.geometry.attributes.dimensions.needsUpdate=!0,d(x),this.render()}).catch(y=>{u(y)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new h.Group;t.forEach(i=>{const{center:{x:r,y:a,z:c},width:s,height:d,depth:u,rotation:o}=i,{fill:n}=A.getColorFromConfig({attribute:i.attribute},S(v({},this.config),{attributeConfigurable:!0}),{}),l=new h.BoxGeometry(s,d,u),p=new h.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});l.rotateZ(o),l.translate(r,a,c);const g=new h.Mesh(l,p);e.add(g);const f=new h.PlaneGeometry(u,d);f.rotateY(Math.PI/2),f.rotateZ(o);const y=new h.Vector3(s/2,0,0),m=new h.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(o);y.applyMatrix4(m),f.translate(r+y.x,a+y.y,c+y.z);const x=new h.MeshBasicMaterial({color:n,side:h.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new h.Mesh(f,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new h.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const a=Object.keys(t.subAttribute);return a.length===0||a.forEach(c=>{const s=i.find(o=>o.value===c);if(!s||!s.subSelected)return;const{key:d,subSelected:u}=s;u.forEach(o=>{var n;const l=(n=t.subAttribute)==null?void 0:n[c];(l==null?void 0:l.includes(o.value))&&(r&&(r+="\u3001"),r+=`${d}:${o.key}`)})}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const c=t.split(`
33
- `),s=Math.max(...c.map(n=>i.measureText(n).width)),d=Math.ceil(s),u=a*1.5,o=u*c.length;e.width=d*r,e.height=o*r,e.style.width=`${d}px`,e.style.height=`${o}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.forEach((n,l)=>{i.fillText(n,0,l*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,l)=>n.z-l.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((n,l)=>n.x-l.x);const s=Math.floor(e.length*a),d=Math.floor(e.length*(1-a));e=e.slice(s,d),e.sort((n,l)=>n.y-l.y);const u=Math.floor(e.length*a),o=Math.floor(e.length*(1-a));return e=e.slice(u,o),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:u})=>{t.forEach((o,n)=>{const l=r[n+1],p=E.getFootOfPerpendicular({x:d,y:u},o,l,!1,!0).length;(!i[n]||p<i[n].distance)&&(i[n]={distance:p,point:{x:d,y:u}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],c=t.map((d,u)=>{const o=r[u],n=r[u+1],l=r[u+2];return Z.getIntersectionBySlope({p1:a[u].point,line1:[o,n],p2:a[u+1].point,line2:[n,l]})});return c.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,a,c;const s=this.scene.children.find(f=>f.uuid===this.pointsUuid);let d=0,u=0,o=0,n=0,l=[],p=[];const g=((c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array)||[];for(let f=0;f<g.length;f+=3){const y=g[f],m=g[f+1],x=g[f+2];$({x:y,y:m},t)&&(x||x===0)&&p.push({x:y,y:m,z:x})}return p.length?(i&&(p=this.filterNoise(p),l=this.getFittedCoordinates(t,p)),p.sort((f,y)=>f.z-y.z),d=p[0].z-.01,u=p[p.length-1].z+.01,n=p.length,e&&(o=p.filter(({z:f})=>f>=e[0]&&f<=e[1]).length),{maxZ:u,minZ:d,count:o,zCount:n,fittedCoordinates:l}):{maxZ:u,minZ:d,count:o,zCount:n,fittedCoordinates:l}}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 h.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 h.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r-s/2},u={x:e+c/2,y:i+a/2,z:r+s/2},o={x:e-c/2,y:i+a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r-s/2};return[d,u,o,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e-c/2,y:i+a/2,z:r+s/2},u={x:e-c/2,y:i+a/2,z:r-s/2},o={x:e-c/2,y:i-a/2,z:r-s/2},n={x:e-c/2,y:i-a/2,z:r+s/2};return[d,u,o,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r+s/2},u={x:e+c/2,y:i-a/2,z:r+s/2},o={x:e-c/2,y:i-a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r+s/2};return[d,u,o,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new h.Matrix4().makeTranslation(-e,-i,-r),s=new h.Matrix4().makeTranslation(e,i,r),d=new h.Matrix4().makeRotationZ(a);return new h.Matrix4().multiply(s).multiply(d).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case M.Left:return this.getPolygonSidePoints(t);case M.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:a}=t,c=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new h.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const d=i.map(n=>new h.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,o=this.containerHeight/a;return{polygon2d:d,zoom:Math.min(u,o)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:c}=k,s={center:e,attribute:i,id:r,valid:a,width:c*2,height:c*2,depth:c*2,rotation:0},d=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new h.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const o=new h.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(c*2),l=this.containerHeight/(c*2);return{point2d:o,zoom:Math.min(n,l)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=k,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},a=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(d=>new h.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),c=this.containerWidth/e,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(c,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new h.Matrix4().makeRotationZ(r.rotation),c=new h.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=S(v({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const a=new h.Matrix4().makeRotationZ(r.rotation),c=new h.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=S(v({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const c=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(y=>new h.Vector3(y.x,y.y,y.z)).map(y=>y.applyMatrix4(c)),[d,u,o,n]=s,l=Math.max(Math.abs(d.x-o.x),Math.abs(d.x-u.x)),g=u.add(n).applyMatrix3(new h.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new h.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new h.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(v({},r),{center:{x:r.center.x-g.x,y:r.center.y-g.y,z:r.center.z-i},width:l,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,a=[],{count:c}=r;for(let s=0;s<c;s++){const d=r.getZ(s);a.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new h.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{lt as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>O(this,[...n],function*(h=this.currentPCDSrc,d,p){if(!h||this.workerLoading)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:m,color:y}=yield this.cacheInstance.loadPCDFile(h),b=new o.BufferGeometry;b.setAttribute("position",new o.BufferAttribute(m,3)),this.isSegment||b.setAttribute("dimensions",new o.BufferAttribute(y,3)),this.initCloudData(m);const f=new o.Points(b);this.renderPointCloud(f,d,p),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>O(this,[n],function*({mappingImgList:h,points:d}){const p=f=>O(this,null,function*(){try{return yield Y.load(f)}catch(x){return console.error("Error loading image:",x),null}}),m=h.length===0?[]:(yield Promise.all(h.map(f=>O(this,null,function*(){let x=yield p(f.url);return!x&&f.fallbackUrl&&(x=yield p(f.fallbackUrl)),x})))).filter(f=>f!==null),y=h.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:m[x].width,height:m[x].height});return this.cacheInstance.cache2DHighlightIndex.set(f.url,C),C});return tt(y)}),this.filterPreResult=(n,h,d)=>O(this,null,function*(){const{points:p}=yield this.cacheInstance.loadPCDFile(n),m=yield this.cacheInstance.loadIndexMap(n,p);return new Promise(y=>{const b=d.map(f=>{const x=E.calculatePointsInsideBox({indexMap:m,polygon:D(f).polygonPointList,zScope:[f.center.z-f.depth/2,f.center.z+f.depth/2],box:f}),w=x>=h.lowerLimitPointsNumInBox;return L(P({},f),{valid:w,count:x})});y(b)})}),this.loadPCDFileByBox=(n,h,d)=>O(this,null,function*(){const p=(b,f)=>O(this,null,function*(){const{width:x=0,height:w=0,depth:C=0}=d!=null?d:{},S=yield this.filterPointsByBox(L(P({},h),{width:h.width+x,height:h.height+w,depth:h.depth+C}),b,f);if(!S){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const z=new o.Points(S.geometry);z.name=this.pointCloudObjectName,this.scene.add(z),this.render()}),{points:m,color:y}=yield this.cacheInstance.loadPCDFile(n);p(m,y)}),this.generateRange=n=>{const h=this.createRange(n);this.scene.add(h)},this.generateTipScopeList=n=>{this.cacheTipScopeList.forEach((h,d)=>{this.removeObjectByName(this.tipScopeObjectName+d)}),n.forEach((h,d)=>{const p=this.createTipScope(h,d);p&&this.scene.add(p)}),this.cacheTipScopeList=n},this.generateBoxArrow=({width:n})=>{const h=new o.Vector3(1,0,0),d=new o.Vector3(n/2,0,0),p=2,m=new o.ArrowHelper(h,d,p,this.highlightColor);return m.visible=this.showDirection,m},this.generateLabel=(n,h,d)=>{const p=this.getTextCanvas(n),m=new o.Texture(p);m.minFilter=o.LinearFilter,m.magFilter=o.LinearFilter,m.needsUpdate=!0;const y=p.width/window.devicePixelRatio,b=p.height/window.devicePixelRatio,f=new o.SpriteMaterial({map:m,depthWrite:!1,color:d}),x=new o.Sprite(f);return x.scale.set(y/h,b/h,1),{sprite:x,canvasWidth:y,canvasHeight:b}},this.generateBoxTrackID=(n,h)=>{if(!n.trackID)return;const{sprite:d}=this.generateLabel(n.trackID.toString(),50,h);return d.position.set(-n.width/2,0,n.depth/2+.5),d},this.generateBoxAttributeLabel=(n,h)=>{if(!n.attribute||this.hiddenText)return;const d=this.findSubAttributeLabel(n,this.config),p=d?`${n.attribute}
32
+ ${d}`:`${n.attribute}`,{sprite:m,canvasHeight:y}=this.generateLabel(p,100,h);return m.position.set(-n.width/2,0,-n.depth/2-y/150),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:h})=>{const d=this.scene.getObjectByName(this.pointCloudObjectName);if(!d)return;const p=d.material.uniforms.pointSize.value;n?d.material.uniforms.pointSize.value=Math.min(p*1.2,10):d.material.uniforms.pointSize.value=Math.max(p/1.2,1),h&&(d.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),d.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new o.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=c,this.checkMode=l!=null?l:!1,this.hiddenText=u,this.view=g,i&&r?(this.isOrthographicCamera=!0,this.camera=new o.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new o.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new o.Scene,this.controls=new q(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new X,this.axesHelper=new o.AxesHelper(1e3),this.filterBoxWorker=new N,this.geometry=new o.BufferGeometry,this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Q.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",n=>{var h,d,p;const m=this.renderer.domElement.getBoundingClientRect(),y=n.originalEvent.clientX-m.left,b=n.originalEvent.clientY-m.top;this.pointer.x=y/m.width*2-1,this.pointer.y=-(b/m.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(w=>{w instanceof o.Group&&w.children.forEach(C=>{C instanceof o.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)}),(h=this.pipe)==null||h.setNeedUpdateCenter(!1),(d=this.pipe)==null||d.setSelectedIDs(w==null?void 0:w.userData.selectedID)}else(p=this.pipe)==null||p.setSelectedIDs(void 0);this.render()})}setHighlightColor(t){this.scene.children.forEach(e=>{if(!(e instanceof o.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 o.BoxHelper||t instanceof o.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(L(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 o.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:a,near:c,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=c,this.camera.far=s,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 o.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 o.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},L(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,a=10,c=e.x-i/2-a,s=e.x-i/2+a,l=e.y+r/2+a,u=e.y-r/2-a,g=100,n=-100,h=500/g;return{left:c,right:s,top:l,bottom:u,near:g,far:n,zoom:h}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:c,depth:s,rotation:l}=t,u=this.getCameraVector(r,l,{width:a,height:c,depth:s},e);return i?(this.updateCamera(i,r),new o.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=k,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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 o.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 o.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new o.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,a,c;if(!e){const s=this.scene.getObjectByName(this.pointCloudObjectName);if(!s)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array}if(window.Worker){const{zMin:s,zMax:l,polygonPointList:u}=D(t),g=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:l,polygonPointList:u,color:i,position:g};return this.filterBoxWorker||(this.filterBoxWorker=new N),new Promise(h=>{var d;(d=this.filterBoxWorker)==null||d.postMessage(n),this.filterBoxWorker.onmessage=p=>{const{color:m,position:y,num:b}=p.data;this.geometry.dispose(),this.geometry.setAttribute("position",new o.Float32BufferAttribute(y,3)),this.geometry.setAttribute("color",new o.Float32BufferAttribute(m,3)),this.geometry.computeBoundingSphere(),this.filterBoxWorker&&(this.filterBoxWorker.terminate(),this.filterBoxWorker=null),h({geometry:this.geometry,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=M.Front,a=lt){let c=T.frontViewMatrix4(a);switch(r){case M.Front:break;case M.Back:c=T.backViewMatrix4(a);break;case M.Left:c=T.leftViewMatrix4(a);break;case M.Right:c=T.rightViewMatrix4(a);break;case M.Top:c=T.topViewMatrix4(a);break;case M.LFT:c=T.leftFrontTopViewMatrix4(a,i);break;case M.RBT:c=T.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),l=new o.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new o.Matrix4().makeTranslation(t.x,t.y,t.z),g=new o.Matrix4().makeRotationZ(e);return new o.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(g).applyMatrix4(u)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new o.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new o.BufferGeometry().setFromPoints(i),a=new o.LineBasicMaterial({color:16711680}),c=new o.Line(r,a);return c.name=this.rangeObjectName,c}createTipScope(t,e){this.removeObjectByName(this.tipScopeObjectName+e);let i=null;const{scopeType:r,range:a}=t;if(r==="circle"){const s=new o.EllipseCurve(0,0,Number(a.radius),Number(a.radius),0,2*Math.PI,!1,0).getPoints(50),l=new o.BufferGeometry().setFromPoints(s),u=new o.LineBasicMaterial({color:16711680});i=new o.Line(l,u)}else if(r==="rect"){const{top:c=0,bottom:s=0,left:l=0,right:u=0}=a,g=l,n=-u,h=c,d=-s,p=new o.Shape;p.moveTo(h,g),p.lineTo(d,g),p.lineTo(d,n),p.lineTo(h,n),p.lineTo(h,g);const m=new o.BufferGeometry().setFromPoints(p.getPoints()),y=new o.LineBasicMaterial({color:16711680});i=new o.Line(m,y)}return i?(i.name=this.tipScopeObjectName+e,i):null}renderPointCloud(t,e,i){if(this.clearPointCloud(),this.workerLoading)return;t.name=this.pointCloudObjectName;const r=new o.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),i&&this.generateTipScopeList(i),this.pointsUuid=t.uuid,t.material=r,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],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return O(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 O(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){if(this.workerLoading)return;this.workerLoading=!0;const{modifiedBoxIds:a,resetAreas:c}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(y=>D(y)),h=this.getAllAttributeColor(n),d=s.geometry.attributes.position.array,p=s.geometry.attributes.dimensions.array,m={cuboidList:n,position:d,color:p,colorList:h,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(m).then(y=>{const{color:b}=y;if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==b.length){u(new Error("Error Path"));return}let f=b;(a.length||c.length)&&(f=b.map((C,S)=>C===-1?p[S]:C));const x=new o.BufferAttribute(f,3);this.highlightPCDSrc=void 0,x.needsUpdate=!0,s.geometry.setAttribute("dimensions",x),s.geometry.attributes.dimensions.needsUpdate=!0;const w={color:f,view:this.view,currentPCDSrc:this.currentPCDSrc};l(w),this.workerLoading=!1,this.render()}).catch(y=>{this.workerLoading=!1,u(y)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new o.Group;t.forEach(i=>{const{center:{x:r,y:a,z:c},width:s,height:l,depth:u,rotation:g}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},L(P({},this.config),{attributeConfigurable:!0}),{}),h=new o.BoxGeometry(s,l,u),d=new o.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});h.rotateZ(g),h.translate(r,a,c);const p=new o.Mesh(h,d);e.add(p);const m=new o.PlaneGeometry(u,l);m.rotateY(Math.PI/2),m.rotateZ(g);const y=new o.Vector3(s/2,0,0),b=new o.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(g);y.applyMatrix4(b),m.translate(r+y.x,a+y.y,c+y.z);const f=new o.MeshBasicMaterial({color:n,side:o.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),x=new o.Mesh(m,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 o.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 a=Object.keys(t.subAttribute);return a.length===0||a.forEach(c=>{const s=i.find(n=>n.value===c);if(!s||!s.subSelected)return;const{key:l,subSelected:u}=s,g=[];u.forEach(n=>{var h;const d=(h=t.subAttribute)==null?void 0:h[c],p=Array.isArray(d)?d:d==null?void 0:d.split(";");(p==null?void 0:p.includes(n.value))&&g.push(n.key)}),g.length>0&&(r&&(r+="\u3001"),r+=`${l}:${g.join("\u3001")}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const c=t.split(`
33
+ `),s=Math.max(...c.map(n=>i.measureText(n).width)),l=Math.ceil(s),u=a*1.5,g=u*c.length;e.width=l*r,e.height=g*r,e.style.width=`${l}px`,e.style.height=`${g}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.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 a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((n,h)=>n.x-h.x);const s=Math.floor(e.length*a),l=Math.floor(e.length*(1-a));e=e.slice(s,l),e.sort((n,h)=>n.y-h.y);const u=Math.floor(e.length*a),g=Math.floor(e.length*(1-a));return e=e.slice(u,g),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:u})=>{t.forEach((g,n)=>{const h=r[n+1],d=E.getFootOfPerpendicular({x:l,y:u},g,h,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:u}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],c=t.map((l,u)=>{const g=r[u],n=r[u+1],h=r[u+2];return Z.getIntersectionBySlope({p1:a[u].point,line1:[g,n],p2:a[u+1].point,line2:[n,h]})});return c.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,a,c;const s=this.scene.children.find(m=>m.uuid===this.pointsUuid);let l=0,u=0,g=0,n=0,h=[],d=[];const p=((c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array)||[];for(let m=0;m<p.length;m+=3){const y=p[m],b=p[m+1],f=p[m+2];K({x:y,y:b},t)&&(f||f===0)&&d.push({x:y,y:b,z:f})}return d.length?(i&&(d=this.filterNoise(d),h=this.getFittedCoordinates(t,d)),d.sort((m,y)=>m.z-y.z),l=d[0].z-.01,u=d[d.length-1].z+.01,n=d.length,e&&(g=d.filter(({z:m})=>m>=e[0]&&m<=e[1]).length),{maxZ:u,minZ:l,count:g,zCount:n,fittedCoordinates:h}):{maxZ:u,minZ:l,count:g,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 o.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 o.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,l={x:e+c/2,y:i+a/2,z:r-s/2},u={x:e+c/2,y:i+a/2,z:r+s/2},g={x:e-c/2,y:i+a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r-s/2};return[l,u,g,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,l={x:e-c/2,y:i+a/2,z:r+s/2},u={x:e-c/2,y:i+a/2,z:r-s/2},g={x:e-c/2,y:i-a/2,z:r-s/2},n={x:e-c/2,y:i-a/2,z:r+s/2};return[l,u,g,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,l={x:e+c/2,y:i+a/2,z:r+s/2},u={x:e+c/2,y:i-a/2,z:r+s/2},g={x:e-c/2,y:i-a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r+s/2};return[l,u,g,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new o.Matrix4().makeTranslation(-e,-i,-r),s=new o.Matrix4().makeTranslation(e,i,r),l=new o.Matrix4().makeRotationZ(a);return new o.Matrix4().multiply(s).multiply(l).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case M.Left:return this.getPolygonSidePoints(t);case M.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:a}=t,c=new o.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new o.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const l=i.map(n=>new o.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,g=this.containerHeight/a;return{polygon2d:l,zoom:Math.min(u,g)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:c}=k,s={center:e,attribute:i,id:r,valid:a,width:c*2,height:c*2,depth:c*2,rotation:0},l=new o.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new o.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const g=new o.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(c*2),h=this.containerHeight/(c*2);return{point2d:g,zoom:Math.min(n,h)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=k,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},a=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(l=>new o.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)})),c=this.containerWidth/e,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(c,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new o.Matrix4().makeRotationZ(r.rotation),c=new o.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=L(P({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const a=new o.Matrix4().makeRotationZ(r.rotation),c=new o.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=L(P({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const c=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(y=>new o.Vector3(y.x,y.y,y.z)).map(y=>y.applyMatrix4(c)),[l,u,g,n]=s,h=Math.max(Math.abs(l.x-g.x),Math.abs(l.x-u.x)),p=u.add(n).applyMatrix3(new o.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new o.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new o.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:L(P({},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,a=[],{count:c}=r;for(let s=0;s<c;s++){const l=r.getZ(s);a.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new o.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{dt as PointCloud};
@@ -1 +1 @@
1
- import*as p from"three";import{MatrixUtils as M,ECameraType as V,PointCloudUtils as G}from"@labelbee/lb-utils";import J from"../../utils/uuid.js";import{transformPointCloudToImage as Q}from"./omniCamera.js";var W=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,C=Math.pow,D=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,E=(r,t)=>{for(var e in t||(t={}))$.call(t,e)&&D(r,e,t[e]);if(R)for(var e of R(t))S.call(t,e)&&D(r,e,t[e]);return r},A=(r,t)=>X(r,Y(t));function g(r){return new p.Matrix4().set(...r)}function v(r,t,e){try{const n=M.transferMatrix34FromKitti2Three(r),s=M.transferMatrix33FromKitti2Three(t),o=M.transferMatrix34FromKitti2Three(e),c=g(n),f=g(s),a=g(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(c),PM:c,RM:f,TM:a}}catch(n){console.error(n)}}function F(r,t,e){var n;const s=new p.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new p.Matrix4().makeRotationZ(e),c=new p.Matrix4().makeTranslation(t.x,t.y,t.z),f=new p.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return s.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(c)}function H(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const O=(r,t)=>t.some(e=>H(r,e[0],e[1])),d=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&O(r.P,[[3,4],[4,4]])&&O(r.T,[[3,4],[4,4]]))},j=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=new p.Vector4(r.x,r.y,r.z),c=g(M.transferMatrix34FromKitti2Three(s)),f=g(M.transferMatrix34FromKitti2Three(e)),a=o.applyMatrix4(c),y=C(C(a.x,2)+C(a.y,2),.5),h=Math.atan(a.z/y),i=n.reduce((l,u,m)=>l+u*C(h,m),0);return a.x=a.x/y*i,a.y=a.y/y*i,a.z=1,a.applyMatrix4(f)},K=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=Q([[r.x,r.y,r.z]],s,e,n);return new p.Vector4(o[0][0],o[0][1],1)},b=(r,t)=>{const{P:e,T:n,fisheyeDistortion:s}=t,o=[r.x,r.y,r.z,1],c=n.map(z=>z.reduce((I,L,Z)=>I+L*o[Z],0)),f=c[0],a=c[1],y=c[2];if(!(y>=.01&&isFinite(y)))return;const h=[[e[0][0],e[0][1]],[e[1][0],e[1][1]]],i=e[0][2],x=e[1][2],l=Math.sqrt(f*f+a*a),u=Math.atan2(l,y),m=u+s.reduce((z,I,L)=>z+I*Math.pow(u,2*L+3),0);let P,_;l!==0?(P=f*m/l,_=a*m/l):(P=0,_=0);const q=h[0][0]*P+h[0][1]*_,N=h[1][0]*P+h[1][1]*_;return{x:q+i,y:N+x}},T=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===V.OmniCamera)return j(r,t);if((t==null?void 0:t.cameraType)===V.KannalaBrandt)return b(r,t);if((t==null?void 0:t.cameraType)===V.OmniCamera11V)return K(r,t)};function w(r,t){const n=new p.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const s=1/n.z,o=new p.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return n.applyMatrix4(o)}function tt(r){const{center:t,width:e,height:n,depth:s,rotation:o}=r,c=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(y=>{const h=F(y,t,o);return{x:h.x,y:h.y}}),f=t.z+s/2,a=t.z-s/2;return A(E({},r),{polygonPointList:c,zMax:f,zMin:a})}function rt(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function k(r,t,e){const n=t.x-r.x,s=t.y-r.y,o=e.x-r.x,c=e.y-r.y;return n*c-o*s}function et(r){const t=rt(r),e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&k(e[e.length-2],e[e.length-1],t[o])<=0;)e.pop();e.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&k(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return e.pop(),n.pop(),e.concat(n)}const B=(r,t)=>{var e;if(d(t))return T(r,t);const{P:n,R:s,T:o}=t,{composeMatrix4:c}=(e=v(n,s,o))!=null?e:{};if(!!c)return w(r,c)},U=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const s=B(r,t);return s?s.x>=0&&s.x<=e&&s.y>=0&&s.y<=n:!1},nt=({points:r,calib:t,width:e,height:n})=>{const s=[];for(let o=0;o<r.length;o+=3){const c=r[o],f=r[o+1],a=r[o+2];U({point:{x:c,y:f,z:a},calib:t,width:e,height:n})?s.push(1):s.push(0)}return s},ot=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function st(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:s}=e,o=G.getAllViewData(r),c=d(t),{P:f,R:a,T:y}=t;let h;if(c===!1){const{composeMatrix4:l}=(n=v(f,a,y))!=null?n:{};if(!l)return;h=l}const i=o.map(l=>({type:l.type,pointList:l.pointList.map(u=>F(u,r.center,r.rotation)).map(u=>c?T(u,t):h&&w(u,h)).map(u=>{if(!!u)return{id:J(),x:u==null?void 0:u.x,y:u==null?void 0:u.y}}).filter(u=>u!==void 0)})).filter(l=>l.pointList.length!==0);i[0]&&i[0].pointList&&(i[0].pointList=i[0].pointList.map(l=>A(E({},l),{specialEdge:!0})));let x=[];if(i.length===6&&s===!0){const l=i[0].pointList,u=i[1].pointList;x=et([...l,...u])}return{transferViewData:i,viewRangePointList:x}}function it(r,t,e){var n;const s=d(t),{P:o,R:c,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=v(o,c,f))!=null?n:{};if(!i)return;a=i}const y=r.length/3,h={};for(let i=0;i<y;i++){const x={x:r[i*3],y:r[i*3+1],z:r[i*3+2]};let l;if(s?l=T(x,t):l=a&&w({x:r[i*3],y:r[i*3+1],z:r[i*3+2]},a),l){const u=Math.floor(l.x),m=Math.floor(l.y);if(u>e.width||m>e.height||u<0||m<0)continue;h[i]={x:u,y:m}}}return{pcdMapping:h}}function at(r,t,e){var n;if(!t||!e)return;const s=d(t),{P:o,R:c,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=v(o,c,f))!=null?n:{};if(!i)return;a=i}const y=[];if(r.forEach(i=>{let x;if(s?x=T(i,t):x=a&&w(i,a),x){const{x:l,y:u}=x;y.push({x:l,y:u})}}),y.some(i=>i.x>0&&i.x<e.width&&i.y>0&&i.y<e.height))return y}export{g as createThreeMatrix4,tt as getCuboidFromPointCloudBox,nt as getHighlightIndexByPoints,d as isFisheyeCalibValid,U as isInImage,H as isMatrixValid,O as isMatrixValidByArr,T as lidar2FisheyeImage,w as lidar2image,ot as mergeHighlightList,j as oCamFisheyeTransfer,K as omniCamera11VTransfer,B as point3DLidar2Image,st as pointCloudLidar2image,at as pointListLidar2Img,it as pointMappingLidar2image,F as rotatePoint,v as transferKitti2Matrix};
1
+ import*as p from"three";import{MatrixUtils as P,ECameraType as F,PointCloudUtils as Z}from"@labelbee/lb-utils";import G from"../../utils/uuid.js";import{transformPointCloudToImage as J}from"./omniCamera.js";var Q=Object.defineProperty,S=Object.defineProperties,W=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,X=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,L=Math.pow,A=(r,t,e)=>t in r?Q(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,H=(r,t)=>{for(var e in t||(t={}))X.call(t,e)&&A(r,e,t[e]);if(D)for(var e of D(t))Y.call(t,e)&&A(r,e,t[e]);return r},j=(r,t)=>S(r,W(t));function v(r){return new p.Matrix4().set(...r)}function T(r,t,e){try{const n=P.transferMatrix34FromKitti2Three(r),s=P.transferMatrix33FromKitti2Three(t),o=P.transferMatrix34FromKitti2Three(e),l=v(n),f=v(s),a=v(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function R(r,t,e){var n;const s=new p.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new p.Matrix4().makeRotationZ(e),l=new p.Matrix4().makeTranslation(t.x,t.y,t.z),f=new p.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return s.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(l)}function K(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const O=(r,t)=>t.some(e=>K(r,e[0],e[1])),d=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&O(r.P,[[3,4],[4,4]])&&O(r.T,[[3,4],[4,4]]))},k=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=new p.Vector4(r.x,r.y,r.z),l=v(P.transferMatrix34FromKitti2Three(s)),f=v(P.transferMatrix34FromKitti2Three(e)),a=o.applyMatrix4(l),h=L(L(a.x,2)+L(a.y,2),.5),x=Math.atan(a.z/h),i=n.reduce((c,u,m)=>c+u*L(x,m),0);return a.x=a.x/h*i,a.y=a.y/h*i,a.z=1,a.applyMatrix4(f)},B=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=J([[r.x,r.y,r.z]],s,e,n);return new p.Vector4(o[0][0],o[0][1],1)},b=(r,t)=>{const{P:e,T:n,fisheyeDistortion:s}=t,o=[r.x,r.y,r.z,1],l=n.map(I=>I.reduce((V,E,q)=>V+E*o[q],0)),f=l[0],a=l[1],h=l[2];if(!(h>=.01&&isFinite(h)))return;const x=[[e[0][0],e[0][1]],[e[1][0],e[1][1]]],i=e[0][2],y=e[1][2],c=Math.sqrt(f*f+a*a),u=Math.atan2(c,h),m=u+s.reduce((I,V,E)=>I+V*Math.pow(u,2*E+3),0);let g,w;c!==0?(g=f*m/c,w=a*m/c):(g=0,w=0);const z=x[0][0]*g+x[0][1]*w,M=x[1][0]*g+x[1][1]*w;return{x:z+i,y:M+y}},_=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===F.OmniCamera)return k(r,t);if((t==null?void 0:t.cameraType)===F.KannalaBrandt)return b(r,t);if((t==null?void 0:t.cameraType)===F.OmniCamera11V)return B(r,t)};function C(r,t){const n=new p.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const s=1/n.z,o=new p.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return n.applyMatrix4(o)}function tt(r){const{center:t,width:e,height:n,depth:s,rotation:o}=r,l=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(h=>{const x=R(h,t,o);return{x:x.x,y:x.y}}),f=t.z+s/2,a=t.z-s/2;return j(H({},r),{polygonPointList:l,zMax:f,zMin:a})}function rt(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function N(r,t,e){const n=t.x-r.x,s=t.y-r.y,o=e.x-r.x,l=e.y-r.y;return n*l-o*s}function et(r){const t=rt(r),e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&N(e[e.length-2],e[e.length-1],t[o])<=0;)e.pop();e.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&N(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return e.pop(),n.pop(),e.concat(n)}const U=(r,t)=>{var e;if(d(t))return _(r,t);const{P:n,R:s,T:o}=t,{composeMatrix4:l}=(e=T(n,s,o))!=null?e:{};if(!!l)return C(r,l)},$=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const s=U(r,t);return s?s.x>=0&&s.x<=e&&s.y>=0&&s.y<=n:!1},nt=({points:r,calib:t,width:e,height:n})=>{const s=[];for(let o=0;o<r.length;o+=3){const l=r[o],f=r[o+1],a=r[o+2];$({point:{x:l,y:f,z:a},calib:t,width:e,height:n})?s.push(1):s.push(0)}return s},ot=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function st(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:s}=e,o=Z.getAllViewData(r),l=d(t),{P:f,R:a,T:h}=t;let x;if(l===!1){const c=f.map(M=>[...M]);if(c.length!==3)throw new Error(`Invalid P matrix: Expected 3 rows, got ${c.length}`);if(new Set(c.map(M=>M.length)).size!==1)throw new Error("Invalid P matrix: Inconsistent column counts between rows");const m=c[0].length;if(m!==3&&m!==4)throw new Error(`Invalid P matrix: Expected 3 or 4 columns, got ${m}`);let g=c;m===3&&(g=c.map(M=>[...M.map(Number),0]));const w=g,{composeMatrix4:z}=(n=T(w,a,h))!=null?n:{};if(!z)return;x=z}const i=o.map(c=>({type:c.type,pointList:c.pointList.map(u=>R(u,r.center,r.rotation)).map(u=>l?_(u,t):x&&C(u,x)).map(u=>{if(!!u)return{id:G(),x:u==null?void 0:u.x,y:u==null?void 0:u.y}}).filter(u=>u!==void 0)})).filter(c=>c.pointList.length!==0);i[0]&&i[0].pointList&&(i[0].pointList=i[0].pointList.map(c=>j(H({},c),{specialEdge:!0})));let y=[];if(i.length===6&&s===!0){const c=i[0].pointList,u=i[1].pointList;y=et([...c,...u])}return{transferViewData:i,viewRangePointList:y}}function it(r,t,e){var n;const s=d(t),{P:o,R:l,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=T(o,l,f))!=null?n:{};if(!i)return;a=i}const h=r.length/3,x={};for(let i=0;i<h;i++){const y={x:r[i*3],y:r[i*3+1],z:r[i*3+2]};let c;if(s?c=_(y,t):c=a&&C({x:r[i*3],y:r[i*3+1],z:r[i*3+2]},a),c){const u=Math.floor(c.x),m=Math.floor(c.y);if(u>e.width||m>e.height||u<0||m<0)continue;x[i]={x:u,y:m}}}return{pcdMapping:x}}function at(r,t,e){var n;if(!t||!e)return;const s=d(t),{P:o,R:l,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=T(o,l,f))!=null?n:{};if(!i)return;a=i}const h=[];if(r.forEach(i=>{let y;if(s?y=_(i,t):y=a&&C(i,a),y){const{x:c,y:u}=y;h.push({x:c,y:u})}}),h.some(i=>i.x>0&&i.x<e.width&&i.y>0&&i.y<e.height))return h}export{v as createThreeMatrix4,tt as getCuboidFromPointCloudBox,nt as getHighlightIndexByPoints,d as isFisheyeCalibValid,$ as isInImage,K as isMatrixValid,O as isMatrixValidByArr,_ as lidar2FisheyeImage,C as lidar2image,ot as mergeHighlightList,k as oCamFisheyeTransfer,B as omniCamera11VTransfer,U as point3DLidar2Image,st as pointCloudLidar2image,at as pointListLidar2Img,it as pointMappingLidar2image,R as rotatePoint,T as transferKitti2Matrix};
@@ -1 +1 @@
1
- import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as D}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as w}from"./toolOperation/basicToolOperation.js";var x=Object.defineProperty,I=Object.defineProperties,M=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,f=(i,t,o)=>t in i?x(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,E=(i,t)=>{for(var o in t||(t={}))_.call(t,o)&&f(i,o,t[o]);if(g)for(var o of g(t))b.call(t,o)&&f(i,o,t[o]);return i},N=(i,t)=>I(i,M(t));const T=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},d=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},v=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let m=v;m.getTopToolName=i=>v.isHybridTool(i)?i[i.length-1]:i;class S{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(m.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:y,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=N(E({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){t.width&&t.height&&this.toolOperationDom.forEach(o=>{o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}),this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,s){this.toolOperationList.forEach(a=>{s!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const s=this.toolOperationList.length+1;return e.style.zIndex=`${s}`,e}getEmptyImage(t,o){const e=T({width:t,height:o}),s=new Image;return s.src=e,s}createOperation(t,o,e){var s;const{width:a,height:h}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,h),l={container:r,size:this.size,config:(s=this==null?void 0:this.config)!=null?s:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(l,e);let n;if(!t)n=new w(l),r.style.zIndex="0",n.init();else{const p=D(t);if(!p)return;n=new p(l)}return n==null||n.init(),n.canvas.id=t!=null?t:"basicCanvas",n.historyDisabled=!0,n.on("dragMove",({currentPos:p,zoom:u,imgInfo:O})=>{this.syncPosition(p,u,O,n)}),n.on("renderZoom",(p,u,O)=>{p&&u&&this.syncPosition(u,p,O,n)}),t?(this.container.appendChild(r),this.toolOperationList.push(n),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),n):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(n),this.toolOperationDom.unshift(r),n)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,s=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!s))return s.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,e),this.toolOperationDom=d(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,s,a;const h=this.toolOperationNameList.indexOf(t);if(h<0||this.toolOperationList.length<1||h>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[h],l=this.toolOperationDom[r];if(!c||!l)return;const n=l.style.zIndex;return l.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${n}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(s=this.toolOperationList[r]).clearCursorLine)==null||a.call(s),this.toolOperationList[r].render(),this.toolOperationList=d(this.toolOperationList,r,h),this.toolOperationDom=d(this.toolOperationDom,r,h),this.toolOperationNameList=d(this.toolOperationNameList,r,h),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}export{m as HybridToolUtils,S as ToolScheduler};
1
+ import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as D}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as w}from"./toolOperation/basicToolOperation.js";var x=Object.defineProperty,I=Object.defineProperties,M=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,f=(i,t,o)=>t in i?x(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,E=(i,t)=>{for(var o in t||(t={}))_.call(t,o)&&f(i,o,t[o]);if(g)for(var o of g(t))b.call(t,o)&&f(i,o,t[o]);return i},N=(i,t)=>I(i,M(t));const T=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},d=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},v=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let m=v;m.getTopToolName=i=>v.isHybridTool(i)?i[i.length-1]:i;class S{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(m.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:y,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=N(E({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){t.width&&t.height&&this.toolOperationDom.forEach(o=>{o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}),this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(r=>{n!==r&&(r.setCurrentPos(t),r.setZoom(o),r.setImgInfo(e),r.renderBasicCanvas(),r.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=T({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:r,height:h}=this.defaultSize,a=this.createDom(),c=this.getEmptyImage(r,h),l={container:a,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(l,e);let s;if(!t)s=new w(l),a.style.zIndex="0",s.init();else{const p=D(t);if(!p)return;s=new p(l)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.historyDisabled=!0,s.on("dragMove",({currentPos:p,zoom:u,imgInfo:O})=>{this.syncPosition(p,u,O,s)}),s.on("renderZoom",(p,u,O)=>{p&&u&&this.syncPosition(u,p,O,s)}),t?(this.container.appendChild(a),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(a),s):(this.container.insertBefore(a,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(a),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],r=this.toolOperationDom[e];if(!(!r||!n))return n.style.zIndex=`${o-1}`,r.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,e),this.toolOperationDom=d(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,r;const h=this.toolOperationNameList.indexOf(t);if(h<0||this.toolOperationList.length<1||h>this.toolOperationDom.length-1)return;const a=this.toolOperationDom.length-1,c=this.toolOperationDom[h],l=this.toolOperationDom[a];if(!c||!l)return;const s=l.style.zIndex;return l.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[a]).clearActiveStatus)==null||e.call(o),(r=(n=this.toolOperationList[a]).clearCursorLine)==null||r.call(n),this.toolOperationList[a].render(),this.toolOperationList=d(this.toolOperationList,a,h),this.toolOperationDom=d(this.toolOperationDom,a,h),this.toolOperationNameList=d(this.toolOperationNameList,a,h),this.toolOperationList[a]}updateDataByToolName(t,o,e=!0){const n=this.toolOperationNameList.indexOf(t);n>=0&&this.toolOperationList[n].setResult(o,e)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}export{m as HybridToolUtils,S as ToolScheduler};
@@ -1 +1 @@
1
- import{i18n as R,ImgPosUtils as L,toolStyleConverter as k}from"@labelbee/lb-utils";import{isNumber as E}from"lodash";import{EOperationMode as w,EToolName as y}from"../../constant/tool.js";import B from"../../utils/MathUtils.js";import x,{CoordinateUtils as G}from"../../utils/tool/AxisUtils.js";import F from"../../utils/tool/CanvasUtils.js";import _ from"../../utils/tool/CommonToolUtils.js";import H from"../../utils/tool/LineToolUtils.js";import{ELang as z,EGrowthMode as V,EDragStatus as Y}from"../../constant/annotation.js";import P from"../../constant/keyCode.js";import{styleString as X,BASE_ICON as $}from"../../constant/style.js";import U from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import J from"../../utils/ActionsHistory.js";import Z from"../../utils/tool/AttributeUtils.js";import q from"../../utils/tool/DblClickEventListener.js";import v from"../../utils/tool/DrawUtils.js";import Q from"../../utils/tool/RenderDomUtils.js";import O from"../../utils/tool/ZoomUtils.js";import tt from"./eventListener.js";var it=Object.defineProperty,et=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable,j=(u,t,i)=>t in u?it(u,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[t]=i,D=(u,t)=>{for(var i in t||(t={}))ot.call(t,i)&&j(u,i,t[i]);if(N)for(var i of N(t))nt.call(t,i)&&j(u,i,t[i]);return u},T=(u,t)=>et(u,st(t)),rt=(u,t,i)=>new Promise((e,o)=>{var n=r=>{try{a(i.next(r))}catch(l){o(l)}},c=r=>{try{a(i.throw(r))}catch(l){o(l)}},a=r=>r.done?e(r.value):Promise.resolve(r.value).then(n,c);a((i=i.apply(u,t)).next())});const K={[z.Zh]:"cn",[z.US]:"en"},at={min:.2,max:1e3,ratio:.4};class ht extends tt{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=w.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=at,this.initImgPos=()=>rt(this,null,function*(){var d,h;if(!this.imgNode)return;const s=(d=this._imgAttribute)==null?void 0:d.zoomRatio,m=(h=this._imgAttribute)==null?void 0:h.isOriginalSize,{currentPos:g,imgInfo:f,zoom:C}=L.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,s,m);this.setCurrentPos(g),this.currentPosStorage=g,this.setImgInfo(f),this.setZoom(C),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",C,g,f)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:h,currentPosStorage:s}=this;try{let m;return h&&s?m={y:s.y+d.y-h.y,x:s.x+d.x-h.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(d,h,s)=>{const{currentPos:m,imgNode:g}=this;if(!g){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&h===-1)return;const f=O.wheelChangePos(g,d,h,m,{zoom:s||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!f)return;const{currentPos:C,ratio:W,zoom:S,imgInfo:M}=f;this.setZoom(S),this.setCurrentPos(C),this.currentPosStorage=C,this.setImgInfo(M),this.zoomInfo.ratio=W,this.emit("renderZoom",S,C,M)},this.zoomChanged=(d,h=V.Linear)=>{const s=O.zoomChanged(this.zoom,d,h);this.wheelChangePos(this.getGetCenterCoordinate(),s>this.zoom?1:-1,s),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawStraightLine=(d,h)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=h.color,s.lineWidth=h.lineWidth,s.globalAlpha=h.globalAlpha,d.forEach((m,g)=>{if(s.beginPath(),g>0){const f=d[g-1];s.save(),s.moveTo(f.x,f.y),s.lineTo(m.x,m.y),s.stroke(),s.restore()}}),s.restore())},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(v.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),v.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,o,n,c,a,r,l,b,I,p;this.container=t.container,this.config=_.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(o=(e=t.imgNode)==null?void 0:e.width)!=null?o:0,height:(c=(n=t.imgNode)==null?void 0:n.height)!=null?c:0,valid:!0,rotate:0},this.forbidOperation=(a=t.forbidOperation)!=null?a:!1,this.forbidBasicResultRender=(r=t.forbidBasicResultRender)!=null?r:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new J,this.style=(l=t.style)!=null?l:_.jsonParser(X),this._imgAttribute=(b=t.imgAttribute)!=null?b:{},this.isHidden=!1,this.dragStatus=Y.Wait,this.defaultAttribute=(I=t==null?void 0:t.defaultAttribute)!=null?I:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(p=t==null?void 0:t.language)!=null?p:z.Zh,R.changeLanguage(K[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.onRightClick=this.onRightClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new q(this.container,200),this.coordUtils=new G(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return $[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===w.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===w.MultiMove&&this.setOperationMode(w.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=K[t];R.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return F.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const o=this.pixelRatio;t.style.position="absolute",t.width=i.width*o,t.height=i.height*o,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,o;const n=this.pixelRatio,c=document.createElement("canvas");this.updateCanvasBasicStyle(c,t,0),this.basicCanvas=c;const a=document.createElement("canvas");this.updateCanvasBasicStyle(a,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(a,this.container.childNodes[0]),this.container.insertBefore(c,this.container.childNodes[0])):(this.container.appendChild(c),this.container.appendChild(a))),this.canvas=a,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(n,n),(o=this.basicCtx)==null||o.scale(n,n),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(D({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:o}=L.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=T(D({},this.zoomInfo),{min:o})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return Z.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getCoordinateUnderZoomByRotateFromImgPoint(t){const{x:i,y:e}=t;return this.basicImgInfo.rotate===90?{x:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.x,y:i*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===180?{x:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.x,y:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===270?{x:e*this.zoom+this.currentPos.x,y:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.y}:{x:i*this.zoom+this.currentPos.x,y:e*this.zoom+this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:o,imgInfo:n,dependToolName:c}=this;if(t&&e&&c){let a=t;switch(c){case y.Polygon:case y.Line:{if(t.pointList){const l=B.calcViewportBoundaries(t.pointList);a={x:l.left,y:l.top,width:l.right-l.left,height:l.bottom-l.top}}break}}const r=L.getBasicRecPos(e,a,i,void 0,o==null?void 0:o.zoomRatio,o==null?void 0:o.isOriginalSize);r&&(this.setCurrentPos(r.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(T(D({},n),{width:n.width/this.innerZoom*r.innerZoom,height:n.height/this.innerZoom*r.innerZoom})),this.setZoom(r.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!E(i==null?void 0:i.x)||!E(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||H.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,t.button===2&&this.onRightClick(t),this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onRightClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch((t.keyCode===P.Alt||t.keyCode===P.A)&&t.preventDefault(),t.keyCode){case P.Space:this.isSpaceKey=!0,t.preventDefault();break;case P.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case P.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),o=t.deltaY||t.wheelDelta;let n=0;o>0&&this.zoom>this.zoomInfo.min&&(n=-1),o<0&&this.zoom<this.zoomInfo.max&&(n=1),this.wheelChangePos(e,n),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;v.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),v.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),v.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}filterCacheContext(){}setAttributeLockList(t){this.attributeLockList=t,this.filterCacheContext(),this.render()}setConfig(t){this.config=_.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",U.getMessagesByLocale(A.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",U.getMessagesByLocale(A.NoRotateNotice,this.lang)),!1;const t=B.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return k.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,o,n,c,a,r,l;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const p=Z.getAttributeIndex(t,(o=(e=this.config)==null?void 0:e.attributeList)!=null?o:[])+1;return((a=(c=(n=this.config)==null?void 0:n.attributeList)==null?void 0:c.find(h=>h.value===t))==null?void 0:a.color)?(l=(r=k.getColorByConfig({attribute:t,config:this.config}))==null?void 0:r.valid)==null?void 0:l.stroke:this.style.attributeLineColor?this.style.attributeLineColor[p]:""}const{color:b,lineColor:I}=this.style;return b&&I?I[b]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=Q.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case y.Rect:{v.drawRect(this.basicCanvas,x.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{v.drawPolygonWithFillAndLine(this.basicCanvas,x.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{v.drawLineWithPointList(this.basicCanvas,x.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{ht as BasicToolOperation};
1
+ import{i18n as R,ImgPosUtils as L,toolStyleConverter as k}from"@labelbee/lb-utils";import{isNumber as E}from"lodash";import{EOperationMode as w,EToolName as y}from"../../constant/tool.js";import B from"../../utils/MathUtils.js";import x,{CoordinateUtils as W}from"../../utils/tool/AxisUtils.js";import G from"../../utils/tool/CanvasUtils.js";import _ from"../../utils/tool/CommonToolUtils.js";import H from"../../utils/tool/LineToolUtils.js";import{ELang as z,EGrowthMode as V,EDragStatus as Y}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{styleString as X,BASE_ICON as $}from"../../constant/style.js";import A from"../../locales/index.js";import{EMessage as O}from"../../locales/constants.js";import q from"../../utils/ActionsHistory.js";import U from"../../utils/tool/AttributeUtils.js";import J from"../../utils/tool/DblClickEventListener.js";import v from"../../utils/tool/DrawUtils.js";import Q from"../../utils/tool/RenderDomUtils.js";import Z from"../../utils/tool/ZoomUtils.js";import tt from"./eventListener.js";var it=Object.defineProperty,et=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable,j=(u,t,i)=>t in u?it(u,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[t]=i,D=(u,t)=>{for(var i in t||(t={}))ot.call(t,i)&&j(u,i,t[i]);if(N)for(var i of N(t))nt.call(t,i)&&j(u,i,t[i]);return u},T=(u,t)=>et(u,st(t)),rt=(u,t,i)=>new Promise((e,s)=>{var a=n=>{try{l(i.next(n))}catch(r){s(r)}},h=n=>{try{l(i.throw(n))}catch(r){s(r)}},l=n=>n.done?e(n.value):Promise.resolve(n.value).then(a,h);l((i=i.apply(u,t)).next())});const K={[z.Zh]:"cn",[z.US]:"en"},at={min:.2,max:1e3,ratio:.4};class ht extends tt{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=w.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=at,this.isOffscreenCanvas=!1,this.initImgPos=()=>rt(this,null,function*(){var d,c;if(!this.imgNode)return;const o=(d=this._imgAttribute)==null?void 0:d.zoomRatio,m=(c=this._imgAttribute)==null?void 0:c.isOriginalSize,{currentPos:g,imgInfo:f,zoom:C}=L.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,o,m);this.setCurrentPos(g),this.currentPosStorage=g,this.setImgInfo(f),this.setZoom(C),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",C,g,f)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:c,currentPosStorage:o}=this;try{let m;return c&&o?m={y:o.y+d.y-c.y,x:o.x+d.x-c.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.moveAnimationFrameId=null,this.wheelChangePos=(d,c,o)=>{const{currentPos:m,imgNode:g}=this;if(!g){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&c===-1)return;const f=Z.wheelChangePos(g,d,c,m,{zoom:o||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!f)return;const{currentPos:C,ratio:F,zoom:M,imgInfo:S}=f;this.setZoom(M),this.setCurrentPos(C),this.currentPosStorage=C,this.setImgInfo(S),this.zoomInfo.ratio=F,this.emit("renderZoom",M,C,S)},this.zoomChanged=(d,c=V.Linear)=>{const o=Z.zoomChanged(this.zoom,d,c);this.wheelChangePos(this.getGetCenterCoordinate(),o>this.zoom?1:-1,o),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawStraightLine=(d,c)=>{const{ctx:o}=this;o&&(o.save(),o.lineCap="round",o.lineJoin="round",o.strokeStyle=c.color,o.lineWidth=c.lineWidth,o.globalAlpha=c.globalAlpha,d.forEach((m,g)=>{if(o.beginPath(),g>0){const f=d[g-1];o.save(),o.moveTo(f.x,f.y),o.lineTo(m.x,m.y),o.stroke(),o.restore()}}),o.restore())},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(v.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),v.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,s,a,h,l,n,r,b,I,P;this.isOffscreenCanvas=!!t.isOffscreenCanvas,this.container=t.container,this.config=_.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(e=t.imgNode)==null?void 0:e.width)!=null?s:0,height:(h=(a=t.imgNode)==null?void 0:a.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(l=t.forbidOperation)!=null?l:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new q,this.style=(r=t.style)!=null?r:_.jsonParser(X),this._imgAttribute=(b=t.imgAttribute)!=null?b:{},this.isHidden=!1,this.dragStatus=Y.Wait,this.defaultAttribute=(I=t==null?void 0:t.defaultAttribute)!=null?I:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(P=t==null?void 0:t.language)!=null?P:z.Zh,R.changeLanguage(K[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.optimizeMouseMove=this.optimizeMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.onRightClick=this.onRightClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new J(this.container,300),this.coordUtils=new W(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get offscreenCtx(){var t;return(t=this.offscreenCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return $[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===w.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===w.MultiMove&&this.setOperationMode(w.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=K[t];R.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return G.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s,a;const h=this.pixelRatio,l=document.createElement("canvas");this.updateCanvasBasicStyle(l,t,0),this.basicCanvas=l;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10);let r;this.isOffscreenCanvas&&(r=document.createElement("canvas"),this.updateCanvasBasicStyle(r,t,20),this.offscreenCanvas=r),i&&(this.container.hasChildNodes()?(this.isOffscreenCanvas&&r&&this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(l,this.container.childNodes[0])):(this.container.appendChild(l),this.container.appendChild(n),this.isOffscreenCanvas&&r&&this.container.appendChild(r))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(h,h),(s=this.basicCtx)==null||s.scale(h,h),(a=this.offscreenCtx)==null||a.scale(h,h),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.offscreenCanvas&&this.container.contains(this.offscreenCanvas)&&this.container.removeChild(this.offscreenCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(D({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:s}=L.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=T(D({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return U.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getCoordinateUnderZoomByRotateFromImgPoint(t){const{x:i,y:e}=t;return this.basicImgInfo.rotate===90?{x:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.x,y:i*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===180?{x:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.x,y:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===270?{x:e*this.zoom+this.currentPos.x,y:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.y}:{x:i*this.zoom+this.currentPos.x,y:e*this.zoom+this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:a,dependToolName:h}=this;if(t&&e&&h){let l=t;switch(h){case y.Polygon:case y.Line:{if(t.pointList){const r=B.calcViewportBoundaries(t.pointList);l={x:r.left,y:r.top,width:r.right-r.left,height:r.bottom-r.top}}break}}const n=L.getBasicRecPos(e,l,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(T(D({},a),{width:a.width/this.innerZoom*n.innerZoom,height:a.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearOffscreenCanvas(){var t;(t=this.offscreenCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.optimizeMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.optimizeMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}optimizeMouseMove(t){this.moveAnimationFrameId||(this.moveAnimationFrameId=requestAnimationFrame(()=>{this.onMouseMove(t),this.moveAnimationFrameId=null}))}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t,i=!0){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!E(e==null?void 0:e.x)||!E(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const s=this.getCurrentPos(e);this.setCurrentPos(s),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:s,zoom:this.zoom,imgInfo:this.imgInfo})}i&&this.render()}catch(s){console.error(s)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||H.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,t.button===2&&this.onRightClick(t),this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onRightClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch((t.keyCode===p.Alt||t.keyCode===p.A)&&t.preventDefault(),t.keyCode){case p.Space:this.isSpaceKey=!0,t.preventDefault();break;case p.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case p.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let a=0;s>0&&this.zoom>this.zoomInfo.min&&(a=-1),s<0&&this.zoom<this.zoomInfo.max&&(a=1),this.wheelChangePos(e,a),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;v.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),v.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),v.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}filterCacheContext(){}setAttributeLockList(t){this.attributeLockList=t,this.filterCacheContext(),this.render()}setConfig(t){this.config=_.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",A.getMessagesByLocale(O.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",A.getMessagesByLocale(O.NoRotateNotice,this.lang)),!1;const t=B.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return k.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,a,h,l,n,r;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const P=U.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((l=(h=(a=this.config)==null?void 0:a.attributeList)==null?void 0:h.find(c=>c.value===t))==null?void 0:l.color)?(r=(n=k.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:r.stroke:this.style.attributeLineColor?this.style.attributeLineColor[P]:""}const{color:b,lineColor:I}=this.style;return b&&I?I[b]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=Q.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case y.Rect:{v.drawRect(this.basicCanvas,x.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{v.drawPolygonWithFillAndLine(this.basicCanvas,x.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{v.drawLineWithPointList(this.basicCanvas,x.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{ht as BasicToolOperation};
@@ -1 +1 @@
1
- import b,{isNumber as D}from"lodash";import{INVALID_COLOR as _,toolStyleConverter as C}from"@labelbee/lb-utils";import{ESortDirection as w,EDragTarget as S,DEFAULT_TEXT_OFFSET as A}from"../../constant/annotation.js";import{EPolygonPattern as v}from"../../constant/tool.js";import f from"../../utils/tool/AxisUtils.js";import y from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import L from"../../utils/tool/PolygonUtils.js";import{polygonConfig as x}from"../../constant/defaultConfig.js";import T from"./polygonOperation.js";import{BasicToolOperation as O}from"./basicToolOperation.js";var k=Object.defineProperty,B=Object.defineProperties,R=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,I=(d,t,e)=>t in d?k(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,u=(d,t)=>{for(var e in t||(t={}))U.call(t,e)&&I(d,e,t[e]);if(m)for(var e of m(t))j.call(t,e)&&I(d,e,t[e]);return d},g=(d,t)=>B(d,R(t));class M extends T{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=o=>{var a;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,o.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const l=(a=this.polygonList.find(c=>c.id===this.hoverID))==null?void 0:a.attribute;l&&l!==this.defaultAttribute&&this.emit("syncAttribute",l)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=o=>{var a;if(o){const l=this.getPointCloudLineColor(o),c=f.changePointListByZoom(o.pointList,this.zoom,this.currentPos);P.drawSelectedPolygonWithFillAndLine(this.canvas,c,{fillColor:"transparent",strokeColor:l,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(a=this.config)==null?void 0:a.lineType}),o.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(c),D(o==null?void 0:o.trackID)&&(o==null?void 0:o.trackID)>=0&&this.renderdrawTrackID(o))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:o}=this.dragInfo;if(this.selectedIDs.length>0){const a=[];this.polygonList.forEach(l=>{if(this.selectedIDs.includes(l.id)){const c=o.find(p=>p.id===l.id);c&&a.push({newPolygon:l,originPolygon:c})}}),this.emit("updatePolygonByDrag",a)}}};var e,i,s,r,n,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(s=y.jsonParser(t.config))!=null?s:{},this.hideAttributes=[],this.checkMode=(r=t.checkMode)!=null?r:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=g(u({},x),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=y.jsonParser(t);this.pointCloudConfig=i,this.config=g(u({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return L.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const s=b.cloneDeep(this.selectedPolygons),r=[];(i=this.selectedPolygons)==null||i.forEach((n,h)=>{n.pointList=n.pointList.map(o=>{var a,l;const{x:c,y:p}=o;return g(u({},o),{x:c+((a=t.x)!=null?a:0),y:p+((l=t.y)!=null?l:0)})}),r.push({originPolygon:s[h],newPolygon:n})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",r),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?_:C.getColorFromConfig({attribute:t.attribute},g(u({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const n=this.getPointCloudLineColor(e),h=f.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),o=this.highlightAttributeList.includes(e.attribute);P.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:o?n:"transparent",strokeColor:n,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),D(e==null?void 0:e.trackID)&&(e==null?void 0:e.trackID)>=0&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){const e=f.changePointListByZoom(t.pointList,this.zoom,this.currentPos),i=e[e.length-1],s=t==null?void 0:t.trackID;P.drawText(this.canvas,i,`${s}`,u({textAlign:"center",color:"white"},A))}renderRectPolygonDirection(t){t.length<2||P.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===v.Rect?t.isRect===!0:this.pattern===v.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>g(u({},n),{pointList:f.changePointListByZoom(n.pointList,this.zoom)}));return L.getHoverPolygonID(i,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=w.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(s=>{var r,n,h,o;return g(u({},s),{x:(n=(r=s.pointList[0])==null?void 0:r.x)!=null?n:0,y:(o=(h=s.pointList[0])==null?void 0:h.y)!=null?o:0})}),i=y.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const s=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(s,s),(i=this.basicCtx)==null||i.scale(s,s),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1,i){if(e){super.setPolygonValidAndRender(t,i);return}this.emit("validUpdate",t)}onMouseDown(t){if(O.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:S.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}setHighlightAttribute(t){this.highlightAttributeList=[t],this.render()}}export{M as default};
1
+ import w,{isNumber as L}from"lodash";import{INVALID_COLOR as b,toolStyleConverter as _}from"@labelbee/lb-utils";import{ESortDirection as C,EDragTarget as S,DEFAULT_TEXT_OFFSET as T}from"../../constant/annotation.js";import{EPolygonPattern as y,ERectToolModeType as x,RECT_TOOL_MODE_NAME as A}from"../../constant/tool.js";import p from"../../utils/tool/AxisUtils.js";import D from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import m from"../../utils/tool/PolygonUtils.js";import{polygonConfig as B}from"../../constant/defaultConfig.js";import M from"../../utils/MathUtils.js";import O from"./polygonOperation.js";import{BasicToolOperation as R}from"./basicToolOperation.js";import k from"../../locales/index.js";import{EMessage as j}from"../../locales/constants.js";var U=Object.defineProperty,E=Object.defineProperties,N=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,I=(d,t,e)=>t in d?U(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,u=(d,t)=>{for(var e in t||(t={}))H.call(t,e)&&I(d,e,t[e]);if(v)for(var e of v(t))F.call(t,e)&&I(d,e,t[e]);return d},g=(d,t)=>E(d,N(t));class Z extends O{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=o=>{var l,a;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,o.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const h=(l=this.polygonList.find(f=>f.id===this.hoverID))==null?void 0:l.attribute;((a=this.selection.selectedIDs)==null?void 0:a.length)===1&&h&&h!==this.defaultAttribute&&this.emit("syncAttribute",h)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=o=>{var l;if(o){const a=this.getPointCloudLineColor(o),h=p.changePointListByZoom(o.pointList,this.zoom,this.currentPos);P.drawSelectedPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(l=this.config)==null?void 0:l.lineType}),o.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(h),L(o==null?void 0:o.trackID)&&(o==null?void 0:o.trackID)>=0&&this.renderdrawTrackID(o))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:o}=this.dragInfo;if(this.selectedIDs.length>0){const l=[];this.polygonList.forEach(a=>{if(this.selectedIDs.includes(a.id)){const h=o.find(f=>f.id===a.id);h&&l.push({newPolygon:a,originPolygon:h})}}),this.emit("updatePolygonByDrag",l)}}};var e,i,s,r,n,c;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(s=D.jsonParser(t.config))!=null?s:{},this.hideAttributes=[],this.checkMode=(r=t.checkMode)!=null?r:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=g(u({},B),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(c=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?c:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}get lastStepByThreePointsMode(){return this.pattern===y.Rect&&this.drawingPointList.length===2}get lastStepByTwoPointsMode(){return this.pattern===y.Rect&&this.rectToolMode===x.TwoPoints&&this.drawingPointList.length===1}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=D.jsonParser(t);this.pointCloudConfig=i,this.config=g(u({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return m.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const s=w.cloneDeep(this.selectedPolygons),r=[];(i=this.selectedPolygons)==null||i.forEach((n,c)=>{n.pointList=n.pointList.map(o=>{var l,a;const{x:h,y:f}=o;return g(u({},o),{x:h+((l=t.x)!=null?l:0),y:f+((a=t.y)!=null?a:0)})}),r.push({originPolygon:s[c],newPolygon:n})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",r),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?b:_.getColorFromConfig({attribute:t.attribute},g(u({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const n=this.getPointCloudLineColor(e),c=p.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),o=this.highlightAttributeList.includes(e.attribute);P.drawPolygonWithFillAndLine(this.canvas,c,{fillColor:o?n:"transparent",strokeColor:n,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),L(e==null?void 0:e.trackID)&&(e==null?void 0:e.trackID)>=0&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(c)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){var e,i;if(!((e=t==null?void 0:t.pointList)==null?void 0:e.length))return;const s=t.pointList[t.pointList.length-1],r=p.changePointByZoom(s,this.zoom,this.currentPos),n=((i=t==null?void 0:t.trackID)==null?void 0:i.toString())||"";P.drawText(this.canvas,r,n,u({textAlign:"center",color:"white"},T))}renderRectPolygonDirection(t){t.length<2||P.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===y.Rect?t.isRect===!0:this.pattern===y.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>g(u({},n),{pointList:p.changePointListByZoom(n.pointList,this.zoom)}));return m.getHoverPolygonID(i,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=C.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(s=>{var r,n,c,o;return g(u({},s),{x:(n=(r=s.pointList[0])==null?void 0:r.x)!=null?n:0,y:(o=(c=s.pointList[0])==null?void 0:c.y)!=null?o:0})}),i=D.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||(this.rectToolMode=localStorage.getItem(A),super.addPointInDrawing(t))}setCanvasSize(t){var e,i;const s=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(s,s),(i=this.basicCtx)==null||i.scale(s,s),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1,i){if(e){super.setPolygonValidAndRender(t,i);return}this.emit("validUpdate",t)}onMouseDown(t){if(R.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:S.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}setHighlightAttribute(t){this.highlightAttributeList=[t],this.render()}createRectByTwoPointsMode(t,e){const i=t[0],s=[...t],r=e.x>i.x&&e.y>i.y,n=e.x<i.x&&e.y<i.y;return r||n?s.push({x:i.x,y:e.y},e,{x:e.x,y:i.y}):s.push({x:e.x,y:i.y},e,{x:i.x,y:e.y}),s}addPointInDrawingHook(t){return this.lastStepByThreePointsMode||this.lastStepByTwoPointsMode?(this.drawingPointList=this.getPointListByRectDrawing(t,this.drawingPointList).value,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)?(this.emit("messageInfo",`${k.getMessagesByLocale(j.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[],{continue:!1}):(this.addDrawingPointToPolygonList(!0),{continue:!1})):{continue:!0}}renderPolygonHook(t){return this.lastStepByTwoPointsMode&&P.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]}),{continue:!0}}getPointListByRectDrawing(t,e){let i;return this.lastStepByThreePointsMode?i=M.getRectangleByRightAngle(t,e):this.lastStepByTwoPointsMode&&(i=this.createRectByTwoPointsMode(e,t)),{continue:!0,value:i}}}export{Z as default};
@@ -1 +1 @@
1
- import E from"lodash";import{EToolName as b,ELineTypes as w,edgeAdsorptionScope as k}from"../../constant/tool.js";import U from"../../utils/tool/RectUtils.js";import L from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/MarkerUtils.js";import j from"../../utils/MathUtils.js";import{EDragStatus as c,ESortDirection as _,DEFAULT_TEXT_OFFSET as N}from"../../constant/annotation.js";import P from"../../constant/keyCode.js";import y from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import m from"../../utils/tool/AttributeUtils.js";import d from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/CommonToolUtils.js";import I from"../../utils/tool/DrawUtils.js";import z from"../../utils/tool/StyleUtils.js";import B from"../../utils/uuid.js";import{BasicToolOperation as Z}from"./basicToolOperation.js";import H from"./textAttributeClass.js";import K from"./Selection.js";var W=Object.defineProperty,$=Object.defineProperties,F=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,M=Math.pow,R=(g,t,e)=>t in g?W(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,x=(g,t)=>{for(var e in t||(t={}))V.call(t,e)&&R(g,e,t[e]);if(T)for(var e of T(t))X.call(t,e)&&R(g,e,t[e]);return g},C=(g,t)=>$(g,F(t));const O=200;class q extends Z{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const o=this.config.markerList[s].value,n=this.currentPageResult.find(l=>l.label===o);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(m.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const o=d.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const l=d.changePointByZoom(n,this.zoom);return j.getLineLength(l,o)<.2})};var e,i;this.config=a.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new K(this),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}get selectedID(){return this.selection.selectedID}get selectedIDs(){return this.selection.selectedIDs}get selectedPoints(){return this.pointList.filter(t=>this.selection.isIdSelected(t.id))}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=a.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=a.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPoints.length>0&&(this.selectedPoints.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.pointList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return m.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=c.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>C(x({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if(this.hoverID&&this.selection.isIdSelected(this.hoverID)&&t.button===0){this.dragStatus=c.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:E.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===c.Start||this.dragStatus===c.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(t.button===2&&this.rightMouseUp(t),this.dragStatus===c.Move){const i=this.pointList.find(s=>(s==null?void 0:s.id)===this.selectedID);if(i){const{newPoint:s,hasClosed:o}=this.getNearPoint(i);s&&Object.assign(i,s),o&&this.emit("messageSuccess",`${y.getMessagesByLocale(S.SuccessfulEdgeAdsorption,this.lang)}`)}this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",i,(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0}this.dragStatus=c.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=c.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const l={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(l);return}const o=d.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):d.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===b.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!L.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(l=>{l.id===this.selectedID&&(l.x=n.x,l.y=n.y)}),this.render())}onKeyDown(t){if(!a.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case P.Delete:this.deletePoint();break;case P.Tab:{this.onTabKeyDown(t);break}case P.Z:this.setIsHidden(!this.isHidden),this.render();break;case P.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=m.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}getNearPoint(t){var e,i,s;if(this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){const o=[b.Polygon,b.Line].includes(this.dependToolName),n=[this.basicResult];if(o){const l=this.dependToolName===b.Polygon,{dropFoot:h,hasClosed:u}=L.getClosestPoint(t,n,(s=(i=(e=this.referenceData)==null?void 0:e.config)==null?void 0:i.lineType)!=null?s:w.Line,k/this.zoom,{isClose:l});return{newPoint:h,hasClosed:u}}}return{newPoint:t,hasClosed:!1}}createPoint(t){if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:e}=this.config;if(e&&this.currentPageResult.length>=e){this.emit("messageInfo",`${y.getMessagesByLocale(S.LowerLimitPoint,this.lang)}`);return}const i=a.getSourceID(this.basicResult),s=this.getCoordinateUnderZoom(t);let o=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const{newPoint:n,hasClosed:l}=this.getNearPoint(o);if(n&&(o=n),l&&this.emit("messageSuccess",`${y.getMessagesByLocale(S.SuccessfulEdgeAdsorption,this.lang)}`),this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let r=!1;switch(this.dependToolName){case b.Rect:{r=!U.isInRect(o,this.basicResult);break}case b.Polygon:{r=!L.isInPolygon(o,this.basicResult.pointList);break}}if(r)return}if(s.x<0||s.y<0||s.x>this.imgInfo.width||s.y>this.imgInfo.height)return}if(this.isMinDistance(o))return;let h=C(x({},o),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:B(8,62),sourceID:i,textAttribute:"",order:a.getMaxOrder(this.pointList.filter(r=>a.isSameSourceID(r.sourceID,i)))+1});if(this.config.textConfigurable){let r="";r=m.getTextAttribute(this.pointList.filter(f=>a.isSameSourceID(f.sourceID,i)),this.config.textCheckType),h=C(x({},h),{textAttribute:r})}if(this.hasMarkerConfig){const r=a.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(r)h=C(x({},h),{label:r.label}),this.markerIndex=r.index,this.emit("markIndexChange");else{this.emit("messageInfo",y.getMessagesByLocale(S.MarkerFinish,this.lang));return}}this.hoverID=h.id;const u=[...this.pointList,h];this.setPointList(u),this.emit("pointCreated",h,this.zoom),this.history.pushHistory(u),this.setSelectedID(h.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(M(t.x-e.x,2)+M(t.y-e.y,2))}getHoverId(){var t;const e=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(t){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const i=this.pointList.filter(s=>s.id!==this.selectedID);this.setPointList(i),this.history.pushHistory(i),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const e=this.pointList.find(i=>i.id===this.hoverID);if(this.setSelectedID(this.hoverID,t.ctrlKey),this.emit("pointSelected",this.hoverID),e&&this.setDefaultAttribute(e==null?void 0:e.attribute),(e==null?void 0:e.label)&&this.hasMarkerConfig){const i=a.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===c.Move||this.dragStatus===c.Start)return;let e=_.ascend;t.shiftKey&&(e=_.descend);const[i,s]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let o=[...i];s&&(o=[...o,...s]);const n=a.getNextSelectedRectID(o,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=a.getRenderResultList(t,a.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedIDs.length>0&&(this.setPointList(this.pointList.filter(e=>this.selection.isIdSelected(e.id))),this.history.pushHistory(this.pointList),(t=this._textAttributeInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===c.Move||this.dragStatus===c.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=c.Wait,{width:O*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;m.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",m.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(m.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(p=>p.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:n,valid:l}=i,h=O*this.zoom*.6,u=d.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),r=this.getColor(n),f=l?r==null?void 0:r.valid.stroke:r==null?void 0:r.invalid.stroke,D=4;this._textAttributeInstance||(this._textAttributeInstance=new H({width:h,container:this.container,icon:this.getTextIconSvg(n),color:f,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((e=this._textAttributeInstance)==null?void 0:e.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${i.textAttribute}`,{left:u.x,top:u.y+D,color:f,width:h})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:n="",attribute:l}=t,h=e||t.id===this.selectedID,u=this.getColor(l),r=d.changePointByZoom(t,this.zoom,this.currentPos),{width:f=2,hiddenText:D=!1}=this.style,p=z.getStrokeAndFill(u,t.valid,{isSelected:h||t.id===this.hoverID});I.drawCircle(this.canvas,r,f,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:p.stroke,fill:p.fill});let v="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(v=`${t.order}`),t.label&&this.hasMarkerConfig&&(v=`${a.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${A.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(v=`${v} ${m.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),D||I.drawText(this.canvas,{x:r.x+f/2,y:r.y-f-4},v,{textAlign:"center",color:p.stroke}),h?this.renderTextAttribute():D||I.drawText(this.canvas,{x:r.x+f,y:r.y+f+24},n,x({color:p.stroke},N))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&e.forEach(i=>{this.renderPoint(i,!0)})}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const o=A.getAuxiliaryLineByMarkerList(this.config.markerList,"value");A.getAuxiliaryLineCoord(o,s).forEach(l=>{const{start:h,end:u}=l,r=d.changePointListByZoom([h,u],this.zoom,this.currentPos);I.drawLine(this.canvas,r[0],r[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){let o=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=this.dependToolName===b.Polygon,l=[this.basicResult],{dropFoot:h}=L.getClosestPoint(o,l,(i=(e=(t=this.referenceData)==null?void 0:t.config)==null?void 0:e.lineType)!=null?i:w.Line,k/this.zoom,{isClose:n});h&&o!==h&&o!==h&&(o=h,I.drawCircle(this.canvas,d.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),I.drawCircle(this.canvas,d.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{q as default};
1
+ import E from"lodash";import{EToolName as b,ELineTypes as w,edgeAdsorptionScope as k}from"../../constant/tool.js";import U from"../../utils/tool/RectUtils.js";import y from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/MarkerUtils.js";import j from"../../utils/MathUtils.js";import{EDragStatus as c,ESortDirection as _,DEFAULT_TEXT_OFFSET as N}from"../../constant/annotation.js";import D from"../../constant/keyCode.js";import S from"../../locales/index.js";import{EMessage as C}from"../../locales/constants.js";import m from"../../utils/tool/AttributeUtils.js";import d from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/CommonToolUtils.js";import p from"../../utils/tool/DrawUtils.js";import z from"../../utils/tool/StyleUtils.js";import B from"../../utils/uuid.js";import{BasicToolOperation as Z}from"./basicToolOperation.js";import H from"./textAttributeClass.js";import K from"./Selection.js";var F=Object.defineProperty,W=Object.defineProperties,$=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,M=Math.pow,R=(g,t,e)=>t in g?F(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,v=(g,t)=>{for(var e in t||(t={}))V.call(t,e)&&R(g,e,t[e]);if(T)for(var e of T(t))X.call(t,e)&&R(g,e,t[e]);return g},L=(g,t)=>W(g,$(t));const O=200;class q extends Z{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const o=this.config.markerList[s].value,n=this.currentPageResult.find(l=>l.label===o);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(m.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const o=d.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const l=d.changePointByZoom(n,this.zoom);return j.getLineLength(l,o)<.2})};var e,i;this.config=a.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new K(this),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}get selectedID(){return this.selection.selectedID}get selectedIDs(){return this.selection.selectedIDs}get selectedPoints(){return this.pointList.filter(t=>this.selection.isIdSelected(t.id))}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=a.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=a.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPoints.length>0&&(this.selectedPoints.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.pointList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return m.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=c.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>L(v({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if(this.hoverID&&this.selection.isIdSelected(this.hoverID)&&t.button===0){this.dragStatus=c.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:E.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===c.Start||this.dragStatus===c.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(t.button===2&&this.rightMouseUp(t),this.dragStatus===c.Move){const i=this.pointList.find(s=>(s==null?void 0:s.id)===this.selectedID);if(i){const{newPoint:s,hasClosed:o}=this.getNearPoint(i);s&&Object.assign(i,s),o&&this.emit("messageSuccess",`${S.getMessagesByLocale(C.SuccessfulEdgeAdsorption,this.lang)}`)}this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",i,(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0}this.dragStatus=c.Wait,this.render()}setPointValidAndRender(t){const e=this.pointList.some(i=>i==null?void 0:i.valid);this.setPointList(this.pointList.map(i=>i.id===t?L(v({},i),{valid:!i.valid}):(this.selection.isIdSelected(i.id)&&(i.valid=!e),i)),!0),this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=c.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const l={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(l);return}const o=d.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):d.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===b.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!y.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(l=>{l.id===this.selectedID&&(l.x=n.x,l.y=n.y)}),this.render())}onKeyDown(t){if(!a.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case D.Delete:this.deletePoint();break;case D.Tab:{this.onTabKeyDown(t);break}case D.F:this.selectedIDs.length>0&&this.setPointValidAndRender(this.selectedID);break;case D.Z:this.setIsHidden(!this.isHidden),this.render();break;case D.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=m.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}getNearPoint(t){var e,i,s;if(this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){const o=[b.Polygon,b.Line].includes(this.dependToolName),n=[this.basicResult];if(o){const l=this.dependToolName===b.Polygon,{dropFoot:h,hasClosed:u}=y.getClosestPoint(t,n,(s=(i=(e=this.referenceData)==null?void 0:e.config)==null?void 0:i.lineType)!=null?s:w.Line,k/this.zoom,{isClose:l});return{newPoint:h,hasClosed:u}}}return{newPoint:t,hasClosed:!1}}createPoint(t){if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:e}=this.config;if(e&&this.currentPageResult.length>=e){this.emit("messageInfo",`${S.getMessagesByLocale(C.LowerLimitPoint,this.lang)}`);return}const i=a.getSourceID(this.basicResult),s=this.getCoordinateUnderZoom(t);let o=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const{newPoint:n,hasClosed:l}=this.getNearPoint(o);if(n&&(o=n),l&&this.emit("messageSuccess",`${S.getMessagesByLocale(C.SuccessfulEdgeAdsorption,this.lang)}`),this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let r=!1;switch(this.dependToolName){case b.Rect:{r=!U.isInRect(o,this.basicResult);break}case b.Polygon:{r=!y.isInPolygon(o,this.basicResult.pointList);break}}if(r)return}if(s.x<0||s.y<0||s.x>this.imgInfo.width||s.y>this.imgInfo.height)return}if(this.isMinDistance(o))return;let h=L(v({},o),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:B(8,62),sourceID:i,textAttribute:"",order:a.getMaxOrder(this.pointList.filter(r=>a.isSameSourceID(r.sourceID,i)))+1});if(this.config.textConfigurable){let r="";r=m.getTextAttribute(this.pointList.filter(f=>a.isSameSourceID(f.sourceID,i)),this.config.textCheckType),h=L(v({},h),{textAttribute:r})}if(this.hasMarkerConfig){const r=a.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(r)h=L(v({},h),{label:r.label}),this.markerIndex=r.index,this.emit("markIndexChange");else{this.emit("messageInfo",S.getMessagesByLocale(C.MarkerFinish,this.lang));return}}this.hoverID=h.id;const u=[...this.pointList,h];this.setPointList(u),this.emit("pointCreated",h,this.zoom),this.history.pushHistory(u),this.setSelectedID(h.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(M(t.x-e.x,2)+M(t.y-e.y,2))}getHoverId(){var t;const e=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(t){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const i=this.pointList.filter(s=>s.id!==this.selectedID);this.setPointList(i),this.history.pushHistory(i),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const e=this.pointList.find(i=>i.id===this.hoverID);if(this.setSelectedID(this.hoverID,t.ctrlKey),this.emit("pointSelected",this.hoverID),e&&this.setDefaultAttribute(e==null?void 0:e.attribute),(e==null?void 0:e.label)&&this.hasMarkerConfig){const i=a.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===c.Move||this.dragStatus===c.Start)return;let e=_.ascend;t.shiftKey&&(e=_.descend);const[i,s]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let o=[...i];s&&(o=[...o,...s]);const n=a.getNextSelectedRectID(o,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=a.getRenderResultList(t,a.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedIDs.length>0&&(this.setPointList(this.pointList.filter(e=>this.selection.isIdSelected(e.id))),this.history.pushHistory(this.pointList),(t=this._textAttributeInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===c.Move||this.dragStatus===c.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=c.Wait,{width:O*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;m.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",m.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(m.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(I=>I.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:n,valid:l}=i,h=O*this.zoom*.6,u=d.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),r=this.getColor(n),f=l?r==null?void 0:r.valid.stroke:r==null?void 0:r.invalid.stroke,P=4;this._textAttributeInstance||(this._textAttributeInstance=new H({width:h,container:this.container,icon:this.getTextIconSvg(n),color:f,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((e=this._textAttributeInstance)==null?void 0:e.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${i.textAttribute}`,{left:u.x,top:u.y+P,color:f,width:h})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:n="",attribute:l}=t,h=e||t.id===this.selectedID,u=this.getColor(l),r=d.changePointByZoom(t,this.zoom,this.currentPos),{width:f=2,hiddenText:P=!1}=this.style,I=z.getStrokeAndFill(u,t.valid,{isSelected:h||t.id===this.hoverID});p.drawCircle(this.canvas,r,f,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:I.stroke,fill:I.fill});let x="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(x=`${t.order}`),t.label&&this.hasMarkerConfig&&(x=`${a.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${A.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(x=`${x} ${m.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),P||p.drawText(this.canvas,{x:r.x+f/2,y:r.y-f-4},x,{textAlign:"center",color:I.stroke}),h?this.renderTextAttribute():P||p.drawText(this.canvas,{x:r.x+f,y:r.y+f+24},n,v({color:I.stroke},N))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&e.forEach(i=>{this.renderPoint(i,!0)})}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const o=A.getAuxiliaryLineByMarkerList(this.config.markerList,"value");A.getAuxiliaryLineCoord(o,s).forEach(l=>{const{start:h,end:u}=l,r=d.changePointListByZoom([h,u],this.zoom,this.currentPos);p.drawLine(this.canvas,r[0],r[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.basicResult&&this.dependToolName){let o=d.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=this.dependToolName===b.Polygon,l=[this.basicResult],{dropFoot:h}=y.getClosestPoint(o,l,(i=(e=(t=this.referenceData)==null?void 0:t.config)==null?void 0:e.lineType)!=null?i:w.Line,k/this.zoom,{isClose:n});h&&o!==h&&o!==h&&(o=h,p.drawCircle(this.canvas,d.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),p.drawCircle(this.canvas,d.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{q as default};