copper3d 3.11.1 → 3.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -388,10 +388,16 @@ clears the undo stack each time a slice arrives.
388
388
  // Register once after initialization
389
389
  const callbackId = scene.addPreRenderCallbackFunction(nrrdTools.start);
390
390
 
391
- // Unregister on teardown
391
+ // Unregister on teardown, then release the instance
392
392
  scene.removePreRenderCallbackFunction(callbackId);
393
+ nrrdTools.dispose();
393
394
  ```
394
395
 
396
+ `dispose()` releases what the instance holds outside its own DOM subtree — the event router's
397
+ listeners (its window `blur` listener pins the whole engine graph), a pending slice step, and
398
+ the drawing-flag timer. Without it, an app that builds a viewer per case leaks one engine graph
399
+ per case. The instance must not be used afterwards; calling it twice is safe.
400
+
395
401
  ---
396
402
 
397
403
  ### 5. Drawing Setup
@@ -503,6 +509,25 @@ leave outline mode to annotate.
503
509
 
504
510
  ---
505
511
 
512
+ ### Zoom range — showing below 1:1
513
+
514
+ The zoom factor used to bottom out at `1`. Lower the floor and a large volume can be fitted
515
+ into a small panel:
516
+
517
+ ```typescript
518
+ nrrdTools.setMinSizeFactor(0.5); // clamped to [0.05, 1]; default 1
519
+ nrrdTools.setMainAreaSize(0.6); // now valid
520
+ ```
521
+
522
+ `setMainAreaSize`, wheel zoom and the `"mainAreaSize"` GUI slider all follow it; the upper
523
+ bound stays `8`. If the current factor is below the new floor it is raised and repainted.
524
+
525
+ The engine never recomputes the floor — the right value depends on the image and axis
526
+ dimensions *and* your panel size — so re-apply it after each case load, axis switch and panel
527
+ resize.
528
+
529
+ ---
530
+
506
531
  ### 7. Channel Color Customization
507
532
 
508
533
  **Default colors:**
@@ -639,6 +664,7 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
639
664
  | | `switchAllSlicesArrayData(slices)` | Swap the series (resets view state) |
640
665
  | | `switchSlicesPreservingView(slices)` | Swap the series, keep slice index / zoom / pan |
641
666
  | **Render** | `start` | Frame callback — pass to render loop |
667
+ | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step and the drawing-flag timer. Instance unusable afterwards; safe to call twice |
642
668
  | **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
643
669
  | | `getActiveLayer()` | Read current layer |
644
670
  | | `setLayerVisible(id, bool)` | Toggle layer in composite view |
@@ -690,7 +716,9 @@ yourself. It throws on an unknown layer, or a channel outside `[1, 255]`.
690
716
  | **Actions** | `executeAction(action, opts?)` | Run: `"undo"` / `"redo"` / `"clearActiveSliceMask"` / `"clearActiveLayerMask"` / `"resetZoom"` / `"downloadCurrentMask"` / `"gaussianSmooth"` (takes `{ sigma? }`) |
691
717
  | **Navigation** | `setSliceOrientation(axis)` | Switch viewing axis `"x"` / `"y"` / `"z"`; extracts the plane on demand if the load skipped it |
692
718
  | | `setSliceMoving(step)` | Step the current slice (coalesced per animation frame) |
693
- | | `setMainAreaSize(factor)` | Set the main-area zoom factor [1, 8] |
719
+ | | `setMainAreaSize(factor)` | Set the main-area zoom factor `[minSizeFactor, 8]` |
720
+ | | `setMinSizeFactor(f)` | Lower the zoom floor below 1:1. Clamped to `[0.05, 1]`; default `1`. Re-apply after case loads, axis switches and panel resizes |
721
+ | | `getMinSizeFactor()` | Read the current zoom floor |
694
722
  | **History** | `undo()` / `redo()` | Undo / redo last stroke |
695
723
  | **Keyboard** | `setKeyboardSettings(partial)` | Remap shortcuts |
696
724
  | | `getKeyboardSettings()` | Read current bindings |
@@ -371,6 +371,46 @@ function animate() {
371
371
  animate();
372
372
  ```
373
373
 
