copper3d 4.0.0 → 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.
Files changed (74) hide show
  1. package/README.md +16 -3
  2. package/ai-index/guides/load-callbacks.md +24 -5
  3. package/ai-index/guides/orientation.md +155 -0
  4. package/ai-index/guides/segmentation-module.md +51 -25
  5. package/ai-index/guides/volume-display.md +1 -1
  6. package/ai-index/manifest.json +14 -6
  7. package/ai-index/symbols.json +1 -1
  8. package/dist/Controls/orbitFraming.d.ts +4 -4
  9. package/dist/Controls/orbitFraming.js +4 -4
  10. package/dist/Loader/copperNrrdLoader.d.ts +15 -1
  11. package/dist/Loader/copperNrrdLoader.js +30 -8
  12. package/dist/Loader/copperNrrdLoader.js.map +1 -1
  13. package/dist/Loader/nrrdWorkerCore.d.ts +15 -2
  14. package/dist/Loader/nrrdWorkerCore.js +47 -3
  15. package/dist/Loader/nrrdWorkerCore.js.map +1 -1
  16. package/dist/Loader/rasDimensions.d.ts +9 -0
  17. package/dist/Loader/rasDimensions.js +12 -0
  18. package/dist/Loader/rasDimensions.js.map +1 -0
  19. package/dist/Scene/commonSceneMethod.d.ts +10 -1
  20. package/dist/Scene/commonSceneMethod.js +11 -3
  21. package/dist/Scene/commonSceneMethod.js.map +1 -1
  22. package/dist/Utils/orientation.d.ts +94 -0
  23. package/dist/Utils/orientation.js +261 -0
  24. package/dist/Utils/orientation.js.map +1 -0
  25. package/dist/Utils/segmentation/NrrdTools.d.ts +4 -0
  26. package/dist/Utils/segmentation/NrrdTools.js +4 -2
  27. package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
  28. package/dist/Utils/segmentation/RenderingUtils.d.ts +0 -5
  29. package/dist/Utils/segmentation/RenderingUtils.js +3 -23
  30. package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
  31. package/dist/Utils/segmentation/contourPaint.d.ts +5 -0
  32. package/dist/Utils/segmentation/contourPaint.js +10 -3
  33. package/dist/Utils/segmentation/contourPaint.js.map +1 -1
  34. package/dist/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  35. package/dist/Utils/segmentation/core/MaskVolume.js +38 -38
  36. package/dist/Utils/segmentation/core/MaskVolume.js.map +1 -1
  37. package/dist/Utils/segmentation/tools/AiAssistTool.js +10 -10
  38. package/dist/Utils/segmentation/tools/AiAssistTool.js.map +1 -1
  39. package/dist/Utils/segmentation/tools/ContrastTool.js +1 -1
  40. package/dist/Utils/segmentation/tools/CrosshairTool.js +30 -22
  41. package/dist/Utils/segmentation/tools/CrosshairTool.js.map +1 -1
  42. package/dist/Utils/segmentation/tools/DrawingTool.js +14 -14
  43. package/dist/Utils/segmentation/tools/DrawingTool.js.map +1 -1
  44. package/dist/Utils/segmentation/tools/ImageStoreHelper.d.ts +3 -5
  45. package/dist/Utils/segmentation/tools/ImageStoreHelper.js +7 -11
  46. package/dist/Utils/segmentation/tools/ImageStoreHelper.js.map +1 -1
  47. package/dist/Utils/segmentation/tools/MaskMirror.js +5 -5
  48. package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -1
  49. package/dist/Utils/segmentation/tools/SliceRenderPipeline.d.ts +28 -4
  50. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +50 -24
  51. package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
  52. package/dist/Utils/segmentation/tools/SphereBrushTool.js +5 -4
  53. package/dist/Utils/segmentation/tools/SphereBrushTool.js.map +1 -1
  54. package/dist/Utils/segmentation/tools/SphereTool.js +13 -11
  55. package/dist/Utils/segmentation/tools/SphereTool.js.map +1 -1
  56. package/dist/bundle.esm.mjs +611 -312
  57. package/dist/bundle.umd.js +618 -311
  58. package/dist/index.d.ts +5 -2
  59. package/dist/index.js +3 -1
  60. package/dist/index.js.map +1 -1
  61. package/dist/types/Controls/orbitFraming.d.ts +4 -4
  62. package/dist/types/Loader/copperNrrdLoader.d.ts +15 -1
  63. package/dist/types/Loader/nrrdWorkerCore.d.ts +15 -2
  64. package/dist/types/Loader/rasDimensions.d.ts +9 -0
  65. package/dist/types/Scene/commonSceneMethod.d.ts +10 -1
  66. package/dist/types/Utils/orientation.d.ts +94 -0
  67. package/dist/types/Utils/segmentation/NrrdTools.d.ts +4 -0
  68. package/dist/types/Utils/segmentation/RenderingUtils.d.ts +0 -5
  69. package/dist/types/Utils/segmentation/contourPaint.d.ts +5 -0
  70. package/dist/types/Utils/segmentation/core/MaskVolume.d.ts +1 -1
  71. package/dist/types/Utils/segmentation/tools/ImageStoreHelper.d.ts +3 -5
  72. package/dist/types/Utils/segmentation/tools/SliceRenderPipeline.d.ts +28 -4
  73. package/dist/types/index.d.ts +5 -2
  74. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -45,6 +45,7 @@ import type { PosableScene } from "./Controls/setCameraPose";
