@labelbee/lb-annotation 1.14.0-alpha.9 → 1.15.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/pointCloud/index.js +2 -2
- package/dist/core/scheduler.js +1 -1
- package/dist/core/toolOperation/LineToolOperation.js +1 -1
- package/dist/core/toolOperation/Selection.js +1 -0
- package/dist/core/toolOperation/cuboidOperation.js +1 -1
- package/dist/core/toolOperation/pointCloud2dOperation.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 +1 -1
- package/dist/core/toolOperation/textAttributeClass.js +9 -9
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/pointCloud/annotation.d.ts +2 -1
- package/dist/types/core/pointCloud/index.d.ts +8 -3
- package/dist/types/core/scheduler.d.ts +16 -3
- package/dist/types/core/toolOperation/LineToolOperation.d.ts +26 -36
- package/dist/types/core/toolOperation/Selection.d.ts +70 -0
- package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +2 -10
- package/dist/types/core/toolOperation/pointOperation.d.ts +10 -4
- package/dist/types/core/toolOperation/polygonOperation.d.ts +23 -14
- package/dist/types/core/toolOperation/rectOperation.d.ts +41 -10
- package/dist/types/core/toolOperation/textAttributeClass.d.ts +6 -0
- package/dist/types/utils/tool/CommonToolUtils.d.ts +2 -2
- package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +2 -2
- package/dist/types/utils/tool/PolygonUtils.d.ts +1 -1
- package/dist/utils/tool/CommonToolUtils.js +1 -1
- package/dist/utils/tool/PolygonUtils.js +1 -1
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/scheduler.js +1 -1
- package/es/core/toolOperation/LineToolOperation.js +1 -1
- package/es/core/toolOperation/Selection.js +1 -0
- package/es/core/toolOperation/cuboidOperation.js +1 -1
- package/es/core/toolOperation/pointCloud2dOperation.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 +1 -1
- package/es/core/toolOperation/textAttributeClass.js +9 -9
- package/es/utils/tool/CommonToolUtils.js +1 -1
- package/es/utils/tool/PolygonUtils.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Manage selectedIds for ToolInstance
|
|
3
|
+
* @author Glenfiddish <edwinlee0927@hotmail.com>
|
|
4
|
+
* @createdate 2023-03-01
|
|
5
|
+
*/
|
|
6
|
+
import { IPolygonData } from '@/types/tool/polygon';
|
|
7
|
+
import LineToolOperation from './LineToolOperation';
|
|
8
|
+
import PointOperation from './pointOperation';
|
|
9
|
+
import PolygonOperation from './polygonOperation';
|
|
10
|
+
import { RectOperation } from './rectOperation';
|
|
11
|
+
type ToolInstance = PointOperation | PolygonOperation | LineToolOperation | RectOperation;
|
|
12
|
+
type SelectedID = string;
|
|
13
|
+
type SelectedIDs = SelectedID[];
|
|
14
|
+
type DataUnit = IPointUnit | IPolygonData | ILine | IRect;
|
|
15
|
+
type DataList = Array<DataUnit>;
|
|
16
|
+
export type SetDataList = (dataList: DataList) => void;
|
|
17
|
+
declare class Selection {
|
|
18
|
+
private _selectedIDs;
|
|
19
|
+
private toolInstance;
|
|
20
|
+
private stashDataList?;
|
|
21
|
+
constructor(toolInstance: ToolInstance);
|
|
22
|
+
get selectedIDs(): SelectedIDs;
|
|
23
|
+
get selectedID(): string | undefined;
|
|
24
|
+
get visibleDataList(): any[];
|
|
25
|
+
get dataList(): DataList;
|
|
26
|
+
/**
|
|
27
|
+
* Trigger tools and _textAttributeInstance to re-render when _selectedIDs changed
|
|
28
|
+
*/
|
|
29
|
+
private set selectedIDs(value);
|
|
30
|
+
/**
|
|
31
|
+
* Update selectedIDs:
|
|
32
|
+
* Remove selectedID when selectedIDs includes
|
|
33
|
+
* Append selectedID when selectedIDs not includes
|
|
34
|
+
* SelectedID is
|
|
35
|
+
* @param selectedID
|
|
36
|
+
*/
|
|
37
|
+
private updateSelectedIDs;
|
|
38
|
+
/**
|
|
39
|
+
* Set selectedIDs
|
|
40
|
+
* isAppend is true: push or remove from selectedIDs
|
|
41
|
+
* isAppend is false: overwrite selectedIDs
|
|
42
|
+
* @param id
|
|
43
|
+
* @param isAppend
|
|
44
|
+
*/
|
|
45
|
+
setSelectedIDs(id?: string, isAppend?: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* Force set selectedIDs not calc
|
|
48
|
+
* @param ids
|
|
49
|
+
*/
|
|
50
|
+
hardSetSelectedIDs(ids: string[]): void;
|
|
51
|
+
selectAll(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Stash data list and pop while paste
|
|
54
|
+
*/
|
|
55
|
+
toStashDataList(): void;
|
|
56
|
+
toUnStashDataList(): DataList | undefined;
|
|
57
|
+
mergeStashData(setDataList: (dataList: DataList) => void): void;
|
|
58
|
+
isIdSelected(id: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Trigger selection events(hijacking tools' key down event)
|
|
61
|
+
* - Copy selected data
|
|
62
|
+
* - Paste stash data
|
|
63
|
+
* - Select visible data
|
|
64
|
+
* @param e
|
|
65
|
+
* @param setDataList
|
|
66
|
+
* @returns if
|
|
67
|
+
*/
|
|
68
|
+
triggerKeyboardEvent(e: KeyboardEvent, setDataList: SetDataList): boolean;
|
|
69
|
+
}
|
|
70
|
+
export default Selection;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It can expand various types of operations
|
|
3
|
-
*
|
|
4
|
-
* @file PointCloud 2D Operation
|
|
5
|
-
* @createdate 2022-07-11
|
|
6
|
-
* @author Ron <ron.f.luo@gmail.com>
|
|
7
|
-
*/
|
|
8
1
|
import { IPointCloudConfig } from '@labelbee/lb-utils';
|
|
9
2
|
import { ESortDirection } from '@/constant/annotation';
|
|
10
3
|
import { IPolygonData, IPolygonPoint } from '@/types/tool/polygon';
|
|
@@ -20,7 +13,6 @@ declare class PointCloud2dOperation extends PolygonOperation {
|
|
|
20
13
|
forbidAddNew: boolean;
|
|
21
14
|
pointCloudConfig: IPointCloudConfig;
|
|
22
15
|
private checkMode;
|
|
23
|
-
private selectedIDs;
|
|
24
16
|
constructor(props: IPolygonOperationProps & IPointCloud2dOperationProps);
|
|
25
17
|
get getSelectedIDs(): string[];
|
|
26
18
|
get enableDrag(): boolean;
|
|
@@ -41,7 +33,7 @@ declare class PointCloud2dOperation extends PolygonOperation {
|
|
|
41
33
|
* @override
|
|
42
34
|
*/
|
|
43
35
|
rightMouseUp: (e: MouseEvent) => void;
|
|
44
|
-
get selectedPolygons(): IPolygonData[]
|
|
36
|
+
get selectedPolygons(): IPolygonData[];
|
|
45
37
|
updateSelectedPolygonsPoints(offset: Partial<ICoordinate>): void;
|
|
46
38
|
/**
|
|
47
39
|
* keydown event
|
|
@@ -67,6 +59,7 @@ declare class PointCloud2dOperation extends PolygonOperation {
|
|
|
67
59
|
* */
|
|
68
60
|
renderSelectedPolygon(): void;
|
|
69
61
|
renderSingleSelectedPolygon: (selectedPolygon: IPolygonData) => void;
|
|
62
|
+
renderdrawTrackID(polygon: IPolygonData): void;
|
|
70
63
|
renderRectPolygonDirection(polygon: IPolygonPoint[]): void;
|
|
71
64
|
get currentPolygonListByPattern(): IPolygonData[];
|
|
72
65
|
/**
|
|
@@ -106,7 +99,6 @@ declare class PointCloud2dOperation extends PolygonOperation {
|
|
|
106
99
|
* @returns
|
|
107
100
|
*/
|
|
108
101
|
setPolygonValidAndRender(id: string, isUpdate?: boolean): void;
|
|
109
|
-
onDragMove(e: MouseEvent): void;
|
|
110
102
|
onMouseDown(e: MouseEvent): true | undefined;
|
|
111
103
|
/**
|
|
112
104
|
* Just Update Data. Not Clear Status
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
|
|
2
|
+
import TextAttributeClass from './textAttributeClass';
|
|
3
|
+
import Selection from './Selection';
|
|
2
4
|
export interface IPointOperationProps extends IBasicToolOperationProps {
|
|
3
5
|
style: any;
|
|
4
6
|
forbidAddNew?: boolean;
|
|
@@ -8,18 +10,21 @@ declare class PointOperation extends BasicToolOperation {
|
|
|
8
10
|
config: IPointToolConfig;
|
|
9
11
|
pointList: IPointUnit[];
|
|
10
12
|
hoverID?: string;
|
|
11
|
-
selectedID?: string;
|
|
12
13
|
markerIndex: number;
|
|
13
14
|
dragInfo?: {
|
|
14
15
|
dragStartCoord: ICoordinate;
|
|
15
16
|
originPointList: IPointUnit[];
|
|
16
17
|
};
|
|
18
|
+
selection: Selection;
|
|
19
|
+
_textAttributeInstance?: TextAttributeClass;
|
|
17
20
|
forbidAddNew?: boolean;
|
|
18
21
|
forbidDelete?: boolean;
|
|
19
|
-
private _textAttributInstance?;
|
|
20
22
|
constructor(props: IPointOperationProps);
|
|
21
23
|
get dataList(): IPointUnit[];
|
|
22
24
|
get drawOutsideTarget(): boolean;
|
|
25
|
+
get selectedID(): string | undefined;
|
|
26
|
+
get selectedIDs(): string[];
|
|
27
|
+
get selectedPoints(): IPointUnit[];
|
|
23
28
|
/**
|
|
24
29
|
* 向外部提供标记的更改
|
|
25
30
|
* @param markerIndex
|
|
@@ -54,7 +59,7 @@ declare class PointOperation extends BasicToolOperation {
|
|
|
54
59
|
textChange: (v: string) => void;
|
|
55
60
|
get selectedText(): string | undefined;
|
|
56
61
|
setStyle(toolStyle: any): void;
|
|
57
|
-
setSelectedID(newID?: string): void;
|
|
62
|
+
setSelectedID(newID?: string, isAppend?: boolean): void;
|
|
58
63
|
/**
|
|
59
64
|
* 获取当前配置下的 icon svg
|
|
60
65
|
* @param attribute
|
|
@@ -74,13 +79,14 @@ declare class PointOperation extends BasicToolOperation {
|
|
|
74
79
|
onMouseMove(e: MouseEvent): undefined;
|
|
75
80
|
onMouseUp(e: MouseEvent): true | undefined;
|
|
76
81
|
onDragMove(e: MouseEvent): void;
|
|
82
|
+
onKeyUp(e: KeyboardEvent): boolean | void;
|
|
77
83
|
onKeyDown(e: KeyboardEvent): void;
|
|
78
84
|
isMinDistance: (coord: ICoordinate) => boolean;
|
|
79
85
|
createPoint(e: MouseEvent): void;
|
|
80
86
|
isInPoint(pos: ICoordinate, point: ICoordinate, zoom?: number): boolean;
|
|
81
87
|
getHoverId(): string | undefined;
|
|
82
88
|
get selectedPoint(): IPointUnit | undefined;
|
|
83
|
-
rightMouseUp(): void;
|
|
89
|
+
rightMouseUp(e: MouseEvent): void;
|
|
84
90
|
onTabKeyDown(e: KeyboardEvent): void;
|
|
85
91
|
/**
|
|
86
92
|
* 当前依赖状态下本页的所有的点
|
|
@@ -3,6 +3,7 @@ import { EPolygonPattern } from '../../constant/tool';
|
|
|
3
3
|
import { IPolygonConfig, IPolygonData, IPolygonPoint } from '../../types/tool/polygon';
|
|
4
4
|
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
|
|
5
5
|
import TextAttributeClass from './textAttributeClass';
|
|
6
|
+
import Selection from './Selection';
|
|
6
7
|
export interface IPolygonOperationProps extends IBasicToolOperationProps {
|
|
7
8
|
}
|
|
8
9
|
declare class PolygonOperation extends BasicToolOperation {
|
|
@@ -12,7 +13,6 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
12
13
|
hoverID?: string;
|
|
13
14
|
hoverPointIndex: number;
|
|
14
15
|
hoverEdgeIndex: number;
|
|
15
|
-
selectedID?: string;
|
|
16
16
|
editPolygonID?: string;
|
|
17
17
|
pattern: EPolygonPattern;
|
|
18
18
|
isCombined: boolean;
|
|
@@ -22,19 +22,25 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
22
22
|
changePointIndex?: number[];
|
|
23
23
|
dragTarget: EDragTarget;
|
|
24
24
|
originPolygon?: IPolygonData;
|
|
25
|
+
selectedPolygons?: IPolygonData[];
|
|
25
26
|
dragPrevCoord: ICoordinate;
|
|
26
27
|
originPolygonList: IPolygonData[];
|
|
27
28
|
};
|
|
28
29
|
private drawingHistory;
|
|
29
30
|
isCtrl: boolean;
|
|
30
31
|
isAlt: boolean;
|
|
31
|
-
|
|
32
|
+
_textAttributeInstance?: TextAttributeClass;
|
|
32
33
|
forbidAddNewPolygonFuc?: (e: MouseEvent) => boolean;
|
|
34
|
+
selection: Selection;
|
|
33
35
|
constructor(props: IPolygonOperationProps);
|
|
36
|
+
get selectedIDs(): string[];
|
|
37
|
+
get selectedID(): string | undefined;
|
|
38
|
+
get minArea(): number;
|
|
34
39
|
eventBinding(): void;
|
|
35
40
|
eventUnbinding(): void;
|
|
36
41
|
destroy(): void;
|
|
37
42
|
get selectedPolygon(): IPolygonData | undefined;
|
|
43
|
+
get selectedPolygons(): IPolygonData[];
|
|
38
44
|
get hoverPolygon(): IPolygonData | undefined;
|
|
39
45
|
get enableDrag(): boolean;
|
|
40
46
|
get visiblePolygonList(): IPolygonData[];
|
|
@@ -55,6 +61,7 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
55
61
|
textAttribute: string;
|
|
56
62
|
attribute: string;
|
|
57
63
|
isRect?: boolean | undefined;
|
|
64
|
+
trackID?: number | undefined;
|
|
58
65
|
}[];
|
|
59
66
|
get selectedText(): string | undefined;
|
|
60
67
|
isAllowDouble: (e: MouseEvent) => boolean;
|
|
@@ -71,6 +78,11 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
71
78
|
* @memberof RectOperation
|
|
72
79
|
*/
|
|
73
80
|
get currentPageResult(): IPolygonData[];
|
|
81
|
+
/**
|
|
82
|
+
* Just Update Data. Not Clear Status
|
|
83
|
+
* @param polygonList
|
|
84
|
+
*/
|
|
85
|
+
setResultAndSelectedID(polygonList: IPolygonData[], selectedID: string): void;
|
|
74
86
|
setResult(polygonList: IPolygonData[]): void;
|
|
75
87
|
/**
|
|
76
88
|
* 外层 sidabr 调用
|
|
@@ -98,7 +110,7 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
98
110
|
clearActiveStatus(): void;
|
|
99
111
|
clearDrawingStatus(): void;
|
|
100
112
|
setPolygonList(polygonList: IPolygonData[]): void;
|
|
101
|
-
setSelectedID(newID?: string): void;
|
|
113
|
+
setSelectedID(newID?: string, isAppend?: boolean): void;
|
|
102
114
|
setDefaultAttribute(defaultAttribute?: string): void;
|
|
103
115
|
setStyle(toolStyle: any): void;
|
|
104
116
|
setPolygonValidAndRender(id: string): void;
|
|
@@ -116,7 +128,7 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
116
128
|
getHoverID(e: MouseEvent): string;
|
|
117
129
|
getHoverEdgeIndex(e: MouseEvent): number;
|
|
118
130
|
getHoverPointIndex(e: MouseEvent): number;
|
|
119
|
-
|
|
131
|
+
deletePolygons(id?: string[]): void;
|
|
120
132
|
deletePolygonPoint(index: number): void;
|
|
121
133
|
spaceKeydown(): void;
|
|
122
134
|
onTabKeyDown(e: KeyboardEvent): void;
|
|
@@ -142,6 +154,11 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
142
154
|
* @returns
|
|
143
155
|
*/
|
|
144
156
|
isPolygonOutSide(selectedPointList: IPolygonPoint[]): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Update polygon position while enableDrag is true
|
|
159
|
+
* @param e {MouseEvent}
|
|
160
|
+
*/
|
|
161
|
+
onDragMove(e: MouseEvent): void;
|
|
145
162
|
/**
|
|
146
163
|
* According to the mode of dragTarget, get the offset when dragging
|
|
147
164
|
* @param e {MouseEvent}
|
|
@@ -153,11 +170,6 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
153
170
|
y: number;
|
|
154
171
|
};
|
|
155
172
|
dragPolygon(e: MouseEvent, selectedPolygon: IPolygonData): IPolygonPoint[] | undefined;
|
|
156
|
-
/**
|
|
157
|
-
* Update polygon position while enableDrag is true
|
|
158
|
-
* @param e {MouseEvent}
|
|
159
|
-
*/
|
|
160
|
-
onDragMove(e: MouseEvent): void;
|
|
161
173
|
onMouseMove(e: MouseEvent): void;
|
|
162
174
|
/**
|
|
163
175
|
* Emit updateList for views update
|
|
@@ -183,11 +195,8 @@ declare class PolygonOperation extends BasicToolOperation {
|
|
|
183
195
|
updateSelectedTextAttribute(newTextAttribute?: string): void;
|
|
184
196
|
renderTextAttribute(): void;
|
|
185
197
|
renderStaticPolygon(): void;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
* @param selectedPolygon
|
|
189
|
-
*/
|
|
190
|
-
renderSelectedPolygon(): void;
|
|
198
|
+
renderSelectedPolygons(): void;
|
|
199
|
+
renderSelectedPolygon(polygon: IPolygonData): void;
|
|
191
200
|
renderHoverPolygon(): void;
|
|
192
201
|
renderPolygon(): void;
|
|
193
202
|
render(): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
|
|
2
|
+
import TextAttributeClass from './textAttributeClass';
|
|
2
3
|
interface IRectOperationProps extends IBasicToolOperationProps {
|
|
3
4
|
drawOutSideTarget: boolean;
|
|
4
5
|
style: any;
|
|
@@ -12,11 +13,11 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
12
13
|
hoverRectID?: string;
|
|
13
14
|
hoverRectPointIndex: number;
|
|
14
15
|
hoverRectEdgeIndex: number;
|
|
15
|
-
selectedRectID?: string;
|
|
16
16
|
isFlow: boolean;
|
|
17
17
|
config: IRectConfig;
|
|
18
18
|
markerIndex: number;
|
|
19
|
-
|
|
19
|
+
_textAttributeInstance?: TextAttributeClass;
|
|
20
|
+
private selection;
|
|
20
21
|
private dragInfo?;
|
|
21
22
|
constructor(props: IRectOperationProps);
|
|
22
23
|
setResult(rectList: IRect[]): void;
|
|
@@ -28,8 +29,11 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
28
29
|
* @param isUpload
|
|
29
30
|
*/
|
|
30
31
|
setRectList(rectList: IRect[], isUpload?: boolean): void;
|
|
31
|
-
get
|
|
32
|
+
get selectedRectID(): string | undefined;
|
|
32
33
|
get selectedID(): string | undefined;
|
|
34
|
+
get selectedRect(): IRect | undefined;
|
|
35
|
+
get selectedIDs(): string[];
|
|
36
|
+
get selectedRects(): IRect[];
|
|
33
37
|
get selectedText(): string | undefined;
|
|
34
38
|
get dataList(): IRect[];
|
|
35
39
|
/**
|
|
@@ -51,7 +55,7 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
51
55
|
*/
|
|
52
56
|
getCurrentPageResult(rectList: IRect[]): IRect[];
|
|
53
57
|
setSelectedID(newID?: string): void;
|
|
54
|
-
setSelectedRectID(newID?: string): void;
|
|
58
|
+
setSelectedRectID(newID?: string, isAppend?: boolean): void;
|
|
55
59
|
setStyle(toolStyle: any): void;
|
|
56
60
|
/**
|
|
57
61
|
* 向外部提供标记的更改
|
|
@@ -78,8 +82,39 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
78
82
|
* @param attribute
|
|
79
83
|
*/
|
|
80
84
|
getTextIconSvg(attribute?: string): any;
|
|
81
|
-
multiMoveMouseDown(e: MouseEvent): boolean;
|
|
82
85
|
onMouseDown(e: MouseEvent): undefined;
|
|
86
|
+
appendOffsetRect(rect: IRect, offset: ICoordinate): {
|
|
87
|
+
x: number;
|
|
88
|
+
y: number;
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
id: string;
|
|
92
|
+
sourceID: string;
|
|
93
|
+
valid: boolean;
|
|
94
|
+
order?: number | undefined;
|
|
95
|
+
attribute: string;
|
|
96
|
+
textAttribute: string;
|
|
97
|
+
disableDelete?: boolean | undefined;
|
|
98
|
+
label?: string | undefined;
|
|
99
|
+
};
|
|
100
|
+
getRectsBoundaries(rects: IRect[], offset: ICoordinate): {
|
|
101
|
+
top: number;
|
|
102
|
+
bottom: number;
|
|
103
|
+
left: number;
|
|
104
|
+
right: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* 判断框是否超过依赖范围
|
|
108
|
+
* @param rects
|
|
109
|
+
* @param offset
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
isRectsOutOfTarget(rects: IRect[], offset: ICoordinate): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Update rect position while dragTarget is equal EDragTarget.Plane
|
|
115
|
+
* @param offset
|
|
116
|
+
*/
|
|
117
|
+
moveRects(offset: ICoordinate): void;
|
|
83
118
|
/**
|
|
84
119
|
* Offset is under zooming.
|
|
85
120
|
* @param offset
|
|
@@ -106,6 +141,7 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
106
141
|
shiftRightMouseUp(e: MouseEvent): void;
|
|
107
142
|
onMouseUp(e: MouseEvent): true | undefined;
|
|
108
143
|
onRightDblClick(e: MouseEvent): void;
|
|
144
|
+
deleteSelectedRect(): void;
|
|
109
145
|
onKeyDown(e: KeyboardEvent): true | undefined;
|
|
110
146
|
onKeyUp(e: KeyboardEvent): void;
|
|
111
147
|
onWheel(e: MouseEvent): void;
|
|
@@ -135,11 +171,6 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
135
171
|
* @param isZoom 矩形框是否为缩放后的比例
|
|
136
172
|
*/
|
|
137
173
|
renderDrawingRect(rect: IRect, zoom?: number, isZoom?: boolean): void;
|
|
138
|
-
/**
|
|
139
|
-
* Experiment. Render the multiSelected Rect
|
|
140
|
-
*
|
|
141
|
-
*/
|
|
142
|
-
renderMultiSelectedRect(): void;
|
|
143
174
|
/**
|
|
144
175
|
* 渲染静态框体
|
|
145
176
|
*/
|
|
@@ -48,6 +48,12 @@ export default class TextAttributeClass {
|
|
|
48
48
|
color: string;
|
|
49
49
|
width?: number;
|
|
50
50
|
}): void;
|
|
51
|
+
/**
|
|
52
|
+
* According to oldIDs' and newIDs' value, remove or re-render textarea
|
|
53
|
+
* @param oldIDs
|
|
54
|
+
* @param newIDs
|
|
55
|
+
*/
|
|
56
|
+
selectedIDsChanged(oldIDs: string[], newIDs: string[]): void;
|
|
51
57
|
/**
|
|
52
58
|
* 用于外层切换选中框调用
|
|
53
59
|
*/
|
|
@@ -45,10 +45,10 @@ export default class CommonToolUtils {
|
|
|
45
45
|
* @param T 当前图片的结果框
|
|
46
46
|
* @param sourceID 当前状态依赖的框体,若依赖原图则返回 '0'
|
|
47
47
|
* @param attributeLockList 当前展示的属性
|
|
48
|
-
* @param
|
|
48
|
+
* @param selectedIDs 是否含有选中逻辑
|
|
49
49
|
* @returns
|
|
50
50
|
*/
|
|
51
|
-
static getRenderResultList<T = any>(resultList: any[], sourceID: string, attributeLockList?: string[],
|
|
51
|
+
static getRenderResultList<T = any>(resultList: any[], sourceID: string, attributeLockList?: string[], selectedIDs?: string[]): [T[], T[]];
|
|
52
52
|
/**
|
|
53
53
|
* 获取当前依赖情况下的 sourceID 提取
|
|
54
54
|
*/
|
|
@@ -15,9 +15,9 @@ import LineToolOperation from '../../core/toolOperation/LineToolOperation';
|
|
|
15
15
|
import PointOperation from '../../core/toolOperation/pointOperation';
|
|
16
16
|
import TextToolOperation from '../../core/toolOperation/TextToolOperation';
|
|
17
17
|
import CommonToolUtils from './CommonToolUtils';
|
|
18
|
-
declare const getCurrentOperation: (toolName: EToolName | ECheckModel) => typeof
|
|
18
|
+
declare const getCurrentOperation: (toolName: EToolName | ECheckModel) => typeof LineToolOperation | typeof PointOperation | typeof PolygonOperation | typeof RectOperationAsNewName | typeof TagOperation | typeof TextToolOperation | typeof ScribbleTool | typeof PointCloud2dOperation | typeof CuboidOperation | typeof CheckOperation;
|
|
19
19
|
declare class EnhanceCommonToolUtils extends CommonToolUtils {
|
|
20
|
-
static getCurrentOperation: (toolName: EToolName | ECheckModel) => typeof
|
|
20
|
+
static getCurrentOperation: (toolName: EToolName | ECheckModel) => typeof LineToolOperation | typeof PointOperation | typeof PolygonOperation | typeof RectOperationAsNewName | typeof TagOperation | typeof TextToolOperation | typeof ScribbleTool | typeof PointCloud2dOperation | typeof CuboidOperation | typeof CheckOperation;
|
|
21
21
|
}
|
|
22
22
|
export { getCurrentOperation };
|
|
23
23
|
export default EnhanceCommonToolUtils;
|
|
@@ -31,7 +31,7 @@ export default class PolygonUtils {
|
|
|
31
31
|
* @returns
|
|
32
32
|
*/
|
|
33
33
|
static getPolygonByID(polygonList: IPolygonData[], id?: string): IPolygonData | undefined;
|
|
34
|
-
static getPolygonByIDs(polygonList: IPolygonData[], ids?: string[]): IPolygonData[]
|
|
34
|
+
static getPolygonByIDs(polygonList: IPolygonData[], ids?: string[]): IPolygonData[];
|
|
35
35
|
static getHoverEdgeIndex(checkPoint: ICoordinate, pointList: IPolygonPoint[], lineType?: ELineTypes, scope?: number): number;
|
|
36
36
|
/**
|
|
37
37
|
* 用于边缘吸附,获取最接近的边
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _=require("lodash"),annotation=require("../../constant/annotation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));class CommonToolUtils{static getStepInfo(t,e){return e==null?void 0:e.filter(r=>r.step===t)[0]}static getCurrentStepInfo(t,e){const r=this.getStepInfo(t,e);return r&&(r.type===annotation.EStepType.QUALITY_INSPECTION||r.type===annotation.EStepType.MANUAL_CORRECTION)?this.getCurrentStepInfo(r.dataSourceStep,e):r}static getMaxOrder(t){let e=0;return t.forEach(r=>{r.order&&r.order>e&&(e=r.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:r,type:i}=e;if(!r||!i)return!0;let n=!0;return(e.isContentEditable||r==="TEXTAREA"||(r==="INPUT"&&i!=="radio"||r==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getNextSelectedRectID(t,e=annotation.ESortDirection.ascend,r){let i=1;e===annotation.ESortDirection.descend&&(i=-1);const n=t.sort((s,c)=>s.x-c.x==0?s.y-c.y:i*(s.x-c.x)),
|
|
1
|
+
"use strict";var _=require("lodash"),annotation=require("../../constant/annotation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));class CommonToolUtils{static getStepInfo(t,e){return e==null?void 0:e.filter(r=>r.step===t)[0]}static getCurrentStepInfo(t,e){const r=this.getStepInfo(t,e);return r&&(r.type===annotation.EStepType.QUALITY_INSPECTION||r.type===annotation.EStepType.MANUAL_CORRECTION)?this.getCurrentStepInfo(r.dataSourceStep,e):r}static getMaxOrder(t){let e=0;return t.forEach(r=>{r.order&&r.order>e&&(e=r.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:r,type:i}=e;if(!r||!i)return!0;let n=!0;return(e.isContentEditable||r==="TEXTAREA"||(r==="INPUT"&&i!=="radio"||r==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getNextSelectedRectID(t,e=annotation.ESortDirection.ascend,r){let i=1;e===annotation.ESortDirection.descend&&(i=-1);const n=t.sort((s,c)=>s.x-c.x==0?s.y-c.y:i*(s.x-c.x)),a=n.findIndex(s=>s.id===r),l=n.length;return n[(a+1)%l]}static getNextSelectedRectIDByEvent(t,e,r){const i=e.shiftKey?annotation.ESortDirection.descend:annotation.ESortDirection.ascend;return this.getNextSelectedRectID(t,i,r)}static getRenderResultList(t,e,r=[],i){const n=[];return[t.filter(l=>i&&i.includes(l.id)?(n.push(l),!1):!(r.length>0&&!r.includes(l==null?void 0:l.attribute)||this.isDifferSourceID(l==null?void 0:l.sourceID,e))),n]}static getSourceID(t){var e;const r="";return t&&(e=t==null?void 0:t.id)!=null?e:r}static findAllLine(t,e=!0){const r=[],i=[...t];i.length>=3&&e===!0&&i.push(__spreadValues({},i[0]));for(let n=0;n<i.length;n++)i[n+1]&&r.push({point1:i[n],point2:i[n+1],pointIndex:n});return r}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],r){if((e==null?void 0:e.length)===0)return;let i=e.map((n,a)=>__spreadProps(__spreadValues({},n),{index:a}));if(typeof r=="number"&&r>0){const n=e[r];if(n&&t.every(a=>a.label!==n.value))return{label:n.value,index:r};i=[...i.slice(r,e.length),...i.slice(0,r)]}for(let n=0;n<i.length;n++)if(!t.some(a=>a.label===i[n].value))return{label:i[n].value,index:i[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(r=>t===r.value)}}CommonToolUtils.jsonParser=(o,t={})=>{try{return typeof o=="string"?JSON.parse(o):_.isObject(o)?o:t}catch(e){return t}},module.exports=CommonToolUtils;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,n=3,i=tool.ELineTypes.Line){let r="",l=Infinity;const o=AxisUtils.default.axisArea(e,n);return t.forEach(s=>{s.pointList&&o.forEach(u=>{const a=this.calcPolygonSize(s.pointList);this.isInPolygon(u,s.pointList,i)&&a<l&&(r=s.id,l=a)})}),r}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,n=e.reduce((i,r,l,o)=>{const s=o[(l+1)%t];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(e,t,n=tool.ELineTypes.Line){let i=0,r,l,o,s;t=[...t],n===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((a,d)=>[...a,d.x,d.y],[]),.5,!0,20)),[o]=t;const u=t.length;for(r=1;r<=u;r++)s=t[r%u],e.x>Math.min(o.x,s.x)&&e.x<=Math.max(o.x,s.x)&&e.y<=Math.max(o.y,s.y)&&o.x!==s.x&&(l=(e.x-o.x)*(s.y-o.y)/(s.x-o.x)+o.y,(o.y===s.y||e.y<=l)&&i++),o=s;return i%2!=0}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,t).map((i,r)=>{var l;const o=r/(tool.SEGMENT_NUMBER+1),s=Math.floor(o),u=(l=e[s])!=null?l:{};return __spreadValues(s===o?__spreadValues({},u):{specialEdge:u.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,n=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const r=[],l=e.slice(0);let o,s,u,a,d,h,P,E,x,m,c,g,f;for(n?(l.unshift(e[e.length-1]),l.unshift(e[e.length-2]),l.unshift(e[e.length-1]),l.unshift(e[e.length-2]),l.push(e[0]),l.push(e[1])):(l.unshift(e[1]),l.unshift(e[0]),l.push(e[e.length-2]),l.push(e[e.length-1])),f=2;f<l.length-4;f+=2)for(u=(l[f+2]-l[f-2])*t,a=(l[f+4]-l[f-0])*t,d=(l[f+3]-l[f-1])*t,h=(l[f+5]-l[f+1])*t,g=0;g<=i;g++)c=g/i,P=2*Math.pow(c,3)-3*Math.pow(c,2)+1,E=-(2*Math.pow(c,3))+3*Math.pow(c,2),x=Math.pow(c,3)-2*Math.pow(c,2)+c,m=Math.pow(c,3)-Math.pow(c,2),o=P*l[f]+E*l[f+2]+x*u+m*a,s=P*l[f+1]+E*l[f+3]+x*d+m*h,r.push(o),r.push(s);const v=[];for(let y=0;y<r.length-1;y+=2)v.push({x:r[y],y:r[y+1]});if(n)for(let y=0;y<i+1;y++){const p=v.shift();v.push(p)}return v}static getPolygonByID(e,t){return e.find(n=>n.id===t)}static getPolygonByIDs(e,t){
|
|
1
|
+
"use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,n=3,i=tool.ELineTypes.Line){let r="",l=Infinity;const o=AxisUtils.default.axisArea(e,n);return t.forEach(s=>{s.pointList&&o.forEach(u=>{const a=this.calcPolygonSize(s.pointList);this.isInPolygon(u,s.pointList,i)&&a<l&&(r=s.id,l=a)})}),r}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,n=e.reduce((i,r,l,o)=>{const s=o[(l+1)%t];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(e,t,n=tool.ELineTypes.Line){let i=0,r,l,o,s;t=[...t],n===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((a,d)=>[...a,d.x,d.y],[]),.5,!0,20)),[o]=t;const u=t.length;for(r=1;r<=u;r++)s=t[r%u],e.x>Math.min(o.x,s.x)&&e.x<=Math.max(o.x,s.x)&&e.y<=Math.max(o.y,s.y)&&o.x!==s.x&&(l=(e.x-o.x)*(s.y-o.y)/(s.x-o.x)+o.y,(o.y===s.y||e.y<=l)&&i++),o=s;return i%2!=0}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,t).map((i,r)=>{var l;const o=r/(tool.SEGMENT_NUMBER+1),s=Math.floor(o),u=(l=e[s])!=null?l:{};return __spreadValues(s===o?__spreadValues({},u):{specialEdge:u.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,n=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const r=[],l=e.slice(0);let o,s,u,a,d,h,P,E,x,m,c,g,f;for(n?(l.unshift(e[e.length-1]),l.unshift(e[e.length-2]),l.unshift(e[e.length-1]),l.unshift(e[e.length-2]),l.push(e[0]),l.push(e[1])):(l.unshift(e[1]),l.unshift(e[0]),l.push(e[e.length-2]),l.push(e[e.length-1])),f=2;f<l.length-4;f+=2)for(u=(l[f+2]-l[f-2])*t,a=(l[f+4]-l[f-0])*t,d=(l[f+3]-l[f-1])*t,h=(l[f+5]-l[f+1])*t,g=0;g<=i;g++)c=g/i,P=2*Math.pow(c,3)-3*Math.pow(c,2)+1,E=-(2*Math.pow(c,3))+3*Math.pow(c,2),x=Math.pow(c,3)-2*Math.pow(c,2)+c,m=Math.pow(c,3)-Math.pow(c,2),o=P*l[f]+E*l[f+2]+x*u+m*a,s=P*l[f+1]+E*l[f+3]+x*d+m*h,r.push(o),r.push(s);const v=[];for(let y=0;y<r.length-1;y+=2)v.push({x:r[y],y:r[y+1]});if(n)for(let y=0;y<i+1;y++){const p=v.shift();v.push(p)}return v}static getPolygonByID(e,t){return e.find(n=>n.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(n=>t.includes(n.id)):[]}static getHoverEdgeIndex(e,t,n=tool.ELineTypes.Line,i=3){let r=[...t];n===tool.ELineTypes.Curve?r=this.createSmoothCurvePoints(t.reduce((s,u)=>[...s,u.x,u.y],[]),.5,!0,tool.SEGMENT_NUMBER):n===tool.ELineTypes.Line&&r.push(r[0]);let l=-1,o=i;for(let s=0;s<r.length-1;s++){const{length:u}=MathUtils.default.getFootOfPerpendicular(e,r[s],r[s+1]);u<o&&(l=s,o=u)}return l===-1?-1:n===tool.ELineTypes.Curve?Math.floor(l/tool.SEGMENT_NUMBER):l}static getClosestPoint(e,t,n=tool.ELineTypes.Line,i=3,r){var l;let o=!1;const s=(l=r==null?void 0:r.isClose)!=null?l:!0;let u="",a=-1,d=Infinity,h=e;const P=20;let E=!1;return t.forEach(x=>{if(!E&&!!x.pointList)switch(n){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(x.pointList,s).forEach((c,g)=>{if(E)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,c.point1,c.point2);const y=MathUtils.default.getLineLength(c.point1,e),p=MathUtils.default.getLineLength(c.point2,e);y<i*2&&(v=c.point1,f=y,E=!0),p<i*2&&(v=c.point2,f=p,E=!0),f<d&&f<i&&(u=x.id,a=g,d=f,h=v,o=!0)});break;case tool.ELineTypes.Curve:{const m=this.createSmoothCurvePoints(x.pointList.reduce((c,g)=>[...c,g.x,g.y],[]),.5,s,P);for(let c=0;c<m.length-1;c++){const{length:g,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,m[c],m[c+1]);g<d&&g<i&&(u=x.id,a=Math.floor(c/(P+1)),d=g,h=f,o=!0)}}break}}),{dropFoot:h,closestEdgeIndex:a,closestPolygonID:u,hasClosed:o}}static isPointListInPolygon(e,t,n=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,n))}static isPointListOutSidePolygon(e,t,n=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,n))}static getPolygonArea(e){let t=0;for(let n=0,i=e.length;n<i;n++){const r=e[n].x,l=e[n===e.length-1?0:n+1].y,o=e[n===e.length-1?0:n+1].x,s=e[n].y;t+=r*l*.5,t-=o*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,n){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,n)}static deletePolygonLastPoint(e,t,n,i){return n===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var n,i;try{let r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(o=>[o.x,o.y]))]]);return t.forEach(o=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(o.pointList.map(a=>[a.x,a.y]))]]),u=turf.difference(r,s);u&&(r=u)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(o=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?o[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):o.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((o,s)=>{const u=s.length,a=s.filter((d,h)=>{const P=(h+1)%u;return!AxisUtils.default.getIsInScope(d,s[P],1)});return a.length<3?o:[...o,a]},[])}catch(r){console.error(r)}}static getPolygonPointList(e,t){const n=t.find(i=>i.id===e);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(n=>PolygonUtils.isPointListInPolygon(e,n.pointList))}static clipPolygonFromWrapPolygon(e,t){const n=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),r=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),l=t[r];let o=[...t.slice(0,r),l,...e,e[0],...t.slice(r,t.length)];return n===i&&(o=[...t.slice(0,r),l,e[0],...e.reverse(),...t.slice(r,t.length)]),o}static isPolygonClosewise(e){const t=e.length;let n,i,r,l=0,o;if(t<3)return 0;for(n=0;n<t;n++)i=(n+1)%t,r=(n+2)%t,o=(e[i].x-e[n].x)*(e[r].y-e[i].y),o-=(e[i].y-e[n].y)*(e[r].x-e[i].x),o<0?l--:o>0&&l++;return l>0?1:l<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let n=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((r,l)=>{const o=LineToolUtils.default.calcDistance(e,r);o<n&&(n=o,i=l)}),i}static combinePolygonWithPolygon(e,t){var n,i;try{const r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(a=>[a.x,a.y]))]]),l=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(a=>[a.x,a.y]))]]),o=turf.union(r,l),s=[],u=e;if(((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(t.id);const a=o==null?void 0:o.geometry.coordinates.map(d=>{var h;return((h=o==null?void 0:o.geometry)==null?void 0:h.type)==="MultiPolygon"?d[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):d.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];u.pointList=a}return{newPolygon:u,unionList:s}}catch(r){console.error(r)}}}module.exports=PolygonUtils;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PointCloudUtils as
|
|
1
|
+
import{PointCloudUtils as u}from"@labelbee/lb-utils";import{EToolName as m,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,d=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},p=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class J{constructor({size:t,container:o,pcdPath:a,extraProps:L,config:O,checkMode:b,toolName:h,proxyMode:_}){this.updateLineList=s=>{const l=(s!=null?s:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(c=>d({i:c},u.transferWorld2Canvas(c,this.toolInstance.size)));return p(d({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(m.Line,l)},this.updatePolygonList=(s,l)=>{let i=s.map(e=>{var r;const{polygon2d:c}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:c,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return p(d({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(c=>u.transferWorld2Canvas(c,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(m.PointCloudPolygon,i)},this.updatePointList=s=>{const l=s==null?void 0:s.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return p(d({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(m.Point,l)};const D=this.getDefaultOrthographic(t),T=S(t),g=new Image;g.src=T;const C=new B({container:o,size:t,toolName:h,proxyMode:_}),v=new A({container:o}),P=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});a&&P.loadPCDFile(a),v.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(d({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:b};L&&Object.assign(I,L);let f=[];E.isSingleTool(h)?f=[h]:f=h,f.forEach((s,l)=>{let i;if(s===m.PointCloudPolygon){const e=C.createOperation(s,g,I);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=C.createOperation(s,g,p(d({},I),{textConfigurable:!1}));l===f.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=v,this.toolScheduler=C,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(d({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}getDefaultOrthographic(t){return{left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100}}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(t)),this.pointCloudInstance.render();const o=S(t),a=new Image;a.src=o,a.onload=()=>{this.toolInstance.setImgNode(a),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=u.getBoxParamsFromResultList(t),a=u.getPolygonListFromResultList(t);this.updatePolygonList(o,a)}addLineListOnTopView(t){const o=u.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=u.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,a){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,a==null?void 0:a.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{J as PointCloudAnnotation};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as b,EPerspectiveView as w,PointCloudUtils as
|
|
1
|
+
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as b,EPerspectiveView as w,PointCloudUtils as k,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import L from"../../_virtual/highlightWorker.js";import N from"../../_virtual/filterBoxWorker.js";import{isInPolygon as E}from"../../utils/tool/polygonTool.js";import O from"../../utils/uuid.js";import F from"../../utils/MathUtils.js";import{PCDLoader as R}from"./PCDLoader.js";import{OrbitControls as W}from"./OrbitControls.js";import{PointCloudCache as Z}from"./cache.js";import{getCuboidFromPointCloudBox as A}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../scheduler.js";var H=Object.defineProperty,U=Object.defineProperties,G=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,j=(f,t,e)=>t in f?H(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,M=(f,t)=>{for(var e in t||(t={}))$.call(t,e)&&j(f,e,t[e]);if(_)for(var e of _(t))X.call(t,e)&&j(f,e,t[e]);return f},P=(f,t)=>U(f,G(t)),S=(f,t,e)=>new Promise((r,o)=>{var s=n=>{try{i(e.next(n))}catch(h){o(h)}},a=n=>{try{i(e.throw(n))}catch(h){o(h)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);i((e=e.apply(f,t)).next())});const Y=30,D=new L({type:"module"});class q{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:o,backgroundColor:s="#4C4C4C",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.addSphereToSense=(i,n="blue")=>{var h;const l=(h=i.id)!=null?h:O();this.removeObjectByName(l);const{radius:d,widthSegments:p,heightSegments:g}=z,{center:x}=i,u=new c.Group,m=new c.SphereGeometry(d,p,g),C=new c.MeshBasicMaterial({color:n}),y=new c.Mesh(m,C);y.position.set(x.x,x.y,x.z),u.add(y),u.name=l,this.scene.add(u)},this.generateSphere=i=>{const{fill:n}=B.getColorFromConfig({attribute:i.attribute},P(M({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(i,n),this.render()},this.generateSpheres=i=>{i.forEach(n=>{const{fill:h}=B.getColorFromConfig({attribute:n.attribute},P(M({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(n,h)}),this.render()},this.addBoxToSense=(i,n=16777215)=>{var h;const l=(h=i.id)!=null?h:O();this.removeObjectByName(l);const{center:d,width:p,height:g,depth:x,rotation:u}=i,m=new c.Group,C=new c.BoxGeometry(p,g,x),y=new c.MeshBasicMaterial({color:"blue"}),v=new c.Mesh(C,y),I=new c.BoxHelper(v,n),V=this.generateBoxArrow(i),T=this.generateBoxTrackID(i);T&&m.add(T),m.add(I),m.add(V),d&&m.position.set(d.x,d.y,d.z),u&&m.rotation.set(0,0,u),m.name=l,this.scene.add(m)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const n=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,n)}},this.overridePointShader=i=>{i.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
@@ -8,4 +8,4 @@ import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as
|
|
|
8
8
|
varying float vVisible;
|
|
9
9
|
${i.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
|
|
10
10
|
if (vVisible < 0.5) discard;
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>S(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:l}=yield this.cacheInstance.loadPCDFile(i),d=new c.BufferGeometry;d.setAttribute("position",new c.BufferAttribute(h,3)),d.setAttribute("color",new c.BufferAttribute(l,3));const p=new c.Points(d);this.renderPointCloud(p,o)}),this.loadPCDFileByBox=(i,o,h)=>S(this,null,function*(){const l=(g,x)=>S(this,null,function*(){const{width:u=0,height:m=0,depth:C=0}=h!=null?h:{},y=yield this.filterPointsByBox(P(M({},o),{width:o.width+u,height:o.height+m,depth:o.depth+C}),g,x);if(!y){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new c.Points(y.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:d,color:p}=yield this.cacheInstance.loadPCDFile(i);l(d,p)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new c.Vector3(1,0,0),h=new c.Vector3(i/2,0,0),l=2,d=16776960,p=new c.ArrowHelper(o,h,l,d);return p.visible=this.showDirection,p},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new c.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const h=new c.SpriteMaterial({map:o,depthWrite:!1}),l=new c.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const h=o.material.size;i?o.material.size=Math.min(h*1.2,10):o.material.size=Math.max(h/1.2,1),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new R(this.camera,this.renderer.domElement),this.pcdLoader=new E,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=W.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,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:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}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 c.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 c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=B.getColorFromConfig({attribute:r.attribute},P(M({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,p=500/l;return{left:a,right:i,top:o,bottom:h,near:l,far:d,zoom:p}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:a,depth:i,rotation:o}=t,h=this.getCameraVector(n,o,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,n),new c.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,n),h)}updateCameraBySphere(t,e){const{center:r}=t,{radius:n}=z,s=this.getCameraVector(r,0,{width:n*2,height:n*2,depth:n*2},e);return this.updateCamera(s,r),s}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateOrthoCameraBySphere(t,e){const r=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}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 c.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 c.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:h}=A(t),l=e;r=r!=null?r:new Float32Array([]);const d={boxParams:t,zMin:i,zMax:o,polygonPointList:h,color:r,position:l};return new Promise(p=>{const g=new L;g.postMessage(d),g.onmessage=x=>{const{color:u,position:m,num:C}=x.data,y=new c.BufferGeometry;y.setAttribute("position",new c.Float32BufferAttribute(m,3)),y.setAttribute("color",new c.Float32BufferAttribute(u,3)),y.computeBoundingSphere(),g.terminate(),p({geometry:y,num:C})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=w.Front,s=X){let a=b.frontViewMatrix4(s);switch(n){case w.Front:break;case w.Back:a=b.backViewMatrix4(s);break;case w.Left:a=b.leftViewMatrix4(s);break;case w.Right:a=b.rightViewMatrix4(s);break;case w.Top:a=b.topViewMatrix4(s);break;case w.LFT:a=b.leftFrontTopViewMatrix4(s,r);break;case w.RBT:a=b.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new c.BufferGeometry().setFromPoints(r),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new c.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>A(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};j.postMessage(i),j.onmessage=o=>{const{color:h}=o.data,l=new c.BufferAttribute(h,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0),l.needsUpdate=!0,e.geometry.setAttribute("color",l),r(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new c.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((d,p)=>d.z-p.z);const r=Math.floor(e.length*.05),n=e[r];e=e.filter(({z:d})=>d>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((d,p)=>d.x-p.x);const i=Math.floor(e.length*s),o=Math.floor(e.length*(1-s));e=e.slice(i,o),e.sort((d,p)=>d.y-p.y);const h=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(h,l),e.length>100?e:t}getFittedCoordinates(t,e){const r=[];let n=[...t,t[0]];e.forEach(({x:i,y:o})=>{t.forEach((h,l)=>{const d=n[l+1],p=F.getFootOfPerpendicular({x:i,y:o},h,d,!1,!0).length;(!r[l]||p<r[l].distance)&&(r[l]={distance:p,point:{x:i,y:o}})})}),n=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,o)=>{const h=n[o],l=n[o+1],d=n[o+2];return D.getIntersectionBySlope({p1:s[o].point,line1:[h,l],p2:s[o+1].point,line2:[l,d]})})}getSensesPointZAxisInPolygon(t,e,r){var n,s,a;const i=this.scene.children.find(u=>u.uuid===this.pointsUuid);let o=0,h=0,l=0,d=0,p=[],g=[];const x=((a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let u=0;u<x.length;u+=3){const m=x[u],C=x[u+1],y=x[u+2];N({x:m,y:C},t)&&(y||y===0)&&g.push({x:m,y:C,z:y})}return g.length?(r&&(g=this.filterNoise(g),p=this.getFittedCoordinates(t,g)),g.sort((u,m)=>u.z-m.z),o=g[0].z-.01,h=g[g.length-1].z+.01,d=g.length,e&&(l=g.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:h,minZ:o,count:l,zCount:d,fittedCoordinates:p}):{maxZ:h,minZ:o,count:l,zCount:d,fittedCoordinates:p}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new c.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,r=this.containerHeight/2;return new c.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},h={x:e+a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2},d={x:e-a/2,y:r+s/2,z:n-i/2};return[o,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n-i/2},d={x:e-a/2,y:r-s/2,z:n+i/2};return[o,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e+a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r-s/2,z:n+i/2},d={x:e-a/2,y:r+s/2,z:n+i/2};return[o,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-r,-n),i=new c.Matrix4().makeTranslation(e,r,n),o=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,w.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,w.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case w.Left:return this.getPolygonSidePoints(t);case w.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(h,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:n,valid:s}=t,{radius:a}=z,i={center:e,attribute:r,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},o=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(o).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=h;const l=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),p=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,p)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:r}=z,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new c.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=P(M({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=P(M({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(m=>new c.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(a)),[o,h,l,d]=i,p=Math.max(Math.abs(o.x-l.x),Math.abs(o.x-h.x)),x=h.add(d).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:P(M({},n),{center:{x:n.center.x-x.x,y:n.center.y-x.y,z:n.center.z-r},width:p,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{Y as PointCloud};
|
|
11
|
+
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,n)=>S(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:l}=yield this.cacheInstance.loadPCDFile(i),d=new c.BufferGeometry;d.setAttribute("position",new c.BufferAttribute(h,3)),d.setAttribute("color",new c.BufferAttribute(l,3));const p=new c.Points(d);this.renderPointCloud(p,n)}),this.loadPCDFileByBox=(i,n,h)=>S(this,null,function*(){const l=(g,x)=>S(this,null,function*(){const{width:u=0,height:m=0,depth:C=0}=h!=null?h:{},y=yield this.filterPointsByBox(P(M({},n),{width:n.width+u,height:n.height+m,depth:n.depth+C}),g,x);if(!y){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new c.Points(y.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:d,color:p}=yield this.cacheInstance.loadPCDFile(i);l(d,p)}),this.generateRange=i=>{const n=this.createRange(i);this.scene.add(n)},this.generateBoxArrow=({width:i})=>{const n=new c.Vector3(1,0,0),h=new c.Vector3(i/2,0,0),l=2,d=16776960,p=new c.ArrowHelper(n,h,l,d);return p.visible=this.showDirection,p},this.generateBoxTrackID=i=>{if(!i.trackID)return;const n=new c.Texture(this.getTextCanvas(i.trackID.toString()));n.needsUpdate=!0;const h=new c.SpriteMaterial({map:n,depthWrite:!1}),l=new c.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:i,customSize:n})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const l=h.material.size;i?h.material.size=Math.min(l*1.2,10):h.material.size=Math.max(l/1.2,1),n&&(h.material.size=n,this.pointsMaterialSize=n),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&o?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(o.left,o.right,o.top,o.bottom,o.near,o.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new W(this.camera,this.renderer.domElement),this.pcdLoader=new R,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Z.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:o,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=o,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,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:r,z:o}=this.initCameraPosition;t.position.set(e,r,o)}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 c.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 c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.addBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=B.getColorFromConfig({attribute:r.attribute},P(M({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:o}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,n=e.y+o/2+s,h=e.y-o/2-s,l=100,d=-100,p=500/l;return{left:a,right:i,top:n,bottom:h,near:l,far:d,zoom:p}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:o,width:s,height:a,depth:i,rotation:n}=t,h=this.getCameraVector(o,n,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,o),new c.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,o),h)}updateCameraBySphere(t,e){const{center:r}=t,{radius:o}=z,s=this.getCameraVector(r,0,{width:o*2,height:o*2,depth:o*2},e);return this.updateCamera(s,r),s}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateOrthoCameraBySphere(t,e){const r=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}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 c.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 c.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e,r){var o,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(o=i==null?void 0:i.geometry)==null?void 0:o.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:n,polygonPointList:h}=A(t),l=e;r=r!=null?r:new Float32Array([]);const d={boxParams:t,zMin:i,zMax:n,polygonPointList:h,color:r,position:l};return new Promise(p=>{const g=new N;g.postMessage(d),g.onmessage=x=>{const{color:u,position:m,num:C}=x.data,y=new c.BufferGeometry;y.setAttribute("position",new c.Float32BufferAttribute(m,3)),y.setAttribute("color",new c.Float32BufferAttribute(u,3)),y.computeBoundingSphere(),g.terminate(),p({geometry:y,num:C})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,o=w.Front,s=Y){let a=b.frontViewMatrix4(s);switch(o){case w.Front:break;case w.Back:a=b.backViewMatrix4(s);break;case w.Left:a=b.leftViewMatrix4(s);break;case w.Right:a=b.rightViewMatrix4(s);break;case w.Top:a=b.topViewMatrix4(s);break;case w.LFT:a=b.leftFrontTopViewMatrix4(s,r);break;case w.RBT:a=b.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),n=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(n).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),o=new c.BufferGeometry().setFromPoints(r),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(o,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new c.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=this.pointsMaterialSize,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const a=(t?[...t]:[]).map(h=>A(h)),i=this.getAllAttributeColor(a),n={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:i};D.postMessage(n),D.onmessage=h=>{const{color:l}=h.data,d=new c.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==l.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,d.needsUpdate=!0,e.geometry.setAttribute("color",d),r(l),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new c.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((d,p)=>d.z-p.z);const r=Math.floor(e.length*.05),o=e[r];e=e.filter(({z:d})=>d>o.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((d,p)=>d.x-p.x);const i=Math.floor(e.length*s),n=Math.floor(e.length*(1-s));e=e.slice(i,n),e.sort((d,p)=>d.y-p.y);const h=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(h,l),e.length>100?e:t}getFittedCoordinates(t,e){const r=[];let o=[...t,t[0]];e.forEach(({x:i,y:n})=>{t.forEach((h,l)=>{const d=o[l+1],p=F.getFootOfPerpendicular({x:i,y:n},h,d,!1,!0).length;(!r[l]||p<r[l].distance)&&(r[l]={distance:p,point:{x:i,y:n}})})}),o=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,n)=>{const h=o[n],l=o[n+1],d=o[n+2];return k.getIntersectionBySlope({p1:s[n].point,line1:[h,l],p2:s[n+1].point,line2:[l,d]})})}getSensesPointZAxisInPolygon(t,e,r){var o,s,a;const i=this.scene.children.find(u=>u.uuid===this.pointsUuid);let n=0,h=0,l=0,d=0,p=[],g=[];const x=((a=(s=(o=i==null?void 0:i.geometry)==null?void 0:o.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let u=0;u<x.length;u+=3){const m=x[u],C=x[u+1],y=x[u+2];E({x:m,y:C},t)&&(y||y===0)&&g.push({x:m,y:C,z:y})}return g.length?(r&&(g=this.filterNoise(g),p=this.getFittedCoordinates(t,g)),g.sort((u,m)=>u.z-m.z),n=g[0].z-.01,h=g[g.length-1].z+.01,d=g.length,e&&(l=g.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:h,minZ:n,count:l,zCount:d,fittedCoordinates:p}):{maxZ:h,minZ:n,count:l,zCount:d,fittedCoordinates:p}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new c.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,r=this.containerHeight/2;return new c.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o-i/2},h={x:e+a/2,y:r+s/2,z:o+i/2},l={x:e-a/2,y:r+s/2,z:o+i/2},d={x:e-a/2,y:r+s/2,z:o-i/2};return[n,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e-a/2,y:r+s/2,z:o+i/2},h={x:e-a/2,y:r+s/2,z:o-i/2},l={x:e-a/2,y:r-s/2,z:o-i/2},d={x:e-a/2,y:r-s/2,z:o+i/2};return[n,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o+i/2},h={x:e+a/2,y:r-s/2,z:o+i/2},l={x:e-a/2,y:r-s/2,z:o+i/2},d={x:e-a/2,y:r+s/2,z:o+i/2};return[n,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:o},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-r,-o),i=new c.Matrix4().makeTranslation(e,r,o),n=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(i).multiply(n).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,w.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,w.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case w.Left:return this.getPolygonSidePoints(t);case w.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:o,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const n=r.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/o,l=this.containerHeight/s;return{polygon2d:n,zoom:Math.min(h,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:o,valid:s}=t,{radius:a}=z,i={center:e,attribute:r,id:o,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},n=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(n).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=h;const l=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),p=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,p)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:r}=z,o={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:o,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(n=>new c.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.getModelTransformationMatrix(t))).map(n=>({x:n.y,y:n.x})).map(n=>({x:-(n.x-this.containerWidth/2),y:-(n.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,o){const s=new c.Matrix4().makeRotationZ(o.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=P(M({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,o){const s=new c.Matrix4().makeRotationZ(o.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=P(M({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,o){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(m=>new c.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(a)),[n,h,l,d]=i,p=Math.max(Math.abs(n.x-l.x),Math.abs(n.x-h.x)),x=h.add(d).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(o.center.x,o.center.y,o.center.z));return{newBoxParams:P(M({},o),{center:{x:o.center.x-x.x,y:o.center.y-x.y,z:o.center.z-r},width:p,height:o.height,depth:o.depth+e,rotation:o.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:o}=r,s=[],{count:a}=o;for(let i=0;i<a;i++){const n=o.getZ(i);s.push(n>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{q as PointCloud};
|