@loaders.gl/las 3.1.0-beta.4 → 3.1.1

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.
@@ -7,27 +7,31 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.LASModuleWasLoaded = exports.LASFile = void 0;
9
9
 
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
10
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
15
 
12
16
  var _lazPerf = _interopRequireDefault(require("./libs/laz-perf"));
13
17
 
14
- let Module = null;
15
- const POINT_FORMAT_READERS = {
16
- 0: dv => {
18
+ var Module = null;
19
+ var POINT_FORMAT_READERS = {
20
+ 0: function _(dv) {
17
21
  return {
18
22
  position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
19
23
  intensity: dv.getUint16(12, true),
20
24
  classification: dv.getUint8(15)
21
25
  };
22
26
  },
23
- 1: dv => {
27
+ 1: function _(dv) {
24
28
  return {
25
29
  position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
26
30
  intensity: dv.getUint16(12, true),
27
31
  classification: dv.getUint8(15)
28
32
  };
29
33
  },
30
- 2: dv => {
34
+ 2: function _(dv) {
31
35
  return {
32
36
  position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
33
37
  intensity: dv.getUint16(12, true),
@@ -35,7 +39,7 @@ const POINT_FORMAT_READERS = {
35
39
  color: [dv.getUint16(20, true), dv.getUint16(22, true), dv.getUint16(24, true)]
36
40
  };
37
41
  },
38
- 3: dv => {
42
+ 3: function _(dv) {
39
43
  return {
40
44
  position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
41
45
  intensity: dv.getUint16(12, true),
@@ -45,18 +49,21 @@ const POINT_FORMAT_READERS = {
45
49
  }
46
50
  };
47
51
 
48
- function readAs(buf, Type = {}, offset, count) {
52
+ function readAs(buf) {
53
+ var Type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
54
+ var offset = arguments.length > 2 ? arguments[2] : undefined;
55
+ var count = arguments.length > 3 ? arguments[3] : undefined;
49
56
  count = count === undefined || count === 0 ? 1 : count;
50
- const sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count);
51
- const r = new Type(sub);
57
+ var sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count);
58
+ var r = new Type(sub);
52
59
 
53
60
  if (count === 1) {
54
61
  return r[0];
55
62
  }
56
63
 
57
- const ret = [];
64
+ var ret = [];
58
65
 
59
- for (let i = 0; i < count; i++) {
66
+ for (var i = 0; i < count; i++) {
60
67
  ret.push(r[i]);
61
68
  }
62
69
 
@@ -64,8 +71,8 @@ function readAs(buf, Type = {}, offset, count) {
64
71
  }
65
72
 
66
73
  function parseLASHeader(arraybuffer) {
67
- let start = 32 * 3 + 35;
68
- const o = {
74
+ var start = 32 * 3 + 35;
75
+ var o = {
69
76
  pointsOffset: readAs(arraybuffer, Uint32Array, 32 * 3),
70
77
  pointsFormatId: readAs(arraybuffer, Uint8Array, 32 * 3 + 8),
71
78
  pointsStructSize: readAs(arraybuffer, Uint16Array, 32 * 3 + 8 + 1),
@@ -75,15 +82,16 @@ function parseLASHeader(arraybuffer) {
75
82
  start += 24;
76
83
  o.offset = readAs(arraybuffer, Float64Array, start, 3);
77
84
  start += 24;
78
- const bounds = readAs(arraybuffer, Float64Array, start, 6);
85
+ var bounds = readAs(arraybuffer, Float64Array, start, 6);
79
86
  start += 48;
80
87
  o.maxs = [bounds[0], bounds[2], bounds[4]];
81
88
  o.mins = [bounds[1], bounds[3], bounds[5]];
82
89
  return o;
83
90
  }
84
91
 
85
- class LASLoader {
86
- constructor(arraybuffer) {
92
+ var LASLoader = function () {
93
+ function LASLoader(arraybuffer) {
94
+ (0, _classCallCheck2.default)(this, LASLoader);
87
95
  (0, _defineProperty2.default)(this, "arraybuffer", void 0);
88
96
  (0, _defineProperty2.default)(this, "readOffset", 0);
89
97
  (0, _defineProperty2.default)(this, "header", {
@@ -103,76 +111,79 @@ class LASLoader {
103
111
  this.arraybuffer = arraybuffer;
104
112
  }
105
113
 
106
- open() {
107
- return true;
108
- }
114
+ (0, _createClass2.default)(LASLoader, [{
115
+ key: "open",
116
+ value: function open() {
117
+ return true;
118
+ }
119
+ }, {
120
+ key: "getHeader",
121
+ value: function getHeader() {
122
+ this.header = parseLASHeader(this.arraybuffer);
123
+ return this.header;
124
+ }
125
+ }, {
126
+ key: "readData",
127
+ value: function readData(count, skip) {
128
+ var header = this.header,
129
+ arraybuffer = this.arraybuffer;
130
+
131
+ if (!header) {
132
+ throw new Error('Cannot start reading data till a header request is issued');
133
+ }
109
134
 
110
- getHeader() {
111
- this.header = parseLASHeader(this.arraybuffer);
112
- return this.header;
113
- }
135
+ var readOffset = this.readOffset;
136
+ var start;
114
137
 
115
- readData(count, skip) {
116
- const {
117
- header,
118
- arraybuffer
119
- } = this;
138
+ if (skip <= 1) {
139
+ count = Math.min(count, header.pointsCount - readOffset);
140
+ start = header.pointsOffset + readOffset * header.pointsStructSize;
141
+ var end = start + count * header.pointsStructSize;
142
+ readOffset += count;
143
+ this.readOffset = readOffset;
144
+ return {
145
+ buffer: arraybuffer.slice(start, end),
146
+ count: count,
147
+ hasMoreData: readOffset < header.pointsCount
148
+ };
149
+ }
120
150
 
121
- if (!header) {
122
- throw new Error('Cannot start reading data till a header request is issued');
123
- }
151
+ var pointsToRead = Math.min(count * skip, header.pointsCount - readOffset);
152
+ var bufferSize = Math.ceil(pointsToRead / skip);
153
+ var pointsRead = 0;
154
+ var buf = new Uint8Array(bufferSize * header.pointsStructSize);
124
155
 
125
- let {
126
- readOffset
127
- } = this;
128
- let start;
156
+ for (var i = 0; i < pointsToRead; i++) {
157
+ if (i % skip === 0) {
158
+ start = header.pointsOffset + readOffset * header.pointsStructSize;
159
+ var src = new Uint8Array(arraybuffer, start, header.pointsStructSize);
160
+ buf.set(src, pointsRead * header.pointsStructSize);
161
+ pointsRead++;
162
+ }
163
+
164
+ readOffset++;
165
+ }
129
166
 
130
- if (skip <= 1) {
131
- count = Math.min(count, header.pointsCount - readOffset);
132
- start = header.pointsOffset + readOffset * header.pointsStructSize;
133
- const end = start + count * header.pointsStructSize;
134
- readOffset += count;
135
167
  this.readOffset = readOffset;
136
168
  return {
137
- buffer: arraybuffer.slice(start, end),
138
- count,
169
+ buffer: buf.buffer,
170
+ count: pointsRead,
139
171
  hasMoreData: readOffset < header.pointsCount
140
172
  };
141
173
  }
142
-
143
- const pointsToRead = Math.min(count * skip, header.pointsCount - readOffset);
144
- const bufferSize = Math.ceil(pointsToRead / skip);
145
- let pointsRead = 0;
146
- const buf = new Uint8Array(bufferSize * header.pointsStructSize);
147
-
148
- for (let i = 0; i < pointsToRead; i++) {
149
- if (i % skip === 0) {
150
- start = header.pointsOffset + readOffset * header.pointsStructSize;
151
- const src = new Uint8Array(arraybuffer, start, header.pointsStructSize);
152
- buf.set(src, pointsRead * header.pointsStructSize);
153
- pointsRead++;
154
- }
155
-
156
- readOffset++;
174
+ }, {
175
+ key: "close",
176
+ value: function close() {
177
+ this.arraybuffer = null;
178
+ return true;
157
179
  }
180
+ }]);
181
+ return LASLoader;
182
+ }();
158
183
 
159
- this.readOffset = readOffset;
160
- return {
161
- buffer: buf.buffer,
162
- count: pointsRead,
163
- hasMoreData: readOffset < header.pointsCount
164
- };
165
- }
166
-
167
- close() {
168
- this.arraybuffer = null;
169
- return true;
170
- }
171
-
172
- }
173
-
174
- class LAZLoader {
175
- constructor(arraybuffer) {
184
+ var LAZLoader = function () {
185
+ function LAZLoader(arraybuffer) {
186
+ (0, _classCallCheck2.default)(this, LAZLoader);
176
187
  (0, _defineProperty2.default)(this, "arraybuffer", void 0);
177
188
  (0, _defineProperty2.default)(this, "instance", null);
178
189
  (0, _defineProperty2.default)(this, "header", null);
@@ -183,103 +194,106 @@ class LAZLoader {
183
194
  }
184
195
  }
185
196
 
186
- open() {
187
- try {
188
- const {
189
- arraybuffer
190
- } = this;
191
- this.instance = new Module.LASZip();
192
- const abInt = new Uint8Array(arraybuffer);
193
-
194
- const buf = Module._malloc(arraybuffer.byteLength);
195
-
196
- this.instance.arraybuffer = arraybuffer;
197
- this.instance.buf = buf;
198
- Module.HEAPU8.set(abInt, buf);
199
- this.instance.open(buf, arraybuffer.byteLength);
200
- this.instance.readOffset = 0;
201
- return true;
202
- } catch (error) {
203
- throw new Error("Failed to open file: ".concat(error.message));
204
- }
205
- }
206
-
207
- getHeader() {
208
- if (!this.instance) {
209
- throw new Error('You need to open the file before trying to read header');
197
+ (0, _createClass2.default)(LAZLoader, [{
198
+ key: "open",
199
+ value: function open() {
200
+ try {
201
+ var arraybuffer = this.arraybuffer;
202
+ this.instance = new Module.LASZip();
203
+ var abInt = new Uint8Array(arraybuffer);
204
+
205
+ var buf = Module._malloc(arraybuffer.byteLength);
206
+
207
+ this.instance.arraybuffer = arraybuffer;
208
+ this.instance.buf = buf;
209
+ Module.HEAPU8.set(abInt, buf);
210
+ this.instance.open(buf, arraybuffer.byteLength);
211
+ this.instance.readOffset = 0;
212
+ return true;
213
+ } catch (error) {
214
+ throw new Error("Failed to open file: ".concat(error.message));
215
+ }
210
216
  }
217
+ }, {
218
+ key: "getHeader",
219
+ value: function getHeader() {
220
+ if (!this.instance) {
221
+ throw new Error('You need to open the file before trying to read header');
222
+ }
211
223
 
212
- try {
213
- const header = parseLASHeader(this.instance.arraybuffer);
214
- header.pointsFormatId &= 0x3f;
215
- this.header = header;
216
- return header;
217
- } catch (error) {
218
- throw new Error("Failed to get header: ".concat(error.message));
224
+ try {
225
+ var header = parseLASHeader(this.instance.arraybuffer);
226
+ header.pointsFormatId &= 0x3f;
227
+ this.header = header;
228
+ return header;
229
+ } catch (error) {
230
+ throw new Error("Failed to get header: ".concat(error.message));
231
+ }
219
232
  }
220
- }
233
+ }, {
234
+ key: "readData",
235
+ value: function readData(count, offset, skip) {
236
+ if (!this.instance) {
237
+ throw new Error('You need to open the file before trying to read stuff');
238
+ }
221
239
 
222
- readData(count, offset, skip) {
223
- if (!this.instance) {
224
- throw new Error('You need to open the file before trying to read stuff');
225
- }
240
+ var header = this.header,
241
+ instance = this.instance;
226
242
 
227
- const {
228
- header,
229
- instance
230
- } = this;
243
+ if (!header) {
244
+ throw new Error('You need to query header before reading, I maintain state that way, sorry :(');
245
+ }
231
246
 
232
- if (!header) {
233
- throw new Error('You need to query header before reading, I maintain state that way, sorry :(');
234
- }
247
+ try {
248
+ var pointsToRead = Math.min(count * skip, header.pointsCount - instance.readOffset);
249
+ var bufferSize = Math.ceil(pointsToRead / skip);
250
+ var pointsRead = 0;
251
+ var thisBuf = new Uint8Array(bufferSize * header.pointsStructSize);
235
252
 
236
- try {
237
- const pointsToRead = Math.min(count * skip, header.pointsCount - instance.readOffset);
238
- const bufferSize = Math.ceil(pointsToRead / skip);
239
- let pointsRead = 0;
240
- const thisBuf = new Uint8Array(bufferSize * header.pointsStructSize);
253
+ var bufRead = Module._malloc(header.pointsStructSize);
241
254
 
242
- const bufRead = Module._malloc(header.pointsStructSize);
255
+ for (var i = 0; i < pointsToRead; i++) {
256
+ instance.getPoint(bufRead);
243
257
 
244
- for (let i = 0; i < pointsToRead; i++) {
245
- instance.getPoint(bufRead);
258
+ if (i % skip === 0) {
259
+ var a = new Uint8Array(Module.HEAPU8.buffer, bufRead, header.pointsStructSize);
260
+ thisBuf.set(a, pointsRead * header.pointsStructSize);
261
+ pointsRead++;
262
+ }
246
263
 
247
- if (i % skip === 0) {
248
- const a = new Uint8Array(Module.HEAPU8.buffer, bufRead, header.pointsStructSize);
249
- thisBuf.set(a, pointsRead * header.pointsStructSize);
250
- pointsRead++;
264
+ instance.readOffset++;
251
265
  }
252
266
 
253
- instance.readOffset++;
267
+ return {
268
+ buffer: thisBuf.buffer,
269
+ count: pointsRead,
270
+ hasMoreData: instance.readOffset < header.pointsCount
271
+ };
272
+ } catch (error) {
273
+ throw new Error("Failed to read data: ".concat(error.message));
254
274
  }
255
-
256
- return {
257
- buffer: thisBuf.buffer,
258
- count: pointsRead,
259
- hasMoreData: instance.readOffset < header.pointsCount
260
- };
261
- } catch (error) {
262
- throw new Error("Failed to read data: ".concat(error.message));
263
275
  }
264
- }
276
+ }, {
277
+ key: "close",
278
+ value: function close() {
279
+ try {
280
+ if (this.instance !== null) {
281
+ this.instance.delete();
282
+ this.instance = null;
283
+ }
265
284
 
266
- close() {
267
- try {
268
- if (this.instance !== null) {
269
- this.instance.delete();
270
- this.instance = null;
285
+ return true;
286
+ } catch (error) {
287
+ throw new Error("Failed to close file: ".concat(error.message));
271
288
  }
272
-
273
- return true;
274
- } catch (error) {
275
- throw new Error("Failed to close file: ".concat(error.message));
276
289
  }
277
- }
290
+ }]);
291
+ return LAZLoader;
292
+ }();
278
293
 
279
- }
280
-
281
- class LASDecoder {
282
- constructor(buffer, len, header) {
294
+ var LASDecoder = function () {
295
+ function LASDecoder(buffer, len, header) {
296
+ (0, _classCallCheck2.default)(this, LASDecoder);
283
297
  (0, _defineProperty2.default)(this, "arrayb", void 0);
284
298
  (0, _defineProperty2.default)(this, "decoder", void 0);
285
299
  (0, _defineProperty2.default)(this, "pointsCount", void 0);
@@ -298,19 +312,23 @@ class LASDecoder {
298
312
  this.maxs = header.maxs;
299
313
  }
300
314
 
301
- getPoint(index) {
302
- if (index < 0 || index >= this.pointsCount) {
303
- throw new Error('Point index out of range');
304
- }
305
-
306
- const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
307
- return this.decoder(dv);
308
- }
315
+ (0, _createClass2.default)(LASDecoder, [{
316
+ key: "getPoint",
317
+ value: function getPoint(index) {
318
+ if (index < 0 || index >= this.pointsCount) {
319
+ throw new Error('Point index out of range');
320
+ }
309
321
 
310
- }
322
+ var dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
323
+ return this.decoder(dv);
324
+ }
325
+ }]);
326
+ return LASDecoder;
327
+ }();
311
328
 
312
- class LASFile {
313
- constructor(arraybuffer) {
329
+ var LASFile = function () {
330
+ function LASFile(arraybuffer) {
331
+ (0, _classCallCheck2.default)(this, LASFile);
314
332
  (0, _defineProperty2.default)(this, "arraybuffer", void 0);
315
333
  (0, _defineProperty2.default)(this, "formatId", 0);
316
334
  (0, _defineProperty2.default)(this, "loader", void 0);
@@ -333,53 +351,62 @@ class LASFile {
333
351
  this.loader = this.isCompressed ? new LAZLoader(this.arraybuffer) : new LASLoader(this.arraybuffer);
334
352
  }
335
353
 
336
- determineFormat() {
337
- const formatId = readAs(this.arraybuffer, Uint8Array, 32 * 3 + 8);
338
- const bit7 = (formatId & 0x80) >> 7;
339
- const bit6 = (formatId & 0x40) >> 6;
354
+ (0, _createClass2.default)(LASFile, [{
355
+ key: "determineFormat",
356
+ value: function determineFormat() {
357
+ var formatId = readAs(this.arraybuffer, Uint8Array, 32 * 3 + 8);
358
+ var bit7 = (formatId & 0x80) >> 7;
359
+ var bit6 = (formatId & 0x40) >> 6;
340
360
 
341
- if (bit7 === 1 && bit6 === 1) {
342
- throw new Error('Old style compression not supported');
343
- }
344
-
345
- this.formatId = formatId & 0x3f;
346
- this.isCompressed = bit7 === 1 || bit6 === 1;
347
- }
348
-
349
- determineVersion() {
350
- const ver = new Int8Array(this.arraybuffer, 24, 2);
351
- this.version = ver[0] * 10 + ver[1];
352
- this.versionAsString = "".concat(ver[0], ".").concat(ver[1]);
353
- return this.version;
354
- }
361
+ if (bit7 === 1 && bit6 === 1) {
362
+ throw new Error('Old style compression not supported');
363
+ }
355
364
 
356
- open() {
357
- if (this.loader.open()) {
358
- this.isOpen = true;
365
+ this.formatId = formatId & 0x3f;
366
+ this.isCompressed = bit7 === 1 || bit6 === 1;
359
367
  }
360
- }
361
-
362
- getHeader() {
363
- return this.loader.getHeader();
364
- }
365
-
366
- readData(count, start, skip) {
367
- return this.loader.readData(count, start, skip);
368
- }
369
-
370
- close() {
371
- if (this.loader.close()) {
372
- this.isOpen = false;
368
+ }, {
369
+ key: "determineVersion",
370
+ value: function determineVersion() {
371
+ var ver = new Int8Array(this.arraybuffer, 24, 2);
372
+ this.version = ver[0] * 10 + ver[1];
373
+ this.versionAsString = "".concat(ver[0], ".").concat(ver[1]);
374
+ return this.version;
373
375
  }
374
- }
375
-
376
- getUnpacker() {
377
- return LASDecoder;
378
- }
379
-
380
- }
376
+ }, {
377
+ key: "open",
378
+ value: function open() {
379
+ if (this.loader.open()) {
380
+ this.isOpen = true;
381
+ }
382
+ }
383
+ }, {
384
+ key: "getHeader",
385
+ value: function getHeader() {
386
+ return this.loader.getHeader();
387
+ }
388
+ }, {
389
+ key: "readData",
390
+ value: function readData(count, start, skip) {
391
+ return this.loader.readData(count, start, skip);
392
+ }
393
+ }, {
394
+ key: "close",
395
+ value: function close() {
396
+ if (this.loader.close()) {
397
+ this.isOpen = false;
398
+ }
399
+ }
400
+ }, {
401
+ key: "getUnpacker",
402
+ value: function getUnpacker() {
403
+ return LASDecoder;
404
+ }
405
+ }]);
406
+ return LASFile;
407
+ }();
381
408
 
382
409
  exports.LASFile = LASFile;
383
- const LASModuleWasLoaded = false;
410
+ var LASModuleWasLoaded = false;
384
411
  exports.LASModuleWasLoaded = LASModuleWasLoaded;
385
412
  //# sourceMappingURL=laslaz-decoder.js.map