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

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.
@@ -6,10 +6,11 @@
6
6
  // @author Filipe Caixeta / http://filipecaixeta.com.br
7
7
  // @author Mugen87 / https://github.com/Mugen87
8
8
 
9
- import {getMeshBoundingBox} from '@loaders.gl/schema';
10
9
  import type {MeshAttribute, MeshAttributes} from '@loaders.gl/schema';
11
- import type {PCDHeader} from './pcd-types';
10
+ import {getMeshBoundingBox} from '@loaders.gl/schema';
11
+ import {decompressLZF} from './decompress-lzf';
12
12
  import {getPCDSchema} from './get-pcd-schema';
13
+ import type {PCDHeader} from './pcd-types';
13
14
 
14
15
  type NormalizedAttributes = {
15
16
  POSITION: {
@@ -55,6 +56,9 @@ export default function parsePCD(data: ArrayBufferLike) {
55
56
  break;
56
57
 
57
58
  case 'binary_compressed':
59
+ attributes = parsePCDBinaryCompressed(pcdHeader, data);
60
+ break;
61
+
58
62
  default:
59
63
  throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
60
64
  }
@@ -312,3 +316,95 @@ function parsePCDBinary(pcdHeader: PCDHeader, data: ArrayBufferLike): HeaderAttr
312
316
 
313
317
  return {position, normal, color};
314
318
  }
319
+
320
+ /** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
321
+ * from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
322
+ * @license MIT (http://opensource.org/licenses/MIT)
323
+ * @param pcdHeader
324
+ * @param data
325
+ * @returns [attributes]
326
+ */
327
+ function parsePCDBinaryCompressed(PCDheader: PCDHeader, data: ArrayBufferLike): HeaderAttributes {
328
+ const position: number[] = [];
329
+ const normal: number[] = [];
330
+ const color: number[] = [];
331
+
332
+ const sizes = new Uint32Array(data.slice(PCDheader.headerLen, PCDheader.headerLen + 8));
333
+ const compressedSize = sizes[0];
334
+ const decompressedSize = sizes[1];
335
+ const decompressed = decompressLZF(
336
+ new Uint8Array(data, PCDheader.headerLen + 8, compressedSize),
337
+ decompressedSize
338
+ );
339
+ const dataview = new DataView(decompressed.buffer);
340
+
341
+ const offset = PCDheader.offset;
342
+
343
+ for (let i = 0; i < PCDheader.points; i++) {
344
+ if (offset.x !== undefined) {
345
+ position.push(
346
+ dataview.getFloat32(
347
+ (PCDheader.points as number) * offset.x + (PCDheader.size as number[])[0] * i,
348
+ LITTLE_ENDIAN
349
+ )
350
+ );
351
+ position.push(
352
+ dataview.getFloat32(
353
+ (PCDheader.points as number) * offset.y + (PCDheader.size as number[])[1] * i,
354
+ LITTLE_ENDIAN
355
+ )
356
+ );
357
+ position.push(
358
+ dataview.getFloat32(
359
+ (PCDheader.points as number) * offset.z + (PCDheader.size as number[])[2] * i,
360
+ LITTLE_ENDIAN
361
+ )
362
+ );
363
+ }
364
+
365
+ if (offset.rgb !== undefined) {
366
+ color.push(
367
+ dataview.getUint8(
368
+ (PCDheader.points as number) * offset.rgb + (PCDheader.size as number[])[3] * i + 0
369
+ ) / 255.0
370
+ );
371
+ color.push(
372
+ dataview.getUint8(
373
+ (PCDheader.points as number) * offset.rgb + (PCDheader.size as number[])[3] * i + 1
374
+ ) / 255.0
375
+ );
376
+ color.push(
377
+ dataview.getUint8(
378
+ (PCDheader.points as number) * offset.rgb + (PCDheader.size as number[])[3] * i + 2
379
+ ) / 255.0
380
+ );
381
+ }
382
+
383
+ if (offset.normal_x !== undefined) {
384
+ normal.push(
385
+ dataview.getFloat32(
386
+ (PCDheader.points as number) * offset.normal_x + (PCDheader.size as number[])[4] * i,
387
+ LITTLE_ENDIAN
388
+ )
389
+ );
390
+ normal.push(
391
+ dataview.getFloat32(
392
+ (PCDheader.points as number) * offset.normal_y + (PCDheader.size as number[])[5] * i,
393
+ LITTLE_ENDIAN
394
+ )
395
+ );
396
+ normal.push(
397
+ dataview.getFloat32(
398
+ (PCDheader.points as number) * offset.normal_z + (PCDheader.size as number[])[6] * i,
399
+ LITTLE_ENDIAN
400
+ )
401
+ );
402
+ }
403
+ }
404
+
405
+ return {
406
+ position,
407
+ normal,
408
+ color
409
+ };
410
+ }