@loaders.gl/pcd 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (68) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +93 -487
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +45 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/decompress-lzf.js +57 -0
  8. package/dist/es5/lib/decompress-lzf.js.map +1 -0
  9. package/dist/es5/lib/get-pcd-schema.js +54 -0
  10. package/dist/es5/lib/get-pcd-schema.js.map +1 -0
  11. package/dist/es5/lib/parse-pcd.js +299 -0
  12. package/dist/es5/lib/parse-pcd.js.map +1 -0
  13. package/dist/es5/lib/pcd-types.js +2 -0
  14. package/dist/es5/lib/pcd-types.js.map +1 -0
  15. package/dist/es5/pcd-loader.js +21 -0
  16. package/dist/es5/pcd-loader.js.map +1 -0
  17. package/dist/es5/workers/pcd-worker.js +6 -0
  18. package/dist/es5/workers/pcd-worker.js.map +1 -0
  19. package/dist/esm/bundle.js +4 -0
  20. package/dist/esm/bundle.js.map +1 -0
  21. package/dist/esm/index.js +10 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/lib/decompress-lzf.js +51 -0
  24. package/dist/esm/lib/decompress-lzf.js.map +1 -0
  25. package/dist/esm/lib/get-pcd-schema.js +48 -0
  26. package/dist/esm/lib/get-pcd-schema.js.map +1 -0
  27. package/dist/esm/lib/parse-pcd.js +289 -0
  28. package/dist/esm/lib/parse-pcd.js.map +1 -0
  29. package/dist/esm/lib/pcd-types.js +2 -0
  30. package/dist/esm/lib/pcd-types.js.map +1 -0
  31. package/dist/esm/pcd-loader.js +14 -0
  32. package/dist/esm/pcd-loader.js.map +1 -0
  33. package/dist/esm/workers/pcd-worker.js +4 -0
  34. package/dist/esm/workers/pcd-worker.js.map +1 -0
  35. package/dist/index.d.ts +3 -25
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +17 -8
  38. package/dist/lib/decompress-lzf.d.ts.map +1 -1
  39. package/dist/lib/decompress-lzf.js +61 -43
  40. package/dist/lib/get-pcd-schema.d.ts +1 -3
  41. package/dist/lib/get-pcd-schema.d.ts.map +1 -1
  42. package/dist/lib/get-pcd-schema.js +32 -19
  43. package/dist/lib/parse-pcd.d.ts +2 -11
  44. package/dist/lib/parse-pcd.d.ts.map +1 -1
  45. package/dist/lib/parse-pcd.js +304 -260
  46. package/dist/lib/pcd-types.d.ts +12 -12
  47. package/dist/lib/pcd-types.d.ts.map +1 -1
  48. package/dist/lib/pcd-types.js +2 -2
  49. package/dist/pcd-loader.d.ts +3 -14
  50. package/dist/pcd-loader.d.ts.map +1 -1
  51. package/dist/pcd-loader.js +21 -14
  52. package/dist/pcd-worker.js +140 -466
  53. package/dist/workers/pcd-worker.js +5 -4
  54. package/package.json +6 -6
  55. package/src/index.ts +3 -2
  56. package/src/lib/decompress-lzf.ts +21 -7
  57. package/src/lib/get-pcd-schema.ts +15 -10
  58. package/src/lib/parse-pcd.ts +95 -42
  59. package/src/lib/pcd-types.ts +9 -9
  60. package/src/pcd-loader.ts +5 -4
  61. package/dist/bundle.js.map +0 -1
  62. package/dist/index.js.map +0 -1
  63. package/dist/lib/decompress-lzf.js.map +0 -1
  64. package/dist/lib/get-pcd-schema.js.map +0 -1
  65. package/dist/lib/parse-pcd.js.map +0 -1
  66. package/dist/lib/pcd-types.js.map +0 -1
  67. package/dist/pcd-loader.js.map +0 -1
  68. package/dist/workers/pcd-worker.js.map +0 -1
