@loaders.gl/pcd 3.4.11 → 3.4.12

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.
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports._typecheckPCDLoader = exports.PCDLoader = void 0;
7
- var VERSION = typeof "3.4.11" !== 'undefined' ? "3.4.11" : 'latest';
7
+ var VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
8
8
  var PCDLoader = {
9
9
  name: 'PCD (Point Cloud Data)',
10
10
  id: 'pcd',
@@ -1,4 +1,4 @@
1
- const VERSION = typeof "3.4.11" !== 'undefined' ? "3.4.11" : 'latest';
1
+ const VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
2
2
  export const PCDLoader = {
3
3
  name: 'PCD (Point Cloud Data)',
4
4
  id: 'pcd',
@@ -976,7 +976,7 @@
976
976
  }
977
977
 
978
978
  // src/pcd-loader.ts
979
- var VERSION = true ? "3.4.11" : "latest";
979
+ var VERSION = true ? "3.4.12" : "latest";
980
980
  var PCDLoader = {
981
981
  name: "PCD (Point Cloud Data)",
982
982
  id: "pcd",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/pcd",
3
- "version": "3.4.11",
3
+ "version": "3.4.12",
4
4
  "description": "Framework-independent loader for the PCD format",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,8 +33,8 @@
33
33
  "build-worker": "esbuild src/workers/pcd-worker.ts --bundle --outfile=dist/pcd-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
34
34
  },
35
35
  "dependencies": {
36
- "@loaders.gl/loader-utils": "3.4.11",
37
- "@loaders.gl/schema": "3.4.11"
36
+ "@loaders.gl/loader-utils": "3.4.12",
37
+ "@loaders.gl/schema": "3.4.12"
38
38
  },
39
- "gitHead": "2b8d490d2372e70dd89eef8f6b215a5205c16621"
39
+ "gitHead": "85254762ae3082f608a863291deef09f2b40c6cf"
40
40
  }
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
package/dist/index.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._typecheckPCDLoader = exports.PCDLoader = exports.PCDWorkerLoader = void 0;
7
- const parse_pcd_1 = __importDefault(require("./lib/parse-pcd"));
8
- const pcd_loader_1 = require("./pcd-loader");
9
- Object.defineProperty(exports, "PCDWorkerLoader", { enumerable: true, get: function () { return pcd_loader_1.PCDLoader; } });
10
- /**
11
- * Loader for PCD - Point Cloud Data
12
- */
13
- exports.PCDLoader = {
14
- ...pcd_loader_1.PCDLoader,
15
- parse: async (arrayBuffer) => (0, parse_pcd_1.default)(arrayBuffer),
16
- parseSync: parse_pcd_1.default
17
- };
18
- exports._typecheckPCDLoader = exports.PCDLoader;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decompressLZF = void 0;
4
- /* eslint-disable */
5
- /**
6
- * from https://gitlab.com/taketwo/three-pcd-loader/blob/master/decompress-lzf.js
7
- * @param inData
8
- * @param outLength
9
- * @returns
10
- */
11
- function decompressLZF(inData, outLength) {
12
- const inLength = inData.length;
13
- const outData = new Uint8Array(outLength);
14
- let inPtr = 0;
15
- let outPtr = 0;
16
- let ctrl;
17
- let len;
18
- let ref;
19
- do {
20
- ctrl = inData[inPtr++];
21
- if (ctrl < 1 << 5) {
22
- ctrl++;
23
- if (outPtr + ctrl > outLength) {
24
- throw new Error('Output buffer is not large enough');
25
- }
26
- if (inPtr + ctrl > inLength) {
27
- throw new Error('Invalid compressed data');
28
- }
29
- do {
30
- outData[outPtr++] = inData[inPtr++];
31
- } while (--ctrl);
32
- }
33
- else {
34
- len = ctrl >> 5;
35
- ref = outPtr - ((ctrl & 0x1f) << 8) - 1;
36
- if (inPtr >= inLength) {
37
- throw new Error('Invalid compressed data');
38
- }
39
- if (len === 7) {
40
- len += inData[inPtr++];
41
- if (inPtr >= inLength) {
42
- throw new Error('Invalid compressed data');
43
- }
44
- }
45
- ref -= inData[inPtr++];
46
- if (outPtr + len + 2 > outLength) {
47
- throw new Error('Output buffer is not large enough');
48
- }
49
- if (ref < 0) {
50
- throw new Error('Invalid compressed data');
51
- }
52
- if (ref >= outPtr) {
53
- throw new Error('Invalid compressed data');
54
- }
55
- do {
56
- outData[outPtr++] = outData[ref++];
57
- } while (--len + 2);
58
- }
59
- } while (inPtr < inLength);
60
- return outData;
61
- }
62
- exports.decompressLZF = decompressLZF;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPCDSchema = void 0;
4
- const schema_1 = require("@loaders.gl/schema");
5
- /**
6
- * Gets schema from PCD header
7
- * @param PCDheader
8
- * @param metadata
9
- * @returns Schema
10
- */
11
- function getPCDSchema(PCDheader, metadata) {
12
- const offset = PCDheader.offset;
13
- const fields = [];
14
- if (offset.x !== undefined) {
15
- fields.push(new schema_1.Field('POSITION', new schema_1.FixedSizeList(3, new schema_1.Field('xyz', new schema_1.Float32())), false));
16
- }
17
- if (offset.normal_x !== undefined) {
18
- fields.push(new schema_1.Field('NORMAL', new schema_1.FixedSizeList(3, new schema_1.Field('xyz', new schema_1.Float32())), false));
19
- }
20
- if (offset.rgb !== undefined) {
21
- fields.push(new schema_1.Field('COLOR_0', new schema_1.FixedSizeList(3, new schema_1.Field('rgb', new schema_1.Uint8())), false));
22
- }
23
- if (offset.intensity !== undefined) {
24
- fields.push(new schema_1.Field('intensity', new schema_1.Field('intensity', new schema_1.Float32()), false));
25
- }
26
- if (offset.label !== undefined) {
27
- fields.push(new schema_1.Field('label', new schema_1.Field('label', new schema_1.Int32()), false));
28
- }
29
- return new schema_1.Schema(fields, metadata);
30
- }
31
- exports.getPCDSchema = getPCDSchema;
@@ -1,331 +0,0 @@
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");
13
- const LITTLE_ENDIAN = true;
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 = new Map([
41
- ['mode', '0'],
42
- ['boundingBox', JSON.stringify(header.boundingBox)]
43
- ]);
44
- const schema = (0, get_pcd_schema_1.getPCDSchema)(pcdHeader, metadata);
45
- return {
46
- loaderData: {
47
- header: pcdHeader
48
- },
49
- header,
50
- schema,
51
- mode: 0,
52
- indices: null,
53
- attributes
54
- };
55
- }
56
- exports.default = parsePCD;
57
- // Create a header that contains common data for PointCloud category loaders
58
- function getMeshHeader(pcdHeader, attributes) {
59
- if (typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
60
- const pointCount = pcdHeader.width * pcdHeader.height; // Supports "organized" point sets
61
- return {
62
- vertexCount: pointCount,
63
- boundingBox: (0, schema_1.getMeshBoundingBox)(attributes)
64
- };
65
- }
66
- return pcdHeader;
67
- }
68
- /**
69
- * @param attributes
70
- * @returns Normalized attributes
71
- */
72
- function getMeshAttributes(attributes) {
73
- const normalizedAttributes = {
74
- POSITION: {
75
- // Binary PCD is only 32 bit
76
- value: new Float32Array(attributes.position),
77
- size: 3
78
- }
79
- };
80
- if (attributes.normal && attributes.normal.length > 0) {
81
- normalizedAttributes.NORMAL = {
82
- value: new Float32Array(attributes.normal),
83
- size: 3
84
- };
85
- }
86
- if (attributes.color && attributes.color.length > 0) {
87
- // TODO - RGBA
88
- normalizedAttributes.COLOR_0 = {
89
- value: new Uint8Array(attributes.color),
90
- size: 3
91
- };
92
- }
93
- if (attributes.intensity && attributes.intensity.length > 0) {
94
- // TODO - RGBA
95
- normalizedAttributes.COLOR_0 = {
96
- value: new Uint8Array(attributes.color),
97
- size: 3
98
- };
99
- }
100
- if (attributes.label && attributes.label.length > 0) {
101
- // TODO - RGBA
102
- normalizedAttributes.COLOR_0 = {
103
- value: new Uint8Array(attributes.label),
104
- size: 3
105
- };
106
- }
107
- return normalizedAttributes;
108
- }
109
- /**
110
- * Incoming data parsing
111
- * @param data
112
- * @returns Header
113
- */
114
- /* eslint-disable complexity, max-statements */
115
- function parsePCDHeader(data) {
116
- const result1 = data.search(/[\r\n]DATA\s(\S*)\s/i);
117
- const result2 = /[\r\n]DATA\s(\S*)\s/i.exec(data.substr(result1 - 1));
118
- const pcdHeader = {};
119
- pcdHeader.data = result2 && result2[1];
120
- if (result2 !== null) {
121
- pcdHeader.headerLen = (result2 && result2[0].length) + result1;
122
- }
123
- pcdHeader.str = data.substr(0, pcdHeader.headerLen);
124
- // remove comments
125
- pcdHeader.str = pcdHeader.str.replace(/\#.*/gi, '');
126
- // parse
127
- pcdHeader.version = /VERSION (.*)/i.exec(pcdHeader.str);
128
- pcdHeader.fields = /FIELDS (.*)/i.exec(pcdHeader.str);
129
- pcdHeader.size = /SIZE (.*)/i.exec(pcdHeader.str);
130
- pcdHeader.type = /TYPE (.*)/i.exec(pcdHeader.str);
131
- pcdHeader.count = /COUNT (.*)/i.exec(pcdHeader.str);
132
- pcdHeader.width = /WIDTH (.*)/i.exec(pcdHeader.str);
133
- pcdHeader.height = /HEIGHT (.*)/i.exec(pcdHeader.str);
134
- pcdHeader.viewpoint = /VIEWPOINT (.*)/i.exec(pcdHeader.str);
135
- pcdHeader.points = /POINTS (.*)/i.exec(pcdHeader.str);
136
- // evaluate
137
- if (pcdHeader.version !== null) {
138
- pcdHeader.version = parseFloat(pcdHeader.version[1]);
139
- }
140
- if (pcdHeader.fields !== null) {
141
- pcdHeader.fields = pcdHeader.fields[1].split(' ');
142
- }
143
- if (pcdHeader.type !== null) {
144
- pcdHeader.type = pcdHeader.type[1].split(' ');
145
- }
146
- if (pcdHeader.width !== null) {
147
- pcdHeader.width = parseInt(pcdHeader.width[1], 10);
148
- }
149
- if (pcdHeader.height !== null) {
150
- pcdHeader.height = parseInt(pcdHeader.height[1], 10);
151
- }
152
- if (pcdHeader.viewpoint !== null) {
153
- pcdHeader.viewpoint = pcdHeader.viewpoint[1];
154
- }
155
- if (pcdHeader.points !== null) {
156
- pcdHeader.points = parseInt(pcdHeader.points[1], 10);
157
- }
158
- if (pcdHeader.points === null &&
159
- typeof pcdHeader.width === 'number' &&
160
- typeof pcdHeader.height === 'number') {
161
- pcdHeader.points = pcdHeader.width * pcdHeader.height;
162
- }
163
- if (pcdHeader.size !== null) {
164
- pcdHeader.size = pcdHeader.size[1].split(' ').map((x) => parseInt(x, 10));
165
- }
166
- if (pcdHeader.count !== null) {
167
- pcdHeader.count = pcdHeader.count[1].split(' ').map((x) => parseInt(x, 10));
168
- }
169
- else {
170
- pcdHeader.count = [];
171
- if (pcdHeader.fields !== null) {
172
- for (let i = 0; i < pcdHeader.fields.length; i++) {
173
- pcdHeader.count.push(1);
174
- }
175
- }
176
- }
177
- pcdHeader.offset = {};
178
- let sizeSum = 0;
179
- if (pcdHeader.fields !== null && pcdHeader.size !== null) {
180
- for (let i = 0; i < pcdHeader.fields.length; i++) {
181
- if (pcdHeader.data === 'ascii') {
182
- pcdHeader.offset[pcdHeader.fields[i]] = i;
183
- }
184
- else {
185
- pcdHeader.offset[pcdHeader.fields[i]] = sizeSum;
186
- sizeSum += pcdHeader.size[i];
187
- }
188
- }
189
- }
190
- // for binary only
191
- pcdHeader.rowSize = sizeSum;
192
- return pcdHeader;
193
- }
194
- /**
195
- * @param pcdHeader
196
- * @param textData
197
- * @returns [attributes]
198
- */
199
- // eslint-enable-next-line complexity, max-statements
200
- function parsePCDASCII(pcdHeader, textData) {
201
- const position = [];
202
- const normal = [];
203
- const color = [];
204
- const intensity = [];
205
- const label = [];
206
- const offset = pcdHeader.offset;
207
- const pcdData = textData.substr(pcdHeader.headerLen);
208
- const lines = pcdData.split('\n');
209
- for (let i = 0; i < lines.length; i++) {
210
- if (lines[i] !== '') {
211
- const line = lines[i].split(' ');
212
- if (offset.x !== undefined) {
213
- position.push(parseFloat(line[offset.x]));
214
- position.push(parseFloat(line[offset.y]));
215
- position.push(parseFloat(line[offset.z]));
216
- }
217
- if (offset.rgb !== undefined) {
218
- const floatValue = parseFloat(line[offset.rgb]);
219
- const binaryColor = new Float32Array([floatValue]);
220
- const dataview = new DataView(binaryColor.buffer, 0);
221
- color.push(dataview.getUint8(0));
222
- color.push(dataview.getUint8(1));
223
- color.push(dataview.getUint8(2));
224
- // TODO - handle alpha channel / RGBA?
225
- }
226
- if (offset.normal_x !== undefined) {
227
- normal.push(parseFloat(line[offset.normal_x]));
228
- normal.push(parseFloat(line[offset.normal_y]));
229
- normal.push(parseFloat(line[offset.normal_z]));
230
- }
231
- if (offset.intensity !== undefined) {
232
- intensity.push(parseFloat(line[offset.intensity]));
233
- }
234
- if (offset.label !== undefined) {
235
- label.push(parseInt(line[offset.label]));
236
- }
237
- }
238
- }
239
- return { position, normal, color };
240
- }
241
- /**
242
- * @param pcdHeader
243
- * @param data
244
- * @returns [attributes]
245
- */
246
- function parsePCDBinary(pcdHeader, data) {
247
- const position = [];
248
- const normal = [];
249
- const color = [];
250
- const intensity = [];
251
- const label = [];
252
- const dataview = new DataView(data, pcdHeader.headerLen);
253
- const offset = pcdHeader.offset;
254
- for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
255
- if (offset.x !== undefined) {
256
- position.push(dataview.getFloat32(row + offset.x, LITTLE_ENDIAN));
257
- position.push(dataview.getFloat32(row + offset.y, LITTLE_ENDIAN));
258
- position.push(dataview.getFloat32(row + offset.z, LITTLE_ENDIAN));
259
- }
260
- if (offset.rgb !== undefined) {
261
- color.push(dataview.getUint8(row + offset.rgb + 0));
262
- color.push(dataview.getUint8(row + offset.rgb + 1));
263
- color.push(dataview.getUint8(row + offset.rgb + 2));
264
- }
265
- if (offset.normal_x !== undefined) {
266
- normal.push(dataview.getFloat32(row + offset.normal_x, LITTLE_ENDIAN));
267
- normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
268
- normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
269
- }
270
- if (offset.intensity !== undefined) {
271
- intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
272
- }
273
- if (offset.label !== undefined) {
274
- label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
275
- }
276
- }
277
- return { position, normal, color, intensity, label };
278
- }
279
- /** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
280
- * from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
281
- * @license MIT (http://opensource.org/licenses/MIT)
282
- * @param pcdHeader
283
- * @param data
284
- * @returns [attributes]
285
- */
286
- // eslint-enable-next-line complexity, max-statements
287
- function parsePCDBinaryCompressed(pcdHeader, data) {
288
- const position = [];
289
- const normal = [];
290
- const color = [];
291
- const intensity = [];
292
- const label = [];
293
- const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
294
- const compressedSize = sizes[0];
295
- const decompressedSize = sizes[1];
296
- const decompressed = (0, decompress_lzf_1.decompressLZF)(new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize), decompressedSize);
297
- const dataview = new DataView(decompressed.buffer);
298
- const offset = pcdHeader.offset;
299
- for (let i = 0; i < pcdHeader.points; i++) {
300
- if (offset.x !== undefined) {
301
- position.push(dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN));
302
- position.push(dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN));
303
- position.push(dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN));
304
- }
305
- if (offset.rgb !== undefined) {
306
- color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255.0);
307
- color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255.0);
308
- color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255.0);
309
- }
310
- if (offset.normal_x !== undefined) {
311
- normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i, LITTLE_ENDIAN));
312
- normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i, LITTLE_ENDIAN));
313
- normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i, LITTLE_ENDIAN));
314
- }
315
- if (offset.intensity !== undefined) {
316
- const intensityIndex = pcdHeader.fields.indexOf('intensity');
317
- intensity.push(dataview.getFloat32(pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i, LITTLE_ENDIAN));
318
- }
319
- if (offset.label !== undefined) {
320
- const labelIndex = pcdHeader.fields.indexOf('label');
321
- label.push(dataview.getInt32(pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i, LITTLE_ENDIAN));
322
- }
323
- }
324
- return {
325
- position,
326
- normal,
327
- color,
328
- intensity,
329
- label
330
- };
331
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._typecheckPCDLoader = exports.PCDLoader = void 0;
4
- // __VERSION__ is injected by babel-plugin-version-inline
5
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
- /**
8
- * Worker loader for PCD - Point Cloud Data
9
- */
10
- exports.PCDLoader = {
11
- name: 'PCD (Point Cloud Data)',
12
- id: 'pcd',
13
- module: 'pcd',
14
- version: VERSION,
15
- worker: true,
16
- extensions: ['pcd'],
17
- mimeTypes: ['text/plain'],
18
- options: {
19
- pcd: {}
20
- }
21
- };
22
- exports._typecheckPCDLoader = exports.PCDLoader;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const index_1 = require("../index");
5
- (0, loader_utils_1.createLoaderWorker)(index_1.PCDLoader);