copper3d 3.11.3 → 3.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +50 -3
  2. package/ai-index/guides/nrrd-tools.md +127 -5
  3. package/ai-index/guides/segmentation-module.md +146 -3
  4. package/ai-index/manifest.json +5 -5
  5. package/ai-index/symbols.json +1 -1
  6. package/dist/Utils/segmentation/CanvasState.js +0 -1
  7. package/dist/Utils/segmentation/CanvasState.js.map +1 -1
  8. package/dist/Utils/segmentation/DragOperator.d.ts +6 -0
  9. package/dist/Utils/segmentation/DragOperator.js +9 -0
  10. package/dist/Utils/segmentation/DragOperator.js.map +1 -1
  11. package/dist/Utils/segmentation/DrawToolCore.js +0 -14
  12. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  13. package/dist/Utils/segmentation/NrrdTools.d.ts +38 -1
  14. package/dist/Utils/segmentation/NrrdTools.js +105 -2
  15. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  16. package/dist/Utils/segmentation/RenderingUtils.d.ts +5 -9
  17. package/dist/Utils/segmentation/RenderingUtils.js +10 -116
  18. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
  19. package/dist/Utils/segmentation/contourPaint.d.ts +37 -0
  20. package/dist/Utils/segmentation/contourPaint.js +128 -0
  21. package/dist/Utils/segmentation/contourPaint.js.map +1 -0
  22. package/dist/Utils/segmentation/core/types.d.ts +0 -1
  23. package/dist/Utils/segmentation/eventRouter/EventRouter.js +0 -1
  24. package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
  25. package/dist/Utils/segmentation/eventRouter/types.d.ts +0 -1
  26. package/dist/Utils/segmentation/tools/DragSliceTool.js +5 -0
  27. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
  28. package/dist/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
  29. package/dist/Utils/segmentation/tools/MaskMirror.js +165 -0
  30. package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -0
  31. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +5 -0
  32. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
  33. package/dist/Utils/segmentation/tools/ToolHost.d.ts +10 -2
  34. package/dist/Utils/segmentation/tools/ZoomTool.js +32 -2
  35. package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
  36. package/dist/bundle.esm.js +450 -130
  37. package/dist/bundle.umd.js +450 -130
  38. package/dist/types/Utils/segmentation/DragOperator.d.ts +6 -0
  39. package/dist/types/Utils/segmentation/NrrdTools.d.ts +38 -1
  40. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +5 -9
  41. package/dist/types/Utils/segmentation/contourPaint.d.ts +37 -0
  42. package/dist/types/Utils/segmentation/core/types.d.ts +0 -1
  43. package/dist/types/Utils/segmentation/eventRouter/types.d.ts +0 -1
  44. package/dist/types/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
  45. package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +10 -2
  46. package/package.json +1 -1