374
+ #### Teardown — `dispose()` <Badge type="tip" text="3.11.2" />
375
+
376
+ ```typescript
377
+ scene.removePreRenderCallbackFunction(callbackId);
378
+ nrrdTools.dispose();
379
+ container.remove(); // your DOM, your call
380
+ ```
381
+
382
+ `dispose()` releases what the instance holds **outside its own DOM subtree**, so a viewer that
383
+ is torn down can actually be garbage-collected:
384
+
385
+ | Released | Why it matters |
386
+ |----------|----------------|
387
+ | The event router's listeners | Its window `blur` listener closes over the router, which reaches the whole engine graph — one live listener pins the entire instance |
388
+ | A pending slice step | The `requestAnimationFrame` `setSliceMoving` coalesces into |
389
+ | The drawing-flag timer | The pending `setIsDrawFalse` timeout |
390
+
391
+ The instance must not be used afterwards. It is safe to call more than once, so an unmount
392
+ hook that may run twice needs no guard.
393
+
394
+ ::: warning It does not remove your container or free the volumes
395
+ `dispose()` deliberately stops at the boundary of what `NrrdTools` attached elsewhere. The
396
+ host element you passed to the constructor is yours to remove, and the `MaskVolume` buffers go
397
+ when the instance does. Drop your reference to `nrrdTools` after calling it.
398
+ :::
399
+
400
+ **Vue 3:**
401
+
402
+ ```typescript
403
+ import { onBeforeUnmount } from 'vue';
404
+
405
+ onBeforeUnmount(() => {
406
+ scene.removePreRenderCallbackFunction(callbackId);
407
+ nrrdTools.dispose();
408
+ });
409
+ ```
410
+
411
+ An app that builds a viewer per case and never calls this leaks one engine graph per case —
412
+ see [Scene Resources](./scene-resources) for the scene-level counterpart.
413
+
374
414
  ---
375
415
 
376
416
  ### 5. Drawing Setup
@@ -1246,6 +1286,55 @@ Set the base display size multiplier (1–8). Larger values use more GPU memory
1246
1286
  nrrdTools.setBaseDrawDisplayCanvasesSize(2); // 2× base resolution
1247
1287
  ```
1248
1288
 
1289
+ #### Zoom range — `setMinSizeFactor()` <Badge type="tip" text="3.11.3" />
1290
+
1291
+ The 2D zoom factor (`sizeFactor`) used to bottom out at `1`, i.e. 1:1 with the image. Lower
1292
+ the floor and the image can be shown **smaller than its original size** — which is what a
1293
+ large volume in a small panel needs:
1294
+
1295
+ ```typescript
1296
+ nrrdTools.setMinSizeFactor(0.5); // allow down to half size
1297
+ nrrdTools.setMainAreaSize(0.6); // now valid
1298
+ const min = nrrdTools.getMinSizeFactor();
1299
+ ```
1300
+
1301
+ | | |
1302
+ |---|---|
1303
+ | Accepted range | clamped to `[0.05, 1]`; a non-finite value resets it to `1` |
1304
+ | Default | `1` — exactly the previous behaviour |
1305
+ | Upper bound | still `8`, unchanged |
1306
+
1307
+ Everything that moves the zoom respects it: `setMainAreaSize`, wheel zoom, and
1308
+ `NrrdState.setZoomFactor`. The `"mainAreaSize"` GUI slider's `min` is updated too, so a
1309
+ connected dat.GUI / lil-gui panel can reach the new range.
1310
+
1311
+ If the current factor is **below** the new minimum it is raised to it and the view repaints
1312
+ immediately, so you can lower and raise the floor freely without leaving the view in an
1313
+ invalid state.
1314
+
1315
+ ::: warning You have to re-apply it — the engine never recomputes it
1316
+ The minimum survives `reset()` and case loads, and the engine will not adjust it on its own:
1317
+ the right value depends on the image and axis dimensions *and* on the size of your panel,
1318
+ neither of which the engine knows. Re-apply it after each
1319
+
1320
+ - case load,
1321
+ - axis switch (`setSliceOrientation`), and
1322
+ - panel resize.
1323
+
1324
+ ```typescript
1325
+ function fitFloor() {
1326
+ const [w, h] = nrrdTools.getCurrentImageDimension(); // per current axis
1327
+ const panel = container.getBoundingClientRect();
1328
+ nrrdTools.setMinSizeFactor(Math.min(panel.width / w, panel.height / h, 1));
1329
+ }
1330
+ ```
1331
+ :::
1332
+
1333
+ ::: tip A thin dimension never floors to zero
1334
+ `resizePaintArea` keeps a loaded image at **at least 1px** per axis, because a factor below 1
1335
+ could otherwise floor a thin dimension to `0`. An unloaded (0×0) image stays `0`.
1336
+ :::
1337
+
1249
1338
  #### Reading image metadata
1250
1339
 
1251
1340
  ```typescript
@@ -1726,6 +1815,7 @@ cap it below what the byte allows. Capping it lower is your product's call, not
1726
1815
  | | `switchAllSlicesArrayData(slices)` | Swap the loaded series (resets slice index / zoom / pan) |
1727
1816
  | | `switchSlicesPreservingView(slices)` | Swap the loaded series, keeping slice index, zoom and pan |
1728
1817
  | **Render** | `start` | Frame callback — pass to render loop |
