@loaders.gl/las 4.0.0-alpha.4 → 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.
Files changed (82) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +19087 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/index.js +44 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/las-loader.js +30 -0
  10. package/dist/es5/las-loader.js.map +1 -0
  11. package/dist/es5/lib/get-las-schema.js +38 -0
  12. package/dist/es5/lib/get-las-schema.js.map +1 -0
  13. package/dist/es5/lib/las-types.js +2 -0
  14. package/dist/es5/lib/las-types.js.map +1 -0
  15. package/dist/es5/lib/laslaz-decoder.js +364 -0
  16. package/dist/es5/lib/laslaz-decoder.js.map +1 -0
  17. package/dist/es5/lib/libs/laz-perf.js +2 -0
  18. package/dist/es5/lib/libs/laz-perf.js.map +1 -0
  19. package/dist/es5/lib/parse-las.js +187 -0
  20. package/dist/es5/lib/parse-las.js.map +1 -0
  21. package/dist/es5/workers/las-worker.js +6 -0
  22. package/dist/es5/workers/las-worker.js.map +1 -0
  23. package/dist/esm/bundle.js +4 -0
  24. package/dist/esm/bundle.js.map +1 -0
  25. package/dist/esm/index.js +9 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/las-loader.js +23 -0
  28. package/dist/esm/las-loader.js.map +1 -0
  29. package/dist/esm/lib/get-las-schema.js +31 -0
  30. package/dist/esm/lib/get-las-schema.js.map +1 -0
  31. package/dist/esm/lib/las-types.js +2 -0
  32. package/dist/esm/lib/las-types.js.map +1 -0
  33. package/dist/esm/lib/laslaz-decoder.js +317 -0
  34. package/dist/esm/lib/laslaz-decoder.js.map +1 -0
  35. package/dist/esm/lib/libs/laz-perf.js +2 -0
  36. package/dist/esm/lib/libs/laz-perf.js.map +1 -0
  37. package/dist/esm/lib/parse-las.js +174 -0
  38. package/dist/esm/lib/parse-las.js.map +1 -0
  39. package/dist/esm/workers/las-worker.js +4 -0
  40. package/dist/esm/workers/las-worker.js.map +1 -0
  41. package/dist/index.d.ts +11 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +13 -8
  44. package/dist/las-loader.d.ts +16 -0
  45. package/dist/las-loader.d.ts.map +1 -0
  46. package/dist/las-loader.js +27 -21
  47. package/dist/las-worker.js +18210 -33163
  48. package/dist/lib/get-las-schema.d.ts +16 -0
  49. package/dist/lib/get-las-schema.d.ts.map +1 -0
  50. package/dist/lib/get-las-schema.js +45 -35
  51. package/dist/lib/las-types.d.ts +28 -0
  52. package/dist/lib/las-types.d.ts.map +1 -0
  53. package/dist/lib/las-types.js +2 -2
  54. package/dist/lib/laslaz-decoder.d.ts +134 -0
  55. package/dist/lib/laslaz-decoder.d.ts.map +1 -0
  56. package/dist/lib/laslaz-decoder.js +366 -363
  57. package/dist/lib/libs/laz-perf.d.ts +2 -0
  58. package/dist/lib/libs/laz-perf.d.ts.map +1 -0
  59. package/dist/lib/libs/laz-perf.js +19006 -0
  60. package/dist/lib/parse-las.d.ts +18 -0
  61. package/dist/lib/parse-las.d.ts.map +1 -0
  62. package/dist/lib/parse-las.js +178 -178
  63. package/dist/workers/las-worker.d.ts +2 -0
  64. package/dist/workers/las-worker.d.ts.map +1 -0
  65. package/dist/workers/las-worker.js +5 -4
  66. package/package.json +10 -10
  67. package/src/index.ts +3 -4
  68. package/src/las-loader.ts +3 -3
  69. package/src/lib/get-las-schema.ts +16 -15
  70. package/src/lib/laslaz-decoder.ts +1 -1
  71. package/src/lib/libs/laz-perf.ts +20615 -0
  72. package/src/lib/parse-las.ts +8 -9
  73. package/dist/bundle.js.map +0 -1
  74. package/dist/index.js.map +0 -1
  75. package/dist/las-loader.js.map +0 -1
  76. package/dist/lib/get-las-schema.js.map +0 -1
  77. package/dist/lib/las-types.js.map +0 -1
  78. package/dist/lib/laslaz-decoder.js.map +0 -1
  79. package/dist/lib/parse-las.js.map +0 -1
  80. package/dist/libs/laz-perf.js +0 -19492
  81. package/src/libs/laz-perf.js +0 -19492
  82. /package/src/workers/{las-worker.js → las-worker.ts} +0 -0
