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