@labelbee/lb-annotation 1.21.0-alpha.1 → 1.21.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/constant/keyCode.js +1 -1
  2. package/dist/core/pointCloud/index.js +1 -1
  3. package/dist/core/pointCloud/matrix.js +1 -1
  4. package/dist/core/toolOperation/SAMToolbarClass.js +9 -0
  5. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  6. package/dist/core/toolOperation/cursorTextClass.js +1 -0
  7. package/dist/core/toolOperation/segmentByRect.js +1 -1
  8. package/dist/core/toolOperation/segmentBySAM.js +1 -0
  9. package/dist/index.js +1 -1
  10. package/dist/types/constant/keyCode.d.ts +3 -1
  11. package/dist/types/core/pointCloud/matrix.d.ts +2 -6
  12. package/dist/types/core/toolOperation/SAMToolbarClass.d.ts +40 -0
  13. package/dist/types/core/toolOperation/basicToolOperation.d.ts +1 -0
  14. package/dist/types/core/toolOperation/cursorTextClass.d.ts +12 -0
  15. package/dist/types/core/toolOperation/segmentByRect.d.ts +11 -4
  16. package/dist/types/core/toolOperation/segmentBySAM.d.ts +39 -0
  17. package/dist/types/index.d.ts +5 -1
  18. package/dist/types/utils/tool/CanvasUtils.d.ts +1 -1
  19. package/dist/types/utils/tool/PolygonUtils.d.ts +12 -0
  20. package/dist/types/utils/tool/RectUtils.d.ts +1 -1
  21. package/dist/types/utils/tool/StyleUtils.d.ts +9 -0
  22. package/dist/utils/tool/CanvasUtils.js +1 -1
  23. package/dist/utils/tool/PolygonUtils.js +1 -1
  24. package/dist/utils/tool/StyleUtils.js +1 -1
  25. package/es/constant/keyCode.js +1 -1
  26. package/es/core/pointCloud/index.js +2 -2
  27. package/es/core/pointCloud/matrix.js +1 -1
  28. package/es/core/toolOperation/SAMToolbarClass.js +9 -0
  29. package/es/core/toolOperation/basicToolOperation.js +1 -1
  30. package/es/core/toolOperation/cursorTextClass.js +1 -0
  31. package/es/core/toolOperation/segmentByRect.js +1 -1
  32. package/es/core/toolOperation/segmentBySAM.js +1 -0
  33. package/es/index.js +1 -1
  34. package/es/utils/tool/CanvasUtils.js +1 -1
  35. package/es/utils/tool/PolygonUtils.js +1 -1
  36. package/es/utils/tool/StyleUtils.js +1 -1
  37. package/package.json +2 -2
@@ -117,4 +117,16 @@ export default class PolygonUtils {
117
117
  newPolygon: IPolygonData;
118
118
  unionList: string[];
119
119
  } | undefined;
120
+ /**
121
+ * 合成两个点集在一起
122
+ * @param pointList1 被插入点集
123
+ * @param pointList2 插入点集
124
+ */
125
+ static composePointList(pointList1: IPolygonPoint[], pointList2: IPolygonPoint[]): IPolygonPoint[];
126
+ /**
127
+ * 将分割辅助算法得到的结果拼接起来
128
+ * 1. 将被包裹的结果与包裹的多边形合成
129
+ * @param polygonList
130
+ */
131
+ static composeSegmentPolygonList(polygonList: any[]): any[];
120
132
  }
@@ -39,7 +39,7 @@ export default class RectUtils {
39
39
  * @param scope
40
40
  * @param zoom
41
41
  */
42
- static isInRect(coordinate: ICoordinate, rect: IRect, scope?: number, zoom?: number): boolean;
42
+ static isInRect(coordinate: ICoordinate, rect: Pick<IRect, 'x' | 'y' | 'width' | 'height'>, scope?: number, zoom?: number): boolean;
43
43
  /**
44
44
  * rect 与 zoom 的乘积
45
45
  * @param rect
@@ -12,4 +12,13 @@ export default class StyleUtils {
12
12
  * @returns
13
13
  */
14
14
  static getStyle2String(style?: StyleSheetList): string | undefined;
15
+ /**
16
+ * Apply a map of styles to an element
17
+ *
18
+ * @param {HTMLElement} el The element that the styles will be applied to
19
+ * @param {Object} styles The map of propName: attribute, both are used as-is
20
+ *
21
+ * @return {HTMLElement} el
22
+ */
23
+ static setDOMStyle(el: HTMLElement, styles: any): HTMLElement;
15
24
  }
