copper3d 3.10.1 → 3.10.3
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 +23 -3
- package/dist/Utils/segmentation/DrawToolCore.js +1 -0
- package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +41 -1
- package/dist/Utils/segmentation/NrrdTools.js +76 -0
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +32 -0
- package/dist/Utils/segmentation/RenderingUtils.js +107 -12
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
- package/dist/Utils/segmentation/core/MarchingSquares.d.ts +26 -0
- package/dist/Utils/segmentation/core/MarchingSquares.js +113 -0
- package/dist/Utils/segmentation/core/MarchingSquares.js.map +1 -1
- package/dist/Utils/segmentation/core/MaskVolume.d.ts +32 -5
- package/dist/Utils/segmentation/core/MaskVolume.js +95 -18
- package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
- package/dist/Utils/segmentation/core/index.d.ts +3 -3
- package/dist/Utils/segmentation/core/index.js +2 -2
- package/dist/Utils/segmentation/core/index.js.map +1 -1
- package/dist/Utils/segmentation/core/types.d.ts +32 -21
- package/dist/Utils/segmentation/core/types.js +77 -10
- package/dist/Utils/segmentation/core/types.js.map +1 -1
- package/dist/Utils/segmentation/coreTools/GuiState.js +2 -0
- package/dist/Utils/segmentation/coreTools/GuiState.js.map +1 -1
- package/dist/Utils/segmentation/tools/DrawingTool.d.ts +19 -2
- package/dist/Utils/segmentation/tools/DrawingTool.js +30 -6
- package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ToolHost.d.ts +7 -1
- package/dist/bundle.esm.js +503 -48
- package/dist/bundle.umd.js +503 -47
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +41 -1
- package/dist/types/Utils/segmentation/RenderingUtils.d.ts +32 -0
- package/dist/types/Utils/segmentation/core/MarchingSquares.d.ts +26 -0
- package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +32 -5
- package/dist/types/Utils/segmentation/core/index.d.ts +3 -3
- package/dist/types/Utils/segmentation/core/types.d.ts +32 -21
- package/dist/types/Utils/segmentation/tools/DrawingTool.d.ts +19 -2
- package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +7 -1
- package/dist/types/index.d.ts +4 -3
- package/package.json +1 -1
package/dist/bundle.esm.js
CHANGED
|
@@ -106318,7 +106318,65 @@ var RenderMode;
|
|
|
106318
106318
|
* | 7 | Auxiliary annotation | Orange |
|
|
106319
106319
|
* | 8 | Extended annotation | Purple |
|
|
106320
106320
|
*/
|
|
106321
|
-
|
|
106321
|
+
/**
|
|
106322
|
+
* The largest label a mask voxel can carry. `MaskVolume` stores one byte per voxel and the
|
|
106323
|
+
* value IS the label, so 0 is empty and 1-255 are annotation channels.
|
|
106324
|
+
*/
|
|
106325
|
+
const MAX_ENGINE_CHANNEL = 255;
|
|
106326
|
+
/** Highest channel whose colour is delivered rather than generated. */
|
|
106327
|
+
const SEEDED_CHANNELS = 8;
|
|
106328
|
+
/**
|
|
106329
|
+
* Successive hues this far apart never revisit an earlier one, which is the whole reason to
|
|
106330
|
+
* use it: any prefix of the sequence is about as spread out as that many hues can be.
|
|
106331
|
+
*/
|
|
106332
|
+
const GOLDEN_ANGLE_DEGREES = 137.508;
|
|
106333
|
+
/**
|
|
106334
|
+
* The colour for a channel past the delivered eight.
|
|
106335
|
+
*
|
|
106336
|
+
* Saturation and lightness are fixed so the only thing that varies is hue: these sit on
|
|
106337
|
+
* greyscale MRI, where a mask that changes brightness between channels reads as a difference
|
|
106338
|
+
* in the image rather than in the annotation.
|
|
106339
|
+
*
|
|
106340
|
+
* Distinct is not the same as distinguishable. Past roughly twenty, neighbouring hues stop
|
|
106341
|
+
* being tellable apart by eye on a greyscale background; that is a limit on how many findings
|
|
106342
|
+
* a product should offer at once, not on what this function will return.
|
|
106343
|
+
*/
|
|
106344
|
+
function generatedChannelColor(channel) {
|
|
106345
|
+
const hue = ((channel - SEEDED_CHANNELS - 1) * GOLDEN_ANGLE_DEGREES) % 360;
|
|
106346
|
+
return hslToRgba(hue, 0.68, 0.55);
|
|
106347
|
+
}
|
|
106348
|
+
/** HSL (h in degrees, s and l in 0-1) to the 0-255 RGBA this module stores. */
|
|
106349
|
+
function hslToRgba(h, s, l) {
|
|
106350
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
106351
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
106352
|
+
const m = l - c / 2;
|
|
106353
|
+
const [r, g, b] = h < 60 ? [c, x, 0] :
|
|
106354
|
+
h < 120 ? [x, c, 0] :
|
|
106355
|
+
h < 180 ? [0, c, x] :
|
|
106356
|
+
h < 240 ? [0, x, c] :
|
|
106357
|
+
h < 300 ? [x, 0, c] :
|
|
106358
|
+
[c, 0, x];
|
|
106359
|
+
const to255 = (v) => Math.round((v + m) * 255);
|
|
106360
|
+
return { r: to255(r), g: to255(g), b: to255(b), a: 255 };
|
|
106361
|
+
}
|
|
106362
|
+
/**
|
|
106363
|
+
* A delivered 0-8 table, continued to 255 with generated colours.
|
|
106364
|
+
*
|
|
106365
|
+
* The seeds are kept verbatim rather than regenerated: every delivered case's chips, 3D
|
|
106366
|
+
* overlay tints and printed report outlines are keyed on them, so a formula that happened to
|
|
106367
|
+
* produce different values would silently recolour work already read and signed off.
|
|
106368
|
+
*
|
|
106369
|
+
* Built eagerly rather than behind a Proxy. `applyLayerChannelColors` walks these with
|
|
106370
|
+
* `Object.entries`, which a Proxy's `get` trap would not serve.
|
|
106371
|
+
*/
|
|
106372
|
+
function extendPalette(seed, from) {
|
|
106373
|
+
const table = Object.assign({}, seed);
|
|
106374
|
+
for (let channel = SEEDED_CHANNELS + 1; channel <= MAX_ENGINE_CHANNEL; channel++) {
|
|
106375
|
+
table[channel] = from(generatedChannelColor(channel));
|
|
106376
|
+
}
|
|
106377
|
+
return table;
|
|
106378
|
+
}
|
|
106379
|
+
const MASK_CHANNEL_COLORS_SEED = {
|
|
106322
106380
|
0: { r: 0, g: 0, b: 0, a: 0 }, // Background (transparent)
|
|
106323
106381
|
1: { r: 16, g: 185, b: 129, a: 255 }, // Emerald / Soft Green — Primary / Tumor
|
|
106324
106382
|
2: { r: 244, g: 63, b: 94, a: 255 }, // Rose / Soft Red — Secondary / Edema
|
|
@@ -106332,7 +106390,7 @@ const MASK_CHANNEL_COLORS = {
|
|
|
106332
106390
|
/**
|
|
106333
106391
|
* CSS color strings for the default channel palette (for reference / UI).
|
|
106334
106392
|
*/
|
|
106335
|
-
const
|
|
106393
|
+
const MASK_CHANNEL_CSS_COLORS_SEED = {
|
|
106336
106394
|
0: 'rgba(0,0,0,0)',
|
|
106337
106395
|
1: 'rgba(16,185,129,1)', // Emerald
|
|
106338
106396
|
2: 'rgba(244,63,94,1)', // Rose
|
|
@@ -106343,15 +106401,10 @@ const MASK_CHANNEL_CSS_COLORS = {
|
|
|
106343
106401
|
7: 'rgba(249,115,22,1)', // Orange
|
|
106344
106402
|
8: 'rgba(139,92,246,1)', // Violet
|
|
106345
106403
|
};
|
|
106346
|
-
/**
|
|
106347
|
-
* Convenience alias for MASK_CHANNEL_CSS_COLORS.
|
|
106348
|
-
* Used by Vue components via `Copper.CHANNEL_COLORS[channel]`.
|
|
106349
|
-
*/
|
|
106350
|
-
const CHANNEL_COLORS = MASK_CHANNEL_CSS_COLORS;
|
|
106351
106404
|
/**
|
|
106352
106405
|
* Hex color strings for each channel (no alpha), used for fillColor/brushColor.
|
|
106353
106406
|
*/
|
|
106354
|
-
const
|
|
106407
|
+
const CHANNEL_HEX_COLORS_SEED = {
|
|
106355
106408
|
0: '#000000',
|
|
106356
106409
|
1: '#10b981', // Emerald
|
|
106357
106410
|
2: '#f43f5e', // Rose
|
|
@@ -106370,7 +106423,7 @@ const CHANNEL_HEX_COLORS = {
|
|
|
106370
106423
|
* Applied ONLY to the AI scratch layer (set per-volume in AiAssistTool.enter) —
|
|
106371
106424
|
* the global palette above is untouched, so the clinician mask stays emerald.
|
|
106372
106425
|
*/
|
|
106373
|
-
const
|
|
106426
|
+
const AI_MASK_CHANNEL_COLORS_SEED = {
|
|
106374
106427
|
0: { r: 0, g: 0, b: 0, a: 0 },
|
|
106375
106428
|
1: { r: 94, g: 200, b: 255, a: 255 }, // Cyan (#5ec8ff) — AI accent (was emerald)
|
|
106376
106429
|
2: { r: 244, g: 63, b: 94, a: 255 }, // Rose
|
|
@@ -106381,7 +106434,7 @@ const AI_MASK_CHANNEL_COLORS = {
|
|
|
106381
106434
|
7: { r: 249, g: 115, b: 22, a: 255 }, // Orange
|
|
106382
106435
|
8: { r: 139, g: 92, b: 246, a: 255 }, // Violet
|
|
106383
106436
|
};
|
|
106384
|
-
const
|
|
106437
|
+
const AI_CHANNEL_HEX_COLORS_SEED = {
|
|
106385
106438
|
0: '#000000',
|
|
106386
106439
|
1: '#5ec8ff', // Cyan — AI accent
|
|
106387
106440
|
2: '#f43f5e', // Rose
|
|
@@ -106392,6 +106445,20 @@ const AI_CHANNEL_HEX_COLORS = {
|
|
|
106392
106445
|
7: '#f97316', // Orange
|
|
106393
106446
|
8: '#8b5cf6', // Violet
|
|
106394
106447
|
};
|
|
106448
|
+
// ── The four palettes, delivered through channel 8 and generated past it ──────
|
|
106449
|
+
const MASK_CHANNEL_COLORS = extendPalette(MASK_CHANNEL_COLORS_SEED, (c) => c);
|
|
106450
|
+
const MASK_CHANNEL_CSS_COLORS = extendPalette(MASK_CHANNEL_CSS_COLORS_SEED, rgbaToCss);
|
|
106451
|
+
const CHANNEL_HEX_COLORS = extendPalette(CHANNEL_HEX_COLORS_SEED, rgbaToHex);
|
|
106452
|
+
const AI_MASK_CHANNEL_COLORS = extendPalette(AI_MASK_CHANNEL_COLORS_SEED, (c) => c);
|
|
106453
|
+
const AI_CHANNEL_HEX_COLORS = extendPalette(AI_CHANNEL_HEX_COLORS_SEED, rgbaToHex);
|
|
106454
|
+
/**
|
|
106455
|
+
* Convenience alias for MASK_CHANNEL_CSS_COLORS.
|
|
106456
|
+
* Used by Vue components via `Copper.CHANNEL_COLORS[channel]`.
|
|
106457
|
+
*
|
|
106458
|
+
* Declared here, with the tables it aliases. It used to sit further up, which was fine while
|
|
106459
|
+
* those were object literals and is a temporal-dead-zone error now that they are built.
|
|
106460
|
+
*/
|
|
106461
|
+
const CHANNEL_COLORS = MASK_CHANNEL_CSS_COLORS;
|
|
106395
106462
|
// ── Color Conversion Utilities ──────────────────────────────────────────
|
|
106396
106463
|
/**
|
|
106397
106464
|
* Convert an RGBAColor to a hex string (no alpha), e.g. '#ff0000'.
|
|
@@ -106573,16 +106640,16 @@ class MaskVolume {
|
|
|
106573
106640
|
* Update the color for a specific label/channel in the color map.
|
|
106574
106641
|
*
|
|
106575
106642
|
* For label-based volumes (1-channel), the channel parameter refers to
|
|
106576
|
-
* the label value
|
|
106643
|
+
* the label value, not the storage channel index.
|
|
106577
106644
|
*
|
|
106578
|
-
* @param channel Label/channel index to update (0
|
|
106645
|
+
* @param channel Label/channel index to update (0-`MAX_ENGINE_CHANNEL`).
|
|
106579
106646
|
* @param color New RGBA color.
|
|
106580
106647
|
*
|
|
106581
|
-
* @throws {RangeError} If channel is outside
|
|
106648
|
+
* @throws {RangeError} If channel is outside the storable label range.
|
|
106582
106649
|
*/
|
|
106583
106650
|
setChannelColor(channel, color) {
|
|
106584
|
-
if (channel < 0 || channel >
|
|
106585
|
-
throw new RangeError(`Invalid channel/label: ${channel} (valid range: 0
|
|
106651
|
+
if (channel < 0 || channel > MAX_ENGINE_CHANNEL) {
|
|
106652
|
+
throw new RangeError(`Invalid channel/label: ${channel} (valid range: 0-${MAX_ENGINE_CHANNEL})`);
|
|
106586
106653
|
}
|
|
106587
106654
|
this.colorMap[channel] = { r: color.r, g: color.g, b: color.b, a: color.a };
|
|
106588
106655
|
}
|
|
@@ -106812,7 +106879,8 @@ class MaskVolume {
|
|
|
106812
106879
|
* @param sliceIndex Index along the specified axis.
|
|
106813
106880
|
* @param imageData Canvas ImageData (RGBA) to convert.
|
|
106814
106881
|
* @param axis `'x'`, `'y'`, or `'z'`.
|
|
106815
|
-
* @param activeChannel Fallback label for pixels whose RGB
|
|
106882
|
+
* @param activeChannel Fallback label for pixels whose RGB matches no channel exactly,
|
|
106883
|
+
* and one of the candidates the nearest-colour search considers.
|
|
106816
106884
|
* @param channelVisible Optional map of visible channels (true=visible, false=hidden).
|
|
106817
106885
|
* If provided, data for hidden channels will be preserved
|
|
106818
106886
|
* when the canvas pixel is transparent.
|
|
@@ -106859,6 +106927,29 @@ class MaskVolume {
|
|
|
106859
106927
|
iStride = this.bytesPerSlice; // i → z
|
|
106860
106928
|
break;
|
|
106861
106929
|
}
|
|
106930
|
+
// Candidates for the nearest-colour fallback below: the labels already on this slice,
|
|
106931
|
+
// plus the one being committed. One cheap pass to collect them, in place of running the
|
|
106932
|
+
// fallback over the whole palette.
|
|
106933
|
+
//
|
|
106934
|
+
// Widening it to all 255 would not just be 255 distance computations per anti-aliased
|
|
106935
|
+
// edge pixel. It would be wrong: the more colours the guess can choose from, the more
|
|
106936
|
+
// readily a fringe resolves to a label that is nowhere on the slice, which puts voxels
|
|
106937
|
+
// into another finding's mask with nothing to show for it.
|
|
106938
|
+
const candidates = [activeChannel];
|
|
106939
|
+
{
|
|
106940
|
+
const seen = new Set([activeChannel]);
|
|
106941
|
+
for (let j = 0; j < expectedH; j++) {
|
|
106942
|
+
let idx = baseIndex + j * jStride;
|
|
106943
|
+
for (let i = 0; i < expectedW; i++) {
|
|
106944
|
+
const label = volData[idx];
|
|
106945
|
+
if (label !== 0 && !seen.has(label)) {
|
|
106946
|
+
seen.add(label);
|
|
106947
|
+
candidates.push(label);
|
|
106948
|
+
}
|
|
106949
|
+
idx += iStride;
|
|
106950
|
+
}
|
|
106951
|
+
}
|
|
106952
|
+
}
|
|
106862
106953
|
let px = 0;
|
|
106863
106954
|
for (let j = 0; j < expectedH; j++) {
|
|
106864
106955
|
let idx = baseIndex + j * jStride;
|
|
@@ -106887,8 +106978,10 @@ class MaskVolume {
|
|
|
106887
106978
|
if (matchedChannel === undefined) {
|
|
106888
106979
|
let minDist = Infinity;
|
|
106889
106980
|
let bestChannel = activeChannel;
|
|
106890
|
-
//
|
|
106891
|
-
|
|
106981
|
+
// Nearest among the labels that can legitimately be here (see `candidates`),
|
|
106982
|
+
// to handle Canvas anti-aliased edge pixels.
|
|
106983
|
+
for (let ci = 0; ci < candidates.length; ci++) {
|
|
106984
|
+
const ch = candidates[ci];
|
|
106892
106985
|
const c = (_a = this.colorMap[ch]) !== null && _a !== void 0 ? _a : MASK_CHANNEL_COLORS[ch];
|
|
106893
106986
|
if (!c)
|
|
106894
106987
|
continue;
|
|
@@ -106912,19 +107005,25 @@ class MaskVolume {
|
|
|
106912
107005
|
}
|
|
106913
107006
|
/**
|
|
106914
107007
|
* Build a Map from RGB packed integer to channel label for reverse lookup.
|
|
106915
|
-
*
|
|
107008
|
+
* Covers every label this instance has a colour for, skipping 0 (transparent).
|
|
106916
107009
|
*
|
|
106917
107010
|
* Instance method ensures custom per-layer colors are correctly reverse-mapped.
|
|
106918
107011
|
*/
|
|
106919
107012
|
buildRgbToChannelMap() {
|
|
106920
|
-
var _a;
|
|
106921
107013
|
const map = new Map();
|
|
106922
|
-
for
|
|
106923
|
-
|
|
106924
|
-
|
|
106925
|
-
|
|
106926
|
-
|
|
106927
|
-
|
|
107014
|
+
// Every label this volume has a colour for, not a fixed 1-8. A pixel painted in
|
|
107015
|
+
// channel 12's colour used to miss this table entirely and fall through to the
|
|
107016
|
+
// nearest-colour guess, which could only ever answer 1-8 -- so the channel could be
|
|
107017
|
+
// drawn and could never be read back. Size is not a cost here: it is built once per
|
|
107018
|
+
// readback and every lookup against it is O(1).
|
|
107019
|
+
for (const key of Object.keys(this.colorMap)) {
|
|
107020
|
+
const ch = Number(key);
|
|
107021
|
+
if (ch < 1)
|
|
107022
|
+
continue; // 0 is "empty", and it is transparent rather than a colour
|
|
107023
|
+
const color = this.colorMap[ch];
|
|
107024
|
+
if (!color)
|
|
107025
|
+
continue;
|
|
107026
|
+
map.set((color.r << 16) | (color.g << 8) | color.b, ch);
|
|
106928
107027
|
}
|
|
106929
107028
|
return map;
|
|
106930
107029
|
}
|
|
@@ -106989,8 +107088,11 @@ class MaskVolume {
|
|
|
106989
107088
|
pixels[px + 1] = 0;
|
|
106990
107089
|
pixels[px + 2] = 0;
|
|
106991
107090
|
pixels[px + 3] = 0;
|
|
107091
|
+
// `=== false`, not falsy: the map records what has been HIDDEN and never covers
|
|
107092
|
+
// every label. `setSliceLabelsFromImageData` already reads it this way; reading it
|
|
107093
|
+
// as falsy here made any label the map did not mention render as invisible.
|
|
106992
107094
|
}
|
|
106993
|
-
else if (channelVisible
|
|
107095
|
+
else if ((channelVisible === null || channelVisible === void 0 ? void 0 : channelVisible[label]) === false) {
|
|
106994
107096
|
pixels[px] = 0;
|
|
106995
107097
|
pixels[px + 1] = 0;
|
|
106996
107098
|
pixels[px + 2] = 0;
|
|
@@ -107132,6 +107234,48 @@ class MaskVolume {
|
|
|
107132
107234
|
this.data.fill(0);
|
|
107133
107235
|
this.version++;
|
|
107134
107236
|
}
|
|
107237
|
+
/**
|
|
107238
|
+
* Zero every voxel carrying one label, leaving every other label in place.
|
|
107239
|
+
*
|
|
107240
|
+
* The third member of the clear family: `clear()` takes the whole volume and
|
|
107241
|
+
* `clearSlice()` takes one slice, both regardless of label. Deleting a single
|
|
107242
|
+
* annotation needs neither — its mask is one label inside a volume it shares with
|
|
107243
|
+
* every other annotation on that layer, so anything coarser takes the neighbours
|
|
107244
|
+
* with it.
|
|
107245
|
+
*
|
|
107246
|
+
* Label-based volumes only, which is what `numChannels === 1` means here: the voxel
|
|
107247
|
+
* value IS the label. A multi-plane volume stores channels as separate planes and
|
|
107248
|
+
* would need a different sweep.
|
|
107249
|
+
*
|
|
107250
|
+
* The version is bumped only when a voxel actually changed. Every derived cache keyed
|
|
107251
|
+
* on it — the contour cache above all — is invalidated by a bump, so bumping for a
|
|
107252
|
+
* clear that found nothing would redraw the layer for no reason.
|
|
107253
|
+
*
|
|
107254
|
+
* @param channel Label to erase, 1-255. Zero is "empty", not a channel.
|
|
107255
|
+
* @throws {RangeError} If `channel` is outside [1, 255].
|
|
107256
|
+
*
|
|
107257
|
+
* @example
|
|
107258
|
+
* ```ts
|
|
107259
|
+
* vol.clearChannel(3); // finding 3's voxels go; 1, 2 and 4 stay
|
|
107260
|
+
* ```
|
|
107261
|
+
*/
|
|
107262
|
+
clearChannel(channel) {
|
|
107263
|
+
// Upper bound is what a Uint8 label can hold. Task 5 of the channel-cap work
|
|
107264
|
+
// replaces both this and setChannelColor's guard with one MAX_ENGINE_CHANNEL.
|
|
107265
|
+
if (!Number.isInteger(channel) || channel < 1 || channel > 255) {
|
|
107266
|
+
throw new RangeError(`Invalid channel to clear: ${channel} (valid range: 1-255; 0 is empty)`);
|
|
107267
|
+
}
|
|
107268
|
+
const data = this.data;
|
|
107269
|
+
let changed = false;
|
|
107270
|
+
for (let i = 0; i < data.length; i++) {
|
|
107271
|
+
if (data[i] === channel) {
|
|
107272
|
+
data[i] = 0;
|
|
107273
|
+
changed = true;
|
|
107274
|
+
}
|
|
107275
|
+
}
|
|
107276
|
+
if (changed)
|
|
107277
|
+
this.version++;
|
|
107278
|
+
}
|
|
107135
107279
|
/**
|
|
107136
107280
|
* Check if the volume contains any non-zero voxel data.
|
|
107137
107281
|
*
|
|
@@ -107758,6 +107902,50 @@ const CELL_POLYGONS = [
|
|
|
107758
107902
|
/* 14 (TL+TR+BR, !BL) */ [[[0, 0], [1, 0], [1, 1], [0.5, 1], [0, 0.5]]],
|
|
107759
107903
|
/* 15 (full) */ [[[0, 0], [1, 0], [1, 1], [0, 1]]],
|
|
107760
107904
|
];
|
|
107905
|
+
/**
|
|
107906
|
+
* Per-cell boundary segments for the same 16 cases — the region's edge, without the region.
|
|
107907
|
+
*
|
|
107908
|
+
* Each entry is the cut line of the corresponding `CELL_POLYGONS` entry: the one edge of that
|
|
107909
|
+
* polygon which does not lie on the cell's border. Filling the polygons and stroking these
|
|
107910
|
+
* therefore describe the same silhouette, which is what lets the renderer swap fill for
|
|
107911
|
+
* outline without the mask's edge appearing to move.
|
|
107912
|
+
*
|
|
107913
|
+
* Endpoints are the midpoints of the cell's sides —
|
|
107914
|
+
* T = (0.5, 0) R = (1, 0.5) B = (0.5, 1) L = (0, 0.5)
|
|
107915
|
+
* — in the same cell-local 0..1 space as `CELL_POLYGONS`, so the caller adds (i, j) + SHIFT
|
|
107916
|
+
* identically for both.
|
|
107917
|
+
*
|
|
107918
|
+
* Cases 0 and 15 emit nothing. 15 is the whole reason an outline is cheap: solid interior has
|
|
107919
|
+
* no boundary, so the segment count follows the perimeter rather than the area.
|
|
107920
|
+
*
|
|
107921
|
+
* Saddles (5 and 10) follow `CELL_POLYGONS`' convention — the two in-corners are disconnected
|
|
107922
|
+
* (4-connectivity) — because the other reading would run a boundary straight through mask the
|
|
107923
|
+
* fill considers solid.
|
|
107924
|
+
*/
|
|
107925
|
+
const CELL_SEGMENTS = [
|
|
107926
|
+
/* 0 (empty) */ [],
|
|
107927
|
+
/* 1 (BL) */ [[[0, 0.5], [0.5, 1]]],
|
|
107928
|
+
/* 2 (BR) */ [[[0.5, 1], [1, 0.5]]],
|
|
107929
|
+
/* 3 (BR+BL) */ [[[0, 0.5], [1, 0.5]]],
|
|
107930
|
+
/* 4 (TR) */ [[[0.5, 0], [1, 0.5]]],
|
|
107931
|
+
/* 5 (TR+BL saddle) */ [
|
|
107932
|
+
[[0.5, 0], [1, 0.5]],
|
|
107933
|
+
[[0, 0.5], [0.5, 1]],
|
|
107934
|
+
],
|
|
107935
|
+
/* 6 (TR+BR) */ [[[0.5, 0], [0.5, 1]]],
|
|
107936
|
+
/* 7 (TR+BR+BL, !TL) */ [[[0.5, 0], [0, 0.5]]],
|
|
107937
|
+
/* 8 (TL) */ [[[0.5, 0], [0, 0.5]]],
|
|
107938
|
+
/* 9 (TL+BL) */ [[[0.5, 0], [0.5, 1]]],
|
|
107939
|
+
/* 10 (TL+BR saddle) */ [
|
|
107940
|
+
[[0.5, 0], [0, 0.5]],
|
|
107941
|
+
[[0.5, 1], [1, 0.5]],
|
|
107942
|
+
],
|
|
107943
|
+
/* 11 (TL+BR+BL, !TR) */ [[[0.5, 0], [1, 0.5]]],
|
|
107944
|
+
/* 12 (TL+TR) */ [[[1, 0.5], [0, 0.5]]],
|
|
107945
|
+
/* 13 (TL+TR+BL, !BR) */ [[[1, 0.5], [0.5, 1]]],
|
|
107946
|
+
/* 14 (TL+TR+BR, !BL) */ [[[0.5, 1], [0, 0.5]]],
|
|
107947
|
+
/* 15 (full) */ [],
|
|
107948
|
+
];
|
|
107761
107949
|
/**
|
|
107762
107950
|
* Emit polygons covering the voxels where `labels === targetLabel`.
|
|
107763
107951
|
* Pure geometry function — no Canvas dependency. Consumers can build a Path2D
|
|
@@ -107879,6 +108067,75 @@ function extractLabelContours(labels, width, height, targetLabel, stride = 1, ch
|
|
|
107879
108067
|
}
|
|
107880
108068
|
return path;
|
|
107881
108069
|
}
|
|
108070
|
+
/**
|
|
108071
|
+
* Emit the boundary of the region where `labels === targetLabel`, as open two-point segments.
|
|
108072
|
+
*
|
|
108073
|
+
* The counterpart to {@link extractLabelPolygons}: that one covers the region, this one traces
|
|
108074
|
+
* its edge. Both walk the same cells with the same sampling, the same out-of-bounds rule and
|
|
108075
|
+
* the same `+0.5` shift, so a renderer can fill one and stroke the other and have the mask end
|
|
108076
|
+
* in exactly the same place either way.
|
|
108077
|
+
*
|
|
108078
|
+
* Segments are emitted per cell and left unjoined. Canvas rasterises a whole `Path2D` in one
|
|
108079
|
+
* compositing pass, so segments meeting at a shared endpoint produce no seam and no doubled
|
|
108080
|
+
* alpha where their round caps overlap — joining them into polylines would buy nothing and
|
|
108081
|
+
* cost a chaining pass.
|
|
108082
|
+
*
|
|
108083
|
+
* Cost follows the perimeter, not the area: solid interior is case 15, which has no boundary.
|
|
108084
|
+
*
|
|
108085
|
+
* Parameters match {@link extractLabelContours}.
|
|
108086
|
+
*/
|
|
108087
|
+
function extractLabelBoundarySegments(labels, width, height, targetLabel, stride = 1, channelOffset = 0, bbox) {
|
|
108088
|
+
var _a, _b, _c, _d;
|
|
108089
|
+
const out = [];
|
|
108090
|
+
const i0 = Math.max(-1, ((_a = bbox === null || bbox === void 0 ? void 0 : bbox.x0) !== null && _a !== void 0 ? _a : 0) - 1);
|
|
108091
|
+
const j0 = Math.max(-1, ((_b = bbox === null || bbox === void 0 ? void 0 : bbox.y0) !== null && _b !== void 0 ? _b : 0) - 1);
|
|
108092
|
+
const i1 = Math.min(width, (_c = bbox === null || bbox === void 0 ? void 0 : bbox.x1) !== null && _c !== void 0 ? _c : width);
|
|
108093
|
+
const j1 = Math.min(height, (_d = bbox === null || bbox === void 0 ? void 0 : bbox.y1) !== null && _d !== void 0 ? _d : height);
|
|
108094
|
+
const sample = (x, y) => {
|
|
108095
|
+
if (x < 0 || x >= width || y < 0 || y >= height)
|
|
108096
|
+
return false;
|
|
108097
|
+
return labels[(y * width + x) * stride + channelOffset] === targetLabel;
|
|
108098
|
+
};
|
|
108099
|
+
// Same convention as extractLabelPolygons: samples sit at voxel centres.
|
|
108100
|
+
const SHIFT = 0.5;
|
|
108101
|
+
for (let j = j0; j < j1; j++) {
|
|
108102
|
+
for (let i = i0; i < i1; i++) {
|
|
108103
|
+
const code = (sample(i, j) ? 8 : 0) |
|
|
108104
|
+
(sample(i + 1, j) ? 4 : 0) |
|
|
108105
|
+
(sample(i + 1, j + 1) ? 2 : 0) |
|
|
108106
|
+
(sample(i, j + 1) ? 1 : 0);
|
|
108107
|
+
// Nothing here, or nothing but mask: neither has an edge in this cell.
|
|
108108
|
+
if (code === 0 || code === 15)
|
|
108109
|
+
continue;
|
|
108110
|
+
const segments = CELL_SEGMENTS[code];
|
|
108111
|
+
for (let s = 0; s < segments.length; s++) {
|
|
108112
|
+
const [a, b] = segments[s];
|
|
108113
|
+
out.push([
|
|
108114
|
+
[i + a[0] + SHIFT, j + a[1] + SHIFT],
|
|
108115
|
+
[i + b[0] + SHIFT, j + b[1] + SHIFT],
|
|
108116
|
+
]);
|
|
108117
|
+
}
|
|
108118
|
+
}
|
|
108119
|
+
}
|
|
108120
|
+
return out;
|
|
108121
|
+
}
|
|
108122
|
+
/**
|
|
108123
|
+
* {@link extractLabelBoundarySegments} as a `Path2D`, ready to stroke.
|
|
108124
|
+
*
|
|
108125
|
+
* The outline counterpart to {@link extractLabelContours}. Stroke this; do not stroke the
|
|
108126
|
+
* contour path — that one is per-cell polygons whose union is the silhouette, and stroking it
|
|
108127
|
+
* draws every internal cell edge as well, covering the mask in a grid.
|
|
108128
|
+
*/
|
|
108129
|
+
function extractLabelOutline(labels, width, height, targetLabel, stride = 1, channelOffset = 0, bbox) {
|
|
108130
|
+
const segments = extractLabelBoundarySegments(labels, width, height, targetLabel, stride, channelOffset, bbox);
|
|
108131
|
+
const path = new Path2D();
|
|
108132
|
+
for (let s = 0; s < segments.length; s++) {
|
|
108133
|
+
const [a, b] = segments[s];
|
|
108134
|
+
path.moveTo(a[0], a[1]);
|
|
108135
|
+
path.lineTo(b[0], b[1]);
|
|
108136
|
+
}
|
|
108137
|
+
return path;
|
|
108138
|
+
}
|
|
107882
108139
|
/**
|
|
107883
108140
|
* Detect the distinct non-zero labels present in a slice region.
|
|
107884
108141
|
*
|
|
@@ -109316,6 +109573,14 @@ class DragOperator {
|
|
|
109316
109573
|
}
|
|
109317
109574
|
}
|
|
109318
109575
|
|
|
109576
|
+
/**
|
|
109577
|
+
* Outline stroke width, in screen pixels.
|
|
109578
|
+
*
|
|
109579
|
+
* Screen pixels rather than voxels so magnifying the image does not thicken the line over the
|
|
109580
|
+
* boundary the clinician magnified it to see. Thin enough to sit on an edge, thick enough to
|
|
109581
|
+
* stay visible against bright tissue.
|
|
109582
|
+
*/
|
|
109583
|
+
const OUTLINE_WIDTH_PX = 1.5;
|
|
109319
109584
|
/**
|
|
109320
109585
|
* RenderingUtils — Rendering / slice-buffer helper methods.
|
|
109321
109586
|
*
|
|
@@ -109347,6 +109612,12 @@ class RenderingUtils {
|
|
|
109347
109612
|
* applied at fill time and intentionally *not* cached, so toggling them
|
|
109348
109613
|
* needs no recompute.
|
|
109349
109614
|
*
|
|
109615
|
+
* The render mode is not in the key either. Fill paths and outline paths
|
|
109616
|
+
* are built lazily and side by side under the same entry, so switching
|
|
109617
|
+
* mode costs one extraction per visible label the first time and is a
|
|
109618
|
+
* cache hit every time after — and a session that never leaves fill mode
|
|
109619
|
+
* never builds an outline.
|
|
109620
|
+
*
|
|
109350
109621
|
* One entry per layer (the current slice). Switching slice/axis or
|
|
109351
109622
|
* editing overwrites it.
|
|
109352
109623
|
*/
|
|
@@ -109433,6 +109704,22 @@ class RenderingUtils {
|
|
|
109433
109704
|
return null; // Volume not ready
|
|
109434
109705
|
}
|
|
109435
109706
|
}
|
|
109707
|
+
/**
|
|
109708
|
+
* Populate one cache entry's paths for one render mode.
|
|
109709
|
+
*
|
|
109710
|
+
* Split out because the two modes are built at different times: whichever is in use when
|
|
109711
|
+
* a slice is first drawn, and the other one only if the clinician switches while still on
|
|
109712
|
+
* that slice. Building both eagerly would make every slice scrub pay for a mode most
|
|
109713
|
+
* sessions never turn on.
|
|
109714
|
+
*/
|
|
109715
|
+
buildPaths(entry, data, stride, outline) {
|
|
109716
|
+
const target = outline ? entry.outlines : entry.fills;
|
|
109717
|
+
for (const lbl of entry.labels) {
|
|
109718
|
+
target.set(lbl, outline
|
|
109719
|
+
? extractLabelOutline(data, entry.W, entry.H, lbl, stride, 0)
|
|
109720
|
+
: extractLabelContours(data, entry.W, entry.H, lbl, stride, 0));
|
|
109721
|
+
}
|
|
109722
|
+
}
|
|
109436
109723
|
/**
|
|
109437
109724
|
* Render a layer's slice onto the target canvas as vector contours.
|
|
109438
109725
|
*
|
|
@@ -109445,6 +109732,27 @@ class RenderingUtils {
|
|
|
109445
109732
|
* is no longer used on this path — callers may pass any valid ImageData.
|
|
109446
109733
|
*/
|
|
109447
109734
|
renderSliceToCanvas(layer, axis, sliceIndex, _buffer, targetCtx, scaledWidth, scaledHeight) {
|
|
109735
|
+
this.drawSlice(layer, axis, sliceIndex, targetCtx, scaledWidth, scaledHeight, this.state.gui_states.drawing.maskRenderMode === "outline");
|
|
109736
|
+
}
|
|
109737
|
+
/**
|
|
109738
|
+
* Render a layer's slice FILLED, whatever the clinician is currently looking at.
|
|
109739
|
+
*
|
|
109740
|
+
* For the tools that bake (`syncLayerSliceData` — pencil and eraser) the layer canvas is
|
|
109741
|
+
* not a picture of the mask, it is the input the mask is rebuilt from: the bake replaces
|
|
109742
|
+
* the whole slice in `MaskVolume` with whatever pixels it finds there.
|
|
109743
|
+
*
|
|
109744
|
+
* An outline is a lossy picture — it says where a mask ends, not what it contains — so
|
|
109745
|
+
* baking one back writes rings and erases every interior on that slice, taking every other
|
|
109746
|
+
* finding on the layer with it. One pencil stroke was enough.
|
|
109747
|
+
*
|
|
109748
|
+
* Hence a separate entry point rather than a flag threaded through the display path: a
|
|
109749
|
+
* render that is about to be read back has a different requirement from one that is about
|
|
109750
|
+
* to be looked at, and the two only coincided while there was one way to draw a mask.
|
|
109751
|
+
*/
|
|
109752
|
+
renderSliceForBake(layer, axis, sliceIndex, targetCtx, scaledWidth, scaledHeight) {
|
|
109753
|
+
this.drawSlice(layer, axis, sliceIndex, targetCtx, scaledWidth, scaledHeight, false);
|
|
109754
|
+
}
|
|
109755
|
+
drawSlice(layer, axis, sliceIndex, targetCtx, scaledWidth, scaledHeight, outline) {
|
|
109448
109756
|
try {
|
|
109449
109757
|
const volume = this.getVolumeForLayer(layer);
|
|
109450
109758
|
if (!volume)
|
|
@@ -109452,28 +109760,72 @@ class RenderingUtils {
|
|
|
109452
109760
|
const stride = volume.getChannels();
|
|
109453
109761
|
const cacheKey = `${axis}:${sliceIndex}:${volume.getVersion()}`;
|
|
109454
109762
|
// Cache miss → run the expensive extraction once. Hits (zoom,
|
|
109455
|
-
// recomposite, contrast toggle) skip straight to the
|
|
109763
|
+
// recomposite, contrast toggle) skip straight to the draw below.
|
|
109456
109764
|
let entry = this._contourCache.get(layer);
|
|
109457
109765
|
if (!entry || entry.key !== cacheKey) {
|
|
109458
109766
|
const slice = volume.getSliceUint8(sliceIndex, axis);
|
|
109459
|
-
|
|
109460
|
-
|
|
109461
|
-
|
|
109462
|
-
|
|
109463
|
-
|
|
109464
|
-
|
|
109465
|
-
|
|
109466
|
-
|
|
109767
|
+
entry = {
|
|
109768
|
+
key: cacheKey,
|
|
109769
|
+
W: slice.width,
|
|
109770
|
+
H: slice.height,
|
|
109771
|
+
labels: findLabelsInSlice(slice.data, slice.width, slice.height, stride, 0),
|
|
109772
|
+
fills: new Map(),
|
|
109773
|
+
outlines: new Map(),
|
|
109774
|
+
};
|
|
109467
109775
|
this._contourCache.set(layer, entry);
|
|
109776
|
+
this.buildPaths(entry, slice.data, stride, outline);
|
|
109777
|
+
}
|
|
109778
|
+
else if ((outline ? entry.outlines : entry.fills).size !== entry.labels.length) {
|
|
109779
|
+
// The mode changed since this slice was last drawn, so the other set of
|
|
109780
|
+
// paths is cached and this one is not. Re-read the slice and build it; from
|
|
109781
|
+
// here on both are present and toggling is a pure cache hit.
|
|
109782
|
+
const slice = volume.getSliceUint8(sliceIndex, axis);
|
|
109783
|
+
this.buildPaths(entry, slice.data, stride, outline);
|
|
109468
109784
|
}
|
|
109469
109785
|
if (entry.labels.length === 0)
|
|
109470
109786
|
return;
|
|
109471
|
-
const { W, H, labels
|
|
109787
|
+
const { W, H, labels } = entry;
|
|
109788
|
+
const paths = outline ? entry.outlines : entry.fills;
|
|
109472
109789
|
const channelVis = this.state.gui_states.layerChannel.channelVisibility[layer];
|
|
109473
109790
|
targetCtx.save();
|
|
109474
|
-
// Vector
|
|
109791
|
+
// Vector drawing — imageSmoothingEnabled is irrelevant here, but keep
|
|
109475
109792
|
// it off to match the rest of the pipeline.
|
|
109476
109793
|
targetCtx.imageSmoothingEnabled = false;
|
|
109794
|
+
if (outline) {
|
|
109795
|
+
// Stroke on an UNTRANSFORMED context, with the voxel→display mapping carried
|
|
109796
|
+
// in the path instead. `lineWidth` is then measured in screen pixels, which
|
|
109797
|
+
// is what the other two options get wrong: stroking under `ctx.scale(sx, sy)`
|
|
109798
|
+
// thickens the line with the zoom, exactly when the clinician has magnified
|
|
109799
|
+
// the image to look at the boundary — and because voxels are rarely isotropic
|
|
109800
|
+
// (sx !== sy), it also comes out thicker in one axis than the other.
|
|
109801
|
+
const matrix = new DOMMatrix();
|
|
109802
|
+
if (axis === 'y') {
|
|
109803
|
+
matrix.scaleSelf(1, -1);
|
|
109804
|
+
matrix.translateSelf(0, -scaledHeight);
|
|
109805
|
+
}
|
|
109806
|
+
matrix.scaleSelf(scaledWidth / W, scaledHeight / H);
|
|
109807
|
+
targetCtx.lineWidth = OUTLINE_WIDTH_PX;
|
|
109808
|
+
// Segments are emitted per cell and meet at shared endpoints; round caps
|
|
109809
|
+
// close those joins. Canvas composites a whole Path2D in one pass, so the
|
|
109810
|
+
// overlap costs no doubled alpha.
|
|
109811
|
+
targetCtx.lineJoin = 'round';
|
|
109812
|
+
targetCtx.lineCap = 'round';
|
|
109813
|
+
for (const lbl of labels) {
|
|
109814
|
+
if (channelVis && channelVis[lbl] === false)
|
|
109815
|
+
continue;
|
|
109816
|
+
const path = paths.get(lbl);
|
|
109817
|
+
if (!path)
|
|
109818
|
+
continue;
|
|
109819
|
+
const color = volume.getChannelColor(lbl);
|
|
109820
|
+
targetCtx.strokeStyle =
|
|
109821
|
+
`rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
109822
|
+
const display = new Path2D();
|
|
109823
|
+
display.addPath(path, matrix);
|
|
109824
|
+
targetCtx.stroke(display);
|
|
109825
|
+
}
|
|
109826
|
+
targetCtx.restore();
|
|
109827
|
+
return;
|
|
109828
|
+
}
|
|
109477
109829
|
// Coronal (axis='y') Z-flip: mirrors the flip applied by the write
|
|
109478
109830
|
// path (syncLayerSliceData). Apply BEFORE the voxel→display scale
|
|
109479
109831
|
// so the flip operates in display coordinates.
|
|
@@ -110691,6 +111043,11 @@ class DrawingTool extends BaseTool {
|
|
|
110691
111043
|
this.ctx.nrrd_states.interaction.drawStartPos.y = e.offsetY;
|
|
110692
111044
|
// Capture pre-draw slice snapshot for undo
|
|
110693
111045
|
this.capturePreDrawSnapshot();
|
|
111046
|
+
// The eraser works on canvas pixels and then bakes the canvas back into the volume, so
|
|
111047
|
+
// it needs the layer solid rather than outlined for the length of the stroke. The display
|
|
111048
|
+
// mode comes back at pointerup, via refreshLayerFromVolume.
|
|
111049
|
+
if (this.ctx.gui_states.mode.eraser)
|
|
111050
|
+
this.solidifyLayerForErase();
|
|
110694
111051
|
// Brush mode: initialize voxel tracking and write first dot
|
|
110695
111052
|
if (!this.ctx.gui_states.mode.pencil && !this.ctx.gui_states.mode.eraser) {
|
|
110696
111053
|
const voxel = this.canvasToVoxel3D(e.offsetX, e.offsetY);
|
|
@@ -111103,17 +111460,36 @@ class DrawingTool extends BaseTool {
|
|
|
111103
111460
|
this.preDrawSlice = null;
|
|
111104
111461
|
}
|
|
111105
111462
|
/**
|
|
111106
|
-
* Redraws persisted layer data onto ctx before new pencil fill.
|
|
111107
|
-
*
|
|
111463
|
+
* Redraws persisted layer data onto ctx before the new pencil fill.
|
|
111464
|
+
*
|
|
111465
|
+
* Uses the BAKE renderer, not the display one. What lands on this canvas is about to be
|
|
111466
|
+
* read straight back into the MaskVolume by `syncLayerSliceData`, which replaces the whole
|
|
111467
|
+
* slice -- so this render is the data, not a picture of it. Drawing outlines here would
|
|
111468
|
+
* bake rings and erase the interior of every mask on the layer.
|
|
111108
111469
|
*/
|
|
111109
111470
|
redrawPreviousImageToLayerCtx(ctx) {
|
|
111110
111471
|
const axis = this.ctx.protectedData.axis;
|
|
111111
111472
|
const W = this.ctx.nrrd_states.view.changedWidth;
|
|
111112
111473
|
const H = this.ctx.nrrd_states.view.changedHeight;
|
|
111113
|
-
|
|
111114
|
-
|
|
111115
|
-
|
|
111116
|
-
|
|
111474
|
+
this.callbacks.renderSliceForBake(this.ctx.gui_states.layerChannel.layer, axis, this.ctx.nrrd_states.view.currentSliceIndex, ctx, W, H);
|
|
111475
|
+
}
|
|
111476
|
+
/**
|
|
111477
|
+
* Put the active layer's canvas into the solid state the eraser and the bake both need.
|
|
111478
|
+
*
|
|
111479
|
+
* The eraser removes pixels matching the active channel's colour, and `syncLayerSliceData`
|
|
111480
|
+
* then rebuilds the whole slice from what is left on the canvas. Against an outline there
|
|
111481
|
+
* is nothing to match inside a mask, so a drag over a lesion erases nothing -- and the bake
|
|
111482
|
+
* that follows writes the ring back and loses every interior on the layer.
|
|
111483
|
+
*
|
|
111484
|
+
* Unconditional rather than checked against the display mode: in fill mode this redraws
|
|
111485
|
+
* what is already on screen, and a mode-dependent branch here is one more thing that can
|
|
111486
|
+
* fall out of step with the renderer.
|
|
111487
|
+
*/
|
|
111488
|
+
solidifyLayerForErase() {
|
|
111489
|
+
const target = this.callbacks.setCurrentLayer();
|
|
111490
|
+
target.canvas.width = target.canvas.width; // clear
|
|
111491
|
+
this.callbacks.renderSliceForBake(this.ctx.gui_states.layerChannel.layer, this.ctx.protectedData.axis, this.ctx.nrrd_states.view.currentSliceIndex, target.ctx, this.ctx.nrrd_states.view.changedWidth, this.ctx.nrrd_states.view.changedHeight);
|
|
111492
|
+
this.callbacks.compositeAllLayers();
|
|
111117
111493
|
}
|
|
111118
111494
|
/** Draw a line segment on a layer canvas (pencil mode only) */
|
|
111119
111495
|
drawLinesOnLayer(ctx, x, y) {
|
|
@@ -112995,6 +113371,7 @@ class DrawToolCore {
|
|
|
112995
113371
|
getVolumeForLayer: (layer) => this.renderer.getVolumeForLayer(layer),
|
|
112996
113372
|
pushUndoDelta: (delta) => this.undoManager.push(delta),
|
|
112997
113373
|
renderSliceToCanvas: (layer, axis, sliceIndex, buffer, ctx, w, h) => this.renderer.renderSliceToCanvas(layer, axis, sliceIndex, buffer, ctx, w, h),
|
|
113374
|
+
renderSliceForBake: (layer, axis, sliceIndex, ctx, w, h) => this.renderer.renderSliceForBake(layer, axis, sliceIndex, ctx, w, h),
|
|
112998
113375
|
getOrCreateSliceBuffer: (axis) => this.renderer.getOrCreateSliceBuffer(axis),
|
|
112999
113376
|
});
|
|
113000
113377
|
this.sphereBrushTool = new SphereBrushTool(toolCtx, {
|
|
@@ -113895,6 +114272,8 @@ class GuiState {
|
|
|
113895
114272
|
fillColor: (_b = opts.defaultFillColor) !== null && _b !== void 0 ? _b : "#f50a33",
|
|
113896
114273
|
brushColor: (_c = opts.defaultBrushColor) !== null && _c !== void 0 ? _c : "#f50a33",
|
|
113897
114274
|
brushAndEraserSize: 10,
|
|
114275
|
+
// Filled is what every existing caller already gets; outline is opt-in.
|
|
114276
|
+
maskRenderMode: "fill",
|
|
113898
114277
|
};
|
|
113899
114278
|
this.viewConfig = {
|
|
113900
114279
|
mainAreaSize: 3,
|
|
@@ -115623,6 +116002,67 @@ class NrrdTools {
|
|
|
115623
116002
|
}
|
|
115624
116003
|
}
|
|
115625
116004
|
}
|
|
116005
|
+
/**
|
|
116006
|
+
* Erase one channel's mask on one layer, undoably.
|
|
116007
|
+
*
|
|
116008
|
+
* The missing third of the clear family that `executeAction` exposes:
|
|
116009
|
+
* `clearActiveSliceMask` takes one slice, `clearActiveLayerMask` takes a whole layer,
|
|
116010
|
+
* and neither can take a single label. Deleting one annotation needs exactly that —
|
|
116011
|
+
* its mask is one label inside a volume shared with every other annotation on the
|
|
116012
|
+
* layer.
|
|
116013
|
+
*
|
|
116014
|
+
* Not folded into `executeAction`: that signature is an action name plus an options
|
|
116015
|
+
* bag, and this needs two required arguments.
|
|
116016
|
+
*
|
|
116017
|
+
* Deltas go onto the engine's own undo stack, so a mistaken clear is recoverable for
|
|
116018
|
+
* as long as the case stays open. That is the whole reason this lives here rather
|
|
116019
|
+
* than in the app: writing zeros from outside and forcing a repaint by stepping the
|
|
116020
|
+
* slice would bypass the stack, and an accidental clear would be permanent.
|
|
116021
|
+
*
|
|
116022
|
+
* Only slices that actually carry the label are touched, so a small annotation in a
|
|
116023
|
+
* deep volume costs a scan and a handful of callbacks rather than one per slice.
|
|
116024
|
+
*
|
|
116025
|
+
* @param layerId Layer whose mask to edit.
|
|
116026
|
+
* @param channel Label to erase, 1-255.
|
|
116027
|
+
* @throws {Error} If `layerId` names no layer. Deliberately NOT routed through
|
|
116028
|
+
* `getVolumeForLayer`, which warns and falls back to the first layer — for a
|
|
116029
|
+
* destructive call that would quietly erase a different layer's annotation.
|
|
116030
|
+
* @throws {RangeError} If `channel` is outside [1, 255] (from `MaskVolume`).
|
|
116031
|
+
*/
|
|
116032
|
+
clearChannel(layerId, channel) {
|
|
116033
|
+
const volume = this.state.protectedData.maskData.volumes[layerId];
|
|
116034
|
+
if (!volume) {
|
|
116035
|
+
const known = this.state.nrrd_states.image.layers.join(", ");
|
|
116036
|
+
throw new Error(`clearChannel: unknown layer "${layerId}" (known layers: ${known})`);
|
|
116037
|
+
}
|
|
116038
|
+
const { depth } = volume.getDimensions();
|
|
116039
|
+
// Snapshot before mutating: `oldSlice` is what undo restores.
|
|
116040
|
+
const deltas = [];
|
|
116041
|
+
for (let z = 0; z < depth; z++) {
|
|
116042
|
+
const slice = volume.getSliceUint8(z, "z").data;
|
|
116043
|
+
if (!slice.some((v) => v === channel))
|
|
116044
|
+
continue;
|
|
116045
|
+
deltas.push({
|
|
116046
|
+
layerId,
|
|
116047
|
+
axis: "z",
|
|
116048
|
+
sliceIndex: z,
|
|
116049
|
+
oldSlice: slice.slice(),
|
|
116050
|
+
newSlice: new Uint8Array(0), // filled below, once the clear has run
|
|
116051
|
+
});
|
|
116052
|
+
}
|
|
116053
|
+
if (deltas.length === 0)
|
|
116054
|
+
return; // nothing drawn on this channel
|
|
116055
|
+
volume.clearChannel(channel);
|
|
116056
|
+
for (const delta of deltas) {
|
|
116057
|
+
delta.newSlice = volume.getSliceUint8(delta.sliceIndex, "z").data.slice();
|
|
116058
|
+
}
|
|
116059
|
+
this.drawCore.undoManager.pushGroup(deltas);
|
|
116060
|
+
for (const delta of deltas) {
|
|
116061
|
+
const { data, width, height } = volume.getSliceUint8(delta.sliceIndex, "z");
|
|
116062
|
+
this.state.annotationCallbacks.onMaskChanged(data, layerId, channel, delta.sliceIndex, "z", width, height, false);
|
|
116063
|
+
}
|
|
116064
|
+
this.reloadMasksFromVolume();
|
|
116065
|
+
}
|
|
115626
116066
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
115627
116067
|
// 4. Public API — Keyboard & History
|
|
115628
116068
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -116024,6 +116464,21 @@ class NrrdTools {
|
|
|
116024
116464
|
setLayerOpacity(layerId, opacity) { this.layerChannelManager.setLayerOpacity(layerId, opacity); }
|
|
116025
116465
|
getLayerOpacity(layerId) { return this.layerChannelManager.getLayerOpacity(layerId); }
|
|
116026
116466
|
getLayerOpacityMap() { return this.layerChannelManager.getLayerOpacityMap(); }
|
|
116467
|
+
/**
|
|
116468
|
+
* Fill every mask, or stroke only its boundary — for every layer and channel at once.
|
|
116469
|
+
*
|
|
116470
|
+
* A display decision, and nothing but: `MaskVolume` is not read differently and not written
|
|
116471
|
+
* at all, so what is stored, uploaded, exported and undone is the complete mask either way.
|
|
116472
|
+
*
|
|
116473
|
+
* Repaints immediately, the same way `setChannelVisible` does, because there is no other
|
|
116474
|
+
* event that would bring the change to the screen — a clinician who switched the mode and
|
|
116475
|
+
* then had to scrub a slice to see it would reasonably call that broken.
|
|
116476
|
+
*/
|
|
116477
|
+
setMaskRenderMode(mode) {
|
|
116478
|
+
this.state.gui_states.drawing.maskRenderMode = mode;
|
|
116479
|
+
this.reloadMasksFromVolume();
|
|
116480
|
+
}
|
|
116481
|
+
getMaskRenderMode() { return this.state.gui_states.drawing.maskRenderMode; }
|
|
116027
116482
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
116028
116483
|
// 8. Delegated — SliceRenderPipeline
|
|
116029
116484
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -117630,15 +118085,15 @@ function installFastSliceRepaint(rawSlice_1) {
|
|
|
117630
118085
|
}
|
|
117631
118086
|
|
|
117632
118087
|
// import * as kiwrious from "copper3d_plugin_heart_k";
|
|
117633
|
-
// "v3.10.
|
|
118088
|
+
// "v3.10.3" is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
|
|
117634
118089
|
// When copper3d is consumed from local source (no rollup replace step), the identifier is undefined and
|
|
117635
118090
|
// referencing it throws a ReferenceError — guard it so local loading still works.
|
|
117636
118091
|
let _revision = "unknown";
|
|
117637
118092
|
try {
|
|
117638
|
-
_revision = "v3.10.
|
|
118093
|
+
_revision = "v3.10.3";
|
|
117639
118094
|
}
|
|
117640
118095
|
catch (_a) {
|
|
117641
|
-
/* "v3.10.
|
|
118096
|
+
/* "v3.10.3" not injected (local source build) */
|
|
117642
118097
|
}
|
|
117643
118098
|
const REVISION = _revision;
|
|
117644
118099
|
// Expose on global so the version can be read in a production browser console via window.__COPPER3D_VERSION__
|
|
@@ -117649,4 +118104,4 @@ if (typeof console !== "undefined") {
|
|
|
117649
118104
|
console.log(`%cCopper3D Visualisation %c${REVISION}`, "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
|
|
117650
118105
|
}
|
|
117651
118106
|
|
|
117652
|
-
export { AI_CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, CameraViewPoint, Copper3dOrbitControls, Copper3dTrackballControls, DEFAULT_AXES, DEFAULT_TARGET_GREY, GaussianSmoother, 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 };
|
|
118107
|
+
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 };
|