1818
+ | **Lifecycle** | `dispose()` | Release the event router's listeners, a pending slice step and the drawing-flag timer. Instance unusable afterwards; safe to call twice |
1729
1819
  | **Layer** | `setActiveLayer(id)` | Switch drawing target layer |
1730
1820
  | | `getActiveLayer()` | Read current layer |
1731
1821
  | | `setLayerVisible(id, bool)` | Toggle layer in composite view |
@@ -1777,7 +1867,9 @@ cap it below what the byte allows. Capping it lower is your product's call, not
1777
1867
  | | `GaussianSmoother.generateKernel1D(sigma)` | Generate a normalized 1D Gaussian kernel |
1778
1868
  | **Navigation** | `setSliceOrientation(axis)` | Switch viewing axis `"x"` / `"y"` / `"z"`; extracts the plane on demand if the load skipped it |
1779
1869
  | | `setSliceMoving(step)` | Step the current slice by `step` (coalesced into one `requestAnimationFrame`) |
1780
- | | `setMainAreaSize(factor)` | Set the main-area zoom factor [1, 8] and reposition the paint area |
1870
+ | | `setMainAreaSize(factor)` | Set the main-area zoom factor `[minSizeFactor, 8]` and reposition the paint area |
1871
+ | | `setMinSizeFactor(f)` | Lower the zoom floor so the image can show below 1:1. Clamped to `[0.05, 1]`; default `1`. Not recomputed by the engine — re-apply after case loads, axis switches and panel resizes |
1872
+ | | `getMinSizeFactor()` | Read the current zoom floor |
1781
1873
  | | `setCalculateDistanceSphere(x, y, slice, type)` | Programmatically place a calculator sphere (simulates full click flow: record origin → draw → write to volume) |
1782
1874
  | **History** | `undo()` | Undo last stroke |
1783
1875
  | | `redo()` | Redo last undone stroke |
@@ -130,6 +130,49 @@ scene class that has none (`disposeScene` calls it optionally).
130
130
 
131
131
  ---
132
132
 
133
+ ## 2b. `NrrdTools.dispose()` <Badge type="tip" text="3.11.2" />
134
+
135
+ ```ts
136
+ nrrdTools.dispose(): void
137
+ ```
138
+
139
+ The same idea one level up. A segmentation viewer also attaches things outside itself, and
140
+ `disposeScene()` knows nothing about it — `NrrdTools` is not a scene, so nothing calls this
141
+ for you.
142
+
143
+ | Released | Why |
144
+ |----------|-----|
145
+ | The event router's listeners | Its window `blur` listener closes over the router, which reaches the whole engine graph — canvases, `MaskVolume` buffers, undo stacks. One listener pins all of it |
146
+ | A pending slice step | The `requestAnimationFrame` that `setSliceMoving` coalesces into |
147
+ | The drawing-flag timer | The pending `setIsDrawFalse` timeout |
148
+
149
+ An app that builds a viewer per case and never calls it leaks one engine graph per case, and
150
+ each one's `blur` listener goes on firing for the life of the page — the same shape of leak as
151
+ the `resize` listener in §2a, with considerably more held behind it.
152
+
153
+ ```ts
154
+ scene.removePreRenderCallbackFunction(callbackId);
155
+ nrrdTools.dispose();
156
+ ```
157
+
158
+ The instance must not be used afterwards. Safe to call twice.
159
+
160
+ It stops at that boundary on purpose: the host element you passed to the constructor is yours
161
+ to remove, and the volumes go when the instance does. Drop your reference to it.
162
+
163
+ ::: tip Full teardown order, viewer plus scene
164
+ ```ts
165
+ scene.removePreRenderCallbackFunction(callbackId); // stop the frame callback first
166
+ nrrdTools.dispose(); // then the viewer's listeners/timers
167
+ renderer.disposeScene(sceneName); // then the scene contents
168
+ container.remove(); // finally your own DOM
169
+ ```
170
+ Unregistering the frame callback first means nothing can run against a half-disposed
171
+ instance.
172
+ :::
173
+
174
+ ---
175
+
133
176
  ## 3. Residency budget
134
177
 
