@loaders.gl/pcd 3.1.0-alpha.4 → 3.1.0-beta.3

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.
Files changed (40) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +778 -0
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/index.js +5 -37
  7. package/dist/es5/index.js.map +1 -1
  8. package/dist/es5/lib/get-pcd-schema.js +2 -2
  9. package/dist/es5/lib/get-pcd-schema.js.map +1 -1
  10. package/dist/es5/lib/parse-pcd.js +47 -51
  11. package/dist/es5/lib/parse-pcd.js.map +1 -1
  12. package/dist/es5/pcd-loader.js +3 -3
  13. package/dist/es5/pcd-loader.js.map +1 -1
  14. package/dist/esm/lib/parse-pcd.js +1 -1
  15. package/dist/esm/lib/parse-pcd.js.map +1 -1
  16. package/dist/esm/pcd-loader.js +1 -1
  17. package/dist/esm/pcd-loader.js.map +1 -1
  18. package/dist/index.d.ts +32 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +18 -0
  21. package/dist/lib/get-pcd-schema.d.ts +12 -0
  22. package/dist/lib/get-pcd-schema.d.ts.map +1 -0
  23. package/dist/lib/get-pcd-schema.js +25 -0
  24. package/dist/lib/parse-pcd.d.ts +17 -0
  25. package/dist/lib/parse-pcd.d.ts.map +1 -0
  26. package/dist/lib/parse-pcd.js +245 -0
  27. package/dist/lib/pcd-types.d.ts +31 -0
  28. package/dist/lib/pcd-types.d.ts.map +1 -0
  29. package/dist/lib/pcd-types.js +2 -0
  30. package/dist/pcd-loader.d.ts +18 -0
  31. package/dist/pcd-loader.d.ts.map +1 -0
  32. package/dist/pcd-loader.js +22 -0
  33. package/dist/pcd-worker.js +832 -2
  34. package/dist/workers/pcd-worker.d.ts +2 -0
  35. package/dist/workers/pcd-worker.d.ts.map +1 -0
  36. package/dist/workers/pcd-worker.js +5 -0
  37. package/package.json +7 -7
  38. package/dist/dist.min.js +0 -2
  39. package/dist/dist.min.js.map +0 -1
  40. package/dist/pcd-worker.js.map +0 -1
