@jax-data-science/sci-image-visualizer 0.12.0 → 0.13.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/esm2022/lib/contracts/region-editor-api.contract.mjs +1 -1
- package/esm2022/lib/contracts/visualizer.contract.mjs +1 -1
- package/esm2022/lib/geometry/reconstruct.mjs +11 -1
- package/esm2022/lib/implementations/napari-js/napari-region-overlay.mjs +18 -6
- package/esm2022/lib/implementations/napari-js/napari-tool-bridge.mjs +29 -14
- package/esm2022/lib/implementations/napari-js/napari-visualizer.service.mjs +6 -1
- package/esm2022/lib/implementations/napari-js/region-overlay/region-svg-renderer.mjs +9 -4
- package/esm2022/lib/region-editor/region-editor.component.mjs +13 -1
- package/esm2022/lib/routing-visualizer.service.mjs +4 -1
- package/esm2022/lib/spatial/spatial-controls.facade.mjs +71 -21
- package/esm2022/lib/spatial/spatial-selection.mjs +70 -1
- package/esm2022/lib/spatial-controls/spatial-controls.component.mjs +53 -11
- package/esm2022/lib/store/region-selection.mjs +21 -4
- package/esm2022/lib/store/region-store.service.mjs +22 -3
- package/esm2022/lib/store/spatial-selection.service.mjs +13 -1
- package/esm2022/lib/toolbar/toolbar-help-dialog/toolbar-help-dialog.component.mjs +3 -3
- package/fesm2022/{jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-a68Hw5rw.mjs → jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-DURPqs5a.mjs} +770 -500
- package/fesm2022/jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-DURPqs5a.mjs.map +1 -0
- package/fesm2022/{jax-data-science-sci-image-visualizer-onnx-sam-session-CvadfzjS.mjs → jax-data-science-sci-image-visualizer-onnx-sam-session-D0IQ6PjZ.mjs} +2 -2
- package/fesm2022/{jax-data-science-sci-image-visualizer-onnx-sam-session-CvadfzjS.mjs.map → jax-data-science-sci-image-visualizer-onnx-sam-session-D0IQ6PjZ.mjs.map} +1 -1
- package/fesm2022/jax-data-science-sci-image-visualizer.mjs +2 -2
- package/lib/contracts/region-editor-api.contract.d.ts +3 -0
- package/lib/contracts/visualizer.contract.d.ts +25 -2
- package/lib/geometry/reconstruct.d.ts +6 -0
- package/lib/implementations/napari-js/napari-region-overlay.d.ts +13 -1
- package/lib/implementations/napari-js/napari-tool-bridge.d.ts +11 -0
- package/lib/implementations/napari-js/napari-visualizer.service.d.ts +3 -0
- package/lib/implementations/napari-js/region-overlay/region-svg-renderer.d.ts +6 -1
- package/lib/routing-visualizer.service.d.ts +1 -0
- package/lib/spatial/spatial-controls.facade.d.ts +16 -2
- package/lib/spatial/spatial-selection.d.ts +16 -1
- package/lib/spatial-controls/spatial-controls.component.d.ts +14 -3
- package/lib/store/region-selection.d.ts +14 -3
- package/lib/store/region-store.service.d.ts +14 -1
- package/lib/store/spatial-selection.service.d.ts +8 -0
- package/package.json +1 -1
- package/fesm2022/jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-a68Hw5rw.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LruCache } from 'napari-js';
|
|
2
2
|
import * as ort from 'onnxruntime-web';
|
|
3
|
-
import { g as getOrtWasmBase, f as fetchModel, r as runEncoder, a as runDecoder } from './jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-
|
|
3
|
+
import { g as getOrtWasmBase, f as fetchModel, r as runEncoder, a as runDecoder } from './jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-DURPqs5a.mjs';
|
|
4
4
|
import '@angular/core';
|
|
5
5
|
import '@angular/common/http';
|
|
6
6
|
import 'rxjs';
|
|
@@ -237,4 +237,4 @@ class OnnxSamSession {
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
export { OnnxSamSession };
|
|
240
|
-
//# sourceMappingURL=jax-data-science-sci-image-visualizer-onnx-sam-session-
|
|
240
|
+
//# sourceMappingURL=jax-data-science-sci-image-visualizer-onnx-sam-session-D0IQ6PjZ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jax-data-science-sci-image-visualizer-onnx-sam-session-CvadfzjS.mjs","sources":["../../src/lib/toolbar/segmentation/pending-calls.ts","../../src/lib/toolbar/segmentation/onnx-sam-session.ts"],"sourcesContent":["/** A reply from the SAM worker: progress for, or the result of, call `id`. */\nexport interface WorkerReply {\n id: number;\n type: string;\n /** Present on `type: 'progress'` replies. */\n fraction?: number;\n /** Present on `type: 'error'` replies. */\n error?: string;\n [key: string]: unknown;\n}\n\ninterface Pending {\n resolve: (reply: WorkerReply) => void;\n reject: (err: Error) => void;\n onProgress?: (fraction: number) => void;\n}\n\n/**\n * Request/response bookkeeping for a worker RPC: each call gets an id and a\n * promise that its reply settles. Every exit path (dispose, a worker crash)\n * must {@link rejectAll}, or awaiting callers never reach their `finally` and a\n * tool's busy flag sticks forever (RT-8).\n */\nexport class PendingCalls {\n private seq = 0;\n private readonly pending = new Map<number, Pending>();\n\n /** Calls still awaiting a reply. */\n get size(): number {\n return this.pending.size;\n }\n\n /** Register a new call; post the message with the returned id. */\n open(onProgress?: (fraction: number) => void): { id: number; promise: Promise<WorkerReply> } {\n const id = ++this.seq;\n const promise = new Promise<WorkerReply>((resolve, reject) => {\n this.pending.set(id, { resolve, reject, onProgress });\n });\n return { id, promise };\n }\n\n /** Route a worker reply to its call: progress, error or result. */\n handle(reply: WorkerReply): void {\n const p = this.pending.get(reply.id);\n if (!p) return;\n if (reply.type === 'progress') {\n p.onProgress?.(reply.fraction ?? 0);\n return;\n }\n this.pending.delete(reply.id);\n if (reply.type === 'error') p.reject(new Error(reply.error ?? 'SAM worker error.'));\n else p.resolve(reply);\n }\n\n /** Reject every pending call with `err` and forget them. */\n rejectAll(err: Error): void {\n const calls = Array.from(this.pending.values());\n this.pending.clear();\n for (const p of calls) p.reject(err);\n }\n}\n","import { LruCache } from 'napari-js';\nimport * as ort from 'onnxruntime-web';\n\nimport { ISamSession, SamEmbedding, SamMaskResult, SamModelDef, SamPrompt } from '../../contracts/sam.contract';\nimport { fetchModel, runEncoder, runDecoder, type CoreEmbedding } from './sam-onnx-core';\nimport { getOrtWasmBase } from './ort-runtime-config';\nimport { PendingCalls, WorkerReply } from './pending-calls';\n\n/**\n * onnxruntime-web implementation of {@link ISamSession} (jit-ui#90), with two\n * execution modes chosen per model:\n *\n * - **in-process** (main thread) — for small WASM models flagged `inProcess`\n * (e.g. micro-sam ViT-T). Fast load + inference with no Web Worker spawn /\n * second ORT runtime / message round-trips; the brief encode runs on the main\n * thread (fine for a tiny model).\n * - **worker** — for WebGPU models (e.g. ViT-B, patho-sam fp16) whose heavy\n * encode would otherwise freeze the tab. Runs in {@link ./onnx-sam.worker} so\n * the UI stays responsive (the spinner animates).\n *\n * Both modes share their inference math via {@link ./sam-onnx-core}. Lazy-imported\n * by the SAM tools so onnxruntime-web / the worker never load in unit tests or\n * the initial bundle.\n */\nexport class OnnxSamSession implements ISamSession {\n private mode: 'inproc' | 'worker' | null = null;\n private loaded = false;\n private inputSize = 1024;\n\n // ── worker mode ──\n private worker: Worker | null = null;\n private readonly calls = new PendingCalls();\n\n // ── in-process mode ──\n private encoder: ort.InferenceSession | null = null;\n private decoder: ort.InferenceSession | null = null;\n private nextToken = 1;\n /** The few most recently used embeddings, by token (one per recently viewed image). */\n private readonly embeddings = new LruCache<CoreEmbedding, number>(3);\n\n async loadModel(model: SamModelDef, onProgress?: (fraction: number) => void): Promise<void> {\n if (!model.encoderUrl || !model.decoderUrl) {\n throw new Error(`SAM model \"${model.id}\" has no ONNX URLs configured.`);\n }\n this.inputSize = model.inputSize;\n const hasGpu = typeof navigator !== 'undefined' && 'gpu' in navigator;\n const eps: string[] = model.encoderProviders ?? (hasGpu ? ['webgpu', 'wasm'] : ['wasm']);\n const usesWebGpu = eps.includes('webgpu');\n // WebGPU must run in the worker (else it freezes the main thread); small\n // WASM models opt into the faster in-process path via `inProcess`.\n this.mode = !usesWebGpu && model.inProcess ? 'inproc' : 'worker';\n\n if (this.mode === 'inproc') {\n ort.env.wasm.wasmPaths = getOrtWasmBase();\n const encBuf = await fetchModel(model.encoderUrl, onProgress, model.revision);\n const decBuf = await fetchModel(model.decoderUrl, undefined, model.revision);\n this.encoder = await ort.InferenceSession.create(encBuf, { executionProviders: eps });\n this.decoder = await ort.InferenceSession.create(decBuf, { executionProviders: ['wasm'] });\n } else {\n await this.call(\n {\n type: 'load',\n encoderUrl: model.encoderUrl,\n decoderUrl: model.decoderUrl,\n revision: model.revision,\n wasmPaths: getOrtWasmBase(),\n inputSize: model.inputSize,\n encoderProviders: model.encoderProviders,\n },\n [],\n onProgress,\n );\n }\n this.loaded = true;\n }\n\n isLoaded(): boolean {\n return this.loaded;\n }\n\n async embed(image: { data: Uint8ClampedArray; width: number; height: number }): Promise<SamEmbedding> {\n if (this.mode === 'inproc') {\n const e = await runEncoder(this.encoder!, image.data, image.width, image.height, this.inputSize);\n const token = this.nextToken++;\n this.embeddings.set(token, e);\n return {\n data: new Float32Array(0),\n dims: e.dims,\n scale: e.scale,\n imageWidth: e.imageWidth,\n imageHeight: e.imageHeight,\n token,\n };\n }\n // worker: transfer the RGBA buffer (callers pass a fresh frame buffer).\n const buffer = image.data.buffer;\n const res = await this.call({ type: 'embed', width: image.width, height: image.height, buffer }, [buffer]);\n return {\n data: new Float32Array(0),\n dims: res['dims'] as number[],\n scale: res['scale'] as number,\n imageWidth: res['imageWidth'] as number,\n imageHeight: res['imageHeight'] as number,\n token: res['token'] as number,\n };\n }\n\n async decode(embedding: SamEmbedding, prompt: SamPrompt): Promise<SamMaskResult> {\n if (this.mode === 'inproc') {\n const e = this.embeddings.get(embedding.token as number);\n if (!e) throw new Error('SAM embedding expired; re-encode the image.');\n return runDecoder(this.decoder!, e, prompt);\n }\n const res = await this.call({ type: 'decode', token: embedding.token, prompt });\n return {\n mask: new Uint8Array(res['buffer'] as ArrayBuffer),\n width: res['width'] as number,\n height: res['height'] as number,\n iou: res['iou'] as number,\n };\n }\n\n /** Release the worker / ORT sessions. Calls still in flight reject (RT-8), so\n * their callers' `finally` blocks run (e.g. a tool's busy flag clears). */\n dispose(): void {\n this.dropWorker(new Error('SAM session disposed'));\n this.encoder?.release?.();\n this.decoder?.release?.();\n this.encoder = this.decoder = null;\n this.embeddings.clear();\n this.loaded = false;\n this.mode = null;\n }\n\n // ── worker plumbing ──────────────────────────────────────────────────────\n private ensureWorker(): Worker {\n if (this.worker) return this.worker;\n const worker = new Worker(new URL('./onnx-sam.worker', import.meta.url), { type: 'module' });\n worker.onmessage = (ev: MessageEvent<WorkerReply>) => this.calls.handle(ev.data);\n worker.onerror = (ev: ErrorEvent) => {\n // A crashed worker can't serve the loaded model any more: drop it, so the\n // next run reloads instead of posting to a dead worker.\n this.dropWorker(new Error(ev.message || 'SAM worker crashed.'));\n this.loaded = false;\n this.mode = null;\n };\n this.worker = worker;\n return worker;\n }\n\n /** Terminate the worker (if any) and reject every call still waiting on it. */\n private dropWorker(err: Error): void {\n this.worker?.terminate();\n this.worker = null;\n this.calls.rejectAll(err);\n }\n\n private call(\n msg: Record<string, unknown>,\n transfer: Transferable[] = [],\n onProgress?: (f: number) => void,\n ): Promise<WorkerReply> {\n const worker = this.ensureWorker();\n const { id, promise } = this.calls.open(onProgress);\n worker.postMessage({ ...msg, id }, transfer);\n return promise;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;AAKG;MACU,YAAY,CAAA;AAAzB,IAAA,WAAA,GAAA;QACU,IAAA,CAAA,GAAG,GAAG,CAAC;AACE,QAAA,IAAA,CAAA,OAAO,GAAG,IAAI,GAAG,EAAmB;IAmCvD;;AAhCE,IAAA,IAAI,IAAI,GAAA;AACN,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI;IAC1B;;AAGA,IAAA,IAAI,CAAC,UAAuC,EAAA;AAC1C,QAAA,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG;QACrB,MAAM,OAAO,GA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B,YAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAClB,QAAA,CAAC;AACD,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;AACpB,QAAA,OAAO,MAAM;IACf;;AAGQ,IAAA,UAAU,CAAC,GAAU,EAAA;AAC3B,QAAA,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE;AACxB,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI;AAClB,QAAA,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;IAC3B;AAEQ,IAAA,IAAI,CACV,GAA4B,EAC5B,QAAA,GAA2B,EAAE,EAC7B,UAAgC,EAAA;AAEhC,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE;AAClC,QAAA,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;AACnD,QAAA,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,GAAG,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC;AAC5C,QAAA,OAAO,OAAO;IAChB;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"jax-data-science-sci-image-visualizer-onnx-sam-session-D0IQ6PjZ.mjs","sources":["../../src/lib/toolbar/segmentation/pending-calls.ts","../../src/lib/toolbar/segmentation/onnx-sam-session.ts"],"sourcesContent":["/** A reply from the SAM worker: progress for, or the result of, call `id`. */\nexport interface WorkerReply {\n id: number;\n type: string;\n /** Present on `type: 'progress'` replies. */\n fraction?: number;\n /** Present on `type: 'error'` replies. */\n error?: string;\n [key: string]: unknown;\n}\n\ninterface Pending {\n resolve: (reply: WorkerReply) => void;\n reject: (err: Error) => void;\n onProgress?: (fraction: number) => void;\n}\n\n/**\n * Request/response bookkeeping for a worker RPC: each call gets an id and a\n * promise that its reply settles. Every exit path (dispose, a worker crash)\n * must {@link rejectAll}, or awaiting callers never reach their `finally` and a\n * tool's busy flag sticks forever (RT-8).\n */\nexport class PendingCalls {\n private seq = 0;\n private readonly pending = new Map<number, Pending>();\n\n /** Calls still awaiting a reply. */\n get size(): number {\n return this.pending.size;\n }\n\n /** Register a new call; post the message with the returned id. */\n open(onProgress?: (fraction: number) => void): { id: number; promise: Promise<WorkerReply> } {\n const id = ++this.seq;\n const promise = new Promise<WorkerReply>((resolve, reject) => {\n this.pending.set(id, { resolve, reject, onProgress });\n });\n return { id, promise };\n }\n\n /** Route a worker reply to its call: progress, error or result. */\n handle(reply: WorkerReply): void {\n const p = this.pending.get(reply.id);\n if (!p) return;\n if (reply.type === 'progress') {\n p.onProgress?.(reply.fraction ?? 0);\n return;\n }\n this.pending.delete(reply.id);\n if (reply.type === 'error') p.reject(new Error(reply.error ?? 'SAM worker error.'));\n else p.resolve(reply);\n }\n\n /** Reject every pending call with `err` and forget them. */\n rejectAll(err: Error): void {\n const calls = Array.from(this.pending.values());\n this.pending.clear();\n for (const p of calls) p.reject(err);\n }\n}\n","import { LruCache } from 'napari-js';\nimport * as ort from 'onnxruntime-web';\n\nimport { ISamSession, SamEmbedding, SamMaskResult, SamModelDef, SamPrompt } from '../../contracts/sam.contract';\nimport { fetchModel, runEncoder, runDecoder, type CoreEmbedding } from './sam-onnx-core';\nimport { getOrtWasmBase } from './ort-runtime-config';\nimport { PendingCalls, WorkerReply } from './pending-calls';\n\n/**\n * onnxruntime-web implementation of {@link ISamSession} (jit-ui#90), with two\n * execution modes chosen per model:\n *\n * - **in-process** (main thread) — for small WASM models flagged `inProcess`\n * (e.g. micro-sam ViT-T). Fast load + inference with no Web Worker spawn /\n * second ORT runtime / message round-trips; the brief encode runs on the main\n * thread (fine for a tiny model).\n * - **worker** — for WebGPU models (e.g. ViT-B, patho-sam fp16) whose heavy\n * encode would otherwise freeze the tab. Runs in {@link ./onnx-sam.worker} so\n * the UI stays responsive (the spinner animates).\n *\n * Both modes share their inference math via {@link ./sam-onnx-core}. Lazy-imported\n * by the SAM tools so onnxruntime-web / the worker never load in unit tests or\n * the initial bundle.\n */\nexport class OnnxSamSession implements ISamSession {\n private mode: 'inproc' | 'worker' | null = null;\n private loaded = false;\n private inputSize = 1024;\n\n // ── worker mode ──\n private worker: Worker | null = null;\n private readonly calls = new PendingCalls();\n\n // ── in-process mode ──\n private encoder: ort.InferenceSession | null = null;\n private decoder: ort.InferenceSession | null = null;\n private nextToken = 1;\n /** The few most recently used embeddings, by token (one per recently viewed image). */\n private readonly embeddings = new LruCache<CoreEmbedding, number>(3);\n\n async loadModel(model: SamModelDef, onProgress?: (fraction: number) => void): Promise<void> {\n if (!model.encoderUrl || !model.decoderUrl) {\n throw new Error(`SAM model \"${model.id}\" has no ONNX URLs configured.`);\n }\n this.inputSize = model.inputSize;\n const hasGpu = typeof navigator !== 'undefined' && 'gpu' in navigator;\n const eps: string[] = model.encoderProviders ?? (hasGpu ? ['webgpu', 'wasm'] : ['wasm']);\n const usesWebGpu = eps.includes('webgpu');\n // WebGPU must run in the worker (else it freezes the main thread); small\n // WASM models opt into the faster in-process path via `inProcess`.\n this.mode = !usesWebGpu && model.inProcess ? 'inproc' : 'worker';\n\n if (this.mode === 'inproc') {\n ort.env.wasm.wasmPaths = getOrtWasmBase();\n const encBuf = await fetchModel(model.encoderUrl, onProgress, model.revision);\n const decBuf = await fetchModel(model.decoderUrl, undefined, model.revision);\n this.encoder = await ort.InferenceSession.create(encBuf, { executionProviders: eps });\n this.decoder = await ort.InferenceSession.create(decBuf, { executionProviders: ['wasm'] });\n } else {\n await this.call(\n {\n type: 'load',\n encoderUrl: model.encoderUrl,\n decoderUrl: model.decoderUrl,\n revision: model.revision,\n wasmPaths: getOrtWasmBase(),\n inputSize: model.inputSize,\n encoderProviders: model.encoderProviders,\n },\n [],\n onProgress,\n );\n }\n this.loaded = true;\n }\n\n isLoaded(): boolean {\n return this.loaded;\n }\n\n async embed(image: { data: Uint8ClampedArray; width: number; height: number }): Promise<SamEmbedding> {\n if (this.mode === 'inproc') {\n const e = await runEncoder(this.encoder!, image.data, image.width, image.height, this.inputSize);\n const token = this.nextToken++;\n this.embeddings.set(token, e);\n return {\n data: new Float32Array(0),\n dims: e.dims,\n scale: e.scale,\n imageWidth: e.imageWidth,\n imageHeight: e.imageHeight,\n token,\n };\n }\n // worker: transfer the RGBA buffer (callers pass a fresh frame buffer).\n const buffer = image.data.buffer;\n const res = await this.call({ type: 'embed', width: image.width, height: image.height, buffer }, [buffer]);\n return {\n data: new Float32Array(0),\n dims: res['dims'] as number[],\n scale: res['scale'] as number,\n imageWidth: res['imageWidth'] as number,\n imageHeight: res['imageHeight'] as number,\n token: res['token'] as number,\n };\n }\n\n async decode(embedding: SamEmbedding, prompt: SamPrompt): Promise<SamMaskResult> {\n if (this.mode === 'inproc') {\n const e = this.embeddings.get(embedding.token as number);\n if (!e) throw new Error('SAM embedding expired; re-encode the image.');\n return runDecoder(this.decoder!, e, prompt);\n }\n const res = await this.call({ type: 'decode', token: embedding.token, prompt });\n return {\n mask: new Uint8Array(res['buffer'] as ArrayBuffer),\n width: res['width'] as number,\n height: res['height'] as number,\n iou: res['iou'] as number,\n };\n }\n\n /** Release the worker / ORT sessions. Calls still in flight reject (RT-8), so\n * their callers' `finally` blocks run (e.g. a tool's busy flag clears). */\n dispose(): void {\n this.dropWorker(new Error('SAM session disposed'));\n this.encoder?.release?.();\n this.decoder?.release?.();\n this.encoder = this.decoder = null;\n this.embeddings.clear();\n this.loaded = false;\n this.mode = null;\n }\n\n // ── worker plumbing ──────────────────────────────────────────────────────\n private ensureWorker(): Worker {\n if (this.worker) return this.worker;\n const worker = new Worker(new URL('./onnx-sam.worker', import.meta.url), { type: 'module' });\n worker.onmessage = (ev: MessageEvent<WorkerReply>) => this.calls.handle(ev.data);\n worker.onerror = (ev: ErrorEvent) => {\n // A crashed worker can't serve the loaded model any more: drop it, so the\n // next run reloads instead of posting to a dead worker.\n this.dropWorker(new Error(ev.message || 'SAM worker crashed.'));\n this.loaded = false;\n this.mode = null;\n };\n this.worker = worker;\n return worker;\n }\n\n /** Terminate the worker (if any) and reject every call still waiting on it. */\n private dropWorker(err: Error): void {\n this.worker?.terminate();\n this.worker = null;\n this.calls.rejectAll(err);\n }\n\n private call(\n msg: Record<string, unknown>,\n transfer: Transferable[] = [],\n onProgress?: (f: number) => void,\n ): Promise<WorkerReply> {\n const worker = this.ensureWorker();\n const { id, promise } = this.calls.open(onProgress);\n worker.postMessage({ ...msg, id }, transfer);\n return promise;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;;;;;AAKG;MACU,YAAY,CAAA;AAAzB,IAAA,WAAA,GAAA;QACU,IAAA,CAAA,GAAG,GAAG,CAAC;AACE,QAAA,IAAA,CAAA,OAAO,GAAG,IAAI,GAAG,EAAmB;IAmCvD;;AAhCE,IAAA,IAAI,IAAI,GAAA;AACN,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI;IAC1B;;AAGA,IAAA,IAAI,CAAC,UAAuC,EAAA;AAC1C,QAAA,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG;QACrB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,KAAI;AAC3D,YAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AACvD,QAAA,CAAC,CAAC;AACF,QAAA,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;IACxB;;AAGA,IAAA,MAAM,CAAC,KAAkB,EAAA;AACvB,QAAA,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;AACpC,QAAA,IAAI,CAAC,CAAC;YAAE;AACR,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE;YAC7B,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;YACnC;QACF;QACA,IAAI,CAAC,OAAO,C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AACnD,QAAA,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,GAAG,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC;AAC5C,QAAA,OAAO,OAAO;IAChB;AACD;;;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { A as ALL_GENES, b as ALL_TOOLBAR_TOOLS, c as ANNOTATION_IMAGE_MAX_DIM, C as CANVAS_TOOL_IDS, d as CELL_SEGMENTER, e as CHANNEL_HISTOGRAM_API, h as CellposeSegmenterService, i as ChannelHistogramComponent, D as DEFAULT_CATEGORICAL_PALETTE, j as DEFAULT_FALLBACK_PALETTE, k as DEFAULT_MUTED_OPACITY, l as DEFAULT_SAM_MODEL_ID, m as DEFAULT_SPATIAL_VIEW, H as HexColorPickerComponent, I as IMAGE_STATE_PORT, n as INSTANCE_SEGMENTER, o as ImageConverterService, L as LUT_COLORS, M as MISSING_COLOR, p as MultiPolygon, N as NAPARI_DECIMATE_OPTIONS, q as NAPARI_DEFAULT_DECIMATE, s as NO_CATEGORY, t as NO_OBSERVATION, P as PLOT_MODE_CONTEXT, u as PLOT_MODE_SESSION, v as PLOT_TYPE_CONTRIBUTIONS, w as PLOT_TYPE_DESCRIPTORS, x as PREFERENCES_PORT, y as PlotType, z as Polygon, B as ProcessingImage, R as REGION_EDITOR_API, E as REGION_IO_PORT, F as REGION_SOURCE_MIN_CHARS, G as Rectangle, J as Region, K as RegionEditorComponent, O as RoutingVisualizerService, S as SAM_MODELS, Q as SEMANTIC_SEGMENTER, T as SPATIAL_DATA_PORT, U as SPATIAL_WIRE_VERSION, V as ShapeSelection, W as SpatialChartsComponent, X as SpatialControlsComponent, Y as SpatialDataHttpService, Z as SpatialSelectionStore, _ as SupersededError, $ as TILE_ACCESS_PORT, a0 as TOOLBAR_TOOLS, a1 as VISUALIZER, a2 as VIZ_ALERT_TOAST_KEY, a3 as VIZ_CONFIG, a4 as VIZ_TOAST_KEY, a5 as ViewerFeature, a6 as VisualizationModule, a7 as VisualizerComponent, a8 as assertManifestVersion, a9 as benefitsFromGrouping, aa as buildOmicsTraces, ab as capabilitiesOf, ac as clearSamModelCache, ad as contrastWindow, ae as contributedPlotTypeOption, af as countMask, ag as cropImage, ah as datasetFromManifest, ai as decodeColumn, aj as decodeCoords, ak as decodeFeatureVector, al as decodePolygons, am as decodeRadius, an as defaultPresetSet, ao as dialogToolContributions, ap as emptySelection, aq as encodeCategorical, ar as encodeContinuous, as as expandZips, at as findColumnMeta, au as getDefaultSamModelId, g as getOrtWasmBase, av as getPlotTypeDescriptor, aw as getSamModel, ax as hasZarrMetadata, ay as hydrateBounds, az as importFile, aA as isBuiltinPlotType, aB as isCanvasToolId, aC as isCategoricalColumn, aD as isContinuousColumn, aE as isDialogToolContribution, aF as isEmptyPresetSet, aG as isLabelVolumeName, aH as isLittleEndian, aI as isNapari3d, aJ as isNapariIsosurface, aK as isNapariScatter, aL as isNapariScatter3d, aM as isNapariSurface, aN as isNapariVolume, aO as isSamModelReady, aP as isSpatialOmics, aQ as isSpatialOmics3d, aR as isThreeDimensional, aS as isZipName, aT as labelClasses, aU as labelSliceGeoJson, aV as lutFor, aW as markerDiameters, aX as maskToIndices, aY as mutedFromSelection, aZ as omicsLayout, a_ as openAnnotations, a$ as openGeoJsonRegionSource, b0 as openHttpRegionSource, b1 as parsePresetSet, b2 as planRegionImport, b3 as pointInRing, b4 as provideVisualization, b5 as readAnnotationSlices, b6 as readLabelVolume, b7 as readOmeZarrLabels, b8 as readZip, b9 as rendererOwnsWheel, ba as resolveCategoryColors, bb as selectByCategory, bc as selectInRegions, bd as setDefaultSamModel, be as setOrtWasmBase, bf as setSamModelUrls, bg as sortToolContributions, bh as visibleToolContributions } from './jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-
|
|
1
|
+
export { A as ALL_GENES, b as ALL_TOOLBAR_TOOLS, c as ANNOTATION_IMAGE_MAX_DIM, C as CANVAS_TOOL_IDS, d as CELL_SEGMENTER, e as CHANNEL_HISTOGRAM_API, h as CellposeSegmenterService, i as ChannelHistogramComponent, D as DEFAULT_CATEGORICAL_PALETTE, j as DEFAULT_FALLBACK_PALETTE, k as DEFAULT_MUTED_OPACITY, l as DEFAULT_SAM_MODEL_ID, m as DEFAULT_SPATIAL_VIEW, H as HexColorPickerComponent, I as IMAGE_STATE_PORT, n as INSTANCE_SEGMENTER, o as ImageConverterService, L as LUT_COLORS, M as MISSING_COLOR, p as MultiPolygon, N as NAPARI_DECIMATE_OPTIONS, q as NAPARI_DEFAULT_DECIMATE, s as NO_CATEGORY, t as NO_OBSERVATION, P as PLOT_MODE_CONTEXT, u as PLOT_MODE_SESSION, v as PLOT_TYPE_CONTRIBUTIONS, w as PLOT_TYPE_DESCRIPTORS, x as PREFERENCES_PORT, y as PlotType, z as Polygon, B as ProcessingImage, R as REGION_EDITOR_API, E as REGION_IO_PORT, F as REGION_SOURCE_MIN_CHARS, G as Rectangle, J as Region, K as RegionEditorComponent, O as RoutingVisualizerService, S as SAM_MODELS, Q as SEMANTIC_SEGMENTER, T as SPATIAL_DATA_PORT, U as SPATIAL_WIRE_VERSION, V as ShapeSelection, W as SpatialChartsComponent, X as SpatialControlsComponent, Y as SpatialDataHttpService, Z as SpatialSelectionStore, _ as SupersededError, $ as TILE_ACCESS_PORT, a0 as TOOLBAR_TOOLS, a1 as VISUALIZER, a2 as VIZ_ALERT_TOAST_KEY, a3 as VIZ_CONFIG, a4 as VIZ_TOAST_KEY, a5 as ViewerFeature, a6 as VisualizationModule, a7 as VisualizerComponent, a8 as assertManifestVersion, a9 as benefitsFromGrouping, aa as buildOmicsTraces, ab as capabilitiesOf, ac as clearSamModelCache, ad as contrastWindow, ae as contributedPlotTypeOption, af as countMask, ag as cropImage, ah as datasetFromManifest, ai as decodeColumn, aj as decodeCoords, ak as decodeFeatureVector, al as decodePolygons, am as decodeRadius, an as defaultPresetSet, ao as dialogToolContributions, ap as emptySelection, aq as encodeCategorical, ar as encodeContinuous, as as expandZips, at as findColumnMeta, au as getDefaultSamModelId, g as getOrtWasmBase, av as getPlotTypeDescriptor, aw as getSamModel, ax as hasZarrMetadata, ay as hydrateBounds, az as importFile, aA as isBuiltinPlotType, aB as isCanvasToolId, aC as isCategoricalColumn, aD as isContinuousColumn, aE as isDialogToolContribution, aF as isEmptyPresetSet, aG as isLabelVolumeName, aH as isLittleEndian, aI as isNapari3d, aJ as isNapariIsosurface, aK as isNapariScatter, aL as isNapariScatter3d, aM as isNapariSurface, aN as isNapariVolume, aO as isSamModelReady, aP as isSpatialOmics, aQ as isSpatialOmics3d, aR as isThreeDimensional, aS as isZipName, aT as labelClasses, aU as labelSliceGeoJson, aV as lutFor, aW as markerDiameters, aX as maskToIndices, aY as mutedFromSelection, aZ as omicsLayout, a_ as openAnnotations, a$ as openGeoJsonRegionSource, b0 as openHttpRegionSource, b1 as parsePresetSet, b2 as planRegionImport, b3 as pointInRing, b4 as provideVisualization, b5 as readAnnotationSlices, b6 as readLabelVolume, b7 as readOmeZarrLabels, b8 as readZip, b9 as rendererOwnsWheel, ba as resolveCategoryColors, bb as selectByCategory, bc as selectInRegions, bd as setDefaultSamModel, be as setOrtWasmBase, bf as setSamModelUrls, bg as sortToolContributions, bh as visibleToolContributions } from './jax-data-science-sci-image-visualizer-jax-data-science-sci-image-visualizer-DURPqs5a.mjs';
|
|
2
2
|
import '@angular/core';
|
|
3
3
|
import '@angular/common/http';
|
|
4
4
|
import 'napari-js';
|
|
5
5
|
import 'rxjs';
|
|
6
6
|
import 'rxjs/operators';
|
|
7
|
-
import 'onnxruntime-web';
|
|
8
7
|
import 'napari-js/geometry';
|
|
8
|
+
import 'onnxruntime-web';
|
|
9
9
|
import 'fast-png';
|
|
10
10
|
import 'fzstd';
|
|
11
11
|
import '@angular/core/rxjs-interop';
|
|
@@ -177,6 +177,9 @@ export interface IRegionEditorApi {
|
|
|
177
177
|
setClassesHidden?(classes: readonly string[], hidden: boolean): void;
|
|
178
178
|
/** Select every region of these classes on the slice, the source's included (taken). */
|
|
179
179
|
selectRegionClasses?(classes: readonly string[], additive?: boolean): Promise<void>;
|
|
180
|
+
/** The classes the selection was picked as by {@link selectRegionClasses}; [] once anything
|
|
181
|
+
* else is selected (a row, a region drawn or clicked). */
|
|
182
|
+
getPickedRegionClasses$?(): Observable<readonly string[]>;
|
|
180
183
|
/** {@link getGeoJsonString} merged with the region source behind the regions (see
|
|
181
184
|
* `RegionStore.getGeoJsonWithSource`); `slice` names a folder stack's slice. */
|
|
182
185
|
getGeoJsonStringWithSource?(regions: Region[], slice?: number): Promise<string>;
|
|
@@ -305,6 +305,12 @@ export interface SpatialCategoricalView {
|
|
|
305
305
|
/** Per-observation category index, or `NO_CATEGORY`. */
|
|
306
306
|
codes: Uint16Array;
|
|
307
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* How "Select from ROIs" selects: inside the volumes of the region classes picked
|
|
310
|
+
* in the Region Editor (Spatial omics 3D, the regions on the dataset's reference
|
|
311
|
+
* volume shown), or by the drawn regions.
|
|
312
|
+
*/
|
|
313
|
+
export type RoiSelectionMode = 'class-volumes' | 'regions';
|
|
308
314
|
/**
|
|
309
315
|
* Controls for the SPATIAL_OMICS plot type: what the observation markers are
|
|
310
316
|
* coloured by, and how they are drawn. Capability-gated like
|
|
@@ -399,9 +405,26 @@ export interface ISpatialControls {
|
|
|
399
405
|
/**
|
|
400
406
|
* Select every observation inside the currently-drawn regions (their union).
|
|
401
407
|
* Reuses the existing ROI tools — rectangle, polygon, freehand, wand, brush —
|
|
402
|
-
* so there is no separate marquee to learn.
|
|
408
|
+
* so there is no separate marquee to learn. In the 3D cloud, the region classes
|
|
409
|
+
* picked in the Region Editor (see {@link getPickedRegionClasses$}) select the
|
|
410
|
+
* observations inside their volumes instead, when the regions sit on the
|
|
411
|
+
* dataset's reference volume; without a pick, the lassos drawn over the cloud.
|
|
412
|
+
* Resolves how many were selected — or null when it was superseded while the
|
|
413
|
+
* classes' outlines were read (a newer selection, a Clear, another dataset, view
|
|
414
|
+
* or pick), in which case nothing was published.
|
|
415
|
+
*/
|
|
416
|
+
selectFromRegions(): Promise<number | null>;
|
|
417
|
+
/**
|
|
418
|
+
* How {@link selectFromRegions} would select now: inside the picked classes'
|
|
419
|
+
* volumes, or by the drawn regions. The rule it runs by, so a panel describing
|
|
420
|
+
* the button can never disagree with what it does.
|
|
421
|
+
*/
|
|
422
|
+
roiSelectionMode?(): RoiSelectionMode;
|
|
423
|
+
/**
|
|
424
|
+
* The region classes the region selection was picked as (a class tree node with
|
|
425
|
+
* its subclasses, a surface clicked in 3D); [] for any other selection.
|
|
403
426
|
*/
|
|
404
|
-
|
|
427
|
+
getPickedRegionClasses$?(): Observable<readonly string[]>;
|
|
405
428
|
/** Select every observation in one category of a categorical column — the
|
|
406
429
|
* legend click. Rejects for an unknown or continuous column. */
|
|
407
430
|
selectCategory(column: string, categoryIndex: number): Promise<number>;
|
|
@@ -28,6 +28,12 @@ export interface ReconstructOptions {
|
|
|
28
28
|
* {@link loftLines}). Empty when no slice has an area and no two slices have lines.
|
|
29
29
|
*/
|
|
30
30
|
export declare function reconstruct(slices: readonly SliceOutlines[], opts?: ReconstructOptions): Mesh;
|
|
31
|
+
/**
|
|
32
|
+
* Fill one slice's outlines into `mask`, a `width × height` grid of image px (pixel i spanning
|
|
33
|
+
* [i, i + 1)), as the reconstruction fills them: each feature even-odd, the features as their
|
|
34
|
+
* union, sampled at pixel centres. Cells already set stay set. Open lines enclose nothing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function fillOutlines(mask: Uint8Array, width: number, height: number, outlines: SliceOutlines): void;
|
|
31
37
|
/**
|
|
32
38
|
* The area inside `rings` (interleaved `x, y`), even-odd: a ring inside an odd number of others is
|
|
33
39
|
* a hole. Exact for rings that do not cross (a polygon set's exteriors and holes).
|
|
@@ -75,8 +75,16 @@ export declare class NapariRegionOverlay implements IRegionOverlay {
|
|
|
75
75
|
/** In-progress manipulation (select/move modes): dragging a body, a polygon vertex, or a
|
|
76
76
|
* rectangle corner. `anchor` is the fixed opposite corner for a rectangle resize. */
|
|
77
77
|
private edit;
|
|
78
|
+
/**
|
|
79
|
+
* Screen space (the 3D view's lassos): the regions this overlay drew itself, by id. Only those
|
|
80
|
+
* are drawn, picked or edited here; every other region in the store is in image space (the
|
|
81
|
+
* image's own, an imported set, structures a tree click took from a source) and means nothing
|
|
82
|
+
* at canvas pixels. Null: every region (world is the image).
|
|
83
|
+
*/
|
|
84
|
+
private readonly own;
|
|
78
85
|
constructor(host: HTMLElement, viewer: OverlayViewer, store: RegionStore, opts?: {
|
|
79
86
|
regionSource?: boolean;
|
|
87
|
+
screenSpace?: boolean;
|
|
80
88
|
});
|
|
81
89
|
/**
|
|
82
90
|
* Whether a region tool currently owns the pointer.
|
|
@@ -115,8 +123,12 @@ export declare class NapariRegionOverlay implements IRegionOverlay {
|
|
|
115
123
|
/** Click-to-place polygon: add a vertex, or close when clicking near the first one. */
|
|
116
124
|
private handlePolygonClick;
|
|
117
125
|
private readonly onDblClick;
|
|
118
|
-
/** The currently-selected region (single selection), or null. */
|
|
126
|
+
/** The currently-selected region (single selection) this overlay draws, or null. */
|
|
119
127
|
private selectedRegion;
|
|
128
|
+
/** Whether this overlay draws (and lets the pointer pick) `region`: see {@link own}. */
|
|
129
|
+
private draws;
|
|
130
|
+
/** The regions this overlay drew in screen space (the 3D view's lassos); [] in image space. */
|
|
131
|
+
ownRegionIds(): number[];
|
|
120
132
|
/**
|
|
121
133
|
* Start a select/move interaction: grab a handle (rectangle corner) or vertex of the already-
|
|
122
134
|
* selected region first; otherwise select the topmost region under the cursor and drag its body.
|
|
@@ -124,8 +124,19 @@ export declare class NapariToolBridge {
|
|
|
124
124
|
* A screen-space shape stops meaning anything the moment the camera moves, so an orbit clears
|
|
125
125
|
* the regions drawn in this view (and only those). The SELECTION they produced is kept: that is
|
|
126
126
|
* the durable artefact, and the highlighted points stay highlighted from every angle.
|
|
127
|
+
*
|
|
128
|
+
* Every other region in the store is in image space - the image's own, an imported set,
|
|
129
|
+
* structures a tree click took from a region source - so the overlay neither draws nor picks it
|
|
130
|
+
* (it would lie flat at canvas pixels over the cloud), and an orbit leaves it alone: they show
|
|
131
|
+
* in 3D as their reconstructions instead.
|
|
127
132
|
*/
|
|
128
133
|
install3dInteraction(viewer: Viewer, host: HTMLElement): void;
|
|
134
|
+
/**
|
|
135
|
+
* Remove the regions the 3D overlay drew in screen space (only those) from the store: a lasso
|
|
136
|
+
* means nothing once the camera it was drawn under moves or the scene goes. Not an edit of the
|
|
137
|
+
* user's: no undo step (NAPARI-SVC-11).
|
|
138
|
+
*/
|
|
139
|
+
private clearOwnLassos;
|
|
129
140
|
/**
|
|
130
141
|
* The {@link OverlayViewer} the 3D region overlay draws through: "world" is the canvas, in
|
|
131
142
|
* canvas-local CSS pixels. A pointer arrives in CLIENT pixels, so `canvasToWorld` subtracts the
|
|
@@ -150,6 +150,9 @@ export declare class NapariVisualizerService extends BaseStoreVisualizer impleme
|
|
|
150
150
|
/** Observations projected to canvas pixels under the 3D camera (the spatial 3D cloud), indexed
|
|
151
151
|
* by observation with NaN for any not drawn; null when no cloud is mounted. */
|
|
152
152
|
getSpatialScreenProjection(obs: SpatialObservations): Float32Array | null;
|
|
153
|
+
/** The ids of the regions drawn over the 3D cloud in screen space (its lassos); [] in 2D. Every
|
|
154
|
+
* other region in the store is in image space, and means nothing at canvas pixels. */
|
|
155
|
+
getSpatialLassoIds(): number[];
|
|
153
156
|
private fitCameraSoon;
|
|
154
157
|
/** @deprecated Plotly-specific; host re-drives plot() from its image stream. */
|
|
155
158
|
reloadAndPlot(): void;
|
|
@@ -24,10 +24,15 @@ export interface RegionDraft {
|
|
|
24
24
|
export declare class NapariRegionSvgRenderer {
|
|
25
25
|
private readonly svg;
|
|
26
26
|
private readonly store;
|
|
27
|
+
private readonly draws;
|
|
27
28
|
private readonly renderer;
|
|
28
29
|
/** Dedicated marquee rect element, updated directly during the drag (no full region redraw). */
|
|
29
30
|
private marqueeEl;
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @param draws which regions are this overlay's to draw (default: every one); the others are
|
|
33
|
+
* left out of the shapes and handles, keeping the store's indices
|
|
34
|
+
*/
|
|
35
|
+
constructor(svg: SVGSVGElement, store: RegionStore, draws?: (region: Region) => boolean);
|
|
31
36
|
/** Follow the camera: one transform attribute plus the screen-space elements. */
|
|
32
37
|
setCamera(affine: Affine): void;
|
|
33
38
|
/** Rebuild the regions (world space) and their labels. */
|
|
@@ -361,6 +361,7 @@ export declare class RoutingVisualizerService implements IVisualizer, IRegionEdi
|
|
|
361
361
|
getHiddenClasses$(): Observable<ReadonlySet<string>>;
|
|
362
362
|
setClassesHidden(classes: readonly string[], hidden: boolean): void;
|
|
363
363
|
selectRegionClasses(classes: readonly string[], additive?: boolean): Promise<void>;
|
|
364
|
+
getPickedRegionClasses$(): Observable<readonly string[]>;
|
|
364
365
|
getGeoJsonStringWithSource(regions: Region[], slice?: number): Promise<string>;
|
|
365
366
|
enterStackMode(slices: Map<number, Region[]>, initialZ?: number, saveLayout?: 'combined' | 'per-slice-file'): void;
|
|
366
367
|
exitStackMode(): void;
|
|
@@ -26,6 +26,11 @@ export interface SpatialRendererFeeds {
|
|
|
26
26
|
};
|
|
27
27
|
/** Observations projected to canvas pixels by the 3D camera, or null when the cloud is not mounted. */
|
|
28
28
|
getSpatialScreenProjection(obs: SpatialObservations): Float32Array | null;
|
|
29
|
+
/** The ids of the regions drawn over the 3D cloud in screen space (its lassos). */
|
|
30
|
+
getSpatialLassoIds(): number[];
|
|
31
|
+
/** Image px per voxel of the volume the region surfaces sit in; null when the plotted image is
|
|
32
|
+
* not a volume's stack (the regions are then not in the reference volume's grid). */
|
|
33
|
+
regionVoxelStep(): number | null;
|
|
29
34
|
}
|
|
30
35
|
/** What the facade works over: the shared stores, the renderer feeds and the router's view state. */
|
|
31
36
|
export interface SpatialControlsContext {
|
|
@@ -53,12 +58,21 @@ export declare class SpatialControlsFacade {
|
|
|
53
58
|
private readonly ctx;
|
|
54
59
|
/** The controls; one object for the facade's life, so consumers can hold it. */
|
|
55
60
|
readonly controls: ISpatialControls;
|
|
56
|
-
/** Latest dataset, mirrored so `selectFromRegions()`
|
|
57
|
-
* runs from a button click and must not await a round-trip. */
|
|
61
|
+
/** Latest dataset, mirrored so `selectFromRegions()` answers from the dataset on
|
|
62
|
+
* screen — it runs from a button click and must not await a round-trip. */
|
|
58
63
|
private dataset;
|
|
59
64
|
private readonly sub;
|
|
65
|
+
/** Bumped per class-volume selection (and on dispose): only the latest may publish. */
|
|
66
|
+
private roiRequest;
|
|
60
67
|
constructor(port: SpatialDataPort, ctx: SpatialControlsContext);
|
|
61
68
|
/** Release the port subscription (the router's injector is being destroyed). */
|
|
62
69
|
dispose(): void;
|
|
70
|
+
/**
|
|
71
|
+
* How "Select from ROIs" selects now — the one rule its executor and the panel's description
|
|
72
|
+
* share: inside the picked classes' volumes in the 3D cloud, when the dataset has a reference
|
|
73
|
+
* volume (and no tissue image) and the plotted image is that volume's stack, so the regions sit
|
|
74
|
+
* in its grid; by the drawn regions otherwise.
|
|
75
|
+
*/
|
|
76
|
+
private roiSelectionMode;
|
|
63
77
|
private build;
|
|
64
78
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Region } from '../models/region';
|
|
2
|
+
import { SliceOutlines } from '../geometry/reconstruct';
|
|
2
3
|
import { RingBounds as Bounds } from '../geometry/ring';
|
|
3
|
-
import { SpatialImageRef, SpatialObservations, SpatialSelectionMask } from '../contracts/spatial-dataset.contract';
|
|
4
|
+
import { SpatialImageRef, SpatialObservations, SpatialSelectionMask, SpatialVolumeMeta } from '../contracts/spatial-dataset.contract';
|
|
4
5
|
/**
|
|
5
6
|
* Which observations fall inside a set of drawn regions.
|
|
6
7
|
*
|
|
@@ -95,6 +96,20 @@ export declare function selectInRegions(observations: SpatialObservations, image
|
|
|
95
96
|
* never selected.
|
|
96
97
|
*/
|
|
97
98
|
export declare function selectInRegionsProjected(screen: Float32Array, count: number, regions: readonly Region[]): SpatialSelectionMask;
|
|
99
|
+
/**
|
|
100
|
+
* Observations inside the VOLUME a stack of outlines encloses: a region class (an
|
|
101
|
+
* atlas structure with its substructures) through every section of the dataset's
|
|
102
|
+
* reference volume, as its 3D reconstruction shows it.
|
|
103
|
+
*
|
|
104
|
+
* The outlines are in the volume's own grid — x, y in voxels, z the slice — which
|
|
105
|
+
* is where regions imported onto the volume's stack sit. An observation is in voxel
|
|
106
|
+
* `(⌊x / vx⌋, ⌊y / vy⌋, ⌊z / vz⌋)` (see `volumeImageRef`), and selected when its
|
|
107
|
+
* slice's outlines cover that voxel, filled as the reconstruction fills them. One
|
|
108
|
+
* slice is rasterised at a time, so a structure through the whole brain costs one
|
|
109
|
+
* slice's mask, not the volume's. An observation outside the volume, or without a
|
|
110
|
+
* z, is never selected.
|
|
111
|
+
*/
|
|
112
|
+
export declare function selectInClassVolumes(observations: SpatialObservations, volume: SpatialVolumeMeta, slices: readonly SliceOutlines[]): SpatialSelectionMask;
|
|
98
113
|
/**
|
|
99
114
|
* Whether two selections hold exactly the same observations.
|
|
100
115
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter, NgZone, OnInit } from '@angular/core';
|
|
2
|
-
import { IVisualizer, ISpatialControls } from '../contracts/visualizer.contract';
|
|
2
|
+
import { IVisualizer, ISpatialControls, RoiSelectionMode } from '../contracts/visualizer.contract';
|
|
3
3
|
import { SpatialDataset } from '../contracts/spatial-dataset.contract';
|
|
4
4
|
import { ColormapNode, SpatialViewState } from '../contracts/display-types';
|
|
5
5
|
import { PanelOption, parseGeneGroups } from '../spatial/spatial-panel-model';
|
|
@@ -81,6 +81,12 @@ export declare class SpatialControlsComponent implements OnInit {
|
|
|
81
81
|
/** An ROI selection that matched nothing, so the UI can say so rather than
|
|
82
82
|
* looking like the button did nothing. */
|
|
83
83
|
protected selectionMissed: boolean;
|
|
84
|
+
/** The mode of the selection that {@link selectionMissed}: what it found nothing inside. */
|
|
85
|
+
protected missedMode: RoiSelectionMode;
|
|
86
|
+
/** The region classes picked in the Region Editor: in 3D, "Select from ROIs" selects inside them. */
|
|
87
|
+
protected pickedClasses: readonly string[];
|
|
88
|
+
/** While "Select from ROIs" reads the picked classes' outlines. */
|
|
89
|
+
protected selectingFromRegions: boolean;
|
|
84
90
|
/**
|
|
85
91
|
* Whether the Distribution section is expanded. Collapsed by default: the
|
|
86
92
|
* panel's primary job is the colour controls, and the chart roughly doubles
|
|
@@ -106,8 +112,13 @@ export declare class SpatialControlsComponent implements OnInit {
|
|
|
106
112
|
onGeneFilter(query: string): Promise<void>;
|
|
107
113
|
/** A gene dropdown opened — see {@link GenePickerModel.ensureList}. */
|
|
108
114
|
ensureGeneList(): Promise<void>;
|
|
109
|
-
/** Select every observation inside the drawn regions (their union)
|
|
110
|
-
|
|
115
|
+
/** Select every observation inside the drawn regions (their union) — in 3D, inside the
|
|
116
|
+
* picked classes' volumes. */
|
|
117
|
+
protected selectFromRegions(): Promise<void>;
|
|
118
|
+
/** In 3D with classes picked, "Select from ROIs" selects inside their volumes. */
|
|
119
|
+
protected get selectsClassVolumes(): boolean;
|
|
120
|
+
/** How "Select from ROIs" selects now: the controls' own rule, the one the selection runs by. */
|
|
121
|
+
private get roiSelectionMode();
|
|
111
122
|
/** Legend click: select one category. Clicking the active row clears it, so a
|
|
112
123
|
* second click is an undo rather than a no-op. */
|
|
113
124
|
protected selectCategory(index: number): Promise<void>;
|
|
@@ -10,18 +10,29 @@ interface HasId {
|
|
|
10
10
|
* owner calls {@link sync} once the region array it projects onto is final,
|
|
11
11
|
* which prunes ids that no longer exist and emits {@link indices$} only when
|
|
12
12
|
* the index set changed.
|
|
13
|
+
*
|
|
14
|
+
* A selection made by picking classes (the class tree, a surface in 3D) also
|
|
15
|
+
* holds those classes: a class is a volume through the whole stack, whether or
|
|
16
|
+
* not it has a region on the slice. Any other selection drops them; an edit
|
|
17
|
+
* ({@link retain}, {@link sync}) keeps them.
|
|
13
18
|
*/
|
|
14
19
|
export declare class RegionSelection {
|
|
15
20
|
private selected;
|
|
21
|
+
private picked;
|
|
16
22
|
private readonly indicesSubject;
|
|
23
|
+
private readonly classesSubject;
|
|
17
24
|
/** The selected regions' current array indices (emits on change only). */
|
|
18
25
|
readonly indices$: Observable<number[]>;
|
|
26
|
+
/** The classes the selection was picked as ([] for any other selection; emits on change only). */
|
|
27
|
+
readonly classes$: Observable<readonly string[]>;
|
|
28
|
+
/** The classes the selection was picked as, as last emitted by {@link sync}. */
|
|
29
|
+
get classes(): readonly string[];
|
|
19
30
|
/** The selected indices as last projected by {@link sync}. */
|
|
20
31
|
get indices(): number[];
|
|
21
32
|
/** The selected ids, in selection order. */
|
|
22
33
|
get ids(): readonly number[];
|
|
23
|
-
/** Replace the selected ids (no emit until {@link sync}). */
|
|
24
|
-
replace(ids: number[]): void;
|
|
34
|
+
/** Replace the selected ids, picked as `classes` if they were (no emit until {@link sync}). */
|
|
35
|
+
replace(ids: number[], classes?: readonly string[]): void;
|
|
25
36
|
/** Keep only the ids `keep` accepts (no emit until {@link sync}). */
|
|
26
37
|
retain(keep: (id: number) => boolean): void;
|
|
27
38
|
/**
|
|
@@ -30,7 +41,7 @@ export declare class RegionSelection {
|
|
|
30
41
|
*/
|
|
31
42
|
selectIndices(indices: number[], regions: readonly HasId[]): void;
|
|
32
43
|
/** Project the selected ids onto `regions`, pruning ids it no longer holds,
|
|
33
|
-
* and emit if the index set changed. */
|
|
44
|
+
* and emit if the index set (or the picked classes) changed. */
|
|
34
45
|
sync(regions: readonly HasId[]): void;
|
|
35
46
|
}
|
|
36
47
|
export {};
|
|
@@ -377,9 +377,22 @@ export declare class RegionStore implements IRegionStore, IRegionEditApi, IRegio
|
|
|
377
377
|
/**
|
|
378
378
|
* Select every region of these classes on the slice — the regions', and the region source's,
|
|
379
379
|
* which are taken into the regions (at most {@link SELECT_CLASSES_LIMIT} of them). Added to the
|
|
380
|
-
* selection with `additive`.
|
|
380
|
+
* selection with `additive`. The selection holds the classes too (see {@link getPickedClasses}).
|
|
381
|
+
* Resolves the selected region ids.
|
|
381
382
|
*/
|
|
382
383
|
selectClasses(classes: readonly string[], additive?: boolean): Promise<number[]>;
|
|
384
|
+
/**
|
|
385
|
+
* The classes the selection was picked as by {@link selectClasses} (a class tree node with its
|
|
386
|
+
* subclasses, a surface clicked in 3D); [] once anything else selected. Each is a volume through
|
|
387
|
+
* the whole stack, whether or not it has a region on the slice.
|
|
388
|
+
*/
|
|
389
|
+
getPickedClasses(): readonly string[];
|
|
390
|
+
getPickedClasses$(): Observable<readonly string[]>;
|
|
391
|
+
/**
|
|
392
|
+
* Every slice's exact outlines of these classes, the region sources' and the regions' (as the
|
|
393
|
+
* 3D reconstruction reads them at the stack's own resolution): what is inside their volume.
|
|
394
|
+
*/
|
|
395
|
+
classSliceOutlines(classes: readonly string[]): Promise<SliceOutlines[]>;
|
|
383
396
|
/**
|
|
384
397
|
* The 3D reconstruction of each group of classes over every slice of the stack (an atlas
|
|
385
398
|
* structure with its substructures, say): the outlines of the regions of those classes on every
|
|
@@ -11,6 +11,14 @@ import * as i0 from "@angular/core";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class SpatialSelectionStore {
|
|
13
13
|
private readonly selection$;
|
|
14
|
+
/** Bumped by every write, a clear of nothing included (see {@link revision}). */
|
|
15
|
+
private writes;
|
|
16
|
+
/**
|
|
17
|
+
* How many times the selection was written (set or cleared, by any writer). A selection
|
|
18
|
+
* computed asynchronously compares it before publishing: a newer write — a Clear, a legend
|
|
19
|
+
* click, a linked chart's brush — supersedes it.
|
|
20
|
+
*/
|
|
21
|
+
revision(): number;
|
|
14
22
|
/** Emits on every change, including a clear. */
|
|
15
23
|
getSelection$(): Observable<SpatialSelectionMask>;
|
|
16
24
|
/** Synchronous read, for a renderer building its first frame. */
|