copper3d 3.6.13 → 3.7.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.
Files changed (48) hide show
  1. package/dist/Loader/copperDicomLoader.js +6 -1
  2. package/dist/Loader/copperDicomLoader.js.map +1 -1
  3. package/dist/Loader/copperRaw4DVolumeLoader.d.ts +10 -0
  4. package/dist/Loader/copperRaw4DVolumeLoader.js +270 -0
  5. package/dist/Loader/copperRaw4DVolumeLoader.js.map +1 -0
  6. package/dist/Loader/mhdParser.d.ts +83 -0
  7. package/dist/Loader/mhdParser.js +130 -0
  8. package/dist/Loader/mhdParser.js.map +1 -0
  9. package/dist/Scene/commonSceneMethod.d.ts +1 -0
  10. package/dist/Scene/commonSceneMethod.js +4 -19
  11. package/dist/Scene/commonSceneMethod.js.map +1 -1
  12. package/dist/Scene/copperMScene.js +2 -15
  13. package/dist/Scene/copperMScene.js.map +1 -1
  14. package/dist/Scene/copperScene.d.ts +7 -1
  15. package/dist/Scene/copperScene.js +14 -2
  16. package/dist/Scene/copperScene.js.map +1 -1
  17. package/dist/Scene/preRenderRegistry.d.ts +33 -0
  18. package/dist/Scene/preRenderRegistry.js +44 -0
  19. package/dist/Scene/preRenderRegistry.js.map +1 -0
  20. package/dist/Utils/colormapData.d.ts +9 -0
  21. package/dist/Utils/colormapData.js +39 -0
  22. package/dist/Utils/colormapData.js.map +1 -0
  23. package/dist/Utils/texture2d.d.ts +2 -0
  24. package/dist/Utils/texture2d.js +7 -1
  25. package/dist/Utils/texture2d.js.map +1 -1
  26. package/dist/Utils/volumeColormap.d.ts +6 -0
  27. package/dist/Utils/volumeColormap.js +14 -0
  28. package/dist/Utils/volumeColormap.js.map +1 -0
  29. package/dist/Utils/volumeShader.d.ts +7 -0
  30. package/dist/Utils/volumeShader.js +98 -0
  31. package/dist/Utils/volumeShader.js.map +1 -0
  32. package/dist/bundle.esm.js +641 -72
  33. package/dist/bundle.umd.js +641 -72
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.js.map +1 -1
  36. package/dist/types/Loader/copperRaw4DVolumeLoader.d.ts +10 -0
  37. package/dist/types/Loader/mhdParser.d.ts +83 -0
  38. package/dist/types/Scene/commonSceneMethod.d.ts +1 -0
  39. package/dist/types/Scene/copperScene.d.ts +7 -1
  40. package/dist/types/Scene/preRenderRegistry.d.ts +33 -0
  41. package/dist/types/Utils/colormapData.d.ts +9 -0
  42. package/dist/types/Utils/texture2d.d.ts +2 -0
  43. package/dist/types/Utils/volumeColormap.d.ts +6 -0
  44. package/dist/types/Utils/volumeShader.d.ts +7 -0
  45. package/dist/types/index.d.ts +2 -2
  46. package/dist/types/types/types.d.ts +82 -2
  47. package/dist/types/types.d.ts +82 -2
  48. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@ import { MeshNodeTool } from "./Utils/MeshNodeTool";
19
19
  import { removeGuiFolderChilden } from "./Utils/segmentation/coreTools/gui";
20
20
  import { SurfaceAnnotator } from "./Utils/surfaceAnnotation";
21
21
  import type { SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions } from "./Utils/surfaceAnnotation";
22
- import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController } from "./types/types";
22
+ import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController } from "./types/types";
23
23
  import { IPaintImage, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, IGuiMeta } from "./Utils/segmentation/core/types";
24
24
  import { NrrdState } from "./Utils/segmentation/coreTools/NrrdState";
25
25
  import { GuiState } from "./Utils/segmentation/coreTools/GuiState";
@@ -30,4 +30,4 @@ import type { AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult } from
30
30
  import "./css/style.css";
