Class SeedOverlay
SeedPoints used to render candidate
tracing seeds (e.g., the output of a deep-learning point detector) on
SNT's canvas and to feed them to downstream consumers (autotracers,
click-to-trace anchors).
Lifecycle: not persisted with the .traces file. Cleared
when the active image changes (see SNT.initialize(ij.ImagePlus)).
Users may import additional CSVs (with ImportSeedPointsCmd
"Import Seed Points (CSV)…" or another command) at any time. Headless/CLI callers
that do not need unit conversion or import guardrails can instead read a CSV
directly via loadCsv(File, boolean).
Threading: intended to be accessed from the Swing EDT (panel UI,
canvas paint). Bulk loaders should use addAll(Collection) to
trigger a single listener fire and a single spatial-index rebuild.
Spatial queries: nearest(double, double, double, double)
uses a lazily-built KD-tree from Smile. The tree is invalidated by any
mutating call; threshold/visibility changes do not invalidate it (queries
are not threshold-aware by default: callers should pre-filter via
filtered() if threshold-aware nearest-neighbor is required).
- Author:
- Tiago Ferreira
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHowSeedOverlayRenderershould pick each seed's LUT slot.static final classThrown byparseCsv(File)when the CSV header is missing a required columnstatic final recordResult ofparseCsv(File): valid seeds plus a count of rows skipped due to parse errors (missing/non-finite coordinates, etc)static interfaceListener fired on any change to the overlay (add/clear/threshold/visibility). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault LUT name (resolved viaColorMaps.get(String)). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a single seed.voidaddAll(Collection<? extends SeedPoint> batch) Bulk-adds seeds.voidaddListener(SeedOverlay.SeedOverlayListener listener) Registers a listener (no-op if already registered).voidclear()Removes all seeds.voidClears the selection.intcountOutOfBounds(long[] dims, double[] spacing, double[] offset) Counts seeds whose voxel coordinates fall outside the given image bounds.filtered()Returns a new list of seeds whose confidence falls in[lowConfidence, highConfidence].get(int index) net.imglib2.display.ColorTabledoubledoubledoubleintReturns the index ofseedin the data list, or-1if absent.booleanisEmpty()booleanisSelected(SeedPoint seed) booleanlist()Returns a defensive snapshot of all held seeds (a freshArrayList, safe to iterate while the overlay continues to mutate on another thread).ParsesfileviaparseCsv(File)and inserts the result into this overlay.nearest(double x, double y, double z, double maxDistance) Returns the seed closest to(x, y, z)in physical units, ornullif the overlay is empty or no seed lies withinmaxDistance.static SeedOverlay.CsvImportResultParses a seed CSV with headerx,y,z,confidence,radius(plus optionalchannel,frame,type,source), assuming coordinates are already in physical (image-calibrated) units.static SeedOverlay.CsvImportResultString/URL counterpart ofparseCsv(File), for script-friendly callers and remote CSVs.booleanRemoves a single seed by reference equality.intremoveAll(Collection<? extends SeedPoint> batch) Bulk-removes seeds by reference equality.removeAt(int index) Removes the seed at the given (data-list) index.voidRemoves a listener (no-op if not registered).intRemoves all currently selected seeds from the data list.voidreplaceAll(Collection<? extends SeedPoint> replacement) Replaces the current contents with the given seeds.intreplaceAllAt(Map<Integer, SeedPoint> replacements) Bulk-replaces seeds at multiple positions, firing listeners and invalidating the spatial index once at the end.booleanReplaces the seed at the given index.voidWrites all held seeds to a CSV file with the canonical headerx,y,z,confidence,radius.intscaleConfidence(Collection<SeedPoint> seeds, double factor) Multiplies the confidence ofseedsbyfactor, clamping each result to[0, 1].intscaleRadius(Collection<SeedPoint> seeds, double factor) Multiplies the physical radius ofseedsbyfactor, clamping each result to>= 0(radius has no upper bound, unlike confidence).voidSets the rendering color mode.voidsetColorTable(String name) Sets the active LUT.voidsetConfidenceRange(double low, double high) Sets the visible confidence range.voidsetSelectedSeeds(Collection<? extends SeedPoint> selection) Replaces the selection set.voidsetTransparency(double t) Sets the global transparency multiplier (clamped to[0, 1]).voidsetUnknownConfidenceColor(Color color) Sets the fallback color used forNaN-confidence seeds inSeedOverlay.ColorMode.CONFIDENCEmode.voidsetVisible(boolean visible) Sets visibility; fires listeners if the value changed.intsize()topKByConfidence(int k) Returns up tokseeds from the visible range ([lowConfidence, highConfidence]) with the highest confidence.int
-
Field Details
-
DEFAULT_COLOR_TABLE_NAME
Default LUT name (resolved viaColorMaps.get(String)).- See Also:
-
-
Constructor Details
-
SeedOverlay
public SeedOverlay()
-
-
Method Details
-
size
public int size()- Returns:
- the number of seeds currently held (irrespective of threshold).
-
isEmpty
public boolean isEmpty()- Returns:
trueif no seeds are held.
-
countOutOfBounds
public int countOutOfBounds(long[] dims, double[] spacing, double[] offset) Counts seeds whose voxel coordinates fall outside the given image bounds.Coordinates are interpreted as physical (calibrated) world units. Per
SNT#getWorldOriginOffset()'s (world = voxelIndex * spacing + offset),offsetis subtracted before dividing byspacingto recover the voxel index - omitting it misreports every seed as out-of-bounds whenever the tethered image/source is not anchored at world (0,0,0), regardless of how much of the source is currently materialized. A seed is considered out-of-bounds when its rounded voxel index is negative or ≥ the dimension on any axis. The z-axis is only checked whendims.length >= 3.- Parameters:
dims- image dimensions in voxels (length 2 for 2D, 3 for 3D); ifnullor length < 2, returns 0spacing- pixel size per axis in physical units; should matchdimslength.nullreturns 0offset- world origin offset per axis (seeSNT#getWorldOriginOffset());nullor too short is treated as all-zero (i.e., world == pixel * spacing)- Returns:
- number of seeds outside the image bounds
-
visibleSize
public int visibleSize()- Returns:
- the number of seeds whose confidence falls in
[lowConfidence, highConfidence].
-
add
Adds a single seed. Fires listeners and invalidates the spatial index. PreferaddAll(Collection)for batches. -
addAll
Bulk-adds seeds. Fires listeners once at the end and invalidates the spatial index once.- Parameters:
batch- seeds to append; ignored ifnullor empty
-
replaceAll
Replaces the current contents with the given seeds. Equivalent toclear()followed byaddAll(Collection), but only fires listeners and rebuilds the spatial index once.- Parameters:
replacement- the new contents (may benull/empty, which behaves likeclear())
-
clear
public void clear()Removes all seeds. Fires listeners. -
remove
Removes a single seed by reference equality. Selection is updated. Fires listeners and invalidates indices if the seed was present.- Returns:
trueif the seed was present and removed
-
removeAll
Bulk-removes seeds by reference equality. Fires listeners once at the end if anything was removed.- Returns:
- the number of seeds actually removed
-
removeAt
Removes the seed at the given (data-list) index. Fires listeners.- Returns:
- the removed seed, or
nullif the index was out of range
-
replaceAt
Replaces the seed at the given index. Ifreplacementis the same reference as the existing seed, this is a no-op. Selection is preserved (the new seed inherits the selection state of the old one). Fires listeners on actual change.- Returns:
trueon success,falseif the index was out of range or the replacement wasnullor identical
-
replaceAllAt
Bulk-replaces seeds at multiple positions, firing listeners and invalidating the spatial index once at the end. Entries with out-of-range indices ornullreplacements are silently skipped.- Parameters:
replacements- map of(model-index, new-seed).nullor empty input is a no-op.- Returns:
- the number of slots actually mutated
-
indexOf
Returns the index ofseedin the data list, or-1if absent. Reference identity (viaList.indexOf(java.lang.Object)) is used. -
scaleConfidence
Multiplies the confidence ofseedsbyfactor, clamping each result to[0, 1]. ASeedPoint.confidenceofNaN("no basis to judge", seeSeedConfidence) is left asNaNsince it fails both clamp comparisons. Seeds not present in the data list (e.g. selected then removed elsewhere) are silently skipped. Fires listeners once viareplaceAllAt(Map).- Parameters:
seeds- seeds to rescale, typically a table selectionfactor- confidence multiplier, e.g.0.9to decrease by 10%,1.1to increase by 10%- Returns:
- the number of seeds actually rescaled
-
scaleRadius
Multiplies the physical radius ofseedsbyfactor, clamping each result to>= 0(radius has no upper bound, unlike confidence). Seeds not present in the data list are silently skipped. Fires listeners once viareplaceAllAt(Map).- Parameters:
seeds- seeds to rescale, typically a table selectionfactor- radius multiplier, e.g.0.9to decrease by 10%,1.1to increase by 10%- Returns:
- the number of seeds actually rescaled
-
getSelectedSeeds
- Returns:
- an unmodifiable, insertion-ordered view of the currently selected seeds. The result is a snapshot (independent collection).
-
isSelected
- Returns:
trueifseedis currently selected.
-
setSelectedSeeds
Replaces the selection set. Seeds not present in the data list are silently ignored. Fires listeners if the resulting selection differs. -
clearSelection
public void clearSelection()Clears the selection. Fires listeners if anything was previously selected. -
removeSelected
public int removeSelected()Removes all currently selected seeds from the data list.- Returns:
- the number of seeds removed (0 if nothing was selected)
-
get
- Returns:
- seed at
index(0-based).
-
list
Returns a defensive snapshot of all held seeds (a freshArrayList, safe to iterate while the overlay continues to mutate on another thread).- Returns:
- a freshly allocated list snapshot
-
filtered
Returns a new list of seeds whose confidence falls in[lowConfidence, highConfidence]. O(N); the result is a snapshot, not a live view. -
topKByConfidence
Returns up tokseeds from the visible range ([lowConfidence, highConfidence]) with the highest confidence. The result is a snapshot (independent list). Internally uses a cached sort that is rebuilt only when the overlay's data mutates.- Parameters:
k- maximum number of seeds to return; values<= 0return an empty list- Returns:
- up to
kseeds sorted by descending confidence
-
getLowConfidence
public double getLowConfidence()- Returns:
- the lower bound of the visible confidence range, in
[0, 1].
-
getHighConfidence
public double getHighConfidence()- Returns:
- the upper bound of the visible confidence range, in
[0, 1].
-
setConfidenceRange
public void setConfidenceRange(double low, double high) Sets the visible confidence range. Values are clamped to[0, 1]; iflow > highthe bounds are swapped. Fires listeners if either bound changed. -
getTransparency
public double getTransparency()- Returns:
- the current global transparency multiplier in
[0, 1].1.0= fully opaque.
-
setTransparency
public void setTransparency(double t) Sets the global transparency multiplier (clamped to[0, 1]). Fires listeners if the value changed. -
getColorMode
- Returns:
- how seed LUT slots are picked at render time. Never
null; defaults toSeedOverlay.ColorMode.CONFIDENCE.
-
setColorMode
Sets the rendering color mode. Fires listeners if the value changed.nullis treated asSeedOverlay.ColorMode.CONFIDENCE. -
getColorTable
public net.imglib2.display.ColorTable getColorTable()- Returns:
- the active LUT for confidence-to-color mapping. Never
null.
-
getColorTableName
- Returns:
- the canonical name of the active LUT (e.g.
"Viridis").
-
setColorTable
Sets the active LUT. Ifnameis not recognised byColorMaps.get(String), this is a no-op. Fires listeners on success. -
getUnknownConfidenceColor
- Returns:
- the fallback color used for
NaN-confidence seeds inSeedOverlay.ColorMode.CONFIDENCEmode. Nevernull.
-
setUnknownConfidenceColor
Sets the fallback color used forNaN-confidence seeds inSeedOverlay.ColorMode.CONFIDENCEmode.nullresets to default. Fires listeners on success. -
isVisible
public boolean isVisible()- Returns:
trueif seeds should be drawn on the canvas.
-
setVisible
public void setVisible(boolean visible) Sets visibility; fires listeners if the value changed. -
nearest
Returns the seed closest to(x, y, z)in physical units, ornullif the overlay is empty or no seed lies withinmaxDistance.Note: this query does not filter by confidence threshold. Use
filtered()and search that list manually if threshold-aware nearest-neighbor is required.- Parameters:
x- query physical Xy- query physical Yz- query physical Z (use 0 for 2D)maxDistance- maximum acceptable distance in physical units; passDouble.POSITIVE_INFINITYto disable- Returns:
- the nearest seed, or
null
-
saveAs
Writes all held seeds to a CSV file with the canonical headerx,y,z,confidence,radius. Channel/frame are written only if any seed has them set (extra columns appended).- Parameters:
file- destination file (will be overwritten)- Throws:
IOException- on write failure
-
parseCsv
public static SeedOverlay.CsvImportResult parseCsv(File file) throws IOException, SeedOverlay.CsvHeaderException Parses a seed CSV with headerx,y,z,confidence,radius(plus optionalchannel,frame,type,source), assuming coordinates are already in physical (image-calibrated) units. Callers needing voxel to physical conversion (e.g.ImportSeedPointsCmd) should convert the returned seeds themselves before callingaddAll(Collection)orreplaceAll(Collection). UseloadCsv(File, boolean)for the common case of physical-unit CSVs- Parameters:
file- the CSV file to read- Returns:
- the parsed seeds and the number of skipped rows
- Throws:
IOException- if the file cannot be readSeedOverlay.CsvHeaderException- if a required column is missing- See Also:
-
parseCsv
public static SeedOverlay.CsvImportResult parseCsv(String filePathOrURL) throws IOException, SeedOverlay.CsvHeaderException String/URL counterpart ofparseCsv(File), for script-friendly callers and remote CSVs. Local paths and remote URLs (e.g.https://.../seeds.csv) are both accepted; a remote URL is downloaded to a temporary local file first (seeSNTUtils.downloadToTempFile(String))- Parameters:
filePathOrURL- local path or remote URL to a seed CSV- Returns:
- the parsed seeds and the number of skipped rows
- Throws:
IOException- if the file/URL cannot be readSeedOverlay.CsvHeaderException- if a required column is missing
-
loadCsv
public SeedOverlay.CsvImportResult loadCsv(File file, boolean replace) throws IOException, SeedOverlay.CsvHeaderException ParsesfileviaparseCsv(File)and inserts the result into this overlay. Coordinates are assumed to already be in physical units; voxel-indexed CSVs need unit conversion first, so parse them withparseCsv(File)and insert the (converted) seeds viaaddAll(Collection)/replaceAll(Collection)instead- Parameters:
file- the CSV file to readreplace- if true, replaces the current seeds; if false, appends- Returns:
- the parse result (seeds inserted, plus skipped-row count)
- Throws:
IOException- if the file cannot be readSeedOverlay.CsvHeaderException- if a required column is missing
-
loadCsv
public SeedOverlay.CsvImportResult loadCsv(String filePathOrURL, boolean replace) throws IOException, SeedOverlay.CsvHeaderException - Throws:
IOExceptionSeedOverlay.CsvHeaderException- See Also:
-
addListener
Registers a listener (no-op if already registered). -
removeListener
Removes a listener (no-op if not registered).
-