@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.3
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/MathUtilsWorker.js +8 -1
- package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
- package/dist/_virtual/filterBoxWorker.js +8 -1
- package/dist/_virtual/highlightWorker.js +8 -1
- package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
- package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
- package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
- package/dist/constant/annotation.js +127 -1
- package/dist/constant/annotationTask.js +30 -1
- package/dist/constant/defaultConfig.js +266 -1
- package/dist/constant/keyCode.js +38 -1
- package/dist/constant/style.js +98 -1
- package/dist/constant/tool.js +236 -1
- package/dist/core/index.js +150 -1
- package/dist/core/pointCloud/OrbitControls.js +665 -1
- package/dist/core/pointCloud/PCDLoader.js +260 -2
- package/dist/core/pointCloud/annotation.js +215 -1
- package/dist/core/pointCloud/cache.js +53 -1
- package/dist/core/pointCloud/index.js +991 -5
- package/dist/core/pointCloud/matrix.js +138 -1
- package/dist/core/pointCloud/segmentation.js +144 -0
- package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
- package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
- package/dist/core/scheduler.js +233 -1
- package/dist/core/toolOperation/LineToolOperation.js +1434 -1
- package/dist/core/toolOperation/ScribbleTool.js +292 -1
- package/dist/core/toolOperation/TextToolOperation.js +131 -1
- package/dist/core/toolOperation/ViewOperation.js +556 -1
- package/dist/core/toolOperation/basicToolOperation.js +881 -1
- package/dist/core/toolOperation/checkOperation.js +208 -1
- package/dist/core/toolOperation/cuboidOperation.js +754 -1
- package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
- package/dist/core/toolOperation/eventListener.js +37 -1
- package/dist/core/toolOperation/measureOperation.js +41 -1
- package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
- package/dist/core/toolOperation/pointOperation.js +696 -1
- package/dist/core/toolOperation/polygonOperation.js +1251 -1
- package/dist/core/toolOperation/rectOperation.js +1233 -1
- package/dist/core/toolOperation/segmentByRect.js +174 -1
- package/dist/core/toolOperation/tagOperation.js +201 -3
- package/dist/core/toolOperation/textAttributeClass.js +182 -16
- package/dist/index.js +185 -1
- package/dist/locales/constants.js +24 -1
- package/dist/locales/en_US/message.js +25 -1
- package/dist/locales/index.js +19 -1
- package/dist/locales/zh_CN/message.js +25 -1
- package/dist/newCore/CanvasScheduler.js +35 -1
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
- package/dist/utils/ActionsHistory.js +84 -1
- package/dist/utils/ImgUtils.js +23 -1
- package/dist/utils/MathUtils.js +385 -2
- package/dist/utils/VectorUtils.js +25 -1
- package/dist/utils/tool/AttributeUtils.js +218 -1
- package/dist/utils/tool/AxisUtils.js +340 -1
- package/dist/utils/tool/CanvasUtils.js +62 -1
- package/dist/utils/tool/CommonToolUtils.js +174 -1
- package/dist/utils/tool/CuboidUtils.js +704 -1
- package/dist/utils/tool/DblClickEventListener.js +102 -1
- package/dist/utils/tool/DrawUtils.js +492 -3
- package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
- package/dist/utils/tool/ImgPosUtils.js +58 -1
- package/dist/utils/tool/LineToolUtils.js +261 -1
- package/dist/utils/tool/MarkerUtils.js +56 -1
- package/dist/utils/tool/PolygonUtils.js +460 -1
- package/dist/utils/tool/RectUtils.js +155 -1
- package/dist/utils/tool/RenderDomClass.js +57 -7
- package/dist/utils/tool/RenderDomUtils.js +21 -4
- package/dist/utils/tool/StyleUtils.js +31 -1
- package/dist/utils/tool/TagUtils.js +129 -1
- package/dist/utils/tool/UnitUtils.js +12 -1
- package/dist/utils/tool/ZoomUtils.js +72 -1
- package/dist/utils/tool/polygonTool.js +133 -1
- package/dist/utils/uuid.js +26 -1
- package/es/_virtual/MathUtilsWorker.js +6 -1
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/_virtual/filterBoxWorker.js +6 -1
- package/es/_virtual/highlightWorker.js +6 -1
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
- package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
- package/es/constant/annotation.js +113 -1
- package/es/constant/annotationTask.js +25 -1
- package/es/constant/defaultConfig.js +260 -1
- package/es/constant/keyCode.js +36 -1
- package/es/constant/style.js +74 -1
- package/es/constant/tool.js +220 -1
- package/es/core/index.js +148 -1
- package/es/core/pointCloud/OrbitControls.js +661 -1
- package/es/core/pointCloud/PCDLoader.js +256 -2
- package/es/core/pointCloud/annotation.js +211 -1
- package/es/core/pointCloud/cache.js +49 -1
- package/es/core/pointCloud/index.js +962 -5
- package/es/core/pointCloud/matrix.js +109 -1
- package/es/core/pointCloud/segmentation.js +120 -0
- package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
- package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
- package/es/core/scheduler.js +228 -1
- package/es/core/toolOperation/LineToolOperation.js +1421 -1
- package/es/core/toolOperation/ScribbleTool.js +290 -1
- package/es/core/toolOperation/TextToolOperation.js +129 -1
- package/es/core/toolOperation/ViewOperation.js +549 -1
- package/es/core/toolOperation/basicToolOperation.js +877 -1
- package/es/core/toolOperation/checkOperation.js +206 -1
- package/es/core/toolOperation/cuboidOperation.js +752 -1
- package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
- package/es/core/toolOperation/eventListener.js +35 -1
- package/es/core/toolOperation/measureOperation.js +39 -1
- package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
- package/es/core/toolOperation/pointOperation.js +690 -1
- package/es/core/toolOperation/polygonOperation.js +1245 -1
- package/es/core/toolOperation/rectOperation.js +1228 -1
- package/es/core/toolOperation/scribbleTool2.js +249 -0
- package/es/core/toolOperation/segmentByRect.js +172 -1
- package/es/core/toolOperation/tagOperation.js +199 -3
- package/es/core/toolOperation/textAttributeClass.js +180 -16
- package/es/index.js +46 -1
- package/es/locales/constants.js +22 -1
- package/es/locales/en_US/message.js +23 -1
- package/es/locales/index.js +17 -1
- package/es/locales/zh_CN/message.js +23 -1
- package/es/newCore/CanvasScheduler.js +31 -1
- package/es/utils/ActionsHistory.js +78 -1
- package/es/utils/ImgUtils.js +21 -1
- package/es/utils/MathUtils.js +380 -2
- package/es/utils/VectorUtils.js +23 -1
- package/es/utils/tool/AttributeUtils.js +212 -1
- package/es/utils/tool/AxisUtils.js +335 -1
- package/es/utils/tool/CanvasUtils.js +60 -1
- package/es/utils/tool/CommonToolUtils.js +172 -1
- package/es/utils/tool/CuboidUtils.js +680 -1
- package/es/utils/tool/DblClickEventListener.js +100 -1
- package/es/utils/tool/DrawUtils.js +490 -3
- package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
- package/es/utils/tool/ImgPosUtils.js +56 -1
- package/es/utils/tool/LineToolUtils.js +255 -1
- package/es/utils/tool/MarkerUtils.js +54 -1
- package/es/utils/tool/PolygonUtils.js +458 -1
- package/es/utils/tool/RectUtils.js +153 -1
- package/es/utils/tool/RenderDomClass.js +55 -7
- package/es/utils/tool/RenderDomUtils.js +19 -4
- package/es/utils/tool/StyleUtils.js +29 -1
- package/es/utils/tool/TagUtils.js +127 -1
- package/es/utils/tool/UnitUtils.js +10 -1
- package/es/utils/tool/ZoomUtils.js +70 -1
- package/es/utils/tool/polygonTool.js +126 -1
- package/es/utils/uuid.js +24 -1
- package/package.json +7 -5
|
@@ -1,2 +1,256 @@
|
|
|
1
|
-
import{Loader
|
|
2
|
-
|
|
1
|
+
import { Loader, FileLoader, LoaderUtils, BufferGeometry, Float32BufferAttribute, PointsMaterial, Points } from 'three';
|
|
2
|
+
import { COLOR_MAP_JET } from '@labelbee/lb-utils';
|
|
3
|
+
|
|
4
|
+
class PCDLoader extends Loader {
|
|
5
|
+
constructor(manager) {
|
|
6
|
+
super(manager);
|
|
7
|
+
this.littleEndian = true;
|
|
8
|
+
}
|
|
9
|
+
load(url, onLoad, onProgress, onError) {
|
|
10
|
+
const scope = this;
|
|
11
|
+
const loader = new FileLoader(scope.manager);
|
|
12
|
+
loader.setPath(scope.path);
|
|
13
|
+
loader.setResponseType("arraybuffer");
|
|
14
|
+
loader.setRequestHeader(scope.requestHeader);
|
|
15
|
+
loader.setWithCredentials(scope.withCredentials);
|
|
16
|
+
loader.load(url, function(data) {
|
|
17
|
+
try {
|
|
18
|
+
onLoad(scope.parse(data));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (onError) {
|
|
21
|
+
onError(e);
|
|
22
|
+
} else {
|
|
23
|
+
console.error(e);
|
|
24
|
+
}
|
|
25
|
+
scope.manager.itemError(url);
|
|
26
|
+
}
|
|
27
|
+
}, onProgress, onError);
|
|
28
|
+
}
|
|
29
|
+
parse(data) {
|
|
30
|
+
function decompressLZF(inData, outLength) {
|
|
31
|
+
const inLength = inData.length;
|
|
32
|
+
const outData = new Uint8Array(outLength);
|
|
33
|
+
let inPtr = 0;
|
|
34
|
+
let outPtr = 0;
|
|
35
|
+
let ctrl;
|
|
36
|
+
let len;
|
|
37
|
+
let ref;
|
|
38
|
+
do {
|
|
39
|
+
ctrl = inData[inPtr++];
|
|
40
|
+
if (ctrl < 1 << 5) {
|
|
41
|
+
ctrl++;
|
|
42
|
+
if (outPtr + ctrl > outLength)
|
|
43
|
+
throw new Error("Output buffer is not large enough");
|
|
44
|
+
if (inPtr + ctrl > inLength)
|
|
45
|
+
throw new Error("Invalid compressed data");
|
|
46
|
+
do {
|
|
47
|
+
outData[outPtr++] = inData[inPtr++];
|
|
48
|
+
} while (--ctrl);
|
|
49
|
+
} else {
|
|
50
|
+
len = ctrl >> 5;
|
|
51
|
+
ref = outPtr - ((ctrl & 31) << 8) - 1;
|
|
52
|
+
if (inPtr >= inLength)
|
|
53
|
+
throw new Error("Invalid compressed data");
|
|
54
|
+
if (len === 7) {
|
|
55
|
+
len += inData[inPtr++];
|
|
56
|
+
if (inPtr >= inLength)
|
|
57
|
+
throw new Error("Invalid compressed data");
|
|
58
|
+
}
|
|
59
|
+
ref -= inData[inPtr++];
|
|
60
|
+
if (outPtr + len + 2 > outLength)
|
|
61
|
+
throw new Error("Output buffer is not large enough");
|
|
62
|
+
if (ref < 0)
|
|
63
|
+
throw new Error("Invalid compressed data");
|
|
64
|
+
if (ref >= outPtr)
|
|
65
|
+
throw new Error("Invalid compressed data");
|
|
66
|
+
do {
|
|
67
|
+
outData[outPtr++] = outData[ref++];
|
|
68
|
+
} while (--len + 2);
|
|
69
|
+
}
|
|
70
|
+
} while (inPtr < inLength);
|
|
71
|
+
return outData;
|
|
72
|
+
}
|
|
73
|
+
function parseHeader(data2) {
|
|
74
|
+
const PCDheader2 = {};
|
|
75
|
+
const result1 = data2.search(/[\n\r]data\s(\S*)\s/i);
|
|
76
|
+
const result2 = /[\n\r]data\s(\S*)\s/i.exec(data2.slice(result1 - 1));
|
|
77
|
+
PCDheader2.data = result2[1];
|
|
78
|
+
PCDheader2.headerLen = result2[0].length + result1;
|
|
79
|
+
PCDheader2.str = data2.slice(0, PCDheader2.headerLen);
|
|
80
|
+
PCDheader2.str = PCDheader2.str.replace(/#.*/gi, "");
|
|
81
|
+
PCDheader2.version = /version (.*)/i.exec(PCDheader2.str);
|
|
82
|
+
PCDheader2.fields = /fields (.*)/i.exec(PCDheader2.str);
|
|
83
|
+
PCDheader2.size = /size (.*)/i.exec(PCDheader2.str);
|
|
84
|
+
PCDheader2.type = /type (.*)/i.exec(PCDheader2.str);
|
|
85
|
+
PCDheader2.count = /count (.*)/i.exec(PCDheader2.str);
|
|
86
|
+
PCDheader2.width = /width (.*)/i.exec(PCDheader2.str);
|
|
87
|
+
PCDheader2.height = /height (.*)/i.exec(PCDheader2.str);
|
|
88
|
+
PCDheader2.viewpoint = /viewpoint (.*)/i.exec(PCDheader2.str);
|
|
89
|
+
PCDheader2.points = /points (.*)/i.exec(PCDheader2.str);
|
|
90
|
+
if (PCDheader2.version !== null)
|
|
91
|
+
PCDheader2.version = parseFloat(PCDheader2.version[1]);
|
|
92
|
+
PCDheader2.fields = PCDheader2.fields !== null ? PCDheader2.fields[1].split(" ") : [];
|
|
93
|
+
if (PCDheader2.type !== null)
|
|
94
|
+
PCDheader2.type = PCDheader2.type[1].split(" ");
|
|
95
|
+
if (PCDheader2.width !== null)
|
|
96
|
+
PCDheader2.width = parseInt(PCDheader2.width[1]);
|
|
97
|
+
if (PCDheader2.height !== null)
|
|
98
|
+
PCDheader2.height = parseInt(PCDheader2.height[1]);
|
|
99
|
+
if (PCDheader2.viewpoint !== null)
|
|
100
|
+
PCDheader2.viewpoint = PCDheader2.viewpoint[1];
|
|
101
|
+
if (PCDheader2.points !== null)
|
|
102
|
+
PCDheader2.points = parseInt(PCDheader2.points[1], 10);
|
|
103
|
+
if (PCDheader2.points === null)
|
|
104
|
+
PCDheader2.points = PCDheader2.width * PCDheader2.height;
|
|
105
|
+
if (PCDheader2.size !== null) {
|
|
106
|
+
PCDheader2.size = PCDheader2.size[1].split(" ").map(function(x) {
|
|
107
|
+
return parseInt(x, 10);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (PCDheader2.count !== null) {
|
|
111
|
+
PCDheader2.count = PCDheader2.count[1].split(" ").map(function(x) {
|
|
112
|
+
return parseInt(x, 10);
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
PCDheader2.count = [];
|
|
116
|
+
for (let i = 0, l = PCDheader2.fields.length; i < l; i++) {
|
|
117
|
+
PCDheader2.count.push(1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
PCDheader2.offset = {};
|
|
121
|
+
let sizeSum = 0;
|
|
122
|
+
for (let i = 0, l = PCDheader2.fields.length; i < l; i++) {
|
|
123
|
+
if (PCDheader2.data === "ascii") {
|
|
124
|
+
PCDheader2.offset[PCDheader2.fields[i]] = i;
|
|
125
|
+
} else {
|
|
126
|
+
PCDheader2.offset[PCDheader2.fields[i]] = sizeSum;
|
|
127
|
+
sizeSum += PCDheader2.size[i] * PCDheader2.count[i];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
PCDheader2.rowSize = sizeSum;
|
|
131
|
+
return PCDheader2;
|
|
132
|
+
}
|
|
133
|
+
const textData = LoaderUtils.decodeText(new Uint8Array(data));
|
|
134
|
+
const PCDheader = parseHeader(textData);
|
|
135
|
+
const position = [];
|
|
136
|
+
const normal = [];
|
|
137
|
+
const color = [];
|
|
138
|
+
if (PCDheader.data === "ascii") {
|
|
139
|
+
const {offset} = PCDheader;
|
|
140
|
+
const pcdData = textData.slice(PCDheader.headerLen);
|
|
141
|
+
const lines = pcdData.split("\n");
|
|
142
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
|
143
|
+
if (lines[i] === "")
|
|
144
|
+
continue;
|
|
145
|
+
const line = lines[i].split(" ");
|
|
146
|
+
if (offset.x !== void 0) {
|
|
147
|
+
position.push(parseFloat(line[offset.x]));
|
|
148
|
+
position.push(parseFloat(line[offset.y]));
|
|
149
|
+
position.push(parseFloat(line[offset.z]));
|
|
150
|
+
}
|
|
151
|
+
if (this.genColorByZ) {
|
|
152
|
+
const pdColor = this.genColorByZ(parseFloat(line[offset.x]), parseFloat(line[offset.y]), parseFloat(line[offset.z]));
|
|
153
|
+
const pdColorUnit8 = pdColor.map((hex) => hex / 255);
|
|
154
|
+
color.push(...pdColorUnit8);
|
|
155
|
+
}
|
|
156
|
+
if (offset.normal_x !== void 0) {
|
|
157
|
+
normal.push(parseFloat(line[offset.normal_x]));
|
|
158
|
+
normal.push(parseFloat(line[offset.normal_y]));
|
|
159
|
+
normal.push(parseFloat(line[offset.normal_z]));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (PCDheader.data === "binary_compressed") {
|
|
164
|
+
const sizes = new Uint32Array(data.slice(PCDheader.headerLen, PCDheader.headerLen + 8));
|
|
165
|
+
const compressedSize = sizes[0];
|
|
166
|
+
const decompressedSize = sizes[1];
|
|
167
|
+
const decompressed = decompressLZF(new Uint8Array(data, PCDheader.headerLen + 8, compressedSize), decompressedSize);
|
|
168
|
+
const dataview = new DataView(decompressed.buffer);
|
|
169
|
+
const {offset} = PCDheader;
|
|
170
|
+
for (let i = 0; i < PCDheader.points; i++) {
|
|
171
|
+
if (offset.x !== void 0) {
|
|
172
|
+
position.push(dataview.getFloat32(PCDheader.points * offset.x + PCDheader.size[0] * i, this.littleEndian));
|
|
173
|
+
position.push(dataview.getFloat32(PCDheader.points * offset.y + PCDheader.size[1] * i, this.littleEndian));
|
|
174
|
+
position.push(dataview.getFloat32(PCDheader.points * offset.z + PCDheader.size[2] * i, this.littleEndian));
|
|
175
|
+
}
|
|
176
|
+
if (offset.normal_x !== void 0) {
|
|
177
|
+
normal.push(dataview.getFloat32(PCDheader.points * offset.normal_x + PCDheader.size[4] * i, this.littleEndian));
|
|
178
|
+
normal.push(dataview.getFloat32(PCDheader.points * offset.normal_y + PCDheader.size[5] * i, this.littleEndian));
|
|
179
|
+
normal.push(dataview.getFloat32(PCDheader.points * offset.normal_z + PCDheader.size[6] * i, this.littleEndian));
|
|
180
|
+
}
|
|
181
|
+
if (this.genColorByZ) {
|
|
182
|
+
const pdColor = this.genColorByZ(dataview.getFloat32(PCDheader.points * offset.x + PCDheader.size[0] * i, this.littleEndian), dataview.getFloat32(PCDheader.points * offset.y + PCDheader.size[0] * i, this.littleEndian), dataview.getFloat32(PCDheader.points * offset.z + PCDheader.size[0] * i, this.littleEndian));
|
|
183
|
+
const pdColorUnit8 = pdColor.map((hex) => hex / 255);
|
|
184
|
+
color.push(...pdColorUnit8);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (PCDheader.data === "binary") {
|
|
189
|
+
const dataview = new DataView(data, PCDheader.headerLen);
|
|
190
|
+
const {offset} = PCDheader;
|
|
191
|
+
for (let i = 0, row = 0; i < PCDheader.points; i++, row += PCDheader.rowSize) {
|
|
192
|
+
if (offset.x !== void 0) {
|
|
193
|
+
position.push(dataview.getFloat32(row + offset.x, this.littleEndian));
|
|
194
|
+
position.push(dataview.getFloat32(row + offset.y, this.littleEndian));
|
|
195
|
+
position.push(dataview.getFloat32(row + offset.z, this.littleEndian));
|
|
196
|
+
}
|
|
197
|
+
if (offset.normal_x !== void 0) {
|
|
198
|
+
normal.push(dataview.getFloat32(row + offset.normal_x, this.littleEndian));
|
|
199
|
+
normal.push(dataview.getFloat32(row + offset.normal_y, this.littleEndian));
|
|
200
|
+
normal.push(dataview.getFloat32(row + offset.normal_z, this.littleEndian));
|
|
201
|
+
}
|
|
202
|
+
if (this.genColorByZ) {
|
|
203
|
+
const pdColor = this.genColorByZ(dataview.getFloat32(row + offset.x, this.littleEndian), dataview.getFloat32(row + offset.y, this.littleEndian), dataview.getFloat32(row + offset.z, this.littleEndian));
|
|
204
|
+
const pdColorUnit8 = pdColor.map((hex) => hex / 255);
|
|
205
|
+
color.push(...pdColorUnit8);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const geometry = new BufferGeometry();
|
|
210
|
+
if (position.length > 0)
|
|
211
|
+
geometry.setAttribute("position", new Float32BufferAttribute(position, 3));
|
|
212
|
+
if (normal.length > 0)
|
|
213
|
+
geometry.setAttribute("normal", new Float32BufferAttribute(normal, 3));
|
|
214
|
+
if (color.length > 0)
|
|
215
|
+
geometry.setAttribute("color", new Float32BufferAttribute(color, 3));
|
|
216
|
+
geometry.computeBoundingSphere();
|
|
217
|
+
const material = new PointsMaterial({size: 0.01});
|
|
218
|
+
if (color.length > 0) {
|
|
219
|
+
material.vertexColors = true;
|
|
220
|
+
} else {
|
|
221
|
+
material.color.setHex(16777215);
|
|
222
|
+
}
|
|
223
|
+
return new Points(geometry, material);
|
|
224
|
+
}
|
|
225
|
+
genColorByCoord(x, y, z) {
|
|
226
|
+
if (z <= 0) {
|
|
227
|
+
return [128, 128, 128];
|
|
228
|
+
}
|
|
229
|
+
if (z < 5) {
|
|
230
|
+
return [255, 0, 0];
|
|
231
|
+
}
|
|
232
|
+
if (z < 10) {
|
|
233
|
+
return [0, 255, 0];
|
|
234
|
+
}
|
|
235
|
+
return [0, 0, 255];
|
|
236
|
+
}
|
|
237
|
+
genColorByZ(x, y, z) {
|
|
238
|
+
const index = getIndex(z);
|
|
239
|
+
const color = COLOR_MAP_JET[index];
|
|
240
|
+
return [color[0], color[1], color[2]];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function getIndex(z) {
|
|
244
|
+
const minZ = -7;
|
|
245
|
+
const maxZ = 3;
|
|
246
|
+
const len = maxZ - minZ;
|
|
247
|
+
if (z < minZ) {
|
|
248
|
+
z = minZ;
|
|
249
|
+
}
|
|
250
|
+
if (z > maxZ) {
|
|
251
|
+
z = maxZ;
|
|
252
|
+
}
|
|
253
|
+
return Math.floor((z - minZ) / len * 255);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export { PCDLoader };
|
|
@@ -1 +1,211 @@
|
|
|
1
|
-
import{PointCloudUtils
|
|
1
|
+
import { PointCloudUtils } from '@labelbee/lb-utils';
|
|
2
|
+
import { EToolName, EPolygonPattern } from '../../constant/tool.js';
|
|
3
|
+
import { CanvasScheduler } from '../../newCore/CanvasScheduler.js';
|
|
4
|
+
import { PointCloud } from './index.js';
|
|
5
|
+
import { ToolScheduler, HybridToolUtils } from '../scheduler.js';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defProps = Object.defineProperties;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
const createEmptyImage = (size) => {
|
|
27
|
+
const canvas = document.createElement("canvas");
|
|
28
|
+
canvas.width = size.width;
|
|
29
|
+
canvas.height = size.height;
|
|
30
|
+
const ctx = canvas.getContext("2d");
|
|
31
|
+
if (ctx) {
|
|
32
|
+
ctx.fillStyle = "black";
|
|
33
|
+
ctx.fillRect(0, 0, size.width, size.height);
|
|
34
|
+
return canvas.toDataURL();
|
|
35
|
+
}
|
|
36
|
+
return "";
|
|
37
|
+
};
|
|
38
|
+
class PointCloudAnnotation {
|
|
39
|
+
constructor({size, container, pcdPath, extraProps, config, checkMode, toolName}) {
|
|
40
|
+
this.updateLineList = (lineList) => {
|
|
41
|
+
const list = lineList.map((v) => {
|
|
42
|
+
var _a;
|
|
43
|
+
return __spreadProps(__spreadValues({}, v), {
|
|
44
|
+
pointList: (_a = v == null ? void 0 : v.pointList) == null ? void 0 : _a.map((point) => PointCloudUtils.transferWorld2Canvas(point, this.toolInstance.size))
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
this.toolScheduler.updateDataByToolName(EToolName.Line, list);
|
|
48
|
+
};
|
|
49
|
+
this.updatePolygonList = (pointCloudDataList, extraList) => {
|
|
50
|
+
let polygonList = pointCloudDataList.map((v) => {
|
|
51
|
+
var _a;
|
|
52
|
+
const {polygon2d: pointList} = this.pointCloudInstance.getBoxTopPolygon2DCoordinate(v);
|
|
53
|
+
return {
|
|
54
|
+
id: v.id,
|
|
55
|
+
sourceID: "",
|
|
56
|
+
pointList,
|
|
57
|
+
isRect: true,
|
|
58
|
+
valid: (_a = v.valid) != null ? _a : true,
|
|
59
|
+
attribute: v.attribute
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
if (extraList) {
|
|
63
|
+
polygonList = polygonList.concat(extraList.map((v) => {
|
|
64
|
+
var _a;
|
|
65
|
+
return __spreadProps(__spreadValues({}, v), {
|
|
66
|
+
pointList: (_a = v == null ? void 0 : v.pointList) == null ? void 0 : _a.map((point) => PointCloudUtils.transferWorld2Canvas(point, this.toolInstance.size))
|
|
67
|
+
});
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
this.toolScheduler.updateDataByToolName(EToolName.PointCloudPolygon, polygonList);
|
|
71
|
+
};
|
|
72
|
+
this.updatePointList = (sphereList) => {
|
|
73
|
+
const pointList = sphereList == null ? void 0 : sphereList.map((v) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const {point2d} = this.pointCloudInstance.getSphereTopPoint2DCoordinate(v);
|
|
76
|
+
return __spreadProps(__spreadValues({}, point2d), {
|
|
77
|
+
id: v.id,
|
|
78
|
+
sourceID: "",
|
|
79
|
+
valid: (_a = v.valid) != null ? _a : true,
|
|
80
|
+
attribute: v.attribute,
|
|
81
|
+
textAttribute: ""
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
this.toolScheduler.updateDataByToolName(EToolName.Point, pointList);
|
|
85
|
+
};
|
|
86
|
+
const defaultOrthographic = this.getDefaultOrthographic(size);
|
|
87
|
+
const imgSrc = createEmptyImage(size);
|
|
88
|
+
const image = new Image();
|
|
89
|
+
image.src = imgSrc;
|
|
90
|
+
const toolScheduler = new ToolScheduler({container, size, toolName});
|
|
91
|
+
const canvasScheduler = new CanvasScheduler({container});
|
|
92
|
+
const pointCloud = new PointCloud({
|
|
93
|
+
container,
|
|
94
|
+
noAppend: true,
|
|
95
|
+
isOrthographicCamera: true,
|
|
96
|
+
orthographicParams: defaultOrthographic
|
|
97
|
+
});
|
|
98
|
+
if (pcdPath) {
|
|
99
|
+
pointCloud.loadPCDFile(pcdPath);
|
|
100
|
+
}
|
|
101
|
+
canvasScheduler.createCanvas(pointCloud.renderer.domElement);
|
|
102
|
+
const defaultProps = {
|
|
103
|
+
size,
|
|
104
|
+
config: JSON.stringify(__spreadProps(__spreadValues({}, config), {attributeConfigurable: true, hideAttribute: true})),
|
|
105
|
+
imgNode: image,
|
|
106
|
+
checkMode
|
|
107
|
+
};
|
|
108
|
+
if (extraProps) {
|
|
109
|
+
Object.assign(defaultProps, extraProps);
|
|
110
|
+
}
|
|
111
|
+
let toolList = [];
|
|
112
|
+
if (HybridToolUtils.isSingleTool(toolName)) {
|
|
113
|
+
toolList = [toolName];
|
|
114
|
+
} else {
|
|
115
|
+
toolList = toolName;
|
|
116
|
+
}
|
|
117
|
+
toolList.forEach((tool, i) => {
|
|
118
|
+
let toolInstance;
|
|
119
|
+
if (tool === EToolName.PointCloudPolygon) {
|
|
120
|
+
const pointCloudPolygonOperation = toolScheduler.createOperation(tool, image, defaultProps);
|
|
121
|
+
pointCloudPolygonOperation.eventBinding();
|
|
122
|
+
pointCloudPolygonOperation.setPattern(EPolygonPattern.Rect);
|
|
123
|
+
this.toolInstance = pointCloudPolygonOperation;
|
|
124
|
+
this.toolInstance.eventBinding();
|
|
125
|
+
this.pointCloud2dOperation = pointCloudPolygonOperation;
|
|
126
|
+
} else {
|
|
127
|
+
toolInstance = toolScheduler.createOperation(tool, image, defaultProps);
|
|
128
|
+
}
|
|
129
|
+
if (i === toolList.length - 1) {
|
|
130
|
+
if (!this.toolInstance) {
|
|
131
|
+
this.toolInstance = toolInstance;
|
|
132
|
+
this.toolInstance.eventBinding();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
this.pointCloudInstance = pointCloud;
|
|
137
|
+
this.canvasScheduler = canvasScheduler;
|
|
138
|
+
this.toolScheduler = toolScheduler;
|
|
139
|
+
this.config = config;
|
|
140
|
+
}
|
|
141
|
+
updateConfig(config) {
|
|
142
|
+
this.config = config;
|
|
143
|
+
this.pointCloud2dOperation.setConfig(JSON.stringify(config));
|
|
144
|
+
}
|
|
145
|
+
getDefaultOrthographic(size) {
|
|
146
|
+
return {
|
|
147
|
+
left: -size.width / 2,
|
|
148
|
+
right: size.width / 2,
|
|
149
|
+
top: size.height / 2,
|
|
150
|
+
bottom: -size.height / 2,
|
|
151
|
+
near: 100,
|
|
152
|
+
far: -100
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
initSize(size) {
|
|
156
|
+
this.pointCloudInstance.updateTopCamera();
|
|
157
|
+
this.pointCloudInstance.setDefaultControls();
|
|
158
|
+
this.pointCloudInstance.initRenderer();
|
|
159
|
+
this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(size));
|
|
160
|
+
this.pointCloudInstance.render();
|
|
161
|
+
const imgSrc = createEmptyImage(size);
|
|
162
|
+
const image = new Image();
|
|
163
|
+
image.src = imgSrc;
|
|
164
|
+
image.onload = () => {
|
|
165
|
+
this.toolInstance.setImgNode(image);
|
|
166
|
+
this.toolInstance.initImgPos();
|
|
167
|
+
};
|
|
168
|
+
this.pointCloud2dOperation.setCanvasSize(size);
|
|
169
|
+
}
|
|
170
|
+
addPolygonListOnTopView(result) {
|
|
171
|
+
const pointCloudDataList = PointCloudUtils.getBoxParamsFromResultList(result);
|
|
172
|
+
const polygonList = PointCloudUtils.getPolygonListFromResultList(result);
|
|
173
|
+
this.updatePolygonList(pointCloudDataList, polygonList);
|
|
174
|
+
}
|
|
175
|
+
addLineListOnTopView(result) {
|
|
176
|
+
const lineList = PointCloudUtils.getLineListFromResultList(result);
|
|
177
|
+
this.updateLineList(lineList);
|
|
178
|
+
}
|
|
179
|
+
addPointListOnTopView(result) {
|
|
180
|
+
const sphereList = PointCloudUtils.getSphereParamsFromResultList(result);
|
|
181
|
+
this.updatePointList(sphereList);
|
|
182
|
+
}
|
|
183
|
+
updateData(pcdPath, result, config) {
|
|
184
|
+
if (!this.toolInstance || !this.pointCloudInstance) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.pointCloudInstance.loadPCDFile(pcdPath, config == null ? void 0 : config.radius);
|
|
188
|
+
this.addPolygonListOnTopView(result);
|
|
189
|
+
this.addLineListOnTopView(result);
|
|
190
|
+
this.addPointListOnTopView(result);
|
|
191
|
+
}
|
|
192
|
+
switchToCanvas(toolName) {
|
|
193
|
+
const newInstance = this.toolScheduler.switchToCanvas(toolName);
|
|
194
|
+
if (newInstance) {
|
|
195
|
+
newInstance.eventBinding();
|
|
196
|
+
this.toolInstance = newInstance;
|
|
197
|
+
return newInstance;
|
|
198
|
+
}
|
|
199
|
+
return this.toolInstance;
|
|
200
|
+
}
|
|
201
|
+
initAllPosition() {
|
|
202
|
+
this.pointCloudInstance.updateTopCamera();
|
|
203
|
+
this.pointCloud2dOperation.initPosition();
|
|
204
|
+
}
|
|
205
|
+
clearAllData() {
|
|
206
|
+
this.pointCloudInstance.clearPointCloudAndRender();
|
|
207
|
+
this.pointCloud2dOperation.clearResult();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { PointCloudAnnotation };
|
|
@@ -1 +1,49 @@
|
|
|
1
|
-
import{PCDLoader
|
|
1
|
+
import { PCDLoader } from './PCDLoader.js';
|
|
2
|
+
|
|
3
|
+
class PointCloudCache {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.MAX_SIZE = 50;
|
|
6
|
+
this.cacheList = [];
|
|
7
|
+
this.loadPCDFile = (src) => {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const clonePoints = this.pointsMap.get(src);
|
|
10
|
+
const cloneColor = this.colorMap.get(src);
|
|
11
|
+
if (clonePoints && cloneColor) {
|
|
12
|
+
resolve({points: clonePoints, color: cloneColor});
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (this.cacheList.length > this.MAX_SIZE) {
|
|
16
|
+
const firstCacheInfo = this.cacheList.shift();
|
|
17
|
+
if (firstCacheInfo) {
|
|
18
|
+
this.pointsMap.delete(firstCacheInfo.src);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
this.cacheList.push({src});
|
|
22
|
+
this.pcdLoader.load(src, (points) => {
|
|
23
|
+
const pointsArray = points.geometry.attributes.position.array;
|
|
24
|
+
const colorArray = points.geometry.attributes.color.array;
|
|
25
|
+
this.pointsMap.set(src, pointsArray);
|
|
26
|
+
this.colorMap.set(src, colorArray);
|
|
27
|
+
resolve({points: pointsArray, color: colorArray});
|
|
28
|
+
}, () => {
|
|
29
|
+
}, (err) => {
|
|
30
|
+
reject(err);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
this.pcdLoader = new PCDLoader();
|
|
35
|
+
this.pointsMap = new Map();
|
|
36
|
+
this.colorMap = new Map();
|
|
37
|
+
}
|
|
38
|
+
static getInstance() {
|
|
39
|
+
if (this.instance == null) {
|
|
40
|
+
this.instance = new PointCloudCache();
|
|
41
|
+
}
|
|
42
|
+
return this.instance;
|
|
43
|
+
}
|
|
44
|
+
updateColor(src, color) {
|
|
45
|
+
this.colorMap.set(src, color);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { PointCloudCache };
|