copper3d 3.11.4 → 3.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -1
- package/ai-index/guides/4D-MRI-LV-rendering.md +1 -1
- package/ai-index/guides/copper3d-rendering-optimization.md +37 -0
- package/ai-index/guides/load-callbacks.md +35 -0
- package/ai-index/guides/nrrd-tools.md +110 -2
- package/ai-index/guides/segmentation-module.md +108 -2
- package/ai-index/manifest.json +8 -8
- package/ai-index/symbols.json +1 -1
- package/dist/Loader/copperNrrdLoader.d.ts +33 -0
- package/dist/Loader/copperNrrdLoader.js +27 -5
- package/dist/Loader/copperNrrdLoader.js.map +1 -1
- package/dist/Renderer/copperRenderer.js +2 -2
- package/dist/Renderer/copperRenderer.js.map +1 -1
- package/dist/Scene/copperScene.d.ts +1 -1
- package/dist/Scene/copperScene.js +4 -1
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/Utils/segmentation/DragOperator.d.ts +6 -0
- package/dist/Utils/segmentation/DragOperator.js +9 -0
- package/dist/Utils/segmentation/DragOperator.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +38 -1
- package/dist/Utils/segmentation/NrrdTools.js +105 -2
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +7 -10
- package/dist/Utils/segmentation/RenderingUtils.js +14 -117
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
- package/dist/Utils/segmentation/contourPaint.d.ts +37 -0
- package/dist/Utils/segmentation/contourPaint.js +128 -0
- package/dist/Utils/segmentation/contourPaint.js.map +1 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js +5 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
- package/dist/Utils/segmentation/tools/MaskMirror.js +165 -0
- package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +8 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
- package/dist/Utils/segmentation/tools/ToolHost.d.ts +10 -2
- package/dist/bundle.esm.js +459 -122
- package/dist/bundle.umd.js +459 -121
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/Loader/copperNrrdLoader.d.ts +33 -0
- package/dist/types/Scene/copperScene.d.ts +1 -1
- package/dist/types/Utils/segmentation/DragOperator.d.ts +6 -0
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +38 -1
- package/dist/types/Utils/segmentation/RenderingUtils.d.ts +7 -10
- package/dist/types/Utils/segmentation/contourPaint.d.ts +37 -0
- package/dist/types/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
- package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +10 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/bundle.esm.js
CHANGED
|
@@ -85665,7 +85665,20 @@ new MeshBasicMaterial({
|
|
|
85665
85665
|
/** All three, which is what `loadNrrd` has always extracted. */
|
|
85666
85666
|
const DEFAULT_AXES = ["x", "y", "z"];
|
|
85667
85667
|
/**
|
|
85668
|
-
*
|
|
85668
|
+
* Post-extraction fixups every `VolumeSlice` needs. Run it on each slice right
|
|
85669
|
+
* after `Volume.extractSlice`; `undefined` (an axis not extracted) is skipped.
|
|
85670
|
+
*
|
|
85671
|
+
* ## Readback-friendly buffer
|
|
85672
|
+
*
|
|
85673
|
+
* Stock `VolumeSlice.repaint` reads `ctxBuffer` back with `getImageData` on
|
|
85674
|
+
* every repaint. three creates that context in the constructor without
|
|
85675
|
+
* `willReadFrequently`, so the canvas may live on the GPU and each repaint
|
|
85676
|
+
* copies it back to the CPU (Chrome warns once per such context). A context's
|
|
85677
|
+
* attributes are fixed by the first `getContext` call on its canvas, so the
|
|
85678
|
+
* buffer is replaced by a canvas whose context is created with the flag;
|
|
85679
|
+
* `updateGeometry` re-fetching it later gets that same context.
|
|
85680
|
+
*
|
|
85681
|
+
* ## three.js regression (present from r175 through at least r185)
|
|
85669
85682
|
*
|
|
85670
85683
|
* `VolumeSlice`'s constructor calls `updateGeometry()` and then `repaint()`, but
|
|
85671
85684
|
* *afterwards* assigns the JSDoc default values:
|
|
@@ -85683,9 +85696,18 @@ const DEFAULT_AXES = ["x", "y", "z"];
|
|
|
85683
85696
|
* Recomputing the geometry right after extraction restores the correct values.
|
|
85684
85697
|
* It is a harmless recompute on three <= r174, where the bug does not exist.
|
|
85685
85698
|
*/
|
|
85686
|
-
function
|
|
85699
|
+
function prepareVolumeSlices(...slices) {
|
|
85687
85700
|
for (const slice of slices) {
|
|
85688
|
-
if (slice
|
|
85701
|
+
if (!slice)
|
|
85702
|
+
continue;
|
|
85703
|
+
if (slice.canvasBuffer) {
|
|
85704
|
+
const buffer = document.createElement("canvas");
|
|
85705
|
+
buffer.width = slice.canvasBuffer.width;
|
|
85706
|
+
buffer.height = slice.canvasBuffer.height;
|
|
85707
|
+
slice.canvasBuffer = buffer;
|
|
85708
|
+
slice.ctxBuffer = buffer.getContext("2d", { willReadFrequently: true });
|
|
85709
|
+
}
|
|
85710
|
+
if (slice.iLength === 0 && typeof slice.updateGeometry === "function") {
|
|
85689
85711
|
slice.updateGeometry();
|
|
85690
85712
|
}
|
|
85691
85713
|
}
|
|
@@ -85714,7 +85736,7 @@ function ensureAxisExtracted(slices, axis, meshes) {
|
|
|
85714
85736
|
const axisIndex = axis === "x" ? 0 : axis === "y" ? 1 : 2;
|
|
85715
85737
|
const initIndex = Math.floor(dimensions[axisIndex] / 2);
|
|
85716
85738
|
const slice = volume.extractSlice(axis, initIndex * ratio[axisIndex]);
|
|
85717
|
-
|
|
85739
|
+
prepareVolumeSlices(slice);
|
|
85718
85740
|
slice.initIndex = initIndex;
|
|
85719
85741
|
slice.MaxIndex = dimensions[axisIndex] - 1;
|
|
85720
85742
|
slice.RSARatio = ratio[axisIndex];
|
|
@@ -85759,7 +85781,7 @@ function copperNrrdLoader(url, loadingBar, segmentation, callback, opts) {
|
|
|
85759
85781
|
const sliceX = wanted.x
|
|
85760
85782
|
? volume.extractSlice("x", initIndexX * ratio[0])
|
|
85761
85783
|
: undefined;
|
|
85762
|
-
|
|
85784
|
+
prepareVolumeSlices(sliceZ, sliceY, sliceX);
|
|
85763
85785
|
if (sliceZ) {
|
|
85764
85786
|
sliceZ.initIndex = initIndexZ;
|
|
85765
85787
|
sliceZ.MaxIndex = dimensions[2] - 1;
|
|
@@ -104535,7 +104557,7 @@ class copperScene extends baseScene {
|
|
|
104535
104557
|
// rayster pick
|
|
104536
104558
|
constructor(container, renderer, opt) {
|
|
104537
104559
|
super(container, renderer, opt);
|
|
104538
|
-
this.clock = new
|
|
104560
|
+
this.clock = new Timer();
|
|
104539
104561
|
// isHalfed: boolean = false;
|
|
104540
104562
|
this.mixer = null;
|
|
104541
104563
|
this.playRate = 1.0;
|
|
@@ -105006,6 +105028,9 @@ class copperScene extends baseScene {
|
|
|
105006
105028
|
}
|
|
105007
105029
|
render(time) {
|
|
105008
105030
|
this.controls.update();
|
|
105031
|
+
// Every frame, so a model's first mixer step is one frame long rather than
|
|
105032
|
+
// the time since this scene was built.
|
|
105033
|
+
this.clock.update();
|
|
105009
105034
|
if (this.modelReady) {
|
|
105010
105035
|
this.mixer && this.mixer.update(this.clock.getDelta() * this.playRate);
|
|
105011
105036
|
// this.mixer && this.mixer.update((time as number) * this.playRate);
|
|
@@ -105033,7 +105058,7 @@ class copperRenderer extends baseRenderer {
|
|
|
105033
105058
|
super(container, options);
|
|
105034
105059
|
this.sceneMap = {};
|
|
105035
105060
|
this.fps = 30;
|
|
105036
|
-
this.renderClock = new
|
|
105061
|
+
this.renderClock = new Timer();
|
|
105037
105062
|
this.delta = 0;
|
|
105038
105063
|
this.interval = 1 / this.fps;
|
|
105039
105064
|
this.preRenderCallbackFunctions = [];
|
|
@@ -105057,7 +105082,7 @@ class copperRenderer extends baseRenderer {
|
|
|
105057
105082
|
if (this.delta === 0) {
|
|
105058
105083
|
this.render();
|
|
105059
105084
|
}
|
|
105060
|
-
this.delta += this.renderClock.getDelta();
|
|
105085
|
+
this.delta += this.renderClock.update().getDelta();
|
|
105061
105086
|
if (this.delta > this.interval) {
|
|
105062
105087
|
this.render();
|
|
105063
105088
|
if ((_c = this.options) === null || _c === void 0 ? void 0 : _c.performanceGui)
|
|
@@ -109313,6 +109338,11 @@ class DragSliceTool extends BaseTool {
|
|
|
109313
109338
|
}
|
|
109314
109339
|
let newIndex = view.currentSliceIndex + sliceModifyNum;
|
|
109315
109340
|
if (newIndex != view.currentSliceIndex || view.showContrast) {
|
|
109341
|
+
// While a preview slice is shown the displayed slice has depth 1, so moving it would
|
|
109342
|
+
// paint blank; the host fetches the target slice instead.
|
|
109343
|
+
const target = Math.min(Math.max(newIndex, view.minIndex), view.maxIndex);
|
|
109344
|
+
if (this.callbacks.previewSliceMove(target))
|
|
109345
|
+
return;
|
|
109316
109346
|
if (newIndex > view.maxIndex) {
|
|
109317
109347
|
newIndex = view.maxIndex;
|
|
109318
109348
|
view.contrastNum = this.ctx.protectedData.displaySlices.length - 1;
|
|
@@ -109441,6 +109471,7 @@ class DragOperator {
|
|
|
109441
109471
|
};
|
|
109442
109472
|
this.sensitiveArray = [];
|
|
109443
109473
|
this.refreshSphereOverlayCb = null;
|
|
109474
|
+
this.previewSliceMoveCb = () => false;
|
|
109444
109475
|
// EventRouter for centralized event handling
|
|
109445
109476
|
this.eventRouter = null;
|
|
109446
109477
|
this.configDragMode = () => {
|
|
@@ -109498,6 +109529,7 @@ class DragOperator {
|
|
|
109498
109529
|
renderSliceToCanvas: (layer, axis, sliceIndex, buffer, targetCtx, w, h) => this.renderSliceToCanvas(layer, axis, sliceIndex, buffer, targetCtx, w, h),
|
|
109499
109530
|
compositeAllLayers: () => this.compositeAllLayers(),
|
|
109500
109531
|
refreshSphereOverlay: () => { var _a; return (_a = this.refreshSphereOverlayCb) === null || _a === void 0 ? void 0 : _a.call(this); },
|
|
109532
|
+
previewSliceMove: (index) => this.previewSliceMoveCb(index),
|
|
109501
109533
|
}, this.showDragNumberDiv, dragEffectCanvases);
|
|
109502
109534
|
}
|
|
109503
109535
|
setShowDragNumberDiv(sliceIndexContainer) {
|
|
@@ -109511,6 +109543,13 @@ class DragOperator {
|
|
|
109511
109543
|
setRefreshSphereOverlay(cb) {
|
|
109512
109544
|
this.refreshSphereOverlayCb = cb;
|
|
109513
109545
|
}
|
|
109546
|
+
/**
|
|
109547
|
+
* Set the callback that may consume a slice move while a preview slice is shown.
|
|
109548
|
+
* Called by NrrdTools; until then every move proceeds normally.
|
|
109549
|
+
*/
|
|
109550
|
+
setPreviewSliceMove(cb) {
|
|
109551
|
+
this.previewSliceMoveCb = cb;
|
|
109552
|
+
}
|
|
109514
109553
|
/**
|
|
109515
109554
|
* Set the EventRouter reference for centralized event handling.
|
|
109516
109555
|
* Called by NrrdTools/DrawToolCore after EventRouter is initialized.
|
|
@@ -109597,6 +109636,125 @@ class DragOperator {
|
|
|
109597
109636
|
* stay visible against bright tissue.
|
|
109598
109637
|
*/
|
|
109599
109638
|
const OUTLINE_WIDTH_PX = 1.5;
|
|
109639
|
+
/**
|
|
109640
|
+
* Populate one cache entry's paths for one render mode.
|
|
109641
|
+
*
|
|
109642
|
+
* Split out because the two modes are built at different times: whichever is in use when
|
|
109643
|
+
* a slice is first drawn, and the other one only if the clinician switches while still on
|
|
109644
|
+
* that slice. Building both eagerly would make every slice scrub pay for a mode most
|
|
109645
|
+
* sessions never turn on.
|
|
109646
|
+
*/
|
|
109647
|
+
function buildPaths(entry, data, stride, outline) {
|
|
109648
|
+
const target = outline ? entry.outlines : entry.fills;
|
|
109649
|
+
for (const lbl of entry.labels) {
|
|
109650
|
+
target.set(lbl, outline
|
|
109651
|
+
? extractLabelOutline(data, entry.W, entry.H, lbl, stride, 0)
|
|
109652
|
+
: extractLabelContours(data, entry.W, entry.H, lbl, stride, 0));
|
|
109653
|
+
}
|
|
109654
|
+
}
|
|
109655
|
+
/**
|
|
109656
|
+
* The cached contours for `slot` under `key`, extracting on a miss. One entry per slot: a new
|
|
109657
|
+
* key overwrites it. `readSlice` is called only when extraction is needed.
|
|
109658
|
+
*/
|
|
109659
|
+
function contourEntry(cache, slot, key, readSlice, outline) {
|
|
109660
|
+
// Cache miss → run the expensive extraction once. Hits (zoom,
|
|
109661
|
+
// recomposite, contrast toggle) skip straight to the draw.
|
|
109662
|
+
let entry = cache.get(slot);
|
|
109663
|
+
if (!entry || entry.key !== key) {
|
|
109664
|
+
const slice = readSlice();
|
|
109665
|
+
entry = {
|
|
109666
|
+
key,
|
|
109667
|
+
W: slice.width,
|
|
109668
|
+
H: slice.height,
|
|
109669
|
+
labels: findLabelsInSlice(slice.data, slice.width, slice.height, slice.stride, 0),
|
|
109670
|
+
fills: new Map(),
|
|
109671
|
+
outlines: new Map(),
|
|
109672
|
+
};
|
|
109673
|
+
cache.set(slot, entry);
|
|
109674
|
+
buildPaths(entry, slice.data, slice.stride, outline);
|
|
109675
|
+
}
|
|
109676
|
+
else if ((outline ? entry.outlines : entry.fills).size !== entry.labels.length) {
|
|
109677
|
+
// The mode changed since this slice was last drawn, so the other set of
|
|
109678
|
+
// paths is cached and this one is not. Re-read the slice and build it; from
|
|
109679
|
+
// here on both are present and toggling is a pure cache hit.
|
|
109680
|
+
const slice = readSlice();
|
|
109681
|
+
buildPaths(entry, slice.data, slice.stride, outline);
|
|
109682
|
+
}
|
|
109683
|
+
return entry;
|
|
109684
|
+
}
|
|
109685
|
+
/** Paint an entry's visible labels onto `targetCtx`, scaled from voxels to `scaledWidth × scaledHeight`. */
|
|
109686
|
+
function paintContours(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, colorOf, channelVis) {
|
|
109687
|
+
if (entry.labels.length === 0)
|
|
109688
|
+
return;
|
|
109689
|
+
targetCtx.save();
|
|
109690
|
+
// A throw (a missing colour, say) must not leave the transform on the target.
|
|
109691
|
+
try {
|
|
109692
|
+
drawPaths(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, colorOf, channelVis);
|
|
109693
|
+
}
|
|
109694
|
+
finally {
|
|
109695
|
+
targetCtx.restore();
|
|
109696
|
+
}
|
|
109697
|
+
}
|
|
109698
|
+
function drawPaths(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, colorOf, channelVis) {
|
|
109699
|
+
const { W, H, labels } = entry;
|
|
109700
|
+
const paths = outline ? entry.outlines : entry.fills;
|
|
109701
|
+
// Vector drawing — imageSmoothingEnabled is irrelevant here, but keep
|
|
109702
|
+
// it off to match the rest of the pipeline.
|
|
109703
|
+
targetCtx.imageSmoothingEnabled = false;
|
|
109704
|
+
if (outline) {
|
|
109705
|
+
// Stroke on an UNTRANSFORMED context, with the voxel→display mapping carried
|
|
109706
|
+
// in the path instead. `lineWidth` is then measured in screen pixels, which
|
|
109707
|
+
// is what the other two options get wrong: stroking under `ctx.scale(sx, sy)`
|
|
109708
|
+
// thickens the line with the zoom, exactly when the clinician has magnified
|
|
109709
|
+
// the image to look at the boundary — and because voxels are rarely isotropic
|
|
109710
|
+
// (sx !== sy), it also comes out thicker in one axis than the other.
|
|
109711
|
+
const matrix = new DOMMatrix();
|
|
109712
|
+
if (axis === "y") {
|
|
109713
|
+
matrix.scaleSelf(1, -1);
|
|
109714
|
+
matrix.translateSelf(0, -scaledHeight);
|
|
109715
|
+
}
|
|
109716
|
+
matrix.scaleSelf(scaledWidth / W, scaledHeight / H);
|
|
109717
|
+
targetCtx.lineWidth = OUTLINE_WIDTH_PX;
|
|
109718
|
+
// Segments are emitted per cell and meet at shared endpoints; round caps
|
|
109719
|
+
// close those joins. Canvas composites a whole Path2D in one pass, so the
|
|
109720
|
+
// overlap costs no doubled alpha.
|
|
109721
|
+
targetCtx.lineJoin = "round";
|
|
109722
|
+
targetCtx.lineCap = "round";
|
|
109723
|
+
for (const lbl of labels) {
|
|
109724
|
+
if (channelVis && channelVis[lbl] === false)
|
|
109725
|
+
continue;
|
|
109726
|
+
const path = paths.get(lbl);
|
|
109727
|
+
if (!path)
|
|
109728
|
+
continue;
|
|
109729
|
+
const color = colorOf(lbl);
|
|
109730
|
+
targetCtx.strokeStyle = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
109731
|
+
const display = new Path2D();
|
|
109732
|
+
display.addPath(path, matrix);
|
|
109733
|
+
targetCtx.stroke(display);
|
|
109734
|
+
}
|
|
109735
|
+
return;
|
|
109736
|
+
}
|
|
109737
|
+
// Coronal (axis='y') Z-flip: mirrors the flip applied by the write
|
|
109738
|
+
// path (syncLayerSliceData). Apply BEFORE the voxel→display scale
|
|
109739
|
+
// so the flip operates in display coordinates.
|
|
109740
|
+
if (axis === "y") {
|
|
109741
|
+
targetCtx.scale(1, -1);
|
|
109742
|
+
targetCtx.translate(0, -scaledHeight);
|
|
109743
|
+
}
|
|
109744
|
+
// Voxel coord (x ∈ [0, W], y ∈ [0, H]) → display coord.
|
|
109745
|
+
targetCtx.scale(scaledWidth / W, scaledHeight / H);
|
|
109746
|
+
for (const lbl of labels) {
|
|
109747
|
+
if (channelVis && channelVis[lbl] === false)
|
|
109748
|
+
continue;
|
|
109749
|
+
const path = paths.get(lbl);
|
|
109750
|
+
if (!path)
|
|
109751
|
+
continue;
|
|
109752
|
+
const color = colorOf(lbl);
|
|
109753
|
+
targetCtx.fillStyle = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
109754
|
+
targetCtx.fill(path, "nonzero");
|
|
109755
|
+
}
|
|
109756
|
+
}
|
|
109757
|
+
|
|
109600
109758
|
/**
|
|
109601
109759
|
* RenderingUtils — Rendering / slice-buffer helper methods.
|
|
109602
109760
|
*
|
|
@@ -109611,6 +109769,10 @@ class RenderingUtils {
|
|
|
109611
109769
|
constructor(state) {
|
|
109612
109770
|
/** Injected callback — set by owner after construction. */
|
|
109613
109771
|
this.setEmptyCanvasSize = () => { };
|
|
109772
|
+
/** Set while this viewer draws another viewer's masks; painted after this viewer's own layers. */
|
|
109773
|
+
this.mirror = null;
|
|
109774
|
+
/** Called after every composite. The owner refreshes the viewers mirroring this one. */
|
|
109775
|
+
this.onComposited = null;
|
|
109614
109776
|
// Reusable ImageData buffer for zero-allocation slice rendering
|
|
109615
109777
|
this._reusableSliceBuffer = null;
|
|
109616
109778
|
this._reusableBufferWidth = 0;
|
|
@@ -109645,7 +109807,8 @@ class RenderingUtils {
|
|
|
109645
109807
|
* Get MaskVolume for a specific layer
|
|
109646
109808
|
*
|
|
109647
109809
|
* @param layer - Layer name: "layer1", "layer2", or "layer3"
|
|
109648
|
-
* @returns MaskVolume instance for the specified layer
|
|
109810
|
+
* @returns MaskVolume instance for the specified layer; `undefined` on a
|
|
109811
|
+
* read-only engine built with no layers, which has no volume to return
|
|
109649
109812
|
*/
|
|
109650
109813
|
getVolumeForLayer(layer) {
|
|
109651
109814
|
const { volumes } = this.state.protectedData.maskData;
|
|
@@ -109653,6 +109816,8 @@ class RenderingUtils {
|
|
|
109653
109816
|
if (vol)
|
|
109654
109817
|
return vol;
|
|
109655
109818
|
const firstLayerId = this.state.nrrd_states.image.layers[0];
|
|
109819
|
+
if (firstLayerId === undefined)
|
|
109820
|
+
return vol;
|
|
109656
109821
|
console.warn(`RenderingUtils: unknown layer "${layer}", falling back to "${firstLayerId}"`);
|
|
109657
109822
|
return volumes[firstLayerId];
|
|
109658
109823
|
}
|
|
@@ -109720,22 +109885,6 @@ class RenderingUtils {
|
|
|
109720
109885
|
return null; // Volume not ready
|
|
109721
109886
|
}
|
|
109722
109887
|
}
|
|
109723
|
-
/**
|
|
109724
|
-
* Populate one cache entry's paths for one render mode.
|
|
109725
|
-
*
|
|
109726
|
-
* Split out because the two modes are built at different times: whichever is in use when
|
|
109727
|
-
* a slice is first drawn, and the other one only if the clinician switches while still on
|
|
109728
|
-
* that slice. Building both eagerly would make every slice scrub pay for a mode most
|
|
109729
|
-
* sessions never turn on.
|
|
109730
|
-
*/
|
|
109731
|
-
buildPaths(entry, data, stride, outline) {
|
|
109732
|
-
const target = outline ? entry.outlines : entry.fills;
|
|
109733
|
-
for (const lbl of entry.labels) {
|
|
109734
|
-
target.set(lbl, outline
|
|
109735
|
-
? extractLabelOutline(data, entry.W, entry.H, lbl, stride, 0)
|
|
109736
|
-
: extractLabelContours(data, entry.W, entry.H, lbl, stride, 0));
|
|
109737
|
-
}
|
|
109738
|
-
}
|
|
109739
109888
|
/**
|
|
109740
109889
|
* Render a layer's slice onto the target canvas as vector contours.
|
|
109741
109890
|
*
|
|
@@ -109773,96 +109922,8 @@ class RenderingUtils {
|
|
|
109773
109922
|
const volume = this.getVolumeForLayer(layer);
|
|
109774
109923
|
if (!volume)
|
|
109775
109924
|
return;
|
|
109776
|
-
const
|
|
109777
|
-
|
|
109778
|
-
// Cache miss → run the expensive extraction once. Hits (zoom,
|
|
109779
|
-
// recomposite, contrast toggle) skip straight to the draw below.
|
|
109780
|
-
let entry = this._contourCache.get(layer);
|
|
109781
|
-
if (!entry || entry.key !== cacheKey) {
|
|
109782
|
-
const slice = volume.getSliceUint8(sliceIndex, axis);
|
|
109783
|
-
entry = {
|
|
109784
|
-
key: cacheKey,
|
|
109785
|
-
W: slice.width,
|
|
109786
|
-
H: slice.height,
|
|
109787
|
-
labels: findLabelsInSlice(slice.data, slice.width, slice.height, stride, 0),
|
|
109788
|
-
fills: new Map(),
|
|
109789
|
-
outlines: new Map(),
|
|
109790
|
-
};
|
|
109791
|
-
this._contourCache.set(layer, entry);
|
|
109792
|
-
this.buildPaths(entry, slice.data, stride, outline);
|
|
109793
|
-
}
|
|
109794
|
-
else if ((outline ? entry.outlines : entry.fills).size !== entry.labels.length) {
|
|
109795
|
-
// The mode changed since this slice was last drawn, so the other set of
|
|
109796
|
-
// paths is cached and this one is not. Re-read the slice and build it; from
|
|
109797
|
-
// here on both are present and toggling is a pure cache hit.
|
|
109798
|
-
const slice = volume.getSliceUint8(sliceIndex, axis);
|
|
109799
|
-
this.buildPaths(entry, slice.data, stride, outline);
|
|
109800
|
-
}
|
|
109801
|
-
if (entry.labels.length === 0)
|
|
109802
|
-
return;
|
|
109803
|
-
const { W, H, labels } = entry;
|
|
109804
|
-
const paths = outline ? entry.outlines : entry.fills;
|
|
109805
|
-
const channelVis = this.state.gui_states.layerChannel.channelVisibility[layer];
|
|
109806
|
-
targetCtx.save();
|
|
109807
|
-
// Vector drawing — imageSmoothingEnabled is irrelevant here, but keep
|
|
109808
|
-
// it off to match the rest of the pipeline.
|
|
109809
|
-
targetCtx.imageSmoothingEnabled = false;
|
|
109810
|
-
if (outline) {
|
|
109811
|
-
// Stroke on an UNTRANSFORMED context, with the voxel→display mapping carried
|
|
109812
|
-
// in the path instead. `lineWidth` is then measured in screen pixels, which
|
|
109813
|
-
// is what the other two options get wrong: stroking under `ctx.scale(sx, sy)`
|
|
109814
|
-
// thickens the line with the zoom, exactly when the clinician has magnified
|
|
109815
|
-
// the image to look at the boundary — and because voxels are rarely isotropic
|
|
109816
|
-
// (sx !== sy), it also comes out thicker in one axis than the other.
|
|
109817
|
-
const matrix = new DOMMatrix();
|
|
109818
|
-
if (axis === 'y') {
|
|
109819
|
-
matrix.scaleSelf(1, -1);
|
|
109820
|
-
matrix.translateSelf(0, -scaledHeight);
|
|
109821
|
-
}
|
|
109822
|
-
matrix.scaleSelf(scaledWidth / W, scaledHeight / H);
|
|
109823
|
-
targetCtx.lineWidth = OUTLINE_WIDTH_PX;
|
|
109824
|
-
// Segments are emitted per cell and meet at shared endpoints; round caps
|
|
109825
|
-
// close those joins. Canvas composites a whole Path2D in one pass, so the
|
|
109826
|
-
// overlap costs no doubled alpha.
|
|
109827
|
-
targetCtx.lineJoin = 'round';
|
|
109828
|
-
targetCtx.lineCap = 'round';
|
|
109829
|
-
for (const lbl of labels) {
|
|
109830
|
-
if (channelVis && channelVis[lbl] === false)
|
|
109831
|
-
continue;
|
|
109832
|
-
const path = paths.get(lbl);
|
|
109833
|
-
if (!path)
|
|
109834
|
-
continue;
|
|
109835
|
-
const color = volume.getChannelColor(lbl);
|
|
109836
|
-
targetCtx.strokeStyle =
|
|
109837
|
-
`rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
109838
|
-
const display = new Path2D();
|
|
109839
|
-
display.addPath(path, matrix);
|
|
109840
|
-
targetCtx.stroke(display);
|
|
109841
|
-
}
|
|
109842
|
-
targetCtx.restore();
|
|
109843
|
-
return;
|
|
109844
|
-
}
|
|
109845
|
-
// Coronal (axis='y') Z-flip: mirrors the flip applied by the write
|
|
109846
|
-
// path (syncLayerSliceData). Apply BEFORE the voxel→display scale
|
|
109847
|
-
// so the flip operates in display coordinates.
|
|
109848
|
-
if (axis === 'y') {
|
|
109849
|
-
targetCtx.scale(1, -1);
|
|
109850
|
-
targetCtx.translate(0, -scaledHeight);
|
|
109851
|
-
}
|
|
109852
|
-
// Voxel coord (x ∈ [0, W], y ∈ [0, H]) → display coord.
|
|
109853
|
-
targetCtx.scale(scaledWidth / W, scaledHeight / H);
|
|
109854
|
-
for (const lbl of labels) {
|
|
109855
|
-
if (channelVis && channelVis[lbl] === false)
|
|
109856
|
-
continue;
|
|
109857
|
-
const path = paths.get(lbl);
|
|
109858
|
-
if (!path)
|
|
109859
|
-
continue;
|
|
109860
|
-
const color = volume.getChannelColor(lbl);
|
|
109861
|
-
targetCtx.fillStyle =
|
|
109862
|
-
`rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
109863
|
-
targetCtx.fill(path, 'nonzero');
|
|
109864
|
-
}
|
|
109865
|
-
targetCtx.restore();
|
|
109925
|
+
const entry = contourEntry(this._contourCache, layer, `${axis}:${sliceIndex}:${volume.getVersion()}`, () => (Object.assign(Object.assign({}, volume.getSliceUint8(sliceIndex, axis)), { stride: volume.getChannels() })), outline);
|
|
109926
|
+
paintContours(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, (lbl) => volume.getChannelColor(lbl), this.state.gui_states.layerChannel.channelVisibility[layer]);
|
|
109866
109927
|
}
|
|
109867
109928
|
catch (_a) {
|
|
109868
109929
|
// Slice out of bounds or volume not ready — skip silently
|
|
@@ -109902,7 +109963,7 @@ class RenderingUtils {
|
|
|
109902
109963
|
* Only draws layers whose visibility is enabled.
|
|
109903
109964
|
*/
|
|
109904
109965
|
compositeAllLayers() {
|
|
109905
|
-
var _a, _b;
|
|
109966
|
+
var _a, _b, _c, _d;
|
|
109906
109967
|
const masterCtx = this.state.protectedData.ctxes.drawingLayerMasterCtx;
|
|
109907
109968
|
const width = this.state.nrrd_states.view.changedWidth;
|
|
109908
109969
|
const height = this.state.nrrd_states.view.changedHeight;
|
|
@@ -109919,6 +109980,8 @@ class RenderingUtils {
|
|
|
109919
109980
|
masterCtx.restore();
|
|
109920
109981
|
}
|
|
109921
109982
|
}
|
|
109983
|
+
(_c = this.mirror) === null || _c === void 0 ? void 0 : _c.paint(masterCtx, width, height);
|
|
109984
|
+
(_d = this.onComposited) === null || _d === void 0 ? void 0 : _d.call(this);
|
|
109922
109985
|
}
|
|
109923
109986
|
}
|
|
109924
109987
|
|
|
@@ -115119,6 +115182,14 @@ class SliceRenderPipeline extends BaseTool {
|
|
|
115119
115182
|
if (this.ctx.gui_states.mode.sphere) {
|
|
115120
115183
|
return;
|
|
115121
115184
|
}
|
|
115185
|
+
// A mirroring viewer has no layers of its own; its mirror paints in the composite.
|
|
115186
|
+
if (this.callbacks.hasMaskMirror()) {
|
|
115187
|
+
this.callbacks.compositeAllLayers();
|
|
115188
|
+
return;
|
|
115189
|
+
}
|
|
115190
|
+
// A read-only viewer has no layers and nothing to reload.
|
|
115191
|
+
if (this.ctx.nrrd_states.image.layers.length === 0)
|
|
115192
|
+
return;
|
|
115122
115193
|
const axis = this.ctx.protectedData.axis;
|
|
115123
115194
|
let sliceIndex = this.ctx.nrrd_states.view.currentSliceIndex;
|
|
115124
115195
|
// Clamp sliceIndex to valid range for current axis
|
|
@@ -115352,6 +115423,170 @@ class SliceRenderPipeline extends BaseTool {
|
|
|
115352
115423
|
}
|
|
115353
115424
|
}
|
|
115354
115425
|
|
|
115426
|
+
const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
115427
|
+
/** A slice's width and height for `axis`, as `getSliceUint8` lays it out. */
|
|
115428
|
+
function sliceDims(dims, axis) {
|
|
115429
|
+
const [w, h, d] = [dims[0], dims[1], dims[2]];
|
|
115430
|
+
return axis === "z" ? [w, h] : axis === "y" ? [w, d] : [d, h];
|
|
115431
|
+
}
|
|
115432
|
+
/** Whether `m` is the identity within `tol`. No matrix counts as the identity. */
|
|
115433
|
+
function isIdentity(m, tol = 1e-9) {
|
|
115434
|
+
if (!m)
|
|
115435
|
+
return true;
|
|
115436
|
+
for (let i = 0; i < 16; i++) {
|
|
115437
|
+
if (Math.abs(m[i] - IDENTITY[i]) > tol)
|
|
115438
|
+
return false;
|
|
115439
|
+
}
|
|
115440
|
+
return true;
|
|
115441
|
+
}
|
|
115442
|
+
/** Whether the 3×3 part of a row-major 4×4 is diagonal: each axis maps onto its own axis. */
|
|
115443
|
+
function isDiagonal(m, tol = 1e-9) {
|
|
115444
|
+
for (const i of [1, 2, 4, 6, 8, 9]) {
|
|
115445
|
+
if (Math.abs(m[i]) > tol)
|
|
115446
|
+
return false;
|
|
115447
|
+
}
|
|
115448
|
+
return true;
|
|
115449
|
+
}
|
|
115450
|
+
/**
|
|
115451
|
+
* For each mirror index along one axis, the inclusive source index range it covers, clamped
|
|
115452
|
+
* to the source's extent; `lo > hi` when it covers none. A mirror voxel no larger than a
|
|
115453
|
+
* source voxel covers the one nearest its centre; a larger one covers every source voxel
|
|
115454
|
+
* whose centre lies within it.
|
|
115455
|
+
*/
|
|
115456
|
+
function coveredRanges(s, t, count, extent) {
|
|
115457
|
+
const lo = new Int32Array(count);
|
|
115458
|
+
const hi = new Int32Array(count);
|
|
115459
|
+
const half = Math.abs(s) / 2;
|
|
115460
|
+
for (let i = 0; i < count; i++) {
|
|
115461
|
+
const c = s * i + t;
|
|
115462
|
+
let a, b;
|
|
115463
|
+
if (Math.abs(s) <= 1) {
|
|
115464
|
+
a = b = Math.round(c);
|
|
115465
|
+
}
|
|
115466
|
+
else {
|
|
115467
|
+
a = Math.ceil(c - half - 1e-9);
|
|
115468
|
+
b = Math.floor(c + half - 1e-9);
|
|
115469
|
+
}
|
|
115470
|
+
lo[i] = Math.max(a, 0);
|
|
115471
|
+
hi[i] = Math.min(b, extent - 1);
|
|
115472
|
+
}
|
|
115473
|
+
return { lo, hi };
|
|
115474
|
+
}
|
|
115475
|
+
/**
|
|
115476
|
+
* The source's labels on this viewer's slice `index` along `axis`. A cell mapping outside
|
|
115477
|
+
* the source is 0. On the same grid with the identity, it is the source's own slice.
|
|
115478
|
+
*
|
|
115479
|
+
* With a diagonal transform (the axes agree, only scale and offset differ), a mirror voxel
|
|
115480
|
+
* coarser than the source shows the first label found among every source voxel it spans, so
|
|
115481
|
+
* a finding thinner than the mirror's slice still appears on the slice that contains it.
|
|
115482
|
+
* Any other transform samples the nearest source voxel.
|
|
115483
|
+
*/
|
|
115484
|
+
function mirrorSliceLabels(source, mirrorDims, axis, index, m) {
|
|
115485
|
+
const sd = source.getDimensions();
|
|
115486
|
+
if (isIdentity(m) && sd.width === mirrorDims[0] && sd.height === mirrorDims[1] && sd.depth === mirrorDims[2]) {
|
|
115487
|
+
const s = source.getSliceUint8(index, axis);
|
|
115488
|
+
return { data: s.data, width: s.width, height: s.height, stride: source.getChannels() };
|
|
115489
|
+
}
|
|
115490
|
+
const mat = m !== null && m !== void 0 ? m : IDENTITY;
|
|
115491
|
+
const [W, H] = sliceDims(mirrorDims, axis);
|
|
115492
|
+
const raw = source.getRawData();
|
|
115493
|
+
const nch = source.getChannels();
|
|
115494
|
+
const out = new Uint8Array(W * H);
|
|
115495
|
+
if (isDiagonal(mat)) {
|
|
115496
|
+
const rx = coveredRanges(mat[0], mat[3], mirrorDims[0], sd.width);
|
|
115497
|
+
const ry = coveredRanges(mat[5], mat[7], mirrorDims[1], sd.height);
|
|
115498
|
+
const rz = coveredRanges(mat[10], mat[11], mirrorDims[2], sd.depth);
|
|
115499
|
+
for (let v = 0; v < H; v++) {
|
|
115500
|
+
for (let u = 0; u < W; u++) {
|
|
115501
|
+
const x = axis === "x" ? index : u;
|
|
115502
|
+
const y = axis === "y" ? index : v;
|
|
115503
|
+
const z = axis === "z" ? index : axis === "y" ? v : u;
|
|
115504
|
+
let label = 0;
|
|
115505
|
+
for (let sz = rz.lo[z]; sz <= rz.hi[z] && !label; sz++) {
|
|
115506
|
+
for (let sy = ry.lo[y]; sy <= ry.hi[y] && !label; sy++) {
|
|
115507
|
+
for (let sx = rx.lo[x]; sx <= rx.hi[x] && !label; sx++) {
|
|
115508
|
+
label = raw[((sz * sd.height + sy) * sd.width + sx) * nch];
|
|
115509
|
+
}
|
|
115510
|
+
}
|
|
115511
|
+
}
|
|
115512
|
+
out[v * W + u] = label;
|
|
115513
|
+
}
|
|
115514
|
+
}
|
|
115515
|
+
return { data: out, width: W, height: H, stride: 1 };
|
|
115516
|
+
}
|
|
115517
|
+
for (let v = 0; v < H; v++) {
|
|
115518
|
+
for (let u = 0; u < W; u++) {
|
|
115519
|
+
// Slice cell (u, v) -> this viewer's voxel, per getSliceUint8's layout.
|
|
115520
|
+
const x = axis === "x" ? index : u;
|
|
115521
|
+
const y = axis === "y" ? index : v;
|
|
115522
|
+
const z = axis === "z" ? index : axis === "y" ? v : u;
|
|
115523
|
+
const sx = Math.round(mat[0] * x + mat[1] * y + mat[2] * z + mat[3]);
|
|
115524
|
+
const sy = Math.round(mat[4] * x + mat[5] * y + mat[6] * z + mat[7]);
|
|
115525
|
+
const sz = Math.round(mat[8] * x + mat[9] * y + mat[10] * z + mat[11]);
|
|
115526
|
+
if (sx < 0 || sy < 0 || sz < 0 || sx >= sd.width || sy >= sd.height || sz >= sd.depth)
|
|
115527
|
+
continue;
|
|
115528
|
+
out[v * W + u] = raw[((sz * sd.height + sy) * sd.width + sx) * nch];
|
|
115529
|
+
}
|
|
115530
|
+
}
|
|
115531
|
+
return { data: out, width: W, height: H, stride: 1 };
|
|
115532
|
+
}
|
|
115533
|
+
/**
|
|
115534
|
+
* One viewer drawing another's masks. Holds no mask data: every paint reads the source's
|
|
115535
|
+
* volumes and display state. A new transform means a new instance, so the cache never holds
|
|
115536
|
+
* contours from another transform.
|
|
115537
|
+
*/
|
|
115538
|
+
class MaskMirror {
|
|
115539
|
+
constructor(self, source, matrix) {
|
|
115540
|
+
this.self = self;
|
|
115541
|
+
this.source = source;
|
|
115542
|
+
this.matrix = matrix;
|
|
115543
|
+
/** One contour entry per source layer, for the slice last painted. */
|
|
115544
|
+
this.cache = new Map();
|
|
115545
|
+
/** The source volume each cache entry was built from; a case load replaces the object. */
|
|
115546
|
+
this.cachedVolumes = new Map();
|
|
115547
|
+
}
|
|
115548
|
+
/** Paint every visible source layer onto `ctx` for this viewer's current axis and slice. */
|
|
115549
|
+
paint(ctx, width, height) {
|
|
115550
|
+
var _a, _b;
|
|
115551
|
+
// The source hides its own layers in sphere mode, so the mirror shows none either.
|
|
115552
|
+
if (this.source.gui_states.mode.sphere)
|
|
115553
|
+
return;
|
|
115554
|
+
const dims = this.self.nrrd_states.image.dimensions;
|
|
115555
|
+
if (!dims || dims.length !== 3)
|
|
115556
|
+
return;
|
|
115557
|
+
const axis = this.self.protectedData.axis;
|
|
115558
|
+
const index = this.self.nrrd_states.view.currentSliceIndex;
|
|
115559
|
+
const lc = this.source.gui_states.layerChannel;
|
|
115560
|
+
const outline = this.source.gui_states.drawing.maskRenderMode === "outline";
|
|
115561
|
+
for (const layerId of this.source.nrrd_states.image.layers) {
|
|
115562
|
+
if (!lc.layerVisibility[layerId])
|
|
115563
|
+
continue;
|
|
115564
|
+
const volume = this.source.protectedData.maskData.volumes[layerId];
|
|
115565
|
+
if (!volume)
|
|
115566
|
+
continue;
|
|
115567
|
+
if (this.cachedVolumes.get(layerId) !== volume) {
|
|
115568
|
+
this.cache.delete(layerId);
|
|
115569
|
+
this.cachedVolumes.set(layerId, volume);
|
|
115570
|
+
}
|
|
115571
|
+
try {
|
|
115572
|
+
const entry = contourEntry(this.cache, layerId, `${axis}:${index}:${volume.getVersion()}`, () => mirrorSliceLabels(volume, dims, axis, index, this.matrix), outline);
|
|
115573
|
+
ctx.save();
|
|
115574
|
+
try {
|
|
115575
|
+
ctx.globalAlpha = (_b = (_a = lc.layerOpacity) === null || _a === void 0 ? void 0 : _a[layerId]) !== null && _b !== void 0 ? _b : 1;
|
|
115576
|
+
paintContours(entry, ctx, axis, width, height, outline, (l) => volume.getChannelColor(l), lc.channelVisibility[layerId]);
|
|
115577
|
+
}
|
|
115578
|
+
finally {
|
|
115579
|
+
// A throw must not leave this layer's alpha or transform on the master canvas.
|
|
115580
|
+
ctx.restore();
|
|
115581
|
+
}
|
|
115582
|
+
}
|
|
115583
|
+
catch (_c) {
|
|
115584
|
+
// The source is not ready for this slice: nothing to draw for this layer.
|
|
115585
|
+
}
|
|
115586
|
+
}
|
|
115587
|
+
}
|
|
115588
|
+
}
|
|
115589
|
+
|
|
115355
115590
|
/**
|
|
115356
115591
|
* NrrdTools.setMasksFromNIfTI forwards its `Map<string, Uint8Array>` argument
|
|
115357
115592
|
* straight through to here with no second channel for metadata, so a caller that
|
|
@@ -115633,7 +115868,15 @@ class NrrdTools {
|
|
|
115633
115868
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
115634
115869
|
constructor(container, options) {
|
|
115635
115870
|
this._sliceRAFId = null;
|
|
115871
|
+
/** Viewers drawing this one's masks (see setMaskMirror). */
|
|
115872
|
+
this._mirrors = new Set();
|
|
115873
|
+
/** The viewer whose masks this one draws, if any. */
|
|
115874
|
+
this._mirrorSource = null;
|
|
115875
|
+
/** The pending frame that refreshes this viewer's mirrors. */
|
|
115876
|
+
this._mirrorFrame = null;
|
|
115636
115877
|
this._pendingSliceStep = 0;
|
|
115878
|
+
/** Receives slice moves while a preview slice is shown; null when none is. */
|
|
115879
|
+
this._previewSliceMove = null;
|
|
115637
115880
|
/** Whether calculator mode is active (not part of gui_states interface) */
|
|
115638
115881
|
this._calculatorActive = false;
|
|
115639
115882
|
/**
|
|
@@ -115666,6 +115909,8 @@ class NrrdTools {
|
|
|
115666
115909
|
this.drawCore = new DrawToolCore(container, this.state);
|
|
115667
115910
|
// Wire DrawToolCore's overridable methods to NrrdTools implementations
|
|
115668
115911
|
this.wireDrawCoreMethods();
|
|
115912
|
+
// Every visible mask change ends in a composite; the viewers mirroring this one follow it.
|
|
115913
|
+
this.drawCore.renderer.onComposited = () => this.scheduleMirrorRefresh();
|
|
115669
115914
|
// Wire RenderingUtils' setEmptyCanvasSize callback
|
|
115670
115915
|
this.drawCore.renderer.setEmptyCanvasSize = (axis) => this.setEmptyCanvasSize(axis);
|
|
115671
115916
|
this.init();
|
|
@@ -115676,6 +115921,7 @@ class NrrdTools {
|
|
|
115676
115921
|
}
|
|
115677
115922
|
// Wire sphere overlay refresh callback into DragOperator → DragSliceTool
|
|
115678
115923
|
this.dragOperator.setRefreshSphereOverlay(() => this.refreshSphereOverlay());
|
|
115924
|
+
this.dragOperator.setPreviewSliceMove((index) => this.previewSliceMove(index));
|
|
115679
115925
|
// Initialize extracted modules
|
|
115680
115926
|
this.initNrrdToolsModules();
|
|
115681
115927
|
}
|
|
@@ -115723,6 +115969,7 @@ class NrrdTools {
|
|
|
115723
115969
|
});
|
|
115724
115970
|
this.sliceRenderPipeline = new SliceRenderPipeline(toolCtx, {
|
|
115725
115971
|
compositeAllLayers: () => this.drawCore.renderer.compositeAllLayers(),
|
|
115972
|
+
hasMaskMirror: () => this._mirrorSource !== null,
|
|
115726
115973
|
getOrCreateSliceBuffer: (axis) => this.drawCore.renderer.getOrCreateSliceBuffer(axis),
|
|
115727
115974
|
renderSliceToCanvas: (layer, axis, sliceIndex, buffer, targetCtx, w, h) => this.drawCore.renderer.renderSliceToCanvas(layer, axis, sliceIndex, buffer, targetCtx, w, h),
|
|
115728
115975
|
getVolumeForLayer: (layer) => this.drawCore.renderer.getVolumeForLayer(layer),
|
|
@@ -116491,10 +116738,49 @@ class NrrdTools {
|
|
|
116491
116738
|
* Used for register/origin image switching where the view state should persist.
|
|
116492
116739
|
*/
|
|
116493
116740
|
switchSlicesPreservingView(allSlices) {
|
|
116741
|
+
this._previewSliceMove = null;
|
|
116494
116742
|
this.state.protectedData.allSlicesArray.length = 0;
|
|
116495
116743
|
this.state.protectedData.allSlicesArray = [...allSlices];
|
|
116496
116744
|
this.sliceRenderPipeline.switchPreservingView();
|
|
116497
116745
|
}
|
|
116746
|
+
/**
|
|
116747
|
+
* Show one slice of a volume before the volume itself has loaded: `header` is the full
|
|
116748
|
+
* volume's geometry, `slice` a depth-1 slice triple of plane `index` (built from one plane's
|
|
116749
|
+
* voxels), shown as slice `index` of the full stack. Geometry is re-initialised only when it
|
|
116750
|
+
* differs from the current one. Replaces whatever slice data is displayed; writes no mask.
|
|
116751
|
+
* The full volume later replaces it with `switchSlicesPreservingView`, keeping `index`.
|
|
116752
|
+
*
|
|
116753
|
+
* Until then every slice move (wheel, keys, drag, `setSliceMoving`) goes to `onSliceMove`
|
|
116754
|
+
* with its clamped target index instead of moving the displayed slice. Axial only; it does
|
|
116755
|
+
* not switch orientation.
|
|
116756
|
+
*/
|
|
116757
|
+
showPreviewSlice(header, slice, index, onSliceMove) {
|
|
116758
|
+
const image = this.state.nrrd_states.image;
|
|
116759
|
+
const same = (a, b) => !!a && a.length === b.length && Array.from(b).every((v, i) => a[i] === v);
|
|
116760
|
+
if (!same(image.dimensions, header.dimensions) ||
|
|
116761
|
+
!same(image.voxelSpacing, header.spacing) ||
|
|
116762
|
+
!same(image.spaceOrigin, header.space_origin)) {
|
|
116763
|
+
this.dataLoader.initFromHeader(header);
|
|
116764
|
+
}
|
|
116765
|
+
slice.z.initIndex = index;
|
|
116766
|
+
this.state.protectedData.allSlicesArray.length = 0;
|
|
116767
|
+
// Take the index from `initIndex` rather than writing the full-stack index into the
|
|
116768
|
+
// depth-1 slice's own `index`, which would be out of range for it.
|
|
116769
|
+
this.sliceRenderPipeline.resetInitState();
|
|
116770
|
+
this.dataLoader.appendSlice(slice, 0);
|
|
116771
|
+
this._previewSliceMove = onSliceMove;
|
|
116772
|
+
}
|
|
116773
|
+
/** Whether a preview slice from `showPreviewSlice` is shown in place of a loaded volume. */
|
|
116774
|
+
isPreviewing() {
|
|
116775
|
+
return this._previewSliceMove !== null;
|
|
116776
|
+
}
|
|
116777
|
+
/** Hands a slice move to the preview's host; false when no preview is shown. */
|
|
116778
|
+
previewSliceMove(index) {
|
|
116779
|
+
if (!this._previewSliceMove)
|
|
116780
|
+
return false;
|
|
116781
|
+
this._previewSliceMove(index);
|
|
116782
|
+
return true;
|
|
116783
|
+
}
|
|
116498
116784
|
appendLoadingbar(loadingbar) {
|
|
116499
116785
|
this.state.protectedData.mainAreaContainer.appendChild(loadingbar);
|
|
116500
116786
|
}
|
|
@@ -116606,7 +116892,10 @@ class NrrdTools {
|
|
|
116606
116892
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
116607
116893
|
// 9. Delegated — DataLoader
|
|
116608
116894
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
116609
|
-
setAllSlices(allSlices) {
|
|
116895
|
+
setAllSlices(allSlices) {
|
|
116896
|
+
this._previewSliceMove = null;
|
|
116897
|
+
this.dataLoader.setAllSlices(allSlices);
|
|
116898
|
+
}
|
|
116610
116899
|
setMasksData(masksData, loadingBar) { this.dataLoader.setMasksData(masksData, loadingBar); }
|
|
116611
116900
|
setMasksFromNIfTI(layerVoxels, loadingBar) { this.dataLoader.setMasksFromNIfTI(layerVoxels, loadingBar); }
|
|
116612
116901
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -116872,6 +117161,7 @@ class NrrdTools {
|
|
|
116872
117161
|
this.reloadMasksFromVolume();
|
|
116873
117162
|
}
|
|
116874
117163
|
reset() {
|
|
117164
|
+
this._previewSliceMove = null;
|
|
116875
117165
|
this.state.protectedData.allSlicesArray.length = 0;
|
|
116876
117166
|
this.state.protectedData.displaySlices.length = 0;
|
|
116877
117167
|
this.drawCore.undoManager.clearAll();
|
|
@@ -116903,10 +117193,41 @@ class NrrdTools {
|
|
|
116903
117193
|
this.state.nrrd_states.sphere.skinSphereOrigin = null;
|
|
116904
117194
|
this.state.nrrd_states.sphere.nippleSphereOrigin = null;
|
|
116905
117195
|
}
|
|
117196
|
+
/**
|
|
117197
|
+
* Draw `source`'s masks on this viewer, read live from it: its volumes, colours, channel and
|
|
117198
|
+
* layer visibility, opacity and render mode. `mirrorToSource` is a row-major 4×4 from this
|
|
117199
|
+
* viewer's voxel (x, y, z, 1) to the source's voxel; omitted means the identity. `null`
|
|
117200
|
+
* detaches. Display only — nothing is written to either viewer's masks.
|
|
117201
|
+
*/
|
|
117202
|
+
setMaskMirror(source, mirrorToSource) {
|
|
117203
|
+
var _a, _b;
|
|
117204
|
+
(_a = this._mirrorSource) === null || _a === void 0 ? void 0 : _a._mirrors.delete(this);
|
|
117205
|
+
this._mirrorSource = source && source !== this ? source : null;
|
|
117206
|
+
this.drawCore.renderer.mirror = this._mirrorSource
|
|
117207
|
+
? new MaskMirror(this.state, this._mirrorSource.state, mirrorToSource !== null && mirrorToSource !== void 0 ? mirrorToSource : null)
|
|
117208
|
+
: null;
|
|
117209
|
+
(_b = this._mirrorSource) === null || _b === void 0 ? void 0 : _b._mirrors.add(this);
|
|
117210
|
+
this.drawCore.renderer.compositeAllLayers();
|
|
117211
|
+
}
|
|
117212
|
+
/** The viewer whose masks this one draws, or null. */
|
|
117213
|
+
getMaskMirrorSource() {
|
|
117214
|
+
return this._mirrorSource;
|
|
117215
|
+
}
|
|
117216
|
+
/** Repaint every mirror of this viewer on the next frame; repeated calls coalesce. */
|
|
117217
|
+
scheduleMirrorRefresh() {
|
|
117218
|
+
if (this._mirrors.size === 0 || this._mirrorFrame !== null)
|
|
117219
|
+
return;
|
|
117220
|
+
this._mirrorFrame = requestAnimationFrame(() => {
|
|
117221
|
+
this._mirrorFrame = null;
|
|
117222
|
+
for (const m of this._mirrors)
|
|
117223
|
+
m.drawCore.renderer.compositeAllLayers();
|
|
117224
|
+
});
|
|
117225
|
+
}
|
|
116906
117226
|
/**
|
|
116907
117227
|
* Releases what this instance holds outside its own DOM subtree, so a viewer that is torn
|
|
116908
117228
|
* down can be garbage-collected: the event router's listeners (its window `blur` listener
|
|
116909
|
-
* reaches the whole engine graph), a pending slice step
|
|
117229
|
+
* reaches the whole engine graph), a pending slice step, the drawing-flag timer and any
|
|
117230
|
+
* mask-mirror link.
|
|
116910
117231
|
*
|
|
116911
117232
|
* The instance must not be used afterwards. Safe to call more than once.
|
|
116912
117233
|
*/
|
|
@@ -116922,6 +117243,22 @@ class NrrdTools {
|
|
|
116922
117243
|
window.clearTimeout(this.preTimer);
|
|
116923
117244
|
this.preTimer = undefined;
|
|
116924
117245
|
}
|
|
117246
|
+
// Release the mirror link from both ends, so neither viewer keeps the other alive.
|
|
117247
|
+
if (this._mirrorSource) {
|
|
117248
|
+
this._mirrorSource._mirrors.delete(this);
|
|
117249
|
+
this._mirrorSource = null;
|
|
117250
|
+
this.drawCore.renderer.mirror = null;
|
|
117251
|
+
}
|
|
117252
|
+
for (const m of this._mirrors) {
|
|
117253
|
+
m._mirrorSource = null;
|
|
117254
|
+
m.drawCore.renderer.mirror = null;
|
|
117255
|
+
m.drawCore.renderer.compositeAllLayers();
|
|
117256
|
+
}
|
|
117257
|
+
this._mirrors.clear();
|
|
117258
|
+
if (this._mirrorFrame !== null) {
|
|
117259
|
+
cancelAnimationFrame(this._mirrorFrame);
|
|
117260
|
+
this._mirrorFrame = null;
|
|
117261
|
+
}
|
|
116925
117262
|
}
|
|
116926
117263
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
116927
117264
|
// 12. Internal — Input Events
|
|
@@ -118226,15 +118563,15 @@ function installFastSliceRepaint(rawSlice_1) {
|
|
|
118226
118563
|
}
|
|
118227
118564
|
|
|
118228
118565
|
// import * as kiwrious from "copper3d_plugin_heart_k";
|
|
118229
|
-
// "v3.11.
|
|
118566
|
+
// "v3.11.6" is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
|
|
118230
118567
|
// When copper3d is consumed from local source (no rollup replace step), the identifier is undefined and
|
|
118231
118568
|
// referencing it throws a ReferenceError — guard it so local loading still works.
|
|
118232
118569
|
let _revision = "unknown";
|
|
118233
118570
|
try {
|
|
118234
|
-
_revision = "v3.11.
|
|
118571
|
+
_revision = "v3.11.6";
|
|
118235
118572
|
}
|
|
118236
118573
|
catch (_a) {
|
|
118237
|
-
/* "v3.11.
|
|
118574
|
+
/* "v3.11.6" not injected (local source build) */
|
|
118238
118575
|
}
|
|
118239
118576
|
const REVISION = _revision;
|
|
118240
118577
|
// Expose on global so the version can be read in a production browser console via window.__COPPER3D_VERSION__
|
|
@@ -118245,4 +118582,4 @@ if (typeof console !== "undefined") {
|
|
|
118245
118582
|
console.log(`%cCopper3D Visualisation %c${REVISION}`, "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
|
|
118246
118583
|
}
|
|
118247
118584
|
|
|
118248
|
-
export { AI_CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, CameraViewPoint, Copper3dOrbitControls, Copper3dTrackballControls, DEFAULT_AXES, DEFAULT_TARGET_GREY, GaussianSmoother, MAX_ENGINE_CHANNEL, MeshNodeTool, NrrdTools, REVISION, SurfaceAnnotator, VOLUME_BOUNDS_NAME, addBoxHelper, addLabelToScene, addVolumeBoundingBox, beginGesture, collectFadeTargets, configKiwriousHeart, convert3DPostoScreenPos, convertScreenPosto3DPos, copperGltfLoader, copperMScene, copperMSceneRenderer, copperRenderer, copperRendererOnDemond, copperScene, copperSceneOnDemond, createSceneBudget, createTexture2D_NRRD, defaultBudgetBytes, disposeMaterial, disposeObject3D, disposeScene, easeInOutCubic, ensureAxisExtracted, exposureExponent, fitDistance, fitView, fullScreenListenner, installFastSliceRepaint, interpolateFlightPose, isGestureActive, isPanEnabled, isRotateEnabled, isZoomEnabled, kiwrious, loadKiwrious, loading$1 as loading, orbitStepPose, orbitSwingAngle, poseDistance, registerNiftiMaskGrid, removeGuiFolderChilden, removeSceneFromMap, restoreFade, rgbaToCss, rgbaToHex, rotateAroundAxis, setCameraPose, setDracoDecoderPath, setFade, setHDRFilePath, setKTX2TranscoderPath, setPanEnabled, setRotateEnabled, setZoomEnabled, throttle, viewPointToPose, zoomPose };
|
|
118585
|
+
export { AI_CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, CameraViewPoint, Copper3dOrbitControls, Copper3dTrackballControls, DEFAULT_AXES, DEFAULT_TARGET_GREY, GaussianSmoother, MAX_ENGINE_CHANNEL, MeshNodeTool, NrrdTools, REVISION, SurfaceAnnotator, VOLUME_BOUNDS_NAME, addBoxHelper, addLabelToScene, addVolumeBoundingBox, beginGesture, collectFadeTargets, configKiwriousHeart, convert3DPostoScreenPos, convertScreenPosto3DPos, copperGltfLoader, copperMScene, copperMSceneRenderer, copperRenderer, copperRendererOnDemond, copperScene, copperSceneOnDemond, createSceneBudget, createTexture2D_NRRD, defaultBudgetBytes, disposeMaterial, disposeObject3D, disposeScene, easeInOutCubic, ensureAxisExtracted, exposureExponent, fitDistance, fitView, fullScreenListenner, installFastSliceRepaint, interpolateFlightPose, isGestureActive, isPanEnabled, isRotateEnabled, isZoomEnabled, kiwrious, loadKiwrious, loading$1 as loading, orbitStepPose, orbitSwingAngle, poseDistance, prepareVolumeSlices, registerNiftiMaskGrid, removeGuiFolderChilden, removeSceneFromMap, restoreFade, rgbaToCss, rgbaToHex, rotateAroundAxis, setCameraPose, setDracoDecoderPath, setFade, setHDRFilePath, setKTX2TranscoderPath, setPanEnabled, setRotateEnabled, setZoomEnabled, throttle, viewPointToPose, zoomPose };
|