@labelbee/lb-annotation 1.27.0-alpha.5 → 1.27.0-alpha.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/highlightWorker.js +1 -1
- package/dist/constant/keyCode.js +1 -1
- package/dist/core/pointCloud/index.js +2 -2
- package/dist/core/pointCloud/matrix.js +1 -1
- package/dist/core/pointCloud/omniCamera.js +1 -1
- package/dist/core/toolOperation/ViewOperation.js +2 -1
- package/dist/core/toolOperation/pointCloud2DRectOperation.js +1 -1
- package/dist/core/toolOperation/pointOperation.js +1 -1
- package/dist/core/toolOperation/polygonOperation.js +1 -1
- package/dist/core/toolOperation/rectOperation.js +2 -1
- package/dist/core/toolOperation/utils/reCalcRect.js +1 -0
- package/dist/index.js +1 -1
- package/dist/types/constant/keyCode.d.ts +1 -0
- package/dist/types/core/pointCloud/index.d.ts +5 -1
- package/dist/types/core/toolOperation/ViewOperation.d.ts +3 -0
- package/dist/types/core/toolOperation/pointCloud2DRectOperation.d.ts +8 -3
- package/dist/types/core/toolOperation/pointOperation.d.ts +4 -0
- package/dist/types/core/toolOperation/polygonOperation.d.ts +2 -0
- package/dist/types/core/toolOperation/rectOperation.d.ts +19 -3
- package/dist/types/core/toolOperation/utils/reCalcRect.d.ts +9 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/utils/tool/AxisUtils.d.ts +4 -0
- package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
- package/dist/types/utils/tool/RectUtils.d.ts +4 -0
- package/dist/utils/tool/PolygonUtils.js +1 -1
- package/es/_virtual/highlightWorker.js +1 -1
- package/es/constant/keyCode.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/pointCloud/matrix.js +1 -1
- package/es/core/pointCloud/omniCamera.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +2 -1
- package/es/core/toolOperation/pointCloud2DRectOperation.js +1 -1
- package/es/core/toolOperation/pointOperation.js +1 -1
- package/es/core/toolOperation/polygonOperation.js +1 -1
- package/es/core/toolOperation/rectOperation.js +2 -1
- package/es/core/toolOperation/utils/reCalcRect.js +1 -0
- package/es/index.js +1 -1
- package/es/utils/tool/PolygonUtils.js +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory=require("./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js"),WorkerFactory=_rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory.createBase64WorkerFactory("
|
|
1
|
+
"use strict";var _rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory=require("./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js"),WorkerFactory=_rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory.createBase64WorkerFactory("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwp2YXIgd29ya2VyX2NvZGU9ZnVuY3Rpb24ocCl7InVzZSBzdHJpY3QiO2NvbnN0IHY9Wy0xLC0xLC0xXTtsZXQgST0hMTtmdW5jdGlvbiBCKGUpe2NvbnN0IHQ9LTcsbz0zLG49by10O3JldHVybiBlPHQmJihlPXQpLGU+byYmKGU9byksTWF0aC5mbG9vcigoZS10KS9uKjI1NSl9ZnVuY3Rpb24gRSgpe2xldCBlO2NvbnN0IHQ9bmV3IEFycmF5KDI1NikuZmlsbCgiIikubWFwKCgpPT5uZXcgQXJyYXkoMykuZmlsbCgiIikpO2ZvcihsZXQgbz0wO288MjA7bysrKXtmb3IoZT0wO2U8MzI7ZSsrKXRbZV1bMF09MTI4KzQqZSx0W2VdWzFdPTAsdFtlXVsyXT0wO2Zvcih0WzMyXVswXT0yNTUsdFszMl1bMV09MCx0WzMyXVsyXT0wLGU9MDtlPDYzO2UrKyl0WzMzK2VdWzBdPTI1NSx0WzMzK2VdWzFdPTQrNCplLHRbMzMrZV1bMl09MDtmb3IodFs5Nl1bMF09MjU0LHRbOTZdWzFdPTI1NSx0Wzk2XVsyXT0yLGU9MDtlPDYyO2UrKyl0Wzk3K2VdWzBdPTI1MC00KmUsdFs5NytlXVsxXT0yNTUsdFs5NytlXVsyXT02KzQqZTtmb3IodFsxNTldWzBdPTEsdFsxNTldWzFdPTI1NSx0WzE1OV1bMl09MjU0LGU9MDtlPDY0O2UrKyl0WzE2MCtlXVswXT0wLHRbMTYwK2VdWzFdPTI1Mi1lKjQsdFsxNjArZV1bMl09MjU1O2ZvcihlPTA7ZTwzMjtlKyspdFsyMjQrZV1bMF09MCx0WzIyNCtlXVsxXT0wLHRbMjI0K2VdWzJdPTI1Mi00KmV9cmV0dXJuIHR9Y29uc3QgUj1FKCk7ZnVuY3Rpb24gaChlLHQsbz0wKXtsZXQgbj0wLGEseCxpLGw7dD1bLi4udF0sbz09PTEmJih0PWNyZWF0ZVNtb290aEN1cnZlUG9pbnRzKHQucmVkdWNlKCh5LGMpPT5bLi4ueSxjLngsYy55XSxbXSksLjUsITAsU0VHTUVOVF9OVU1CRVIpKSxbaV09dDtjb25zdCB1PXQubGVuZ3RoO2ZvcihhPTE7YTw9dTthKyspbD10W2EldV0sZS54Pk1hdGgubWluKGkueCxsLngpJiZlLng8PU1hdGgubWF4KGkueCxsLngpJiZlLnk8PU1hdGgubWF4KGkueSxsLnkpJiZpLnghPT1sLngmJih4PShlLngtaS54KSoobC55LWkueSkvKGwueC1pLngpK2kueSwoaS55PT09bC55fHxlLnk8PXgpJiZuKyspLGk9bDtyZXR1cm4gbiUyIT0wfWZ1bmN0aW9uIE8oe3pNaW46ZSx6TWF4OnQscG9seWdvblBvaW50TGlzdDpvLGF0dHJpYnV0ZTpuLHg6YSx5OngsejppLGNvbG9yTGlzdDpsLHZhbGlkOnV9KXtpZihoKHt4OmEseTp4fSxvKSYmaT49ZSYmaTw9dClyZXR1cm4gdT09PSExP1sxLDEwMy8yNTUsMTAyLzI1NV06bFtuXT9sW25dLnJnYmEuc2xpY2UoMCwzKS5tYXAoYz0+Yy8yNTUpOlsxLDAsMF19ZnVuY3Rpb24gbShlKXtjb25zdCB0PUIoZSksbz1SW3RdLFtuLGEseF09bztyZXR1cm5bbi8yNTUsYS8yNTUseC8yNTVdfXJldHVybiBvbm1lc3NhZ2U9ZnVuY3Rpb24odCl7Y29uc3R7cG9zaXRpb246byxjb2xvcjpuLGN1Ym9pZExpc3Q6YSxjb2xvckxpc3Q6eCxoaWdobGlnaHRJbmRleDppfT10LmRhdGE7bGV0e21vZGlmaWVkQm94SWRzOmw9W10scmVzZXRBcmVhczp1PVtdfT10LmRhdGEseT0wO2Z1bmN0aW9uIGMoKXt5Kz0xfWlmKCFvKXJldHVybjtjb25zdCBfPSEhKGk9PW51bGw/dm9pZCAwOmkubGVuZ3RoKTsoX3x8SSkmJihsPVtdLHU9W10pO2NvbnN0IHc9bC5sZW5ndGg/YS5maWx0ZXIocj0+bC5pbmNsdWRlcyhyLmlkKSk6YTtmb3IobGV0IHI9MDtyPG8ubGVuZ3RoO3IrPTMpe2NvbnN0IEM9b1tyXSxMPW9bcisxXSxkPW9bcisyXTtsZXQgZztpZih1Lmxlbmd0aD09PTEmJiFsLmxlbmd0aCloKHt4OkMseTpMfSx1WzBdKT9nPW0oZCk6Zz12O2Vsc2UgaWYodS5sZW5ndGh8fGwubGVuZ3RoKXtsZXQgcz0hMTt3LnNvbWUoZj0+e2NvbnN0IE09Tyh7cG9seWdvblBvaW50TGlzdDpmLnBvbHlnb25Qb2ludExpc3Qsek1pbjpmLnpNaW4sek1heDpmLnpNYXgseDpDLHk6TCx6OmQsYXR0cmlidXRlOmYuYXR0cmlidXRlLGNvbG9yTGlzdDp4LHZhbGlkOmYudmFsaWR9KTtyZXR1cm4gTT8oYygpLGc9TSxzPSEwLCEwKTohMX0pLCFzJiZ1Lmxlbmd0aCYmKHM9dS5zb21lKGY9Pmgoe3g6Qyx5Okx9LGYpPyhnPW0oZCksITApOiExKSksIXMmJiFfJiYoST9nPW0oZCk6Zz12KX1lbHNlIHcuc29tZShzPT57Y29uc3QgZj1PKHtwb2x5Z29uUG9pbnRMaXN0OnMucG9seWdvblBvaW50TGlzdCx6TWluOnMuek1pbix6TWF4OnMuek1heCx4OkMseTpMLHo6ZCxhdHRyaWJ1dGU6cy5hdHRyaWJ1dGUsY29sb3JMaXN0OngsdmFsaWQ6cy52YWxpZH0pO3JldHVybiBmPyhjKCksZz1mLCEwKTohMX0pO2NvbnN0IEE9cz0+e2NvbnN0IGY9TWF0aC5mbG9vcihzLzMpO3JldHVybiBpJiZpW2ZdPT09MX07aWYoZylpZihnWzBdPT09dlswXSYmQShyKSluW3JdPTAsbltyKzFdPTAsbltyKzJdPTA7ZWxzZXtjb25zdFtzLGYsTV09ZztuW3JdPXMsbltyKzFdPWYsbltyKzJdPU19ZWxzZSBpZihBKHIpKW5bcl09MCxuW3IrMV09MCxuW3IrMl09MDtlbHNle2NvbnN0W3MsZixNXT1tKGQpO25bcl09cyxuW3IrMV09ZixuW3IrMl09TX19ST1fLHBvc3RNZXNzYWdlKHtwb2ludHM6byxjb2xvcjpuLG51bTp5fSl9LHAuaXNJblBvbHlnb249aCxPYmplY3QuZGVmaW5lUHJvcGVydHkocCwiX19lc01vZHVsZSIse3ZhbHVlOiEwfSkscH0oe30pOwoK",null,!1);module.exports=WorkerFactory;
|
package/dist/constant/keyCode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var EKeyCode;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace",t[t.Minus=189]="Minus",t[t.Equal=187]="Equal"})(EKeyCode||(EKeyCode={}));var EKeyCode$1=EKeyCode;module.exports=EKeyCode$1;
|
|
1
|
+
"use strict";var EKeyCode;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.P=80]="P",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace",t[t.Minus=189]="Minus",t[t.Equal=187]="Equal"})(EKeyCode||(EKeyCode={}));var EKeyCode$1=EKeyCode;module.exports=EKeyCode$1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(y){if(y&&y.__esModule)return y;var t=Object.create(null);return y&&Object.keys(y).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(y,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return y[e]}})}}),t.default=y,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(y,t,e)=>t in y?__defProp(y,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):y[t]=e,__spreadValues=(y,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(y,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(y,e,t[e]);return y},__spreadProps=(y,t)=>__defProps(y,__getOwnPropDescs(t)),__async=(y,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(n){r(n)}},a=l=>{try{o(e.throw(l))}catch(n){r(n)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,a);o((e=e.apply(y,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:o,checkMode:l}){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.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"sphere");const{radius:p,widthSegments:x,heightSegments:g}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:u}=n,m=new THREE__namespace.Group,f=new THREE__namespace.SphereGeometry(p,x,g),w=new THREE__namespace.MeshBasicMaterial({color:c}),C=new THREE__namespace.Mesh(f,w);C.position.set(u.x,u.y,u.z),m.add(C),m.name=`sphere${d}`,this.scene.add(m)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:h}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,h)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"box");const{center:p,width:x,height:g,depth:u,rotation:m}=n,f=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(x,g,u),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),b=new THREE__namespace.Mesh(w,C),v=new THREE__namespace.BoxHelper(b,c),M=this.generateBoxArrow(n),P=this.generateBoxTrackID(n);P&&f.add(P),f.add(v),f.add(M),p&&f.position.set(p.x,p.y,p.z),m&&f.rotation.set(0,0,m),f.name=`box${d}`,this.scene.add(f)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
2
2
|
attribute vec3 dimensions;
|
|
3
3
|
varying vec3 vDimensions;
|
|
4
4
|
uniform float pointSize;
|
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
|
|
29
29
|
// Output the final color
|
|
30
30
|
gl_FragColor = vec4(color, 1.0);
|
|
31
|
-
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:h,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.filterPreResult=(n,c,h)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),u=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(m=>{const p=h.map(g=>{const y=MathUtils.default.calculatePointsInsideBox({indexMap:u,polygon:matrix.getCuboidFromPointCloudBox(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),x=y>=c.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},g),{valid:x,count:y})});m(p)})}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=h!=null?h:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const b=new THREE__namespace.Points(C.geometry);b.name=this.pointCloudObjectName,this.scene.add(b),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,h,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:o,near:a,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=a,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 THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,a=e.x-i/2-o,s=e.x-i/2+o,l=e.y+r/2+o,n=e.y-r/2-o,c=100,h=-100,d=500/c;return{left:a,right:s,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:a,depth:s,rotation:l}=t,n=this.getCameraVector(r,l,{width:o,height:a,depth:s},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,o,a;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=(a=(o=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:a.array}if(window.Worker){const{zMin:s,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:s,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(h),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,o=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(o);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(o);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(o);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(o);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(o);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(o,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(o,i);break}const s=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),o=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,o);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("workerLoading"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[]){const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!!r)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((o,a)=>{if(window.Worker){const l=(e?[...e]:[]).map(h=>matrix.getCuboidFromPointCloudBox(h)),n=this.getAllAttributeColor(l),c={cuboidList:l,position:r.geometry.attributes.position.array,color:r.geometry.attributes.dimensions.array,colorList:n,highlightIndex:i};this.handleWebworker(c).then(h=>{const{color:d}=h,u=new THREE__namespace.BufferAttribute(d,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||r.geometry.attributes.position.array.length!==d.length){a(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,d),this.highlightPCDSrc=void 0,u.needsUpdate=!0,r.geometry.setAttribute("dimensions",u),r.geometry.attributes.dimensions.needsUpdate=!0,o(d),this.render()}).catch(h=>{a(h)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:o,z:a},width:s,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(s,l,n),u=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,o,a);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(s/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,o+g.y,a+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const o=.005,a=Math.floor(e.length*(1-o));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const s=Math.floor(e.length*o),l=Math.floor(e.length*(1-o));e=e.slice(s,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*o),c=Math.floor(e.length*(1-o));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:o[n].point,line1:[c,h],p2:o[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,o,a;const s=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],u=[];const m=((a=(o=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,h=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:o,width:a,depth:s}=t,l={x:e+a/2,y:i+o/2,z:r-s/2},n={x:e+a/2,y:i+o/2,z:r+s/2},c={x:e-a/2,y:i+o/2,z:r+s/2},h={x:e-a/2,y:i+o/2,z:r-s/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:a,depth:s}=t,l={x:e-a/2,y:i+o/2,z:r+s/2},n={x:e-a/2,y:i+o/2,z:r-s/2},c={x:e-a/2,y:i-o/2,z:r-s/2},h={x:e-a/2,y:i-o/2,z:r+s/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:a,depth:s}=t,l={x:e+a/2,y:i+o/2,z:r+s/2},n={x:e+a/2,y:i-o/2,z:r+s/2},c={x:e-a/2,y:i-o/2,z:r+s/2},h={x:e-a/2,y:i+o/2,z:r+s/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),s=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(o);return new THREE__namespace.Matrix4().multiply(s).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/o;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,s={center:e,attribute:i,id:r,valid:o,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,s=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(a,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(o);let s=r;return s.center={x:s.center.x+a.x,y:s.center.y+a.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const o=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(o);let s=r;return s.center={x:s.center.x+a.x,y:s.center.y+a.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const a=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[l,n,c,h]=s,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(h).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,o=[],{count:a}=r;for(let s=0;s<a;s++){const l=r.getZ(s);o.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:p}=yield this.cacheInstance.loadPCDFile(c),x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||x.setAttribute("dimensions",new THREE__namespace.BufferAttribute(p,3)),this.initCloudData(d);const g=new THREE__namespace.Points(x);this.renderPointCloud(g,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=u=>__async(this,null,function*(){try{return yield ImgUtils.default.load(u)}catch(m){return console.error("Error loading image:",m),null}}),p=c.length===0?[]:(yield Promise.all(c.map(u=>__async(this,null,function*(){let m=yield d(u.url);return!m&&u.fallbackUrl&&(m=yield d(u.fallbackUrl)),m})))).filter(u=>u!==null),x=c.map((u,m)=>{var f;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(f=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?f:[];const w=matrix.getHighlightIndexByPoints({points:h,calib:u.calib,width:p[m].width,height:p[m].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,w),w});return matrix.mergeHighlightList(x)}),this.filterPreResult=(n,c,h)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),p=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(x=>{const g=h.map(u=>{const m=MathUtils.default.calculatePointsInsideBox({indexMap:p,polygon:matrix.getCuboidFromPointCloudBox(u).polygonPointList,zScope:[u.center.z-u.depth/2,u.center.z+u.depth/2],box:u}),f=m>=c.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},u),{valid:f,count:m})});x(g)})}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(g,u)=>__async(this,null,function*(){const{width:m=0,height:f=0,depth:w=0}=h!=null?h:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+m,height:c.height+f,depth:c.depth+w}),g,u);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const b=new THREE__namespace.Points(C.geometry);b.name=this.pointCloudObjectName,this.scene.add(b),this.render()}),{points:p,color:x}=yield this.cacheInstance.loadPCDFile(n);d(p,x)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,p=16776960,x=new THREE__namespace.ArrowHelper(c,h,d,p);return x.visible=this.showDirection,x},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,h=-100,d=500/c;return{left:a,right:o,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const p=new filterBoxWorker;p.postMessage(h),p.onmessage=x=>{const{color:g,position:u,num:m}=x.data,f=new THREE__namespace.BufferGeometry;f.setAttribute("position",new THREE__namespace.Float32BufferAttribute(u,3)),f.setAttribute("color",new THREE__namespace.Float32BufferAttribute(g,3)),f.computeBoundingSphere(),p.terminate(),d({geometry:f,num:m})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:s,resetAreas:a}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,n)=>{if(window.Worker){const h=(e?[...e]:[]).map(u=>matrix.getCuboidFromPointCloudBox(u)),d=this.getAllAttributeColor(h),p=o.geometry.attributes.position.array,x=o.geometry.attributes.dimensions.array,g={cuboidList:h,position:p,color:x,colorList:d,highlightIndex:i,modifiedBoxIds:s,resetAreas:a};this.handleWebworker(g).then(u=>{const{color:m}=u;let f=m;(s.length||a.length)&&(f=m.map((C,b)=>C===-1?x[b]:C));const w=new THREE__namespace.BufferAttribute(f,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==m.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,f),this.highlightPCDSrc=void 0,w.needsUpdate=!0,o.geometry.setAttribute("dimensions",w),o.geometry.attributes.dimensions.needsUpdate=!0,l(f),this.render()}).catch(u=>{n(u)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),p=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const x=new THREE__namespace.Mesh(d,p);e.add(x);const g=new THREE__namespace.PlaneGeometry(n,l);g.rotateY(Math.PI/2),g.rotateZ(c);const u=new THREE__namespace.Vector3(o/2,0,0),m=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);u.applyMatrix4(m),g.translate(r+u.x,s+u.y,a+u.z);const f=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(g,f);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],p=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||p<i[h].distance)&&(i[h]={distance:p,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(g=>g.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],p=[];const x=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let g=0;g<x.length;g+=3){const u=x[g],m=x[g+1],f=x[g+2];polygonTool.isInPolygon({x:u,y:m},t)&&(f||f===0)&&p.push({x:u,y:m,z:f})}return p.length?(i&&(p=this.filterNoise(p),d=this.getFittedCoordinates(t,p)),p.sort((g,u)=>g.z-u.z),l=p[0].z-.01,n=p[p.length-1].z+.01,h=p.length,e&&(c=p.filter(({z:g})=>g>=e[0]&&g<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r-o/2},n={x:e+a/2,y:i+s/2,z:r+o/2},c={x:e-a/2,y:i+s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r-o/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2},c={x:e-a/2,y:i-s/2,z:r-o/2},h={x:e-a/2,y:i-s/2,z:r+o/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r+o/2},n={x:e+a/2,y:i-s/2,z:r+o/2},c={x:e-a/2,y:i-s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r+o/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),x=n.add(h).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-x.x,y:r.center.y-x.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),uuid=require("../../utils/uuid.js"),omniCamera=require("./omniCamera.js");function _interopNamespace(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if(r!=="default"){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));function createThreeMatrix4(e){return new THREE__namespace.Matrix4().set(...e)}function transferKitti2Matrix(e,t,r){try{const n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(e),i=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(t),o=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r),l=createThreeMatrix4(n),f=createThreeMatrix4(i),a=createThreeMatrix4(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function rotatePoint(e,t,r){var n;const i=new THREE__namespace.Vector3(e.x,e.y,(n=e==null?void 0:e.z)!=null?n:1),o=new THREE__namespace.Matrix4().makeRotationZ(r),l=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(l)}function isMatrixValid(e,t,r){return!(e.length!==t||e.some(n=>n.length!==r))}const isMatrixValidByArr=(e,t)=>t.some(r=>isMatrixValid(e,r[0],r[1])),isFisheyeCalibValid=e=>{var t;return!!(((t=e.fisheyeDistortion)==null?void 0:t.length)>0&&isMatrixValidByArr(e.P,[[3,4],[4,4]])&&isMatrixValidByArr(e.T,[[3,4],[4,4]]))},oCamFisheyeTransfer=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:i}=t,o=new THREE__namespace.Vector4(e.x,e.y,e.z),l=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(i)),f=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r)),a=o.applyMatrix4(l),x=__pow(__pow(a.x,2)+__pow(a.y,2),.5),p=Math.atan(a.z/x),s=n.reduce((c,u,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),uuid=require("../../utils/uuid.js"),omniCamera=require("./omniCamera.js");function _interopNamespace(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if(r!=="default"){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));function createThreeMatrix4(e){return new THREE__namespace.Matrix4().set(...e)}function transferKitti2Matrix(e,t,r){try{const n=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(e),i=lbUtils.MatrixUtils.transferMatrix33FromKitti2Three(t),o=lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r),l=createThreeMatrix4(n),f=createThreeMatrix4(i),a=createThreeMatrix4(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function rotatePoint(e,t,r){var n;const i=new THREE__namespace.Vector3(e.x,e.y,(n=e==null?void 0:e.z)!=null?n:1),o=new THREE__namespace.Matrix4().makeRotationZ(r),l=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),f=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(l)}function isMatrixValid(e,t,r){return!(e.length!==t||e.some(n=>n.length!==r))}const isMatrixValidByArr=(e,t)=>t.some(r=>isMatrixValid(e,r[0],r[1])),isFisheyeCalibValid=e=>{var t;return!!(((t=e.fisheyeDistortion)==null?void 0:t.length)>0&&isMatrixValidByArr(e.P,[[3,4],[4,4]])&&isMatrixValidByArr(e.T,[[3,4],[4,4]]))},oCamFisheyeTransfer=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:i}=t,o=new THREE__namespace.Vector4(e.x,e.y,e.z),l=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(i)),f=createThreeMatrix4(lbUtils.MatrixUtils.transferMatrix34FromKitti2Three(r)),a=o.applyMatrix4(l),x=__pow(__pow(a.x,2)+__pow(a.y,2),.5),p=Math.atan(a.z/x),s=n.reduce((c,u,h)=>c+u*__pow(p,h),0);return a.x=a.x/x*s,a.y=a.y/x*s,a.z=1,a.applyMatrix4(f)},omniCamera11VTransfer=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:r,fisheyeDistortion:n,T:i}=t,o=omniCamera.transformPointCloudToImage([[e.x,e.y,e.z]],i,r,n);return new THREE__namespace.Vector4(o[0][0],o[0][1],1)},kbCamFisheyeTransfer=(e,t)=>{const{P:r,T:n,fisheyeDistortion:i}=t,o=[e.x,e.y,e.z,1],l=n.map(g=>g.reduce((M,v,_)=>M+v*o[_],0)),f=l[0],a=l[1],x=l[2];if(!(x>=.01&&isFinite(x)))return;const p=[[r[0][0],r[0][1]],[r[1][0],r[1][1]]],s=r[0][2],y=r[1][2],c=Math.sqrt(f*f+a*a),u=Math.atan2(c,x),h=u+i.reduce((g,M,v)=>g+M*Math.pow(u,2*v+3),0);let m,d;c!==0?(m=f*h/c,d=a*h/c):(m=0,d=0);const T=p[0][0]*m+p[0][1]*d,P=p[1][0]*m+p[1][1]*d;return{x:T+s,y:P+y}},lidar2FisheyeImage=(e,t)=>{if(isFisheyeCalibValid(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.OmniCamera)return oCamFisheyeTransfer(e,t);if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.KannalaBrandt)return kbCamFisheyeTransfer(e,t);if((t==null?void 0:t.cameraType)===lbUtils.ECameraType.OmniCamera11V)return omniCamera11VTransfer(e,t)};function lidar2image(e,t){const n=new THREE__namespace.Vector4(e.x,e.y,e.z).applyMatrix4(t);if(n.z<0)return;const i=1/n.z,o=new THREE__namespace.Matrix4().set(i,0,0,0,0,i,0,0,0,0,i,0,0,0,0,1);return n.applyMatrix4(o)}function getCuboidFromPointCloudBox(e){const{center:t,width:r,height:n,depth:i,rotation:o}=e,l=[{x:t.x+r/2,y:t.y-n/2},{x:t.x+r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y+n/2},{x:t.x-r/2,y:t.y-n/2}].map(x=>{const p=rotatePoint(x,t,o);return{x:p.x,y:p.y}}),f=t.z+i/2,a=t.z-i/2;return __spreadProps(__spreadValues({},e),{polygonPointList:l,zMax:f,zMin:a})}function sortPoints(e){const t=e.slice();return t.sort((r,n)=>r.x===n.x?n.y-r.y:r.x-n.x),t}function crossProduct(e,t,r){const n=t.x-e.x,i=t.y-e.y,o=r.x-e.x,l=r.y-e.y;return n*l-o*i}function buildConvexHull(e){const t=sortPoints(e),r=[];for(let o=0;o<t.length;o++){for(;r.length>=2&&crossProduct(r[r.length-2],r[r.length-1],t[o])<=0;)r.pop();r.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&crossProduct(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return r.pop(),n.pop(),r.concat(n)}const point3DLidar2Image=(e,t)=>{var r;if(isFisheyeCalibValid(t))return lidar2FisheyeImage(e,t);const{P:n,R:i,T:o}=t,{composeMatrix4:l}=(r=transferKitti2Matrix(n,i,o))!=null?r:{};if(!!l)return lidar2image(e,l)},isInImage=({point:e,calib:t,width:r,height:n})=>{if(!t)return!1;const i=point3DLidar2Image(e,t);return i?i.x>=0&&i.x<=r&&i.y>=0&&i.y<=n:!1},getHighlightIndexByPoints=({points:e,calib:t,width:r,height:n})=>{const i=[];for(let o=0;o<e.length;o+=3){const l=e[o],f=e[o+1],a=e[o+2];isInImage({point:{x:l,y:f,z:a},calib:t,width:r,height:n})?i.push(1):i.push(0)}return i},mergeHighlightList=e=>{if(e.length===0)return[];const t=[];for(let r=0;r<e[0].length;r++){for(let n=0;n<e.length;n++)if(e[n][r]===1){t.push(1);break}t.length===r&&t.push(0)}return t};function pointCloudLidar2image(e,t,r={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:i}=r,o=lbUtils.PointCloudUtils.getAllViewData(e),l=isFisheyeCalibValid(t),{P:f,R:a,T:x}=t;let p;if(l===!1){const{composeMatrix4:c}=(n=transferKitti2Matrix(f,a,x))!=null?n:{};if(!c)return;p=c}const s=o.map(c=>({type:c.type,pointList:c.pointList.map(u=>rotatePoint(u,e.center,e.rotation)).map(u=>l?lidar2FisheyeImage(u,t):p&&lidar2image(u,p)).map(u=>{if(!!u)return{id:uuid(),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);s[0]&&s[0].pointList&&(s[0].pointList=s[0].pointList.map(c=>__spreadProps(__spreadValues({},c),{specialEdge:!0})));let y=[];if(s.length===6&&i===!0){const c=s[0].pointList,u=s[1].pointList;y=buildConvexHull([...c,...u])}return{transferViewData:s,viewRangePointList:y}}function pointMappingLidar2image(e,t,r){var n;const i=isFisheyeCalibValid(t),{P:o,R:l,T:f}=t;let a;if(i===!1){const{composeMatrix4:s}=(n=transferKitti2Matrix(o,l,f))!=null?n:{};if(!s)return;a=s}const x=e.length/3,p={};for(let s=0;s<x;s++){const y={x:e[s*3],y:e[s*3+1],z:e[s*3+2]};let c;if(i?c=lidar2FisheyeImage(y,t):c=a&&lidar2image({x:e[s*3],y:e[s*3+1],z:e[s*3+2]},a),c){const u=Math.floor(c.x),h=Math.floor(c.y);if(u>r.width||h>r.height||u<0||h<0)continue;p[s]={x:u,y:h}}}return{pcdMapping:p}}function pointListLidar2Img(e,t,r){var n;if(!t||!r)return;const i=isFisheyeCalibValid(t),{P:o,R:l,T:f}=t;let a;if(i===!1){const{composeMatrix4:s}=(n=transferKitti2Matrix(o,l,f))!=null?n:{};if(!s)return;a=s}const x=[];if(e.forEach(s=>{let y;if(i?y=lidar2FisheyeImage(s,t):y=a&&lidar2image(s,a),y){const{x:c,y:u}=y;x.push({x:c,y:u})}}),x.some(s=>s.x>0&&s.x<r.width&&s.y>0&&s.y<r.height))return x}exports.createThreeMatrix4=createThreeMatrix4,exports.getCuboidFromPointCloudBox=getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=getHighlightIndexByPoints,exports.isFisheyeCalibValid=isFisheyeCalibValid,exports.isInImage=isInImage,exports.isMatrixValid=isMatrixValid,exports.isMatrixValidByArr=isMatrixValidByArr,exports.lidar2FisheyeImage=lidar2FisheyeImage,exports.lidar2image=lidar2image,exports.mergeHighlightList=mergeHighlightList,exports.oCamFisheyeTransfer=oCamFisheyeTransfer,exports.omniCamera11VTransfer=omniCamera11VTransfer,exports.point3DLidar2Image=point3DLidar2Image,exports.pointCloudLidar2image=pointCloudLidar2image,exports.pointListLidar2Img=pointListLidar2Img,exports.pointMappingLidar2image=pointMappingLidar2image,exports.rotatePoint=rotatePoint,exports.transferKitti2Matrix=transferKitti2Matrix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var math=require("mathjs");function _interopNamespace(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if(n!=="default"){var o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}var math__namespace=_interopNamespace(math);function convertMatrix(t){if(t.length!==1||t[0].length!==3)throw new Error("Input matrix must be a 1x3 or 3x1 matrix");return[[t[0][0]],[t[0][1]],[t[0][2]],[1]]}function normOfRows(t){const e=[];for(let n=0;n<t.length;n++){const o=t[n],r=o[0]*o[0]+o[1]*o[1],s=Math.sqrt(r);e.push(s)}return e}function polyVal(t,e){const n=t.length,o=[];for(let r=0;r<e.length;r++){let s=0;for(let u=0;u<t.length;u++)s=t[n-u-1]+s*e[r];o.push(s)}return o}function fisheyeCameraToImage(t,e,n){const o=math__namespace.matrix([[e[0][0],e[0][1]],[e[1][0],e[1][1]]]),r=e[0][2],s=e[1][2],u=n,i=normOfRows(t.toArray().map(d=>d.slice(0,2))),a=math__namespace.dotDivide(math__namespace.ones(math__namespace.matrix(i).size()),i),m=math__namespace.atan2(math__namespace.multiply(-1,t.subset(math__namespace.index(math__namespace.range(0,math__namespace.matrix(t).size()[0]),2))),i),c=polyVal(u,m);let l=math__namespace.ones(2,t.size()[0]);const g=math__namespace.multiply(t.subset(math__namespace.index(math__namespace.range(0,t.size()[0]),0)),a*c),h=math__namespace.multiply(t.subset(math__namespace.index(math__namespace.range(0,t.size()[0]),1)),a*c),f=math__namespace.matrix([[g,0],[h,0]]);l=math__namespace.subset(f,math__namespace.index(math__namespace.range(0,f.size()[0]),0));const x=math__namespace.matrix([r,s]),p=math__namespace.multiply(o,l),y=x.reshape([2,1]);return math__namespace.transpose(math__namespace.add(p,y)).toArray()}function transformPointCloudToImage(t=[],e,n,o){const r=math__namespace.matrix(convertMatrix(t)),s=math__namespace.matrix(e),u=math__namespace.multiply(s,r);return fisheyeCameraToImage(math__namespace.transpose(u),n,o)}exports.transformPointCloudToImage=transformPointCloudToImage;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t)),__async=(v,t,e)=>new Promise((i,o)=>{var r=a=>{try{s(e.next(a))}catch(n){o(n)}},c=a=>{try{s(e.throw(a))}catch(n){o(n)}},s=a=>a.done?i(a.value):Promise.resolve(a.value).then(r,c);s((e=e.apply(v,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=i=>{var o,r;const c=this.getCoordinateUnderZoom(i),s=AxisUtils.default.changePointByZoom(c,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",n=Number.MAX_SAFE_INTEGER;for(let h=0;h<this.annotations.length;h++){const l=this.annotations[h];switch(l.type){case"rect":{const d=l.annotation;if(RectUtils.isInRect(c,d,newScope,this.zoom)){const f=d.width*d.height;f<n&&(a=d.id,n=f)}break}case"polygon":{const d=l.annotation;if(PolygonUtils.isInPolygon(s,d.pointList)){const f=PolygonUtils.getPolygonArea(d.pointList);f<n&&(a=d.id,n=f)}break}}}return a};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:c}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(s=>{this.connectionPoints=s.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:s.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,c=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";return!t||e===!0?{headerText:i,bottomText:o}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/c*o.innerZoom,height:r.height/c*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=tool.ELineTypes.Line}=s,n=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos),h=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:a,strokeColor:r.stroke});let l=[];if(s.showKeyPoint?l=DrawUtils.drawPolygonWithKeyPoint(this.canvas,n,h):l=DrawUtils.drawPolygon(this.canvas,n,h),(s==null?void 0:s.showDirection)===!0&&((o=s==null?void 0:s.pointList)==null?void 0:o.length)>=2){let g=n[0],y=MathUtils.default.getLineCenterPoint([n[0],n[1]]);if(a===tool.ELineTypes.Curve){const u=Math.floor(tool.SEGMENT_NUMBER/2);g=l[u],y=l[u+1]}DrawUtils.drawArrowByCanvas(this.canvas,g,y,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,n[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(f&&DrawUtils.drawText(this.canvas,this.appendOffset(n[0]),f,c),p){const g=n[n.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:g.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:g.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,c)}}renderPolygon(t){var e,i,o,r,c;if(t.type!=="polygon")return;const{style:s,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:h=tool.ELineTypes.Line}=n,l=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||s.fill){const u=rgba__default.default((r=(o=s==null?void 0:s.fill)!=null?o:s==null?void 0:s.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${u[0]}, ${u[1]}, ${u[2]},${u[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,l,{color:m,lineType:h})}const d=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},s),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:s.stroke});let f=[];if(n.showKeyPoint?f=DrawUtils.drawPolygonWithKeyPoint(this.canvas,l,d):f=DrawUtils.drawPolygon(this.canvas,l,d),(n==null?void 0:n.showDirection)===!0&&((c=n==null?void 0:n.pointList)==null?void 0:c.length)>=2){let u=l[0],m=MathUtils.default.getLineCenterPoint([l[0],l[1]]);if(h===tool.ELineTypes.Curve){const P=Math.floor(tool.SEGMENT_NUMBER/2);u=f[P],m=f[P+1]}DrawUtils.drawArrowByCanvas(this.canvas,u,m,{color:s.stroke,thickness:s.thickness}),DrawUtils.drawCircle(this.canvas,l[0],s.thickness+6,{color:s.stroke,thickness:s.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(g&&DrawUtils.drawText(this.canvas,this.appendOffset(l[0]),g,a),y){const u=l[l.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:u.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:u.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,c=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),s=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,a=o.stroke,n=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:l}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,n,{strokeColor:a,fillColor:s,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:h,bottomText:l})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},c=___default.default.pick(i,["stroke","thickness"]);o.forEach((s,a)=>{const n=__spreadValues(__spreadProps(__spreadValues({},c),{id:`${t.annotation.id}-${a}`,pointList:s.pointList}),r);switch(s.type){case"line":this.renderLine({type:"line",annotation:n});break;case"polygon":this.renderPolygon({type:"polygon",annotation:n});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:s,canvas:a}=CanvasUtils.createCanvas(c),n=typeof t.pixelSize=="number"?t.pixelSize:13;s&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:a,points:i,size:c,defaultRGBA:t.defaultRGBA,pixelSize:n}),DrawUtils.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:a})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,c,s;const a=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:l=!1,isReference:d,hiddenRectSize:f=!1}=h,{zoom:p}=this,g=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:y,y:u,width:m,height:P}=g,x=rgba__default.default((o=(i=a==null?void 0:a.fill)!=null?i:a==null?void 0:a.stroke)!=null?o:DEFAULT_STROKE_COLOR),w=`rgba(${x[0]}, ${x[1]}, ${x[2]},${x[3]*.8})`;(h.id===this.mouseHoverID||a.fill)&&DrawUtils.drawRectWithFill(this.canvas,g,{color:w}),DrawUtils.drawRect(this.canvas,g,__spreadValues(__spreadProps(__spreadValues({},a),{hiddenText:!0}),this.getReferenceOptions(d))),(h==null?void 0:h.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:w,position:{x:y-16,y:u-16}});const{headerText:T,bottomText:I}=this.getRenderText(h,h==null?void 0:h.hiddenText);T&&DrawUtils.drawText(this.canvas,{x:y,y:u-6},T,__spreadValues({textMaxWidth:300},n));const b=`${Math.round(m/p)} * ${Math.round(P/p)}`,S=b.length*7;if(!l&&!f&&DrawUtils.drawText(this.canvas,{x:y+m-S,y:u+P+15},b,n),I){const k=20,C=Math.max(20,m-S);DrawUtils.drawText(this.canvas,{x:y,y:u+P+k},h.textAttribute,__spreadValues({textMaxWidth:C},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,l=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),d=(r=a.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,l,d,a);const{headerText:f,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);f&&DrawUtils.drawText(this.canvas,{x:l.x+d/2,y:l.y-d-4},f,__spreadValues({textAlign:"center"},n)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:l.x+d,y:l.y+d+24}),p,n);break}case"text":{const h=e.annotation,{text:l,x:d,y:f,textMaxWidth:p,color:g="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:u=25,font:m=tool.DEFAULT_FONT,position:P}=h,x=10,w=10,T=AxisUtils.default.changePointByZoom({x:d,y:f},this.zoom,this.currentPos),{width:I,height:b,fontHeight:S=0}=MathUtils.default.getTextArea(this.canvas,h.text,p,m,u);if(P==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:I+w*2,height:b+x*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:T.x+w,y:T.y+S+x},l,{color:g,lineHeight:u,font:m,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}module.exports=ViewOperation;
|
|
1
|
+
"use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),TagUtils=require("../../utils/tool/TagUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(g){return g&&typeof g=="object"&&"default"in g?g:{default:g}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,o)=>{var r=l=>{try{n(e.next(l))}catch(s){o(s)}},a=l=>{try{n(e.throw(l))}catch(s){o(s)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(r,a);n((e=e.apply(g,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=i=>{var o,r;const a=this.getCoordinateUnderZoom(i),n=AxisUtils.default.changePointByZoom(a,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let l="",s=Number.MAX_SAFE_INTEGER;for(let u=0;u<this.annotations.length;u++){const h=this.annotations[u];switch(h.type){case"rect":{const c=h.annotation;if(RectUtils.isInRect(a,c,newScope,this.zoom)){const d=c.width*c.height;d<s&&(l=c.id,s=d)}break}case"polygon":{const c=h.annotation;if(PolygonUtils.isInPolygon(n,c.pointList)){const d=PolygonUtils.getPolygonArea(c.pointList);d<s&&(l=c.id,s=d)}break}}}return l};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:a}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}setConfig(t){this.config=t}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,a=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";if(!t||e===!0)return{headerText:i,bottomText:o};(t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute);const{secondaryAttributeConfigurable:r,subAttributeList:a}=this.config;return(t==null?void 0:t.subAttribute)&&r&&a&&TagUtils.getTagNameList(t==null?void 0:t.subAttribute,a).forEach(l=>{i+=`
|
|
2
|
+
${l.keyName}: ${l.value.join("\u3001")}`}),{headerText:i,bottomText:o}}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/a*o.innerZoom,height:r.height/a*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:l=tool.ELineTypes.Line}=n,s=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos),u=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:l,strokeColor:r.stroke});let h=[];if(n.showKeyPoint?h=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,u):h=DrawUtils.drawPolygon(this.canvas,s,u),(n==null?void 0:n.showDirection)===!0&&((o=n==null?void 0:n.pointList)==null?void 0:o.length)>=2){let v=s[0],p=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(l===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=h[f],p=h[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,p,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:d,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(d&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),d,a),y){const v=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:v.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:v.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderPolygon(t){var e,i,o,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:l}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:u=tool.ELineTypes.Line}=s,h=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const f=rgba__default.default((r=(o=n==null?void 0:n.fill)!=null?o:n==null?void 0:n.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,h,{color:m,lineType:u})}const c=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:u,strokeColor:n.stroke});let d=[];if(s.showKeyPoint?d=DrawUtils.drawPolygonWithKeyPoint(this.canvas,h,c):d=DrawUtils.drawPolygon(this.canvas,h,c),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let f=h[0],m=MathUtils.default.getLineCenterPoint([h[0],h[1]]);if(u===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=d[x],m=d[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,h[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(h[0]),v,l),p){const f=h[h.length-2];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,l)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,a=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,l=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:u,bottomText:h}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:l,fillColor:n,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:u,bottomText:h})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},a=___default.default.pick(i,["stroke","thickness"]);o.forEach((n,l)=>{const s=__spreadValues(__spreadProps(__spreadValues({},a),{id:`${t.annotation.id}-${l}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:l}=CanvasUtils.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:l,points:i,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),DrawUtils.drawImg(this.canvas,l,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:l})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,a,n,l,s;const u=this.getSpecificStyle(e.annotation),h=this.getFontStyle(e.annotation,u);switch(e.type){case"rect":{const c=e.annotation,{hiddenText:d=!1,isReference:y,hiddenRectSize:v=!1}=c,{zoom:p}=this,f=AxisUtils.default.changeRectByZoom(c,this.zoom,this.currentPos),{x:m,y:x,width:w,height:b}=f,P=rgba__default.default((o=(i=u==null?void 0:u.fill)!=null?i:u==null?void 0:u.stroke)!=null?o:DEFAULT_STROKE_COLOR),S=`rgba(${P[0]}, ${P[1]}, ${P[2]},${P[3]*.8})`;(c.id===this.mouseHoverID||u.fill)&&DrawUtils.drawRectWithFill(this.canvas,f,{color:S}),DrawUtils.drawRect(this.canvas,f,__spreadValues(__spreadProps(__spreadValues({},u),{hiddenText:!0}),this.getReferenceOptions(y))),(c==null?void 0:c.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:S,position:{x:m-16,y:x-16}});const{headerText:I,bottomText:T}=this.getRenderText(c,c==null?void 0:c.hiddenText);I&&DrawUtils.drawText(this.canvas,{x:m,y:x-6},I,__spreadValues({textMaxWidth:300},h));const k=`${Math.round(w/p)} * ${Math.round(b/p)}`,C=k.length*7;if(!d&&!v&&DrawUtils.drawText(this.canvas,{x:m+w-C,y:x+b+15},k,h),T){const E=20,R=Math.max(20,w-C);DrawUtils.drawText(this.canvas,{x:m,y:x+b+E},c.textAttribute,__spreadValues({textMaxWidth:R},h))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const c=e.annotation,d=AxisUtils.default.changePointByZoom(c,this.zoom,this.currentPos),y=(r=u.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,d,y,u);const{headerText:v,bottomText:p}=this.getRenderText(c,c==null?void 0:c.hiddenText);v&&DrawUtils.drawText(this.canvas,{x:d.x+y/2,y:d.y-y-4},v,__spreadValues({textAlign:"center"},h)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:d.x+y,y:d.y+y+24}),p,h);break}case"text":{const c=e.annotation,{text:d,x:y,y:v,textMaxWidth:p,color:f="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:x=25,font:w=tool.DEFAULT_FONT,position:b,offset:P}=c,S=10,I=10,T=AxisUtils.default.changePointByZoom({x:y,y:v},this.zoom,this.currentPos);P&&(T.x+=(a=P.x)!=null?a:0,T.y+=(n=P.y)!=null?n:0);const{width:k,height:C,fontHeight:E=0}=MathUtils.default.getTextArea(this.canvas,c.text,p,w,x);if(b==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:k+I*2,height:C+S*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),DrawUtils.drawText(this.canvas,{x:T.x+I,y:T.y+E+S},d,{color:f,lineHeight:x,font:w,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(l=e.annotation).renderEnhance)==null||s.call(l,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}module.exports=ViewOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var rectOperation=require("./rectOperation.js");class PointCloud2DRectOperation extends rectOperation.RectOperation{constructor(e){super(e);this.checkMode=e.checkMode}createNewDrawingRect(){}deleteSelectedRect(){}
|
|
1
|
+
"use strict";var keyCode=require("../../constant/keyCode.js"),rectOperation=require("./rectOperation.js"),reCalcRect=require("./utils/reCalcRect.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloud2DRectOperation extends rectOperation.RectOperation{constructor(e){super(e);this.checkMode=e.checkMode}createNewDrawingRect(e,t){this.checkMode||super.createNewDrawingRect(e,t)}deleteSelectedRect(e){if(this.checkMode)return;const{selectedRects:t}=this;t.length&&e.stopPropagation(),this.emit("deleteSelectedRects",t)}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.setSelectedRectID(this.drawingRect.id),this.emit("afterAddingDrawingRect",__spreadValues({},this.selectedRect)))}setSelectedRectID(e){this.checkMode||super.setSelectedRectID(e)}onKeyDown(e){if(this.checkMode||![keyCode.Delete,keyCode.R].includes(e.keyCode))return;super.onKeyDown(e);const{keyCode:t,ctrlKey:s,altKey:c,shiftKey:i,metaKey:n}=e;switch(t){case keyCode.R:{if(s||c||i||n)return;this.resizeRect();break}}return!0}renderDrawingRect(e,t=this.zoom,s=!1){const c=(e==null?void 0:e.boxID)||(e==null?void 0:e.lineDash);super.renderDrawingRect(c?e:__spreadProps(__spreadValues({},e),{lineDash:[3]}),t,s)}resizeRect(e=100,t=100){var s;if(!this.imgNode||!((s=this.selectedRects)==null?void 0:s.length)||e<=0||t<=0||this.selectedRects[0].width<=e&&this.selectedRects[0].height<=t)return;const{width:c,height:i}=this.basicImgInfo,n={width:c,height:i,x:0,y:0},a=reCalcRect(this.selectedRects[0],n,e,t);a.noChange||(this.setRectList(this.rectList.map(o=>this.selectedIDs.includes(o.id)?__spreadValues(__spreadValues({},o),a):o),!0),this.render(),this.updateDragResult())}}module.exports=PointCloud2DRectOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _=require("lodash"),tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(l){return l&&typeof l=="object"&&"default"in l?l:{default:l}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const r=this.config.markerList[s].value,n=this.currentPageResult.find(o=>o.label===r);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(AttributeUtils.default.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const o=AxisUtils.default.changePointByZoom(n,this.zoom);return MathUtils.default.getLineLength(o,r)<.2})};var e,i;this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new Selection(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=CommonToolUtils.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=CommonToolUtils.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 AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.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=>__spreadProps(__spreadValues({},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=annotation.EDragStatus.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:___default.default.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(t),this.dragStatus===annotation.EDragStatus.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const o={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(o);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(o=>{o.id===this.selectedID&&(o.x=n.x,o.y=n.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,r;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const o=CommonToolUtils.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[tool.EToolName.Polygon,tool.EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const g=((i=this.referenceData)==null?void 0:i.toolName)===tool.EToolName.Polygon,{dropFoot:f,hasClosed:v}=PolygonUtils.getClosestPoint(d,this.referenceData.result,(r=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?r:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:g});f&&(d=f),v&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let h=!1;switch(this.dependToolName){case tool.EToolName.Rect:{h=!RectUtils.isInRect(d,this.basicResult);break}case tool.EToolName.Polygon:{h=!PolygonUtils.isInPolygon(d,this.basicResult.pointList);break}}if(h)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let a=__spreadProps(__spreadValues({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:o,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,o)))+1});if(this.config.textConfigurable){let h="";h=AttributeUtils.default.getTextAttribute(this.pointList.filter(g=>CommonToolUtils.isSameSourceID(g.sourceID,o)),this.config.textCheckType),a=__spreadProps(__spreadValues({},a),{textAttribute:h})}if(this.hasMarkerConfig){const h=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)a=__spreadProps(__spreadValues({},a),{label:h.label}),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=a.id;const c=[...this.pointList,a];this.setPointList(c),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(c),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.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=CommonToolUtils.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let r=[...i];s&&(r=[...r,...s]);const n=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.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===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.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(r=>r.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=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.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(g=>g.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:n,valid:o}=i,u=TEXTAREA_WIDTH*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),a=this.getColor(n),c=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,h=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:u,container:this.container,icon:this.getTextIconSvg(n),color:c,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:d.x,top:d.y+h,color:c,width:u})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:n="",attribute:o}=t,u=e||t.id===this.selectedID,d=this.getColor(o),a=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:h=!1}=this.style,g=StyleUtils.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,a,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:g.stroke,fill:g.fill});let f="";(((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&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(f=`${f} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),h||DrawUtils.drawText(this.canvas,{x:a.x+c/2,y:a.y-c-4},f,{textAlign:"center",color:g.stroke}),u?this.renderTextAttribute():h||DrawUtils.drawText(this.canvas,{x:a.x+c,y:a.y+c+24},n,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.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]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const r=MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList,"value");MarkerUtils.getAuxiliaryLineCoord(r,s).forEach(o=>{const{start:u,end:d}=o,a=AxisUtils.default.changePointListByZoom([u,d],this.zoom,this.currentPos);DrawUtils.drawLine(this.canvas,a[0],a[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===tool.EToolName.Polygon,{dropFoot:o}=PolygonUtils.getClosestPoint(r,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:n});o&&r!==o&&r!==o&&(r=o,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
|
|
1
|
+
"use strict";var _=require("lodash"),tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(l){return l&&typeof l=="object"&&"default"in l?l:{default:l}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const r=this.config.markerList[s].value,n=this.currentPageResult.find(h=>h.label===r);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(AttributeUtils.default.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const h=AxisUtils.default.changePointByZoom(n,this.zoom);return MathUtils.default.getLineLength(h,r)<.2})};var e,i;this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new Selection(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=CommonToolUtils.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=CommonToolUtils.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 AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.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=>__spreadProps(__spreadValues({},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=annotation.EDragStatus.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:___default.default.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.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===annotation.EDragStatus.Move){const i=this.pointList.find(s=>(s==null?void 0:s.id)===this.selectedID);if(i){const{newPoint:s,hasClosed:r}=this.getNearPoint(i);s&&Object.assign(i,s),r&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.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=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const h={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(h);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(h=>{h.id===this.selectedID&&(h.x=n.x,h.y=n.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this));const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.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 r=[tool.EToolName.Polygon,tool.EToolName.Line].includes(this.dependToolName),n=[this.basicResult];if(r){const h=this.dependToolName===tool.EToolName.Polygon,{dropFoot:a,hasClosed:d}=PolygonUtils.getClosestPoint(t,n,(s=(i=(e=this.referenceData)==null?void 0:e.config)==null?void 0:i.lineType)!=null?s:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:h});return{newPoint:a,hasClosed:d}}}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",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const i=CommonToolUtils.getSourceID(this.basicResult),s=this.getCoordinateUnderZoom(t);let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const{newPoint:n,hasClosed:h}=this.getNearPoint(r);if(n&&(r=n),h&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`),this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let o=!1;switch(this.dependToolName){case tool.EToolName.Rect:{o=!RectUtils.isInRect(r,this.basicResult);break}case tool.EToolName.Polygon:{o=!PolygonUtils.isInPolygon(r,this.basicResult.pointList);break}}if(o)return}if(s.x<0||s.y<0||s.x>this.imgInfo.width||s.y>this.imgInfo.height)return}if(this.isMinDistance(r))return;let a=__spreadProps(__spreadValues({},r),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:i,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,i)))+1});if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.pointList.filter(u=>CommonToolUtils.isSameSourceID(u.sourceID,i)),this.config.textCheckType),a=__spreadProps(__spreadValues({},a),{textAttribute:o})}if(this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)a=__spreadProps(__spreadValues({},a),{label:o.label}),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=a.id;const d=[...this.pointList,a];this.setPointList(d),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(d),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.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=CommonToolUtils.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let r=[...i];s&&(r=[...r,...s]);const n=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.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===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.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(r=>r.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=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.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(c=>c.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:n,valid:h}=i,a=TEXTAREA_WIDTH*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),o=this.getColor(n),u=h?o==null?void 0:o.valid.stroke:o==null?void 0:o.invalid.stroke,f=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:a,container:this.container,icon:this.getTextIconSvg(n),color:u,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:d.x,top:d.y+f,color:u,width:a})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:n="",attribute:h}=t,a=e||t.id===this.selectedID,d=this.getColor(h),o=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:u=2,hiddenText:f=!1}=this.style,c=StyleUtils.getStrokeAndFill(d,t.valid,{isSelected:a||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,o,u,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:c.stroke,fill:c.fill});let g="";(((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&&(g=`${t.order}`),t.label&&this.hasMarkerConfig&&(g=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),f||DrawUtils.drawText(this.canvas,{x:o.x+u/2,y:o.y-u-4},g,{textAlign:"center",color:c.stroke}),a?this.renderTextAttribute():f||DrawUtils.drawText(this.canvas,{x:o.x+u,y:o.y+u+24},n,__spreadValues({color:c.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.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]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const r=MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList,"value");MarkerUtils.getAuxiliaryLineCoord(r,s).forEach(h=>{const{start:a,end:d}=h,o=AxisUtils.default.changePointListByZoom([a,d],this.zoom,this.currentPos);DrawUtils.drawLine(this.canvas,o[0],o[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 r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=this.dependToolName===tool.EToolName.Polygon,h=[this.basicResult],{dropFoot:a}=PolygonUtils.getClosestPoint(r,h,(i=(e=(t=this.referenceData)==null?void 0:t.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:n});a&&r!==a&&r!==a&&(r=a,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(c){return c&&typeof c=="object"&&"default"in c?c:{default:c}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new Selection(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),r=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t,e){if(!t)return;const i=this.polygonList.map(s=>{var o;if(s.id===t){const l=(o=s==null?void 0:s.valid)!=null?o:!0;return __spreadProps(__spreadValues({},s),{valid:e!=null?e:!l})}return s});this.setPolygonList(i),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(PolygonUtils.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const l=o.find(n=>n.id===this.editPolygonID);if(!l)return;l.pointList=this.drawingPointList,this.editPolygonID=""}else{const l=uuid(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(r=>CommonToolUtils.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:r})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(l)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,d,g,a;return __spreadProps(__spreadValues({},r),{x:(d=(h=r.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=r.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(r=>CanvasUtils.inViewPort({x:r.x,y:r.y},o)),n=CommonToolUtils.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}onMouseLeave(){this.dragInfo&&(this.emitUpdatePolygonByDrag(),this.clearPolygonDrag(),this.history.pushHistory(this.polygonList))}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=annotation.EDragTarget.Plane;const o=this.selectedPolygons[0].pointList,l=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=annotation.EDragStatus.Start;const n=this.getHoverPointIndex(t),r=this.getHoverEdgeIndex(t);n>-1?(s=annotation.EDragTarget.Point,i=[n]):r>-1&&this.hoverEdgeIndex>-1&&(s=annotation.EDragTarget.Line,i=[r,(r+1)%o.length])}this.dragInfo={dragStartCoord:l,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:l,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=PolygonUtils.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(r=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,g=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),l.length>0&&l.forEach((a,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:r,textAttribute:g})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const l=PolygonUtils.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(r=>!RectUtils.isInRect(r,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=__spreadProps(__spreadValues({},i),{pointList:s});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:h}=this.dragInfo;if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(o)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),g=MathUtils.default.getArrayIndex(n[0]-1,4),a=[r[d],r[g]],u=MathUtils.default.getRectPerpendicularOffset(h,s,a);return{x:u.x/this.zoom,y:u.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===annotation.EDragTarget.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=___default.default.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=annotation.EDragStatus.Move,o){case annotation.EDragTarget.Plane:i=i.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+n.x,y:r.y+n.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((r,h)=>l&&l.includes(h)?__spreadProps(__spreadValues({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o===annotation.EDragTarget.Point&&l&&(i=MathUtils.default.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render()),this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t)}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList);return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],h=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${l}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,d=this.getColor(h),g=StyleUtils.getStrokeAndFill(d,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(l=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},r,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),l=StyleUtils.getStrokeAndFill(o,t.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let n=`${(i=AttributeUtils.default.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(n=`${t.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:l.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const o=this.getColor(this.defaultAttribute),l=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(r=h)}n.push(r)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:d,y:g}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:d,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
|
|
1
|
+
"use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(c){return c&&typeof c=="object"&&"default"in c?c:{default:c}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new Selection(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}rotatePolygonEdge(t,e=this.selectedID){!e||!PolygonUtils.getPolygonByID(this.polygonList,e)||(this.setPolygonList(this.setPolygonDataByID({pointList:t},e)),this.render())}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),r=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.stopDrag(),this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t,e){if(!t)return;const i=this.polygonList.map(s=>{var o;if(s.id===t){const l=(o=s==null?void 0:s.valid)!=null?o:!0;return __spreadProps(__spreadValues({},s),{valid:e!=null?e:!l})}return s});this.setPolygonList(i),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(PolygonUtils.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const l=o.find(n=>n.id===this.editPolygonID);if(!l)return;l.pointList=this.drawingPointList,this.editPolygonID=""}else{const l=uuid(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(r=>CommonToolUtils.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:r})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(l)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,d,g,a;return __spreadProps(__spreadValues({},r),{x:(d=(h=r.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=r.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(r=>CanvasUtils.inViewPort({x:r.x,y:r.y},o)),n=CommonToolUtils.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}onMouseLeave(){this.dragInfo&&(this.emitUpdatePolygonByDrag(),this.clearPolygonDrag(),this.history.pushHistory(this.polygonList))}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=annotation.EDragTarget.Plane;const o=this.selectedPolygons[0].pointList,l=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=annotation.EDragStatus.Start;const n=this.getHoverPointIndex(t),r=this.getHoverEdgeIndex(t);n>-1?(s=annotation.EDragTarget.Point,i=[n]):r>-1&&this.hoverEdgeIndex>-1&&(s=annotation.EDragTarget.Line,i=[r,(r+1)%o.length])}this.dragInfo={dragStartCoord:l,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:l,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=PolygonUtils.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(r=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,g=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),l.length>0&&l.forEach((a,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:r,textAttribute:g})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const l=PolygonUtils.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(r=>!RectUtils.isInRect(r,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=__spreadProps(__spreadValues({},i),{pointList:s});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:h}=this.dragInfo;if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(o)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),g=MathUtils.default.getArrayIndex(n[0]-1,4),a=[r[d],r[g]],u=MathUtils.default.getRectPerpendicularOffset(h,s,a);return{x:u.x/this.zoom,y:u.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===annotation.EDragTarget.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=___default.default.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=annotation.EDragStatus.Move,o){case annotation.EDragTarget.Plane:i=i.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+n.x,y:r.y+n.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((r,h)=>l&&l.includes(h)?__spreadProps(__spreadValues({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o===annotation.EDragTarget.Point&&l&&(i=MathUtils.default.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render()),this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t)}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}stopDrag(){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.stopDrag(),this.history.pushHistory(this.polygonList);return}if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Start){this.stopDrag();return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&this.stopDrag()}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],h=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${l}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,d=this.getColor(h),g=StyleUtils.getStrokeAndFill(d,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(l=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},r,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),l=StyleUtils.getStrokeAndFill(o,t.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let n=`${(i=AttributeUtils.default.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(n=`${t.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:l.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const o=this.getColor(this.defaultAttribute),l=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(r=h)}n.push(r)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:d,y:g}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:d,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
|