@labelbee/lb-annotation 1.27.0-alpha.6 → 1.27.0-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/highlightWorker.js +1 -1
- package/dist/constant/keyCode.js +1 -1
- package/dist/core/pointCloud/OrbitControls.js +1 -1
- package/dist/core/pointCloud/index.js +4 -2
- package/dist/core/pointCloud/matrix.js +1 -1
- package/dist/core/pointCloud/omniCamera.js +1 -1
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/dist/core/toolOperation/basicToolOperation.js +1 -1
- package/dist/core/toolOperation/pointCloud2DRectOperation.js +1 -1
- package/dist/core/toolOperation/pointOperation.js +1 -1
- package/dist/core/toolOperation/polygonOperation.js +1 -1
- package/dist/core/toolOperation/rectOperation.js +2 -1
- package/dist/core/toolOperation/utils/reCalcRect.js +1 -0
- package/dist/types/constant/keyCode.d.ts +1 -0
- package/dist/types/core/pointCloud/index.d.ts +47 -3
- package/dist/types/core/toolOperation/ViewOperation.d.ts +18 -1
- package/dist/types/core/toolOperation/basicToolOperation.d.ts +1 -0
- package/dist/types/core/toolOperation/pointCloud2DRectOperation.d.ts +14 -3
- package/dist/types/core/toolOperation/pointOperation.d.ts +4 -0
- package/dist/types/core/toolOperation/polygonOperation.d.ts +2 -0
- package/dist/types/core/toolOperation/rectOperation.d.ts +22 -5
- package/dist/types/core/toolOperation/utils/reCalcRect.d.ts +9 -0
- package/dist/types/utils/tool/AxisUtils.d.ts +4 -0
- package/dist/types/utils/tool/PolygonUtils.d.ts +13 -0
- package/dist/types/utils/tool/RectUtils.d.ts +4 -0
- package/dist/utils/tool/PolygonUtils.js +1 -1
- package/es/_virtual/highlightWorker.js +1 -1
- package/es/constant/keyCode.js +1 -1
- package/es/core/pointCloud/OrbitControls.js +1 -1
- package/es/core/pointCloud/index.js +4 -2
- package/es/core/pointCloud/matrix.js +1 -1
- package/es/core/pointCloud/omniCamera.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/basicToolOperation.js +1 -1
- package/es/core/toolOperation/pointCloud2DRectOperation.js +1 -1
- package/es/core/toolOperation/pointOperation.js +1 -1
- package/es/core/toolOperation/polygonOperation.js +1 -1
- package/es/core/toolOperation/rectOperation.js +2 -1
- package/es/core/toolOperation/utils/reCalcRect.js +1 -0
- package/es/utils/tool/PolygonUtils.js +1 -1
- package/package.json +2 -2
|
@@ -10,6 +10,7 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
10
10
|
firstCurrentPos?: ICoordinate;
|
|
11
11
|
rectList: IRect[];
|
|
12
12
|
hoverRectID?: string;
|
|
13
|
+
selectedRectTextAttribute: string;
|
|
13
14
|
hoverRectPointIndex: number;
|
|
14
15
|
hoverRectEdgeIndex: number;
|
|
15
16
|
isFlow: boolean;
|
|
@@ -20,6 +21,9 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
20
21
|
private selection;
|
|
21
22
|
private dragInfo?;
|
|
22
23
|
private highlightVisible;
|
|
24
|
+
/** Whether or not add rect */
|
|
25
|
+
private enableAddRect;
|
|
26
|
+
renderPointCloud2DHighlight(): void;
|
|
23
27
|
constructor(props: IRectOperationProps);
|
|
24
28
|
setResult(rectList: IRect[]): void;
|
|
25
29
|
destroy(): void;
|
|
@@ -72,7 +76,12 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
72
76
|
setMarkerIndexAndSelect: (markerIndex: number) => void;
|
|
73
77
|
/** 更新文本输入,并且进行关闭 */
|
|
74
78
|
updateSelectedRectTextAttribute(newTextAttribute?: string): void;
|
|
79
|
+
updateSelectedRectSubAttribute(key: string, value: string): void;
|
|
75
80
|
getHoverRectID: (e: MouseEvent) => string;
|
|
81
|
+
/**
|
|
82
|
+
* 获取当前选中rect的文本
|
|
83
|
+
*/
|
|
84
|
+
getSelectedRectTextAttribute: (hoverRectID: string) => string;
|
|
76
85
|
/**
|
|
77
86
|
* 获取当前的选中部分的hoverIndex
|
|
78
87
|
* ../../../param e
|
|
@@ -99,6 +108,10 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
99
108
|
disableDelete?: boolean | undefined;
|
|
100
109
|
isHighlight?: boolean | undefined;
|
|
101
110
|
label?: string | undefined;
|
|
111
|
+
lineDash?: number[] | undefined;
|
|
112
|
+
subAttribute?: {
|
|
113
|
+
[key: string]: string;
|
|
114
|
+
} | undefined;
|
|
102
115
|
};
|
|
103
116
|
getRectsBoundaries(rects: IRect[], offset: ICoordinate): {
|
|
104
117
|
top: number;
|
|
@@ -129,6 +142,7 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
129
142
|
setAttributeLockList(attributeLockList: string[]): void;
|
|
130
143
|
setBasicResult(basicResult: any): void;
|
|
131
144
|
setRectValidAndRender(id: string): void;
|
|
145
|
+
setDefaultSubAttribute: () => void;
|
|
132
146
|
createNewDrawingRect(e: MouseEvent, basicSourceID: string): void;
|
|
133
147
|
/**
|
|
134
148
|
* 将绘制中的框体添加进 rectList 中
|
|
@@ -141,12 +155,14 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
141
155
|
* mouseup 下的鼠标右键
|
|
142
156
|
* @param e
|
|
143
157
|
*/
|
|
144
|
-
rightMouseUp(e: MouseEvent):
|
|
158
|
+
rightMouseUp(e: MouseEvent): IRect | undefined;
|
|
145
159
|
shiftRightMouseUp(e: MouseEvent): void;
|
|
146
160
|
updateDragResult(): void;
|
|
161
|
+
/** Allow/Disallow to add rect to rectList */
|
|
162
|
+
setEnableAddRect(isEnableAddRect: boolean): void;
|
|
147
163
|
onMouseUp(e: MouseEvent): true | undefined;
|
|
148
164
|
onRightDblClick(e: MouseEvent): void;
|
|
149
|
-
deleteSelectedRect(): void;
|
|
165
|
+
deleteSelectedRect(e: UIEvent): void;
|
|
150
166
|
onKeyDown(e: KeyboardEvent): true | undefined;
|
|
151
167
|
onKeyUp(e: KeyboardEvent): void;
|
|
152
168
|
onWheel(e: MouseEvent): void;
|
|
@@ -172,10 +188,10 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
172
188
|
/**
|
|
173
189
|
* 绘制当前框的
|
|
174
190
|
* @param rect 当前矩形框
|
|
175
|
-
* @param zoom
|
|
176
|
-
* @param isZoom
|
|
191
|
+
* @param zoom 缩放比例
|
|
192
|
+
* @param isZoom 是否进行缩放
|
|
177
193
|
*/
|
|
178
|
-
renderDrawingRect(rect: IRect, zoom?: number, isZoom?: boolean): void;
|
|
194
|
+
renderDrawingRect(rect: IRect, zoom?: number, isZoom?: boolean, isPointCloud2DHighlight?: boolean): void;
|
|
179
195
|
/**
|
|
180
196
|
* 渲染静态框体
|
|
181
197
|
*/
|
|
@@ -192,6 +208,7 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
192
208
|
render(): void;
|
|
193
209
|
setDefaultAttribute(defaultAttribute?: string): void;
|
|
194
210
|
setValid(valid: boolean): void;
|
|
211
|
+
private clearDrawingStatus;
|
|
195
212
|
/**
|
|
196
213
|
* 清楚所有的中间状态
|
|
197
214
|
*/
|
|
@@ -35,6 +35,10 @@ export default class AxisUtils {
|
|
|
35
35
|
disableDelete?: boolean | undefined;
|
|
36
36
|
isHighlight?: boolean | undefined;
|
|
37
37
|
label?: string | undefined;
|
|
38
|
+
lineDash?: number[] | undefined;
|
|
39
|
+
subAttribute?: {
|
|
40
|
+
[key: string]: string;
|
|
41
|
+
} | undefined;
|
|
38
42
|
};
|
|
39
43
|
/**
|
|
40
44
|
* 计算点在 zoom 和 currentPos 的转换
|
|
@@ -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[];
|
|
@@ -13,6 +20,7 @@ export default class PolygonUtils {
|
|
|
13
20
|
*/
|
|
14
21
|
static calcPolygonSize(pointList?: IPolygonPoint[]): number;
|
|
15
22
|
static isInPolygon(checkPoint: IPolygonPoint, polygonPoints: (IPolygonPoint | ICoordinate)[], lineType?: ELineTypes): boolean;
|
|
23
|
+
static isPointInOrOnPolygon(point: IPolygonPoint, polygonData: (IPolygonPoint | ICoordinate)[], errorMargin?: number): boolean;
|
|
16
24
|
/**
|
|
17
25
|
* 通过数据转换为平滑曲线的点提交 [{x: number, y: number}...] => [x, ...smoothCurvePoints ,y]
|
|
18
26
|
* @param pointList
|
|
@@ -129,4 +137,9 @@ export default class PolygonUtils {
|
|
|
129
137
|
* @param polygonList
|
|
130
138
|
*/
|
|
131
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;
|
|
132
145
|
}
|
|
@@ -59,6 +59,10 @@ export default class RectUtils {
|
|
|
59
59
|
disableDelete?: boolean | undefined;
|
|
60
60
|
isHighlight?: boolean | undefined;
|
|
61
61
|
label?: string | undefined;
|
|
62
|
+
lineDash?: number[] | undefined;
|
|
63
|
+
subAttribute?: {
|
|
64
|
+
[key: string]: string;
|
|
65
|
+
} | undefined;
|
|
62
66
|
};
|
|
63
67
|
/**
|
|
64
68
|
* 判断当前矩形是否不在多边形内
|
|
@@ -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=(
|
|
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{createBase64WorkerFactory as b}from"./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js";var
|
|
1
|
+
import{createBase64WorkerFactory as b}from"./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js";var l=b("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwp2YXIgd29ya2VyX2NvZGU9ZnVuY3Rpb24ocCl7InVzZSBzdHJpY3QiO2NvbnN0IHY9Wy0xLC0xLC0xXTtsZXQgST0hMTtmdW5jdGlvbiBCKGUpe2NvbnN0IHQ9LTcsbz0zLG49by10O3JldHVybiBlPHQmJihlPXQpLGU+byYmKGU9byksTWF0aC5mbG9vcigoZS10KS9uKjI1NSl9ZnVuY3Rpb24gRSgpe2xldCBlO2NvbnN0IHQ9bmV3IEFycmF5KDI1NikuZmlsbCgiIikubWFwKCgpPT5uZXcgQXJyYXkoMykuZmlsbCgiIikpO2ZvcihsZXQgbz0wO288MjA7bysrKXtmb3IoZT0wO2U8MzI7ZSsrKXRbZV1bMF09MTI4KzQqZSx0W2VdWzFdPTAsdFtlXVsyXT0wO2Zvcih0WzMyXVswXT0yNTUsdFszMl1bMV09MCx0WzMyXVsyXT0wLGU9MDtlPDYzO2UrKyl0WzMzK2VdWzBdPTI1NSx0WzMzK2VdWzFdPTQrNCplLHRbMzMrZV1bMl09MDtmb3IodFs5Nl1bMF09MjU0LHRbOTZdWzFdPTI1NSx0Wzk2XVsyXT0yLGU9MDtlPDYyO2UrKyl0Wzk3K2VdWzBdPTI1MC00KmUsdFs5NytlXVsxXT0yNTUsdFs5NytlXVsyXT02KzQqZTtmb3IodFsxNTldWzBdPTEsdFsxNTldWzFdPTI1NSx0WzE1OV1bMl09MjU0LGU9MDtlPDY0O2UrKyl0WzE2MCtlXVswXT0wLHRbMTYwK2VdWzFdPTI1Mi1lKjQsdFsxNjArZV1bMl09MjU1O2ZvcihlPTA7ZTwzMjtlKyspdFsyMjQrZV1bMF09MCx0WzIyNCtlXVsxXT0wLHRbMjI0K2VdWzJdPTI1Mi00KmV9cmV0dXJuIHR9Y29uc3QgUj1FKCk7ZnVuY3Rpb24gaChlLHQsbz0wKXtsZXQgbj0wLGEseCxpLGw7dD1bLi4udF0sbz09PTEmJih0PWNyZWF0ZVNtb290aEN1cnZlUG9pbnRzKHQucmVkdWNlKCh5LGMpPT5bLi4ueSxjLngsYy55XSxbXSksLjUsITAsU0VHTUVOVF9OVU1CRVIpKSxbaV09dDtjb25zdCB1PXQubGVuZ3RoO2ZvcihhPTE7YTw9dTthKyspbD10W2EldV0sZS54Pk1hdGgubWluKGkueCxsLngpJiZlLng8PU1hdGgubWF4KGkueCxsLngpJiZlLnk8PU1hdGgubWF4KGkueSxsLnkpJiZpLnghPT1sLngmJih4PShlLngtaS54KSoobC55LWkueSkvKGwueC1pLngpK2kueSwoaS55PT09bC55fHxlLnk8PXgpJiZuKyspLGk9bDtyZXR1cm4gbiUyIT0wfWZ1bmN0aW9uIE8oe3pNaW46ZSx6TWF4OnQscG9seWdvblBvaW50TGlzdDpvLGF0dHJpYnV0ZTpuLHg6YSx5OngsejppLGNvbG9yTGlzdDpsLHZhbGlkOnV9KXtpZihoKHt4OmEseTp4fSxvKSYmaT49ZSYmaTw9dClyZXR1cm4gdT09PSExP1sxLDEwMy8yNTUsMTAyLzI1NV06bFtuXT9sW25dLnJnYmEuc2xpY2UoMCwzKS5tYXAoYz0+Yy8yNTUpOlsxLDAsMF19ZnVuY3Rpb24gbShlKXtjb25zdCB0PUIoZSksbz1SW3RdLFtuLGEseF09bztyZXR1cm5bbi8yNTUsYS8yNTUseC8yNTVdfXJldHVybiBvbm1lc3NhZ2U9ZnVuY3Rpb24odCl7Y29uc3R7cG9zaXRpb246byxjb2xvcjpuLGN1Ym9pZExpc3Q6YSxjb2xvckxpc3Q6eCxoaWdobGlnaHRJbmRleDppfT10LmRhdGE7bGV0e21vZGlmaWVkQm94SWRzOmw9W10scmVzZXRBcmVhczp1PVtdfT10LmRhdGEseT0wO2Z1bmN0aW9uIGMoKXt5Kz0xfWlmKCFvKXJldHVybjtjb25zdCBfPSEhKGk9PW51bGw/dm9pZCAwOmkubGVuZ3RoKTsoX3x8SSkmJihsPVtdLHU9W10pO2NvbnN0IHc9bC5sZW5ndGg/YS5maWx0ZXIocj0+bC5pbmNsdWRlcyhyLmlkKSk6YTtmb3IobGV0IHI9MDtyPG8ubGVuZ3RoO3IrPTMpe2NvbnN0IEM9b1tyXSxMPW9bcisxXSxkPW9bcisyXTtsZXQgZztpZih1Lmxlbmd0aD09PTEmJiFsLmxlbmd0aCloKHt4OkMseTpMfSx1WzBdKT9nPW0oZCk6Zz12O2Vsc2UgaWYodS5sZW5ndGh8fGwubGVuZ3RoKXtsZXQgcz0hMTt3LnNvbWUoZj0+e2NvbnN0IE09Tyh7cG9seWdvblBvaW50TGlzdDpmLnBvbHlnb25Qb2ludExpc3Qsek1pbjpmLnpNaW4sek1heDpmLnpNYXgseDpDLHk6TCx6OmQsYXR0cmlidXRlOmYuYXR0cmlidXRlLGNvbG9yTGlzdDp4LHZhbGlkOmYudmFsaWR9KTtyZXR1cm4gTT8oYygpLGc9TSxzPSEwLCEwKTohMX0pLCFzJiZ1Lmxlbmd0aCYmKHM9dS5zb21lKGY9Pmgoe3g6Qyx5Okx9LGYpPyhnPW0oZCksITApOiExKSksIXMmJiFfJiYoST9nPW0oZCk6Zz12KX1lbHNlIHcuc29tZShzPT57Y29uc3QgZj1PKHtwb2x5Z29uUG9pbnRMaXN0OnMucG9seWdvblBvaW50TGlzdCx6TWluOnMuek1pbix6TWF4OnMuek1heCx4OkMseTpMLHo6ZCxhdHRyaWJ1dGU6cy5hdHRyaWJ1dGUsY29sb3JMaXN0OngsdmFsaWQ6cy52YWxpZH0pO3JldHVybiBmPyhjKCksZz1mLCEwKTohMX0pO2NvbnN0IEE9cz0+e2NvbnN0IGY9TWF0aC5mbG9vcihzLzMpO3JldHVybiBpJiZpW2ZdPT09MX07aWYoZylpZihnWzBdPT09dlswXSYmQShyKSluW3JdPTAsbltyKzFdPTAsbltyKzJdPTA7ZWxzZXtjb25zdFtzLGYsTV09ZztuW3JdPXMsbltyKzFdPWYsbltyKzJdPU19ZWxzZSBpZihBKHIpKW5bcl09MCxuW3IrMV09MCxuW3IrMl09MDtlbHNle2NvbnN0W3MsZixNXT1tKGQpO25bcl09cyxuW3IrMV09ZixuW3IrMl09TX19ST1fLHBvc3RNZXNzYWdlKHtwb2ludHM6byxjb2xvcjpuLG51bTp5fSl9LHAuaXNJblBvbHlnb249aCxPYmplY3QuZGVmaW5lUHJvcGVydHkocCwiX19lc01vZHVsZSIse3ZhbHVlOiEwfSkscH0oe30pOwoK",null,!1);export{l as default};
|
package/es/constant/keyCode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace",t[t.Minus=189]="Minus",t[t.Equal=187]="Equal"})(a||(a={}));var n=a;export{n as default};
|
|
1
|
+
var a;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.P=80]="P",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace",t[t.Minus=189]="Minus",t[t.Equal=187]="Equal"})(a||(a={}));var n=a;export{n as default};
|
|
@@ -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
|
|
1
|
+
import*as h from"three";import{toolStyleConverter as j,PerspectiveShiftUtils as z,EPerspectiveView as M,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 E from"../../utils/MathUtils.js";import Y from"../../utils/ImgUtils.js";import{PCDLoader as K}from"./PCDLoader.js";import{OrbitControls as X}from"./OrbitControls.js";import{PointCloudCache as q}from"./cache.js";import{getCuboidFromPointCloudBox as 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,N=Object.getOwnPropertySymbols,at=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,F=(C,t,e)=>t in C?nt(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,v=(C,t)=>{for(var e in t||(t={}))at.call(t,e)&&F(C,e,t[e]);if(N)for(var e of N(t))ht.call(t,e)&&F(C,e,t[e]);return C},S=(C,t)=>ot(C,st(t)),B=(C,t,e)=>new Promise((i,r)=>{var a=d=>{try{s(e.next(d))}catch(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(C,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=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,o="blue")=>{var l;const u=(l=n.id)!=null?l:_();this.removeObjectByName(u,"sphere");const{radius:f,widthSegments:m,heightSegments:x}=L,{center:g}=n,y=new h.Group,w=new h.SphereGeometry(f,m,x),b=new h.MeshBasicMaterial({color:o}),P=new h.Mesh(w,b);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${u}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:o}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,o),this.render()},this.generateSpheres=n=>{n.forEach(o=>{const{fill:l}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,l)}),this.render()},this.addBoxToSense=(n,o=16777215)=>{var l;const u=(l=n.id)!=null?l:_();this.removeObjectByName(u,"box");const{center:f,width:m,height:x,depth:g,rotation:y}=n,w=new h.Group,b=new h.BoxGeometry(m,x,g),P=new h.MeshBasicMaterial({color:"blue"}),O=new h.Mesh(b,P),V=new h.BoxHelper(O,o),R=this.generateBoxArrow(n),T=this.generateBoxTrackID(n);T&&w.add(T);const A=this.generateBoxAttributeLabel(n);A&&w.add(A),w.add(V),w.add(R),f&&w.position.set(f.x,f.y,f.z),y&&w.rotation.set(0,0,y),w.name=`box${u}`;const H=new h.BoxGeometry(m,x,g),W=new h.MeshBasicMaterial({visible:!1}),k=new h.Mesh(H,W);k.userData={selectedID:u},w.add(k),this.scene.add(w)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const o=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,o)}},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 L,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)=>S(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:u,color:m}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(u,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(m,3)),this.initCloudData(u);const p=new a.Points(f);this.renderPointCloud(p,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>S(this,[n],function*({mappingImgList:l,points:c}){const u=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),m=l.map((p,g)=>{var x;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(x=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?x:[];const y=$({points:c,calib:p.calib,width:u[g].width,height:u[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,y),y});return Y(m)}),this.filterPreResult=(n,l,c)=>S(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),m=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(f=>{const p=c.map(g=>{const x=A.calculatePointsInsideBox({indexMap:m,polygon:D(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),y=x>=l.lowerLimitPointsNumInBox;return P(b({},g),{valid:y,count:x})});f(p)})}),this.loadPCDFileByBox=(n,l,c)=>S(this,null,function*(){const u=(p,g)=>S(this,null,function*(){const{width:x=0,height:y=0,depth:M=0}=c!=null?c:{},v=yield this.filterPointsByBox(P(b({},l),{width:l.width+x,height:l.height+y,depth:l.depth+M}),p,g);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const z=new a.Points(v.geometry);z.name=this.pointCloudObjectName,this.scene.add(z),this.render()}),{points:m,color:f}=yield this.cacheInstance.loadPCDFile(n);u(m,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),u=2,m=16776960,f=new a.ArrowHelper(l,c,u,m);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),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=o,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,s?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),s===!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(b({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(P(b({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 b({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:o,near:h,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=o,this.camera.near=h,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 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 L.getColorFromConfig({attribute:t},P(b({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,o=10,h=e.x-i/2-o,s=e.x-i/2+o,d=e.y+r/2+o,n=e.y-r/2-o,l=100,c=-100,u=500/l;return{left:h,right:s,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:o,height:h,depth:s,rotation:d}=t,n=this.getCameraVector(r,d,{width:o,height:h,depth:s},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,o=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(o,i),o}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,o,h;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=(h=(o=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array}if(window.Worker){const{zMin:s,zMax:d,polygonPointList:n}=D(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:s,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(u=>{const m=new R;m.postMessage(c),m.onmessage=f=>{const{color:p,position:g,num:x}=f.data,y=new a.BufferGeometry;y.setAttribute("position",new a.Float32BufferAttribute(g,3)),y.setAttribute("color",new a.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),m.terminate(),u({geometry:y,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,o=nt){let h=B.frontViewMatrix4(o);switch(r){case C.Front:break;case C.Back:h=B.backViewMatrix4(o);break;case C.Left:h=B.leftViewMatrix4(o);break;case C.Right:h=B.rightViewMatrix4(o);break;case C.Top:h=B.topViewMatrix4(o);break;case C.LFT:h=B.leftFrontTopViewMatrix4(o,i);break;case C.RBT:h=B.rightBackTopViewMatrix4(o,i);break}const s=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(s).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),o=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,o);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],o=t[e+2];this.store.cloudData.set(`${i}@${r}@${o}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return S(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("workerLoading"));return}this.workerLoading=!0,I.postMessage(t),I.onmessage=r=>{e(r.data),this.workerLoading=!1},I.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return S(this,arguments,function*(e,i=[]){const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!!r)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((o,h)=>{if(window.Worker){const d=(e?[...e]:[]).map(c=>D(c)),n=this.getAllAttributeColor(d),l={cuboidList:d,position:r.geometry.attributes.position.array,color:r.geometry.attributes.dimensions.array,colorList:n,highlightIndex:i};this.handleWebworker(l).then(c=>{const{color:u}=c,m=new a.BufferAttribute(u,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||r.geometry.attributes.position.array.length!==u.length){h(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,u),this.highlightPCDSrc=void 0,m.needsUpdate=!0,r.geometry.setAttribute("dimensions",m),r.geometry.attributes.dimensions.needsUpdate=!0,o(u),this.render()}).catch(c=>{h(c)})}})})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:o,z:h},width:s,height:d,depth:n,rotation:l}=i,{fill:c}=L.getColorFromConfig({attribute:i.attribute},P(b({},this.config),{attributeConfigurable:!0}),{}),u=new a.BoxGeometry(s,d,n),m=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});u.rotateZ(l),u.translate(r,o,h);const f=new a.Mesh(u,m);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(s/2,0,0),x=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(x),p.translate(r+g.x,o+g.y,h+g.z);const y=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,y);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((c,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 o=.005,h=Math.floor(e.length*(1-o));e=e.slice(0,h),e.sort((c,u)=>c.x-u.x);const s=Math.floor(e.length*o),d=Math.floor(e.length*(1-o));e=e.slice(s,d),e.sort((c,u)=>c.y-u.y);const n=Math.floor(e.length*o),l=Math.floor(e.length*(1-o));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],m=A.getFootOfPerpendicular({x:d,y:n},l,u,!1,!0).length;(!i[c]||m<i[c].distance)&&(i[c]={distance:m,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const o=[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:o[n].point,line1:[l,c],p2:o[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,o,h;const s=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,u=[],m=[];const f=((h=(o=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:o.position)==null?void 0:h.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],x=f[p+1],y=f[p+2];H({x:g,y:x},t)&&(y||y===0)&&m.push({x:g,y:x,z:y})}return m.length?(i&&(m=this.filterNoise(m),u=this.getFittedCoordinates(t,m)),m.sort((p,g)=>p.z-g.z),d=m[0].z-.01,n=m[m.length-1].z+.01,c=m.length,e&&(l=m.filter(({z:p})=>p>=e[0]&&p<=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:o,width:h,depth:s}=t,d={x:e+h/2,y:i+o/2,z:r-s/2},n={x:e+h/2,y:i+o/2,z:r+s/2},l={x:e-h/2,y:i+o/2,z:r+s/2},c={x:e-h/2,y:i+o/2,z:r-s/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:s}=t,d={x:e-h/2,y:i+o/2,z:r+s/2},n={x:e-h/2,y:i+o/2,z:r-s/2},l={x:e-h/2,y:i-o/2,z:r-s/2},c={x:e-h/2,y:i-o/2,z:r+s/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:o,width:h,depth:s}=t,d={x:e+h/2,y:i+o/2,z:r+s/2},n={x:e+h/2,y:i-o/2,z:r+s/2},l={x:e-h/2,y:i-o/2,z:r+s/2},c={x:e-h/2,y:i+o/2,z:r+s/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:o}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),s=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(o);return new a.Matrix4().multiply(s).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:o}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;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/o;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:o}=t,{radius:h}=O,s={center:e,attribute:i,id:r,valid:o,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(s)).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)},o=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(o,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,o=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,s=this.containerHeight/i;return{polygon2d:o,zoom:Math.min(h,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(o);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=P(b({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const o=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(o);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=P(b({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var o;const h=(o=this.sideMatrix)==null?void 0:o.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[d,n,l,c]=s,u=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:P(b({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:u,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,o=[],{count:h}=r;for(let s=0;s<h;s++){const d=r.getZ(s);o.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(o,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
|
|
31
|
+
}`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>B(this,[...n],function*(o=this.currentPCDSrc,l){if(!o)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=o;const{points:u,color:f}=yield this.cacheInstance.loadPCDFile(o),m=new h.BufferGeometry;m.setAttribute("position",new h.BufferAttribute(u,3)),this.isSegment||m.setAttribute("dimensions",new h.BufferAttribute(f,3)),this.initCloudData(u);const x=new h.Points(m);this.renderPointCloud(x,l),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>B(this,[n],function*({mappingImgList:o,points:l}){const u=g=>B(this,null,function*(){try{return yield Y.load(g)}catch(y){return console.error("Error loading image:",y),null}}),f=o.length===0?[]:(yield Promise.all(o.map(g=>B(this,null,function*(){let y=yield u(g.url);return!y&&g.fallbackUrl&&(y=yield u(g.fallbackUrl)),y})))).filter(g=>g!==null),m=o.map((g,y)=>{var w;if(this.cacheInstance.cache2DHighlightIndex.has(g.url))return(w=this.cacheInstance.cache2DHighlightIndex.get(g.url))!=null?w:[];const b=Q({points:l,calib:g.calib,width:f[y].width,height:f[y].height});return this.cacheInstance.cache2DHighlightIndex.set(g.url,b),b});return J(m)}),this.filterPreResult=(n,o,l)=>B(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),f=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(m=>{const x=l.map(g=>{const y=E.calculatePointsInsideBox({indexMap:f,polygon:I(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),w=y>=o.lowerLimitPointsNumInBox;return S(v({},g),{valid:w,count:y})});m(x)})}),this.loadPCDFileByBox=(n,o,l)=>B(this,null,function*(){const u=(x,g)=>B(this,null,function*(){const{width:y=0,height:w=0,depth:b=0}=l!=null?l:{},P=yield this.filterPointsByBox(S(v({},o),{width:o.width+y,height:o.height+w,depth:o.depth+b}),x,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const O=new h.Points(P.geometry);O.name=this.pointCloudObjectName,this.scene.add(O),this.render()}),{points:f,color:m}=yield this.cacheInstance.loadPCDFile(n);u(f,m)}),this.generateRange=n=>{const o=this.createRange(n);this.scene.add(o)},this.generateBoxArrow=({width:n})=>{const o=new h.Vector3(1,0,0),l=new h.Vector3(n/2,0,0),u=2,f=16776960,m=new h.ArrowHelper(o,l,u,f);return m.visible=this.showDirection,m},this.generateLabel=(n,o)=>{const l=this.getTextCanvas(n),u=new h.Texture(l);u.minFilter=h.LinearFilter,u.magFilter=h.LinearFilter,u.needsUpdate=!0;const f=l.width/window.devicePixelRatio,m=l.height/window.devicePixelRatio,x=new h.SpriteMaterial({map:u,depthWrite:!1}),g=new h.Sprite(x);return g.scale.set(f/o,m/o,1),{sprite:g,canvasWidth:f,canvasHeight:m}},this.generateBoxTrackID=n=>{if(!n.trackID)return;const{sprite:o}=this.generateLabel(n.trackID.toString(),50);return o.position.set(-n.width/2,0,n.depth/2+.5),o},this.generateBoxAttributeLabel=n=>{if(!n.attribute||this.hiddenText)return;const o=this.findSubAttributeLabel(n,this.config),l=o?`${n.attribute}
|
|
32
|
+
${o}`:`${n.attribute}`,{sprite:u,canvasHeight:f}=this.generateLabel(l,100);return u.position.set(-n.width/2,0,-n.depth/2-f/150),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:o})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const u=l.material.uniforms.pointSize.value;n?l.material.uniforms.pointSize.value=Math.min(u*1.2,10):l.material.uniforms.pointSize.value=Math.max(u/1.2,1),o&&(l.material.uniforms.pointSize.value=o,this.pointsMaterialSize=o),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",n=>{var o,l,u;const f=this.renderer.domElement.getBoundingClientRect(),m=n.originalEvent.clientX-f.left,x=n.originalEvent.clientY-f.top;this.pointer.x=m/f.width*2-1,this.pointer.y=-(x/f.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const g=[];this.scene.children.forEach(w=>{w instanceof h.Group&&w.children.forEach(b=>{b instanceof h.Mesh&&g.push(b)})});const y=this.raycaster.intersectObjects(g,!1);if(y.length>0){const w=y[0].object;(o=this.pipe)==null||o.setNeedUpdateCenter(!1),(l=this.pipe)==null||l.setSelectedIDs(w.userData.selectedID)}else(u=this.pipe)==null||u.setSelectedIDs(void 0)})}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,n=100,o=-100,l=500/n;return{left:c,right:s,top:d,bottom:p,near:n,far:o,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),n=e;i=i!=null?i:new Float32Array([]);const o={boxParams:t,zMin:s,zMax:d,polygonPointList:p,color:i,position:n};return new Promise(l=>{const u=new G;u.postMessage(o),u.onmessage=f=>{const{color:m,position:x,num:g}=f.data,y=new h.BufferGeometry;y.setAttribute("position",new h.Float32BufferAttribute(x,3)),y.setAttribute("color",new h.Float32BufferAttribute(m,3)),y.computeBoundingSphere(),u.terminate(),l({geometry:y,num:g})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=M.Front,a=ct){let c=z.frontViewMatrix4(a);switch(r){case M.Front:break;case M.Back:c=z.backViewMatrix4(a);break;case M.Left:c=z.leftViewMatrix4(a);break;case M.Right:c=z.rightViewMatrix4(a);break;case M.Top:c=z.topViewMatrix4(a);break;case M.LFT:c=z.leftFrontTopViewMatrix4(a,i);break;case M.RBT:c=z.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(c),d=new h.Matrix4().makeTranslation(-t.x,-t.y,-t.z),p=new h.Matrix4().makeTranslation(t.x,t.y,t.z),n=new h.Matrix4().makeRotationZ(e);return new h.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(d).applyMatrix4(n).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 o=(e?[...e]:[]).map(x=>I(x)),l=this.getAllAttributeColor(o),u=s.geometry.attributes.position.array,f=s.geometry.attributes.dimensions.array,m={cuboidList:o,position:u,color:f,colorList:l,highlightIndex:i,modifiedBoxIds:a,resetAreas:c};this.handleWebworker(m).then(x=>{const{color:g}=x;let y=g;(a.length||c.length)&&(y=g.map((b,P)=>b===-1?f[P]:b));const w=new h.BufferAttribute(y,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==g.length){p(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,y),this.highlightPCDSrc=void 0,w.needsUpdate=!0,s.geometry.setAttribute("dimensions",w),s.geometry.attributes.dimensions.needsUpdate=!0,d(y),this.render()}).catch(x=>{p(x)})}})})}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:n}=i,{fill:o}=j.getColorFromConfig({attribute:i.attribute},S(v({},this.config),{attributeConfigurable:!0}),{}),l=new h.BoxGeometry(s,d,p),u=new h.MeshBasicMaterial({color:o,transparent:!0,opacity:.2,depthTest:!1});l.rotateZ(n),l.translate(r,a,c);const f=new h.Mesh(l,u);e.add(f);const m=new h.PlaneGeometry(p,d);m.rotateY(Math.PI/2),m.rotateZ(n);const x=new h.Vector3(s/2,0,0),g=new h.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(n);x.applyMatrix4(g),m.translate(r+x.x,a+x.y,c+x.z);const y=new h.MeshBasicMaterial({color:o,side:h.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new h.Mesh(m,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 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;p.forEach(n=>{var o;const l=(o=t.subAttribute)==null?void 0:o[c];(l==null?void 0:l.includes(n.value))&&(r&&(r+="\u3001"),r+=`${d}:${n.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(o=>i.measureText(o).width)),d=Math.ceil(s),p=a*1.5,n=p*c.length;e.width=d*r,e.height=n*r,e.style.width=`${d}px`,e.style.height=`${n}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",c.forEach((o,l)=>{i.fillText(o,0,l*p)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((o,l)=>o.z-l.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:o})=>o>r.z+.1);const a=.005,c=Math.floor(e.length*(1-a));e=e.slice(0,c),e.sort((o,l)=>o.x-l.x);const s=Math.floor(e.length*a),d=Math.floor(e.length*(1-a));e=e.slice(s,d),e.sort((o,l)=>o.y-l.y);const p=Math.floor(e.length*a),n=Math.floor(e.length*(1-a));return e=e.slice(p,n),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:p})=>{t.forEach((n,o)=>{const l=r[o+1],u=E.getFootOfPerpendicular({x:d,y:p},n,l,!1,!0).length;(!i[o]||u<i[o].distance)&&(i[o]={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 n=r[p],o=r[p+1],l=r[p+2];return U.getIntersectionBySlope({p1:a[p].point,line1:[n,o],p2:a[p+1].point,line2:[o,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(m=>m.uuid===this.pointsUuid);let d=0,p=0,n=0,o=0,l=[],u=[];const f=((c=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:c.array)||[];for(let m=0;m<f.length;m+=3){const x=f[m],g=f[m+1],y=f[m+2];$({x,y:g},t)&&(y||y===0)&&u.push({x,y:g,z:y})}return u.length?(i&&(u=this.filterNoise(u),l=this.getFittedCoordinates(t,u)),u.sort((m,x)=>m.z-x.z),d=u[0].z-.01,p=u[u.length-1].z+.01,o=u.length,e&&(n=u.filter(({z:m})=>m>=e[0]&&m<=e[1]).length),{maxZ:p,minZ:d,count:n,zCount:o,fittedCoordinates:l}):{maxZ:p,minZ:d,count:n,zCount:o,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},n={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};return[d,p,n,o]}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},n={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};return[d,p,n,o]}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},n={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};return[d,p,n,o]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,c=new h.Matrix4().makeTranslation(-e,-i,-r),s=new h.Matrix4().makeTranslation(e,i,r),d=new h.Matrix4().makeRotationZ(a);return new h.Matrix4().multiply(s).multiply(d).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,M.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case M.Left:return this.getPolygonSidePoints(t);case M.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:a}=t,c=new h.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new h.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const d=i.map(o=>new h.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.sideMatrix)),p=this.containerWidth/r,n=this.containerHeight/a;return{polygon2d:d,zoom:Math.min(p,n)/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 n=new h.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),o=this.containerWidth/(c*2),l=this.containerHeight/(c*2);return{point2d:n,zoom:Math.min(o,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(x=>new h.Vector3(x.x,x.y,x.z)).map(x=>x.applyMatrix4(c)),[d,p,n,o]=s,l=Math.max(Math.abs(d.x-n.x),Math.abs(d.x-p.x)),f=p.add(o).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-f.x,y:r.center.y-f.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*as p from"three";import{MatrixUtils as M,ECameraType as
|
|
1
|
+
import*as p from"three";import{MatrixUtils as M,ECameraType as V,PointCloudUtils as G}from"@labelbee/lb-utils";import J from"../../utils/uuid.js";import{transformPointCloudToImage as Q}from"./omniCamera.js";var W=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,C=Math.pow,D=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,E=(r,t)=>{for(var e in t||(t={}))$.call(t,e)&&D(r,e,t[e]);if(R)for(var e of R(t))S.call(t,e)&&D(r,e,t[e]);return r},A=(r,t)=>X(r,Y(t));function g(r){return new p.Matrix4().set(...r)}function v(r,t,e){try{const n=M.transferMatrix34FromKitti2Three(r),s=M.transferMatrix33FromKitti2Three(t),o=M.transferMatrix34FromKitti2Three(e),c=g(n),f=g(s),a=g(o);return{composeMatrix4:a.clone().premultiply(f).premultiply(c),PM:c,RM:f,TM:a}}catch(n){console.error(n)}}function F(r,t,e){var n;const s=new p.Vector3(r.x,r.y,(n=r==null?void 0:r.z)!=null?n:1),o=new p.Matrix4().makeRotationZ(e),c=new p.Matrix4().makeTranslation(t.x,t.y,t.z),f=new p.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return s.clone().applyMatrix4(f).applyMatrix4(o).applyMatrix4(c)}function H(r,t,e){return!(r.length!==t||r.some(n=>n.length!==e))}const O=(r,t)=>t.some(e=>H(r,e[0],e[1])),d=r=>{var t;return!!(((t=r.fisheyeDistortion)==null?void 0:t.length)>0&&O(r.P,[[3,4],[4,4]])&&O(r.T,[[3,4],[4,4]]))},j=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=new p.Vector4(r.x,r.y,r.z),c=g(M.transferMatrix34FromKitti2Three(s)),f=g(M.transferMatrix34FromKitti2Three(e)),a=o.applyMatrix4(c),y=C(C(a.x,2)+C(a.y,2),.5),h=Math.atan(a.z/y),i=n.reduce((l,u,m)=>l+u*C(h,m),0);return a.x=a.x/y*i,a.y=a.y/y*i,a.z=1,a.applyMatrix4(f)},K=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}const{P:e,fisheyeDistortion:n,T:s}=t,o=Q([[r.x,r.y,r.z]],s,e,n);return new p.Vector4(o[0][0],o[0][1],1)},b=(r,t)=>{const{P:e,T:n,fisheyeDistortion:s}=t,o=[r.x,r.y,r.z,1],c=n.map(z=>z.reduce((I,L,Z)=>I+L*o[Z],0)),f=c[0],a=c[1],y=c[2];if(!(y>=.01&&isFinite(y)))return;const h=[[e[0][0],e[0][1]],[e[1][0],e[1][1]]],i=e[0][2],x=e[1][2],l=Math.sqrt(f*f+a*a),u=Math.atan2(l,y),m=u+s.reduce((z,I,L)=>z+I*Math.pow(u,2*L+3),0);let P,_;l!==0?(P=f*m/l,_=a*m/l):(P=0,_=0);const q=h[0][0]*P+h[0][1]*_,N=h[1][0]*P+h[1][1]*_;return{x:q+i,y:N+x}},T=(r,t)=>{if(d(t)===!1){console.error("Error Calib, it need fisheye calib");return}if((t==null?void 0:t.cameraType)===V.OmniCamera)return j(r,t);if((t==null?void 0:t.cameraType)===V.KannalaBrandt)return b(r,t);if((t==null?void 0:t.cameraType)===V.OmniCamera11V)return K(r,t)};function w(r,t){const n=new p.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(n.z<0)return;const s=1/n.z,o=new p.Matrix4().set(s,0,0,0,0,s,0,0,0,0,s,0,0,0,0,1);return n.applyMatrix4(o)}function tt(r){const{center:t,width:e,height:n,depth:s,rotation:o}=r,c=[{x:t.x+e/2,y:t.y-n/2},{x:t.x+e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y+n/2},{x:t.x-e/2,y:t.y-n/2}].map(y=>{const h=F(y,t,o);return{x:h.x,y:h.y}}),f=t.z+s/2,a=t.z-s/2;return A(E({},r),{polygonPointList:c,zMax:f,zMin:a})}function rt(r){const t=r.slice();return t.sort((e,n)=>e.x===n.x?n.y-e.y:e.x-n.x),t}function k(r,t,e){const n=t.x-r.x,s=t.y-r.y,o=e.x-r.x,c=e.y-r.y;return n*c-o*s}function et(r){const t=rt(r),e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&k(e[e.length-2],e[e.length-1],t[o])<=0;)e.pop();e.push(t[o])}const n=[];for(let o=t.length-1;o>=0;o--){for(;n.length>=2&&k(n[n.length-2],n[n.length-1],t[o])<=0;)n.pop();n.push(t[o])}return e.pop(),n.pop(),e.concat(n)}const B=(r,t)=>{var e;if(d(t))return T(r,t);const{P:n,R:s,T:o}=t,{composeMatrix4:c}=(e=v(n,s,o))!=null?e:{};if(!!c)return w(r,c)},U=({point:r,calib:t,width:e,height:n})=>{if(!t)return!1;const s=B(r,t);return s?s.x>=0&&s.x<=e&&s.y>=0&&s.y<=n:!1},nt=({points:r,calib:t,width:e,height:n})=>{const s=[];for(let o=0;o<r.length;o+=3){const c=r[o],f=r[o+1],a=r[o+2];U({point:{x:c,y:f,z:a},calib:t,width:e,height:n})?s.push(1):s.push(0)}return s},ot=r=>{if(r.length===0)return[];const t=[];for(let e=0;e<r[0].length;e++){for(let n=0;n<r.length;n++)if(r[n][e]===1){t.push(1);break}t.length===e&&t.push(0)}return t};function st(r,t,e={createRange:!1}){var n;if(!t)return{transferViewData:[],viewRangePointList:[]};const{createRange:s}=e,o=G.getAllViewData(r),c=d(t),{P:f,R:a,T:y}=t;let h;if(c===!1){const{composeMatrix4:l}=(n=v(f,a,y))!=null?n:{};if(!l)return;h=l}const i=o.map(l=>({type:l.type,pointList:l.pointList.map(u=>F(u,r.center,r.rotation)).map(u=>c?T(u,t):h&&w(u,h)).map(u=>{if(!!u)return{id:J(),x:u==null?void 0:u.x,y:u==null?void 0:u.y}}).filter(u=>u!==void 0)})).filter(l=>l.pointList.length!==0);i[0]&&i[0].pointList&&(i[0].pointList=i[0].pointList.map(l=>A(E({},l),{specialEdge:!0})));let x=[];if(i.length===6&&s===!0){const l=i[0].pointList,u=i[1].pointList;x=et([...l,...u])}return{transferViewData:i,viewRangePointList:x}}function it(r,t,e){var n;const s=d(t),{P:o,R:c,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=v(o,c,f))!=null?n:{};if(!i)return;a=i}const y=r.length/3,h={};for(let i=0;i<y;i++){const x={x:r[i*3],y:r[i*3+1],z:r[i*3+2]};let l;if(s?l=T(x,t):l=a&&w({x:r[i*3],y:r[i*3+1],z:r[i*3+2]},a),l){const u=Math.floor(l.x),m=Math.floor(l.y);if(u>e.width||m>e.height||u<0||m<0)continue;h[i]={x:u,y:m}}}return{pcdMapping:h}}function at(r,t,e){var n;if(!t||!e)return;const s=d(t),{P:o,R:c,T:f}=t;let a;if(s===!1){const{composeMatrix4:i}=(n=v(o,c,f))!=null?n:{};if(!i)return;a=i}const y=[];if(r.forEach(i=>{let x;if(s?x=T(i,t):x=a&&w(i,a),x){const{x:l,y:u}=x;y.push({x:l,y:u})}}),y.some(i=>i.x>0&&i.x<e.width&&i.y>0&&i.y<e.height))return y}export{g as createThreeMatrix4,tt as getCuboidFromPointCloudBox,nt as getHighlightIndexByPoints,d as isFisheyeCalibValid,U as isInImage,H as isMatrixValid,O as isMatrixValidByArr,T as lidar2FisheyeImage,w as lidar2image,ot as mergeHighlightList,j as oCamFisheyeTransfer,K as omniCamera11VTransfer,B as point3DLidar2Image,st as pointCloudLidar2image,at as pointListLidar2Img,it as pointMappingLidar2image,F as rotatePoint,v as transferKitti2Matrix};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import*as t from"mathjs";function P(n){if(n.length!==1||n[0].length!==3)throw new Error("Input matrix must be a 1x3 or 3x1 matrix");return[[n[0][0]],[n[0][1]],[n[0][2]],[1]]}function b(n){const o=[];for(let e=0;e<n.length;e++){const s=n[e],r=s[0]*s[0]+s[1]*s[1],i=Math.sqrt(r);o.push(i)}return o}function v(n,o){const e=n.length,s=[];for(let r=0;r<o.length;r++){let i=0;for(let l=0;l<n.length;l++)i=n[e-l-1]+i*o[r];s.push(i)}return s}function w(n,o,e){const s=t.matrix([[o[0][0],o[0][1]],[o[1][0],o[1][1]]]),r=o[0][2],i=o[1][2],l=e,a=b(n.toArray().map(z=>z.slice(0,2))),u=t.dotDivide(t.ones(t.matrix(a).size()),a),h=t.atan2(t.multiply(-1,n.subset(t.index(t.range(0,t.matrix(n).size()[0]),2))),a),c=v(l,h);let m=t.ones(2,n.size()[0]);const x=t.multiply(n.subset(t.index(t.range(0,n.size()[0]),0)),u*c),g=t.multiply(n.subset(t.index(t.range(0,n.size()[0]),1)),u*c),f=t.matrix([[x,0],[g,0]]);m=t.subset(f,t.index(t.range(0,f.size()[0]),0));const y=t.matrix([r,i]),p=t.multiply(s,m),d=y.reshape([2,1]);return t.transpose(t.add(p,d)).toArray()}function C(n=[],o,e,s){const r=t.matrix(P(n)),i=t.matrix(o),l=t.multiply(i,r);return w(t.transpose(l),e,s)}export{C as transformPointCloudToImage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ImgPosUtils as H}from"@labelbee/lb-utils";import E from"lodash";import M from"color-rgba";import d from"../../utils/tool/DrawUtils.js";import b from"../../utils/tool/AxisUtils.js";import W from"../../utils/tool/RectUtils.js";import z from"../../utils/tool/PolygonUtils.js";import k from"../../utils/MathUtils.js";import j from"../../utils/tool/RenderDomClass.js";import{ELineTypes as R,DEFAULT_FONT as V,SEGMENT_NUMBER as U}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as B,TEXT_ATTRIBUTE_OFFSET as O,DEFAULT_TEXT_SHADOW as G}from"../../constant/annotation.js";import K,{cropAndEnlarge as X}from"../../utils/ImgUtils.js";import q from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as Y}from"./basicToolOperation.js";import{pointCloudLidar2image as J}from"../pointCloud/matrix.js";var Q=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,F=(v,t,e)=>t in v?Q(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,m=(v,t)=>{for(var e in t||(t={}))ot.call(t,e)&&F(v,e,t[e]);if($)for(var e of $(t))it.call(t,e)&&F(v,e,t[e]);return v},T=(v,t)=>tt(v,et(t)),nt=(v,t,e)=>new Promise((o,i)=>{var r=a=>{try{s(e.next(a))}catch(n){i(n)}},c=a=>{try{s(e.throw(a))}catch(n){i(n)}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((e=e.apply(v,t)).next())});const st=3,rt=3,L="#6371FF";class at extends Y{constructor(t){super(T(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),s=b.changePointByZoom(c,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",n=Number.MAX_SAFE_INTEGER;for(let h=0;h<this.annotations.length;h++){const l=this.annotations[h];switch(l.type){case"rect":{const u=l.annotation;if(W.isInRect(c,u,st,this.zoom)){const g=u.width*u.height;g<n&&(a=u.id,n=g)}break}case"polygon":{const u=l.annotation;if(z.isInPolygon(s,u.pointList)){const g=z.getPolygonArea(u.pointList);g<n&&(a=u.id,n=g)}break}}}return a};var e;this.style=(e=t.style)!=null?e:{stroke:L,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new j({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:c}=k.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(s=>{this.connectionPoints=s.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:s.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let 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=X(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);K.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 nt(this,null,function*(){if(!E.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,o=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const i=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:o}),this.staticImgNode=i}})}getSpecificStyle(t){const e=E.pick(t,["stroke","thickness","fill","radius"]),o=m(m({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return T(m({},G),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+B.offsetX,y:e+B.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=k.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=H.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(T(m({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=b.changePointByZoom(t,this.zoom,this.currentPos);d.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),d.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=R.Line}=s,n=b.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos),h=T(m(m({},r),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:a,strokeColor:r.stroke});let l=[];if(s.showKeyPoint?l=d.drawPolygonWithKeyPoint(this.canvas,n,h):l=d.drawPolygon(this.canvas,n,h),(s==null?void 0:s.showDirection)===!0&&((i=s==null?void 0:s.pointList)==null?void 0:i.length)>=2){let p=n[0],P=k.getLineCenterPoint([n[0],n[1]]);if(a===R.Curve){const f=Math.floor(U/2);p=l[f],P=l[f+1]}d.drawArrowByCanvas(this.canvas,p,P,{color:r.stroke,thickness:r.thickness}),d.drawCircle(this.canvas,n[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(g&&d.drawText(this.canvas,this.appendOffset(n[0]),g,c),y){const p=n[n.length-1];d.drawText(this.canvas,this.appendOffset({x:p.x+O.x,y:p.y+O.y}),y,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:s,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:h=R.Line}=n,l=b.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||s.fill){const f=M((r=(i=s==null?void 0:s.fill)!=null?i:s==null?void 0:s.stroke)!=null?r:L),x=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;d.drawPolygonWithFill(this.canvas,l,{color:x,lineType:h})}const u=T(m(T(m({},s),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:s.stroke});let g=[];if(n.showKeyPoint?g=d.drawPolygonWithKeyPoint(this.canvas,l,u):g=d.drawPolygon(this.canvas,l,u),(n==null?void 0:n.showDirection)===!0&&((c=n==null?void 0:n.pointList)==null?void 0:c.length)>=2){let f=l[0],x=k.getLineCenterPoint([l[0],l[1]]);if(h===R.Curve){const w=Math.floor(U/2);f=g[w],x=g[w+1]}d.drawArrowByCanvas(this.canvas,f,x,{color:s.stroke,thickness:s.thickness}),d.drawCircle(this.canvas,l[0],s.thickness+6,{color:s.stroke,thickness:s.thickness})}const{headerText:p,bottomText:P}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(p&&d.drawText(this.canvas,this.appendOffset(l[0]),p,a),P){const f=l[l.length-1];d.drawText(this.canvas,this.appendOffset({x:f.x+O.x,y:f.y+O.y}),P,a)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=M((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:L),s=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,a=i.stroke,n=b.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:l}=this.getRenderText(r,r==null?void 0:r.hiddenText);d.drawCuboidWithText(this.canvas,n,{strokeColor:a,fillColor:s,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:h,bottomText:l})}renderBox3d(t){var e;if(t.type!=="box3d")return;const o=t.annotation,{transferViewData:i}=(e=J(o,o.calib))!=null?e:{};if(!i)return;const r={fill:"transparent"},c=E.pick(o,["stroke","thickness"]);i.forEach((s,a)=>{const n=m(T(m({},c),{id:`${t.annotation.id}-${a}`,pointList:s.pointList}),r);switch(s.type){case"line":this.renderLine({type:"line",annotation:n});break;case"polygon":this.renderPolygon({type:"polygon",annotation:n});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const 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){d.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:s,canvas:a}=q.createCanvas(c),n=typeof t.pixelSize=="number"?t.pixelSize:13;s&&(o==null?void 0:o.length)>0&&(d.drawPixel({canvas:a,points:o,size:c,defaultRGBA:t.defaultRGBA,pixelSize:n}),d.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:a})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,c,s;const a=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:l=!1,isReference:u,hiddenRectSize:g=!1}=h,{zoom:y}=this,p=b.changeRectByZoom(h,this.zoom,this.currentPos),{x:P,y:f,width:x,height:w}=p,_=M((i=(o=a==null?void 0:a.fill)!=null?o:a==null?void 0:a.stroke)!=null?i:L),I=`rgba(${_[0]}, ${_[1]}, ${_[2]},${_[3]*.8})`;(h.id===this.mouseHoverID||a.fill)&&d.drawRectWithFill(this.canvas,p,{color:I}),d.drawRect(this.canvas,p,m(T(m({},a),{hiddenText:!0}),this.getReferenceOptions(u))),(h==null?void 0:h.isHighlight)&&d.drawHighlightFlag({canvas:this.canvas,color:I,position:{x:P-16,y:f-16}});const{headerText:S,bottomText:A}=this.getRenderText(h,h==null?void 0:h.hiddenText);S&&d.drawText(this.canvas,{x:P,y:f-6},S,m({textMaxWidth:300},n));const C=`${Math.round(x/y)} * ${Math.round(w/y)}`,D=C.length*7;if(!l&&!g&&d.drawText(this.canvas,{x:P+x-D,y:f+w+15},C,n),A){const N=20,Z=Math.max(20,x-D);d.drawText(this.canvas,{x:P,y:f+w+N},h.textAttribute,m({textMaxWidth:Z},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,l=b.changePointByZoom(h,this.zoom,this.currentPos),u=(r=a.radius)!=null?r:rt;d.drawCircle(this.canvas,l,u,a);const{headerText:g,bottomText:y}=this.getRenderText(h,h==null?void 0:h.hiddenText);g&&d.drawText(this.canvas,{x:l.x+u/2,y:l.y-u-4},g,m({textAlign:"center"},n)),y&&d.drawText(this.canvas,this.appendOffset({x:l.x+u,y:l.y+u+24}),y,n);break}case"text":{const h=e.annotation,{text:l,x:u,y:g,textMaxWidth:y,color:p="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:x=V,position:w}=h,_=10,I=10,S=b.changePointByZoom({x:u,y:g},this.zoom,this.currentPos),{width:A,height:C,fontHeight:D=0}=k.getTextArea(this.canvas,h.text,y,x,f);if(w==="rt")break;d.drawRectWithFill(this.canvas,{x:S.x,y:S.y,width:A+I*2,height:C+_*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),d.drawText(this.canvas,{x:S.x+I,y:S.y+D+_},l,{color:p,lineHeight:f,font:x,textMaxWidth:y});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{at as default};
|
|
1
|
+
import{ImgPosUtils as W}from"@labelbee/lb-utils";import B from"lodash";import $ 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 H}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=a=>{try{n(e.next(a))}catch(s){i(s)}},l=a=>{try{n(e.throw(a))}catch(s){i(s)}},n=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,l);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 l=this.getCoordinateUnderZoom(o),n=T.changePointByZoom(l,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",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(l,d,at,this.zoom)){const f=d.width*d.height;f<s&&(a=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&&(a=d.id,s=f)}break}}}return a};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:l}=L.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:l},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);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,l=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(p({},X),{color:e.stroke,font:`normal normal 600 ${r}px ${l}`})}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:l}=this.innerPosAndZoom;r&&this.setImgInfo(_(p({},r),{width:r.width/l*i.innerZoom,height:r.height/l*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:l}=this.getRenderStyle(r),n=r.annotation,a=(o=this.pointCloudBoxList)==null?void 0:o.find(c=>c.id===n.id),s=this.hiddenText?"":`${a==null?void 0:a.trackID} ${a==null?void 0:a.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,l)})}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:l}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=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:a,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(a===E.Curve){const g=Math.floor(H/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,l),y){const v=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:v.x+U.x,y:v.y+U.y}),y,l)}}renderPolygon(t){var e,o,i,r,l;if(t.type!=="polygon")return;const{style:n,fontStyle:a}=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=$((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&&((l=s==null?void 0:s.pointList)==null?void 0:l.length)>=2){let g=c[0],P=L.getLineCenterPoint([c[0],c[1]]);if(u===E.Curve){const w=Math.floor(H/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,a),m){const g=c[c.length-2];h.drawText(this.canvas,this.appendOffset({x:g.x+U.x,y:g.y+U.y}),m,a)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,l=$((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:z),n=`rgba(${l[0]}, ${l[1]}, ${l[2]},${l[3]*.8})`,a=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:a,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"},l=B.pick(o,["stroke","thickness"]);i.forEach((n,a)=>{const s=p(_(p({},l),{id:`${t.annotation.id}-${a}`,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 l={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:a}=J.createCanvas(l),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(o==null?void 0:o.length)>0&&(h.drawPixel({canvas:a,points:o,size:l,defaultRGBA:t.defaultRGBA,pixelSize:s}),h.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:a})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,l,n,a,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=$((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+=(l=b.x)!=null?l: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=(a=e.annotation).renderEnhance)==null||s.call(a,{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};
|