Class GWDTTracerFactory

java.lang.Object
sc.fiji.snt.tracing.auto.GWDTTracerFactory

public class GWDTTracerFactory extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    create(ij.ImagePlus source)
    Creates the optimal GWDT tracer from an ImagePlus.
    create(net.imagej.ImgPlus<?> source)
    Creates the optimal GWDT tracer from an ImgPlus.
    create(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing)
    Creates the optimal GWDT tracer for the given image.
    create(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing, long sparseThresholdMB, long diskThresholdMB)
    Creates optimal tracer with manual threshold override.
    static long
    Estimate working memory requirements in MB.
    static GWDTTracer<?>
    forceArray(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing)
    Force use of array storage regardless of image size.
    forceDisk(net.imglib2.RandomAccessibleInterval<?> source, double[] spacing)
    Force use of disk-backed storage regardless of image size.
    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 void
    Print current memory status and thresholds to console.
    static String
    recommendBackend(long[] dims)
    Get recommended storage backend type for an image.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 trace
      spacing - voxel spacing [x, y, z]
      Returns:
      optimal tracer implementation
    • create

      public static AbstractGWDTTracer<?> create(net.imagej.ImgPlus<?> source)
      Creates the optimal GWDT tracer from an ImgPlus.
      Parameters:
      source - the grayscale image to trace
      Returns:
      optimal tracer implementation
    • create

      public static AbstractGWDTTracer<?> create(ij.ImagePlus source)
      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

      public static String recommendBackend(long[] dims)
      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 trace
      spacing - voxel spacing [x, y, z]
      sparseThresholdMB - use sparse above this (MB), or -1 for dynamic
      diskThresholdMB - 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 trace
      spacing - 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 trace
      spacing - 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 trace
      spacing - voxel spacing
      Returns:
      disk-backed tracer