/** * Copyright (c) 2026 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Tadej Satler */ import { Volume } from '../../../mol-model/volume.js'; import { StatefulPluginComponent } from '../../../mol-plugin-state/component.js'; import { PluginContext } from '../../../mol-plugin/context.js'; import { StateObjectCell, StateTransform } from '../../../mol-state/index.js'; import { Color } from '../../../mol-util/color/index.js'; import { BodyId, BodyInfo, BodyMaskParams, LabelStore, ViewMask } from './types.js'; export type PreviewMode = 'none' | 'active' | 'all'; export interface VolumeSegmentorStats { /** Voxels above the threshold. */ candidates: number; /** Voxels above the threshold not assigned to any body. */ unassigned: number; total: number; } export interface VolumeSegmentorState { targetVolumeRef: StateTransform.Ref | undefined; threshold: Volume.IsoValue; isDrawing: boolean; activeBodyId: BodyId | undefined; /** Snapshot of the body definitions (new array on every change). */ bodies: BodyInfo[]; defaults: BodyMaskParams; preview: PreviewMode; undoDepth: number; stats: VolumeSegmentorStats; busy: boolean; /** Mirrors `LabelStore.version`. */ version: number; /** Last non-fatal message for the UI (e.g. why a preview was skipped). */ message: string | undefined; } /** * Drives interactive body segmentation of one volume. Bodies are defined by their view * polygons (plus an optional remainder body); voxel labels are recomputed from these * definitions after every change and kept in sync with the plugin state (colored source * surface, per-body mask previews). */ export declare class VolumeSegmentorManager extends StatefulPluginComponent { readonly plugin: PluginContext; static get(plugin: PluginContext): VolumeSegmentorManager | undefined; static register(plugin: PluginContext, manager: VolumeSegmentorManager): void; static unregister(plugin: PluginContext): void; readonly behaviors: { state: import("rxjs").BehaviorSubject; }; private candidates; private undoStack; private previewRefs; private themeSyncInFlight; private pendingTargetRef; private thresholdTimer; private thresholdInFlight; private pendingThreshold; private recomputing; private recomputeQueued; constructor(plugin: PluginContext); private update; get volume(): Volume | undefined; get store(): LabelStore | undefined; get thresholdAbs(): number; get activeBody(): BodyInfo | undefined; /** Direct isosurface representations of the target volume (previews excluded). */ private get volumeIsosurfaceReprs(); private volumeIsosurfaceReprsOf; /** All representations of the volume at `ref` (previews excluded). */ private volumeReprsOf; setTargetVolume(ref: StateTransform.Ref | undefined): Promise; private applyTargetVolume; private computeStats; /** * Colors the source isosurfaces by body label and disables wrapping across box faces. * Idempotent: only representations that are not set up yet are touched. */ private applyThemeToVolume; private refreshTheme; /** Sets the threshold; the isosurface follows with a short debounce and bodies are recomputed. */ setThreshold(value: Volume.IsoValue): void; private clearThresholdTimer; private flushThreshold; private applyThreshold; /** * Zeroes isolated blobs smaller than `minVoxels` (at the current threshold) in the source * volume itself, then rebuilds its representations and recomputes the bodies. Returns the * number of voxels zeroed. This edit cannot be undone. */ removeDust(minVoxels: number): Promise; /** * Mirrors the source volume along X to fix a map stored with the opposite handedness, then * rebuilds its representations and recomputes the bodies. View polygons are kept, so bodies * are relabelled against the mirrored data. This edit cannot be undone. */ flipHandedness(): Promise; /** Downloads the source volume as MRC, including dust removal and handedness flips. */ saveVolume(): void; /** Representations compare volumes by grid reference, so in-place edits need a rebuild. */ private rebuildVolumeRepresentations; private snapshot; private setBodies; addBody(name?: string, color?: Color): BodyInfo | undefined; /** Adds (or activates) the body that collects every voxel no other body claims. */ addRemainderBody(name?: string): Promise; removeBody(id: BodyId): Promise; /** Moves a body up (`-1`) or down (`+1`) in the priority order. */ moveBody(id: BodyId, delta: -1 | 1): Promise; setActiveBody(id: BodyId | undefined): void; renameBody(id: BodyId, name: string): void; setBodyColor(id: BodyId, color: Color): Promise; /** Per-body extend / soft edge; `undefined` values fall back to the defaults. */ setBodyMaskParams(id: BodyId, params: { extend?: number; softEdge?: number; }): Promise; setDefaults(defaults: BodyMaskParams): Promise; setDrawing(isDrawing: boolean): void; addView(bodyId: BodyId, view: ViewMask): Promise; removeView(bodyId: BodyId, viewId: string): Promise; /** Toggles a view between selecting inside and outside its polygon. */ invertView(bodyId: BodyId, viewId: string): Promise; flyTo(view: ViewMask, durationMs?: number): void; undo(): Promise; /** Removes all bodies. */ reset(): Promise; /** Recomputes all voxel labels from the body definitions (list order = priority). */ recompute(): Promise; private recomputeOnce; private runBusy; setPreview(preview: PreviewMode): Promise; private previewTargets; private estimatePreviewBytes; /** Creates, updates or removes per-body mask preview nodes to match the current state. */ private syncPreviews; private removePreview; private removePreviews; /** Downloads one MRC mask per body (largest first), optionally bundled as a zip. */ exportMasks(options: { bundleZip: boolean; compress: boolean; }): Promise; dispose(): void; } /** True for state cells created by the body mask preview, so volume pickers can skip them. */ export declare function isBodyMaskCell(cell: StateObjectCell): boolean;