copper3d 3.7.0 → 3.7.1

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 (165) hide show
  1. package/dist/Controls/Copper3dOrbitControls.d.ts +54 -0
  2. package/dist/Controls/Copper3dOrbitControls.js +134 -0
  3. package/dist/Controls/Copper3dOrbitControls.js.map +1 -0
  4. package/dist/Controls/Copper3dTrackballControls.d.ts +45 -45
  5. package/dist/Controls/Copper3dTrackballControls.js.map +1 -1
  6. package/dist/Controls/copperControls.d.ts +17 -17
  7. package/dist/Controls/copperControls.js.map +1 -1
  8. package/dist/Controls/orbitFraming.d.ts +71 -0
  9. package/dist/Controls/orbitFraming.js +94 -0
  10. package/dist/Controls/orbitFraming.js.map +1 -0
  11. package/dist/Loader/copperDicomLoader.d.ts +13 -13
  12. package/dist/Loader/copperDicomLoader.js.map +1 -1
  13. package/dist/Loader/copperGltfLoader.d.ts +3 -3
  14. package/dist/Loader/copperNrrdLoader.d.ts +13 -13
  15. package/dist/Loader/copperNrrdLoader.js.map +1 -1
  16. package/dist/Loader/copperOBJLoader.d.ts +3 -3
  17. package/dist/Loader/copperRaw4DVolumeLoader.d.ts +10 -10
  18. package/dist/Loader/copperRaw4DVolumeLoader.js.map +1 -1
  19. package/dist/Loader/copperVtkLoader.d.ts +8 -8
  20. package/dist/Loader/copperVtkLoader.js.map +1 -1
  21. package/dist/Loader/mhdParser.d.ts +83 -83
  22. package/dist/Loader/mhdParser.js.map +1 -1
  23. package/dist/Renderer/baseRenderer.d.ts +32 -33
  24. package/dist/Renderer/baseRenderer.js +1 -1
  25. package/dist/Renderer/baseRenderer.js.map +1 -1
  26. package/dist/Renderer/copperMSceneRenderer.d.ts +24 -24
  27. package/dist/Renderer/copperMSceneRenderer.js.map +1 -1
  28. package/dist/Renderer/copperRenderer.d.ts +20 -20
  29. package/dist/Renderer/copperRenderer.js.map +1 -1
  30. package/dist/Renderer/copperRendererOnDemond.d.ts +12 -12
  31. package/dist/Renderer/copperRendererOnDemond.js.map +1 -1
  32. package/dist/Scene/baseScene.d.ts +38 -38
  33. package/dist/Scene/baseScene.js.map +1 -1
  34. package/dist/Scene/commonSceneMethod.d.ts +50 -50
  35. package/dist/Scene/commonSceneMethod.js.map +1 -1
  36. package/dist/Scene/copperMScene.d.ts +42 -42
  37. package/dist/Scene/copperMScene.js.map +1 -1
  38. package/dist/Scene/copperScene.d.ts +64 -64
  39. package/dist/Scene/copperScene.js.map +1 -1
  40. package/dist/Scene/copperSceneOnDemond.d.ts +13 -13
  41. package/dist/Scene/copperSceneOnDemond.js.map +1 -1
  42. package/dist/Scene/preRenderRegistry.d.ts +33 -33
  43. package/dist/Utils/MeshNodeTool.d.ts +41 -41
  44. package/dist/Utils/MeshNodeTool.js.map +1 -1
  45. package/dist/Utils/add3DLabel.d.ts +18 -18
  46. package/dist/Utils/add3DLabel.js.map +1 -1
  47. package/dist/Utils/colormapData.d.ts +9 -9
  48. package/dist/Utils/colormapData.js.map +1 -1
  49. package/dist/Utils/convet.d.ts +1 -1
  50. package/dist/Utils/convet.js.map +1 -1
  51. package/dist/Utils/download.d.ts +1 -1
  52. package/dist/Utils/download.js.map +1 -1
  53. package/dist/Utils/getVOILUT.d.ts +13 -13
  54. package/dist/Utils/getVOILUT.js.map +1 -1
  55. package/dist/Utils/kiwrious/configKiwrious.d.ts +4 -4
  56. package/dist/Utils/kiwrious/configKiwrious.js.map +1 -1
  57. package/dist/Utils/raycaster.d.ts +8 -8
  58. package/dist/Utils/raycaster.js.map +1 -1
  59. package/dist/Utils/segmentation/CanvasState.d.ts +31 -31
  60. package/dist/Utils/segmentation/CanvasState.js.map +1 -1
  61. package/dist/Utils/segmentation/DragOperator.d.ts +45 -45
  62. package/dist/Utils/segmentation/DragOperator.js.map +1 -1
  63. package/dist/Utils/segmentation/DrawToolCore.d.ts +168 -168
  64. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -1
  65. package/dist/Utils/segmentation/NrrdTools.d.ts +334 -334
  66. package/dist/Utils/segmentation/NrrdTools.js +1 -1
  67. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  68. package/dist/Utils/segmentation/RenderingUtils.d.ts +96 -96
  69. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
  70. package/dist/Utils/segmentation/core/GaussianSmoother.d.ts +55 -55
  71. package/dist/Utils/segmentation/core/GaussianSmoother.js.map +1 -1
  72. package/dist/Utils/segmentation/core/MarchingSquares.d.ts +80 -80
  73. package/dist/Utils/segmentation/core/MarchingSquares.js.map +1 -1
  74. package/dist/Utils/segmentation/core/MaskVolume.d.ts +471 -471
  75. package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
  76. package/dist/Utils/segmentation/core/UndoManager.d.ts +51 -51
  77. package/dist/Utils/segmentation/core/UndoManager.js.map +1 -1
  78. package/dist/Utils/segmentation/core/index.d.ts +76 -76
  79. package/dist/Utils/segmentation/core/types.d.ts +505 -505
  80. package/dist/Utils/segmentation/core/types.js +36 -36
  81. package/dist/Utils/segmentation/core/types.js.map +1 -1
  82. package/dist/Utils/segmentation/coreTools/GuiState.d.ts +22 -22
  83. package/dist/Utils/segmentation/coreTools/NrrdState.d.ts +25 -25
  84. package/dist/Utils/segmentation/coreTools/divControlTools.d.ts +19 -19
  85. package/dist/Utils/segmentation/coreTools/gui.d.ts +42 -42
  86. package/dist/Utils/segmentation/coreTools/gui.js.map +1 -1
  87. package/dist/Utils/segmentation/eventRouter/EventRouter.d.ts +157 -157
  88. package/dist/Utils/segmentation/eventRouter/EventRouter.js.map +1 -1
  89. package/dist/Utils/segmentation/eventRouter/index.d.ts +7 -7
  90. package/dist/Utils/segmentation/eventRouter/types.d.ts +71 -71
  91. package/dist/Utils/segmentation/tools/AiAssistTool.d.ts +249 -249
  92. package/dist/Utils/segmentation/tools/AiAssistTool.js.map +1 -1
  93. package/dist/Utils/segmentation/tools/BaseTool.d.ts +31 -31
  94. package/dist/Utils/segmentation/tools/ContrastTool.d.ts +23 -23
  95. package/dist/Utils/segmentation/tools/ContrastTool.js.map +1 -1
  96. package/dist/Utils/segmentation/tools/CrosshairTool.d.ts +40 -40
  97. package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
  98. package/dist/Utils/segmentation/tools/DataLoader.d.ts +33 -33
  99. package/dist/Utils/segmentation/tools/DataLoader.js.map +1 -1
  100. package/dist/Utils/segmentation/tools/DragSliceTool.d.ts +33 -33
  101. package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
  102. package/dist/Utils/segmentation/tools/DrawingTool.d.ts +126 -126
  103. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
  104. package/dist/Utils/segmentation/tools/EraserTool.d.ts +16 -16
  105. package/dist/Utils/segmentation/tools/EraserTool.js.map +1 -1
  106. package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +42 -42
  107. package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
  108. package/dist/Utils/segmentation/tools/LayerChannelManager.d.ts +56 -56
  109. package/dist/Utils/segmentation/tools/LayerChannelManager.js.map +1 -1
  110. package/dist/Utils/segmentation/tools/PanTool.d.ts +47 -47
  111. package/dist/Utils/segmentation/tools/PanTool.js.map +1 -1
  112. package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +85 -85
  113. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
  114. package/dist/Utils/segmentation/tools/SphereBrushTool.d.ts +204 -204
  115. package/dist/Utils/segmentation/tools/SphereBrushTool.js.map +1 -1
  116. package/dist/Utils/segmentation/tools/SphereTool.d.ts +249 -249
  117. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
  118. package/dist/Utils/segmentation/tools/ToolHost.d.ts +76 -76
  119. package/dist/Utils/segmentation/tools/ZoomTool.d.ts +16 -16
  120. package/dist/Utils/segmentation/tools/ZoomTool.js.map +1 -1
  121. package/dist/Utils/segmentation/tools/index.d.ts +25 -25
  122. package/dist/Utils/surfaceAnnotation/MeshGraph.d.ts +46 -46
  123. package/dist/Utils/surfaceAnnotation/MeshGraph.js.map +1 -1
  124. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.d.ts +213 -213
  125. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js.map +1 -1
  126. package/dist/Utils/surfaceAnnotation/annotationStore.d.ts +32 -32
  127. package/dist/Utils/surfaceAnnotation/annotationStore.js.map +1 -1
  128. package/dist/Utils/surfaceAnnotation/contourRender.d.ts +7 -7
  129. package/dist/Utils/surfaceAnnotation/geodesicContour.d.ts +59 -59
  130. package/dist/Utils/surfaceAnnotation/geodesicContour.js.map +1 -1
  131. package/dist/Utils/surfaceAnnotation/index.d.ts +3 -3
  132. package/dist/Utils/surfaceAnnotation/pointMarkers.d.ts +16 -16
  133. package/dist/Utils/surfaceAnnotation/raycastSurface.d.ts +8 -8
  134. package/dist/Utils/surfaceAnnotation/raycastSurface.js.map +1 -1
  135. package/dist/Utils/surfaceAnnotation/strokeContour.d.ts +29 -29
  136. package/dist/Utils/surfaceAnnotation/strokeContour.js.map +1 -1
  137. package/dist/Utils/surfaceAnnotation/types.d.ts +47 -47
  138. package/dist/Utils/texture2d.d.ts +14 -14
  139. package/dist/Utils/texture2d.js.map +1 -1
  140. package/dist/Utils/utils.d.ts +37 -37
  141. package/dist/Utils/utils.js.map +1 -1
  142. package/dist/Utils/volumeColormap.d.ts +6 -6
  143. package/dist/Utils/volumeShader.d.ts +7 -7
  144. package/dist/Utils/workers/reformatSaveDataWorker.d.ts +13 -13
  145. package/dist/Utils/workers/reformatSaveDataWorker.js.map +1 -1
  146. package/dist/bundle.esm.js +64859 -44206
  147. package/dist/bundle.umd.js +64876 -44222
  148. package/dist/index.d.ts +35 -33
  149. package/dist/index.js +2 -1
  150. package/dist/index.js.map +1 -1
  151. package/dist/lib/dicom_pharser_dictionary.d.ts +1 -1
  152. package/dist/lib/environment/index.d.ts +8 -8
  153. package/dist/lib/three-vignette.d.ts +11 -11
  154. package/dist/lib/three-vignette.js.map +1 -1
  155. package/dist/types/Controls/Copper3dOrbitControls.d.ts +54 -0
  156. package/dist/types/Controls/orbitFraming.d.ts +71 -0
  157. package/dist/types/Loader/copperDicomLoader.d.ts +1 -1
  158. package/dist/types/Renderer/baseRenderer.d.ts +0 -1
  159. package/dist/types/Scene/copperScene.d.ts +1 -1
  160. package/dist/types/Utils/convet.d.ts +1 -1
  161. package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  162. package/dist/types/Utils/workers/reformatSaveDataWorker.d.ts +1 -1
  163. package/dist/types/index.d.ts +3 -1
  164. package/dist/types/types.d.ts +310 -310
  165. package/package.json +4 -4
