Package sc.fiji.snt.tracing.auto
Class GWDTTracerFactory
java.lang.Object
sc.fiji.snt.tracing.auto.GWDTTracerFactory
Factory for creating optimal GWDT tracer implementations based on image size.
Automatically selects the best storage backend:
- Array storage: Images < 1GB - Fast, high memory
- Sparse storage: Images 1GB-5GB - Balanced, lower memory
- Disk-backed storage: Images > 5GB - Slow, minimal memory
The thresholds are based on estimated working memory (not source image size): working memory ≈ source size × 10 (for GWDT + Fast Marching data structures).
Usage:
// Automatic selection
AbstractGWDTTracer<?> tracer = GWDTTracerFactory.create(image);
tracer.setSeedPhysical(somaCenter);
List<Tree> trees = tracer.traceTrees();
// Manual selection
AbstractGWDTTracer<?> tracer = new SparseGWDTTracer<>(image);
- Author:
- Tiago Ferreira
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractGWDTTracer<?> create(ij.ImagePlus source) Creates the optimal GWDT tracer from an ImagePlus.static AbstractGWDTTracer<?> create(net.imagej.ImgPlus<?> source) Creates the optimal GWDT tracer from an ImgPlus.static AbstractGWDTTracer<?> create(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Creates the optimal GWDT tracer for the given image.static AbstractGWDTTracer<?> create(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing, long sparseThresholdMB, long diskThresholdMB) Creates optimal tracer with manual threshold override.static longestimateWorkingMemoryMB(long[] dims) Estimate working memory requirements in MB.static GWDTTracer<?> forceArray(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Force use of array storage regardless of image size.static DiskBackedGWDTTracer<?> forceDisk(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Force use of disk-backed storage regardless of image size.static SparseGWDTTracer<?> forceSparse(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Force use of sparse storage regardless of image size.static long[]Get current memory thresholds being used.static voidPrint current memory status and thresholds to console.static StringrecommendBackend(long[] dims) Get recommended storage backend type for an image.
-
Constructor Details
-
GWDTTracerFactory
public GWDTTracerFactory()
-
-
Method Details
-
create
public static AbstractGWDTTracer<?> create(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Creates the optimal GWDT tracer for the given image.Automatically selects between Array, Sparse, or DiskBacked storage based on estimated working memory requirements.
- Parameters:
source- the grayscale image to tracespacing- voxel spacing [x, y, z]- Returns:
- optimal tracer implementation
-
create
Creates the optimal GWDT tracer from an ImgPlus.- Parameters:
source- the grayscale image to trace- Returns:
- optimal tracer implementation
-
create
Creates the optimal GWDT tracer from an ImagePlus.- Parameters:
source- the grayscale image to trace- Returns:
- optimal tracer implementation
-
estimateWorkingMemoryMB
public static long estimateWorkingMemoryMB(long[] dims) Estimate working memory requirements in MB.Formula: (total voxels × bytes per voxel) / (1024²) where bytes per voxel = GWDT (8) + distances (8) + parents (4) + state (1) = 21 We use 25 to include overhead.
- Parameters:
dims- image dimensions- Returns:
- estimated working memory in megabytes
-
recommendBackend
Get recommended storage backend type for an image.- Parameters:
dims- image dimensions- Returns:
- "array", "sparse", or "disk"
-
getCurrentThresholds
public static long[] getCurrentThresholds()Get current memory thresholds being used.Useful for diagnostics and testing.
- Returns:
- array of [sparseThresholdMB, diskThresholdMB]
-
printMemoryStatus
public static void printMemoryStatus()Print current memory status and thresholds to console. Useful for debugging memory-related issues. -
create
public static AbstractGWDTTracer<?> create(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing, long sparseThresholdMB, long diskThresholdMB) Creates optimal tracer with manual threshold override.Allows forcing specific backends for testing or when automatic selection is not appropriate for your workflow.
- Parameters:
source- the grayscale image to tracespacing- voxel spacing [x, y, z]sparseThresholdMB- use sparse above this (MB), or -1 for dynamicdiskThresholdMB- use disk above this (MB), or -1 for dynamic- Returns:
- optimal tracer implementation
-
forceArray
public static GWDTTracer<?> forceArray(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Force use of array storage regardless of image size.Use with caution - may cause OutOfMemoryError for large images.
- Parameters:
source- the grayscale image to tracespacing- voxel spacing- Returns:
- array-based tracer
-
forceSparse
public static SparseGWDTTracer<?> forceSparse(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Force use of sparse storage regardless of image size.- Parameters:
source- the grayscale image to tracespacing- voxel spacing- Returns:
- sparse tracer
-
forceDisk
public static DiskBackedGWDTTracer<?> forceDisk(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing) Force use of disk-backed storage regardless of image size.- Parameters:
source- the grayscale image to tracespacing- voxel spacing- Returns:
- disk-backed tracer
-