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.
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 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) 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).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.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.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]).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) Counts seeds whose voxel coordinates fall outside the given image bounds.Coordinates are interpreted as physical (calibrated) units, divided by the corresponding
spacingto yield voxel indices. 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 0- 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. -
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. -
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
-
addListener
Registers a listener (no-op if already registered). -
removeListener
Removes a listener (no-op if not registered).
-