45
45
  import { addVolumeBoundingBox, VOLUME_BOUNDS_NAME } from "./Loader/volumeBoundingBox";
46
46
  import type { BoundingBoxHost, VolumeBoundingBoxOpts } from "./Loader/volumeBoundingBox";
47
47
  import { DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices } from "./Loader/copperNrrdLoader";
48
+ import { rasDimensions } from "./Loader/rasDimensions";
48
49
  import type { NrrdAxis } from "./Loader/copperNrrdLoader";
49
50
  import { easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle } from "./Controls/cameraTransitions";
50
51
  import type { Pose } from "./Controls/cameraTransitions";
@@ -60,8 +61,10 @@ import { CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_
60
61
  import type { LayerId, ChannelValue } from "./Utils/segmentation/core/index";
61
62
  import { MAX_ENGINE_CHANNEL } from "./Utils/segmentation/core/index";
62
63
  import type { AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult } from "./Utils/segmentation/tools/AiAssistTool";
64
+ import { OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels } from "./Utils/orientation";
65
+ import type { NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation } from "./Utils/orientation";
63
66
  import "./css/style.css";
64
67
  export declare const REVISION: string;
65
- export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, };
66
- export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, };
68
+ export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, rasDimensions, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels, };
69
+ export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation, };
67
70
  export type { CameraViewPreset } from "./Controls/orbitFraming";
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ import { beginGesture, isGestureActive } from "./Controls/gestureGate";
34
34
  import { setCameraPose } from "./Controls/setCameraPose";
35
35
  import { addVolumeBoundingBox, VOLUME_BOUNDS_NAME, } from "./Loader/volumeBoundingBox";
36
36
  import { DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices } from "./Loader/copperNrrdLoader";
37
+ import { rasDimensions } from "./Loader/rasDimensions";
37
38
  import { easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, } from "./Controls/cameraTransitions";
38
39
  import { installFastSliceRepaint } from "./Loader/fastSliceRepaint";
39
40
  import { SurfaceAnnotator } from "./Utils/surfaceAnnotation";
