@loaders.gl/las 3.1.3 → 4.0.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.
Files changed (56) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/dist.min.js +14970 -100
  4. package/dist/index.js +8 -17
  5. package/dist/index.js.map +1 -0
  6. package/dist/las-loader.js +21 -28
  7. package/dist/las-loader.js.map +1 -0
  8. package/dist/las-worker.js +14908 -47
  9. package/dist/lib/get-las-schema.js +35 -44
  10. package/dist/lib/get-las-schema.js.map +1 -0
  11. package/dist/lib/las-types.js +2 -2
  12. package/dist/{es5/lib → lib}/las-types.js.map +0 -0
  13. package/dist/lib/laslaz-decoder.js +363 -366
  14. package/dist/lib/laslaz-decoder.js.map +1 -0
  15. package/dist/lib/libs/laz-perf.js +2 -19006
  16. package/dist/lib/libs/laz-perf.js.map +1 -0
  17. package/dist/lib/parse-las.js +178 -176
  18. package/dist/lib/parse-las.js.map +1 -0
  19. package/dist/workers/las-worker.js +4 -5
  20. package/dist/workers/las-worker.js.map +1 -0
  21. package/package.json +8 -7
  22. package/dist/es5/bundle.js +0 -7
  23. package/dist/es5/bundle.js.map +0 -1
  24. package/dist/es5/index.js +0 -61
  25. package/dist/es5/index.js.map +0 -1
  26. package/dist/es5/las-loader.js +0 -32
  27. package/dist/es5/las-loader.js.map +0 -1
  28. package/dist/es5/lib/get-las-schema.js +0 -47
  29. package/dist/es5/lib/get-las-schema.js.map +0 -1
  30. package/dist/es5/lib/las-types.js +0 -2
  31. package/dist/es5/lib/laslaz-decoder.js +0 -412
  32. package/dist/es5/lib/laslaz-decoder.js.map +0 -1
  33. package/dist/es5/lib/libs/laz-perf.js +0 -2
  34. package/dist/es5/lib/libs/laz-perf.js.map +0 -1
  35. package/dist/es5/lib/parse-las.js +0 -226
  36. package/dist/es5/lib/parse-las.js.map +0 -1
  37. package/dist/es5/workers/las-worker.js +0 -8
  38. package/dist/es5/workers/las-worker.js.map +0 -1
  39. package/dist/esm/bundle.js +0 -5
  40. package/dist/esm/bundle.js.map +0 -1
  41. package/dist/esm/index.js +0 -9
  42. package/dist/esm/index.js.map +0 -1
  43. package/dist/esm/las-loader.js +0 -24
  44. package/dist/esm/las-loader.js.map +0 -1
  45. package/dist/esm/lib/get-las-schema.js +0 -37
  46. package/dist/esm/lib/get-las-schema.js.map +0 -1
  47. package/dist/esm/lib/las-types.js +0 -2
  48. package/dist/esm/lib/las-types.js.map +0 -1
  49. package/dist/esm/lib/laslaz-decoder.js +0 -392
  50. package/dist/esm/lib/laslaz-decoder.js.map +0 -1
  51. package/dist/esm/lib/libs/laz-perf.js +0 -2
  52. package/dist/esm/lib/libs/laz-perf.js.map +0 -1
  53. package/dist/esm/lib/parse-las.js +0 -191
  54. package/dist/esm/lib/parse-las.js.map +0 -1
  55. package/dist/esm/workers/las-worker.js +0 -4
  56. package/dist/esm/workers/las-worker.js.map +0 -1
@@ -1,395 +1,392 @@
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.LASModuleWasLoaded = exports.LASFile = void 0;
7
- const laz_perf_1 = __importDefault(require("./libs/laz-perf"));
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import getModule from './libs/laz-perf';
8
3
  let Module = null;
