Class BinaryTracerCommonCmd

java.lang.Object
org.scijava.module.AbstractModule
org.scijava.module.DefaultMutableModule
org.scijava.command.DynamicCommand
sc.fiji.snt.gui.cmds.CommonDynamicCmd
sc.fiji.snt.plugin.BinaryTracerCommonCmd
All Implemented Interfaces:
Runnable, org.scijava.Cancelable, org.scijava.command.Command, org.scijava.Contextual, org.scijava.module.Module, org.scijava.module.MutableModule, org.scijava.plugin.SciJavaPlugin
Direct Known Subclasses:
AutotraceFromBinarySeedsCmd, AutotraceFromBinaryTipsCmd, BinaryTracerCmd, BinaryTracerFileCmd

public abstract class BinaryTracerCommonCmd extends CommonDynamicCmd
Abstract base command providing shared parameters and logic for BinaryTracer-based autotracing. Subclassed by BinaryTracerCmd (interactive, image already loaded) and file-based variants (non-interactive, batch processing).
Author:
Cameron Arshadi, Tiago Ferreira
  • Field Details

    • ROI_AUTO_DETECT

      public static final String ROI_AUTO_DETECT
      See Also:
    • ROI_UNSET

      public static final String ROI_UNSET
      See Also:
    • ROI_CONTAINED

      public static final String ROI_CONTAINED
      See Also:
    • ROI_EDGE

      public static final String ROI_EDGE
      See Also:
    • ROI_CENTROID

      public static final String ROI_CENTROID
      See Also:
    • ROI_CENTROID_WEIGHTED

      public static final String ROI_CENTROID_WEIGHTED
      See Also:
    • inputDir

      protected File inputDir
    • originalImgChoice

      protected String originalImgChoice
    • rootChoice

      protected String rootChoice
    • roiPlane

      protected boolean roiPlane
    • loopSolvingChoice

      protected String loopSolvingChoice
    • pruneByLength

      protected boolean pruneByLength
    • lengthThreshold

      protected double lengthThreshold
    • connectComponents

      protected boolean connectComponents
    • maxConnectDist

      protected double maxConnectDist
    • cullSingleNodePaths

      protected boolean cullSingleNodePaths
    • debugMode

      protected boolean debugMode
    • afterTracingChoice

      protected String afterTracingChoice
    • headless

      protected boolean headless
    • impMap

      protected HashMap<String,ij.ImagePlus> impMap
    • chosenMaskImp

      protected ij.ImagePlus chosenMaskImp
    • abortRun

      protected boolean abortRun
    • ensureMaskImgVisibleOnAbort

      protected boolean ensureMaskImgVisibleOnAbort
    • maskImgFileBeingProcessed

      protected File maskImgFileBeingProcessed
  • Constructor Details

    • BinaryTracerCommonCmd

      public BinaryTracerCommonCmd()
  • Method Details

    • isFileMode

      protected abstract boolean isFileMode()
      Returns whether this command operates in file mode (loading images from file paths) or in image-choice mode (selecting from open images).
      Returns:
      true for file-based operation, false for choice-widget operation
    • initForImage

      protected void initForImage()
      Initializes the command for interactive (image-choice) mode. Populates choice widgets from open images and resolves file chooser fields.
    • initForFile

      protected void initForFile()
      Initializes the command for file-based (batch) mode. Hides choice widgets and resolves fields that are only relevant in interactive mode. Debug mode is always enabled in batch mode.
    • runCommand

      protected void runCommand()
      Executes the core tracing pipeline: loads images (from file or choice widgets based on isFileMode()), validates inputs, runs BinaryTracer, and post-processes the resulting trees.
    • validateBeforeTracing

      protected boolean validateBeforeTracing(ij.gui.Roi roi, boolean inferRootFromRoi, boolean isSame, boolean isSegmented, boolean isValidOrigImg, boolean isSameDim, boolean isCompatible, boolean isValidConnectDist, boolean isValidRoi)
      Validates configuration before tracing begins. The default (non-interactive) implementation logs warnings and adjusts flags as needed without prompting the user. Interactive subclasses may override this to display a confirmation dialog.

      This method may modify connectComponents and ensureMaskImgVisibleOnAbort directly.

      Parameters:
      roi - the active ROI (may be null)
      inferRootFromRoi - whether root inference from ROI is requested
      isSame - whether mask and original image are the same
      isSegmented - whether the mask image is binary/thresholded
      isValidOrigImg - whether the original image path is valid
      isSameDim - whether mask and original share dimensions
      isCompatible - whether images share spatial calibration
      isValidConnectDist - whether the max connection distance is valid
      isValidRoi - whether the ROI is a valid area ROI
      Returns:
      true to proceed with tracing, false to abort
    • confirmIfNotSegmented

      protected boolean confirmIfNotSegmented(ij.ImagePlus mask)
      Focused pre-flight for seed-driven subclasses that bypass runCommand() (and therefore validateBeforeTracing(ij.gui.Roi, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean)). Confirms with the user before treating a non-segmented (grayscale) image as a tracing mask. Returns true (proceed) when the image is already segmented, when running headless, or when the user accepts the prompt.
      Parameters:
      mask - the candidate mask image
      Returns:
      true to proceed with tracing, false to abort
    • createAndConfigureConverter

      protected BinaryTracer createAndConfigureConverter(ij.ImagePlus maskImp, ij.ImagePlus origImp)
      Builds and configures a BinaryTracer for the supplied images. Wraps the constructor with the standard configuration (prune mode, length threshold, component-connection options, loop-solving strategy, original-intensity image), so runCommand() and seed-driven subclasses (e.g. AutotraceFromBinarySeedsCmd) can share the same configuration pipeline without duplicating it.

      Caller is expected to supply a mask image that has already been skeletonized; this method does not re-skeletonize. The intensity image is optional: when null, intensity-based loop solving falls back to BinaryTracer.PERIPHERAL_SEGMENTS. Root placement (via setRootRoi / setRoots) is the caller's responsibility — this method leaves the tracer's root unset so the same flow can serve both ROI-driven and seed-driven runs.

      Parameters:
      maskImp - the skeletonized mask image (required).
      origImp - the original intensity image (optional; may be null).
      Returns:
      a configured but unrooted BinaryTracer; caller adds a root and invokes BinaryTracer.getTrees().
    • handleTracedTrees

      protected void handleTracedTrees(List<Tree> trees)
      Called after tracing completes with valid trees. The default implementation honors afterTracingChoice: optionally replaces existing paths, assigns colors (per-tree "dim" palette when proofreading, inter-tree otherwise), adds trees via PathAndFillManager, and optionally calibrates the Curation Manager for proofreading. Subclasses may override to export trees to disk or adopt the mask image as tracing canvas.
      Parameters:
      trees - the traced trees (guaranteed non-null and non-empty)
    • getRootStrategy

      protected int getRootStrategy()
      Returns the BinaryTracer root strategy constant corresponding to the current rootChoice selection.
      Returns:
      the root strategy constant
    • assignRoiZPosition

      protected void assignRoiZPosition(ij.gui.Roi roi)
      Assigns or clears the Z-position on the given ROI based on roiPlane and the current mask image.
      Parameters:
      roi - the ROI to configure
    • isSegmented

      protected boolean isSegmented(ij.ImagePlus imp)
      Checks whether the given image is binary (segmented) or thresholded.
      Parameters:
      imp - the image to check
      Returns:
      true if the image is binary or has an active threshold
    • setPruneMode

      public void setPruneMode(BinaryTracer skConverter)
      Configures the prune mode on a BinaryTracer based on the current loopSolvingChoice selection.
      Parameters:
      skConverter - the tracer to configure
    • pruneModeToString

      protected String pruneModeToString(BinaryTracer binaryTracer)
      Returns a human-readable string for the current prune mode of the given tracer.
      Parameters:
      binaryTracer - the tracer to inspect
      Returns:
      a string describing the prune mode
    • getRoi

      protected ij.gui.Roi getRoi(ij.ImagePlus... imps)
      Retrieves the first non-null ROI from the supplied images. Falls back to the first ROI in each image's overlay if no direct ROI is set.
      Parameters:
      imps - the images to search for ROIs
      Returns:
      the first ROI found, or null if none exists
    • info

      protected void info(String msg)
      Displays an informational message via the SNT UI, or logs it if no UI is available.
      Parameters:
      msg - the message to display
    • noImgError

      protected void noImgError()
    • cancel

      public void cancel()
      Specified by:
      cancel in interface org.scijava.module.Module
      Overrides:
      cancel in class CommonDynamicCmd
    • cancel

      public void cancel(String reason)
      Specified by:
      cancel in interface org.scijava.Cancelable
      Overrides:
      cancel in class CommonDynamicCmd
    • error

      protected void error(String msg)
      Overrides:
      error in class CommonDynamicCmd