copper3d 3.10.1 → 3.10.2
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/NrrdTools.d.ts +28 -0
- package/dist/Utils/segmentation/NrrdTools.js +61 -0
- package/dist/Utils/segmentation/NrrdTools.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 +1 -1
- package/dist/Utils/segmentation/core/index.js +1 -1
- package/dist/Utils/segmentation/core/index.js.map +1 -1
- package/dist/Utils/segmentation/core/types.d.ts +22 -21
- package/dist/Utils/segmentation/core/types.js +77 -10
- package/dist/Utils/segmentation/core/types.js.map +1 -1
- package/dist/bundle.esm.js +236 -31
- package/dist/bundle.umd.js +236 -30
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +28 -0
- package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +32 -5
- package/dist/types/Utils/segmentation/core/index.d.ts +1 -1
- package/dist/types/Utils/segmentation/core/types.d.ts +22 -21
- package/dist/types/index.d.ts +2 -1
- 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
|
*
|
|
@@ -115623,6 +115767,67 @@ class NrrdTools {
|
|
|
115623
115767
|
}
|
|
115624
115768
|
}
|
|
115625
115769
|
}
|
|
115770
|
+
/**
|
|
115771
|
+
* Erase one channel's mask on one layer, undoably.
|
|
115772
|
+
*
|
|
115773
|
+
* The missing third of the clear family that `executeAction` exposes:
|
|
115774
|
+
* `clearActiveSliceMask` takes one slice, `clearActiveLayerMask` takes a whole layer,
|
|
115775
|
+
* and neither can take a single label. Deleting one annotation needs exactly that —
|
|
115776
|
+
* its mask is one label inside a volume shared with every other annotation on the
|
|
115777
|
+
* layer.
|
|
115778
|
+
*
|
|
115779
|
+
* Not folded into `executeAction`: that signature is an action name plus an options
|
|
115780
|
+
* bag, and this needs two required arguments.
|
|
115781
|
+
*
|
|
115782
|
+
* Deltas go onto the engine's own undo stack, so a mistaken clear is recoverable for
|
|
115783
|
+
* as long as the case stays open. That is the whole reason this lives here rather
|
|
115784
|
+
* than in the app: writing zeros from outside and forcing a repaint by stepping the
|
|
115785
|
+
* slice would bypass the stack, and an accidental clear would be permanent.
|
|
115786
|
+
*
|
|
115787
|
+
* Only slices that actually carry the label are touched, so a small annotation in a
|
|
115788
|
+
* deep volume costs a scan and a handful of callbacks rather than one per slice.
|
|
115789
|
+
*
|
|
115790
|
+
* @param layerId Layer whose mask to edit.
|
|
115791
|
+
* @param channel Label to erase, 1-255.
|
|
115792
|
+
* @throws {Error} If `layerId` names no layer. Deliberately NOT routed through
|
|
115793
|
+
* `getVolumeForLayer`, which warns and falls back to the first layer — for a
|
|
115794
|
+
* destructive call that would quietly erase a different layer's annotation.
|
|
115795
|
+
* @throws {RangeError} If `channel` is outside [1, 255] (from `MaskVolume`).
|
|
115796
|
+
*/
|
|
115797
|
+
clearChannel(layerId, channel) {
|
|
115798
|
+
const volume = this.state.protectedData.maskData.volumes[layerId];
|
|
115799
|
+
if (!volume) {
|
|
115800
|
+
const known = this.state.nrrd_states.image.layers.join(", ");
|
|
115801
|
+
throw new Error(`clearChannel: unknown layer "${layerId}" (known layers: ${known})`);
|
|
115802
|
+
}
|
|
115803
|
+
const { depth } = volume.getDimensions();
|
|
115804
|
+
// Snapshot before mutating: `oldSlice` is what undo restores.
|
|
115805
|
+
const deltas = [];
|
|
115806
|
+
for (let z = 0; z < depth; z++) {
|
|
115807
|
+
const slice = volume.getSliceUint8(z, "z").data;
|
|
115808
|
+
if (!slice.some((v) => v === channel))
|
|
115809
|
+
continue;
|
|
115810
|
+
deltas.push({
|
|
115811
|
+
layerId,
|
|
115812
|
+
axis: "z",
|
|
115813
|
+
sliceIndex: z,
|
|
115814
|
+
oldSlice: slice.slice(),
|
|
115815
|
+
newSlice: new Uint8Array(0), // filled below, once the clear has run
|
|
115816
|
+
});
|
|
115817
|
+
}
|
|
115818
|
+
if (deltas.length === 0)
|
|
115819
|
+
return; // nothing drawn on this channel
|
|
115820
|
+
volume.clearChannel(channel);
|
|
115821
|
+
for (const delta of deltas) {
|
|
115822
|
+
delta.newSlice = volume.getSliceUint8(delta.sliceIndex, "z").data.slice();
|
|
115823
|
+
}
|
|
115824
|
+
this.drawCore.undoManager.pushGroup(deltas);
|
|
115825
|
+
for (const delta of deltas) {
|
|
115826
|
+
const { data, width, height } = volume.getSliceUint8(delta.sliceIndex, "z");
|
|
115827
|
+
this.state.annotationCallbacks.onMaskChanged(data, layerId, channel, delta.sliceIndex, "z", width, height, false);
|
|
115828
|
+
}
|
|
115829
|
+
this.reloadMasksFromVolume();
|
|
115830
|
+
}
|
|
115626
115831
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
115627
115832
|
// 4. Public API — Keyboard & History
|
|
115628
115833
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -117630,15 +117835,15 @@ function installFastSliceRepaint(rawSlice_1) {
|
|
|
117630
117835
|
}
|
|
117631
117836
|
|
|
117632
117837
|
// import * as kiwrious from "copper3d_plugin_heart_k";
|
|
117633
|
-
// "v3.10.
|
|
117838
|
+
// "v3.10.2" is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
|
|
117634
117839
|
// When copper3d is consumed from local source (no rollup replace step), the identifier is undefined and
|
|
117635
117840
|
// referencing it throws a ReferenceError — guard it so local loading still works.
|
|
117636
117841
|
let _revision = "unknown";
|
|
117637
117842
|
try {
|
|
117638
|
-
_revision = "v3.10.
|
|
117843
|
+
_revision = "v3.10.2";
|
|
117639
117844
|
}
|
|
117640
117845
|
catch (_a) {
|
|
117641
|
-
/* "v3.10.
|
|
117846
|
+
/* "v3.10.2" not injected (local source build) */
|
|
117642
117847
|
}
|
|
117643
117848
|
const REVISION = _revision;
|
|
117644
117849
|
// Expose on global so the version can be read in a production browser console via window.__COPPER3D_VERSION__
|
|
@@ -117649,4 +117854,4 @@ if (typeof console !== "undefined") {
|
|
|
117649
117854
|
console.log(`%cCopper3D Visualisation %c${REVISION}`, "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
|
|
117650
117855
|
}
|
|
117651
117856
|
|
|
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 };
|
|
117857
|
+
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 };
|