@loaders.gl/pcd 4.0.0-alpha.5 → 4.0.0-alpha.6
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 +2 -2
- package/dist/dist.min.js +93 -487
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +45 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/decompress-lzf.js +57 -0
- package/dist/es5/lib/decompress-lzf.js.map +1 -0
- package/dist/es5/lib/get-pcd-schema.js +54 -0
- package/dist/es5/lib/get-pcd-schema.js.map +1 -0
- package/dist/es5/lib/parse-pcd.js +299 -0
- package/dist/es5/lib/parse-pcd.js.map +1 -0
- package/dist/es5/lib/pcd-types.js +2 -0
- package/dist/es5/lib/pcd-types.js.map +1 -0
- package/dist/es5/pcd-loader.js +21 -0
- package/dist/es5/pcd-loader.js.map +1 -0
- package/dist/es5/workers/pcd-worker.js +6 -0
- package/dist/es5/workers/pcd-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/decompress-lzf.js +51 -0
- package/dist/esm/lib/decompress-lzf.js.map +1 -0
- package/dist/esm/lib/get-pcd-schema.js +48 -0
- package/dist/esm/lib/get-pcd-schema.js.map +1 -0
- package/dist/esm/lib/parse-pcd.js +289 -0
- package/dist/esm/lib/parse-pcd.js.map +1 -0
- package/dist/esm/lib/pcd-types.js +2 -0
- package/dist/esm/lib/pcd-types.js.map +1 -0
- package/dist/esm/pcd-loader.js +14 -0
- package/dist/esm/pcd-loader.js.map +1 -0
- package/dist/esm/workers/pcd-worker.js +4 -0
- package/dist/esm/workers/pcd-worker.js.map +1 -0
- package/dist/index.d.ts +3 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- package/dist/lib/decompress-lzf.d.ts.map +1 -1
- package/dist/lib/decompress-lzf.js +61 -43
- package/dist/lib/get-pcd-schema.d.ts +1 -3
- package/dist/lib/get-pcd-schema.d.ts.map +1 -1
- package/dist/lib/get-pcd-schema.js +32 -19
- package/dist/lib/parse-pcd.d.ts +2 -11
- package/dist/lib/parse-pcd.d.ts.map +1 -1
- package/dist/lib/parse-pcd.js +304 -260
- package/dist/lib/pcd-types.d.ts +12 -12
- package/dist/lib/pcd-types.d.ts.map +1 -1
- package/dist/lib/pcd-types.js +2 -2
- package/dist/pcd-loader.d.ts +3 -14
- package/dist/pcd-loader.d.ts.map +1 -1
- package/dist/pcd-loader.js +21 -14
- package/dist/pcd-worker.js +140 -466
- package/dist/workers/pcd-worker.js +5 -4
- package/package.json +6 -6
- package/src/index.ts +3 -2
- package/src/lib/decompress-lzf.ts +21 -7
- package/src/lib/get-pcd-schema.ts +15 -10
- package/src/lib/parse-pcd.ts +95 -42
- package/src/lib/pcd-types.ts +9 -9
- package/src/pcd-loader.ts +5 -4
- package/dist/bundle.js.map +0 -1
- 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/pcd-worker.js
CHANGED
|
@@ -35,16 +35,33 @@
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// ../worker-utils/src/lib/worker-farm/worker-body.ts
|
|
38
|
+
function getParentPort() {
|
|
39
|
+
let parentPort;
|
|
40
|
+
try {
|
|
41
|
+
eval("globalThis.parentPort = require('worker_threads').parentPort");
|
|
42
|
+
parentPort = globalThis.parentPort;
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
return parentPort;
|
|
46
|
+
}
|
|
38
47
|
var onMessageWrapperMap = new Map();
|
|
39
48
|
var WorkerBody = class {
|
|
49
|
+
static inWorkerThread() {
|
|
50
|
+
return typeof self !== "undefined" || Boolean(getParentPort());
|
|
51
|
+
}
|
|
40
52
|
static set onmessage(onMessage) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
const { type, payload } = message.data;
|
|
53
|
+
function handleMessage(message) {
|
|
54
|
+
const parentPort3 = getParentPort();
|
|
55
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
46
56
|
onMessage(type, payload);
|
|
47
|
-
}
|
|
57
|
+
}
|
|
58
|
+
const parentPort2 = getParentPort();
|
|
59
|
+
if (parentPort2) {
|
|
60
|
+
parentPort2.on("message", handleMessage);
|
|
61
|
+
parentPort2.on("exit", () => console.debug("Node worker closing"));
|
|
62
|
+
} else {
|
|
63
|
+
globalThis.onmessage = handleMessage;
|
|
64
|
+
}
|
|
48
65
|
}
|
|
49
66
|
static addEventListener(onMessage) {
|
|
50
67
|
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
@@ -53,22 +70,36 @@
|
|
|
53
70
|
if (!isKnownMessage(message)) {
|
|
54
71
|
return;
|
|
55
72
|
}
|
|
56
|
-
const
|
|
73
|
+
const parentPort3 = getParentPort();
|
|
74
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
57
75
|
onMessage(type, payload);
|
|
58
76
|
};
|
|
59
77
|
}
|
|
60
|
-
|
|
78
|
+
const parentPort2 = getParentPort();
|
|
79
|
+
if (parentPort2) {
|
|
80
|
+
console.error("not implemented");
|
|
81
|
+
} else {
|
|
82
|
+
globalThis.addEventListener("message", onMessageWrapper);
|
|
83
|
+
}
|
|
61
84
|
}
|
|
62
85
|
static removeEventListener(onMessage) {
|
|
63
86
|
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
64
87
|
onMessageWrapperMap.delete(onMessage);
|
|
65
|
-
|
|
88
|
+
const parentPort2 = getParentPort();
|
|
89
|
+
if (parentPort2) {
|
|
90
|
+
console.error("not implemented");
|
|
91
|
+
} else {
|
|
92
|
+
globalThis.removeEventListener("message", onMessageWrapper);
|
|
93
|
+
}
|
|
66
94
|
}
|
|
67
95
|
static postMessage(type, payload) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
96
|
+
const data = { source: "loaders.gl", type, payload };
|
|
97
|
+
const transferList = getTransferList(payload);
|
|
98
|
+
const parentPort2 = getParentPort();
|
|
99
|
+
if (parentPort2) {
|
|
100
|
+
parentPort2.postMessage(data, transferList);
|
|
101
|
+
} else {
|
|
102
|
+
globalThis.postMessage(data, transferList);
|
|
72
103
|
}
|
|
73
104
|
}
|
|
74
105
|
};
|
|
@@ -80,19 +111,20 @@
|
|
|
80
111
|
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
81
112
|
var requestId = 0;
|
|
82
113
|
function createLoaderWorker(loader) {
|
|
83
|
-
if (
|
|
114
|
+
if (!WorkerBody.inWorkerThread()) {
|
|
84
115
|
return;
|
|
85
116
|
}
|
|
86
117
|
WorkerBody.onmessage = async (type, payload) => {
|
|
87
118
|
switch (type) {
|
|
88
119
|
case "process":
|
|
89
120
|
try {
|
|
90
|
-
const { input, options = {} } = payload;
|
|
121
|
+
const { input, options = {}, context = {} } = payload;
|
|
91
122
|
const result = await parseData({
|
|
92
123
|
loader,
|
|
93
124
|
arrayBuffer: input,
|
|
94
125
|
options,
|
|
95
126
|
context: {
|
|
127
|
+
...context,
|
|
96
128
|
parse: parseOnMainThread
|
|
97
129
|
}
|
|
98
130
|
});
|
|
@@ -151,7 +183,7 @@
|
|
|
151
183
|
return await parser(data, { ...options }, context, loader);
|
|
152
184
|
}
|
|
153
185
|
|
|
154
|
-
// ../schema/src/
|
|
186
|
+
// ../schema/src/lib/mesh/mesh-utils.ts
|
|
155
187
|
function getMeshBoundingBox(attributes) {
|
|
156
188
|
let minX = Infinity;
|
|
157
189
|
let minY = Infinity;
|
|
@@ -178,422 +210,6 @@
|
|
|
178
210
|
];
|
|
179
211
|
}
|
|
180
212
|
|
|
181
|
-
// ../schema/src/lib/utils/assert.ts
|
|
182
|
-
function assert(condition, message) {
|
|
183
|
-
if (!condition) {
|
|
184
|
-
throw new Error(message || "loader assertion failed.");
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// ../schema/src/lib/schema/impl/schema.ts
|
|
189
|
-
var Schema = class {
|
|
190
|
-
constructor(fields, metadata) {
|
|
191
|
-
assert(Array.isArray(fields));
|
|
192
|
-
checkNames(fields);
|
|
193
|
-
this.fields = fields;
|
|
194
|
-
this.metadata = metadata || new Map();
|
|
195
|
-
}
|
|
196
|
-
compareTo(other) {
|
|
197
|
-
if (this.metadata !== other.metadata) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
if (this.fields.length !== other.fields.length) {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
for (let i = 0; i < this.fields.length; ++i) {
|
|
204
|
-
if (!this.fields[i].compareTo(other.fields[i])) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
select(...columnNames) {
|
|
211
|
-
const nameMap = Object.create(null);
|
|
212
|
-
for (const name of columnNames) {
|
|
213
|
-
nameMap[name] = true;
|
|
214
|
-
}
|
|
215
|
-
const selectedFields = this.fields.filter((field) => nameMap[field.name]);
|
|
216
|
-
return new Schema(selectedFields, this.metadata);
|
|
217
|
-
}
|
|
218
|
-
selectAt(...columnIndices) {
|
|
219
|
-
const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
|
|
220
|
-
return new Schema(selectedFields, this.metadata);
|
|
221
|
-
}
|
|
222
|
-
assign(schemaOrFields) {
|
|
223
|
-
let fields;
|
|
224
|
-
let metadata = this.metadata;
|
|
225
|
-
if (schemaOrFields instanceof Schema) {
|
|
226
|
-
const otherSchema = schemaOrFields;
|
|
227
|
-
fields = otherSchema.fields;
|
|
228
|
-
metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
|
|
229
|
-
} else {
|
|
230
|
-
fields = schemaOrFields;
|
|
231
|
-
}
|
|
232
|
-
const fieldMap = Object.create(null);
|
|
233
|
-
for (const field of this.fields) {
|
|
234
|
-
fieldMap[field.name] = field;
|
|
235
|
-
}
|
|
236
|
-
for (const field of fields) {
|
|
237
|
-
fieldMap[field.name] = field;
|
|
238
|
-
}
|
|
239
|
-
const mergedFields = Object.values(fieldMap);
|
|
240
|
-
return new Schema(mergedFields, metadata);
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
function checkNames(fields) {
|
|
244
|
-
const usedNames = {};
|
|
245
|
-
for (const field of fields) {
|
|
246
|
-
if (usedNames[field.name]) {
|
|
247
|
-
console.warn("Schema: duplicated field name", field.name, field);
|
|
248
|
-
}
|
|
249
|
-
usedNames[field.name] = true;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function mergeMaps(m1, m2) {
|
|
253
|
-
return new Map([...m1 || new Map(), ...m2 || new Map()]);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// ../schema/src/lib/schema/impl/field.ts
|
|
257
|
-
var Field = class {
|
|
258
|
-
constructor(name, type, nullable = false, metadata = new Map()) {
|
|
259
|
-
this.name = name;
|
|
260
|
-
this.type = type;
|
|
261
|
-
this.nullable = nullable;
|
|
262
|
-
this.metadata = metadata;
|
|
263
|
-
}
|
|
264
|
-
get typeId() {
|
|
265
|
-
return this.type && this.type.typeId;
|
|
266
|
-
}
|
|
267
|
-
clone() {
|
|
268
|
-
return new Field(this.name, this.type, this.nullable, this.metadata);
|
|
269
|
-
}
|
|
270
|
-
compareTo(other) {
|
|
271
|
-
return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
|
|
272
|
-
}
|
|
273
|
-
toString() {
|
|
274
|
-
return `${this.type}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${this.metadata}` : ""}`;
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
// ../schema/src/lib/schema/impl/enum.ts
|
|
279
|
-
var Type;
|
|
280
|
-
(function(Type2) {
|
|
281
|
-
Type2[Type2["NONE"] = 0] = "NONE";
|
|
282
|
-
Type2[Type2["Null"] = 1] = "Null";
|
|
283
|
-
Type2[Type2["Int"] = 2] = "Int";
|
|
284
|
-
Type2[Type2["Float"] = 3] = "Float";
|
|
285
|
-
Type2[Type2["Binary"] = 4] = "Binary";
|
|
286
|
-
Type2[Type2["Utf8"] = 5] = "Utf8";
|
|
287
|
-
Type2[Type2["Bool"] = 6] = "Bool";
|
|
288
|
-
Type2[Type2["Decimal"] = 7] = "Decimal";
|
|
289
|
-
Type2[Type2["Date"] = 8] = "Date";
|
|
290
|
-
Type2[Type2["Time"] = 9] = "Time";
|
|
291
|
-
Type2[Type2["Timestamp"] = 10] = "Timestamp";
|
|
292
|
-
Type2[Type2["Interval"] = 11] = "Interval";
|
|
293
|
-
Type2[Type2["List"] = 12] = "List";
|
|
294
|
-
Type2[Type2["Struct"] = 13] = "Struct";
|
|
295
|
-
Type2[Type2["Union"] = 14] = "Union";
|
|
296
|
-
Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
|
|
297
|
-
Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
|
|
298
|
-
Type2[Type2["Map"] = 17] = "Map";
|
|
299
|
-
Type2[Type2["Dictionary"] = -1] = "Dictionary";
|
|
300
|
-
Type2[Type2["Int8"] = -2] = "Int8";
|
|
301
|
-
Type2[Type2["Int16"] = -3] = "Int16";
|
|
302
|
-
Type2[Type2["Int32"] = -4] = "Int32";
|
|
303
|
-
Type2[Type2["Int64"] = -5] = "Int64";
|
|
304
|
-
Type2[Type2["Uint8"] = -6] = "Uint8";
|
|
305
|
-
Type2[Type2["Uint16"] = -7] = "Uint16";
|
|
306
|
-
Type2[Type2["Uint32"] = -8] = "Uint32";
|
|
307
|
-
Type2[Type2["Uint64"] = -9] = "Uint64";
|
|
308
|
-
Type2[Type2["Float16"] = -10] = "Float16";
|
|
309
|
-
Type2[Type2["Float32"] = -11] = "Float32";
|
|
310
|
-
Type2[Type2["Float64"] = -12] = "Float64";
|
|
311
|
-
Type2[Type2["DateDay"] = -13] = "DateDay";
|
|
312
|
-
Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
|
|
313
|
-
Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
|
|
314
|
-
Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
|
|
315
|
-
Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
|
|
316
|
-
Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
|
|
317
|
-
Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
|
|
318
|
-
Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
|
|
319
|
-
Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
|
|
320
|
-
Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
|
|
321
|
-
Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
|
|
322
|
-
Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
|
|
323
|
-
Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
|
|
324
|
-
Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
|
|
325
|
-
})(Type || (Type = {}));
|
|
326
|
-
|
|
327
|
-
// ../schema/src/lib/schema/impl/type.ts
|
|
328
|
-
var DataType = class {
|
|
329
|
-
static isNull(x) {
|
|
330
|
-
return x && x.typeId === Type.Null;
|
|
331
|
-
}
|
|
332
|
-
static isInt(x) {
|
|
333
|
-
return x && x.typeId === Type.Int;
|
|
334
|
-
}
|
|
335
|
-
static isFloat(x) {
|
|
336
|
-
return x && x.typeId === Type.Float;
|
|
337
|
-
}
|
|
338
|
-
static isBinary(x) {
|
|
339
|
-
return x && x.typeId === Type.Binary;
|
|
340
|
-
}
|
|
341
|
-
static isUtf8(x) {
|
|
342
|
-
return x && x.typeId === Type.Utf8;
|
|
343
|
-
}
|
|
344
|
-
static isBool(x) {
|
|
345
|
-
return x && x.typeId === Type.Bool;
|
|
346
|
-
}
|
|
347
|
-
static isDecimal(x) {
|
|
348
|
-
return x && x.typeId === Type.Decimal;
|
|
349
|
-
}
|
|
350
|
-
static isDate(x) {
|
|
351
|
-
return x && x.typeId === Type.Date;
|
|
352
|
-
}
|
|
353
|
-
static isTime(x) {
|
|
354
|
-
return x && x.typeId === Type.Time;
|
|
355
|
-
}
|
|
356
|
-
static isTimestamp(x) {
|
|
357
|
-
return x && x.typeId === Type.Timestamp;
|
|
358
|
-
}
|
|
359
|
-
static isInterval(x) {
|
|
360
|
-
return x && x.typeId === Type.Interval;
|
|
361
|
-
}
|
|
362
|
-
static isList(x) {
|
|
363
|
-
return x && x.typeId === Type.List;
|
|
364
|
-
}
|
|
365
|
-
static isStruct(x) {
|
|
366
|
-
return x && x.typeId === Type.Struct;
|
|
367
|
-
}
|
|
368
|
-
static isUnion(x) {
|
|
369
|
-
return x && x.typeId === Type.Union;
|
|
370
|
-
}
|
|
371
|
-
static isFixedSizeBinary(x) {
|
|
372
|
-
return x && x.typeId === Type.FixedSizeBinary;
|
|
373
|
-
}
|
|
374
|
-
static isFixedSizeList(x) {
|
|
375
|
-
return x && x.typeId === Type.FixedSizeList;
|
|
376
|
-
}
|
|
377
|
-
static isMap(x) {
|
|
378
|
-
return x && x.typeId === Type.Map;
|
|
379
|
-
}
|
|
380
|
-
static isDictionary(x) {
|
|
381
|
-
return x && x.typeId === Type.Dictionary;
|
|
382
|
-
}
|
|
383
|
-
get typeId() {
|
|
384
|
-
return Type.NONE;
|
|
385
|
-
}
|
|
386
|
-
compareTo(other) {
|
|
387
|
-
return this === other;
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
var Null = class extends DataType {
|
|
391
|
-
get typeId() {
|
|
392
|
-
return Type.Null;
|
|
393
|
-
}
|
|
394
|
-
get [Symbol.toStringTag]() {
|
|
395
|
-
return "Null";
|
|
396
|
-
}
|
|
397
|
-
toString() {
|
|
398
|
-
return "Null";
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
var Bool = class extends DataType {
|
|
402
|
-
get typeId() {
|
|
403
|
-
return Type.Bool;
|
|
404
|
-
}
|
|
405
|
-
get [Symbol.toStringTag]() {
|
|
406
|
-
return "Bool";
|
|
407
|
-
}
|
|
408
|
-
toString() {
|
|
409
|
-
return "Bool";
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
var Int = class extends DataType {
|
|
413
|
-
constructor(isSigned, bitWidth) {
|
|
414
|
-
super();
|
|
415
|
-
this.isSigned = isSigned;
|
|
416
|
-
this.bitWidth = bitWidth;
|
|
417
|
-
}
|
|
418
|
-
get typeId() {
|
|
419
|
-
return Type.Int;
|
|
420
|
-
}
|
|
421
|
-
get [Symbol.toStringTag]() {
|
|
422
|
-
return "Int";
|
|
423
|
-
}
|
|
424
|
-
toString() {
|
|
425
|
-
return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
var Uint8 = class extends Int {
|
|
429
|
-
constructor() {
|
|
430
|
-
super(false, 8);
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
var Precision = {
|
|
434
|
-
HALF: 16,
|
|
435
|
-
SINGLE: 32,
|
|
436
|
-
DOUBLE: 64
|
|
437
|
-
};
|
|
438
|
-
var Float = class extends DataType {
|
|
439
|
-
constructor(precision) {
|
|
440
|
-
super();
|
|
441
|
-
this.precision = precision;
|
|
442
|
-
}
|
|
443
|
-
get typeId() {
|
|
444
|
-
return Type.Float;
|
|
445
|
-
}
|
|
446
|
-
get [Symbol.toStringTag]() {
|
|
447
|
-
return "Float";
|
|
448
|
-
}
|
|
449
|
-
toString() {
|
|
450
|
-
return `Float${this.precision}`;
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
var Float32 = class extends Float {
|
|
454
|
-
constructor() {
|
|
455
|
-
super(Precision.SINGLE);
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
var Binary = class extends DataType {
|
|
459
|
-
constructor() {
|
|
460
|
-
super();
|
|
461
|
-
}
|
|
462
|
-
get typeId() {
|
|
463
|
-
return Type.Binary;
|
|
464
|
-
}
|
|
465
|
-
toString() {
|
|
466
|
-
return "Binary";
|
|
467
|
-
}
|
|
468
|
-
get [Symbol.toStringTag]() {
|
|
469
|
-
return "Binary";
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
var Utf8 = class extends DataType {
|
|
473
|
-
get typeId() {
|
|
474
|
-
return Type.Utf8;
|
|
475
|
-
}
|
|
476
|
-
get [Symbol.toStringTag]() {
|
|
477
|
-
return "Utf8";
|
|
478
|
-
}
|
|
479
|
-
toString() {
|
|
480
|
-
return "Utf8";
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
var DateUnit = {
|
|
484
|
-
DAY: 0,
|
|
485
|
-
MILLISECOND: 1
|
|
486
|
-
};
|
|
487
|
-
var Date = class extends DataType {
|
|
488
|
-
constructor(unit) {
|
|
489
|
-
super();
|
|
490
|
-
this.unit = unit;
|
|
491
|
-
}
|
|
492
|
-
get typeId() {
|
|
493
|
-
return Type.Date;
|
|
494
|
-
}
|
|
495
|
-
get [Symbol.toStringTag]() {
|
|
496
|
-
return "Date";
|
|
497
|
-
}
|
|
498
|
-
toString() {
|
|
499
|
-
return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
var TimeUnit = {
|
|
503
|
-
SECOND: 1,
|
|
504
|
-
MILLISECOND: 1e3,
|
|
505
|
-
MICROSECOND: 1e6,
|
|
506
|
-
NANOSECOND: 1e9
|
|
507
|
-
};
|
|
508
|
-
var Time = class extends DataType {
|
|
509
|
-
constructor(unit, bitWidth) {
|
|
510
|
-
super();
|
|
511
|
-
this.unit = unit;
|
|
512
|
-
this.bitWidth = bitWidth;
|
|
513
|
-
}
|
|
514
|
-
get typeId() {
|
|
515
|
-
return Type.Time;
|
|
516
|
-
}
|
|
517
|
-
toString() {
|
|
518
|
-
return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
|
|
519
|
-
}
|
|
520
|
-
get [Symbol.toStringTag]() {
|
|
521
|
-
return "Time";
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
var Timestamp = class extends DataType {
|
|
525
|
-
constructor(unit, timezone = null) {
|
|
526
|
-
super();
|
|
527
|
-
this.unit = unit;
|
|
528
|
-
this.timezone = timezone;
|
|
529
|
-
}
|
|
530
|
-
get typeId() {
|
|
531
|
-
return Type.Timestamp;
|
|
532
|
-
}
|
|
533
|
-
get [Symbol.toStringTag]() {
|
|
534
|
-
return "Timestamp";
|
|
535
|
-
}
|
|
536
|
-
toString() {
|
|
537
|
-
return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
var IntervalUnit = {
|
|
541
|
-
DAY_TIME: 0,
|
|
542
|
-
YEAR_MONTH: 1
|
|
543
|
-
};
|
|
544
|
-
var Interval = class extends DataType {
|
|
545
|
-
constructor(unit) {
|
|
546
|
-
super();
|
|
547
|
-
this.unit = unit;
|
|
548
|
-
}
|
|
549
|
-
get typeId() {
|
|
550
|
-
return Type.Interval;
|
|
551
|
-
}
|
|
552
|
-
get [Symbol.toStringTag]() {
|
|
553
|
-
return "Interval";
|
|
554
|
-
}
|
|
555
|
-
toString() {
|
|
556
|
-
return `Interval<${IntervalUnit[this.unit]}>`;
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
var FixedSizeList = class extends DataType {
|
|
560
|
-
constructor(listSize, child) {
|
|
561
|
-
super();
|
|
562
|
-
this.listSize = listSize;
|
|
563
|
-
this.children = [child];
|
|
564
|
-
}
|
|
565
|
-
get typeId() {
|
|
566
|
-
return Type.FixedSizeList;
|
|
567
|
-
}
|
|
568
|
-
get valueType() {
|
|
569
|
-
return this.children[0].type;
|
|
570
|
-
}
|
|
571
|
-
get valueField() {
|
|
572
|
-
return this.children[0];
|
|
573
|
-
}
|
|
574
|
-
get [Symbol.toStringTag]() {
|
|
575
|
-
return "FixedSizeList";
|
|
576
|
-
}
|
|
577
|
-
toString() {
|
|
578
|
-
return `FixedSizeList[${this.listSize}]<${this.valueType}>`;
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
var Struct = class extends DataType {
|
|
582
|
-
constructor(children) {
|
|
583
|
-
super();
|
|
584
|
-
this.children = children;
|
|
585
|
-
}
|
|
586
|
-
get typeId() {
|
|
587
|
-
return Type.Struct;
|
|
588
|
-
}
|
|
589
|
-
toString() {
|
|
590
|
-
return `Struct<{${this.children.map((f) => `${f.name}:${f.type}`).join(", ")}}>`;
|
|
591
|
-
}
|
|
592
|
-
get [Symbol.toStringTag]() {
|
|
593
|
-
return "Struct";
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
|
|
597
213
|
// src/lib/decompress-lzf.ts
|
|
598
214
|
function decompressLZF(inData, outLength) {
|
|
599
215
|
const inLength = inData.length;
|
|
@@ -607,30 +223,37 @@
|
|
|
607
223
|
ctrl = inData[inPtr++];
|
|
608
224
|
if (ctrl < 1 << 5) {
|
|
609
225
|
ctrl++;
|
|
610
|
-
if (outPtr + ctrl > outLength)
|
|
226
|
+
if (outPtr + ctrl > outLength) {
|
|
611
227
|
throw new Error("Output buffer is not large enough");
|
|
612
|
-
|
|
228
|
+
}
|
|
229
|
+
if (inPtr + ctrl > inLength) {
|
|
613
230
|
throw new Error("Invalid compressed data");
|
|
231
|
+
}
|
|
614
232
|
do {
|
|
615
233
|
outData[outPtr++] = inData[inPtr++];
|
|
616
234
|
} while (--ctrl);
|
|
617
235
|
} else {
|
|
618
236
|
len = ctrl >> 5;
|
|
619
237
|
ref = outPtr - ((ctrl & 31) << 8) - 1;
|
|
620
|
-
if (inPtr >= inLength)
|
|
238
|
+
if (inPtr >= inLength) {
|
|
621
239
|
throw new Error("Invalid compressed data");
|
|
240
|
+
}
|
|
622
241
|
if (len === 7) {
|
|
623
242
|
len += inData[inPtr++];
|
|
624
|
-
if (inPtr >= inLength)
|
|
243
|
+
if (inPtr >= inLength) {
|
|
625
244
|
throw new Error("Invalid compressed data");
|
|
245
|
+
}
|
|
626
246
|
}
|
|
627
247
|
ref -= inData[inPtr++];
|
|
628
|
-
if (outPtr + len + 2 > outLength)
|
|
248
|
+
if (outPtr + len + 2 > outLength) {
|
|
629
249
|
throw new Error("Output buffer is not large enough");
|
|
630
|
-
|
|
250
|
+
}
|
|
251
|
+
if (ref < 0) {
|
|
631
252
|
throw new Error("Invalid compressed data");
|
|
632
|
-
|
|
253
|
+
}
|
|
254
|
+
if (ref >= outPtr) {
|
|
633
255
|
throw new Error("Invalid compressed data");
|
|
256
|
+
}
|
|
634
257
|
do {
|
|
635
258
|
outData[outPtr++] = outData[ref++];
|
|
636
259
|
} while (--len + 2);
|
|
@@ -644,15 +267,24 @@
|
|
|
644
267
|
const offset = PCDheader.offset;
|
|
645
268
|
const fields = [];
|
|
646
269
|
if (offset.x !== void 0) {
|
|
647
|
-
fields.push(
|
|
270
|
+
fields.push({
|
|
271
|
+
name: "POSITION",
|
|
272
|
+
type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
|
|
273
|
+
});
|
|
648
274
|
}
|
|
649
275
|
if (offset.normal_x !== void 0) {
|
|
650
|
-
fields.push(
|
|
276
|
+
fields.push({
|
|
277
|
+
name: "NORMAL",
|
|
278
|
+
type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
|
|
279
|
+
});
|
|
651
280
|
}
|
|
652
281
|
if (offset.rgb !== void 0) {
|
|
653
|
-
fields.push(
|
|
282
|
+
fields.push({
|
|
283
|
+
name: "COLOR_0",
|
|
284
|
+
type: { type: "fixed-size-list", listSize: 3, children: [{ name: "rgb", type: "uint8" }] }
|
|
285
|
+
});
|
|
654
286
|
}
|
|
655
|
-
return
|
|
287
|
+
return { fields, metadata };
|
|
656
288
|
}
|
|
657
289
|
|
|
658
290
|
// src/lib/parse-pcd.ts
|
|
@@ -676,19 +308,18 @@
|
|
|
676
308
|
}
|
|
677
309
|
attributes = getMeshAttributes(attributes);
|
|
678
310
|
const header = getMeshHeader(pcdHeader, attributes);
|
|
679
|
-
const metadata =
|
|
311
|
+
const metadata = Object.fromEntries([
|
|
680
312
|
["mode", "0"],
|
|
681
313
|
["boundingBox", JSON.stringify(header.boundingBox)]
|
|
682
314
|
]);
|
|
683
315
|
const schema = getPCDSchema(pcdHeader, metadata);
|
|
684
316
|
return {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
},
|
|
317
|
+
loader: "pcd",
|
|
318
|
+
loaderData: pcdHeader,
|
|
688
319
|
header,
|
|
689
320
|
schema,
|
|
690
321
|
mode: 0,
|
|
691
|
-
|
|
322
|
+
topology: "point-list",
|
|
692
323
|
attributes
|
|
693
324
|
};
|
|
694
325
|
}
|
|
@@ -700,7 +331,10 @@
|
|
|
700
331
|
boundingBox: getMeshBoundingBox(attributes)
|
|
701
332
|
};
|
|
702
333
|
}
|
|
703
|
-
return
|
|
334
|
+
return {
|
|
335
|
+
vertexCount: pcdHeader.vertexCount,
|
|
336
|
+
boundingBox: pcdHeader.boundingBox
|
|
337
|
+
};
|
|
704
338
|
}
|
|
705
339
|
function getMeshAttributes(attributes) {
|
|
706
340
|
const normalizedAttributes = {
|
|
@@ -721,6 +355,18 @@
|
|
|
721
355
|
size: 3
|
|
722
356
|
};
|
|
723
357
|
}
|
|
358
|
+
if (attributes.intensity && attributes.intensity.length > 0) {
|
|
359
|
+
normalizedAttributes.COLOR_0 = {
|
|
360
|
+
value: new Uint8Array(attributes.color),
|
|
361
|
+
size: 3
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
if (attributes.label && attributes.label.length > 0) {
|
|
365
|
+
normalizedAttributes.COLOR_0 = {
|
|
366
|
+
value: new Uint8Array(attributes.label),
|
|
367
|
+
size: 3
|
|
368
|
+
};
|
|
369
|
+
}
|
|
724
370
|
return normalizedAttributes;
|
|
725
371
|
}
|
|
726
372
|
function parsePCDHeader(data) {
|
|
@@ -798,6 +444,8 @@
|
|
|
798
444
|
const position = [];
|
|
799
445
|
const normal = [];
|
|
800
446
|
const color = [];
|
|
447
|
+
const intensity = [];
|
|
448
|
+
const label = [];
|
|
801
449
|
const offset = pcdHeader.offset;
|
|
802
450
|
const pcdData = textData.substr(pcdHeader.headerLen);
|
|
803
451
|
const lines = pcdData.split("\n");
|
|
@@ -822,6 +470,12 @@
|
|
|
822
470
|
normal.push(parseFloat(line[offset.normal_y]));
|
|
823
471
|
normal.push(parseFloat(line[offset.normal_z]));
|
|
824
472
|
}
|
|
473
|
+
if (offset.intensity !== void 0) {
|
|
474
|
+
intensity.push(parseFloat(line[offset.intensity]));
|
|
475
|
+
}
|
|
476
|
+
if (offset.label !== void 0) {
|
|
477
|
+
label.push(parseInt(line[offset.label]));
|
|
478
|
+
}
|
|
825
479
|
}
|
|
826
480
|
}
|
|
827
481
|
return { position, normal, color };
|
|
@@ -830,6 +484,8 @@
|
|
|
830
484
|
const position = [];
|
|
831
485
|
const normal = [];
|
|
832
486
|
const color = [];
|
|
487
|
+
const intensity = [];
|
|
488
|
+
const label = [];
|
|
833
489
|
const dataview = new DataView(data, pcdHeader.headerLen);
|
|
834
490
|
const offset = pcdHeader.offset;
|
|
835
491
|
for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
|
|
@@ -848,45 +504,63 @@
|
|
|
848
504
|
normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
|
|
849
505
|
normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
|
|
850
506
|
}
|
|
507
|
+
if (offset.intensity !== void 0) {
|
|
508
|
+
intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
|
|
509
|
+
}
|
|
510
|
+
if (offset.label !== void 0) {
|
|
511
|
+
label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
|
|
512
|
+
}
|
|
851
513
|
}
|
|
852
|
-
return { position, normal, color };
|
|
514
|
+
return { position, normal, color, intensity, label };
|
|
853
515
|
}
|
|
854
|
-
function parsePCDBinaryCompressed(
|
|
516
|
+
function parsePCDBinaryCompressed(pcdHeader, data) {
|
|
855
517
|
const position = [];
|
|
856
518
|
const normal = [];
|
|
857
519
|
const color = [];
|
|
858
|
-
const
|
|
520
|
+
const intensity = [];
|
|
521
|
+
const label = [];
|
|
522
|
+
const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
|
|
859
523
|
const compressedSize = sizes[0];
|
|
860
524
|
const decompressedSize = sizes[1];
|
|
861
|
-
const decompressed = decompressLZF(new Uint8Array(data,
|
|
525
|
+
const decompressed = decompressLZF(new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize), decompressedSize);
|
|
862
526
|
const dataview = new DataView(decompressed.buffer);
|
|
863
|
-
const offset =
|
|
864
|
-
for (let i = 0; i <
|
|
527
|
+
const offset = pcdHeader.offset;
|
|
528
|
+
for (let i = 0; i < pcdHeader.points; i++) {
|
|
865
529
|
if (offset.x !== void 0) {
|
|
866
|
-
position.push(dataview.getFloat32(
|
|
867
|
-
position.push(dataview.getFloat32(
|
|
868
|
-
position.push(dataview.getFloat32(
|
|
530
|
+
position.push(dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN));
|
|
531
|
+
position.push(dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN));
|
|
532
|
+
position.push(dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN));
|
|
869
533
|
}
|
|
870
534
|
if (offset.rgb !== void 0) {
|
|
871
|
-
color.push(dataview.getUint8(
|
|
872
|
-
color.push(dataview.getUint8(
|
|
873
|
-
color.push(dataview.getUint8(
|
|
535
|
+
color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255);
|
|
536
|
+
color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255);
|
|
537
|
+
color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255);
|
|
874
538
|
}
|
|
875
539
|
if (offset.normal_x !== void 0) {
|
|
876
|
-
normal.push(dataview.getFloat32(
|
|
877
|
-
normal.push(dataview.getFloat32(
|
|
878
|
-
normal.push(dataview.getFloat32(
|
|
540
|
+
normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i, LITTLE_ENDIAN));
|
|
541
|
+
normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i, LITTLE_ENDIAN));
|
|
542
|
+
normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i, LITTLE_ENDIAN));
|
|
543
|
+
}
|
|
544
|
+
if (offset.intensity !== void 0) {
|
|
545
|
+
const intensityIndex = pcdHeader.fields.indexOf("intensity");
|
|
546
|
+
intensity.push(dataview.getFloat32(pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i, LITTLE_ENDIAN));
|
|
547
|
+
}
|
|
548
|
+
if (offset.label !== void 0) {
|
|
549
|
+
const labelIndex = pcdHeader.fields.indexOf("label");
|
|
550
|
+
label.push(dataview.getInt32(pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i, LITTLE_ENDIAN));
|
|
879
551
|
}
|
|
880
552
|
}
|
|
881
553
|
return {
|
|
882
554
|
position,
|
|
883
555
|
normal,
|
|
884
|
-
color
|
|
556
|
+
color,
|
|
557
|
+
intensity,
|
|
558
|
+
label
|
|
885
559
|
};
|
|
886
560
|
}
|
|
887
561
|
|
|
888
562
|
// src/pcd-loader.ts
|
|
889
|
-
var VERSION = true ? "4.0.0-alpha.
|
|
563
|
+
var VERSION = true ? "4.0.0-alpha.6" : "latest";
|
|
890
564
|
var PCDLoader = {
|
|
891
565
|
name: "PCD (Point Cloud Data)",
|
|
892
566
|
id: "pcd",
|