@labelbee/lb-annotation 1.27.0-alpha.53 → 1.27.0-alpha.55

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.
@@ -4,7 +4,7 @@
4
4
  * @author Ron <ron.f.luo@gmail.com>
5
5
  */
6
6
  import * as THREE from 'three';
7
- import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig, ICalib } from '@labelbee/lb-utils';
7
+ import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig, ICalib, IPointCloudBoxList } from '@labelbee/lb-utils';
8
8
  import { OrthographicCamera, PerspectiveCamera } from 'three';
9
9
  import { IPolygonPoint } from '@/types/tool/polygon';
10
10
  import { PCDLoader } from './PCDLoader';
@@ -29,6 +29,11 @@ interface IProps {
29
29
  config?: IPointCloudConfig;
30
30
  isSegment?: boolean;
31
31
  checkMode?: boolean;
32
+ hiddenText?: boolean;
33
+ }
34
+ interface IPipeTypes {
35
+ setSelectedIDs: (ids?: string[] | string) => void;
36
+ setNeedUpdateCenter: (value: boolean) => void;
32
37
  }
33
38
  export interface IEventBus {
34
39
  on: EventListener['on'];
@@ -80,8 +85,13 @@ export declare class PointCloud extends EventListener {
80
85
  private isSegment;
81
86
  private checkMode;
82
87
  private workerLoading;
88
+ private raycaster;
89
+ private pointer;
90
+ private pipe?;
91
+ private hiddenText;
83
92
  constructor({ container, noAppend, isOrthographicCamera, orthographicParams, backgroundColor, // GRAY_BACKGROUND
84
- config, isSegment, checkMode, }: IProps);
93
+ config, isSegment, checkMode, hiddenText, }: IProps);
94
+ setHandlerPipe(pipe: IPipeTypes): void;
85
95
  initSegment(): void;
86
96
  orbiterStart(): void;
87
97
  orbiterChange(): void;
@@ -281,8 +291,38 @@ export declare class PointCloud extends EventListener {
281
291
  setShowDirection(showDirection: boolean): void;
282
292
  generateRange: (radius: number) => void;
283
293
  generateBoxArrow: ({ width }: IPointCloudBox) => THREE.ArrowHelper;
294
+ /**
295
+ * Universal generation of label information
296
+ * @param text generation text
297
+ * @param scaleFactor scale size
298
+ * @returns { sprite, canvasWidth, canvasHeight }
299
+ */
300
+ generateLabel: (text: string, scaleFactor: number) => {
301
+ sprite: THREE.Sprite;
302
+ canvasWidth: number;
303
+ canvasHeight: number;
304
+ };
305
+ /**
306
+ * Generate label information for ID
307
+ * @param boxParams
308
+ * @returns sprite
309
+ */
284
310
  generateBoxTrackID: (boxParams: IPointCloudBox) => THREE.Sprite | undefined;
311
+ /**
312
+ * Generate label information for secondary attributes
313
+ * @param boxParams
314
+ * @returns sprite
315
+ */
316
+ generateBoxAttributeLabel: (boxParams: IPointCloudBox) => THREE.Sprite | undefined;
317
+ /**
318
+ * Splicing sub attribute content
319
+ * @param boxParams
320
+ * @param config
321
+ * @returns
322
+ */
323
+ findSubAttributeLabel(boxParams: IPointCloudBox, config?: IPointCloudConfig): string;
285
324
  getTextCanvas(text: string): HTMLCanvasElement;
325
+ updateHiddenTextAndRender(hiddenText: boolean, pointCloudBoxList: IPointCloudBoxList): void;
286
326
  /**
287
327
  * Filter road points and noise in all directions
288
328
  * 1. The first 5% of the z-axis is used as the road coordinate
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 查看模式 - 支持简单数据注入查看
3
3
  */
4
- import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, TAnnotationViewPixelPoints, IBasicStyle, TAnnotationViewCuboid } from '@labelbee/lb-utils';
4
+ import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, TAnnotationViewPixelPoints, IBasicStyle, TAnnotationViewCuboid, IPointCloudBoxList } from '@labelbee/lb-utils';
5
5
  import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
