Package sc.fiji.snt

Class AStarRefiner

java.lang.Object
sc.fiji.snt.AStarRefiner
All Implemented Interfaces:
Callable<Path>

public class AStarRefiner extends Object implements Callable<Path>
Post-hoc A* re-tracing of a single, already-existing Path: treats the path's current nodes as waypoints and re-derives the geometry between them via SNT.autoTraceSync(List, sc.fiji.snt.util.PointInImage, SNT.SearchSettingsSnapshot), using either the cost function/search parameters currently configured on the active SNT instance, or a frozen SNT.SearchSettingsSnapshot shared across a whole batch (see AStarRefiner(SNT, Path, SNT.SearchSettingsSnapshot)).

Intended for manually-traced paths against data streamed from disk/network, where running A* interactively may be too slow to be practical. See PathManagerUI's "Refine" menu ("Re-trace with A*...").

call() is thread-safe for parallel execution across paths (it does not modify the original path, and calls SNT.autoTraceSync(java.util.List<sc.fiji.snt.util.SNTPoint>, sc.fiji.snt.util.PointInImage) rather than the interactive tracing entry points, so concurrent workers do not serialize behind the single-threaded pool used by interactive tracing). apply() must be called sequentially afterward to commit the result via Path.replaceNodes(Path), which also reconciles this path's own branch point (if it has a parent) and any of its children's branch points against the new geometry.

Author:
Tiago Ferreira
See Also:
  • Constructor Details

    • AStarRefiner

      public AStarRefiner(SNT snt, Path path)
      Creates a refiner for a single path, reading search settings (cost function, data structure, secondary/hessian image) live from snt at the time call() actually runs.

      Prefer AStarRefiner(SNT, Path, SNT.SearchSettingsSnapshot) for batches of more than one path, so all paths share identical settings even if the live A* controls are changed mid-batch (they remain enabled during a batch by design).

      Parameters:
      snt - the live SNT instance whose current A* search parameters (cost function, hessian, image data) are used
      path - the path to re-trace; must have at least 2 nodes
      Throws:
      IllegalArgumentException - if path is null or has fewer than 2 nodes
    • AStarRefiner

      public AStarRefiner(SNT snt, Path path, SNT.SearchSettingsSnapshot settings)
      Creates a refiner for a single path, using a frozen SNT.SearchSettingsSnapshot instead of the live search settings.
      Parameters:
      snt - the live SNT instance whose image data is used
      path - the path to re-trace; must have at least 2 nodes
      settings - a snapshot from SNT.snapshotSearchSettings(), or null to read the live settings at call-time (equivalent to AStarRefiner(SNT, Path))
      Throws:
      IllegalArgumentException - if path is null or has fewer than 2 nodes
  • Method Details

    • readPreferences

      public void readPreferences()
      No-op: kept for consistency with PathFitter/MultiSpectralRefiner, which read persisted preferences here. A* re-tracing simply reuses whichever search parameters are already configured on the live SNT instance.
    • applySettings

      public void applySettings(AStarRefiner ref)
      No-op: kept for consistency with the other AbstractRefineHelper workers; there are no per-worker settings to propagate here (see readPreferences()).
      Parameters:
      ref - the reference refiner (unused)
    • getPath

      public Path getPath()
      Returns the original path being re-traced.
      Returns:
      the path
    • succeeded

      public boolean succeeded()
      Whether the re-trace succeeded. Only meaningful after call().
      Returns:
      true if a valid re-traced path was produced
    • getFailureReason

      public String getFailureReason()
      Human-readable reason call() failed, or null if it succeeded (or hasn't run yet).
      Returns:
      the failure reason, or null
    • call

      public Path call()
      Runs the A* re-trace on this path's current waypoints. Thread-safe: does not modify the original path. Call apply() afterward (sequentially) to commit results.
      Specified by:
      call in interface Callable<Path>
      Returns:
      the re-traced path, or null if re-tracing failed
    • apply

      public void apply()
      Applies the re-traced geometry to the original path via Path.replaceNodes(Path). Must be called sequentially (not thread-safe), typically on the EDT after all parallel call() invocations have completed.
      Throws:
      IllegalStateException - if call() has not been run or did not succeed