9
4
  const POINT_FORMAT_READERS = {
10
- 0: (dv) => {
11
- return {
12
- position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
13
- intensity: dv.getUint16(12, true),
14
- classification: dv.getUint8(15)
15
- };
16
- },
17
- 1: (dv) => {
18
- return {
19
- position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
20
- intensity: dv.getUint16(12, true),
21
- classification: dv.getUint8(15)
22
- };
23
- },
24
- 2: (dv) => {
25
- return {
26
- position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
27
- intensity: dv.getUint16(12, true),
28
- classification: dv.getUint8(15),
29
- color: [dv.getUint16(20, true), dv.getUint16(22, true), dv.getUint16(24, true)]
30
- };
31
- },
32
- 3: (dv) => {
33
- return {
34
- position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
35
- intensity: dv.getUint16(12, true),
36
- classification: dv.getUint8(15),
37
- color: [dv.getUint16(28, true), dv.getUint16(30, true), dv.getUint16(32, true)]
38
- };
39
- }
5
+ 0: dv => {
6
+ return {
7
+ position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
8
+ intensity: dv.getUint16(12, true),
9
+ classification: dv.getUint8(15)
10
+ };
11
+ },
12
+ 1: dv => {
13
+ return {
14
+ position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
15
+ intensity: dv.getUint16(12, true),
16
+ classification: dv.getUint8(15)
17
+ };
18
+ },
19
+ 2: dv => {
20
+ return {
21
+ position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
22
+ intensity: dv.getUint16(12, true),
23
+ classification: dv.getUint8(15),
24
+ color: [dv.getUint16(20, true), dv.getUint16(22, true), dv.getUint16(24, true)]
25
+ };
26
+ },
27
+ 3: dv => {
28
+ return {
29
+ position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
30
+ intensity: dv.getUint16(12, true),
31
+ classification: dv.getUint8(15),
32
+ color: [dv.getUint16(28, true), dv.getUint16(30, true), dv.getUint16(32, true)]
33
+ };
34
+ }
40
35
  };
41
- /**
42
- * Reads incoming binary data depends on the Type parameter
43
- * @param buf
44
- * @param Type
45
- * @param offset
46
- * @param count
47
- * @returns number | number[] from incoming binary data
48
- */
36
+
49
37
  function readAs(buf, Type = {}, offset, count) {
50
- count = count === undefined || count === 0 ? 1 : count;
51
- const sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count);
52
- const r = new Type(sub);
53
- if (count === 1) {
54
- return r[0];
55
- }
56
- const ret = [];
57
- for (let i = 0; i < count; i++) {
58
- ret.push(r[i]);
59
- }
60
- return ret;
38
+ count = count === undefined || count === 0 ? 1 : count;
39
+ const sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count);
40
+ const r = new Type(sub);
41
+
42
+ if (count === 1) {
43
+ return r[0];
44
+ }
45
+
46
+ const ret = [];
47
+
48
+ for (let i = 0; i < count; i++) {
49
+ ret.push(r[i]);
50
+ }
51
+
52
+ return ret;
61
53
  }
62
- /**
63
- * Parsing of header's attributes
64
- * @param arraybuffer
65
- * @returns header as LASHeader
66
- */
54
+
67
55
  function parseLASHeader(arraybuffer) {
68
- let start = 32 * 3 + 35;
69
- const o = {
70
- pointsOffset: readAs(arraybuffer, Uint32Array, 32 * 3),
71
- pointsFormatId: readAs(arraybuffer, Uint8Array, 32 * 3 + 8),
72
- pointsStructSize: readAs(arraybuffer, Uint16Array, 32 * 3 + 8 + 1),
73
- pointsCount: readAs(arraybuffer, Uint32Array, 32 * 3 + 11),
74
- scale: readAs(arraybuffer, Float64Array, start, 3)
75
- };
76
- start += 24; // 8*3
77
- o.offset = readAs(arraybuffer, Float64Array, start, 3);
78
- start += 24;
79
- const bounds = readAs(arraybuffer, Float64Array, start, 6);
80
- start += 48; // 8*6;
81
- o.maxs = [bounds[0], bounds[2], bounds[4]];
82
- o.mins = [bounds[1], bounds[3], bounds[5]];
83
- return o;
56
+ let start = 32 * 3 + 35;
57
+ const o = {
58
+ pointsOffset: readAs(arraybuffer, Uint32Array, 32 * 3),
59
+ pointsFormatId: readAs(arraybuffer, Uint8Array, 32 * 3 + 8),
60
+ pointsStructSize: readAs(arraybuffer, Uint16Array, 32 * 3 + 8 + 1),
61
+ pointsCount: readAs(arraybuffer, Uint32Array, 32 * 3 + 11),
62
+ scale: readAs(arraybuffer, Float64Array, start, 3)
63
+ };
64
+ start += 24;
65
+ o.offset = readAs(arraybuffer, Float64Array, start, 3);
66
+ start += 24;
67
+ const bounds = readAs(arraybuffer, Float64Array, start, 6);
68
+ start += 48;
69
+ o.maxs = [bounds[0], bounds[2], bounds[4]];
70
+ o.mins = [bounds[1], bounds[3], bounds[5]];
71
+ return o;
84
72
  }
