@loaders.gl/pcd 3.1.0 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +5 -778
- package/dist/dist.min.js +870 -0
- package/dist/es5/lib/decompress-lzf.js +51 -0
- package/dist/es5/lib/decompress-lzf.js.map +1 -0
- package/dist/es5/lib/parse-pcd.js +51 -0
- package/dist/es5/lib/parse-pcd.js.map +1 -1
- package/dist/es5/pcd-loader.js +1 -1
- package/dist/esm/lib/decompress-lzf.js +44 -0
- package/dist/esm/lib/decompress-lzf.js.map +1 -0
- package/dist/esm/lib/parse-pcd.js +50 -0
- package/dist/esm/lib/parse-pcd.js.map +1 -1
- package/dist/esm/pcd-loader.js +1 -1
- package/dist/lib/decompress-lzf.d.ts +8 -0
- package/dist/lib/decompress-lzf.d.ts.map +1 -0
- package/dist/lib/decompress-lzf.js +55 -0
- package/dist/lib/parse-pcd.d.ts.map +1 -1
- package/dist/lib/parse-pcd.js +43 -0
- package/dist/pcd-worker.js +88 -1
- package/package.json +6 -6
- package/src/lib/decompress-lzf.ts +50 -0
- package/src/lib/parse-pcd.ts +98 -2
package/dist/pcd-worker.js
CHANGED
|
@@ -594,6 +594,51 @@
|
|
|
594
594
|
}
|
|
595
595
|
};
|
|
596
596
|
|
|
597
|
+
// src/lib/decompress-lzf.ts
|
|
598
|
+
function decompressLZF(inData, outLength) {
|
|
599
|
+
const inLength = inData.length;
|
|
600
|
+
const outData = new Uint8Array(outLength);
|
|
601
|
+
let inPtr = 0;
|
|
602
|
+
let outPtr = 0;
|
|
603
|
+
let ctrl;
|
|
604
|
+
let len;
|
|
605
|
+
let ref;
|
|
606
|
+
do {
|
|
607
|
+
ctrl = inData[inPtr++];
|
|
608
|
+
if (ctrl < 1 << 5) {
|
|
609
|
+
ctrl++;
|
|
610
|
+
if (outPtr + ctrl > outLength)
|
|
611
|
+
throw new Error("Output buffer is not large enough");
|
|
612
|
+
if (inPtr + ctrl > inLength)
|
|
613
|
+
throw new Error("Invalid compressed data");
|
|
614
|
+
do {
|
|
615
|
+
outData[outPtr++] = inData[inPtr++];
|
|
616
|
+
} while (--ctrl);
|
|
617
|
+
} else {
|
|
618
|
+
len = ctrl >> 5;
|
|
619
|
+
ref = outPtr - ((ctrl & 31) << 8) - 1;
|
|
620
|
+
if (inPtr >= inLength)
|
|
621
|
+
throw new Error("Invalid compressed data");
|
|
622
|
+
if (len === 7) {
|
|
623
|
+
len += inData[inPtr++];
|
|
624
|
+
if (inPtr >= inLength)
|
|
625
|
+
throw new Error("Invalid compressed data");
|
|
626
|
+
}
|
|
627
|
+
ref -= inData[inPtr++];
|
|
628
|
+
if (outPtr + len + 2 > outLength)
|
|
629
|
+
throw new Error("Output buffer is not large enough");
|
|
630
|
+
if (ref < 0)
|
|
631
|
+
throw new Error("Invalid compressed data");
|
|
632
|
+
if (ref >= outPtr)
|
|
633
|
+
throw new Error("Invalid compressed data");
|
|
634
|
+
do {
|
|
635
|
+
outData[outPtr++] = outData[ref++];
|
|
636
|
+
} while (--len + 2);
|
|
637
|
+
}
|
|
638
|
+
} while (inPtr < inLength);
|
|
639
|
+
return outData;
|
|
640
|
+
}
|
|
641
|
+
|
|
597
642
|
// src/lib/get-pcd-schema.ts
|
|
598
643
|
function getPCDSchema(PCDheader, metadata) {
|
|
599
644
|
const offset = PCDheader.offset;
|
|
@@ -624,6 +669,8 @@
|
|
|
624
669
|
attributes = parsePCDBinary(pcdHeader, data);
|
|
625
670
|
break;
|
|
626
671
|
case "binary_compressed":
|
|
672
|
+
attributes = parsePCDBinaryCompressed(pcdHeader, data);
|
|
673
|
+
break;
|
|
627
674
|
default:
|
|
628
675
|
throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
|
|
629
676
|
}
|
|
@@ -804,9 +851,42 @@
|
|
|
804
851
|
}
|
|
805
852
|
return { position, normal, color };
|
|
806
853
|
}
|
|
854
|
+
function parsePCDBinaryCompressed(PCDheader, data) {
|
|
855
|
+
const position = [];
|
|
856
|
+
const normal = [];
|
|
857
|
+
const color = [];
|
|
858
|
+
const sizes = new Uint32Array(data.slice(PCDheader.headerLen, PCDheader.headerLen + 8));
|
|
859
|
+
const compressedSize = sizes[0];
|
|
860
|
+
const decompressedSize = sizes[1];
|
|
861
|
+
const decompressed = decompressLZF(new Uint8Array(data, PCDheader.headerLen + 8, compressedSize), decompressedSize);
|
|
862
|
+
const dataview = new DataView(decompressed.buffer);
|
|
863
|
+
const offset = PCDheader.offset;
|
|
864
|
+
for (let i = 0; i < PCDheader.points; i++) {
|
|
865
|
+
if (offset.x !== void 0) {
|
|
866
|
+
position.push(dataview.getFloat32(PCDheader.points * offset.x + PCDheader.size[0] * i, LITTLE_ENDIAN));
|
|
867
|
+
position.push(dataview.getFloat32(PCDheader.points * offset.y + PCDheader.size[1] * i, LITTLE_ENDIAN));
|
|
868
|
+
position.push(dataview.getFloat32(PCDheader.points * offset.z + PCDheader.size[2] * i, LITTLE_ENDIAN));
|
|
869
|
+
}
|
|
870
|
+
if (offset.rgb !== void 0) {
|
|
871
|
+
color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 0) / 255);
|
|
872
|
+
color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 1) / 255);
|
|
873
|
+
color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 2) / 255);
|
|
874
|
+
}
|
|
875
|
+
if (offset.normal_x !== void 0) {
|
|
876
|
+
normal.push(dataview.getFloat32(PCDheader.points * offset.normal_x + PCDheader.size[4] * i, LITTLE_ENDIAN));
|
|
877
|
+
normal.push(dataview.getFloat32(PCDheader.points * offset.normal_y + PCDheader.size[5] * i, LITTLE_ENDIAN));
|
|
878
|
+
normal.push(dataview.getFloat32(PCDheader.points * offset.normal_z + PCDheader.size[6] * i, LITTLE_ENDIAN));
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return {
|
|
882
|
+
position,
|
|
883
|
+
normal,
|
|
884
|
+
color
|
|
885
|
+
};
|
|
886
|
+
}
|
|
807
887
|
|
|
808
888
|
// src/pcd-loader.ts
|
|
809
|
-
var VERSION =
|
|
889
|
+
var VERSION = true ? "3.1.4" : "latest";
|
|
810
890
|
var PCDLoader = {
|
|
811
891
|
name: "PCD (Point Cloud Data)",
|
|
812
892
|
id: "pcd",
|
|
@@ -830,3 +910,10 @@
|
|
|
830
910
|
// src/workers/pcd-worker.ts
|
|
831
911
|
createLoaderWorker(PCDLoader2);
|
|
832
912
|
})();
|
|
913
|
+
/** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
|
|
914
|
+
* from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
|
|
915
|
+
* @license MIT (http://opensource.org/licenses/MIT)
|
|
916
|
+
* @param pcdHeader
|
|
917
|
+
* @param data
|
|
918
|
+
* @returns [attributes]
|
|
919
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/pcd",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "Framework-independent loader for the PCD format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
31
|
"pre-build": "npm run build-worker && npm run build-bundle",
|
|
32
|
-
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/
|
|
33
|
-
"build-worker": "esbuild src/workers/pcd-worker.ts --bundle --outfile=dist/pcd-worker.js"
|
|
32
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
|
|
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.1.
|
|
37
|
-
"@loaders.gl/schema": "3.1.
|
|
36
|
+
"@loaders.gl/loader-utils": "3.1.4",
|
|
37
|
+
"@loaders.gl/schema": "3.1.4"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "4d27d3ac6023e53b562dcad83b9254b198e81ee5"
|
|
40
40
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* from https://gitlab.com/taketwo/three-pcd-loader/blob/master/decompress-lzf.js
|
|
4
|
+
* @param inData
|
|
5
|
+
* @param outLength
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function decompressLZF(inData: Uint8Array, outLength: number): Uint8Array {
|
|
9
|
+
const inLength = inData.length;
|
|
10
|
+
const outData = new Uint8Array(outLength);
|
|
11
|
+
let inPtr = 0;
|
|
12
|
+
let outPtr = 0;
|
|
13
|
+
let ctrl;
|
|
14
|
+
let len;
|
|
15
|
+
let ref;
|
|
16
|
+
|
|
17
|
+
do {
|
|
18
|
+
ctrl = inData[inPtr++];
|
|
19
|
+
|
|
20
|
+
if (ctrl < 1 << 5) {
|
|
21
|
+
ctrl++;
|
|
22
|
+
if (outPtr + ctrl > outLength) throw new Error('Output buffer is not large enough');
|
|
23
|
+
if (inPtr + ctrl > inLength) throw new Error('Invalid compressed data');
|
|
24
|
+
|
|
25
|
+
do {
|
|
26
|
+
outData[outPtr++] = inData[inPtr++];
|
|
27
|
+
} while (--ctrl);
|
|
28
|
+
} else {
|
|
29
|
+
len = ctrl >> 5;
|
|
30
|
+
ref = outPtr - ((ctrl & 0x1f) << 8) - 1;
|
|
31
|
+
if (inPtr >= inLength) throw new Error('Invalid compressed data');
|
|
32
|
+
|
|
33
|
+
if (len === 7) {
|
|
34
|
+
len += inData[inPtr++];
|
|
35
|
+
if (inPtr >= inLength) throw new Error('Invalid compressed data');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
ref -= inData[inPtr++];
|
|
39
|
+
if (outPtr + len + 2 > outLength) throw new Error('Output buffer is not large enough');
|
|
40
|
+
if (ref < 0) throw new Error('Invalid compressed data');
|
|
41
|
+
if (ref >= outPtr) throw new Error('Invalid compressed data');
|
|
42
|
+
|
|
43
|
+
do {
|
|
44
|
+
outData[outPtr++] = outData[ref++];
|
|
45
|
+
} while (--len + 2);
|
|
46
|
+
}
|
|
47
|
+
} while (inPtr < inLength);
|
|
48
|
+
|
|
49
|
+
return outData;
|
|
50
|
+
}
|
package/src/lib/parse-pcd.ts
CHANGED
|
@@ -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
|
|
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
|
+
}
|