@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/copc.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { decodePoints as e, readLASHeader as t } from "./las.js";
|
|
2
|
+
import { t as n } from "./range-BQuJAjUM.js";
|
|
3
|
+
//#region src/copc.ts
|
|
4
|
+
var r = 32, i = 375;
|
|
5
|
+
function a(e) {
|
|
6
|
+
let t = e.find((e) => e.userId === "copc" && e.recordId === 1);
|
|
7
|
+
if (!t || t.data.byteLength < 160) throw TypeError("Not a COPC file (no copc info record); pass a .copc.laz, or load a plain LAS with loadLAS");
|
|
8
|
+
let n = new DataView(t.data.buffer, t.data.byteOffset, t.data.byteLength), r = (e) => n.getFloat64(e, !0), i = (e) => Number(n.getBigUint64(e, !0));
|
|
9
|
+
return {
|
|
10
|
+
center: [
|
|
11
|
+
r(0),
|
|
12
|
+
r(8),
|
|
13
|
+
r(16)
|
|
14
|
+
],
|
|
15
|
+
halfSize: r(24),
|
|
16
|
+
spacing: r(32),
|
|
17
|
+
rootHierarchyOffset: i(40),
|
|
18
|
+
rootHierarchySize: i(48),
|
|
19
|
+
gpsTime: [r(56), r(64)]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
var o = class o {
|
|
23
|
+
constructor(e, t, n, r, i, a) {
|
|
24
|
+
this.url = e, this.fetcher = t, this.header = n, this.records = r, this.info = i, this.root = a, this.origin = i.center;
|
|
25
|
+
}
|
|
26
|
+
static async open(e, c = {}) {
|
|
27
|
+
let l = c.fetch ?? globalThis.fetch, u = c.signal, d = (t, r) => n(l, e, t, r, u), f = s(await d(0, i)), { header: p, records: m } = t(await d(0, f)), h = a(m), g = h.halfSize * 2;
|
|
28
|
+
if (!(g > 0)) throw RangeError("COPC info holds a cube of no size; the file is corrupt");
|
|
29
|
+
let _ = /* @__PURE__ */ new Map(), v = (e, t, n, r, i, a, o) => {
|
|
30
|
+
let s = g / 2 ** e, c = /* @__PURE__ */ new Float64Array(6), l = [
|
|
31
|
+
t,
|
|
32
|
+
n,
|
|
33
|
+
r
|
|
34
|
+
];
|
|
35
|
+
for (let e = 0; e < 3; e++) c[e] = l[e] * s - h.halfSize, c[e + 3] = c[e] + s;
|
|
36
|
+
let u = {
|
|
37
|
+
id: "",
|
|
38
|
+
level: e,
|
|
39
|
+
bounds: c,
|
|
40
|
+
spacing: h.spacing / 2 ** e,
|
|
41
|
+
count: i,
|
|
42
|
+
parent: null,
|
|
43
|
+
children: Array(8).fill(null),
|
|
44
|
+
offset: a,
|
|
45
|
+
bytes: o
|
|
46
|
+
};
|
|
47
|
+
_.set(`${e}-${t}-${n}-${r}`, u);
|
|
48
|
+
}, y = [[h.rootHierarchyOffset, h.rootHierarchySize]], b = /* @__PURE__ */ new Set([h.rootHierarchyOffset]);
|
|
49
|
+
for (; y.length;) {
|
|
50
|
+
let e = y.splice(0), t = await Promise.all(e.map(([e, t]) => d(e, t)));
|
|
51
|
+
for (let e of t) {
|
|
52
|
+
if (e.byteLength % r) throw RangeError("COPC hierarchy page is not whole entries; the file is corrupt");
|
|
53
|
+
let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
54
|
+
for (let n = 0; n < e.byteLength; n += r) {
|
|
55
|
+
let e = t.getInt32(n, !0), r = t.getInt32(n + 4, !0), i = t.getInt32(n + 8, !0), a = t.getInt32(n + 12, !0), o = Number(t.getBigUint64(n + 16, !0)), s = t.getInt32(n + 24, !0), c = t.getInt32(n + 28, !0), l = 2 ** e;
|
|
56
|
+
if (!(e >= 0 && e < 32) || !(r >= 0 && r < l && i >= 0 && i < l && a >= 0 && a < l)) throw RangeError(`COPC hierarchy voxel ${e}-${r}-${i}-${a} lies outside the cube; the file is corrupt`);
|
|
57
|
+
if (c === -1) {
|
|
58
|
+
if (b.has(o)) throw RangeError(`COPC hierarchy page at ${o} is listed twice; the file is corrupt`);
|
|
59
|
+
b.add(o), y.push([o, s]);
|
|
60
|
+
} else if (c < 0) throw RangeError("COPC hierarchy holds a negative point count; the file is corrupt");
|
|
61
|
+
else v(e, r, i, a, c, o, s);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let x = _.get("0-0-0-0");
|
|
66
|
+
if (!x) throw RangeError("COPC hierarchy has no root voxel; the file is corrupt");
|
|
67
|
+
x.id = "r";
|
|
68
|
+
let S = [..._].sort((e, t) => e[1].level - t[1].level);
|
|
69
|
+
for (let [e, t] of S) {
|
|
70
|
+
if (t === x) continue;
|
|
71
|
+
let [n, r, i, a] = e.split("-").map(Number), o = _.get(`${n - 1}-${r >> 1}-${i >> 1}-${a >> 1}`);
|
|
72
|
+
if (!o) throw RangeError(`COPC voxel ${e} has no parent voxel; the file is corrupt`);
|
|
73
|
+
let s = r & 1 | (i & 1) << 1 | (a & 1) << 2;
|
|
74
|
+
t.parent = o, t.id = o.id + s, o.children[s] = t;
|
|
75
|
+
}
|
|
76
|
+
for (let e = S.length - 1; e >= 0; e--) {
|
|
77
|
+
let t = S[e][1], n = t.parent;
|
|
78
|
+
n && !t.count && !t.children.some(Boolean) && (n.children[n.children.indexOf(t)] = null);
|
|
79
|
+
}
|
|
80
|
+
return new o(e, l, p, m, h, x);
|
|
81
|
+
}
|
|
82
|
+
async load(t, r) {
|
|
83
|
+
let { offset: i, bytes: a, count: o } = t;
|
|
84
|
+
if (!o) return { positions: /* @__PURE__ */ new Float32Array() };
|
|
85
|
+
let [s, { decodeLazChunk: c }] = await Promise.all([n(this.fetcher, this.url, i, a, r), import("./laz.js")]), l = c(s, o, this.header, this.records);
|
|
86
|
+
r.throwIfAborted();
|
|
87
|
+
let u = e({
|
|
88
|
+
...this.header,
|
|
89
|
+
pointCount: o
|
|
90
|
+
}, this.records, l, { origin: this.origin }), d = u.rgb, f = {
|
|
91
|
+
intensity: u.intensity,
|
|
92
|
+
classification: u.classification,
|
|
93
|
+
return_number: u.returnNumber,
|
|
94
|
+
number_of_returns: u.numberOfReturns,
|
|
95
|
+
classification_flags: u.classificationFlags,
|
|
96
|
+
scan_angle: u.scanAngle,
|
|
97
|
+
point_source_id: u.pointSourceId,
|
|
98
|
+
user_data: u.userData,
|
|
99
|
+
...u.gpsTime ? { gps_time: u.gpsTime } : {},
|
|
100
|
+
...u.nir ? { nir: u.nir } : {},
|
|
101
|
+
...u.extra
|
|
102
|
+
};
|
|
103
|
+
if (!d) return {
|
|
104
|
+
positions: u.positions,
|
|
105
|
+
attributes: f
|
|
106
|
+
};
|
|
107
|
+
let p = new Uint8Array(d.length), m = this.wideColors;
|
|
108
|
+
if (m === void 0 && d.length) {
|
|
109
|
+
m = !1;
|
|
110
|
+
for (let e = 0; e < d.length && !m; e++) m = d[e] > 255;
|
|
111
|
+
this.wideColors = m;
|
|
112
|
+
}
|
|
113
|
+
for (let e = 0; e < d.length; e++) p[e] = m ? d[e] >> 8 : d[e];
|
|
114
|
+
return {
|
|
115
|
+
positions: u.positions,
|
|
116
|
+
colors: p,
|
|
117
|
+
colorComponents: 3,
|
|
118
|
+
attributes: f
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function s(e) {
|
|
123
|
+
if (e.byteLength < 100) throw RangeError("COPC header is cut short; the file is truncated");
|
|
124
|
+
return new DataView(e.buffer, e.byteOffset, e.byteLength).getUint32(96, !0);
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { o as CopcSource, a as copcInfo };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PointCloud, type PointCloudData, type PointCloudOptions } from './cloud.js';
|
|
2
|
+
/** 8-bit RGBA pixels, row 0 at the top: an `ImageData` fits. */
|
|
3
|
+
export interface DepthFrameImage {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
data: Uint8Array | Uint8ClampedArray;
|
|
7
|
+
}
|
|
8
|
+
/** How a depth video stores depth. */
|
|
9
|
+
export type DepthEncoding =
|
|
10
|
+
/** One 8-bit channel (the red one) of a grey picture: `near` at 0 and `far` at 255 (`invert` swaps them). */
|
|
11
|
+
'gray'
|
|
12
|
+
/** 16 bits: red is the high byte and green the low one (lossless formats only). Value / 65535 between `near` and `far`. */
|
|
13
|
+
| 'rg16'
|
|
14
|
+
/** 16 bits as in `'rg16'`, read as millimetres: metres = value / 1000, `near` and `far` still clip. */
|
|
15
|
+
| 'millimeters';
|
|
16
|
+
/** Where the depth sits in a frame. */
|
|
17
|
+
export type DepthLayout =
|
|
18
|
+
/** The colour is the left half of the frame and the depth the right half (the usual one-file depth video). */
|
|
19
|
+
'side-by-side'
|
|
20
|
+
/** The colour is the top half and the depth the bottom half. */
|
|
21
|
+
| 'top-bottom'
|
|
22
|
+
/** The depth is a second picture, passed beside the frame. */
|
|
23
|
+
| 'separate';
|
|
24
|
+
/** Options of {@link depthVideoPoints} and {@link DepthVideoCloud}. */
|
|
25
|
+
export interface DepthVideoOptions {
|
|
26
|
+
/** Where the depth is. Default `'side-by-side'`. */
|
|
27
|
+
layout?: DepthLayout;
|
|
28
|
+
/** How depth is stored. Default `'gray'`. */
|
|
29
|
+
encoding?: DepthEncoding;
|
|
30
|
+
/** The depth, in metres, that the lowest stored value means, and the nearest depth kept. Default 0.3. */
|
|
31
|
+
near?: number;
|
|
32
|
+
/** The depth that the highest stored value means, and the farthest kept. Default 5. */
|
|
33
|
+
far?: number;
|
|
34
|
+
/** The stored values run the other way: the highest is near. Default false. */
|
|
35
|
+
invert?: boolean;
|
|
36
|
+
/** Vertical field of view in degrees, for a camera with square pixels. Default 60. Ignored with `intrinsics`. */
|
|
37
|
+
fov?: number;
|
|
38
|
+
/** The camera's focal lengths and principal point in pixels of the colour picture, when known (they set `fov`). */
|
|
39
|
+
intrinsics?: {
|
|
40
|
+
fx: number;
|
|
41
|
+
fy: number;
|
|
42
|
+
cx: number;
|
|
43
|
+
cy: number;
|
|
44
|
+
};
|
|
45
|
+
/** Keep every n-th pixel in both directions. Default 1. */
|
|
46
|
+
stride?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Drop a pixel whose depth differs from a neighbour's (left, right, above, below) by more than this share of its own
|
|
49
|
+
* depth: the flying pixels along an edge. 0 keeps everything. Default 0.05.
|
|
50
|
+
*/
|
|
51
|
+
maxJump?: number;
|
|
52
|
+
}
|
|
53
|
+
/** Points from one frame, in `PointCloudData`'s shape. */
|
|
54
|
+
export interface DepthVideoPoints extends PointCloudData {
|
|
55
|
+
positions: Float32Array;
|
|
56
|
+
/** RGB in 0..255 per point. */
|
|
57
|
+
colors: Uint8Array;
|
|
58
|
+
/** Pixels kept, which is `positions.length / 3`. */
|
|
59
|
+
count: number;
|
|
60
|
+
/** Size of the colour picture the points came from. */
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Unprojects one RGB + depth frame into points, dropping pixels with no depth or with a jump (see `maxJump`). Returns
|
|
66
|
+
* `PointCloudData` for `new PointCloud(...)`. `depth` is the second picture of `layout: 'separate'`; it may differ in
|
|
67
|
+
* size from the colour picture.
|
|
68
|
+
* @throws TypeError or RangeError for options out of range, MargoError `'failed'` for an empty picture.
|
|
69
|
+
*/
|
|
70
|
+
export declare function depthVideoPoints(frame: DepthFrameImage, options?: DepthVideoOptions, depth?: DepthFrameImage): DepthVideoPoints;
|
|
71
|
+
/** Options of {@link DepthVideoCloud}: the video options plus those of the cloud it makes. */
|
|
72
|
+
export interface DepthVideoCloudOptions extends DepthVideoOptions {
|
|
73
|
+
/** Size of the colour picture the video will deliver (after `layout` splitting), in pixels. */
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
/** Options of the `PointCloud`, for example `material`. */
|
|
77
|
+
cloud?: Omit<PointCloudOptions, 'positions' | 'colors' | 'sizes' | 'colorComponents'>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A `PointCloud` that follows a depth video: one point per kept pixel, rewritten by every `update(frame)`. Pixels with
|
|
81
|
+
* no depth, and flying pixels, get size 0 for the frame, so the point count never changes and nothing is reallocated.
|
|
82
|
+
* Add `cloud` to a `PointsPlugin`.
|
|
83
|
+
*/
|
|
84
|
+
export declare class DepthVideoCloud implements Disposable {
|
|
85
|
+
/** The cloud to add to a `PointsPlugin`. */
|
|
86
|
+
readonly cloud: PointCloud;
|
|
87
|
+
/** Points the cloud holds (showing or not). */
|
|
88
|
+
readonly count: number;
|
|
89
|
+
private readonly options;
|
|
90
|
+
constructor(options: DepthVideoCloudOptions);
|
|
91
|
+
/**
|
|
92
|
+
* Writes a frame into the cloud and returns how many points show. A frame whose colour picture is not `width` x
|
|
93
|
+
* `height` throws a RangeError.
|
|
94
|
+
*/
|
|
95
|
+
update(frame: DepthFrameImage, depth?: DepthFrameImage): number;
|
|
96
|
+
/** Releases the cloud. */
|
|
97
|
+
[Symbol.dispose](): void;
|
|
98
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { t as e } from "./cloud-B4O_G-Df.js";
|
|
2
|
+
import { MargoError as t } from "@margoengine/math/errors";
|
|
3
|
+
//#region src/depth-video.ts
|
|
4
|
+
function n(e) {
|
|
5
|
+
let t = {
|
|
6
|
+
layout: e.layout ?? "side-by-side",
|
|
7
|
+
encoding: e.encoding ?? "gray",
|
|
8
|
+
near: e.near ?? .3,
|
|
9
|
+
far: e.far ?? 5,
|
|
10
|
+
invert: e.invert ?? !1,
|
|
11
|
+
fov: e.fov ?? 60,
|
|
12
|
+
intrinsics: e.intrinsics,
|
|
13
|
+
stride: e.stride ?? 1,
|
|
14
|
+
maxJump: e.maxJump ?? .05
|
|
15
|
+
};
|
|
16
|
+
if (![
|
|
17
|
+
"side-by-side",
|
|
18
|
+
"top-bottom",
|
|
19
|
+
"separate"
|
|
20
|
+
].includes(t.layout)) throw TypeError(`layout ${t.layout} is unknown; use 'side-by-side', 'top-bottom' or 'separate'`);
|
|
21
|
+
if (![
|
|
22
|
+
"gray",
|
|
23
|
+
"rg16",
|
|
24
|
+
"millimeters"
|
|
25
|
+
].includes(t.encoding)) throw TypeError(`encoding ${t.encoding} is unknown; use 'gray', 'rg16' or 'millimeters'`);
|
|
26
|
+
if (!(t.near > 0) || !(t.far > t.near) || !Number.isFinite(t.far)) throw RangeError(`near ${t.near} and far ${t.far} must satisfy 0 < near < far`);
|
|
27
|
+
if (!(t.fov > 0 && t.fov < 180)) throw RangeError(`fov ${t.fov} must be between 0 and 180 degrees`);
|
|
28
|
+
if (!Number.isInteger(t.stride) || t.stride < 1) throw RangeError(`stride ${t.stride} must be an integer of at least 1`);
|
|
29
|
+
if (!(t.maxJump >= 0)) throw RangeError(`maxJump ${t.maxJump} must not be negative`);
|
|
30
|
+
return t;
|
|
31
|
+
}
|
|
32
|
+
var r = (e, n) => {
|
|
33
|
+
if (!(e.width > 0 && e.height > 0) || e.data.length < e.width * e.height * 4) throw new t("failed", `${n}: the image is empty or shorter than width x height x 4 bytes; pass RGBA pixels`);
|
|
34
|
+
};
|
|
35
|
+
function i(e, t, n) {
|
|
36
|
+
if (r(e, "depth video frame"), n === "separate") {
|
|
37
|
+
if (!t) throw TypeError("layout 'separate' needs the depth picture as the second argument");
|
|
38
|
+
return r(t, "depth picture"), {
|
|
39
|
+
color: {
|
|
40
|
+
x: 0,
|
|
41
|
+
y: 0,
|
|
42
|
+
w: e.width,
|
|
43
|
+
h: e.height,
|
|
44
|
+
image: e
|
|
45
|
+
},
|
|
46
|
+
depth: {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
w: t.width,
|
|
50
|
+
h: t.height,
|
|
51
|
+
image: t
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
let i = n === "side-by-side" ? e.width : e.height;
|
|
56
|
+
if (i % 2) throw RangeError(`a ${n} frame needs an even ${n === "side-by-side" ? "width" : "height"}; got ${i}`);
|
|
57
|
+
let a = n === "side-by-side" ? e.width / 2 : e.width, o = n === "side-by-side" ? e.height : e.height / 2;
|
|
58
|
+
return {
|
|
59
|
+
color: {
|
|
60
|
+
x: 0,
|
|
61
|
+
y: 0,
|
|
62
|
+
w: a,
|
|
63
|
+
h: o,
|
|
64
|
+
image: e
|
|
65
|
+
},
|
|
66
|
+
depth: {
|
|
67
|
+
x: n === "side-by-side" ? a : 0,
|
|
68
|
+
y: n === "side-by-side" ? 0 : o,
|
|
69
|
+
w: a,
|
|
70
|
+
h: o,
|
|
71
|
+
image: e
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function a(e, t, n, r) {
|
|
76
|
+
let i = ((t.y + r) * t.image.width + t.x + n) * 4, a = t.image.data;
|
|
77
|
+
if (e.encoding === "millimeters") {
|
|
78
|
+
let t = a[i] << 8 | a[i + 1], n = t / 1e3;
|
|
79
|
+
return t !== 0 && n >= e.near && n <= e.far ? n : NaN;
|
|
80
|
+
}
|
|
81
|
+
let o = e.encoding === "gray" ? a[i] : a[i] << 8 | a[i + 1];
|
|
82
|
+
if (o === 0) return NaN;
|
|
83
|
+
let s = o / (e.encoding === "gray" ? 255 : 65535);
|
|
84
|
+
return e.near + (e.invert ? 1 - s : s) * (e.far - e.near);
|
|
85
|
+
}
|
|
86
|
+
function o(e, t, n) {
|
|
87
|
+
let { color: r, depth: o } = i(e, t, n.layout), s = n.intrinsics ?? {
|
|
88
|
+
fx: r.h / 2 / Math.tan(n.fov * Math.PI / 360),
|
|
89
|
+
fy: r.h / 2 / Math.tan(n.fov * Math.PI / 360),
|
|
90
|
+
cx: r.w / 2,
|
|
91
|
+
cy: r.h / 2
|
|
92
|
+
}, c = Math.ceil(r.w / n.stride), l = Math.ceil(r.h / n.stride), u = c * l, d = new Float32Array(u * 3), f = new Uint8Array(u * 3), p = new Uint8Array(u), m = new Float32Array(u);
|
|
93
|
+
for (let e = 0; e < l; e++) for (let t = 0; t < c; t++) {
|
|
94
|
+
let i = Math.min(r.w - 1, t * n.stride), s = Math.min(r.h - 1, e * n.stride);
|
|
95
|
+
m[e * c + t] = a(n, o, Math.min(o.w - 1, Math.floor((i + .5) / r.w * o.w)), Math.min(o.h - 1, Math.floor((s + .5) / r.h * o.h)));
|
|
96
|
+
}
|
|
97
|
+
let h = 0;
|
|
98
|
+
for (let e = 0; e < l; e++) for (let t = 0; t < c; t++) {
|
|
99
|
+
let i = e * c + t, a = m[i];
|
|
100
|
+
if (Number.isNaN(a)) continue;
|
|
101
|
+
if (n.maxJump > 0) {
|
|
102
|
+
let r = !1;
|
|
103
|
+
for (let [i, o] of [
|
|
104
|
+
[-1, 0],
|
|
105
|
+
[1, 0],
|
|
106
|
+
[0, -1],
|
|
107
|
+
[0, 1]
|
|
108
|
+
]) {
|
|
109
|
+
let s = t + i, u = e + o;
|
|
110
|
+
if (s < 0 || u < 0 || s >= c || u >= l) continue;
|
|
111
|
+
let d = m[u * c + s];
|
|
112
|
+
!Number.isNaN(d) && Math.abs(d - a) > a * n.maxJump && (r = !0);
|
|
113
|
+
}
|
|
114
|
+
if (r) continue;
|
|
115
|
+
}
|
|
116
|
+
let o = Math.min(r.w - 1, t * n.stride), u = Math.min(r.h - 1, e * n.stride), g = ((r.y + u) * r.image.width + r.x + o) * 4;
|
|
117
|
+
d[i * 3] = (o + .5 - s.cx) * a / s.fx, d[i * 3 + 1] = (s.cy - (u + .5)) * a / s.fy, d[i * 3 + 2] = -a, f[i * 3] = r.image.data[g], f[i * 3 + 1] = r.image.data[g + 1], f[i * 3 + 2] = r.image.data[g + 2], p[i] = 1, h++;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
columns: c,
|
|
121
|
+
rows: l,
|
|
122
|
+
width: r.w,
|
|
123
|
+
height: r.h,
|
|
124
|
+
positions: d,
|
|
125
|
+
colors: f,
|
|
126
|
+
valid: p,
|
|
127
|
+
shown: h
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function s(e, t = {}, r) {
|
|
131
|
+
let i = o(e, r, n(t)), a = new Float32Array(i.shown * 3), s = new Uint8Array(i.shown * 3), c = 0;
|
|
132
|
+
for (let e = 0; e < i.valid.length; e++) i.valid[e] && (a.set(i.positions.subarray(e * 3, e * 3 + 3), c * 3), s.set(i.colors.subarray(e * 3, e * 3 + 3), c * 3), c++);
|
|
133
|
+
return {
|
|
134
|
+
positions: a,
|
|
135
|
+
colors: s,
|
|
136
|
+
count: c,
|
|
137
|
+
width: i.width,
|
|
138
|
+
height: i.height
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
var c = class {
|
|
142
|
+
constructor(t) {
|
|
143
|
+
let r = n(t);
|
|
144
|
+
if (!Number.isInteger(t.width) || !Number.isInteger(t.height) || t.width < 1 || t.height < 1) throw RangeError(`width ${t.width} and height ${t.height} must be integers of at least 1`);
|
|
145
|
+
this.options = t, this.count = Math.ceil(t.width / r.stride) * Math.ceil(t.height / r.stride), this.cloud = new e({
|
|
146
|
+
...t.cloud,
|
|
147
|
+
positions: new Float32Array(this.count * 3),
|
|
148
|
+
colors: new Uint8Array(this.count * 3),
|
|
149
|
+
colorComponents: 3,
|
|
150
|
+
sizes: new Float32Array(this.count)
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
update(e, t) {
|
|
154
|
+
let r = o(e, t, n(this.options));
|
|
155
|
+
if (r.width !== this.options.width || r.height !== this.options.height) throw RangeError(`the frame's colour picture is ${r.width} x ${r.height}; this cloud was made for ${this.options.width} x ${this.options.height}`);
|
|
156
|
+
let i = new Float32Array(r.valid);
|
|
157
|
+
return this.cloud.updatePositions(0, r.positions).updateColors(0, r.colors, 3).updateSizes(0, i), r.shown;
|
|
158
|
+
}
|
|
159
|
+
[Symbol.dispose]() {
|
|
160
|
+
this.cloud.dispose();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
//#endregion
|
|
164
|
+
export { c as DepthVideoCloud, s as depthVideoPoints };
|
package/dist/e57.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** CRC-32C of bytes. */
|
|
2
|
+
export declare function crc32c(bytes: Uint8Array): number;
|
|
3
|
+
/** A parsed XML element (the subset E57 uses: elements, attributes, text). */
|
|
4
|
+
export interface E57Element {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
7
|
+
readonly children: readonly E57Element[];
|
|
8
|
+
readonly text: string;
|
|
9
|
+
}
|
|
10
|
+
/** Parses XML into elements (no DTDs, no processing beyond the declaration); throws TypeError on malformed input. */
|
|
11
|
+
export declare function parseXML(source: string): E57Element;
|
|
12
|
+
/** The file header. */
|
|
13
|
+
export interface E57Header {
|
|
14
|
+
readonly versionMajor: number;
|
|
15
|
+
readonly versionMinor: number;
|
|
16
|
+
readonly physicalLength: number;
|
|
17
|
+
readonly xmlOffset: number;
|
|
18
|
+
readonly xmlLength: number;
|
|
19
|
+
readonly pageSize: number;
|
|
20
|
+
}
|
|
21
|
+
/** One field of a points prototype. */
|
|
22
|
+
export interface E57Field {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly type: 'Float' | 'ScaledInteger' | 'Integer';
|
|
25
|
+
/** Float precision in bits (32 or 64), or the packed width of integers. */
|
|
26
|
+
readonly bits: number;
|
|
27
|
+
readonly minimum: number;
|
|
28
|
+
readonly maximum: number;
|
|
29
|
+
readonly scale: number;
|
|
30
|
+
readonly offset: number;
|
|
31
|
+
}
|
|
32
|
+
/** One scan (a data3D child): its points in world coordinates (pose applied) relative to the file's origin. */
|
|
33
|
+
export interface E57Scan {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly guid: string;
|
|
36
|
+
/** Rotation quaternion [w, x, y, z] and translation of the scan's pose. */
|
|
37
|
+
readonly pose: {
|
|
38
|
+
readonly rotation: readonly [number, number, number, number];
|
|
39
|
+
readonly translation: readonly [number, number, number];
|
|
40
|
+
};
|
|
41
|
+
readonly fields: readonly E57Field[];
|
|
42
|
+
/** Records stored (including invalid ones). */
|
|
43
|
+
readonly recordCount: number;
|
|
44
|
+
/** Valid points kept. */
|
|
45
|
+
readonly count: number;
|
|
46
|
+
/** xyz per point relative to `origin`, float32. */
|
|
47
|
+
readonly positions: Float32Array;
|
|
48
|
+
/** Intensity normalised to 0..1 by `intensityLimits`, when the scan has it. */
|
|
49
|
+
readonly intensity?: Float32Array;
|
|
50
|
+
/** RGBA 0..255, normalised by `colorLimits`, when the scan has colour. */
|
|
51
|
+
readonly colors?: Uint8Array;
|
|
52
|
+
/** Any other numeric field (returnIndex, timeStamp, rowIndex, ...), by name, raw values. */
|
|
53
|
+
readonly attributes: Readonly<Record<string, Float64Array>>;
|
|
54
|
+
}
|
|
55
|
+
/** How an E57 2D image maps pixels to rays. */
|
|
56
|
+
export type E57ImageProjection = 'pinhole' | 'spherical' | 'cylindrical' | 'visualReference';
|
|
57
|
+
/** One images2D entry: the encoded picture bytes with the camera pose and projection parameters. */
|
|
58
|
+
export interface E57Image {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly guid: string;
|
|
61
|
+
/** guid of the scan (data3D child) this picture was taken with, when stated. */
|
|
62
|
+
readonly associatedScanGuid?: string;
|
|
63
|
+
readonly description?: string;
|
|
64
|
+
readonly projection: E57ImageProjection;
|
|
65
|
+
readonly width: number;
|
|
66
|
+
readonly height: number;
|
|
67
|
+
/** Encoding of `data`. */
|
|
68
|
+
readonly format: 'jpeg' | 'png';
|
|
69
|
+
readonly mime: 'image/jpeg' | 'image/png';
|
|
70
|
+
/** The encoded picture, ready for `new Blob([data], { type: mime })` or `createImageBitmap`. */
|
|
71
|
+
readonly data: Uint8Array<ArrayBuffer>;
|
|
72
|
+
/** Optional PNG mask (non-zero pixels are valid). */
|
|
73
|
+
readonly mask?: Uint8Array<ArrayBuffer>;
|
|
74
|
+
/** Camera pose in the file's world frame (not recentred on `origin`): rotation [w, x, y, z] and translation. */
|
|
75
|
+
readonly pose: {
|
|
76
|
+
readonly rotation: readonly [number, number, number, number];
|
|
77
|
+
readonly translation: readonly [number, number, number];
|
|
78
|
+
};
|
|
79
|
+
/** Projection parameters by name: pinhole focalLength, pixelWidth, pixelHeight, principalPointX/Y; spherical
|
|
80
|
+
* pixelWidth, pixelHeight; cylindrical radius, principalPointY, pixelWidth, pixelHeight. Lengths in metres. */
|
|
81
|
+
readonly parameters: Readonly<Record<string, number>>;
|
|
82
|
+
}
|
|
83
|
+
/** A parsed E57 file. */
|
|
84
|
+
export interface E57File {
|
|
85
|
+
readonly header: E57Header;
|
|
86
|
+
readonly xml: E57Element;
|
|
87
|
+
/** World position of local [0, 0, 0]: the centre of every scan's posed bounds unless `origin` was given. */
|
|
88
|
+
readonly origin: readonly [number, number, number];
|
|
89
|
+
readonly scans: readonly E57Scan[];
|
|
90
|
+
/** The images2D pictures with their poses (empty when the file has none or `images: false`). */
|
|
91
|
+
readonly images: readonly E57Image[];
|
|
92
|
+
/** Coordinate metadata text of the root, when present. */
|
|
93
|
+
readonly coordinateMetadata?: string;
|
|
94
|
+
}
|
|
95
|
+
/** Options of `parseE57`. */
|
|
96
|
+
export interface E57Options {
|
|
97
|
+
/** World position to store positions relative to. Default: the centre of all posed points. */
|
|
98
|
+
origin?: readonly [number, number, number];
|
|
99
|
+
/** Verify every page's CRC-32C. Default true. */
|
|
100
|
+
verifyChecksums?: boolean;
|
|
101
|
+
/** Keep points flagged invalid (cartesianInvalidState 2, sphericalInvalidState 2). Default false. */
|
|
102
|
+
keepInvalid?: boolean;
|
|
103
|
+
/** Read the images2D pictures. Default true. */
|
|
104
|
+
images?: boolean;
|
|
105
|
+
signal?: AbortSignal;
|
|
106
|
+
}
|
|
107
|
+
/** Reads the 48-byte header. */
|
|
108
|
+
export declare function readE57Header(bytes: Uint8Array): E57Header;
|
|
109
|
+
/** Parses an E57 file: every scan's points posed into one world frame. */
|
|
110
|
+
export declare function parseE57(input: ArrayBuffer | Uint8Array, options?: E57Options): E57File;
|
|
111
|
+
/** Fetches and parses an E57 file. Aborts with `options.signal`. */
|
|
112
|
+
export declare function loadE57(url: string | URL, options?: E57Options & {
|
|
113
|
+
fetch?: typeof fetch;
|
|
114
|
+
}): Promise<E57File>;
|
|
115
|
+
/** A scan for `writeE57`. */
|
|
116
|
+
export interface E57WriteScan {
|
|
117
|
+
name?: string;
|
|
118
|
+
/** xyz per point (scan-local unless a pose is given). Or give `spherical` instead. */
|
|
119
|
+
positions?: ArrayLike<number>;
|
|
120
|
+
/** range, azimuth, elevation per point (radians). */
|
|
121
|
+
spherical?: ArrayLike<number>;
|
|
122
|
+
/** Store coordinates as ScaledInteger with this resolution instead of double floats. */
|
|
123
|
+
resolution?: number;
|
|
124
|
+
/** Intensity 0..1 (stored as a 16-bit Integer). */
|
|
125
|
+
intensity?: ArrayLike<number>;
|
|
126
|
+
/** RGB 0..255 per point (8-bit Integers). */
|
|
127
|
+
rgb?: ArrayLike<number>;
|
|
128
|
+
/** cartesianInvalidState (or spherical) per point: 0 valid, 1 direction only, 2 invalid. */
|
|
129
|
+
invalid?: ArrayLike<number>;
|
|
130
|
+
pose?: {
|
|
131
|
+
rotation?: readonly [number, number, number, number];
|
|
132
|
+
translation?: readonly [number, number, number];
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** A picture for `writeE57`. */
|
|
136
|
+
export interface E57WriteImage {
|
|
137
|
+
name?: string;
|
|
138
|
+
/** Encoded JPEG or PNG bytes. */
|
|
139
|
+
data: Uint8Array;
|
|
140
|
+
format: 'jpeg' | 'png';
|
|
141
|
+
projection: 'pinhole' | 'spherical' | 'cylindrical';
|
|
142
|
+
width: number;
|
|
143
|
+
height: number;
|
|
144
|
+
/** PNG mask bytes. */
|
|
145
|
+
mask?: Uint8Array;
|
|
146
|
+
/** Index of the scan written with it that this picture belongs to. */
|
|
147
|
+
scan?: number;
|
|
148
|
+
pose?: {
|
|
149
|
+
rotation?: readonly [number, number, number, number];
|
|
150
|
+
translation?: readonly [number, number, number];
|
|
151
|
+
};
|
|
152
|
+
/** Projection parameters (focalLength, pixelWidth, pixelHeight, principalPointX, principalPointY, radius). */
|
|
153
|
+
parameters?: Readonly<Record<string, number>>;
|
|
154
|
+
}
|
|
155
|
+
/** Writes an E57 file (bitPack codec, one data packet stream per scan). Meant for tools and round-trip tests. */
|
|
156
|
+
export declare function writeE57(scans: readonly E57WriteScan[], options?: {
|
|
157
|
+
packetBytes?: number;
|
|
158
|
+
}): Uint8Array;
|
|
159
|
+
/** `writeE57` with pictures: the same scans plus `images` written as images2D with their poses and projections. */
|
|
160
|
+
export declare function writeE57Document(scans: readonly E57WriteScan[], options?: {
|
|
161
|
+
packetBytes?: number;
|
|
162
|
+
images?: readonly E57WriteImage[];
|
|
163
|
+
}): Uint8Array;
|