copper3d 3.7.1 → 3.7.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/dist/Loader/copperNrrdLoader.js +27 -0
- package/dist/Loader/copperNrrdLoader.js.map +1 -1
- package/dist/Utils/segmentation/CanvasState.js +1 -0
- package/dist/Utils/segmentation/CanvasState.js.map +1 -1
- package/dist/Utils/segmentation/DrawToolCore.d.ts +24 -0
- package/dist/Utils/segmentation/DrawToolCore.js +64 -0
- package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +16 -0
- package/dist/Utils/segmentation/NrrdTools.js +16 -0
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/core/UndoManager.d.ts +21 -2
- package/dist/Utils/segmentation/core/UndoManager.js +20 -0
- package/dist/Utils/segmentation/core/UndoManager.js.map +1 -1
- package/dist/Utils/segmentation/core/types.d.ts +7 -0
- package/dist/bundle.esm.js +131 -3
- package/dist/bundle.umd.js +131 -3
- package/dist/types/Utils/segmentation/DrawToolCore.d.ts +24 -0
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +16 -0
- package/dist/types/Utils/segmentation/core/UndoManager.d.ts +21 -2
- package/dist/types/Utils/segmentation/core/types.d.ts +7 -0
- package/package.json +1 -1
package/dist/bundle.umd.js
CHANGED
|
@@ -64922,6 +64922,32 @@ void main() {
|
|
|
64922
64922
|
transparent: true,
|
|
64923
64923
|
side: DoubleSide,
|
|
64924
64924
|
});
|
|
64925
|
+
/**
|
|
64926
|
+
* Work around a three.js regression (present from r175 through at least r185).
|
|
64927
|
+
*
|
|
64928
|
+
* `VolumeSlice`'s constructor calls `updateGeometry()` and then `repaint()`, but
|
|
64929
|
+
* *afterwards* assigns the JSDoc default values:
|
|
64930
|
+
*
|
|
64931
|
+
* this.iLength = 0;
|
|
64932
|
+
* this.jLength = 0;
|
|
64933
|
+
* this.sliceAccess = null;
|
|
64934
|
+
*
|
|
64935
|
+
* which wipe the values `updateGeometry()` just computed. `repaint()` only
|
|
64936
|
+
* recomputes them when `geometryNeedsUpdate` is true (i.e. after `index` was
|
|
64937
|
+
* assigned), so any repaint that is not preceded by an index change calls
|
|
64938
|
+
* `ctx.getImageData(0, 0, 0, 0)` and throws
|
|
64939
|
+
* `IndexSizeError: The source width is 0`.
|
|
64940
|
+
*
|
|
64941
|
+
* Recomputing the geometry right after extraction restores the correct values.
|
|
64942
|
+
* It is a harmless recompute on three <= r174, where the bug does not exist.
|
|
64943
|
+
*/
|
|
64944
|
+
function repairSliceGeometry(...slices) {
|
|
64945
|
+
for (const slice of slices) {
|
|
64946
|
+
if (slice && slice.iLength === 0 && typeof slice.updateGeometry === "function") {
|
|
64947
|
+
slice.updateGeometry();
|
|
64948
|
+
}
|
|
64949
|
+
}
|
|
64950
|
+
}
|
|
64925
64951
|
function copperNrrdLoader(url, loadingBar, segmentation, callback, opts) {
|
|
64926
64952
|
let nrrdMeshes;
|
|
64927
64953
|
let nrrdSlices;
|
|
@@ -64940,6 +64966,7 @@ void main() {
|
|
|
64940
64966
|
const sliceY = volume.extractSlice("y", initIndexY * ratio[1]);
|
|
64941
64967
|
//x plane
|
|
64942
64968
|
const sliceX = volume.extractSlice("x", initIndexX * ratio[0]);
|
|
64969
|
+
repairSliceGeometry(sliceZ, sliceY, sliceX);
|
|
64943
64970
|
sliceZ.initIndex = initIndexZ;
|
|
64944
64971
|
sliceY.initIndex = initIndexY;
|
|
64945
64972
|
sliceX.initIndex = initIndexX;
|
|
@@ -96420,6 +96447,26 @@ void main() {
|
|
|
96420
96447
|
const redoStack = (_b = this.redoStacks.get(layerId)) !== null && _b !== void 0 ? _b : this.redoStacks.get("layer1");
|
|
96421
96448
|
redoStack.length = 0;
|
|
96422
96449
|
}
|
|
96450
|
+
/**
|
|
96451
|
+
* Push a whole-volume replacement as one undo unit.
|
|
96452
|
+
*
|
|
96453
|
+
* Only the newest snapshot per layer is retained: each holds two full volumes, so
|
|
96454
|
+
* an unbounded stack would be hundreds of megabytes. Slice deltas below it survive.
|
|
96455
|
+
*/
|
|
96456
|
+
pushVolumeSnapshot(layerId, oldVolume, newVolume) {
|
|
96457
|
+
var _a, _b;
|
|
96458
|
+
const stack = (_a = this.undoStacks.get(layerId)) !== null && _a !== void 0 ? _a : this.undoStacks.get("layer1");
|
|
96459
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
96460
|
+
if (!Array.isArray(stack[i]))
|
|
96461
|
+
stack.splice(i, 1);
|
|
96462
|
+
}
|
|
96463
|
+
stack.push({ layerId, oldVolume, newVolume });
|
|
96464
|
+
if (stack.length > MAX_STACK_SIZE) {
|
|
96465
|
+
stack.shift();
|
|
96466
|
+
}
|
|
96467
|
+
const redoStack = (_b = this.redoStacks.get(layerId)) !== null && _b !== void 0 ? _b : this.redoStacks.get("layer1");
|
|
96468
|
+
redoStack.length = 0;
|
|
96469
|
+
}
|
|
96423
96470
|
/**
|
|
96424
96471
|
* Undo the last operation on the active layer.
|
|
96425
96472
|
* @returns The delta(s) that were undone, or undefined if nothing to undo.
|
|
@@ -101855,6 +101902,9 @@ void main() {
|
|
|
101855
101902
|
if (opts.onClearLayerVolume) {
|
|
101856
101903
|
this.state.annotationCallbacks.onLayerVolumeCleared = opts.onClearLayerVolume;
|
|
101857
101904
|
}
|
|
101905
|
+
if (opts.onLayerVolumeReplaced) {
|
|
101906
|
+
this.state.annotationCallbacks.onLayerVolumeReplaced = opts.onLayerVolumeReplaced;
|
|
101907
|
+
}
|
|
101858
101908
|
if (opts.getSphereData) {
|
|
101859
101909
|
this.state.annotationCallbacks.onSphereChanged = opts.getSphereData;
|
|
101860
101910
|
}
|
|
@@ -102227,6 +102277,12 @@ void main() {
|
|
|
102227
102277
|
if (!entry)
|
|
102228
102278
|
return;
|
|
102229
102279
|
this.state.protectedData.isDrawing = true;
|
|
102280
|
+
if (!Array.isArray(entry)) {
|
|
102281
|
+
// VolumeSnapshot: restore the pre-replacement volume in one step.
|
|
102282
|
+
this.applyVolumeSnapshot(entry.layerId, entry.oldVolume);
|
|
102283
|
+
this.setIsDrawFalse(1000);
|
|
102284
|
+
return;
|
|
102285
|
+
}
|
|
102230
102286
|
for (const delta of entry) {
|
|
102231
102287
|
try {
|
|
102232
102288
|
const vol = this.renderer.getVolumeForLayer(delta.layerId);
|
|
@@ -102254,6 +102310,12 @@ void main() {
|
|
|
102254
102310
|
if (!entry)
|
|
102255
102311
|
return;
|
|
102256
102312
|
this.state.protectedData.isDrawing = true;
|
|
102313
|
+
if (!Array.isArray(entry)) {
|
|
102314
|
+
// VolumeSnapshot: re-apply the post-replacement volume in one step.
|
|
102315
|
+
this.applyVolumeSnapshot(entry.layerId, entry.newVolume);
|
|
102316
|
+
this.setIsDrawFalse(1000);
|
|
102317
|
+
return;
|
|
102318
|
+
}
|
|
102257
102319
|
for (const delta of entry) {
|
|
102258
102320
|
try {
|
|
102259
102321
|
const vol = this.renderer.getVolumeForLayer(delta.layerId);
|
|
@@ -102290,6 +102352,55 @@ void main() {
|
|
|
102290
102352
|
}
|
|
102291
102353
|
this.renderer.compositeAllLayers();
|
|
102292
102354
|
}
|
|
102355
|
+
/**
|
|
102356
|
+
* Restore a whole layer volume after an undo or redo of a mask upload.
|
|
102357
|
+
* This is the ONLY place onLayerVolumeReplaced fires - the initial upload
|
|
102358
|
+
* (replaceLayerVolume below) does not fire it, since the backend already has
|
|
102359
|
+
* that data from the upload request itself.
|
|
102360
|
+
*
|
|
102361
|
+
* Fires onLayerVolumeReplaced ONCE instead of one onMaskChanged per slice - the
|
|
102362
|
+
* app persists the volume in a single request rather than one call per slice.
|
|
102363
|
+
*/
|
|
102364
|
+
applyVolumeSnapshot(layerId, data) {
|
|
102365
|
+
const vol = this.renderer.getVolumeForLayer(layerId);
|
|
102366
|
+
if (!vol)
|
|
102367
|
+
return;
|
|
102368
|
+
vol.setRawData(new Uint8Array(data));
|
|
102369
|
+
this.renderer.invalidateSliceBuffer();
|
|
102370
|
+
this.reloadMasksFromVolume();
|
|
102371
|
+
if (!this.state.nrrd_states.flags.loadingMaskData) {
|
|
102372
|
+
this.state.annotationCallbacks.onLayerVolumeReplaced(layerId);
|
|
102373
|
+
}
|
|
102374
|
+
}
|
|
102375
|
+
/**
|
|
102376
|
+
* Replace a layer's entire volume, optionally recording it as one undo step.
|
|
102377
|
+
*
|
|
102378
|
+
* Used by the mask upload dialog. Unlike DataLoader.setMasksFromNIfTI this records
|
|
102379
|
+
* undo history and does not resetZoom, so the clinician keeps their view.
|
|
102380
|
+
*
|
|
102381
|
+
* This call does NOT fire onLayerVolumeReplaced - the caller (the upload flow)
|
|
102382
|
+
* already knows it just replaced the volume and is responsible for persisting it.
|
|
102383
|
+
* The callback exists only for applyVolumeSnapshot below, so a later undo/redo of
|
|
102384
|
+
* this replacement can tell the backend to fall back to the old/new volume.
|
|
102385
|
+
*/
|
|
102386
|
+
replaceLayerVolume(layerId, data, opts = {}) {
|
|
102387
|
+
const vol = this.renderer.getVolumeForLayer(layerId);
|
|
102388
|
+
if (!vol) {
|
|
102389
|
+
console.warn(`replaceLayerVolume: unknown layer "${layerId}"`);
|
|
102390
|
+
return;
|
|
102391
|
+
}
|
|
102392
|
+
const expected = vol.getRawData().length;
|
|
102393
|
+
if (data.length !== expected) {
|
|
102394
|
+
console.warn(`replaceLayerVolume: size mismatch (${data.length} vs ${expected})`);
|
|
102395
|
+
return;
|
|
102396
|
+
}
|
|
102397
|
+
if (opts.undoable) {
|
|
102398
|
+
this.undoManager.pushVolumeSnapshot(layerId, new Uint8Array(vol.getRawData()), new Uint8Array(data));
|
|
102399
|
+
}
|
|
102400
|
+
vol.setRawData(new Uint8Array(data));
|
|
102401
|
+
this.renderer.invalidateSliceBuffer();
|
|
102402
|
+
this.reloadMasksFromVolume();
|
|
102403
|
+
}
|
|
102293
102404
|
/****************************Store images (delegated to ImageStoreHelper)****************************************************/
|
|
102294
102405
|
syncLayerSliceData(index, layer) {
|
|
102295
102406
|
this.imageStoreHelper.syncLayerSliceData(index, layer);
|
|
@@ -102511,6 +102622,7 @@ void main() {
|
|
|
102511
102622
|
onSphereChanged: () => { },
|
|
102512
102623
|
onCalculatorPositionsChanged: () => { },
|
|
102513
102624
|
onLayerVolumeCleared: () => { },
|
|
102625
|
+
onLayerVolumeReplaced: () => { },
|
|
102514
102626
|
onChannelColorChanged: () => { },
|
|
102515
102627
|
};
|
|
102516
102628
|
/** Whether the keyboard-config dialog is open (suppresses all shortcuts). */
|
|
@@ -104786,6 +104898,22 @@ void main() {
|
|
|
104786
104898
|
// Refresh the display so all three axes reflect the new data
|
|
104787
104899
|
this.reloadMasksFromVolume();
|
|
104788
104900
|
}
|
|
104901
|
+
/**
|
|
104902
|
+
* Replace a layer's entire voxel buffer.
|
|
104903
|
+
*
|
|
104904
|
+
* This call itself does NOT fire onLayerVolumeReplaced - callers (e.g. the mask
|
|
104905
|
+
* upload flow) must persist the new volume themselves. The callback fires only
|
|
104906
|
+
* later, if the clinician undoes or redoes this replacement, because at that
|
|
104907
|
+
* point the backend still holds the newer volume and needs to be told to fall
|
|
104908
|
+
* back to the old one.
|
|
104909
|
+
*
|
|
104910
|
+
* @param layerId Layer to overwrite.
|
|
104911
|
+
* @param data Voxels, exactly the layer volume's length.
|
|
104912
|
+
* @param opts `undoable: true` records one Ctrl+Z step for the whole volume.
|
|
104913
|
+
*/
|
|
104914
|
+
replaceLayerVolume(layerId, data, opts = {}) {
|
|
104915
|
+
this.drawCore.replaceLayerVolume(layerId, data, opts);
|
|
104916
|
+
}
|
|
104789
104917
|
}
|
|
104790
104918
|
|
|
104791
104919
|
/**
|
|
@@ -105217,15 +105345,15 @@ void main() {
|
|
|
105217
105345
|
}
|
|
105218
105346
|
|
|
105219
105347
|
// import * as kiwrious from "copper3d_plugin_heart_k";
|
|
105220
|
-
// "v3.7.
|
|
105348
|
+
// "v3.7.3" is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
|
|
105221
105349
|
// When copper3d is consumed from local source (no rollup replace step), the identifier is undefined and
|
|
105222
105350
|
// referencing it throws a ReferenceError — guard it so local loading still works.
|
|
105223
105351
|
let _revision = "unknown";
|
|
105224
105352
|
try {
|
|
105225
|
-
_revision = "v3.7.
|
|
105353
|
+
_revision = "v3.7.3";
|
|
105226
105354
|
}
|
|
105227
105355
|
catch (_a) {
|
|
105228
|
-
/* "v3.7.
|
|
105356
|
+
/* "v3.7.3" not injected (local source build) */
|
|
105229
105357
|
}
|
|
105230
105358
|
const REVISION = _revision;
|
|
105231
105359
|
// Expose on global so the version can be read in a production browser console via window.__COPPER3D_VERSION__
|
|
@@ -131,6 +131,30 @@ export declare class DrawToolCore {
|
|
|
131
131
|
* Re-render a layer canvas from MaskVolume and composite to master.
|
|
132
132
|
*/
|
|
133
133
|
private applyUndoRedoToCanvas;
|
|
134
|
+
/**
|
|
135
|
+
* Restore a whole layer volume after an undo or redo of a mask upload.
|
|
136
|
+
* This is the ONLY place onLayerVolumeReplaced fires - the initial upload
|
|
137
|
+
* (replaceLayerVolume below) does not fire it, since the backend already has
|
|
138
|
+
* that data from the upload request itself.
|
|
139
|
+
*
|
|
140
|
+
* Fires onLayerVolumeReplaced ONCE instead of one onMaskChanged per slice - the
|
|
141
|
+
* app persists the volume in a single request rather than one call per slice.
|
|
142
|
+
*/
|
|
143
|
+
private applyVolumeSnapshot;
|
|
144
|
+
/**
|
|
145
|
+
* Replace a layer's entire volume, optionally recording it as one undo step.
|
|
146
|
+
*
|
|
147
|
+
* Used by the mask upload dialog. Unlike DataLoader.setMasksFromNIfTI this records
|
|
148
|
+
* undo history and does not resetZoom, so the clinician keeps their view.
|
|
149
|
+
*
|
|
150
|
+
* This call does NOT fire onLayerVolumeReplaced - the caller (the upload flow)
|
|
151
|
+
* already knows it just replaced the volume and is responsible for persisting it.
|
|
152
|
+
* The callback exists only for applyVolumeSnapshot below, so a later undo/redo of
|
|
153
|
+
* this replacement can tell the backend to fall back to the old/new volume.
|
|
154
|
+
*/
|
|
155
|
+
replaceLayerVolume(layerId: string, data: Uint8Array, opts?: {
|
|
156
|
+
undoable?: boolean;
|
|
157
|
+
}): void;
|
|
134
158
|
/****************************Store images (delegated to ImageStoreHelper)****************************************************/
|
|
135
159
|
syncLayerSliceData(index: number, layer: string): void;
|
|
136
160
|
/******************************** Utils gui related functions (delegated to ContrastTool) ***************************************/
|
|
@@ -331,4 +331,20 @@ export declare class NrrdTools {
|
|
|
331
331
|
* ```
|
|
332
332
|
*/
|
|
333
333
|
copyLayerData(sourceLayerId: string, targetLayerId: string): void;
|
|
334
|
+
/**
|
|
335
|
+
* Replace a layer's entire voxel buffer.
|
|
336
|
+
*
|
|
337
|
+
* This call itself does NOT fire onLayerVolumeReplaced - callers (e.g. the mask
|
|
338
|
+
* upload flow) must persist the new volume themselves. The callback fires only
|
|
339
|
+
* later, if the clinician undoes or redoes this replacement, because at that
|
|
340
|
+
* point the backend still holds the newer volume and needs to be told to fall
|
|
341
|
+
* back to the old one.
|
|
342
|
+
*
|
|
343
|
+
* @param layerId Layer to overwrite.
|
|
344
|
+
* @param data Voxels, exactly the layer volume's length.
|
|
345
|
+
* @param opts `undoable: true` records one Ctrl+Z step for the whole volume.
|
|
346
|
+
*/
|
|
347
|
+
replaceLayerVolume(layerId: string, data: Uint8Array, opts?: {
|
|
348
|
+
undoable?: boolean;
|
|
349
|
+
}): void;
|
|
334
350
|
}
|
|
@@ -19,8 +19,20 @@ export interface MaskDelta {
|
|
|
19
19
|
/** Full slice data captured after the drawing operation. */
|
|
20
20
|
newSlice: Uint8Array;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* A whole-layer volume replacement (mask upload), stored as before/after volumes.
|
|
24
|
+
*
|
|
25
|
+
* A MaskDelta is per-slice, so expressing an upload as a delta group would mean one
|
|
26
|
+
* entry per slice - ~84 MB and one backend request per slice on undo for a
|
|
27
|
+
* 512x512x160 case. One snapshot restores the volume in a single step instead.
|
|
28
|
+
*/
|
|
29
|
+
export interface VolumeSnapshot {
|
|
30
|
+
layerId: string;
|
|
31
|
+
oldVolume: Uint8Array;
|
|
32
|
+
newVolume: Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
/** A slice-delta group or a whole-volume snapshot. `Array.isArray` discriminates. */
|
|
35
|
+
export type UndoEntry = MaskDelta[] | VolumeSnapshot;
|
|
24
36
|
export declare class UndoManager {
|
|
25
37
|
private undoStacks;
|
|
26
38
|
private redoStacks;
|
|
@@ -32,6 +44,13 @@ export declare class UndoManager {
|
|
|
32
44
|
push(delta: MaskDelta): void;
|
|
33
45
|
/** Push a group of deltas as a single undo unit (e.g. 3D sphere spanning multiple slices). */
|
|
34
46
|
pushGroup(deltas: MaskDelta[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* Push a whole-volume replacement as one undo unit.
|
|
49
|
+
*
|
|
50
|
+
* Only the newest snapshot per layer is retained: each holds two full volumes, so
|
|
51
|
+
* an unbounded stack would be hundreds of megabytes. Slice deltas below it survive.
|
|
52
|
+
*/
|
|
53
|
+
pushVolumeSnapshot(layerId: string, oldVolume: Uint8Array, newVolume: Uint8Array): void;
|
|
35
54
|
/**
|
|
36
55
|
* Undo the last operation on the active layer.
|
|
37
56
|
* @returns The delta(s) that were undone, or undefined if nothing to undo.
|
|
@@ -451,6 +451,12 @@ export interface IAnnotationCallbacks {
|
|
|
451
451
|
onSphereChanged(sphereOrigin: number[], sphereRadius: number): void;
|
|
452
452
|
onCalculatorPositionsChanged(tumour: ICommXYZ | null, skin: ICommXYZ | null, rib: ICommXYZ | null, nipple: ICommXYZ | null, axis: "x" | "y" | "z"): void;
|
|
453
453
|
onLayerVolumeCleared(layerId: string): void;
|
|
454
|
+
/**
|
|
455
|
+
* Fired once after an undo or redo restores a whole-layer volume.
|
|
456
|
+
* NOT fired by the initial replaceLayerVolume call (the mask upload), because the
|
|
457
|
+
* backend already holds that data from the upload request that preceded it.
|
|
458
|
+
*/
|
|
459
|
+
onLayerVolumeReplaced(layerId: string): void;
|
|
454
460
|
onChannelColorChanged(layerId: string, channel: number, color: {
|
|
455
461
|
r: number;
|
|
456
462
|
g: number;
|
|
@@ -491,6 +497,7 @@ export interface IDragOpts {
|
|
|
491
497
|
export interface IDrawOpts {
|
|
492
498
|
getMaskData?: (sliceData: Uint8Array, layerId: string, channelId: number, sliceIndex: number, axis: "x" | "y" | "z", width: number, height: number, clearFlag?: boolean) => void;
|
|
493
499
|
onClearLayerVolume?: (layerId: string) => void;
|
|
500
|
+
onLayerVolumeReplaced?: (layerId: string) => void;
|
|
494
501
|
getSphereData?: (sphereOrigin: number[], sphereRadius: number) => void;
|
|
495
502
|
getCalculateSpherePositionsData?: (tumourSphereOrigin: ICommXYZ | null, skinSphereOrigin: ICommXYZ | null, ribSphereOrigin: ICommXYZ | null, nippleSphereOrigin: ICommXYZ | null, aixs: "x" | "y" | "z") => void;
|
|
496
503
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copper3d",
|
|
3
3
|
"description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
|
|
4
|
-
"version": "3.7.
|
|
4
|
+
"version": "3.7.3",
|
|
5
5
|
"main": "dist/bundle.umd.js",
|
|
6
6
|
"moudle": "dist/bundle.esm.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|