@@ -1 +1 @@
1
- "use strict";var MathUtils=require("../MathUtils.js");class CanvasUtils{static getMousePositionOnCanvasFromEvent(e,t){if(t&&e){const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}}return null}static getClientRect(e){if(e){const t=e.getBoundingClientRect();return{x:t.left,y:t.top,width:t.width,height:t.height}}return null}static getSize(e){if(e){const t=e.getBoundingClientRect();return{width:t.width,height:t.height}}return null}static inViewPort(e,t){return e?MathUtils.default.isInRange(e.x,[t.left,t.right])&&MathUtils.default.isInRange(e.y,[t.top,t.bottom]):!1}static createCanvas(e){const t=document.createElement("canvas"),{width:n,height:a}=e;t.width=n,t.height=a;const s=t.getContext("2d");return{canvas:t,ctx:s}}}CanvasUtils.getViewPort=(i,e,t)=>{const{width:n,height:a}=i,{x:s,y:o}=e,r=(0-o)/t,c=(0-s)/t,l=r+a/t,g=c+n/t;return{top:r,bottom:l,left:c,right:g}},CanvasUtils.getPixelRatio=i=>{if(!i||!window)return 1;const e=i.backingStorePixelRatio||i.webkitBackingStorePixelRatio||i.mozBackingStorePixelRatio||i.msBackingStorePixelRatio||i.oBackingStorePixelRatio||i.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/e},module.exports=CanvasUtils;
1
+ "use strict";var MathUtils=require("../MathUtils.js");class CanvasUtils{static getMousePositionOnCanvasFromEvent(i,t){if(t&&i){const n=t.getBoundingClientRect();return{x:i.clientX-n.left,y:i.clientY-n.top}}return null}static getClientRect(i){if(i){const t=i.getBoundingClientRect();return{x:t.left,y:t.top,width:t.width,height:t.height}}return null}static getSize(i){if(i){const t=i.getBoundingClientRect();return{width:t.width,height:t.height}}return null}static inViewPort(i,t){return i?MathUtils.default.isInRange(i.x,[t.left,t.right])&&MathUtils.default.isInRange(i.y,[t.top,t.bottom]):!1}static createCanvas(i,t){const n=document.createElement("canvas"),{width:s,height:c}=i;n.width=s,n.height=c;const a=n.getContext("2d");return t&&a&&(a.fillStyle=t,a.fillRect(0,0,i.width,i.height)),{canvas:n,ctx:a}}}CanvasUtils.getViewPort=(e,i,t)=>{const{width:n,height:s}=e,{x:c,y:a}=i,l=(0-a)/t,r=(0-c)/t,o=l+s/t,g=r+n/t;return{top:l,bottom:o,left:r,right:g}},CanvasUtils.getPixelRatio=e=>{if(!e||!window)return 1;const i=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/i},module.exports=CanvasUtils;
@@ -1 +1 @@
1
- "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,n=3,i=tool.ELineTypes.Line){let r="",l=Infinity;const o=AxisUtils.default.axisArea(e,n);return t.forEach(s=>{s.pointList&&o.forEach(u=>{const a=this.calcPolygonSize(s.pointList);this.isInPolygon(u,s.pointList,i)&&a<l&&(r=s.id,l=a)})}),r}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,n=e.reduce((i,r,l,o)=>{const s=o[(l+1)%t];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(e,t,n=tool.ELineTypes.Line){let i=0,r,l,o,s;t=[...t],n===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((a,d)=>[...a,d.x,d.y],[]),.5,!0,20)),[o]=t;const u=t.length;for(r=1;r<=u;r++)s=t[r%u],e.x>Math.min(o.x,s.x)&&e.x<=Math.max(o.x,s.x)&&e.y<=Math.max(o.y,s.y)&&o.x!==s.x&&(l=(e.x-o.x)*(s.y-o.y)/(s.x-o.x)+o.y,(o.y===s.y||e.y<=l)&&i++),o=s;return i%2!=0}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,t).map((i,r)=>{var l;const o=r/(tool.SEGMENT_NUMBER+1),s=Math.floor(o),u=(l=e[s])!=null?l:{};return __spreadValues(s===o?__spreadValues({},u):{specialEdge:u.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,n=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const r=[],l=e.slice(0);let o,s,u,a,d,h,P,E,x,m,c,g,f;for(n?(l.unshift(e[e.length-1]),l.unshift(e[e.length-2]),l.unshift(e[e.length-1]),l.unshift(e[e.length-2]),l.push(e[0]),l.push(e[1])):(l.unshift(e[1]),l.unshift(e[0]),l.push(e[e.length-2]),l.push(e[e.length-1])),f=2;f<l.length-4;f+=2)for(u=(l[f+2]-l[f-2])*t,a=(l[f+4]-l[f-0])*t,d=(l[f+3]-l[f-1])*t,h=(l[f+5]-l[f+1])*t,g=0;g<=i;g++)c=g/i,P=2*Math.pow(c,3)-3*Math.pow(c,2)+1,E=-(2*Math.pow(c,3))+3*Math.pow(c,2),x=Math.pow(c,3)-2*Math.pow(c,2)+c,m=Math.pow(c,3)-Math.pow(c,2),o=P*l[f]+E*l[f+2]+x*u+m*a,s=P*l[f+1]+E*l[f+3]+x*d+m*h,r.push(o),r.push(s);const v=[];for(let y=0;y<r.length-1;y+=2)v.push({x:r[y],y:r[y+1]});if(n)for(let y=0;y<i+1;y++){const p=v.shift();v.push(p)}return v}static getPolygonByID(e,t){return e.find(n=>n.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(n=>t.includes(n.id)):[]}static getHoverEdgeIndex(e,t,n=tool.ELineTypes.Line,i=3){let r=[...t];n===tool.ELineTypes.Curve?r=this.createSmoothCurvePoints(t.reduce((s,u)=>[...s,u.x,u.y],[]),.5,!0,tool.SEGMENT_NUMBER):n===tool.ELineTypes.Line&&r.push(r[0]);let l=-1,o=i;for(let s=0;s<r.length-1;s++){const{length:u}=MathUtils.default.getFootOfPerpendicular(e,r[s],r[s+1]);u<o&&(l=s,o=u)}return l===-1?-1:n===tool.ELineTypes.Curve?Math.floor(l/tool.SEGMENT_NUMBER):l}static getClosestPoint(e,t,n=tool.ELineTypes.Line,i=3,r){var l;let o=!1;const s=(l=r==null?void 0:r.isClose)!=null?l:!0;let u="",a=-1,d=Infinity,h=e;const P=20;let E=!1;return t.forEach(x=>{if(!E&&!!x.pointList)switch(n){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(x.pointList,s).forEach((c,g)=>{if(E)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,c.point1,c.point2);const y=MathUtils.default.getLineLength(c.point1,e),p=MathUtils.default.getLineLength(c.point2,e);y<i*2&&(v=c.point1,f=y,E=!0),p<i*2&&(v=c.point2,f=p,E=!0),f<d&&f<i&&(u=x.id,a=g,d=f,h=v,o=!0)});break;case tool.ELineTypes.Curve:{const m=this.createSmoothCurvePoints(x.pointList.reduce((c,g)=>[...c,g.x,g.y],[]),.5,s,P);for(let c=0;c<m.length-1;c++){const{length:g,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,m[c],m[c+1]);g<d&&g<i&&(u=x.id,a=Math.floor(c/(P+1)),d=g,h=f,o=!0)}}break}}),{dropFoot:h,closestEdgeIndex:a,closestPolygonID:u,hasClosed:o}}static isPointListInPolygon(e,t,n=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,n))}static isPointListOutSidePolygon(e,t,n=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,n))}static getPolygonArea(e){let t=0;for(let n=0,i=e.length;n<i;n++){const r=e[n].x,l=e[n===e.length-1?0:n+1].y,o=e[n===e.length-1?0:n+1].x,s=e[n].y;t+=r*l*.5,t-=o*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,n){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,n)}static deletePolygonLastPoint(e,t,n,i){return n===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var n,i;try{let r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(o=>[o.x,o.y]))]]);return t.forEach(o=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(o.pointList.map(a=>[a.x,a.y]))]]),u=turf.difference(r,s);u&&(r=u)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(o=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?o[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):o.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((o,s)=>{const u=s.length,a=s.filter((d,h)=>{const P=(h+1)%u;return!AxisUtils.default.getIsInScope(d,s[P],1)});return a.length<3?o:[...o,a]},[])}catch(r){console.error(r)}}static getPolygonPointList(e,t){const n=t.find(i=>i.id===e);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(n=>PolygonUtils.isPointListInPolygon(e,n.pointList))}static clipPolygonFromWrapPolygon(e,t){const n=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),r=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),l=t[r];let o=[...t.slice(0,r),l,...e,e[0],...t.slice(r,t.length)];return n===i&&(o=[...t.slice(0,r),l,e[0],...e.reverse(),...t.slice(r,t.length)]),o}static isPolygonClosewise(e){const t=e.length;let n,i,r,l=0,o;if(t<3)return 0;for(n=0;n<t;n++)i=(n+1)%t,r=(n+2)%t,o=(e[i].x-e[n].x)*(e[r].y-e[i].y),o-=(e[i].y-e[n].y)*(e[r].x-e[i].x),o<0?l--:o>0&&l++;return l>0?1:l<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let n=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((r,l)=>{const o=LineToolUtils.default.calcDistance(e,r);o<n&&(n=o,i=l)}),i}static combinePolygonWithPolygon(e,t){var n,i;try{const r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(a=>[a.x,a.y]))]]),l=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(a=>[a.x,a.y]))]]),o=turf.union(r,l),s=[],u=e;if(((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(t.id);const a=o==null?void 0:o.geometry.coordinates.map(d=>{var h;return((h=o==null?void 0:o.geometry)==null?void 0:h.type)==="MultiPolygon"?d[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):d.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];u.pointList=a}return{newPolygon:u,unionList:s}}catch(r){console.error(r)}}}module.exports=PolygonUtils;
1
+ "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,n=3,i=tool.ELineTypes.Line){let r="",o=Infinity;const l=AxisUtils.default.axisArea(e,n);return t.forEach(s=>{s.pointList&&l.forEach(u=>{const a=this.calcPolygonSize(s.pointList);this.isInPolygon(u,s.pointList,i)&&a<o&&(r=s.id,o=a)})}),r}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,n=e.reduce((i,r,o,l)=>{const s=l[(o+1)%t];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(e,t,n=tool.ELineTypes.Line){let i=0,r,o,l,s;t=[...t],n===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((a,h)=>[...a,h.x,h.y],[]),.5,!0,20)),[l]=t;const u=t.length;for(r=1;r<=u;r++)s=t[r%u],e.x>Math.min(l.x,s.x)&&e.x<=Math.max(l.x,s.x)&&e.y<=Math.max(l.y,s.y)&&l.x!==s.x&&(o=(e.x-l.x)*(s.y-l.y)/(s.x-l.x)+l.y,(l.y===s.y||e.y<=o)&&i++),l=s;return i%2!=0}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,t).map((i,r)=>{var o;const l=r/(tool.SEGMENT_NUMBER+1),s=Math.floor(l),u=(o=e[s])!=null?o:{};return __spreadValues(s===l?__spreadValues({},u):{specialEdge:u.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,n=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const r=[],o=e.slice(0);let l,s,u,a,h,g,P,E,x,m,c,d,f;for(n?(o.unshift(e[e.length-1]),o.unshift(e[e.length-2]),o.unshift(e[e.length-1]),o.unshift(e[e.length-2]),o.push(e[0]),o.push(e[1])):(o.unshift(e[1]),o.unshift(e[0]),o.push(e[e.length-2]),o.push(e[e.length-1])),f=2;f<o.length-4;f+=2)for(u=(o[f+2]-o[f-2])*t,a=(o[f+4]-o[f-0])*t,h=(o[f+3]-o[f-1])*t,g=(o[f+5]-o[f+1])*t,d=0;d<=i;d++)c=d/i,P=2*Math.pow(c,3)-3*Math.pow(c,2)+1,E=-(2*Math.pow(c,3))+3*Math.pow(c,2),x=Math.pow(c,3)-2*Math.pow(c,2)+c,m=Math.pow(c,3)-Math.pow(c,2),l=P*o[f]+E*o[f+2]+x*u+m*a,s=P*o[f+1]+E*o[f+3]+x*h+m*g,r.push(l),r.push(s);const v=[];for(let y=0;y<r.length-1;y+=2)v.push({x:r[y],y:r[y+1]});if(n)for(let y=0;y<i+1;y++){const M=v.shift();v.push(M)}return v}static getPolygonByID(e,t){return e.find(n=>n.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(n=>t.includes(n.id)):[]}static getHoverEdgeIndex(e,t,n=tool.ELineTypes.Line,i=3){let r=[...t];n===tool.ELineTypes.Curve?r=this.createSmoothCurvePoints(t.reduce((s,u)=>[...s,u.x,u.y],[]),.5,!0,tool.SEGMENT_NUMBER):n===tool.ELineTypes.Line&&r.push(r[0]);let o=-1,l=i;for(let s=0;s<r.length-1;s++){const{length:u}=MathUtils.default.getFootOfPerpendicular(e,r[s],r[s+1]);u<l&&(o=s,l=u)}return o===-1?-1:n===tool.ELineTypes.Curve?Math.floor(o/tool.SEGMENT_NUMBER):o}static getClosestPoint(e,t,n=tool.ELineTypes.Line,i=3,r){var o;let l=!1;const s=(o=r==null?void 0:r.isClose)!=null?o:!0;let u="",a=-1,h=Infinity,g=e;const P=20;let E=!1;return t.forEach(x=>{if(!E&&!!x.pointList)switch(n){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(x.pointList,s).forEach((c,d)=>{if(E)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,c.point1,c.point2);const y=MathUtils.default.getLineLength(c.point1,e),M=MathUtils.default.getLineLength(c.point2,e);y<i*2&&(v=c.point1,f=y,E=!0),M<i*2&&(v=c.point2,f=M,E=!0),f<h&&f<i&&(u=x.id,a=d,h=f,g=v,l=!0)});break;case tool.ELineTypes.Curve:{const m=this.createSmoothCurvePoints(x.pointList.reduce((c,d)=>[...c,d.x,d.y],[]),.5,s,P);for(let c=0;c<m.length-1;c++){const{length:d,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,m[c],m[c+1]);d<h&&d<i&&(u=x.id,a=Math.floor(c/(P+1)),h=d,g=f,l=!0)}}break}}),{dropFoot:g,closestEdgeIndex:a,closestPolygonID:u,hasClosed:l}}static isPointListInPolygon(e,t,n=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,n))}static isPointListOutSidePolygon(e,t,n=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,n))}static getPolygonArea(e){let t=0;for(let n=0,i=e.length;n<i;n++){const r=e[n].x,o=e[n===e.length-1?0:n+1].y,l=e[n===e.length-1?0:n+1].x,s=e[n].y;t+=r*o*.5,t-=l*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,n){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,n)}static deletePolygonLastPoint(e,t,n,i){return n===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var n,i;try{let r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(l=>[l.x,l.y]))]]);return t.forEach(l=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(l.pointList.map(a=>[a.x,a.y]))]]),u=turf.difference(r,s);u&&(r=u)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(l=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):l.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const u=s.length,a=s.filter((h,g)=>{const P=(g+1)%u;return!AxisUtils.default.getIsInScope(h,s[P],1)});return a.length<3?l:[...l,a]},[])}catch(r){console.error(r)}}static getPolygonPointList(e,t){const n=t.find(i=>i.id===e);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(n=>PolygonUtils.isPointListInPolygon(e,n.pointList))}static clipPolygonFromWrapPolygon(e,t){const n=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),r=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),o=t[r];let l=[...t.slice(0,r),o,...e,e[0],...t.slice(r,t.length)];return n===i&&(l=[...t.slice(0,r),o,e[0],...e.reverse(),...t.slice(r,t.length)]),l}static isPolygonClosewise(e){const t=e.length;let n,i,r,o=0,l;if(t<3)return 0;for(n=0;n<t;n++)i=(n+1)%t,r=(n+2)%t,l=(e[i].x-e[n].x)*(e[r].y-e[i].y),l-=(e[i].y-e[n].y)*(e[r].x-e[i].x),l<0?o--:l>0&&o++;return o>0?1:o<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let n=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((r,o)=>{const l=LineToolUtils.default.calcDistance(e,r);l<n&&(n=l,i=o)}),i}static combinePolygonWithPolygon(e,t){var n,i;try{const r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(a=>[a.x,a.y]))]]),o=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(a=>[a.x,a.y]))]]),l=turf.union(r,o),s=[],u=e;if(((i=(n=l==null?void 0:l.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(t.id);const a=l==null?void 0:l.geometry.coordinates.map(h=>{var g;return((g=l==null?void 0:l.geometry)==null?void 0:g.type)==="MultiPolygon"?h[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):h.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];u.pointList=a}return{newPolygon:u,unionList:s}}catch(r){console.error(r)}}static composePointList(e,t){let n=0,i=0,r=Number.MAX_VALUE;return e.forEach((o,l)=>{t.forEach((s,u)=>{const a=LineToolUtils.default.calcDistance(o,s);a<r&&(n=l+1,i=u+1,r=a)})}),[...e.slice(0,n),...t.slice(i,t.length),...t.slice(0,i),...e.slice(n,e.length)]}static composeSegmentPolygonList(e){var t,n;const i=[];for(let r=0;r<e.length;r++)for(let o=0;o<e.length;o++){const l=(t=e[r])==null?void 0:t.pointList,s=(n=e[o])==null?void 0:n.pointList;r!==o&&l&&s&&PolygonUtils.isPointListInPolygon(s,l)&&(e[r].pointList=PolygonUtils.composePointList(l,s),i.unshift(o))}return i.forEach(r=>{e.splice(r,1)}),e}}module.exports=PolygonUtils;
@@ -1 +1 @@
1
- "use strict";class StyleUtils{static getStrokeAndFill(e,i=!0,r={}){const{isSelected:s=!1,isHover:l=!1}=r;return s?{stroke:i?e.validSelected.stroke:e.invalidSelected.stroke,fill:i?e.validSelected.fill:e.invalidSelected.fill}:l?{stroke:i?e.validHover.stroke:e.invalidHover.stroke,fill:i?e.validHover.fill:e.invalidHover.fill}:{stroke:i?e.valid.stroke:e.invalid.stroke,fill:i?e.valid.fill:e.invalid.fill}}static getStyle2String(e){if(!!e)return Object.entries(e).reduce((i,r)=>`${i} ${r[0]}: ${r[1]};`,"")}}module.exports=StyleUtils;
1
+ "use strict";class StyleUtils{static getStrokeAndFill(e,i=!0,r={}){const{isSelected:s=!1,isHover:t=!1}=r;return s?{stroke:i?e.validSelected.stroke:e.invalidSelected.stroke,fill:i?e.validSelected.fill:e.invalidSelected.fill}:t?{stroke:i?e.validHover.stroke:e.invalidHover.stroke,fill:i?e.validHover.fill:e.invalidHover.fill}:{stroke:i?e.valid.stroke:e.invalid.stroke,fill:i?e.valid.fill:e.invalid.fill}}static getStyle2String(e){if(!!e)return Object.entries(e).reduce((i,r)=>`${i} ${r[0]}: ${r[1]};`,"")}static setDOMStyle(e,i){return Object.keys(i).forEach(r=>{e.style[r]!==i[r]&&(e.style[r]=i[r])}),e}}module.exports=StyleUtils;
@@ -1 +1 @@
1
- var a;(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"})(a||(a={}));var c=a;export{c as default};
1
+ var a;(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"})(a||(a={}));var n=a;export{n as default};
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as b,PointCloudUtils as F,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,L=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,C=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&L(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&L(w,e,t[e]);return w},S=(w,t)=>tt(w,et(t)),z=(w,t,e)=>new Promise((i,r)=>{var s=d=>{try{o(e.next(d))}catch(n){r(n)}},h=d=>{try{o(e.throw(d))}catch(n){r(n)}},o=d=>d.done?i(d.value):Promise.resolve(d.value).then(s,h);o((e=e.apply(w,t)).next())});const nt=30,k=new E({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:d}){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.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,l="blue")=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"sphere");const{radius:u,widthSegments:f,heightSegments:p}=O,{center:g}=n,y=new a.Group,x=new a.SphereGeometry(u,f,p),M=new a.MeshBasicMaterial({color:l}),P=new a.Mesh(x,M);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l),this.render()},this.generateSpheres=n=>{n.forEach(l=>{const{fill:c}=this.getColorFromConfig(l.attribute);this.addSphereToSense(l,c)}),this.render()},this.addBoxToSense=(n,l=16777215)=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"box");const{center:u,width:f,height:p,depth:g,rotation:y}=n,x=new a.Group,M=new a.BoxGeometry(f,p,g),P=new a.MeshBasicMaterial({color:"blue"}),B=new a.Mesh(M,P),_=new a.BoxHelper(B,l),N=this.generateBoxArrow(n),D=this.generateBoxTrackID(n);D&&x.add(D),x.add(_),x.add(N),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${m}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const l=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,l)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as b,PointCloudUtils as F,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,k=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,C=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&k(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&k(w,e,t[e]);return w},S=(w,t)=>tt(w,et(t)),z=(w,t,e)=>new Promise((i,r)=>{var s=d=>{try{o(e.next(d))}catch(n){r(n)}},h=d=>{try{o(e.throw(d))}catch(n){r(n)}},o=d=>d.done?i(d.value):Promise.resolve(d.value).then(s,h);o((e=e.apply(w,t)).next())});const nt=30,L=new E({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:d}){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.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,l="blue")=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"sphere");const{radius:u,widthSegments:f,heightSegments:p}=O,{center:g}=n,y=new a.Group,x=new a.SphereGeometry(u,f,p),M=new a.MeshBasicMaterial({color:l}),P=new a.Mesh(x,M);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l),this.render()},this.generateSpheres=n=>{n.forEach(l=>{const{fill:c}=this.getColorFromConfig(l.attribute);this.addSphereToSense(l,c)}),this.render()},this.addBoxToSense=(n,l=16777215)=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"box");const{center:u,width:f,height:p,depth:g,rotation:y}=n,x=new a.Group,M=new a.BoxGeometry(f,p,g),P=new a.MeshBasicMaterial({color:"blue"}),B=new a.Mesh(M,P),_=new a.BoxHelper(B,l),N=this.generateBoxArrow(n),D=this.generateBoxTrackID(n);D&&x.add(D),x.add(_),x.add(N),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${m}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const l=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,l)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,4 @@ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(m);const p=new a.Points(f);this.renderPointCloud(p,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:l,points:c}){const m=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),u=l.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=$({points:c,calib:p.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return Y(u)}),this.loadPCDFileByBox=(n,l,c)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=c!=null?c:{},P=yield this.filterPointsByBox(S(C({},l),{width:l.width+y,height:l.height+x,depth:l.depth+M}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:u,color:f}=yield this.cacheInstance.loadPCDFile(n);m(u,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(l,c,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),m=new a.Sprite(c);return m.scale.set(5,5,5),m.position.set(-n.width/2,0,n.depth/2+.5),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const m=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(m*1.2,10):c.material.uniforms.pointSize.value=Math.max(m/1.2,1),l&&(c.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(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 X(C({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(S(C({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 C({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(C({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,c=-100,m=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=A(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(m=>{const u=new V;u.postMessage(c),u.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,s=nt){let h=v.frontViewMatrix4(s);switch(r){case b.Front:break;case b.Back:h=v.backViewMatrix4(s);break;case b.Left:h=v.leftViewMatrix4(s);break;case b.Right:h=v.rightViewMatrix4(s);break;case b.Top:h=v.topViewMatrix4(s);break;case b.LFT:h=v.leftFrontTopViewMatrix4(s,i);break;case b.RBT:h=v.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(l=>A(l)),d=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};k.postMessage(n),k.onmessage=l=>{const{color:c}=l.data,m=new a.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=T.getColorFromConfig({attribute:i.attribute},S(C({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(o,d,n),u=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(l),m.translate(r,s,h);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(o/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.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((c,m)=>c.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((c,m)=>c.x-m.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((c,m)=>c.y-m.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,c)=>{const m=r[c+1],u=H.getFootOfPerpendicular({x:d,y:n},l,m,!1,!0).length;(!i[c]||u<i[c].distance)&&(i[c]={distance:u,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],m=r[n+2];return F.getIntersectionBySlope({p1:s[n].point,line1:[l,c],p2:s[n+1].point,line2:[c,m]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,m=[],u=[];const f=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];R({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),m=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),d=u[0].z-.01,n=u[u.length-1].z+.01,c=u.length,e&&(l=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}):{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},l={x:e-h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},l={x:e-h/2,y:i-s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},l={x:e-h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case b.Left:return this.getPolygonSidePoints(t);case b.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new a.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),m=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[d,n,l,c]=o,m=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(C({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(m);const p=new a.Points(f);this.renderPointCloud(p,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:l,points:c}){const m=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),u=l.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=$({points:c,calib:p.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return Y(u)}),this.loadPCDFileByBox=(n,l,c)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=c!=null?c:{},P=yield this.filterPointsByBox(S(C({},l),{width:l.width+y,height:l.height+x,depth:l.depth+M}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const B=new a.Points(P.geometry);B.name=this.pointCloudObjectName,this.scene.add(B),this.render()}),{points:u,color:f}=yield this.cacheInstance.loadPCDFile(n);m(u,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(l,c,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),m=new a.Sprite(c);return m.scale.set(5,5,5),m.position.set(-n.width/2,0,n.depth/2+.5),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const m=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(m*1.2,10):c.material.uniforms.pointSize.value=Math.max(m/1.2,1),l&&(c.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(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 X(C({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(S(C({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 C({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},S(C({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,c=-100,m=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=A(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(m=>{const u=new V;u.postMessage(c),u.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,s=nt){let h=v.frontViewMatrix4(s);switch(r){case b.Front:break;case b.Back:h=v.backViewMatrix4(s);break;case b.Left:h=v.leftViewMatrix4(s);break;case b.Right:h=v.rightViewMatrix4(s);break;case b.Top:h=v.topViewMatrix4(s);break;case b.LFT:h=v.leftFrontTopViewMatrix4(s,i);break;case b.RBT:h=v.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(l=>A(l)),d=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(n),L.onmessage=l=>{const{color:c}=l.data,m=new a.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=T.getColorFromConfig({attribute:i.attribute},S(C({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(o,d,n),u=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(l),m.translate(r,s,h);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(o/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.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((c,m)=>c.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((c,m)=>c.x-m.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((c,m)=>c.y-m.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,c)=>{const m=r[c+1],u=H.getFootOfPerpendicular({x:d,y:n},l,m,!1,!0).length;(!i[c]||u<i[c].distance)&&(i[c]={distance:u,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],m=r[n+2];return F.getIntersectionBySlope({p1:s[n].point,line1:[l,c],p2:s[n+1].point,line2:[c,m]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,m=[],u=[];const f=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];R({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),m=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),d=u[0].z-.01,n=u[u.length-1].z+.01,c=u.length,e&&(l=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}):{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},l={x:e-h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},l={x:e-h/2,y:i-s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},l={x:e-h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case b.Left:return this.getPolygonSidePoints(t);case b.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new a.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),m=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=S(C({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[d,n,l,c]=o,m=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(C({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
@@ -1 +1 @@
1
- import*as y from"three";import{MatrixUtils as M,PointCloudUtils as D}from"@labelbee/lb-utils";import H from"../../utils/uuid.js";var E=Object.defineProperty,j=Object.defineProperties,K=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,_=Math.pow,z=(r,t,e)=>t in r?E(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,C=(r,t)=>{for(var e in t||(t={}))k.call(t,e)&&z(r,e,t[e]);if(I)for(var e of I(t))A.call(t,e)&&z(r,e,t[e]);return r},R=(r,t)=>j(r,K(t));function g(r){return new y.Matrix4().set(...r)}function v(r,t,e){try{const n=M.transferMatrix34FromKitti2Three(r),o=M.transferMatrix33FromKitti2Three(t),i=M.transferMatrix34FromKitti2Three(e),l=g(n),f=g(o),a=g(i);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function T(r,t,e){var n;const o=new y.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),i=new y.Matrix4().makeRotationZ(e),l=new y.Matrix4().makeTranslation(t.x,t.y,t.z),f=new y.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return o.clone().applyMatrix4(f).applyMatrix4(i).applyMatrix4(l)}function L(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const m=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&L(r.P,3,4)&&L(r.T,3,4))},w=(r,t)=>{if(m(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:o}=t,i=new y.Vector4(r.x,r.y,r.z),l=g(M.transferMatrix34FromKitti2Three(o)),f=g(M.transferMatrix34FromKitti2Three(e)),a=i.applyMatrix4(l),x=_(_(a.x,2)+_(a.y,2),.5),h=Math.atan(a.z/x),s=n.reduce((u,c,d)=>u+c*_(h,d),0);return a.x=a.x/x*s,a.y=a.y/x*s,a.z=1,a.applyMatrix4(f)};function P(r,t){const n=new y.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const o=1/n.z,i=new y.Matrix4().set(o,0,0,0,0,o,0,0,0,0,o,0,0,0,0,1);return n.applyMatrix4(i)}function B(r){const{center:t,width:e,height:n,depth:o,rotation:i}=r,l=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(x=>{const h=T(x,t,i);return{x:h.x,y:h.y}}),f=t.z+o/2,a=t.z-o/2;return R(C({},r),{polygonPointList:l,zMax:f,zMin:a})}function U(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function F(r,t,e){const n=t.x-r.x,o=t.y-r.y,i=e.x-r.x,l=e.y-r.y;return n*l-i*o}function N(r){const t=U(r),e=[];for(let i=0;i<t.length;i++){for(;e.length>=2&&F(e[e.length-2],e[e.length-1],t[i])<=0;)e.pop();e.push(t[i])}const n=[];for(let i=t.length-1;i>=0;i--){for(;n.length>=2&&F(n[n.length-2],n[n.length-1],t[i])<=0;)n.pop();n.push(t[i])}return e.pop(),n.pop(),e.concat(n)}const O=(r,t)=>{var e;if(m(t))return w(r,t);const{P:n,R:o,T:i}=t,{composeMatrix4:l}=(e=v(n,o,i))!=null?e:{};if(!!l)return P(r,l)},V=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const o=O(r,t);return o?o.x>=0&&o.x<=e&&o.y>=0&&o.y<=n:!1},Z=({points:r,calib:t,width:e,height:n})=>{const o=[];for(let i=0;i<r.length;i+=3){const l=r[i],f=r[i+1],a=r[i+2];V({point:{x:l,y:f,z:a},calib:t,width:e,height:n})?o.push(1):o.push(0)}return o},q=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function G(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:o}=e,i=D.getAllViewData(r),l=m(t),{P:f,R:a,T:x}=t;let h;if(l===!1){const{composeMatrix4:u}=(n=v(f,a,x))!=null?n:{};if(!u)return;h=u}const s=i.map(u=>({type:u.type,pointList:u.pointList.map(c=>T(c,r.center,r.rotation)).map(c=>l?w(c,t):h&&P(c,h)).map(c=>{if(!!c)return{id:H(),x:c==null?void 0:c.x,y:c==null?void 0:c.y}}).filter(c=>c!==void 0)})).filter(u=>u.pointList.length!==0);s[0]&&s[0].pointList&&l&&(s[0].pointList=s[0].pointList.map(u=>R(C({},u),{specialEdge:!0})));let p=[];if(s.length===6&&o===!0){const u=s[0].pointList,c=s[1].pointList;p=N([...u,...c])}return{transferViewData:s,viewRangePointList:p}}function J(r,t,e){var n;const o=m(t),{P:i,R:l,T:f}=t;let a;if(o===!1){const{composeMatrix4:s}=(n=v(i,l,f))!=null?n:{};if(!s)return;a=s}const x=r.length/3,h={};for(let s=0;s<x;s++){const p={x:r[s*3],y:r[s*3+1],z:r[s*3+2]};let u;if(o?u=w(p,t):u=a&&P({x:r[s*3],y:r[s*3+1],z:r[s*3+2]},a),u){const c=Math.floor(u.x),d=Math.floor(u.y);if(c>e.width||d>e.height||c<0||d<0)continue;h[s]={x:c,y:d}}}return{pcdMapping:h}}function Q(r,t,e){var n;if(!t||!e)return;const o=m(t),{P:i,R:l,T:f}=t;let a;if(o===!1){const{composeMatrix4:s}=(n=v(i,l,f))!=null?n:{};if(!s)return;a=s}const x=[];if(r.forEach(s=>{let p;if(o?p=w(s,t):p=a&&P(s,a),p){const{x:u,y:c}=p;x.push({x:u,y:c})}}),x.some(s=>s.x>0&&s.x<e.width&&s.y>0&&s.y<e.height))return x}export{g as createThreeMatrix4,B as getCuboidFromPointCloudBox,Z as getHighlightIndexByPoints,m as isFisheyeCalibValid,V as isInImage,L as isMatrixValid,w as lidar2FisheyeImage,P as lidar2image,q as mergeHighlightList,O as point3DLidar2Image,G as pointCloudLidar2image,Q as pointListLidar2Img,J as pointMappingLidar2image,T as rotatePoint,v as transferKitti2Matrix};
1
+ import*as h from"three";import{MatrixUtils as d,PointCloudUtils as D}from"@labelbee/lb-utils";import H from"../../utils/uuid.js";var j=Object.defineProperty,E=Object.defineProperties,K=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,v=Math.pow,C=(r,t,e)=>t in r?j(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,O=(r,t)=>{for(var e in t||(t={}))k.call(t,e)&&C(r,e,t[e]);if(L)for(var e of L(t))A.call(t,e)&&C(r,e,t[e]);return r},R=(r,t)=>E(r,K(t));function y(r){return new h.Matrix4().set(...r)}function w(r,t,e){try{const n=d.transferMatrix34FromKitti2Three(r),i=d.transferMatrix33FromKitti2Three(t),o=d.transferMatrix34FromKitti2Three(e),l=y(n),f=y(i),a=y(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(l),PM:l,RM:f,TM:a}}catch(n){console.error(n)}}function T(r,t,e){var n;const i=new h.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new h.Matrix4().makeRotationZ(e),l=new h.Matrix4().makeTranslation(t.x,t.y,t.z),f=new h.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(l)}function z(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const M=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&z(r.P,3,4)&&z(r.T,3,4))},_=(r,t)=>{if(M(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:i}=t,o=new h.Vector4(r.x,r.y,r.z),l=y(d.transferMatrix34FromKitti2Three(i)),f=y(d.transferMatrix34FromKitti2Three(e)),a=o.applyMatrix4(l),x=v(v(a.x,2)+v(a.y,2),.5),p=Math.atan(a.z/x),s=n.reduce((u,c,m)=>u+c*v(p,m),0);return a.x=a.x/x*s,a.y=a.y/x*s,a.z=1,a.applyMatrix4(f)};function P(r,t){const n=new h.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const i=1/n.z,o=new h.Matrix4().set(i,0,0,0,0,i,0,0,0,0,i,0,0,0,0,1);return n.applyMatrix4(o)}function B(r){const{center:t,width:e,height:n,depth:i,rotation:o}=r,l=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(x=>{const p=T(x,t,o);return{x:p.x,y:p.y}}),f=t.z+i/2,a=t.z-i/2;return R(O({},r),{polygonPointList:l,zMax:f,zMin:a})}function U(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function V(r,t,e){const n=t.x-r.x,i=t.y-r.y,o=e.x-r.x,l=e.y-r.y;return n*l-o*i}function N(r){const t=U(r),e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&V(e[e.length-2],e[e.length-1],t[o])<=0;)e.pop();e.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&V(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return e.pop(),n.pop(),e.concat(n)}const F=(r,t)=>{var e;if(M(t))return _(r,t);const{P:n,R:i,T:o}=t,{composeMatrix4:l}=(e=w(n,i,o))!=null?e:{};if(!!l)return P(r,l)},I=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const i=F(r,t);return i?i.x>=0&&i.x<=e&&i.y>=0&&i.y<=n:!1},S=({points:r,calib:t,width:e,height:n})=>{const i=[];for(let o=0;o<r.length;o+=3){const l=r[o],f=r[o+1],a=r[o+2];I({point:{x:l,y:f,z:a},calib:t,width:e,height:n})?i.push(1):i.push(0)}return i},Z=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function b(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:i}=e,o=D.getAllViewData(r),l=M(t),{P:f,R:a,T:x}=t;let p;if(l===!1){const{composeMatrix4:u}=(n=w(f,a,x))!=null?n:{};if(!u)return;p=u}const s=o.map(u=>({type:u.type,pointList:u.pointList.map(c=>T(c,r.center,r.rotation)).map(c=>l?_(c,t):p&&P(c,p)).map(c=>{if(!!c)return{id:H(),x:c==null?void 0:c.x,y:c==null?void 0:c.y}}).filter(c=>c!==void 0)})).filter(u=>u.pointList.length!==0);s[0]&&s[0].pointList&&l&&(s[0].pointList=s[0].pointList.map(u=>R(O({},u),{specialEdge:!0})));let g=[];if(s.length===6&&i===!0){const u=s[0].pointList,c=s[1].pointList;g=N([...u,...c])}return{transferViewData:s,viewRangePointList:g}}function q(r,t,e){var n;const i=M(t),{P:o,R:l,T:f}=t;let a;if(i===!1){const{composeMatrix4:s}=(n=w(o,l,f))!=null?n:{};if(!s)return;a=s}const x=r.length/3,p={};for(let s=0;s<x;s++){const g={x:r[s*3],y:r[s*3+1],z:r[s*3+2]};let u;if(i?u=_(g,t):u=a&&P({x:r[s*3],y:r[s*3+1],z:r[s*3+2]},a),u){const c=Math.floor(u.x),m=Math.floor(u.y);if(c>e.width||m>e.height||c<0||m<0)continue;p[s]={x:c,y:m}}}return{pcdMapping:p}}export{y as createThreeMatrix4,B as getCuboidFromPointCloudBox,S as getHighlightIndexByPoints,M as isFisheyeCalibValid,I as isInImage,z as isMatrixValid,_ as lidar2FisheyeImage,P as lidar2image,Z as mergeHighlightList,F as point3DLidar2Image,b as pointCloudLidar2image,q as pointMappingLidar2image,T as rotatePoint,w as transferKitti2Matrix};
@@ -0,0 +1,9 @@
1
+ import d from"../../utils/tool/AxisUtils.js";import s from"../../utils/tool/StyleUtils.js";var h=Object.defineProperty,l=Object.getOwnPropertySymbols,c=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,u=(r,t,e)=>t in r?h(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,_=(r,t)=>{for(var e in t||(t={}))c.call(t,e)&&u(r,e,t[e]);if(l)for(var e of l(t))O.call(t,e)&&u(r,e,t[e]);return r};const p={height:38},f=8,v={height:"22px",border:"1px solid #666fff",color:"#666fff",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",borderRadius:"4px",padding:"0 8px"};class b{constructor(t){const{container:e,toggleClickType:i,finish:o,reset:n,i18n:a}=t;this.container=e,this.onToggleClickType=i,this.onFinish=o,this.onReset=n,this.disabled=!1,this.i18n=a,this._toolbarDOM=this.initToolbarDOM(),this._radioGroupDOM=this.initRadioGroupDOM(),this._buttonGroupDOM=this.initButtonGroupDOM(),this.appendToContainer(),this.onClick=this.onClick.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.eventBinding(),this.onToggle("add")}appendToContainer(){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||(this.container.appendChild(this._toolbarDOM),this._toolbarDOM.appendChild(this._radioGroupDOM),this._toolbarDOM.appendChild(this._buttonGroupDOM))}clearToolbarDOM(){this._toolbarDOM&&this.container.contains(this._toolbarDOM)&&(this.eventUnbinding(),this.container.removeChild(this._toolbarDOM))}initToolbarDOM(){const t=document.createElement("div");return t.setAttribute("id","LABELBEE_SAM_TOOLBAR"),s.setDOMStyle(t,{display:"flex",position:"absolute",fontSize:"14px",height:`${p.height}px`,padding:"0 8px",borderRadius:"4px",backgroundColor:"#FFFFFF",zIndex:"10"}),t}initRadioGroupDOM(){const t=[{text:`${this.i18n.t("AddPoints")}(+)`,value:"add"},{text:`${this.i18n.t("RemovePoints")}(-)`,value:"remove"}],e=document.createElement("div");e.setAttribute("id","LABELBEE_SAM_TOOLBAR_RADIO_GROUP"),s.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center"});let i="";return t.forEach(o=>{i+=`<label class="ant-radio-wrapper"
2
+ ><span class="ant-radio"
3
+ ><input
4
+ class="ant-radio-input"
5
+ type="radio"
6
+ value="${o.value}"
7
+ checked="" /><span class="ant-radio-inner"></span></span
8
+ ><span data-value="${o.value}">${o.text}</span></label
9
+ >`}),e.innerHTML=i,e}initButtonGroupDOM(){const t=[{text:`${this.i18n.t("Reset")}`,value:"reset"},{text:`${this.i18n.t("Finish")}`,value:"finish"}],e=document.createElement("div");return e.setAttribute("id","LABELBEE_SAM_TOOLBAR_BUTTON_GROUP"),s.setDOMStyle(e,{height:"100%",display:"flex",justifyContent:"space-around",alignItems:"center",gap:"8px"}),t.forEach(i=>{const o=document.createElement("div");o.setAttribute("data-value",i.value),o.textContent=i.text;const n=_({},v);i.value==="finish"&&Object.assign(n,{color:"white",backgroundColor:"#666fff"}),s.setDOMStyle(o,n),e.appendChild(o)}),e}update(t){const{left:e,top:i}=t;!this._toolbarDOM||s.setDOMStyle(this._toolbarDOM,{left:`${e}px`,top:`${i}px`})}onClick(t){var e,i;if(t.stopPropagation(),t.preventDefault(),!this.disabled){if((e=this._radioGroupDOM)==null?void 0:e.contains(t.target)){const o=t.target,n=o.getAttribute("value")||o.getAttribute("data-value");n&&this.onToggleClickType(n);return}if((i=this._buttonGroupDOM)==null?void 0:i.contains(t.target)){const n=t.target.getAttribute("data-value");n==="reset"&&this.onReset(),n==="finish"&&this.onFinish()}}}eventBinding(){var t,e;(t=this._toolbarDOM)==null||t.addEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.addEventListener("mouseup",this.onMouseUp)}onMouseUp(t){t.stopPropagation(),t.preventDefault()}eventUnbinding(){var t,e;(t=this._toolbarDOM)==null||t.removeEventListener("click",this.onClick),(e=this._toolbarDOM)==null||e.removeEventListener("mouseup",this.onMouseUp)}setDisabled(t){!this._toolbarDOM||!this._radioGroupDOM||!this._buttonGroupDOM||t===this.disabled||(this.disabled=t,s.setDOMStyle(this._toolbarDOM,{filter:t?"grayscale(100%)":"none",cursor:t?"not-allowed":"default"}),s.setDOMStyle(this._radioGroupDOM,{pointerEvents:t?"none":"auto"}),s.setDOMStyle(this._buttonGroupDOM,{pointerEvents:t?"none":"auto"}))}onToggle(t){var e;(e=this._radioGroupDOM)==null||e.querySelectorAll("label").forEach(i=>{var o,n;const a=(o=i.querySelector("input"))==null?void 0:o.getAttribute("value");i.setAttribute("class",`ant-radio-wrapper${a===t?" ant-radio-wrapper-checked":""}`),(n=i.querySelector(".ant-radio"))==null||n.setAttribute("class",`ant-radio${a===t?" ant-radio-checked":""}`)})}}const M=({rect:r,currentPos:t,zoom:e})=>{const i=p.height,o=d.getOffsetCoordinate(r,t,e),n=o.x,a=o.y-i-f;return{left:n<0?0:n,top:a<0?0:a}};export{b as default,M as getSAMToolbarOffset};
@@ -1 +1 @@
1
- import{ImgPosUtils as P,toolStyleConverter as S}from"@labelbee/lb-utils";import{isNumber as M}from"lodash";import{EOperationMode as p,EToolName as y}from"../../constant/tool.js";import R from"../../utils/MathUtils.js";import L,{CoordinateUtils as j}from"../../utils/tool/AxisUtils.js";import T from"../../utils/tool/CanvasUtils.js";import _ from"../../utils/tool/CommonToolUtils.js";import K from"../../utils/tool/LineToolUtils.js";import{EGrowthMode as W,EDragStatus as F,ELang as G}from"../../constant/annotation.js";import w from"../../constant/keyCode.js";import{styleString as H,BASE_ICON as V}from"../../constant/style.js";import k from"../../locales/index.js";import{EMessage as E}from"../../locales/constants.js";import Y from"../../utils/ActionsHistory.js";import B from"../../utils/tool/AttributeUtils.js";import X from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import $ from"../../utils/tool/RenderDomUtils.js";import U from"../../utils/tool/ZoomUtils.js";import q from"./eventListener.js";var J=Object.defineProperty,Q=Object.defineProperties,tt=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,Z=(c,t,i)=>t in c?J(c,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[t]=i,D=(c,t)=>{for(var i in t||(t={}))it.call(t,i)&&Z(c,i,t[i]);if(O)for(var i of O(t))et.call(t,i)&&Z(c,i,t[i]);return c},A=(c,t)=>Q(c,tt(t)),st=(c,t,i)=>new Promise((e,s)=>{var o=n=>{try{r(i.next(n))}catch(a){s(a)}},h=n=>{try{r(i.throw(n))}catch(a){s(a)}},r=n=>n.done?e(n.value):Promise.resolve(n.value).then(o,h);r((i=i.apply(c,t)).next())});const ot={min:.2,max:1e3,ratio:.4};class nt extends q{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=p.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=ot,this.initImgPos=()=>st(this,null,function*(){var l,d;if(!this.imgNode)return;const u=(l=this._imgAttribute)==null?void 0:l.zoomRatio,m=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:f,imgInfo:I,zoom:v}=P.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(I),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,I)}),this.getCurrentPos=l=>{const{_firstClickCoordinate:d,currentPosStorage:u}=this;try{let m;return d&&u?m={y:u.y+l.y-d.y,x:u.x+l.x-d.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(l,d,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const I=U.wheelChangePos(f,l,d,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!I)return;const{currentPos:v,ratio:N,zoom:x,imgInfo:z}=I;this.setZoom(x),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(z),this.zoomInfo.ratio=N,this.emit("renderZoom",x,v,z)},this.zoomChanged=(l,d=W.Linear)=>{const u=U.zoomChanged(this.zoom,l,d);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=l=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,l),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(g.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),g.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,s,o,h,r,n,a,C,b;this.container=t.container,this.config=_.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(e=t.imgNode)==null?void 0:e.width)!=null?s:0,height:(h=(o=t.imgNode)==null?void 0:o.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new Y,this.style=(a=t.style)!=null?a:_.jsonParser(H),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=F.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=G.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new X(this.container,200),this.coordUtils=new j(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return V[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===p.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===p.MultiMove&&this.setOperationMode(p.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return T.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(r))),this.canvas=r,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(D({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:s}=P.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=A(D({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return B.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&e&&h){let r=t;switch(h){case y.Polygon:case y.Line:{if(t.pointList){const a=R.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=P.getBasicRecPos(e,r,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(A(D({},o),{width:o.width/this.innerZoom*n.innerZoom,height:o.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!M(i==null?void 0:i.x)||!M(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||K.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===w.Alt&&t.preventDefault(),t.keyCode){case w.Space:this.isSpaceKey=!0,t.preventDefault();break;case w.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case w.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>this.zoomInfo.min&&(o=-1),s<0&&this.zoom<this.zoomInfo.max&&(o=1),this.wheelChangePos(e,o),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=_.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",k.getMessagesByLocale(E.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",k.getMessagesByLocale(E.NoRotateNotice,this.lang)),!1;const t=R.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return S.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,o,h,r,n,a;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const l=B.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(u=>u.value===t))==null?void 0:r.color)?(a=(n=S.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[l]:""}const{color:C,lineColor:b}=this.style;return C&&b?b[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=$.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case y.Rect:{g.drawRect(this.basicCanvas,L.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,L.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{g.drawLineWithPointList(this.basicCanvas,L.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{nt as BasicToolOperation};
1
+ import{i18n as R,ImgPosUtils as L,toolStyleConverter as k}from"@labelbee/lb-utils";import{isNumber as E}from"lodash";import{EOperationMode as w,EToolName as y}from"../../constant/tool.js";import B from"../../utils/MathUtils.js";import _,{CoordinateUtils as G}from"../../utils/tool/AxisUtils.js";import F from"../../utils/tool/CanvasUtils.js";import D from"../../utils/tool/CommonToolUtils.js";import H from"../../utils/tool/LineToolUtils.js";import{ELang as x,EGrowthMode as V,EDragStatus as Y}from"../../constant/annotation.js";import P from"../../constant/keyCode.js";import{styleString as X,BASE_ICON as $}from"../../constant/style.js";import U from"../../locales/index.js";import{EMessage as Z}from"../../locales/constants.js";import q from"../../utils/ActionsHistory.js";import O from"../../utils/tool/AttributeUtils.js";import J from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import Q from"../../utils/tool/RenderDomUtils.js";import A from"../../utils/tool/ZoomUtils.js";import tt from"./eventListener.js";var it=Object.defineProperty,et=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable,j=(c,t,i)=>t in c?it(c,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[t]=i,z=(c,t)=>{for(var i in t||(t={}))ot.call(t,i)&&j(c,i,t[i]);if(N)for(var i of N(t))nt.call(t,i)&&j(c,i,t[i]);return c},T=(c,t)=>et(c,st(t)),rt=(c,t,i)=>new Promise((e,s)=>{var o=n=>{try{r(i.next(n))}catch(a){s(a)}},h=n=>{try{r(i.throw(n))}catch(a){s(a)}},r=n=>n.done?e(n.value):Promise.resolve(n.value).then(o,h);r((i=i.apply(c,t)).next())});const K={[x.Zh]:"cn",[x.US]:"en"},at={min:.2,max:1e3,ratio:.4};class ht extends tt{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=w.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=at,this.initImgPos=()=>rt(this,null,function*(){var d,l;if(!this.imgNode)return;const u=(d=this._imgAttribute)==null?void 0:d.zoomRatio,m=(l=this._imgAttribute)==null?void 0:l.isOriginalSize,{currentPos:f,imgInfo:I,zoom:v}=L.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(I),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,I)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:l,currentPosStorage:u}=this;try{let m;return l&&u?m={y:u.y+d.y-l.y,x:u.x+d.x-l.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(d,l,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&l===-1)return;const I=A.wheelChangePos(f,d,l,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!I)return;const{currentPos:v,ratio:W,zoom:S,imgInfo:M}=I;this.setZoom(S),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(M),this.zoomInfo.ratio=W,this.emit("renderZoom",S,v,M)},this.zoomChanged=(d,l=V.Linear)=>{const u=A.zoomChanged(this.zoom,d,l);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(g.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),g.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,s,o,h,r,n,a,C,b,p;this.container=t.container,this.config=D.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(e=t.imgNode)==null?void 0:e.width)!=null?s:0,height:(h=(o=t.imgNode)==null?void 0:o.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new q,this.style=(a=t.style)!=null?a:D.jsonParser(X),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=Y.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(p=t==null?void 0:t.language)!=null?p:x.Zh,R.changeLanguage(K[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new J(this.container,200),this.coordUtils=new G(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return $[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===w.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===w.MultiMove&&this.setOperationMode(w.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=K[t];R.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return F.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(r))),this.canvas=r,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(z({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:s}=L.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=T(z({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return O.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&e&&h){let r=t;switch(h){case y.Polygon:case y.Line:{if(t.pointList){const a=B.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=L.getBasicRecPos(e,r,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(T(z({},o),{width:o.width/this.innerZoom*n.innerZoom,height:o.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!E(i==null?void 0:i.x)||!E(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||H.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===P.Alt&&t.preventDefault(),t.keyCode){case P.Space:this.isSpaceKey=!0,t.preventDefault();break;case P.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case P.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>this.zoomInfo.min&&(o=-1),s<0&&this.zoom<this.zoomInfo.max&&(o=1),this.wheelChangePos(e,o),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=D.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",U.getMessagesByLocale(Z.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",U.getMessagesByLocale(Z.NoRotateNotice,this.lang)),!1;const t=B.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return k.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,o,h,r,n,a;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const p=O.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(l=>l.value===t))==null?void 0:r.color)?(a=(n=k.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[p]:""}const{color:C,lineColor:b}=this.style;return C&&b?b[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=Q.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case y.Rect:{g.drawRect(this.basicCanvas,_.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,_.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{g.drawLineWithPointList(this.basicCanvas,_.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{ht as BasicToolOperation};
@@ -0,0 +1 @@
1
+ import n from"../../utils/tool/StyleUtils.js";const i=30,o=10;class l{constructor(t){const{container:e}=t;this.container=e,this._textDOM=this.initTextDOM(),this.appendToContainer()}initTextDOM(){const t=document.createElement("div");return n.setDOMStyle(t,{display:"none",position:"absolute",fontSize:"14px",height:`${i}px`,lineHeight:`${i}px`,padding:"0 8px",borderRadius:"2px",backgroundColor:"#FFFFFF",zIndex:"10",color:"white",whiteSpace:"nowrap"}),t}appendToContainer(){!this._textDOM||this.container.appendChild(this._textDOM)}clearTextDOM(){this._textDOM&&this.container.contains(this._textDOM)&&this.container.removeChild(this._textDOM)}update(t,e,s){const{left:r,top:a}=t;!this._textDOM||(n.setDOMStyle(this._textDOM,{display:"block",left:`${r+o}px`,top:`${a-i-o}px`,backgroundColor:e}),this._textDOM.innerHTML=s)}}export{l as default};
@@ -1 +1 @@
1
- import{i18n as d}from"@labelbee/lb-utils";import m from"../../utils/tool/AxisUtils.js";import{RectOperation as g}from"./rectOperation.js";import f from"../../constant/keyCode.js";var p=(u,e,t)=>new Promise((i,c)=>{var r=s=>{try{o(t.next(s))}catch(h){c(h)}},n=s=>{try{o(t.throw(s))}catch(h){c(h)}},o=s=>s.done?i(s.value):Promise.resolve(s.value).then(r,n);o((t=t.apply(u,e)).next())});class y extends g{constructor(e){super(e);this.onKeydown=t=>{switch(t.keyCode){case f.Esc:t.preventDefault(),t.stopPropagation(),this.clearPredictionInfo();break;case f.Z:t.ctrlKey&&(t.preventDefault(),t.stopPropagation(),this.rectList=[],this.render());break}},this.segmentPrediction=t=>p(this,null,function*(){const i=this.getCoordinateUnderZoom(t);if(this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}yield this.runPrediction({point:i,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),this.clearPredictionInfo()}),this.isRunSegment=!1,this.runPrediction=e.runPrediction}setRunPrediction(e){this.runPrediction=e}eventBinding(){document.addEventListener("keydown",e=>this.onKeydown(e)),super.eventBinding()}clearPredictionInfo(){this.rectList=[],this.isShowCursor=!1,this.coord={x:-1,y:-1},this.drawingRect=void 0,this.isRunSegment=!1,this.clearCanvas(),this.render()}onMouseUp(e){if(!this.isRunSegment){if(e.button===0&&this.rectList.length===1&&!this.isRunSegment){e.stopPropagation(),this.segmentPrediction(e),this.clearActiveStatus();return}super.onMouseUp(e)}}onMouseDown(e){this.isRunSegment||super.onMouseDown(e)}renderCursorLine(){var e;if(!this.ctx)return;const{ctx:t}=this,i=10,c=1,{x:r,y:n}=this.coord;t.save(),t.strokeStyle="white",t.setLineDash([6]),t.lineWidth=c,t.strokeRect(r-i,n-i,i*2,i*2),t.restore();let o=`\u2460 ${d.t("FramingOfObjectToBeDivided")}`;const s=d.language==="en";let h=s?326:186;if(((e=this.rectList)==null?void 0:e.length)===1){o=`\u2461 ${d.t("ClickOnTarget")}`,h=s?232:142;const a=2;t.save(),t.strokeStyle="white";const l=c+i;t.beginPath(),t.moveTo(r+l+a*2,n+l+a),t.arc(r+l+a,n+l+a,a,0,Math.PI*2,!0),t.stroke(),t.restore()}this.isRunSegment&&(h=s?316:136,o=d.t("SplittingAlgorithmPrediction")),t.save(),t.fillStyle=this.style.strokeColor,t.fillRect(r+i,n-i*4-1,h,32),t.restore(),t.save(),t.font="14px Source Han Sans CN",t.fillStyle="white",t.fillText(o,r+i+14,n-i*2),t.restore(),super.renderCursorLine()}renderDrawingRect(e,t,i=!1){if(this.ctx&&e){const c=m.changeRectByZoom(e,i?t:this.zoom,this.currentPos),{x:r,y:n,width:o,height:s}=c;this.ctx.save(),this.ctx.lineCap="butt",this.ctx.lineWidth=this.style.strokeWidth,this.ctx.strokeStyle="white",this.ctx.strokeRect(r,n,o,s),this.ctx.strokeStyle=this.style.strokeColor,this.ctx.setLineDash([6]),this.ctx.strokeRect(r,n,o,s),this.ctx.restore()}}renderTextAttribute(){}renderSelectedRect(){}}export{y as default};
1
+ import{i18n as u}from"@labelbee/lb-utils";import g from"../../utils/tool/AxisUtils.js";import{RectOperation as m}from"./rectOperation.js";import d from"../../constant/keyCode.js";import p from"./cursorTextClass.js";var v=(a,t,e)=>new Promise((s,r)=>{var h=i=>{try{o(e.next(i))}catch(c){r(c)}},n=i=>{try{o(e.throw(i))}catch(c){r(c)}},o=i=>i.done?s(i.value):Promise.resolve(i.value).then(h,n);o((e=e.apply(a,t)).next())});class y extends m{constructor(t){super(t);this.segmentPrediction=e=>v(this,null,function*(){const s=this.getCoordinateInOrigin(e);if(this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}yield this.runPrediction({point:s,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),this.clearPredictionInfo()}),this.isRunSegment=!1,this.runPrediction=t.runPrediction}setRunPrediction(t){this.runPrediction=t}eventBinding(){document.addEventListener("keydown",t=>this.onKeydown(t)),super.eventBinding()}onKeydown(t){switch(t.keyCode){case d.Esc:t.preventDefault(),t.stopPropagation(),this.clearPredictionInfo();break;case d.Z:t.ctrlKey&&(t.preventDefault(),t.stopPropagation(),this.rectList=[],this.render());break}}clearPredictionInfo(){var t;this.rectList=[],this.isShowCursor=!1,this.coord={x:-1,y:-1},this.drawingRect=void 0,this.isRunSegment=!1,(t=this.cursorTextInstance)==null||t.clearTextDOM(),this.cursorTextInstance=void 0,this.clearCanvas(),this.render()}onMouseUp(t){if(!this.isRunSegment){if(t.button===0&&this.rectList.length===1&&!this.isRunSegment){t.stopPropagation(),this.segmentPrediction(t),this.clearActiveStatus();return}super.onMouseUp(t)}}onMouseDown(t){this.isRunSegment||super.onMouseDown(t)}renderCursorLine(){if(!this.ctx)return;const{ctx:t}=this,e=10,s=1,{x:r,y:h}=this.coord,n=this.getLineColor(this.defaultAttribute);t.save(),t.strokeStyle="white",t.setLineDash([6]),t.lineWidth=s,t.strokeRect(r-e,h-e,e*2,e*2),t.restore(),this.renderCursorText(),super.renderCursorLine(n)}renderDrawingRect(t,e,s=!1){var r;if(this.ctx&&t){const h=g.changeRectByZoom(t,s?e:this.zoom,this.currentPos),{x:n,y:o,width:i,height:c}=h,l=(r=e!=null?e:this.zoom)!=null?r:1;this.ctx.save(),this.ctx.lineCap="butt";const x=this.style.strokeWidth,f=10;this.ctx.lineWidth=x,this.ctx.strokeStyle="white",this.ctx.setLineDash([]),this.ctx.strokeRect(n,o,i,c),this.ctx.strokeStyle=this.getLineColor(this.defaultAttribute),this.ctx.setLineDash([f*l]),this.ctx.strokeRect(n,o,i,c),this.ctx.restore()}}cursorText(){var t;let e=`\u2460 ${u.t("FramingOfObjectToBeDivided")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(e=`\u2461 ${u.t("ClickOnTarget")}`),this.isRunSegment&&(e=u.t("SplittingAlgorithmPrediction")),e}renderTextAttribute(){}renderSelectedRect(){}renderCursorText(){var t;if(this.coord.x<0||this.coord.y<0){(t=this.cursorTextInstance)==null||t.clearTextDOM(),this.cursorTextInstance=void 0;return}this.cursorTextInstance||(this.cursorTextInstance=new p({container:this.container}));const e={left:this.coord.x,top:this.coord.y};this.cursorTextInstance.update(e,this.getLineColor(this.defaultAttribute),this.cursorText())}}export{y as default};
@@ -0,0 +1 @@
1
+ import{i18n as r,ELineTypes as _}from"@labelbee/lb-utils";import f from"../../constant/keyCode.js";import T from"../../utils/tool/RectUtils.js";import O from"../../utils/uuid.js";import S from"../../utils/tool/DrawUtils.js";import w from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/StyleUtils.js";import C from"../../utils/ActionsHistory.js";import k,{getSAMToolbarOffset as R}from"./SAMToolbarClass.js";import A from"./segmentByRect.js";var L=Object.defineProperty,j=Object.defineProperties,M=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,D=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,y=(o,t,e)=>t in o?L(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,x=(o,t)=>{for(var e in t||(t={}))D.call(t,e)&&y(o,e,t[e]);if(m)for(var e of m(t))U.call(t,e)&&y(o,e,t[e]);return o},H=(o,t)=>j(o,M(t)),B=(o,t,e)=>new Promise((i,s)=>{var a=n=>{try{h(e.next(n))}catch(d){s(d)}},l=n=>{try{h(e.throw(n))}catch(d){s(d)}},h=n=>n.done?i(n.value):Promise.resolve(n.value).then(a,l);h((e=e.apply(o,t)).next())});class E extends A{constructor(t){super(t);this.segmentPrediction=e=>B(this,null,function*(){var i,s,a,l,h,n,d,g;if(this.isRunSegment)return;const c=this.getCoordinateInOrigin(e),b={x:0,y:0,width:(s=(i=this.basicImgInfo)==null?void 0:i.width)!=null?s:0,height:(l=(a=this.basicImgInfo)==null?void 0:a.height)!=null?l:0};if(!T.isInRect(c,b,0,1)){(h=this.onOutSide)==null||h.call(this);return}if(this.clickType==="add"&&this.addPoints.push([c.x,c.y]),this.clickType==="remove"&&this.removePoints.push([c.x,c.y]),this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}(n=this.toolbarInstance)==null||n.setDisabled(!0);try{const v=yield this.runPrediction({addPoints:this.addPoints,removePoints:this.removePoints,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),P=v==null?void 0:v.filter(u=>{var p;return((p=u==null?void 0:u.pointList)==null?void 0:p.length)>2}).map(u=>H(x({},u),{id:O(),attribute:this.defaultAttribute}));this.predictionResult=P,(d=this.SAMHistory)==null||d.pushHistory(this.predictionResult)}finally{(g=this.toolbarInstance)==null||g.setDisabled(!1),this.isRunSegment=!1}}),this.clickType="add",this.addPoints=[],this.removePoints=[],this.predictionResult=[],this.onOutSide=t.onOutSide,this.onFinish=t.onFinish,this.SAMHistory=new C,this.clearPredictionInfo=this.clearPredictionInfo.bind(this),this.onLanguageChanged=this.onLanguageChanged.bind(this)}onKeydown(t){switch(super.onKeydown(t),t.keyCode){case f.Minus:this.toggleClickType("remove");break;case f.Equal:this.toggleClickType("add");break}}onMouseUp(t){var e;if(t.button===0&&((e=this.rectList)==null?void 0:e.length)){this.segmentPrediction(t);return}super.onMouseUp(t)}eventBinding(){super.eventBinding(),r.on("languageChanged",this.onLanguageChanged)}eventUnbinding(){super.eventUnbinding(),r.off("languageChanged",this.onLanguageChanged)}setOnOutSide(t){this.onOutSide=t}onMouseDown(t){var e;t.button===0&&((e=this.rectList)==null?void 0:e.length)||super.onMouseDown(t)}onLanguageChanged(){var t;(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,this.renderToolbar()}drawPredictionResult(){var t;const e=this.getColor(this.defaultAttribute);(t=this.predictionResult)==null||t.forEach(i=>{this.drawPolygon(i,e)})}drawPolygon(t,e){var i,s;const a=w.changePointListByZoom(t.pointList,this.zoom,this.currentPos),l=I.getStrokeAndFill(e,!0,{isHover:!0});S.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:l.fill,strokeColor:l.stroke,thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineType:_.Line})}clearPredictionInfo(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,super.clearPredictionInfo(),this.render()}renderToolbar(){const t=this.rectList[0];if(!t)return;this.toolbarInstance||(this.toolbarInstance=new k({container:this.container,toggleClickType:i=>this.toggleClickType(i),finish:()=>{var i,s;(s=this.onFinish)==null||s.call(this,(i=this.predictionResult)!=null?i:[]),this.clearPredictionInfo()},reset:()=>this.reset(),i18n:r}));const e=R({rect:t,zoom:this.zoom,currentPos:this.currentPos});this.toolbarInstance.update(e)}toggleClickType(t){var e;this.clickType=t,(e=this.toolbarInstance)==null||e.onToggle(t),this.render()}reset(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.SAMHistory)==null||t.empty(),this.render()}cursorText(){var t;let e=`\u2460 ${r.t("PleaseFrameTheObjectToBeDividedFirst")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(this.clickType==="add"&&(e=this.addPoints.length===0?`\u2461 ${r.t("ClickOnTheTargetObjectToSplitIt")}`:`\u2461 ${r.t("ClickTheTargetObjectAgainToIncreaseTheSegmentation")}`),this.clickType==="remove"&&(e=this.removePoints.length===0?`\u2461 ${r.t("ClickOnTheTargetObjectToDeleteTheSegmentation")}`:`\u2461 ${r.t("ClickAgainOnTheTargetObjectToDeleteTheSegmentation")}`)),this.isRunSegment&&(e=r.t("SplittingAlgorithmPrediction")),e}undo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.undo();this.predictionResult=e,this.render()}redo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.redo();this.predictionResult=e,this.render()}render(){var t,e;if(super.render(),(t=this.rectList)==null?void 0:t.length){this.renderToolbar(),this.drawPredictionResult();return}(e=this.toolbarInstance)==null||e.clearToolbarDOM(),this.toolbarInstance=void 0}}export{E as default};
package/es/index.js CHANGED
@@ -1 +1 @@
1
- export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as i from"./constant/style.js";export{i as cStyle};import*as a from"./constant/tool.js";export{a as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
1
+ export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";export{default as SegmentByRect}from"./core/toolOperation/segmentByRect.js";export{default as SegmentBySAM}from"./core/toolOperation/segmentBySAM.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as CanvasUtils}from"./utils/tool/CanvasUtils.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{default as CursorTextClass}from"./core/toolOperation/cursorTextClass.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,lidar2FisheyeImage,lidar2image,mergeHighlightList,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
@@ -1 +1 @@
1
- import g from"../MathUtils.js";class c{static getMousePositionOnCanvasFromEvent(i,t){if(t&&i){const n=t.getBoundingClientRect();return{x:i.clientX-n.left,y:i.clientY-n.top}}return null}static getClientRect(i){if(i){const t=i.getBoundingClientRect();return{x:t.left,y:t.top,width:t.width,height:t.height}}return null}static getSize(i){if(i){const t=i.getBoundingClientRect();return{width:t.width,height:t.height}}return null}static inViewPort(i,t){return i?g.isInRange(i.x,[t.left,t.right])&&g.isInRange(i.y,[t.top,t.bottom]):!1}static createCanvas(i){const t=document.createElement("canvas"),{width:n,height:a}=i;t.width=n,t.height=a;const s=t.getContext("2d");return{canvas:t,ctx:s}}}c.getViewPort=(e,i,t)=>{const{width:n,height:a}=e,{x:s,y:l}=i,o=(0-l)/t,r=(0-s)/t,h=o+a/t,u=r+n/t;return{top:o,bottom:h,left:r,right:u}},c.getPixelRatio=e=>{if(!e||!window)return 1;const i=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/i};export{c as default};
1
+ import g from"../MathUtils.js";class l{static getMousePositionOnCanvasFromEvent(i,t){if(t&&i){const n=t.getBoundingClientRect();return{x:i.clientX-n.left,y:i.clientY-n.top}}return null}static getClientRect(i){if(i){const t=i.getBoundingClientRect();return{x:t.left,y:t.top,width:t.width,height:t.height}}return null}static getSize(i){if(i){const t=i.getBoundingClientRect();return{width:t.width,height:t.height}}return null}static inViewPort(i,t){return i?g.isInRange(i.x,[t.left,t.right])&&g.isInRange(i.y,[t.top,t.bottom]):!1}static createCanvas(i,t){const n=document.createElement("canvas"),{width:s,height:c}=i;n.width=s,n.height=c;const a=n.getContext("2d");return t&&a&&(a.fillStyle=t,a.fillRect(0,0,i.width,i.height)),{canvas:n,ctx:a}}}l.getViewPort=(e,i,t)=>{const{width:n,height:s}=e,{x:c,y:a}=i,r=(0-a)/t,o=(0-c)/t,h=r+s/t,u=o+n/t;return{top:r,bottom:h,left:o,right:u}},l.getPixelRatio=e=>{if(!e||!window)return 1;const i=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/i};export{l as default};
@@ -1 +1 @@
1
- import{polygon as S,difference as _,union as j}from"@turf/turf";import{ERotateDirection as B}from"../../constant/annotation.js";import F from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as M}from"../../constant/tool.js";import D from"./AxisUtils.js";import C from"../MathUtils.js";import z from"./LineToolUtils.js";var N=Object.defineProperty,b=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,O=(p,t,e)=>t in p?N(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,A=(p,t)=>{for(var e in t||(t={}))R.call(t,e)&&O(p,e,t[e]);if(b)for(var e of b(t))T.call(t,e)&&O(p,e,t[e]);return p};class g{static getHoverPolygonID(t,e,n=3,i=y.Line){let r="",l=Infinity;const o=D.axisArea(t,n);return e.forEach(s=>{s.pointList&&o.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<l&&(r=s.id,l=u)})}),r}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,n=t.reduce((i,r,l,o)=>{const s=o[(l+1)%e];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(t,e,n=y.Line){let i=0,r,l,o,s;e=[...e],n===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((u,h)=>[...u,h.x,h.y],[]),.5,!0,20)),[o]=e;const c=e.length;for(r=1;r<=c;r++)s=e[r%c],t.x>Math.min(o.x,s.x)&&t.x<=Math.max(o.x,s.x)&&t.y<=Math.max(o.y,s.y)&&o.x!==s.x&&(l=(t.x-o.x)*(s.y-o.y)/(s.x-o.x)+o.y,(o.y===s.y||t.y<=l)&&i++),o=s;return i%2!=0}static createSmoothCurvePointsFromPointList(t,e=M){return this.createSmoothCurvePoints(t.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,e).map((i,r)=>{var l;const o=r/(M+1),s=Math.floor(o),c=(l=t[s])!=null?l:{};return A(s===o?A({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,n=!1,i=M){if(t.length<4)return t;const r=[],l=t.slice(0);let o,s,c,u,h,m,v,L,P,E,a,d,f;for(n?(l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.push(t[0]),l.push(t[1])):(l.unshift(t[1]),l.unshift(t[0]),l.push(t[t.length-2]),l.push(t[t.length-1])),f=2;f<l.length-4;f+=2)for(c=(l[f+2]-l[f-2])*e,u=(l[f+4]-l[f-0])*e,h=(l[f+3]-l[f-1])*e,m=(l[f+5]-l[f+1])*e,d=0;d<=i;d++)a=d/i,v=2*Math.pow(a,3)-3*Math.pow(a,2)+1,L=-(2*Math.pow(a,3))+3*Math.pow(a,2),P=Math.pow(a,3)-2*Math.pow(a,2)+a,E=Math.pow(a,3)-Math.pow(a,2),o=v*l[f]+L*l[f+2]+P*c+E*u,s=v*l[f+1]+L*l[f+3]+P*h+E*m,r.push(o),r.push(s);const I=[];for(let x=0;x<r.length-1;x+=2)I.push({x:r[x],y:r[x+1]});if(n)for(let x=0;x<i+1;x++){const w=I.shift();I.push(w)}return I}static getPolygonByID(t,e){return t.find(n=>n.id===e)}static getPolygonByIDs(t,e){return e&&(e==null?void 0:e.length)>0?t.filter(n=>e.includes(n.id)):[]}static getHoverEdgeIndex(t,e,n=y.Line,i=3){let r=[...e];n===y.Curve?r=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,M):n===y.Line&&r.push(r[0]);let l=-1,o=i;for(let s=0;s<r.length-1;s++){const{length:c}=C.getFootOfPerpendicular(t,r[s],r[s+1]);c<o&&(l=s,o=c)}return l===-1?-1:n===y.Curve?Math.floor(l/M):l}static getClosestPoint(t,e,n=y.Line,i=3,r){var l;let o=!1;const s=(l=r==null?void 0:r.isClose)!=null?l:!0;let c="",u=-1,h=Infinity,m=t;const v=20;let L=!1;return e.forEach(P=>{if(!L&&!!P.pointList)switch(n){case y.Line:F.findAllLine(P.pointList,s).forEach((a,d)=>{if(L)return;let{length:f,footPoint:I}=C.getFootOfPerpendicular(t,a.point1,a.point2);const x=C.getLineLength(a.point1,t),w=C.getLineLength(a.point2,t);x<i*2&&(I=a.point1,f=x,L=!0),w<i*2&&(I=a.point2,f=w,L=!0),f<h&&f<i&&(c=P.id,u=d,h=f,m=I,o=!0)});break;case y.Curve:{const E=this.createSmoothCurvePoints(P.pointList.reduce((a,d)=>[...a,d.x,d.y],[]),.5,s,v);for(let a=0;a<E.length-1;a++){const{length:d,footPoint:f}=C.getFootOfPerpendicular(t,E[a],E[a+1]);d<h&&d<i&&(c=P.id,u=Math.floor(a/(v+1)),h=d,m=f,o=!0)}}break}}),{dropFoot:m,closestEdgeIndex:u,closestPolygonID:c,hasClosed:o}}static isPointListInPolygon(t,e,n=y.Line){return t.every(i=>this.isInPolygon(i,e,n))}static isPointListOutSidePolygon(t,e,n=y.Line){return t.some(i=>!this.isInPolygon(i,e,n))}static getPolygonArea(t){let e=0;for(let n=0,i=t.length;n<i;n++){const r=t[n].x,l=t[n===t.length-1?0:n+1].y,o=t[n===t.length-1?0:n+1].x,s=t[n].y;e+=r*l*.5,e-=o*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,n){let i=1;return t===B.Anticlockwise&&(i=-1),i*=e,C.rotateRectPointList(i,n)}static deletePolygonLastPoint(t,e,n,i){return n===i.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var n,i;try{let r=S([[...g.concatBeginAndEnd(t.map(o=>[o.x,o.y]))]]);return e.forEach(o=>{const s=S([[...g.concatBeginAndEnd(o.pointList.map(u=>[u.x,u.y]))]]),c=_(r,s);c&&(r=c)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(o=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?o[0].reduce(g.deletePolygonLastPoint,[]):o.reduce(g.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((o,s)=>{const c=s.length,u=s.filter((h,m)=>{const v=(m+1)%c;return!D.getIsInScope(h,s[v],1)});return u.length<3?o:[...o,u]},[])}catch(r){console.error(r)}}static getPolygonPointList(t,e){const n=e.find(i=>i.id===t);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(n=>g.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=g.isPolygonClosewise(e),i=g.isPolygonClosewise(t),r=g.getClosePointDistanceFromPolygon(t[0],e),l=e[r];let o=[...e.slice(0,r),l,...t,t[0],...e.slice(r,e.length)];return n===i&&(o=[...e.slice(0,r),l,t[0],...t.reverse(),...e.slice(r,e.length)]),o}static isPolygonClosewise(t){const e=t.length;let n,i,r,l=0,o;if(e<3)return 0;for(n=0;n<e;n++)i=(n+1)%e,r=(n+2)%e,o=(t[i].x-t[n].x)*(t[r].y-t[i].y),o-=(t[i].y-t[n].y)*(t[r].x-t[i].x),o<0?l--:o>0&&l++;return l>0?1:l<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let n=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((r,l)=>{const o=z.calcDistance(t,r);o<n&&(n=o,i=l)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const r=S([[...g.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),l=S([[...g.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),o=j(r,l),s=[],c=t;if(((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=o==null?void 0:o.geometry.coordinates.map(h=>{var m;return((m=o==null?void 0:o.geometry)==null?void 0:m.type)==="MultiPolygon"?h[0].reduce(g.deletePolygonLastPoint,[]):h.reduce(g.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(r){console.error(r)}}}export{g as default};
1
+ import{polygon as A,difference as B,union as O}from"@turf/turf";import{ERotateDirection as F}from"../../constant/annotation.js";import N from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as p}from"../../constant/tool.js";import D from"./AxisUtils.js";import L from"../MathUtils.js";import b from"./LineToolUtils.js";var z=Object.defineProperty,_=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,j=(M,t,e)=>t in M?z(M,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):M[t]=e,S=(M,t)=>{for(var e in t||(t={}))R.call(t,e)&&j(M,e,t[e]);if(_)for(var e of _(t))T.call(t,e)&&j(M,e,t[e]);return M};class h{static getHoverPolygonID(t,e,n=3,i=y.Line){let o="",r=Infinity;const l=D.axisArea(t,n);return e.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(o=s.id,r=u)})}),o}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,n=t.reduce((i,o,r,l)=>{const s=l[(r+1)%e];return i+o.x*s.y-s.x*o.y},0);return Math.abs(n)/2}static isInPolygon(t,e,n=y.Line){let i=0,o,r,l,s;e=[...e],n===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((u,d)=>[...u,d.x,d.y],[]),.5,!0,20)),[l]=e;const c=e.length;for(o=1;o<=c;o++)s=e[o%c],t.x>Math.min(l.x,s.x)&&t.x<=Math.max(l.x,s.x)&&t.y<=Math.max(l.y,s.y)&&l.x!==s.x&&(r=(t.x-l.x)*(s.y-l.y)/(s.x-l.x)+l.y,(l.y===s.y||t.y<=r)&&i++),l=s;return i%2!=0}static createSmoothCurvePointsFromPointList(t,e=p){return this.createSmoothCurvePoints(t.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!1,e).map((i,o)=>{var r;const l=o/(p+1),s=Math.floor(l),c=(r=t[s])!=null?r:{};return S(s===l?S({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,n=!1,i=p){if(t.length<4)return t;const o=[],r=t.slice(0);let l,s,c,u,d,m,v,E,P,I,a,g,f;for(n?(r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.push(t[0]),r.push(t[1])):(r.unshift(t[1]),r.unshift(t[0]),r.push(t[t.length-2]),r.push(t[t.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*e,u=(r[f+4]-r[f-0])*e,d=(r[f+3]-r[f-1])*e,m=(r[f+5]-r[f+1])*e,g=0;g<=i;g++)a=g/i,v=2*Math.pow(a,3)-3*Math.pow(a,2)+1,E=-(2*Math.pow(a,3))+3*Math.pow(a,2),P=Math.pow(a,3)-2*Math.pow(a,2)+a,I=Math.pow(a,3)-Math.pow(a,2),l=v*r[f]+E*r[f+2]+P*c+I*u,s=v*r[f+1]+E*r[f+3]+P*d+I*m,o.push(l),o.push(s);const C=[];for(let x=0;x<o.length-1;x+=2)C.push({x:o[x],y:o[x+1]});if(n)for(let x=0;x<i+1;x++){const w=C.shift();C.push(w)}return C}static getPolygonByID(t,e){return t.find(n=>n.id===e)}static getPolygonByIDs(t,e){return e&&(e==null?void 0:e.length)>0?t.filter(n=>e.includes(n.id)):[]}static getHoverEdgeIndex(t,e,n=y.Line,i=3){let o=[...e];n===y.Curve?o=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,p):n===y.Line&&o.push(o[0]);let r=-1,l=i;for(let s=0;s<o.length-1;s++){const{length:c}=L.getFootOfPerpendicular(t,o[s],o[s+1]);c<l&&(r=s,l=c)}return r===-1?-1:n===y.Curve?Math.floor(r/p):r}static getClosestPoint(t,e,n=y.Line,i=3,o){var r;let l=!1;const s=(r=o==null?void 0:o.isClose)!=null?r:!0;let c="",u=-1,d=Infinity,m=t;const v=20;let E=!1;return e.forEach(P=>{if(!E&&!!P.pointList)switch(n){case y.Line:N.findAllLine(P.pointList,s).forEach((a,g)=>{if(E)return;let{length:f,footPoint:C}=L.getFootOfPerpendicular(t,a.point1,a.point2);const x=L.getLineLength(a.point1,t),w=L.getLineLength(a.point2,t);x<i*2&&(C=a.point1,f=x,E=!0),w<i*2&&(C=a.point2,f=w,E=!0),f<d&&f<i&&(c=P.id,u=g,d=f,m=C,l=!0)});break;case y.Curve:{const I=this.createSmoothCurvePoints(P.pointList.reduce((a,g)=>[...a,g.x,g.y],[]),.5,s,v);for(let a=0;a<I.length-1;a++){const{length:g,footPoint:f}=L.getFootOfPerpendicular(t,I[a],I[a+1]);g<d&&g<i&&(c=P.id,u=Math.floor(a/(v+1)),d=g,m=f,l=!0)}}break}}),{dropFoot:m,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(t,e,n=y.Line){return t.every(i=>this.isInPolygon(i,e,n))}static isPointListOutSidePolygon(t,e,n=y.Line){return t.some(i=>!this.isInPolygon(i,e,n))}static getPolygonArea(t){let e=0;for(let n=0,i=t.length;n<i;n++){const o=t[n].x,r=t[n===t.length-1?0:n+1].y,l=t[n===t.length-1?0:n+1].x,s=t[n].y;e+=o*r*.5,e-=l*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,n){let i=1;return t===F.Anticlockwise&&(i=-1),i*=e,L.rotateRectPointList(i,n)}static deletePolygonLastPoint(t,e,n,i){return n===i.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var n,i;try{let o=A([[...h.concatBeginAndEnd(t.map(l=>[l.x,l.y]))]]);return e.forEach(l=>{const s=A([[...h.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=B(o,s);c&&(o=c)}),((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates.map(l=>{var s;return((s=o==null?void 0:o.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(h.deletePolygonLastPoint,[]):l.reduce(h.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((d,m)=>{const v=(m+1)%c;return!D.getIsInScope(d,s[v],1)});return u.length<3?l:[...l,u]},[])}catch(o){console.error(o)}}static getPolygonPointList(t,e){const n=e.find(i=>i.id===t);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(n=>h.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=h.isPolygonClosewise(e),i=h.isPolygonClosewise(t),o=h.getClosePointDistanceFromPolygon(t[0],e),r=e[o];let l=[...e.slice(0,o),r,...t,t[0],...e.slice(o,e.length)];return n===i&&(l=[...e.slice(0,o),r,t[0],...t.reverse(),...e.slice(o,e.length)]),l}static isPolygonClosewise(t){const e=t.length;let n,i,o,r=0,l;if(e<3)return 0;for(n=0;n<e;n++)i=(n+1)%e,o=(n+2)%e,l=(t[i].x-t[n].x)*(t[o].y-t[i].y),l-=(t[i].y-t[n].y)*(t[o].x-t[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let n=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((o,r)=>{const l=b.calcDistance(t,o);l<n&&(n=l,i=r)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const o=A([[...h.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),r=A([[...h.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),l=O(o,r),s=[],c=t;if(((i=(n=l==null?void 0:l.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=l==null?void 0:l.geometry.coordinates.map(d=>{var m;return((m=l==null?void 0:l.geometry)==null?void 0:m.type)==="MultiPolygon"?d[0].reduce(h.deletePolygonLastPoint,[]):d.reduce(h.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(o){console.error(o)}}static composePointList(t,e){let n=0,i=0,o=Number.MAX_VALUE;return t.forEach((r,l)=>{e.forEach((s,c)=>{const u=b.calcDistance(r,s);u<o&&(n=l+1,i=c+1,o=u)})}),[...t.slice(0,n),...e.slice(i,e.length),...e.slice(0,i),...t.slice(n,t.length)]}static composeSegmentPolygonList(t){var e,n;const i=[];for(let o=0;o<t.length;o++)for(let r=0;r<t.length;r++){const l=(e=t[o])==null?void 0:e.pointList,s=(n=t[r])==null?void 0:n.pointList;o!==r&&l&&s&&h.isPointListInPolygon(s,l)&&(t[o].pointList=h.composePointList(l,s),i.unshift(r))}return i.forEach(o=>{t.splice(o,1)}),t}}export{h as default};
@@ -1 +1 @@
1
- class d{static getStrokeAndFill(e,i=!0,r={}){const{isSelected:s=!1,isHover:l=!1}=r;return s?{stroke:i?e.validSelected.stroke:e.invalidSelected.stroke,fill:i?e.validSelected.fill:e.invalidSelected.fill}:l?{stroke:i?e.validHover.stroke:e.invalidHover.stroke,fill:i?e.validHover.fill:e.invalidHover.fill}:{stroke:i?e.valid.stroke:e.invalid.stroke,fill:i?e.valid.fill:e.invalid.fill}}static getStyle2String(e){if(!!e)return Object.entries(e).reduce((i,r)=>`${i} ${r[0]}: ${r[1]};`,"")}}export{d as default};
1
+ class f{static getStrokeAndFill(e,i=!0,r={}){const{isSelected:s=!1,isHover:t=!1}=r;return s?{stroke:i?e.validSelected.stroke:e.invalidSelected.stroke,fill:i?e.validSelected.fill:e.invalidSelected.fill}:t?{stroke:i?e.validHover.stroke:e.invalidHover.stroke,fill:i?e.validHover.fill:e.invalidHover.fill}:{stroke:i?e.valid.stroke:e.invalid.stroke,fill:i?e.valid.fill:e.invalid.fill}}static getStyle2String(e){if(!!e)return Object.entries(e).reduce((i,r)=>`${i} ${r[0]}: ${r[1]};`,"")}static setDOMStyle(e,i){return Object.keys(i).forEach(r=>{e.style[r]!==i[r]&&(e.style[r]=i[r])}),e}}export{f as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.21.0-alpha.1",
3
+ "version": "1.21.0-dev.2",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -94,7 +94,7 @@
94
94
  "typescript": "^4.2.3"
95
95
  },
96
96
  "dependencies": {
97
- "@labelbee/lb-utils": "1.13.1-alpha.1",
97
+ "@labelbee/lb-utils": "1.14.0-dev.1",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",