@vitessce/comparative 3.9.4 → 3.9.5

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,17 +1,17 @@
1
- import { aw as n, ax as we, ay as se, ar as ue, as as ze, az as _e, l as he, aA as ke, aB as Ie, m as re, aC as le, e as C, V as b, ag as Z, ae as De, aq as D, aD as Me, aE as Pe, av as Ae, W as Be, ad as Ne, z as Ue, aF as Le, aG as X, ao as B, aH as Oe, am as Fe } from "./index-Ce5JOk5t.js";
2
- import { useRef as M, useState as fe, useMemo as de, useEffect as $, Suspense as Ve } from "react";
3
- import { u as ve, a as Ge, O as me, C as qe } from "./OrbitControls-DWelGoKt.js";
4
- const S = 32, A = 64, V = 64, ce = 4, oe = A * V * ce, ge = A * S, xe = V * S, pe = ce * S, F = {
1
+ import { aw as n, ax as we, ay as se, ar as ue, as as ze, az as _e, l as he, aA as ke, aB as Ie, m as re, aC as le, e as C, V as _, ag as Z, ae as De, aq as M, aD as Me, aE as Pe, av as Ae, W as Be, ad as Ne, z as Ue, aF as Le, aG as j, ao as N, aH as Oe, am as Fe } from "./index-cJZeOqnJ.js";
2
+ import { useRef as P, useState as fe, useMemo as de, useEffect as $, Suspense as Ve } from "react";
3
+ import { u as ve, a as Ge, O as me, C as qe } from "./OrbitControls-BwflPmLE.js";
4
+ const S = 32, B = 64, G = 64, ce = 4, oe = B * G * ce, ge = B * S, xe = G * S, pe = ce * S, V = {
5
5
  NOT_STARTED: "not_started",
6
6
  IN_PROGRESS: "in_progress",
7
7
  COMPLETE: "complete",
8
8
  FAILED: "failed"
9
9
  };
10
- function z(h) {
11
- se(le.DEBUG) && console.warn(`%cDM: ${h}`, "background: blue; color: white; padding: 2px; border-radius: 3px;");
10
+ function z(f) {
11
+ se(le.DEBUG) && console.warn(`%cDM: ${f}`, "background: blue; color: white; padding: 2px; border-radius: 3px;");
12
12
  }
13
- function Ze(h) {
14
- return h.map((t) => {
13
+ function Ze(f) {
14
+ return f.map((t) => {
15
15
  const { dims: e } = t;
16
16
  return [
17
17
  // Other spatial-accelerated code assumes TCZYX dimension order
@@ -25,8 +25,8 @@ function Ze(h) {
25
25
  ];
26
26
  });
27
27
  }
28
- function Xe(h) {
29
- return h.map((t) => {
28
+ function Xe(f) {
29
+ return f.map((t) => {
30
30
  const e = [
31
31
  t.depth,
32
32
  // z
@@ -42,8 +42,8 @@ function Xe(h) {
42
42
  ];
43
43
  });
44
44
  }
45
- function je(h, t) {
46
- n.debug("_initMRMCPT", h, t);
45
+ function je(f, t) {
46
+ n.debug("_initMRMCPT", f, t);
47
47
  const e = {
48
48
  channelOffsets: [
49
49
  [0, 0, 1],
@@ -68,14 +68,14 @@ function je(h, t) {
68
68
  // original z extent plus the l0 z extent times the channel count
69
69
  };
70
70
  e.xExtent = 1, e.yExtent = 1, e.zExtent = 1;
71
- const i = h[0][0];
72
- e.z0Extent = i, e.lowestDataRes = h.length - 1;
73
- for (let c = h.length - 1; c > 0; c--)
71
+ const i = f[0][0];
72
+ e.z0Extent = i, e.lowestDataRes = f.length - 1;
73
+ for (let u = f.length - 1; u > 0; u--)
74
74
  e.anchors.push([
75
75
  e.xExtent,
76
76
  e.yExtent,
77
77
  e.zExtent
78
- ]), e.xExtent += h[c][2], e.yExtent += h[c][1], e.zExtent += h[c][0];
78
+ ]), e.xExtent += f[u][2], e.yExtent += f[u][1], e.zExtent += f[u][0];
79
79
  e.anchors.push([0, 0, e.zExtent]), e.anchors.reverse(), e.zTotal = e.zExtent + t * i;
80
80
  const a = new Uint8Array(ge * xe * pe);
81
81
  a.fill(0);
@@ -90,51 +90,59 @@ function je(h, t) {
90
90
  bcTHREE: o
91
91
  };
92
92
  }
93
- function Ye(h, t, e, i, a) {
93
+ function Ye(f, t, e, i, a) {
94
94
  const r = (o) => Math.max(0, Math.min(127, Math.floor(o / 2)));
95
- return (1 << 31 | 1 << 30 | r(h) << 23 | r(t) << 16 | (e & 63) << 10 | (i & 63) << 4 | a & 15) >>> 0;
95
+ return (1 << 31 | 1 << 30 | r(f) << 23 | r(t) << 16 | (e & 63) << 10 | (i & 63) << 4 | a & 15) >>> 0;
96
96
  }
97
- function He(h, t, e, i) {
97
+ function He(f, t, e, i) {
98
98
  const { PT_zExtent: a, PT_z0Extent: r, PT_anchors: o } = i;
99
- let l = -1, c = -1, s = -1, g = -1, p = -1;
99
+ let l = -1, u = -1, s = -1, v = -1, g = -1;
100
100
  if (e >= a)
101
- c = 0, s = h, g = t, p = (e - a) % r, l = Math.floor((e - a) / r);
101
+ u = 0, s = f, v = t, g = (e - a) % r, l = Math.floor((e - a) / r);
102
102
  else
103
- for (let u = 1; u < o.length; u++)
104
- if (!(h < o[u][0] && t < o[u][1] && e < o[u][2])) {
105
- c = u;
103
+ for (let c = 1; c < o.length; c++)
104
+ if (!(f < o[c][0] && t < o[c][1] && e < o[c][2])) {
105
+ u = c;
106
106
  const d = [0, 0, 0];
107
- h >= o[u][0] && (d[0] = 1), t >= o[u][1] && (d[1] = 1), e >= o[u][2] && (d[2] = 1);
108
- const v = d[0] << 2 | d[1] << 1 | d[2];
109
- l = Math.max(1, Math.min(7, v)) - 1;
110
- const f = d.map((x, _) => x * o[u][_]);
111
- s = h - f[0], g = t - f[1], p = e - f[2];
107
+ f >= o[c][0] && (d[0] = 1), t >= o[c][1] && (d[1] = 1), e >= o[c][2] && (d[2] = 1);
108
+ const m = d[0] << 2 | d[1] << 1 | d[2];
109
+ l = Math.max(1, Math.min(7, m)) - 1;
110
+ const h = d.map((x, b) => x * o[c][b]);
111
+ s = f - h[0], v = t - h[1], g = e - h[2];
112
112
  break;
113
113
  }
114
114
  return {
115
115
  channel: l,
116
- resolution: c,
116
+ resolution: u,
117
117
  x: s,
118
- y: g,
119
- z: p
118
+ y: v,
119
+ z: g
120
120
  };
121
121
  }
122
- function Ke(h, t) {
123
- const e = /* @__PURE__ */ new Map();
124
- for (let a = 0; a < h.length; a += 4) {
125
- const r = h[a], o = h[a + 1], l = h[a + 2], c = h[a + 3];
126
- if ((r | o | l | c) === 0)
122
+ const Ke = 0.25;
123
+ function We(f, t, e) {
124
+ const i = /* @__PURE__ */ new Map(), { width: a, height: r, sigmaNormalized: o } = e, l = Number.isInteger(a) && Number.isInteger(r) && a > 0 && r > 0 && typeof o == "number";
125
+ l || n.warn("_requestBufferToRequestObjects: proceeding without weighting");
126
+ const u = Math.floor(f.length / 4);
127
+ for (let v = 0; v < u; v += 1) {
128
+ const g = v * 4, c = f[g], d = f[g + 1], m = f[g + 2], h = f[g + 3];
129
+ if ((c | d | m | h) === 0)
127
130
  continue;
128
- const s = (r << 24 | o << 16 | l << 8 | c) >>> 0;
129
- e.set(s, (e.get(s) || 0) + 1);
131
+ const x = (c << 24 | d << 16 | m << 8 | h) >>> 0;
132
+ let b = 1;
133
+ if (l) {
134
+ const R = v % a, E = Math.floor(v / a), k = R - a / 2, O = E - r / 2, T = Math.sqrt(k * k / (a * a) + O * O / (r * r)) / o;
135
+ b = Math.exp(-0.5 * T * T);
136
+ }
137
+ i.set(x, (i.get(x) || 0) + b);
130
138
  }
131
- return { requests: [...e.entries()].sort((a, r) => r[1] - a[1]).slice(0, t).map(([a]) => ({
132
- x: a >> 22 & 1023,
133
- y: a >> 12 & 1023,
134
- z: a & 4095
135
- })), origRequestCount: e.size };
139
+ return { requests: [...i.entries()].sort((v, g) => g[1] - v[1]).slice(0, t).map(([v]) => ({
140
+ x: v >> 22 & 1023,
141
+ y: v >> 12 & 1023,
142
+ z: v & 4095
143
+ })), origRequestCount: i.size };
136
144
  }
137
- class We {
145
+ class $e {
138
146
  constructor(t) {
139
147
  z("CLASS INITIALIZING"), n.debug("VolumeDataManager constructor", { glParam: t, glParamContext: t.getContext?.() });
140
148
  const e = t.getContext?.() || t, i = t;
@@ -213,7 +221,7 @@ class We {
213
221
  // l0 z extent
214
222
  zTotal: 0
215
223
  // original z extent plus the l0 z extent times the channel count
216
- }, this.bricksEverLoaded = /* @__PURE__ */ new Set(), this.isBusy = !1, this.BCTimeStamps = new Array(oe).fill(0), this.BCMinMax = new Array(oe).fill([0, 0]), this.BCFull = !1, this.BCUnusedIndex = 0, this.bc2pt = new Array(oe).fill(null), this.LRUStack = [], this.triggerUsage = !0, this.triggerRequest = !1, this.timeStamp = 0, this.k = 40, this.noNewRequests = !1, this.manuallyStopped = !1, this.needsBailout = !1, this.initStatus = F.NOT_STARTED, this.initError = null, this._lastChannelConfig = null, this.currentRequestCount = 0, this.totalBricksRequested = 0, z("VolumeDataManager constructor complete");
224
+ }, this.bricksEverLoaded = /* @__PURE__ */ new Set(), this.isBusy = !1, this.BCTimeStamps = new Array(oe).fill(0), this.BCMinMax = new Array(oe).fill([0, 0]), this.BCFull = !1, this.BCUnusedIndex = 0, this.bc2pt = new Array(oe).fill(null), this.LRUStack = [], this.triggerUsage = !0, this.triggerRequest = !1, this.timeStamp = 0, this.k = 40, this.noNewRequests = !1, this.manuallyStopped = !1, this.needsBailout = !1, this.initStatus = V.NOT_STARTED, this.initError = null, this._lastChannelConfig = null, this.currentRequestCount = 0, this.totalBricksRequested = 0, z("VolumeDataManager constructor complete");
217
225
  }
218
226
  /**
219
227
  * Get loading progress information
@@ -293,8 +301,8 @@ class We {
293
301
  * @returns {Promise<Object>} Object with Zarr store details and device limits
294
302
  */
295
303
  async init(t) {
296
- if (z("INIT()"), this.initStatus !== F.NOT_STARTED)
297
- return n.debug("VolumeDataManager init() was called more than once!"), this.initStatus === F.COMPLETE ? {
304
+ if (z("INIT()"), this.initStatus !== V.NOT_STARTED)
305
+ return n.debug("VolumeDataManager init() was called more than once!"), this.initStatus === V.COMPLETE ? {
298
306
  success: !0,
299
307
  deviceLimits: this.deviceLimits,
300
308
  zarrStore: this.zarrStore,
@@ -302,7 +310,7 @@ class We {
302
310
  physicalSizeTotal: this.zarrStore.physicalSizeTotal,
303
311
  physicalSizeVoxel: this.zarrStore.physicalSizeVoxel,
304
312
  error: null
305
- } : this.initStatus === F.FAILED ? {
313
+ } : this.initStatus === V.FAILED ? {
306
314
  success: !1,
307
315
  error: this.initError || "Unknown initialization error"
308
316
  } : {
@@ -310,7 +318,7 @@ class We {
310
318
  pending: !0,
311
319
  error: "Initialization in progress"
312
320
  };
313
- this.initStatus = F.IN_PROGRESS, z("INIT() IN PROGRESS");
321
+ this.initStatus = V.IN_PROGRESS, z("INIT() IN PROGRESS");
314
322
  try {
315
323
  const e = this.images?.[this.imageLayerScopes?.[0]]?.image?.instance;
316
324
  if (this.ngffMetadata = e.vivLoader.metadata, n.debug("ngffMetadata", this.ngffMetadata), !e || e.getType() !== "ome-zarr")
@@ -323,7 +331,7 @@ class We {
323
331
  if (!we(o[0].labels, ["t", "c", "z", "y", "x"]))
324
332
  throw new Error("Expected OME-Zarr data with dimensions [t, c, z, y, x]");
325
333
  n.debug("vivData", o);
326
- const l = o.map((s) => s._data), c = new Array(r).fill(null);
334
+ const l = o.map((s) => s._data), u = new Array(r).fill(null);
327
335
  if (l.length > 0) {
328
336
  const s = l[0];
329
337
  if (this.zarrStore = {
@@ -341,13 +349,13 @@ class We {
341
349
  // store: this.store,
342
350
  // group: this.group,
343
351
  channelCount: a[0][1],
344
- scales: c
352
+ scales: u
345
353
  }, this.channels.colorMappings = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(-1), this.channels.zarrMappings = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(void 0), this.channels.downsampleMin = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(void 0), this.channels.downsampleMax = new Array(Math.min(this.zarrStore.channelCount, 7)).fill(void 0), s.meta && s.meta.physicalSizes) {
346
- const { x: d, y: v, z: f } = s.meta.physicalSizes, x = f?.size || 1, _ = v?.size || 1, y = d?.size || 1;
347
- this.zarrStore.physicalSizeVoxel = [x, _, y], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
354
+ const { x: d, y: m, z: h } = s.meta.physicalSizes, x = h?.size || 1, b = m?.size || 1, R = d?.size || 1;
355
+ this.zarrStore.physicalSizeVoxel = [x, b, R], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
348
356
  (s.shape[2] || 1) * x,
349
- (s.shape[3] || 1) * _,
350
- (s.shape[4] || 1) * y
357
+ (s.shape[3] || 1) * b,
358
+ (s.shape[4] || 1) * R
351
359
  ]);
352
360
  } else
353
361
  this.zarrStore.physicalSizeVoxel = [1, 1, 1], this.zarrStore.physicalSizeTotal = [
@@ -355,45 +363,45 @@ class We {
355
363
  s.shape[3] || 1,
356
364
  s.shape[4] || 1
357
365
  ];
358
- const { multiscales: g } = this.ngffMetadata;
359
- if (!g)
366
+ const { multiscales: v } = this.ngffMetadata;
367
+ if (!v)
360
368
  throw new Error("Expected multiscales metadata in group.attrs");
361
- if (g?.[0]?.datasets?.[0]?.coordinateTransformations) {
369
+ if (v?.[0]?.datasets?.[0]?.coordinateTransformations) {
362
370
  for (let d = 0; d < r; d++)
363
- if (g?.[0]?.datasets?.[d]?.coordinateTransformations?.[0]?.scale) {
364
- const { scale: v } = g[0].datasets[d].coordinateTransformations[0];
365
- c[d] = [v[4], v[3], v[2]];
371
+ if (v?.[0]?.datasets?.[d]?.coordinateTransformations?.[0]?.scale) {
372
+ const { scale: m } = v[0].datasets[d].coordinateTransformations[0];
373
+ u[d] = [m[4], m[3], m[2]];
366
374
  }
367
375
  } else {
368
376
  n.error("no coordinateTransformations available, assuming downsampling ratio of 2 per dimension");
369
377
  for (let d = 0; d < r; d++) {
370
- const v = 2 ** d;
371
- c[d] = [v, v, v];
378
+ const m = 2 ** d;
379
+ u[d] = [m, m, m];
372
380
  }
373
381
  }
374
- this.zarrStore.scales = c;
375
- const { coordinateTransformations: p } = this.ngffMetadata;
376
- if (p?.[0]?.scale) {
377
- const { scale: d } = p[0], v = d.length;
378
- if (v >= 3) {
379
- const f = d[v - 3], x = d[v - 2], _ = d[v - 1];
380
- this.zarrStore.physicalSizeVoxel = [f, x, _], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
381
- (s.shape[2] || 1) * f,
382
+ this.zarrStore.scales = u;
383
+ const { coordinateTransformations: g } = this.ngffMetadata;
384
+ if (g?.[0]?.scale) {
385
+ const { scale: d } = g[0], m = d.length;
386
+ if (m >= 3) {
387
+ const h = d[m - 3], x = d[m - 2], b = d[m - 1];
388
+ this.zarrStore.physicalSizeVoxel = [h, x, b], s.shape && s.shape.length >= 5 && (this.zarrStore.physicalSizeTotal = [
389
+ (s.shape[2] || 1) * h,
382
390
  (s.shape[3] || 1) * x,
383
- (s.shape[4] || 1) * _
391
+ (s.shape[4] || 1) * b
384
392
  ]);
385
393
  }
386
394
  }
387
395
  this.zarrStore.brickLayout = Xe(e.getMultiResolutionStats()), n.debug("config", t);
388
- const { omero: u } = this.ngffMetadata || {};
389
- if (!u)
396
+ const { omero: c } = this.ngffMetadata || {};
397
+ if (!c)
390
398
  throw new Error("Expected omero metadata in ngffMetadata");
391
- n.debug("omero", u), Object.keys(t).forEach((d, v) => {
392
- const f = t[d].spatialTargetC;
393
- this.channels.zarrMappings[v] = f, this.channels.colorMappings[v] = v, this.channels.downsampleMin[v] = u?.channels?.[f]?.window?.min || 0, this.channels.downsampleMax[v] = u?.channels?.[f]?.window?.max || 65535;
399
+ n.debug("omero", c), Object.keys(t).forEach((d, m) => {
400
+ const h = t[d].spatialTargetC;
401
+ this.channels.zarrMappings[m] = h, this.channels.colorMappings[m] = m, this.channels.downsampleMin[m] = c?.channels?.[h]?.window?.min || 0, this.channels.downsampleMax[m] = c?.channels?.[h]?.window?.max || 65535;
394
402
  }), n.debug("zarrMappings after init", this.channels.zarrMappings), n.debug("colorMappings after init", this.channels.colorMappings), n.debug("downsampleMin after init", this.channels.downsampleMin), n.debug("downsampleMax after init", this.channels.downsampleMax), this.initMRMCPT();
395
403
  }
396
- return this.initStatus = F.COMPLETE, z("INIT() COMPLETE"), {
404
+ return this.initStatus = V.COMPLETE, z("INIT() COMPLETE"), {
397
405
  success: !0,
398
406
  deviceLimits: this.deviceLimits,
399
407
  zarrStore: this.zarrStore,
@@ -403,7 +411,7 @@ class We {
403
411
  error: null
404
412
  };
405
413
  } catch (e) {
406
- return z("INIT() FAILED"), n.error("Error initializing VolumeDataManager:", e), this.initStatus = F.FAILED, this.initError = e.message || "Unknown error", {
414
+ return z("INIT() FAILED"), n.error("Error initializing VolumeDataManager:", e), this.initStatus = V.FAILED, this.initError = e.message || "Unknown error", {
407
415
  success: !1,
408
416
  error: this.initError
409
417
  };
@@ -434,37 +442,37 @@ class We {
434
442
  n.debug("channels not initialized yet");
435
443
  return;
436
444
  }
437
- const e = Object.values(t).map((l) => l.spatialTargetC).filter((l) => l !== void 0), i = this.channels.zarrMappings.filter((l) => l !== void 0), a = [...new Set(e)].sort((l, c) => l - c), r = [...new Set(i)].sort((l, c) => l - c);
438
- a.length === r.length && a.every((l, c) => l === r[c]) && n.debug("Channel mappings unchanged, skipping update"), n.debug("Channel mappings changed:", {
445
+ const e = Object.values(t).map((l) => l.spatialTargetC).filter((l) => l !== void 0), i = this.channels.zarrMappings.filter((l) => l !== void 0), a = [...new Set(e)].sort((l, u) => l - u), r = [...new Set(i)].sort((l, u) => l - u);
446
+ a.length === r.length && a.every((l, u) => l === r[u]) && n.debug("Channel mappings unchanged, skipping update"), n.debug("Channel mappings changed:", {
439
447
  current: r,
440
448
  requested: a
441
- }), Object.entries(t).forEach(([l, c]) => {
442
- const s = c.spatialTargetC;
449
+ }), Object.entries(t).forEach(([l, u]) => {
450
+ const s = u.spatialTargetC;
443
451
  n.debug(`UI channel "${l}" wants zarr channel ${s}`);
444
- const g = this.channels.zarrMappings.indexOf(s);
445
- if (g === -1) {
446
- const p = this.channels.zarrMappings.findIndex((u) => u === void 0);
447
- if (p !== -1)
448
- this.channels.zarrMappings[p] = s, n.debug("channelData", c), n.debug("this.ngffMetadata?.omero?.channels", this.ngffMetadata?.omero?.channels), n.debug("targetZarrChannel", s), this.channels.downsampleMin[p] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[p] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, n.debug(`Mapped zarr channel ${s} to slot ${p}`), n.debug("channels", this.channels);
452
+ const v = this.channels.zarrMappings.indexOf(s);
453
+ if (v === -1) {
454
+ const g = this.channels.zarrMappings.findIndex((c) => c === void 0);
455
+ if (g !== -1)
456
+ this.channels.zarrMappings[g] = s, n.debug("channelData", u), n.debug("this.ngffMetadata?.omero?.channels", this.ngffMetadata?.omero?.channels), n.debug("targetZarrChannel", s), this.channels.downsampleMin[g] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[g] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, n.debug(`Mapped zarr channel ${s} to slot ${g}`), n.debug("channels", this.channels);
449
457
  else {
450
458
  n.debug("No free slots found, looking for unused mapped channels");
451
- const u = this.channels.zarrMappings.filter((f) => f !== void 0), d = e, v = u.filter((f) => !d.includes(f));
452
- if (n.debug("Currently mapped:", u), n.debug("Still requested:", d), n.debug("Unused mapped channels:", v), v.length > 0) {
453
- const f = this.channels.zarrMappings.findIndex((x) => v.includes(x));
454
- if (f !== -1) {
455
- const x = this.channels.zarrMappings[f];
456
- this.channels.zarrMappings[f] = s, this.channels.downsampleMin[f] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[f] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, n.debug(`Reused slot ${f}: ${x} -> ${s}`), this._purgeChannel(f);
459
+ const c = this.channels.zarrMappings.filter((h) => h !== void 0), d = e, m = c.filter((h) => !d.includes(h));
460
+ if (n.debug("Currently mapped:", c), n.debug("Still requested:", d), n.debug("Unused mapped channels:", m), m.length > 0) {
461
+ const h = this.channels.zarrMappings.findIndex((x) => m.includes(x));
462
+ if (h !== -1) {
463
+ const x = this.channels.zarrMappings[h];
464
+ this.channels.zarrMappings[h] = s, this.channels.downsampleMin[h] = this.ngffMetadata?.omero?.channels?.[s]?.window?.min || 0, this.channels.downsampleMax[h] = this.ngffMetadata?.omero?.channels?.[s]?.window?.max || 65535, n.debug(`Reused slot ${h}: ${x} -> ${s}`), this._purgeChannel(h);
457
465
  } else
458
466
  n.error("Could not find slot to reuse - this should not happen");
459
467
  } else
460
468
  n.error("All slots are full and all mapped channels are still in use");
461
469
  }
462
470
  } else
463
- n.debug(`Zarr channel ${s} already mapped to slot ${g}`);
471
+ n.debug(`Zarr channel ${s} already mapped to slot ${v}`);
464
472
  });
465
473
  const o = Object.values(t).map((l) => {
466
- const c = this.channels.zarrMappings.indexOf(l.spatialTargetC);
467
- return c !== -1 ? c : -1;
474
+ const u = this.channels.zarrMappings.indexOf(l.spatialTargetC);
475
+ return u !== -1 ? u : -1;
468
476
  });
469
477
  for (; o.length < 7; )
470
478
  o.push(-1);
@@ -567,14 +575,26 @@ class We {
567
575
  if (!this.zarrStore || !this.zarrStore.arrays[o])
568
576
  throw new Error("Zarr store or resolution not initialized");
569
577
  n.debug("loadZarrChunk", { t, c: e, z: i, y: a, x: r, resolution: o });
570
- const c = await this.zarrStore.arrays[o].getChunk([t, e, i, a, r]);
571
- if (!c)
578
+ const u = await this.zarrStore.arrays[o].getChunk([t, e, i, a, r]);
579
+ if (!u)
572
580
  throw new Error(`No chunk found at coordinates [${t},${e},${i},${a},${r}]`);
573
- if (c.data.length !== S * S * S)
574
- throw new Error(`Unexpected chunk size: ${c.data.length}`);
575
- return c.data;
581
+ if (u.data.length !== S * S * S)
582
+ throw new Error(`Unexpected chunk size: ${u.data.length}`);
583
+ return u.data;
576
584
  }
577
- async processRequestData(t) {
585
+ /**
586
+ * Process the buffer of brick requests from the shader, turning them into
587
+ * actual Promises for Zarr chunks on the JS side.
588
+ * @param {Uint8Array} buffer The bufRequest (of length width*height*4)
589
+ * containing the brick requests from the shader.
590
+ * @param {object} optsForWeighting
591
+ * @param {number} optsForWeighting.width The width of the render target.
592
+ * @param {number} optsForWeighting.height The height of the render target.
593
+ * @param {number} optsForWeighting.sigmaNormalized The normalized sigma value
594
+ * to use for weighting the brick requests based on their distance from
595
+ * the center of the render target.
596
+ */
597
+ async processRequestData(t, e) {
578
598
  if (this.isBusy) {
579
599
  n.debug("processRequestData: already busy, skipping");
580
600
  return;
@@ -588,8 +608,8 @@ class We {
588
608
  return;
589
609
  }
590
610
  this.isBusy = !0, this.triggerRequest = !1;
591
- const { requests: e, origRequestCount: i } = Ke(t, this.k);
592
- e.length === 0 && (this.noNewRequests = !0), n.debug(`processRequestData: handling ${e.length} requests of ${i}`), await this.handleBrickRequests(e), this.triggerUsage = !0, this.isBusy = !1;
611
+ const { requests: i, origRequestCount: a } = We(t, this.k, e);
612
+ i.length === 0 && (this.noNewRequests = !0), n.debug(`processRequestData: handling ${i.length} requests of ${a}`), await this.handleBrickRequests(i), this.triggerUsage = !0, this.isBusy = !1;
593
613
  }
594
614
  async processUsageData(t) {
595
615
  if (this.isBusy) {
@@ -606,8 +626,8 @@ class We {
606
626
  const r = t[a], o = t[a + 1], l = t[a + 2];
607
627
  if ((r | o | l) === 0)
608
628
  continue;
609
- const c = l * A * V + o * A + r;
610
- c < this.BCTimeStamps.length && i.add(c);
629
+ const u = l * B * G + o * B + r;
630
+ u < this.BCTimeStamps.length && i.add(u);
611
631
  }
612
632
  Array.from(i).forEach((a) => {
613
633
  this.BCTimeStamps[a] = e;
@@ -642,8 +662,8 @@ class We {
642
662
  this.PT.anchors[r][0] * e[0]
643
663
  ];
644
664
  n.debug("anchor", o);
645
- const l = this.zarrStore.brickLayout[r], c = l[0] * l[1] * l[2];
646
- n.debug("extents", l), n.debug("size", c), i.texSubImage3D(i.TEXTURE_3D, 0, o[0], o[1], o[2], l[0], l[1], l[2], i.RED_INTEGER, i.UNSIGNED_INT, new Uint32Array(c));
665
+ const l = this.zarrStore.brickLayout[r], u = l[0] * l[1] * l[2];
666
+ n.debug("extents", l), n.debug("size", u), i.texSubImage3D(i.TEXTURE_3D, 0, o[0], o[1], o[2], l[0], l[1], l[2], i.RED_INTEGER, i.UNSIGNED_INT, new Uint32Array(u));
647
667
  }
648
668
  i.bindTexture(i.TEXTURE_3D, null);
649
669
  }
@@ -668,17 +688,17 @@ class We {
668
688
  */
669
689
  _allocateBCSlots(t) {
670
690
  let e = [];
671
- const i = A * V * ce;
691
+ const i = B * G * ce;
672
692
  if (!this.BCFull && this.BCUnusedIndex + t > i && (this.BCFull = !0, n.debug("BRICK CACHE FULL")), this.BCFull)
673
693
  this.LRUStack.length < t && this._buildLRU(), e = this.LRUStack.splice(0, t).map((a) => {
674
694
  this._evictBrick(a);
675
- const r = Math.floor(a / (A * V)), o = a - r * A * V, l = Math.floor(o / A), c = o % A;
676
- return { bcIndex: a, x: c, y: l, z: r };
695
+ const r = Math.floor(a / (B * G)), o = a - r * B * G, l = Math.floor(o / B), u = o % B;
696
+ return { bcIndex: a, x: u, y: l, z: r };
677
697
  });
678
698
  else {
679
699
  for (let a = 0; a < t; ++a) {
680
- const r = (this.BCUnusedIndex + a) % i, o = Math.floor(r / (A * V)), l = r - o * A * V, c = Math.floor(l / A), s = l % A;
681
- e.push({ bcIndex: r, x: s, y: c, z: o });
700
+ const r = (this.BCUnusedIndex + a) % i, o = Math.floor(r / (B * G)), l = r - o * B * G, u = Math.floor(l / B), s = l % B;
701
+ e.push({ bcIndex: r, x: s, y: u, z: o });
682
702
  }
683
703
  this.BCUnusedIndex += t;
684
704
  }
@@ -705,18 +725,18 @@ class We {
705
725
  n.error("Channel index out of bounds", { channel: i, mappingsLength: this.channels.zarrMappings.length });
706
726
  return;
707
727
  }
708
- const c = this.channels.zarrMappings[i];
709
- if (c === void 0 || c === -1)
728
+ const u = this.channels.zarrMappings[i];
729
+ if (u === void 0 || u === -1)
710
730
  if (n.warn("zarrChannel is undefined or -1", {
711
- zarrChannel: c,
731
+ zarrChannel: u,
712
732
  channel: i,
713
733
  ptCoord: t,
714
734
  channelMappings: this.channels.zarrMappings,
715
735
  contextLost: this.isContextLost()
716
736
  }), this._lastChannelConfig && this._lastChannelConfig.zarrMappings[i] !== void 0) {
717
737
  n.warn("Attempting to use last known channel config"), this.channels.zarrMappings = [...this._lastChannelConfig.zarrMappings], this.channels.colorMappings = [...this._lastChannelConfig.colorMappings], this.channels.downsampleMin = [...this._lastChannelConfig.downsampleMin], this.channels.downsampleMax = [...this._lastChannelConfig.downsampleMax];
718
- const y = this.channels.zarrMappings[i];
719
- if (y !== void 0 && y !== -1)
738
+ const R = this.channels.zarrMappings[i];
739
+ if (R !== void 0 && R !== -1)
720
740
  n.debug("Successfully restored channel mapping, continuing with upload");
721
741
  else {
722
742
  n.error("Could not restore valid channel mapping, aborting brick upload");
@@ -726,35 +746,35 @@ class We {
726
746
  n.error("No fallback channel config available, aborting brick upload");
727
747
  return;
728
748
  }
729
- n.debug("starting to load zarr chunk", { resolution: a, z: l, y: o, x: r, zarrChannel: c });
730
- let s = await this.loadZarrChunk(0, c, l, o, r, a);
749
+ n.debug("starting to load zarr chunk", { resolution: a, z: l, y: o, x: r, zarrChannel: u });
750
+ let s = await this.loadZarrChunk(0, u, l, o, r, a);
731
751
  if (n.debug("chunk", s), s instanceof Uint16Array) {
732
752
  if (n.debug("chunk is Uint16Array, converting to Uint8Array"), this.channels.downsampleMin[i] === void 0) {
733
753
  const T = this.channels.zarrMappings[i];
734
754
  n.debug("channelId was not found in this.channels.downsampleMin[channel]", T), this.channels.downsampleMin[i] = this.ngffMetadata?.omero?.channels?.[T]?.window?.min || 0, this.channels.downsampleMax[i] = this.ngffMetadata?.omero?.channels?.[T]?.window?.max || 65535, n.debug("this.channels.downsampleMin[channel]", this.channels.downsampleMin[i]), n.debug("this.channels.downsampleMax[channel]", this.channels.downsampleMax[i]);
735
755
  }
736
- const y = new Uint16Array(s.buffer), E = new Uint8Array(s.length), L = this.channels.downsampleMin[i], G = this.channels.downsampleMax[i], j = G - L;
737
- for (let T = 0; T < y.length; T++) {
738
- const U = y[T], N = Math.max(L, Math.min(G, U));
739
- E[T] = (N - L) * 255 / j | 0;
756
+ const R = new Uint16Array(s.buffer), E = new Uint8Array(s.length), k = this.channels.downsampleMin[i], O = this.channels.downsampleMax[i], X = O - k;
757
+ for (let T = 0; T < R.length; T++) {
758
+ const L = R[T], U = Math.max(k, Math.min(O, L));
759
+ E[T] = (U - k) * 255 / X | 0;
740
760
  }
741
761
  s = E;
742
762
  }
743
763
  if (!(s instanceof Uint8Array))
744
764
  throw new Error(`Unsupported chunk type: ${s.constructor.name}. Expected Uint8Array.`);
745
- let g = 255, p = 0;
746
- for (let y = 0; y < s.length; ++y) {
747
- const E = s[y];
748
- E < g && (g = E), E > p && (p = E);
765
+ let v = 255, g = 0;
766
+ for (let R = 0; R < s.length; ++R) {
767
+ const E = s[R];
768
+ E < v && (v = E), E > g && (g = E);
749
769
  }
750
- const { gl: u } = this, d = this.renderer.properties.get(this.bcTHREE).__webglTexture;
751
- u.activeTexture(u.TEXTURE2), u.bindTexture(u.TEXTURE_3D, d), u.pixelStorei(u.UNPACK_ALIGNMENT, 1), u.texSubImage3D(u.TEXTURE_3D, 0, e.x * S, e.y * S, e.z * S, S, S, S, u.RED, u.UNSIGNED_BYTE, s), u.pixelStorei(u.UNPACK_ALIGNMENT, 4), u.bindTexture(u.TEXTURE_3D, null);
752
- const v = u.getError();
753
- v !== u.NO_ERROR && n.error("WebGL error during brick upload:", v, s), i >= this.channels.zarrMappings.length && (n.debug("channel is out of bounds", i), g = 255, p = 255);
754
- const f = Ye(g, p, e.x, e.y, e.z), x = this.renderer.properties.get(this.ptTHREE).__webglTexture;
755
- u.activeTexture(u.TEXTURE0), u.bindTexture(u.TEXTURE_3D, x), u.texSubImage3D(u.TEXTURE_3D, 0, t.x, t.y, t.z, 1, 1, 1, u.RED_INTEGER, u.UNSIGNED_INT, new Uint32Array([f])), u.bindTexture(u.TEXTURE_3D, null);
756
- const _ = u.getError();
757
- _ !== u.NO_ERROR && n.error("WebGL error during pagetable upload:", _, s), this.BCTimeStamps[e.bcIndex] = this.timeStamp, this.BCMinMax[e.bcIndex] = [g, p], this.bc2pt[e.bcIndex] = t;
770
+ const { gl: c } = this, d = this.renderer.properties.get(this.bcTHREE).__webglTexture;
771
+ c.activeTexture(c.TEXTURE2), c.bindTexture(c.TEXTURE_3D, d), c.pixelStorei(c.UNPACK_ALIGNMENT, 1), c.texSubImage3D(c.TEXTURE_3D, 0, e.x * S, e.y * S, e.z * S, S, S, S, c.RED, c.UNSIGNED_BYTE, s), c.pixelStorei(c.UNPACK_ALIGNMENT, 4), c.bindTexture(c.TEXTURE_3D, null);
772
+ const m = c.getError();
773
+ m !== c.NO_ERROR && n.error("WebGL error during brick upload:", m, s), i >= this.channels.zarrMappings.length && (n.debug("channel is out of bounds", i), v = 255, g = 255);
774
+ const h = Ye(v, g, e.x, e.y, e.z), x = this.renderer.properties.get(this.ptTHREE).__webglTexture;
775
+ c.activeTexture(c.TEXTURE0), c.bindTexture(c.TEXTURE_3D, x), c.texSubImage3D(c.TEXTURE_3D, 0, t.x, t.y, t.z, 1, 1, 1, c.RED_INTEGER, c.UNSIGNED_INT, new Uint32Array([h])), c.bindTexture(c.TEXTURE_3D, null);
776
+ const b = c.getError();
777
+ b !== c.NO_ERROR && n.error("WebGL error during pagetable upload:", b, s), this.BCTimeStamps[e.bcIndex] = this.timeStamp, this.BCMinMax[e.bcIndex] = [v, g], this.bc2pt[e.bcIndex] = t;
758
778
  }
759
779
  /* ------------------------------------------------------------- *
760
780
  * 5. Public: handle a batch of PT requests (array of {x,y,z}) *
@@ -783,7 +803,7 @@ class We {
783
803
  this.LRUStack = t.sort((e, i) => e.time - i.time).slice(0, this.k).map((e) => e.index);
784
804
  }
785
805
  }
786
- const $e = `//
806
+ const Qe = `//
787
807
  // Output: Unnormalized ray direction from camera to each vertex
788
808
  // Used by fragment shader for ray marching through the volume
789
809
  out vec3 rayDirUnnorm;
@@ -842,7 +862,7 @@ void main()
842
862
  // Pass through texture coordinates for volume sampling
843
863
  vUv = uv;
844
864
  }
845
- `, Qe = `//
865
+ `, Je = `//
846
866
  // #include <packing>
847
867
  precision highp float;
848
868
  precision highp int;
@@ -2407,21 +2427,21 @@ void main(void) {
2407
2427
  outColor.a);
2408
2428
 
2409
2429
  }
2410
- `, Je = {
2430
+ `, et = {
2411
2431
  uniforms: {
2412
2432
  u_size: { value: new C(1, 1, 1) },
2413
- clim0: { value: new b(0.2, 0.8) },
2414
- clim1: { value: new b(0.2, 0.8) },
2415
- clim2: { value: new b(0.2, 0.8) },
2416
- clim3: { value: new b(0.2, 0.8) },
2417
- clim4: { value: new b(0.2, 0.8) },
2418
- clim5: { value: new b(0.2, 0.8) },
2419
- clim6: { value: new b(0.2, 0.8) },
2420
- clim7: { value: new b(0.2, 0.8) },
2421
- xClip: { value: new b(0, 1e6) },
2422
- yClip: { value: new b(0, 1e6) },
2423
- zClip: { value: new b(0, 1e6) },
2424
- u_window_size: { value: new b(1, 1) },
2433
+ clim0: { value: new _(0.2, 0.8) },
2434
+ clim1: { value: new _(0.2, 0.8) },
2435
+ clim2: { value: new _(0.2, 0.8) },
2436
+ clim3: { value: new _(0.2, 0.8) },
2437
+ clim4: { value: new _(0.2, 0.8) },
2438
+ clim5: { value: new _(0.2, 0.8) },
2439
+ clim6: { value: new _(0.2, 0.8) },
2440
+ clim7: { value: new _(0.2, 0.8) },
2441
+ xClip: { value: new _(0, 1e6) },
2442
+ yClip: { value: new _(0, 1e6) },
2443
+ zClip: { value: new _(0, 1e6) },
2444
+ u_window_size: { value: new _(1, 1) },
2425
2445
  u_vol_scale: { value: new C(1, 1, 1) },
2426
2446
  // Set renderstyle to 3 or 4 for debugging modes
2427
2447
  u_renderstyle: { value: 2 },
@@ -2437,14 +2457,14 @@ void main(void) {
2437
2457
  channelMapping: {
2438
2458
  value: [-1, -1, -1, -1, -1, -1, -1]
2439
2459
  },
2440
- resGlobal: { value: new b(0, 9) },
2441
- res0: { value: new b(0, 9) },
2442
- res1: { value: new b(0, 9) },
2443
- res2: { value: new b(0, 9) },
2444
- res3: { value: new b(0, 9) },
2445
- res4: { value: new b(0, 9) },
2446
- res5: { value: new b(0, 9) },
2447
- res6: { value: new b(0, 9) },
2460
+ resGlobal: { value: new _(0, 9) },
2461
+ res0: { value: new _(0, 9) },
2462
+ res1: { value: new _(0, 9) },
2463
+ res2: { value: new _(0, 9) },
2464
+ res3: { value: new _(0, 9) },
2465
+ res4: { value: new _(0, 9) },
2466
+ res5: { value: new _(0, 9) },
2467
+ res6: { value: new _(0, 9) },
2448
2468
  maxChannels: { value: 0 },
2449
2469
  lodFactor: { value: 1 },
2450
2470
  near: { value: 0.1 },
@@ -2475,24 +2495,24 @@ void main(void) {
2475
2495
  scale8: { value: new C(256, 256, 256) },
2476
2496
  scale9: { value: new C(512, 512, 512) }
2477
2497
  },
2478
- vertexShader: $e,
2479
- fragmentShader: Qe
2498
+ vertexShader: Qe,
2499
+ fragmentShader: Je
2480
2500
  };
2481
- function P(h) {
2482
- se(le.DEBUG) && console.warn(`%cRM: ${h}`, "background: orange; color: white; padding: 2px; border-radius: 3px;");
2501
+ function A(f) {
2502
+ se(le.DEBUG) && console.warn(`%cRM: ${f}`, "background: orange; color: white; padding: 2px; border-radius: 3px;");
2483
2503
  }
2484
- function ne(h, t) {
2485
- return h / t[1];
2504
+ function ne(f, t) {
2505
+ return f / t[1];
2486
2506
  }
2487
- class et {
2507
+ class tt {
2488
2508
  constructor() {
2489
- P("Initializing VolumeRenderManager"), this.uniforms = null, this.shader = null, this.meshScale = [1, 1, 1], this.geometrySize = [1, 1, 1], this.boxSize = [1, 1, 1], this.zarrInit = !1, this.channelsVisible = [], this.channelTargetC = [], this.zarrStoreNumResolutions = null, this.channelMaxResolutionIndex = [], this.colors = [], this.contrastLimits = [], this.layerTransparency = 1, this.xSlice = new b(-1, 1e5), this.ySlice = new b(-1, 1e5), this.zSlice = new b(-1, 1e5), this.originalScale = [1, 1, 1], this.physicalDimensions = [1, 1, 1], this.maxResolution = [1, 1, 1], this.maxRange = 255, this.maxRangeSet = !1, this.initializeShader();
2509
+ A("Initializing VolumeRenderManager"), this.uniforms = null, this.shader = null, this.meshScale = [1, 1, 1], this.geometrySize = [1, 1, 1], this.boxSize = [1, 1, 1], this.zarrInit = !1, this.channelsVisible = [], this.channelTargetC = [], this.zarrStoreNumResolutions = null, this.channelMaxResolutionIndex = [], this.colors = [], this.contrastLimits = [], this.layerTransparency = 1, this.xSlice = new _(-1, 1e5), this.ySlice = new _(-1, 1e5), this.zSlice = new _(-1, 1e5), this.originalScale = [1, 1, 1], this.physicalDimensions = [1, 1, 1], this.maxResolution = [1, 1, 1], this.maxRange = 255, this.maxRangeSet = !1, this.initializeShader();
2490
2510
  }
2491
2511
  /**
2492
2512
  * Initialize shader and uniform objects
2493
2513
  */
2494
2514
  initializeShader() {
2495
- P("Initializing shader"), this.shader = Je, this.uniforms = De.clone(this.shader.uniforms);
2515
+ A("Initializing shader"), this.shader = et, this.uniforms = De.clone(this.shader.uniforms);
2496
2516
  }
2497
2517
  /**
2498
2518
  * Extract rendering settings from coordination props
@@ -2500,61 +2520,61 @@ class et {
2500
2520
  * @returns {Object} Extracted rendering settings
2501
2521
  */
2502
2522
  extractRenderingSettingsFromProps(t) {
2503
- const { images: e = {}, imageLayerScopes: i = [], imageLayerCoordination: a = [{}], imageChannelScopesByLayer: r = {}, imageChannelCoordination: o = [{}], spatialRenderingMode: l } = t, c = i[0];
2504
- if (!c)
2505
- return P("Extracting rendering settings from props - no layer scope"), {
2523
+ const { images: e = {}, imageLayerScopes: i = [], imageLayerCoordination: a = [{}], imageChannelScopesByLayer: r = {}, imageChannelCoordination: o = [{}], spatialRenderingMode: l } = t, u = i[0];
2524
+ if (!u)
2525
+ return A("Extracting rendering settings from props - no layer scope"), {
2506
2526
  valid: !1
2507
2527
  };
2508
- const s = r[c], g = a[0][c], p = o[0][c], u = e[c]?.image?.instance?.getData();
2509
- if (!u)
2510
- return P("Extracting rendering settings from props - no image data"), {
2528
+ const s = r[u], v = a[0][u], g = o[0][u], c = e[u]?.image?.instance?.getData();
2529
+ if (!c)
2530
+ return A("Extracting rendering settings from props - no image data"), {
2511
2531
  valid: !1
2512
2532
  };
2513
- if (!p[s?.[0]][D.SPATIAL_CHANNEL_WINDOW])
2514
- return P("Extracting rendering settings from props - no channel window set"), {
2533
+ if (!g[s?.[0]][M.SPATIAL_CHANNEL_WINDOW])
2534
+ return A("Extracting rendering settings from props - no channel window set"), {
2515
2535
  valid: !1
2516
2536
  };
2517
- const d = e[c].image.instance, v = l === "3D", f = g[D.PHOTOMETRIC_INTERPRETATION] === "RGB", x = g[D.SPATIAL_LAYER_VISIBLE], _ = g[D.SPATIAL_LAYER_OPACITY], y = f ? [
2537
+ const d = e[u].image.instance, m = l === "3D", h = v[M.PHOTOMETRIC_INTERPRETATION] === "RGB", x = v[M.SPATIAL_LAYER_VISIBLE], b = v[M.SPATIAL_LAYER_OPACITY], R = h ? [
2518
2538
  [255, 0, 0],
2519
2539
  [0, 255, 0],
2520
2540
  [0, 0, 255]
2521
- ] : s.map((k) => p[k][D.SPATIAL_CHANNEL_COLOR]), E = f ? [
2541
+ ] : s.map((I) => g[I][M.SPATIAL_CHANNEL_COLOR]), E = h ? [
2522
2542
  [0, 255],
2523
2543
  [0, 255],
2524
2544
  [0, 255]
2525
- ] : s.map((k) => p[k][D.SPATIAL_CHANNEL_WINDOW] || [0, 255]);
2526
- this.maxRangeSet || (this.maxRange = Math.max(...E.map((k) => k[1])), this.maxRangeSet = !0);
2527
- const L = f ? [
2545
+ ] : s.map((I) => g[I][M.SPATIAL_CHANNEL_WINDOW] || [0, 255]);
2546
+ this.maxRangeSet || (this.maxRange = Math.max(...E.map((I) => I[1])), this.maxRangeSet = !0);
2547
+ const k = h ? [
2528
2548
  x && !0,
2529
2549
  x && !0,
2530
2550
  x && !0
2531
- ] : s.map((k) => x && p[k][D.SPATIAL_CHANNEL_VISIBLE]), G = f ? [
2551
+ ] : s.map((I) => x && g[I][M.SPATIAL_CHANNEL_VISIBLE]), O = h ? [
2532
2552
  x && !0,
2533
2553
  x && !0,
2534
2554
  x && !0
2535
- ] : s.map((k) => x && d.getChannelIndex(p[k][D.SPATIAL_TARGET_C])), j = f ? [
2555
+ ] : s.map((I) => x && d.getChannelIndex(g[I][M.SPATIAL_TARGET_C])), X = h ? [
2536
2556
  x && null,
2537
2557
  x && null,
2538
2558
  x && null
2539
- ] : s.map((k) => p[k][D.SPATIAL_MAX_RESOLUTION]);
2540
- let T = g[D.SPATIAL_SLICE_X], U = g[D.SPATIAL_SLICE_Y], N = g[D.SPATIAL_SLICE_Z];
2541
- const Y = g[D.SPATIAL_LOD_FACTOR] ?? 1;
2542
- T = T !== null ? T : new b(-1, 1e5), U = U !== null ? U : new b(-1, 1e5), N = N !== null ? N : new b(-1, 1e5);
2543
- const ie = e[c].image.loaders[0].channels;
2544
- return P("Extracting rendering settings from props - success"), {
2559
+ ] : s.map((I) => g[I][M.SPATIAL_MAX_RESOLUTION]);
2560
+ let T = v[M.SPATIAL_SLICE_X], L = v[M.SPATIAL_SLICE_Y], U = v[M.SPATIAL_SLICE_Z];
2561
+ const Y = v[M.SPATIAL_LOD_FACTOR] ?? 1;
2562
+ T = T !== null ? T : new _(-1, 1e5), L = L !== null ? L : new _(-1, 1e5), U = U !== null ? U : new _(-1, 1e5);
2563
+ const ie = e[u].image.loaders[0].channels;
2564
+ return A("Extracting rendering settings from props - success"), {
2545
2565
  valid: !0,
2546
- channelsVisible: L,
2566
+ channelsVisible: k,
2547
2567
  allChannels: ie,
2548
- channelTargetC: G,
2549
- channelMaxResolutionIndex: j,
2550
- data: u,
2551
- colors: y,
2568
+ channelTargetC: O,
2569
+ channelMaxResolutionIndex: X,
2570
+ data: c,
2571
+ colors: R,
2552
2572
  contrastLimits: E,
2553
- is3dMode: v,
2554
- layerTransparency: _,
2573
+ is3dMode: m,
2574
+ layerTransparency: b,
2555
2575
  xSlice: T,
2556
- ySlice: U,
2557
- zSlice: N,
2576
+ ySlice: L,
2577
+ zSlice: U,
2558
2578
  lodFactor: Y
2559
2579
  };
2560
2580
  }
@@ -2565,60 +2585,60 @@ class et {
2565
2585
  */
2566
2586
  updateFromProps(t) {
2567
2587
  const e = this.extractRenderingSettingsFromProps(t);
2568
- return e.valid ? (this.channelsVisible = e.channelsVisible, this.channelTargetC = e.channelTargetC, this.channelMaxResolutionIndex = e.channelMaxResolutionIndex, this.colors = e.colors, this.contrastLimits = e.contrastLimits, this.renderingMode = e.renderingMode, this.layerTransparency = e.layerTransparency, this.xSlice = e.xSlice, this.ySlice = e.ySlice, this.zSlice = e.zSlice, this.uniforms.lodFactor.value = e.lodFactor, P(`lodFactor ${e.lodFactor}`), this.shader.uniforms.lodFactor.value = e.lodFactor, P("Updating from props - success"), !0) : (P("Updating from props - invalid settings"), !1);
2588
+ return e.valid ? (this.channelsVisible = e.channelsVisible, this.channelTargetC = e.channelTargetC, this.channelMaxResolutionIndex = e.channelMaxResolutionIndex, this.colors = e.colors, this.contrastLimits = e.contrastLimits, this.renderingMode = e.renderingMode, this.layerTransparency = e.layerTransparency, this.xSlice = e.xSlice, this.ySlice = e.ySlice, this.zSlice = e.zSlice, this.uniforms.lodFactor.value = e.lodFactor, A(`lodFactor ${e.lodFactor}`), this.shader.uniforms.lodFactor.value = e.lodFactor, A("Updating from props - success"), !0) : (A("Updating from props - invalid settings"), !1);
2569
2589
  }
2570
2590
  /**
2571
2591
  * Update the rendering based on the current volume data from the data manager
2572
2592
  * @param {object} volumeDataManagerProps - Params derived from the volume data manager
2573
2593
  * @returns {Object|null} Updated rendering settings or null if rendering is not possible
2574
2594
  */
2575
- updateRendering({ zarrStoreShapes: t, originalScaleXYZ: e, physicalDimensionsXYZ: i, maxResolutionXYZ: a, boxDimensionsXYZ: r, normalizedScaleXYZ: o, bcTHREE: l, ptTHREE: c }) {
2576
- if (P("Updating rendering"), this.channelTargetC.findIndex((v, f) => this.channelsVisible[f]), !Array.isArray(t) || t.length === 0)
2595
+ updateRendering({ zarrStoreShapes: t, originalScaleXYZ: e, physicalDimensionsXYZ: i, maxResolutionXYZ: a, boxDimensionsXYZ: r, normalizedScaleXYZ: o, bcTHREE: l, ptTHREE: u }) {
2596
+ if (A("Updating rendering"), this.channelTargetC.findIndex((m, h) => this.channelsVisible[h]), !Array.isArray(t) || t.length === 0)
2577
2597
  return null;
2578
- const s = t[0], g = {
2598
+ const s = t[0], v = {
2579
2599
  xLength: s[4] || 1,
2580
2600
  yLength: s[3] || 1,
2581
2601
  zLength: s[2] || 1
2582
- }, p = [], u = [], d = [];
2583
- if (this.channelTargetC.forEach((v, f) => {
2584
- this.channelsVisible[f];
2602
+ }, g = [], c = [], d = [];
2603
+ if (this.channelTargetC.forEach((m, h) => {
2604
+ this.channelsVisible[h];
2585
2605
  {
2586
- const _ = [0, this.maxRange ? this.maxRange : 255];
2587
- u.push([
2588
- this.colors[f][0] / 255,
2589
- this.colors[f][1] / 255,
2590
- this.colors[f][2] / 255,
2591
- this.channelsVisible[f] ? 1 : 0
2592
- ]), n.debug("colorsSave", u), this.contrastLimits[f][0] === 0 && this.contrastLimits[f][1] === 255 ? d.push([
2593
- ne(_[0], _),
2594
- ne(_[1], _)
2606
+ const b = [0, this.maxRange ? this.maxRange : 255];
2607
+ c.push([
2608
+ this.colors[h][0] / 255,
2609
+ this.colors[h][1] / 255,
2610
+ this.colors[h][2] / 255,
2611
+ this.channelsVisible[h] ? 1 : 0
2612
+ ]), n.debug("colorsSave", c), this.contrastLimits[h][0] === 0 && this.contrastLimits[h][1] === 255 ? d.push([
2613
+ ne(b[0], b),
2614
+ ne(b[1], b)
2595
2615
  ]) : d.push([
2596
- ne(this.contrastLimits[f][0], _),
2597
- ne(this.contrastLimits[f][1], _)
2616
+ ne(this.contrastLimits[h][0], b),
2617
+ ne(this.contrastLimits[h][1], b)
2598
2618
  ]);
2599
2619
  }
2600
2620
  }), !this.zarrInit) {
2601
2621
  this.originalScale = e, this.physicalDimensions = i, this.maxResolution = a;
2602
- const v = r;
2622
+ const m = r;
2603
2623
  this.normalizedScale = o, this.meshScale = [
2604
2624
  this.originalScale[0] / this.originalScale[0],
2605
2625
  this.originalScale[1] / this.originalScale[0],
2606
2626
  this.originalScale[2] / this.originalScale[0]
2607
- ], this.geometrySize = v, this.boxSize = v, n.debug("this.boxSize", this.boxSize), n.debug("this.geometrySize", this.geometrySize), n.debug("this.meshScale", this.meshScale), n.debug("this.originalScale", this.originalScale), n.debug("this.physicalDimensions", this.physicalDimensions), n.debug("this.maxResolution", this.maxResolution), n.debug("scaledResolution", v), this.zarrInit = !0;
2627
+ ], this.geometrySize = m, this.boxSize = m, n.debug("this.boxSize", this.boxSize), n.debug("this.geometrySize", this.geometrySize), n.debug("this.meshScale", this.meshScale), n.debug("this.originalScale", this.originalScale), n.debug("this.physicalDimensions", this.physicalDimensions), n.debug("this.maxResolution", this.maxResolution), n.debug("scaledResolution", m), this.zarrInit = !0;
2608
2628
  }
2609
2629
  return this.updateUniforms(
2610
- p,
2611
2630
  g,
2631
+ v,
2612
2632
  // Pass dimensions object instead of volume
2613
2633
  this.renderingMode,
2614
2634
  d,
2615
- u,
2635
+ c,
2616
2636
  this.layerTransparency,
2617
2637
  this.xSlice,
2618
2638
  this.ySlice,
2619
2639
  this.zSlice,
2620
2640
  l,
2621
- c
2641
+ u
2622
2642
  ), {
2623
2643
  uniforms: this.uniforms,
2624
2644
  shader: this.shader,
@@ -2639,10 +2659,10 @@ class et {
2639
2659
  * @param {Vector2} ySlice - Y clipping plane
2640
2660
  * @param {Vector2} zSlice - Z clipping plane
2641
2661
  */
2642
- updateUniforms(t, e, i, a, r, o, l, c, s, g, p) {
2643
- P("Updating uniforms"), this.uniforms.boxSize.value.set(this.boxSize[0], this.boxSize[1], this.boxSize[2]), this.uniforms.brickCacheTex.value = g, this.uniforms.pageTableTex.value = p, this.uniforms.near.value = 0.1, this.uniforms.far.value = 3e3, this.uniforms.opacity.value = o, this.uniforms.volumeCount.value = t.length, this.uniforms.u_size.value.set(e.xLength, e.yLength, e.zLength), this.uniforms.u_window_size.value.set(0, 0), this.uniforms.u_vol_scale.value.set(1 / e.xLength, 1 / e.yLength, 1 / e.zLength * 2), this.uniforms.clim0.value.set(a.length > 0 ? a[0][0] : null, a.length > 0 ? a[0][1] : null), this.uniforms.clim1.value.set(a.length > 1 ? a[1][0] : null, a.length > 1 ? a[1][1] : null), this.uniforms.clim2.value.set(a.length > 2 ? a[2][0] : null, a.length > 2 ? a[2][1] : null), this.uniforms.clim3.value.set(a.length > 3 ? a[3][0] : null, a.length > 3 ? a[3][1] : null), this.uniforms.clim4.value.set(a.length > 4 ? a[4][0] : null, a.length > 4 ? a[4][1] : null), this.uniforms.clim5.value.set(a.length > 5 ? a[5][0] : null, a.length > 5 ? a[5][1] : null), this.uniforms.clim6.value.set(a.length > 6 ? a[6][0] : null, a.length > 6 ? a[6][1] : null), this.uniforms.xClip.value.set(l[0] * (1 / this.maxResolution[0]) * this.boxSize[0], l[1] * (1 / this.maxResolution[0]) * this.boxSize[0]), this.uniforms.yClip.value.set(c[0] * (1 / this.maxResolution[1]) * this.boxSize[1], c[1] * (1 / this.maxResolution[1]) * this.boxSize[1]), this.uniforms.zClip.value.set(s[0] * (1 / this.maxResolution[2]) * this.boxSize[2], s[1] * (1 / this.maxResolution[2]) * this.boxSize[2]), this.uniforms.color0.value.set(r.length > 0 ? r[0][0] : null, r.length > 0 ? r[0][1] : null, r.length > 0 ? r[0][2] : null, r.length > 0 ? r[0][3] : null), this.uniforms.color1.value.set(r.length > 1 ? r[1][0] : null, r.length > 1 ? r[1][1] : null, r.length > 1 ? r[1][2] : null, r.length > 1 ? r[1][3] : null), this.uniforms.color2.value.set(r.length > 2 ? r[2][0] : null, r.length > 2 ? r[2][1] : null, r.length > 2 ? r[2][2] : null, r.length > 2 ? r[2][3] : null), this.uniforms.color3.value.set(r.length > 3 ? r[3][0] : null, r.length > 3 ? r[3][1] : null, r.length > 3 ? r[3][2] : null, r.length > 3 ? r[3][3] : null), this.uniforms.color4.value.set(r.length > 4 ? r[4][0] : null, r.length > 4 ? r[4][1] : null, r.length > 4 ? r[4][2] : null, r.length > 4 ? r[4][3] : null), this.uniforms.color5.value.set(r.length > 5 ? r[5][0] : null, r.length > 5 ? r[5][1] : null, r.length > 5 ? r[5][2] : null, r.length > 5 ? r[5][3] : null), this.uniforms.color6.value.set(r.length > 6 ? r[6][0] : null, r.length > 6 ? r[6][1] : null, r.length > 6 ? r[6][2] : null, r.length > 6 ? r[6][3] : null);
2644
- for (let u = 0; u < 7; u++)
2645
- typeof this.channelMaxResolutionIndex[u] == "number" && this.uniforms[`res${u}`].value.set(Math.max(1, this.channelMaxResolutionIndex[u]), this.zarrStoreNumResolutions - 1);
2662
+ updateUniforms(t, e, i, a, r, o, l, u, s, v, g) {
2663
+ A("Updating uniforms"), this.uniforms.boxSize.value.set(this.boxSize[0], this.boxSize[1], this.boxSize[2]), this.uniforms.brickCacheTex.value = v, this.uniforms.pageTableTex.value = g, this.uniforms.near.value = 0.1, this.uniforms.far.value = 3e3, this.uniforms.opacity.value = o, this.uniforms.volumeCount.value = t.length, this.uniforms.u_size.value.set(e.xLength, e.yLength, e.zLength), this.uniforms.u_window_size.value.set(0, 0), this.uniforms.u_vol_scale.value.set(1 / e.xLength, 1 / e.yLength, 1 / e.zLength * 2), this.uniforms.clim0.value.set(a.length > 0 ? a[0][0] : null, a.length > 0 ? a[0][1] : null), this.uniforms.clim1.value.set(a.length > 1 ? a[1][0] : null, a.length > 1 ? a[1][1] : null), this.uniforms.clim2.value.set(a.length > 2 ? a[2][0] : null, a.length > 2 ? a[2][1] : null), this.uniforms.clim3.value.set(a.length > 3 ? a[3][0] : null, a.length > 3 ? a[3][1] : null), this.uniforms.clim4.value.set(a.length > 4 ? a[4][0] : null, a.length > 4 ? a[4][1] : null), this.uniforms.clim5.value.set(a.length > 5 ? a[5][0] : null, a.length > 5 ? a[5][1] : null), this.uniforms.clim6.value.set(a.length > 6 ? a[6][0] : null, a.length > 6 ? a[6][1] : null), this.uniforms.xClip.value.set(l[0] * (1 / this.maxResolution[0]) * this.boxSize[0], l[1] * (1 / this.maxResolution[0]) * this.boxSize[0]), this.uniforms.yClip.value.set(u[0] * (1 / this.maxResolution[1]) * this.boxSize[1], u[1] * (1 / this.maxResolution[1]) * this.boxSize[1]), this.uniforms.zClip.value.set(s[0] * (1 / this.maxResolution[2]) * this.boxSize[2], s[1] * (1 / this.maxResolution[2]) * this.boxSize[2]), this.uniforms.color0.value.set(r.length > 0 ? r[0][0] : null, r.length > 0 ? r[0][1] : null, r.length > 0 ? r[0][2] : null, r.length > 0 ? r[0][3] : null), this.uniforms.color1.value.set(r.length > 1 ? r[1][0] : null, r.length > 1 ? r[1][1] : null, r.length > 1 ? r[1][2] : null, r.length > 1 ? r[1][3] : null), this.uniforms.color2.value.set(r.length > 2 ? r[2][0] : null, r.length > 2 ? r[2][1] : null, r.length > 2 ? r[2][2] : null, r.length > 2 ? r[2][3] : null), this.uniforms.color3.value.set(r.length > 3 ? r[3][0] : null, r.length > 3 ? r[3][1] : null, r.length > 3 ? r[3][2] : null, r.length > 3 ? r[3][3] : null), this.uniforms.color4.value.set(r.length > 4 ? r[4][0] : null, r.length > 4 ? r[4][1] : null, r.length > 4 ? r[4][2] : null, r.length > 4 ? r[4][3] : null), this.uniforms.color5.value.set(r.length > 5 ? r[5][0] : null, r.length > 5 ? r[5][1] : null, r.length > 5 ? r[5][2] : null, r.length > 5 ? r[5][3] : null), this.uniforms.color6.value.set(r.length > 6 ? r[6][0] : null, r.length > 6 ? r[6][1] : null, r.length > 6 ? r[6][2] : null, r.length > 6 ? r[6][3] : null);
2664
+ for (let c = 0; c < 7; c++)
2665
+ typeof this.channelMaxResolutionIndex[c] == "number" && this.uniforms[`res${c}`].value.set(Math.max(1, this.channelMaxResolutionIndex[c]), this.zarrStoreNumResolutions - 1);
2646
2666
  }
2647
2667
  /**
2648
2668
  * Sets the processing render target
@@ -2655,12 +2675,12 @@ class et {
2655
2675
  }
2656
2676
  */
2657
2677
  setChannelMapping(t) {
2658
- P("setting channel mapping"), n.debug("channelMapping", t), this.uniforms.channelMapping.value = t;
2678
+ A("setting channel mapping"), n.debug("channelMapping", t), this.uniforms.channelMapping.value = t;
2659
2679
  }
2660
2680
  // Only called on initialization of the
2661
2681
  // VolumeDataManager and VolumeRenderManager for a particular image.
2662
2682
  setZarrUniforms(t, e) {
2663
- P("setting zarr uniforms"), n.debug("zarrStore", t), n.debug("PT", e);
2683
+ A("setting zarr uniforms"), n.debug("zarrStore", t), n.debug("PT", e);
2664
2684
  for (let i = 0; i <= 9; i++)
2665
2685
  e.anchors && e.anchors[i] ? this.uniforms[`anchor${i}`].value.set(e.anchors[i][0] || 0, e.anchors[i][1] || 0, e.anchors[i][2] || 0) : (n.debug("anchor", i, "does not exist"), this.uniforms[`anchor${i}`].value.set(0, 0, 0)), t.scales && t.scales[i] ? this.uniforms[`scale${i}`].value.set(t.scales[i][0] || 1, t.scales[i][1] || 1, t.scales[i][2] || 1) : n.debug("scale", i, "does not exist");
2666
2686
  n.debug("zarrStore.brickLayout", t.brickLayout), this.zarrStoreNumResolutions = t.brickLayout.length;
@@ -2673,13 +2693,13 @@ class et {
2673
2693
  this.uniforms.resGlobal.value.set(1, t.brickLayout.length - 1), this.uniforms.voxelExtents.value.set(t.shapes[0][4], t.shapes[0][3], t.shapes[0][2]), this.uniforms.maxChannels.value = Math.min(t.channelCount, 7), n.debug("this.channelsVisible", this.channelsVisible), n.debug("zarrStore.shapes[0]", t.shapes[0]), n.debug("PT", e), n.debug("uniforms", this.uniforms);
2674
2694
  }
2675
2695
  }
2676
- const tt = `//
2696
+ const nt = `//
2677
2697
  varying vec2 vUv;
2678
2698
  void main() {
2679
2699
  vUv = uv;
2680
2700
  gl_Position = vec4(position, 1.0);
2681
2701
  }
2682
- `, nt = `//
2702
+ `, rt = `//
2683
2703
  // Input texture to blur
2684
2704
  uniform sampler2D tDiffuse;
2685
2705
  // Resolution of the texture (width, height)
@@ -2865,50 +2885,57 @@ void main() {
2865
2885
  gl_FragColor = color;
2866
2886
  }
2867
2887
  `;
2868
- function be(h, t) {
2869
- const e = h.properties?.get(t);
2888
+ function be(f, t) {
2889
+ const e = f.properties?.get(t);
2870
2890
  return e?.framebuffer || e?.__webglFramebuffer || t.__webglFramebuffer;
2871
2891
  }
2872
- function Q(h) {
2873
- se(le.DEBUG) && console.warn(`%cV: ${h}`, "background: deeppink; color: white; padding: 2px; border-radius: 3px;");
2892
+ function Q(f) {
2893
+ se(le.DEBUG) && console.warn(`%cV: ${f}`, "background: deeppink; color: white; padding: 2px; border-radius: 3px;");
2874
2894
  }
2875
- function rt(h, t, e, { mrtRef: i }) {
2876
- h.setRenderTarget(i.current), h.clear(!0, !0, !0), h.render(e, t);
2895
+ function it(f, t, e, { mrtRef: i }) {
2896
+ f.setRenderTarget(i.current), f.clear(!0, !0, !0), f.render(e, t);
2877
2897
  }
2878
- function it(h, { screenSceneRef: t, screenCameraRef: e }) {
2879
- h.setRenderTarget(null), h.clear(!0, !0, !0), h.render(t.current, e.current);
2898
+ function at(f, { screenSceneRef: t, screenCameraRef: e }) {
2899
+ f.setRenderTarget(null), f.clear(!0, !0, !0), f.render(t.current, e.current);
2880
2900
  }
2881
- function at(h, { frameRef: t, dataManager: e, mrtRef: i, bufRequest: a, bufUsage: r }) {
2882
- const o = h.getContext(), l = t.current;
2883
- e.noNewRequests === !0 && !e.manuallyStopped && l % 100 === 0 && l < 500 && (e.noNewRequests = !1), e.triggerRequest === !0 && e.noNewRequests === !1 ? (o.bindFramebuffer(o.READ_FRAMEBUFFER, be(h, i.current)), o.readBuffer(o.COLOR_ATTACHMENT1), o.readPixels(0, 0, i.current.width, i.current.height, o.RGBA, o.UNSIGNED_BYTE, a.current), e.processRequestData(a.current)) : e.triggerUsage === !0 && e.noNewRequests === !1 && (o.bindFramebuffer(o.READ_FRAMEBUFFER, be(h, i.current)), o.readBuffer(o.COLOR_ATTACHMENT2), o.readPixels(0, 0, i.current.width, i.current.height, o.RGBA, o.UNSIGNED_BYTE, r.current), e.processUsageData(r.current));
2901
+ function ot(f, { frameRef: t, dataManager: e, mrtRef: i, bufRequest: a, bufUsage: r }) {
2902
+ const o = f.getContext(), l = t.current;
2903
+ e.noNewRequests === !0 && !e.manuallyStopped && l % 100 === 0 && l < 500 && (e.noNewRequests = !1), e.triggerRequest === !0 && e.noNewRequests === !1 ? (o.bindFramebuffer(o.READ_FRAMEBUFFER, be(f, i.current)), o.readBuffer(o.COLOR_ATTACHMENT1), o.readPixels(0, 0, i.current.width, i.current.height, o.RGBA, o.UNSIGNED_BYTE, a.current), e.processRequestData(a.current, {
2904
+ // If width/height are not yet available,
2905
+ // processRequestData will proceed without weighting.
2906
+ width: i?.current?.width,
2907
+ height: i?.current?.height,
2908
+ // Default sigmaNormalized = 0.25; can be tuned
2909
+ sigmaNormalized: Ke
2910
+ })) : e.triggerUsage === !0 && e.noNewRequests === !1 && (o.bindFramebuffer(o.READ_FRAMEBUFFER, be(f, i.current)), o.readBuffer(o.COLOR_ATTACHMENT2), o.readPixels(0, 0, i.current.width, i.current.height, o.RGBA, o.UNSIGNED_BYTE, r.current), e.processUsageData(r.current));
2884
2911
  }
2885
- function ot(h, t) {
2886
- const { invalidate: e, isInteracting: i, dataManager: a, spatialRenderingModeChanging: r, meshRef: o, stillRef: l, screenQuadRef: c, lastSampleRef: s, frameRef: g, lastFrameCountRef: p } = t;
2887
- if (c.current && (l.current ? c.current.material.uniforms.gaussian.value = 0 : c.current.material.uniforms.gaussian.value = 7), i) {
2912
+ function st(f, t) {
2913
+ const { invalidate: e, isInteracting: i, dataManager: a, spatialRenderingModeChanging: r, meshRef: o, stillRef: l, screenQuadRef: u, lastSampleRef: s, frameRef: v, lastFrameCountRef: g } = t;
2914
+ if (u.current && (l.current ? u.current.material.uniforms.gaussian.value = 0 : u.current.material.uniforms.gaussian.value = 7), i) {
2888
2915
  a.manuallyStopped || (a.noNewRequests = !1, a.triggerUsage = !0);
2889
2916
  return;
2890
2917
  }
2891
2918
  if (r)
2892
2919
  return;
2893
- const u = o.current?.material?.uniforms, d = u?.renderRes?.value ?? a?.PT?.lowestDataRes;
2920
+ const c = o.current?.material?.uniforms, d = c?.renderRes?.value ?? a?.PT?.lowestDataRes;
2894
2921
  if (a.noNewRequests) {
2895
- d !== 0 ? (u && (u.renderRes.value = 0), n.debug("Adaptive Quality: No new requests. Setting renderSpeed to 0 (best quality)."), l.current = !1, c.current.material.uniforms.gaussian.value = 7, e()) : l.current || (n.debug("Adaptive Quality: No new requests and already at best quality. Setting stillRef to true."), l.current = !0, c.current.material.uniforms.gaussian.value = 0);
2922
+ d !== 0 ? (c && (c.renderRes.value = 0), n.debug("Adaptive Quality: No new requests. Setting renderSpeed to 0 (best quality)."), l.current = !1, u.current.material.uniforms.gaussian.value = 7, e()) : l.current || (n.debug("Adaptive Quality: No new requests and already at best quality. Setting stillRef to true."), l.current = !0, u.current.material.uniforms.gaussian.value = 0);
2896
2923
  return;
2897
2924
  }
2898
2925
  l.current && (l.current = !1, e());
2899
- const v = h.getElapsedTime();
2900
- if (v - s.current < 1)
2926
+ const m = f.getElapsedTime();
2927
+ if (m - s.current < 1)
2901
2928
  return;
2902
- const f = v - s.current, x = g.current - p.current;
2903
- let _ = 0;
2904
- f > 0 && (_ = x / f), s.current = v, p.current = g.current;
2905
- const y = _ > 100 && d > 0, E = _ < 30 && d < a.PT.lowestDataRes;
2906
- if (y || E) {
2907
- const L = d + (E ? 1 : -1);
2908
- u && (u.renderRes.value = L), e();
2929
+ const h = m - s.current, x = v.current - g.current;
2930
+ let b = 0;
2931
+ h > 0 && (b = x / h), s.current = m, g.current = v.current;
2932
+ const R = b > 100 && d > 0, E = b < 30 && d < a.PT.lowestDataRes;
2933
+ if (R || E) {
2934
+ const k = d + (E ? 1 : -1);
2935
+ c && (c.renderRes.value = k), e();
2909
2936
  }
2910
2937
  }
2911
- function st(h) {
2938
+ function lt(f) {
2912
2939
  const {
2913
2940
  images: t,
2914
2941
  imageLayerScopes: e,
@@ -2918,37 +2945,37 @@ function st(h) {
2918
2945
  // onInitComplete,
2919
2946
  spatialRenderingMode: o,
2920
2947
  spatialRenderingModeChanging: l,
2921
- onVolumeLoadingUpdate: c
2922
- } = h, {
2948
+ onVolumeLoadingUpdate: u
2949
+ } = f, {
2923
2950
  gl: s
2924
2951
  // scene,
2925
2952
  // camera
2926
- } = ve(), g = ve((R) => R.invalidate), p = M(null), u = M(null), d = M(null), v = M(null), f = M(null), [x, _] = fe({
2953
+ } = ve(), v = ve((y) => y.invalidate), g = P(null), c = P(null), d = P(null), m = P(null), h = P(null), [x, b] = fe({
2927
2954
  uniforms: null,
2928
2955
  shader: null,
2929
2956
  meshScale: [1, 1, 1],
2930
2957
  geometrySize: [1, 1, 1]
2931
- }), y = o === "3D", E = M(null), L = M(null), G = M(null), [j, T] = fe(!1), U = M(null), N = M(!1), Y = M(0), ie = M(0), k = M(0), m = de(() => new We(s), [s]), w = de(() => new et(), []);
2958
+ }), R = o === "3D", E = P(null), k = P(null), O = P(null), [X, T] = fe(!1), L = P(null), U = P(!1), Y = P(0), ie = P(0), I = P(0), p = de(() => new $e(s), [s]), w = de(() => new tt(), []);
2932
2959
  $(() => {
2933
2960
  Q("useEffect MRT target matching canvas");
2934
- const { width: R, height: I } = s.domElement, q = new Me(R, I, 3);
2961
+ const { width: y, height: D } = s.domElement, q = new Me(y, D, 3);
2935
2962
  q.texture.forEach((W) => {
2936
2963
  W.format = Pe, W.type = _e, W.minFilter = re, W.magFilter = re, W.generateMipmaps = !1;
2937
2964
  });
2938
- const O = new Ae(), ee = new Be(-1, 1, 1, -1, 0.1, 10);
2965
+ const F = new Ae(), ee = new Be(-1, 1, 1, -1, 0.1, 10);
2939
2966
  ee.position.z = 1;
2940
2967
  const te = new Ne({
2941
2968
  uniforms: {
2942
2969
  // Bind the first render target texture as the input of the gaussian blur shader.
2943
2970
  tDiffuse: { value: q.texture[0] },
2944
- resolution: { value: new b(R, I) },
2971
+ resolution: { value: new _(y, D) },
2945
2972
  gaussian: { value: 7 }
2946
2973
  },
2947
- vertexShader: tt,
2948
- fragmentShader: nt,
2974
+ vertexShader: nt,
2975
+ fragmentShader: rt,
2949
2976
  transparent: !0
2950
2977
  }), K = new Ue(new Le(2, 2), te);
2951
- return O.add(K), E.current = O, L.current = ee, G.current = K, d.current = new Uint8Array(R * I * 4), v.current = new Uint8Array(R * I * 4), f.current = q, () => {
2978
+ return F.add(K), E.current = F, k.current = ee, O.current = K, d.current = new Uint8Array(y * D * 4), m.current = new Uint8Array(y * D * 4), h.current = q, () => {
2952
2979
  q.dispose(), te.dispose(), K.geometry.dispose();
2953
2980
  };
2954
2981
  }, [s]);
@@ -2957,8 +2984,8 @@ function st(h) {
2957
2984
  const J = r?.[0]?.[ae];
2958
2985
  $(() => {
2959
2986
  Q("useEffect INIT");
2960
- let R = !1;
2961
- if (!m || !w) {
2987
+ let y = !1;
2988
+ if (!p || !w) {
2962
2989
  n.debug("dataManager or renderManager not initialized yet");
2963
2990
  return;
2964
2991
  }
@@ -2971,22 +2998,22 @@ function st(h) {
2971
2998
  return;
2972
2999
  }
2973
3000
  return (async () => {
2974
- if (m.initStatus === F.COMPLETE) {
3001
+ if (p.initStatus === V.COMPLETE) {
2975
3002
  n.debug("dataManager already initialized, skipping");
2976
3003
  return;
2977
3004
  }
2978
- if (m.initImages(t, e), await m.init(J), R) {
3005
+ if (p.initImages(t, e), await p.init(J), y) {
2979
3006
  n.debug("Initialization useEffect has rerun, aborting remaining initialization");
2980
3007
  return;
2981
3008
  }
2982
- n.debug("dataManager initialized"), w.setZarrUniforms(m.zarrStore, m.PT), w.setChannelMapping(m.channels.colorMappings), n.debug("rm.uniforms", w.uniforms), g();
3009
+ n.debug("dataManager initialized"), w.setZarrUniforms(p.zarrStore, p.PT), w.setChannelMapping(p.channels.colorMappings), n.debug("rm.uniforms", w.uniforms), v();
2983
3010
  })(), () => {
2984
- R = !0;
3011
+ y = !0;
2985
3012
  };
2986
- }, [m, w, t, e]), $(() => {
2987
- if (o === "3D" && m && w) {
3013
+ }, [p, w, t, e]), $(() => {
3014
+ if (o === "3D" && p && w) {
2988
3015
  Q("useEffect spatialRenderingMode");
2989
- const I = {
3016
+ const D = {
2990
3017
  images: t,
2991
3018
  imageLayerScopes: e,
2992
3019
  imageLayerCoordination: i,
@@ -2994,75 +3021,75 @@ function st(h) {
2994
3021
  imageChannelCoordination: r,
2995
3022
  spatialRenderingMode: o
2996
3023
  };
2997
- if (w.updateFromProps(I)) {
3024
+ if (w.updateFromProps(D)) {
2998
3025
  const { zarrInit: q } = w;
2999
- q || (m.ptTHREE.needsUpdate = !1, m.bcTHREE.needsUpdate = !1, m.renderer.initTexture(m.bcTHREE), m.renderer.initTexture(m.ptTHREE), m.initTexture());
3000
- const O = w.updateRendering({
3001
- zarrStoreShapes: m.zarrStore.shapes,
3002
- originalScaleXYZ: m.getOriginalScaleXYZ(),
3003
- physicalDimensionsXYZ: m.getPhysicalDimensionsXYZ(),
3004
- maxResolutionXYZ: m.getMaxResolutionXYZ(),
3005
- boxDimensionsXYZ: m.getBoxDimensionsXYZ(),
3006
- normalizedScaleXYZ: m.getNormalizedScaleXYZ(),
3007
- bcTHREE: m.bcTHREE,
3008
- ptTHREE: m.ptTHREE
3026
+ q || (p.ptTHREE.needsUpdate = !1, p.bcTHREE.needsUpdate = !1, p.renderer.initTexture(p.bcTHREE), p.renderer.initTexture(p.ptTHREE), p.initTexture());
3027
+ const F = w.updateRendering({
3028
+ zarrStoreShapes: p.zarrStore.shapes,
3029
+ originalScaleXYZ: p.getOriginalScaleXYZ(),
3030
+ physicalDimensionsXYZ: p.getPhysicalDimensionsXYZ(),
3031
+ maxResolutionXYZ: p.getMaxResolutionXYZ(),
3032
+ boxDimensionsXYZ: p.getBoxDimensionsXYZ(),
3033
+ normalizedScaleXYZ: p.getNormalizedScaleXYZ(),
3034
+ bcTHREE: p.bcTHREE,
3035
+ ptTHREE: p.ptTHREE
3009
3036
  });
3010
- O && _(O);
3037
+ F && b(F);
3011
3038
  }
3012
3039
  }
3013
- }, [m, w, t, e, i, a, r, o]), Ge((R, I, q) => {
3014
- if (!f.current || !m || !w || !x.shader)
3040
+ }, [p, w, t, e, i, a, r, o]), Ge((y, D, q) => {
3041
+ if (!h.current || !p || !w || !x.shader)
3015
3042
  return;
3016
- const { gl: O, camera: ee, scene: te, clock: K } = R;
3017
- N.current || rt(O, ee, te, { mrtRef: f }), it(O, { screenSceneRef: E, screenCameraRef: L }), at(O, { frameRef: Y, dataManager: m, mrtRef: f, bufRequest: d, bufUsage: v }), ot(K, {
3018
- invalidate: g,
3019
- isInteracting: j,
3020
- dataManager: m,
3043
+ const { gl: F, camera: ee, scene: te, clock: K } = y;
3044
+ U.current || it(F, ee, te, { mrtRef: h }), at(F, { screenSceneRef: E, screenCameraRef: k }), ot(F, { frameRef: Y, dataManager: p, mrtRef: h, bufRequest: d, bufUsage: m }), st(K, {
3045
+ invalidate: v,
3046
+ isInteracting: X,
3047
+ dataManager: p,
3021
3048
  spatialRenderingModeChanging: l,
3022
- meshRef: u,
3023
- stillRef: N,
3024
- screenQuadRef: G,
3049
+ meshRef: c,
3050
+ stillRef: U,
3051
+ screenQuadRef: O,
3025
3052
  lastSampleRef: ie,
3026
3053
  frameRef: Y,
3027
- lastFrameCountRef: k
3054
+ lastFrameCountRef: I
3028
3055
  }), Y.current += 1;
3029
3056
  }, 1);
3030
- const H = X((R) => {
3031
- if (Q("invalidateOnInteraction callback"), T(R), R) {
3032
- const I = u.current?.material?.uniforms;
3033
- I && (I.renderRes.value = m.PT.lowestDataRes), N.current = !1, g();
3057
+ const H = j((y) => {
3058
+ if (Q("invalidateOnInteraction callback"), T(y), y) {
3059
+ const D = c.current?.material?.uniforms;
3060
+ D && (D.renderRes.value = p.PT.lowestDataRes), U.current = !1, v();
3034
3061
  }
3035
- }), Re = X((R) => {
3062
+ }), Re = j((y) => {
3036
3063
  H(!0);
3037
- }), ye = X((R) => {
3038
- clearTimeout(U.current), U.current = setTimeout(() => {
3064
+ }), ye = j((y) => {
3065
+ clearTimeout(L.current), L.current = setTimeout(() => {
3039
3066
  H(!1);
3040
3067
  }, 300);
3041
3068
  });
3042
3069
  $(() => {
3043
- Q("useEffect firstImageLayerChannelCoordination"), H(!0), n.debug("something about channels changed"), m.updateChannels(J), w.setChannelMapping(m.channels.colorMappings), clearTimeout(U.current), U.current = setTimeout(() => {
3070
+ Q("useEffect firstImageLayerChannelCoordination"), H(!0), n.debug("something about channels changed"), p.updateChannels(J), w.setChannelMapping(p.channels.colorMappings), clearTimeout(L.current), L.current = setTimeout(() => {
3044
3071
  H(!1);
3045
3072
  }, 300);
3046
- }, [m, J, w, H]);
3047
- const Ee = X(() => {
3048
- m && m.stopLoading();
3049
- }), Te = X(() => {
3050
- m && m.restartLoading();
3051
- }), Se = X(() => m ? m.getLoadingProgress() : null);
3073
+ }, [p, J, w, H]);
3074
+ const Ee = j(() => {
3075
+ p && p.stopLoading();
3076
+ }), Te = j(() => {
3077
+ p && p.restartLoading();
3078
+ }), Se = j(() => p ? p.getLoadingProgress() : null);
3052
3079
  return $(() => {
3053
- if (!c)
3080
+ if (!u)
3054
3081
  return;
3055
- const R = setInterval(() => {
3056
- const I = Se();
3057
- c({
3058
- loadingProgress: I,
3059
- stillRef: N,
3082
+ const y = setInterval(() => {
3083
+ const D = Se();
3084
+ u({
3085
+ loadingProgress: D,
3086
+ stillRef: U,
3060
3087
  onStopLoading: Ee,
3061
3088
  onRestartLoading: Te
3062
3089
  });
3063
3090
  }, 1e3);
3064
- return () => clearInterval(R);
3065
- }, [c, N]), !y || !m || !w ? null : x.shader ? B.jsxs("group", { children: [B.jsx(
3091
+ return () => clearInterval(y);
3092
+ }, [u, U]), !R || !p || !w ? null : x.shader ? N.jsxs("group", { children: [N.jsx(
3066
3093
  me,
3067
3094
  {
3068
3095
  // ref={mainOrbitControlsRef}
@@ -3070,10 +3097,10 @@ function st(h) {
3070
3097
  onStart: Re,
3071
3098
  onEnd: ye
3072
3099
  }
3073
- ), B.jsxs("mesh", { ref: u, scale: x.meshScale, children: [B.jsx("boxGeometry", { args: x.geometrySize }), B.jsx("shaderMaterial", { uniforms: x.uniforms, vertexShader: x.shader.vertexShader, fragmentShader: x.shader.fragmentShader, side: Fe, transparent: !1, glslVersion: Oe })] })] }) : B.jsxs("group", { children: [B.jsxs("mesh", { children: [B.jsx("boxGeometry", { args: [1, 1, 1] }), B.jsx("meshBasicMaterial", { color: "#444", wireframe: !0 })] }), B.jsx(me, { ref: p })] });
3100
+ ), N.jsxs("mesh", { ref: c, scale: x.meshScale, children: [N.jsx("boxGeometry", { args: x.geometrySize }), N.jsx("shaderMaterial", { uniforms: x.uniforms, vertexShader: x.shader.vertexShader, fragmentShader: x.shader.fragmentShader, side: Fe, transparent: !1, glslVersion: Oe })] })] }) : N.jsxs("group", { children: [N.jsxs("mesh", { children: [N.jsx("boxGeometry", { args: [1, 1, 1] }), N.jsx("meshBasicMaterial", { color: "#444", wireframe: !0 })] }), N.jsx(me, { ref: g })] });
3074
3101
  }
3075
- function ft(h) {
3076
- return B.jsx(qe, { frameloop: "always", style: {
3102
+ function dt(f) {
3103
+ return N.jsx(qe, { frameloop: "always", style: {
3077
3104
  position: "absolute",
3078
3105
  top: 0,
3079
3106
  left: 0,
@@ -3093,8 +3120,8 @@ function ft(h) {
3093
3120
  logarithmicDepthBuffer: !1,
3094
3121
  preserveDrawingBuffer: !1,
3095
3122
  autoClear: !1
3096
- }, children: B.jsx(Ve, { fallback: "Initializing Volume View...", children: B.jsx(st, { ...h }) }) });
3123
+ }, children: N.jsx(Ve, { fallback: "Initializing Volume View...", children: N.jsx(lt, { ...f }) }) });
3097
3124
  }
3098
3125
  export {
3099
- ft as SpatialWrapper
3126
+ dt as SpatialWrapper
3100
3127
  };