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
|
@@ -2,9 +2,27 @@ import * as THREE from "three";
|
|
|
2
2
|
import { baseScene } from "./baseScene";
|
|
3
3
|
import { copperGltfLoader } from "../Loader/copperGltfLoader";
|
|
4
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 { fitView as fitViewOn } from "../Controls/fitView";
|
|
8
|
+
import { setCameraPose as setCameraPoseOn } from "../Controls/setCameraPose";
|
|
5
9
|
export class copperSceneOnDemond extends baseScene {
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
/**
|
|
11
|
+
* `opt.controls` picks the controls class, as it already did on
|
|
12
|
+
* `copperScene`. New in 3.9.0 -- this class hardcoded `OrbitControls`
|
|
13
|
+
* before, so passing the option produced no error and no effect.
|
|
14
|
+
*
|
|
15
|
+
* The DEFAULT stays `OrbitControls`, which is what this class has always
|
|
16
|
+
* built. It differs from `copperScene`'s default (`Copper3dTrackballControls`)
|
|
17
|
+
* on purpose: changing it would silently swap the controls under every
|
|
18
|
+
* existing on-demand viewer.
|
|
19
|
+
*
|
|
20
|
+
* Note that the renderer's own `options.controls` is deliberately NOT
|
|
21
|
+
* consulted. It has never had any effect here, so honouring it now would
|
|
22
|
+
* change behaviour for anyone who set it and never noticed.
|
|
23
|
+
*/
|
|
24
|
+
constructor(container, renderer, opt) {
|
|
25
|
+
super(container, renderer, opt);
|
|
8
26
|
this.renderRequested = false;
|
|
9
27
|
this.isResize = false;
|
|
10
28
|
this.confirmResize = () => {
|
|
@@ -26,12 +44,30 @@ export class copperSceneOnDemond extends baseScene {
|
|
|
26
44
|
requestAnimationFrame(this.render);
|
|
27
45
|
}
|
|
28
46
|
};
|
|
29
|
-
|
|
47
|
+
if ((opt === null || opt === void 0 ? void 0 : opt.controls) === "copper3d") {
|
|
48
|
+
const trackball = new Copper3dTrackballControls(this.camera, renderer.domElement);
|
|
49
|
+
// Without this the viewer is dead to the mouse: the trackball
|
|
50
|
+
// dispatches `change` only from inside `update()`, and `update()` only
|
|
51
|
+
// runs inside `render()` -- which nothing schedules until a `change`
|
|
52
|
+
// arrives. See `Copper3dTrackballControls.updateOnInput`.
|
|
53
|
+
trackball.updateOnInput = true;
|
|
54
|
+
this.controls = trackball;
|
|
55
|
+
}
|
|
56
|
+
else if ((opt === null || opt === void 0 ? void 0 : opt.controls) === "trackball") {
|
|
57
|
+
// three's own TrackballControls has the same "change only from
|
|
58
|
+
// update()" shape and no equivalent flag, so this combination needs the
|
|
59
|
+
// caller to pump a frame from its own input listeners. Prefer
|
|
60
|
+
// "copper3d" under on-demand rendering.
|
|
61
|
+
this.controls = new TrackballControls(this.camera, renderer.domElement);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.controls = new OrbitControls(this.camera, renderer.domElement);
|
|
65
|
+
}
|
|
30
66
|
this.controls.addEventListener("change", this.requestRenderIfNotRequested);
|
|
31
67
|
window.addEventListener("resize", this.confirmResize, false);
|
|
32
68
|
requestAnimationFrame(this.render);
|
|
33
69
|
}
|
|
34
|
-
loadGltf(url, callback) {
|
|
70
|
+
loadGltf(url, callback, opts) {
|
|
35
71
|
const loader = copperGltfLoader(this.renderer);
|
|
36
72
|
loader.load(url, (gltf) => {
|
|
37
73
|
const box = new THREE.Box3().setFromObject(gltf.scene);
|
|
@@ -52,9 +88,69 @@ export class copperSceneOnDemond extends baseScene {
|
|
|
52
88
|
this.content = gltf.scene;
|
|
53
89
|
this.scene.add(gltf.scene);
|
|
54
90
|
callback && callback(gltf.scene);
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
|
|
91
|
+
},
|
|
92
|
+
// Slots three and four, in that order. Before 3.9.0 an empty function
|
|
93
|
+
// named `error` sat in the onProgress slot and there was no fourth
|
|
94
|
+
// argument at all, so a failed load invoked nothing.
|
|
95
|
+
opts === null || opts === void 0 ? void 0 : opts.onProgress, opts === null || opts === void 0 ? void 0 : opts.onError);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Re-frames the camera on `bounds`, keeping the preset's view direction and
|
|
99
|
+
* up and replacing only its distance. Returns false when there is nothing
|
|
100
|
+
* to do -- an orthographic camera (no field of view to fit against), or a
|
|
101
|
+
* preset whose eye sits exactly on its target.
|
|
102
|
+
*
|
|
103
|
+
* Does not render: the caller decides when to draw, which matters here
|
|
104
|
+
* because this scene renders on demand.
|
|
105
|
+
*/
|
|
106
|
+
fitView(preset, aspect, bounds, margin) {
|
|
107
|
+
if (!this.camera.isPerspectiveCamera) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
// `controls` is a union of three classes; only some declare
|
|
111
|
+
// `handleResize`, and `fitView` already treats it as optional.
|
|
112
|
+
return fitViewOn(this, preset, aspect, bounds, margin);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Moves the camera to `pose` and syncs the controls' orbit pivot with it.
|
|
116
|
+
* Without that last part the next drag silently undoes the move -- see
|
|
117
|
+
* `Controls/setCameraPose.ts`.
|
|
118
|
+
*
|
|
119
|
+
* Does not render; the caller decides when to draw.
|
|
120
|
+
*/
|
|
121
|
+
setCameraPose(pose) {
|
|
122
|
+
setCameraPoseOn(this, pose);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Releases what this scene attached OUTSIDE itself.
|
|
126
|
+
*
|
|
127
|
+
* The `resize` listener the constructor puts on `window` used to have no
|
|
128
|
+
* counterpart: every scene ever created stayed subscribed for the life of
|
|
129
|
+
* the page, kept alive by the closure, and went on calling
|
|
130
|
+
* `requestRenderIfNotRequested` -- and so `onWindowResize`, which resizes
|
|
131
|
+
* the SHARED renderer -- long after it stopped being displayed. An app that
|
|
132
|
+
* creates a scene per case leaks one of those per case.
|
|
133
|
+
*
|
|
134
|
+
* Does not touch the scene graph or the renderer: what a scene's contents
|
|
135
|
+
* are worth keeping is the caller's decision, and the renderer is shared
|
|
136
|
+
* with every other scene. `disposeScene(renderer, name)` is the one that
|
|
137
|
+
* tears the contents down.
|
|
138
|
+
*
|
|
139
|
+
* Deliberately NOT `controls.dispose()`. That path ends in
|
|
140
|
+
* `domElement.style.touchAction = ""`, and every scene here shares one
|
|
141
|
+
* canvas -- only `connect()` sets it back to `"none"`. Disposing one
|
|
142
|
+
* scene's controls would kill touch rotation on the canvas for the rest of
|
|
143
|
+
* the session. Disabling them is enough.
|
|
144
|
+
*
|
|
145
|
+
* Safe to call twice.
|
|
146
|
+
*/
|
|
147
|
+
dispose() {
|
|
148
|
+
window.removeEventListener("resize", this.confirmResize);
|
|
149
|
+
this.controls.enabled = false;
|
|
150
|
+
this.controls.removeEventListener("change", this.requestRenderIfNotRequested);
|
|
151
|
+
// Nothing in flight can arrive after this: `render` clears the flag, and
|
|
152
|
+
// an already-scheduled frame only draws.
|
|
153
|
+
this.renderRequested = false;
|
|
58
154
|
}
|
|
59
155
|
}
|
|
60
156
|
//# sourceMappingURL=copperSceneOnDemond.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copperSceneOnDemond.js","sourceRoot":"","sources":["../../src/Scene/copperSceneOnDemond.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"copperSceneOnDemond.js","sourceRoot":"","sources":["../../src/Scene/copperSceneOnDemond.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAK7E,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAKhD;;;;;;;;;;;;;OAaG;IACH,YACE,SAAyB,EACzB,QAA6B,EAC7B,GAAsB;QAEtB,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QAtBlC,oBAAe,GAAwB,KAAK,CAAC;QAC7C,aAAQ,GAAY,KAAK,CAAC;QAoI1B,kBAAa,GAAG,GAAG,EAAE;YACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACrC,CAAC,CAAC;QAqCF,WAAM,GAAG,GAAG,EAAE;YACZ,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;YAEjC,I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ACP,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,aAAa,CAAC,IAAU;QACtB,eAAe,CAAC,IAA+B,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAOD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO;QACL,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAC/B,QAAQ,EACR,IAAI,CAAC,2BAA2B,CACjC,CAAC;QACF,yEAAyE;QACzE,yCAAyC;QACzC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;IAC/B,CAAC;CAmBF"}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
const TEXTURE_SLOTS = [
|
|
14
|
+
'map',
|
|
15
|
+
'normalMap',
|
|
16
|
+
'roughnessMap',
|
|
17
|
+
'metalnessMap',
|
|
18
|
+
'aoMap',
|
|
19
|
+
'emissiveMap',
|
|
20
|
+
'alphaMap',
|
|
21
|
+
'bumpMap',
|
|
22
|
+
'displacementMap',
|
|
23
|
+
'envMap',
|
|
24
|
+
'lightMap',
|
|
25
|
+
'specularMap',
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* `Material.dispose()` does NOT cascade into its textures, so a canvas-backed
|
|
29
|
+
* or image-backed map stays on the GPU without this. Handles the array form
|
|
30
|
+
* too: a multi-material mesh would otherwise reach `Array.prototype.dispose`,
|
|
31
|
+
* which does not exist.
|
|
32
|
+
*/
|
|
33
|
+
export function disposeMaterial(material) {
|
|
34
|
+
var _a;
|
|
35
|
+
if (!material)
|
|
36
|
+
return;
|
|
37
|
+
if (Array.isArray(material)) {
|
|
38
|
+
for (const one of material)
|
|
39
|
+
disposeMaterial(one);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (const slot of TEXTURE_SLOTS)
|
|
43
|
+
(_a = material[slot]) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
44
|
+
material.dispose();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Works on a lone mesh as well as on a whole subtree -- `traverse` visits the
|
|
48
|
+
* root itself -- so a slice plane that was never added to a scene is freed by
|
|
49
|
+
* the same call.
|
|
50
|
+
*/
|
|
51
|
+
export function disposeObject3D(root) {
|
|
52
|
+
root.traverse((child) => {
|
|
53
|
+
var _a;
|
|
54
|
+
if (!(child === null || child === void 0 ? void 0 : child.isMesh))
|
|
55
|
+
return;
|
|
56
|
+
(_a = child.geometry) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
57
|
+
disposeMaterial(child.material);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=dispose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispose.js","sourceRoot":"","sources":["../../src/Utils/dispose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA2BH,MAAM,aAAa,GAAG;IACpB,KAAK;IACL,WAAW;IACX,cAAc;IACd,cAAc;IACd,OAAO;IACP,aAAa;IACb,UAAU;IACV,SAAS;IACT,iBAAiB;IACjB,QAAQ;IACR,UAAU;IACV,aAAa;CACL,CAAA;AAEV;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAsE;;IAEtE,IAAI,CAAC,QAAQ;QAAE,OAAM;IACrB,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,QAAQ;YAAE,eAAe,CAAC,GAAG,CAAC,CAAA;QAChD,OAAM;IACR,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,aAAa;QAAE,MAAA,QAAQ,CAAC,IAAI,CAAC,0CAAE,OAAO,EAAE,CAAA;IAC3D,QAAQ,CAAC,OAAO,EAAE,CAAA;AACpB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAwB;IACtD,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;;QACtB,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,CAAA;YAAE,OAAM;QAC1B,MAAA,KAAK,CAAC,QAAQ,0CAAE,OAAO,EAAE,CAAA;QACzB,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -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>;
|
|
@@ -7,53 +7,165 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
let loaded;
|
|
11
|
+
let loading;
|
|
12
|
+
/** URLs and callbacks set before the module arrived, replayed once it does. */
|
|
13
|
+
const pending = {};
|
|
14
|
+
/**
|
|
15
|
+
* Imports the sensor plugin once and caches it. Concurrent callers share the
|
|
16
|
+
* import. Everything on the `kiwrious` facade below funnels through here, so
|
|
17
|
+
* callers only need this directly when they want to await the load.
|
|
18
|
+
*/
|
|
19
|
+
export function loadKiwrious() {
|
|
20
|
+
loading !== null && loading !== void 0 ? loading : (loading = (() => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
// The nested webpack runtime reads `document.currentScript` the moment
|
|
23
|
+
// the module evaluates; stand one in for the duration of the import so it
|
|
24
|
+
// takes a same-origin base URL instead of throwing, then restore the
|
|
25
|
+
// native getter. `tagName` matters as well as `src` -- one of the two
|
|
26
|
+
// readers checks it before taking `.src`.
|
|
27
|
+
const shimmed = typeof document !== "undefined" && document.currentScript === null;
|
|
28
|
+
if (shimmed) {
|
|
29
|
+
Object.defineProperty(document, "currentScript", {
|
|
30
|
+
configurable: true,
|
|
31
|
+
value: {
|
|
32
|
+
tagName: "SCRIPT",
|
|
33
|
+
src: new URL("./", document.baseURI).href,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const mod = yield import("copper3d_plugin_heart_k");
|
|
39
|
+
const exports = (_a = mod.default) !== null && _a !== void 0 ? _a : mod;
|
|
40
|
+
loaded = exports;
|
|
41
|
+
// Replay whatever was configured while the import was in flight.
|
|
42
|
+
if (pending.binUrl !== undefined)
|
|
43
|
+
exports.setBinUrl(pending.binUrl);
|
|
44
|
+
if (pending.wasmUrl !== undefined)
|
|
45
|
+
exports.setWasm(pending.wasmUrl);
|
|
46
|
+
if (pending.onSerialData)
|
|
47
|
+
exports.serialService.onSerialData = pending.onSerialData;
|
|
48
|
+
if (pending.onSerialConnection)
|
|
49
|
+
exports.serialService.onSerialConnection = pending.onSerialConnection;
|
|
50
|
+
return exports;
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
if (shimmed)
|
|
54
|
+
delete document.currentScript;
|
|
55
|
+
}
|
|
56
|
+
}))());
|
|
57
|
+
return loading;
|
|
18
58
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Stands in for the plugin's `serialService` before it has loaded, so the
|
|
61
|
+
* call shape callers already use keeps working unchanged: assign the two
|
|
62
|
+
* callbacks, then call `connectAndReadAsync()`.
|
|
63
|
+
*/
|
|
64
|
+
const serialServiceFacade = {
|
|
65
|
+
get onSerialData() {
|
|
66
|
+
return loaded ? loaded.serialService.onSerialData : pending.onSerialData;
|
|
67
|
+
},
|
|
68
|
+
set onSerialData(fn) {
|
|
69
|
+
pending.onSerialData = fn;
|
|
70
|
+
if (loaded)
|
|
71
|
+
loaded.serialService.onSerialData = fn;
|
|
72
|
+
},
|
|
73
|
+
get onSerialConnection() {
|
|
74
|
+
return loaded
|
|
75
|
+
? loaded.serialService.onSerialConnection
|
|
76
|
+
: pending.onSerialConnection;
|
|
77
|
+
},
|
|
78
|
+
set onSerialConnection(fn) {
|
|
79
|
+
pending.onSerialConnection = fn;
|
|
80
|
+
if (loaded)
|
|
81
|
+
loaded.serialService.onSerialConnection = fn;
|
|
82
|
+
},
|
|
83
|
+
// Nothing can be reading before the module exists, so `false` is the honest
|
|
84
|
+
// answer rather than a placeholder.
|
|
85
|
+
get isReading() {
|
|
86
|
+
return loaded ? loaded.serialService.isReading : false;
|
|
87
|
+
},
|
|
88
|
+
get canResumeReading() {
|
|
89
|
+
return loaded ? loaded.serialService.canResumeReading : false;
|
|
90
|
+
},
|
|
91
|
+
connectAndReadAsync() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const k = yield loadKiwrious();
|
|
94
|
+
return k.serialService.connectAndReadAsync();
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
disconnectAsync() {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
// Not `loadKiwrious()`: disconnecting something that was never connected
|
|
100
|
+
// must not be what pulls a 2MB bundle over the wire.
|
|
101
|
+
if (!loaded)
|
|
102
|
+
return;
|
|
103
|
+
return loaded.serialService.disconnectAsync();
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
resumeReading() {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
if (!loaded)
|
|
109
|
+
return;
|
|
110
|
+
return loaded.serialService.resumeReading();
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
triggerStopReading() {
|
|
114
|
+
loaded === null || loaded === void 0 ? void 0 : loaded.serialService.triggerStopReading();
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* The plugin's public surface, unchanged for callers: `kiwrious.setBinUrl()`,
|
|
119
|
+
* `kiwrious.setWasm()` and `kiwrious.serialService.*` all still work without
|
|
120
|
+
* awaiting anything. The first call that genuinely needs the module
|
|
121
|
+
* (`connectAndReadAsync`) is what triggers the import.
|
|
122
|
+
*
|
|
123
|
+
* Cast because `SerialService_kiwrious` is declared with private fields, so
|
|
124
|
+
* nothing structural can satisfy it -- the facade forwards every public
|
|
125
|
+
* member.
|
|
126
|
+
*/
|
|
27
127
|
const kiwrious = {
|
|
28
|
-
serialService,
|
|
29
|
-
setBinUrl
|
|
30
|
-
|
|
128
|
+
serialService: serialServiceFacade,
|
|
129
|
+
setBinUrl: (url) => {
|
|
130
|
+
pending.binUrl = url;
|
|
131
|
+
loaded === null || loaded === void 0 ? void 0 : loaded.setBinUrl(url);
|
|
132
|
+
},
|
|
133
|
+
setWasm: (url) => {
|
|
134
|
+
pending.wasmUrl = url;
|
|
135
|
+
loaded === null || loaded === void 0 ? void 0 : loaded.setWasm(url);
|
|
136
|
+
},
|
|
31
137
|
};
|
|
32
138
|
export default kiwrious;
|
|
139
|
+
/**
|
|
140
|
+
* Now async: it awaits the plugin before wiring the buttons, so a click that
|
|
141
|
+
* lands immediately after cannot race the import. Callers that ignored the
|
|
142
|
+
* return value before still work -- the buttons are simply live one
|
|
143
|
+
* microtask-chain later.
|
|
144
|
+
*/
|
|
33
145
|
export function configKiwriousHeart(connectBtn, disconnectBtn, binUrl, wasmUrl, connectionCallback, heartDataCallback) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
connectBtn.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
disconnectBtn.
|
|
45
|
-
|
|
46
|
-
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
// config kiwrious
|
|
148
|
+
kiwrious.setBinUrl(binUrl);
|
|
149
|
+
kiwrious.setWasm(wasmUrl);
|
|
150
|
+
yield loadKiwrious();
|
|
151
|
+
connectBtn.onclick = () => __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
connectBtn.disabled = true;
|
|
153
|
+
yield kiwrious.serialService.connectAndReadAsync();
|
|
154
|
+
connectBtn.disabled = false;
|
|
155
|
+
});
|
|
156
|
+
disconnectBtn.onclick = () => __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
disconnectBtn.disabled = true;
|
|
158
|
+
yield kiwrious.serialService.disconnectAsync();
|
|
159
|
+
disconnectBtn.disabled = false;
|
|
160
|
+
});
|
|
161
|
+
kiwrious.serialService.onSerialConnection = (isConnected) => {
|
|
162
|
+
connectionCallback(isConnected);
|
|
163
|
+
};
|
|
164
|
+
kiwrious.serialService.onSerialData = (decodedData) => {
|
|
165
|
+
const values = decodedData.decodedValues;
|
|
166
|
+
const val = values[0].value;
|
|
167
|
+
heartDataCallback(val, val.status, val.heartrate);
|
|
168
|
+
};
|
|
47
169
|
});
|
|
48
|
-
kiwrious.serialService.onSerialConnection = (isConnected) => {
|
|
49
|
-
connectionCallback(isConnected);
|
|
50
|
-
};
|
|
51
|
-
kiwrious.serialService.onSerialData = (decodedData) => {
|
|
52
|
-
const values = decodedData.decodedValues;
|
|
53
|
-
const val = values[0].value;
|
|
54
|
-
heartDataCallback(val, val.status, val.heartrate);
|
|
55
|
-
// const status = val.status;
|
|
56
|
-
// const hrVal = val.heartrate;
|
|
57
|
-
};
|
|
58
170
|
}
|
|
59
171
|
//# sourceMappingURL=configKiwrious.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configKiwrious.js","sourceRoot":"","sources":["../../../src/Utils/kiwrious/configKiwrious.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"configKiwrious.js","sourceRoot":"","sources":["../../../src/Utils/kiwrious/configKiwrious.ts"],"names":[],"mappings":";;;;;;;;;AAiCA,IAAI,MAAmC,CAAC;AACxC,IAAI,OAA6C,CAAC;AAElD,+EAA+E;AAC/E,MAAM,OAAO,GAKT,EAAE,CAAC;AAEP;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,aAAP,OAAO,cAAP,OAAO,IAAP,OAAO,GAAK,CAAC,GAAS,EAAE;;QACtB,uEAAuE;QACvE,0EAA0E;QAC1E,qEAAqE;QACrE,sEAAsE;QACtE,0CAA0C;QAC1C,MAAM,OAAO,GACX,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,CAAC;QACrE,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE;gBAC/C,YAAY,EAAE,IAAI;gBAClB,KAAK,EAAE;oBACL,OAAO,EAAE,QAAQ;oBACjB,GAAG,EAAE,IAAI,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI;iBAC1C;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC;YACH,MAAM,GAAG,GAAQ,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAC;YACzD,MAAM,OAAO,GAAoB,MAAA,GAAG,CAAC,OAAO,mCAAI,GAAG,CAAC;YACpD,MAAM,GAAG,OAAO,CAAC;YAEjB,iEAAiE;YACjE,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;gBAAE,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACpE,IAAI,OAAO,CAAC,OAAO,KAAK,SA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BAAkD,EAClD,iBAA0E;;QAE1E,kBAAkB;QAClB,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC3B,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,MAAM,YAAY,EAAE,CAAC;QAErB,UAAU,CAAC,OAAO,GAAG,GAAS,EAAE;YAC9B,UAAU,CAAC,QAAQ,GAAG,IAAI,CAAC;YAC3B,MAAM,QAAQ,CAAC,aAAa,CAAC,mBAAmB,EAAE,CAAC;YACnD,UAAU,CAAC,QAAQ,GAAG,KAAK,CAAC;QAC9B,CAAC,CAAA,CAAC;QAEF,aAAa,CAAC,OAAO,GAAG,GAAS,EAAE;YACjC,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;YAC9B,MAAM,QAAQ,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC;YAC/C,aAAa,CAAC,QAAQ,GAAG,KAAK,CAAC;QACjC,CAAC,CAAA,CAAC;QAEF,QAAQ,CAAC,aAAa,CAAC,kBAAkB,GAAG,CAAC,WAAoB,EAAE,EAAE;YACnE,kBAAkB,CAAC,WAAW,CAAC,CAAC;QAClC,CAAC,CAAC;QACF,QAAQ,CAAC,aAAa,CAAC,YAAY,GAAG,CACpC,WAAsC,EACtC,EAAE;YACF,MAAM,MAAM,GAAG,WAAW,CAAC,aAA8C,CAAC;YAE1E,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAC5B,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC;CAAA"}
|
|
@@ -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,46 @@
|
|
|
1
|
+
export function collectFadeTargets(root) {
|
|
2
|
+
const targets = [];
|
|
3
|
+
root.traverse((child) => {
|
|
4
|
+
if (!(child === null || child === void 0 ? void 0 : child.isMesh) || !child.material)
|
|
5
|
+
return;
|
|
6
|
+
const materials = Array.isArray(child.material)
|
|
7
|
+
? child.material
|
|
8
|
+
: [child.material];
|
|
9
|
+
for (const material of materials) {
|
|
10
|
+
targets.push({
|
|
11
|
+
material,
|
|
12
|
+
opacity: material.opacity,
|
|
13
|
+
transparent: material.transparent,
|
|
14
|
+
depthWrite: material.depthWrite,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return targets;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Scales each material toward transparent by `factor`, RELATIVE to the
|
|
22
|
+
* opacity it already had. Scaling rather than assigning is what keeps an
|
|
23
|
+
* already-translucent material translucent: `opacity = factor` would end
|
|
24
|
+
* every crossfade with it fully opaque.
|
|
25
|
+
*
|
|
26
|
+
* `depthWrite` is suppressed for the whole fade and only restored at the
|
|
27
|
+
* fully-opaque end. A partially transparent mesh that still writes depth
|
|
28
|
+
* occludes everything drawn behind it, so a fade with depth writing left on
|
|
29
|
+
* shows the outgoing model punching holes in the incoming one.
|
|
30
|
+
*/
|
|
31
|
+
export function setFade(targets, factor) {
|
|
32
|
+
for (const t of targets) {
|
|
33
|
+
t.material.transparent = true;
|
|
34
|
+
t.material.opacity = t.opacity * factor;
|
|
35
|
+
t.material.depthWrite = t.depthWrite && factor >= 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Puts each material back exactly as `collectFadeTargets` found it. */
|
|
39
|
+
export function restoreFade(targets) {
|
|
40
|
+
for (const t of targets) {
|
|
41
|
+
t.material.transparent = t.transparent;
|
|
42
|
+
t.material.opacity = t.opacity;
|
|
43
|
+
t.material.depthWrite = t.depthWrite;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=modelCrossfade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelCrossfade.js","sourceRoot":"","sources":["../../src/Utils/modelCrossfade.ts"],"names":[],"mappings":"AAyBA,MAAM,UAAU,kBAAkB,CAAC,IAAwB;IACzD,MAAM,OAAO,GAAiB,EAAE,CAAA;IAChC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uB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
|
|
@@ -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;
|