copper3d 3.7.5 → 3.9.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/dist/Controls/Copper3dTrackballControls.d.ts +25 -1
- package/dist/Controls/Copper3dTrackballControls.js +20 -0
- package/dist/Controls/Copper3dTrackballControls.js.map +1 -1
- package/dist/Controls/cameraTransitions.d.ts +87 -0
- package/dist/Controls/cameraTransitions.js +285 -0
- package/dist/Controls/cameraTransitions.js.map +1 -0
- package/dist/Controls/controlsAxes.d.ts +31 -0
- package/dist/Controls/controlsAxes.js +63 -0
- package/dist/Controls/controlsAxes.js.map +1 -0
- package/dist/Controls/fitView.d.ts +45 -0
- package/dist/Controls/fitView.js +40 -0
- package/dist/Controls/fitView.js.map +1 -0
- package/dist/Controls/gestureGate.d.ts +48 -0
- package/dist/Controls/gestureGate.js +67 -0
- package/dist/Controls/gestureGate.js.map +1 -0
- package/dist/Controls/orbitFraming.d.ts +39 -0
- package/dist/Controls/orbitFraming.js +39 -0
- package/dist/Controls/orbitFraming.js.map +1 -1
- package/dist/Controls/setCameraPose.d.ts +50 -0
- package/dist/Controls/setCameraPose.js +20 -0
- package/dist/Controls/setCameraPose.js.map +1 -0
- package/dist/Loader/copperGltfLoader.d.ts +35 -0
- package/dist/Loader/copperGltfLoader.js +43 -2
- package/dist/Loader/copperGltfLoader.js.map +1 -1
- package/dist/Loader/copperNrrdLoader.d.ts +47 -0
- package/dist/Loader/copperNrrdLoader.js +88 -42
- package/dist/Loader/copperNrrdLoader.js.map +1 -1
- package/dist/Loader/fastSliceRepaint.d.ts +56 -0
- package/dist/Loader/fastSliceRepaint.js +159 -0
- package/dist/Loader/fastSliceRepaint.js.map +1 -0
- package/dist/Loader/volumeBoundingBox.d.ts +44 -0
- package/dist/Loader/volumeBoundingBox.js +32 -0
- package/dist/Loader/volumeBoundingBox.js.map +1 -0
- package/dist/Renderer/copperRendererOnDemond.d.ts +21 -3
- package/dist/Renderer/copperRendererOnDemond.js +26 -2
- package/dist/Renderer/copperRendererOnDemond.js.map +1 -1
- package/dist/Renderer/disposeScene.d.ts +51 -0
- package/dist/Renderer/disposeScene.js +51 -0
- package/dist/Renderer/disposeScene.js.map +1 -0
- package/dist/Renderer/sceneBudget.d.ts +40 -0
- package/dist/Renderer/sceneBudget.js +86 -0
- package/dist/Renderer/sceneBudget.js.map +1 -0
- package/dist/Scene/copperMScene.d.ts +2 -1
- package/dist/Scene/copperMScene.js +4 -4
- package/dist/Scene/copperMScene.js.map +1 -1
- package/dist/Scene/copperScene.d.ts +2 -1
- package/dist/Scene/copperScene.js +6 -4
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/Scene/copperSceneOnDemond.d.ts +66 -3
- package/dist/Scene/copperSceneOnDemond.js +103 -7
- package/dist/Scene/copperSceneOnDemond.js.map +1 -1
- package/dist/Utils/dispose.d.ts +48 -0
- package/dist/Utils/dispose.js +60 -0
- package/dist/Utils/dispose.js.map +1 -0
- package/dist/Utils/kiwrious/configKiwrious.d.ts +23 -1
- package/dist/Utils/kiwrious/configKiwrious.js +154 -42
- package/dist/Utils/kiwrious/configKiwrious.js.map +1 -1
- package/dist/Utils/modelCrossfade.d.ts +36 -0
- package/dist/Utils/modelCrossfade.js +46 -0
- package/dist/Utils/modelCrossfade.js.map +1 -0
- package/dist/Utils/volumeExposure.d.ts +32 -0
- package/dist/Utils/volumeExposure.js +104 -0
- package/dist/Utils/volumeExposure.js.map +1 -0
- package/dist/bundle.esm.js +63653 -51923
- package/dist/bundle.umd.js +63701 -51933
- package/dist/index.d.ts +32 -3
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/dist/types/Controls/Copper3dTrackballControls.d.ts +25 -1
- package/dist/types/Controls/cameraTransitions.d.ts +87 -0
- package/dist/types/Controls/controlsAxes.d.ts +31 -0
- package/dist/types/Controls/fitView.d.ts +45 -0
- package/dist/types/Controls/gestureGate.d.ts +48 -0
- package/dist/types/Controls/orbitFraming.d.ts +39 -0
- package/dist/types/Controls/setCameraPose.d.ts +50 -0
- package/dist/types/Loader/copperGltfLoader.d.ts +35 -0
- package/dist/types/Loader/copperNrrdLoader.d.ts +47 -0
- package/dist/types/Loader/fastSliceRepaint.d.ts +56 -0
- package/dist/types/Loader/volumeBoundingBox.d.ts +44 -0
- package/dist/types/Renderer/copperRendererOnDemond.d.ts +21 -3
- package/dist/types/Renderer/disposeScene.d.ts +51 -0
- package/dist/types/Renderer/sceneBudget.d.ts +40 -0
- package/dist/types/Scene/copperMScene.d.ts +2 -1
- package/dist/types/Scene/copperScene.d.ts +2 -1
- package/dist/types/Scene/copperSceneOnDemond.d.ts +66 -3
- package/dist/types/Utils/dispose.d.ts +48 -0
- package/dist/types/Utils/kiwrious/configKiwrious.d.ts +23 -1
- package/dist/types/Utils/modelCrossfade.d.ts +36 -0
- package/dist/types/Utils/volumeExposure.d.ts +32 -0
- package/dist/types/index.d.ts +32 -3
- package/package.json +7 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
/**
|
|
3
|
+
* The wireframe box around an NRRD volume.
|
|
4
|
+
*
|
|
5
|
+
* It is the only thing that gives a lone slice plane spatial context -- without
|
|
6
|
+
* it the plane floats in an unbounded void and nothing tells the reader how far
|
|
7
|
+
* through the volume they have scrubbed.
|
|
8
|
+
*
|
|
9
|
+
* Replaces `addBoxHelper`, which cannot be used for this:
|
|
10
|
+
*
|
|
11
|
+
* - It is typed to take a `copperScene`, so `copperSceneOnDemond` -- a sibling
|
|
12
|
+
* subclass, not a descendant -- does not type-check even though it has the
|
|
13
|
+
* `addObject` this needs.
|
|
14
|
+
* - Without its optional third argument it wraps a module-level `cube` that
|
|
15
|
+
* `copperNrrdLoader` never assigns, i.e. `new THREE.BoxHelper(undefined)`.
|
|
16
|
+
* - It sizes the box from `volume.matrix` rather than the volume's RAS
|
|
17
|
+
* dimensions, which is not the box a reader expects around the data.
|
|
18
|
+
*
|
|
19
|
+
* `addBoxHelper` is kept as-is and deprecated rather than fixed, because a
|
|
20
|
+
* caller passing their own `boxCube` gets working behaviour from it today.
|
|
21
|
+
*/
|
|
22
|
+
/** The parts of a scene this needs -- structural, so both `copperScene` and
|
|
23
|
+
* `copperSceneOnDemond` satisfy it, as does a plain test double. */
|
|
24
|
+
export interface BoundingBoxHost {
|
|
25
|
+
addObject: (object: THREE.Object3D) => void;
|
|
26
|
+
}
|
|
27
|
+
export interface VolumeBoundingBoxOpts {
|
|
28
|
+
/** Defaults to white, which is what reads against a dark viewer. Pass a
|
|
29
|
+
* darker tone for a light background, where white lines vanish. */
|
|
30
|
+
color?: THREE.ColorRepresentation;
|
|
31
|
+
/** `object.name`, so a later children sweep can find and dispose it like
|
|
32
|
+
* anything else in the scene. */
|
|
33
|
+
name?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare const VOLUME_BOUNDS_NAME = "volume-bounds";
|
|
36
|
+
/**
|
|
37
|
+
* Adds the box and returns it, so the caller can hide, move or dispose it.
|
|
38
|
+
* Returns `undefined` for a degenerate volume -- a zero extent on any axis
|
|
39
|
+
* would produce a flat or empty helper rather than a box.
|
|
40
|
+
*
|
|
41
|
+
* @param rasDimensions the volume's `RASDimensions`, i.e. its extent in world
|
|
42
|
+
* units along x, y and z
|
|
43
|
+
*/
|
|
44
|
+
export declare function addVolumeBoundingBox(scene: BoundingBoxHost, rasDimensions: ArrayLike<number>, opts?: VolumeBoundingBoxOpts): THREE.BoxHelper | undefined;
|
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import { baseRenderer } from "./baseRenderer";
|
|
2
|
-
import { ICopperRenderOpt } from "../types/types";
|
|
2
|
+
import { ICopperRenderOpt, ICopperSceneOpts, SceneMapType } from "../types/types";
|
|
3
3
|
import { copperSceneOnDemond } from "../Scene/copperSceneOnDemond";
|
|
4
4
|
export declare class copperRendererOnDemond extends baseRenderer {
|
|
5
|
-
|
|
5
|
+
/** Public so `disposeScene` can unregister an entry. Nothing else removes
|
|
6
|
+
* one, so a long-lived renderer otherwise accumulates every scene it has
|
|
7
|
+
* ever built, decoded volumes included. */
|
|
8
|
+
sceneMap: SceneMapType;
|
|
6
9
|
constructor(container: HTMLDivElement, options?: ICopperRenderOpt);
|
|
7
10
|
getSceneByName(name: string): import("..").copperScene | import("../Scene/baseScene").baseScene | import("..").copperMScene;
|
|
11
|
+
/**
|
|
12
|
+
* Unregisters a scene and frees its geometries, materials and textures.
|
|
13
|
+
* Returns the scene that was disposed, or undefined if there was none.
|
|
14
|
+
*/
|
|
15
|
+
disposeScene(name: string): import("./disposeScene").DisposableScene | undefined;
|
|
8
16
|
setCurrentScene(sceneIn: copperSceneOnDemond): void;
|
|
9
|
-
|
|
17
|
+
/**
|
|
18
|
+
* `opt` is per-scene and new in 3.9.0 -- `{ controls: "copper3d" }` builds
|
|
19
|
+
* the scene with `Copper3dTrackballControls` instead of the default
|
|
20
|
+
* `OrbitControls`. Omit it for exactly the previous behaviour.
|
|
21
|
+
*
|
|
22
|
+
* Deliberately a parameter rather than a read of this renderer's own
|
|
23
|
+
* `options.controls`: that option has never had any effect on on-demand
|
|
24
|
+
* scenes, so honouring it now would swap the controls under anyone who set
|
|
25
|
+
* it and never noticed.
|
|
26
|
+
*/
|
|
27
|
+
createScene(name: string, opt?: ICopperSceneOpts): copperSceneOnDemond | undefined;
|
|
10
28
|
animate: () => void;
|
|
11
29
|
render(): void;
|
|
12
30
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { DisposableObject3D } from '../Utils/dispose';
|
|
2
|
+
/**
|
|
3
|
+
* Removes a scene from a renderer's map and frees what it holds.
|
|
4
|
+
*
|
|
5
|
+
* There is otherwise no way out of `sceneMap` at all: nothing in copper3d
|
|
6
|
+
* removes an entry, so a long-lived renderer accumulates every scene it has
|
|
7
|
+
* ever built, decoded volumes included.
|
|
8
|
+
*
|
|
9
|
+
* Written as a free function so it can be called on a renderer instance the
|
|
10
|
+
* caller already has, and unit-tested against a plain object. The renderer
|
|
11
|
+
* class wraps it as a one-line method.
|
|
12
|
+
*/
|
|
13
|
+
/** The parts of a scene this needs. Structural, so a test does not have to
|
|
14
|
+
* build a real one. */
|
|
15
|
+
export interface DisposableScene {
|
|
16
|
+
scene: {
|
|
17
|
+
children: DisposableObject3D[];
|
|
18
|
+
remove: (object: any) => void;
|
|
19
|
+
};
|
|
20
|
+
controls: {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Narrowed to the one event this removes, so it accepts both a
|
|
23
|
+
* `string`-typed emitter and one already narrowed to its own events. */
|
|
24
|
+
removeEventListener?: (type: 'change', listener: () => void) => void;
|
|
25
|
+
};
|
|
26
|
+
requestRenderIfNotRequested: () => void;
|
|
27
|
+
/** `copperSceneOnDemond.dispose()`, which releases the `window` resize
|
|
28
|
+
* listener the scene registered on itself. Optional: scene classes that
|
|
29
|
+
* attach nothing outside themselves do not have one. */
|
|
30
|
+
dispose?: () => void;
|
|
31
|
+
}
|
|
32
|
+
export interface SceneDisposalHost<S extends DisposableScene = DisposableScene> {
|
|
33
|
+
sceneMap: Record<string, S>;
|
|
34
|
+
getSceneByName: (name: string) => S | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Unregisters a scene WITHOUT freeing anything, for callers re-registering it
|
|
38
|
+
* under a different name.
|
|
39
|
+
*
|
|
40
|
+
* Throws if the entry survives removal. `delete` on a missing property is a
|
|
41
|
+
* silent no-op, so restructuring `sceneMap` into a real `Map` would stop
|
|
42
|
+
* eviction working with no crash and no type error -- the map would grow
|
|
43
|
+
* without bound again, invisibly. Confirming through the host's own accessor
|
|
44
|
+
* fails loudly instead.
|
|
45
|
+
*/
|
|
46
|
+
export declare function removeSceneFromMap(host: SceneDisposalHost<any>, name: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Unregisters a scene and frees everything in it. Returns the scene that was
|
|
49
|
+
* disposed, or `undefined` if there was none under that name.
|
|
50
|
+
*/
|
|
51
|
+
export declare function disposeScene<S extends DisposableScene>(host: SceneDisposalHost<S>, name: string): S | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much decoded scene data may stay resident, as a byte budget with LRU
|
|
3
|
+
* eviction and pinning.
|
|
4
|
+
*
|
|
5
|
+
* Bytes rather than a scene count, because a count is not the thing at risk:
|
|
6
|
+
* an NRRD volume can be 51KB or 53MB on disk and decodes to a typed array
|
|
7
|
+
* larger still, so "three scenes" is anywhere from 150KB to 250MB.
|
|
8
|
+
*
|
|
9
|
+
* Whatever is on screen should be pinned and is never a victim, however far
|
|
10
|
+
* over the limit that puts the total. Blanking a view the reader is looking
|
|
11
|
+
* at is strictly worse than the memory it saves -- and with several viewports
|
|
12
|
+
* sharing one renderer, more than one scene is visible at a time.
|
|
13
|
+
*/
|
|
14
|
+
export interface SceneBudget {
|
|
15
|
+
/** Records (or re-records) a resident scene's decoded size and marks it
|
|
16
|
+
* most-recently-used. */
|
|
17
|
+
register: (key: string, bytes: number) => void;
|
|
18
|
+
/** Marks an already-registered scene most-recently-used. No-op if absent. */
|
|
19
|
+
touch: (key: string) => void;
|
|
20
|
+
/** Protects a scene from eviction while it is on screen. */
|
|
21
|
+
pin: (key: string) => void;
|
|
22
|
+
unpin: (key: string) => void;
|
|
23
|
+
/** Forgets a scene entirely. Call after its GPU resources are freed. */
|
|
24
|
+
release: (key: string) => void;
|
|
25
|
+
/** Carries bytes, queue position and pin state to a new key, for callers
|
|
26
|
+
* that rename a scene in place. */
|
|
27
|
+
rename: (from: string, to: string) => void;
|
|
28
|
+
/** Keys to evict, least-recently-used first, never pinned. Empty when the
|
|
29
|
+
* total is within budget or nothing evictable is left. */
|
|
30
|
+
overflow: () => string[];
|
|
31
|
+
bytes: () => number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `deviceMemory` is a Chromium-only hint in GiB, absent in Safari and every
|
|
35
|
+
* iOS browser. Absent must mean the SMALL budget: an iPad is both the device
|
|
36
|
+
* that omits the API and the one most likely to have its tab killed for using
|
|
37
|
+
* too much.
|
|
38
|
+
*/
|
|
39
|
+
export declare function defaultBudgetBytes(deviceMemoryGiB?: number): number;
|
|
40
|
+
export declare function createSceneBudget(limitBytes: number): SceneBudget;
|
|
@@ -2,6 +2,7 @@ import * as THREE from "three";
|
|
|
2
2
|
import { GUI } from "dat.gui";
|
|
3
3
|
import { Controls, CameraViewPoint } from "../Controls/copperControls";
|
|
4
4
|
import { customMeshType } from "../lib/three-vignette";
|
|
5
|
+
import type { GltfLoadOpts } from "../Loader/copperGltfLoader";
|
|
5
6
|
import { positionType, nrrdSliceType } from "../types/types";
|
|
6
7
|
import { commonScene } from "./commonSceneMethod";
|
|
7
8
|
export declare class copperMScene extends commonScene {
|
|
@@ -24,7 +25,7 @@ export declare class copperMScene extends commonScene {
|
|
|
24
25
|
constructor(container: HTMLDivElement, renderer: THREE.WebGLRenderer);
|
|
25
26
|
init(): void;
|
|
26
27
|
setControls(type: number): void;
|
|
27
|
-
loadGltf(url: string, callback?: (content: THREE.Group) => void): void;
|
|
28
|
+
loadGltf(url: string, callback?: (content: THREE.Group) => void, opts?: GltfLoadOpts): void;
|
|
28
29
|
setViewPoint(camera: THREE.PerspectiveCamera, target?: number[]): CameraViewPoint;
|
|
29
30
|
loadOBJ(url: string, callback?: (mesh: THREE.Group) => void): void;
|
|
30
31
|
drawWholeNrrd(nrrdSlices: nrrdSliceType): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import { Copper3dTrackballControls } from "../Controls/Copper3dTrackballControls";
|
|
3
3
|
import { CameraViewPoint } from "../Controls/copperControls";
|
|
4
|
+
import type { GltfLoadOpts } from "../Loader/copperGltfLoader";
|
|
4
5
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
|
5
6
|
import { baseScene } from "./baseScene";
|
|
6
7
|
import { vtkModels } from "../types/types";
|
|
@@ -17,7 +18,7 @@ export declare class copperScene extends baseScene {
|
|
|
17
18
|
private clipAction;
|
|
18
19
|
private surfaceAnnotators;
|
|
19
20
|
constructor(container: HTMLDivElement, renderer: THREE.WebGLRenderer, opt?: ICopperSceneOpts);
|
|
20
|
-
loadGltf(url: string, callback?: (content: THREE.Group) => void): void;
|
|
21
|
+
loadGltf(url: string, callback?: (content: THREE.Group) => void, opts?: GltfLoadOpts): void;
|
|
21
22
|
loadPureGLB(url: string, callback?: (mesh: THREE.Group) => void, opts?: {
|
|
22
23
|
color: string;
|
|
23
24
|
enhanceMaterial?: boolean;
|
|
@@ -1,13 +1,76 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import { baseScene } from "./baseScene";
|
|
3
|
+
import type { GltfLoadOpts } from "../Loader/copperGltfLoader";
|
|
3
4
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
|
5
|
+
import { TrackballControls } from "three/examples/jsm/controls/TrackballControls";
|
|
6
|
+
import { Copper3dTrackballControls } from "../Controls/Copper3dTrackballControls";
|
|
7
|
+
import { CameraViewPoint } from "../Controls/copperControls";
|
|
8
|
+
import type { FitBounds } from "../Controls/orbitFraming";
|
|
9
|
+
import type { Pose } from "../Controls/cameraTransitions";
|
|
10
|
+
import { ICopperSceneOpts } from "../types/types";
|
|
4
11
|
export declare class copperSceneOnDemond extends baseScene {
|
|
5
|
-
controls: OrbitControls;
|
|
12
|
+
controls: OrbitControls | Copper3dTrackballControls | TrackballControls;
|
|
6
13
|
renderRequested: boolean | undefined;
|
|
7
14
|
isResize: boolean;
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* `opt.controls` picks the controls class, as it already did on
|
|
17
|
+
* `copperScene`. New in 3.9.0 -- this class hardcoded `OrbitControls`
|
|
18
|
+
* before, so passing the option produced no error and no effect.
|
|
19
|
+
*
|
|
20
|
+
* The DEFAULT stays `OrbitControls`, which is what this class has always
|
|
21
|
+
* built. It differs from `copperScene`'s default (`Copper3dTrackballControls`)
|
|
22
|
+
* on purpose: changing it would silently swap the controls under every
|
|
23
|
+
* existing on-demand viewer.
|
|
24
|
+
*
|
|
25
|
+
* Note that the renderer's own `options.controls` is deliberately NOT
|
|
26
|
+
* consulted. It has never had any effect here, so honouring it now would
|
|
27
|
+
* change behaviour for anyone who set it and never noticed.
|
|
28
|
+
*/
|
|
29
|
+
constructor(container: HTMLDivElement, renderer: THREE.WebGLRenderer, opt?: ICopperSceneOpts);
|
|
30
|
+
loadGltf(url: string, callback?: (content: THREE.Group) => void, opts?: GltfLoadOpts): void;
|
|
31
|
+
/**
|
|
32
|
+
* Re-frames the camera on `bounds`, keeping the preset's view direction and
|
|
33
|
+
* up and replacing only its distance. Returns false when there is nothing
|
|
34
|
+
* to do -- an orthographic camera (no field of view to fit against), or a
|
|
35
|
+
* preset whose eye sits exactly on its target.
|
|
36
|
+
*
|
|
37
|
+
* Does not render: the caller decides when to draw, which matters here
|
|
38
|
+
* because this scene renders on demand.
|
|
39
|
+
*/
|
|
40
|
+
fitView(preset: CameraViewPoint, aspect: number, bounds: FitBounds, margin?: number): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Moves the camera to `pose` and syncs the controls' orbit pivot with it.
|
|
43
|
+
* Without that last part the next drag silently undoes the move -- see
|
|
44
|
+
* `Controls/setCameraPose.ts`.
|
|
45
|
+
*
|
|
46
|
+
* Does not render; the caller decides when to draw.
|
|
47
|
+
*/
|
|
48
|
+
setCameraPose(pose: Pose): void;
|
|
10
49
|
confirmResize: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Releases what this scene attached OUTSIDE itself.
|
|
52
|
+
*
|
|
53
|
+
* The `resize` listener the constructor puts on `window` used to have no
|
|
54
|
+
* counterpart: every scene ever created stayed subscribed for the life of
|
|
55
|
+
* the page, kept alive by the closure, and went on calling
|
|
56
|
+
* `requestRenderIfNotRequested` -- and so `onWindowResize`, which resizes
|
|
57
|
+
* the SHARED renderer -- long after it stopped being displayed. An app that
|
|
58
|
+
* creates a scene per case leaks one of those per case.
|
|
59
|
+
*
|
|
60
|
+
* Does not touch the scene graph or the renderer: what a scene's contents
|
|
61
|
+
* are worth keeping is the caller's decision, and the renderer is shared
|
|
62
|
+
* with every other scene. `disposeScene(renderer, name)` is the one that
|
|
63
|
+
* tears the contents down.
|
|
64
|
+
*
|
|
65
|
+
* Deliberately NOT `controls.dispose()`. That path ends in
|
|
66
|
+
* `domElement.style.touchAction = ""`, and every scene here shares one
|
|
67
|
+
* canvas -- only `connect()` sets it back to `"none"`. Disposing one
|
|
68
|
+
* scene's controls would kill touch rotation on the canvas for the rest of
|
|
69
|
+
* the session. Disabling them is enough.
|
|
70
|
+
*
|
|
71
|
+
* Safe to call twice.
|
|
72
|
+
*/
|
|
73
|
+
dispose(): void;
|
|
11
74
|
render: () => void;
|
|
12
75
|
requestRenderIfNotRequested: () => void;
|
|
13
76
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frees the GPU resources behind an object that is no longer displayed.
|
|
3
|
+
*
|
|
4
|
+
* `scene.remove()` only unlinks: three keeps the geometry's buffers and the
|
|
5
|
+
* material's textures uploaded until they are disposed explicitly. Nothing in
|
|
6
|
+
* copper3d disposes what it creates, so anything that swaps models or evicts
|
|
7
|
+
* scenes needs this or its footprint is unbounded.
|
|
8
|
+
*
|
|
9
|
+
* Typed structurally rather than against `THREE.Object3D` so it also accepts
|
|
10
|
+
* the minimal shapes callers and tests hand around; a real three object
|
|
11
|
+
* satisfies these interfaces.
|
|
12
|
+
*/
|
|
13
|
+
interface Disposable {
|
|
14
|
+
dispose: () => void;
|
|
15
|
+
}
|
|
16
|
+
/** A material and the texture slots three's built-in materials use. All
|
|
17
|
+
* optional: any given material has only some of them. */
|
|
18
|
+
export interface DisposableMaterial extends Disposable {
|
|
19
|
+
map?: Disposable | null;
|
|
20
|
+
normalMap?: Disposable | null;
|
|
21
|
+
roughnessMap?: Disposable | null;
|
|
22
|
+
metalnessMap?: Disposable | null;
|
|
23
|
+
aoMap?: Disposable | null;
|
|
24
|
+
emissiveMap?: Disposable | null;
|
|
25
|
+
alphaMap?: Disposable | null;
|
|
26
|
+
bumpMap?: Disposable | null;
|
|
27
|
+
displacementMap?: Disposable | null;
|
|
28
|
+
envMap?: Disposable | null;
|
|
29
|
+
lightMap?: Disposable | null;
|
|
30
|
+
specularMap?: Disposable | null;
|
|
31
|
+
}
|
|
32
|
+
export interface DisposableObject3D {
|
|
33
|
+
traverse: (callback: (child: any) => void) => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `Material.dispose()` does NOT cascade into its textures, so a canvas-backed
|
|
37
|
+
* or image-backed map stays on the GPU without this. Handles the array form
|
|
38
|
+
* too: a multi-material mesh would otherwise reach `Array.prototype.dispose`,
|
|
39
|
+
* which does not exist.
|
|
40
|
+
*/
|
|
41
|
+
export declare function disposeMaterial(material: DisposableMaterial | DisposableMaterial[] | null | undefined): void;
|
|
42
|
+
/**
|
|
43
|
+
* Works on a lone mesh as well as on a whole subtree -- `traverse` visits the
|
|
44
|
+
* root itself -- so a slice plane that was never added to a scene is freed by
|
|
45
|
+
* the same call.
|
|
46
|
+
*/
|
|
47
|
+
export declare function disposeObject3D(root: DisposableObject3D): void;
|
|
48
|
+
export {};
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import { kiwriousType } from "../../types/types";
|
|
2
|
+
/**
|
|
3
|
+
* Imports the sensor plugin once and caches it. Concurrent callers share the
|
|
4
|
+
* import. Everything on the `kiwrious` facade below funnels through here, so
|
|
5
|
+
* callers only need this directly when they want to await the load.
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadKiwrious(): Promise<kiwriousType>;
|
|
8
|
+
/**
|
|
9
|
+
* The plugin's public surface, unchanged for callers: `kiwrious.setBinUrl()`,
|
|
10
|
+
* `kiwrious.setWasm()` and `kiwrious.serialService.*` all still work without
|
|
11
|
+
* awaiting anything. The first call that genuinely needs the module
|
|
12
|
+
* (`connectAndReadAsync`) is what triggers the import.
|
|
13
|
+
*
|
|
14
|
+
* Cast because `SerialService_kiwrious` is declared with private fields, so
|
|
15
|
+
* nothing structural can satisfy it -- the facade forwards every public
|
|
16
|
+
* member.
|
|
17
|
+
*/
|
|
2
18
|
declare const kiwrious: kiwriousType;
|
|
3
19
|
export default kiwrious;
|
|
4
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Now async: it awaits the plugin before wiring the buttons, so a click that
|
|
22
|
+
* lands immediately after cannot race the import. Callers that ignored the
|
|
23
|
+
* return value before still work -- the buttons are simply live one
|
|
24
|
+
* microtask-chain later.
|
|
25
|
+
*/
|
|
26
|
+
export declare function configKiwriousHeart(connectBtn: HTMLButtonElement, disconnectBtn: HTMLButtonElement, binUrl: string, wasmUrl: string, connectionCallback: (isConnected: boolean) => void, heartDataCallback: (heartData: any, status: string, hrVal: number) => void): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DisposableObject3D } from './dispose';
|
|
2
|
+
/**
|
|
3
|
+
* Crossfading one model into another in the same scene.
|
|
4
|
+
*
|
|
5
|
+
* Split into capture / apply / restore so the caller owns the timing: the
|
|
6
|
+
* fade is driven frame by frame from whatever animation loop it already has,
|
|
7
|
+
* rather than this starting a second one.
|
|
8
|
+
*/
|
|
9
|
+
export interface FadeableMaterial {
|
|
10
|
+
opacity: number;
|
|
11
|
+
transparent: boolean;
|
|
12
|
+
depthWrite: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** One mesh material enrolled in a crossfade, together with the appearance it
|
|
15
|
+
* had before the fade started. */
|
|
16
|
+
export interface FadeTarget {
|
|
17
|
+
material: FadeableMaterial;
|
|
18
|
+
opacity: number;
|
|
19
|
+
transparent: boolean;
|
|
20
|
+
depthWrite: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function collectFadeTargets(root: DisposableObject3D): FadeTarget[];
|
|
23
|
+
/**
|
|
24
|
+
* Scales each material toward transparent by `factor`, RELATIVE to the
|
|
25
|
+
* opacity it already had. Scaling rather than assigning is what keeps an
|
|
26
|
+
* already-translucent material translucent: `opacity = factor` would end
|
|
27
|
+
* every crossfade with it fully opaque.
|
|
28
|
+
*
|
|
29
|
+
* `depthWrite` is suppressed for the whole fade and only restored at the
|
|
30
|
+
* fully-opaque end. A partially transparent mesh that still writes depth
|
|
31
|
+
* occludes everything drawn behind it, so a fade with depth writing left on
|
|
32
|
+
* shows the outgoing model punching holes in the incoming one.
|
|
33
|
+
*/
|
|
34
|
+
export declare function setFade(targets: FadeTarget[], factor: number): void;
|
|
35
|
+
/** Puts each material back exactly as `collectFadeTargets` found it. */
|
|
36
|
+
export declare function restoreFade(targets: FadeTarget[]): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much to lift a volume's mid-tones so its tissue is actually readable.
|
|
3
|
+
*
|
|
4
|
+
* A slice is painted with `(raw - windowLow) * 255 / (windowHigh - windowLow)`
|
|
5
|
+
* and the NRRD loader sets that window to the volume's own min/max. When the
|
|
6
|
+
* max is a handful of bright outliers -- normal on a contrast-enhanced MRI --
|
|
7
|
+
* the tissue ends up in the bottom of the range and the image reads as dark.
|
|
8
|
+
*
|
|
9
|
+
* The answer here is a gamma curve, `out = 255 * (in / 255) ** exponent`,
|
|
10
|
+
* applied on top of that window rather than replacing it. Narrowing the window
|
|
11
|
+
* instead cannot work: any linear window bright enough to lift the tissue
|
|
12
|
+
* saturates the top of the range, and on a contrast-enhanced study the lesion
|
|
13
|
+
* IS the top of the range. Gamma is monotonic and fixes both ends, so nothing
|
|
14
|
+
* clips however far the middle is raised.
|
|
15
|
+
*/
|
|
16
|
+
/** The parts of a loaded volume this reads. Structural rather than the
|
|
17
|
+
* loader's own type, so it is testable without building one. */
|
|
18
|
+
export interface ExposureVolume {
|
|
19
|
+
data: ArrayLike<number>;
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}
|
|
23
|
+
/** Where the median tissue voxel should land on the 0-255 greyscale. */
|
|
24
|
+
export declare const DEFAULT_TARGET_GREY = 75;
|
|
25
|
+
/**
|
|
26
|
+
* The gamma exponent that puts `volume`'s median tissue voxel on
|
|
27
|
+
* `targetGrey`, or 1 when it needs no lift or cannot be measured.
|
|
28
|
+
*
|
|
29
|
+
* Solving per volume is what makes volumes with wildly different maxima come
|
|
30
|
+
* out looking alike.
|
|
31
|
+
*/
|
|
32
|
+
export declare function exposureExponent(volume: ExposureVolume, targetGrey?: number): number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,13 +4,15 @@ import { copperScene } from "./Scene/copperScene";
|
|
|
4
4
|
import { CameraViewPoint } from "./Controls/copperControls";
|
|
5
5
|
import { addLabelToScene, positionType, screenPosType, convert3DPostoScreenPos, convertScreenPosto3DPos } from "./Utils/add3DLabel";
|
|
6
6
|
import { addBoxHelper, optsType } from "./Loader/copperNrrdLoader";
|
|
7
|
+
import { copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath } from "./Loader/copperGltfLoader";
|
|
8
|
+
import type { GltfLoadOpts } from "./Loader/copperGltfLoader";
|
|
7
9
|
import { fullScreenListenner, loading, throttle } from "./Utils/utils";
|
|
8
10
|
import { copperRendererOnDemond } from "./Renderer/copperRendererOnDemond";
|
|
9
11
|
import { copperSceneOnDemond } from "./Scene/copperSceneOnDemond";
|
|
10
12
|
import { copperMSceneRenderer } from "./Renderer/copperMSceneRenderer";
|
|
11
13
|
import { copperMScene } from "./Scene/copperMScene";
|
|
12
14
|
import { createTexture2D_NRRD } from "./Utils/texture2d";
|
|
13
|
-
import { configKiwriousHeart } from "./Utils/kiwrious/configKiwrious";
|
|
15
|
+
import { configKiwriousHeart, loadKiwrious } from "./Utils/kiwrious/configKiwrious";
|
|
14
16
|
import kiwrious from "./Utils/kiwrious/configKiwrious";
|
|
15
17
|
import { NrrdTools } from "./Utils/segmentation/NrrdTools";
|
|
16
18
|
import { GaussianSmoother } from "./Utils/segmentation/core/GaussianSmoother";
|
|
@@ -18,6 +20,33 @@ import { Copper3dTrackballControls } from "./Controls/Copper3dTrackballControls"
|
|
|
18
20
|
import { Copper3dOrbitControls } from "./Controls/Copper3dOrbitControls";
|
|
19
21
|
import { MeshNodeTool } from "./Utils/MeshNodeTool";
|
|
20
22
|
import { removeGuiFolderChilden } from "./Utils/segmentation/coreTools/gui";
|
|
23
|
+
import { exposureExponent, DEFAULT_TARGET_GREY } from "./Utils/volumeExposure";
|
|
24
|
+
import type { ExposureVolume } from "./Utils/volumeExposure";
|
|
25
|
+
import { disposeObject3D, disposeMaterial } from "./Utils/dispose";
|
|
26
|
+
import type { DisposableObject3D, DisposableMaterial } from "./Utils/dispose";
|
|
27
|
+
import { collectFadeTargets, setFade, restoreFade } from "./Utils/modelCrossfade";
|
|
28
|
+
import type { FadeTarget, FadeableMaterial } from "./Utils/modelCrossfade";
|
|
29
|
+
import { createSceneBudget, defaultBudgetBytes } from "./Renderer/sceneBudget";
|
|
30
|
+
import type { SceneBudget } from "./Renderer/sceneBudget";
|
|
31
|
+
import { disposeScene, removeSceneFromMap } from "./Renderer/disposeScene";
|
|
32
|
+
import type { DisposableScene, SceneDisposalHost } from "./Renderer/disposeScene";
|
|
33
|
+
import { fitDistance } from "./Controls/orbitFraming";
|
|
34
|
+
import type { FitBounds } from "./Controls/orbitFraming";
|
|
35
|
+
import { fitView } from "./Controls/fitView";
|
|
36
|
+
import type { FitViewScene } from "./Controls/fitView";
|
|
37
|
+
import { isRotateEnabled, setRotateEnabled, isPanEnabled, setPanEnabled, isZoomEnabled, setZoomEnabled } from "./Controls/controlsAxes";
|
|
38
|
+
import type { AxisGatedControls } from "./Controls/controlsAxes";
|
|
39
|
+
import { beginGesture, isGestureActive } from "./Controls/gestureGate";
|
|
40
|
+
import type { GestureAxes } from "./Controls/gestureGate";
|
|
41
|
+
import { setCameraPose } from "./Controls/setCameraPose";
|
|
42
|
+
import type { PosableScene } from "./Controls/setCameraPose";
|
|
43
|
+
import { addVolumeBoundingBox, VOLUME_BOUNDS_NAME } from "./Loader/volumeBoundingBox";
|
|
44
|
+
import type { BoundingBoxHost, VolumeBoundingBoxOpts } from "./Loader/volumeBoundingBox";
|
|
45
|
+
import { DEFAULT_AXES } from "./Loader/copperNrrdLoader";
|
|
46
|
+
import type { NrrdAxis } from "./Loader/copperNrrdLoader";
|
|
47
|
+
import { easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle } from "./Controls/cameraTransitions";
|
|
48
|
+
import type { Pose } from "./Controls/cameraTransitions";
|
|
49
|
+
import { installFastSliceRepaint } from "./Loader/fastSliceRepaint";
|
|
21
50
|
import { SurfaceAnnotator } from "./Utils/surfaceAnnotation";
|
|
22
51
|
import type { SurfaceAnnotatorOptions, Annotation, AnnotationMode, ExportOptions } from "./Utils/surfaceAnnotation";
|
|
23
52
|
import { nrrdMeshesType, nrrdSliceType, SensorDecodedValue_kiwrious, SensorReadResult_kiwrious, HeartRateResult_kiwrious, loadingBarType, exportPaintImageType, IOptVTKLoader, aligned4DSurfaceType, aligned4DOptsType, Aligned4DController, raw4DVolumeTransformType, raw4DVolumeOptsType, Raw4DVolumeController } from "./types/types";
|
|
@@ -30,6 +59,6 @@ import type { LayerId, ChannelValue } from "./Utils/segmentation/core/index";
|
|
|
30
59
|
import type { AiPromptTool, AiPromptPoint, AiPromptPayload, AiMaskResult } from "./Utils/segmentation/tools/AiAssistTool";
|
|
31
60
|
import "./css/style.css";
|
|
32
61
|
export declare const REVISION: string;
|
|
33
|
-
export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, NrrdTools, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, CHANNEL_COLORS, CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, AI_CHANNEL_HEX_COLORS, rgbaToHex, rgbaToCss, GaussianSmoother, SurfaceAnnotator, };
|
|
34
|
-
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, };
|
|
62
|
+
export { copperRenderer, copperRendererOnDemond, copperMSceneRenderer, setHDRFilePath, addLabelToScene, convert3DPostoScreenPos, convertScreenPosto3DPos, addBoxHelper, fullScreenListenner, configKiwriousHeart, copperScene, copperSceneOnDemond, copperMScene, CameraViewPoint, kiwrious, loadKiwrious, NrrdTools, loading, Copper3dTrackballControls, Copper3dOrbitControls, createTexture2D_NRRD, MeshNodeTool, throttle, removeGuiFolderChilden, 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, copperGltfLoader, setDracoDecoderPath, setKTX2TranscoderPath, easeInOutCubic, viewPointToPose, rotateAroundAxis, interpolateFlightPose, poseDistance, orbitStepPose, zoomPose, orbitSwingAngle, installFastSliceRepaint, };
|
|
63
|
+
export type { positionType, screenPosType, optsType, 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, 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, };
|
|
35
64
|
export type { CameraViewPreset } from "./Controls/orbitFraming";
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
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.
|
|
4
|
+
"version": "3.9.0",
|
|
5
5
|
"main": "dist/bundle.umd.js",
|
|
6
6
|
"moudle": "dist/bundle.esm.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc && rollup -c rollup.config.js",
|
|
10
10
|
"build:t": "rollup -c rollup.config.js",
|
|
11
|
-
"test": "
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"test:watch": "vitest",
|
|
13
|
+
"bench": "vitest bench"
|
|
12
14
|
},
|
|
13
15
|
"files": [
|
|
14
16
|
"dist"
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"@rollup/plugin-replace": "^4.0.0",
|
|
36
38
|
"@rollup/plugin-typescript": "^8.3.2",
|
|
37
39
|
"@types/file-saver": "^2.0.5",
|
|
40
|
+
"jsdom": "^29.1.1",
|
|
38
41
|
"postcss": "^8.4.14",
|
|
39
42
|
"rollup": "^2.74.1",
|
|
40
43
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
@@ -44,7 +47,8 @@
|
|
|
44
47
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
45
48
|
"rollup-plugin-terser": "^7.0.2",
|
|
46
49
|
"rollup-plugin-typescript2": "^0.31.2",
|
|
47
|
-
"typescript": "^5.9.3"
|
|
50
|
+
"typescript": "^5.9.3",
|
|
51
|
+
"vitest": "^4.1.10"
|
|
48
52
|
},
|
|
49
53
|
"dependencies": {
|
|
50
54
|
"@types/dat.gui": "^0.7.9",
|