copper3d 3.6.13 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Loader/copperDicomLoader.js +6 -1
- package/dist/Loader/copperDicomLoader.js.map +1 -1
- package/dist/Loader/copperRaw4DVolumeLoader.d.ts +10 -0
- package/dist/Loader/copperRaw4DVolumeLoader.js +270 -0
- package/dist/Loader/copperRaw4DVolumeLoader.js.map +1 -0
- package/dist/Loader/mhdParser.d.ts +83 -0
- package/dist/Loader/mhdParser.js +130 -0
- package/dist/Loader/mhdParser.js.map +1 -0
- package/dist/Scene/commonSceneMethod.d.ts +1 -0
- package/dist/Scene/commonSceneMethod.js +4 -19
- package/dist/Scene/commonSceneMethod.js.map +1 -1
- package/dist/Scene/copperMScene.js +2 -15
- package/dist/Scene/copperMScene.js.map +1 -1
- package/dist/Scene/copperScene.d.ts +7 -1
- package/dist/Scene/copperScene.js +14 -2
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/Scene/preRenderRegistry.d.ts +33 -0
- package/dist/Scene/preRenderRegistry.js +44 -0
- package/dist/Scene/preRenderRegistry.js.map +1 -0
- package/dist/Utils/colormapData.d.ts +9 -0
- package/dist/Utils/colormapData.js +39 -0
- package/dist/Utils/colormapData.js.map +1 -0
- package/dist/Utils/texture2d.d.ts +2 -0
- package/dist/Utils/texture2d.js +7 -1
- package/dist/Utils/texture2d.js.map +1 -1
- package/dist/Utils/volumeColormap.d.ts +6 -0
- package/dist/Utils/volumeColormap.js +14 -0
- package/dist/Utils/volumeColormap.js.map +1 -0
- package/dist/Utils/volumeShader.d.ts +7 -0
- package/dist/Utils/volumeShader.js +98 -0
- package/dist/Utils/volumeShader.js.map +1 -0
- package/dist/bundle.esm.js +641 -72
- package/dist/bundle.umd.js +641 -72
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/Loader/copperRaw4DVolumeLoader.d.ts +10 -0
- package/dist/types/Loader/mhdParser.d.ts +83 -0
- package/dist/types/Scene/commonSceneMethod.d.ts +1 -0
- package/dist/types/Scene/copperScene.d.ts +7 -1
- package/dist/types/Scene/preRenderRegistry.d.ts +33 -0
- package/dist/types/Utils/colormapData.d.ts +9 -0
- package/dist/types/Utils/texture2d.d.ts +2 -0
- package/dist/types/Utils/volumeColormap.d.ts +6 -0
- package/dist/types/Utils/volumeShader.d.ts +7 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/types/types.d.ts +82 -2
- package/dist/types/types.d.ts +82 -2
- package/package.json +1 -1
package/dist/bundle.esm.js
CHANGED
|
@@ -41146,6 +41146,50 @@ function perturbRandom(x, dx) {
|
|
|
41146
41146
|
return xp;
|
|
41147
41147
|
}
|
|
41148
41148
|
|
|
41149
|
+
/**
|
|
41150
|
+
* Registry of per-frame callbacks, keyed by a stable id.
|
|
41151
|
+
*
|
|
41152
|
+
* Deliberately dependency-free (no three.js) so it can be unit-tested under
|
|
41153
|
+
* `node --experimental-strip-types --test`.
|
|
41154
|
+
*
|
|
41155
|
+
* It replaces an object literal that was duplicated across `commonSceneMethod` and
|
|
41156
|
+
* `copperMScene` and carried three bugs, one of which silently corrupted callers:
|
|
41157
|
+
*
|
|
41158
|
+
* 1. `index` was never incremented, so `addPreRenderCallbackFunction` always returned 0.
|
|
41159
|
+
* Callers who stored that value and later removed it deleted somebody else's callback.
|
|
41160
|
+
* 2. `add` guarded with `if (!fn.id)`, and the very first id was 0 — falsy — so the first
|
|
41161
|
+
* callback looked unregistered forever and could be added twice.
|
|
41162
|
+
* 3. `remove(id)` spliced `cache` at the raw id, treating the id as an array index. Removing
|
|
41163
|
+
* one callback shifted every later one down, so every previously handed-out id then
|
|
41164
|
+
* pointed at its neighbour.
|
|
41165
|
+
*
|
|
41166
|
+
* Here ids come from a monotonic counter, are never reused, and are held in an array parallel
|
|
41167
|
+
* to `cache` — so a removal cannot invalidate anyone else's id.
|
|
41168
|
+
*/
|
|
41169
|
+
function createPreRenderRegistry() {
|
|
41170
|
+
return {
|
|
41171
|
+
index: 0,
|
|
41172
|
+
cache: [],
|
|
41173
|
+
ids: [],
|
|
41174
|
+
add(fn) {
|
|
41175
|
+
const existing = this.cache.indexOf(fn);
|
|
41176
|
+
if (existing !== -1)
|
|
41177
|
+
return this.ids[existing];
|
|
41178
|
+
const id = this.index++;
|
|
41179
|
+
this.cache.push(fn);
|
|
41180
|
+
this.ids.push(id);
|
|
41181
|
+
return id;
|
|
41182
|
+
},
|
|
41183
|
+
remove(id) {
|
|
41184
|
+
const at = this.ids.indexOf(id);
|
|
41185
|
+
if (at === -1)
|
|
41186
|
+
return;
|
|
41187
|
+
this.cache.splice(at, 1);
|
|
41188
|
+
this.ids.splice(at, 1);
|
|
41189
|
+
},
|
|
41190
|
+
};
|
|
41191
|
+
}
|
|
41192
|
+
|
|
41149
41193
|
/* eslint no-bitwise: 0 */
|
|
41150
41194
|
/**
|
|
41151
41195
|
* Volume of Interest Lookup Table Function
|
|
@@ -41246,6 +41290,7 @@ var dicomParser = unwrapExports(dicomParser_min);
|
|
|
41246
41290
|
const loader$1 = new FileLoader().setResponseType("arraybuffer");
|
|
41247
41291
|
function copperDicomLoader(url, callback) {
|
|
41248
41292
|
loader$1.load(url, (arrayBuffer) => {
|
|
41293
|
+
var _a;
|
|
41249
41294
|
var dicomFileAsBuffer = new Uint8Array(arrayBuffer);
|
|
41250
41295
|
const dataSet = dicomParser.parseDicom(dicomFileAsBuffer);
|
|
41251
41296
|
// const dataSet = dicomParser.parseDicom(dicomFileAsBuffer, {
|
|
@@ -41275,7 +41320,7 @@ function copperDicomLoader(url, callback) {
|
|
|
41275
41320
|
windowCenter = parseInt(tags["x00281050"]); //window center
|
|
41276
41321
|
windowWidth = parseInt(tags["x00281051"]); //window width
|
|
41277
41322
|
}
|
|
41278
|
-
catch (
|
|
41323
|
+
catch (_b) {
|
|
41279
41324
|
w = dataSet.uint16("x00280011");
|
|
41280
41325
|
h = dataSet.uint16("x00280010");
|
|
41281
41326
|
invert = dataSet.string("x00280004") === "MONOCHROME1" ? true : false;
|
|
@@ -41297,6 +41342,9 @@ function copperDicomLoader(url, callback) {
|
|
|
41297
41342
|
const ipp = parseDS(dataSet.string("x00200032")); // ImagePositionPatient
|
|
41298
41343
|
const iop = parseDS(dataSet.string("x00200037")); // ImageOrientationPatient
|
|
41299
41344
|
const spacing = parseDS(dataSet.string("x00280030")); // PixelSpacing
|
|
41345
|
+
// FrameOfReferenceUID: two series share a world coordinate system only if this matches.
|
|
41346
|
+
// It is the only field that lets another modality prove it is already registered to this one.
|
|
41347
|
+
const frameOfReferenceUID = (_a = dataSet.string("x00200052")) !== null && _a !== void 0 ? _a : undefined;
|
|
41300
41348
|
let instanceNumber = parseInt(dataSet.string("x00200013"));
|
|
41301
41349
|
if (Number.isNaN(instanceNumber))
|
|
41302
41350
|
instanceNumber = undefined;
|
|
@@ -41325,6 +41373,7 @@ function copperDicomLoader(url, callback) {
|
|
|
41325
41373
|
imagePositionPatient: ipp,
|
|
41326
41374
|
imageOrientationPatient: iop,
|
|
41327
41375
|
pixelSpacing: spacing,
|
|
41376
|
+
frameOfReferenceUID,
|
|
41328
41377
|
corners,
|
|
41329
41378
|
};
|
|
41330
41379
|
callback && callback(copperVolume);
|
|
@@ -41397,7 +41446,7 @@ function getLut(data, windowWidth, windowCenter, invert, voiLUT) {
|
|
|
41397
41446
|
|
|
41398
41447
|
var vert_2d = "out vec2 vUv;\n\nvoid main() {\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n // Use the geometry's own UVs; DICOM rows are top-down so flip v.\n vUv = vec2( uv.x, 1.0 - uv.y );\n\n}\n";
|
|
41399
41448
|
|
|
41400
|
-
var frag_2d = "precision highp float;\nprecision highp int;\nprecision highp sampler2DArray;\n\nuniform sampler2DArray diffuse;\nin vec2 vUv;\nuniform int depth;\nuniform float uOpacity;\n\nout vec4 outColor;\n\nvoid main() {\n\n vec4 color = texture( diffuse, vec3( vUv, depth ) );\n\n
|
|
41449
|
+
var frag_2d = "precision highp float;\nprecision highp int;\nprecision highp sampler2DArray;\n\nuniform sampler2DArray diffuse;\nin vec2 vUv;\nuniform int depth;\nuniform float uOpacity;\n// Post-window gain. Defaults to 1.5, the value this shader used to hard-code.\n// It cannot lift true black (0 * gain == 0), but it does clip the top of the\n// range, so 1.0 is the faithful setting. Blacks that look grey are almost always\n// a window whose lower bound sits below 0, not this gain.\nuniform float uBrightness;\n\nout vec4 outColor;\n\nvoid main() {\n\n vec4 color = texture( diffuse, vec3( vUv, depth ) );\n\n outColor = vec4( color.rrr * uBrightness, uOpacity );\n\n}";
|
|
41401
41450
|
|
|
41402
41451
|
let planeWidth = 80;
|
|
41403
41452
|
let planeHeight = 80;
|
|
@@ -41422,6 +41471,7 @@ function createTexture2D_NRRD(data, width, height, depth, callback) {
|
|
|
41422
41471
|
diffuse: { value: texture },
|
|
41423
41472
|
depth: { value: 1 },
|
|
41424
41473
|
uOpacity: { value: 1 },
|
|
41474
|
+
uBrightness: { value: 1.5 },
|
|
41425
41475
|
},
|
|
41426
41476
|
vertexShader: vert_2d,
|
|
41427
41477
|
fragmentShader: frag_2d,
|
|
@@ -41464,6 +41514,7 @@ function createTexture2D_Array(copperVolume, depth, scene, gui, aligned = false)
|
|
|
41464
41514
|
diffuse: { value: texture },
|
|
41465
41515
|
depth: { value: 0 },
|
|
41466
41516
|
uOpacity: { value: 1 },
|
|
41517
|
+
uBrightness: { value: 1.5 },
|
|
41467
41518
|
},
|
|
41468
41519
|
vertexShader: vert_2d,
|
|
41469
41520
|
fragmentShader: frag_2d,
|
|
@@ -41496,7 +41547,11 @@ function createTexture2D_Array(copperVolume, depth, scene, gui, aligned = false)
|
|
|
41496
41547
|
copperVolume.windowWidth = width;
|
|
41497
41548
|
updateTexture(copperVolume);
|
|
41498
41549
|
}
|
|
41499
|
-
|
|
41550
|
+
/** Post-window gain. 1.0 is faithful; the historical default is 1.5. */
|
|
41551
|
+
function setBrightness(v) {
|
|
41552
|
+
material.uniforms.uBrightness.value = v;
|
|
41553
|
+
}
|
|
41554
|
+
return { mesh, copperVolume, updateTexture, setFrame, setWindow, setBrightness };
|
|
41500
41555
|
}
|
|
41501
41556
|
|
|
41502
41557
|
/*!
|
|
@@ -49497,22 +49552,7 @@ class commonScene {
|
|
|
49497
49552
|
}
|
|
49498
49553
|
this.controls = new Copper3dTrackballControls(this.camera, this.container);
|
|
49499
49554
|
this.controls.dispose();
|
|
49500
|
-
this.preRenderCallbackFunctions =
|
|
49501
|
-
index: 0,
|
|
49502
|
-
cache: [],
|
|
49503
|
-
add(fn) {
|
|
49504
|
-
if (!fn.id) {
|
|
49505
|
-
fn.id = this.cache.length;
|
|
49506
|
-
this.cache.push(fn);
|
|
49507
|
-
return;
|
|
49508
|
-
}
|
|
49509
|
-
},
|
|
49510
|
-
remove(id) {
|
|
49511
|
-
if (this.cache[id]) {
|
|
49512
|
-
this.cache.splice(id, 1);
|
|
49513
|
-
}
|
|
49514
|
-
},
|
|
49515
|
-
};
|
|
49555
|
+
this.preRenderCallbackFunctions = createPreRenderRegistry();
|
|
49516
49556
|
}
|
|
49517
49557
|
createDemoMesh() {
|
|
49518
49558
|
const geometry = new BoxGeometry();
|
|
@@ -49538,10 +49578,9 @@ class commonScene {
|
|
|
49538
49578
|
this.sort = false;
|
|
49539
49579
|
}
|
|
49540
49580
|
}
|
|
49581
|
+
/** Registers a per-frame callback and returns its id, for removePreRenderCallbackFunction. */
|
|
49541
49582
|
addPreRenderCallbackFunction(callbackFunction) {
|
|
49542
|
-
this.preRenderCallbackFunctions.add(callbackFunction);
|
|
49543
|
-
const id = this.preRenderCallbackFunctions.index;
|
|
49544
|
-
return id;
|
|
49583
|
+
return this.preRenderCallbackFunctions.add(callbackFunction);
|
|
49545
49584
|
}
|
|
49546
49585
|
removePreRenderCallbackFunction(id) {
|
|
49547
49586
|
this.preRenderCallbackFunctions.remove(id);
|
|
@@ -57410,6 +57449,569 @@ function copperGltfLoader(renderer) {
|
|
|
57410
57449
|
return loader;
|
|
57411
57450
|
}
|
|
57412
57451
|
|
|
57452
|
+
/******************************************************************************
|
|
57453
|
+
Copyright (c) Microsoft Corporation.
|
|
57454
|
+
|
|
57455
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
57456
|
+
purpose with or without fee is hereby granted.
|
|
57457
|
+
|
|
57458
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
57459
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
57460
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
57461
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
57462
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
57463
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
57464
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
57465
|
+
***************************************************************************** */
|
|
57466
|
+
|
|
57467
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
57468
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
57469
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
57470
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
57471
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
57472
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
57473
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
57474
|
+
});
|
|
57475
|
+
}
|
|
57476
|
+
|
|
57477
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
57478
|
+
var e = new Error(message);
|
|
57479
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57480
|
+
};
|
|
57481
|
+
|
|
57482
|
+
/**
|
|
57483
|
+
* Minimal MetaImage (.mhd) header parser.
|
|
57484
|
+
*
|
|
57485
|
+
* Deliberately dependency-free (no three.js) so it can run under
|
|
57486
|
+
* `node --experimental-strip-types --test`.
|
|
57487
|
+
*
|
|
57488
|
+
* Only the subset the 4D ultrasound data uses is supported: 3D, uncompressed,
|
|
57489
|
+
* uint8. Anything else throws rather than silently mis-rendering.
|
|
57490
|
+
*/
|
|
57491
|
+
/** Row-major identity — the value MetaImage writes when it has no real orientation. */
|
|
57492
|
+
const IDENTITY_MATRIX = [1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
57493
|
+
function triple(raw, field) {
|
|
57494
|
+
const parts = raw.trim().split(/\s+/).map(Number);
|
|
57495
|
+
if (parts.length !== 3 || parts.some((n) => !Number.isFinite(n))) {
|
|
57496
|
+
throw new Error(`mhd: ${field} must be 3 numbers, got "${raw}"`);
|
|
57497
|
+
}
|
|
57498
|
+
return [parts[0], parts[1], parts[2]];
|
|
57499
|
+
}
|
|
57500
|
+
function matrix3x3(raw) {
|
|
57501
|
+
const parts = raw.trim().split(/\s+/).map(Number);
|
|
57502
|
+
if (parts.length !== 9 || parts.some((n) => !Number.isFinite(n))) {
|
|
57503
|
+
throw new Error(`mhd: TransformMatrix must be 9 numbers, got "${raw}"`);
|
|
57504
|
+
}
|
|
57505
|
+
return parts;
|
|
57506
|
+
}
|
|
57507
|
+
/** Floating-point headers rarely round-trip exactly; compare with a tolerance. */
|
|
57508
|
+
const near = (a, b) => Math.abs(a - b) < 1e-6;
|
|
57509
|
+
function parseMhdHeader(text) {
|
|
57510
|
+
var _a, _b;
|
|
57511
|
+
const fields = new Map();
|
|
57512
|
+
for (const line of text.split(/\r?\n/)) {
|
|
57513
|
+
const eq = line.indexOf("=");
|
|
57514
|
+
if (eq === -1)
|
|
57515
|
+
continue;
|
|
57516
|
+
fields.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());
|
|
57517
|
+
}
|
|
57518
|
+
const need = (key) => {
|
|
57519
|
+
const value = fields.get(key);
|
|
57520
|
+
if (value === undefined)
|
|
57521
|
+
throw new Error(`mhd: missing required field "${key}"`);
|
|
57522
|
+
return value;
|
|
57523
|
+
};
|
|
57524
|
+
const nDims = Number(need("NDims"));
|
|
57525
|
+
if (nDims !== 3)
|
|
57526
|
+
throw new Error(`mhd: only NDims=3 is supported, got ${nDims}`);
|
|
57527
|
+
if (need("CompressedData").toLowerCase() === "true") {
|
|
57528
|
+
throw new Error("mhd: CompressedData=True is not supported");
|
|
57529
|
+
}
|
|
57530
|
+
const elementType = need("ElementType");
|
|
57531
|
+
if (elementType !== "MET_UCHAR") {
|
|
57532
|
+
throw new Error(`mhd: only MET_UCHAR is supported, got ${elementType}`);
|
|
57533
|
+
}
|
|
57534
|
+
const spacing = triple(need("ElementSpacing"), "ElementSpacing");
|
|
57535
|
+
const offsetRaw = fields.get("Offset");
|
|
57536
|
+
const offset = offsetRaw === undefined ? [0, 0, 0] : triple(offsetRaw, "Offset");
|
|
57537
|
+
const matrixRaw = fields.get("TransformMatrix");
|
|
57538
|
+
const transformMatrix = matrixRaw === undefined ? IDENTITY_MATRIX : matrix3x3(matrixRaw);
|
|
57539
|
+
const hasOffset = !offset.every((v) => near(v, 0));
|
|
57540
|
+
const hasRotation = !transformMatrix.every((v, i) => near(v, IDENTITY_MATRIX[i]));
|
|
57541
|
+
return {
|
|
57542
|
+
dims: triple(need("DimSize"), "DimSize"),
|
|
57543
|
+
spacing,
|
|
57544
|
+
elementType,
|
|
57545
|
+
compressed: false,
|
|
57546
|
+
elementDataFile: need("ElementDataFile"),
|
|
57547
|
+
offset,
|
|
57548
|
+
transformMatrix,
|
|
57549
|
+
anatomicalOrientation: (_a = fields.get("AnatomicalOrientation")) !== null && _a !== void 0 ? _a : null,
|
|
57550
|
+
frameOfReferenceUID: (_b = fields.get("FrameOfReferenceUID")) !== null && _b !== void 0 ? _b : null,
|
|
57551
|
+
hasPose: hasOffset || hasRotation,
|
|
57552
|
+
hasRealSpacing: !spacing.every((v) => near(v, 1)),
|
|
57553
|
+
};
|
|
57554
|
+
}
|
|
57555
|
+
/**
|
|
57556
|
+
* Decide whether a header's pose may be trusted.
|
|
57557
|
+
*
|
|
57558
|
+
* Two independent things must hold, and the second is the one people forget:
|
|
57559
|
+
*
|
|
57560
|
+
* 1. the header must actually carry a pose (`hasPose`), and
|
|
57561
|
+
* 2. that pose must be expressed in the SAME world frame as the scene.
|
|
57562
|
+
*
|
|
57563
|
+
* DICOM proves (2) with FrameOfReferenceUID. MetaImage has no such field, so a producer must
|
|
57564
|
+
* carry the UID across as a custom line. When the caller names the scene's frame and the file
|
|
57565
|
+
* cannot match it, the pose is refused — a pose in another scanner's coordinate system is
|
|
57566
|
+
* worse than no pose at all, because it looks authoritative while being wrong.
|
|
57567
|
+
*
|
|
57568
|
+
* When the caller names no frame, a pose is honoured but reported as `unverified`: nobody
|
|
57569
|
+
* checked, and the UI should not claim otherwise.
|
|
57570
|
+
*/
|
|
57571
|
+
function resolveRegistration(header, expectedFrameOfReferenceUID) {
|
|
57572
|
+
if (!header.hasPose) {
|
|
57573
|
+
return { registered: false, frameVerified: false, reason: "no-pose" };
|
|
57574
|
+
}
|
|
57575
|
+
if (!expectedFrameOfReferenceUID) {
|
|
57576
|
+
return { registered: true, frameVerified: false, reason: "unverified" };
|
|
57577
|
+
}
|
|
57578
|
+
if (!header.frameOfReferenceUID) {
|
|
57579
|
+
return { registered: false, frameVerified: false, reason: "frame-missing" };
|
|
57580
|
+
}
|
|
57581
|
+
if (header.frameOfReferenceUID !== expectedFrameOfReferenceUID) {
|
|
57582
|
+
return { registered: false, frameVerified: false, reason: "frame-mismatch" };
|
|
57583
|
+
}
|
|
57584
|
+
return { registered: true, frameVerified: true, reason: "verified" };
|
|
57585
|
+
}
|
|
57586
|
+
/**
|
|
57587
|
+
* voxel index -> world, as a column-major 4x4 (three.js `Matrix4.elements` order).
|
|
57588
|
+
*
|
|
57589
|
+
* ITK/MetaImage convention: `world = Offset + D · (Spacing ∘ index)`, with `D` the
|
|
57590
|
+
* row-major direction matrix from TransformMatrix.
|
|
57591
|
+
*
|
|
57592
|
+
* Only meaningful when `header.hasPose` — otherwise this is the identity scaled by
|
|
57593
|
+
* spacing, which places the volume at the world origin and means nothing.
|
|
57594
|
+
*/
|
|
57595
|
+
function voxelToWorldMatrix(header) {
|
|
57596
|
+
const d = header.transformMatrix;
|
|
57597
|
+
const [sx, sy, sz] = header.spacing;
|
|
57598
|
+
const [ox, oy, oz] = header.offset;
|
|
57599
|
+
// Column-major: each of the first three columns is a scaled direction (a column of D).
|
|
57600
|
+
return [
|
|
57601
|
+
d[0] * sx, d[3] * sx, d[6] * sx, 0,
|
|
57602
|
+
d[1] * sy, d[4] * sy, d[7] * sy, 0,
|
|
57603
|
+
d[2] * sz, d[5] * sz, d[8] * sz, 0,
|
|
57604
|
+
ox, oy, oz, 1,
|
|
57605
|
+
];
|
|
57606
|
+
}
|
|
57607
|
+
/** Number of voxels implied by the header — equals the .raw byte length for uint8. */
|
|
57608
|
+
function voxelCount(header) {
|
|
57609
|
+
return header.dims[0] * header.dims[1] * header.dims[2];
|
|
57610
|
+
}
|
|
57611
|
+
|
|
57612
|
+
/**
|
|
57613
|
+
* Blue -> orange transfer function for ultrasound volume rendering.
|
|
57614
|
+
*
|
|
57615
|
+
* Dependency-free (no three.js) so it can be unit-tested under Node.
|
|
57616
|
+
* The ALPHA channel is load-bearing: three's VolumeRenderShader1 samples this
|
|
57617
|
+
* ramp as RGBA, so alpha is what turns low-intensity speckle transparent and
|
|
57618
|
+
* gives the volume its cloud-like appearance.
|
|
57619
|
+
*/
|
|
57620
|
+
/** Linear interpolation between two RGB stops. */
|
|
57621
|
+
function mix(a, b, t) {
|
|
57622
|
+
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
57623
|
+
}
|
|
57624
|
+
const DEEP_BLUE = [30, 60, 120];
|
|
57625
|
+
const PALE_BLUE = [150, 190, 230];
|
|
57626
|
+
const WARM_ORANGE = [255, 170, 90];
|
|
57627
|
+
/**
|
|
57628
|
+
* Fraction of the ramp spent going blue -> pale blue before turning orange.
|
|
57629
|
+
* Tuned against the data: under the default clim window a typical MIP sample lands
|
|
57630
|
+
* around 0.63 of the ramp, so a 0.6 span turned the whole cloud orange. At 0.75 only
|
|
57631
|
+
* the brightest ~0.1% of samples (raw > 139, the p99.9) read as warm highlights.
|
|
57632
|
+
*/
|
|
57633
|
+
const BLUE_SPAN = 0.75;
|
|
57634
|
+
/** Alpha curve exponent. >1 keeps the low-intensity speckle transparent. */
|
|
57635
|
+
const ALPHA_GAMMA = 1.6;
|
|
57636
|
+
function buildBlueOrangeRGBA(size = 256) {
|
|
57637
|
+
const out = new Uint8Array(size * 4);
|
|
57638
|
+
for (let i = 0; i < size; i++) {
|
|
57639
|
+
const t = i / (size - 1);
|
|
57640
|
+
const [r, g, b] = t < BLUE_SPAN
|
|
57641
|
+
? mix(DEEP_BLUE, PALE_BLUE, t / BLUE_SPAN)
|
|
57642
|
+
: mix(PALE_BLUE, WARM_ORANGE, (t - BLUE_SPAN) / (1 - BLUE_SPAN));
|
|
57643
|
+
out[i * 4 + 0] = Math.round(r);
|
|
57644
|
+
out[i * 4 + 1] = Math.round(g);
|
|
57645
|
+
out[i * 4 + 2] = Math.round(b);
|
|
57646
|
+
out[i * 4 + 3] = Math.round(Math.pow(t, ALPHA_GAMMA) * 255);
|
|
57647
|
+
}
|
|
57648
|
+
return out;
|
|
57649
|
+
}
|
|
57650
|
+
|
|
57651
|
+
/**
|
|
57652
|
+
* A 1-D RGBA colormap texture for VolumeRenderShader1's `u_cmdata` uniform.
|
|
57653
|
+
* Caller owns the texture and must dispose() it.
|
|
57654
|
+
*/
|
|
57655
|
+
function createBlueOrangeColormap(size = 256) {
|
|
57656
|
+
const texture = new DataTexture(buildBlueOrangeRGBA(size), size, 1, RGBAFormat);
|
|
57657
|
+
texture.minFilter = texture.magFilter = LinearFilter;
|
|
57658
|
+
texture.wrapS = texture.wrapT = ClampToEdgeWrapping;
|
|
57659
|
+
texture.needsUpdate = true;
|
|
57660
|
+
return texture;
|
|
57661
|
+
}
|
|
57662
|
+
|
|
57663
|
+
/**
|
|
57664
|
+
* three's VolumeRenderShader1 offers only MIP and ISO, and no opacity control. Clone it and
|
|
57665
|
+
* splice in:
|
|
57666
|
+
*
|
|
57667
|
+
* - a `u_opacity` uniform, and
|
|
57668
|
+
* - a third render style, DVR (`u_renderstyle == 2`): front-to-back alpha compositing.
|
|
57669
|
+
*
|
|
57670
|
+
* Why DVR matters here: MIP takes the MAXIMUM sample along each ray, so a dark cavity
|
|
57671
|
+
* surrounded by bright tissue can never appear — the max always picks the bright speckle in
|
|
57672
|
+
* front of or behind it. Compositing accumulates colour and opacity instead, letting low
|
|
57673
|
+
* intensity stay transparent, which is what makes the LV chamber visible inside an echo.
|
|
57674
|
+
*
|
|
57675
|
+
* Every edit is asserted: if a future three.js release rewrites these lines we fail loudly at
|
|
57676
|
+
* construction rather than shipping a shader that silently ignores opacity, silently drops
|
|
57677
|
+
* DVR, or fails to compile.
|
|
57678
|
+
*/
|
|
57679
|
+
/** Matches the trailing `if (gl_FragColor.a < 0.05) discard;` in main(), tabs and all. */
|
|
57680
|
+
const DISCARD_TEST = /if\s*\(\s*gl_FragColor\.a\s*<\s*0\.05\s*\)\s*discard;/;
|
|
57681
|
+
const CLIM_DECL = "uniform vec2 u_clim;";
|
|
57682
|
+
/** The forward declaration block, and the dispatch inside main(). */
|
|
57683
|
+
const CAST_ISO_PROTO = "void cast_iso(vec3 start_loc, vec3 step, int nsteps, vec3 view_ray);";
|
|
57684
|
+
const CAST_ISO_CALL = "cast_iso(start_loc, step, nsteps, view_ray);";
|
|
57685
|
+
/**
|
|
57686
|
+
* Front-to-back emission-absorption compositing.
|
|
57687
|
+
*
|
|
57688
|
+
* Two details matter, both established by rendering this dataset offline:
|
|
57689
|
+
*
|
|
57690
|
+
* - Emission is scaled by the windowed intensity `t`, not taken straight from the colormap.
|
|
57691
|
+
* The colormap's low end is a mid blue, so thousands of faint samples each deposit blue
|
|
57692
|
+
* and wash the interior out into a featureless shell. Weighting by `t` makes low-intensity
|
|
57693
|
+
* blood pool contribute almost nothing, which is what lets the chamber read as dark.
|
|
57694
|
+
* - `u_dvr_gain` then restores the brightness that the `t` weighting removed.
|
|
57695
|
+
*
|
|
57696
|
+
* Opacity per sample is `colour.a * u_dvr_density`; the colormap's alpha ramp is the transfer
|
|
57697
|
+
* function. Accumulation is premultiplied and un-premultiplied at the end, because three
|
|
57698
|
+
* blends with (srcAlpha, 1 - srcAlpha).
|
|
57699
|
+
*/
|
|
57700
|
+
const CAST_DVR_BODY = `
|
|
57701
|
+
|
|
57702
|
+
void cast_dvr(vec3 start_loc, vec3 step, int nsteps, vec3 view_ray) {
|
|
57703
|
+
|
|
57704
|
+
vec4 acc = vec4(0.0);
|
|
57705
|
+
vec3 loc = start_loc;
|
|
57706
|
+
|
|
57707
|
+
// Same hard-coded bound + inner break as cast_mip: GLSL cannot compare the
|
|
57708
|
+
// loop index against a non-constant expression.
|
|
57709
|
+
for (int iter=0; iter<MAX_STEPS; iter++) {
|
|
57710
|
+
if (iter >= nsteps)
|
|
57711
|
+
break;
|
|
57712
|
+
|
|
57713
|
+
float val = sample1(loc);
|
|
57714
|
+
float t = clamp((val - u_clim[0]) / (u_clim[1] - u_clim[0]), 0.0, 1.0);
|
|
57715
|
+
vec4 color = apply_colormap(val);
|
|
57716
|
+
|
|
57717
|
+
float a = color.a * u_dvr_density;
|
|
57718
|
+
vec3 emission = color.rgb * t * u_dvr_gain;
|
|
57719
|
+
|
|
57720
|
+
// Front-to-back: what is already accumulated occludes what is behind it.
|
|
57721
|
+
acc.rgb += (1.0 - acc.a) * emission * a;
|
|
57722
|
+
acc.a += (1.0 - acc.a) * a;
|
|
57723
|
+
|
|
57724
|
+
// Early ray termination: nothing behind an opaque accumulation matters.
|
|
57725
|
+
if (acc.a >= 0.95)
|
|
57726
|
+
break;
|
|
57727
|
+
|
|
57728
|
+
loc += step;
|
|
57729
|
+
}
|
|
57730
|
+
|
|
57731
|
+
// three blends with (srcAlpha, 1 - srcAlpha), so hand back straight alpha.
|
|
57732
|
+
if (acc.a > 0.001)
|
|
57733
|
+
acc.rgb /= acc.a;
|
|
57734
|
+
|
|
57735
|
+
gl_FragColor = acc;
|
|
57736
|
+
}`;
|
|
57737
|
+
/** Replace `find` once, throwing `message` if it was not present. */
|
|
57738
|
+
function spliceOnce(source, find, replace, message) {
|
|
57739
|
+
const out = source.replace(find, replace);
|
|
57740
|
+
if (out === source)
|
|
57741
|
+
throw new Error(`volumeShader: ${message} — three's VolumeShader changed`);
|
|
57742
|
+
return out;
|
|
57743
|
+
}
|
|
57744
|
+
function createVolumeShaderWithOpacity() {
|
|
57745
|
+
const uniforms = UniformsUtils.clone(VolumeRenderShader1.uniforms);
|
|
57746
|
+
uniforms.u_opacity = { value: 1.0 };
|
|
57747
|
+
uniforms.u_dvr_density = { value: 0.25 };
|
|
57748
|
+
uniforms.u_dvr_gain = { value: 2.5 };
|
|
57749
|
+
let fragmentShader = VolumeRenderShader1.fragmentShader;
|
|
57750
|
+
fragmentShader = spliceOnce(fragmentShader, CLIM_DECL, `${CLIM_DECL}\n uniform float u_opacity;\n uniform float u_dvr_density;\n uniform float u_dvr_gain;`, "could not declare u_opacity / u_dvr_density / u_dvr_gain");
|
|
57751
|
+
fragmentShader = spliceOnce(fragmentShader, CAST_ISO_PROTO, `${CAST_ISO_PROTO}\n\t\t\t\tvoid cast_dvr(vec3 start_loc, vec3 step, int nsteps, vec3 view_ray);`, "could not forward-declare cast_dvr");
|
|
57752
|
+
fragmentShader = spliceOnce(fragmentShader, CAST_ISO_CALL, `${CAST_ISO_CALL}\n\t\t\t\t\t\telse if (u_renderstyle == 2)\n\t\t\t\t\t\t\t\tcast_dvr(start_loc, step, nsteps, view_ray);`, "could not dispatch cast_dvr");
|
|
57753
|
+
fragmentShader = spliceOnce(fragmentShader, DISCARD_TEST, "gl_FragColor.a *= u_opacity;\n\t\t\t\t\t\tif (gl_FragColor.a < 0.01) discard;", "could not patch the discard test");
|
|
57754
|
+
// The fragment shader is one template literal ending in `}`; append the new function.
|
|
57755
|
+
fragmentShader = fragmentShader.trimEnd() + CAST_DVR_BODY;
|
|
57756
|
+
return { uniforms, vertexShader: VolumeRenderShader1.vertexShader, fragmentShader };
|
|
57757
|
+
}
|
|
57758
|
+
|
|
57759
|
+
/** u_renderstyle encoding. `dvr` is our addition — see Utils/volumeShader.ts. */
|
|
57760
|
+
const RENDER_STYLE = { mip: 0, iso: 1, dvr: 2 };
|
|
57761
|
+
/**
|
|
57762
|
+
* Starting window, measured from the data rather than guessed: this volume's maximum
|
|
57763
|
+
* sample is 178/255 = 0.698 and 65% of its voxels are zero. A window whose top sits
|
|
57764
|
+
* above the data maximum (the old [0.2, 0.9]) squeezes nearly every sample into the
|
|
57765
|
+
* colormap's transparent low end, producing a near-invisible cloud.
|
|
57766
|
+
*
|
|
57767
|
+
* The floor then matters differently per render style. Under DVR the LV blood pool sits at
|
|
57768
|
+
* roughly 0.13 normalised, so a floor near 0.10 is what makes the chamber go transparent and
|
|
57769
|
+
* become visible; MIP prefers a lower floor (~0.01) to keep the faint speckle. The default
|
|
57770
|
+
* serves DVR, which is the style that can actually show the heart.
|
|
57771
|
+
*/
|
|
57772
|
+
const DEFAULT_CLIM = [0.1, 0.55];
|
|
57773
|
+
/** Resolve `ElementDataFile` relative to its .mhd URL. */
|
|
57774
|
+
function resolveRawUrl(mhdUrl, elementDataFile) {
|
|
57775
|
+
return mhdUrl.replace(/[^/]+$/, elementDataFile);
|
|
57776
|
+
}
|
|
57777
|
+
function loadFrame(mhdUrl) {
|
|
57778
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57779
|
+
const headerResponse = yield fetch(mhdUrl);
|
|
57780
|
+
if (!headerResponse.ok) {
|
|
57781
|
+
throw new Error(`mhd fetch failed: ${mhdUrl} (${headerResponse.status})`);
|
|
57782
|
+
}
|
|
57783
|
+
const header = parseMhdHeader(yield headerResponse.text());
|
|
57784
|
+
const rawUrl = resolveRawUrl(mhdUrl, header.elementDataFile);
|
|
57785
|
+
const rawResponse = yield fetch(rawUrl);
|
|
57786
|
+
if (!rawResponse.ok) {
|
|
57787
|
+
throw new Error(`raw fetch failed: ${rawUrl} (${rawResponse.status})`);
|
|
57788
|
+
}
|
|
57789
|
+
const buffer = yield rawResponse.arrayBuffer();
|
|
57790
|
+
const expected = voxelCount(header);
|
|
57791
|
+
if (buffer.byteLength !== expected) {
|
|
57792
|
+
throw new Error(`raw size mismatch for ${rawUrl}: got ${buffer.byteLength}, expected ${expected}`);
|
|
57793
|
+
}
|
|
57794
|
+
return { data: new Uint8Array(buffer), dims: header.dims, header };
|
|
57795
|
+
});
|
|
57796
|
+
}
|
|
57797
|
+
/** uint8 volume -> single-channel 3D texture. 1 byte/voxel; do not widen to float. */
|
|
57798
|
+
function createVolumeTexture(frame) {
|
|
57799
|
+
const [width, height, depth] = frame.dims;
|
|
57800
|
+
const texture = new Data3DTexture(frame.data, width, height, depth);
|
|
57801
|
+
texture.format = RedFormat;
|
|
57802
|
+
texture.type = UnsignedByteType;
|
|
57803
|
+
texture.minFilter = texture.magFilter = LinearFilter;
|
|
57804
|
+
texture.unpackAlignment = 1;
|
|
57805
|
+
texture.needsUpdate = true;
|
|
57806
|
+
return texture;
|
|
57807
|
+
}
|
|
57808
|
+
/**
|
|
57809
|
+
* Load a 4D volume sequence (one .mhd/.raw pair per cardiac phase) and add it to `scene`
|
|
57810
|
+
* as a raycast volume.
|
|
57811
|
+
*
|
|
57812
|
+
* The returned controller runs NO clock of its own — drive it with setFrame()/setPhase()
|
|
57813
|
+
* so it can share a cardiac-phase clock with other modalities.
|
|
57814
|
+
*/
|
|
57815
|
+
function loadRaw4DVolume(mhdUrls, scene, opts = {}, callback) {
|
|
57816
|
+
let loaded = 0;
|
|
57817
|
+
const jobs = mhdUrls.map((url) => loadFrame(url).then((frame) => {
|
|
57818
|
+
var _a;
|
|
57819
|
+
(_a = opts.onProgress) === null || _a === void 0 ? void 0 : _a.call(opts, ++loaded, mhdUrls.length);
|
|
57820
|
+
return frame;
|
|
57821
|
+
}));
|
|
57822
|
+
Promise.all(jobs)
|
|
57823
|
+
.then((frames) => {
|
|
57824
|
+
var _a, _b, _c, _d, _e, _f;
|
|
57825
|
+
if (frames.length === 0) {
|
|
57826
|
+
throw new Error("raw4DVolume: mhdUrls is empty");
|
|
57827
|
+
}
|
|
57828
|
+
const dims = frames[0].dims;
|
|
57829
|
+
for (const frame of frames) {
|
|
57830
|
+
if (frame.dims.join() !== dims.join()) {
|
|
57831
|
+
throw new Error(`raw4DVolume: frames disagree on dims (${frame.dims} vs ${dims})`);
|
|
57832
|
+
}
|
|
57833
|
+
}
|
|
57834
|
+
const [width, height, depth] = dims;
|
|
57835
|
+
const textures = frames.map(createVolumeTexture);
|
|
57836
|
+
const colormap = createBlueOrangeColormap();
|
|
57837
|
+
const { uniforms, vertexShader, fragmentShader } = createVolumeShaderWithOpacity();
|
|
57838
|
+
const clim = (_a = opts.clim) !== null && _a !== void 0 ? _a : DEFAULT_CLIM;
|
|
57839
|
+
uniforms.u_data.value = textures[0];
|
|
57840
|
+
uniforms.u_size.value.set(width, height, depth);
|
|
57841
|
+
uniforms.u_clim.value.set(clim[0], clim[1]);
|
|
57842
|
+
uniforms.u_renderstyle.value = RENDER_STYLE[(_b = opts.renderStyle) !== null && _b !== void 0 ? _b : "mip"];
|
|
57843
|
+
uniforms.u_renderthreshold.value = (_c = opts.isoThreshold) !== null && _c !== void 0 ? _c : 0.35;
|
|
57844
|
+
uniforms.u_cmdata.value = colormap;
|
|
57845
|
+
uniforms.u_opacity.value = (_d = opts.opacity) !== null && _d !== void 0 ? _d : 0.9;
|
|
57846
|
+
uniforms.u_dvr_density.value = (_e = opts.dvrDensity) !== null && _e !== void 0 ? _e : 0.25;
|
|
57847
|
+
uniforms.u_dvr_gain.value = (_f = opts.dvrGain) !== null && _f !== void 0 ? _f : 2.5;
|
|
57848
|
+
const material = new ShaderMaterial({
|
|
57849
|
+
uniforms,
|
|
57850
|
+
vertexShader,
|
|
57851
|
+
fragmentShader,
|
|
57852
|
+
// The volume shader marches from the back face inward.
|
|
57853
|
+
side: BackSide,
|
|
57854
|
+
transparent: true,
|
|
57855
|
+
depthWrite: false,
|
|
57856
|
+
// REQUIRED: the MRI plane and the VTK surfaces both write depth (neither sets
|
|
57857
|
+
// depthWrite:false). With depth testing on, back faces sitting behind them are
|
|
57858
|
+
// discarded — and since the ray march is bootstrapped by the back-face fragment,
|
|
57859
|
+
// those pixels cast no ray at all, slicing the cone away exactly over the heart.
|
|
57860
|
+
depthTest: false,
|
|
57861
|
+
});
|
|
57862
|
+
// The shader expects local coords spanning [-0.5, size-0.5] on each axis.
|
|
57863
|
+
const geometry = new BoxGeometry(width, height, depth);
|
|
57864
|
+
geometry.translate(width / 2 - 0.5, height / 2 - 0.5, depth / 2 - 0.5);
|
|
57865
|
+
const mesh = new Mesh(geometry, material);
|
|
57866
|
+
// Re-centre the box on the group origin so `root`'s transform rotates about the
|
|
57867
|
+
// volume's centre rather than its corner.
|
|
57868
|
+
mesh.position.set(-(width - 1) / 2, -(height - 1) / 2, -(depth - 1) / 2);
|
|
57869
|
+
// Draw after the MRI plane (0) and the surfaces (1..n) — see loadAligned4D.
|
|
57870
|
+
mesh.renderOrder = 10;
|
|
57871
|
+
const root = new Group();
|
|
57872
|
+
root.add(mesh);
|
|
57873
|
+
scene.add(root);
|
|
57874
|
+
const frameCount = textures.length;
|
|
57875
|
+
let disposed = false;
|
|
57876
|
+
// --- Path 1: the header actually places the volume, so trust it ------------------
|
|
57877
|
+
//
|
|
57878
|
+
// `mesh` is centred on the group origin, so a point at group-local `p` is voxel
|
|
57879
|
+
// index `p + half`. The header gives voxel -> world, hence root = V2W . T(half).
|
|
57880
|
+
//
|
|
57881
|
+
// A zero Offset with an identity TransformMatrix is NOT treated as a pose: it is
|
|
57882
|
+
// indistinguishable from "nobody filled this in", and silently trusting it would
|
|
57883
|
+
// place an unregistered volume at the world origin while claiming it is registered.
|
|
57884
|
+
//
|
|
57885
|
+
// A pose is equally worthless if it is expressed in a DIFFERENT world frame — same
|
|
57886
|
+
// patient, different scanner, different origin. DICOM proves a shared frame with
|
|
57887
|
+
// FrameOfReferenceUID; MetaImage has no such field, so a producer must carry it across as
|
|
57888
|
+
// a custom line. When the caller names the scene's frame, a missing or mismatched UID
|
|
57889
|
+
// means the header's placement must NOT be trusted.
|
|
57890
|
+
const header = frames[0].header;
|
|
57891
|
+
const expectedUID = opts.expectFrameOfReferenceUID;
|
|
57892
|
+
const { registered, frameVerified, reason } = resolveRegistration(header, expectedUID);
|
|
57893
|
+
if (reason === "frame-missing") {
|
|
57894
|
+
console.warn("raw4DVolume: the .mhd places the volume but declares no FrameOfReferenceUID, so " +
|
|
57895
|
+
"nothing shows it shares the scene's world frame. Treating it as UNREGISTERED. " +
|
|
57896
|
+
`Add 'FrameOfReferenceUID = ${expectedUID}' to the .mhd to accept its pose.`);
|
|
57897
|
+
}
|
|
57898
|
+
else if (reason === "frame-mismatch") {
|
|
57899
|
+
console.warn("raw4DVolume: the .mhd's FrameOfReferenceUID does not match the scene's, so its pose " +
|
|
57900
|
+
"describes a different coordinate system. Treating it as UNREGISTERED.\n" +
|
|
57901
|
+
` volume: ${header.frameOfReferenceUID}\n scene : ${expectedUID}`);
|
|
57902
|
+
}
|
|
57903
|
+
else if (reason === "unverified") {
|
|
57904
|
+
console.warn("raw4DVolume: honouring the .mhd's pose, but no expected FrameOfReferenceUID was " +
|
|
57905
|
+
"supplied, so nothing verified that it shares the scene's world frame.");
|
|
57906
|
+
}
|
|
57907
|
+
if (registered) {
|
|
57908
|
+
const half = new Matrix4().makeTranslation((width - 1) / 2, (height - 1) / 2, (depth - 1) / 2);
|
|
57909
|
+
const voxelToWorld = new Matrix4().fromArray(voxelToWorldMatrix(header));
|
|
57910
|
+
root.matrixAutoUpdate = false;
|
|
57911
|
+
root.matrix.copy(voxelToWorld.multiply(half));
|
|
57912
|
+
root.matrixWorldNeedsUpdate = true;
|
|
57913
|
+
}
|
|
57914
|
+
let warnedManualOverride = false;
|
|
57915
|
+
const applyTransform = (t) => {
|
|
57916
|
+
if (registered) {
|
|
57917
|
+
if (!warnedManualOverride) {
|
|
57918
|
+
warnedManualOverride = true;
|
|
57919
|
+
console.warn("raw4DVolume: ignoring manual transform — this volume is placed by its .mhd " +
|
|
57920
|
+
"Offset/TransformMatrix. Strip those fields to pose it by hand.");
|
|
57921
|
+
}
|
|
57922
|
+
return;
|
|
57923
|
+
}
|
|
57924
|
+
if (t.position)
|
|
57925
|
+
root.position.set(t.position[0], t.position[1], t.position[2]);
|
|
57926
|
+
// quaternion wins: aligning the cone axis to an arbitrary world direction is
|
|
57927
|
+
// natural as a quaternion and awkward as Euler angles.
|
|
57928
|
+
if (t.quaternion) {
|
|
57929
|
+
root.quaternion.set(t.quaternion[0], t.quaternion[1], t.quaternion[2], t.quaternion[3]);
|
|
57930
|
+
}
|
|
57931
|
+
else if (t.rotation) {
|
|
57932
|
+
root.rotation.set(t.rotation[0], t.rotation[1], t.rotation[2]);
|
|
57933
|
+
}
|
|
57934
|
+
if (t.scale !== undefined) {
|
|
57935
|
+
typeof t.scale === "number"
|
|
57936
|
+
? root.scale.setScalar(t.scale)
|
|
57937
|
+
: root.scale.set(t.scale[0], t.scale[1], t.scale[2]);
|
|
57938
|
+
}
|
|
57939
|
+
};
|
|
57940
|
+
// Callers may always pass a fallback pose; a registered header simply wins, quietly.
|
|
57941
|
+
if (!registered && opts.transform)
|
|
57942
|
+
applyTransform(opts.transform);
|
|
57943
|
+
const setFrame = (i) => {
|
|
57944
|
+
if (disposed)
|
|
57945
|
+
return;
|
|
57946
|
+
const index = ((i % frameCount) + frameCount) % frameCount;
|
|
57947
|
+
uniforms.u_data.value = textures[index];
|
|
57948
|
+
};
|
|
57949
|
+
const ctrl = {
|
|
57950
|
+
root,
|
|
57951
|
+
mesh,
|
|
57952
|
+
frameCount,
|
|
57953
|
+
registered,
|
|
57954
|
+
frameVerified,
|
|
57955
|
+
frameOfReferenceUID: header.frameOfReferenceUID,
|
|
57956
|
+
setFrame,
|
|
57957
|
+
setPhase: (p) => setFrame(Math.floor(p * frameCount)),
|
|
57958
|
+
setOpacity: (v) => {
|
|
57959
|
+
if (disposed)
|
|
57960
|
+
return;
|
|
57961
|
+
uniforms.u_opacity.value = v;
|
|
57962
|
+
},
|
|
57963
|
+
setClim: (lo, hi) => {
|
|
57964
|
+
if (disposed)
|
|
57965
|
+
return;
|
|
57966
|
+
// three's apply_colormap divides by (hi - lo); keep the span non-zero.
|
|
57967
|
+
uniforms.u_clim.value.set(lo, Math.max(hi, lo + 1e-3));
|
|
57968
|
+
},
|
|
57969
|
+
setRenderStyle: (s) => {
|
|
57970
|
+
if (disposed)
|
|
57971
|
+
return;
|
|
57972
|
+
uniforms.u_renderstyle.value = RENDER_STYLE[s];
|
|
57973
|
+
},
|
|
57974
|
+
setDvrDensity: (v) => {
|
|
57975
|
+
if (disposed)
|
|
57976
|
+
return;
|
|
57977
|
+
uniforms.u_dvr_density.value = v;
|
|
57978
|
+
},
|
|
57979
|
+
setDvrGain: (v) => {
|
|
57980
|
+
if (disposed)
|
|
57981
|
+
return;
|
|
57982
|
+
uniforms.u_dvr_gain.value = v;
|
|
57983
|
+
},
|
|
57984
|
+
setTransform: (t) => {
|
|
57985
|
+
if (disposed)
|
|
57986
|
+
return;
|
|
57987
|
+
applyTransform(t);
|
|
57988
|
+
},
|
|
57989
|
+
dispose: () => {
|
|
57990
|
+
if (disposed)
|
|
57991
|
+
return;
|
|
57992
|
+
disposed = true;
|
|
57993
|
+
scene.remove(root);
|
|
57994
|
+
root.remove(mesh);
|
|
57995
|
+
geometry.dispose();
|
|
57996
|
+
material.dispose();
|
|
57997
|
+
colormap.dispose();
|
|
57998
|
+
textures.forEach((t) => t.dispose());
|
|
57999
|
+
textures.length = 0;
|
|
58000
|
+
},
|
|
58001
|
+
};
|
|
58002
|
+
callback && callback(ctrl);
|
|
58003
|
+
})
|
|
58004
|
+
.catch((err) => {
|
|
58005
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
58006
|
+
if (opts.onError) {
|
|
58007
|
+
opts.onError(error);
|
|
58008
|
+
}
|
|
58009
|
+
else {
|
|
58010
|
+
throw error;
|
|
58011
|
+
}
|
|
58012
|
+
});
|
|
58013
|
+
}
|
|
58014
|
+
|
|
57413
58015
|
class VTKLoader extends Loader {
|
|
57414
58016
|
|
|
57415
58017
|
constructor( manager ) {
|
|
@@ -62870,12 +63472,12 @@ class copperScene extends baseScene {
|
|
|
62870
63472
|
applyFrame();
|
|
62871
63473
|
}
|
|
62872
63474
|
};
|
|
62873
|
-
this.addPreRenderCallbackFunction(tick);
|
|
62874
|
-
const clockId = tick.id;
|
|
63475
|
+
const clockId = this.addPreRenderCallbackFunction(tick);
|
|
62875
63476
|
const ctrl = {
|
|
62876
63477
|
plane: tex.mesh,
|
|
62877
63478
|
surfaceMeshes,
|
|
62878
63479
|
frameCount,
|
|
63480
|
+
frameOfReferenceUID: stacked.frameOfReferenceUID,
|
|
62879
63481
|
play: () => {
|
|
62880
63482
|
playing = true;
|
|
62881
63483
|
lastStep = performance.now();
|
|
@@ -62904,6 +63506,9 @@ class copperScene extends baseScene {
|
|
|
62904
63506
|
setWindow: (center, width) => {
|
|
62905
63507
|
tex.setWindow(center, width);
|
|
62906
63508
|
},
|
|
63509
|
+
setPlaneBrightness: (v) => {
|
|
63510
|
+
tex.setBrightness(v);
|
|
63511
|
+
},
|
|
62907
63512
|
setPlaneOpacity: (v) => {
|
|
62908
63513
|
const m = tex.mesh.material;
|
|
62909
63514
|
m.transparent = v < 1;
|
|
@@ -62945,6 +63550,14 @@ class copperScene extends baseScene {
|
|
|
62945
63550
|
callback && callback(ctrl);
|
|
62946
63551
|
});
|
|
62947
63552
|
}
|
|
63553
|
+
/**
|
|
63554
|
+
* Load a 4D volume sequence (.mhd/.raw per cardiac phase) and render it as a raycast
|
|
63555
|
+
* volume. The returned controller runs no clock of its own — drive it with
|
|
63556
|
+
* setFrame()/setPhase() so it can share a cardiac-phase clock with other modalities.
|
|
63557
|
+
*/
|
|
63558
|
+
loadRaw4DVolume(mhdUrls, opts, callback) {
|
|
63559
|
+
loadRaw4DVolume(mhdUrls, this.scene, opts, callback);
|
|
63560
|
+
}
|
|
62948
63561
|
getPlayRate() {
|
|
62949
63562
|
return this.playRate;
|
|
62950
63563
|
}
|
|
@@ -63343,21 +63956,7 @@ class copperMScene extends commonScene {
|
|
|
63343
63956
|
this.controls.rotateSpeed = 0.02;
|
|
63344
63957
|
this.controls.staticMoving = true;
|
|
63345
63958
|
// this.controls = new OrbitControls(this.camera, this.container);
|
|
63346
|
-
this.preRenderCallbackFunctions =
|
|
63347
|
-
index: 0,
|
|
63348
|
-
cache: [],
|
|
63349
|
-
add(fn) {
|
|
63350
|
-
if (!fn.id) {
|
|
63351
|
-
fn.id = ++this.index;
|
|
63352
|
-
this.cache[fn.id] = fn;
|
|
63353
|
-
return;
|
|
63354
|
-
}
|
|
63355
|
-
},
|
|
63356
|
-
remove(id) {
|
|
63357
|
-
if (this.cache[id])
|
|
63358
|
-
delete this.cache[id];
|
|
63359
|
-
},
|
|
63360
|
-
};
|
|
63959
|
+
this.preRenderCallbackFunctions = createPreRenderRegistry();
|
|
63361
63960
|
this.init();
|
|
63362
63961
|
}
|
|
63363
63962
|
init() {
|
|
@@ -63730,36 +64329,6 @@ class copperMSceneRenderer {
|
|
|
63730
64329
|
}
|
|
63731
64330
|
}
|
|
63732
64331
|
|
|
63733
|
-
/******************************************************************************
|
|
63734
|
-
Copyright (c) Microsoft Corporation.
|
|
63735
|
-
|
|
63736
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
63737
|
-
purpose with or without fee is hereby granted.
|
|
63738
|
-
|
|
63739
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
63740
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
63741
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
63742
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
63743
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
63744
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
63745
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
63746
|
-
***************************************************************************** */
|
|
63747
|
-
|
|
63748
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
63749
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
63750
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
63751
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
63752
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
63753
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
63754
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
63755
|
-
});
|
|
63756
|
-
}
|
|
63757
|
-
|
|
63758
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
63759
|
-
var e = new Error(message);
|
|
63760
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
63761
|
-
};
|
|
63762
|
-
|
|
63763
64332
|
var bundle = createCommonjsModule(function (module, exports) {
|
|
63764
64333
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
63765
64334
|
module.exports = factory();
|
|
@@ -83987,15 +84556,15 @@ function evaluateElement(element, weights) {
|
|
|
83987
84556
|
}
|
|
83988
84557
|
|
|
83989
84558
|
// import * as kiwrious from "copper3d_plugin_heart_k";
|
|
83990
|
-
// "v3.
|
|
84559
|
+
// "v3.7.0" is injected at build time by rollup @rollup/plugin-replace, sourced from package.json version.
|
|
83991
84560
|
// When copper3d is consumed from local source (no rollup replace step), the identifier is undefined and
|
|
83992
84561
|
// referencing it throws a ReferenceError — guard it so local loading still works.
|
|
83993
84562
|
let _revision = "unknown";
|
|
83994
84563
|
try {
|
|
83995
|
-
_revision = "v3.
|
|
84564
|
+
_revision = "v3.7.0";
|
|
83996
84565
|
}
|
|
83997
84566
|
catch (_a) {
|
|
83998
|
-
/* "v3.
|
|
84567
|
+
/* "v3.7.0" not injected (local source build) */
|
|
83999
84568
|
}
|
|
84000
84569
|
const REVISION = _revision;
|
|
84001
84570
|
// Expose on global so the version can be read in a production browser console via window.__COPPER3D_VERSION__
|