6
6
  interface IViewOperationProps extends IBasicToolOperationProps {
7
7
  style: IBasicStyle;
@@ -27,6 +27,11 @@ export default class ViewOperation extends BasicToolOperation {
27
27
  private connectionPoints;
28
28
  private connectPointsStatus?;
29
29
  private cacheCanvas?;
30
+ private needUpdatePosition;
31
+ private posTimer;
32
+ private convexHullGroup;
33
+ private pointCloudBoxList?;
34
+ private hiddenText?;
30
35
  constructor(props: IViewOperationProps);
31
36
  clearConnectionPoints(): void;
32
37
  /**
@@ -47,9 +52,12 @@ export default class ViewOperation extends BasicToolOperation {
47
52
  * 1. crop the canvas.
48
53
  */
49
54
  generateStaticImgNode(): void;
55
+ onRightClick(e: MouseEvent): void;
50
56
  onMouseMove(e: MouseEvent): void;
51
57
  getHoverRectID: (e: MouseEvent) => string | undefined;
52
58
  updateData(annotations: TAnnotationViewData[]): Promise<void>;
59
+ setPointCloudBoxList(pointCloudBoxList: IPointCloudBoxList): void;
60
+ setHiddenText(hiddenText: boolean): void;
53
61
  setConfig(config: {
54
62
  [a: string]: any;
55
63
  } | string): void;
@@ -92,6 +100,11 @@ export default class ViewOperation extends BasicToolOperation {
92
100
  */
93
101
  focusPositionByPointList(pointList: ICoordinate[]): void;
94
102
  renderConnectionPoints(): void;
103
+ /**
104
+ * Separate rendering of sub attribute content
105
+ * The principle is the same as other tools for rendering sub attribute content
106
+ */
107
+ renderAttribute(): void;
95
108
  getRenderStyle(annotation: TAnnotationViewData): {
96
109
  style: {
97
110
  radius: any;
@@ -114,5 +127,6 @@ export default class ViewOperation extends BasicToolOperation {
114
127
  renderBox3d(annotation: TAnnotationViewBox3d): void;
115
128
  renderPixelPoints(annotation: TAnnotationViewPixelPoints): void;
116
129
  render(): void;
130
+ private getClickTargetId;
117
131
  }
118
132
  export {};
@@ -234,6 +234,7 @@ declare class BasicToolOperation extends EventListener {
234
234
  onMouseUp(e: MouseEvent): boolean | void;
235
235
  onMouseLeave(): void;
236
236
  onClick(e: MouseEvent): void;
237
+ onRightClick(e: MouseEvent): void;
237
238
  onLeftDblClick(e: MouseEvent): void;
238
239
  onRightDblClick(e: MouseEvent): void;
239
240
  onKeyDown(e: KeyboardEvent): boolean | void;
@@ -15,5 +15,8 @@ declare class PointCloud2DRectOperation extends RectOperation {
15
15
  onKeyDown(e: KeyboardEvent): true | undefined;
16
16
  renderDrawingRect(rect: IPointCloud2DRectOperationViewRect & IRect, zoom?: number, isZoom?: boolean): void;
17
17
  resizeRect(resizeWidth?: number, resizeHeight?: number): void;
18
+ rightMouseUp(e: MouseEvent): (IRect & {
19
+ boxID?: string | undefined;
20
+ }) | undefined;
18
21
  }
19
22
  export default PointCloud2DRectOperation;
@@ -154,7 +154,7 @@ declare class RectOperation extends BasicToolOperation {
154
154
  * mouseup 下的鼠标右键
155
155
  * @param e
156
156
  */
157
- rightMouseUp(e: MouseEvent): void;
157
+ rightMouseUp(e: MouseEvent): IRect | undefined;
158
158
  shiftRightMouseUp(e: MouseEvent): void;
159
159
  updateDragResult(): void;
160
160
  /** Allow/Disallow to add rect to rectList */
@@ -1,6 +1,13 @@
1
1
  import { ERotateDirection } from '@/constant/annotation';
2
+ import { TAnnotationViewData, TAnnotationViewLine } from '@labelbee/lb-utils';
2
3
  import { IPolygonData, IPolygonPoint } from '../../types/tool/polygon';
3
4
  import { ELineTypes } from '../../constant/tool';
5
+ export interface IConvexHullGroupType {
6
+ [id: string]: {
7
+ points: TAnnotationViewLine['annotation']['pointList'];
8
+ convexHull: ICoordinate[];
9
+ };
10
+ }
4
11
  export default class PolygonUtils {
5
12
  static getHoverPolygonID(checkPoint: IPolygonPoint, polygonPoints: {
6
13
  pointList: IPolygonPoint[];
@@ -130,4 +137,9 @@ export default class PolygonUtils {
130
137
  * @param polygonList
131
138
  */
132
139
  static composeSegmentPolygonList(polygonList: any[]): any[];
140
+ /**
141
+ * Convex hull algorithm - Graham scan
142
+ */
143
+ static computeConvexHull(points: IPolygonPoint[]): IPolygonPoint[];
144
+ static createConvexHullGroup(annotations: TAnnotationViewData[]): IConvexHullGroupType;
133
145
  }
@@ -1 +1 @@
1
- "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,o=3,i=tool.ELineTypes.Line){let n="",r=Infinity;const l=AxisUtils.default.axisArea(e,o);return t.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(n=s.id,r=u)})}),n}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,o=e.reduce((i,n,r,l)=>{const s=l[(r+1)%t];return i+n.x*s.y-s.x*n.y},0);return Math.abs(o)/2}static isInPolygon(e,t,o=tool.ELineTypes.Line){return t=[...t],o===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(e,t)}static isPointInOrOnPolygon(e,t,o=1e-9){const{x:i,y:n}=e;let r=!1;for(let l=0,s=t.length-1;l<t.length;s=l++){const{x:c,y:u}=t[l],{x:h,y:d}=t[s],y=i<=Math.max(c,h)&&i>=Math.min(c,h)&&n<=Math.max(u,d)&&n>=Math.min(u,d),P=(n-u)*(h-c)-(i-c)*(d-u);if(y&&Math.abs(P)<o)return!0;u>n!=d>n&&i<(h-c)*(n-u)/(d-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!1,t).map((i,n)=>{var r;const l=n/(tool.SEGMENT_NUMBER+1),s=Math.floor(l),c=(r=e[s])!=null?r:{};return __spreadValues(s===l?__spreadValues({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,o=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const n=[],r=e.slice(0);let l,s,c,u,h,d,y,P,m,x,a,g,f;for(o?(r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.push(e[0]),r.push(e[1])):(r.unshift(e[1]),r.unshift(e[0]),r.push(e[e.length-2]),r.push(e[e.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*t,u=(r[f+4]-r[f-0])*t,h=(r[f+3]-r[f-1])*t,d=(r[f+5]-r[f+1])*t,g=0;g<=i;g++)a=g/i,y=2*Math.pow(a,3)-3*Math.pow(a,2)+1,P=-(2*Math.pow(a,3))+3*Math.pow(a,2),m=Math.pow(a,3)-2*Math.pow(a,2)+a,x=Math.pow(a,3)-Math.pow(a,2),l=y*r[f]+P*r[f+2]+m*c+x*u,s=y*r[f+1]+P*r[f+3]+m*h+x*d,n.push(l),n.push(s);const v=[];for(let E=0;E<n.length-1;E+=2)v.push({x:n[E],y:n[E+1]});if(o)for(let E=0;E<i+1;E++){const M=v.shift();v.push(M)}return v}static getPolygonByID(e,t){return e.find(o=>o.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(o=>t.includes(o.id)):[]}static getHoverEdgeIndex(e,t,o=tool.ELineTypes.Line,i=5){let n=[...t];o===tool.ELineTypes.Curve?n=this.createSmoothCurvePoints(t.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,tool.SEGMENT_NUMBER):o===tool.ELineTypes.Line&&n.push(n[0]);let r=-1,l=i;for(let s=0;s<n.length-1;s++){const{length:c}=MathUtils.default.getFootOfPerpendicular(e,n[s],n[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:o===tool.ELineTypes.Curve?Math.floor(r/tool.SEGMENT_NUMBER):r}static getClosestPoint(e,t,o=tool.ELineTypes.Line,i=3,n){var r;let l=!1;const s=(r=n==null?void 0:n.isClose)!=null?r:!0;let c="",u=-1,h=Infinity,d=e;const y=20;let P=!1;return t.forEach(m=>{if(!P&&!!m.pointList)switch(o){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(m.pointList,s).forEach((a,g)=>{if(P)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,a.point1,a.point2);const E=MathUtils.default.getLineLength(a.point1,e),M=MathUtils.default.getLineLength(a.point2,e);E<i*2&&(v=a.point1,f=E,P=!0),M<i*2&&(v=a.point2,f=M,P=!0),f<h&&f<i&&(c=m.id,u=g,h=f,d=v,l=!0)});break;case tool.ELineTypes.Curve:{const x=this.createSmoothCurvePoints(m.pointList.reduce((a,g)=>[...a,g.x,g.y],[]),.5,s,y);for(let a=0;a<x.length-1;a++){const{length:g,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,x[a],x[a+1]);g<h&&g<i&&(c=m.id,u=Math.floor(a/(y+1)),h=g,d=f,l=!0)}}break}}),{dropFoot:d,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(e,t,o=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,o))}static isPointListOutSidePolygon(e,t,o=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,o))}static getPolygonArea(e){let t=0;for(let o=0,i=e.length;o<i;o++){const n=e[o].x,r=e[o===e.length-1?0:o+1].y,l=e[o===e.length-1?0:o+1].x,s=e[o].y;t+=n*r*.5,t-=l*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,o){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,o)}static deletePolygonLastPoint(e,t,o,i){return o===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var o,i;try{let n=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(l=>[l.x,l.y]))]]);return t.forEach(l=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=turf.difference(n,s);c&&(n=c)}),((i=(o=n==null?void 0:n.geometry)==null?void 0:o.coordinates.map(l=>{var s;return((s=n==null?void 0:n.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):l.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((h,d)=>{const y=(d+1)%c;return!AxisUtils.default.getIsInScope(h,s[y],1)});return u.length<3?l:[...l,u]},[])}catch(n){console.error(n)}}static getPolygonPointList(e,t){const o=t.find(i=>i.id===e);return o&&o.pointList&&o.pointList.length>0?o.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(o=>PolygonUtils.isPointListInPolygon(e,o.pointList))}static clipPolygonFromWrapPolygon(e,t){const o=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),n=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),r=t[n];let l=[...t.slice(0,n),r,...e,e[0],...t.slice(n,t.length)];return o===i&&(l=[...t.slice(0,n),r,e[0],...e.reverse(),...t.slice(n,t.length)]),l}static isPolygonClosewise(e){const t=e.length;let o,i,n,r=0,l;if(t<3)return 0;for(o=0;o<t;o++)i=(o+1)%t,n=(o+2)%t,l=(e[i].x-e[o].x)*(e[n].y-e[i].y),l-=(e[i].y-e[o].y)*(e[n].x-e[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let o=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((n,r)=>{const l=LineToolUtils.default.calcDistance(e,n);l<o&&(o=l,i=r)}),i}static combinePolygonWithPolygon(e,t){var o,i;try{const n=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),l=turf.union(n,r),s=[],c=e;if(((i=(o=l==null?void 0:l.geometry)==null?void 0:o.coordinates)==null?void 0:i.length)===1){s.push(t.id);const u=l==null?void 0:l.geometry.coordinates.map(h=>{var d;return((d=l==null?void 0:l.geometry)==null?void 0:d.type)==="MultiPolygon"?h[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):h.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(n){console.error(n)}}static composePointList(e,t){let o=0,i=0,n=Number.MAX_VALUE;return e.forEach((r,l)=>{t.forEach((s,c)=>{const u=LineToolUtils.default.calcDistance(r,s);u<n&&(o=l+1,i=c+1,n=u)})}),[...e.slice(0,o),...t.slice(i,t.length),...t.slice(0,i),...e.slice(o,e.length)]}static composeSegmentPolygonList(e){var t,o;const i=[];for(let n=0;n<e.length;n++)for(let r=0;r<e.length;r++){const l=(t=e[n])==null?void 0:t.pointList,s=(o=e[r])==null?void 0:o.pointList;n!==r&&l&&s&&PolygonUtils.isPointListInPolygon(s,l)&&(e[n].pointList=PolygonUtils.composePointList(l,s),i.unshift(r))}return i.forEach(n=>{e.splice(n,1)}),e}}module.exports=PolygonUtils;
1
+ "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(p,e,t)=>e in p?__defProp(p,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):p[e]=t,__spreadValues=(p,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(p,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(p,t,e[t]);return p};class PolygonUtils{static getHoverPolygonID(e,t,n=3,i=tool.ELineTypes.Line){let o="",r=Infinity;const l=AxisUtils.default.axisArea(e,n);return t.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(o=s.id,r=u)})}),o}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,n=e.reduce((i,o,r,l)=>{const s=l[(r+1)%t];return i+o.x*s.y-s.x*o.y},0);return Math.abs(n)/2}static isInPolygon(e,t,n=tool.ELineTypes.Line){return t=[...t],n===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(e,t)}static isPointInOrOnPolygon(e,t,n=1e-9){const{x:i,y:o}=e;let r=!1;for(let l=0,s=t.length-1;l<t.length;s=l++){const{x:c,y:u}=t[l],{x:h,y:d}=t[s],y=i<=Math.max(c,h)&&i>=Math.min(c,h)&&o<=Math.max(u,d)&&o>=Math.min(u,d),P=(o-u)*(h-c)-(i-c)*(d-u);if(y&&Math.abs(P)<n)return!0;u>o!=d>o&&i<(h-c)*(o-u)/(d-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!1,t).map((i,o)=>{var r;const l=o/(tool.SEGMENT_NUMBER+1),s=Math.floor(l),c=(r=e[s])!=null?r:{};return __spreadValues(s===l?__spreadValues({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,n=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const o=[],r=e.slice(0);let l,s,c,u,h,d,y,P,x,m,a,g,f;for(n?(r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.push(e[0]),r.push(e[1])):(r.unshift(e[1]),r.unshift(e[0]),r.push(e[e.length-2]),r.push(e[e.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*t,u=(r[f+4]-r[f-0])*t,h=(r[f+3]-r[f-1])*t,d=(r[f+5]-r[f+1])*t,g=0;g<=i;g++)a=g/i,y=2*Math.pow(a,3)-3*Math.pow(a,2)+1,P=-(2*Math.pow(a,3))+3*Math.pow(a,2),x=Math.pow(a,3)-2*Math.pow(a,2)+a,m=Math.pow(a,3)-Math.pow(a,2),l=y*r[f]+P*r[f+2]+x*c+m*u,s=y*r[f+1]+P*r[f+3]+x*h+m*d,o.push(l),o.push(s);const v=[];for(let E=0;E<o.length-1;E+=2)v.push({x:o[E],y:o[E+1]});if(n)for(let E=0;E<i+1;E++){const L=v.shift();v.push(L)}return v}static getPolygonByID(e,t){return e.find(n=>n.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(n=>t.includes(n.id)):[]}static getHoverEdgeIndex(e,t,n=tool.ELineTypes.Line,i=5){let o=[...t];n===tool.ELineTypes.Curve?o=this.createSmoothCurvePoints(t.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,tool.SEGMENT_NUMBER):n===tool.ELineTypes.Line&&o.push(o[0]);let r=-1,l=i;for(let s=0;s<o.length-1;s++){const{length:c}=MathUtils.default.getFootOfPerpendicular(e,o[s],o[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:n===tool.ELineTypes.Curve?Math.floor(r/tool.SEGMENT_NUMBER):r}static getClosestPoint(e,t,n=tool.ELineTypes.Line,i=3,o){var r;let l=!1;const s=(r=o==null?void 0:o.isClose)!=null?r:!0;let c="",u=-1,h=Infinity,d=e;const y=20;let P=!1;return t.forEach(x=>{if(!P&&!!x.pointList)switch(n){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(x.pointList,s).forEach((a,g)=>{if(P)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,a.point1,a.point2);const E=MathUtils.default.getLineLength(a.point1,e),L=MathUtils.default.getLineLength(a.point2,e);E<i*2&&(v=a.point1,f=E,P=!0),L<i*2&&(v=a.point2,f=L,P=!0),f<h&&f<i&&(c=x.id,u=g,h=f,d=v,l=!0)});break;case tool.ELineTypes.Curve:{const m=this.createSmoothCurvePoints(x.pointList.reduce((a,g)=>[...a,g.x,g.y],[]),.5,s,y);for(let a=0;a<m.length-1;a++){const{length:g,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,m[a],m[a+1]);g<h&&g<i&&(c=x.id,u=Math.floor(a/(y+1)),h=g,d=f,l=!0)}}break}}),{dropFoot:d,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(e,t,n=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,n))}static isPointListOutSidePolygon(e,t,n=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,n))}static getPolygonArea(e){let t=0;for(let n=0,i=e.length;n<i;n++){const o=e[n].x,r=e[n===e.length-1?0:n+1].y,l=e[n===e.length-1?0:n+1].x,s=e[n].y;t+=o*r*.5,t-=l*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,n){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,n)}static deletePolygonLastPoint(e,t,n,i){return n===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var n,i;try{let o=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(l=>[l.x,l.y]))]]);return t.forEach(l=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=turf.difference(o,s);c&&(o=c)}),((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates.map(l=>{var s;return((s=o==null?void 0:o.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):l.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((h,d)=>{const y=(d+1)%c;return!AxisUtils.default.getIsInScope(h,s[y],1)});return u.length<3?l:[...l,u]},[])}catch(o){console.error(o)}}static getPolygonPointList(e,t){const n=t.find(i=>i.id===e);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(n=>PolygonUtils.isPointListInPolygon(e,n.pointList))}static clipPolygonFromWrapPolygon(e,t){const n=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),o=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),r=t[o];let l=[...t.slice(0,o),r,...e,e[0],...t.slice(o,t.length)];return n===i&&(l=[...t.slice(0,o),r,e[0],...e.reverse(),...t.slice(o,t.length)]),l}static isPolygonClosewise(e){const t=e.length;let n,i,o,r=0,l;if(t<3)return 0;for(n=0;n<t;n++)i=(n+1)%t,o=(n+2)%t,l=(e[i].x-e[n].x)*(e[o].y-e[i].y),l-=(e[i].y-e[n].y)*(e[o].x-e[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let n=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((o,r)=>{const l=LineToolUtils.default.calcDistance(e,o);l<n&&(n=l,i=r)}),i}static combinePolygonWithPolygon(e,t){var n,i;try{const o=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),l=turf.union(o,r),s=[],c=e;if(((i=(n=l==null?void 0:l.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(t.id);const u=l==null?void 0:l.geometry.coordinates.map(h=>{var d;return((d=l==null?void 0:l.geometry)==null?void 0:d.type)==="MultiPolygon"?h[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):h.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(o){console.error(o)}}static composePointList(e,t){let n=0,i=0,o=Number.MAX_VALUE;return e.forEach((r,l)=>{t.forEach((s,c)=>{const u=LineToolUtils.default.calcDistance(r,s);u<o&&(n=l+1,i=c+1,o=u)})}),[...e.slice(0,n),...t.slice(i,t.length),...t.slice(0,i),...e.slice(n,e.length)]}static composeSegmentPolygonList(e){var t,n;const i=[];for(let o=0;o<e.length;o++)for(let r=0;r<e.length;r++){const l=(t=e[o])==null?void 0:t.pointList,s=(n=e[r])==null?void 0:n.pointList;o!==r&&l&&s&&PolygonUtils.isPointListInPolygon(s,l)&&(e[o].pointList=PolygonUtils.composePointList(l,s),i.unshift(r))}return i.forEach(o=>{e.splice(o,1)}),e}static computeConvexHull(e){e.sort((o,r)=>o.x!==r.x?o.x-r.x:o.y-r.y);const t=(o,r,l)=>(r.x-o.x)*(l.y-o.y)-(r.y-o.y)*(l.x-o.x),n=[];for(const o of e){for(;n.length>=2&&t(n[n.length-2],n[n.length-1],o)<=0;)n.pop();n.push(o)}const i=[];for(let o=e.length-1;o>=0;o--){const r=e[o];for(;i.length>=2&&t(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return i.pop(),n.pop(),n.concat(i)}static createConvexHullGroup(e){const t={};return e.forEach(n=>{n.type==="line"&&(t[n.annotation.id]||(t[n.annotation.id]={points:[],convexHull:[]}),t[n.annotation.id].points.push(...n.annotation.pointList))}),Object.keys(t).forEach(n=>{t[n].convexHull=this.computeConvexHull(t[n].points)}),t}}module.exports=PolygonUtils;
@@ -1 +1 @@
1
- import{EventDispatcher as je,Vector3 as b,MOUSE as R,TOUCH as j,Quaternion as le,Spherical as ue,Vector2 as p}from"three";var xe=Object.defineProperty,Se=(T,u,m)=>u in T?xe(T,u,{enumerable:!0,configurable:!0,writable:!0,value:m}):T[u]=m,Ie=(T,u,m)=>(Se(T,typeof u!="symbol"?u+"":u,m),m);const pe={type:"change"},Z={type:"start"},me={type:"end"};class ke extends je{constructor(u,m){super();Ie(this,"listenToKeyEvents",t=>{t.addEventListener("keydown",onKeyDown),this._domElementKeyEvents=t}),m===void 0&&console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.'),m===document&&console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'),this.object=u,this.domElement=m,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new b,this.minDistance=0,this.maxDistance=Infinity,this.minZoom=0,this.maxZoom=Infinity,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-Infinity,this.maxAzimuthAngle=Infinity,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:R.ROTATE,MIDDLE:R.DOLLY,RIGHT:R.PAN},this.touches={ONE:j.ROTATE,TWO:j.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return s.phi},this.getAzimuthalAngle=function(){return s.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.saveState=function(){e.target0.copy(e.target),e.position0.copy(e.object.position),e.zoom0=e.object.zoom},this.reset=function(){e.target.copy(e.target0),e.object.position.copy(e.position0),e.object.zoom=e.zoom0,e.object.updateProjectionMatrix(),e.dispatchEvent(pe),e.update(),i=a.NONE},this.update=function(){const t=new b,n=new le().setFromUnitVectors(u.up,new b(0,1,0)),r=n.clone().invert(),c=new b,l=new le,N=2*Math.PI;return function(){const{position:ce}=e.object;t.copy(ce).sub(e.target),t.applyQuaternion(n),s.setFromVector3(t),e.autoRotate&&i===a.NONE&&C(he()),e.enableDamping?(s.theta+=h.theta*e.dampingFactor,s.phi+=h.phi*e.dampingFactor):(s.theta+=h.theta,s.phi+=h.phi);let d=e.minAzimuthAngle,f=e.maxAzimuthAngle;return isFinite(d)&&isFinite(f)&&(d<-Math.PI?d+=N:d>Math.PI&&(d-=N),f<-Math.PI?f+=N:f>Math.PI&&(f-=N),d<=f?s.theta=Math.max(d,Math.min(f,s.theta)):s.theta=s.theta>(d+f)/2?Math.max(d,s.theta):Math.min(f,s.theta)),s.phi=Math.max(e.minPolarAngle,Math.min(e.maxPolarAngle,s.phi)),s.makeSafe(),s.radius*=S,s.radius=Math.max(e.minDistance,Math.min(e.maxDistance,s.radius)),e.enableDamping===!0?e.target.addScaledVector(O,e.dampingFactor):e.target.add(O),t.setFromSpherical(s),t.applyQuaternion(r),ce.copy(e.target).add(t),e.object.lookAt(e.target),e.enableDamping===!0?(h.theta*=1-e.dampingFactor,h.phi*=1-e.dampingFactor,O.multiplyScalar(1-e.dampingFactor)):(h.set(0,0,0),O.set(0,0,0)),S=1,I||c.distanceToSquared(e.object.position)>F||8*(1-l.dot(e.object.quaternion))>F?(e.dispatchEvent(pe),c.copy(e.object.position),l.copy(e.object.quaternion),I=!1,!0):!1}}(),this.dispose=function(){e.domElement.removeEventListener("contextmenu",ie),e.domElement.removeEventListener("pointerdown",ne),e.domElement.removeEventListener("pointercancel",oe),e.domElement.removeEventListener("wheel",ae),e.domElement.removeEventListener("pointermove",v),e.domElement.removeEventListener("pointerup",z),e._domElementKeyEvents!==null&&e._domElementKeyEvents.removeEventListener("keydown",Le)};const e=this,a={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let i=a.NONE;const F=1e-6,s=new ue,h=new ue;let S=1;const O=new b;let I=!1;const E=new p,g=new p,w=new p,y=new p,P=new p,M=new p,A=new p,L=new p,x=new p,o=[],k={};function he(){return 2*Math.PI/60/60*e.autoRotateSpeed}function Y(){return Math.pow(.95,e.zoomSpeed)}function C(t){h.theta-=t}function X(t){h.phi-=t}const K=function(){const t=new b;return function(r,c){t.setFromMatrixColumn(c,0),t.multiplyScalar(-r),O.add(t)}}(),V=function(){const t=new b;return function(r,c){e.screenSpacePanning===!0?t.setFromMatrixColumn(c,1):(t.setFromMatrixColumn(c,0),t.crossVectors(e.object.up,t)),t.multiplyScalar(r),O.add(t)}}(),D=function(){const t=new b;return function(r,c){const l=e.domElement;if(e.object.isPerspectiveCamera){const{position:N}=e.object;t.copy(N).sub(e.target);let _=t.length();_*=Math.tan(e.object.fov/2*Math.PI/180),K(2*r*_/l.clientHeight,e.object.matrix),V(2*c*_/l.clientHeight,e.object.matrix)}else e.object.isOrthographicCamera?(K(r*(e.object.right-e.object.left)/e.object.zoom/l.clientWidth,e.object.matrix),V(c*(e.object.top-e.object.bottom)/e.object.zoom/l.clientHeight,e.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),e.enablePan=!1)}}();function H(t){e.object.isPerspectiveCamera?S/=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom*t)),e.object.updateProjectionMatrix(),I=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function W(t){e.object.isPerspectiveCamera?S*=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom/t)),e.object.updateProjectionMatrix(),I=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function q(t){E.set(t.clientX,t.clientY)}function de(t){A.set(t.clientX,t.clientY)}function G(t){y.set(t.clientX,t.clientY)}function fe(t){g.set(t.clientX,t.clientY),w.subVectors(g,E).multiplyScalar(e.rotateSpeed);const n=e.domElement;C(2*Math.PI*w.x/n.clientHeight),X(2*Math.PI*w.y/n.clientHeight),E.copy(g),e.update()}function be(t){L.set(t.clientX,t.clientY),x.subVectors(L,A),x.y>0?H(Y()):x.y<0&&W(Y()),A.copy(L),e.update()}function Ee(t){P.set(t.clientX,t.clientY),M.subVectors(P,y).multiplyScalar(e.panSpeed),D(M.x,M.y),y.copy(P),e.update()}function ge(t){t.deltaY<0?W(Y()):t.deltaY>0&&H(Y()),e.update()}function ye(t){let n=!1;switch(t.code){case e.keys.UP:D(0,e.keyPanSpeed),n=!0;break;case e.keys.BOTTOM:D(0,-e.keyPanSpeed),n=!0;break;case e.keys.LEFT:D(e.keyPanSpeed,0),n=!0;break;case e.keys.RIGHT:D(-e.keyPanSpeed,0),n=!0;break}n&&(t.preventDefault(),e.update())}function B(){if(o.length===1)E.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);E.set(t,n)}}function Q(){if(o.length===1)y.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);y.set(t,n)}}function J(){const t=o[0].pageX-o[1].pageX,n=o[0].pageY-o[1].pageY,r=Math.sqrt(t*t+n*n);A.set(0,r)}function Pe(){e.enableZoom&&J(),e.enablePan&&Q()}function Te(){e.enableZoom&&J(),e.enableRotate&&B()}function $(t){if(o.length==1)g.set(t.pageX,t.pageY);else{const r=U(t),c=.5*(t.pageX+r.x),l=.5*(t.pageY+r.y);g.set(c,l)}w.subVectors(g,E).multiplyScalar(e.rotateSpeed);const n=e.domElement;C(2*Math.PI*w.x/n.clientHeight),X(2*Math.PI*w.y/n.clientHeight),E.copy(g)}function ee(t){if(o.length===1)P.set(t.pageX,t.pageY);else{const n=U(t),r=.5*(t.pageX+n.x),c=.5*(t.pageY+n.y);P.set(r,c)}M.subVectors(P,y).multiplyScalar(e.panSpeed),D(M.x,M.y),y.copy(P)}function te(t){const n=U(t),r=t.pageX-n.x,c=t.pageY-n.y,l=Math.sqrt(r*r+c*c);L.set(0,l),x.set(0,Math.pow(L.y/A.y,e.zoomSpeed)),H(x.y),A.copy(L)}function Oe(t){e.enableZoom&&te(t),e.enablePan&&ee(t)}function we(t){e.enableZoom&&te(t),e.enableRotate&&$(t)}function ne(t){e.enabled!==!1&&(o.length===0&&(e.domElement.setPointerCapture(t.pointerId),e.domElement.addEventListener("pointermove",v),e.domElement.addEventListener("pointerup",z)),Re(t),t.pointerType==="touch"?De(t):Me(t))}function v(t){e.enabled!==!1&&(t.pointerType==="touch"?Ne(t):Ae(t))}function z(t){se(t),o.length===0&&(e.domElement.releasePointerCapture(t.pointerId),e.domElement.removeEventListener("pointermove",v),e.domElement.removeEventListener("pointerup",z)),e.dispatchEvent(me),i=a.NONE}function oe(t){se(t)}function Me(t){let n;switch(t.button){case 0:n=e.mouseButtons.LEFT;break;case 1:n=e.mouseButtons.MIDDLE;break;case 2:n=e.mouseButtons.RIGHT;break;default:n=-1}switch(n){case R.DOLLY:if(e.enableZoom===!1)return;de(t),i=a.DOLLY;break;case R.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enablePan===!1)return;G(t),i=a.PAN}else{if(e.enableRotate===!1)return;q(t),i=a.ROTATE}break;case R.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enableRotate===!1)return;q(t),i=a.ROTATE}else{if(e.enablePan===!1)return;G(t),i=a.PAN}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(Z)}function Ae(t){if(e.enabled!==!1)switch(i){case a.ROTATE:if(e.enableRotate===!1)return;fe(t);break;case a.DOLLY:if(e.enableZoom===!1)return;be(t);break;case a.PAN:if(e.enablePan===!1)return;Ee(t);break}}function ae(t){e.enabled===!1||e.enableZoom===!1||i!==a.NONE||(t.preventDefault(),e.dispatchEvent(Z),ge(t),e.dispatchEvent(me))}function Le(t){e.enabled===!1||e.enablePan===!1||ye(t)}function De(t){switch(re(t),o.length){case 1:switch(e.touches.ONE){case j.ROTATE:if(e.enableRotate===!1)return;B(),i=a.TOUCH_ROTATE;break;case j.PAN:if(e.enablePan===!1)return;Q(),i=a.TOUCH_PAN;break;default:i=a.NONE}break;case 2:switch(e.touches.TWO){case j.DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;Pe(),i=a.TOUCH_DOLLY_PAN;break;case j.DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;Te(),i=a.TOUCH_DOLLY_ROTATE;break;default:i=a.NONE}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(Z)}function Ne(t){switch(re(t),i){case a.TOUCH_ROTATE:if(e.enableRotate===!1)return;$(t),e.update();break;case a.TOUCH_PAN:if(e.enablePan===!1)return;ee(t),e.update();break;case a.TOUCH_DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;Oe(t),e.update();break;case a.TOUCH_DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;we(t),e.update();break;default:i=a.NONE}}function ie(t){e.enabled!==!1&&t.preventDefault()}function Re(t){o.push(t)}function se(t){delete k[t.pointerId];for(let n=0;n<o.length;n++)if(o[n].pointerId==t.pointerId){o.splice(n,1);return}}function re(t){let n=k[t.pointerId];n===void 0&&(n=new p,k[t.pointerId]=n),n.set(t.pageX,t.pageY)}function U(t){const n=t.pointerId===o[0].pointerId?o[1]:o[0];return k[n.pointerId]}e.domElement.addEventListener("contextmenu",ie),e.domElement.addEventListener("pointerdown",ne),e.domElement.addEventListener("pointercancel",oe),e.domElement.addEventListener("wheel",ae,{passive:!1}),this.update()}}export{ke as OrbitControls};
1
+ import{EventDispatcher as je,Vector3 as b,MOUSE as R,TOUCH as j,Quaternion as le,Spherical as ue,Vector2 as p}from"three";var xe=Object.defineProperty,Se=(T,u,m)=>u in T?xe(T,u,{enumerable:!0,configurable:!0,writable:!0,value:m}):T[u]=m,ke=(T,u,m)=>(Se(T,typeof u!="symbol"?u+"":u,m),m);const pe={type:"change"},Z={type:"start"},me={type:"end"};class Ie extends je{constructor(u,m){super();ke(this,"listenToKeyEvents",t=>{t.addEventListener("keydown",onKeyDown),this._domElementKeyEvents=t}),m===void 0&&console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.'),m===document&&console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'),this.object=u,this.domElement=m,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new b,this.minDistance=0,this.maxDistance=Infinity,this.minZoom=0,this.maxZoom=Infinity,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-Infinity,this.maxAzimuthAngle=Infinity,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:R.ROTATE,MIDDLE:R.DOLLY,RIGHT:R.PAN},this.touches={ONE:j.ROTATE,TWO:j.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return s.phi},this.getAzimuthalAngle=function(){return s.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.saveState=function(){e.target0.copy(e.target),e.position0.copy(e.object.position),e.zoom0=e.object.zoom},this.reset=function(){e.target.copy(e.target0),e.object.position.copy(e.position0),e.object.zoom=e.zoom0,e.object.updateProjectionMatrix(),e.dispatchEvent(pe),e.update(),i=a.NONE},this.update=function(){const t=new b,n=new le().setFromUnitVectors(u.up,new b(0,1,0)),r=n.clone().invert(),c=new b,l=new le,N=2*Math.PI;return function(){const{position:ce}=e.object;t.copy(ce).sub(e.target),t.applyQuaternion(n),s.setFromVector3(t),e.autoRotate&&i===a.NONE&&_(he()),e.enableDamping?(s.theta+=h.theta*e.dampingFactor,s.phi+=h.phi*e.dampingFactor):(s.theta+=h.theta,s.phi+=h.phi);let d=e.minAzimuthAngle,f=e.maxAzimuthAngle;return isFinite(d)&&isFinite(f)&&(d<-Math.PI?d+=N:d>Math.PI&&(d-=N),f<-Math.PI?f+=N:f>Math.PI&&(f-=N),d<=f?s.theta=Math.max(d,Math.min(f,s.theta)):s.theta=s.theta>(d+f)/2?Math.max(d,s.theta):Math.min(f,s.theta)),s.phi=Math.max(e.minPolarAngle,Math.min(e.maxPolarAngle,s.phi)),s.makeSafe(),s.radius*=S,s.radius=Math.max(e.minDistance,Math.min(e.maxDistance,s.radius)),e.enableDamping===!0?e.target.addScaledVector(O,e.dampingFactor):e.target.add(O),t.setFromSpherical(s),t.applyQuaternion(r),ce.copy(e.target).add(t),e.object.lookAt(e.target),e.enableDamping===!0?(h.theta*=1-e.dampingFactor,h.phi*=1-e.dampingFactor,O.multiplyScalar(1-e.dampingFactor)):(h.set(0,0,0),O.set(0,0,0)),S=1,k||c.distanceToSquared(e.object.position)>F||8*(1-l.dot(e.object.quaternion))>F?(e.dispatchEvent(pe),c.copy(e.object.position),l.copy(e.object.quaternion),k=!1,!0):!1}}(),this.dispose=function(){e.domElement.removeEventListener("contextmenu",ie),e.domElement.removeEventListener("pointerdown",ne),e.domElement.removeEventListener("pointercancel",oe),e.domElement.removeEventListener("wheel",ae),e.domElement.removeEventListener("pointermove",v),e.domElement.removeEventListener("pointerup",z),e._domElementKeyEvents!==null&&e._domElementKeyEvents.removeEventListener("keydown",Le)};const e=this,a={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let i=a.NONE;const F=1e-6,s=new ue,h=new ue;let S=1;const O=new b;let k=!1;const E=new p,g=new p,w=new p,y=new p,P=new p,M=new p,A=new p,L=new p,x=new p,o=[],I={};function he(){return 2*Math.PI/60/60*e.autoRotateSpeed}function Y(){return Math.pow(.95,e.zoomSpeed)}function _(t){h.theta-=t}function X(t){h.phi-=t}const K=function(){const t=new b;return function(r,c){t.setFromMatrixColumn(c,0),t.multiplyScalar(-r),O.add(t)}}(),V=function(){const t=new b;return function(r,c){e.screenSpacePanning===!0?t.setFromMatrixColumn(c,1):(t.setFromMatrixColumn(c,0),t.crossVectors(e.object.up,t)),t.multiplyScalar(r),O.add(t)}}(),D=function(){const t=new b;return function(r,c){const l=e.domElement;if(e.object.isPerspectiveCamera){const{position:N}=e.object;t.copy(N).sub(e.target);let C=t.length();C*=Math.tan(e.object.fov/2*Math.PI/180),K(2*r*C/l.clientHeight,e.object.matrix),V(2*c*C/l.clientHeight,e.object.matrix)}else e.object.isOrthographicCamera?(K(r*(e.object.right-e.object.left)/e.object.zoom/l.clientWidth,e.object.matrix),V(c*(e.object.top-e.object.bottom)/e.object.zoom/l.clientHeight,e.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),e.enablePan=!1)}}();function H(t){e.object.isPerspectiveCamera?S/=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom*t)),e.object.updateProjectionMatrix(),k=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function W(t){e.object.isPerspectiveCamera?S*=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom/t)),e.object.updateProjectionMatrix(),k=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function q(t){E.set(t.clientX,t.clientY)}function de(t){A.set(t.clientX,t.clientY)}function G(t){y.set(t.clientX,t.clientY)}function fe(t){g.set(t.clientX,t.clientY),w.subVectors(g,E).multiplyScalar(e.rotateSpeed);const n=e.domElement;_(2*Math.PI*w.x/n.clientHeight),X(2*Math.PI*w.y/n.clientHeight),E.copy(g),e.update()}function be(t){L.set(t.clientX,t.clientY),x.subVectors(L,A),x.y>0?H(Y()):x.y<0&&W(Y()),A.copy(L),e.update()}function Ee(t){P.set(t.clientX,t.clientY),M.subVectors(P,y).multiplyScalar(e.panSpeed),D(M.x,M.y),y.copy(P),e.update()}function ge(t){t.deltaY<0?W(Y()):t.deltaY>0&&H(Y()),e.update()}function ye(t){let n=!1;switch(t.code){case e.keys.UP:D(0,e.keyPanSpeed),n=!0;break;case e.keys.BOTTOM:D(0,-e.keyPanSpeed),n=!0;break;case e.keys.LEFT:D(e.keyPanSpeed,0),n=!0;break;case e.keys.RIGHT:D(-e.keyPanSpeed,0),n=!0;break}n&&(t.preventDefault(),e.update())}function B(){if(o.length===1)E.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);E.set(t,n)}}function Q(){if(o.length===1)y.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);y.set(t,n)}}function J(){const t=o[0].pageX-o[1].pageX,n=o[0].pageY-o[1].pageY,r=Math.sqrt(t*t+n*n);A.set(0,r)}function Pe(){e.enableZoom&&J(),e.enablePan&&Q()}function Te(){e.enableZoom&&J(),e.enableRotate&&B()}function $(t){if(o.length==1)g.set(t.pageX,t.pageY);else{const r=U(t),c=.5*(t.pageX+r.x),l=.5*(t.pageY+r.y);g.set(c,l)}w.subVectors(g,E).multiplyScalar(e.rotateSpeed);const n=e.domElement;_(2*Math.PI*w.x/n.clientHeight),X(2*Math.PI*w.y/n.clientHeight),E.copy(g)}function ee(t){if(o.length===1)P.set(t.pageX,t.pageY);else{const n=U(t),r=.5*(t.pageX+n.x),c=.5*(t.pageY+n.y);P.set(r,c)}M.subVectors(P,y).multiplyScalar(e.panSpeed),D(M.x,M.y),y.copy(P)}function te(t){const n=U(t),r=t.pageX-n.x,c=t.pageY-n.y,l=Math.sqrt(r*r+c*c);L.set(0,l),x.set(0,Math.pow(L.y/A.y,e.zoomSpeed)),H(x.y),A.copy(L)}function Oe(t){e.enableZoom&&te(t),e.enablePan&&ee(t)}function we(t){e.enableZoom&&te(t),e.enableRotate&&$(t)}function ne(t){e.enabled!==!1&&(o.length===0&&(e.domElement.setPointerCapture(t.pointerId),e.domElement.addEventListener("pointermove",v),e.domElement.addEventListener("pointerup",z)),Re(t),t.pointerType==="touch"?De(t):Me(t))}function v(t){e.enabled!==!1&&(t.pointerType==="touch"?Ne(t):Ae(t))}function z(t){se(t),o.length===0&&(e.domElement.releasePointerCapture(t.pointerId),e.domElement.removeEventListener("pointermove",v),e.domElement.removeEventListener("pointerup",z)),e.dispatchEvent(me),i=a.NONE}function oe(t){se(t)}function Me(t){let n;switch(t.button){case 0:n=e.mouseButtons.LEFT;break;case 1:n=e.mouseButtons.MIDDLE;break;case 2:n=e.mouseButtons.RIGHT;break;default:n=-1}switch(n){case R.DOLLY:if(e.enableZoom===!1)return;de(t),i=a.DOLLY;break;case R.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enablePan===!1)return;G(t),i=a.PAN}else{if(e.enableRotate===!1)return;q(t),i=a.ROTATE}break;case R.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enableRotate===!1)return;q(t),i=a.ROTATE}else{if(e.enablePan===!1)return;G(t),i=a.PAN}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(Z)}function Ae(t){if(e.enabled!==!1)switch(i){case a.ROTATE:if(e.enableRotate===!1)return;fe(t);break;case a.DOLLY:if(e.enableZoom===!1)return;be(t);break;case a.PAN:if(e.enablePan===!1)return;Ee(t);break}}function ae(t){e.enabled===!1||e.enableZoom===!1||i!==a.NONE||(t.preventDefault(),e.dispatchEvent(Z),ge(t),e.dispatchEvent(me))}function Le(t){e.enabled===!1||e.enablePan===!1||ye(t)}function De(t){switch(re(t),o.length){case 1:switch(e.touches.ONE){case j.ROTATE:if(e.enableRotate===!1)return;B(),i=a.TOUCH_ROTATE;break;case j.PAN:if(e.enablePan===!1)return;Q(),i=a.TOUCH_PAN;break;default:i=a.NONE}break;case 2:switch(e.touches.TWO){case j.DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;Pe(),i=a.TOUCH_DOLLY_PAN;break;case j.DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;Te(),i=a.TOUCH_DOLLY_ROTATE;break;default:i=a.NONE}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(Z)}function Ne(t){switch(re(t),i){case a.TOUCH_ROTATE:if(e.enableRotate===!1)return;$(t),e.update();break;case a.TOUCH_PAN:if(e.enablePan===!1)return;ee(t),e.update();break;case a.TOUCH_DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;Oe(t),e.update();break;case a.TOUCH_DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;we(t),e.update();break;default:i=a.NONE}}function ie(t){e.enabled!==!1&&(t.preventDefault(),e.dispatchEvent({type:"rightClick",originalEvent:t}))}function Re(t){o.push(t)}function se(t){delete I[t.pointerId];for(let n=0;n<o.length;n++)if(o[n].pointerId==t.pointerId){o.splice(n,1);return}}function re(t){let n=I[t.pointerId];n===void 0&&(n=new p,I[t.pointerId]=n),n.set(t.pageX,t.pageY)}function U(t){const n=t.pointerId===o[0].pointerId?o[1]:o[0];return I[n.pointerId]}e.domElement.addEventListener("contextmenu",ie),e.domElement.addEventListener("pointerdown",ne),e.domElement.addEventListener("pointercancel",oe),e.domElement.addEventListener("wheel",ae,{passive:!1}),this.update()}}export{Ie as OrbitControls};
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as k,PerspectiveShiftUtils as S,EPerspectiveView as b,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import R from"../../_virtual/filterBoxWorker.js";import{isInPolygon as H}from"../../utils/tool/polygonTool.js";import L from"../../utils/uuid.js";import A from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as U}from"./PCDLoader.js";import{OrbitControls as Z}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as I,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as 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,_=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,j=(C,t,e)=>t in C?J(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,P=(C,t)=>{for(var e in t||(t={}))it.call(t,e)&&j(C,e,t[e]);if(_)for(var e of _(t))rt.call(t,e)&&j(C,e,t[e]);return C},B=(C,t)=>tt(C,et(t)),v=(C,t,e)=>new Promise((i,r)=>{var s=d=>{try{o(e.next(d))}catch(n){r(n)}},h=d=>{try{o(e.throw(d))}catch(n){r(n)}},o=d=>d.done?i(d.value):Promise.resolve(d.value).then(s,h);o((e=e.apply(C,t)).next())});const nt=30,D=new V({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:d}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,l="blue")=>{var c;const u=(c=n.id)!=null?c:L();this.removeObjectByName(u,"sphere");const{radius:p,widthSegments:x,heightSegments:g}=O,{center:m}=n,f=new a.Group,y=new a.SphereGeometry(p,x,g),w=new a.MeshBasicMaterial({color:l}),M=new a.Mesh(y,w);M.position.set(m.x,m.y,m.z),f.add(M),f.name=`sphere${u}`,this.scene.add(f)},this.generateSphere=n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l),this.render()},this.generateSpheres=n=>{n.forEach(l=>{const{fill:c}=this.getColorFromConfig(l.attribute);this.addSphereToSense(l,c)}),this.render()},this.addBoxToSense=(n,l=16777215)=>{var c;const u=(c=n.id)!=null?c:L();this.removeObjectByName(u,"box");const{center:p,width:x,height:g,depth:m,rotation:f}=n,y=new a.Group,w=new a.BoxGeometry(x,g,m),M=new a.MeshBasicMaterial({color:"blue"}),z=new a.Mesh(w,M),N=new a.BoxHelper(z,l),F=this.generateBoxArrow(n),T=this.generateBoxTrackID(n);T&&y.add(T),y.add(N),y.add(F),p&&y.position.set(p.x,p.y,p.z),f&&y.rotation.set(0,0,f),y.name=`box${u}`,this.scene.add(y)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const l=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,l)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as h from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as z,EPerspectiveView as C,PointCloudUtils as U,DEFAULT_SPHERE_PARAMS as L}from"@labelbee/lb-utils";import Z from"../../_virtual/highlightWorker.js";import G from"../../_virtual/filterBoxWorker.js";import{isInPolygon as $}from"../../utils/tool/polygonTool.js";import _ from"../../utils/uuid.js";import N from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as K}from"./PCDLoader.js";import{OrbitControls as X}from"./OrbitControls.js";import{PointCloudCache as q}from"./cache.js";import{getCuboidFromPointCloudBox as I,getHighlightIndexByPoints as Q,mergeHighlightList as J}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as tt}from"./segmentation.js";import et from"./store/index.js";import it from"./render/index.js";import rt from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var nt=Object.defineProperty,ot=Object.defineProperties,st=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,F=(b,t,e)=>t in b?nt(b,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):b[t]=e,v=(b,t)=>{for(var e in t||(t={}))at.call(t,e)&&F(b,e,t[e]);if(E)for(var e of E(t))ht.call(t,e)&&F(b,e,t[e]);return b},S=(b,t)=>ot(b,st(t)),B=(b,t,e)=>new Promise((i,r)=>{var a=d=>{try{s(e.next(d))}catch(p){r(p)}},c=d=>{try{s(e.throw(d))}catch(p){r(p)}},s=d=>d.done?i(d.value):Promise.resolve(d.value).then(a,c);s((e=e.apply(b,t)).next())});const ct=30,D=new Z({type:"module"});class lt extends rt{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:a="#4C4C4C",config:c,isSegment:s,checkMode:d,hiddenText:p=!1}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.workerLoading=!1,this.raycaster=new h.Raycaster,this.pointer=new h.Vector2,this.hiddenText=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,n="blue")=>{var l;const u=(l=o.id)!=null?l:_();this.removeObjectByName(u,"sphere");const{radius:x,widthSegments:g,heightSegments:y}=L,{center:m}=o,f=new h.Group,w=new h.SphereGeometry(x,g,y),M=new h.MeshBasicMaterial({color:n}),P=new h.Mesh(w,M);P.position.set(m.x,m.y,m.z),f.add(P),f.name=`sphere${u}`,this.scene.add(f)},this.generateSphere=o=>{const{fill:n}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,n),this.render()},this.generateSpheres=o=>{o.forEach(n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l)}),this.render()},this.addBoxToSense=(o,n=16777215)=>{var l;const u=(l=o.id)!=null?l:_();this.removeObjectByName(u,"box");const{center:x,width:g,height:y,depth:m,rotation:f}=o,w=new h.Group,M=new h.BoxGeometry(g,y,m),P=new h.MeshBasicMaterial({color:"blue"}),O=new h.Mesh(M,P),V=new h.BoxHelper(O,n),R=this.generateBoxArrow(o),T=this.generateBoxTrackID(o);T&&w.add(T);const k=this.generateBoxAttributeLabel(o);k&&w.add(k),w.add(V),w.add(R),x&&w.position.set(x.x,x.y,x.z),f&&w.rotation.set(0,0,f),w.name=`box${u}`;const H=new h.BoxGeometry(g,y,m),W=new h.MeshBasicMaterial({visible:!1}),A=new h.Mesh(H,W);A.userData={selectedID:u},w.add(A),this.scene.add(w)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const n=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,n)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,6 @@ import*as a from"three";import{toolStyleConverter as k,PerspectiveShiftUtils as
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>v(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:u,color:p}=yield this.cacheInstance.loadPCDFile(l),x=new a.BufferGeometry;x.setAttribute("position",new a.BufferAttribute(u,3)),this.isSegment||x.setAttribute("dimensions",new a.BufferAttribute(p,3)),this.initCloudData(u);const g=new a.Points(x);this.renderPointCloud(g,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>v(this,[n],function*({mappingImgList:l,points:c}){const u=m=>v(this,null,function*(){try{return yield W.load(m)}catch(f){return console.error("Error loading image:",f),null}}),p=l.length===0?[]:(yield Promise.all(l.map(m=>v(this,null,function*(){let f=yield u(m.url);return!f&&m.fallbackUrl&&(f=yield u(m.fallbackUrl)),f})))).filter(m=>m!==null),x=l.map((m,f)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?y:[];const w=$({points:c,calib:m.calib,width:p[f].width,height:p[f].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,w),w});return Y(x)}),this.filterPreResult=(n,l,c)=>v(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),p=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(x=>{const g=c.map(m=>{const f=A.calculatePointsInsideBox({indexMap:p,polygon:I(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),y=f>=l.lowerLimitPointsNumInBox;return B(P({},m),{valid:y,count:f})});x(g)})}),this.loadPCDFileByBox=(n,l,c)=>v(this,null,function*(){const u=(g,m)=>v(this,null,function*(){const{width:f=0,height:y=0,depth:w=0}=c!=null?c:{},M=yield this.filterPointsByBox(B(P({},l),{width:l.width+f,height:l.height+y,depth:l.depth+w}),g,m);if(!M){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const z=new a.Points(M.geometry);z.name=this.pointCloudObjectName,this.scene.add(z),this.render()}),{points:p,color:x}=yield this.cacheInstance.loadPCDFile(n);u(p,x)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),u=2,p=16776960,x=new a.ArrowHelper(l,c,u,p);return x.visible=this.showDirection,x},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),u=new a.Sprite(c);return u.scale.set(5,5,5),u.position.set(-n.width/2,0,n.depth/2+.5),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const u=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(u*1.2,10):c.material.uniforms.pointSize.value=Math.max(u/1.2,1),l&&(c.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new Z(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new U,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new X(P({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(B(P({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return P({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return k.getColorFromConfig({attribute:t},B(P({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,c=-100,u=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=I(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(u=>{const p=new R;p.postMessage(c),p.onmessage=x=>{const{color:g,position:m,num:f}=x.data,y=new a.BufferGeometry;y.setAttribute("position",new a.Float32BufferAttribute(m,3)),y.setAttribute("color",new a.Float32BufferAttribute(g,3)),y.computeBoundingSphere(),p.terminate(),u({geometry:y,num:f})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=b.Front,s=nt){let h=S.frontViewMatrix4(s);switch(r){case b.Front:break;case b.Back:h=S.backViewMatrix4(s);break;case b.Left:h=S.leftViewMatrix4(s);break;case b.Right:h=S.rightViewMatrix4(s);break;case b.Top:h=S.topViewMatrix4(s);break;case b.LFT:h=S.leftFrontTopViewMatrix4(s,i);break;case b.RBT:h=S.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return v(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,D.postMessage(t),D.onmessage=r=>{e(r.data),this.workerLoading=!1},D.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return v(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:s,resetAreas:h}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((d,n)=>{if(window.Worker){const c=(e?[...e]:[]).map(m=>I(m)),u=this.getAllAttributeColor(c),p=o.geometry.attributes.position.array,x=o.geometry.attributes.dimensions.array,g={cuboidList:c,position:p,color:x,colorList:u,highlightIndex:i,modifiedBoxIds:s,resetAreas:h};this.handleWebworker(g).then(m=>{const{color:f}=m;let y=f;(s.length||h.length)&&(y=f.map((M,z)=>M===-1?x[z]:M));const w=new a.BufferAttribute(y,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==f.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,y),this.highlightPCDSrc=void 0,w.needsUpdate=!0,o.geometry.setAttribute("dimensions",w),o.geometry.attributes.dimensions.needsUpdate=!0,d(y),this.render()}).catch(m=>{n(m)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=k.getColorFromConfig({attribute:i.attribute},B(P({},this.config),{attributeConfigurable:!0}),{}),u=new a.BoxGeometry(o,d,n),p=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});u.rotateZ(l),u.translate(r,s,h);const x=new a.Mesh(u,p);e.add(x);const g=new a.PlaneGeometry(n,d);g.rotateY(Math.PI/2),g.rotateZ(l);const m=new a.Vector3(o/2,0,0),f=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);m.applyMatrix4(f),g.translate(r+m.x,s+m.y,h+m.z);const y=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new a.Mesh(g,y);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((c,u)=>c.z-u.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((c,u)=>c.x-u.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((c,u)=>c.y-u.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,c)=>{const u=r[c+1],p=A.getFootOfPerpendicular({x:d,y:n},l,u,!1,!0).length;(!i[c]||p<i[c].distance)&&(i[c]={distance:p,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],u=r[n+2];return E.getIntersectionBySlope({p1:s[n].point,line1:[l,c],p2:s[n+1].point,line2:[c,u]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(g=>g.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,u=[],p=[];const x=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let g=0;g<x.length;g+=3){const m=x[g],f=x[g+1],y=x[g+2];H({x:m,y:f},t)&&(y||y===0)&&p.push({x:m,y:f,z:y})}return p.length?(i&&(p=this.filterNoise(p),u=this.getFittedCoordinates(t,p)),p.sort((g,m)=>g.z-m.z),d=p[0].z-.01,n=p[p.length-1].z+.01,c=p.length,e&&(l=p.filter(({z:g})=>g>=e[0]&&g<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:u}):{maxZ:n,minZ:d,count:l,zCount:c,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:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},l={x:e-h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},l={x:e-h/2,y:i-s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},l={x:e-h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,b.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case b.Left:return this.getPolygonSidePoints(t);case b.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new a.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),u=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=B(P({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=B(P({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(m=>new a.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(h)),[d,n,l,c]=o,u=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),x=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:B(P({},r),{center:{x:r.center.x-x.x,y:r.center.y-x.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,s=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...o)=>B(this,[...o],function*(n=this.currentPCDSrc,l){if(!n)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=n;const{points:u,color:x}=yield this.cacheInstance.loadPCDFile(n),g=new h.BufferGeometry;g.setAttribute("position",new h.BufferAttribute(u,3)),this.isSegment||g.setAttribute("dimensions",new h.BufferAttribute(x,3)),this.initCloudData(u);const y=new h.Points(g);this.renderPointCloud(y,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=o=>B(this,[o],function*({mappingImgList:n,points:l}){const u=m=>B(this,null,function*(){try{return yield Y.load(m)}catch(f){return console.error("Error loading image:",f),null}}),x=n.length===0?[]:(yield Promise.all(n.map(m=>B(this,null,function*(){let f=yield u(m.url);return!f&&m.fallbackUrl&&(f=yield u(m.fallbackUrl)),f})))).filter(m=>m!==null),g=n.map((m,f)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(m.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(m.url))!=null?w:[];const M=Q({points:l,calib:m.calib,width:x[f].width,height:x[f].height});return this.cacheInstance.cache2DHighlightIndex.set(m.url,M),M});return J(g)}),this.filterPreResult=(o,n,l)=>B(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(o),x=yield this.cacheInstance.loadIndexMap(o,u);return new Promise(g=>{const y=l.map(m=>{const f=N.calculatePointsInsideBox({indexMap:x,polygon:I(m).polygonPointList,zScope:[m.center.z-m.depth/2,m.center.z+m.depth/2],box:m}),w=f>=n.lowerLimitPointsNumInBox;return S(v({},m),{valid:w,count:f})});g(y)})}),this.loadPCDFileByBox=(o,n,l)=>B(this,null,function*(){const u=(y,m)=>B(this,null,function*(){const{width:f=0,height:w=0,depth:M=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(v({},n),{width:n.width+f,height:n.height+w,depth:n.depth+M}),y,m);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const O=new h.Points(P.geometry);O.name=this.pointCloudObjectName,this.scene.add(O),this.render()}),{points:x,color:g}=yield this.cacheInstance.loadPCDFile(o);u(x,g)}),this.generateRange=o=>{const n=this.createRange(o);this.scene.add(n)},this.generateBoxArrow=({width:o})=>{const n=new h.Vector3(1,0,0),l=new h.Vector3(o/2,0,0),u=2,x=16776960,g=new h.ArrowHelper(n,l,u,x);return g.visible=this.showDirection,g},this.generateLabel=(o,n)=>{const l=this.getTextCanvas(o),u=new h.Texture(l);u.minFilter=h.LinearFilter,u.magFilter=h.LinearFilter,u.needsUpdate=!0;const x=l.width/window.devicePixelRatio,g=l.height/window.devicePixelRatio,y=new h.SpriteMaterial({map:u,depthWrite:!1}),m=new h.Sprite(y);return m.scale.set(x/n,g/n,1),{sprite:m,canvasWidth:x,canvasHeight:g}},this.generateBoxTrackID=o=>{if(!o.trackID)return;const{sprite:n}=this.generateLabel(o.trackID.toString(),50);return n.position.set(-o.width/2,0,o.depth/2+.5),n},this.generateBoxAttributeLabel=o=>{if(!o.attribute||this.hiddenText)return;const n=this.findSubAttributeLabel(o,this.config),l=n?`${o.attribute}
32
+ ${n}`:`${o.attribute}`,{sprite:u,canvasWidth:x,canvasHeight:g}=this.generateLabel(l,100);return u.position.set(-o.width/2,o.height/2-x/200,-o.depth/2-g/150),u},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:n})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const u=l.material.uniforms.pointSize.value;o?l.material.uniforms.pointSize.value=Math.min(u*1.2,10):l.material.uniforms.pointSize.value=Math.max(u/1.2,1),n&&(l.material.uniforms.pointSize.value=n,this.pointsMaterialSize=n),l.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new h.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=c,this.checkMode=d!=null?d:!1,this.hiddenText=p,i&&r?(this.isOrthographicCamera=!0,this.camera=new h.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new h.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new h.Scene,this.controls=new X(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new K,this.axesHelper=new h.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=q.getInstance(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",o=>{var n,l;const u=this.renderer.domElement.getBoundingClientRect(),x=o.originalEvent.clientX-u.left,g=o.originalEvent.clientY-u.top;this.pointer.x=x/u.width*2-1,this.pointer.y=-(g/u.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const y=[];this.scene.children.forEach(f=>{f instanceof h.Group&&f.children.forEach(w=>{w instanceof h.Mesh&&y.push(w)})});const m=this.raycaster.intersectObjects(y,!1);if(m.length>0){const f=m[0].object;(n=this.pipe)==null||n.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs([f.userData.selectedID])}})}setHandlerPipe(t){this.pipe=t}initSegment(){this.store=new et(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new tt(v({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new it(S(v({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return v({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new h.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:a,near:c,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=c,this.camera.far=s,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new h.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new h.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return j.getColorFromConfig({attribute:t},S(v({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,a=10,c=e.x-i/2-a,s=e.x-i/2+a,d=e.y+r/2+a,p=e.y-r/2-a,o=100,n=-100,l=500/o;return{left:c,right:s,top:d,bottom:p,near:o,far:n,zoom:l}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:c,depth:s,rotation:d}=t,p=this.getCameraVector(r,d,{width:a,height:c,depth:s},e);return i?(this.updateCamera(i,r),new h.Vector3(i.x,i.y,i.z)):(this.updateCamera(p,r),p)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=L,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new h.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new h.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new h.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,a,c;if(!e){const s=this.scene.getObjectByName(this.pointCloudObjectName);if(!s)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array}if(window.Worker){const{zMin:s,zMax:d,polygonPointList:p}=I(t),o=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:d,polygonPointList:p,color:i,position:o};return new Promise(l=>{const u=new G;u.postMessage(n),u.onmessage=x=>{const{color:g,position:y,num:m}=x.data,f=new h.BufferGeometry;f.setAttribute("position",new h.Float32BufferAttribute(y,3)),f.setAttribute("color",new h.Float32BufferAttribute(g,3)),f.computeBoundingSphere(),u.terminate(),l({geometry:f,num:m})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,a=ct){let c=z.frontViewMatrix4(a);switch(r){case C.Front:break;case C.Back:c=z.backViewMatrix4(a);break;case C.Left:c=z.leftViewMatrix4(a);break;case C.Right:c=z.rightViewMatrix4(a);break;case C.Top:c=z.topViewMatrix4(a);break;case C.LFT:c=z.leftFrontTopViewMatrix4(a,i);break;case C.RBT:c=z.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),d=new h.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new h.Matrix4().makeTranslation(t.x,t.y,t.z),o=new h.Matrix4().makeRotationZ(e);return new h.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(d).applyMatrix4(o).applyMatrix4(p)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new h.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new h.BufferGeometry().setFromPoints(i),a=new h.LineBasicMaterial({color:16711680}),c=new h.Line(r,a);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new h.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return B(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,D.postMessage(t),D.onmessage=r=>{e(r.data),this.workerLoading=!1},D.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return B(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:c}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((d,p)=>{if(window.Worker){const n=(e?[...e]:[]).map(y=>I(y)),l=this.getAllAttributeColor(n),u=s.geometry.attributes.position.array,x=s.geometry.attributes.dimensions.array,g={cuboidList:n,position:u,color:x,colorList:l,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(g).then(y=>{const{color:m}=y;let f=m;(a.length||c.length)&&(f=m.map((M,P)=>M===-1?x[P]:M));const w=new h.BufferAttribute(f,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==m.length){p(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,f),this.highlightPCDSrc=void 0,w.needsUpdate=!0,s.geometry.setAttribute("dimensions",w),s.geometry.attributes.dimensions.needsUpdate=!0,d(f),this.render()}).catch(y=>{p(y)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new h.Group;t.forEach(i=>{const{center:{x:r,y:a,z:c},width:s,height:d,depth:p,rotation:o}=i,{fill:n}=j.getColorFromConfig({attribute:i.attribute},S(v({},this.config),{attributeConfigurable:!0}),{}),l=new h.BoxGeometry(s,d,p),u=new h.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});l.rotateZ(o),l.translate(r,a,c);const x=new h.Mesh(l,u);e.add(x);const g=new h.PlaneGeometry(p,d);g.rotateY(Math.PI/2),g.rotateZ(o);const y=new h.Vector3(s/2,0,0),m=new h.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(o);y.applyMatrix4(m),g.translate(r+y.x,a+y.y,c+y.z);const f=new h.MeshBasicMaterial({color:n,side:h.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new h.Mesh(g,f);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new h.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const a=Object.keys(t.subAttribute);return a.length===0||a.forEach(c=>{const s=i.find(n=>n.value===c);if(!s||!s.subSelected)return;const{key:d,subSelected:p}=s,o=p.find(n=>{var l;return n.value===((l=t.subAttribute)==null?void 0:l[c])});o&&(r&&(r+="\u3001"),r+=`${d}:${o.key}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const c=t.split(`
33
+ `),s=Math.max(...c.map(n=>i.measureText(n).width)),d=Math.ceil(s),p=a*1.5,o=p*c.length;e.width=d*r,e.height=o*r,e.style.width=`${d}px`,e.style.height=`${o}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.forEach((n,l)=>{i.fillText(n,0,l*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,l)=>n.z-l.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((n,l)=>n.x-l.x);const s=Math.floor(e.length*a),d=Math.floor(e.length*(1-a));e=e.slice(s,d),e.sort((n,l)=>n.y-l.y);const p=Math.floor(e.length*a),o=Math.floor(e.length*(1-a));return e=e.slice(p,o),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:p})=>{t.forEach((o,n)=>{const l=r[n+1],u=N.getFootOfPerpendicular({x:d,y:p},o,l,!1,!0).length;(!i[n]||u<i[n].distance)&&(i[n]={distance:u,point:{x:d,y:p}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],c=t.map((d,p)=>{const o=r[p],n=r[p+1],l=r[p+2];return U.getIntersectionBySlope({p1:a[p].point,line1:[o,n],p2:a[p+1].point,line2:[n,l]})});return c.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,a,c;const s=this.scene.children.find(g=>g.uuid===this.pointsUuid);let d=0,p=0,o=0,n=0,l=[],u=[];const x=((c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array)||[];for(let g=0;g<x.length;g+=3){const y=x[g],m=x[g+1],f=x[g+2];$({x:y,y:m},t)&&(f||f===0)&&u.push({x:y,y:m,z:f})}return u.length?(i&&(u=this.filterNoise(u),l=this.getFittedCoordinates(t,u)),u.sort((g,y)=>g.z-y.z),d=u[0].z-.01,p=u[u.length-1].z+.01,n=u.length,e&&(o=u.filter(({z:g})=>g>=e[0]&&g<=e[1]).length),{maxZ:p,minZ:d,count:o,zCount:n,fittedCoordinates:l}):{maxZ:p,minZ:d,count:o,zCount:n,fittedCoordinates:l}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new h.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new h.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r-s/2},p={x:e+c/2,y:i+a/2,z:r+s/2},o={x:e-c/2,y:i+a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r-s/2};return[d,p,o,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e-c/2,y:i+a/2,z:r+s/2},p={x:e-c/2,y:i+a/2,z:r-s/2},o={x:e-c/2,y:i-a/2,z:r-s/2},n={x:e-c/2,y:i-a/2,z:r+s/2};return[d,p,o,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:c,depth:s}=t,d={x:e+c/2,y:i+a/2,z:r+s/2},p={x:e+c/2,y:i-a/2,z:r+s/2},o={x:e-c/2,y:i-a/2,z:r+s/2},n={x:e-c/2,y:i+a/2,z:r+s/2};return[d,p,o,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new h.Matrix4().makeTranslation(-e,-i,-r),s=new h.Matrix4().makeTranslation(e,i,r),d=new h.Matrix4().makeRotationZ(a);return new h.Matrix4().multiply(s).multiply(d).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,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:a}=t,c=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new h.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const d=i.map(n=>new h.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,o=this.containerHeight/a;return{polygon2d:d,zoom:Math.min(p,o)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:c}=L,s={center:e,attribute:i,id:r,valid:a,width:c*2,height:c*2,depth:c*2,rotation:0},d=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),p=new h.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=p;const o=new h.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(c*2),l=this.containerHeight/(c*2);return{point2d:o,zoom:Math.min(n,l)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=L,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},a=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=this.getPolygonTopPoints(t).map(d=>new h.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),c=this.containerWidth/e,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(c,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new h.Matrix4().makeRotationZ(r.rotation),c=new h.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=S(v({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const a=new h.Matrix4().makeRotationZ(r.rotation),c=new h.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+c.x,y:s.center.y+c.y,z:s.center.z-t.z},s=S(v({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const c=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(y=>new h.Vector3(y.x,y.y,y.z)).map(y=>y.applyMatrix4(c)),[d,p,o,n]=s,l=Math.max(Math.abs(d.x-o.x),Math.abs(d.x-p.x)),x=p.add(n).applyMatrix3(new h.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new h.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new h.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:S(v({},r),{center:{x:r.center.x-x.x,y:r.center.y-x.y,z:r.center.z-i},width:l,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,a=[],{count:c}=r;for(let s=0;s<c;s++){const d=r.getZ(s);a.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new h.Float32BufferAttribute(a,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{lt as PointCloud};
@@ -1 +1 @@
1
- import{ImgPosUtils as j}from"@labelbee/lb-utils";import U from"lodash";import B from"color-rgba";import c from"../../utils/tool/DrawUtils.js";import _ from"../../utils/tool/AxisUtils.js";import V from"../../utils/tool/RectUtils.js";import $ from"../../utils/tool/PolygonUtils.js";import R from"../../utils/MathUtils.js";import G from"../../utils/tool/RenderDomClass.js";import{ELineTypes as L,DEFAULT_FONT as K,SEGMENT_NUMBER as F}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as N,TEXT_ATTRIBUTE_OFFSET as E,DEFAULT_TEXT_SHADOW as X}from"../../constant/annotation.js";import q,{cropAndEnlarge as Y}from"../../utils/ImgUtils.js";import J from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as Q}from"./basicToolOperation.js";import{pointCloudLidar2image as tt}from"../pointCloud/matrix.js";var et=Object.defineProperty,ot=Object.defineProperties,it=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,H=(x,t,e)=>t in x?et(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,m=(x,t)=>{for(var e in t||(t={}))nt.call(t,e)&&H(x,e,t[e]);if(Z)for(var e of Z(t))st.call(t,e)&&H(x,e,t[e]);return x},S=(x,t)=>ot(x,it(t)),rt=(x,t,e)=>new Promise((o,i)=>{var r=h=>{try{n(e.next(h))}catch(s){i(s)}},a=h=>{try{n(e.throw(h))}catch(s){i(s)}},n=h=>h.done?o(h.value):Promise.resolve(h.value).then(r,a);n((e=e.apply(x,t)).next())});const at=3,lt=3,M="#6371FF";class ct extends Q{constructor(t){super(S(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const a=this.getCoordinateUnderZoom(o),n=_.changePointByZoom(a,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 f=0;f<this.annotations.length;f++){const d=this.annotations[f];switch(d.type){case"rect":{const l=d.annotation;if(V.isInRect(a,l,at,this.zoom)){const u=l.width*l.height;u<s&&(h=l.id,s=u)}break}case"polygon":{const l=d.annotation;if($.isInPolygon(n,l.pointList)){const u=$.getPolygonArea(l.pointList);u<s&&(h=l.id,s=u)}break}}}return h};var e;this.style=(e=t.style)!=null?e:{stroke:M,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new G({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:a}=R.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},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=Y(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);q.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){return rt(this,null,function*(){if(!U.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}})}setConfig(t){this.config=t}getSpecificStyle(t){const e=U.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,a=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return S(m({},X),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+N.offsetX,y:e+N.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),(t==null?void 0:t.subAttributeText)&&(o+=t==null?void 0:t.subAttributeText),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=R.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=j.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(S(m({},r),{width:r.width/a*i.innerZoom,height:r.height/a*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=_.changePointByZoom(t,this.zoom,this.currentPos);c.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),c.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:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=L.Line}=n,s=_.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),f=S(m(m({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:r.stroke});let d=[];if(n.showKeyPoint?d=c.drawPolygonWithKeyPoint(this.canvas,s,f):d=c.drawPolygon(this.canvas,s,f),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let p=s[0],v=R.getLineCenterPoint([s[0],s[1]]);if(h===L.Curve){const g=Math.floor(F/2);p=d[g],v=d[g+1]}c.drawArrowByCanvas(this.canvas,p,v,{color:r.stroke,thickness:r.thickness}),c.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:u,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&c.drawText(this.canvas,this.appendOffset(s[0]),u,a),y){const p=s[s.length-1];c.drawText(this.canvas,this.appendOffset({x:p.x+E.x,y:p.y+E.y}),y,a)}}renderPolygon(t){var e,o,i,r,a;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:f=L.Line}=s,d=_.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=B((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:M),P=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;c.drawPolygonWithFill(this.canvas,d,{color:P,lineType:f})}const l=S(m(S(m({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:f,strokeColor:n.stroke});let u=[];if(s.showKeyPoint?u=c.drawPolygonWithKeyPoint(this.canvas,d,l):u=c.drawPolygon(this.canvas,d,l),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let g=d[0],P=R.getLineCenterPoint([d[0],d[1]]);if(f===L.Curve){const w=Math.floor(F/2);g=u[w],P=u[w+1]}c.drawArrowByCanvas(this.canvas,g,P,{color:n.stroke,thickness:n.thickness}),c.drawCircle(this.canvas,d[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:p,bottomText:v}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(p&&c.drawText(this.canvas,this.appendOffset(d[0]),p,h),v){const g=d[d.length-2];c.drawText(this.canvas,this.appendOffset({x:g.x+E.x,y:g.y+E.y}),v,h)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,a=B((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:M),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,h=i.stroke,s=_.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:f,bottomText:d}=this.getRenderText(r,r==null?void 0:r.hiddenText);c.drawCuboidWithText(this.canvas,s,{strokeColor:h,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:f,bottomText:d})}renderBox3d(t){var e;if(t.type!=="box3d")return;const o=t.annotation,{transferViewData:i}=(e=tt(o,o.calib))!=null?e:{};if(!i)return;const r={fill:"transparent"},a=U.pick(o,["stroke","thickness"]);i.forEach((n,h)=>{const s=m(S(m({},a),{id:`${t.annotation.id}-${h}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const 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+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){c.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:h}=J.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(o==null?void 0:o.length)>0&&(c.drawPixel({canvas:h,points:o,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),c.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,a,n,h,s;const f=this.getSpecificStyle(e.annotation),d=this.getFontStyle(e.annotation,f);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:u=!1,isReference:y,hiddenRectSize:p=!1}=l,{zoom:v}=this,g=_.changeRectByZoom(l,this.zoom,this.currentPos),{x:P,y:w,width:I,height:k}=g,b=B((i=(o=f==null?void 0:f.fill)!=null?o:f==null?void 0:f.stroke)!=null?i:M),C=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;(l.id===this.mouseHoverID||f.fill)&&c.drawRectWithFill(this.canvas,g,{color:C}),c.drawRect(this.canvas,g,m(S(m({},f),{hiddenText:!0}),this.getReferenceOptions(y))),(l==null?void 0:l.isHighlight)&&c.drawHighlightFlag({canvas:this.canvas,color:C,position:{x:P-16,y:w-16}});const{headerText:D,bottomText:T}=this.getRenderText(l,l==null?void 0:l.hiddenText);D&&c.drawText(this.canvas,{x:P,y:w-6},D,m({textMaxWidth:300},d));const O=`${Math.round(I/v)} * ${Math.round(k/v)}`,A=O.length*7;if(!u&&!p&&c.drawText(this.canvas,{x:P+I-A,y:w+k+15},O,d),T){const z=20,W=Math.max(20,I-A);c.drawText(this.canvas,{x:P,y:w+k+z},l.textAttribute,m({textMaxWidth:W},d))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,u=_.changePointByZoom(l,this.zoom,this.currentPos),y=(r=f.radius)!=null?r:lt;c.drawCircle(this.canvas,u,y,f);const{headerText:p,bottomText:v}=this.getRenderText(l,l==null?void 0:l.hiddenText);p&&c.drawText(this.canvas,{x:u.x+y/2,y:u.y-y-4},p,m({textAlign:"center"},d)),v&&c.drawText(this.canvas,this.appendOffset({x:u.x+y,y:u.y+y+24}),v,d);break}case"text":{const l=e.annotation,{text:u,x:y,y:p,textMaxWidth:v,color:g="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:w=25,font:I=K,position:k,offset:b}=l,C=10,D=10,T=_.changePointByZoom({x:y,y:p},this.zoom,this.currentPos);b&&(T.x+=(a=b.x)!=null?a:0,T.y+=(n=b.y)!=null?n:0);const{width:O,height:A,fontHeight:z=0}=R.getTextArea(this.canvas,l.text,v,I,w);if(k==="rt")break;c.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:O+D*2,height:A+C*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),c.drawText(this.canvas,{x:T.x+D,y:T.y+z+C},u,{color:g,lineHeight:w,font:I,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&&((s=(h=e.annotation).renderEnhance)==null||s.call(h,{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{ct as default};
1
+ import{ImgPosUtils as W}from"@labelbee/lb-utils";import B from"lodash";import H from"color-rgba";import h from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import G from"../../utils/tool/RectUtils.js";import D from"../../utils/tool/PolygonUtils.js";import L from"../../utils/MathUtils.js";import V from"../../utils/tool/RenderDomClass.js";import{ELineTypes as E,DEFAULT_FONT as K,SEGMENT_NUMBER as $}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as F,TEXT_ATTRIBUTE_OFFSET as U,DEFAULT_TEXT_SHADOW as X}from"../../constant/annotation.js";import q,{cropAndEnlarge as Y}from"../../utils/ImgUtils.js";import J from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as Q}from"./basicToolOperation.js";import{pointCloudLidar2image as tt}from"../pointCloud/matrix.js";var et=Object.defineProperty,ot=Object.defineProperties,it=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,Z=(x,t,e)=>t in x?et(x,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):x[t]=e,p=(x,t)=>{for(var e in t||(t={}))nt.call(t,e)&&Z(x,e,t[e]);if(N)for(var e of N(t))st.call(t,e)&&Z(x,e,t[e]);return x},_=(x,t)=>ot(x,it(t)),rt=(x,t,e)=>new Promise((o,i)=>{var r=l=>{try{n(e.next(l))}catch(s){i(s)}},a=l=>{try{n(e.throw(l))}catch(s){i(s)}},n=l=>l.done?o(l.value):Promise.resolve(l.value).then(r,a);n((e=e.apply(x,t)).next())});const at=3,lt=3,z="#6371FF";class ct extends Q{constructor(t){super(_(p({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.needUpdatePosition=!0,this.posTimer=null,this.convexHullGroup={},this.pointCloudBoxList=[],this.hiddenText=!1,this.getHoverRectID=o=>{var i,r;const a=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(a,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let l="",s=Number.MAX_SAFE_INTEGER;for(let u=0;u<this.annotations.length;u++){const c=this.annotations[u];switch(c.type){case"rect":{const d=c.annotation;if(G.isInRect(a,d,at,this.zoom)){const f=d.width*d.height;f<s&&(l=d.id,s=f)}break}case"polygon":{const d=c.annotation;if(D.isInPolygon(n,d.pointList)){const f=D.getPolygonArea(d.pointList);f<s&&(l=d.id,s=f)}break}}}return l};var e;this.style=(e=t.style)!=null?e:{stroke:z,thickness:3},this.annotations=t.annotations,this.convexHullGroup=D.createConvexHullGroup(t.annotations),this.loading=!1,this.renderDomInstance=new V({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:a}=L.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},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=Y(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);q.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}onRightClick(t){const e=this.getClickTargetId(t);!e||(this.needUpdatePosition=!1,this.posTimer&&clearTimeout(this.posTimer),this.emit("onRightClick",{event:t,targetId:e}),this.posTimer=setTimeout(()=>{this.needUpdatePosition=!0},1e3))}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){return rt(this,null,function*(){if(!B.isEqual(this.annotations,t)&&(this.annotations=t,this.convexHullGroup=D.createConvexHullGroup(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}})}setPointCloudBoxList(t){this.pointCloudBoxList=t}setHiddenText(t){this.hiddenText=t,this.render()}setConfig(t){this.config=t}getSpecificStyle(t){const e=B.pick(t,["stroke","thickness","fill","radius"]),o=p(p({},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,a=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(p({},X),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+F.offsetX,y:e+F.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),(t==null?void 0:t.subAttributeText)&&(o+=t==null?void 0:t.subAttributeText),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){if(!this.needUpdatePosition)return;const e=L.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=W.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(_(p({},r),{width:r.width/a*i.innerZoom,height:r.height/a*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"})})}renderAttribute(){B.chunk(this.annotations,6).forEach(e=>{var o,i;const r=e.find(c=>c.type==="polygon");if(!r)return;const{fontStyle:a}=this.getRenderStyle(r),n=r.annotation,l=(o=this.pointCloudBoxList)==null?void 0:o.find(c=>c.id===n.id),s=this.hiddenText?"":l==null?void 0:l.attribute,u=T.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos);s&&h.drawText(this.canvas,this.appendOffset(u[0]),s,a)})}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:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:l=E.Line}=n,s=T.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),u=_(p(p({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:l,strokeColor:r.stroke});let c=[];if(n.showKeyPoint?c=h.drawPolygonWithKeyPoint(this.canvas,s,u):c=h.drawPolygon(this.canvas,s,u),(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=L.getLineCenterPoint([s[0],s[1]]);if(l===E.Curve){const g=Math.floor($/2);v=c[g],m=c[g+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,a),y){const v=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:v.x+U.x,y:v.y+U.y}),y,a)}}renderPolygon(t){var e,o,i,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:l}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:u=E.Line}=s,c=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=H((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:z),P=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;h.drawPolygonWithFill(this.canvas,c,{color:P,lineType:u})}const d=_(p(_(p({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:u,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=h.drawPolygonWithKeyPoint(this.canvas,c,d):f=h.drawPolygon(this.canvas,c,d),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let g=c[0],P=L.getLineCenterPoint([c[0],c[1]]);if(u===E.Curve){const w=Math.floor($/2);g=f[w],P=f[w+1]}h.drawArrowByCanvas(this.canvas,g,P,{color:n.stroke,thickness:n.thickness}),h.drawCircle(this.canvas,c[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(c[0]),v,l),m){const g=c[c.length-2];h.drawText(this.canvas,this.appendOffset({x:g.x+U.x,y:g.y+U.y}),m,l)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,a=H((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:z),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,l=i.stroke,s=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:u,bottomText:c}=this.getRenderText(r,r==null?void 0:r.hiddenText);h.drawCuboidWithText(this.canvas,s,{strokeColor:l,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:u,bottomText:c})}renderBox3d(t){var e;if(t.type!=="box3d")return;const o=t.annotation,{transferViewData:i}=(e=tt(o,o.calib))!=null?e:{};if(!i)return;const r={fill:"transparent"},a=B.pick(o,["stroke","thickness"]);i.forEach((n,l)=>{const s=p(_(p({},a),{id:`${t.annotation.id}-${l}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const 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+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){h.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:l}=J.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(o==null?void 0:o.length)>0&&(h.drawPixel({canvas:l,points:o,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),h.drawImg(this.canvas,l,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:l})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,a,n,l,s;const u=this.getSpecificStyle(e.annotation),c=this.getFontStyle(e.annotation,u);switch(e.type){case"rect":{const d=e.annotation,{hiddenText:f=!1,isReference:y,hiddenRectSize:v=!1}=d,{zoom:m}=this,g=T.changeRectByZoom(d,this.zoom,this.currentPos),{x:P,y:w,width:k,height:S}=g,b=H((i=(o=u==null?void 0:u.fill)!=null?o:u==null?void 0:u.stroke)!=null?i:z),I=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;(d.id===this.mouseHoverID||u.fill)&&h.drawRectWithFill(this.canvas,g,{color:I}),h.drawRect(this.canvas,g,p(_(p({},u),{hiddenText:!0}),this.getReferenceOptions(y))),(d==null?void 0:d.isHighlight)&&h.drawHighlightFlag({canvas:this.canvas,color:I,position:{x:P-16,y:w-16}});const{headerText:R,bottomText:C}=this.getRenderText(d,d==null?void 0:d.hiddenText);R&&h.drawText(this.canvas,{x:P,y:w-6},R,p({textMaxWidth:300},c));const O=`${Math.round(k/m)} * ${Math.round(S/m)}`,A=O.length*7;if(!f&&!v&&h.drawText(this.canvas,{x:P+k-A,y:w+S+15},O,c),C){const M=20,j=Math.max(20,k-A);h.drawText(this.canvas,{x:P,y:w+S+M},d.textAttribute,p({textMaxWidth:j},c))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const d=e.annotation,f=T.changePointByZoom(d,this.zoom,this.currentPos),y=(r=u.radius)!=null?r:lt;h.drawCircle(this.canvas,f,y,u);const{headerText:v,bottomText:m}=this.getRenderText(d,d==null?void 0:d.hiddenText);v&&h.drawText(this.canvas,{x:f.x+y/2,y:f.y-y-4},v,p({textAlign:"center"},c)),m&&h.drawText(this.canvas,this.appendOffset({x:f.x+y,y:f.y+y+24}),m,c);break}case"text":{const d=e.annotation,{text:f,x:y,y:v,textMaxWidth:m,color:g="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:w=25,font:k=K,position:S,offset:b}=d,I=10,R=10,C=T.changePointByZoom({x:y,y:v},this.zoom,this.currentPos);b&&(C.x+=(a=b.x)!=null?a:0,C.y+=(n=b.y)!=null?n:0);const{width:O,height:A,fontHeight:M=0}=L.getTextArea(this.canvas,d.text,m,k,w);if(S==="rt")break;h.drawRectWithFill(this.canvas,{x:C.x,y:C.y,width:O+R*2,height:A+I*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),h.drawText(this.canvas,{x:C.x+R,y:C.y+M+I},f,{color:g,lineHeight:w,font:k,textMaxWidth:m});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(l=e.annotation).renderEnhance)==null||s.call(l,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints(),this.renderAttribute()}catch(t){console.error("ViewOperation Render Error",t)}}getClickTargetId(t){const e=this.getCoordinateUnderZoom(t),o=T.changePointByZoom(e,1/this.zoom);for(const i in this.convexHullGroup){if(!Object.prototype.hasOwnProperty.call(this.convexHullGroup,i))continue;const r=this.convexHullGroup[i].convexHull;if(D.isInPolygon(o,r))return i}}}export{ct as default};