Package sc.fiji.snt.plugin
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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Stringprotected ij.ImagePlusprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected Fileprotected doubleprotected Stringprotected Fileprotected doubleprotected Stringprotected booleanstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected booleanprotected StringFields inherited from class sc.fiji.snt.gui.cmds.CommonDynamicCmd
EMPTY_LABEL, HEADER_HTML, snt, sntService, statusService, ui, uiServiceFields inherited from class org.scijava.command.DynamicCommand
moduleService, pluginService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassignRoiZPosition(ij.gui.Roi roi) Assigns or clears the Z-position on the given ROI based onroiPlaneand the current mask image.voidcancel()voidprotected booleanconfirmIfNotSegmented(ij.ImagePlus mask) Focused pre-flight for seed-driven subclasses that bypassrunCommand()(and thereforevalidateBeforeTracing(ij.gui.Roi, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean)).protected BinaryTracercreateAndConfigureConverter(ij.ImagePlus maskImp, ij.ImagePlus origImp) Builds and configures aBinaryTracerfor the supplied images.protected voidprotected ij.gui.RoigetRoi(ij.ImagePlus... imps) Retrieves the first non-null ROI from the supplied images.protected intReturns theBinaryTracerroot strategy constant corresponding to the currentrootChoiceselection.protected voidhandleTracedTrees(List<Tree> trees) Called after tracing completes with valid trees.protected voidDisplays an informational message via the SNT UI, or logs it if no UI is available.protected voidInitializes the command for file-based (batch) mode.protected voidInitializes the command for interactive (image-choice) mode.protected abstract booleanReturns whether this command operates in file mode (loading images from file paths) or in image-choice mode (selecting from open images).protected booleanisSegmented(ij.ImagePlus imp) Checks whether the given image is binary (segmented) or thresholded.protected voidprotected StringpruneModeToString(BinaryTracer binaryTracer) Returns a human-readable string for the current prune mode of the given tracer.protected voidExecutes the core tracing pipeline: loads images (from file or choice widgets based onisFileMode()), validates inputs, runsBinaryTracer, and post-processes the resulting trees.voidsetPruneMode(BinaryTracer skConverter) Configures the prune mode on aBinaryTracerbased on the currentloopSolvingChoiceselection.protected booleanvalidateBeforeTracing(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.Methods inherited from class sc.fiji.snt.gui.cmds.CommonDynamicCmd
getPromptWithCloseHandler, getPromptWithCloseHandler, init, isCanceled, msg, notifyExternalDataLoaded, notifyLoadingEnd, notifyLoadingStart, resetUI, resetUI, resetUI, run, statusMethods inherited from class org.scijava.command.DynamicCommand
context, getCancelReason, getContext, getInfo, getInput, getOutput, saveInputs, setContext, setInput, setOutput, uncancelMethods inherited from class org.scijava.module.AbstractModule
getDelegateObject, getInputs, getOutputs, initialize, isInputResolved, isOutputResolved, preview, resolveInput, resolveOutput, setInputs, setOutputs, unresolveInput, unresolveOutputMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.scijava.module.Module
getDelegateObject, getInputs, getOutputs, initialize, isInputResolved, isOutputResolved, isResolved, preview, resolveInput, resolveOutput, setInputs, setOutputs, setResolved, unresolveInput, unresolveOutputMethods inherited from interface org.scijava.module.MutableModule
addInput, addInput, addOutput, addOutput, removeInput, removeOutput
-
Field Details
-
ROI_AUTO_DETECT
- See Also:
-
ROI_UNSET
- See Also:
-
ROI_CONTAINED
- See Also:
-
ROI_EDGE
- See Also:
-
ROI_CENTROID
- See Also:
-
ROI_CENTROID_WEIGHTED
- See Also:
-
inputDir
-
originalImgChoice
-
rootChoice
-
roiPlane
protected boolean roiPlane -
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
-
headless
protected boolean headless -
impMap
-
chosenMaskImp
protected ij.ImagePlus chosenMaskImp -
abortRun
protected boolean abortRun -
ensureMaskImgVisibleOnAbort
protected boolean ensureMaskImgVisibleOnAbort -
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:
truefor file-based operation,falsefor 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 onisFileMode()), validates inputs, runsBinaryTracer, 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
connectComponentsandensureMaskImgVisibleOnAbortdirectly.- Parameters:
roi- the active ROI (may benull)inferRootFromRoi- whether root inference from ROI is requestedisSame- whether mask and original image are the sameisSegmented- whether the mask image is binary/thresholdedisValidOrigImg- whether the original image path is validisSameDim- whether mask and original share dimensionsisCompatible- whether images share spatial calibrationisValidConnectDist- whether the max connection distance is validisValidRoi- whether the ROI is a valid area ROI- Returns:
trueto proceed with tracing,falseto abort
-
confirmIfNotSegmented
protected boolean confirmIfNotSegmented(ij.ImagePlus mask) Focused pre-flight for seed-driven subclasses that bypassrunCommand()(and thereforevalidateBeforeTracing(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. Returnstrue(proceed) when the image is already segmented, when running headless, or when the user accepts the prompt.- Parameters:
mask- the candidate mask image- Returns:
trueto proceed with tracing,falseto abort
-
createAndConfigureConverter
Builds and configures aBinaryTracerfor the supplied images. Wraps the constructor with the standard configuration (prune mode, length threshold, component-connection options, loop-solving strategy, original-intensity image), sorunCommand()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 toBinaryTracer.PERIPHERAL_SEGMENTS. Root placement (viasetRootRoi/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 benull).- Returns:
- a configured but unrooted
BinaryTracer; caller adds a root and invokesBinaryTracer.getTrees().
-
handleTracedTrees
Called after tracing completes with valid trees. The default implementation honorsafterTracingChoice: 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 theBinaryTracerroot strategy constant corresponding to the currentrootChoiceselection.- Returns:
- the root strategy constant
-
assignRoiZPosition
protected void assignRoiZPosition(ij.gui.Roi roi) Assigns or clears the Z-position on the given ROI based onroiPlaneand 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:
trueif the image is binary or has an active threshold
-
setPruneMode
Configures the prune mode on aBinaryTracerbased on the currentloopSolvingChoiceselection.- Parameters:
skConverter- the tracer to configure
-
pruneModeToString
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
nullif none exists
-
info
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:
cancelin interfaceorg.scijava.module.Module- Overrides:
cancelin classCommonDynamicCmd
-
cancel
- Specified by:
cancelin interfaceorg.scijava.Cancelable- Overrides:
cancelin classCommonDynamicCmd
-
error
- Overrides:
errorin classCommonDynamicCmd
-