copper3d 4.1.1 → 4.1.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.
@@ -8849,6 +8849,8 @@
8849
8849
  super(container, renderer, opt);
8850
8850
  this.renderRequested = false;
8851
8851
  this.isResize = false;
8852
+ /** Handle of the callback loop's next frame; null while the loop is not running. */
8853
+ this.callbackFrame = null;
8852
8854
  this.confirmResize = () => {
8853
8855
  this.isResize = true;
8854
8856
  this.requestRenderIfNotRequested();
@@ -8945,6 +8947,43 @@
8945
8947
  setCameraPose(pose) {
8946
8948
  setCameraPose(this, pose);
8947
8949
  }
8950
+ /**
8951
+ * Registers a per-frame callback, as on `copperScene` -- `nrrdTools.start` is the usual one.
8952
+ *
8953
+ * This scene draws only on demand, and before 4.1.2 nothing here ran the registry:
8954
+ * registering returned an id and the callback never ran. Now the scene runs a
8955
+ * `requestAnimationFrame` loop of its own while anything is registered, and none while
8956
+ * nothing is. The loop calls the callbacks and nothing else -- it does not render the WebGL
8957
+ * scene, so a callback that changes what the scene shows still asks for a frame with
8958
+ * `requestRenderIfNotRequested`.
8959
+ */
8960
+ addPreRenderCallbackFunction(callbackFunction) {
8961
+ const id = super.addPreRenderCallbackFunction(callbackFunction);
8962
+ if (this.callbackFrame === null) {
8963
+ this.callbackFrame = requestAnimationFrame(() => this.runCallbackFrame());
8964
+ }
8965
+ return id;
8966
+ }
8967
+ removePreRenderCallbackFunction(id) {
8968
+ super.removePreRenderCallbackFunction(id);
8969
+ if (this.preRenderCallbackFunctions.cache.length === 0)
8970
+ this.stopCallbackLoop();
8971
+ }
8972
+ runCallbackFrame() {
8973
+ if (this.preRenderCallbackFunctions.cache.length === 0) {
8974
+ this.callbackFrame = null;
8975
+ return;
8976
+ }
8977
+ // Next frame first, so a callback that throws costs one frame rather than the loop.
8978
+ this.callbackFrame = requestAnimationFrame(() => this.runCallbackFrame());
8979
+ // A copy: a callback may unregister itself, or another, while this runs.
8980
+ [...this.preRenderCallbackFunctions.cache].forEach((fn) => fn.call(null));
8981
+ }
8982
+ stopCallbackLoop() {
8983
+ if (this.callbackFrame !== null)
8984
+ cancelAnimationFrame(this.callbackFrame);
8985
+ this.callbackFrame = null;
8986
+ }
8948
8987
  /**
8949
8988
  * Releases what this scene attached OUTSIDE itself.
8950
8989
  *
@@ -8975,6 +9014,8 @@
8975
9014
  // Nothing in flight can arrive after this: `render` clears the flag, and
8976
9015
  // an already-scheduled frame only draws.
8977
9016
  this.renderRequested = false;
9017
+ // The registered callbacks stay registered, but stop being called.
9018
+ this.stopCallbackLoop();
8978
9019
  }
8979
9020
  }
8980
9021
 
@@ -16745,6 +16786,29 @@
16745
16786
  *
16746
16787
  * Created by NrrdTools which passes in a shared CanvasState.
16747
16788
  */
16789
+ /**
16790
+ * The channels a slice delta changed: every label that differs between the slice before and
16791
+ * after, background (0) excluded, in ascending order.
16792
+ *
16793
+ * In a label volume a voxel's value is its channel, so this is exactly the set of channels an
16794
+ * undo or redo of the delta touches — which is what the host needs to know, not the channel
16795
+ * that happens to be active.
16796
+ */
16797
+ function changedChannels(oldSlice, newSlice) {
16798
+ const seen = new Set();
16799
+ const n = Math.min(oldSlice.length, newSlice.length);
16800
+ for (let i = 0; i < n; i++) {
16801
+ const before = oldSlice[i];
16802
+ const after = newSlice[i];
16803
+ if (before === after)
16804
+ continue;
16805
+ if (before !== 0)
16806
+ seen.add(before);
16807
+ if (after !== 0)
16808
+ seen.add(after);
16809
+ }
16810
+ return [...seen].sort((a, b) => a - b);
16811
+ }
16748
16812
  class DrawToolCore {
16749
16813
  setAnnotationSuspended(suspended) {
16750
16814
  this.annotationSuspended = suspended;
@@ -16766,10 +16830,6 @@
16766
16830
  if (this.paintSliceIndex !== this.state.protectedData.mainPreSlices.index) {
16767
16831
  this.paintSliceIndex = this.state.protectedData.mainPreSlices.index;
16768
16832
  }
16769
- // Suppress wheel only when starting a draw operation
16770
- if (this.eventRouter.getMode() === 'draw') {
16771
- this.activeWheelMode = 'none';
16772
- }
16773
16833
  if (e.button === 0) {
16774
16834
  // Every branch that can write into a mask is gated; the crosshair below is a
16775
16835
  // read-only probe and stays available, as do pan (button 2) and the wheel.
@@ -16780,6 +16840,11 @@
16780
16840
  this.aiAssistTool.onPointerDown(e);
16781
16841
  }
16782
16842
  else if (this.eventRouter.getMode() === 'draw') {
16843
+ // No wheel for the length of the stroke; the pointer-up that ends it turns it back
16844
+ // on. Set here, where a stroke really starts, and nowhere earlier: a press that starts
16845
+ // none -- suspended, or not the left button -- has no pointer-up that ends a stroke,
16846
+ // so nothing would ever turn the wheel back on.
16847
+ this.activeWheelMode = 'none';
16783
16848
  this.drawingTool.onPointerDown(e);
16784
16849
  }
16785
16850
  else if (this.eventRouter.isCrosshairEnabled()) {
@@ -16859,6 +16924,29 @@
16859
16924
  this.setIsDrawFalse(100);
16860
16925
  }
16861
16926
  }
16927
+ /**
16928
+ * The per-frame callback hosts register (`scene.addPreRenderCallbackFunction(nrrdTools.start)`).
16929
+ *
16930
+ * One function for the life of the instance. It used to BE the frame `draw()` installs, read
16931
+ * at registration time, so a host that registered before `draw()` held the empty placeholder
16932
+ * for good and the overlay never drew. A getter rather than a field so the prototype-built
16933
+ * test doubles have it too.
16934
+ */
16935
+ get start() {
16936
+ var _a;
16937
+ return ((_a = this.boundStart) !== null && _a !== void 0 ? _a : (this.boundStart = () => this.startFrame()));
16938
+ }
16939
+ /**
16940
+ * Skips frames until the first slice has sized the canvases. Until then the master canvas is
16941
+ * 0x0, and `drawImage` of a 0x0 source throws InvalidStateError -- every frame, from inside
16942
+ * the scene's render, which then skips its own WebGL draw.
16943
+ */
16944
+ startFrame() {
16945
+ const master = this.state.protectedData.canvases.drawingCanvasLayerMaster;
16946
+ if (master.width === 0 || master.height === 0)
16947
+ return;
16948
+ this.renderFrame();
16949
+ }
16862
16950
  constructor(container, state) {
16863
16951
  this.drawingPrameters = {
16864
16952
  handleOnDrawingMouseDown: (ev) => { },
@@ -16909,7 +16997,8 @@
16909
16997
  */
16910
16998
  this.wheelModeBeforeDrag = null;
16911
16999
  // need to return to parent
16912
- this.start = () => { };
17000
+ /** The per-frame composite. `draw()` builds it (in `paintOnCanvas`); a no-op until then. */
17001
+ this.renderFrame = () => { };
16913
17002
  this.configContrastDragMode = () => {
16914
17003
  this.contrastTool.configContrastDragMode();
16915
17004
  };
@@ -17023,15 +17112,18 @@
17023
17112
  this.eventRouter.setKeydownHandler((ev) => {
17024
17113
  if (this.state.configKeyBoard)
17025
17114
  return;
17026
- // Handle undo (Ctrl+Z)
17115
+ // Handle undo (Ctrl+Z). Cancelled so the browser does not also run its own page-level
17116
+ // undo, which reverts the last text typed anywhere on the page and moves focus there.
17027
17117
  if ((ev.ctrlKey || ev.metaKey) && ev.key === this.state.keyboardSettings.undo) {
17118
+ ev.preventDefault();
17028
17119
  undoFlag = true;
17029
17120
  this.undoLastPainting();
17030
17121
  }
17031
- // Handle redo (Ctrl+<redo key> or Ctrl+Shift+<undo key>)
17122
+ // Handle redo (Ctrl+<redo key> or Ctrl+Shift+<undo key>), cancelled for the same reason
17032
17123
  const redoKey = this.state.keyboardSettings.redo;
17033
17124
  const undoKeyUpper = this.state.keyboardSettings.undo.toUpperCase();
17034
17125
  if ((ev.ctrlKey || ev.metaKey) && (ev.key === redoKey || (ev.shiftKey && ev.key === undoKeyUpper))) {
17126
+ ev.preventDefault();
17035
17127
  this.redoLastPainting();
17036
17128
  }
17037
17129
  // Handle mouse wheel mode toggle (Ctrl+1 = Scroll:Zoom, Ctrl+2 = Scroll:Slice)
@@ -17300,7 +17392,7 @@
17300
17392
  this.drawingPrameters.handleOnDrawingMouseUp = (e) => {
17301
17393
  this.onCanvasPointerUp(e);
17302
17394
  };
17303
- this.start = () => {
17395
+ this.renderFrame = () => {
17304
17396
  if (this.state.gui_states.viewConfig.readyToUpdate) {
17305
17397
  this.state.protectedData.ctxes.drawingCtx.clearRect(0, 0, this.state.nrrd_states.view.changedWidth, this.state.nrrd_states.view.changedHeight);
17306
17398
  this.state.protectedData.ctxes.drawingCtx.globalAlpha =
@@ -17550,7 +17642,7 @@
17550
17642
  if (!this.state.nrrd_states.flags.loadingMaskData) {
17551
17643
  const { data: sliceData, width, height } = this.renderer.getVolumeForLayer(delta.layerId)
17552
17644
  .getSliceUint8(delta.sliceIndex, delta.axis);
17553
- this.state.annotationCallbacks.onMaskChanged(sliceData, delta.layerId, this.state.gui_states.layerChannel.activeChannel || 1, delta.sliceIndex, delta.axis, width, height, false);
17645
+ this.state.annotationCallbacks.onMaskChanged(sliceData, delta.layerId, this.state.gui_states.layerChannel.activeChannel || 1, delta.sliceIndex, delta.axis, width, height, false, { channels: changedChannels(delta.oldSlice, delta.newSlice) });
17554
17646
  }
17555
17647
  }
17556
17648
  this.setIsDrawFalse(1000);
@@ -17583,7 +17675,7 @@
17583
17675
  if (!this.state.nrrd_states.flags.loadingMaskData) {
17584
17676
  const { data: sliceData, width, height } = this.renderer.getVolumeForLayer(delta.layerId)
17585
17677
  .getSliceUint8(delta.sliceIndex, delta.axis);
17586
- this.state.annotationCallbacks.onMaskChanged(sliceData, delta.layerId, this.state.gui_states.layerChannel.activeChannel || 1, delta.sliceIndex, delta.axis, width, height, false);
17678
+ this.state.annotationCallbacks.onMaskChanged(sliceData, delta.layerId, this.state.gui_states.layerChannel.activeChannel || 1, delta.sliceIndex, delta.axis, width, height, false, { channels: changedChannels(delta.oldSlice, delta.newSlice) });
17587
17679
  }
17588
17680
  }
17589
17681
  this.setIsDrawFalse(1000);
@@ -20774,8 +20866,9 @@
20774
20866
  }
20775
20867
  }
20776
20868
  /**
20777
- * Get the DrawToolCore's start() render loop callback.
20778
- * This is called by DragSliceTool's requestAnimationFrame loop.
20869
+ * The per-frame callback that draws the annotation overlay; register it with the scene.
20870
+ * The same function every time, so it may be registered before `draw()`. It does nothing
20871
+ * until `draw()` has run and the first slice has sized the canvases.
20779
20872
  */
20780
20873
  get start() {
20781
20874
  return this.drawCore.start;
@@ -22050,15 +22143,15 @@
22050
22143
  }
22051
22144
 
22052
22145
  // import * as kiwrious from "copper3d_plugin_heart_k";
22053
- // "v4.1.1" is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
22146
+ // "v4.1.3" is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
22054
22147
  // When copper3d is consumed from local source (no rollup replace step), the identifier is undefined and
22055
22148
  // referencing it throws a ReferenceError — guard it so local loading still works.
22056
22149
  let _revision = "unknown";
22057
22150
  try {
22058
- _revision = "v4.1.1";
22151
+ _revision = "v4.1.3";
22059
22152
  }
22060
22153
  catch (_a) {
22061
- /* "v4.1.1" not injected (local source build) */
22154
+ /* "v4.1.3" not injected (local source build) */
22062
22155
  }
22063
22156
  const REVISION = _revision;
22064
22157
  // "186" is three's revision at build time, injected the same way.
package/dist/index.d.ts CHANGED
@@ -56,7 +56,7 @@ import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadR
56
56
  import { IPaintImage, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, IGuiMeta } from "./Utils/segmentation/core/types";
57
57
  import { NrrdState } from "./Utils/segmentation/coreTools/NrrdState";
58
58
  import { GuiState } from "./Utils/segmentation/coreTools/GuiState";
59
- import type { ToolMode, IAnnotationCallbacks, MaskRenderMode } from "./Utils/segmentation/core/types";
59
+ import type { ToolMode, IAnnotationCallbacks, IMaskHistoryChange, MaskRenderMode } from "./Utils/segmentation/core/types";
60
60
  import { CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss } from "./Utils/segmentation/core/index";
61
61
  import type { LayerId, ChannelValue } from "./Utils/segmentation/core/index";
62
62
  import { MAX_ENGINE_CHANNEL } from "./Utils/segmentation/core/index";
@@ -66,5 +66,5 @@ import type { NrrdOrientationFields, OrientationErrorCode, OrientationTransform,
66
66
  import "./css/style.css";
67
67
  export declare const REVISION: string;
68
68
  export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, rasDimensions, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels, };
69
- export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation, };
69
+ export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, IMaskHistoryChange, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation, };
70
70
  export type { CameraViewPreset } from "./Controls/orbitFraming";
@@ -12,6 +12,8 @@ export declare class copperSceneOnDemond extends baseScene {
12
12
  controls: OrbitControls | Copper3dTrackballControls | TrackballControls;
13
13
  renderRequested: boolean | undefined;
14
14
  isResize: boolean;
15
+ /** Handle of the callback loop's next frame; null while the loop is not running. */
16
+ private callbackFrame;
15
17
  /**
16
18
  * `opt.controls` picks the controls class, as it already did on
17
19
  * `copperScene`. New in 3.9.0 -- this class hardcoded `OrbitControls`
@@ -47,6 +49,20 @@ export declare class copperSceneOnDemond extends baseScene {
47
49
  */
48
50
  setCameraPose(pose: Pose): void;
49
51
  confirmResize: () => void;
52
+ /**
53
+ * Registers a per-frame callback, as on `copperScene` -- `nrrdTools.start` is the usual one.
54
+ *
55
+ * This scene draws only on demand, and before 4.1.2 nothing here ran the registry:
56
+ * registering returned an id and the callback never ran. Now the scene runs a
57
+ * `requestAnimationFrame` loop of its own while anything is registered, and none while
58
+ * nothing is. The loop calls the callbacks and nothing else -- it does not render the WebGL
59
+ * scene, so a callback that changes what the scene shows still asks for a frame with
60
+ * `requestRenderIfNotRequested`.
61
+ */
62
+ addPreRenderCallbackFunction(callbackFunction: Function): number;
63
+ removePreRenderCallbackFunction(id: number): void;
64
+ private runCallbackFrame;
65
+ private stopCallbackLoop;
50
66
  /**
51
67
  * Releases what this scene attached OUTSIDE itself.
52
68
  *
@@ -22,6 +22,15 @@ import { UndoManager } from "./core";
22
22
  *
23
23
  * Created by NrrdTools which passes in a shared CanvasState.
24
24
  */
25
+ /**
26
+ * The channels a slice delta changed: every label that differs between the slice before and
27
+ * after, background (0) excluded, in ascending order.
28
+ *
29
+ * In a label volume a voxel's value is its channel, so this is exactly the set of channels an
30
+ * undo or redo of the delta touches — which is what the host needs to know, not the channel
31
+ * that happens to be active.
32
+ */
33
+ export declare function changedChannels(oldSlice: Uint8Array, newSlice: Uint8Array): number[];
25
34
  export declare class DrawToolCore {
26
35
  container: HTMLElement;
27
36
  mainAreaContainer: HTMLDivElement;
@@ -89,7 +98,24 @@ export declare class DrawToolCore {
89
98
  * Only set to 'Scroll:Zoom' — Scroll:Slice never needs a swap.
90
99
  */
91
100
  private wheelModeBeforeDrag;
92
- start: () => void;
101
+ /** The per-frame composite. `draw()` builds it (in `paintOnCanvas`); a no-op until then. */
102
+ private renderFrame;
103
+ private boundStart?;
104
+ /**
105
+ * The per-frame callback hosts register (`scene.addPreRenderCallbackFunction(nrrdTools.start)`).
106
+ *
107
+ * One function for the life of the instance. It used to BE the frame `draw()` installs, read
108
+ * at registration time, so a host that registered before `draw()` held the empty placeholder
109
+ * for good and the overlay never drew. A getter rather than a field so the prototype-built
110
+ * test doubles have it too.
111
+ */
112
+ get start(): () => void;
113
+ /**
114
+ * Skips frames until the first slice has sized the canvases. Until then the master canvas is
115
+ * 0x0, and `drawImage` of a 0x0 source throws InvalidStateError -- every frame, from inside
116
+ * the scene's render, which then skips its own WebGL draw.
117
+ */
118
+ private startFrame;
93
119
  constructor(container: HTMLElement, state: CanvasState);
94
120
  private initTools;
95
121
  private initDrawToolCore;
@@ -480,8 +480,9 @@ export declare class NrrdTools {
480
480
  private setShowInMainArea;
481
481
  private clearDictionary;
482
482
  /**
483
- * Get the DrawToolCore's start() render loop callback.
484
- * This is called by DragSliceTool's requestAnimationFrame loop.
483
+ * The per-frame callback that draws the annotation overlay; register it with the scene.
484
+ * The same function every time, so it may be registered before `draw()`. It does nothing
485
+ * until `draw()` has run and the first slice has sized the canvases.
485
486
  */
486
487
  get start(): () => void;
487
488
  /**
@@ -67,7 +67,7 @@
67
67
  * const legacy = convertVolumeToIPaintImages(volume);
68
68
  * ```
69
69
  */
70
- export type { Dimensions, RGBAColor, ChannelColorMap, SliceRenderOptions, LayerId, ChannelValue, ICommXYZ, ICommXY, ISkipSlicesDictType, ToolMode, IDragPrameters, IDrawingEvents, IContrastEvents, IPaintImages, IPaintImage, ILayerRenderTarget, IDownloadImageConfig, INewMaskData, IMaskData, IProtected, IToolModeState, IDrawingConfig, IViewConfig, ILayerChannelState, IGUIStates, IGuiMeta, IGuiParameterSettings, IImageMetadata, IViewState, IInteractionState, ISphereState, IInternalFlags, INrrdStates, IAnnotationCallbacks, IConvertObjType, ICursorPage, IDragOpts, IDrawOpts, IKeyBoardSettings, MaskRenderMode, } from './types';
70
+ export type { Dimensions, RGBAColor, ChannelColorMap, SliceRenderOptions, LayerId, ChannelValue, ICommXYZ, ICommXY, ISkipSlicesDictType, ToolMode, IDragPrameters, IDrawingEvents, IContrastEvents, IPaintImages, IPaintImage, ILayerRenderTarget, IDownloadImageConfig, INewMaskData, IMaskData, IProtected, IToolModeState, IDrawingConfig, IViewConfig, ILayerChannelState, IGUIStates, IGuiMeta, IGuiParameterSettings, IImageMetadata, IViewState, IInteractionState, ISphereState, IInternalFlags, INrrdStates, IAnnotationCallbacks, IMaskHistoryChange, IConvertObjType, ICursorPage, IDragOpts, IDrawOpts, IKeyBoardSettings, MaskRenderMode, } from './types';
71
71
  export { RenderMode, MAX_ENGINE_CHANNEL, MASK_CHANNEL_COLORS, MASK_CHANNEL_CSS_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, } from './types';
72
72
  export { MaskVolume } from './MaskVolume';
73
73
  export type { MaskDelta, UndoEntry } from './UndoManager';
@@ -459,8 +459,18 @@ export interface IInternalFlags {
459
459
  export interface INrrdStates extends IImageMetadata, IViewState, IInteractionState, ISphereState, IInternalFlags {
460
460
  }
461
461
  /** Callbacks for external notification of annotation data changes */
462
+ /** What an undo or redo changed, passed with the slice it restored. */
463
+ export interface IMaskHistoryChange {
464
+ /** The channels whose voxels the undone or redone delta changed, ascending. */
465
+ channels: number[];
466
+ }
462
467
  export interface IAnnotationCallbacks {
463
- onMaskChanged(sliceData: Uint8Array, layerId: string, channelId: number, sliceIndex: number, axis: "x" | "y" | "z", width: number, height: number, clearFlag: boolean): void;
468
+ /**
469
+ * A slice of a layer changed. `channelId` is the active channel, which is the one a stroke
470
+ * paints. `history` is set only when the change was an undo or redo: it names the channels
471
+ * that change actually touched, which need not include the active one.
472
+ */
473
+ onMaskChanged(sliceData: Uint8Array, layerId: string, channelId: number, sliceIndex: number, axis: "x" | "y" | "z", width: number, height: number, clearFlag: boolean, history?: IMaskHistoryChange): void;
464
474
  onSphereChanged(sphereOrigin: number[], sphereRadius: number): void;
465
475
  onCalculatorPositionsChanged(tumour: ICommXYZ | null, skin: ICommXYZ | null, rib: ICommXYZ | null, nipple: ICommXYZ | null, axis: "x" | "y" | "z"): void;
466
476
  onLayerVolumeCleared(layerId: string): void;
@@ -508,7 +518,7 @@ export interface IDragOpts {
508
518
  getSliceNum?: (index: number, contrastNum: number) => void;
509
519
  }
510
520
  export interface IDrawOpts {
511
- getMaskData?: (sliceData: Uint8Array, layerId: string, channelId: number, sliceIndex: number, axis: "x" | "y" | "z", width: number, height: number, clearFlag?: boolean) => void;
521
+ getMaskData?: (sliceData: Uint8Array, layerId: string, channelId: number, sliceIndex: number, axis: "x" | "y" | "z", width: number, height: number, clearFlag?: boolean, history?: IMaskHistoryChange) => void;
512
522
  onClearLayerVolume?: (layerId: string) => void;
513
523
  onLayerVolumeReplaced?: (layerId: string) => void;
514
524
  getSphereData?: (sphereOrigin: number[], sphereRadius: number) => void;
@@ -56,7 +56,7 @@ import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadR
56
56
  import { IPaintImage, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, IGuiMeta } from "./Utils/segmentation/core/types";
57
57
  import { NrrdState } from "./Utils/segmentation/coreTools/NrrdState";
58
58
  import { GuiState } from "./Utils/segmentation/coreTools/GuiState";
59
- import type { ToolMode, IAnnotationCallbacks, MaskRenderMode } from "./Utils/segmentation/core/types";
59
+ import type { ToolMode, IAnnotationCallbacks, IMaskHistoryChange, MaskRenderMode } from "./Utils/segmentation/core/types";
60
60
  import { CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss } from "./Utils/segmentation/core/index";
61
61
  import type { LayerId, ChannelValue } from "./Utils/segmentation/core/index";
62
62
  import { MAX_ENGINE_CHANNEL } from "./Utils/segmentation/core/index";
@@ -66,5 +66,5 @@ import type { NrrdOrientationFields, OrientationErrorCode, OrientationTransform,
66
66
  import "./css/style.css";
67
67
  export declare const REVISION: string;
68
68
  export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, rasDimensions, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels, };
69
- export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation, };
69
+ export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, IMaskHistoryChange, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation, };
70
70
  export type { CameraViewPreset } from "./Controls/orbitFraming";
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": "4.1.1",
4
+ "version": "4.1.3",
5
5
  "main": "dist/bundle.umd.js",
6
6
  "module": "dist/bundle.esm.mjs",
7
7
  "types": "dist/types/index.d.ts",