@labelbee/lb-annotation 1.14.0-alpha.3 → 1.14.0-alpha.6

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