@@ -1,244 +1,282 @@
1
- import { getMeshBoundingBox } from '@loaders.gl/schema';
2
- import { decompressLZF } from './decompress-lzf';
3
- import { getPCDSchema } from './get-pcd-schema';
1
+ "use strict";
2
+ // PCD Loader, adapted from THREE.js (MIT license)
3
+ // Description: A loader for PCD ascii and binary files.
4
+ // Limitations: Compressed binary files are not supported.
5
+ //
6
+ // Attributions per original THREE.js source file:
7
+ // @author Filipe Caixeta / http://filipecaixeta.com.br
8
+ // @author Mugen87 / https://github.com/Mugen87
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const schema_1 = require("@loaders.gl/schema");
11
+ const decompress_lzf_1 = require("./decompress-lzf");
12
+ const get_pcd_schema_1 = require("./get-pcd-schema");
4
13
  const LITTLE_ENDIAN = true;
5
- export default function parsePCD(data) {
6
- const textData = new TextDecoder().decode(data);
7
- const pcdHeader = parsePCDHeader(textData);
8
- let attributes = {};
9
-
10
- switch (pcdHeader.data) {
11
- case 'ascii':
12
- attributes = parsePCDASCII(pcdHeader, textData);
13
- break;
14
-
15
- case 'binary':
16
- attributes = parsePCDBinary(pcdHeader, data);
17
- break;
18
-
19
- case 'binary_compressed':
20
- attributes = parsePCDBinaryCompressed(pcdHeader, data);
21
- break;
22
-
23
- default:
24
- throw new Error("PCD: ".concat(pcdHeader.data, " files are not supported"));
25
- }
26
-
27
- attributes = getMeshAttributes(attributes);
28
- const header = getMeshHeader(pcdHeader, attributes);
29
- const metadata = new Map([['mode', '0'], ['boundingBox', JSON.stringify(header.boundingBox)]]);
30
- const schema = getPCDSchema(pcdHeader, metadata);
31
- return {
32
- loaderData: {
33
- header: pcdHeader
34
- },
35
- header,
36
- schema,
37
- mode: 0,
38
- indices: null,
39
- attributes
40
- };
14
+ /**
15
+ *
16
+ * @param data
17
+ * @returns
18
+ */
19
+ function parsePCD(data) {
20
+ // parse header (always ascii format)
21
+ const textData = new TextDecoder().decode(data);
22
+ const pcdHeader = parsePCDHeader(textData);
23
+ let attributes = {};
24
+ // parse data
25
+ switch (pcdHeader.data) {
26
+ case 'ascii':
27
+ attributes = parsePCDASCII(pcdHeader, textData);
28
+ break;
29
+ case 'binary':
30
+ attributes = parsePCDBinary(pcdHeader, data);
31
+ break;
32
+ case 'binary_compressed':
33
+ attributes = parsePCDBinaryCompressed(pcdHeader, data);
34
+ break;
35
+ default:
36
+ throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
37
+ }
38
+ attributes = getMeshAttributes(attributes);
39
+ const header = getMeshHeader(pcdHeader, attributes);
40
+ const metadata = Object.fromEntries([
41
+ ['mode', '0'],
42
+ ['boundingBox', JSON.stringify(header.boundingBox)]
43
+ ]);
44
+ const schema = (0, get_pcd_schema_1.getPCDSchema)(pcdHeader, metadata);
45
+ return {
46
+ loader: 'pcd',
47
+ loaderData: pcdHeader,
48
+ header,
49
+ schema,
50
+ mode: 0,
51
+ topology: 'point-list',
52
+ attributes
53
+ };
41
54
  }
42
-
55
+ exports.default = parsePCD;
56
+ // Create a header that contains common data for PointCloud category loaders
43
57
  function getMeshHeader(pcdHeader, attributes) {
44
- if (typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
45
- const pointCount = pcdHeader.width * pcdHeader.height;
58
+ if (typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
59
+ const pointCount = pcdHeader.width * pcdHeader.height; // Supports "organized" point sets
60
+ return {
61
+ vertexCount: pointCount,
62
+ boundingBox: (0, schema_1.getMeshBoundingBox)(attributes)
63
+ };
64
+ }
46
65
  return {
47
- vertexCount: pointCount,
48
- boundingBox: getMeshBoundingBox(attributes)
66
+ vertexCount: pcdHeader.vertexCount,
67
+ boundingBox: pcdHeader.boundingBox
49
68
  };
50
- }
51
-
52
- return pcdHeader;
53
69
  }
54
-
70
+ /**
71
+ * @param attributes
72
+ * @returns Normalized attributes
73
+ */
55
74
  function getMeshAttributes(attributes) {
56
- const normalizedAttributes = {
57
- POSITION: {
58
- value: new Float32Array(attributes.position),
59
- size: 3
60
- }
61
- };
62
-
63
- if (attributes.normal && attributes.normal.length > 0) {
64
- normalizedAttributes.NORMAL = {
65
- value: new Float32Array(attributes.normal),
66
- size: 3
75
+ const normalizedAttributes = {
76
+ POSITION: {
77
+ // Binary PCD is only 32 bit
78
+ value: new Float32Array(attributes.position),
79
+ size: 3
80
+ }
67
81
  };
68
- }
69
-
70
- if (attributes.color && attributes.color.length > 0) {
71
- normalizedAttributes.COLOR_0 = {
72
- value: new Uint8Array(attributes.color),
73
- size: 3
74
- };
75
- }
76
-
77
- return normalizedAttributes;
82
+ if (attributes.normal && attributes.normal.length > 0) {
83
+ normalizedAttributes.NORMAL = {
84
+ value: new Float32Array(attributes.normal),
85
+ size: 3
86
+ };
87
+ }
88
+ if (attributes.color && attributes.color.length > 0) {
89
+ // TODO - RGBA
90
+ normalizedAttributes.COLOR_0 = {
91
+ value: new Uint8Array(attributes.color),
92
+ size: 3
93
+ };
94
+ }
95
+ if (attributes.intensity && attributes.intensity.length > 0) {
96
+ // TODO - RGBA
97
+ normalizedAttributes.COLOR_0 = {
98
+ value: new Uint8Array(attributes.color),
99
+ size: 3
100
+ };
101
+ }
102
+ if (attributes.label && attributes.label.length > 0) {
103
+ // TODO - RGBA
104
+ normalizedAttributes.COLOR_0 = {
105
+ value: new Uint8Array(attributes.label),
106
+ size: 3
107
+ };
108
+ }
109
+ return normalizedAttributes;
78
110
  }
79
-
111
+ /**
112
+ * Incoming data parsing
113
+ * @param data
114
+ * @returns Header
115
+ */
116
+ /* eslint-disable complexity, max-statements */
80
117
  function parsePCDHeader(data) {
81
- const result1 = data.search(/[\r\n]DATA\s(\S*)\s/i);
82
- const result2 = /[\r\n]DATA\s(\S*)\s/i.exec(data.substr(result1 - 1));
83
- const pcdHeader = {};
84
- pcdHeader.data = result2 && result2[1];
85
-
86
- if (result2 !== null) {
87
- pcdHeader.headerLen = (result2 && result2[0].length) + result1;
88
- }
89
-
90
- pcdHeader.str = data.substr(0, pcdHeader.headerLen);
91
- pcdHeader.str = pcdHeader.str.replace(/\#.*/gi, '');
92
- pcdHeader.version = /VERSION (.*)/i.exec(pcdHeader.str);
93
- pcdHeader.fields = /FIELDS (.*)/i.exec(pcdHeader.str);
94
- pcdHeader.size = /SIZE (.*)/i.exec(pcdHeader.str);
95
- pcdHeader.type = /TYPE (.*)/i.exec(pcdHeader.str);
96
- pcdHeader.count = /COUNT (.*)/i.exec(pcdHeader.str);
97
- pcdHeader.width = /WIDTH (.*)/i.exec(pcdHeader.str);
98
- pcdHeader.height = /HEIGHT (.*)/i.exec(pcdHeader.str);
99
- pcdHeader.viewpoint = /VIEWPOINT (.*)/i.exec(pcdHeader.str);
100
- pcdHeader.points = /POINTS (.*)/i.exec(pcdHeader.str);
101
-
102
- if (pcdHeader.version !== null) {
103
- pcdHeader.version = parseFloat(pcdHeader.version[1]);
104
- }
105
-
106
- if (pcdHeader.fields !== null) {
107
- pcdHeader.fields = pcdHeader.fields[1].split(' ');
108
- }
109
-
110
- if (pcdHeader.type !== null) {
111
- pcdHeader.type = pcdHeader.type[1].split(' ');
112
- }
113
-
114
- if (pcdHeader.width !== null) {
115
- pcdHeader.width = parseInt(pcdHeader.width[1], 10);
116
- }
117
-
118
- if (pcdHeader.height !== null) {
119
- pcdHeader.height = parseInt(pcdHeader.height[1], 10);
120
- }
121
-
122
- if (pcdHeader.viewpoint !== null) {
123
- pcdHeader.viewpoint = pcdHeader.viewpoint[1];
124
- }
125
-
126
- if (pcdHeader.points !== null) {
127
- pcdHeader.points = parseInt(pcdHeader.points[1], 10);
128
- }
129
-
130
- if (pcdHeader.points === null && typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
131
- pcdHeader.points = pcdHeader.width * pcdHeader.height;
132
- }
133
-
134
- if (pcdHeader.size !== null) {
135
- pcdHeader.size = pcdHeader.size[1].split(' ').map(x => parseInt(x, 10));
136
- }
137
-
138
- if (pcdHeader.count !== null) {
139
- pcdHeader.count = pcdHeader.count[1].split(' ').map(x => parseInt(x, 10));
140
- } else {
141
- pcdHeader.count = [];
142
-
118
+ const result1 = data.search(/[\r\n]DATA\s(\S*)\s/i);
119
+ const result2 = /[\r\n]DATA\s(\S*)\s/i.exec(data.substr(result1 - 1));
120
+ const pcdHeader = {};
121
+ pcdHeader.data = result2 && result2[1];
122
+ if (result2 !== null) {
123
+ pcdHeader.headerLen = (result2 && result2[0].length) + result1;
124
+ }
125
+ pcdHeader.str = data.substr(0, pcdHeader.headerLen);
126
+ // remove comments
127
+ pcdHeader.str = pcdHeader.str.replace(/\#.*/gi, '');
128
+ // parse
129
+ pcdHeader.version = /VERSION (.*)/i.exec(pcdHeader.str);
130
+ pcdHeader.fields = /FIELDS (.*)/i.exec(pcdHeader.str);
131
+ pcdHeader.size = /SIZE (.*)/i.exec(pcdHeader.str);
132
+ pcdHeader.type = /TYPE (.*)/i.exec(pcdHeader.str);
133
+ pcdHeader.count = /COUNT (.*)/i.exec(pcdHeader.str);
134
+ pcdHeader.width = /WIDTH (.*)/i.exec(pcdHeader.str);
135
+ pcdHeader.height = /HEIGHT (.*)/i.exec(pcdHeader.str);
136
+ pcdHeader.viewpoint = /VIEWPOINT (.*)/i.exec(pcdHeader.str);
137
+ pcdHeader.points = /POINTS (.*)/i.exec(pcdHeader.str);
138
+ // evaluate
139
+ if (pcdHeader.version !== null) {
140
+ pcdHeader.version = parseFloat(pcdHeader.version[1]);
141
+ }
143
142
  if (pcdHeader.fields !== null) {
144
- for (let i = 0; i < pcdHeader.fields.length; i++) {
145
- pcdHeader.count.push(1);
146
- }
143
+ pcdHeader.fields = pcdHeader.fields[1].split(' ');
144
+ }
145
+ if (pcdHeader.type !== null) {
146
+ pcdHeader.type = pcdHeader.type[1].split(' ');
147
+ }
148
+ if (pcdHeader.width !== null) {
149
+ pcdHeader.width = parseInt(pcdHeader.width[1], 10);
150
+ }
151
+ if (pcdHeader.height !== null) {
152
+ pcdHeader.height = parseInt(pcdHeader.height[1], 10);
147
153
  }
148
- }
149
-
150
- pcdHeader.offset = {};
151
- let sizeSum = 0;
152
-
153
- if (pcdHeader.fields !== null && pcdHeader.size !== null) {
154
- for (let i = 0; i < pcdHeader.fields.length; i++) {
155
- if (pcdHeader.data === 'ascii') {
156
- pcdHeader.offset[pcdHeader.fields[i]] = i;
157
- } else {
158
- pcdHeader.offset[pcdHeader.fields[i]] = sizeSum;
159
- sizeSum += pcdHeader.size[i];
160
- }
154
+ if (pcdHeader.viewpoint !== null) {
155
+ pcdHeader.viewpoint = pcdHeader.viewpoint[1];
161
156
  }
162
- }
163
-
164
- pcdHeader.rowSize = sizeSum;
165
- return pcdHeader;
157
+ if (pcdHeader.points !== null) {
158
+ pcdHeader.points = parseInt(pcdHeader.points[1], 10);
159
+ }
160
+ if (pcdHeader.points === null &&
161
+ typeof pcdHeader.width === 'number' &&
162
+ typeof pcdHeader.height === 'number') {
163
+ pcdHeader.points = pcdHeader.width * pcdHeader.height;
164
+ }
165
+ if (pcdHeader.size !== null) {
166
+ pcdHeader.size = pcdHeader.size[1].split(' ').map((x) => parseInt(x, 10));
167
+ }
168
+ if (pcdHeader.count !== null) {
169
+ pcdHeader.count = pcdHeader.count[1].split(' ').map((x) => parseInt(x, 10));
170
+ }
171
+ else {
172
+ pcdHeader.count = [];
173
+ if (pcdHeader.fields !== null) {
174
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
175
+ pcdHeader.count.push(1);
176
+ }
177
+ }
178
+ }
179
+ pcdHeader.offset = {};
180
+ let sizeSum = 0;
181
+ if (pcdHeader.fields !== null && pcdHeader.size !== null) {
182
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
183
+ if (pcdHeader.data === 'ascii') {
184
+ pcdHeader.offset[pcdHeader.fields[i]] = i;
185
+ }
186
+ else {
187
+ pcdHeader.offset[pcdHeader.fields[i]] = sizeSum;
188
+ sizeSum += pcdHeader.size[i];
189
+ }
190
+ }
191
+ }
192
+ // for binary only
193
+ pcdHeader.rowSize = sizeSum;
194
+ return pcdHeader;
166
195
  }
167
-
196
+ /**
197
+ * @param pcdHeader
198
+ * @param textData
199
+ * @returns [attributes]
200
+ */
201
+ // eslint-enable-next-line complexity, max-statements
168
202
  function parsePCDASCII(pcdHeader, textData) {
169
- const position = [];
170
- const normal = [];
171
- const color = [];
172
- const offset = pcdHeader.offset;
173
- const pcdData = textData.substr(pcdHeader.headerLen);
174
- const lines = pcdData.split('\n');
175
-
176
- for (let i = 0; i < lines.length; i++) {
177
- if (lines[i] !== '') {
178
- const line = lines[i].split(' ');
179
-
180
- if (offset.x !== undefined) {
181
- position.push(parseFloat(line[offset.x]));
182
- position.push(parseFloat(line[offset.y]));
183
- position.push(parseFloat(line[offset.z]));
184
- }
185
-
186
- if (offset.rgb !== undefined) {
187
- const floatValue = parseFloat(line[offset.rgb]);
188
- const binaryColor = new Float32Array([floatValue]);
189
- const dataview = new DataView(binaryColor.buffer, 0);
190
- color.push(dataview.getUint8(0));
191
- color.push(dataview.getUint8(1));
192
- color.push(dataview.getUint8(2));
193
- }
194
-
195
- if (offset.normal_x !== undefined) {
196
- normal.push(parseFloat(line[offset.normal_x]));
197
- normal.push(parseFloat(line[offset.normal_y]));
198
- normal.push(parseFloat(line[offset.normal_z]));
199
- }
203
+ const position = [];
204
+ const normal = [];
205
+ const color = [];
206
+ const intensity = [];
207
+ const label = [];
208
+ const offset = pcdHeader.offset;
209
+ const pcdData = textData.substr(pcdHeader.headerLen);
210
+ const lines = pcdData.split('\n');
211
+ for (let i = 0; i < lines.length; i++) {
212
+ if (lines[i] !== '') {
213
+ const line = lines[i].split(' ');
214
+ if (offset.x !== undefined) {
215
+ position.push(parseFloat(line[offset.x]));
216
+ position.push(parseFloat(line[offset.y]));
217
+ position.push(parseFloat(line[offset.z]));
218
+ }
219
+ if (offset.rgb !== undefined) {
220
+ const floatValue = parseFloat(line[offset.rgb]);
221
+ const binaryColor = new Float32Array([floatValue]);
222
+ const dataview = new DataView(binaryColor.buffer, 0);
223
+ color.push(dataview.getUint8(0));
224
+ color.push(dataview.getUint8(1));
225
+ color.push(dataview.getUint8(2));
226
+ // TODO - handle alpha channel / RGBA?
227
+ }
228
+ if (offset.normal_x !== undefined) {
229
+ normal.push(parseFloat(line[offset.normal_x]));
230
+ normal.push(parseFloat(line[offset.normal_y]));
231
+ normal.push(parseFloat(line[offset.normal_z]));
232
+ }
233
+ if (offset.intensity !== undefined) {
234
+ intensity.push(parseFloat(line[offset.intensity]));
235
+ }
236
+ if (offset.label !== undefined) {
237
+ label.push(parseInt(line[offset.label]));
238
+ }
239
+ }
200
240
  }
201
- }
202
-
203
- return {
204
- position,
205
- normal,
206
- color
207
- };
241
+ return { position, normal, color };
208
242
  }
209
-
243
+ /**
244
+ * @param pcdHeader
245
+ * @param data
246
+ * @returns [attributes]
247
+ */
210
248
  function parsePCDBinary(pcdHeader, data) {
211
- const position = [];
212
- const normal = [];
213
- const color = [];
214
- const dataview = new DataView(data, pcdHeader.headerLen);
215
- const offset = pcdHeader.offset;
216
-
217
- for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
218
- if (offset.x !== undefined) {
219
- position.push(dataview.getFloat32(row + offset.x, LITTLE_ENDIAN));
220
- position.push(dataview.getFloat32(row + offset.y, LITTLE_ENDIAN));
221
- position.push(dataview.getFloat32(row + offset.z, LITTLE_ENDIAN));
222
- }
223
-
224
- if (offset.rgb !== undefined) {
225
- color.push(dataview.getUint8(row + offset.rgb + 0));
226
- color.push(dataview.getUint8(row + offset.rgb + 1));
227
- color.push(dataview.getUint8(row + offset.rgb + 2));
228
- }
229
-
230
- if (offset.normal_x !== undefined) {
231
- normal.push(dataview.getFloat32(row + offset.normal_x, LITTLE_ENDIAN));
232
- normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
233
- normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
249
+ const position = [];
250
+ const normal = [];
251
+ const color = [];
252
+ const intensity = [];
253
+ const label = [];
254
+ const dataview = new DataView(data, pcdHeader.headerLen);
255
+ const offset = pcdHeader.offset;
256
+ for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
257
+ if (offset.x !== undefined) {
258
+ position.push(dataview.getFloat32(row + offset.x, LITTLE_ENDIAN));
259
+ position.push(dataview.getFloat32(row + offset.y, LITTLE_ENDIAN));
260
+ position.push(dataview.getFloat32(row + offset.z, LITTLE_ENDIAN));
261
+ }
262
+ if (offset.rgb !== undefined) {
263
+ color.push(dataview.getUint8(row + offset.rgb + 0));
264
+ color.push(dataview.getUint8(row + offset.rgb + 1));
265
+ color.push(dataview.getUint8(row + offset.rgb + 2));
266
+ }
267
+ if (offset.normal_x !== undefined) {
268
+ normal.push(dataview.getFloat32(row + offset.normal_x, LITTLE_ENDIAN));
269
+ normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
270
+ normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
271
+ }
272
+ if (offset.intensity !== undefined) {
273
+ intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
274
+ }
275
+ if (offset.label !== undefined) {
276
+ label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
277
+ }
234
278
  }
235
- }
236
-
237
- return {
238
- position,
239
- normal,
240
- color
241
- };
279
+ return { position, normal, color, intensity, label };
242
280
  }
243
281
  /** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
244
282
  * from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
@@ -247,43 +285,49 @@ function parsePCDBinary(pcdHeader, data) {
247
285
  * @param data
248
286
  * @returns [attributes]
249
287
  */
250
-
251
-
252
- function parsePCDBinaryCompressed(PCDheader, data) {
253
- const position = [];
254
- const normal = [];
255
- const color = [];
256
- const sizes = new Uint32Array(data.slice(PCDheader.headerLen, PCDheader.headerLen + 8));
257
- const compressedSize = sizes[0];
258
- const decompressedSize = sizes[1];
259
- const decompressed = decompressLZF(new Uint8Array(data, PCDheader.headerLen + 8, compressedSize), decompressedSize);
260
- const dataview = new DataView(decompressed.buffer);
261
- const offset = PCDheader.offset;
262
-
263
- for (let i = 0; i < PCDheader.points; i++) {
264
- if (offset.x !== undefined) {
265
- position.push(dataview.getFloat32(PCDheader.points * offset.x + PCDheader.size[0] * i, LITTLE_ENDIAN));
266
- position.push(dataview.getFloat32(PCDheader.points * offset.y + PCDheader.size[1] * i, LITTLE_ENDIAN));
267
- position.push(dataview.getFloat32(PCDheader.points * offset.z + PCDheader.size[2] * i, LITTLE_ENDIAN));
288
+ // eslint-enable-next-line complexity, max-statements
289
+ function parsePCDBinaryCompressed(pcdHeader, data) {
290
+ const position = [];
291
+ const normal = [];
292
+ const color = [];
293
+ const intensity = [];
294
+ const label = [];
295
+ const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
296
+ const compressedSize = sizes[0];
297
+ const decompressedSize = sizes[1];
298
+ const decompressed = (0, decompress_lzf_1.decompressLZF)(new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize), decompressedSize);
299
+ const dataview = new DataView(decompressed.buffer);
300
+ const offset = pcdHeader.offset;
301
+ for (let i = 0; i < pcdHeader.points; i++) {
302
+ if (offset.x !== undefined) {
303
+ position.push(dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN));
304
+ position.push(dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN));
305
+ position.push(dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN));
306
+ }
307
+ if (offset.rgb !== undefined) {
308
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255.0);
309
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255.0);
310
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255.0);
311
+ }
312
+ if (offset.normal_x !== undefined) {
313
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i, LITTLE_ENDIAN));
314
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i, LITTLE_ENDIAN));
315
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i, LITTLE_ENDIAN));
316
+ }
317
+ if (offset.intensity !== undefined) {
318
+ const intensityIndex = pcdHeader.fields.indexOf('intensity');
319
+ intensity.push(dataview.getFloat32(pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i, LITTLE_ENDIAN));
320
+ }
321
+ if (offset.label !== undefined) {
322
+ const labelIndex = pcdHeader.fields.indexOf('label');
323
+ label.push(dataview.getInt32(pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i, LITTLE_ENDIAN));
324
+ }
268
325
  }