@@ -0,0 +1,12 @@
1
+ import { Schema } from '@loaders.gl/schema';
2
+ import type { PCDHeader } from './pcd-types';
3
+ declare type SchemaMetadata = Map<string, any>;
4
+ /**
5
+ * Gets schema from PCD header
6
+ * @param PCDheader
7
+ * @param metadata
8
+ * @returns Schema
9
+ */
10
+ export declare function getPCDSchema(PCDheader: PCDHeader, metadata: SchemaMetadata): Schema;
11
+ export {};
12
+ //# sourceMappingURL=get-pcd-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-pcd-schema.d.ts","sourceRoot":"","sources":["../../src/lib/get-pcd-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAuC,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAE3C,aAAK,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEvC;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,GAAG,MAAM,CAoBnF"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPCDSchema = void 0;
4
+ const schema_1 = require("@loaders.gl/schema");
5
+ /**
6
+ * Gets schema from PCD header
7
+ * @param PCDheader
8
+ * @param metadata
9
+ * @returns Schema
10
+ */
11
+ function getPCDSchema(PCDheader, metadata) {
12
+ const offset = PCDheader.offset;
13
+ const fields = [];
14
+ if (offset.x !== undefined) {
15
+ fields.push(new schema_1.Field('POSITION', new schema_1.FixedSizeList(3, new schema_1.Field('xyz', new schema_1.Float32())), false));
16
+ }
17
+ if (offset.normal_x !== undefined) {
18
+ fields.push(new schema_1.Field('NORMAL', new schema_1.FixedSizeList(3, new schema_1.Field('xyz', new schema_1.Float32())), false));
19
+ }
20
+ if (offset.rgb !== undefined) {
21
+ fields.push(new schema_1.Field('COLOR_0', new schema_1.FixedSizeList(3, new schema_1.Field('rgb', new schema_1.Uint8())), false));
22
+ }
23
+ return new schema_1.Schema(fields, metadata);
24
+ }
25
+ exports.getPCDSchema = getPCDSchema;
@@ -0,0 +1,17 @@
1
+ import type { PCDHeader } from './pcd-types';
2
+ /**
3
+ *
4
+ * @param data
5
+ * @returns
6
+ */
7
+ export default function parsePCD(data: ArrayBufferLike): {
8
+ loaderData: {
9
+ header: PCDHeader;
10
+ };
11
+ header: Partial<PCDHeader>;
12
+ schema: import("@loaders.gl/schema").Schema;
13
+ mode: number;
14
+ indices: null;
15
+ attributes: any;
16
+ };
17
+ //# sourceMappingURL=parse-pcd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-pcd.d.ts","sourceRoot":"","sources":["../../src/lib/parse-pcd.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAwB3C;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,IAAI,EAAE,eAAe;;;;;;;;;EA2CrD"}
@@ -0,0 +1,245 @@
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 get_pcd_schema_1 = require("./get-pcd-schema");
12
+ const LITTLE_ENDIAN = true;
13
+ /**
14
+ *
15
+ * @param data
16
+ * @returns
17
+ */
18
+ function parsePCD(data) {
19
+ // parse header (always ascii format)
20
+ const textData = new TextDecoder().decode(data);
21
+ const pcdHeader = parsePCDHeader(textData);
22
+ let attributes = {};
23
+ // parse data
24
+ switch (pcdHeader.data) {
25
+ case 'ascii':
26
+ attributes = parsePCDASCII(pcdHeader, textData);
27
+ break;
28
+ case 'binary':
29
+ attributes = parsePCDBinary(pcdHeader, data);
30
+ break;
31
+ case 'binary_compressed':
32
+ default:
33
+ throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
34
+ }
35
+ attributes = getMeshAttributes(attributes);
36
+ const header = getMeshHeader(pcdHeader, attributes);
37
+ const metadata = new Map([
38
+ ['mode', '0'],
39
+ ['boundingBox', JSON.stringify(header.boundingBox)]
40
+ ]);
41
+ const schema = (0, get_pcd_schema_1.getPCDSchema)(pcdHeader, metadata);
42
+ return {
43
+ loaderData: {
44
+ header: pcdHeader
45
+ },
46
+ header,
47
+ schema,
48
+ mode: 0,
49
+ indices: null,
50
+ attributes
51
+ };
52
+ }
53
+ exports.default = parsePCD;
54
+ // Create a header that contains common data for PointCloud category loaders
55
+ function getMeshHeader(pcdHeader, attributes) {
56
+ if (typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
57
+ const pointCount = pcdHeader.width * pcdHeader.height; // Supports "organized" point sets
58
+ return {
59
+ vertexCount: pointCount,
60
+ boundingBox: (0, schema_1.getMeshBoundingBox)(attributes)
61
+ };
62
+ }
63
+ return pcdHeader;
64
+ }
65
+ /**
66
+ * @param attributes
67
+ * @returns Normalized attributes
68
+ */
69
+ function getMeshAttributes(attributes) {
70
+ const normalizedAttributes = {
71
+ POSITION: {
72
+ // Binary PCD is only 32 bit
73
+ value: new Float32Array(attributes.position),
74
+ size: 3
75
+ }
76
+ };
77
+ if (attributes.normal && attributes.normal.length > 0) {
78
+ normalizedAttributes.NORMAL = {
79
+ value: new Float32Array(attributes.normal),
80
+ size: 3
81
+ };
82
+ }
83
+ if (attributes.color && attributes.color.length > 0) {
84
+ // TODO - RGBA
85
+ normalizedAttributes.COLOR_0 = {
86
+ value: new Uint8Array(attributes.color),
87
+ size: 3
88
+ };
89
+ }
90
+ return normalizedAttributes;
91
+ }
92
+ /**
93
+ * Incoming data parsing
94
+ * @param data
95
+ * @returns Header
96
+ */
97
+ /* eslint-disable complexity, max-statements */
98
+ function parsePCDHeader(data) {
99
+ const result1 = data.search(/[\r\n]DATA\s(\S*)\s/i);
100
+ const result2 = /[\r\n]DATA\s(\S*)\s/i.exec(data.substr(result1 - 1));
101
+ const pcdHeader = {};
102
+ pcdHeader.data = result2 && result2[1];
103
+ if (result2 !== null) {
104
+ pcdHeader.headerLen = (result2 && result2[0].length) + result1;
105
+ }
106
+ pcdHeader.str = data.substr(0, pcdHeader.headerLen);
107
+ // remove comments
108
+ pcdHeader.str = pcdHeader.str.replace(/\#.*/gi, '');
109
+ // parse
110
+ pcdHeader.version = /VERSION (.*)/i.exec(pcdHeader.str);
111
+ pcdHeader.fields = /FIELDS (.*)/i.exec(pcdHeader.str);
112
+ pcdHeader.size = /SIZE (.*)/i.exec(pcdHeader.str);
113
+ pcdHeader.type = /TYPE (.*)/i.exec(pcdHeader.str);
114
+ pcdHeader.count = /COUNT (.*)/i.exec(pcdHeader.str);
115
+ pcdHeader.width = /WIDTH (.*)/i.exec(pcdHeader.str);
116
+ pcdHeader.height = /HEIGHT (.*)/i.exec(pcdHeader.str);
117
+ pcdHeader.viewpoint = /VIEWPOINT (.*)/i.exec(pcdHeader.str);
118
+ pcdHeader.points = /POINTS (.*)/i.exec(pcdHeader.str);
119
+ // evaluate
120
+ if (pcdHeader.version !== null) {
121
+ pcdHeader.version = parseFloat(pcdHeader.version[1]);
122
+ }
123
+ if (pcdHeader.fields !== null) {
124
+ pcdHeader.fields = pcdHeader.fields[1].split(' ');
125
+ }
126
+ if (pcdHeader.type !== null) {
127
+ pcdHeader.type = pcdHeader.type[1].split(' ');
128
+ }
129
+ if (pcdHeader.width !== null) {
130
+ pcdHeader.width = parseInt(pcdHeader.width[1], 10);
131
+ }
132
+ if (pcdHeader.height !== null) {
133
+ pcdHeader.height = parseInt(pcdHeader.height[1], 10);
134
+ }
135
+ if (pcdHeader.viewpoint !== null) {
136
+ pcdHeader.viewpoint = pcdHeader.viewpoint[1];
137
+ }
138
+ if (pcdHeader.points !== null) {
139
+ pcdHeader.points = parseInt(pcdHeader.points[1], 10);
140
+ }
141
+ if (pcdHeader.points === null &&
142
+ typeof pcdHeader.width === 'number' &&
143
+ typeof pcdHeader.height === 'number') {
144
+ pcdHeader.points = pcdHeader.width * pcdHeader.height;
145
+ }
146
+ if (pcdHeader.size !== null) {
147
+ pcdHeader.size = pcdHeader.size[1].split(' ').map((x) => parseInt(x, 10));
148
+ }
149
+ if (pcdHeader.count !== null) {
150
+ pcdHeader.count = pcdHeader.count[1].split(' ').map((x) => parseInt(x, 10));
151
+ }
152
+ else {
153
+ pcdHeader.count = [];
154
+ if (pcdHeader.fields !== null) {
155
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
156
+ pcdHeader.count.push(1);
157
+ }
158
+ }
159
+ }
160
+ pcdHeader.offset = {};
161
+ let sizeSum = 0;
162
+ if (pcdHeader.fields !== null && pcdHeader.size !== null) {
163
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
164
+ if (pcdHeader.data === 'ascii') {
165
+ pcdHeader.offset[pcdHeader.fields[i]] = i;
166
+ }
167
+ else {
168
+ pcdHeader.offset[pcdHeader.fields[i]] = sizeSum;
169
+ sizeSum += pcdHeader.size[i];
170
+ }
171
+ }
172
+ }
173
+ // for binary only
174
+ pcdHeader.rowSize = sizeSum;
175
+ return pcdHeader;
176
+ }
177
+ /**
178
+ * @param pcdHeader
179
+ * @param textData
180
+ * @returns [attributes]
181
+ */
182
+ /* eslint-enable complexity, max-statements */
183
+ function parsePCDASCII(pcdHeader, textData) {
184
+ const position = [];
185
+ const normal = [];
186
+ const color = [];
187
+ const offset = pcdHeader.offset;
188
+ const pcdData = textData.substr(pcdHeader.headerLen);
189
+ const lines = pcdData.split('\n');
190
+ for (let i = 0; i < lines.length; i++) {
191
+ if (lines[i] !== '') {
192
+ const line = lines[i].split(' ');
193
+ if (offset.x !== undefined) {
194
+ position.push(parseFloat(line[offset.x]));
195
+ position.push(parseFloat(line[offset.y]));
196
+ position.push(parseFloat(line[offset.z]));
197
+ }
198
+ if (offset.rgb !== undefined) {
199
+ const floatValue = parseFloat(line[offset.rgb]);
200
+ const binaryColor = new Float32Array([floatValue]);
201
+ const dataview = new DataView(binaryColor.buffer, 0);
202
+ color.push(dataview.getUint8(0));
203
+ color.push(dataview.getUint8(1));
204
+ color.push(dataview.getUint8(2));
205
+ // TODO - handle alpha channel / RGBA?
206
+ }
207
+ if (offset.normal_x !== undefined) {
208
+ normal.push(parseFloat(line[offset.normal_x]));
209
+ normal.push(parseFloat(line[offset.normal_y]));
210
+ normal.push(parseFloat(line[offset.normal_z]));
211
+ }
212
+ }
213
+ }
214
+ return { position, normal, color };
215
+ }
216
+ /**
217
+ * @param pcdHeader
218
+ * @param data
219
+ * @returns [attributes]
220
+ */
221
+ function parsePCDBinary(pcdHeader, data) {
222
+ const position = [];
223
+ const normal = [];
224
+ const color = [];
225
+ const dataview = new DataView(data, pcdHeader.headerLen);
226
+ const offset = pcdHeader.offset;
227
+ for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
228
+ if (offset.x !== undefined) {
229
+ position.push(dataview.getFloat32(row + offset.x, LITTLE_ENDIAN));
230
+ position.push(dataview.getFloat32(row + offset.y, LITTLE_ENDIAN));
231
+ position.push(dataview.getFloat32(row + offset.z, LITTLE_ENDIAN));
232
+ }
233
+ if (offset.rgb !== undefined) {
234
+ color.push(dataview.getUint8(row + offset.rgb + 0));
235
+ color.push(dataview.getUint8(row + offset.rgb + 1));
236
+ color.push(dataview.getUint8(row + offset.rgb + 2));
237
+ }
238
+ if (offset.normal_x !== undefined) {
239
+ normal.push(dataview.getFloat32(row + offset.normal_x, LITTLE_ENDIAN));
240
+ normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
241
+ normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
242
+ }
243
+ }
244
+ return { position, normal, color };
245
+ }
@@ -0,0 +1,31 @@
1
+ import type { Mesh } from '@loaders.gl/schema';
2
+ declare type BoundingBox = [[number, number, number], [number, number, number]];
3
+ export declare type PCDHeader = {
4
+ data: any;
5
+ headerLen: number;
6
+ str: string;
7
+ version: RegExpExecArray | null | number;
8
+ fields: RegExpExecArray | null | string[];
9
+ size: RegExpExecArray | null | number[];
10
+ type: RegExpExecArray | null | string[];
11
+ count: RegExpExecArray | null | number[];
12
+ width: RegExpExecArray | number;
13
+ height: RegExpExecArray | number;
14
+ viewpoint: RegExpExecArray | null | string;
15
+ points: RegExpExecArray | number;
16
+ offset: {
17
+ [index: string]: number;
18
+ };
19
+ rowSize: number;
20
+ vertexCount: number;
21
+ boundingBox: BoundingBox;
22
+ };
23
+ /** */
24
+ export declare type PCDMesh = Mesh & {
25
+ loader: 'pcd';
26
+ loaderData: PCDHeader;
27
+ topology: 'point-list';
28
+ mode: 0;
29
+ };
30
+ export {};
31
+ //# sourceMappingURL=pcd-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pcd-types.d.ts","sourceRoot":"","sources":["../../src/lib/pcd-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AAE7C,aAAK,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAExE,oBAAY,SAAS,GAAG;IACtB,IAAI,EAAE,GAAG,CAAC;IACV,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,CAAC;IACzC,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IAC1C,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IACxC,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IACxC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;IACzC,KAAK,EAAE,eAAe,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,eAAe,GAAG,MAAM,CAAC;IACjC,SAAS,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,eAAe,GAAG,MAAM,CAAC;IACjC,MAAM,EAAE;QAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,OAAO;AACP,oBAAY,OAAO,GAAG,IAAI,GAAG;IAC3B,MAAM,EAAE,KAAK,CAAC;IACd,UAAU,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC;CACT,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ import type { Loader } from '@loaders.gl/loader-utils';
2
+ /**
3
+ * Worker loader for PCD - Point Cloud Data
4
+ */
5
+ export declare const PCDLoader: {
6
+ name: string;
7
+ id: string;
8
+ module: string;
9
+ version: any;
10
+ worker: boolean;
11
+ extensions: string[];
12
+ mimeTypes: string[];
13
+ options: {
14
+ pcd: {};
15
+ };
16
+ };
17
+ export declare const _typecheckPCDLoader: Loader;
18
+ //# sourceMappingURL=pcd-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pcd-loader.d.ts","sourceRoot":"","sources":["../src/pcd-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAMrD;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;CAWrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAkB,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckPCDLoader = exports.PCDLoader = void 0;
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
+ /**
8
+ * Worker loader for PCD - Point Cloud Data
9
+ */
10
+ exports.PCDLoader = {
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
+ }
21
+ };
22
+ exports._typecheckPCDLoader = exports.PCDLoader;