@@ -41,6 +42,7 @@ import { CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_
41
42
  import { MAX_ENGINE_CHANNEL } from "./Utils/segmentation/core/index";
42
43
  import { REVISION as THREE_REVISION } from "three";
43
44
  import { checkThreeRevision } from "./Utils/threeRevisionCheck";
45
+ import { OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels, } from "./Utils/orientation";
44
46
  import "./css/style.css";
45
47
  // __REVISION__ is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
46
48
  // When copper3d is consumed from local source (no rollup replace step), the identifier is undefined and
@@ -69,5 +71,5 @@ if (typeof window !== "undefined") {
69
71
  if (typeof console !== "undefined") {
70
72
  console.log(`%cCopper3D Visualisation %c${REVISION}`, "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
71
73
  }
72
- export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, };
74
+ export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, rasDimensions, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels, };
73
75
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js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AY,EACZ,QAAQ,EACR,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,OAAO,EACP,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,eAAe,EACf,uBAAuB,GACxB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,eAAe,EAGf,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAY,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACvE,OA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b,cAAc,EACd,YAAY,EACZ,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,EACd,kBAAkB,EAClB,UAAU,GACX,CAAC"}
@@ -53,10 +53,10 @@ export declare function computeFraming(box: THREE.Box3, fovDeg: number): Framing
53
53
  * distance comes from C5 auto-framing (the implicit 600 in the JSON is ignored).
54
54
  *
55
55
  * up must be Gram-Schmidt-orthogonalised against the view direction (decision D1):
56
- * OrbitControls uses camera.up as its polar axis, and nrrd_view_coronal.json's up
57
- * (0,1,-1) is not perpendicular to its own view direction (0,1,0) — feeding it raw
58
- * gives a 45-degree-tilted pole. The old trackball path got away with it only because
59
- * three's lookAt() orthogonalises internally.
56
+ * OrbitControls uses camera.up as its polar axis, and a preset whose up is not
57
+ * perpendicular to its own view direction would otherwise get a tilted pole. The
58
+ * old trackball path got away with that only because three's lookAt() orthogonalises
59
+ * internally.
60
60
  */
61
61
  export declare function resolveViewPose(preset: CameraViewPreset, pivot: THREE.Vector3, dist: number): ViewPose;
62
62
  /**
@@ -4,6 +4,7 @@ import { copperScene } from "../Scene/copperScene";
4
4
  import { GUI } from "dat.gui";
5
5
  import { nrrdMeshesType, nrrdSliceType, loadingBarType } from "../types/types";
6
6
  import { Copper3dTrackballControls } from "../Controls/Copper3dTrackballControls";
7
+ import { type VolumeOrientation } from "../Utils/orientation";
7
8
  /**
8
9
  * Real worker in production; a test double can be substituted via
9
10
  * `__setNrrdWorkerFactoryForTests` (see that function's doc comment).
@@ -46,6 +47,8 @@ export interface NrrdVolume extends Omit<Volume, "matrix"> {
46
47
  max: number;
47
48
  windowLow: number;
48
49
  windowHigh: number;
50
+ /** How the file reached the canonical voxel order, and its canonical grid in patient space. */
51
+ orientation: VolumeOrientation;
49
52
  }
50
53
  /** A slice axis, in the sense `Volume.extractSlice` uses. */
51
54
  export type NrrdAxis = "x" | "y" | "z";
@@ -151,7 +154,18 @@ export declare function prepareVolumeSlices(...slices: any[]): void;
151
154
  * from -- there is no separate "the volume" reference kept around for this.
152
155
  */
153
156
  export declare function ensureAxisExtracted(slices: nrrdSliceType, axis: NrrdAxis, meshes?: nrrdMeshesType): any;
154
- export declare function copperNrrdLoader(url: string, loadingBar: loadingBarType, segmentation: boolean, callback?: (volume: any, nrrdMeshes: nrrdMeshesType, nrrdSlices: nrrdSliceType, gui?: GUI) => void, opts?: optsType): void;
157
+ /**
158
+ * Loads an NRRD in the canonical voxel order (i -> patient Left, j -> Posterior, k -> Superior),
159
+ * whatever order its file stores, so every view comes out in the radiological convention. A file
160
+ * whose patient orientation cannot be established fails through `opts.onError` with an
161
+ * `OrientationError` and is never displayed.
162
+ */
163
+ export declare function copperNrrdLoader(url: string, loadingBar: loadingBarType, callback?: (volume: any, nrrdMeshes: nrrdMeshesType, nrrdSlices: nrrdSliceType, gui?: GUI) => void, opts?: optsType): void;
164
+ /**
165
+ * @deprecated Shows the file in its stored voxel order, not the canonical LPS order every other
166
+ * loader uses, with window and threshold values fixed for one demo case. Use
167
+ * `copperNrrdLoader` instead. Will be removed in a future major release.
168
+ */
155
169
  export declare function copperNrrdTexture3dLoader(url: string, scene: THREE.Scene, container: HTMLDivElement, callback?: (volume: any, gui?: GUI) => void): void;
