Class SparseStorageBackend
- All Implemented Interfaces:
StorageBackend
Only stores non-default values (e.g., foreground voxels, traced nodes). Achieves 10-100× memory reduction for sparse neuronal structures. Best for thin structures with lots of background.
Trade-offs:- Memory: 10-100× less than ArrayStorageBackend
- Speed: ~1.5-2× slower due to hash lookups vs array indexing
- Best for: Sparse images where <10% of voxels are foreground
- Author:
- Tiago Ferreira
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildGraph(long[] dims, double[] spacing, double threshold) Build graph from computed Fast Marching data.voidcomputeGWDT(net.imglib2.RandomAccessibleInterval<?> source, double threshold, double[] spacing, double minIntensity, double maxIntensity) Compute Gray-Weighted Distance Transform.voiddispose()Clean up resources (close files, free memory, delete temp files).longGet estimated memory usage in bytes.Returns the set of linear indices that have been marked as ALIVE during Fast Marching.Get storage backend type name for logging.doublegetDistance(long index) Get Fast Marching distance at linear index.doublegetGWDT(long index) Get GWDT value at linear index.doubleGet maximum GWDT value across the entire image.longgetParent(long index) Get parent pointer at linear index.bytegetState(long index) Get Fast Marching state at linear index.voidinitializeFastMarching(long[] dims, long seedIndex) Initialize Fast Marching data structures.voidreinitializeFastMarching(long[] dims, long seedIndex, Set<Long> excludedIndices) Re-initializes Fast Marching data structures (distances, parents, state) while preserving the pre-computed GWDT.voidsetConnectivityType(int type) Sets the connectivity type for neighbor iteration.voidsetDistance(long index, double distance) Set Fast Marching distance at linear index.voidsetGWDT(long index, double value) Overwrites the GWDT value at a linear index.voidsetParent(long index, long parentIndex) Set parent pointer at linear index.voidsetState(long index, byte stateValue) Set Fast Marching state at linear index.voidsetTrackAliveIndices(boolean track) Enable or disable tracking of ALIVE indices during Fast Marching.
-
Constructor Details
-
SparseStorageBackend
public SparseStorageBackend(long[] dims)
-
-
Method Details
-
computeGWDT
public void computeGWDT(net.imglib2.RandomAccessibleInterval<?> source, double threshold, double[] spacing, double minIntensity, double maxIntensity) Description copied from interface:StorageBackendCompute Gray-Weighted Distance Transform.For each foreground pixel, GWDT = sum of intensities along shortest path to background. Uses Fast Marching with background pixels as seeds.
- Specified by:
computeGWDTin interfaceStorageBackend- Parameters:
source- input image (untyped RandomAccessibleInterval)threshold- background thresholdspacing- voxel spacing [x, y, z]minIntensity- minimum intensity in source (for normalization)maxIntensity- maximum intensity in source (for normalization)
-
getGWDT
public double getGWDT(long index) Description copied from interface:StorageBackendGet GWDT value at linear index.- Specified by:
getGWDTin interfaceStorageBackend- Parameters:
index- linear voxel index- Returns:
- GWDT value, or Double.MAX_VALUE if not computed
-
setGWDT
public void setGWDT(long index, double value) Description copied from interface:StorageBackendOverwrites the GWDT value at a linear index. Used to apply waypoint attractors between GWDT computation and Fast Marching: pulling a voxel's GWDT value towardStorageBackend.getMaxGWDT()makes its traversal cost approach zero, so the FM wavefront prefers it.The maximum reported by
StorageBackend.getMaxGWDT()is not automatically recomputed; callers that bias above the original max should refresh it externally if needed.- Specified by:
setGWDTin interfaceStorageBackend- Parameters:
index- linear voxel indexvalue- the new GWDT value
-
getMaxGWDT
public double getMaxGWDT()Description copied from interface:StorageBackendGet maximum GWDT value across the entire image.- Specified by:
getMaxGWDTin interfaceStorageBackend- Returns:
- maximum GWDT value
-
initializeFastMarching
public void initializeFastMarching(long[] dims, long seedIndex) Description copied from interface:StorageBackendInitialize Fast Marching data structures.Allocates storage for distances, parents, and state arrays. Initializes all values to defaults (distances=MAX_VALUE, parents=-1, state=FAR).
- Specified by:
initializeFastMarchingin interfaceStorageBackend- Parameters:
dims- image dimensionsseedIndex- linear index of seed voxel (root)
-
reinitializeFastMarching
Description copied from interface:StorageBackendRe-initializes Fast Marching data structures (distances, parents, state) while preserving the pre-computed GWDT. Voxels whose linear indices appear inexcludedIndicesare pre-marked as ALIVE with distance 0, effectively making them impassable barriers for the next FM run.Excluded voxels are stamped directly into the state array after ALIVE tracking is initialized, so they are not added to the tracked ALIVE set. This ensures
StorageBackend.buildGraph(long[], double[], double)only sees voxels reached by the current FM pass, not leftover exclusions.This enables a NeuTube-style recovery pass: after tracing from one seed, the traced region (optionally dilated) is excluded and a new FM run can proceed from a different seed without recomputing the GWDT.
- Specified by:
reinitializeFastMarchingin interfaceStorageBackend- Parameters:
dims- image dimensionsseedIndex- linear index of the new seed voxelexcludedIndices- set of linear indices to pre-mark as ALIVE (impassable); may benullor empty
-
setDistance
public void setDistance(long index, double distance) Description copied from interface:StorageBackendSet Fast Marching distance at linear index.- Specified by:
setDistancein interfaceStorageBackend- Parameters:
index- linear voxel indexdistance- geodesic distance from seed
-
getDistance
public double getDistance(long index) Description copied from interface:StorageBackendGet Fast Marching distance at linear index.- Specified by:
getDistancein interfaceStorageBackend- Parameters:
index- linear voxel index- Returns:
- distance from seed, or Double.MAX_VALUE if unreached
-
setParent
public void setParent(long index, long parentIndex) Description copied from interface:StorageBackendSet parent pointer at linear index.- Specified by:
setParentin interfaceStorageBackend- Parameters:
index- linear voxel indexparentIndex- linear index of parent voxel in shortest path tree
-
getParent
public long getParent(long index) Description copied from interface:StorageBackendGet parent pointer at linear index.- Specified by:
getParentin interfaceStorageBackend- Parameters:
index- linear voxel index- Returns:
- parent index, or -1 if root or unset
-
setState
public void setState(long index, byte stateValue) Description copied from interface:StorageBackendSet Fast Marching state at linear index.- Specified by:
setStatein interfaceStorageBackend- Parameters:
index- linear voxel indexstateValue- one of FAR (0), TRIAL (1), or ALIVE (2)
-
getState
public byte getState(long index) Description copied from interface:StorageBackendGet Fast Marching state at linear index.- Specified by:
getStatein interfaceStorageBackend- Parameters:
index- linear voxel index- Returns:
- state value: FAR (0), TRIAL (1), or ALIVE (2)
-
buildGraph
Description copied from interface:StorageBackendBuild graph from computed Fast Marching data.Walks the parent pointers to reconstruct the shortest path tree, converting voxel coordinates to physical coordinates and creating SWCPoint nodes connected by edges.
- Specified by:
buildGraphin interfaceStorageBackend- Parameters:
dims- image dimensionsspacing- voxel spacing for coordinate conversionthreshold- background threshold (for validation)- Returns:
- directed weighted graph representing the traced tree
-
estimateMemoryUsage
public long estimateMemoryUsage()Description copied from interface:StorageBackendGet estimated memory usage in bytes.- Specified by:
estimateMemoryUsagein interfaceStorageBackend- Returns:
- estimated memory footprint of this backend
-
getBackendType
Description copied from interface:StorageBackendGet storage backend type name for logging.- Specified by:
getBackendTypein interfaceStorageBackend- Returns:
- human-readable backend type (e.g., "Array (in-memory)", "Sparse", "Disk-backed")
-
getAliveIndices
Description copied from interface:StorageBackendReturns the set of linear indices that have been marked as ALIVE during Fast Marching. Only available whenALIVE trackingis enabled; returnsnullotherwise.- Specified by:
getAliveIndicesin interfaceStorageBackend- Returns:
- the tracked ALIVE indices, or null if tracking is disabled
-
dispose
public void dispose()Description copied from interface:StorageBackendClean up resources (close files, free memory, delete temp files).Called automatically after tracing completes. Implementations should release any resources and allow garbage collection.
- Specified by:
disposein interfaceStorageBackend
-
setConnectivityType
public void setConnectivityType(int type) Sets the connectivity type for neighbor iteration. -
setTrackAliveIndices
public void setTrackAliveIndices(boolean track) Description copied from interface:StorageBackendEnable or disable tracking of ALIVE indices during Fast Marching.When enabled, the backend maintains a set of linear indices that have been marked as ALIVE. This allows
StorageBackend.buildGraph(long[], double[], double)to iterate only touched voxels instead of scanning the entire volume, providing dramatic speedup for large sparse images.Memory cost: ~24 bytes per ALIVE voxel
Recommended settings:- ArrayStorageBackend: ON (default) - moderate speedup, low cost
- SparseStorageBackend: OFF (default) - already iterates keys only
- DiskBackedStorageBackend: ON (default) - essential for performance
- Specified by:
setTrackAliveIndicesin interfaceStorageBackend- Parameters:
track- true to track ALIVE indices, false to use full-volume scan
-