31
31
  export declare const REVISION: string;
32
32
  export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, NrrdTools, loading, Copper3dTrackballControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, };
33
- export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, };
33
+ export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation,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AC;CAC1B;AAAC,WAAM;IACN,oDAAoD;CACrD;AACD,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAElC,8GAA8G;AAC9G,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IAChC,MAAc,CAAC,oBAAoB,GAAG,QAAQ,CAAC;CACjD;AAED,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;IAClC,OAAO,CAAC,GAAG,CACT,8BAA8B,QAAQ,EAAE,EACxC,8CAA8C,EAC9C,8CAA8C,CAC/C,CAAC;CACH;AAED,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,SAAS,EACT,OAAO,EACP,yBAAyB,EACzB,oBAAoB,EACpB,YAAY,EACZ,QAAQ,EACR,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,gBAAgB,GACjB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import * as THREE from "three";
2
+ import { raw4DVolumeOptsType, Raw4DVolumeController } from "../types/types";
3
+ /**
4
+ * Load a 4D volume sequence (one .mhd/.raw pair per cardiac phase) and add it to `scene`
5
+ * as a raycast volume.
6
+ *
7
+ * The returned controller runs NO clock of its own — drive it with setFrame()/setPhase()
8
+ * so it can share a cardiac-phase clock with other modalities.
9
+ */
10
+ export declare function loadRaw4DVolume(mhdUrls: Array<string>, scene: THREE.Scene, opts?: raw4DVolumeOptsType, callback?: (ctrl: Raw4DVolumeController) => void): void;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Minimal MetaImage (.mhd) header parser.
3
+ *
4
+ * Deliberately dependency-free (no three.js) so it can run under
5
+ * `node --experimental-strip-types --test`.
6
+ *
7
+ * Only the subset the 4D ultrasound data uses is supported: 3D, uncompressed,
8
+ * uint8. Anything else throws rather than silently mis-rendering.
9
+ */
10
+ export type Matrix3x3 = [number, number, number, number, number, number, number, number, number];
11
+ /** Row-major identity — the value MetaImage writes when it has no real orientation. */
12
+ export declare const IDENTITY_MATRIX: Matrix3x3;
13
+ export interface MhdHeader {
14
+ /** DimSize — x is the fastest-varying axis. e.g. [189, 189, 134] */
15
+ dims: [number, number, number];
16
+ /** ElementSpacing in mm. e.g. [1, 1, 1] */
17
+ spacing: [number, number, number];
18
+ /** ElementType, always "MET_UCHAR" here. */
19
+ elementType: string;
20
+ /** CompressedData — always false here (true is rejected). */
21
+ compressed: boolean;
22
+ /** ElementDataFile, relative to the .mhd. e.g. "DZET01_17871377_000.raw" */
23
+ elementDataFile: string;
24
+ /** Offset — world coordinates of voxel (0,0,0). Defaults to the origin. */
25
+ offset: [number, number, number];
26
+ /** TransformMatrix — row-major direction cosines. Defaults to the identity. */
27
+ transformMatrix: Matrix3x3;
28
+ /** AnatomicalOrientation, e.g. "RAI". `null` when absent. */
29
+ anatomicalOrientation: string | null;
30
+ /**
31
+ * MetaImage has no standard way to assert "this is the same world frame as that MRI".
32
+ * DICOM does — FrameOfReferenceUID (0020,0052). MetaImage readers ignore unknown keys,
33
+ * so a producer can carry the UID across as a custom line. `null` when absent.
34
+ */
35
+ frameOfReferenceUID: string | null;
36
+ /**
37
+ * True when Offset or TransformMatrix carry real values, i.e. the header actually places
38
+ * the volume somewhere. A zero offset with an identity matrix is ambiguous — it may mean
39
+ * "at the origin, unrotated" or "nobody filled this in" — and is treated as the latter,
40
+ * because silently trusting it is the dangerous failure mode.
41
+ */
42
+ hasPose: boolean;
43
+ /** True when ElementSpacing is not the placeholder 1 1 1, i.e. real physical voxel size. */
44
+ hasRealSpacing: boolean;
45
+ }
46
+ export declare function parseMhdHeader(text: string): MhdHeader;
47
+ export type RegistrationReason = "no-pose" | "frame-missing" | "frame-mismatch" | "unverified" | "verified";
48
+ export interface RegistrationDecision {
49
+ /** Honour the header's placement? */
50
+ registered: boolean;
51
+ /** Did a FrameOfReferenceUID actually prove the shared world frame? */
52
+ frameVerified: boolean;
53
+ reason: RegistrationReason;
54
+ }
55
+ /**
56
+ * Decide whether a header's pose may be trusted.
57
+ *
58
+ * Two independent things must hold, and the second is the one people forget:
59
+ *
60
+ * 1. the header must actually carry a pose (`hasPose`), and
61
+ * 2. that pose must be expressed in the SAME world frame as the scene.
62
+ *
63
+ * DICOM proves (2) with FrameOfReferenceUID. MetaImage has no such field, so a producer must
64
+ * carry the UID across as a custom line. When the caller names the scene's frame and the file
65
+ * cannot match it, the pose is refused — a pose in another scanner's coordinate system is
66
+ * worse than no pose at all, because it looks authoritative while being wrong.
67
+ *
68
+ * When the caller names no frame, a pose is honoured but reported as `unverified`: nobody
69
+ * checked, and the UI should not claim otherwise.
70
+ */
71
+ export declare function resolveRegistration(header: MhdHeader, expectedFrameOfReferenceUID?: string | null): RegistrationDecision;
72
+ /**
73
+ * voxel index -> world, as a column-major 4x4 (three.js `Matrix4.elements` order).
74
+ *
75
+ * ITK/MetaImage convention: `world = Offset + D · (Spacing ∘ index)`, with `D` the
76
+ * row-major direction matrix from TransformMatrix.
77
+ *
78
+ * Only meaningful when `header.hasPose` — otherwise this is the identity scaled by
79
+ * spacing, which places the volume at the world origin and means nothing.
80
+ */
81
+ export declare function voxelToWorldMatrix(header: MhdHeader): number[];
82
+ /** Number of voxels implied by the header — equals the .raw byte length for uint8. */
83
+ export declare function voxelCount(header: MhdHeader): number;
@@ -28,6 +28,7 @@ export declare class commonScene {
28
28
  addObject(obj: any): void;
29
29
  setDepth(value: number): void;
30
30
  setDicomFilesOrder(value: "ascending" | "descending"): void;
31
+ /** Registers a per-frame callback and returns its id, for removePreRenderCallbackFunction. */
31
32
  addPreRenderCallbackFunction(callbackFunction: Function): number;
32
33
  removePreRenderCallbackFunction(id: number): void;
33
34
  pickModel(content: THREE.Group, callback: (selectMesh: THREE.Mesh | undefined) => void, options?: string[]): void;
@@ -5,7 +5,7 @@ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
5
5
  import { baseScene } from "./baseScene";
6
6
  import { vtkModels } from "../types/types";
7
7
  import { TrackballControls } from "three/examples/jsm/controls/TrackballControls";
8
- import { ICopperSceneOpts, aligned4DOptsType, Aligned4DController } from "../types/types";
8
+ import { ICopperSceneOpts, aligned4DOptsType, Aligned4DController, raw4DVolumeOptsType, Raw4DVolumeController } from "../types/types";
9
9
  import { SurfaceAnnotator } from "../Utils/surfaceAnnotation";
10
10
  import type { SurfaceAnnotatorOptions } from "../Utils/surfaceAnnotation";
11
11
  export declare class copperScene extends baseScene {
@@ -40,6 +40,12 @@ export declare class copperScene extends baseScene {
40
40
  * advance together off ONE shared frame clock. Returns a controller (play/pause/...).
41
41
  */
42
42
  loadAligned4D(opts: aligned4DOptsType, callback?: (ctrl: Aligned4DController) => void): void;
43
+ /**
44
+ * Load a 4D volume sequence (.mhd/.raw per cardiac phase) and render it as a raycast
45
+ * volume. The returned controller runs no clock of its own — drive it with
46
+ * setFrame()/setPhase() so it can share a cardiac-phase clock with other modalities.
47
+ */
48
+ loadRaw4DVolume(mhdUrls: Array<string>, opts?: raw4DVolumeOptsType, callback?: (ctrl: Raw4DVolumeController) => void): void;
43
49
  getPlayRate(): number;
44
50
  setPlayRate(playRate: number): void;
45
51
  setModelPosition(model: THREE.Group | THREE.Mesh, position: {
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Registry of per-frame callbacks, keyed by a stable id.
3
+ *
4
+ * Deliberately dependency-free (no three.js) so it can be unit-tested under
5
+ * `node --experimental-strip-types --test`.
6
+ *
7
+ * It replaces an object literal that was duplicated across `commonSceneMethod` and
8
+ * `copperMScene` and carried three bugs, one of which silently corrupted callers:
9
+ *
10
+ * 1. `index` was never incremented, so `addPreRenderCallbackFunction` always returned 0.
11
+ * Callers who stored that value and later removed it deleted somebody else's callback.
12
+ * 2. `add` guarded with `if (!fn.id)`, and the very first id was 0 — falsy — so the first
13
+ * callback looked unregistered forever and could be added twice.
14
+ * 3. `remove(id)` spliced `cache` at the raw id, treating the id as an array index. Removing
15
+ * one callback shifted every later one down, so every previously handed-out id then
16
+ * pointed at its neighbour.
17
+ *
18
+ * Here ids come from a monotonic counter, are never reused, and are held in an array parallel
19
+ * to `cache` — so a removal cannot invalidate anyone else's id.
20
+ */
21
+ export interface PreRenderRegistry {
22
+ /** Monotonic counter for the next id. NOT an index into `cache`. */
23
+ index: number;
24
+ /** Callbacks, in insertion order. Consumers iterate this each frame. */
25
+ cache: Function[];
26
+ /** Ids, parallel to `cache`. Stable across removals. */
27
+ ids: number[];
28
+ /** Registers `fn` and returns its id. Idempotent: re-adding returns the existing id. */
29
+ add: (fn: Function) => number;
30
+ /** Removes the callback with this id. A no-op for an unknown id. */
31
+ remove: (id: number) => void;
32
+ }
33
+ export declare function createPreRenderRegistry(): PreRenderRegistry;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Blue -> orange transfer function for ultrasound volume rendering.
3
+ *
4
+ * Dependency-free (no three.js) so it can be unit-tested under Node.
5
+ * The ALPHA channel is load-bearing: three's VolumeRenderShader1 samples this
6
+ * ramp as RGBA, so alpha is what turns low-intensity speckle transparent and
7
+ * gives the volume its cloud-like appearance.
8
+ */
9
+ export declare function buildBlueOrangeRGBA(size?: number): Uint8Array;
@@ -7,6 +7,8 @@ export interface texture2dResult {
7
7
  updateTexture: (copperVolume: copperVolumeType) => void;
8
8
  setFrame: (i: number) => void;
9
9
  setWindow: (center: number, width: number) => void;
10
+ /** Post-window gain. 1.0 is faithful; 1.5 is the historical hard-coded default. */
11
+ setBrightness: (v: number) => void;
10
12
  }
11
13
  export declare function createTexture2D_NRRD(data: Uint8Array, width: number, height: number, depth: number, callback: (mesh: THREE.Mesh) => void): void;
12
14
  export declare function createTexture2D_Array(copperVolume: copperVolumeType, depth: number, scene: THREE.Scene, gui?: GUI, aligned?: boolean): texture2dResult;
@@ -0,0 +1,6 @@
1
+ import * as THREE from "three";
2
+ /**
3
+ * A 1-D RGBA colormap texture for VolumeRenderShader1's `u_cmdata` uniform.
4
+ * Caller owns the texture and must dispose() it.
5
+ */
6
+ export declare function createBlueOrangeColormap(size?: number): THREE.DataTexture;
@@ -0,0 +1,7 @@
1
+ import * as THREE from "three";
2
+ export interface VolumeShaderParts {
3
+ uniforms: Record<string, THREE.IUniform>;
4
+ vertexShader: string;
5
+ fragmentShader: string;
6
+ }
7
+ export declare function createVolumeShaderWithOpacity(): VolumeShaderParts;
@@ -19,7 +19,7 @@ import { MeshNodeTool } from "./Utils/MeshNodeTool";
19
19
  import { removeGuiFolderChilden } from "./Utils/segmentation/coreTools/gui";
20
20
  import { SurfaceAnnotator } from "./Utils/surfaceAnnotation";
21
21
  import type { SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions } from "./Utils/surfaceAnnotation";
22
- import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController } from "./types/types";
22
+ import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController } from "./types/types";
23
23
  import { IPaintImage, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, IGuiMeta } from "./Utils/segmentation/core/types";
24
24
  import { NrrdState } from "./Utils/segmentation/coreTools/NrrdState";
25
25
  import { GuiState } from "./Utils/segmentation/coreTools/GuiState";
@@ -30,4 +30,4 @@ import type { AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult } from
30
30
  import "./css/style.css";
31
31
  export declare const REVISION: string;
32
32
  export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, NrrdTools, loading, Copper3dTrackballControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, };
33
- export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, };
33
+ export type { positionType, screenPosType, optsType, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, };
@@ -38,10 +38,15 @@ interface modelVisualisationDataType {
38
38
  visible: boolean;
39
39
  mesh: THREE.Mesh;
40
40
  }
41
+ /** Implemented by `Scene/preRenderRegistry.ts`, which is where the semantics are documented. */
41
42
  interface preRenderCallbackFunctionType {
43
+ /** Monotonic counter for the next id. NOT an index into `cache`. */
42
44
  index: number;
43
45
  cache: Function[];
44
- add: (fn: any) => void;
46
+ /** Ids, parallel to `cache`. Stable across removals. */
47
+ ids: number[];
48
+ /** Registers `fn` and returns its id. Idempotent. */
49
+ add: (fn: Function) => number;
45
50
  remove: (id: number) => void;
46
51
  }
47
52
  interface baseStateType {
@@ -169,6 +174,7 @@ interface copperVolumeType {
169
174
  imagePositionPatient?: number[];
170
175
  imageOrientationPatient?: number[];
171
176
  pixelSpacing?: number[];
177
+ frameOfReferenceUID?: string;
172
178
  corners?: planeCorners;
173
179
  }
174
180
  interface aligned4DSurfaceType {
@@ -190,6 +196,11 @@ interface Aligned4DController {
190
196
  plane: THREE.Mesh;
191
197
  surfaceMeshes: Record<string, THREE.Mesh>;
192
198
  frameCount: number;
199
+ /**
200
+ * The MRI series' DICOM FrameOfReferenceUID (0020,0052). Another modality is registered to
201
+ * this scene only if it declares the same UID; nothing else proves a shared world frame.
202
+ */
203
+ frameOfReferenceUID?: string;
193
204
  play: () => void;
194
205
  pause: () => void;
195
206
  toggle: () => void;
@@ -197,11 +208,80 @@ interface Aligned4DController {
197
208
  setFrame: (i: number) => void;
198
209
  setFrameOffset: (name: string, n: number) => void;
199
210
  setWindow: (center: number, width: number) => void;
211
+ /** Post-window gain on the MRI plane. 1.0 is faithful; 1.5 is the historical default. */
212
+ setPlaneBrightness: (v: number) => void;
200
213
  setPlaneOpacity: (v: number) => void;
201
214
  setSurfaceOpacity: (name: string, v: number) => void;
202
215
  setSurfaceVisible: (name: string, visible: boolean) => void;
203
216
  dispose: () => void;
204
217
  }
218
+ interface raw4DVolumeTransformType {
219
+ position?: [number, number, number];
220
+ /** Euler XYZ, radians. Ignored when `quaternion` is supplied. */
221
+ rotation?: [number, number, number];
222
+ /** [x, y, z, w]. Takes precedence over `rotation` — use it to align the volume
223
+ * to an arbitrary world axis, which Euler angles express awkwardly. */
224
+ quaternion?: [number, number, number, number];
225
+ scale?: number | [number, number, number];
226
+ }
227
+ interface raw4DVolumeOptsType {
228
+ transform?: raw4DVolumeTransformType;
229
+ /**
230
+ * "mip" = maximum intensity projection (cannot show a dark cavity inside bright tissue).
231
+ * "dvr" = front-to-back compositing (can). "iso" = isosurface.
232
+ */
233
+ renderStyle?: "mip" | "iso" | "dvr";
234
+ /** Per-sample opacity multiplier for the "dvr" style. */
235
+ dvrDensity?: number;
236
+ /** Brightness restored after DVR weights emission by intensity. */
237
+ dvrGain?: number;
238
+ /** Intensity window in normalised 0..1 units (uint8 samples arrive normalised). */
239
+ clim?: [number, number];
240
+ /** Only used when renderStyle === "iso". */
241
+ isoThreshold?: number;
242
+ opacity?: number;
243
+ onProgress?: (loaded: number, total: number) => void;
244
+ /** Called if any frame fails to load/parse/validate. Without it the failure is rethrown. */
245
+ onError?: (err: Error) => void;
246
+ /**
247
+ * The scene's DICOM FrameOfReferenceUID. When given, the .mhd's pose is honoured only if the
248
+ * file declares the same UID — a pose in another scanner's frame is worse than no pose.
249
+ */
250
+ expectFrameOfReferenceUID?: string;
251
+ }
252
+ interface Raw4DVolumeController {
253
+ /** Transform target — move/rotate/scale this, not `mesh`. */
254
+ root: THREE.Group;
255
+ /** The raycast box. Exposed for debugging / bounding-box helpers. */
256
+ mesh: THREE.Mesh;
257
+ frameCount: number;
258
+ /**
259
+ * True when the .mhd carried a real Offset/TransformMatrix and the volume was placed
260
+ * from it. False means the volume is NOT registered: the caller's `transform` positions
261
+ * it, and that pose is a best-effort guess, not an anatomical alignment.
262
+ */
263
+ registered: boolean;
264
+ /**
265
+ * True only when the .mhd declared a FrameOfReferenceUID that matched the scene's. A
266
+ * registered volume with `frameVerified === false` was placed by a header nobody checked.
267
+ */
268
+ frameVerified: boolean;
269
+ /**
270
+ * The .mhd's custom FrameOfReferenceUID line, if present. Only a matching UID proves the
271
+ * volume shares a world frame with the MRI; MetaImage has no standard field for this.
272
+ */
273
+ frameOfReferenceUID: string | null;
274
+ setFrame: (i: number) => void;
275
+ /** Normalised cardiac phase in [0,1). */
276
+ setPhase: (p: number) => void;
277
+ setOpacity: (v: number) => void;
278
+ setClim: (lo: number, hi: number) => void;
279
+ setRenderStyle: (s: "mip" | "iso" | "dvr") => void;
280
+ setDvrDensity: (v: number) => void;
281
+ setDvrGain: (v: number) => void;
282
+ setTransform: (t: raw4DVolumeTransformType) => void;
283
+ dispose: () => void;
284
+ }
205
285
  interface dicomLoaderOptsType {
206
286
  gui?: GUI;
207
287
  getMesh?: (mesh: THREE.Mesh) => void;
@@ -227,4 +307,4 @@ interface IMeshNodes {
227
307
  nodes: INodes;
228
308
  elements: IElements;
229
309
  }
230
- export type { SceneMapType, ICopperRenderOpt, stateType, modelVisualisationDataType, preRenderCallbackFunctionType, baseStateType, nrrdMeshesType, nrrdSliceType, loadingBarType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, SerialService_kiwrious, kiwriousType, mouseMovePositionType, positionType, optionsGltfExporterType, vtkModels, planeCorners, copperVolumeType, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, dicomLoaderOptsType, exportPaintImagesType, exportPaintImageType, storeExportPaintImageType, IOptVTKLoader, ICopperSceneOpts, IMeshNodes, };
310
+ export type { SceneMapType, ICopperRenderOpt, stateType, modelVisualisationDataType, preRenderCallbackFunctionType, baseStateType, nrrdMeshesType, nrrdSliceType, loadingBarType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, SerialService_kiwrious, kiwriousType, mouseMovePositionType, positionType, optionsGltfExporterType, vtkModels, planeCorners, copperVolumeType, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, dicomLoaderOptsType, exportPaintImagesType, exportPaintImageType, storeExportPaintImageType, IOptVTKLoader, ICopperSceneOpts, IMeshNodes, };
@@ -38,10 +38,15 @@ interface modelVisualisationDataType {
38
38
  visible: boolean;
39
39
  mesh: THREE.Mesh;
40
40
  }
41
+ /** Implemented by `Scene/preRenderRegistry.ts`, which is where the semantics are documented. */
41
42
  interface preRenderCallbackFunctionType {
43
+ /** Monotonic counter for the next id. NOT an index into `cache`. */
42
44
  index: number;
43
45
  cache: Function[];
44
- add: (fn: any) => void;
46
+ /** Ids, parallel to `cache`. Stable across removals. */
47
+ ids: number[];
48
+ /** Registers `fn` and returns its id. Idempotent. */
49
+ add: (fn: Function) => number;
45
50
  remove: (id: number) => void;
46
51
  }
47
52
  interface baseStateType {
@@ -169,6 +174,7 @@ interface copperVolumeType {
169
174
  imagePositionPatient?: number[];
170
175
  imageOrientationPatient?: number[];
171
176
  pixelSpacing?: number[];
177
+ frameOfReferenceUID?: string;
172
178
  corners?: planeCorners;
173
179
  }
174
180
  interface aligned4DSurfaceType {
@@ -190,6 +196,11 @@ interface Aligned4DController {
190
196
  plane: THREE.Mesh;
191
197
  surfaceMeshes: Record<string, THREE.Mesh>;
192
198
  frameCount: number;
199
+ /**
200
+ * The MRI series' DICOM FrameOfReferenceUID (0020,0052). Another modality is registered to
201
+ * this scene only if it declares the same UID; nothing else proves a shared world frame.
202
+ */
203
+ frameOfReferenceUID?: string;
193
204
  play: () => void;
194
205
  pause: () => void;
195
206
  toggle: () => void;
@@ -197,11 +208,80 @@ interface Aligned4DController {
197
208
  setFrame: (i: number) => void;
198
209
  setFrameOffset: (name: string, n: number) => void;
199
210
  setWindow: (center: number, width: number) => void;
211
+ /** Post-window gain on the MRI plane. 1.0 is faithful; 1.5 is the historical default. */
212
+ setPlaneBrightness: (v: number) => void;
200
213
  setPlaneOpacity: (v: number) => void;
201
214
  setSurfaceOpacity: (name: string, v: number) => void;
202
215
  setSurfaceVisible: (name: string, visible: boolean) => void;
203
216
  dispose: () => void;
204
217
  }
218
+ interface raw4DVolumeTransformType {
219
+ position?: [number, number, number];
220
+ /** Euler XYZ, radians. Ignored when `quaternion` is supplied. */
221
+ rotation?: [number, number, number];
222
+ /** [x, y, z, w]. Takes precedence over `rotation` — use it to align the volume
223
+ * to an arbitrary world axis, which Euler angles express awkwardly. */
224
+ quaternion?: [number, number, number, number];
225
+ scale?: number | [number, number, number];
226
+ }
227
+ interface raw4DVolumeOptsType {
228
+ transform?: raw4DVolumeTransformType;
229
+ /**
230
+ * "mip" = maximum intensity projection (cannot show a dark cavity inside bright tissue).
231
+ * "dvr" = front-to-back compositing (can). "iso" = isosurface.
232
+ */
233
+ renderStyle?: "mip" | "iso" | "dvr";
234
+ /** Per-sample opacity multiplier for the "dvr" style. */
235
+ dvrDensity?: number;
236
+ /** Brightness restored after DVR weights emission by intensity. */
237
+ dvrGain?: number;
238
+ /** Intensity window in normalised 0..1 units (uint8 samples arrive normalised). */
239
+ clim?: [number, number];
240
+ /** Only used when renderStyle === "iso". */
241
+ isoThreshold?: number;
242
+ opacity?: number;
243
+ onProgress?: (loaded: number, total: number) => void;
244
+ /** Called if any frame fails to load/parse/validate. Without it the failure is rethrown. */
245
+ onError?: (err: Error) => void;
246
+ /**
247
+ * The scene's DICOM FrameOfReferenceUID. When given, the .mhd's pose is honoured only if the
248
+ * file declares the same UID — a pose in another scanner's frame is worse than no pose.
249
+ */
250
+ expectFrameOfReferenceUID?: string;
251
+ }
252
+ interface Raw4DVolumeController {
253
+ /** Transform target — move/rotate/scale this, not `mesh`. */
254
+ root: THREE.Group;
255
+ /** The raycast box. Exposed for debugging / bounding-box helpers. */
256
+ mesh: THREE.Mesh;
257
+ frameCount: number;
258
+ /**
259
+ * True when the .mhd carried a real Offset/TransformMatrix and the volume was placed
260
+ * from it. False means the volume is NOT registered: the caller's `transform` positions
261
+ * it, and that pose is a best-effort guess, not an anatomical alignment.
262
+ */
263
+ registered: boolean;
264
+ /**
265
+ * True only when the .mhd declared a FrameOfReferenceUID that matched the scene's. A
266
+ * registered volume with `frameVerified === false` was placed by a header nobody checked.
267
+ */
268
+ frameVerified: boolean;
269
+ /**
270
+ * The .mhd's custom FrameOfReferenceUID line, if present. Only a matching UID proves the
271
+ * volume shares a world frame with the MRI; MetaImage has no standard field for this.
272
+ */
273
+ frameOfReferenceUID: string | null;
274
+ setFrame: (i: number) => void;
275
+ /** Normalised cardiac phase in [0,1). */
276
+ setPhase: (p: number) => void;
277
+ setOpacity: (v: number) => void;
278
+ setClim: (lo: number, hi: number) => void;
279
+ setRenderStyle: (s: "mip" | "iso" | "dvr") => void;
280
+ setDvrDensity: (v: number) => void;
281
+ setDvrGain: (v: number) => void;
282
+ setTransform: (t: raw4DVolumeTransformType) => void;
283
+ dispose: () => void;
284
+ }
205
285
  interface dicomLoaderOptsType {
206
286
  gui?: GUI;
207
287
  getMesh?: (mesh: THREE.Mesh) => void;
@@ -227,4 +307,4 @@ interface IMeshNodes {
227
307
  nodes: INodes;
228
308
  elements: IElements;
229
309
  }
230
- export type { SceneMapType, ICopperRenderOpt, stateType, modelVisualisationDataType, preRenderCallbackFunctionType, baseStateType, nrrdMeshesType, nrrdSliceType, loadingBarType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, SerialService_kiwrious, kiwriousType, mouseMovePositionType, positionType, optionsGltfExporterType, vtkModels, planeCorners, copperVolumeType, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, dicomLoaderOptsType, exportPaintImagesType, exportPaintImageType, storeExportPaintImageType, IOptVTKLoader, ICopperSceneOpts, IMeshNodes, };
310
+ export type { SceneMapType, ICopperRenderOpt, stateType, modelVisualisationDataType, preRenderCallbackFunctionType, baseStateType, nrrdMeshesType, nrrdSliceType, loadingBarType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, SerialService_kiwrious, kiwriousType, mouseMovePositionType, positionType, optionsGltfExporterType, vtkModels, planeCorners, copperVolumeType, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, dicomLoaderOptsType, exportPaintImagesType, exportPaintImageType, storeExportPaintImageType, IOptVTKLoader, ICopperSceneOpts, IMeshNodes, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "copper3d",
3
3
  "description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
4
- "version": "3.6.13",
4
+ "version": "3.7.0",
5
5
  "main": "dist/bundle.umd.js",
6
6
  "moudle": "dist/bundle.esm.js",
7
7
  "types": "dist/types/index.d.ts",