156
170
  export declare function getWholeSlices(nrrdSlices: nrrdSliceType, scene: THREE.Scene, gui: GUI, controls: Copper3dTrackballControls): void;
157
171
  /**
@@ -1,3 +1,4 @@
1
+ import { type OrientationTransform, type VolumeGeometry, type VolumeOrientation } from "../Utils/orientation";
1
2
  /** A message this module hands back to the caller, in the exact shape `postMessage` expects
2
3
  * (payload + a transfer list containing every `Transferable` inside it). */
3
4
  export type WorkerEmit = (message: NrrdWorkerMessage, transfer?: Transferable[]) => void;
@@ -5,7 +6,6 @@ export interface NrrdLoadCommand {
5
6
  cmd: "load";
6
7
  id: string;
7
8
  url: string;
8
- segmentation: boolean;
9
9
  knownMinMax?: [number, number];
10
10
  }
11
11
  export interface NrrdAbortCommand {
@@ -26,7 +26,7 @@ export interface NrrdWorkerPayload {
26
26
  spacing: [number, number, number];
27
27
  axisOrder: string[];
28
28
  RASDimensions: [number, number, number];
29
- segmentation: boolean;
29
+ orientation: VolumeOrientation;
30
30
  min: number;
31
31
  max: number;
32
32
  windowLow: number;
@@ -51,6 +51,8 @@ export type NrrdWorkerMessage = {
51
51
  type: "error";
52
52
  name: string;
53
53
  message: string;
54
+ code?: string;
55
+ detail?: string;
54
56
  };
55
57
  interface PendingUrlFetch {
56
58
  bufferPromise: Promise<ArrayBuffer>;
@@ -65,6 +67,17 @@ export interface NrrdWorkerState {
65
67
  callerToUrl: Map<string, string>;
66
68
  }
67
69
  export declare function createNrrdWorkerState(): NrrdWorkerState;
70
+ /**
71
+ * Puts a just-parsed volume into the canonical voxel order (i -> Left, j -> Posterior,
72
+ * k -> Superior) and rewrites every field derived from the order together, so nothing downstream
73
+ * ever sees the file's own order. With the voxels in this order, three's slice layout under
74
+ * `segmentation = true` plus the engine's fixed per-axis display mapping is the radiological view.
75
+ *
76
+ * `matrix` is written exactly diagonal: three turns a slice position back into an index through
77
+ * `inverseMatrix` and rounds it, and an oblique file's cross terms would drift that index. The
78
+ * true, oblique geometry is kept in `orientation` and `header` instead.
79
+ */
80
+ export declare function canonicaliseVolume(volume: any, native: VolumeGeometry, transform: OrientationTransform): void;
68
81
  /**
69
82
  * Handles one `{cmd: "load"}` command. Dedupes the underlying fetch by URL exactly like
70
83
  * `copperNrrdLoader.ts`'s old `sharedFetchNrrdArrayBuffer` did (one real request per URL,
@@ -0,0 +1,9 @@
1
+ /**
2
+ * three's `RASDimensions` for a grid: per axis, `(n − 1)·s + 1`.
3
+ *
4
+ * three places the plane for slice index `k·s` at `k·s − (RASDimensions − 1)/2`, and every
5
+ * texture spans `n·s` centred on 0, drawing voxel k's centre at `k·s − (n − 1)·s/2`. This value
6
+ * makes the two the same point. It also makes `RSAMaxIndex = RASDimensions − 1` exactly the last
7
+ * voxel's index `(n − 1)·s`, so a slider stepping `voxel × spacing` reaches it. Not an integer.
8
+ */
9
+ export declare function rasDimensions(dims: ArrayLike<number>, spacing: ArrayLike<number>): [number, number, number];
@@ -41,8 +41,17 @@ export declare class commonScene {
41
41
  */
42
42
  addSubView(): HTMLDivElement;
43
43
  loadDicom(urls: string | Array<string>, opts?: dicomLoaderOptsType): void;
44
- loadNrrd(url: string, loadingBar: loadingBarType, segmentation: boolean, callback?: (volume: any, nrrdMeshes: nrrdMeshesType, nrrdSlices: nrrdSliceType, gui?: GUI) => void, opts?: optsType): void;
44
+ /**
45
+ * Loads an NRRD in the canonical voxel order (i -> patient Left, j -> Posterior,
46
+ * k -> Superior), whatever order its file stores; see `copperNrrdLoader`.
47
+ */
48
+ loadNrrd(url: string, loadingBar: loadingBarType, callback?: (volume: any, nrrdMeshes: nrrdMeshesType, nrrdSlices: nrrdSliceType, gui?: GUI) => void, opts?: optsType): void;
45
49
  updateControls(camera: THREE.PerspectiveCamera | THREE.OrthographicCamera): void;
50
+ /**
51
+ * @deprecated Shows the file in its stored voxel order, not the canonical LPS order every
52
+ * other loader uses, with window and threshold values fixed for one demo case. Use
53
+ * `loadNrrd` (`copperNrrdLoader`) instead. Will be removed in a future major release.
54
+ */
46
55
  loadNrrdTexture3d(url: string, callback?: (volume: any, gui?: GUI) => void): void;
47
56
  loadOBJ(url: string, callback?: (mesh: THREE.Group) => void, opts?: {
48
57
  color: string;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The canonical voxel order, and the rule that puts any volume into it.
3
+ *
4
+ * Canonical order: voxel index i increases toward the patient's Left, j toward Posterior, k
5
+ * toward Superior. Axis codes use the TOWARD convention of DICOM, nibabel and SimpleITK, so "LPS"
6
+ * names that order (legacy ITK and ITK-SNAP call the same order "RAI").
7
+ *
8
+ * Each native axis is assigned the anatomical axis it is nearest to and flipped when it points the
9
+ * other way. That is a permutation and flips, never a resampling, so obliquity stays in the
10
+ * geometry instead of being snapped away. With the voxels in this order, the fixed per-axis display
11
+ * mapping (SliceRenderPipeline.flipDisplayImageByAxis) shows every volume in the radiological
12
+ * convention, whatever order its file stores.
13
+ *
14
+ * The backend (app/geometry/canonical.py) implements the same rule for everything it reads and
15
+ * writes. The app holds both to one fixture, annotator-backend/tests/fixtures/orientation_cases.json.
16
+ *
17
+ * Pure: no DOM and no three, so it runs inside the NRRD worker as well as on the main thread.
18
+ */
19
+ export type Vec3 = [number, number, number];
20
+ /** A voxel grid in patient space. */
21
+ export interface VolumeGeometry {
22
+ dims: Vec3;
23
+ /** `directions[a]` is one step along voxel axis a, in LPS millimetres. Its length is the spacing. */
24
+ directions: [Vec3, Vec3, Vec3];
25
+ /** The LPS position of the centre of voxel (0, 0, 0). */
26
+ origin: Vec3;
27
+ }
28
+ /** From the native voxel order to a target order. */
29
+ export interface OrientationTransform {
30
+ /** `perm[c]` is the native axis that becomes axis c. */
31
+ perm: Vec3;
32
+ /** `flip[c]`: index c runs opposite to that native axis (c = n - 1 - native). */
33
+ flip: [boolean, boolean, boolean];
34
+ /** The angle between axis c and its anatomical axis, in degrees. */
35
+ obliquityDeg: Vec3;
36
+ }
37
+ export type OrientationErrorCode = "no_space" | "time_space" | "scanner_space" | "non_anatomical_space" | "unknown_space" | "no_directions" | "not_3d" | "no_origin" | "degenerate" | "ambiguous_oblique";
38
+ /** A volume whose patient orientation cannot be established. It is refused, never guessed. */
39
+ export declare class OrientationError extends Error {
40
+ readonly code: OrientationErrorCode;
41
+ readonly detail: string;
42
+ constructor(code: OrientationErrorCode, detail: string);
43
+ }
44
+ /** How a loaded volume reached the canonical order, and where its canonical grid lies in patient space. */
45
+ export interface VolumeOrientation {
46
+ /** The transform the file's voxels went through. */
47
+ transform: OrientationTransform;
48
+ /** The file's own dims, before reordering. */
49
+ nativeDims: Vec3;
50
+ /** The canonical grid in LPS, obliquity included. Unlike `volume.matrix`, this is never snapped. */
51
+ geometry: VolumeGeometry;
52
+ }
53
+ /** The orientation fields of an NRRD header, as written in the file. */
54
+ export interface NrrdOrientationFields {
55
+ space: string | null;
56
+ sizes: number[];
57
+ /** One vector per axis; `null` where the file says `none` (a non-spatial axis). */
58
+ spaceDirections: (number[] | null)[] | null;
59
+ spaceOrigin: number[] | null;
60
+ }
61
+ export type ViewAxis = "x" | "y" | "z";
62
+ export interface ViewLabels {
63
+ left: string;
64
+ right: string;
65
+ top: string;
66
+ bottom: string;
67
+ }
68
+ /**
69
+ * The text header of an NRRD document: everything before the first blank line. Read here instead
70
+ * of taken from three's NRRDLoader, which fills in identity directions when a file has none and so
71
+ * makes "no orientation" indistinguishable from "identity".
72
+ */
73
+ export declare function nrrdHeaderText(buffer: ArrayBuffer): string;
74
+ /** Reads the orientation fields from an NRRD header's text. Comments and `key:=value` pairs are skipped. */
75
+ export declare function readNrrdOrientationFields(headerText: string): NrrdOrientationFields;
76
+ /** An NRRD's geometry in LPS. Throws OrientationError when its patient orientation cannot be established. */
77
+ export declare function geometryFromNrrd(fields: NrrdOrientationFields): VolumeGeometry;
78
+ /** The transform into the voxel order that `codes` names (TOWARD), e.g. "LPS" or "RAI". */
79
+ export declare function orientationTransform(geometry: VolumeGeometry, codes?: string): OrientationTransform;
80
+ /** The transform into the canonical order (i->L, j->P, k->S). */
81
+ export declare function canonicalTransform(geometry: VolumeGeometry): OrientationTransform;
82
+ export declare function isIdentityTransform(transform: OrientationTransform): boolean;
83
+ /** The same grid described in the transform's voxel order. The origin moves to the new first voxel. */
84
+ export declare function reorientedGeometry(geometry: VolumeGeometry, transform: OrientationTransform): VolumeGeometry;
85
+ type VoxelArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
86
+ /**
87
+ * Voxels (i fastest, as NRRD stores them) rewritten in the transform's order. The identity
88
+ * returns `data` itself, with no copy; any other transform returns a new array of the same type.
89
+ */
90
+ export declare function reorientVoxels<T extends VoxelArray>(data: T, dims: Vec3, transform: OrientationTransform): T;
91
+ /** The orientation letters at each screen edge of a view of a canonical grid. */
92
+ export declare function viewLabels(axis: ViewAxis, geometry: VolumeGeometry): ViewLabels;
93
+ export declare function spacingOf(geometry: VolumeGeometry): Vec3;
94
+ export {};
@@ -471,6 +471,10 @@ export declare class NrrdTools {
471
471
  */
472
472
  dispose(): void;
473
473
  configMouseSliceWheel(): (e: WheelEvent) => void;
474
+ /**
475
+ * Rebuilds the zoom/slice wheel handler for the current wheel setting. It attaches no listener:
476
+ * the EventRouter owns the canvas's `wheel` event and calls this handler in zoom mode only.
477
+ */
474
478
  updateMouseWheelEvent(): void;
475
479
  setIsDrawFalse(target: number): void;
476
480
  private setShowInMainArea;
@@ -112,11 +112,6 @@ export declare class RenderingUtils {
112
112
  * Invalidate the reusable buffer (e.g. when switching datasets).
113
113
  */
114
114
  invalidateSliceBuffer(): void;
115
- /**
116
- * Apply the same flip transform used by flipDisplayImageByAxis() to any
117
- * canvas context.
118
- */
119
- applyMaskFlipForAxis(ctx: CanvasRenderingContext2D, width: number, height: number, axis: "x" | "y" | "z"): void;
120
115
  /**
121
116
  * Composite all layer canvases to the master display canvas.
122
117
  * Only draws layers whose visibility is enabled.
@@ -14,6 +14,11 @@ export interface LabelSlice {
14
14
  * stay visible against bright tissue.
15
15
  */
16
16
  export declare const OUTLINE_WIDTH_PX = 1.5;
17
+ /**
18
+ * Whether a view's slice rows run up the screen. Coronal and sagittal slices store z
19
+ * ascending in their rows and show superior at the top, so their rows are drawn bottom-up.
20
+ */
21
+ export declare function rowsRunUp(axis: "x" | "y" | "z"): boolean;
17
22
  /**
18
23
  * One slice's contours, in voxel coordinates. Fill and outline paths are built lazily and side
19
24
  * by side, so switching mode costs one extraction the first time and is a cache hit after.
@@ -165,7 +165,7 @@ export declare class MaskVolume {
165
165
  * |------|----------|--------|--------|
166
166
  * | `z` | Axial | width | height |
167
167
  * | `y` | Coronal | width | depth |
168
- * | `x` | Sagittal | depth | height |
168
+ * | `x` | Sagittal | height | depth |
169
169
  *
170
170
  * @param sliceIndex Index along the specified axis.
171
171
  * @param axis `'x'` (sagittal), `'y'` (coronal), or `'z'` (axial).
@@ -27,11 +27,9 @@ export declare class ImageStoreHelper extends BaseTool {
27
27
  /**
28
28
  * Vertically flip an ImageData buffer in-place (swap rows top↔bottom).
29
29
  *
30
- * Used to compensate for the Z-axis direction reversal between sagittal
31
- * and coronal views. On coronal, Z runs along the canvas j-axis (vertical),
32
- * and the display flip (scale(1,-1)) reverses Z relative to sagittal's
33
- * horizontal Z mapping. This row-swap aligns the Z ordering so that
34
- * MaskVolume stores data in a consistent coordinate system.
30
+ * Coronal and sagittal show superior at the top, while their slices store z ascending in
31
+ * their rows. The bake canvas is a picture of the display, so its rows are reversed before
32
+ * they are written into the MaskVolume.
35
33
  */
36
34
  private flipImageDataVertically;
37
35
  /**
@@ -1,6 +1,18 @@
1
1
  import { BaseTool } from "./BaseTool";
2
2
  import type { ToolContext } from "./BaseTool";
3
3
  import type { SliceRenderHostDeps } from "./ToolHost";
4
+ /**
5
+ * The size three's slice canvas is shown at. The sagittal view turns that canvas a quarter turn
6
+ * (see `flipDisplayImageByAxis`), so its width and height trade places; every other canvas, mask
7
+ * slices included, is laid out at this size.
8
+ */
9
+ export declare function displaySizeOf(axis: "x" | "y" | "z", canvas: {
10
+ width: number;
11
+ height: number;
12
+ }): {
13
+ width: number;
14
+ height: number;
15
+ };
4
16
  /**
5
17
  * Manages slice rendering pipeline: slice setup, canvas rendering, and view helpers.
6
18
  *
@@ -10,6 +22,8 @@ import type { SliceRenderHostDeps } from "./ToolHost";
10
22
  export declare class SliceRenderPipeline extends BaseTool {
11
23
  private callbacks;
12
24
  private initState;
25
+ /** The view the layer canvases were last drawn for; a different view must redraw them. */
26
+ private layerCanvasAxis?;
13
27
  constructor(ctx: ToolContext, callbacks: SliceRenderHostDeps);
14
28
  /**
15
29
  * Reset initState to true (called from NrrdTools.reset() when switching datasets).
@@ -43,10 +57,20 @@ export declare class SliceRenderPipeline extends BaseTool {
43
57
  redrawDisplayCanvas(): void;
44
58
  redrawMianPreOnDisplayCanvas(): void;
45
59
  /**
46
- * flip the canvas to a correct position.
47
- * This is because the slice canvas from threejs is not in a correct 2D postion.
48
- * Thus, everytime when we redraw the display canvas, we need to flip to draw the origin canvas from threejs.
49
- * Under different axis(sagittal, Axial, Coronal), the flip orientation is different.
60
+ * Maps three's slice canvas onto the display canvas. Callers then draw that canvas into
61
+ * (0, 0, changedWidth, changedHeight).
62
+ *
63
+ * The loader puts every volume in the canonical voxel order (i -> patient Left, j -> Posterior,
64
+ * k -> Superior), and three lays a slice out by voxel index with fixed row reversals. This fixed
65
+ * per-axis transform undoes those reversals, which makes each view the radiological one:
66
+ * - axial (z): screen-right = +i (patient Left), screen-down = +j (Posterior);
67
+ * - coronal (y): screen-right = +i, screen-down = -k (Superior at the top);
68
+ * - sagittal (x): screen-right = +j (Anterior on the left), screen-down = -k.
69
+ * Three's sagittal canvas runs columns along -k and rows along -j, so sagittal is a quarter
70
+ * turn as well as a scale: the drawn rectangle is the display size (`displaySizeOf`), whose
71
+ * width and height are three's height and width.
72
+ * `Utils/orientation.ts` (VIEW_LAYOUT) states the same layout for the orientation letters, so the
73
+ * two change together.
50
74
  */
51
75
  flipDisplayImageByAxis(): void;
52
76
  /**
@@ -45,6 +45,7 @@ import type { PosableScene } from "./Controls/setCameraPose";
45
45
  import { addVolumeBoundingBox, VOLUME_BOUNDS_NAME } from "./Loader/volumeBoundingBox";
46
46
  import type { BoundingBoxHost, VolumeBoundingBoxOpts } from "./Loader/volumeBoundingBox";
47
47
  import { DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices } from "./Loader/copperNrrdLoader";
48
+ import { rasDimensions } from "./Loader/rasDimensions";
48
49
  import type { NrrdAxis } from "./Loader/copperNrrdLoader";
49
50
  import { easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle } from "./Controls/cameraTransitions";
50
51
  import type { Pose } from "./Controls/cameraTransitions";
@@ -60,8 +61,10 @@ import { CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_
60
61
  import type { LayerId, ChannelValue } from "./Utils/segmentation/core/index";
61
62
  import { MAX_ENGINE_CHANNEL } from "./Utils/segmentation/core/index";
62
63
  import type { AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult } from "./Utils/segmentation/tools/AiAssistTool";
64
+ import { OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels } from "./Utils/orientation";
65
+ import type { NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation } from "./Utils/orientation";
63
66
  import "./css/style.css";
64
67
  export declare const REVISION: string;
65
- export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, };
66
- export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, };
68
+ export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, registerNiftiMaskGrid, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, MAX_ENGINE_CHANNEL, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, exposureExponent, DEFAULT_TARGET_GREY, disposeObject3D, disposeMaterial, collectFadeTargets, setFade, restoreFade, createSceneBudget, defaultBudgetBytes, disposeScene, removeSceneFromMap, fitDistance, fitView, isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled, beginGesture, isGestureActive, setCameraPose, addVolumeBoundingBox, VOLUME_BOUNDS_NAME, rasDimensions, DEFAULT_AXES, ensureAxisExtracted, prepareVolumeSlices, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, OrientationError, canonicalTransform, geometryFromNrrd, readNrrdOrientationFields, reorientVoxels, reorientedGeometry, viewLabels, };
69
+ export type { positionType, screenPosType, optsType, NrrdHeaderLike, GltfLoadOpts, nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, IPaintImage, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController, ICommXYZ, IGUIStates, IGuiParameterSettings, INrrdStates, NrrdState, GuiState, IGuiMeta, ToolMode, IAnnotationCallbacks, MaskRenderMode, LayerId, ChannelValue, AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult, SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions, ExposureVolume, DisposableObject3D, DisposableMaterial, FadeTarget, FadeableMaterial, SceneBudget, DisposableScene, SceneDisposalHost, FitBounds, FitViewScene, AxisGatedControls, GestureAxes, PosableScene, BoundingBoxHost, VolumeBoundingBoxOpts, NrrdAxis, Pose, NrrdOrientationFields, OrientationErrorCode, OrientationTransform, ViewAxis, ViewLabels, VolumeGeometry, VolumeOrientation, };
67
70
  export type { CameraViewPreset } from "./Controls/orbitFraming";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "copper3d",
3
3
  "description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
4
- "version": "4.0.0",
4
+ "version": "4.1.0",
5
5
  "main": "dist/bundle.umd.js",
6
6
  "module": "dist/bundle.esm.mjs",
7
7
  "types": "dist/types/index.d.ts",