@@ -1,392 +1,395 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import getModule from '../libs/laz-perf';
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"));
3
8
  let Module = null;
4
9
  const POINT_FORMAT_READERS = {
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
- }
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
+ }
35
40
  };
36
-
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
+ */
37
49
  function readAs(buf, Type = {}, offset, count) {
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;
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;
53
61
  }
54
-
62
+ /**
63
+ * Parsing of header's attributes
64
+ * @param arraybuffer
65
+ * @returns header as LASHeader
66
+ */
55
67
  function parseLASHeader(arraybuffer) {
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;
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;
72
84
  }
73
-
85
+ // LAS Loader
86
+ // Loads uncompressed files
87
+ //
74
88
  class LASLoader {
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');
115
- }
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
- };
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;
133
106
  }
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++;
107
+ /**
108
+ * @returns boolean
109
+ */
110
+ open() {
111
+ // Nothing needs to be done to open this
112
+ return true;
149
113
  }
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
-
164
- }
165
-
166
- class LAZLoader {
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();
114
+ /**
115
+ * Parsing of incoming binary
116
+ * @returns LASHeader
117
+ */
118
+ getHeader() {
119
+ this.header = parseLASHeader(this.arraybuffer);
120
+ return this.header;
178
121
  }
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));
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
+ };
199
166
  }
200
- }
201
-
202
- getHeader() {
203
- if (!this.instance) {
204
- throw new Error('You need to open the file before trying to read header');
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;
205
175
  }
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));
176
+ }
177
+ /**
178
+ * LAZ Loader
179
+ * Uses NaCL module to load LAZ files
180
+ */
181
+ 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
+ }
214
190
  }
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');
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
+ }
220
211
  }
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 :(');
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
+ }
229
225
  }
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++;
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}`);
246
263
  }
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));
258
264
  }
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));
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
+ }
271
280
  }
272
- }
273
-
274
281
  }
275
-
282
+ /**
283
+ * Helper class: Decodes LAS records into points
284
+ */
276
285
  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');
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;
295
+ }
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');
304
+ }
305
+ const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
306
+ return this.decoder(dv);
307
307
  }
308
-
309
- const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
310
- return this.decoder(dv);
311
- }
312
-
313
308
  }
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');
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);
335
330
  }
336
-
337
- this.determineFormat();
338
-
339
- if (POINT_FORMAT_READERS[this.formatId] === undefined) {
340
- throw new Error('The point format ID is not supported');
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;
341
343
  }
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');
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;
353
353
  }
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;
354
+ /**
355
+ * Reads if the file is open
356
+ * @returns boolean
357
+ */
358
+ open() {
359
+ if (this.loader.open()) {
360
+ this.isOpen = true;
361
+ }
362
+ }
363
+ /**
364
+ * Gets the header
365
+ * @returns Header
366
+ */
367
+ getHeader() {
368
+ return this.loader.getHeader();
369
+ }
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);
378
+ }
379
+ /**
380
+ * Closes the file
381
+ */
382
+ close() {
383
+ if (this.loader.close()) {
384
+ this.isOpen = false;
385
+ }
369
386
  }
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;
387
+ /**
388
+ */
389
+ getUnpacker() {
390
+ return LASDecoder;
383
391
  }
384
- }
385
-
386
- getUnpacker() {
387
- return LASDecoder;
388
- }
389
-
390
392
  }
391
- export const LASModuleWasLoaded = false;
392
- //# sourceMappingURL=laslaz-decoder.js.map
393
+ exports.LASFile = LASFile;
394
+ exports.LASModuleWasLoaded = false;
395
+ /* eslint no-use-before-define: 2 */