copper3d 3.11.4 → 3.11.6
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/README.md +51 -1
- package/ai-index/guides/4D-MRI-LV-rendering.md +1 -1
- package/ai-index/guides/copper3d-rendering-optimization.md +37 -0
- package/ai-index/guides/load-callbacks.md +35 -0
- package/ai-index/guides/nrrd-tools.md +110 -2
- package/ai-index/guides/segmentation-module.md +108 -2
- package/ai-index/manifest.json +8 -8
- package/ai-index/symbols.json +1 -1
- package/dist/Loader/copperNrrdLoader.d.ts +33 -0
- package/dist/Loader/copperNrrdLoader.js +27 -5
- package/dist/Loader/copperNrrdLoader.js.map +1 -1
- package/dist/Renderer/copperRenderer.js +2 -2
- package/dist/Renderer/copperRenderer.js.map +1 -1
- package/dist/Scene/copperScene.d.ts +1 -1
- package/dist/Scene/copperScene.js +4 -1
- package/dist/Scene/copperScene.js.map +1 -1
- package/dist/Utils/segmentation/DragOperator.d.ts +6 -0
- package/dist/Utils/segmentation/DragOperator.js +9 -0
- package/dist/Utils/segmentation/DragOperator.js.map +1 -1
- package/dist/Utils/segmentation/NrrdTools.d.ts +38 -1
- package/dist/Utils/segmentation/NrrdTools.js +105 -2
- package/dist/Utils/segmentation/NrrdTools.js.map +1 -1
- package/dist/Utils/segmentation/RenderingUtils.d.ts +7 -10
- package/dist/Utils/segmentation/RenderingUtils.js +14 -117
- package/dist/Utils/segmentation/RenderingUtils.js.map +1 -1
- package/dist/Utils/segmentation/contourPaint.d.ts +37 -0
- package/dist/Utils/segmentation/contourPaint.js +128 -0
- package/dist/Utils/segmentation/contourPaint.js.map +1 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js +5 -0
- package/dist/Utils/segmentation/tools/DragSliceTool.js.map +1 -1
- package/dist/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
- package/dist/Utils/segmentation/tools/MaskMirror.js +165 -0
- package/dist/Utils/segmentation/tools/MaskMirror.js.map +1 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js +8 -0
- package/dist/Utils/segmentation/tools/SliceRenderPipeline.js.map +1 -1
- package/dist/Utils/segmentation/tools/ToolHost.d.ts +10 -2
- package/dist/bundle.esm.js +459 -122
- package/dist/bundle.umd.js +459 -121
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/Loader/copperNrrdLoader.d.ts +33 -0
- package/dist/types/Scene/copperScene.d.ts +1 -1
- package/dist/types/Utils/segmentation/DragOperator.d.ts +6 -0
- package/dist/types/Utils/segmentation/NrrdTools.d.ts +38 -1
- package/dist/types/Utils/segmentation/RenderingUtils.d.ts +7 -10
- package/dist/types/Utils/segmentation/contourPaint.d.ts +37 -0
- package/dist/types/Utils/segmentation/tools/MaskMirror.d.ts +42 -0
- package/dist/types/Utils/segmentation/tools/ToolHost.d.ts +10 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* Outline stroke width, in screen pixels.
|
|
4
|
-
*
|
|
5
|
-
* Screen pixels rather than voxels so magnifying the image does not thicken the line over the
|
|
6
|
-
* boundary the clinician magnified it to see. Thin enough to sit on an edge, thick enough to
|
|
7
|
-
* stay visible against bright tissue.
|
|
8
|
-
*/
|
|
9
|
-
const OUTLINE_WIDTH_PX = 1.5;
|
|
1
|
+
import { contourEntry, paintContours } from "./contourPaint";
|
|
10
2
|
/**
|
|
11
3
|
* RenderingUtils — Rendering / slice-buffer helper methods.
|
|
12
4
|
*
|
|
@@ -21,6 +13,10 @@ export class RenderingUtils {
|
|
|
21
13
|
constructor(state) {
|
|
22
14
|
/** Injected callback — set by owner after construction. */
|
|
23
15
|
this.setEmptyCanvasSize = () => { };
|
|
16
|
+
/** Set while this viewer draws another viewer's masks; painted after this viewer's own layers. */
|
|
17
|
+
this.mirror = null;
|
|
18
|
+
/** Called after every composite. The owner refreshes the viewers mirroring this one. */
|
|
19
|
+
this.onComposited = null;
|
|
24
20
|
// Reusable ImageData buffer for zero-allocation slice rendering
|
|
25
21
|
this._reusableSliceBuffer = null;
|
|
26
22
|
this._reusableBufferWidth = 0;
|
|
@@ -55,7 +51,8 @@ export class RenderingUtils {
|
|
|
55
51
|
* Get MaskVolume for a specific layer
|
|
56
52
|
*
|
|
57
53
|
* @param layer - Layer name: "layer1", "layer2", or "layer3"
|
|
58
|
-
* @returns MaskVolume instance for the specified layer
|
|
54
|
+
* @returns MaskVolume instance for the specified layer; `undefined` on a
|
|
55
|
+
* read-only engine built with no layers, which has no volume to return
|
|
59
56
|
*/
|
|
60
57
|
getVolumeForLayer(layer) {
|
|
61
58
|
const { volumes } = this.state.protectedData.maskData;
|
|
@@ -63,6 +60,8 @@ export class RenderingUtils {
|
|
|
63
60
|
if (vol)
|
|
64
61
|
return vol;
|
|
65
62
|
const firstLayerId = this.state.nrrd_states.image.layers[0];
|
|
63
|
+
if (firstLayerId === undefined)
|
|
64
|
+
return vol;
|
|
66
65
|
console.warn(`RenderingUtils: unknown layer "${layer}", falling back to "${firstLayerId}"`);
|
|
67
66
|
return volumes[firstLayerId];
|
|
68
67
|
}
|
|
@@ -130,22 +129,6 @@ export class RenderingUtils {
|
|
|
130
129
|
return null; // Volume not ready
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Populate one cache entry's paths for one render mode.
|
|
135
|
-
*
|
|
136
|
-
* Split out because the two modes are built at different times: whichever is in use when
|
|
137
|
-
* a slice is first drawn, and the other one only if the clinician switches while still on
|
|
138
|
-
* that slice. Building both eagerly would make every slice scrub pay for a mode most
|
|
139
|
-
* sessions never turn on.
|
|
140
|
-
*/
|
|
141
|
-
buildPaths(entry, data, stride, outline) {
|
|
142
|
-
const target = outline ? entry.outlines : entry.fills;
|
|
143
|
-
for (const lbl of entry.labels) {
|
|
144
|
-
target.set(lbl, outline
|
|
145
|
-
? extractLabelOutline(data, entry.W, entry.H, lbl, stride, 0)
|
|
146
|
-
: extractLabelContours(data, entry.W, entry.H, lbl, stride, 0));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
132
|
/**
|
|
150
133
|
* Render a layer's slice onto the target canvas as vector contours.
|
|
151
134
|
*
|
|
@@ -183,96 +166,8 @@ export class RenderingUtils {
|
|
|
183
166
|
const volume = this.getVolumeForLayer(layer);
|
|
184
167
|
if (!volume)
|
|
185
168
|
return;
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
// Cache miss → run the expensive extraction once. Hits (zoom,
|
|
189
|
-
// recomposite, contrast toggle) skip straight to the draw below.
|
|
190
|
-
let entry = this._contourCache.get(layer);
|
|
191
|
-
if (!entry || entry.key !== cacheKey) {
|
|
192
|
-
const slice = volume.getSliceUint8(sliceIndex, axis);
|
|
193
|
-
entry = {
|
|
194
|
-
key: cacheKey,
|
|
195
|
-
W: slice.width,
|
|
196
|
-
H: slice.height,
|
|
197
|
-
labels: findLabelsInSlice(slice.data, slice.width, slice.height, stride, 0),
|
|
198
|
-
fills: new Map(),
|
|
199
|
-
outlines: new Map(),
|
|
200
|
-
};
|
|
201
|
-
this._contourCache.set(layer, entry);
|
|
202
|
-
this.buildPaths(entry, slice.data, stride, outline);
|
|
203
|
-
}
|
|
204
|
-
else if ((outline ? entry.outlines : entry.fills).size !== entry.labels.length) {
|
|
205
|
-
// The mode changed since this slice was last drawn, so the other set of
|
|
206
|
-
// paths is cached and this one is not. Re-read the slice and build it; from
|
|
207
|
-
// here on both are present and toggling is a pure cache hit.
|
|
208
|
-
const slice = volume.getSliceUint8(sliceIndex, axis);
|
|
209
|
-
this.buildPaths(entry, slice.data, stride, outline);
|
|
210
|
-
}
|
|
211
|
-
if (entry.labels.length === 0)
|
|
212
|
-
return;
|
|
213
|
-
const { W, H, labels } = entry;
|
|
214
|
-
const paths = outline ? entry.outlines : entry.fills;
|
|
215
|
-
const channelVis = this.state.gui_states.layerChannel.channelVisibility[layer];
|
|
216
|
-
targetCtx.save();
|
|
217
|
-
// Vector drawing — imageSmoothingEnabled is irrelevant here, but keep
|
|
218
|
-
// it off to match the rest of the pipeline.
|
|
219
|
-
targetCtx.imageSmoothingEnabled = false;
|
|
220
|
-
if (outline) {
|
|
221
|
-
// Stroke on an UNTRANSFORMED context, with the voxel→display mapping carried
|
|
222
|
-
// in the path instead. `lineWidth` is then measured in screen pixels, which
|
|
223
|
-
// is what the other two options get wrong: stroking under `ctx.scale(sx, sy)`
|
|
224
|
-
// thickens the line with the zoom, exactly when the clinician has magnified
|
|
225
|
-
// the image to look at the boundary — and because voxels are rarely isotropic
|
|
226
|
-
// (sx !== sy), it also comes out thicker in one axis than the other.
|
|
227
|
-
const matrix = new DOMMatrix();
|
|
228
|
-
if (axis === 'y') {
|
|
229
|
-
matrix.scaleSelf(1, -1);
|
|
230
|
-
matrix.translateSelf(0, -scaledHeight);
|
|
231
|
-
}
|
|
232
|
-
matrix.scaleSelf(scaledWidth / W, scaledHeight / H);
|
|
233
|
-
targetCtx.lineWidth = OUTLINE_WIDTH_PX;
|
|
234
|
-
// Segments are emitted per cell and meet at shared endpoints; round caps
|
|
235
|
-
// close those joins. Canvas composites a whole Path2D in one pass, so the
|
|
236
|
-
// overlap costs no doubled alpha.
|
|
237
|
-
targetCtx.lineJoin = 'round';
|
|
238
|
-
targetCtx.lineCap = 'round';
|
|
239
|
-
for (const lbl of labels) {
|
|
240
|
-
if (channelVis && channelVis[lbl] === false)
|
|
241
|
-
continue;
|
|
242
|
-
const path = paths.get(lbl);
|
|
243
|
-
if (!path)
|
|
244
|
-
continue;
|
|
245
|
-
const color = volume.getChannelColor(lbl);
|
|
246
|
-
targetCtx.strokeStyle =
|
|
247
|
-
`rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
248
|
-
const display = new Path2D();
|
|
249
|
-
display.addPath(path, matrix);
|
|
250
|
-
targetCtx.stroke(display);
|
|
251
|
-
}
|
|
252
|
-
targetCtx.restore();
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
// Coronal (axis='y') Z-flip: mirrors the flip applied by the write
|
|
256
|
-
// path (syncLayerSliceData). Apply BEFORE the voxel→display scale
|
|
257
|
-
// so the flip operates in display coordinates.
|
|
258
|
-
if (axis === 'y') {
|
|
259
|
-
targetCtx.scale(1, -1);
|
|
260
|
-
targetCtx.translate(0, -scaledHeight);
|
|
261
|
-
}
|
|
262
|
-
// Voxel coord (x ∈ [0, W], y ∈ [0, H]) → display coord.
|
|
263
|
-
targetCtx.scale(scaledWidth / W, scaledHeight / H);
|
|
264
|
-
for (const lbl of labels) {
|
|
265
|
-
if (channelVis && channelVis[lbl] === false)
|
|
266
|
-
continue;
|
|
267
|
-
const path = paths.get(lbl);
|
|
268
|
-
if (!path)
|
|
269
|
-
continue;
|
|
270
|
-
const color = volume.getChannelColor(lbl);
|
|
271
|
-
targetCtx.fillStyle =
|
|
272
|
-
`rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
273
|
-
targetCtx.fill(path, 'nonzero');
|
|
274
|
-
}
|
|
275
|
-
targetCtx.restore();
|
|
169
|
+
const entry = contourEntry(this._contourCache, layer, `${axis}:${sliceIndex}:${volume.getVersion()}`, () => (Object.assign(Object.assign({}, volume.getSliceUint8(sliceIndex, axis)), { stride: volume.getChannels() })), outline);
|
|
170
|
+
paintContours(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, (lbl) => volume.getChannelColor(lbl), this.state.gui_states.layerChannel.channelVisibility[layer]);
|
|
276
171
|
}
|
|
277
172
|
catch (_a) {
|
|
278
173
|
// Slice out of bounds or volume not ready — skip silently
|
|
@@ -312,7 +207,7 @@ export class RenderingUtils {
|
|
|
312
207
|
* Only draws layers whose visibility is enabled.
|
|
313
208
|
*/
|
|
314
209
|
compositeAllLayers() {
|
|
315
|
-
var _a, _b;
|
|
210
|
+
var _a, _b, _c, _d;
|
|
316
211
|
const masterCtx = this.state.protectedData.ctxes.drawingLayerMasterCtx;
|
|
317
212
|
const width = this.state.nrrd_states.view.changedWidth;
|
|
318
213
|
const height = this.state.nrrd_states.view.changedHeight;
|
|
@@ -329,6 +224,8 @@ export class RenderingUtils {
|
|
|
329
224
|
masterCtx.restore();
|
|
330
225
|
}
|
|
331
226
|
}
|
|
227
|
+
(_c = this.mirror) === null || _c === void 0 ? void 0 : _c.paint(masterCtx, width, height);
|
|
228
|
+
(_d = this.onComposited) === null || _d === void 0 ? void 0 : _d.call(this);
|
|
332
229
|
}
|
|
333
230
|
}
|
|
334
231
|
//# sourceMappingURL=RenderingUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderingUtils.js","sourceRoot":"","sources":["../../../src/Utils/segmentation/RenderingUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RenderingUtils.js","sourceRoot":"","sources":["../../../src/Utils/segmentation/RenderingUtils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAqB,MAAM,gBAAgB,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAc;IAyCvB,YAAY,KAAkB;QAtC9B,2DAA2D;QAC3D,uBAAkB,GAAqC,GAAG,EAAE,GAAG,CAAC,CAAC;QAEjE,kGAAkG;QAClG,WAAM,GAAsB,IAAI,CAAC;QAEjC,wFAAwF;QACxF,iBAAY,GAAwB,IAAI,CAAC;QAEzC,gEAAgE;QACxD,yBAAoB,GAAqB,IAAI,CAAC;QAC9C,yBAAoB,GAAW,CAAC,CAAC;QACjC,0BAAqB,GAAW,CAAC,CAAC;QAE1C;;;;;;;;;;;;;;;;;;;;;WAqBG;QACK,kBAAa,GAAG,IAAI,GAAG,EAAwB,CAAC;QAGpD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,oEAAoE;IAEpE;;;;;;OAMG;IACH,iBAAiB,CAAC,KAAa;QAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,aA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M,0CAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7C,MAAA,IAAI,CAAC,YAAY,oDAAI,CAAC;IAC1B,CAAC;CACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RGBAColor } from "./core/types";
|
|
2
|
+
/** One 2D slice of labels: `width × height` cells, `stride` bytes apart, the label at offset 0. */
|
|
3
|
+
export interface LabelSlice {
|
|
4
|
+
data: Uint8Array;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
stride: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Outline stroke width, in screen pixels.
|
|
11
|
+
*
|
|
12
|
+
* Screen pixels rather than voxels so magnifying the image does not thicken the line over the
|
|
13
|
+
* boundary the clinician magnified it to see. Thin enough to sit on an edge, thick enough to
|
|
14
|
+
* stay visible against bright tissue.
|
|
15
|
+
*/
|
|
16
|
+
export declare const OUTLINE_WIDTH_PX = 1.5;
|
|
17
|
+
/**
|
|
18
|
+
* One slice's contours, in voxel coordinates. Fill and outline paths are built lazily and side
|
|
19
|
+
* by side, so switching mode costs one extraction the first time and is a cache hit after.
|
|
20
|
+
*/
|
|
21
|
+
export interface ContourEntry {
|
|
22
|
+
key: string;
|
|
23
|
+
W: number;
|
|
24
|
+
H: number;
|
|
25
|
+
labels: number[];
|
|
26
|
+
/** Silhouettes, to fill. Built on first use of fill mode for this slice. */
|
|
27
|
+
fills: Map<number, Path2D>;
|
|
28
|
+
/** Boundaries, to stroke. Built on first use of outline mode for this slice. */
|
|
29
|
+
outlines: Map<number, Path2D>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The cached contours for `slot` under `key`, extracting on a miss. One entry per slot: a new
|
|
33
|
+
* key overwrites it. `readSlice` is called only when extraction is needed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function contourEntry(cache: Map<string, ContourEntry>, slot: string, key: string, readSlice: () => LabelSlice, outline: boolean): ContourEntry;
|
|
36
|
+
/** Paint an entry's visible labels onto `targetCtx`, scaled from voxels to `scaledWidth × scaledHeight`. */
|
|
37
|
+
export declare function paintContours(entry: ContourEntry, targetCtx: CanvasRenderingContext2D, axis: "x" | "y" | "z", scaledWidth: number, scaledHeight: number, outline: boolean, colorOf: (label: number) => RGBAColor, channelVis?: Record<number, boolean>): void;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { extractLabelContours, extractLabelOutline, findLabelsInSlice } from "./core/MarchingSquares";
|
|
2
|
+
/**
|
|
3
|
+
* Outline stroke width, in screen pixels.
|
|
4
|
+
*
|
|
5
|
+
* Screen pixels rather than voxels so magnifying the image does not thicken the line over the
|
|
6
|
+
* boundary the clinician magnified it to see. Thin enough to sit on an edge, thick enough to
|
|
7
|
+
* stay visible against bright tissue.
|
|
8
|
+
*/
|
|
9
|
+
export const OUTLINE_WIDTH_PX = 1.5;
|
|
10
|
+
/**
|
|
11
|
+
* Populate one cache entry's paths for one render mode.
|
|
12
|
+
*
|
|
13
|
+
* Split out because the two modes are built at different times: whichever is in use when
|
|
14
|
+
* a slice is first drawn, and the other one only if the clinician switches while still on
|
|
15
|
+
* that slice. Building both eagerly would make every slice scrub pay for a mode most
|
|
16
|
+
* sessions never turn on.
|
|
17
|
+
*/
|
|
18
|
+
function buildPaths(entry, data, stride, outline) {
|
|
19
|
+
const target = outline ? entry.outlines : entry.fills;
|
|
20
|
+
for (const lbl of entry.labels) {
|
|
21
|
+
target.set(lbl, outline
|
|
22
|
+
? extractLabelOutline(data, entry.W, entry.H, lbl, stride, 0)
|
|
23
|
+
: extractLabelContours(data, entry.W, entry.H, lbl, stride, 0));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The cached contours for `slot` under `key`, extracting on a miss. One entry per slot: a new
|
|
28
|
+
* key overwrites it. `readSlice` is called only when extraction is needed.
|
|
29
|
+
*/
|
|
30
|
+
export function contourEntry(cache, slot, key, readSlice, outline) {
|
|
31
|
+
// Cache miss → run the expensive extraction once. Hits (zoom,
|
|
32
|
+
// recomposite, contrast toggle) skip straight to the draw.
|
|
33
|
+
let entry = cache.get(slot);
|
|
34
|
+
if (!entry || entry.key !== key) {
|
|
35
|
+
const slice = readSlice();
|
|
36
|
+
entry = {
|
|
37
|
+
key,
|
|
38
|
+
W: slice.width,
|
|
39
|
+
H: slice.height,
|
|
40
|
+
labels: findLabelsInSlice(slice.data, slice.width, slice.height, slice.stride, 0),
|
|
41
|
+
fills: new Map(),
|
|
42
|
+
outlines: new Map(),
|
|
43
|
+
};
|
|
44
|
+
cache.set(slot, entry);
|
|
45
|
+
buildPaths(entry, slice.data, slice.stride, outline);
|
|
46
|
+
}
|
|
47
|
+
else if ((outline ? entry.outlines : entry.fills).size !== entry.labels.length) {
|
|
48
|
+
// The mode changed since this slice was last drawn, so the other set of
|
|
49
|
+
// paths is cached and this one is not. Re-read the slice and build it; from
|
|
50
|
+
// here on both are present and toggling is a pure cache hit.
|
|
51
|
+
const slice = readSlice();
|
|
52
|
+
buildPaths(entry, slice.data, slice.stride, outline);
|
|
53
|
+
}
|
|
54
|
+
return entry;
|
|
55
|
+
}
|
|
56
|
+
/** Paint an entry's visible labels onto `targetCtx`, scaled from voxels to `scaledWidth × scaledHeight`. */
|
|
57
|
+
export function paintContours(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, colorOf, channelVis) {
|
|
58
|
+
if (entry.labels.length === 0)
|
|
59
|
+
return;
|
|
60
|
+
targetCtx.save();
|
|
61
|
+
// A throw (a missing colour, say) must not leave the transform on the target.
|
|
62
|
+
try {
|
|
63
|
+
drawPaths(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, colorOf, channelVis);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
targetCtx.restore();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function drawPaths(entry, targetCtx, axis, scaledWidth, scaledHeight, outline, colorOf, channelVis) {
|
|
70
|
+
const { W, H, labels } = entry;
|
|
71
|
+
const paths = outline ? entry.outlines : entry.fills;
|
|
72
|
+
// Vector drawing — imageSmoothingEnabled is irrelevant here, but keep
|
|
73
|
+
// it off to match the rest of the pipeline.
|
|
74
|
+
targetCtx.imageSmoothingEnabled = false;
|
|
75
|
+
if (outline) {
|
|
76
|
+
// Stroke on an UNTRANSFORMED context, with the voxel→display mapping carried
|
|
77
|
+
// in the path instead. `lineWidth` is then measured in screen pixels, which
|
|
78
|
+
// is what the other two options get wrong: stroking under `ctx.scale(sx, sy)`
|
|
79
|
+
// thickens the line with the zoom, exactly when the clinician has magnified
|
|
80
|
+
// the image to look at the boundary — and because voxels are rarely isotropic
|
|
81
|
+
// (sx !== sy), it also comes out thicker in one axis than the other.
|
|
82
|
+
const matrix = new DOMMatrix();
|
|
83
|
+
if (axis === "y") {
|
|
84
|
+
matrix.scaleSelf(1, -1);
|
|
85
|
+
matrix.translateSelf(0, -scaledHeight);
|
|
86
|
+
}
|
|
87
|
+
matrix.scaleSelf(scaledWidth / W, scaledHeight / H);
|
|
88
|
+
targetCtx.lineWidth = OUTLINE_WIDTH_PX;
|
|
89
|
+
// Segments are emitted per cell and meet at shared endpoints; round caps
|
|
90
|
+
// close those joins. Canvas composites a whole Path2D in one pass, so the
|
|
91
|
+
// overlap costs no doubled alpha.
|
|
92
|
+
targetCtx.lineJoin = "round";
|
|
93
|
+
targetCtx.lineCap = "round";
|
|
94
|
+
for (const lbl of labels) {
|
|
95
|
+
if (channelVis && channelVis[lbl] === false)
|
|
96
|
+
continue;
|
|
97
|
+
const path = paths.get(lbl);
|
|
98
|
+
if (!path)
|
|
99
|
+
continue;
|
|
100
|
+
const color = colorOf(lbl);
|
|
101
|
+
targetCtx.strokeStyle = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
102
|
+
const display = new Path2D();
|
|
103
|
+
display.addPath(path, matrix);
|
|
104
|
+
targetCtx.stroke(display);
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// Coronal (axis='y') Z-flip: mirrors the flip applied by the write
|
|
109
|
+
// path (syncLayerSliceData). Apply BEFORE the voxel→display scale
|
|
110
|
+
// so the flip operates in display coordinates.
|
|
111
|
+
if (axis === "y") {
|
|
112
|
+
targetCtx.scale(1, -1);
|
|
113
|
+
targetCtx.translate(0, -scaledHeight);
|
|
114
|
+
}
|
|
115
|
+
// Voxel coord (x ∈ [0, W], y ∈ [0, H]) → display coord.
|
|
116
|
+
targetCtx.scale(scaledWidth / W, scaledHeight / H);
|
|
117
|
+
for (const lbl of labels) {
|
|
118
|
+
if (channelVis && channelVis[lbl] === false)
|
|
119
|
+
continue;
|
|
120
|
+
const path = paths.get(lbl);
|
|
121
|
+
if (!path)
|
|
122
|
+
continue;
|
|
123
|
+
const color = colorOf(lbl);
|
|
124
|
+
targetCtx.fillStyle = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a / 255})`;
|
|
125
|
+
targetCtx.fill(path, "nonzero");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=contourPaint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contourPaint.js","sourceRoot":"","sources":["../../../src/Utils/segmentation/contourPaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAUtG;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAiBpC;;;;;;;GAOG;AACH,SAAS,UAAU,CAAC,KAAmB,EAAE,IAAgB,EAAE,MAAc,EAAE,OAAgB;IACzF,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACtD,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,CACR,GA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EAAE,CAAC;QACjB,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACvB,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC;IAED,wDAAwD;IACxD,SAAS,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAEnD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,UAAU,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK;YAAE,SAAS;QACtD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,SAAS,CAAC,SAAS,GAAG,QAAQ,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;QACnF,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -53,6 +53,11 @@ export class DragSliceTool extends BaseTool {
|
|
|
53
53
|
}
|
|
54
54
|
let newIndex = view.currentSliceIndex + sliceModifyNum;
|
|
55
55
|
if (newIndex != view.currentSliceIndex || view.showContrast) {
|
|
56
|
+
// While a preview slice is shown the displayed slice has depth 1, so moving it would
|
|
57
|
+
// paint blank; the host fetches the target slice instead.
|
|
58
|
+
const target = Math.min(Math.max(newIndex, view.minIndex), view.maxIndex);
|
|
59
|
+
if (this.callbacks.previewSliceMove(target))
|
|
60
|
+
return;
|
|
56
61
|
if (newIndex > view.maxIndex) {
|
|
57
62
|
newIndex = view.maxIndex;
|
|
58
63
|
view.contrastNum = this.ctx.protectedData.displaySlices.length - 1;
|
|
@@ -1 +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AAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC;YACzC,CAAC;YACD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACtB,IAAI,CAAC,iBAAiB,CAAC,SAAS,GAAG,aAAa,WAAW,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAC7G,mBAAmB,IAAI,CAAC,iBAAiB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnE,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,iBAAiB,CAAC,SAAS,GAAG,UAAU,IAAI,CAAC,iBAAiB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC3F,CAAC;QACH,CAAC;IACH,CAAC;IAED,0BAA0B;QACxB,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,mBAAmB;YACxC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9E,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,mBAAmB,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drawing another viewer's masks, read live through a voxel-to-voxel transform.
|
|
3
|
+
*
|
|
4
|
+
* The transform is a row-major 4×4 from this viewer's voxel (x, y, z, 1) to the source's
|
|
5
|
+
* voxel. Slices are built in `MaskVolume.getSliceUint8`'s layout for this viewer's own grid,
|
|
6
|
+
* so the source's paint code draws them unchanged, flips included.
|
|
7
|
+
*/
|
|
8
|
+
import type { MaskVolume } from "../core/index";
|
|
9
|
+
import type { CanvasState } from "../CanvasState";
|
|
10
|
+
import { type LabelSlice } from "../contourPaint";
|
|
11
|
+
export type Axis = "x" | "y" | "z";
|
|
12
|
+
/** A slice's width and height for `axis`, as `getSliceUint8` lays it out. */
|
|
13
|
+
export declare function sliceDims(dims: ArrayLike<number>, axis: Axis): [number, number];
|
|
14
|
+
/** Whether `m` is the identity within `tol`. No matrix counts as the identity. */
|
|
15
|
+
export declare function isIdentity(m: ArrayLike<number> | null | undefined, tol?: number): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The source's labels on this viewer's slice `index` along `axis`. A cell mapping outside
|
|
18
|
+
* the source is 0. On the same grid with the identity, it is the source's own slice.
|
|
19
|
+
*
|
|
20
|
+
* With a diagonal transform (the axes agree, only scale and offset differ), a mirror voxel
|
|
21
|
+
* coarser than the source shows the first label found among every source voxel it spans, so
|
|
22
|
+
* a finding thinner than the mirror's slice still appears on the slice that contains it.
|
|
23
|
+
* Any other transform samples the nearest source voxel.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mirrorSliceLabels(source: MaskVolume, mirrorDims: ArrayLike<number>, axis: Axis, index: number, m: ArrayLike<number> | null): LabelSlice;
|
|
26
|
+
/**
|
|
27
|
+
* One viewer drawing another's masks. Holds no mask data: every paint reads the source's
|
|
28
|
+
* volumes and display state. A new transform means a new instance, so the cache never holds
|
|
29
|
+
* contours from another transform.
|
|
30
|
+
*/
|
|
31
|
+
export declare class MaskMirror {
|
|
32
|
+
private readonly self;
|
|
33
|
+
readonly source: CanvasState;
|
|
34
|
+
private readonly matrix;
|
|
35
|
+
/** One contour entry per source layer, for the slice last painted. */
|
|
36
|
+
private cache;
|
|
37
|
+
/** The source volume each cache entry was built from; a case load replaces the object. */
|
|
38
|
+
private cachedVolumes;
|
|
39
|
+
constructor(self: CanvasState, source: CanvasState, matrix: ArrayLike<number> | null);
|
|
40
|
+
/** Paint every visible source layer onto `ctx` for this viewer's current axis and slice. */
|
|
41
|
+
paint(ctx: CanvasRenderingContext2D, width: number, height: number): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { contourEntry, paintContours } from "../contourPaint";
|
|
2
|
+
const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
3
|
+
/** A slice's width and height for `axis`, as `getSliceUint8` lays it out. */
|
|
4
|
+
export function sliceDims(dims, axis) {
|
|
5
|
+
const [w, h, d] = [dims[0], dims[1], dims[2]];
|
|
6
|
+
return axis === "z" ? [w, h] : axis === "y" ? [w, d] : [d, h];
|
|
7
|
+
}
|
|
8
|
+
/** Whether `m` is the identity within `tol`. No matrix counts as the identity. */
|
|
9
|
+
export function isIdentity(m, tol = 1e-9) {
|
|
10
|
+
if (!m)
|
|
11
|
+
return true;
|
|
12
|
+
for (let i = 0; i < 16; i++) {
|
|
13
|
+
if (Math.abs(m[i] - IDENTITY[i]) > tol)
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
/** Whether the 3×3 part of a row-major 4×4 is diagonal: each axis maps onto its own axis. */
|
|
19
|
+
function isDiagonal(m, tol = 1e-9) {
|
|
20
|
+
for (const i of [1, 2, 4, 6, 8, 9]) {
|
|
21
|
+
if (Math.abs(m[i]) > tol)
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* For each mirror index along one axis, the inclusive source index range it covers, clamped
|
|
28
|
+
* to the source's extent; `lo > hi` when it covers none. A mirror voxel no larger than a
|
|
29
|
+
* source voxel covers the one nearest its centre; a larger one covers every source voxel
|
|
30
|
+
* whose centre lies within it.
|
|
31
|
+
*/
|
|
32
|
+
function coveredRanges(s, t, count, extent) {
|
|
33
|
+
const lo = new Int32Array(count);
|
|
34
|
+
const hi = new Int32Array(count);
|
|
35
|
+
const half = Math.abs(s) / 2;
|
|
36
|
+
for (let i = 0; i < count; i++) {
|
|
37
|
+
const c = s * i + t;
|
|
38
|
+
let a, b;
|
|
39
|
+
if (Math.abs(s) <= 1) {
|
|
40
|
+
a = b = Math.round(c);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
a = Math.ceil(c - half - 1e-9);
|
|
44
|
+
b = Math.floor(c + half - 1e-9);
|
|
45
|
+
}
|
|
46
|
+
lo[i] = Math.max(a, 0);
|
|
47
|
+
hi[i] = Math.min(b, extent - 1);
|
|
48
|
+
}
|
|
49
|
+
return { lo, hi };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The source's labels on this viewer's slice `index` along `axis`. A cell mapping outside
|
|
53
|
+
* the source is 0. On the same grid with the identity, it is the source's own slice.
|
|
54
|
+
*
|
|
55
|
+
* With a diagonal transform (the axes agree, only scale and offset differ), a mirror voxel
|
|
56
|
+
* coarser than the source shows the first label found among every source voxel it spans, so
|
|
57
|
+
* a finding thinner than the mirror's slice still appears on the slice that contains it.
|
|
58
|
+
* Any other transform samples the nearest source voxel.
|
|
59
|
+
*/
|
|
60
|
+
export function mirrorSliceLabels(source, mirrorDims, axis, index, m) {
|
|
61
|
+
const sd = source.getDimensions();
|
|
62
|
+
if (isIdentity(m) && sd.width === mirrorDims[0] && sd.height === mirrorDims[1] && sd.depth === mirrorDims[2]) {
|
|
63
|
+
const s = source.getSliceUint8(index, axis);
|
|
64
|
+
return { data: s.data, width: s.width, height: s.height, stride: source.getChannels() };
|
|
65
|
+
}
|
|
66
|
+
const mat = m !== null && m !== void 0 ? m : IDENTITY;
|
|
67
|
+
const [W, H] = sliceDims(mirrorDims, axis);
|
|
68
|
+
const raw = source.getRawData();
|
|
69
|
+
const nch = source.getChannels();
|
|
70
|
+
const out = new Uint8Array(W * H);
|
|
71
|
+
if (isDiagonal(mat)) {
|
|
72
|
+
const rx = coveredRanges(mat[0], mat[3], mirrorDims[0], sd.width);
|
|
73
|
+
const ry = coveredRanges(mat[5], mat[7], mirrorDims[1], sd.height);
|
|
74
|
+
const rz = coveredRanges(mat[10], mat[11], mirrorDims[2], sd.depth);
|
|
75
|
+
for (let v = 0; v < H; v++) {
|
|
76
|
+
for (let u = 0; u < W; u++) {
|
|
77
|
+
const x = axis === "x" ? index : u;
|
|
78
|
+
const y = axis === "y" ? index : v;
|
|
79
|
+
const z = axis === "z" ? index : axis === "y" ? v : u;
|
|
80
|
+
let label = 0;
|
|
81
|
+
for (let sz = rz.lo[z]; sz <= rz.hi[z] && !label; sz++) {
|
|
82
|
+
for (let sy = ry.lo[y]; sy <= ry.hi[y] && !label; sy++) {
|
|
83
|
+
for (let sx = rx.lo[x]; sx <= rx.hi[x] && !label; sx++) {
|
|
84
|
+
label = raw[((sz * sd.height + sy) * sd.width + sx) * nch];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
out[v * W + u] = label;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { data: out, width: W, height: H, stride: 1 };
|
|
92
|
+
}
|
|
93
|
+
for (let v = 0; v < H; v++) {
|
|
94
|
+
for (let u = 0; u < W; u++) {
|
|
95
|
+
// Slice cell (u, v) -> this viewer's voxel, per getSliceUint8's layout.
|
|
96
|
+
const x = axis === "x" ? index : u;
|
|
97
|
+
const y = axis === "y" ? index : v;
|
|
98
|
+
const z = axis === "z" ? index : axis === "y" ? v : u;
|
|
99
|
+
const sx = Math.round(mat[0] * x + mat[1] * y + mat[2] * z + mat[3]);
|
|
100
|
+
const sy = Math.round(mat[4] * x + mat[5] * y + mat[6] * z + mat[7]);
|
|
101
|
+
const sz = Math.round(mat[8] * x + mat[9] * y + mat[10] * z + mat[11]);
|
|
102
|
+
if (sx < 0 || sy < 0 || sz < 0 || sx >= sd.width || sy >= sd.height || sz >= sd.depth)
|
|
103
|
+
continue;
|
|
104
|
+
out[v * W + u] = raw[((sz * sd.height + sy) * sd.width + sx) * nch];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { data: out, width: W, height: H, stride: 1 };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* One viewer drawing another's masks. Holds no mask data: every paint reads the source's
|
|
111
|
+
* volumes and display state. A new transform means a new instance, so the cache never holds
|
|
112
|
+
* contours from another transform.
|
|
113
|
+
*/
|
|
114
|
+
export class MaskMirror {
|
|
115
|
+
constructor(self, source, matrix) {
|
|
116
|
+
this.self = self;
|
|
117
|
+
this.source = source;
|
|
118
|
+
this.matrix = matrix;
|
|
119
|
+
/** One contour entry per source layer, for the slice last painted. */
|
|
120
|
+
this.cache = new Map();
|
|
121
|
+
/** The source volume each cache entry was built from; a case load replaces the object. */
|
|
122
|
+
this.cachedVolumes = new Map();
|
|
123
|
+
}
|
|
124
|
+
/** Paint every visible source layer onto `ctx` for this viewer's current axis and slice. */
|
|
125
|
+
paint(ctx, width, height) {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
// The source hides its own layers in sphere mode, so the mirror shows none either.
|
|
128
|
+
if (this.source.gui_states.mode.sphere)
|
|
129
|
+
return;
|
|
130
|
+
const dims = this.self.nrrd_states.image.dimensions;
|
|
131
|
+
if (!dims || dims.length !== 3)
|
|
132
|
+
return;
|
|
133
|
+
const axis = this.self.protectedData.axis;
|
|
134
|
+
const index = this.self.nrrd_states.view.currentSliceIndex;
|
|
135
|
+
const lc = this.source.gui_states.layerChannel;
|
|
136
|
+
const outline = this.source.gui_states.drawing.maskRenderMode === "outline";
|
|
137
|
+
for (const layerId of this.source.nrrd_states.image.layers) {
|
|
138
|
+
if (!lc.layerVisibility[layerId])
|
|
139
|
+
continue;
|
|
140
|
+
const volume = this.source.protectedData.maskData.volumes[layerId];
|
|
141
|
+
if (!volume)
|
|
142
|
+
continue;
|
|
143
|
+
if (this.cachedVolumes.get(layerId) !== volume) {
|
|
144
|
+
this.cache.delete(layerId);
|
|
145
|
+
this.cachedVolumes.set(layerId, volume);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const entry = contourEntry(this.cache, layerId, `${axis}:${index}:${volume.getVersion()}`, () => mirrorSliceLabels(volume, dims, axis, index, this.matrix), outline);
|
|
149
|
+
ctx.save();
|
|
150
|
+
try {
|
|
151
|
+
ctx.globalAlpha = (_b = (_a = lc.layerOpacity) === null || _a === void 0 ? void 0 : _a[layerId]) !== null && _b !== void 0 ? _b : 1;
|
|
152
|
+
paintContours(entry, ctx, axis, width, height, outline, (l) => volume.getChannelColor(l), lc.channelVisibility[layerId]);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
// A throw must not leave this layer's alpha or transform on the master canvas.
|
|
156
|
+
ctx.restore();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (_c) {
|
|
160
|
+
// The source is not ready for this slice: nothing to draw for this layer.
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=MaskMirror.js.map
|