@@ -20,6 +20,7 @@ export declare class DragOperator {
20
20
  private renderSliceToCanvas;
21
21
  private compositeAllLayers;
22
22
  private refreshSphereOverlayCb;
23
+ private previewSliceMoveCb;
23
24
  private eventRouter;
24
25
  constructor(container: HTMLElement, nrrd_sates: NrrdState, gui_states: GuiState, protectedData: IProtected, drawingPrameters: IDrawingEvents, setSyncsliceNum: () => void, setIsDrawFalse: (target: number) => void, flipDisplayImageByAxis: () => void, setEmptyCanvasSize: (axis?: "x" | "y" | "z") => void, getOrCreateSliceBuffer: (axis: "x" | "y" | "z") => ImageData | null, renderSliceToCanvas: (layer: string, axis: "x" | "y" | "z", sliceIndex: number, buffer: ImageData, targetCtx: CanvasRenderingContext2D, scaledWidth: number, scaledHeight: number) => void, compositeAllLayers: () => void);
25
26
  private init;
@@ -29,6 +30,11 @@ export declare class DragOperator {
29
30
  * Called by NrrdTools after DrawToolCore is initialized.
30
31
  */
31
32
  setRefreshSphereOverlay(cb: () => void): void;
33
+ /**
34
+ * Set the callback that may consume a slice move while a preview slice is shown.
35
+ * Called by NrrdTools; until then every move proceeds normally.
36
+ */
37
+ setPreviewSliceMove(cb: (index: number) => boolean): void;
32
38
  /**
33
39
  * Set the EventRouter reference for centralized event handling.
34
40
  * Called by NrrdTools/DrawToolCore after EventRouter is initialized.
@@ -5,6 +5,7 @@ import { DragOperator } from "./DragOperator";
5
5
  import type { ChannelValue, RGBAColor, ChannelColorMap } from "./core";
6
6
  import type { SphereType } from "./tools/SphereTool";
7
7
  import type { AiPromptTool, AiPromptPayload, AiMaskResult } from "./tools/AiAssistTool";
8
+ import { type NrrdHeaderLike } from "./tools/DataLoader";
8
9
  /**
9
10
  * Core NRRD annotation tool for medical image segmentation.
10
11
  *
@@ -37,7 +38,15 @@ export declare class NrrdTools {
37
38
  private preTimer;
38
39
  private guiParameterSettings;
39
40
  private _sliceRAFId;
41
+ /** Viewers drawing this one's masks (see setMaskMirror). */
42
+ private _mirrors;
43
+ /** The viewer whose masks this one draws, if any. */
44
+ private _mirrorSource;
45
+ /** The pending frame that refreshes this viewer's mirrors. */
46
+ private _mirrorFrame;
40
47
  private _pendingSliceStep;
48
+ /** Receives slice moves while a preview slice is shown; null when none is. */
49
+ private _previewSliceMove;
41
50
  /** Whether calculator mode is active (not part of gui_states interface) */
42
51
  private _calculatorActive;
43
52
  /** Layer/channel management (extracted module) */
@@ -229,6 +238,22 @@ export declare class NrrdTools {
229
238
  * Used for register/origin image switching where the view state should persist.
230
239
  */
231
240
  switchSlicesPreservingView(allSlices: Array<nrrdSliceType>): void;
241
+ /**
242
+ * Show one slice of a volume before the volume itself has loaded: `header` is the full
243
+ * volume's geometry, `slice` a depth-1 slice triple of plane `index` (built from one plane's
244
+ * voxels), shown as slice `index` of the full stack. Geometry is re-initialised only when it
245
+ * differs from the current one. Replaces whatever slice data is displayed; writes no mask.
246
+ * The full volume later replaces it with `switchSlicesPreservingView`, keeping `index`.
247
+ *
248
+ * Until then every slice move (wheel, keys, drag, `setSliceMoving`) goes to `onSliceMove`
249
+ * with its clamped target index instead of moving the displayed slice. Axial only; it does
250
+ * not switch orientation.
251
+ */
252
+ showPreviewSlice(header: NrrdHeaderLike, slice: nrrdSliceType, index: number, onSliceMove: (index: number) => void): void;
253
+ /** Whether a preview slice from `showPreviewSlice` is shown in place of a loaded volume. */
254
+ isPreviewing(): boolean;
255
+ /** Hands a slice move to the preview's host; false when no preview is shown. */
256
+ private previewSliceMove;
232
257
  appendLoadingbar(loadingbar: HTMLDivElement): void;
233
258
  getCurrentImageDimension(): number[];
234
259
  getVoxelSpacing(): number[];
@@ -425,10 +450,22 @@ export declare class NrrdTools {
425
450
  aiCommitToLayer(targetLayer?: string): void;
426
451
  clearActiveLayer(): void;
427
452
  reset(): void;
453
+ /**
454
+ * Draw `source`'s masks on this viewer, read live from it: its volumes, colours, channel and
455
+ * layer visibility, opacity and render mode. `mirrorToSource` is a row-major 4×4 from this
456
+ * viewer's voxel (x, y, z, 1) to the source's voxel; omitted means the identity. `null`
457
+ * detaches. Display only — nothing is written to either viewer's masks.
458
+ */
459
+ setMaskMirror(source: NrrdTools | null, mirrorToSource?: ArrayLike<number>): void;
460
+ /** The viewer whose masks this one draws, or null. */
461
+ getMaskMirrorSource(): NrrdTools | null;
462
+ /** Repaint every mirror of this viewer on the next frame; repeated calls coalesce. */
463
+ private scheduleMirrorRefresh;
428
464
  /**
429
465
  * Releases what this instance holds outside its own DOM subtree, so a viewer that is torn
430
466
  * down can be garbage-collected: the event router's listeners (its window `blur` listener
431
- * reaches the whole engine graph), a pending slice step and the drawing-flag timer.
467
+ * reaches the whole engine graph), a pending slice step, the drawing-flag timer and any
468
+ * mask-mirror link.
432
469
  *
433
470
  * The instance must not be used afterwards. Safe to call more than once.
434
471
  */
@@ -1,6 +1,7 @@
1
1
  import type { INewMaskData } from "./core/types";
2
2
  import type { MaskVolume } from "./core/index";
3
3
  import type { CanvasState } from "./CanvasState";
4
+ import type { MaskMirror } from "./tools/MaskMirror";
4
5
  /**
5
6
  * RenderingUtils — Rendering / slice-buffer helper methods.
6
7
  *
@@ -15,6 +16,10 @@ export declare class RenderingUtils {
15
16
  private state;
16
17
  /** Injected callback — set by owner after construction. */
17
18
  setEmptyCanvasSize: (axis?: "x" | "y" | "z") => void;
19
+ /** Set while this viewer draws another viewer's masks; painted after this viewer's own layers. */
20
+ mirror: MaskMirror | null;
21
+ /** Called after every composite. The owner refreshes the viewers mirroring this one. */
22
+ onComposited: (() => void) | null;
18
23
  private _reusableSliceBuffer;
19
24
  private _reusableBufferWidth;
20
25
  private _reusableBufferHeight;
@@ -73,15 +78,6 @@ export declare class RenderingUtils {
73
78
  * allocating a new ImageData per layer per slice switch.
74
79
  */
75
80
  getOrCreateSliceBuffer(axis: "x" | "y" | "z"): ImageData | null;
76
- /**
77
- * Populate one cache entry's paths for one render mode.
78
- *
79
- * Split out because the two modes are built at different times: whichever is in use when
80
- * a slice is first drawn, and the other one only if the clinician switches while still on
81
- * that slice. Building both eagerly would make every slice scrub pay for a mode most
82
- * sessions never turn on.
83
- */
84
- private buildPaths;
85
81
  /**
86
82
  * Render a layer's slice onto the target canvas as vector contours.
87
83
  *
@@ -0,0 +1,37 @@
1
+ import type { RGBAColor } from "./core/types";
2
+ /** One 2D slice of labels: `width × height` cells, `stride` bytes apart, the label at offset 0. */
3
+ export interface LabelSlice {
4
+ data: Uint8Array;
5
+ width: number;
6
+ height: number;
7
+ stride: number;
8
+ }
9
+ /**
10
+ * Outline stroke width, in screen pixels.
11
+ *
12
+ * Screen pixels rather than voxels so magnifying the image does not thicken the line over the
13
+ * boundary the clinician magnified it to see. Thin enough to sit on an edge, thick enough to
14
+ * stay visible against bright tissue.
15
+ */
16
+ export declare const OUTLINE_WIDTH_PX = 1.5;
17
+ /**
18
+ * One slice's contours, in voxel coordinates. Fill and outline paths are built lazily and side
19
+ * by side, so switching mode costs one extraction the first time and is a cache hit after.
20
+ */
21
+ export interface ContourEntry {
22
+ key: string;
23
+ W: number;
24
+ H: number;
25
+ labels: number[];
26
+ /** Silhouettes, to fill. Built on first use of fill mode for this slice. */
27
+ fills: Map<number, Path2D>;
28
+ /** Boundaries, to stroke. Built on first use of outline mode for this slice. */
29
+ outlines: Map<number, Path2D>;
30
+ }
31
+ /**
32
+ * The cached contours for `slot` under `key`, extracting on a miss. One entry per slot: a new
33
+ * key overwrites it. `readSlice` is called only when extraction is needed.
34
+ */
35
+ export declare function contourEntry(cache: Map<string, ContourEntry>, slot: string, key: string, readSlice: () => LabelSlice, outline: boolean): ContourEntry;
36
+ /** Paint an entry's visible labels onto `targetCtx`, scaled from voxels to `scaledWidth × scaledHeight`. */
37
+ export declare function paintContours(entry: ContourEntry, targetCtx: CanvasRenderingContext2D, axis: "x" | "y" | "z", scaledWidth: number, scaledHeight: number, outline: boolean, colorOf: (label: number) => RGBAColor, channelVis?: Record<number, boolean>): void;
@@ -520,6 +520,5 @@ export interface IKeyBoardSettings {
520
520
  redo: string;
521
521
  contrast: string[];
522
522
  crosshair: string;
523
- sphere: string;
524
523
  mouseWheel: "Scroll:Zoom" | "Scroll:Slice";
525
524
  }
@@ -56,7 +56,6 @@ export interface KeyboardSettings {
56
56
  redo: string;
57
57
  contrast: string[];
58
58
  crosshair: string;
59
- sphere: string;
60
59
  mouseWheel: 'Scroll:Zoom' | 'Scroll:Slice';
61
60
  }
62
61
  /**
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Drawing another viewer's masks, read live through a voxel-to-voxel transform.
3
+ *
4
+ * The transform is a row-major 4×4 from this viewer's voxel (x, y, z, 1) to the source's
5
+ * voxel. Slices are built in `MaskVolume.getSliceUint8`'s layout for this viewer's own grid,
6
+ * so the source's paint code draws them unchanged, flips included.
7
+ */
8
+ import type { MaskVolume } from "../core/index";
9
+ import type { CanvasState } from "../CanvasState";
10
+ import { type LabelSlice } from "../contourPaint";
11
+ export type Axis = "x" | "y" | "z";
12
+ /** A slice's width and height for `axis`, as `getSliceUint8` lays it out. */
13
+ export declare function sliceDims(dims: ArrayLike<number>, axis: Axis): [number, number];
14
+ /** Whether `m` is the identity within `tol`. No matrix counts as the identity. */
15
+ export declare function isIdentity(m: ArrayLike<number> | null | undefined, tol?: number): boolean;
16
+ /**
17
+ * The source's labels on this viewer's slice `index` along `axis`. A cell mapping outside
18
+ * the source is 0. On the same grid with the identity, it is the source's own slice.
19
+ *
20
+ * With a diagonal transform (the axes agree, only scale and offset differ), a mirror voxel
21
+ * coarser than the source shows the first label found among every source voxel it spans, so
22
+ * a finding thinner than the mirror's slice still appears on the slice that contains it.
23
+ * Any other transform samples the nearest source voxel.
24
+ */
25
+ export declare function mirrorSliceLabels(source: MaskVolume, mirrorDims: ArrayLike<number>, axis: Axis, index: number, m: ArrayLike<number> | null): LabelSlice;
26
+ /**
27
+ * One viewer drawing another's masks. Holds no mask data: every paint reads the source's
28
+ * volumes and display state. A new transform means a new instance, so the cache never holds
29
+ * contours from another transform.
30
+ */
31
+ export declare class MaskMirror {
32
+ private readonly self;
33
+ readonly source: CanvasState;
34
+ private readonly matrix;
35
+ /** One contour entry per source layer, for the slice last painted. */
36
+ private cache;
37
+ /** The source volume each cache entry was built from; a case load replaces the object. */
38
+ private cachedVolumes;
39
+ constructor(self: CanvasState, source: CanvasState, matrix: ArrayLike<number> | null);
40
+ /** Paint every visible source layer onto `ctx` for this viewer's current axis and slice. */
41
+ paint(ctx: CanvasRenderingContext2D, width: number, height: number): void;
42
+ }
@@ -17,6 +17,8 @@ export interface ToolHost {
17
17
  setEmptyCanvasSize(axis?: "x" | "y" | "z"): void;
18
18
  drawImageOnEmptyImage(canvas: HTMLCanvasElement): void;
19
19
  compositeAllLayers(): void;
20
+ /** Whether this viewer draws another viewer's masks instead of its own layers. */
21
+ hasMaskMirror(): boolean;
20
22
  renderSliceToCanvas(layer: string, axis: "x" | "y" | "z", sliceIndex: number, buffer: ImageData, targetCtx: CanvasRenderingContext2D, scaledWidth: number, scaledHeight: number): void;
21
23
  /**
22
24
  * Render a layer's slice filled, whatever the display mode is. For tools that follow a
@@ -40,6 +42,12 @@ export interface ToolHost {
40
42
  getVolumeForLayer(layer: string): MaskVolume;
41
43
  setIsDrawFalse(target: number): void;
42
44
  setSyncsliceNum(): void;
45
+ /**
46
+ * Offers a slice move to the host while a preview slice is shown (see
47
+ * `NrrdTools.showPreviewSlice`). Returns true when the move was consumed, in which
48
+ * case the caller must not move the displayed slice itself.
49
+ */
50
+ previewSliceMove(index: number): boolean;
43
51
  resetPaintAreaUIPosition(l?: number, t?: number): void;
44
52
  resizePaintArea(moveDistance: number): void;
45
53
  resetZoom(): void;
@@ -80,11 +88,11 @@ export type SphereHostDeps = Pick<ToolHost, 'setEmptyCanvasSize' | 'drawImageOnE
80
88
  /** DrawingTool host dependencies */
81
89
  export type DrawingHostDeps = Pick<ToolHost, 'setCurrentLayer' | 'compositeAllLayers' | 'syncLayerSliceData' | 'filterDrawedImage' | 'getVolumeForLayer' | 'pushUndoDelta' | 'renderSliceToCanvas' | 'renderSliceForBake' | 'getOrCreateSliceBuffer'>;
82
90
  /** DragSliceTool host dependencies */
83
- export type DragSliceHostDeps = Pick<ToolHost, 'setSyncsliceNum' | 'setIsDrawFalse' | 'flipDisplayImageByAxis' | 'setEmptyCanvasSize' | 'getOrCreateSliceBuffer' | 'renderSliceToCanvas' | 'refreshSphereOverlay' | 'compositeAllLayers'>;
91
+ export type DragSliceHostDeps = Pick<ToolHost, 'setSyncsliceNum' | 'setIsDrawFalse' | 'flipDisplayImageByAxis' | 'setEmptyCanvasSize' | 'getOrCreateSliceBuffer' | 'renderSliceToCanvas' | 'refreshSphereOverlay' | 'compositeAllLayers' | 'previewSliceMove'>;
84
92
  /** LayerChannelManager host dependencies */
85
93
  export type LayerChannelHostDeps = Pick<ToolHost, 'reloadMasksFromVolume' | 'getVolumeForLayer' | 'onChannelColorChanged'>;
86
94
  /** SliceRenderPipeline host dependencies */
87
- export type SliceRenderHostDeps = Pick<ToolHost, 'compositeAllLayers' | 'getOrCreateSliceBuffer' | 'renderSliceToCanvas' | 'getVolumeForLayer' | 'refreshSphereOverlay' | 'syncGuiParameterSettings' | 'repraintCurrentContrastSlice' | 'clearUndoHistory' | 'updateShowNumDiv' | 'updateCurrentContrastSlice'>;
95
+ export type SliceRenderHostDeps = Pick<ToolHost, 'compositeAllLayers' | 'hasMaskMirror' | 'getOrCreateSliceBuffer' | 'renderSliceToCanvas' | 'getVolumeForLayer' | 'refreshSphereOverlay' | 'syncGuiParameterSettings' | 'repraintCurrentContrastSlice' | 'clearUndoHistory' | 'updateShowNumDiv' | 'updateCurrentContrastSlice'>;
88
96
  /** DataLoader host dependencies */
89
97
  export type DataLoaderHostDeps = Pick<ToolHost, 'invalidateSliceBuffer' | 'setDisplaySlicesBaseOnAxis' | 'afterLoadSlice' | 'setEmptyCanvasSize' | 'syncLayerSliceData' | 'reloadMasksFromVolume' | 'resetZoom' | 'notifyUser'>;
90
98
  /** SphereBrushTool host dependencies */
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.11.3",
4
+ "version": "3.11.5",
5
5
  "main": "dist/bundle.umd.js",
6
6
  "moudle": "dist/bundle.esm.js",
7
7
  "types": "dist/types/index.d.ts",