@@ -1,471 +1,471 @@
1
- /**
2
- * MaskVolume — True 3D Volumetric Mask Storage
3
- *
4
- * Stores annotation masks in a single contiguous Uint8Array with the memory
5
- * layout [z][y][x][channel] (slice-major order).
6
- *
7
- * Design goals:
8
- * - Contiguous memory for optimal cache locality and minimal GC pressure.
9
- * - Multi-channel support (binary mask, confidence, labels, etc.).
10
- * - O(1) voxel access with full bounds checking.
11
- * - Slice extraction to ImageData for Canvas rendering (all 3 axes).
12
- * - Multi-channel color mapping with 4 render modes.
13
- *
14
- * Memory comparison (512 × 512 × 100, 1 channel):
15
- * Old ImageData approach ≈ 4.4 GB → MaskVolume ≈ 25 MB (~99 % reduction)
16
- *
17
- * @example
18
- * ```ts
19
- * const vol = new MaskVolume(512, 512, 100); // 1 channel (default)
20
- * vol.setVoxel(256, 256, 50, 255); // paint centre voxel
21
- *
22
- * // Grayscale slice (backward compatible)
23
- * const slice = vol.getSliceImageData(50, 'z');
24
- *
25
- * // Colored slice
26
- * const colored = vol.getSliceImageData(50, 'z', {
27
- * mode: RenderMode.COLORED_SINGLE,
28
- * channel: 0,
29
- * opacity: 0.6,
30
- * });
31
- * ```
32
- */
33
- import type { Dimensions, RGBAColor, ChannelColorMap, SliceRenderOptions } from './types';
34
- export declare class MaskVolume {
35
- /** Contiguous backing buffer — layout [z][y][x][channel]. */
36
- private data;
37
- /** Volume size in voxels. */
38
- private readonly dims;
39
- /** Number of value channels per voxel (≥ 1). */
40
- private readonly numChannels;
41
- /**
42
- * Number of bytes in one complete z-slice.
43
- * Equal to width × height × channels.
44
- */
45
- private readonly bytesPerSlice;
46
- /** Per-channel color map used for colored rendering modes. */
47
- private colorMap;
48
- /**
49
- * Monotonic data-mutation counter.
50
- *
51
- * Incremented by every method that mutates voxel data (not color).
52
- * Consumers (e.g. the contour cache in RenderingUtils) key cached
53
- * derivations on this value so an edit automatically invalidates them —
54
- * it is impossible to forget an invalidation point because every write
55
- * bumps the version. Color-map changes do **not** bump it (colors are
56
- * applied at fill time, never cached).
57
- */
58
- private version;
59
- /**
60
- * Create a new MaskVolume.
61
- *
62
- * All voxels are initialised to **0**.
63
- *
64
- * @param width Number of voxels along the X axis (≥ 1).
65
- * @param height Number of voxels along the Y axis (≥ 1).
66
- * @param depth Number of voxels along the Z axis (≥ 1).
67
- * @param channels Number of channels per voxel (default 1).
68
- * @param customColorMap Optional color map to override defaults.
69
- *
70
- * @throws {RangeError} If any dimension or the channel count is < 1.
71
- */
72
- constructor(width: number, height: number, depth: number, channels?: number, customColorMap?: ChannelColorMap);
73
- /**
74
- * Map 3D coordinates + channel to a flat 1D index.
75
- *
76
- * **Memory layout (slice-major):**
77
- * ```
78
- * index = (z × height × width × channels)
79
- * + (y × width × channels)
80
- * + (x × channels)
81
- * + channel
82
- * ```
83
- *
84
- * @param x Voxel column (0 … width − 1).
85
- * @param y Voxel row (0 … height − 1).
86
- * @param z Slice index (0 … depth − 1).
87
- * @param channel Channel index (0 … channels − 1).
88
- * @returns Flat 1D index into `this.data`.
89
- *
90
- * @throws {RangeError} If any coordinate or channel is out of bounds.
91
- */
92
- private getIndex;
93
- /**
94
- * Read a single voxel value.
95
- *
96
- * @param x Voxel column (0 … width − 1).
97
- * @param y Voxel row (0 … height − 1).
98
- * @param z Slice index (0 … depth − 1).
99
- * @param channel Channel index (default 0).
100
- * @returns The stored value (0 – 255).
101
- *
102
- * @throws {RangeError} If any coordinate is out of bounds.
103
- */
104
- getVoxel(x: number, y: number, z: number, channel?: number): number;
105
- /**
106
- * Write a single voxel value.
107
- *
108
- * Values are clamped to the Uint8 range [0, 255] by the typed array.
109
- *
110
- * @param x Voxel column (0 … width − 1).
111
- * @param y Voxel row (0 … height − 1).
112
- * @param z Slice index (0 … depth − 1).
113
- * @param value New voxel value (0 – 255).
114
- * @param channel Channel index (default 0).
115
- *
116
- * @throws {RangeError} If any coordinate is out of bounds.
117
- */
118
- setVoxel(x: number, y: number, z: number, value: number, channel?: number): void;
119
- /**
120
- * Return the current data-mutation version.
121
- *
122
- * Increments on every voxel write. Use as a cache key so derived data
123
- * (e.g. extracted contours) is invalidated whenever the volume changes.
124
- */
125
- getVersion(): number;
126
- /**
127
- * Update the color for a specific label/channel in the color map.
128
- *
129
- * For label-based volumes (1-channel), the channel parameter refers to
130
- * the label value (0-8), not the storage channel index.
131
- *
132
- * @param channel Label/channel index to update (0-8).
133
- * @param color New RGBA color.
134
- *
135
- * @throws {RangeError} If channel is outside valid label range [0, 8].
136
- */
137
- setChannelColor(channel: number, color: RGBAColor): void;
138
- /**
139
- * Get the current color for a channel.
140
- *
141
- * Falls back to the background color (transparent) if no color is defined.
142
- *
143
- * @param channel Channel index.
144
- * @returns A copy of the RGBA color.
145
- */
146
- getChannelColor(channel: number): RGBAColor;
147
- /**
148
- * Reset the color map for one or all labels to defaults.
149
- *
150
- * @param channel Optional specific label to reset. If omitted, resets all.
151
- */
152
- resetChannelColors(channel?: number): void;
153
- /**
154
- * Get a shallow copy of the entire color map.
155
- *
156
- * @returns A copy of the color map (safe to mutate).
157
- */
158
- getColorMap(): ChannelColorMap;
159
- /**
160
- * Extract a 2D slice as an ImageData with color mapping.
161
- *
162
- * Slice dimensions depend on the axis:
163
- *
164
- * | Axis | Plane | Width | Height |
165
- * |------|----------|--------|--------|
166
- * | `z` | Axial | width | height |
167
- * | `y` | Coronal | width | depth |
168
- * | `x` | Sagittal | depth | height |
169
- *
170
- * @param sliceIndex Index along the specified axis.
171
- * @param axis `'x'` (sagittal), `'y'` (coronal), or `'z'` (axial).
172
- * @param options Rendering options (mode, channel, colors, etc.).
173
- * @returns ImageData ready for `ctx.putImageData()`.
174
- *
175
- * @throws {RangeError} If sliceIndex is out of bounds for the given axis.
176
- *
177
- * @example
178
- * ```ts
179
- * // Grayscale (default, backward compatible)
180
- * const gs = vol.getSliceImageData(50, 'z');
181
- *
182
- * // Colored single-channel
183
- * const cs = vol.getSliceImageData(50, 'z', {
184
- * mode: RenderMode.COLORED_SINGLE,
185
- * channel: 0,
186
- * });
187
- *
188
- * // Multi-channel priority
189
- * const mc = vol.getSliceImageData(50, 'z', {
190
- * mode: RenderMode.COLORED_MULTI,
191
- * visibleChannels: [false, true, true, true],
192
- * });
193
- * ```
194
- */
195
- getSliceImageData(sliceIndex: number, axis?: 'x' | 'y' | 'z', options?: SliceRenderOptions): ImageData;
196
- /**
197
- * Write a 2D ImageData back into the volume for the given axis/slice.
198
- *
199
- * When the volume has **4 channels**, all RGBA components are stored
200
- * (ch0=R, ch1=G, ch2=B, ch3=A) for lossless round-trip.
201
- * Otherwise, the **R channel** of each pixel is used as grayscale.
202
- *
203
- * @param sliceIndex Index along the specified axis.
204
- * @param imageData Source ImageData (expected dimensions must match the axis).
205
- * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
206
- * @param channel Target channel (default 0, ignored when numChannels >= 4).
207
- *
208
- * @throws {RangeError} If sliceIndex is out of bounds.
209
- * @throws {Error} If imageData dimensions don't match.
210
- *
211
- * @example
212
- * ```ts
213
- * const imgData = ctx.getImageData(0, 0, 512, 512);
214
- * vol.setSliceFromImageData(50, imgData, 'z');
215
- * ```
216
- */
217
- setSliceFromImageData(sliceIndex: number, imageData: ImageData, axis?: 'x' | 'y' | 'z', channel?: number): void;
218
- /**
219
- /**
220
- * Store label data from canvas RGBA ImageData into a 1-channel volume.
221
- *
222
- * For each pixel: matches the RGB color against MASK_CHANNEL_COLORS to
223
- * determine which channel label to store. If no match is found, falls
224
- * back to `activeChannel`. Transparent pixels (alpha === 0) are stored as 0.
225
- *
226
- * This is the write counterpart to `renderLabelSliceInto`.
227
- *
228
- * @param sliceIndex Index along the specified axis.
229
- * @param imageData Canvas ImageData (RGBA) to convert.
230
- * @param axis `'x'`, `'y'`, or `'z'`.
231
- * @param activeChannel Fallback label for pixels whose RGB doesn't match any channel (1-8).
232
- * @param channelVisible Optional map of visible channels (true=visible, false=hidden).
233
- * If provided, data for hidden channels will be preserved
234
- * when the canvas pixel is transparent.
235
- */
236
- setSliceLabelsFromImageData(sliceIndex: number, imageData: ImageData, axis?: 'x' | 'y' | 'z', activeChannel?: number, channelVisible?: Record<number, boolean>): void;
237
- /**
238
- * Build a Map from RGB packed integer to channel label for reverse lookup.
239
- * Uses this instance's colorMap (channels 1-8, skips 0 = transparent).
240
- *
241
- * Instance method ensures custom per-layer colors are correctly reverse-mapped.
242
- */
243
- private buildRgbToChannelMap;
244
- /**
245
- * Render a 1-channel label slice into a pre-allocated RGBA ImageData buffer.
246
- *
247
- * Each voxel stores a label value (0-8). Label 0 = transparent.
248
- * Labels 1-8 are mapped to colors via MASK_CHANNEL_COLORS, filtered
249
- * by the channelVisible array.
250
- *
251
- * @param sliceIndex Index along the specified axis.
252
- * @param axis `'x'`, `'y'`, or `'z'`.
253
- * @param target Pre-allocated ImageData buffer (must match slice dimensions).
254
- * @param channelVisible Array where index N indicates if channel N is visible.
255
- * If undefined, all channels are visible.
256
- * @param opacity Opacity multiplier 0.0–1.0 (default 1.0).
257
- */
258
- renderLabelSliceInto(sliceIndex: number, axis: "x" | "y" | "z" | undefined, target: ImageData, channelVisible?: Record<number, boolean>, opacity?: number): void;
259
- /**
260
- * Return a copy of the volume dimensions.
261
- *
262
- * @returns `{ width, height, depth }` — a fresh object (safe to mutate).
263
- */
264
- getDimensions(): Dimensions;
265
- /**
266
- * Return the number of channels per voxel.
267
- *
268
- * @returns Channel count (≥ 1).
269
- */
270
- getChannels(): number;
271
- /**
272
- * Return the number of bytes in one complete z-slice.
273
- *
274
- * Equal to `width × height × channels`. Useful for direct buffer
275
- * index arithmetic in performance-critical code paths.
276
- *
277
- * @returns Bytes per z-slice.
278
- */
279
- getBytesPerSlice(): number;
280
- /**
281
- * Return total memory used by the backing buffer, in bytes.
282
- *
283
- * @returns `width × height × depth × channels` bytes.
284
- *
285
- * @example
286
- * ```ts
287
- * const vol = new MaskVolume(512, 512, 100);
288
- * vol.getMemoryUsage(); // 26_214_400 (~25 MB)
289
- * ```
290
- */
291
- getMemoryUsage(): number;
292
- /**
293
- * Return a **reference** to the raw backing buffer.
294
- *
295
- * Use this for direct read access (e.g. serialisation, GPU upload).
296
- * Mutating the returned array mutates the volume.
297
- *
298
- * @returns The underlying Uint8Array.
299
- *
300
- * @example
301
- * ```ts
302
- * // Serialise for network transfer
303
- * const bytes = vol.getRawData();
304
- * socket.send(bytes.buffer);
305
- * ```
306
- */
307
- getRawData(): Uint8Array;
308
- /**
309
- * Replace the entire backing buffer.
310
- *
311
- * The provided array **must** have exactly the same length as the
312
- * current buffer (`width × height × depth × channels`).
313
- *
314
- * @param newData Replacement data.
315
- * @throws {Error} If the length does not match.
316
- *
317
- * @example
318
- * ```ts
319
- * // Restore from a saved snapshot
320
- * const saved = new Uint8Array(savedBuffer);
321
- * vol.setRawData(saved);
322
- * ```
323
- */
324
- setRawData(newData: Uint8Array): void;
325
- /**
326
- * Create an independent deep copy of this volume.
327
- *
328
- * The clone has the same dimensions, channels, data, and color map
329
- * but shares no references with the original.
330
- *
331
- * @returns A new MaskVolume with identical content.
332
- *
333
- * @example
334
- * ```ts
335
- * // Undo support: snapshot before an operation
336
- * const snapshot = vol.clone();
337
- * performEdit(vol);
338
- * // Rollback: vol.setRawData(snapshot.getRawData());
339
- * ```
340
- */
341
- clone(): MaskVolume;
342
- /**
343
- * Zero every voxel in the entire volume (all channels).
344
- *
345
- * @example
346
- * ```ts
347
- * vol.clear();
348
- * vol.getVoxel(256, 256, 50); // 0
349
- * ```
350
- */
351
- clear(): void;
352
- /**
353
- * Check if the volume contains any non-zero voxel data.
354
- *
355
- * Returns true if at least one voxel has a non-zero value,
356
- * false if all voxels are zero (empty mask).
357
- *
358
- * This is useful for determining if a layer has actual mask
359
- * annotations before saving or exporting.
360
- *
361
- * @returns True if any voxel is non-zero, false if all zeros.
362
- *
363
- * @example
364
- * ```ts
365
- * const vol = new MaskVolume(512, 512, 100);
366
- * vol.hasData(); // false (all zeros)
367
- *
368
- * vol.setVoxel(256, 256, 50, 255);
369
- * vol.hasData(); // true
370
- * ```
371
- */
372
- hasData(): boolean;
373
- /**
374
- * Zero every voxel in a single slice along the given axis.
375
- *
376
- * If `channel` is provided, only that channel is cleared;
377
- * otherwise **all** channels in the slice are cleared.
378
- *
379
- * @param sliceIndex Index along the specified axis.
380
- * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
381
- * @param channel Optional channel to clear (default: all).
382
- *
383
- * @throws {RangeError} If sliceIndex is out of bounds.
384
- *
385
- * @example
386
- * ```ts
387
- * // Erase a single axial slice
388
- * vol.clearSlice(50, 'z');
389
- *
390
- * // Erase only channel 1 of slice 50
391
- * vol.clearSlice(50, 'z', 1);
392
- * ```
393
- */
394
- clearSlice(sliceIndex: number, axis?: 'x' | 'y' | 'z', channel?: number): void;
395
- /**
396
- * Extract a 2D slice as a flat Uint8Array (one byte per voxel per channel).
397
- *
398
- * For a 1-channel volume the result is `sliceWidth × sliceHeight` bytes,
399
- * each byte being the label value at that pixel. This is suitable for
400
- * sending to a backend that expects raw label data (e.g. NIfTI slice
401
- * replacement).
402
- *
403
- * @param sliceIndex Index along the specified axis.
404
- * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
405
- * @returns A **copy** of the slice data plus its dimensions.
406
- *
407
- * @throws {RangeError} If sliceIndex is out of bounds.
408
- *
409
- * @example
410
- * ```ts
411
- * const { data, width, height } = vol.getSliceUint8(50, 'z');
412
- * // data.length === width * height * channels
413
- * ```
414
- */
415
- getSliceUint8(sliceIndex: number, axis?: 'x' | 'y' | 'z'): {
416
- data: Uint8Array;
417
- width: number;
418
- height: number;
419
- };
420
- /**
421
- * Write a 2D slice from a flat Uint8Array back into the volume.
422
- *
423
- * This is the inverse of {@link getSliceUint8}. The `data` array must
424
- * have exactly `sliceWidth × sliceHeight × channels` bytes.
425
- *
426
- * @param sliceIndex Index along the specified axis.
427
- * @param data Flat source array (same layout as returned by getSliceUint8).
428
- * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
429
- *
430
- * @throws {RangeError} If sliceIndex is out of bounds.
431
- */
432
- setSliceUint8(sliceIndex: number, data: Uint8Array, axis?: 'x' | 'y' | 'z'): void;
433
- /**
434
- * Get the 2D slice dimensions for a given axis.
435
- *
436
- * @returns `[width, height]` of the slice.
437
- */
438
- private getSliceDimensions;
439
- /**
440
- * Validate that a slice index is within bounds for the given axis.
441
- *
442
- * @throws {RangeError} If out of bounds.
443
- */
444
- private validateSliceIndex;
445
- /**
446
- * Render a single channel as grayscale (original behaviour).
447
- *
448
- * Non-zero voxels are fully opaque (A = 255), zero voxels are
449
- * transparent (A = 0).
450
- */
451
- private renderGrayscale;
452
- /**
453
- * Render a single channel with its predefined color.
454
- *
455
- * Alpha is modulated by the voxel intensity and the opacity multiplier.
456
- */
457
- private renderColoredSingle;
458
- /**
459
- * Render all visible channels with distinct colors.
460
- *
461
- * The **highest-index** non-zero visible channel wins (priority-based).
462
- */
463
- private renderColoredMulti;
464
- /**
465
- * Render all visible channels with additive blending.
466
- *
467
- * Each channel contributes its color weighted by intensity × opacity.
468
- * RGB values are clamped to 255.
469
- */
470
- private renderBlended;
471
- }
1
+ /**
2
+ * MaskVolume — True 3D Volumetric Mask Storage
3
+ *
4
+ * Stores annotation masks in a single contiguous Uint8Array with the memory
5
+ * layout [z][y][x][channel] (slice-major order).
6
+ *
7
+ * Design goals:
8
+ * - Contiguous memory for optimal cache locality and minimal GC pressure.
9
+ * - Multi-channel support (binary mask, confidence, labels, etc.).
10
+ * - O(1) voxel access with full bounds checking.
11
+ * - Slice extraction to ImageData for Canvas rendering (all 3 axes).
12
+ * - Multi-channel color mapping with 4 render modes.
13
+ *
14
+ * Memory comparison (512 × 512 × 100, 1 channel):
15
+ * Old ImageData approach ≈ 4.4 GB → MaskVolume ≈ 25 MB (~99 % reduction)
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const vol = new MaskVolume(512, 512, 100); // 1 channel (default)
20
+ * vol.setVoxel(256, 256, 50, 255); // paint centre voxel
21
+ *
22
+ * // Grayscale slice (backward compatible)
23
+ * const slice = vol.getSliceImageData(50, 'z');
24
+ *
25
+ * // Colored slice
26
+ * const colored = vol.getSliceImageData(50, 'z', {
27
+ * mode: RenderMode.COLORED_SINGLE,
28
+ * channel: 0,
29
+ * opacity: 0.6,
30
+ * });
31
+ * ```
32
+ */
33
+ import type { Dimensions, RGBAColor, ChannelColorMap, SliceRenderOptions } from './types';
34
+ export declare class MaskVolume {
35
+ /** Contiguous backing buffer — layout [z][y][x][channel]. */
36
+ private data;
37
+ /** Volume size in voxels. */
38
+ private readonly dims;
39
+ /** Number of value channels per voxel (≥ 1). */
40
+ private readonly numChannels;
41
+ /**
42
+ * Number of bytes in one complete z-slice.
43
+ * Equal to width × height × channels.
44
+ */
45
+ private readonly bytesPerSlice;
46
+ /** Per-channel color map used for colored rendering modes. */
47
+ private colorMap;
48
+ /**
49
+ * Monotonic data-mutation counter.
50
+ *
51
+ * Incremented by every method that mutates voxel data (not color).
52
+ * Consumers (e.g. the contour cache in RenderingUtils) key cached
53
+ * derivations on this value so an edit automatically invalidates them —
54
+ * it is impossible to forget an invalidation point because every write
55
+ * bumps the version. Color-map changes do **not** bump it (colors are
56
+ * applied at fill time, never cached).
57
+ */
58
+ private version;
59
+ /**
60
+ * Create a new MaskVolume.
61
+ *
62
+ * All voxels are initialised to **0**.
63
+ *
64
+ * @param width Number of voxels along the X axis (≥ 1).
65
+ * @param height Number of voxels along the Y axis (≥ 1).
66
+ * @param depth Number of voxels along the Z axis (≥ 1).
67
+ * @param channels Number of channels per voxel (default 1).
68
+ * @param customColorMap Optional color map to override defaults.
69
+ *
70
+ * @throws {RangeError} If any dimension or the channel count is < 1.
71
+ */
72
+ constructor(width: number, height: number, depth: number, channels?: number, customColorMap?: ChannelColorMap);
73
+ /**
74
+ * Map 3D coordinates + channel to a flat 1D index.
75
+ *
76
+ * **Memory layout (slice-major):**
77
+ * ```
78
+ * index = (z × height × width × channels)
79
+ * + (y × width × channels)
80
+ * + (x × channels)
81
+ * + channel
82
+ * ```
83
+ *
84
+ * @param x Voxel column (0 … width − 1).
85
+ * @param y Voxel row (0 … height − 1).
86
+ * @param z Slice index (0 … depth − 1).
87
+ * @param channel Channel index (0 … channels − 1).
88
+ * @returns Flat 1D index into `this.data`.
89
+ *
90
+ * @throws {RangeError} If any coordinate or channel is out of bounds.
91
+ */
92
+ private getIndex;
93
+ /**
94
+ * Read a single voxel value.
95
+ *
96
+ * @param x Voxel column (0 … width − 1).
97
+ * @param y Voxel row (0 … height − 1).
98
+ * @param z Slice index (0 … depth − 1).
99
+ * @param channel Channel index (default 0).
100
+ * @returns The stored value (0 – 255).
101
+ *
102
+ * @throws {RangeError} If any coordinate is out of bounds.
103
+ */
104
+ getVoxel(x: number, y: number, z: number, channel?: number): number;
105
+ /**
106
+ * Write a single voxel value.
107
+ *
108
+ * Values are clamped to the Uint8 range [0, 255] by the typed array.
109
+ *
110
+ * @param x Voxel column (0 … width − 1).
111
+ * @param y Voxel row (0 … height − 1).
112
+ * @param z Slice index (0 … depth − 1).
113
+ * @param value New voxel value (0 – 255).
114
+ * @param channel Channel index (default 0).
115
+ *
116
+ * @throws {RangeError} If any coordinate is out of bounds.
117
+ */
118
+ setVoxel(x: number, y: number, z: number, value: number, channel?: number): void;
119
+ /**
120
+ * Return the current data-mutation version.
121
+ *
122
+ * Increments on every voxel write. Use as a cache key so derived data
123
+ * (e.g. extracted contours) is invalidated whenever the volume changes.
124
+ */
125
+ getVersion(): number;
126
+ /**
127
+ * Update the color for a specific label/channel in the color map.
128
+ *
129
+ * For label-based volumes (1-channel), the channel parameter refers to
130
+ * the label value (0-8), not the storage channel index.
131
+ *
132
+ * @param channel Label/channel index to update (0-8).
133
+ * @param color New RGBA color.
134
+ *
135
+ * @throws {RangeError} If channel is outside valid label range [0, 8].
136
+ */
137
+ setChannelColor(channel: number, color: RGBAColor): void;
138
+ /**
139
+ * Get the current color for a channel.
140
+ *
141
+ * Falls back to the background color (transparent) if no color is defined.
142
+ *
143
+ * @param channel Channel index.
144
+ * @returns A copy of the RGBA color.
145
+ */
146
+ getChannelColor(channel: number): RGBAColor;
147
+ /**
148
+ * Reset the color map for one or all labels to defaults.
149
+ *
150
+ * @param channel Optional specific label to reset. If omitted, resets all.
151
+ */
152
+ resetChannelColors(channel?: number): void;
153
+ /**
154
+ * Get a shallow copy of the entire color map.
155
+ *
156
+ * @returns A copy of the color map (safe to mutate).
157
+ */
158
+ getColorMap(): ChannelColorMap;
159
+ /**
160
+ * Extract a 2D slice as an ImageData with color mapping.
161
+ *
162
+ * Slice dimensions depend on the axis:
163
+ *
164
+ * | Axis | Plane | Width | Height |
165
+ * |------|----------|--------|--------|
166
+ * | `z` | Axial | width | height |
167
+ * | `y` | Coronal | width | depth |
168
+ * | `x` | Sagittal | depth | height |
169
+ *
170
+ * @param sliceIndex Index along the specified axis.
171
+ * @param axis `'x'` (sagittal), `'y'` (coronal), or `'z'` (axial).
172
+ * @param options Rendering options (mode, channel, colors, etc.).
173
+ * @returns ImageData ready for `ctx.putImageData()`.
174
+ *
175
+ * @throws {RangeError} If sliceIndex is out of bounds for the given axis.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * // Grayscale (default, backward compatible)
180
+ * const gs = vol.getSliceImageData(50, 'z');
181
+ *
182
+ * // Colored single-channel
183
+ * const cs = vol.getSliceImageData(50, 'z', {
184
+ * mode: RenderMode.COLORED_SINGLE,
185
+ * channel: 0,
186
+ * });
187
+ *
188
+ * // Multi-channel priority
189
+ * const mc = vol.getSliceImageData(50, 'z', {
190
+ * mode: RenderMode.COLORED_MULTI,
191
+ * visibleChannels: [false, true, true, true],
192
+ * });
193
+ * ```
194
+ */
195
+ getSliceImageData(sliceIndex: number, axis?: 'x' | 'y' | 'z', options?: SliceRenderOptions): ImageData;
196
+ /**
197
+ * Write a 2D ImageData back into the volume for the given axis/slice.
198
+ *
199
+ * When the volume has **4 channels**, all RGBA components are stored
200
+ * (ch0=R, ch1=G, ch2=B, ch3=A) for lossless round-trip.
201
+ * Otherwise, the **R channel** of each pixel is used as grayscale.
202
+ *
203
+ * @param sliceIndex Index along the specified axis.
204
+ * @param imageData Source ImageData (expected dimensions must match the axis).
205
+ * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
206
+ * @param channel Target channel (default 0, ignored when numChannels >= 4).
207
+ *
208
+ * @throws {RangeError} If sliceIndex is out of bounds.
209
+ * @throws {Error} If imageData dimensions don't match.
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * const imgData = ctx.getImageData(0, 0, 512, 512);
214
+ * vol.setSliceFromImageData(50, imgData, 'z');
215
+ * ```
216
+ */
217
+ setSliceFromImageData(sliceIndex: number, imageData: ImageData, axis?: 'x' | 'y' | 'z', channel?: number): void;
218
+ /**
219
+ /**
220
+ * Store label data from canvas RGBA ImageData into a 1-channel volume.
221
+ *
222
+ * For each pixel: matches the RGB color against MASK_CHANNEL_COLORS to
223
+ * determine which channel label to store. If no match is found, falls
224
+ * back to `activeChannel`. Transparent pixels (alpha === 0) are stored as 0.
225
+ *
226
+ * This is the write counterpart to `renderLabelSliceInto`.
227
+ *
228
+ * @param sliceIndex Index along the specified axis.
229
+ * @param imageData Canvas ImageData (RGBA) to convert.
230
+ * @param axis `'x'`, `'y'`, or `'z'`.
231
+ * @param activeChannel Fallback label for pixels whose RGB doesn't match any channel (1-8).
232
+ * @param channelVisible Optional map of visible channels (true=visible, false=hidden).
233
+ * If provided, data for hidden channels will be preserved
234
+ * when the canvas pixel is transparent.
235
+ */
236
+ setSliceLabelsFromImageData(sliceIndex: number, imageData: ImageData, axis?: 'x' | 'y' | 'z', activeChannel?: number, channelVisible?: Record<number, boolean>): void;
237
+ /**
238
+ * Build a Map from RGB packed integer to channel label for reverse lookup.
239
+ * Uses this instance's colorMap (channels 1-8, skips 0 = transparent).
240
+ *
241
+ * Instance method ensures custom per-layer colors are correctly reverse-mapped.
242
+ */
243
+ private buildRgbToChannelMap;
244
+ /**
245
+ * Render a 1-channel label slice into a pre-allocated RGBA ImageData buffer.
246
+ *
247
+ * Each voxel stores a label value (0-8). Label 0 = transparent.
248
+ * Labels 1-8 are mapped to colors via MASK_CHANNEL_COLORS, filtered
249
+ * by the channelVisible array.
250
+ *
251
+ * @param sliceIndex Index along the specified axis.
252
+ * @param axis `'x'`, `'y'`, or `'z'`.
253
+ * @param target Pre-allocated ImageData buffer (must match slice dimensions).
254
+ * @param channelVisible Array where index N indicates if channel N is visible.
255
+ * If undefined, all channels are visible.
256
+ * @param opacity Opacity multiplier 0.0–1.0 (default 1.0).
257
+ */
258
+ renderLabelSliceInto(sliceIndex: number, axis: "x" | "y" | "z" | undefined, target: ImageData, channelVisible?: Record<number, boolean>, opacity?: number): void;
259
+ /**
260
+ * Return a copy of the volume dimensions.
261
+ *
262
+ * @returns `{ width, height, depth }` — a fresh object (safe to mutate).
263
+ */
264
+ getDimensions(): Dimensions;
265
+ /**
266
+ * Return the number of channels per voxel.
267
+ *
268
+ * @returns Channel count (≥ 1).
269
+ */
270
+ getChannels(): number;
271
+ /**
272
+ * Return the number of bytes in one complete z-slice.
273
+ *
274
+ * Equal to `width × height × channels`. Useful for direct buffer
275
+ * index arithmetic in performance-critical code paths.
276
+ *
277
+ * @returns Bytes per z-slice.
278
+ */
279
+ getBytesPerSlice(): number;
280
+ /**
281
+ * Return total memory used by the backing buffer, in bytes.
282
+ *
283
+ * @returns `width × height × depth × channels` bytes.
284
+ *
285
+ * @example
286
+ * ```ts
287
+ * const vol = new MaskVolume(512, 512, 100);
288
+ * vol.getMemoryUsage(); // 26_214_400 (~25 MB)
289
+ * ```
290
+ */
291
+ getMemoryUsage(): number;
292
+ /**
293
+ * Return a **reference** to the raw backing buffer.
294
+ *
295
+ * Use this for direct read access (e.g. serialisation, GPU upload).
296
+ * Mutating the returned array mutates the volume.
297
+ *
298
+ * @returns The underlying Uint8Array.
299
+ *
300
+ * @example
301
+ * ```ts
302
+ * // Serialise for network transfer
303
+ * const bytes = vol.getRawData();
304
+ * socket.send(bytes.buffer);
305
+ * ```
306
+ */
307
+ getRawData(): Uint8Array;
308
+ /**
309
+ * Replace the entire backing buffer.
310
+ *
311
+ * The provided array **must** have exactly the same length as the
312
+ * current buffer (`width × height × depth × channels`).
313
+ *
314
+ * @param newData Replacement data.
315
+ * @throws {Error} If the length does not match.
316
+ *
317
+ * @example
318
+ * ```ts
319
+ * // Restore from a saved snapshot
320
+ * const saved = new Uint8Array(savedBuffer);
321
+ * vol.setRawData(saved);
322
+ * ```
323
+ */
324
+ setRawData(newData: Uint8Array): void;
325
+ /**
326
+ * Create an independent deep copy of this volume.
327
+ *
328
+ * The clone has the same dimensions, channels, data, and color map
329
+ * but shares no references with the original.
330
+ *
331
+ * @returns A new MaskVolume with identical content.
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * // Undo support: snapshot before an operation
336
+ * const snapshot = vol.clone();
337
+ * performEdit(vol);
338
+ * // Rollback: vol.setRawData(snapshot.getRawData());
339
+ * ```
340
+ */
341
+ clone(): MaskVolume;
342
+ /**
343
+ * Zero every voxel in the entire volume (all channels).
344
+ *
345
+ * @example
346
+ * ```ts
347
+ * vol.clear();
348
+ * vol.getVoxel(256, 256, 50); // 0
349
+ * ```
350
+ */
351
+ clear(): void;
352
+ /**
353
+ * Check if the volume contains any non-zero voxel data.
354
+ *
355
+ * Returns true if at least one voxel has a non-zero value,
356
+ * false if all voxels are zero (empty mask).
357
+ *
358
+ * This is useful for determining if a layer has actual mask
359
+ * annotations before saving or exporting.
360
+ *
361
+ * @returns True if any voxel is non-zero, false if all zeros.
362
+ *
363
+ * @example
364
+ * ```ts
365
+ * const vol = new MaskVolume(512, 512, 100);
366
+ * vol.hasData(); // false (all zeros)
367
+ *
368
+ * vol.setVoxel(256, 256, 50, 255);
369
+ * vol.hasData(); // true
370
+ * ```
371
+ */
372
+ hasData(): boolean;
373
+ /**
374
+ * Zero every voxel in a single slice along the given axis.
375
+ *
376
+ * If `channel` is provided, only that channel is cleared;
377
+ * otherwise **all** channels in the slice are cleared.
378
+ *
379
+ * @param sliceIndex Index along the specified axis.
380
+ * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
381
+ * @param channel Optional channel to clear (default: all).
382
+ *
383
+ * @throws {RangeError} If sliceIndex is out of bounds.
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * // Erase a single axial slice
388
+ * vol.clearSlice(50, 'z');
389
+ *
390
+ * // Erase only channel 1 of slice 50
391
+ * vol.clearSlice(50, 'z', 1);
392
+ * ```
393
+ */
394
+ clearSlice(sliceIndex: number, axis?: 'x' | 'y' | 'z', channel?: number): void;
395
+ /**
396
+ * Extract a 2D slice as a flat Uint8Array (one byte per voxel per channel).
397
+ *
398
+ * For a 1-channel volume the result is `sliceWidth × sliceHeight` bytes,
399
+ * each byte being the label value at that pixel. This is suitable for
400
+ * sending to a backend that expects raw label data (e.g. NIfTI slice
401
+ * replacement).
402
+ *
403
+ * @param sliceIndex Index along the specified axis.
404
+ * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
405
+ * @returns A **copy** of the slice data plus its dimensions.
406
+ *
407
+ * @throws {RangeError} If sliceIndex is out of bounds.
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * const { data, width, height } = vol.getSliceUint8(50, 'z');
412
+ * // data.length === width * height * channels
413
+ * ```
414
+ */
415
+ getSliceUint8(sliceIndex: number, axis?: 'x' | 'y' | 'z'): {
416
+ data: Uint8Array;
417
+ width: number;
418
+ height: number;
419
+ };
420
+ /**
421
+ * Write a 2D slice from a flat Uint8Array back into the volume.
422
+ *
423
+ * This is the inverse of {@link getSliceUint8}. The `data` array must
424
+ * have exactly `sliceWidth × sliceHeight × channels` bytes.
425
+ *
426
+ * @param sliceIndex Index along the specified axis.
427
+ * @param data Flat source array (same layout as returned by getSliceUint8).
428
+ * @param axis `'x'`, `'y'`, or `'z'` (default `'z'`).
429
+ *
430
+ * @throws {RangeError} If sliceIndex is out of bounds.
431
+ */
432
+ setSliceUint8(sliceIndex: number, data: Uint8Array, axis?: 'x' | 'y' | 'z'): void;
433
+ /**
434
+ * Get the 2D slice dimensions for a given axis.
435
+ *
436
+ * @returns `[width, height]` of the slice.
437
+ */
438
+ private getSliceDimensions;
439
+ /**
440
+ * Validate that a slice index is within bounds for the given axis.
441
+ *
442
+ * @throws {RangeError} If out of bounds.
443
+ */
444
+ private validateSliceIndex;
445
+ /**
446
+ * Render a single channel as grayscale (original behaviour).
447
+ *
448
+ * Non-zero voxels are fully opaque (A = 255), zero voxels are
449
+ * transparent (A = 0).
450
+ */
451
+ private renderGrayscale;
452
+ /**
453
+ * Render a single channel with its predefined color.
454
+ *
455
+ * Alpha is modulated by the voxel intensity and the opacity multiplier.
456
+ */
457
+ private renderColoredSingle;
458
+ /**
459
+ * Render all visible channels with distinct colors.
460
+ *
461
+ * The **highest-index** non-zero visible channel wins (priority-based).
462
+ */
463
+ private renderColoredMulti;
464
+ /**
465
+ * Render all visible channels with additive blending.
466
+ *
467
+ * Each channel contributes its color weighted by intensity × opacity.
468
+ * RGB values are clamped to 255.
469
+ */
470
+ private renderBlended;
471
+ }