@loaders.gl/pcd 4.0.0-alpha.23 → 4.0.0-alpha.24
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/es5/pcd-loader.js +1 -1
- package/dist/esm/pcd-loader.js +1 -1
- package/dist/pcd-worker.js +1 -1
- package/package.json +4 -4
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -17
- package/dist/lib/decompress-lzf.js +0 -62
- package/dist/lib/get-pcd-schema.js +0 -33
- package/dist/lib/parse-pcd.js +0 -333
- package/dist/lib/pcd-types.js +0 -2
- package/dist/pcd-loader.js +0 -22
- package/dist/workers/pcd-worker.js +0 -5
package/dist/es5/pcd-loader.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.PCDLoader = void 0;
|
|
7
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
7
|
+
var VERSION = typeof "4.0.0-alpha.24" !== 'undefined' ? "4.0.0-alpha.24" : 'latest';
|
|
8
8
|
var PCDLoader = {
|
|
9
9
|
name: 'PCD (Point Cloud Data)',
|
|
10
10
|
id: 'pcd',
|
package/dist/esm/pcd-loader.js
CHANGED
package/dist/pcd-worker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/pcd",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.24",
|
|
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": "4.0.0-alpha.
|
|
37
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
36
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.24",
|
|
37
|
+
"@loaders.gl/schema": "4.0.0-alpha.24"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "97a8990595c132fb14e3445a8768d9f4cb98ff05"
|
|
40
40
|
}
|
package/dist/bundle.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,17 +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.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
|
-
};
|
|
@@ -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,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPCDSchema = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Gets schema from PCD header
|
|
6
|
-
* @param PCDheader
|
|
7
|
-
* @param metadata
|
|
8
|
-
* @returns Schema
|
|
9
|
-
*/
|
|
10
|
-
function getPCDSchema(PCDheader, metadata) {
|
|
11
|
-
const offset = PCDheader.offset;
|
|
12
|
-
const fields = [];
|
|
13
|
-
if (offset.x !== undefined) {
|
|
14
|
-
fields.push({
|
|
15
|
-
name: 'POSITION',
|
|
16
|
-
type: { type: 'fixed-size-list', listSize: 3, children: [{ name: 'xyz', type: 'float32' }] }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
if (offset.normal_x !== undefined) {
|
|
20
|
-
fields.push({
|
|
21
|
-
name: 'NORMAL',
|
|
22
|
-
type: { type: 'fixed-size-list', listSize: 3, children: [{ name: 'xyz', type: 'float32' }] }
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (offset.rgb !== undefined) {
|
|
26
|
-
fields.push({
|
|
27
|
-
name: 'COLOR_0',
|
|
28
|
-
type: { type: 'fixed-size-list', listSize: 3, children: [{ name: 'rgb', type: 'uint8' }] }
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return { fields, metadata };
|
|
32
|
-
}
|
|
33
|
-
exports.getPCDSchema = getPCDSchema;
|
package/dist/lib/parse-pcd.js
DELETED
|
@@ -1,333 +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 = 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
|
-
};
|
|
54
|
-
}
|
|
55
|
-
exports.default = parsePCD;
|
|
56
|
-
// Create a header that contains common data for PointCloud category loaders
|
|
57
|
-
function getMeshHeader(pcdHeader, attributes) {
|
|
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
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
vertexCount: pcdHeader.vertexCount,
|
|
67
|
-
boundingBox: pcdHeader.boundingBox
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* @param attributes
|
|
72
|
-
* @returns Normalized attributes
|
|
73
|
-
*/
|
|
74
|
-
function getMeshAttributes(attributes) {
|
|
75
|
-
const normalizedAttributes = {
|
|
76
|
-
POSITION: {
|
|
77
|
-
// Binary PCD is only 32 bit
|
|
78
|
-
value: new Float32Array(attributes.position),
|
|
79
|
-
size: 3
|
|
80
|
-
}
|
|
81
|
-
};
|
|
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;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Incoming data parsing
|
|
113
|
-
* @param data
|
|
114
|
-
* @returns Header
|
|
115
|
-
*/
|
|
116
|
-
/* eslint-disable complexity, max-statements */
|
|
117
|
-
function parsePCDHeader(data) {
|
|
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
|
-
}
|
|
142
|
-
if (pcdHeader.fields !== null) {
|
|
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);
|
|
153
|
-
}
|
|
154
|
-
if (pcdHeader.viewpoint !== null) {
|
|
155
|
-
pcdHeader.viewpoint = pcdHeader.viewpoint[1];
|
|
156
|
-
}
|
|
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;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* @param pcdHeader
|
|
198
|
-
* @param textData
|
|
199
|
-
* @returns [attributes]
|
|
200
|
-
*/
|
|
201
|
-
// eslint-enable-next-line complexity, max-statements
|
|
202
|
-
function parsePCDASCII(pcdHeader, textData) {
|
|
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
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return { position, normal, color };
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* @param pcdHeader
|
|
245
|
-
* @param data
|
|
246
|
-
* @returns [attributes]
|
|
247
|
-
*/
|
|
248
|
-
function parsePCDBinary(pcdHeader, data) {
|
|
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
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return { position, normal, color, intensity, label };
|
|
280
|
-
}
|
|
281
|
-
/** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
|
|
282
|
-
* from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
|
|
283
|
-
* @license MIT (http://opensource.org/licenses/MIT)
|
|
284
|
-
* @param pcdHeader
|
|
285
|
-
* @param data
|
|
286
|
-
* @returns [attributes]
|
|
287
|
-
*/
|
|
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
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return {
|
|
327
|
-
position,
|
|
328
|
-
normal,
|
|
329
|
-
color,
|
|
330
|
-
intensity,
|
|
331
|
-
label
|
|
332
|
-
};
|
|
333
|
-
}
|
package/dist/lib/pcd-types.js
DELETED
package/dist/pcd-loader.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.PCDLoader = void 0;
|
|
5
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
8
|
-
/**
|
|
9
|
-
* Worker loader for PCD - Point Cloud Data
|
|
10
|
-
*/
|
|
11
|
-
exports.PCDLoader = {
|
|
12
|
-
name: 'PCD (Point Cloud Data)',
|
|
13
|
-
id: 'pcd',
|
|
14
|
-
module: 'pcd',
|
|
15
|
-
version: VERSION,
|
|
16
|
-
worker: true,
|
|
17
|
-
extensions: ['pcd'],
|
|
18
|
-
mimeTypes: ['text/plain'],
|
|
19
|
-
options: {
|
|
20
|
-
pcd: {}
|
|
21
|
-
}
|
|
22
|
-
};
|