85
- // LAS Loader
86
- // Loads uncompressed files
87
- //
73
+
88
74
  class LASLoader {
89
- constructor(arraybuffer) {
90
- this.readOffset = 0;
91
- this.header = {
92
- pointsOffset: 0,
93
- pointsFormatId: 0,
94
- pointsStructSize: 0,
95
- pointsCount: 0,
96
- scale: [0, 0, 0],
97
- offset: [0, 0, 0],
98
- maxs: [0],
99
- mins: [0],
100
- totalToRead: 0,
101
- totalRead: 0,
102
- versionAsString: '',
103
- isCompressed: true
104
- };
105
- this.arraybuffer = arraybuffer;
106
- }
107
- /**
108
- * @returns boolean
109
- */
110
- open() {
111
- // Nothing needs to be done to open this
112
- return true;
75
+ constructor(arraybuffer) {
76
+ _defineProperty(this, "arraybuffer", void 0);
77
+
78
+ _defineProperty(this, "readOffset", 0);
79
+
80
+ _defineProperty(this, "header", {
81
+ pointsOffset: 0,
82
+ pointsFormatId: 0,
83
+ pointsStructSize: 0,
84
+ pointsCount: 0,
85
+ scale: [0, 0, 0],
86
+ offset: [0, 0, 0],
87
+ maxs: [0],
88
+ mins: [0],
89
+ totalToRead: 0,
90
+ totalRead: 0,
91
+ versionAsString: '',
92
+ isCompressed: true
93
+ });
94
+
95
+ this.arraybuffer = arraybuffer;
96
+ }
97
+
98
+ open() {
99
+ return true;
100
+ }
101
+
102
+ getHeader() {
103
+ this.header = parseLASHeader(this.arraybuffer);
104
+ return this.header;
105
+ }
106
+
107
+ readData(count, skip) {
108
+ const {
109
+ header,
110
+ arraybuffer
111
+ } = this;
112
+
113
+ if (!header) {
114
+ throw new Error('Cannot start reading data till a header request is issued');
113
115
  }
114
- /**
115
- * Parsing of incoming binary
116
- * @returns LASHeader
117
- */
118
- getHeader() {
119
- this.header = parseLASHeader(this.arraybuffer);
120
- return this.header;
116
+
117
+ let {
118
+ readOffset
119
+ } = this;
120
+ let start;
121
+
122
+ if (skip <= 1) {
123
+ count = Math.min(count, header.pointsCount - readOffset);
124
+ start = header.pointsOffset + readOffset * header.pointsStructSize;
125
+ const end = start + count * header.pointsStructSize;
126
+ readOffset += count;
127
+ this.readOffset = readOffset;
128
+ return {
129
+ buffer: arraybuffer.slice(start, end),
130
+ count,
131
+ hasMoreData: readOffset < header.pointsCount
132
+ };
121
133
  }
122
- /**
123
- * Reading data
124
- * @param count
125
- * @param skip
126
- * @returns new ArrayBuffer, count, hasMoreData
127
- */
128
- readData(count, skip) {
129
- const { header, arraybuffer } = this;
130
- if (!header) {
131
- throw new Error('Cannot start reading data till a header request is issued');
132
- }
133
- let { readOffset } = this;
134
- let start;
135
- if (skip <= 1) {
136
- count = Math.min(count, header.pointsCount - readOffset);
137
- start = header.pointsOffset + readOffset * header.pointsStructSize;
138
- const end = start + count * header.pointsStructSize;
139
- readOffset += count;
140
- this.readOffset = readOffset;
141
- return {
142
- buffer: arraybuffer.slice(start, end),
143
- count,
144
- hasMoreData: readOffset < header.pointsCount
145
- };
146
- }
147
- const pointsToRead = Math.min(count * skip, header.pointsCount - readOffset);
148
- const bufferSize = Math.ceil(pointsToRead / skip);
149
- let pointsRead = 0;
150
- const buf = new Uint8Array(bufferSize * header.pointsStructSize);
151
- for (let i = 0; i < pointsToRead; i++) {
152
- if (i % skip === 0) {
153
- start = header.pointsOffset + readOffset * header.pointsStructSize;
154
- const src = new Uint8Array(arraybuffer, start, header.pointsStructSize);
155
- buf.set(src, pointsRead * header.pointsStructSize);
156
- pointsRead++;
157
- }
158
- readOffset++;
159
- }
160
- this.readOffset = readOffset;
161
- return {
162
- buffer: buf.buffer,
163
- count: pointsRead,
164
- hasMoreData: readOffset < header.pointsCount
165
- };
166
- }
167
- /**
168
- * Method which brings data to null to close the file
169
- * @returns
170
- */
171
- close() {
172
- // @ts-ignore Possibly null
173
- this.arraybuffer = null;
174
- return true;
134
+
135
+ const pointsToRead = Math.min(count * skip, header.pointsCount - readOffset);
136
+ const bufferSize = Math.ceil(pointsToRead / skip);
137
+ let pointsRead = 0;
138
+ const buf = new Uint8Array(bufferSize * header.pointsStructSize);
139
+
140
+ for (let i = 0; i < pointsToRead; i++) {
141
+ if (i % skip === 0) {
142
+ start = header.pointsOffset + readOffset * header.pointsStructSize;
143
+ const src = new Uint8Array(arraybuffer, start, header.pointsStructSize);
144
+ buf.set(src, pointsRead * header.pointsStructSize);
145
+ pointsRead++;
146
+ }
147
+
148
+ readOffset++;
175
149
  }
150
+
151
+ this.readOffset = readOffset;
152
+ return {
153
+ buffer: buf.buffer,
154
+ count: pointsRead,
155
+ hasMoreData: readOffset < header.pointsCount
156
+ };
157
+ }
158
+
159
+ close() {
160
+ this.arraybuffer = null;
161
+ return true;
162
+ }
163
+
176
164
  }
177
- /**
178
- * LAZ Loader
179
- * Uses NaCL module to load LAZ files
180
- */
165
+
181
166
  class LAZLoader {
182
- constructor(arraybuffer) {
183
- this.instance = null; // LASZip instance
184
- this.header = null;
185
- this.arraybuffer = arraybuffer;
186
- if (!Module) {
187
- // Avoid executing laz-perf on import
188
- Module = (0, laz_perf_1.default)();
189
- }
167
+ constructor(arraybuffer) {
168
+ _defineProperty(this, "arraybuffer", void 0);
169
+
170
+ _defineProperty(this, "instance", null);
171
+
172
+ _defineProperty(this, "header", null);
173
+
174
+ this.arraybuffer = arraybuffer;
175
+
176
+ if (!Module) {
177
+ Module = getModule();
190
178
  }
191
- /**
192
- * Opens the file
193
- * @returns boolean
194
- */
195
- open() {
196
- try {
197
- const { arraybuffer } = this;
198
- this.instance = new Module.LASZip();
199
- const abInt = new Uint8Array(arraybuffer);
200
- const buf = Module._malloc(arraybuffer.byteLength);
201
- this.instance.arraybuffer = arraybuffer;
202
- this.instance.buf = buf;
203
- Module.HEAPU8.set(abInt, buf);
204
- this.instance.open(buf, arraybuffer.byteLength);
205
- this.instance.readOffset = 0;
206
- return true;
207
- }
208
- catch (error) {
209
- throw new Error(`Failed to open file: ${error.message}`);
210
- }
179
+ }
180
+
181
+ open() {
182
+ try {
183
+ const {
184
+ arraybuffer
185
+ } = this;
186
+ this.instance = new Module.LASZip();
187
+ const abInt = new Uint8Array(arraybuffer);
188
+
189
+ const buf = Module._malloc(arraybuffer.byteLength);
190
+
191
+ this.instance.arraybuffer = arraybuffer;
192
+ this.instance.buf = buf;
193
+ Module.HEAPU8.set(abInt, buf);
194
+ this.instance.open(buf, arraybuffer.byteLength);
195
+ this.instance.readOffset = 0;
196
+ return true;
197
+ } catch (error) {
198
+ throw new Error("Failed to open file: ".concat(error.message));
211
199
  }
212
- getHeader() {
213
- if (!this.instance) {
214
- throw new Error('You need to open the file before trying to read header');
215
- }
216
- try {
217
- const header = parseLASHeader(this.instance.arraybuffer);
218
- header.pointsFormatId &= 0x3f;
219
- this.header = header;
220
- return header;
221
- }
222
- catch (error) {
223
- throw new Error(`Failed to get header: ${error.message}`);
224
- }
200
+ }
201
+
202
+ getHeader() {
203
+ if (!this.instance) {
204
+ throw new Error('You need to open the file before trying to read header');
225
205
  }
226
- /**
227
- * @param count
228
- * @param offset
229
- * @param skip
230
- * @returns Data
231
- */
232
- readData(count, offset, skip) {
233
- if (!this.instance) {
234
- throw new Error('You need to open the file before trying to read stuff');
235
- }
236
- const { header, instance } = this;
237
- if (!header) {
238
- throw new Error('You need to query header before reading, I maintain state that way, sorry :(');
239
- }
240
- try {
241
- const pointsToRead = Math.min(count * skip, header.pointsCount - instance.readOffset);
242
- const bufferSize = Math.ceil(pointsToRead / skip);
243
- let pointsRead = 0;
244
- const thisBuf = new Uint8Array(bufferSize * header.pointsStructSize);
245
- const bufRead = Module._malloc(header.pointsStructSize);
246
- for (let i = 0; i < pointsToRead; i++) {
247
- instance.getPoint(bufRead);
248
- if (i % skip === 0) {
249
- const a = new Uint8Array(Module.HEAPU8.buffer, bufRead, header.pointsStructSize);
250
- thisBuf.set(a, pointsRead * header.pointsStructSize);
251
- pointsRead++;
252
- }
253
- instance.readOffset++;
254
- }
255
- return {
256
- buffer: thisBuf.buffer,
257
- count: pointsRead,
258
- hasMoreData: instance.readOffset < header.pointsCount
259
- };
260
- }
261
- catch (error) {
262
- throw new Error(`Failed to read data: ${error.message}`);
263
- }
206
+
207
+ try {
208
+ const header = parseLASHeader(this.instance.arraybuffer);
209
+ header.pointsFormatId &= 0x3f;
210
+ this.header = header;
211
+ return header;
212
+ } catch (error) {
213
+ throw new Error("Failed to get header: ".concat(error.message));
264
214
  }
265
- /**
266
- * Deletes the instance
267
- * @returns boolean
268
- */
269
- close() {
270
- try {
271
- if (this.instance !== null) {
272
- this.instance.delete();
273
- this.instance = null;
274
- }
275
- return true;
276
- }
277
- catch (error) {
278
- throw new Error(`Failed to close file: ${error.message}`);
279
- }
215
+ }
216
+
217
+ readData(count, offset, skip) {
218
+ if (!this.instance) {
219
+ throw new Error('You need to open the file before trying to read stuff');
280
220
  }
281
- }
282
- /**
283
- * Helper class: Decodes LAS records into points
284
- */
285
- class LASDecoder {
286
- constructor(buffer, len, header) {
287
- this.arrayb = buffer;
288
- this.decoder = POINT_FORMAT_READERS[header.pointsFormatId];
289
- this.pointsCount = len;
290
- this.pointSize = header.pointsStructSize;
291
- this.scale = header.scale;
292
- this.offset = header.offset;
293
- this.mins = header.mins;
294
- this.maxs = header.maxs;
221
+
222
+ const {
223
+ header,
224
+ instance
225
+ } = this;
226
+
227
+ if (!header) {
228
+ throw new Error('You need to query header before reading, I maintain state that way, sorry :(');
295
229
  }
296
- /**
297
- * Decodes data depends on this point size
298
- * @param index
299
- * @returns New object
300
- */
301
- getPoint(index) {
302
- if (index < 0 || index >= this.pointsCount) {
303
- throw new Error('Point index out of range');
230
+
231
+ try {
232
+ const pointsToRead = Math.min(count * skip, header.pointsCount - instance.readOffset);
233
+ const bufferSize = Math.ceil(pointsToRead / skip);
234
+ let pointsRead = 0;
235
+ const thisBuf = new Uint8Array(bufferSize * header.pointsStructSize);
236
+
237
+ const bufRead = Module._malloc(header.pointsStructSize);
238
+
239
+ for (let i = 0; i < pointsToRead; i++) {
240
+ instance.getPoint(bufRead);
241
+
242
+ if (i % skip === 0) {
243
+ const a = new Uint8Array(Module.HEAPU8.buffer, bufRead, header.pointsStructSize);
244
+ thisBuf.set(a, pointsRead * header.pointsStructSize);
245
+ pointsRead++;
304
246
  }
305
- const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
306
- return this.decoder(dv);
247
+
248
+ instance.readOffset++;
249
+ }
250
+
251
+ return {
252
+ buffer: thisBuf.buffer,
253
+ count: pointsRead,
254
+ hasMoreData: instance.readOffset < header.pointsCount
255
+ };
256
+ } catch (error) {
257
+ throw new Error("Failed to read data: ".concat(error.message));
307
258
  }
308
- }
309
- /**
310
- * A single consistent interface for loading LAS/LAZ files
311
- */
312
- class LASFile {
313
- constructor(arraybuffer) {
314
- this.formatId = 0;
315
- this.isCompressed = true;
316
- this.isOpen = false;
317
- this.version = 0;
318
- this.versionAsString = '';
319
- this.arraybuffer = arraybuffer;
320
- if (this.determineVersion() > 13) {
321
- throw new Error('Only file versions <= 1.3 are supported at this time');
322
- }
323
- this.determineFormat();
324
- if (POINT_FORMAT_READERS[this.formatId] === undefined) {
325
- throw new Error('The point format ID is not supported');
326
- }
327
- this.loader = this.isCompressed
328
- ? new LAZLoader(this.arraybuffer)
329
- : new LASLoader(this.arraybuffer);
259
+ }
260
+
261
+ close() {
262
+ try {
263
+ if (this.instance !== null) {
264
+ this.instance.delete();
265
+ this.instance = null;
266
+ }
267
+
268
+ return true;
269
+ } catch (error) {
270
+ throw new Error("Failed to close file: ".concat(error.message));
330
271
  }
331
- /**
332
- * Determines format in parameters of LASHeaer
333
- */
334
- determineFormat() {
335
- const formatId = readAs(this.arraybuffer, Uint8Array, 32 * 3 + 8);
336
- const bit7 = (formatId & 0x80) >> 7;
337
- const bit6 = (formatId & 0x40) >> 6;
338
- if (bit7 === 1 && bit6 === 1) {
339
- throw new Error('Old style compression not supported');
340
- }
341
- this.formatId = formatId & 0x3f;
342
- this.isCompressed = bit7 === 1 || bit6 === 1;
343
- }
344
- /**
345
- * Determines version
346
- * @returns version
347
- */
348
- determineVersion() {
349
- const ver = new Int8Array(this.arraybuffer, 24, 2);
350
- this.version = ver[0] * 10 + ver[1];
351
- this.versionAsString = `${ver[0]}.${ver[1]}`;
352
- return this.version;
272
+ }
273
+
274
+ }
275
+
276
+ class LASDecoder {
277
+ constructor(buffer, len, header) {
278
+ _defineProperty(this, "arrayb", void 0);
279
+
280
+ _defineProperty(this, "decoder", void 0);
281
+
282
+ _defineProperty(this, "pointsCount", void 0);
283
+
284
+ _defineProperty(this, "pointSize", void 0);
285
+
286
+ _defineProperty(this, "scale", void 0);
287
+
288
+ _defineProperty(this, "offset", void 0);
289
+
290
+ _defineProperty(this, "mins", void 0);
291
+
292
+ _defineProperty(this, "maxs", void 0);
293
+
294
+ this.arrayb = buffer;
295
+ this.decoder = POINT_FORMAT_READERS[header.pointsFormatId];
296
+ this.pointsCount = len;
297
+ this.pointSize = header.pointsStructSize;
298
+ this.scale = header.scale;
299
+ this.offset = header.offset;
300
+ this.mins = header.mins;
301
+ this.maxs = header.maxs;
302
+ }
303
+
304
+ getPoint(index) {
305
+ if (index < 0 || index >= this.pointsCount) {
306
+ throw new Error('Point index out of range');
353
307
  }
354
- /**
355
- * Reads if the file is open
356
- * @returns boolean
357
- */
358
- open() {
359
- if (this.loader.open()) {
360
- this.isOpen = true;
361
- }
308
+
309
+ const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
310
+ return this.decoder(dv);
311
+ }
312
+
313
+ }
314
+
315
+ export class LASFile {
316
+ constructor(arraybuffer) {
317
+ _defineProperty(this, "arraybuffer", void 0);
318
+
319
+ _defineProperty(this, "formatId", 0);
320
+
321
+ _defineProperty(this, "loader", void 0);
322
+
323
+ _defineProperty(this, "isCompressed", true);
324
+
325
+ _defineProperty(this, "isOpen", false);
326
+
327
+ _defineProperty(this, "version", 0);
328
+
329
+ _defineProperty(this, "versionAsString", '');
330
+
331
+ this.arraybuffer = arraybuffer;
332
+
333
+ if (this.determineVersion() > 13) {
334
+ throw new Error('Only file versions <= 1.3 are supported at this time');
362
335
  }
363
- /**
364
- * Gets the header
365
- * @returns Header
366
- */
367
- getHeader() {
368
- return this.loader.getHeader();
336
+
337
+ this.determineFormat();
338
+
339
+ if (POINT_FORMAT_READERS[this.formatId] === undefined) {
340
+ throw new Error('The point format ID is not supported');
369
341
  }
370
- /**
371
- * @param count
372
- * @param start
373
- * @param skip
374
- * @returns Data
375
- */
376
- readData(count, start, skip) {
377
- return this.loader.readData(count, start, skip);
342
+
343
+ this.loader = this.isCompressed ? new LAZLoader(this.arraybuffer) : new LASLoader(this.arraybuffer);
344
+ }
345
+
346
+ determineFormat() {
347
+ const formatId = readAs(this.arraybuffer, Uint8Array, 32 * 3 + 8);
348
+ const bit7 = (formatId & 0x80) >> 7;
349
+ const bit6 = (formatId & 0x40) >> 6;
350
+
351
+ if (bit7 === 1 && bit6 === 1) {
352
+ throw new Error('Old style compression not supported');
378
353
  }
379
- /**
380
- * Closes the file
381
- */
382
- close() {
383
- if (this.loader.close()) {
384
- this.isOpen = false;
385
- }
354
+
355
+ this.formatId = formatId & 0x3f;
356
+ this.isCompressed = bit7 === 1 || bit6 === 1;
357
+ }
358
+
359
+ determineVersion() {
360
+ const ver = new Int8Array(this.arraybuffer, 24, 2);
361
+ this.version = ver[0] * 10 + ver[1];
362
+ this.versionAsString = "".concat(ver[0], ".").concat(ver[1]);
363
+ return this.version;
364
+ }
365
+
366
+ open() {
367
+ if (this.loader.open()) {
368
+ this.isOpen = true;
386
369
  }
387
- /**
388
- */
389
- getUnpacker() {
390
- return LASDecoder;
370
+ }
371
+
372
+ getHeader() {
373
+ return this.loader.getHeader();
374
+ }
375
+
376
+ readData(count, start, skip) {
377
+ return this.loader.readData(count, start, skip);
378
+ }
379
+
380
+ close() {
381
+ if (this.loader.close()) {
382
+ this.isOpen = false;
391
383
  }
384
+ }
385
+
386
+ getUnpacker() {
387
+ return LASDecoder;
388
+ }
389
+
392
390
  }
393
- exports.LASFile = LASFile;
394
- exports.LASModuleWasLoaded = false;
395
- /* eslint no-use-before-define: 2 */
391
+ export const LASModuleWasLoaded = false;
392
+ //# sourceMappingURL=laslaz-decoder.js.map