copper3d 3.11.6 → 4.1.0
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 +62 -6
- package/ai-index/guides/load-callbacks.md +24 -5
- package/ai-index/guides/orientation.md +155 -0
- package/ai-index/guides/segmentation-module.md +51 -25
- package/ai-index/guides/upgrading-to-4.md +118 -0
- package/ai-index/guides/volume-display.md +1 -1
- package/ai-index/manifest.json +22 -6
- package/ai-index/symbols.json +1 -1
- package/dist/Controls/Copper3dOrbitControls.d.ts +1 -1
- package/dist/Controls/Copper3dOrbitControls.js +1 -1
- package/dist/Controls/Copper3dOrbitControls.js.map +1 -1
- package/dist/Controls/orbitFraming.d.ts +4 -4
- package/dist/Controls/orbitFraming.js +4 -4
- package/dist/Loader/copperGltfLoader.d.ts +1 -2
- package/dist/Loader/copperGltfLoader.js +3 -3
- package/dist/Loader/copperGltfLoader.js.map +1 -1
- package/dist/Loader/copperNrrdLoader.d.ts +16 -2
- package/dist/Loader/copperNrrdLoader.js +34 -12
- package/dist/Loader/copperNrrdLoader.js.map +1 -1
- package/dist/Loader/copperOBJLoader.d.ts +1 -2
- package/dist/Loader/copperOBJLoader.js +1 -1
- package/dist/Loader/copperOBJLoader.js.map +1 -1
- package/dist/Loader/copperVtkLoader.d.ts +1 -2
- package/dist/Loader/copperVtkLoader.js +1 -1
- package/dist/Loader/copperVtkLoader.js.map +1 -1
- package/dist/Loader/nrrdWorkerCore.d.ts +15 -2
- package/dist/Loader/nrrdWorkerCore.js +49 -5
- package/dist/Loader/nrrdWorkerCore.js.map +1 -1
- package/dist/Loader/rasDimensions.d.ts +9 -0
- package/dist/Loader/rasDimensions.js +12 -0
- package/dist/Loader/rasDimensions.js.map +1 -0
- package/dist/Renderer/baseRenderer.d.ts +1 -1
- package/dist/Renderer/baseRenderer.js +2 -2
- package/dist/Renderer/baseRenderer.js.map +1 -1
- package/dist/Renderer/copperMSceneRenderer.js +1 -1
- package/dist/Renderer/copperMSceneRenderer.js.map +1 -1
- package/dist/Scene/commonSceneMethod.d.ts +12 -3
- package/dist/Scene/commonSceneMethod.js +12 -4
- package/dist/Scene/commonSceneMethod.js.map +1 -1
- package/dist/Scene/copperMScene.js +1 -1
- package/dist/Scene/copperMScene.js.map +1 -1
- package/dist/Scene/copperScene.d.ts +2 -2
- package/dist/Scene/copperScene.js +3 -3
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/Scene/copperSceneOnDemond.d.ts +2 -2
- package/dist/Scene/copperSceneOnDemond.js +2 -2
- package/dist/Scene/copperSceneOnDemond.js.map +1 -1
- package/dist/Utils/orientation.d.ts +94 -0
- package/dist/Utils/orientation.js +261 -0
- package/dist/Utils/orientation.js.map +1 -0
- package/dist/Utils/segmentation/NrrdTools.d.ts +4 -0
- package/dist/Utils/segmentation/NrrdTools.js +4 -2
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +0 -5
- package/dist/Utils/segmentation/RenderingUtils.js +3 -23
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
- package/dist/Utils/segmentation/contourPaint.d.ts +5 -0
- package/dist/Utils/segmentation/contourPaint.js +10 -3
- package/dist/Utils/segmentation/contourPaint.js.map +1 -1
- package/dist/Utils/segmentation/core/MaskVolume.d.ts +1 -1
- package/dist/Utils/segmentation/core/MaskVolume.js +38 -38
- package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
- package/dist/Utils/segmentation/tools/AiAssistTool.js +10 -10
- package/dist/Utils/segmentation/tools/AiAssistTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ContrastTool.js +1 -1
- package/dist/Utils/segmentation/tools/CrosshairTool.js +30 -22
- package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/DrawingTool.js +14 -14
- package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +3 -5
- package/dist/Utils/segmentation/tools/ImageStoreHelper.js +7 -11
- package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
- package/dist/Utils/segmentation/tools/MaskMirror.js +5 -5
- package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -1
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +28 -4
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +50 -24
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
- package/dist/Utils/segmentation/tools/SphereBrushTool.js +5 -4
- package/dist/Utils/segmentation/tools/SphereBrushTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/SphereTool.js +13 -11
- package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js +1 -1
- package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js.map +1 -1
- package/dist/Utils/surfaceAnnotation/contourRender.d.ts +1 -1
- package/dist/Utils/surfaceAnnotation/contourRender.js +3 -3
- package/dist/Utils/surfaceAnnotation/contourRender.js.map +1 -1
- package/dist/Utils/threeRevisionCheck.d.ts +14 -0
- package/dist/Utils/threeRevisionCheck.js +21 -0
- package/dist/Utils/threeRevisionCheck.js.map +1 -0
- package/dist/Utils/volumeShader.js +1 -1
- package/dist/Utils/volumeShader.js.map +1 -1
- package/dist/bundle.esm.mjs +22060 -0
- package/dist/bundle.umd.js +22141 -118657
- package/dist/index.d.ts +5 -2
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Controls/Copper3dOrbitControls.d.ts +1 -1
- package/dist/types/Controls/orbitFraming.d.ts +4 -4
- package/dist/types/Loader/copperGltfLoader.d.ts +1 -1
- package/dist/types/Loader/copperNrrdLoader.d.ts +16 -2
- package/dist/types/Loader/copperOBJLoader.d.ts +1 -1
- package/dist/types/Loader/copperVtkLoader.d.ts +1 -1
- package/dist/types/Loader/nrrdWorkerCore.d.ts +15 -2
- package/dist/types/Loader/rasDimensions.d.ts +9 -0
- package/dist/types/Renderer/baseRenderer.d.ts +1 -1
- package/dist/types/Scene/commonSceneMethod.d.ts +12 -3
- package/dist/types/Scene/copperScene.d.ts +2 -2
- package/dist/types/Scene/copperSceneOnDemond.d.ts +2 -2
- package/dist/types/Utils/orientation.d.ts +94 -0
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +4 -0
- package/dist/types/Utils/segmentation/RenderingUtils.d.ts +0 -5
- package/dist/types/Utils/segmentation/contourPaint.d.ts +5 -0
- package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +1 -1
- package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +3 -5
- package/dist/types/Utils/segmentation/tools/SliceRenderPipeline.d.ts +28 -4
- package/dist/types/Utils/surfaceAnnotation/contourRender.d.ts +1 -1
- package/dist/types/Utils/threeRevisionCheck.d.ts +14 -0
- package/dist/types/index.d.ts +5 -2
- package/package.json +23 -5
- package/dist/bundle.esm.js +0 -118585
package/README.md
CHANGED
|
@@ -2,16 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
[![CI][ci]][ci-url]
|
|
4
4
|
[![NPM Package][npm]][npm-url]
|
|
5
|
-
[![
|
|
5
|
+
[![Documentation][docs]][docs-url]
|
|
6
6
|
[![Copper3d Examples][examples]][examples-url]
|
|
7
7
|
[![NRRD_Segmentation_Tool example][nrrd_example]][nrrd_example-url]
|
|
8
8
|
[![MedTech Heart example][heart_example]][heart_example-url]
|
|
9
9
|
|
|
10
10
|
A 3D visualisation package based on three.js — multiple scenes, NRRD/DICOM image loading, and a full medical image segmentation annotation engine.
|
|
11
11
|
|
|
12
|
+
### Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install copper3d three@~0.186.0
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**`three` is a peer dependency since 4.0.0** — you install it, and copper3d shares your copy.
|
|
19
|
+
It is not bundled, so there is exactly one three on the page: bundling it would give you a
|
|
20
|
+
second (three warns *"Multiple instances of Three.js being imported"*), and a `Mesh` built by
|
|
21
|
+
your code would not be an `instanceof` the `Mesh` copper3d checks against.
|
|
22
|
+
|
|
23
|
+
TypeScript users also want the types, which are an optional peer:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install -D @types/three@~0.186.0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
copper3d imports three's addons through `three/addons/*`, which three exposes only via its
|
|
30
|
+
package `exports` map. If your `tsconfig.json` still has `"moduleResolution": "node"`, move it
|
|
31
|
+
to `"bundler"` (or `"node16"`/`"nodenext"`) — `"node"` predates exports maps and cannot
|
|
32
|
+
resolve those paths.
|
|
33
|
+
|
|
34
|
+
At import, copper3d compares the three it was built against with the one actually loaded and
|
|
35
|
+
logs a `console.error` if they differ. npm refuses a mismatched peer at install time; yarn 1
|
|
36
|
+
and pnpm only warn, so the check is repeated where it cannot be scrolled past.
|
|
37
|
+
|
|
12
38
|
### Documentation
|
|
13
39
|
|
|
14
|
-
https://
|
|
40
|
+
**https://linkungao.github.io/copper3d_visualisation/** — guides and the full generated API
|
|
41
|
+
reference, in English and 简体中文.
|
|
42
|
+
|
|
43
|
+
| | |
|
|
44
|
+
|---|---|
|
|
45
|
+
| [Upgrading to 4.0](https://linkungao.github.io/copper3d_visualisation/guide/upgrading-to-4) | **Start here if you are on 3.x** — three is now a peer dependency |
|
|
46
|
+
| [Patient Orientation](https://linkungao.github.io/copper3d_visualisation/guide/orientation) | Canonical LPS order, `OrientationError`, view labels |
|
|
47
|
+
| [NrrdTools Usage Guide](https://linkungao.github.io/copper3d_visualisation/guide/nrrd-tools) | The segmentation engine, end to end |
|
|
48
|
+
| [Segmentation Module](https://linkungao.github.io/copper3d_visualisation/guide/segmentation-module) | Its architecture and internals |
|
|
49
|
+
| [Load Progress & Errors](https://linkungao.github.io/copper3d_visualisation/guide/load-callbacks) | `loadNrrd` / `loadGltf` options and callbacks |
|
|
50
|
+
| [AI Coding Assistants (MCP)](https://linkungao.github.io/copper3d_visualisation/guide/mcp-server) | Point your assistant at the real API |
|
|
51
|
+
| [API reference](https://linkungao.github.io/copper3d_visualisation/apidist/modules) | Generated from source by TypeDoc |
|
|
52
|
+
|
|
53
|
+
The site is built from [`apidocs/`](https://github.com/LinkunGao/copper3d_visualisation/tree/main/apidocs)
|
|
54
|
+
with VitePress and deploys to GitHub Pages.
|
|
55
|
+
|
|
56
|
+
> The old Sphinx site on readthedocs was retired at 3.11.6. It had not been updated since
|
|
57
|
+
> v2.0.7 (December 2023) and documented an API that no longer exists — `Copper.Renderer`
|
|
58
|
+
> rather than `copperRenderer`, and nothing from the 3.x segmentation engine. Everything now
|
|
59
|
+
> lives at the link above. Its sources remain in git history if you need them.
|
|
15
60
|
|
|
16
61
|
### Previous versions
|
|
17
62
|
|
|
@@ -205,16 +250,27 @@ CameraViewPoint {
|
|
|
205
250
|
|
|
206
251
|
### Loading NRRD volumes
|
|
207
252
|
|
|
208
|
-
`scene.loadNrrd(url, loadingBar,
|
|
253
|
+
`scene.loadNrrd(url, loadingBar, callback, opts?)` fetches, gunzips and parses
|
|
209
254
|
the volume **in a shared Web Worker**; the pixel buffer comes back as a transferable and the
|
|
210
255
|
main thread only rehydrates a `Volume` around it. Two concurrent loads of the same URL share
|
|
211
256
|
one network transfer. The worker is inlined into the bundle, so there is no second asset file
|
|
212
257
|
to serve.
|
|
213
258
|
|
|
259
|
+
Every volume comes back in the **canonical voxel order** (`i` → patient Left, `j` → Posterior,
|
|
260
|
+
`k` → Superior), whatever order its file stores, so each view is the radiological one without
|
|
261
|
+
you doing anything. `volume.orientation` records how the file got there. A file whose patient
|
|
262
|
+
orientation cannot be established is refused through `onError` with an `OrientationError`,
|
|
263
|
+
never guessed at — see [Patient Orientation](https://linkungao.github.io/copper3d_visualisation/guide/orientation).
|
|
264
|
+
|
|
265
|
+
> **Breaking in 4.1.0:** the `segmentation` argument was removed —
|
|
266
|
+
> `loadNrrd(url, loadingBar, segmentation, callback, opts)` is now
|
|
267
|
+
> `loadNrrd(url, loadingBar, callback, opts)`. The canonical order makes the flag meaningless,
|
|
268
|
+
> so it is always on; leaving it in shifts your other arguments by one.
|
|
269
|
+
|
|
214
270
|
```ts
|
|
215
271
|
const controller = new AbortController();
|
|
216
272
|
|
|
217
|
-
scene.loadNrrd(url, loadingBar,
|
|
273
|
+
scene.loadNrrd(url, loadingBar, (volume, meshes, slices) => { /* ... */ }, {
|
|
218
274
|
openGui: false,
|
|
219
275
|
axes: ["z"], // extract only the planes you show
|
|
220
276
|
knownMinMax: [min, max], // skip three's whole-volume intensity scan
|
|
@@ -845,8 +901,8 @@ Special thanks to [Duke University dataset](https://wiki.cancerimagingarchive.ne
|
|
|
845
901
|
[ci-url]: https://github.com/LinkunGao/copper3d_visualisation/actions/workflows/ci.yml
|
|
846
902
|
[npm]: https://img.shields.io/npm/v/copper3d
|
|
847
903
|
[npm-url]: https://www.npmjs.com/package/copper3d
|
|
848
|
-
[
|
|
849
|
-
[
|
|
904
|
+
[docs]: https://img.shields.io/badge/docs-copper3d-blue
|
|
905
|
+
[docs-url]: https://linkungao.github.io/copper3d_visualisation/
|
|
850
906
|
[examples]: https://img.shields.io/badge/copper3d__visualisation-examples-orange
|
|
851
907
|
[examples-url]: https://linkungao.github.io/copper3d_examples
|
|
852
908
|
[nrrd_example]: https://img.shields.io/badge/Nrrd__Segmentation__tool-example-orange
|
|
@@ -37,10 +37,29 @@ Available on `copperSceneOnDemond`, `copperScene` and `copperMScene`. (
|
|
|
37
37
|
|
|
38
38
|
## `scene.loadNrrd`
|
|
39
39
|
|
|
40
|
+
::: warning Breaking in 4.1.0: the `segmentation` argument is gone
|
|
41
|
+
```ts
|
|
42
|
+
scene.loadNrrd(url, loadingBar, segmentation, callback, opts); // before
|
|
43
|
+
scene.loadNrrd(url, loadingBar, callback, opts); // 4.1.0
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
It no longer means anything. The loader now puts every volume in the
|
|
47
|
+
[canonical voxel order](./orientation) and lays slices out by voxel index, which is what the
|
|
48
|
+
flag used to approximate — so it is always on, and passing it would only shift your other
|
|
49
|
+
arguments by one.
|
|
50
|
+
|
|
51
|
+
Two more things come with that:
|
|
52
|
+
|
|
53
|
+
- **`volume.orientation`** is new on the loaded volume: how the file reached the canonical
|
|
54
|
+
order, and its canonical grid in patient space.
|
|
55
|
+
- **A volume whose patient orientation cannot be established is refused**, through `onError`
|
|
56
|
+
with an `OrientationError`. It is never guessed at and never displayed.
|
|
57
|
+
:::
|
|
58
|
+
|
|
40
59
|
The callbacks go on the existing `opts` object:
|
|
41
60
|
|
|
42
61
|
```ts
|
|
43
|
-
scene.loadNrrd(url, loadingBar,
|
|
62
|
+
scene.loadNrrd(url, loadingBar, callback, {
|
|
44
63
|
openGui: false,
|
|
45
64
|
onProgress: (event) => { /* ... */ },
|
|
46
65
|
onError: (error) => showFailure(error),
|
|
@@ -68,7 +87,7 @@ buffer plus a geometry, a material and a canvas-backed texture that nothing
|
|
|
68
87
|
frees.
|
|
69
88
|
|
|
70
89
|
```ts
|
|
71
|
-
scene.loadNrrd(url, loadingBar,
|
|
90
|
+
scene.loadNrrd(url, loadingBar, callback, {
|
|
72
91
|
openGui: false,
|
|
73
92
|
axes: ["z"], // an axial-only viewer
|
|
74
93
|
});
|
|
@@ -123,7 +142,7 @@ decompressed the same bytes to write its headers.
|
|
|
123
142
|
```ts
|
|
124
143
|
const { min, max } = await fetch(`/files/${caseId}/headers`).then((r) => r.json());
|
|
125
144
|
|
|
126
|
-
scene.loadNrrd(url, loadingBar,
|
|
145
|
+
scene.loadNrrd(url, loadingBar, callback, {
|
|
127
146
|
openGui: false,
|
|
128
147
|
knownMinMax: [min, max],
|
|
129
148
|
});
|
|
@@ -144,7 +163,7 @@ function loadCase(url: string) {
|
|
|
144
163
|
inflight?.abort(); // stop the previous download
|
|
145
164
|
inflight = new AbortController();
|
|
146
165
|
|
|
147
|
-
scene.loadNrrd(url, loadingBar,
|
|
166
|
+
scene.loadNrrd(url, loadingBar, onLoaded, {
|
|
148
167
|
openGui: false,
|
|
149
168
|
signal: inflight.signal,
|
|
150
169
|
onError: (error) => {
|
|
@@ -234,7 +253,7 @@ function armStallTimer() {
|
|
|
234
253
|
}
|
|
235
254
|
|
|
236
255
|
armStallTimer();
|
|
237
|
-
scene.loadNrrd(url, loadingBar,
|
|
256
|
+
scene.loadNrrd(url, loadingBar, (volume, meshes, slices) => {
|
|
238
257
|
clearTimeout(timer);
|
|
239
258
|
/* ... */
|
|
240
259
|
}, {
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Patient Orientation <Badge type="tip" text="4.1.0" />
|
|
2
|
+
|
|
3
|
+
Every volume `loadNrrd` returns is in the **canonical voxel order**, whatever order its file
|
|
4
|
+
stores. That is what makes each view come out in the radiological convention without the
|
|
5
|
+
caller doing anything.
|
|
6
|
+
|
|
7
|
+
## The canonical order
|
|
8
|
+
|
|
9
|
+
| Voxel index | increases toward |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `i` | the patient's **L**eft |
|
|
12
|
+
| `j` | **P**osterior |
|
|
13
|
+
| `k` | **S**uperior |
|
|
14
|
+
|
|
15
|
+
Axis codes use the **TOWARD** convention of DICOM, nibabel and SimpleITK, so this order is
|
|
16
|
+
named `LPS`.
|
|
17
|
+
|
|
18
|
+
::: warning The same order has two names
|
|
19
|
+
Legacy ITK and **ITK-SNAP call this exact order `RAI`** — they name the axis each index comes
|
|
20
|
+
*from* rather than the one it goes *toward*. If you are comparing against ITK-SNAP, `RAI`
|
|
21
|
+
there and `LPS` here are the same thing, not a mismatch.
|
|
22
|
+
:::
|
|
23
|
+
|
|
24
|
+
Reaching it is a **permutation and flips, never a resampling**. Each native axis is assigned
|
|
25
|
+
the anatomical axis it is nearest to and reversed if it points the other way. Obliquity is
|
|
26
|
+
therefore preserved in the geometry rather than snapped away — nothing is interpolated and no
|
|
27
|
+
voxel value changes.
|
|
28
|
+
|
|
29
|
+
## What you get back
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
scene.loadNrrd(url, loadingBar, (volume, meshes, slices) => {
|
|
33
|
+
volume.orientation.transform; // how the file's voxels were reordered
|
|
34
|
+
volume.orientation.nativeDims; // the file's own dims, before reordering
|
|
35
|
+
volume.orientation.geometry; // the canonical grid in LPS, obliquity included
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`volume.orientation.geometry` is **never snapped**, unlike `volume.matrix`. Use it when you
|
|
40
|
+
need true patient-space positions.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
interface VolumeOrientation {
|
|
44
|
+
transform: OrientationTransform;
|
|
45
|
+
nativeDims: [number, number, number];
|
|
46
|
+
geometry: VolumeGeometry;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface OrientationTransform {
|
|
50
|
+
/** perm[c] is the native axis that became axis c. */
|
|
51
|
+
perm: [number, number, number];
|
|
52
|
+
/** flip[c]: index c runs opposite to that native axis. */
|
|
53
|
+
flip: [boolean, boolean, boolean];
|
|
54
|
+
/** Angle between axis c and its anatomical axis, in degrees. */
|
|
55
|
+
obliquityDeg: [number, number, number];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface VolumeGeometry {
|
|
59
|
+
dims: [number, number, number];
|
|
60
|
+
/** directions[a] is one step along voxel axis a, in LPS millimetres; its length is the spacing. */
|
|
61
|
+
directions: [Vec3, Vec3, Vec3];
|
|
62
|
+
/** LPS position of the centre of voxel (0, 0, 0). */
|
|
63
|
+
origin: [number, number, number];
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## A volume with no establishable orientation is refused
|
|
68
|
+
|
|
69
|
+
It is never guessed at. The load fails through `opts.onError` with an `OrientationError`,
|
|
70
|
+
and nothing is displayed:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { OrientationError } from "copper3d";
|
|
74
|
+
|
|
75
|
+
scene.loadNrrd(url, loadingBar, onLoaded, {
|
|
76
|
+
openGui: false,
|
|
77
|
+
onError: (err) => {
|
|
78
|
+
if (err instanceof OrientationError) {
|
|
79
|
+
showFailure(`This file cannot be oriented: ${err.detail}`); // err.code is stable
|
|
80
|
+
} else {
|
|
81
|
+
showFailure(err); // network, parse, abort
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`OrientationError` crosses the worker boundary intact, so it arrives as the engine's own error
|
|
88
|
+
type rather than a plain `Error` — which is how you can tell a refused orientation from a
|
|
89
|
+
failed fetch.
|
|
90
|
+
|
|
91
|
+
| `err.code` | Means |
|
|
92
|
+
|---|---|
|
|
93
|
+
| `no_space` | The header has no `space` field |
|
|
94
|
+
| `unknown_space` / `non_anatomical_space` | `space` names something not anatomical (`3d-right-handed`, …) |
|
|
95
|
+
| `time_space` | A time-varying space (`rast`, `last`, `lpst`, `*-time`) |
|
|
96
|
+
| `scanner_space` | Scanner-relative, not patient-relative |
|
|
97
|
+
| `no_directions` / `no_origin` / `not_3d` | Required geometry fields missing, or not a 3-D volume |
|
|
98
|
+
| `degenerate` | Direction vectors do not span 3-D |
|
|
99
|
+
| `ambiguous_oblique` | A voxel axis sits ~45° from every anatomical axis, so it has no nearest one |
|
|
100
|
+
|
|
101
|
+
## Orientation letters for a view
|
|
102
|
+
|
|
103
|
+
`viewLabels` gives the letters to put at each edge of a view, following 3D Slicer's rule — an
|
|
104
|
+
axis more than 1° off an anatomical axis also gets that axis's letter:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { viewLabels } from "copper3d";
|
|
108
|
+
|
|
109
|
+
const labels = viewLabels("z", volume.orientation.geometry);
|
|
110
|
+
// { left: "R", right: "L", top: "A", bottom: "P" } for an axial view
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The layout it assumes is the same one `SliceRenderPipeline.flipDisplayImageByAxis` draws, and
|
|
114
|
+
the two are kept in step deliberately — see
|
|
115
|
+
[the flip mechanism](./segmentation-module#_6-flip-mechanism).
|
|
116
|
+
|
|
117
|
+
| View | screen-right | screen-down |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| axial (`z`) | `+i` (patient Left) | `+j` (Posterior) |
|
|
120
|
+
| coronal (`y`) | `+i` | `−k` (Superior at the top) |
|
|
121
|
+
| sagittal (`x`) | `+j` (Anterior on the left) | `−k` |
|
|
122
|
+
|
|
123
|
+
## Working with headers yourself
|
|
124
|
+
|
|
125
|
+
The module is pure — no DOM and no three — so it runs in the NRRD worker and on the main
|
|
126
|
+
thread alike.
|
|
127
|
+
|
|
128
|
+
| Function | Does |
|
|
129
|
+
|---|---|
|
|
130
|
+
| `readNrrdOrientationFields(headerText)` | Pulls `space`, `sizes`, `space directions`, `space origin` out of an NRRD header's text |
|
|
131
|
+
| `geometryFromNrrd(fields)` | Those fields as a `VolumeGeometry` in LPS. Throws `OrientationError` |
|
|
132
|
+
| `canonicalTransform(geometry)` | The transform into the canonical order |
|
|
133
|
+
| `reorientedGeometry(geometry, transform)` | The same grid described in the new order; the origin moves to the new first voxel |
|
|
134
|
+
| `reorientVoxels(data, dims, transform)` | Applies the permutation and flips to a typed array |
|
|
135
|
+
| `viewLabels(axis, geometry)` | The letters at each screen edge |
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import {
|
|
139
|
+
readNrrdOrientationFields, geometryFromNrrd,
|
|
140
|
+
canonicalTransform, reorientVoxels, reorientedGeometry,
|
|
141
|
+
} from "copper3d";
|
|
142
|
+
|
|
143
|
+
const fields = readNrrdOrientationFields(headerText);
|
|
144
|
+
const geometry = geometryFromNrrd(fields); // throws OrientationError if unestablishable
|
|
145
|
+
const t = canonicalTransform(geometry);
|
|
146
|
+
const voxels = reorientVoxels(raw, geometry.dims, t);
|
|
147
|
+
const grid = reorientedGeometry(geometry, t);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
::: tip Masks must be reoriented the same way
|
|
151
|
+
A mask you bring in from elsewhere is in *its* file's order. Put it through the same
|
|
152
|
+
`canonicalTransform` / `reorientVoxels` pair before handing it to `setMasksFromNIfTI`, or it
|
|
153
|
+
will land on the right grid in the wrong order. `registerNiftiMaskGrid` catches a mismatched
|
|
154
|
+
*grid*, not a mismatched *order*.
|
|
155
|
+
:::
|
|
@@ -907,7 +907,7 @@ Underlying data structure: a single contiguous `Uint8Array`
|
|
|
907
907
|
|------|-------------|--------------|-------|
|
|
908
908
|
| z (Axial) | width | height | Most common, contiguous memory |
|
|
909
909
|
| y (Coronal) | width | depth | Extracted row by row |
|
|
910
|
-
| x (Sagittal) |
|
|
910
|
+
| x (Sagittal) | height | depth | Columns along `y`, rows along `z` (changed in 4.1.0) |
|
|
911
911
|
|
|
912
912
|
emptyCanvas size configuration: `SliceRenderPipeline.setEmptyCanvasSize()` → `tools/SliceRenderPipeline.ts`
|
|
913
913
|
|
|
@@ -1045,47 +1045,73 @@ fill considers solid.
|
|
|
1045
1045
|
|
|
1046
1046
|
## 6. Flip Mechanism
|
|
1047
1047
|
|
|
1048
|
-
### 6.1 Display
|
|
1048
|
+
### 6.1 Display Mapping (CT/MRI image only) <Badge type="tip" text="4.1.0" />
|
|
1049
1049
|
|
|
1050
1050
|
**`flipDisplayImageByAxis()`** — `SliceRenderPipeline.flipDisplayImageByAxis()`
|
|
1051
1051
|
|
|
1052
|
-
|
|
1052
|
+
The loader puts every volume in the [canonical voxel order](./orientation) (`i` → patient
|
|
1053
|
+
Left, `j` → Posterior, `k` → Superior), and three lays a slice out by voxel index with fixed
|
|
1054
|
+
row reversals. This per-axis transform undoes those reversals, which is what makes each view
|
|
1055
|
+
the radiological one:
|
|
1056
|
+
|
|
1057
|
+
| Axis | screen-right | screen-down | Transform |
|
|
1058
|
+
|------|--------------|-------------|-----------|
|
|
1059
|
+
| z (Axial) | `+i` (patient Left) | `+j` (Posterior) | `scale(1, -1)` + `translate(0, -h)` |
|
|
1060
|
+
| y (Coronal) | `+i` | `−k` (Superior at the top) | `scale(1, -1)` + `translate(0, -h)` |
|
|
1061
|
+
| x (Sagittal) | `+j` (Anterior on the left) | `−k` | `transform(0, h/w, -w/h, 0, w, 0)` |
|
|
1062
|
+
|
|
1063
|
+
::: warning Sagittal is a quarter turn, not a flip
|
|
1064
|
+
three's sagittal canvas runs columns along `−k` and rows along `−j`, so the view is a **90°
|
|
1065
|
+
rotation as well as a scale**. Its drawn rectangle is the *display* size — width and height
|
|
1066
|
+
swapped relative to three's canvas — which is what `displaySizeOf(axis, canvas)` returns.
|
|
1067
|
+
Every other canvas, mask slices included, is laid out at that same display size.
|
|
1068
|
+
|
|
1069
|
+
Before 4.1.0 sagittal was `scale(-1, -1)` + `translate(-w, -h)`, a 180° flip, which was only
|
|
1070
|
+
correct for volumes already stored in one particular order.
|
|
1071
|
+
:::
|
|
1053
1072
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
| x (Sagittal) | `scale(-1, -1)` + `translate(-w, -h)` |
|
|
1057
|
-
| y (Coronal) | `scale(1, -1)` + `translate(0, -h)` |
|
|
1058
|
-
| z (Axial) | `scale(1, -1)` + `translate(0, -h)` |
|
|
1073
|
+
`Utils/orientation.ts`'s `VIEW_LAYOUT` states the same layout for the orientation letters, so
|
|
1074
|
+
the two are changed in the same commit.
|
|
1059
1075
|
|
|
1060
1076
|
Called from: `SliceRenderPipeline.redrawDisplayCanvas()`
|
|
1061
1077
|
|
|
1062
|
-
### 6.2 Mask Flip (Coronal
|
|
1078
|
+
### 6.2 Mask Flip (Coronal **and** Sagittal) <Badge type="tip" text="4.1.0" />
|
|
1063
1079
|
|
|
1064
|
-
|
|
1080
|
+
Mask contours are drawn bottom-up for any view whose slice rows run up the screen, which
|
|
1081
|
+
`contourPaint.rowsRunUp(axis)` decides:
|
|
1065
1082
|
|
|
1066
1083
|
```ts
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1084
|
+
/** Coronal and sagittal slices store z ascending in their rows and show superior at
|
|
1085
|
+
* the top, so their rows are drawn bottom-up. */
|
|
1086
|
+
export function rowsRunUp(axis: "x" | "y" | "z"): boolean {
|
|
1087
|
+
return axis !== "z";
|
|
1071
1088
|
}
|
|
1072
|
-
targetCtx.drawImage(emptyCanvas, 0, 0, scaledWidth, scaledHeight);
|
|
1073
|
-
if (axis === 'y') targetCtx.restore();
|
|
1074
1089
|
```
|
|
1075
1090
|
|
|
1076
|
-
| Axis | Mask
|
|
1077
|
-
|
|
1078
|
-
| z (Axial) | **None** |
|
|
1079
|
-
| y (Coronal) |
|
|
1080
|
-
| x (Sagittal) |
|
|
1091
|
+
| Axis | Mask flip | Why |
|
|
1092
|
+
|------|-----------|-----|
|
|
1093
|
+
| z (Axial) | **None** | Rows already run down the screen |
|
|
1094
|
+
| y (Coronal) | `scale(1, -1)` | Rows store `k` ascending; Superior belongs at the top |
|
|
1095
|
+
| x (Sagittal) | `scale(1, -1)` | Same — rows run along `k` |
|
|
1081
1096
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1097
|
+
It is applied in both drawing paths: on the `DOMMatrix` for outline mode, and on the context
|
|
1098
|
+
for fill mode, in each case *before* the voxel→display scale so the flip happens in display
|
|
1099
|
+
coordinates.
|
|
1100
|
+
|
|
1101
|
+
::: warning Changed in 4.1.0
|
|
1102
|
+
Sagittal previously had **no** mask flip, and sagittal slices were laid out `depth × height`.
|
|
1103
|
+
Both changed together: slices are now `height × depth` (columns along `y`, rows along `z`),
|
|
1104
|
+
and the flip applies. A caller reading `getSliceUint8` for the sagittal axis gets the
|
|
1105
|
+
transposed layout from 4.1.0 on.
|
|
1084
1106
|
:::
|
|
1085
1107
|
|
|
1086
|
-
### 6.3 applyMaskFlipForAxis
|
|
1108
|
+
### 6.3 `applyMaskFlipForAxis` was removed <Badge type="warning" text="removed in 4.1.0" />
|
|
1087
1109
|
|
|
1088
|
-
`RenderingUtils.applyMaskFlipForAxis()`
|
|
1110
|
+
`RenderingUtils.applyMaskFlipForAxis()` no longer exists. It duplicated the per-axis transform
|
|
1111
|
+
as a third copy, which could — and did — drift from the display path and the contour path.
|
|
1112
|
+
The two remaining copies are kept in step deliberately:
|
|
1113
|
+
`SliceRenderPipeline.flipDisplayImageByAxis` for the image, `contourPaint.rowsRunUp` for the
|
|
1114
|
+
masks.
|
|
1089
1115
|
|
|
1090
1116
|
---
|
|
1091
1117
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Upgrading to 4.0 <Badge type="warning" text="breaking" />
|
|
2
|
+
|
|
3
|
+
4.0.0 is a packaging release. The copper3d API itself is unchanged — every class, method and
|
|
4
|
+
type from 3.11.x still works the same way. What changed is **how three.js reaches you**, and
|
|
5
|
+
that needs a change on your side.
|
|
6
|
+
|
|
7
|
+
## The one required change
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install copper3d three@~0.186.0
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`three` is now a **peer dependency**. Previously copper3d depended on three and bundled it;
|
|
14
|
+
now you install it and copper3d shares your copy.
|
|
15
|
+
|
|
16
|
+
TypeScript users also want the types, which are an *optional* peer:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -D @types/three@~0.186.0
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
::: tip Why peer, not bundled
|
|
23
|
+
Bundling three gave the page two copies. three itself warns about this —
|
|
24
|
+
*"Multiple instances of Three.js being imported"* — and the consequence is worse than the
|
|
25
|
+
warning: a `Mesh` your code builds is not an `instanceof` the `Mesh` copper3d checks against,
|
|
26
|
+
because they come from different modules. Anything you pass across the boundary — a camera,
|
|
27
|
+
a scene, a geometry — had to survive that.
|
|
28
|
+
|
|
29
|
+
With a peer dependency there is exactly one three on the page, and objects cross freely.
|
|
30
|
+
:::
|
|
31
|
+
|
|
32
|
+
## What else changed
|
|
33
|
+
|
|
34
|
+
| | 3.11.x | 4.0.0 |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| three | bundled dependency, `^0.185.1` | **peer** dependency, `~0.186.0` |
|
|
37
|
+
| `@types/three` | dependency | optional peer, `~0.186.0` |
|
|
38
|
+
| ESM bundle | `dist/bundle.esm.js` | `dist/bundle.esm.mjs` |
|
|
39
|
+
| `package.json` `module` field | `"moudle"` *(typo — never resolved)* | `"module"`, plus a real `exports` map |
|
|
40
|
+
| three addon imports | `three/examples/jsm/…` | `three/addons/…` |
|
|
41
|
+
|
|
42
|
+
### The `exports` map
|
|
43
|
+
|
|
44
|
+
`package.json` now declares one:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"exports": {
|
|
49
|
+
".": {
|
|
50
|
+
"types": "./dist/types/index.d.ts",
|
|
51
|
+
"import": "./dist/bundle.esm.mjs",
|
|
52
|
+
"require": "./dist/bundle.umd.js"
|
|
53
|
+
},
|
|
54
|
+
"./dist/css/*": "./dist/css/*",
|
|
55
|
+
"./package.json": "./package.json"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`import` and `require` now resolve to the right build automatically. The ESM file is `.mjs`
|
|
61
|
+
so Node loads it as ESM without the package needing `"type": "module"`.
|
|
62
|
+
|
|
63
|
+
::: warning Deep imports are no longer reachable
|
|
64
|
+
An `exports` map is a boundary. If you were reaching into the package —
|
|
65
|
+
`import … from "copper3d/dist/bundle.esm.js"` — it will stop resolving. Import from the
|
|
66
|
+
package root, or from `copper3d/dist/css/...` for the stylesheet.
|
|
67
|
+
:::
|
|
68
|
+
|
|
69
|
+
### `moduleResolution` in your tsconfig
|
|
70
|
+
|
|
71
|
+
copper3d imports three's addons as `three/addons/*`, which three exposes **only** through its
|
|
72
|
+
`exports` map. TypeScript's legacy `"node"` resolution predates exports maps and cannot follow
|
|
73
|
+
those paths, so if your `tsconfig.json` says:
|
|
74
|
+
|
|
75
|
+
```jsonc
|
|
76
|
+
{ "compilerOptions": { "moduleResolution": "node" } }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
move it to `"bundler"` (Vite, webpack, Rollup) or `"node16"` / `"nodenext"` (Node). Leaving it
|
|
80
|
+
on `"node"` also means TypeScript ignores copper3d's own `exports` map and may not find its
|
|
81
|
+
types at all.
|
|
82
|
+
|
|
83
|
+
### The revision check
|
|
84
|
+
|
|
85
|
+
At import, copper3d compares the three revision it was **built** against with the one actually
|
|
86
|
+
**loaded**, and logs a `console.error` on a mismatch:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
copper3d was built against three r186, but three r180 is loaded.
|
|
90
|
+
Install the three version copper3d's peerDependencies name.
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
npm refuses an incompatible peer at install time, but yarn 1 and pnpm only warn — and three
|
|
94
|
+
changes behaviour between minor releases, so a mismatch is worth seeing somewhere it cannot be
|
|
95
|
+
scrolled past. The check never throws; it reports and carries on.
|
|
96
|
+
|
|
97
|
+
A build from source with nothing injected skips the comparison.
|
|
98
|
+
|
|
99
|
+
## What did *not* change
|
|
100
|
+
|
|
101
|
+
- Every copper3d class, method, option and type. No call sites need editing.
|
|
102
|
+
- `copperRenderer`, `copperScene`, `NrrdTools`, the loaders, the segmentation engine.
|
|
103
|
+
- The UMD build is still at `dist/bundle.umd.js`, now with `three` mapped to the `THREE`
|
|
104
|
+
global.
|
|
105
|
+
|
|
106
|
+
::: tip The UMD build is for `require`, not a `<script>` tag
|
|
107
|
+
Only three's **core** has a browser global. `three/addons/*` has none, so a bare script tag
|
|
108
|
+
cannot satisfy copper3d's addon imports. Use a bundler, or the ESM build.
|
|
109
|
+
:::
|
|
110
|
+
|
|
111
|
+
## Checklist
|
|
112
|
+
|
|
113
|
+
1. `npm install copper3d three@~0.186.0` (and `-D @types/three@~0.186.0` for TypeScript).
|
|
114
|
+
2. If your `tsconfig.json` has `"moduleResolution": "node"`, change it.
|
|
115
|
+
3. Replace any deep import of `copper3d/dist/...` with a root import.
|
|
116
|
+
4. Load the app once and check the console for the revision-mismatch error.
|
|
117
|
+
|
|
118
|
+
Nothing else. If step 4 is quiet and the app builds, you are done.
|
|
@@ -151,7 +151,7 @@ plane spatial context — without it the plane floats in an unbounded void and
|
|
|
151
151
|
nothing tells the reader how far through the volume they have scrubbed.
|
|
152
152
|
|
|
153
153
|
```ts
|
|
154
|
-
scene.loadNrrd(url, loadingBar,
|
|
154
|
+
scene.loadNrrd(url, loadingBar, (volume, meshes) => {
|
|
155
155
|
scene.addObject(meshes.z);
|
|
156
156
|
Copper.addVolumeBoundingBox(scene, volume.RASDimensions, { color: 0x8a7f84 });
|
|
157
157
|
});
|
package/ai-index/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"copper3dVersion": "
|
|
4
|
-
"generatedAt": "2026-10-
|
|
5
|
-
"symbolCount":
|
|
3
|
+
"copper3dVersion": "4.1.0",
|
|
4
|
+
"generatedAt": "2026-10-14T04:44:40.265Z",
|
|
5
|
+
"symbolCount": 1204,
|
|
6
6
|
"guides": [
|
|
7
7
|
{
|
|
8
8
|
"id": "4D-MRI-LV-rendering",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"title": "Load Progress & Errors",
|
|
75
75
|
"summary": "Every loader in copper3d gained `onProgress` and `onError` in **3.9.0**. Before that there was no way to find out that a load had failed — a broken URL, a 404, a corrupt file and a very slow download all looked identical from outside: the …",
|
|
76
76
|
"lang": "en",
|
|
77
|
-
"bytes":
|
|
77
|
+
"bytes": 11891
|
|
78
78
|
},
|
|
79
79
|
{
|
|
80
80
|
"id": "mcp-server",
|
|
@@ -100,6 +100,14 @@
|
|
|
100
100
|
"lang": "en",
|
|
101
101
|
"bytes": 6195
|
|
102
102
|
},
|
|
103
|
+
{
|
|
104
|
+
"id": "orientation",
|
|
105
|
+
"file": "orientation.md",
|
|
106
|
+
"title": "Patient Orientation <Badge type=\"tip\" text=\"4.1.0\" />",
|
|
107
|
+
"summary": "Every volume `loadNrrd` returns is in the **canonical voxel order**, whatever order its file stores. That is what makes each view come out in the radiological convention without the caller doing anything.",
|
|
108
|
+
"lang": "en",
|
|
109
|
+
"bytes": 6103
|
|
110
|
+
},
|
|
103
111
|
{
|
|
104
112
|
"id": "rotation-pivot",
|
|
105
113
|
"file": "rotation-pivot.md",
|
|
@@ -122,7 +130,7 @@
|
|
|
122
130
|
"title": "Segmentation Module Documentation",
|
|
123
131
|
"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
132
|
"lang": "en",
|
|
125
|
-
"bytes":
|
|
133
|
+
"bytes": 84465
|
|
126
134
|
},
|
|
127
135
|
{
|
|
128
136
|
"id": "surface-annotation-api",
|
|
@@ -132,13 +140,21 @@
|
|
|
132
140
|
"lang": "en",
|
|
133
141
|
"bytes": 22495
|
|
134
142
|
},
|
|
143
|
+
{
|
|
144
|
+
"id": "upgrading-to-4",
|
|
145
|
+
"file": "upgrading-to-4.md",
|
|
146
|
+
"title": "Upgrading to 4.0 <Badge type=\"warning\" text=\"breaking\" />",
|
|
147
|
+
"summary": "4.0.0 is a packaging release. The copper3d API itself is unchanged — every class, method and type from 3.11.x still works the same way. What changed is **how three.js reaches you**, and that needs a change on your side.",
|
|
148
|
+
"lang": "en",
|
|
149
|
+
"bytes": 4439
|
|
150
|
+
},
|
|
135
151
|
{
|
|
136
152
|
"id": "volume-display",
|
|
137
153
|
"file": "volume-display.md",
|
|
138
154
|
"title": "copper3d — Volume Slice Display",
|
|
139
155
|
"summary": "Two functions for the greyscale a volume slice actually comes out as: one that makes scrubbing cheap, one that makes dark studies readable.",
|
|
140
156
|
"lang": "en",
|
|
141
|
-
"bytes":
|
|
157
|
+
"bytes": 7754
|
|
142
158
|
}
|
|
143
159
|
]
|
|
144
160
|
}
|