269
-
270
- if (offset.rgb !== undefined) {
271
- color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 0) / 255.0);
272
- color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 1) / 255.0);
273
- color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 2) / 255.0);
274
- }
275
-
276
- if (offset.normal_x !== undefined) {
277
- normal.push(dataview.getFloat32(PCDheader.points * offset.normal_x + PCDheader.size[4] * i, LITTLE_ENDIAN));
278
- normal.push(dataview.getFloat32(PCDheader.points * offset.normal_y + PCDheader.size[5] * i, LITTLE_ENDIAN));
279
- normal.push(dataview.getFloat32(PCDheader.points * offset.normal_z + PCDheader.size[6] * i, LITTLE_ENDIAN));
280
- }
281
- }
282
-
283
- return {
284
- position,
285
- normal,
286
- color
287
- };
326
+ return {
327
+ position,
328
+ normal,
329
+ color,
330
+ intensity,
331
+ label
332
+ };
288
333
  }
289
- //# sourceMappingURL=parse-pcd.js.map
@@ -1,18 +1,18 @@
1
1
  import type { Mesh } from '@loaders.gl/schema';
2
- declare type BoundingBox = [[number, number, number], [number, number, number]];
3
- export declare type PCDHeader = {
2
+ type BoundingBox = [[number, number, number], [number, number, number]];
3
+ export type PCDHeader = {
4
4
  data: any;
5
5
  headerLen: number;
6
6
  str: string;
7
- version: RegExpExecArray | null | number;
8
- fields: RegExpExecArray | null | string[];
9
- size: RegExpExecArray | null | number[];
10
- type: RegExpExecArray | null | string[];
11
- count: RegExpExecArray | null | number[];
12
- width: RegExpExecArray | number;
13
- height: RegExpExecArray | number;
14
- viewpoint: RegExpExecArray | null | string;
15
- points: RegExpExecArray | number;
7
+ version: number;
8
+ fields: string[];
9
+ size: number[];
10
+ type: null | string[];
11
+ count: null | number[];
12
+ width: number;
13
+ height: number;
14
+ viewpoint: null | string;
15
+ points: number;
16
16
  offset: {
17
17
  [index: string]: number;
18
18
  };
@@ -21,7 +21,7 @@ export declare type PCDHeader = {
21
21
  boundingBox: BoundingBox;
22
22
  };
23
23
  /** */
24
- export declare type PCDMesh = Mesh & {
24
+ export type PCDMesh = Mesh & {
25
25
  loader: 'pcd';
26
26
  loaderData: PCDHeader;
27
27
  topology: 'point-list';
@@ -1 +1 @@
1
- {"version":3,"file":"pcd-types.d.ts","sourceRoot":"","sources":["../../src/lib/pcd-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AAE7C,aAAK,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAExE,oBAAY,SAAS,GAAG;IACtB,IAAI,EAAE,GAAG,CAAC;IACV,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,CAAC;IACzC,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IAC1C,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IACxC,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IACxC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IACzC,KAAK,EAAE,eAAe,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,eAAe,GAAG,MAAM,CAAC;IACjC,SAAS,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,eAAe,GAAG,MAAM,CAAC;IACjC,MAAM,EAAE;QAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,OAAO;AACP,oBAAY,OAAO,GAAG,IAAI,GAAG;IAC3B,MAAM,EAAE,KAAK,CAAC;IACd,UAAU,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC;CACT,CAAC"}
1
+ {"version":3,"file":"pcd-types.d.ts","sourceRoot":"","sources":["../../src/lib/pcd-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AAE7C,KAAK,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAExE,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,GAAG,CAAC;IACV,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,IAAI,GAAG,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,OAAO;AACP,MAAM,MAAM,OAAO,GAAG,IAAI,GAAG;IAC3B,MAAM,EAAE,KAAK,CAAC;IACd,UAAU,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC;CACT,CAAC"}
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=pcd-types.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });