@margoengine/points 0.0.0-stage → 1.0.0
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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +876 -2
- package/dist/attributes-DNc-1pdr.js +256 -0
- package/dist/attributes.d.ts +48 -0
- package/dist/clip.d.ts +55 -0
- package/dist/clip.js +122 -0
- package/dist/cloud-B4O_G-Df.js +545 -0
- package/dist/cloud.d.ts +155 -0
- package/dist/color.d.ts +1 -0
- package/dist/copc-write.d.ts +95 -0
- package/dist/copc-write.js +318 -0
- package/dist/copc.d.ts +55 -0
- package/dist/copc.js +127 -0
- package/dist/depth-video.d.ts +98 -0
- package/dist/depth-video.js +164 -0
- package/dist/e57.d.ts +163 -0
- package/dist/e57.js +624 -0
- package/dist/frame.d.ts +14 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1246 -0
- package/dist/las.d.ts +213 -0
- package/dist/las.js +500 -0
- package/dist/laz-encode-CHXgHra_.js +446 -0
- package/dist/laz-encode.d.ts +14 -0
- package/dist/laz-model-DCphHLqH.js +385 -0
- package/dist/laz-model.d.ts +47 -0
- package/dist/laz-write.d.ts +46 -0
- package/dist/laz-write.js +75 -0
- package/dist/laz.d.ts +50 -0
- package/dist/laz.js +645 -0
- package/dist/material.d.ts +167 -0
- package/dist/math.d.ts +103 -0
- package/dist/octree.d.ts +182 -0
- package/dist/octree.js +360 -0
- package/dist/pick.d.ts +76 -0
- package/dist/pick.js +192 -0
- package/dist/plugin.d.ts +235 -0
- package/dist/potree-las-RC8sjbYU.js +1 -0
- package/dist/potree-las.d.ts +1 -0
- package/dist/potree.d.ts +70 -0
- package/dist/potree.js +451 -0
- package/dist/range-BQuJAjUM.js +23 -0
- package/dist/range.d.ts +4 -0
- package/dist/screen-door-CALlYs39.js +7 -0
- package/dist/shaders-DCnbvb0-.js +282 -0
- package/dist/shaders.d.ts +52 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/shared/selection-mask.d.ts +52 -0
- package/dist/shared/style-expression.d.ts +18 -0
- package/dist/sprites.d.ts +78 -0
- package/dist/storage-limit.d.ts +6 -0
- package/dist/style.d.ts +124 -0
- package/dist/style.js +709 -0
- package/dist/surfels.d.ts +95 -0
- package/dist/surfels.js +538 -0
- package/dist/survey-DToZwkJv.js +46 -0
- package/dist/survey.d.ts +10 -0
- package/dist/tier-BcFbLPVT.js +91 -0
- package/dist/tier.d.ts +6 -0
- package/package.json +102 -4
package/dist/laz.js
ADDED
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import { a as e, c as t, d as n, i as r, l as i, n as a, o, r as s, s as c, t as l, u } from "./laz-model-DCphHLqH.js";
|
|
2
|
+
import { MargoError as d } from "@margoengine/math/errors";
|
|
3
|
+
//#region src/laz.ts
|
|
4
|
+
var f = [
|
|
5
|
+
"BYTE",
|
|
6
|
+
"SHORT",
|
|
7
|
+
"INT",
|
|
8
|
+
"LONG",
|
|
9
|
+
"FLOAT",
|
|
10
|
+
"DOUBLE",
|
|
11
|
+
"POINT10",
|
|
12
|
+
"GPSTIME11",
|
|
13
|
+
"RGB12",
|
|
14
|
+
"WAVEPACKET13",
|
|
15
|
+
"POINT14",
|
|
16
|
+
"RGB14",
|
|
17
|
+
"RGBNIR14",
|
|
18
|
+
"WAVEPACKET14",
|
|
19
|
+
"BYTE14"
|
|
20
|
+
], p = 0, m = 6, h = 7, g = 8, _ = 9, v = 10, y = 11, b = 12, x = 13, S = 14, C = 4294967295;
|
|
21
|
+
function w(e) {
|
|
22
|
+
let t = e.find((e) => e.userId === "laszip encoded" && e.recordId === 22204);
|
|
23
|
+
if (!t) throw TypeError("LAZ file has no LASzip record (user id \"laszip encoded\", record 22204); the file is corrupt or not LAZ");
|
|
24
|
+
let n = t.data, r = new DataView(n.buffer, n.byteOffset, n.byteLength);
|
|
25
|
+
if (n.byteLength < 34) throw TypeError("LASzip record is shorter than 34 bytes; the file is corrupt");
|
|
26
|
+
let i = r.getUint16(32, !0);
|
|
27
|
+
if (n.byteLength < 34 + i * 6) throw TypeError(`LASzip record lists ${i} items but holds fewer; the file is corrupt`);
|
|
28
|
+
let a = [];
|
|
29
|
+
for (let e = 0; e < i; e++) {
|
|
30
|
+
let t = r.getUint16(34 + e * 6, !0);
|
|
31
|
+
a.push({
|
|
32
|
+
type: t,
|
|
33
|
+
name: f[t] ?? `item ${t}`,
|
|
34
|
+
size: r.getUint16(36 + e * 6, !0),
|
|
35
|
+
version: r.getUint16(38 + e * 6, !0)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
let o = r.getUint32(12, !0), s = r.getUint16(0, !0);
|
|
39
|
+
return {
|
|
40
|
+
compressor: s,
|
|
41
|
+
coder: r.getUint16(2, !0),
|
|
42
|
+
version: `${r.getUint8(4)}.${r.getUint8(5)}.${r.getUint16(6, !0)}`,
|
|
43
|
+
options: r.getUint32(8, !0),
|
|
44
|
+
chunkSize: o === C || o === 0 && s >= 2 ? "variable" : o,
|
|
45
|
+
items: a
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function T(e, t) {
|
|
49
|
+
return t ? [v, ...e === 7 ? [y] : e === 8 || e === 10 ? [b] : []].concat(e === 9 || e === 10 ? [x] : []) : [
|
|
50
|
+
m,
|
|
51
|
+
...[
|
|
52
|
+
1,
|
|
53
|
+
3,
|
|
54
|
+
4,
|
|
55
|
+
5
|
|
56
|
+
].includes(e) ? [h] : [],
|
|
57
|
+
...[
|
|
58
|
+
2,
|
|
59
|
+
3,
|
|
60
|
+
5
|
|
61
|
+
].includes(e) ? [g] : [],
|
|
62
|
+
...e === 4 || e === 5 ? [_] : []
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
var E = (e) => new d("unsupported", `LAZ ${e} is not supported by this decoder; decompress the file to LAS first (for example with laszip or PDAL)`);
|
|
66
|
+
function D(e, t) {
|
|
67
|
+
if (e.coder !== 0) throw E(`coder ${e.coder} (only arithmetic coding, 0, is defined)`);
|
|
68
|
+
if (e.compressor > 3) throw E(`compressor ${e.compressor}`);
|
|
69
|
+
if (e.compressor === 0) return;
|
|
70
|
+
let n = e.compressor === 3, r = t.pointFormat;
|
|
71
|
+
if (n !== r >= 6) throw E(`point format ${r} with compressor ${e.compressor} (formats 0 to 5 use 1 or 2, formats 6 to 10 use 3)`);
|
|
72
|
+
let i = T(r, n), a = e.items.map((e) => e.type), o = a.slice(i.length), s = e.items.reduce((e, t) => e + t.size, 0), c = n ? S : p;
|
|
73
|
+
if (i.some((e, t) => a[t] !== e) || o.some((e) => e !== c) || s !== t.pointRecordLength) throw TypeError(`LASzip items ${e.items.map((e) => `${e.name}(${e.size})`).join(" ")} do not match point format ${r} with ${t.pointRecordLength}-byte records; the file is corrupt`);
|
|
74
|
+
let l = {
|
|
75
|
+
[m]: 20,
|
|
76
|
+
[h]: 8,
|
|
77
|
+
[g]: 6,
|
|
78
|
+
[v]: 30,
|
|
79
|
+
[y]: 6,
|
|
80
|
+
[b]: 8,
|
|
81
|
+
[_]: 29,
|
|
82
|
+
[x]: 29
|
|
83
|
+
};
|
|
84
|
+
for (let t of e.items) {
|
|
85
|
+
if (l[t.type] !== void 0 && l[t.type] !== t.size) throw TypeError(`LASzip item ${t.name} has size ${t.size}, not ${l[t.type]}; the file is corrupt`);
|
|
86
|
+
let e = n ? 3 : t.type === _ ? 1 : 2;
|
|
87
|
+
if (t.version !== e) throw E(t.version === 1 && e === 2 ? `item ${t.name} version 1 (the coding of LASzip 1.0, which neither the LAZ specification 1.4 nor the LASzip paper describes, so a clean room decoder has nothing to follow)` : `item ${t.name} version ${t.version} (this decoder reads version ${e}, what LASzip 2 and 3 write)`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var ee = /* @__PURE__ */ new Uint8Array(), O = class {
|
|
91
|
+
constructor() {
|
|
92
|
+
this.bytes = ee, this.at = 0, this.end = 0, this.over = 0, this.value = 0, this.length = 0, this.label = "";
|
|
93
|
+
}
|
|
94
|
+
init(e, t, n, r) {
|
|
95
|
+
if (this.bytes = e, this.at = t, this.end = n, this.over = 0, this.label = r, this.length = 4294967295, this.value = this.byte() * 16777216 + this.byte() * 65536 + this.byte() * 256 + this.byte(), this.value === 4294967295) throw RangeError(`LAZ ${r} starts with an invalid code; the file is corrupt`);
|
|
96
|
+
}
|
|
97
|
+
byte() {
|
|
98
|
+
if (this.at < this.end) return this.bytes[this.at++];
|
|
99
|
+
if (++this.over > 4) throw RangeError(`LAZ ${this.label} reads past its end; the file is corrupt`);
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
renorm() {
|
|
103
|
+
do
|
|
104
|
+
this.value = this.value * 256 + this.byte(), this.length *= 256;
|
|
105
|
+
while (this.length < o);
|
|
106
|
+
}
|
|
107
|
+
decodeBit(e) {
|
|
108
|
+
let t = e.prob * (this.length >>> 13), n;
|
|
109
|
+
return this.value < t ? (n = 0, this.length = t, e.zeros++) : (n = 1, this.value -= t, this.length -= t), this.length < 16777216 && this.renorm(), --e.until === 0 && e.update(), n;
|
|
110
|
+
}
|
|
111
|
+
decodeSymbol(e) {
|
|
112
|
+
let t, n, r = this.length, i = this.length >>>= 15, a = e.dist;
|
|
113
|
+
if (e.table) {
|
|
114
|
+
let o = Math.floor(this.value / i), s = Math.min(o >>> e.tableShift, e.tableSize);
|
|
115
|
+
t = e.table[s];
|
|
116
|
+
let c = e.table[s + 1] + 1;
|
|
117
|
+
for (; c > t + 1;) {
|
|
118
|
+
let e = t + c >>> 1;
|
|
119
|
+
a[e] > o ? c = e : t = e;
|
|
120
|
+
}
|
|
121
|
+
n = a[t] * i, t !== e.last && (r = a[t + 1] * i);
|
|
122
|
+
} else {
|
|
123
|
+
n = t = 0;
|
|
124
|
+
let o = e.symbols, s = o >>> 1;
|
|
125
|
+
do {
|
|
126
|
+
let e = i * a[s];
|
|
127
|
+
e > this.value ? (o = s, r = e) : (t = s, n = e);
|
|
128
|
+
} while ((s = t + o >>> 1) !== t);
|
|
129
|
+
}
|
|
130
|
+
return this.value -= n, this.length = r - n, this.length < 16777216 && this.renorm(), e.counts[t]++, --e.until === 0 && e.update(), t;
|
|
131
|
+
}
|
|
132
|
+
readBits(e) {
|
|
133
|
+
if (e > 19) {
|
|
134
|
+
let t = this.readBits(16);
|
|
135
|
+
return this.readBits(e - 16) * 65536 + t;
|
|
136
|
+
}
|
|
137
|
+
let t = this.length >>>= e, n = Math.floor(this.value / t);
|
|
138
|
+
return this.value -= t * n, this.length < 16777216 && this.renorm(), n;
|
|
139
|
+
}
|
|
140
|
+
readInt() {
|
|
141
|
+
let e = this.readBits(16);
|
|
142
|
+
return this.readBits(16) * 65536 + e;
|
|
143
|
+
}
|
|
144
|
+
readInt64() {
|
|
145
|
+
let e = this.readInt();
|
|
146
|
+
return BigInt(this.readInt()) << 32n | BigInt(e);
|
|
147
|
+
}
|
|
148
|
+
}, k = class {
|
|
149
|
+
constructor(e, t = 16, n = 1, r = 8) {
|
|
150
|
+
this.dec = e, this.bitsHigh = r, this.k = 0, this.zero = new l(), this.corrector = [], t && t < 32 ? (this.corrBits = t, this.corrRange = 2 ** t, this.corrMin = -(this.corrRange / 2)) : (this.corrBits = 32, this.corrRange = 0, this.corrMin = -2147483648), this.kModels = Array.from({ length: n }, () => new c(this.corrBits + 1));
|
|
151
|
+
for (let e = 1; e <= this.corrBits; e++) this.corrector[e] = new c(1 << Math.min(e, r));
|
|
152
|
+
}
|
|
153
|
+
reset() {
|
|
154
|
+
for (let e of this.kModels) e.reset();
|
|
155
|
+
this.zero.reset();
|
|
156
|
+
for (let e = 1; e <= this.corrBits; e++) this.corrector[e].reset();
|
|
157
|
+
}
|
|
158
|
+
decompress(e, t = 0) {
|
|
159
|
+
let n = e + this.corrector_(this.kModels[t]);
|
|
160
|
+
return this.corrRange ? n < 0 ? n + this.corrRange : n >= this.corrRange ? n - this.corrRange : n : n | 0;
|
|
161
|
+
}
|
|
162
|
+
corrector_(e) {
|
|
163
|
+
let t = this.dec, n = this.k = t.decodeSymbol(e);
|
|
164
|
+
if (!n) return t.decodeBit(this.zero);
|
|
165
|
+
if (n >= 32) return this.corrMin;
|
|
166
|
+
let r;
|
|
167
|
+
if (n <= this.bitsHigh) r = t.decodeSymbol(this.corrector[n]);
|
|
168
|
+
else {
|
|
169
|
+
let e = n - this.bitsHigh;
|
|
170
|
+
r = t.decodeSymbol(this.corrector[n]) * 2 ** e + t.readBits(e);
|
|
171
|
+
}
|
|
172
|
+
return r >= 2 ** (n - 1) ? r + 1 : r - (2 ** n - 1);
|
|
173
|
+
}
|
|
174
|
+
}, te = class {
|
|
175
|
+
constructor(e) {
|
|
176
|
+
this.dec = e, this.size = 20, this.x = 0, this.y = 0, this.z = 0, this.intensity = 0, this.bits = 0, this.cls = 0, this.angle = 0, this.user = 0, this.psid = 0, this.lastIntensity = /* @__PURE__ */ new Uint16Array(16), this.lastHeight = /* @__PURE__ */ new Int32Array(8), this.medianX = u(16), this.medianY = u(16), this.changed = new c(64), this.angleModels = [new c(256), new c(256)], this.bitByte = [], this.classes = [], this.userData = [], this.icIntensity = new k(e, 16, 4), this.icPsid = new k(e, 16), this.icX = new k(e, 32, 2), this.icY = new k(e, 32, 22), this.icZ = new k(e, 32, 20);
|
|
177
|
+
}
|
|
178
|
+
init(e, t) {
|
|
179
|
+
for (let e of this.medianX) e.reset();
|
|
180
|
+
for (let e of this.medianY) e.reset();
|
|
181
|
+
this.lastIntensity.fill(0), this.lastHeight.fill(0), this.changed.reset();
|
|
182
|
+
for (let e of this.angleModels) e.reset();
|
|
183
|
+
n(this.bitByte), n(this.classes), n(this.userData);
|
|
184
|
+
for (let e of [
|
|
185
|
+
this.icIntensity,
|
|
186
|
+
this.icPsid,
|
|
187
|
+
this.icX,
|
|
188
|
+
this.icY,
|
|
189
|
+
this.icZ
|
|
190
|
+
]) e.reset();
|
|
191
|
+
this.x = e.getInt32(t, !0), this.y = e.getInt32(t + 4, !0), this.z = e.getInt32(t + 8, !0), this.intensity = 0, this.bits = e.getUint8(t + 14), this.cls = e.getUint8(t + 15), this.angle = e.getUint8(t + 16), this.user = e.getUint8(t + 17), this.psid = e.getUint16(t + 18, !0);
|
|
192
|
+
}
|
|
193
|
+
read(e, t) {
|
|
194
|
+
let n = this.dec, o = n.decodeSymbol(this.changed);
|
|
195
|
+
o & 32 && (this.bits = n.decodeSymbol(i(this.bitByte, this.bits, 256)));
|
|
196
|
+
let s = this.bits & 7, c = this.bits >> 3 & 7, l = r[c * 8 + s], u = a[c * 8 + s], d = +(c === 1);
|
|
197
|
+
o && (o & 16 ? (this.intensity = this.icIntensity.decompress(this.lastIntensity[l], l < 3 ? l : 3), this.lastIntensity[l] = this.intensity) : this.intensity = this.lastIntensity[l], o & 8 && (this.cls = n.decodeSymbol(i(this.classes, this.cls, 256))), o & 4 && (this.angle = n.decodeSymbol(this.angleModels[this.bits >> 6 & 1]) + this.angle & 255), o & 2 && (this.user = n.decodeSymbol(i(this.userData, this.user, 256))), o & 1 && (this.psid = this.icPsid.decompress(this.psid)));
|
|
198
|
+
let f = this.icX.decompress(this.medianX[l].get(), d);
|
|
199
|
+
this.x = this.x + f | 0, this.medianX[l].add(f);
|
|
200
|
+
let p = this.icX.k;
|
|
201
|
+
f = this.icY.decompress(this.medianY[l].get(), d + (p < 20 ? p & -2 : 20)), this.y = this.y + f | 0, this.medianY[l].add(f), p = this.icX.k + this.icY.k >>> 1, this.z = this.icZ.decompress(this.lastHeight[u], d + (p < 18 ? p & -2 : 18)), this.lastHeight[u] = this.z, e.setInt32(t, this.x, !0), e.setInt32(t + 4, this.y, !0), e.setInt32(t + 8, this.z, !0), e.setUint16(t + 12, this.intensity, !0), e.setUint8(t + 14, this.bits), e.setUint8(t + 15, this.cls), e.setUint8(t + 16, this.angle), e.setUint8(t + 17, this.user), e.setUint16(t + 18, this.psid, !0);
|
|
202
|
+
}
|
|
203
|
+
}, A = 500, j = -10, M = 511, N = class {
|
|
204
|
+
constructor(e, t) {
|
|
205
|
+
this.dec = e, this.layered = t, this.last = 0, this.next = 0, this.low = /* @__PURE__ */ new Uint32Array(4), this.high = /* @__PURE__ */ new Uint32Array(4), this.diff = /* @__PURE__ */ new Int32Array(4), this.extreme = /* @__PURE__ */ new Int32Array(4), this.fullCode = t ? M : 512, this.multi = new c(this.fullCode + 4), this.zero = new c(t ? 5 : 6), this.ic = new k(e, 32, 9);
|
|
206
|
+
}
|
|
207
|
+
reset(e, t) {
|
|
208
|
+
this.multi.reset(), this.zero.reset(), this.ic.reset(), this.last = this.next = 0, this.diff.fill(0), this.extreme.fill(0), this.low.fill(0), this.high.fill(0), this.low[0] = e, this.high[0] = t;
|
|
209
|
+
}
|
|
210
|
+
add(e, t) {
|
|
211
|
+
let n = this.low[e] + t;
|
|
212
|
+
this.low[e] = n, n >= 4294967296 ? this.high[e]++ : n < 0 && this.high[e]--;
|
|
213
|
+
}
|
|
214
|
+
full() {
|
|
215
|
+
let e = this.next = this.next + 1 & 3, t = this.ic.decompress(this.high[this.last] | 0, 8);
|
|
216
|
+
this.low[e] = this.dec.readInt(), this.high[e] = t, this.last = e, this.diff[e] = 0, this.extreme[e] = 0;
|
|
217
|
+
}
|
|
218
|
+
extremeDiff(e) {
|
|
219
|
+
++this.extreme[this.last] > 3 && (this.diff[this.last] = e, this.extreme[this.last] = 0);
|
|
220
|
+
}
|
|
221
|
+
read() {
|
|
222
|
+
let e = this.dec, t = this.ic;
|
|
223
|
+
for (let n = 0;; n++) {
|
|
224
|
+
if (n > 3) throw RangeError(`LAZ ${e.label} GPS time switches sequence repeatedly; the file is corrupt`);
|
|
225
|
+
let r = this.last;
|
|
226
|
+
if (this.diff[r] === 0) {
|
|
227
|
+
let n = e.decodeSymbol(this.zero), i = +!this.layered;
|
|
228
|
+
if (n === i) {
|
|
229
|
+
let e = t.decompress(0, 0);
|
|
230
|
+
this.diff[r] = e, this.add(r, e), this.extreme[r] = 0;
|
|
231
|
+
} else if (n === i + 1) this.full();
|
|
232
|
+
else if (n > i + 1) {
|
|
233
|
+
this.last = r + n - i - 1 & 3;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
let i = e.decodeSymbol(this.multi);
|
|
239
|
+
if (i === 1) {
|
|
240
|
+
let e = t.decompress(this.diff[r], 1);
|
|
241
|
+
this.add(r, e), this.extreme[r] = 0;
|
|
242
|
+
} else if (i < M) {
|
|
243
|
+
let e;
|
|
244
|
+
i === 0 ? (e = t.decompress(0, 7), this.extremeDiff(e)) : i < A ? e = t.decompress(Math.imul(i, this.diff[r]), i < 10 ? 2 : 3) : i === A ? (e = t.decompress(Math.imul(A, this.diff[r]), 4), this.extremeDiff(e)) : (i = A - i, i > j ? e = t.decompress(Math.imul(i, this.diff[r]), 5) : (e = t.decompress(Math.imul(j, this.diff[r]), 6), this.extremeDiff(e))), this.add(r, e);
|
|
245
|
+
} else if (i === this.fullCode) this.full();
|
|
246
|
+
else if (i > this.fullCode) {
|
|
247
|
+
this.last = r + i - this.fullCode & 3;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}, ne = class {
|
|
254
|
+
constructor(e) {
|
|
255
|
+
this.size = 8, this.gps = new N(e, !1);
|
|
256
|
+
}
|
|
257
|
+
init(e, t) {
|
|
258
|
+
this.gps.reset(e.getUint32(t, !0), e.getUint32(t + 4, !0));
|
|
259
|
+
}
|
|
260
|
+
read(e, t) {
|
|
261
|
+
let n = this.gps;
|
|
262
|
+
n.read(), e.setUint32(t, n.low[n.last], !0), e.setUint32(t + 4, n.high[n.last], !0);
|
|
263
|
+
}
|
|
264
|
+
}, P = class {
|
|
265
|
+
constructor() {
|
|
266
|
+
this.used = new c(128), this.diff = Array.from({ length: 6 }, () => new c(256));
|
|
267
|
+
}
|
|
268
|
+
reset() {
|
|
269
|
+
this.used.reset();
|
|
270
|
+
for (let e of this.diff) e.reset();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
function re(e, n, r) {
|
|
274
|
+
let i = e.decodeSymbol(n.used), a = r[0], o = r[1], s = r[2], c = i & 1 ? e.decodeSymbol(n.diff[0]) + (a & 255) & 255 : a & 255;
|
|
275
|
+
c |= i & 2 ? (e.decodeSymbol(n.diff[1]) + (a >> 8) & 255) << 8 : a & 65280;
|
|
276
|
+
let l = c, u = c;
|
|
277
|
+
if (i & 64) {
|
|
278
|
+
let r = (c & 255) - (a & 255);
|
|
279
|
+
l = i & 4 ? e.decodeSymbol(n.diff[2]) + t(r + (o & 255)) & 255 : o & 255, i & 16 ? (r = Math.trunc((r + (l & 255) - (o & 255)) / 2), u = e.decodeSymbol(n.diff[4]) + t(r + (s & 255)) & 255) : u = s & 255, r = (c >> 8) - (a >> 8), l |= i & 8 ? (e.decodeSymbol(n.diff[3]) + t(r + (o >> 8)) & 255) << 8 : o & 65280, i & 32 ? (r = Math.trunc((r + (l >> 8) - (o >> 8)) / 2), u |= (e.decodeSymbol(n.diff[5]) + t(r + (s >> 8)) & 255) << 8) : u |= s & 65280;
|
|
280
|
+
}
|
|
281
|
+
r[0] = c, r[1] = l, r[2] = u;
|
|
282
|
+
}
|
|
283
|
+
var ie = (e, t, n) => {
|
|
284
|
+
e.setUint16(t, n[0], !0), e.setUint16(t + 2, n[1], !0), e.setUint16(t + 4, n[2], !0);
|
|
285
|
+
}, ae = class {
|
|
286
|
+
constructor(e) {
|
|
287
|
+
this.dec = e, this.size = 6, this.last = /* @__PURE__ */ new Uint16Array(3), this.models = new P();
|
|
288
|
+
}
|
|
289
|
+
init(e, t) {
|
|
290
|
+
this.models.reset();
|
|
291
|
+
for (let n = 0; n < 3; n++) this.last[n] = e.getUint16(t + n * 2, !0);
|
|
292
|
+
}
|
|
293
|
+
read(e, t) {
|
|
294
|
+
re(this.dec, this.models, this.last), ie(e, t, this.last);
|
|
295
|
+
}
|
|
296
|
+
}, oe = class {
|
|
297
|
+
constructor(e, t) {
|
|
298
|
+
this.dec = e, this.size = t, this.last = new Uint8Array(t), this.models = Array.from({ length: t }, () => new c(256));
|
|
299
|
+
}
|
|
300
|
+
init(e, t) {
|
|
301
|
+
n(this.models);
|
|
302
|
+
for (let n = 0; n < this.size; n++) this.last[n] = e.getUint8(t + n);
|
|
303
|
+
}
|
|
304
|
+
read(e, t) {
|
|
305
|
+
for (let n = 0; n < this.size; n++) this.last[n] = this.last[n] + this.dec.decodeSymbol(this.models[n]) & 255, e.setUint8(t + n, this.last[n]);
|
|
306
|
+
}
|
|
307
|
+
}, F = class {
|
|
308
|
+
constructor() {
|
|
309
|
+
this.index = 0, this.offset = 0n, this.size = 0, this.location = 0, this.dx = 0, this.dy = 0, this.dz = 0;
|
|
310
|
+
}
|
|
311
|
+
readFrom(e, t) {
|
|
312
|
+
this.index = e.getUint8(t), this.offset = e.getBigUint64(t + 1, !0), this.size = e.getInt32(t + 9, !0), this.location = e.getInt32(t + 13, !0), this.dx = e.getInt32(t + 17, !0), this.dy = e.getInt32(t + 21, !0), this.dz = e.getInt32(t + 25, !0);
|
|
313
|
+
}
|
|
314
|
+
copy(e) {
|
|
315
|
+
this.index = e.index, this.offset = e.offset, this.size = e.size, this.location = e.location, this.dx = e.dx, this.dy = e.dy, this.dz = e.dz;
|
|
316
|
+
}
|
|
317
|
+
writeTo(e, t) {
|
|
318
|
+
e.setUint8(t, this.index), e.setBigUint64(t + 1, this.offset, !0), e.setInt32(t + 9, this.size, !0), e.setInt32(t + 13, this.location, !0), e.setInt32(t + 17, this.dx, !0), e.setInt32(t + 21, this.dy, !0), e.setInt32(t + 25, this.dz, !0);
|
|
319
|
+
}
|
|
320
|
+
}, I = class {
|
|
321
|
+
constructor(e) {
|
|
322
|
+
this.index = new c(256), this.offsetType = Array.from({ length: 4 }, () => new c(4)), this.lastType = 0, this.lastDiff = 0, this.offsetDiff = new k(e, 32), this.size = new k(e, 32), this.location = new k(e, 32), this.direction = new k(e, 32, 3);
|
|
323
|
+
}
|
|
324
|
+
reset() {
|
|
325
|
+
this.lastType = this.lastDiff = 0, this.index.reset(), n(this.offsetType), this.offsetDiff.reset(), this.size.reset(), this.location.reset(), this.direction.reset();
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
function L(e, t, n) {
|
|
329
|
+
n.index = e.decodeSymbol(t.index);
|
|
330
|
+
let r = t.lastType = e.decodeSymbol(t.offsetType[t.lastType]);
|
|
331
|
+
r === 1 ? n.offset = BigInt.asUintN(64, n.offset + BigInt(n.size >>> 0)) : r === 2 ? (t.lastDiff = t.offsetDiff.decompress(t.lastDiff), n.offset = BigInt.asUintN(64, n.offset + BigInt(t.lastDiff))) : r === 3 && (n.offset = e.readInt64()), n.size = t.size.decompress(n.size), n.location = t.location.decompress(n.location), n.dx = t.direction.decompress(n.dx, 0), n.dy = t.direction.decompress(n.dy, 1), n.dz = t.direction.decompress(n.dz, 2);
|
|
332
|
+
}
|
|
333
|
+
var se = class {
|
|
334
|
+
constructor(e) {
|
|
335
|
+
this.dec = e, this.size = 29, this.last = new F(), this.models = new I(e);
|
|
336
|
+
}
|
|
337
|
+
init(e, t) {
|
|
338
|
+
this.models.reset(), this.last.readFrom(e, t);
|
|
339
|
+
}
|
|
340
|
+
read(e, t) {
|
|
341
|
+
L(this.dec, this.models, this.last), this.last.writeTo(e, t);
|
|
342
|
+
}
|
|
343
|
+
}, R = class {
|
|
344
|
+
constructor() {
|
|
345
|
+
this.x = 0, this.y = 0, this.z = 0, this.intensity = 0, this.ret = 0, this.returns = 0, this.classFlags = 0, this.channel = 0, this.scanDirection = 0, this.edge = 0, this.cls = 0, this.user = 0, this.angle = 0, this.psid = 0, this.gpsLow = 0, this.gpsHigh = 0, this.gpsChange = !1;
|
|
346
|
+
}
|
|
347
|
+
copy(e) {
|
|
348
|
+
Object.assign(this, e);
|
|
349
|
+
}
|
|
350
|
+
readFrom(e, t) {
|
|
351
|
+
this.x = e.getInt32(t, !0), this.y = e.getInt32(t + 4, !0), this.z = e.getInt32(t + 8, !0), this.intensity = e.getUint16(t + 12, !0);
|
|
352
|
+
let n = e.getUint8(t + 14), r = e.getUint8(t + 15);
|
|
353
|
+
this.ret = n & 15, this.returns = n >> 4, this.classFlags = r & 15, this.channel = r >> 4 & 3, this.scanDirection = r >> 6 & 1, this.edge = r >> 7, this.cls = e.getUint8(t + 16), this.user = e.getUint8(t + 17), this.angle = e.getInt16(t + 18, !0), this.psid = e.getUint16(t + 20, !0), this.gpsLow = e.getUint32(t + 22, !0), this.gpsHigh = e.getUint32(t + 26, !0), this.gpsChange = !1;
|
|
354
|
+
}
|
|
355
|
+
writeTo(e, t) {
|
|
356
|
+
e.setInt32(t, this.x, !0), e.setInt32(t + 4, this.y, !0), e.setInt32(t + 8, this.z, !0), e.setUint16(t + 12, this.intensity, !0), e.setUint8(t + 14, this.ret | this.returns << 4), e.setUint8(t + 15, this.classFlags | this.channel << 4 | this.scanDirection << 6 | this.edge << 7), e.setUint8(t + 16, this.cls), e.setUint8(t + 17, this.user), e.setInt16(t + 18, this.angle, !0), e.setUint16(t + 20, this.psid, !0), e.setUint32(t + 22, this.gpsLow, !0), e.setUint32(t + 26, this.gpsHigh, !0);
|
|
357
|
+
}
|
|
358
|
+
}, z = 0, B = 1, V = 2, H = 3, U = 4, W = 5, G = 6, K = 7, q = 8, ce = class {
|
|
359
|
+
constructor(e) {
|
|
360
|
+
this.unused = !0, this.last = new R(), this.lastIntensity = /* @__PURE__ */ new Uint16Array(8), this.lastZ = /* @__PURE__ */ new Int32Array(8), this.medianX = u(12), this.medianY = u(12), this.changed = Array.from({ length: 8 }, () => new c(128)), this.channel = new c(3), this.returns = [], this.ret = [], this.retGpsSame = new c(13), this.classes = [], this.flags = [], this.userData = [], this.icX = new k(e[z], 32, 2), this.icY = new k(e[z], 32, 22), this.icZ = new k(e[B], 32, 20), this.icIntensity = new k(e[U], 16, 4), this.icAngle = new k(e[W], 16, 2), this.icPsid = new k(e[K], 16), this.gps = new N(e[q], !0);
|
|
361
|
+
}
|
|
362
|
+
reset(e) {
|
|
363
|
+
for (let e of this.changed) e.reset();
|
|
364
|
+
this.channel.reset(), this.retGpsSame.reset(), n(this.returns), n(this.ret), n(this.classes), n(this.flags), n(this.userData);
|
|
365
|
+
for (let e of [
|
|
366
|
+
this.icX,
|
|
367
|
+
this.icY,
|
|
368
|
+
this.icZ,
|
|
369
|
+
this.icIntensity,
|
|
370
|
+
this.icAngle,
|
|
371
|
+
this.icPsid
|
|
372
|
+
]) e.reset();
|
|
373
|
+
for (let e of this.medianX) e.reset();
|
|
374
|
+
for (let e of this.medianY) e.reset();
|
|
375
|
+
this.lastZ.fill(e.z), this.lastIntensity.fill(e.intensity), this.gps.reset(e.gpsLow, e.gpsHigh), this.last.copy(e), this.last.gpsChange = !1, this.unused = !1;
|
|
376
|
+
}
|
|
377
|
+
}, le = class {
|
|
378
|
+
constructor(e) {
|
|
379
|
+
this.channel = e, this.size = 30, this.layers = 9, this.dec = Array.from({ length: 9 }, () => new O()), this.has = Array(9).fill(!1), this.contexts = [], this.first = new R();
|
|
380
|
+
}
|
|
381
|
+
layer(e, t, n, r, i) {
|
|
382
|
+
this.has[e] = e === z || r > n, this.has[e] && this.dec[e].init(t, n, r, i);
|
|
383
|
+
}
|
|
384
|
+
context(e, t) {
|
|
385
|
+
let n = this.contexts[e] ??= new ce(this.dec);
|
|
386
|
+
return n.reset(t), n;
|
|
387
|
+
}
|
|
388
|
+
init(e, t) {
|
|
389
|
+
this.first.readFrom(e, t);
|
|
390
|
+
for (let e of this.contexts) e && (e.unused = !0);
|
|
391
|
+
this.channel.current = this.channel.item = this.first.channel, this.context(this.first.channel, this.first);
|
|
392
|
+
}
|
|
393
|
+
read(t, n) {
|
|
394
|
+
let r = this.dec, a = this.has, o = this.contexts[this.channel.current], c = o.last, l = +(c.ret === 1) + (c.ret >= c.returns ? 2 : 0) + (c.gpsChange ? 4 : 0), u = r[z].decodeSymbol(o.changed[l]);
|
|
395
|
+
if (this.channel.item = 0, u & 64) {
|
|
396
|
+
let e = this.channel.current + r[z].decodeSymbol(o.channel) + 1 & 3, t = this.contexts[e];
|
|
397
|
+
o = t && !t.unused ? t : this.context(e, c), this.channel.current = this.channel.item = e, c = o.last, c.channel = e;
|
|
398
|
+
}
|
|
399
|
+
let d = !!(u & 32), f = !!(u & 16), p = !!(u & 8), m = +!!f, h = c.returns, g = c.ret;
|
|
400
|
+
u & 4 && (c.returns = r[z].decodeSymbol(i(o.returns, h, 16)));
|
|
401
|
+
let _ = u & 3;
|
|
402
|
+
_ === 1 ? c.ret = g + 1 & 15 : _ === 2 ? c.ret = g + 15 & 15 : _ === 3 && (c.ret = f ? r[z].decodeSymbol(i(o.ret, g, 16)) : g + r[z].decodeSymbol(o.retGpsSame) + 2 & 15);
|
|
403
|
+
let v = c.returns, y = c.ret, b = e[v * 16 + y], x = s[v * 16 + y], S = +(v === 1), C = (y === 1 ? 2 : 0) + +(y >= v), w = o.medianX[b << 1 | m], T = o.medianY[b << 1 | m], E = o.icX.decompress(w.get(), S);
|
|
404
|
+
c.x = c.x + E | 0, w.add(E);
|
|
405
|
+
let D = o.icX.k;
|
|
406
|
+
if (E = o.icY.decompress(T.get(), S + (D < 20 ? D & -2 : 20)), c.y = c.y + E | 0, T.add(E), a[B] && (D = o.icX.k + o.icY.k >>> 1, c.z = o.icZ.decompress(o.lastZ[x], S + (D < 18 ? D & -2 : 18)), o.lastZ[x] = c.z), a[V]) {
|
|
407
|
+
let e = ((c.cls & 31) << 1) + +(C === 3);
|
|
408
|
+
c.cls = r[V].decodeSymbol(i(o.classes, e, 256));
|
|
409
|
+
}
|
|
410
|
+
if (a[H]) {
|
|
411
|
+
let e = c.edge << 5 | c.scanDirection << 4 | c.classFlags, t = r[H].decodeSymbol(i(o.flags, e, 64));
|
|
412
|
+
c.edge = t >> 5 & 1, c.scanDirection = t >> 4 & 1, c.classFlags = t & 15;
|
|
413
|
+
}
|
|
414
|
+
if (a[U]) {
|
|
415
|
+
let e = C << 1 | m;
|
|
416
|
+
c.intensity = o.icIntensity.decompress(o.lastIntensity[e], C), o.lastIntensity[e] = c.intensity;
|
|
417
|
+
}
|
|
418
|
+
a[W] && p && (c.angle = o.icAngle.decompress(c.angle, m) << 16 >> 16), a[G] && (c.user = r[G].decodeSymbol(i(o.userData, c.user >> 2, 256))), a[K] && d && (c.psid = o.icPsid.decompress(c.psid)), a[q] && f && (o.gps.read(), c.gpsLow = o.gps.low[o.gps.last], c.gpsHigh = o.gps.high[o.gps.last]), c.writeTo(t, n), c.gpsChange = f;
|
|
419
|
+
}
|
|
420
|
+
}, J = class {
|
|
421
|
+
constructor(e) {
|
|
422
|
+
this.channel = e, this.dec = [], this.has = [], this.contexts = [], this.current = 0;
|
|
423
|
+
}
|
|
424
|
+
layer(e, t, n, r, i) {
|
|
425
|
+
this.dec[e] ??= new O(), this.has[e] = r > n, this.has[e] && this.dec[e].init(t, n, r, i);
|
|
426
|
+
}
|
|
427
|
+
context(e, t, n) {
|
|
428
|
+
let r = this.contexts[e] ??= this.create();
|
|
429
|
+
return this.start(r, t, n), r.unused = !1, r;
|
|
430
|
+
}
|
|
431
|
+
init(e, t) {
|
|
432
|
+
for (let e of this.contexts) e && (e.unused = !0);
|
|
433
|
+
this.current = this.channel.current, this.context(this.current, e, t);
|
|
434
|
+
}
|
|
435
|
+
read(e, t) {
|
|
436
|
+
let n = this.channel.item, r = this.contexts[this.current];
|
|
437
|
+
if (this.current !== n) {
|
|
438
|
+
this.current = n;
|
|
439
|
+
let e = this.contexts[n];
|
|
440
|
+
(!e || e.unused) && (r = this.context(n, r, 0));
|
|
441
|
+
}
|
|
442
|
+
this.decode(this.contexts[n], r, e, t);
|
|
443
|
+
}
|
|
444
|
+
}, ue = class {
|
|
445
|
+
constructor() {
|
|
446
|
+
this.unused = !0, this.last = /* @__PURE__ */ new Uint16Array(4), this.rgb = new P(), this.nirUsed = new c(4), this.nir = [new c(256), new c(256)];
|
|
447
|
+
}
|
|
448
|
+
}, de = class extends J {
|
|
449
|
+
constructor(e, t) {
|
|
450
|
+
super(e), this.size = t, this.layers = t === 8 ? 2 : 1;
|
|
451
|
+
}
|
|
452
|
+
create() {
|
|
453
|
+
return new ue();
|
|
454
|
+
}
|
|
455
|
+
start(e, t, n) {
|
|
456
|
+
e.rgb.reset(), e.nirUsed.reset();
|
|
457
|
+
for (let t of e.nir) t.reset();
|
|
458
|
+
if (!(t instanceof DataView)) e.last.set(t.last);
|
|
459
|
+
else for (let r = 0; r < this.size / 2; r++) e.last[r] = t.getUint16(n + r * 2, !0);
|
|
460
|
+
}
|
|
461
|
+
decode(e, t, n, r) {
|
|
462
|
+
let i = t.last;
|
|
463
|
+
if (this.has[0] && re(this.dec[0], e.rgb, i), ie(n, r, i), this.layers === 2) {
|
|
464
|
+
if (this.has[1]) {
|
|
465
|
+
let t = this.dec[1], n = t.decodeSymbol(e.nirUsed), r = i[3], a = n & 1 ? t.decodeSymbol(e.nir[0]) + (r & 255) & 255 : r & 255;
|
|
466
|
+
a |= n & 2 ? (t.decodeSymbol(e.nir[1]) + (r >> 8) & 255) << 8 : r & 65280, i[3] = a;
|
|
467
|
+
}
|
|
468
|
+
n.setUint16(r + 6, i[3], !0);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}, fe = class {
|
|
472
|
+
constructor(e) {
|
|
473
|
+
this.unused = !0, this.last = new Uint8Array(e), this.models = Array.from({ length: e }, () => new c(256));
|
|
474
|
+
}
|
|
475
|
+
}, pe = class extends J {
|
|
476
|
+
constructor(e, t) {
|
|
477
|
+
super(e), this.size = t, this.layers = t;
|
|
478
|
+
}
|
|
479
|
+
create() {
|
|
480
|
+
return new fe(this.size);
|
|
481
|
+
}
|
|
482
|
+
start(e, t, r) {
|
|
483
|
+
if (n(e.models), t instanceof DataView) for (let n = 0; n < this.size; n++) e.last[n] = t.getUint8(r + n);
|
|
484
|
+
else e.last.set(t.last);
|
|
485
|
+
}
|
|
486
|
+
decode(e, t, n, r) {
|
|
487
|
+
let i = t.last;
|
|
488
|
+
for (let t = 0; t < this.size; t++) this.has[t] && (i[t] = i[t] + this.dec[t].decodeSymbol(e.models[t]) & 255), n.setUint8(r + t, i[t]);
|
|
489
|
+
}
|
|
490
|
+
}, me = class {
|
|
491
|
+
constructor(e) {
|
|
492
|
+
this.unused = !0, this.last = new F(), this.models = new I(e);
|
|
493
|
+
}
|
|
494
|
+
}, he = class extends J {
|
|
495
|
+
constructor(...e) {
|
|
496
|
+
super(...e), this.size = 29, this.layers = 1;
|
|
497
|
+
}
|
|
498
|
+
create() {
|
|
499
|
+
return new me(this.dec[0]);
|
|
500
|
+
}
|
|
501
|
+
start(e, t, n) {
|
|
502
|
+
e.models.reset(), t instanceof DataView ? e.last.readFrom(t, n) : e.last.copy(t.last);
|
|
503
|
+
}
|
|
504
|
+
decode(e, t, n, r) {
|
|
505
|
+
this.has[0] && L(this.dec[0], e.models, t.last), t.last.writeTo(n, r);
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
function ge(e, t, n) {
|
|
509
|
+
let r = new DataView(e.buffer, e.byteOffset, e.byteLength), i = t.pointDataOffset + 8;
|
|
510
|
+
if (i > e.byteLength) throw RangeError("LAZ point data is shorter than its 8-byte chunk table offset; the file is truncated");
|
|
511
|
+
let a = Number(r.getBigInt64(t.pointDataOffset, !0));
|
|
512
|
+
if (a === -1 && e.byteLength >= i + 8 && (a = Number(r.getBigInt64(e.byteLength - 8, !0))), !(a >= i && a + 8 <= e.byteLength)) throw RangeError(`LAZ chunk table offset ${a} lies outside the file; the file is truncated or corrupt (LAZ is read through its chunk table)`);
|
|
513
|
+
let o = r.getUint32(a, !0), s = r.getUint32(a + 4, !0), c = n.chunkSize === "variable";
|
|
514
|
+
if (o !== 0) throw E(`chunk table version ${o}`);
|
|
515
|
+
let l = c ? void 0 : Math.ceil(t.pointCount / n.chunkSize);
|
|
516
|
+
if (l === void 0 ? s > t.pointCount : s !== l) throw RangeError(`LAZ chunk table lists ${s} chunks for ${t.pointCount} points${l === void 0 ? "" : ` (expected ${l})`}; the file is corrupt`);
|
|
517
|
+
let u = [];
|
|
518
|
+
if (!s) return u;
|
|
519
|
+
let d = new O(), f = new k(d, 32, 2);
|
|
520
|
+
d.init(e, a + 8, e.byteLength, "chunk table");
|
|
521
|
+
let p = 0, m = 0, h = i, g = 0;
|
|
522
|
+
for (let e = 0; e < s; e++) {
|
|
523
|
+
if (p = c ? f.decompress(p, 0) : Math.min(n.chunkSize, t.pointCount - g), m = f.decompress(m, 1), p < 0 || m < 0 || h + m > a || g + p > t.pointCount) throw RangeError(`LAZ chunk ${e} (${p} points, ${m} bytes at ${h}) does not fit the point data; the file is corrupt`);
|
|
524
|
+
u.push({
|
|
525
|
+
start: h,
|
|
526
|
+
end: h + m,
|
|
527
|
+
count: p
|
|
528
|
+
}), h += m, g += p;
|
|
529
|
+
}
|
|
530
|
+
if (g !== t.pointCount) throw RangeError(`LAZ chunks hold ${g} points but the header says ${t.pointCount}; the file is corrupt`);
|
|
531
|
+
return u;
|
|
532
|
+
}
|
|
533
|
+
function Y(e) {
|
|
534
|
+
let t = new O(), n = e.compressor === 3, r = {
|
|
535
|
+
current: 0,
|
|
536
|
+
item: 0
|
|
537
|
+
};
|
|
538
|
+
return {
|
|
539
|
+
readers: e.items.map((e) => {
|
|
540
|
+
switch (e.type) {
|
|
541
|
+
case m: return new te(t);
|
|
542
|
+
case h: return new ne(t);
|
|
543
|
+
case g: return new ae(t);
|
|
544
|
+
case _: return new se(t);
|
|
545
|
+
case p: return new oe(t, e.size);
|
|
546
|
+
case v: return new le(r);
|
|
547
|
+
case y:
|
|
548
|
+
case b: return new de(r, e.size);
|
|
549
|
+
case x: return new he(r);
|
|
550
|
+
default: return new pe(r, e.size);
|
|
551
|
+
}
|
|
552
|
+
}),
|
|
553
|
+
dec: t,
|
|
554
|
+
layered: n
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
function X(e, t, n, r, i, a) {
|
|
558
|
+
let { readers: o, dec: s, layered: c } = i, l = `chunk ${n}`, u = new DataView(a.buffer, a.byteOffset, a.byteLength);
|
|
559
|
+
if (!t.count) return;
|
|
560
|
+
let d = t.start + r;
|
|
561
|
+
if (d > t.end) throw RangeError(`LAZ ${l} is shorter than its first point; the file is corrupt`);
|
|
562
|
+
if (a.set(e.subarray(t.start, d)), c) {
|
|
563
|
+
let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = o, i = r.reduce((e, t) => e + t.layers, 0);
|
|
564
|
+
if (d + 4 + i * 4 > t.end) throw RangeError(`LAZ ${l} is shorter than its layer table; the file is corrupt`);
|
|
565
|
+
let a = n.getUint32(d, !0);
|
|
566
|
+
if (a !== t.count) throw RangeError(`LAZ ${l} holds ${a} points but its table says ${t.count}; the file is corrupt`);
|
|
567
|
+
let s = d + 4, c = s + i * 4, u = 0;
|
|
568
|
+
for (let i of r) for (let r = 0; r < i.layers; r++, s += 4, u++) {
|
|
569
|
+
let a = n.getUint32(s, !0);
|
|
570
|
+
if (c + a > t.end) throw RangeError(`LAZ ${l} layer sizes run past the chunk; the file is corrupt`);
|
|
571
|
+
i.layer(r, e, c, c + a, `${l} layer ${u}`), c += a;
|
|
572
|
+
}
|
|
573
|
+
} else s.init(e, d, t.end, l);
|
|
574
|
+
d = 0;
|
|
575
|
+
for (let e of o) e.init(u, d), d += e.size;
|
|
576
|
+
Z(o, u, 1, t.count, r);
|
|
577
|
+
}
|
|
578
|
+
function Z(e, t, n, r, i) {
|
|
579
|
+
for (let a = n; a < r; a++) {
|
|
580
|
+
let n = a * i;
|
|
581
|
+
for (let r of e) r.read(t, n), n += r.size;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
var Q = 5e4;
|
|
585
|
+
function* _e(e, t, n) {
|
|
586
|
+
let r = t.pointRecordLength, i = t.pointCount;
|
|
587
|
+
if (!i) return;
|
|
588
|
+
let a = Math.min(Q, i), o = new Uint8Array(a * r);
|
|
589
|
+
if (t.pointDataOffset + r > e.byteLength) throw RangeError("LAZ point data is shorter than its first point; the file is truncated");
|
|
590
|
+
X(e, {
|
|
591
|
+
start: t.pointDataOffset,
|
|
592
|
+
end: e.byteLength,
|
|
593
|
+
count: a
|
|
594
|
+
}, 0, r, n, o), yield o;
|
|
595
|
+
for (let e = a; e < i;) {
|
|
596
|
+
let t = Math.min(Q, i - e), a = new Uint8Array(t * r);
|
|
597
|
+
Z(n.readers, new DataView(a.buffer), 0, t, r), e += t, yield a;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
var $ = () => globalThis.performance?.now() ?? Date.now();
|
|
601
|
+
async function* ve(e, t, n, r = {}) {
|
|
602
|
+
let i = r.signal;
|
|
603
|
+
if (i?.throwIfAborted(), !t.compressed) throw TypeError("LAS file is not compressed (no LAZ bit in the point format); use parseLAS");
|
|
604
|
+
let a = w(n);
|
|
605
|
+
D(a, t);
|
|
606
|
+
let o = t.pointRecordLength;
|
|
607
|
+
if (a.compressor === 0) {
|
|
608
|
+
yield e.subarray(t.pointDataOffset, t.pointDataOffset + t.pointCount * o);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
let s = Y(a), c = $(), l = async () => {
|
|
612
|
+
i?.throwIfAborted(), $() - c > 30 && (await new Promise((e) => setTimeout(e, 0)), i?.throwIfAborted(), c = $());
|
|
613
|
+
};
|
|
614
|
+
if (a.compressor === 1) {
|
|
615
|
+
for (let n of _e(e, t, s)) yield n, await l();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
let u = ge(e, t, a);
|
|
619
|
+
for (let t = 0; t < u.length; t++) {
|
|
620
|
+
await l();
|
|
621
|
+
let n = new Uint8Array(u[t].count * o);
|
|
622
|
+
X(e, u[t], t, o, s, n), yield n;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function ye(e, t, n, r) {
|
|
626
|
+
let i = w(r);
|
|
627
|
+
D(i, n);
|
|
628
|
+
let a = n.pointRecordLength;
|
|
629
|
+
if (!Number.isSafeInteger(t) || t < 0) throw RangeError(`LAZ chunk point count ${t} is not a whole number of 0 or more; pass the count its index gives`);
|
|
630
|
+
if (t && i.compressor === 3 && e.byteLength >= a + 4) {
|
|
631
|
+
let n = new DataView(e.buffer, e.byteOffset, e.byteLength).getUint32(a, !0);
|
|
632
|
+
if (n !== t) throw RangeError(`LAZ chunk 0 holds ${n} points but its table says ${t}; the file is corrupt`);
|
|
633
|
+
}
|
|
634
|
+
let o = new Uint8Array(t * a);
|
|
635
|
+
return X(e, {
|
|
636
|
+
start: 0,
|
|
637
|
+
end: e.byteLength,
|
|
638
|
+
count: t
|
|
639
|
+
}, 0, a, Y(i), o), o;
|
|
640
|
+
}
|
|
641
|
+
function be() {
|
|
642
|
+
return (e, t, n, r) => ve(e, t, n, { signal: r });
|
|
643
|
+
}
|
|
644
|
+
//#endregion
|
|
645
|
+
export { be as createLazDecoder, ye as decodeLazChunk, ve as lazChunks, w as lazInfo };
|