@labelbee/lb-annotation 1.19.0-alpha.4 → 1.20.0-alpha.1

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 (34) hide show
  1. package/dist/core/pointCloud/index.js +2 -2
  2. package/dist/core/pointCloud/matrix.js +1 -1
  3. package/dist/core/pointCloud/segmentation.js +1 -1
  4. package/dist/core/pointCloud/selector/rectSelector.js +1 -0
  5. package/dist/core/pointCloud/store/index.js +1 -1
  6. package/dist/core/toolOperation/ViewOperation.js +1 -1
  7. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/types/core/pointCloud/index.d.ts +3 -2
  10. package/dist/types/core/pointCloud/matrix.d.ts +25 -3
  11. package/dist/types/core/pointCloud/segmentation.d.ts +5 -2
  12. package/dist/types/core/pointCloud/selector/rectSelector.d.ts +8 -0
  13. package/dist/types/core/pointCloud/store/index.d.ts +10 -0
  14. package/dist/types/core/toolOperation/ViewOperation.d.ts +11 -3
  15. package/dist/types/core/toolOperation/basicToolOperation.d.ts +4 -0
  16. package/dist/types/utils/ImgUtils.d.ts +12 -0
  17. package/dist/types/utils/color.d.ts +5 -0
  18. package/dist/types/utils/tool/CanvasUtils.d.ts +4 -0
  19. package/dist/types/utils/tool/DrawUtils.d.ts +15 -0
  20. package/dist/utils/ImgUtils.js +1 -1
  21. package/dist/utils/tool/CanvasUtils.js +1 -1
  22. package/dist/utils/tool/DrawUtils.js +3 -3
  23. package/es/core/pointCloud/index.js +2 -2
  24. package/es/core/pointCloud/matrix.js +1 -1
  25. package/es/core/pointCloud/segmentation.js +1 -1
  26. package/es/core/pointCloud/selector/rectSelector.js +1 -0
  27. package/es/core/pointCloud/store/index.js +1 -1
  28. package/es/core/toolOperation/ViewOperation.js +1 -1
  29. package/es/core/toolOperation/basicToolOperation.js +1 -1
  30. package/es/index.js +1 -1
  31. package/es/utils/ImgUtils.js +1 -1
  32. package/es/utils/tool/CanvasUtils.js +1 -1
  33. package/es/utils/tool/DrawUtils.js +3 -3
  34. package/package.json +2 -2
@@ -63,6 +63,9 @@ declare class PointCloudStore {
63
63
  */
64
64
  get formatData(): {
65
65
  attribute: string;
66
+ subAttribute: {
67
+ [x: string]: string;
68
+ } | undefined;
66
69
  id: string;
67
70
  indexes: number[];
68
71
  }[];
@@ -109,6 +112,13 @@ declare class PointCloudStore {
109
112
  resetAllSegDataSizeAndRender(): void;
110
113
  highlightPoints(newPoints: ThreePoints): void;
111
114
  highlightPointsByAttribute(attribute: string): void;
115
+ /**
116
+ * Get All segment indexes by attribute.
117
+ * @param attribute
118
+ * @returns
119
+ */
120
+ getHighlightAttribute(attribute: string): number[][];
112
121
  setAttribute(attribute: string): void;
122
+ setSubAttribute(key: string, value: string): void;
113
123
  }
114
124
  export default PointCloudStore;
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * 查看模式 - 支持简单数据注入查看
3
3
  */
4
- import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, IBasicStyle, TAnnotationViewCuboid } from '@labelbee/lb-utils';
4
+ import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, TAnnotationViewPixelPoints, IBasicStyle, TAnnotationViewCuboid } from '@labelbee/lb-utils';
5
5
  import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
6
6
  interface IViewOperationProps extends IBasicToolOperationProps {
7
7
  style: IBasicStyle;
8
+ staticMode?: boolean;
8
9
  annotations: TAnnotationViewData[];
9
10
  }
