three-slicer-viewer 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,176 +0,0 @@
1
- const U = new Int8Array(8), W = new Int8Array(8), G = new Int8Array(8);
2
- for (let t = 0; t < 8; t++)
3
- U[t] = t & 1, W[t] = t >> 1 & 1, G[t] = t >> 2 & 1;
4
- const T = [], rt = [];
5
- for (let t = 0; t < 8; t++) for (let l = t + 1; l < 8; l++)
6
- Math.abs(U[t] - U[l]) + Math.abs(W[t] - W[l]) + Math.abs(G[t] - G[l]) === 1 && (T.push(t), rt.push(l));
7
- const ot = 127.5, q = (t) => t > ot, x = (t) => {
8
- const l = [];
9
- let A = new t(1048576), r = 0, m = 0;
10
- return {
11
- push3(u, C, h) {
12
- r + 3 > A.length && (l.push(A.subarray(0, r)), m += r, A = new t(1 << 20), r = 0), A[r++] = u, A[r++] = C, A[r++] = h;
13
- },
14
- concat() {
15
- l.push(A.subarray(0, r)), m += r;
16
- const u = new t(m);
17
- let C = 0;
18
- for (const h of l)
19
- u.set(h, C), C += h.length;
20
- return u;
21
- }
22
- };
23
- }, ct = { 0: [0.68, 0.238, 0.023], 5: [0.328, 0.188, 0.687], 6: [0.434, 0.352, 0.144] };
24
- function ht(t, l, A, r, m, u, C, h) {
25
- const b = t + 1, a = l + 1;
26
- let o = new Int32Array(b * a).fill(-1), i = new Int32Array(b * a).fill(-1);
27
- const N = null;
28
- let F = N, w = N, H = null, P = null, J = null, d = null, at = 0;
29
- const tt = x(Float32Array), Y = x(Uint32Array), et = x(Float32Array);
30
- let nt = 0, Q = !1;
31
- const S = (g, c, n) => !g || c < 0 || n < 0 || c >= t || n >= l ? 0 : g[c + t * n], O = new Float64Array(8);
32
- function lt(g, c, n, R, s, k, y, p) {
33
- const e = c + 1 + b * (n + 1), M = g[e];
34
- if (M >= 0) return M;
35
- O[0] = S(s, c, n), O[1] = S(s, c + 1, n), O[2] = S(s, c, n + 1), O[3] = S(s, c + 1, n + 1), O[4] = S(k, c, n), O[5] = S(k, c + 1, n), O[6] = S(k, c, n + 1), O[7] = S(k, c + 1, n + 1);
36
- let z = 0, f = 0, I = 0, v = 0;
37
- for (let E = 0; E < T.length; E++) {
38
- const B = T[E], L = rt[E];
39
- if (q(O[B]) === q(O[L])) continue;
40
- const X = Math.min(1, Math.max(0, (ot - O[B]) / (O[L] - O[B])));
41
- z += U[B] + X * (U[L] - U[B]), f += W[B] + X * (W[L] - W[B]), I += G[B] + X * (G[L] - G[B]), v++;
42
- }
43
- const K = v ? z / v : 0.5, j = v ? f / v : 0.5, D = v ? I / v : 0.5;
44
- if (tt.push3(u + (c + K + 0.5) * A, C + (n + j + 0.5) * r, h + (R + D + 0.5) * m), Q) {
45
- let E = 0;
46
- for (let L = 0; L < 8; L++) {
47
- if (!q(O[L])) continue;
48
- const X = S(G[L] ? p : y, c + U[L], n + W[L]);
49
- if (X === 5) {
50
- E = 5;
51
- break;
52
- }
53
- X === 6 && (E = 6);
54
- }
55
- const B = ct[E];
56
- et.push3(B[0], B[1], B[2]);
57
- }
58
- return g[e] = nt, nt++;
59
- }
60
- const Z = (g, c, n) => c === N || n < 0 || n >= l ? t : g ? g[n * 2] : 0, _ = (g, c, n) => c === N || n < 0 || n >= l ? -1 : g ? g[n * 2 + 1] : t - 1;
61
- function V(g, c, n) {
62
- const R = at++, s = (e, M) => lt(o, e, M, R - 1, F, w, H, P), k = (e, M) => lt(i, e, M, R, w, g, P, c), y = (e, M, z, f, I) => {
63
- I ? (Y.push3(f, z, M), Y.push3(f, M, e)) : (Y.push3(e, M, z), Y.push3(e, z, f));
64
- };
65
- for (let e = 0; e < l; e++) {
66
- const M = Math.min(Z(J, F, e), Z(d, w, e)), z = Math.max(_(J, F, e), _(d, w, e));
67
- for (let f = M; f <= z; f++) {
68
- const I = q(S(F, f, e)), v = q(S(w, f, e));
69
- I !== v && y(s(f - 1, e - 1), s(f, e - 1), s(f, e), s(f - 1, e), !I);
70
- }
71
- }
72
- for (let e = 0; e < l; e++) {
73
- const M = Z(d, w, e), z = _(d, w, e);
74
- for (let f = M - 1; f <= z; f++) {
75
- const I = q(S(w, f, e)), v = q(S(w, f + 1, e));
76
- I !== v && y(s(f, e - 1), s(f, e), k(f, e), k(f, e - 1), !I);
77
- }
78
- }
79
- for (let e = -1; e < l; e++) {
80
- const M = Math.min(Z(d, w, e), Z(d, w, e + 1)), z = Math.max(_(d, w, e), _(d, w, e + 1));
81
- for (let f = M; f <= z; f++) {
82
- const I = q(S(w, f, e)), v = q(S(w, f, e + 1));
83
- I !== v && y(s(f - 1, e), k(f - 1, e), k(f, e), s(f, e), !I);
84
- }
85
- }
86
- const p = o;
87
- o = i, i = p.fill(-1);
88
- }
89
- let $ = !1;
90
- return {
91
- // Slices arrive bottom-up. Layer s can only be processed once s+1 is known (its cells' upper corners live
92
- // there), so the first slice just primes the window and every later push runs the step one layer behind.
93
- // `roles` is an optional parallel Uint8Array (0=model, 5=support, 6=pad) that turns on vertex colours;
94
- // `ranges` the per-row occupancy spans fillSliceFromRGBA returns, which confine the sweep to the model.
95
- pushSlice(g, c = null, n = null) {
96
- if (c && (Q = !0), !$) {
97
- $ = !0, w = g, P = c, d = n;
98
- return;
99
- }
100
- V(g, c), F = w, w = g, H = P, P = c, J = d, d = n;
101
- },
102
- finish({ smoothRounds: g = 0, normalRounds: c = 0 } = {}) {
103
- $ && (V(N, null), F = w, w = N, H = P, P = null, J = d, d = null), V(N, null);
104
- const n = tt.concat(), R = Y.concat();
105
- g > 0 && st(n, R, g);
106
- const s = new Float32Array(n.length);
107
- for (let k = 0; k < R.length; k += 3) {
108
- const y = R[k] * 3, p = R[k + 1] * 3, e = R[k + 2] * 3, M = n[p] - n[y], z = n[p + 1] - n[y + 1], f = n[p + 2] - n[y + 2], I = n[e] - n[y], v = n[e + 1] - n[y + 1], K = n[e + 2] - n[y + 2], j = z * K - f * v, D = f * I - M * K, E = M * v - z * I;
109
- s[y] += j, s[y + 1] += D, s[y + 2] += E, s[p] += j, s[p + 1] += D, s[p + 2] += E, s[e] += j, s[e + 1] += D, s[e + 2] += E;
110
- }
111
- return ft(s), c > 0 && ut(s, R, c), { positions: n, indices: R, normals: s, colors: Q ? et.concat() : null };
112
- }
113
- };
114
- }
115
- function ft(t) {
116
- for (let l = 0; l < t.length; l += 3) {
117
- const A = Math.hypot(t[l], t[l + 1], t[l + 2]) || 1;
118
- t[l] /= A, t[l + 1] /= A, t[l + 2] /= A;
119
- }
120
- }
121
- function ut(t, l, A = 2) {
122
- const r = new Float32Array(t.length);
123
- for (let m = 0; m < A; m++) {
124
- r.fill(0);
125
- for (let u = 0; u < l.length; u += 3) {
126
- const C = l[u] * 3, h = l[u + 1] * 3, b = l[u + 2] * 3;
127
- for (const [a, o] of [[C, h], [h, b], [b, C]])
128
- r[a] += t[o], r[a + 1] += t[o + 1], r[a + 2] += t[o + 2], r[o] += t[a], r[o + 1] += t[a + 1], r[o + 2] += t[a + 2];
129
- }
130
- for (let u = 0; u < t.length; u += 3)
131
- t[u] += 0.5 * r[u], t[u + 1] += 0.5 * r[u + 1], t[u + 2] += 0.5 * r[u + 2];
132
- ft(t);
133
- }
134
- }
135
- function st(t, l, A = 4) {
136
- const r = new Float32Array(t.length), m = new Float32Array(t.length / 3), u = (h, b) => {
137
- const a = h * 3, o = b * 3, i = Math.abs(t[o + 2] - t[a + 2]) + 0.05 * (Math.abs(t[o] - t[a]) + Math.abs(t[o + 1] - t[a + 1])) + 1e-6;
138
- r[a] += i * t[o], r[a + 1] += i * t[o + 1], r[a + 2] += i * t[o + 2], r[o] += i * t[a], r[o + 1] += i * t[a + 1], r[o + 2] += i * t[a + 2], m[h] += i, m[b] += i;
139
- }, C = (h) => {
140
- r.fill(0), m.fill(0);
141
- for (let b = 0; b < l.length; b += 3) {
142
- const a = l[b], o = l[b + 1], i = l[b + 2];
143
- u(a, o), u(o, i), u(i, a);
144
- }
145
- for (let b = 0; b < m.length; b++) {
146
- const a = m[b];
147
- if (!a) continue;
148
- const o = b * 3;
149
- t[o] += h * (r[o] / a - t[o]), t[o + 1] += h * (r[o + 1] / a - t[o + 1]), t[o + 2] += h * (r[o + 2] / a - t[o + 2]);
150
- }
151
- };
152
- for (let h = 0; h < A; h++)
153
- C(0.5), C(-0.53);
154
- }
155
- function bt(t, l, A, r, m) {
156
- const u = new Uint32Array(l.buffer, l.byteOffset, l.byteLength >> 2), C = new Int32Array(r * 2);
157
- for (let h = 0; h < r; h++) {
158
- const b = r - 1 - h, a = h * A * 4 >> 2, o = A * (b + r * m);
159
- let i = A, N = -1;
160
- for (let F = 0; F < A; F++) {
161
- const w = u[a + F];
162
- if (w === 0) {
163
- t[o + F] = 0;
164
- continue;
165
- }
166
- const H = w >> 8 & 255;
167
- t[o + F] = H, H && (F < i && (i = F), F > N && (N = F));
168
- }
169
- C[b * 2] = i, C[b * 2 + 1] = N;
170
- }
171
- return C;
172
- }
173
- export {
174
- bt as f,
175
- ht as m
176
- };