135
178
  ```ts
@@ -534,6 +534,7 @@ nrrdTools.setCalculateDistanceSphere(200, 150, 42, 'skin');
534
534
  | Method | Description |
535
535
  |--------|-------------|
536
536
  | `drag(opts?)` | Enable drag-to-scroll slice navigation |
537
+ | `dispose()` | Teardown: `eventRouter.unbindAll()`, cancel the pending slice-step `requestAnimationFrame`, clear the `setIsDrawFalse` timer. Releases only what the instance attached outside its own DOM subtree — the window `blur` listener is the one that pins the whole engine graph. Instance unusable afterwards; idempotent |
537
538
  | `setAnnotationSuspended(bool)` | Block every input that can write into a mask, at `DrawToolCore.onCanvasPointerDown`. Slice scrubbing, zoom, pan and the crosshair stay live (see 7.1) |
538
539
  | `isAnnotationSuspended()` | Query the suspension state |
539
540
  | `setSliceOrientation(axis)` | Switch viewing axis. Calls `ensureAxisExtracted` for every loaded contrast first, so a narrowed-axes load can still switch planes |
@@ -545,7 +546,9 @@ nrrdTools.setCalculateDistanceSphere(200, 150, 42, 'skin');
545
546
  | `switchAllSlicesArrayData(slices)` | Swap the loaded series and rebuild the display (resets view state) |
546
547
  | `switchSlicesPreservingView(slices)` | Swap the loaded series via `switchPreservingView()`, keeping slice index, zoom and pan |
547
548
  | `setSliceMoving(step)` | Step the current slice; steps are accumulated and applied in one `requestAnimationFrame` |
548
- | `setMainAreaSize(factor)` | Clamp the zoom factor to [1, 8], resize the paint area and reset its UI position |
549
+ | `setMainAreaSize(factor)` | Clamp the zoom factor to `[view.minSizeFactor, 8]`, resize the paint area and reset its UI position |
550
+ | `setMinSizeFactor(f)` | Lower bound for `sizeFactor`, clamped to `[0.05, 1]` (non-finite → `1`). Also updates `guiParameterSettings.advance.mainAreaSize.min`, and raises + repaints the current factor if it is now below the floor. Never recomputed by the engine — it depends on image/axis dimensions *and* host panel size |
551
+ | `getMinSizeFactor()` | Read the current floor |
549
552
  | `setBaseDrawDisplayCanvasesSize(size)` | Set canvas base size multiplier (1–8) |
550
553
  | `setupGUI(gui)` | Set up the dat.GUI panel |
551
554
  | `enableContrastDragEvents(callback)` | Enable contrast drag (window/level) events |
@@ -588,7 +591,8 @@ NrrdState groups 44 properties into 5 semantic sub-objects:
588
591
  | `currentSliceIndex` | `number` | Current slice index |
589
592
  | `maxIndex` / `minIndex` | `number` | Slice index range |
590
593
  | `changedWidth` / `changedHeight` | `number` | Canvas display dimensions |
591
- | `sizeFactor` | `number` | Scale factor |
594
+ | `sizeFactor` | `number` | Scale factor. Clamped to `[minSizeFactor, 8]` everywhere it is written — `setMainAreaSize`, `ZoomTool`'s wheel, `NrrdState.setZoomFactor` |
595
+ | `minSizeFactor` | `number` | Lower bound for `sizeFactor`, in `[0.05, 1]`. Default `1` (never smaller than 1:1). Survives `reset()` and case loads |
592
596
  | `originWidth` / `originHeight` | `number` | Original image dimensions |
593
597
 
594
598
  #### nrrd_states.interaction (IInteractionState)
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "copper3dVersion": "3.11.1",
4
- "generatedAt": "2026-09-29T01:00:06.303Z",
5
- "symbolCount": 1194,
3
+ "copper3dVersion": "3.11.3",
4
+ "generatedAt": "2026-09-30T00:54:40.159Z",
5
+ "symbolCount": 1199,
6
6
  "guides": [
7
7
  {
8
8
  "id": "4D-MRI-LV-rendering",
@@ -90,7 +90,7 @@
90
90
  "title": "NrrdTools Usage Guide",
91
91
  "summary": "Copper3D `NrrdTools` — Medical Image Segmentation Annotation Engine",
92
92
  "lang": "en",
93
- "bytes": 70593
93
+ "bytes": 74550
94
94
  },
95
95
  {
96
96
  "id": "on-demand-controls",
@@ -114,7 +114,7 @@
114
114
  "title": "copper3d — Scene Resources",
115
115
  "summary": "Freeing what a scene holds, bounding how much stays resident, and crossfading one model into another. All exported from the package entry (`copper3d`).",
116
116
  "lang": "en",
117
- "bytes": 9093
117
+ "bytes": 10866
118
118
  },
119
119
  {
120
120
  "id": "segmentation-module",
@@ -122,7 +122,7 @@
122
122
  "title": "Segmentation Module Documentation",
123
123
  "summary": "⚠️ **Note**: All line number references in this document are from historical versions. After multiple rounds of refactoring (State Management Refactor, NrrdTools God Class Split, inheritance → composition refactor), these references are ou…",
124
124
  "lang": "en",
125
- "bytes": 73632
125
+ "bytes": 74638
126
126
  },
127
127
  {
128
128
  "id": "surface-annotation-api",