10
11
  export interface ISpecificStyle {
@@ -25,6 +26,7 @@ export default class ViewOperation extends BasicToolOperation {
25
26
  private renderDomInstance;
26
27
  private connectionPoints;
27
28
  private connectPointsStatus?;
29
+ private cacheCanvas?;
28
30
  constructor(props: IViewOperationProps);
29
31
  clearConnectionPoints(): void;
30
32
  /**
@@ -35,6 +37,11 @@ export default class ViewOperation extends BasicToolOperation {
35
37
  setLoading(loading: boolean): void;
36
38
  onMouseLeave(): void;
37
39
  onMouseDown(e: MouseEvent): true | undefined;
40
+ setImgNode(imgNode: HTMLImageElement, basicImgInfo?: Partial<{
41
+ valid: boolean;
42
+ rotate: number;
43
+ }>): void;
44
+ generateStaticImgNode(): void;
38
45
  onMouseMove(e: MouseEvent): void;
39
46
  getHoverRectID: (e: MouseEvent) => string | undefined;
40
47
  updateData(annotations: TAnnotationViewData[]): void;
@@ -80,9 +87,9 @@ export default class ViewOperation extends BasicToolOperation {
80
87
  getRenderStyle(annotation: TAnnotationViewData): {
81
88
  style: {
82
89
  radius: any;
83
- fill: any;
84
- thickness: any;
85
90
  stroke: any;
91
+ thickness: any;
92
+ fill: any;
86
93
  };
87
94
  fontStyle: {
88
95
  color: string;
@@ -97,6 +104,7 @@ export default class ViewOperation extends BasicToolOperation {
97
104
  renderPolygon(annotation: TAnnotationViewPolygon): void;
98
105
  renderSingleCuboid(annotation: TAnnotationViewCuboid): void;
99
106
  renderBox3d(annotation: TAnnotationViewBox3d): void;
107
+ renderPixelPoints(annotation: TAnnotationViewPixelPoints): void;
100
108
  render(): void;
101
109
  }
102
110
  export {};
@@ -10,6 +10,7 @@ interface IBasicToolOperationProps {
10
10
  container: HTMLElement;
11
11
  size: ISize;
12
12
  imgNode?: HTMLImageElement;
13
+ staticMode?: boolean;
13
14
  style?: any;
14
15
  rotate?: number;
15
16
  imgAttribute?: any;
@@ -40,6 +41,7 @@ declare class BasicToolOperation extends EventListener {
40
41
  canvas: HTMLCanvasElement;
41
42
  basicCanvas: HTMLCanvasElement;
42
43
  imgNode?: HTMLImageElement;
44
+ staticImgNode?: HTMLImageElement;
43
45
  basicImgInfo: any;
44
46
  isImgError: boolean;
45
47
  basicResult?: any;
@@ -57,6 +59,7 @@ declare class BasicToolOperation extends EventListener {
57
59
  imgInfo?: ISize;
58
60
  isDrag: boolean;
59
61
  isSpaceKey: boolean;
62
+ staticMode: boolean;
60
63
  attributeLockList: string[];
61
64
  dblClickListener: DblClickEventListener;
62
65
  isHidden: boolean;
@@ -247,6 +250,7 @@ declare class BasicToolOperation extends EventListener {
247
250
  zoomChangeOnCenter: (newZoom: number) => void;
248
251
  renderCursorLine(lineColor?: any): void;
249
252
  drawImg: () => void;
253
+ drawStaticImg: () => void;
250
254
  /**
251
255
  * 更改当前 canvas 整体的大小,需要重新初始化
252
256
  * @param size
@@ -1,3 +1,15 @@
1
1
  export default class ImgUtils {
2
2
  static load(src: string): Promise<HTMLImageElement>;
3
3
  }
4
+ /**
5
+ * Creates a new canvas, crops and enlarges an existing canvas, draws the cropped and enlarged image onto the new canvas,
6
+ * and returns the data URL of the new canvas.
7
+ *
8
+ * @param {HTMLCanvasElement} canvas - The original canvas to be cropped and enlarged
9
+ * @param {number} width - The width of the area to be cropped from the center of the original canvas
10
+ * @param {number} height - The height of the area to be cropped from the center of the original canvas
11
+ * @param {number} scale - The amount by which to enlarge the cropped area
12
+ * @returns {string} - A data URL of the cropped and enlarged image
13
+ */
14
+ declare const cropAndEnlarge: (canvas: HTMLCanvasElement, width: number, height: number, scale: number) => string;
15
+ export { cropAndEnlarge };
@@ -0,0 +1,5 @@
1
+ export declare const getColorValues: (rgbString: string) => {
2
+ red: number;
3
+ green: number;
4
+ blue: number;
5
+ };
@@ -43,4 +43,8 @@ export default class CanvasUtils {
43
43
  * @returns
44
44
  */
45
45
  static getPixelRatio: (context: any) => number;
46
+ static createCanvas(size: ISize): {
47
+ canvas: HTMLCanvasElement;
48
+ ctx: CanvasRenderingContext2D | null;
49
+ };
46
50
  }
@@ -1,4 +1,5 @@
1
1
  import type { ICuboid, ICuboidConfig, IDrawingCuboid } from '@/types/tool/cuboid';
2
+ import { IPixelPoints } from '@labelbee/lb-utils';
2
3
  import { ELineTypes } from '../../constant/tool';
3
4
  import { IPolygonPoint } from '../../types/tool/polygon';
4
5
  export interface IDrawTextConfig {
@@ -193,4 +194,18 @@ export default class DrawUtils {
193
194
  headerText?: string;
194
195
  bottomText?: string;
195
196
  }): void;
197
+ /**
198
+ * Draw by points
199
+ *
200
+ * points.length === 100,000++.
201
+ * @param param0
202
+ * @returns
203
+ */
204
+ static drawPixel({ canvas, points, size, }: {
205
+ canvas: HTMLCanvasElement;
206
+ points: IPixelPoints[];
207
+ size: ISize;
208
+ }): {
209
+ canvas: HTMLCanvasElement;
210
+ };
196
211
  }
@@ -1 +1 @@
1
- "use strict";class ImgUtils{static load(s){return new Promise((o,r)=>{const e=new Image;e.crossOrigin="anonymous",s.startsWith("file")?e.src=encodeURI(s):e.src=s,e.onload=()=>{o(e)},e.onerror=()=>{r(e)}})}}module.exports=ImgUtils;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class ImgUtils{static load(t){return new Promise((n,o)=>{const e=new Image;e.crossOrigin="anonymous",t.startsWith("file")?e.src=encodeURI(t):e.src=t,e.onload=()=>{n(e)},e.onerror=()=>{o(e)}})}}const cropAndEnlarge=(r,t,n,o)=>{if(!r)return"";const e=r.width/2,d=r.height/2,a=e-t/2,i=d-n/2,s=document.createElement("canvas");s.width=t*o,s.height=n*o;const c=s.getContext("2d");return c==null||c.drawImage(r,a,i,t,n,0,0,t*o,n*o),s.toDataURL()};exports.cropAndEnlarge=cropAndEnlarge,exports.default=ImgUtils;
@@ -1 +1 @@
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}}CanvasUtils.getViewPort=(e,i,t)=>{const{width:n,height:s}=e,{x:l,y:o}=i,a=(0-o)/t,r=(0-l)/t,g=a+s/t,c=r+n/t;return{top:a,bottom:g,left:r,right:c}},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
+ "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,3 +1,3 @@
1
- "use strict";var tool=require("../../constant/tool.js"),PolygonUtils=require("./PolygonUtils.js"),UnitUtils=require("./UnitUtils.js"),AxisUtils=require("./AxisUtils.js"),CuboidUtils=require("./CuboidUtils.js"),AttributeUtils=require("./AttributeUtils.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,i)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,__spreadValues=(r,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(r,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(r,i,t[i]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));const DEFAULT_ZOOM=1,DEFAULT_CURRENT_POS={x:0,y:0},DEFAULT_ROTATE=0,DEFAULT_COLOR="",_DrawUtils=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,thickness:s=1,lineCap:a="round",lineDash:d}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=a,d&&o.setLineDash(d),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",hiddenText:a=!1,lineDash:d}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)&&e.setLineDash(d),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),a===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,u=0,y=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+u},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,a)=>`${s}${a.keyName}: ${a.value.join(" \u3001 ")}
2
- `,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",lineType:a=tool.ELineTypes.Line,lineDash:d,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)?e.setLineDash(d):e.setLineDash([])})(),a===tool.ELineTypes.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=PolygonUtils.createSmoothCurvePointsFromPointList([...t],tool.SEGMENT_NUMBER),n!==void 0&&n>-1&&(t=t.slice((tool.SEGMENT_NUMBER+1)*n,(tool.SEGMENT_NUMBER+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const c=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&c.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),c.forEach(h=>{const w=t[h.i1],g=t[h.i2];e.beginPath(),e.moveTo(w.x,w.y),e.lineTo(g.x,g.y),e.stroke()}),e.restore();const u=4,y=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,u+y,o),this.drawSpecialPoint(r,h,u,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:a=1,color:d=DEFAULT_COLOR,fill:n=DEFAULT_COLOR}=e,f=UnitUtils.deg2rad(l),c=UnitUtils.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=d,o.fillStyle=n,o.lineWidth=a,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR}=e;o.save();const s=UnitUtils.deg2rad(0),a=UnitUtils.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,a,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const a=i*1.5,d=a*Math.sqrt(3)/2,n=a/2;o.moveTo(l,s-a),o.lineTo(l-d,s+n),o.lineTo(l+d,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=tool.ELineTypes.Line}=i;return e===!0&&(t=[...t,t[0]]),o===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,__spreadProps(__spreadValues({},i),{lineType:tool.ELineTypes.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,lineType:l=tool.ELineTypes.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...a]=t;return e.moveTo(s.x,s.y),a.forEach(d=>{e.lineTo(d.x,d.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:a,lineType:d}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:a,lineType:d});return this.drawPolygonWithFill(r,t,{color:o,lineType:d}),n}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,font:s=tool.DEFAULT_FONT,shadowColor:a="",shadowBlur:d=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:u=0,offsetY:y=0,textAlign:h="start",lineHeight:w}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=a,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=d,this.wrapText(r,`${i}`,t.x+u,t.y+y,c,w),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=t.split(`
3
- `);for(let d=0;d<a.length;d++){const n=a[d].split("");let f="";for(let c=0;c<n.length;c++){const u=f+n[c],h=s.measureText(u).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=n[c],e+=l):f=u}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",theta:a=30,headLen:d=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+a)*Math.PI/180,c=(n-a)*Math.PI/180,u=d*Math.cos(f),y=d*Math.sin(f),h=d*Math.cos(c),w=d*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+u,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+w),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:a,fillColor:d}=i,n={color:s,thickness:a};if(e){const c=AxisUtils.default.transformPlain2PointList(e);_DrawUtils.drawPolygon(r,c,__spreadProps(__spreadValues({},n),{isClose:!0}));const u=CuboidUtils.getCuboidAllSideLine(t);u==null||u.forEach(y=>{_DrawUtils.drawLine(r,y.p1,y.p2,__spreadValues({},n))})}const f=AxisUtils.default.transformPlain2PointList(l);if(o&&e&&l){const c=CuboidUtils.getPointListsByDirection({direction:o,frontPoints:l,backPoints:e});c&&_DrawUtils.drawPolygonWithFill(r,c,{color:d})}_DrawUtils.drawPolygon(r,f,__spreadProps(__spreadValues({},n),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:a,selectedID:d,headerText:n,bottomText:f}=e,{backPoints:c,frontPoints:u,textAttribute:y}=t,h=u.br.x-u.bl.x;_DrawUtils.drawCuboid(r,t,i);let w="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(w=`${t.order}`),t.attribute&&(w=`${w} ${AttributeUtils.default.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!a&&c&&w&&_DrawUtils.drawText(r,{x:c.tl.x,y:c.tl.y-5},n!=null?n:w,{color:o,textMaxWidth:300});const g=CuboidUtils.getCuboidTextAttributeOffset({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!a&&y&&t.id!==d){const x=Math.max(20,h*.8);_DrawUtils.drawText(r,{x:g.left,y:g.top},f!=null?f:y,{color:l,textMaxWidth:x})}}};let DrawUtils=_DrawUtils;DrawUtils.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=DEFAULT_ZOOM,currentPos:l=DEFAULT_CURRENT_POS,rotate:s=DEFAULT_ROTATE,imgAttribute:a}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(a){const{contrast:d,saturation:n,brightness:f}=a;e.filter=`saturate(${n+100}%) contrast(${d+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()},module.exports=DrawUtils;
1
+ "use strict";var rgba=require("color-rgba"),lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),PolygonUtils=require("./PolygonUtils.js"),UnitUtils=require("./UnitUtils.js"),AxisUtils=require("./AxisUtils.js"),CuboidUtils=require("./CuboidUtils.js"),AttributeUtils=require("./AttributeUtils.js");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,i)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,__spreadValues=(r,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(r,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(r,i,t[i]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));const DEFAULT_ZOOM=1,DEFAULT_CURRENT_POS={x:0,y:0},DEFAULT_ROTATE=0,DEFAULT_COLOR="",_DrawUtils=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,thickness:s=1,lineCap:a="round",lineDash:d}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=a,d&&o.setLineDash(d),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",hiddenText:a=!1,lineDash:d}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)&&e.setLineDash(d),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),a===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,u=0,y=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+u},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,a)=>`${s}${a.keyName}: ${a.value.join(" \u3001 ")}
2
+ `,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",lineType:a=tool.ELineTypes.Line,lineDash:d,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)?e.setLineDash(d):e.setLineDash([])})(),a===tool.ELineTypes.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=PolygonUtils.createSmoothCurvePointsFromPointList([...t],tool.SEGMENT_NUMBER),n!==void 0&&n>-1&&(t=t.slice((tool.SEGMENT_NUMBER+1)*n,(tool.SEGMENT_NUMBER+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const c=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&c.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),c.forEach(h=>{const g=t[h.i1],w=t[h.i2];e.beginPath(),e.moveTo(g.x,g.y),e.lineTo(w.x,w.y),e.stroke()}),e.restore();const u=4,y=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,u+y,o),this.drawSpecialPoint(r,h,u,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:a=1,color:d=DEFAULT_COLOR,fill:n=DEFAULT_COLOR}=e,f=UnitUtils.deg2rad(l),c=UnitUtils.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=d,o.fillStyle=n,o.lineWidth=a,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR}=e;o.save();const s=UnitUtils.deg2rad(0),a=UnitUtils.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,a,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const a=i*1.5,d=a*Math.sqrt(3)/2,n=a/2;o.moveTo(l,s-a),o.lineTo(l-d,s+n),o.lineTo(l+d,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=tool.ELineTypes.Line}=i;return e===!0&&(t=[...t,t[0]]),o===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,__spreadProps(__spreadValues({},i),{lineType:tool.ELineTypes.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,lineType:l=tool.ELineTypes.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...a]=t;return e.moveTo(s.x,s.y),a.forEach(d=>{e.lineTo(d.x,d.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:a,lineType:d}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:a,lineType:d});return this.drawPolygonWithFill(r,t,{color:o,lineType:d}),n}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,font:s=tool.DEFAULT_FONT,shadowColor:a="",shadowBlur:d=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:u=0,offsetY:y=0,textAlign:h="start",lineHeight:g}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=a,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=d,this.wrapText(r,`${i}`,t.x+u,t.y+y,c,g),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=t.split(`
3
+ `);for(let d=0;d<a.length;d++){const n=a[d].split("");let f="";for(let c=0;c<n.length;c++){const u=f+n[c],h=s.measureText(u).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=n[c],e+=l):f=u}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",theta:a=30,headLen:d=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+a)*Math.PI/180,c=(n-a)*Math.PI/180,u=d*Math.cos(f),y=d*Math.sin(f),h=d*Math.cos(c),g=d*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+u,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+g),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:a,fillColor:d}=i,n={color:s,thickness:a};if(e){const c=AxisUtils.default.transformPlain2PointList(e);_DrawUtils.drawPolygon(r,c,__spreadProps(__spreadValues({},n),{isClose:!0}));const u=CuboidUtils.getCuboidAllSideLine(t);u==null||u.forEach(y=>{_DrawUtils.drawLine(r,y.p1,y.p2,__spreadValues({},n))})}const f=AxisUtils.default.transformPlain2PointList(l);if(o&&e&&l){const c=CuboidUtils.getPointListsByDirection({direction:o,frontPoints:l,backPoints:e});c&&_DrawUtils.drawPolygonWithFill(r,c,{color:d})}_DrawUtils.drawPolygon(r,f,__spreadProps(__spreadValues({},n),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:a,selectedID:d,headerText:n,bottomText:f}=e,{backPoints:c,frontPoints:u,textAttribute:y}=t,h=u.br.x-u.bl.x;_DrawUtils.drawCuboid(r,t,i);let g="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.attribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!a&&c&&g&&_DrawUtils.drawText(r,{x:c.tl.x,y:c.tl.y-5},n!=null?n:g,{color:o,textMaxWidth:300});const w=CuboidUtils.getCuboidTextAttributeOffset({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!a&&y&&t.id!==d){const x=Math.max(20,h*.8);_DrawUtils.drawText(r,{x:w.left,y:w.top},f!=null?f:y,{color:l,textMaxWidth:x})}}static drawPixel({canvas:r,points:t,size:i}){const e=r.getContext("2d"),{width:o,height:l}=i,s=e.getImageData(0,0,o,l),a=(c,u)=>{const[y,h,g,w]=rgba__default.default(u);s.data[c]=y,s.data[c+1]=h,s.data[c+2]=g,s.data[c+3]=Math.floor(255*w)},d=Math.max(o,l),n=Math.floor(Math.pow(lbUtils.MathUtils.calculateThousandsPlace(d),2)),f=lbUtils.MathUtils.generateCoordinates(n);return t.forEach(c=>{for(const[u,y]of f){const h=(c.y+y)*(s.width*4)+(c.x+u)*4;a(h,c.color)}}),e.putImageData(s,0,0),{canvas:r}}};let DrawUtils=_DrawUtils;DrawUtils.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=DEFAULT_ZOOM,currentPos:l=DEFAULT_CURRENT_POS,rotate:s=DEFAULT_ROTATE,imgAttribute:a}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(a){const{contrast:d,saturation:n,brightness:f}=a;e.filter=`saturate(${n+100}%) contrast(${d+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()},module.exports=DrawUtils;
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as z,PerspectiveShiftUtils as B,EPerspectiveView as b,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import F from"../../_virtual/filterBoxWorker.js";import{isInPolygon as H}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import R 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,isInImage,lidar2image,mergeHighlightList,point2dTo3D,point3DLidar2Image,pointCloudLidar2image,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},M=(w,t)=>tt(w,et(t)),D=(w,t,e)=>new Promise((i,r)=>{var o=d=>{try{n(e.next(d))}catch(s){r(s)}},c=d=>{try{n(e.throw(d))}catch(s){r(s)}},n=d=>d.done?i(d.value):Promise.resolve(d.value).then(o,c);n((e=e.apply(w,t)).next())});const nt=30,L=new V({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:o="#4C4C4C",config:c,isSegment:n,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=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(s,h="blue")=>{var l;const u=(l=s.id)!=null?l:I();this.removeObjectByName(u,"sphere");const{radius:p,widthSegments:f,heightSegments:m}=O,{center:g}=s,y=new a.Group,x=new a.SphereGeometry(p,f,m),P=new a.MeshBasicMaterial({color:h}),v=new a.Mesh(x,P);v.position.set(g.x,g.y,g.z),y.add(v),y.name=`sphere${u}`,this.scene.add(y)},this.generateSphere=s=>{const{fill:h}=z.getColorFromConfig({attribute:s.attribute},M(C({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(s,h),this.render()},this.generateSpheres=s=>{s.forEach(h=>{const{fill:l}=z.getColorFromConfig({attribute:h.attribute},M(C({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(s,h=16777215)=>{var l;const u=(l=s.id)!=null?l:I();this.removeObjectByName(u,"box");const{center:p,width:f,height:m,depth:g,rotation:y}=s,x=new a.Group,P=new a.BoxGeometry(f,m,g),v=new a.MeshBasicMaterial({color:"blue"}),S=new a.Mesh(P,v),_=new a.BoxHelper(S,h),N=this.generateBoxArrow(s),T=this.generateBoxTrackID(s);T&&x.add(T),x.add(_),x.add(N),p&&x.position.set(p.x,p.y,p.z),y&&x.rotation.set(0,0,y),x.name=`box${u}`,this.scene.add(x)},this.applyCameraTarget=s=>{if(this.camera.type==="OrthographicCamera"&&s){const h=this.getOrthographicCameraTarget(s);this.updateCameraZoom(s.zoom),this.updateCamera(s.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as C,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import F 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,isInImage,lidar2image,mergeHighlightList,point2dTo3D,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,M=(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 o=d=>{try{n(e.next(d))}catch(s){r(s)}},c=d=>{try{n(e.throw(d))}catch(s){r(s)}},n=d=>d.done?i(d.value):Promise.resolve(d.value).then(o,c);n((e=e.apply(w,t)).next())});const nt=30,L=new F({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:o="#4C4C4C",config:c,isSegment:n,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=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=s=>{if(!!this.store)switch(s.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(s,h="blue")=>{var l;const m=(l=s.id)!=null?l:I();this.removeObjectByName(m,"sphere");const{radius:u,widthSegments:f,heightSegments:p}=O,{center:g}=s,y=new a.Group,x=new a.SphereGeometry(u,f,p),b=new a.MeshBasicMaterial({color:h}),P=new a.Mesh(x,b);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=s=>{const{fill:h}=this.getColorFromConfig(s.attribute);this.addSphereToSense(s,h),this.render()},this.generateSpheres=s=>{s.forEach(h=>{const{fill:l}=this.getColorFromConfig(h.attribute);this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(s,h=16777215)=>{var l;const m=(l=s.id)!=null?l:I();this.removeObjectByName(m,"box");const{center:u,width:f,height:p,depth:g,rotation:y}=s,x=new a.Group,b=new a.BoxGeometry(f,p,g),P=new a.MeshBasicMaterial({color:"blue"}),B=new a.Mesh(b,P),_=new a.BoxHelper(B,h),N=this.generateBoxArrow(s),D=this.generateBoxTrackID(s);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=s=>{if(this.camera.type==="OrthographicCamera"&&s){const h=this.getOrthographicCameraTarget(s);this.updateCameraZoom(s.zoom),this.updateCamera(s.position,h)}},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 z,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=(...s)=>D(this,[...s],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:u,color:p}=yield this.cacheInstance.loadPCDFile(h),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(u,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(p,3)),this.initCloudData(u);const m=new a.Points(f);this.renderPointCloud(m,l)}),this.getHighlightIndexByMappingImgList=s=>D(this,[s],function*({mappingImgList:h,points:l}){const u=h.length===0?[]:yield Promise.all(h.map(m=>W.load(m.url))),p=h.map((m,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?y:[];const x=$({points:l,calib:m.calib,width:u[g].width,height:u[g].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,x),x});return Y(p)}),this.loadPCDFileByBox=(s,h,l)=>D(this,null,function*(){const u=(m,g)=>D(this,null,function*(){const{width:y=0,height:x=0,depth:P=0}=l!=null?l:{},v=yield this.filterPointsByBox(M(C({},h),{width:h.width+y,height:h.height+x,depth:h.depth+P}),m,g);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;const S=new a.Points(v.geometry);S.name=this.pointCloudObjectName,this.scene.add(S),this.render()}),{points:p,color:f}=yield this.cacheInstance.loadPCDFile(s);u(p,f)}),this.generateRange=s=>{const h=this.createRange(s);this.scene.add(h)},this.generateBoxArrow=({width:s})=>{const h=new a.Vector3(1,0,0),l=new a.Vector3(s/2,0,0),u=2,p=16776960,f=new a.ArrowHelper(h,l,u,p);return f.visible=this.showDirection,f},this.generateBoxTrackID=s=>{if(!s.trackID)return;const h=new a.Texture(this.getTextCanvas(s.trackID.toString()));h.needsUpdate=!0;const l=new a.SpriteMaterial({map:h,depthWrite:!1}),u=new a.Sprite(l);return u.scale.set(5,5,5),u.position.set(-s.width/2,0,s.depth/2+.5),u},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const u=l.material.uniforms.pointSize.value;s?l.material.uniforms.pointSize.value=Math.min(u*1.2,10):l.material.uniforms.pointSize.value=Math.max(u/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=c,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,n?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(),n===!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({dom:this.container,store:this.store}),this.pointCloudRender=new K(M(C({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),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("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("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},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){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:o,near:c,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=c,this.camera.far=n,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()}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=z.getColorFromConfig({attribute:i.attribute},M(C({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,c=e.x-i/2-o,n=e.x-i/2+o,d=e.y+r/2+o,s=e.y-r/2-o,h=100,l=-100,u=500/h;return{left:c,right:n,top:d,bottom:s,near:h,far:l,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:c,depth:n,rotation:d}=t,s=this.getCameraVector(r,d,{width:o,height:c,depth:n},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new 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,o,c;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array}if(window.Worker){const{zMin:n,zMax:d,polygonPointList:s}=A(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:n,zMax:d,polygonPointList:s,color:i,position:h};return new Promise(u=>{const p=new F;p.postMessage(l),p.onmessage=f=>{const{color:m,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(m,3)),x.computeBoundingSphere(),p.terminate(),u({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,o=nt){let c=B.frontViewMatrix4(o);switch(r){case b.Front:break;case b.Back:c=B.backViewMatrix4(o);break;case b.Left:c=B.leftViewMatrix4(o);break;case b.Right:c=B.rightViewMatrix4(o);break;case b.Top:c=B.topViewMatrix4(o);break;case b.LFT:c=B.leftFrontTopViewMatrix4(o,i);break;case b.RBT:c=B.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(c),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new a.Matrix4().makeTranslation(t.x,t.y,t.z),h=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(d).applyMatrix4(h).applyMatrix4(s)}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),o=new a.LineBasicMaterial({color:16711680}),c=new a.Line(r,o);return c.name=this.rangeObjectName,c}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],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{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,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(h=>A(h)),d=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(s),L.onmessage=h=>{const{color:l}=h.data,u=new a.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==l.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,u.needsUpdate=!0,i.geometry.setAttribute("dimensions",u),i.geometry.attributes.dimensions.needsUpdate=!0,r(l),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:o,z:c},width:n,height:d,depth:s,rotation:h}=i,{fill:l}=z.getColorFromConfig({attribute:i.attribute},M(C({},this.config),{attributeConfigurable:!0}),{}),u=new a.BoxGeometry(n,d,s),p=new a.MeshBasicMaterial({color:l,transparent:!0,opacity:.2,depthTest:!1});u.rotateZ(h),u.translate(r,o,c);const f=new a.Mesh(u,p);e.add(f);const m=new a.PlaneGeometry(s,d);m.rotateY(Math.PI/2),m.rotateZ(h);const g=new a.Vector3(n/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(h);g.applyMatrix4(y),m.translate(r+g.x,o+g.y,c+g.z);const x=new a.MeshBasicMaterial({color:l,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),P=new a.Mesh(m,x);e.add(P)}),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((l,u)=>l.z-u.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:l})=>l>r.z+.1);const o=.005,c=Math.floor(e.length*(1-o));e=e.slice(0,c),e.sort((l,u)=>l.x-u.x);const n=Math.floor(e.length*o),d=Math.floor(e.length*(1-o));e=e.slice(n,d),e.sort((l,u)=>l.y-u.y);const s=Math.floor(e.length*o),h=Math.floor(e.length*(1-o));return e=e.slice(s,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:d})=>{t.forEach((s,h)=>{const l=r[h+1],u=R.getFootOfPerpendicular({x:n,y:d},s,l,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:n,y:d}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,d)=>{const s=r[d],h=r[d+1],l=r[d+2];return E.getIntersectionBySlope({p1:o[d].point,line1:[s,h],p2:o[d+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,c;const n=this.scene.children.find(m=>m.uuid===this.pointsUuid);let d=0,s=0,h=0,l=0,u=[],p=[];const f=((c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array)||[];for(let m=0;m<f.length;m+=3){const g=f[m],y=f[m+1],x=f[m+2];H({x:g,y},t)&&(x||x===0)&&p.push({x:g,y,z:x})}return p.length?(i&&(p=this.filterNoise(p),u=this.getFittedCoordinates(t,p)),p.sort((m,g)=>m.z-g.z),d=p[0].z-.01,s=p[p.length-1].z+.01,l=p.length,e&&(h=p.filter(({z:m})=>m>=e[0]&&m<=e[1]).length),{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:u}):{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:u}}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:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r-n/2},s={x:e+c/2,y:i+o/2,z:r+n/2},h={x:e-c/2,y:i+o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r-n/2};return[d,s,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e-c/2,y:i+o/2,z:r+n/2},s={x:e-c/2,y:i+o/2,z:r-n/2},h={x:e-c/2,y:i-o/2,z:r-n/2},l={x:e-c/2,y:i-o/2,z:r+n/2};return[d,s,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r+n/2},s={x:e+c/2,y:i-o/2,z:r+n/2},h={x:e-c/2,y:i-o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r+n/2};return[d,s,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,c=new a.Matrix4().makeTranslation(-e,-i,-r),n=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(o);return new a.Matrix4().multiply(n).multiply(d).multiply(c)}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:o}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const d=i.map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,h=this.containerHeight/o;return{polygon2d:d,zoom:Math.min(s,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:c}=O,n={center:e,attribute:i,id:r,valid:o,width:c*2,height:c*2,depth:c*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new a.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const h=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(c*2),u=this.containerHeight/(c*2);return{point2d:h,zoom:Math.min(l,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=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)})),c=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(c,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=M(C({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=M(C({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const c=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(c)),[d,s,h,l]=n,u=Math.max(Math.abs(d.x-h.x),Math.abs(d.x-s.x)),f=s.add(l).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:M(C({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:u,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,o=[],{count:c}=r;for(let n=0;n<c;n++){const d=r.getZ(n);o.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(o,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=(...s)=>z(this,[...s],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=h;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(h),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,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=s=>z(this,[s],function*({mappingImgList:h,points:l}){const m=h.length===0?[]:yield Promise.all(h.map(p=>W.load(p.url))),u=h.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:l,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=(s,h,l)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:b=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(M({},h),{width:h.width+y,height:h.height+x,depth:h.depth+b}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=s;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(s);m(u,f)}),this.generateRange=s=>{const h=this.createRange(s);this.scene.add(h)},this.generateBoxArrow=({width:s})=>{const h=new a.Vector3(1,0,0),l=new a.Vector3(s/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(h,l,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=s=>{if(!s.trackID)return;const h=new a.Texture(this.getTextCanvas(s.trackID.toString()));h.needsUpdate=!0;const l=new a.SpriteMaterial({map:h,depthWrite:!1}),m=new a.Sprite(l);return m.scale.set(5,5,5),m.position.set(-s.width/2,0,s.depth/2+.5),m},this.applyZAxisPoints=s=>{this.zAxisLimit=s,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:s,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const m=l.material.uniforms.pointSize.value;s?l.material.uniforms.pointSize.value=Math.min(m*1.2,10):l.material.uniforms.pointSize.value=Math.max(m/1.2,1),h&&(l.material.uniforms.pointSize.value=h,this.pointsMaterialSize=h),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=o,this.config=c,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,n?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(),n===!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({dom:this.container,store:this.store}),this.pointCloudRender=new K(S(M({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),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 M({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode},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){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:o,near:c,far:n}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=c,this.camera.far=n,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(M({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,c=e.x-i/2-o,n=e.x-i/2+o,d=e.y+r/2+o,s=e.y-r/2-o,h=100,l=-100,m=500/h;return{left:c,right:n,top:d,bottom:s,near:h,far:l,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:o,height:c,depth:n,rotation:d}=t,s=this.getCameraVector(r,d,{width:o,height:c,depth:n},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(s,r),s)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new 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,o,c;if(!e){const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.array}if(window.Worker){const{zMin:n,zMax:d,polygonPointList:s}=A(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:n,zMax:d,polygonPointList:s,color:i,position:h};return new Promise(m=>{const u=new V;u.postMessage(l),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=C.Front,o=nt){let c=v.frontViewMatrix4(o);switch(r){case C.Front:break;case C.Back:c=v.backViewMatrix4(o);break;case C.Left:c=v.leftViewMatrix4(o);break;case C.Right:c=v.rightViewMatrix4(o);break;case C.Top:c=v.topViewMatrix4(o);break;case C.LFT:c=v.leftFrontTopViewMatrix4(o,i);break;case C.RBT:c=v.rightBackTopViewMatrix4(o,i);break}const n=this.createThreeMatrix4(c),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),s=new a.Matrix4().makeTranslation(t.x,t.y,t.z),h=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(n).applyMatrix4(d).applyMatrix4(h).applyMatrix4(s)}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),o=new a.LineBasicMaterial({color:16711680}),c=new a.Line(r,o);return c.name=this.rangeObjectName,c}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],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{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,o)=>{if(window.Worker){const n=(t?[...t]:[]).map(h=>A(h)),d=this.getAllAttributeColor(n),s={cuboidList:n,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};L.postMessage(s),L.onmessage=h=>{const{color:l}=h.data,m=new a.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==l.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(l),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:o,z:c},width:n,height:d,depth:s,rotation:h}=i,{fill:l}=T.getColorFromConfig({attribute:i.attribute},S(M({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(n,d,s),u=new a.MeshBasicMaterial({color:l,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(h),m.translate(r,o,c);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(s,d);p.rotateY(Math.PI/2),p.rotateZ(h);const g=new a.Vector3(n/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(h);g.applyMatrix4(y),p.translate(r+g.x,o+g.y,c+g.z);const x=new a.MeshBasicMaterial({color:l,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),b=new a.Mesh(p,x);e.add(b)}),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((l,m)=>l.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:l})=>l>r.z+.1);const o=.005,c=Math.floor(e.length*(1-o));e=e.slice(0,c),e.sort((l,m)=>l.x-m.x);const n=Math.floor(e.length*o),d=Math.floor(e.length*(1-o));e=e.slice(n,d),e.sort((l,m)=>l.y-m.y);const s=Math.floor(e.length*o),h=Math.floor(e.length*(1-o));return e=e.slice(s,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:n,y:d})=>{t.forEach((s,h)=>{const l=r[h+1],m=H.getFootOfPerpendicular({x:n,y:d},s,l,!1,!0).length;(!i[h]||m<i[h].distance)&&(i[h]={distance:m,point:{x:n,y:d}})})}),r=[t[t.length-1],...t,t[0]];const o=[i[i.length-1],...i];return t.map((n,d)=>{const s=r[d],h=r[d+1],l=r[d+2];return E.getIntersectionBySlope({p1:o[d].point,line1:[s,h],p2:o[d+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var r,o,c;const n=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,s=0,h=0,l=0,m=[],u=[];const f=((c=(o=(r=n==null?void 0:n.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:c.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,s=u[u.length-1].z+.01,l=u.length,e&&(h=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:s,minZ:d,count:h,zCount:l,fittedCoordinates:m}):{maxZ:s,minZ:d,count:h,zCount:l,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:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r-n/2},s={x:e+c/2,y:i+o/2,z:r+n/2},h={x:e-c/2,y:i+o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r-n/2};return[d,s,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e-c/2,y:i+o/2,z:r+n/2},s={x:e-c/2,y:i+o/2,z:r-n/2},h={x:e-c/2,y:i-o/2,z:r-n/2},l={x:e-c/2,y:i-o/2,z:r+n/2};return[d,s,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:c,depth:n}=t,d={x:e+c/2,y:i+o/2,z:r+n/2},s={x:e+c/2,y:i-o/2,z:r+n/2},h={x:e-c/2,y:i-o/2,z:r+n/2},l={x:e-c/2,y:i+o/2,z:r+n/2};return[d,s,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,c=new a.Matrix4().makeTranslation(-e,-i,-r),n=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(o);return new a.Matrix4().multiply(n).multiply(d).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const d=i.map(l=>new a.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),s=this.containerWidth/r,h=this.containerHeight/o;return{polygon2d:d,zoom:Math.min(s,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:c}=O,n={center:e,attribute:i,id:r,valid:o,width:c*2,height:c*2,depth:c*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new a.Matrix4().premultiply(this.getModelTransformationMatrix(n)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const h=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(c*2),m=this.containerHeight/(c*2);return{point2d:h,zoom:Math.min(l,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},o=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=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)})),c=this.containerWidth/e,n=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(c,n)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(M({},n),{width:Math.abs(n.width+e),height:n.height,depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxByBackUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(o);let n=r;return n.center={x:n.center.x+c.x,y:n.center.y+c.y,z:n.center.z-t.z},n=S(M({},n),{width:n.width,height:Math.abs(n.height+e),depth:Math.abs(n.depth+i)}),{newBoxParams:n}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const c=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const n=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(c)),[d,s,h,l]=n,m=Math.max(Math.abs(d.x-h.x),Math.abs(d.x-s.x)),f=s.add(l).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(M({},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,o=[],{count:c}=r;for(let n=0;n<c;n++){const d=r.getZ(n);o.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
@@ -1 +1 @@
1
- import*as u from"three";import{MatrixUtils as g,PointCloudUtils as T}from"@labelbee/lb-utils";import z from"../../utils/uuid.js";var O=Object.defineProperty,R=Object.defineProperties,V=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,v=(r,t,e)=>t in r?O(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,H=(r,t)=>{for(var e in t||(t={}))I.call(t,e)&&v(r,e,t[e]);if(d)for(var e of d(t))L.call(t,e)&&v(r,e,t[e]);return r},D=(r,t)=>R(r,V(t));function y(r){return new u.Matrix4().set(...r)}function h(r,t,e){const n=g.transferMatrix34FromKitti2Three(r),i=g.transferMatrix33FromKitti2Three(t),o=g.transferMatrix34FromKitti2Three(e),s=y(n),l=y(i),a=y(o);return{composeMatrix4:a.clone().premultiply(l).premultiply(s),PM:s,RM:l,TM:a}}function m(r,t,e){var n;const i=new u.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new u.Matrix4().makeRotationZ(e),s=new u.Matrix4().makeTranslation(t.x,t.y,t.z),l=new u.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(l).applyMatrix4(o).applyMatrix4(s)}function M(r,t){const n=new u.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const i=1/n.z,o=new u.Matrix4().set(i,0,0,0,0,i,0,0,0,0,i,0,0,0,0,1);return n.applyMatrix4(o)}function j(r){const{center:t,width:e,height:n,depth:i,rotation:o}=r,s=[{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(p=>{const f=m(p,t,o);return{x:f.x,y:f.y}}),l=t.z+i/2,a=t.z-i/2;return D(H({},r),{polygonPointList:s,zMax:l,zMin:a})}function b(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function w(r,t,e){const n=t.x-r.x,i=t.y-r.y,o=e.x-r.x,s=e.y-r.y;return n*s-o*i}function C(r){const t=b(r),e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&w(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&&w(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 P=(r,t)=>{const{P:e,R:n,T:i}=t,{composeMatrix4:o}=h(e,n,i);return M(r,o)},F=(r,t)=>{const{P:e,R:n,T:i}=t,{composeMatrix4:o}=h(e,n,i);return new u.Vector4(r.x,r.y,r.z).applyMatrix4(o.invert())},_=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const i=P(r,t);return i?i.x>=0&&i.x<=e&&i.y>=0&&i.y<=n:!1},k=({points:r,calib:t,width:e,height:n})=>{const i=[];for(let o=0;o<r.length;o+=3){const s=r[o],l=r[o+1],a=r[o+2];_({point:{x:s,y:l,z:a},calib:t,width:e,height:n})?i.push(1):i.push(0)}return i},A=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 E(r,t,e={createRange:!1}){const{createRange:n}=e,i=T.getAllViewData(r),{P:o,R:s,T:l}=t,{composeMatrix4:a}=h(o,s,l),p=i.map(x=>({type:x.type,pointList:x.pointList.map(c=>m(c,r.center,r.rotation)).map(c=>M(c,a)).map(c=>{if(!!c)return{id:z(),x:c==null?void 0:c.x,y:c==null?void 0:c.y}}).filter(c=>c!==void 0)})).filter(x=>x.pointList.length!==0);let f=[];if(p.length===6&&n===!0){const x=p[0].pointList,c=p[1].pointList;f=C([...x,...c])}return{transferViewData:p,viewRangePointList:f}}export{y as createThreeMatrix4,j as getCuboidFromPointCloudBox,k as getHighlightIndexByPoints,_ as isInImage,M as lidar2image,A as mergeHighlightList,F as point2dTo3D,P as point3DLidar2Image,E as pointCloudLidar2image,m as rotatePoint,h as transferKitti2Matrix};
1
+ import*as x from"three";import{MatrixUtils as m,PointCloudUtils as T}from"@labelbee/lb-utils";import z from"../../utils/uuid.js";var R=Object.defineProperty,O=Object.defineProperties,V=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,w=(r,t,e)=>t in r?R(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,D=(r,t)=>{for(var e in t||(t={}))L.call(t,e)&&w(r,e,t[e]);if(d)for(var e of d(t))I.call(t,e)&&w(r,e,t[e]);return r},H=(r,t)=>O(r,V(t));function h(r){return new x.Matrix4().set(...r)}function y(r,t,e){const n=m.transferMatrix34FromKitti2Three(r),i=m.transferMatrix33FromKitti2Three(t),o=m.transferMatrix34FromKitti2Three(e),c=h(n),l=h(i),u=h(o);return{composeMatrix4:u.clone().premultiply(l).premultiply(c),PM:c,RM:l,TM:u}}function M(r,t,e){var n;const i=new x.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new x.Matrix4().makeRotationZ(e),c=new x.Matrix4().makeTranslation(t.x,t.y,t.z),l=new x.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return i.clone().applyMatrix4(l).applyMatrix4(o).applyMatrix4(c)}function g(r,t){const n=new x.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const i=1/n.z,o=new x.Matrix4().set(i,0,0,0,0,i,0,0,0,0,i,0,0,0,0,1);return n.applyMatrix4(o)}function j(r){const{center:t,width:e,height:n,depth:i,rotation:o}=r,c=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(a=>{const f=M(a,t,o);return{x:f.x,y:f.y}}),l=t.z+i/2,u=t.z-i/2;return H(D({},r),{polygonPointList:c,zMax:l,zMin:u})}function b(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,c=e.y-r.y;return n*c-o*i}function C(r){const t=b(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 P=(r,t)=>{const{P:e,R:n,T:i}=t,{composeMatrix4:o}=y(e,n,i);return g(r,o)},F=(r,t)=>{const{P:e,R:n,T:i}=t,{composeMatrix4:o}=y(e,n,i);return new x.Vector4(r.x,r.y,r.z).applyMatrix4(o.invert())},_=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const i=P(r,t);return i?i.x>=0&&i.x<=e&&i.y>=0&&i.y<=n:!1},k=({points:r,calib:t,width:e,height:n})=>{const i=[];for(let o=0;o<r.length;o+=3){const c=r[o],l=r[o+1],u=r[o+2];_({point:{x:c,y:l,z:u},calib:t,width:e,height:n})?i.push(1):i.push(0)}return i},A=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 E(r,t,e={createRange:!1}){if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:n}=e,i=T.getAllViewData(r),{P:o,R:c,T:l}=t,{composeMatrix4:u}=y(o,c,l),a=i.map(p=>({type:p.type,pointList:p.pointList.map(s=>M(s,r.center,r.rotation)).map(s=>g(s,u)).map(s=>{if(!!s)return{id:z(),x:s==null?void 0:s.x,y:s==null?void 0:s.y}}).filter(s=>s!==void 0)})).filter(p=>p.pointList.length!==0);let f=[];if(a.length===6&&n===!0){const p=a[0].pointList,s=a[1].pointList;f=C([...p,...s])}return{transferViewData:a,viewRangePointList:f}}function K(r,t,e){const{P:n,R:i,T:o}=t,{composeMatrix4:c}=y(n,i,o),l=r.length/3,u={};for(let a=0;a<l;a++){const f=g({x:r[a*3],y:r[a*3+1],z:r[a*3+2]},c);if(f){const p=Math.floor(f.x),s=Math.floor(f.y);if(p>e.width||s>e.height||p<0||s<0)continue;u[a]={x:p,y:s}}}return{pcdMapping:u}}export{h as createThreeMatrix4,j as getCuboidFromPointCloudBox,k as getHighlightIndexByPoints,_ as isInImage,g as lidar2image,A as mergeHighlightList,F as point2dTo3D,P as point3DLidar2Image,E as pointCloudLidar2image,K as pointMappingLidar2image,M as rotatePoint,y as transferKitti2Matrix};
@@ -1 +1 @@
1
- import{EPointCloudSegmentStatus as r}from"@labelbee/lb-utils";import n from"./selector/lassoSelector.js";import c from"./selector/circleSelector.js";class h{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([r.Ready,r.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const i=o.intersectObjects(this.store.allSegmentPoints,!1)[0];i?this.store.highlightPoints(i.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new n(this.store),this.circleSelector=new c(this.store),this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}export{h as PointCloudSegmentOperation};
1
+ import{EPointCloudSegmentStatus as i}from"@labelbee/lb-utils";import c from"./selector/lassoSelector.js";import n from"./selector/circleSelector.js";import h from"./selector/rectSelector.js";class l{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([i.Ready,i.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const r=o.intersectObjects(this.store.allSegmentPoints,!1)[0];r?this.store.highlightPoints(r.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new c(this.store),this.rectSelector=new h(this.store),this.circleSelector=new n(this.store),this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Rect(){this.currentTool=this.rectSelector,this.currentToolName="RectSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}export{l as PointCloudSegmentOperation};
@@ -0,0 +1 @@
1
+ import f from"./selector.js";class h extends f{mouseDown(t){t.button===2&&(this.pushPoint(t.offsetX,t.offsetY),this.startX=t.offsetX,this.startY=t.offsetY)}mouseUp(t){t.button===2&&(this.store.getPointsInPolygon(this.polygon2d),this.polygon2d.length=0,this.startX=this.startY=NaN)}mouseMove(t){if(t.button===2&&this.startX&&this.startY){const s=this.startX,o=this.startY,n=t.offsetX,e=t.offsetY,i=[{x:s,y:o},{x:n,y:o},{x:n,y:e},{x:s,y:e},{x:s,y:o}];this.updatePolygon2d(i)}}}export{h as default};
@@ -1 +1 @@
1
- import*as v from"three";import{EPointCloudSegmentMode as D,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as y}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,P=(d,t)=>{for(var e in t||(t={}))B.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))k.call(t,e)&&w(d,e,t[e]);return d},b=(d,t)=>_(d,R(t));const I="LABELBEE_CANVAS_";class j{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=D.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(l=>l===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const l=y.splitPointsFromIndexes(c.indexes,i),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const f=this.scene.getObjectByName(r);f&&(f.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),f.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=a,this.emit=n,this.on=o,this.unbind=h,this.checkMode=p,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const s=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(s[h*3],s[h*3+1],s[h*3+2]),this.cloudData.set(`${s[h*3]}@${s[h*3+1]}@${s[h*3+2]}`,{visible:!0})});const o=b(P({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",b(P({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${I}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,s){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${s} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,s=this.originPoints;if(s){const a=s.length,n=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const l=s[i],S=s[i+1],f=s[i+2],g=y.getCloudKeys(l,S,f);this.segmentMode===D.Remove&&(this.cloudData.get(g).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===D.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(g).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===D.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case D.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=b(P({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case D.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=b(P({},this.cacheSegData),{points:y.splitPointsFromPoints(a,t),indexes:y.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],o=t[s+2],h=y.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const a=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const o=this.cloudData.get(y.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=b(P({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(P({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}export{j as default};
1
+ import*as v from"three";import{EPointCloudSegmentMode as y,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as P}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,k=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,D=(d,t)=>{for(var e in t||(t={}))k.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))B.call(t,e)&&w(d,e,t[e]);return d},b=(d,t)=>_(d,R(t));const H="LABELBEE_CANVAS_";class I{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=y.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var g;if(u!==((g=this.cacheSegData)==null?void 0:g.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(g=>g===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const g=P.splitPointsFromIndexes(c.indexes,i),S=[];g.forEach(l=>{S.push(this.originPoints[l*3],this.originPoints[l*3+1],this.originPoints[l*3+2])}),c.indexes=g,c.points=new Float32Array(S);const f=this.scene.getObjectByName(r);f&&(f.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),f.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=a,this.emit=n,this.on=o,this.unbind=h,this.checkMode=p,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSubAttribute=this.setSubAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,subAttribute:s.subAttribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.resetSelectedSegmentStatus(),this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const s=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(s[h*3],s[h*3+1],s[h*3+2]),this.cloudData.set(`${s[h*3]}@${s[h*3+1]}@${s[h*3+2]}`,{visible:!0})});const o=b(D({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",b(D({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${H}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,s){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${s} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,s=this.originPoints;if(s){const a=s.length,n=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const g=s[i],S=s[i+1],f=s[i+2],l=P.getCloudKeys(g,S,f);this.segmentMode===y.Remove&&(this.cloudData.get(l).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===y.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(l).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(l).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(l).visible===!1&&(this.cloudData.get(l).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===y.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case y.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=b(D({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,subAttribute:{},points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case y.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=b(D({},this.cacheSegData),{points:P.splitPointsFromPoints(a,t),indexes:P.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],o=t[s+2],h=P.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}clearStash(){if(this.isCheckStatus){this.resetSelectedSegmentStatus();return}if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const a=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const o=this.cloudData.get(P.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=b(D({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(D({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}getHighlightAttribute(t){const e=[];return this.segmentData.forEach(s=>{s.attribute===t&&e.push(s.indexes)}),e}setAttribute(t){this.currentAttribute=t}setSubAttribute(t,e){!this.cacheSegData||(this.cacheSegData.subAttribute=b(D({},this.cacheSegData.subAttribute),{[t]:e}),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}}export{I as default};
@@ -1 +1 @@
1
- import{ImgPosUtils as Z}from"@labelbee/lb-utils";import M from"lodash";import E from"color-rgba";import h from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import W from"../../utils/tool/RectUtils.js";import $ from"../../utils/tool/PolygonUtils.js";import C from"../../utils/MathUtils.js";import H from"../../utils/tool/RenderDomClass.js";import{ELineTypes as L,DEFAULT_FONT as j,SEGMENT_NUMBER as F}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as B,TEXT_ATTRIBUTE_OFFSET as A,DEFAULT_TEXT_SHADOW as N}from"../../constant/annotation.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import{pointCloudLidar2image as K}from"../pointCloud/matrix.js";var X=Object.defineProperty,G=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,U=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,z=(P,t,e)=>t in P?X(P,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):P[t]=e,g=(P,t)=>{for(var e in t||(t={}))q.call(t,e)&&z(P,e,t[e]);if(U)for(var e of U(t))J.call(t,e)&&z(P,e,t[e]);return P},_=(P,t)=>G(P,Y(t));const Q=3,tt=3,I="#6371FF";class et extends V{constructor(t){super(_(g({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(c,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let d="",s=Number.MAX_SAFE_INTEGER;for(let l=0;l<this.annotations.length;l++){const a=this.annotations[l];switch(a.type){case"rect":{const u=a.annotation;if(W.isInRect(c,u,Q,this.zoom)){const f=u.width*u.height;f<s&&(d=u.id,s=f)}break}case"polygon":{const u=a.annotation;if($.isInPolygon(n,u.pointList)){const f=$.getPolygonArea(u.pointList);f<s&&(d=u.id,s=f)}break}}}return d};var e;this.style=(e=t.style)!=null?e:{stroke:I,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new H({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:c}=C.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=M.pick(t,["stroke","thickness","fill","radius"]),o=g(g({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(g({},N),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+B.offsetX,y:e+B.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=C.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=Z.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(_(g({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=T.changePointByZoom(t,this.zoom,this.currentPos);h.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),h.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:d=L.Line}=n,s=T.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),l=_(g(g({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:d,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=h.drawPolygonWithKeyPoint(this.canvas,s,l):a=h.drawPolygon(this.canvas,s,l),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let v=s[0],m=C.getLineCenterPoint([s[0],s[1]]);if(d===L.Curve){const p=Math.floor(F/2);v=a[p],m=a[p+1]}h.drawArrowByCanvas(this.canvas,v,m,{color:r.stroke,thickness:r.thickness}),h.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&h.drawText(this.canvas,this.appendOffset(s[0]),f,c),y){const v=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:v.x+A.x,y:v.y+A.y}),y,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:n,fontStyle:d}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:l=L.Line}=s,a=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const p=E((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:I),x=`rgba(${p[0]}, ${p[1]}, ${p[2]},${p[3]*.8})`;h.drawPolygonWithFill(this.canvas,a,{color:x,lineType:l})}const u=_(g(_(g({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:l,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=h.drawPolygonWithKeyPoint(this.canvas,a,u):f=h.drawPolygon(this.canvas,a,u),(s==null?void 0:s.showDirection)===!0&&((c=s==null?void 0:s.pointList)==null?void 0:c.length)>=2){let p=a[0],x=C.getLineCenterPoint([a[0],a[1]]);if(l===L.Curve){const w=Math.floor(F/2);p=f[w],x=f[w+1]}h.drawArrowByCanvas(this.canvas,p,x,{color:n.stroke,thickness:n.thickness}),h.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:m}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&h.drawText(this.canvas,this.appendOffset(a[0]),v,d),m){const p=a[a.length-1];h.drawText(this.canvas,this.appendOffset({x:p.x+A.x,y:p.y+A.y}),m,d)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=E((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:I),n=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,d=i.stroke,s=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:l,bottomText:a}=this.getRenderText(r,r==null?void 0:r.hiddenText);h.drawCuboidWithText(this.canvas,s,{strokeColor:d,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:l,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,{transferViewData:o}=K(e,e.calib),i={fill:"transparent"},r=M.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const d=g(_(g({},r),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),i);switch(c.type){case"line":this.renderLine({type:"line",annotation:d});break;case"polygon":this.renderPolygon({type:"polygon",annotation:d});break}})}render(){try{if(super.render(),this.loading===!0)return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,c,n;const d=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,d);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:a=!1,isReference:u,hiddenRectSize:f=!1}=l,{zoom:y}=this,v=T.changeRectByZoom(l,this.zoom,this.currentPos),{x:m,y:p,width:x,height:w}=v;if(l.id===this.mouseHoverID||d.fill){const b=E((i=(o=d==null?void 0:d.fill)!=null?o:d==null?void 0:d.stroke)!=null?i:I),D=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;h.drawRectWithFill(this.canvas,v,{color:D})}h.drawRect(this.canvas,v,g(_(g({},d),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:S,bottomText:R}=this.getRenderText(l,l==null?void 0:l.hiddenText);S&&h.drawText(this.canvas,{x:m,y:p-6},S,g({textMaxWidth:300},s));const k=`${Math.round(x/y)} * ${Math.round(w/y)}`,O=k.length*7;if(!a&&!f&&h.drawText(this.canvas,{x:m+x-O,y:p+w+15},k,s),R){const b=20,D=Math.max(20,x-O);h.drawText(this.canvas,{x:m,y:p+w+b},l.textAttribute,g({textMaxWidth:D},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,a=T.changePointByZoom(l,this.zoom,this.currentPos),u=(r=d.radius)!=null?r:tt;h.drawCircle(this.canvas,a,u,d);const{headerText:f,bottomText:y}=this.getRenderText(l,l==null?void 0:l.hiddenText);f&&h.drawText(this.canvas,{x:a.x+u/2,y:a.y-u-4},f,g({textAlign:"center"},s)),y&&h.drawText(this.canvas,this.appendOffset({x:a.x+u,y:a.y+u+24}),y,s);break}case"text":{const l=e.annotation,{text:a,x:u,y:f,textMaxWidth:y,color:v="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:p=25,font:x=j,position:w}=l,S=10,R=10,k=T.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:O,height:b,fontHeight:D=0}=C.getTextArea(this.canvas,l.text,y,x,p);if(w==="rt")break;h.drawRectWithFill(this.canvas,{x:k.x,y:k.y,width:O+R*2,height:b+S*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),h.drawText(this.canvas,{x:k.x+R,y:k.y+D+S},a,{color:v,lineHeight:p,font:x,textMaxWidth:y});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}default:break}(n=(c=e.annotation)==null?void 0:c.renderEnhance)==null||n.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this})}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{et as default};
1
+ import{ImgPosUtils as B}from"@labelbee/lb-utils";import E from"lodash";import M from"color-rgba";import l from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/RectUtils.js";import U from"../../utils/tool/PolygonUtils.js";import C from"../../utils/MathUtils.js";import W from"../../utils/tool/RenderDomClass.js";import{ELineTypes as O,DEFAULT_FONT as j,SEGMENT_NUMBER as z}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as $,TEXT_ATTRIBUTE_OFFSET as L,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import V,{cropAndEnlarge as K}from"../../utils/ImgUtils.js";import X from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as G}from"./basicToolOperation.js";import{pointCloudLidar2image as q}from"../pointCloud/matrix.js";var Y=Object.defineProperty,J=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,N=(x,t,e)=>t in x?Y(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,m=(x,t)=>{for(var e in t||(t={}))tt.call(t,e)&&N(x,e,t[e]);if(F)for(var e of F(t))et.call(t,e)&&N(x,e,t[e]);return x},_=(x,t)=>J(x,Q(t));const ot=3,it=3,A="#6371FF";class nt extends G{constructor(t){super(_(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(c,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let h="",s=Number.MAX_SAFE_INTEGER;for(let d=0;d<this.annotations.length;d++){const a=this.annotations[d];switch(a.type){case"rect":{const u=a.annotation;if(Z.isInRect(c,u,ot,this.zoom)){const f=u.width*u.height;f<s&&(h=u.id,s=f)}break}case"polygon":{const u=a.annotation;if(U.isInPolygon(n,u.pointList)){const f=U.getPolygonArea(u.pointList);f<s&&(h=u.id,s=f)}break}}}return h};var e;this.style=(e=t.style)!=null?e:{stroke:A,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new W({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:c}=C.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const o=K(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);V.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){if(!E.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,o=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const i=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:o}),this.staticImgNode=i}}getSpecificStyle(t){const e=E.pick(t,["stroke","thickness","fill","radius"]),o=m(m({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(m({},H),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+$.offsetX,y:e+$.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=C.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=B.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(_(m({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=T.changePointByZoom(t,this.zoom,this.currentPos);l.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),l.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=O.Line}=n,s=T.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),d=_(m(m({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=l.drawPolygonWithKeyPoint(this.canvas,s,d):a=l.drawPolygon(this.canvas,s,d),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let p=s[0],y=C.getLineCenterPoint([s[0],s[1]]);if(h===O.Curve){const g=Math.floor(z/2);p=a[g],y=a[g+1]}l.drawArrowByCanvas(this.canvas,p,y,{color:r.stroke,thickness:r.thickness}),l.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:v}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&l.drawText(this.canvas,this.appendOffset(s[0]),f,c),v){const p=s[s.length-1];l.drawText(this.canvas,this.appendOffset({x:p.x+L.x,y:p.y+L.y}),v,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:n,fontStyle:h}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:d=O.Line}=s,a=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=M((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:A),P=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;l.drawPolygonWithFill(this.canvas,a,{color:P,lineType:d})}const u=_(m(_(m({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:d,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=l.drawPolygonWithKeyPoint(this.canvas,a,u):f=l.drawPolygon(this.canvas,a,u),(s==null?void 0:s.showDirection)===!0&&((c=s==null?void 0:s.pointList)==null?void 0:c.length)>=2){let g=a[0],P=C.getLineCenterPoint([a[0],a[1]]);if(d===O.Curve){const w=Math.floor(z/2);g=f[w],P=f[w+1]}l.drawArrowByCanvas(this.canvas,g,P,{color:n.stroke,thickness:n.thickness}),l.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:p,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(p&&l.drawText(this.canvas,this.appendOffset(a[0]),p,h),y){const g=a[a.length-1];l.drawText(this.canvas,this.appendOffset({x:g.x+L.x,y:g.y+L.y}),y,h)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=M((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:A),n=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,h=i.stroke,s=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:d,bottomText:a}=this.getRenderText(r,r==null?void 0:r.hiddenText);l.drawCuboidWithText(this.canvas,s,{strokeColor:h,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:d,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,{transferViewData:o}=q(e,e.calib),i={fill:"transparent"},r=E.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const h=m(_(m({},r),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),i);switch(c.type){case"line":this.renderLine({type:"line",annotation:h});break;case"polygon":this.renderPolygon({type:"polygon",annotation:h});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const o=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(o.length>0)){console.warn("Empty pixelPoints");return}const i=this.imgNode.src+o.length,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){l.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:h}=X.createCanvas(c);n&&(o==null?void 0:o.length)>0&&(l.drawPixel({canvas:h,points:o,size:c}),l.drawImg(this.canvas,h,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:h})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,c,n;const h=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,h);switch(e.type){case"rect":{const d=e.annotation,{hiddenText:a=!1,isReference:u,hiddenRectSize:f=!1}=d,{zoom:v}=this,p=T.changeRectByZoom(d,this.zoom,this.currentPos),{x:y,y:g,width:P,height:w}=p;if(d.id===this.mouseHoverID||h.fill){const b=M((i=(o=h==null?void 0:h.fill)!=null?o:h==null?void 0:h.stroke)!=null?i:A),k=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;l.drawRectWithFill(this.canvas,p,{color:k})}l.drawRect(this.canvas,p,m(_(m({},h),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:I,bottomText:D}=this.getRenderText(d,d==null?void 0:d.hiddenText);I&&l.drawText(this.canvas,{x:y,y:g-6},I,m({textMaxWidth:300},s));const S=`${Math.round(P/v)} * ${Math.round(w/v)}`,R=S.length*7;if(!a&&!f&&l.drawText(this.canvas,{x:y+P-R,y:g+w+15},S,s),D){const b=20,k=Math.max(20,P-R);l.drawText(this.canvas,{x:y,y:g+w+b},d.textAttribute,m({textMaxWidth:k},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const d=e.annotation,a=T.changePointByZoom(d,this.zoom,this.currentPos),u=(r=h.radius)!=null?r:it;l.drawCircle(this.canvas,a,u,h);const{headerText:f,bottomText:v}=this.getRenderText(d,d==null?void 0:d.hiddenText);f&&l.drawText(this.canvas,{x:a.x+u/2,y:a.y-u-4},f,m({textAlign:"center"},s)),v&&l.drawText(this.canvas,this.appendOffset({x:a.x+u,y:a.y+u+24}),v,s);break}case"text":{const d=e.annotation,{text:a,x:u,y:f,textMaxWidth:v,color:p="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:g=25,font:P=j,position:w}=d,I=10,D=10,S=T.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:R,height:b,fontHeight:k=0}=C.getTextArea(this.canvas,d.text,v,P,g);if(w==="rt")break;l.drawRectWithFill(this.canvas,{x:S.x,y:S.y,width:R+D*2,height:b+I*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),l.drawText(this.canvas,{x:S.x+D,y:S.y+k+I},a,{color:p,lineHeight:g,font:P,textMaxWidth:v});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((n=(c=e.annotation).renderEnhance)==null||n.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{nt as default};