public class PathAndFillManager extends DefaultHandler implements UniverseListener
SNT
instance, but accessing a PathAndFillManager directly is useful
for batch/headless operations.Modifier and Type | Class and Description |
---|---|
class |
PathAndFillManager.AllPointsIterator |
Modifier and Type | Field and Description |
---|---|
protected boolean |
enableUIupdates |
protected SNT |
plugin |
protected static int |
TRACES_FILE_TYPE_COMPRESSED_XML |
protected static int |
TRACES_FILE_TYPE_ML_JSON |
protected static int |
TRACES_FILE_TYPE_SWC |
protected static int |
TRACES_FILE_TYPE_UNCOMPRESSED_XML |
Modifier | Constructor and Description |
---|---|
|
PathAndFillManager()
Instantiates a new PathAndFillManager using default values.
|
|
PathAndFillManager(double x_spacing,
double y_spacing,
double z_spacing,
String spacing_units)
Instantiates a new PathAndFillManager imposing specified pixel dimensions,
which may be required for pixel operations.
|
protected |
PathAndFillManager(SNT plugin) |
Modifier and Type | Method and Description |
---|---|
protected void |
addFill(Fill fill) |
void |
addPath(Path p)
Adds a new path.
|
void |
addPath(Path p,
boolean retainTags) |
void |
addPath(Path p,
boolean forceNewName,
boolean forceNewId) |
protected void |
addPath(Path p,
boolean forceNewName,
boolean forceNewId,
boolean assumeMaxUsedTreeID) |
void |
addPath(Path p,
int id,
int treeID) |
void |
addPathAndFillListener(sc.fiji.snt.PathAndFillListener listener)
Adds a PathAndFillListener.
|
void |
addTree(Tree tree)
Adds a
Tree . |
protected boolean |
allPathsShareSameSpatialCalibration() |
Iterator<PointInImage> |
allPointsIterator() |
boolean |
anySelected()
Checks whether at least one Path is currently selected in the UI.
|
protected ij.measure.Calibration |
assignSpatialSettings(Dataset dataset) |
protected void |
assignSpatialSettings(ij.ImagePlus imp) |
void |
canvasResized()
Deprecated.
|
void |
clear()
Deletes all paths and fills.
|
void |
contentAdded(Content c)
Deprecated.
|
void |
contentChanged(Content c)
Deprecated.
|
void |
contentRemoved(Content c)
Deprecated.
|
void |
contentSelected(Content c)
Deprecated.
|
static PathAndFillManager |
createFromFile(String filePath,
int... swcTypes)
Creates a PathAndFillManager instance from imported data
|
static PathAndFillManager |
createFromGraph(DirectedWeightedGraph graph,
boolean keepTreePathStructure)
Create a new PathAndFillManager instance from the graph.
|
static PathAndFillManager |
createFromNodes(Collection<SWCPoint> nodes)
Creates a PathAndFillManager instance from a collection of reconstruction
nodes.
|
protected void |
deleteFills(int[] indices) |
boolean |
deletePath(int index)
Deletes a Path by index
|
boolean |
deletePath(Path p)
Deletes a path.
|
boolean |
deletePaths(Collection<Path> paths)
Deletes a collection of paths.
|
void |
deletePaths(int[] indices)
Delete paths by position.
|
void |
downsampleAll(double maximumPermittedDistance)
Downsamples alls path using Ramer–Douglas–Peucker simplification.
|
void |
endElement(String uri,
String localName,
String qName) |
protected boolean |
exportAllPathsAsSWC(Path[] primaryPaths,
String baseFilename) |
boolean |
exportAllPathsAsSWC(String baseFilename)
Exports all as Paths as SWC file(s).
|
protected boolean |
exportConnectedStructureAsSWC(Path primaryPath,
File swcFile) |
void |
exportFillsAsCSV(File outputFile)
Export fills as CSV.
|
void |
exportToCSV(File outputFile)
Output some potentially useful information about all the Paths managed by
this instance as a CSV (comma separated values) file.
|
boolean |
exportTree(int treeIndex,
File file) |
protected void |
flushSWCPoints(List<SWCPoint> swcPoints,
PrintWriter pw) |
protected List<Fill> |
getAllFills() |
protected List<Path> |
getAllPathsRenderedInViewPort(TracerCanvas canvas) |
BoundingBox |
getBoundingBox(boolean compute)
Returns the BoundingBox enclosing all nodes of all existing Paths.
|
List<NearPoint> |
getCorrespondences(PathAndFillManager other,
double maxDistance)
For each point in this PathAndFillManager, find the corresponding point on
the other one.
|
protected String |
getDefaultName(Path p) |
Map<Fill,FillerThread> |
getLoadedFills() |
Path |
getPath(int i)
Returns the Path at the specified position in the PathAndFillManager list.
|
protected Path |
getPathFrom3DViewerName(String name) |
Path |
getPathFromID(int id)
Returns the Path with the specified id.
|
Path |
getPathFromName(String name,
boolean caseSensitive)
Returns the Path with the specified name.
|
int |
getPathIndex(Path p)
Gets the index of a Path.
|
ArrayList<Path> |
getPaths()
Returns all the paths.
|
List<Path> |
getPathsFiltered()
Returns the 'de facto' Paths.
|
Collection<Path> |
getPathsInROI(Roi roi) |
Path[] |
getPathsStructured() |
Path[] |
getPathsStructured(Collection<Path> paths) |
SNT |
getPlugin()
Gets the SNT instance.
|
Set<Path> |
getSelectedPaths()
Gets all paths selected in the GUI
|
protected List<Path> |
getSelectedPathsRenderedInViewPort(TracerCanvas canvas) |
protected File |
getSWCFileForIndex(String prefix,
int index) |
List<SWCPoint> |
getSWCFor(Collection<Path> paths) |
List<SWCPoint> |
getSWCForOld(Collection<Path> paths)
Gets the list of SWCPoints associated with a collection of Paths.
|
Collection<Tree> |
getTrees()
Returns all the paths associated with this PathAndFillManager instance,
grouped by Tree.
|
protected List<Path> |
getUnSelectedPathsRenderedInViewPort(TracerCanvas canvas) |
protected int |
guessTracesFileType(String filename) |
protected void |
importGraph(DirectedWeightedGraph graph) |
protected void |
importGraphWithPathStructure(DirectedWeightedGraph graph) |
Map<String,Tree> |
importNeurons(Map<String,TreeSet<SWCPoint>> map,
ColorRGB color,
String spatialUnit)
Import neuron(s) as a collection of reconstruction nodes (SWC points)
|
protected boolean |
importSWC(BufferedReader br,
String descriptor,
boolean assumeCoordinatesInVoxels,
double xOffset,
double yOffset,
double zOffset,
double xScale,
double yScale,
double zScale,
boolean replaceAllPaths,
int... swcTypes)
Imports SWC data with advanced settings.
|
protected boolean |
importSWC(String filePath,
boolean ignoreCalibration)
Imports an SWC file.
|
boolean |
importSWC(String filePath,
boolean assumeCoordinatesInVoxels,
double xOffset,
double yOffset,
double zOffset,
double xScale,
double yScale,
double zScale,
boolean replaceAllPaths,
int... swcTypes)
Imports an SWC file using advanced options.
|
boolean |
importSWC(String descriptor,
String urlOrFilePath)
Imports an SWC file using default settings.
|
List<Tree> |
importSWCs(Map<String,String> swcs,
ColorRGB color)
Imports a group of SWC files (Remote URLs supported).
|
boolean |
isSelected(Path path)
Checks if a Path is currently selected in the GUI.
|
boolean |
load(String filePath,
int... swcTypes)
Imports a reconstruction file (any supported extension).
|
protected boolean |
loadCompressedXML(String filename) |
boolean |
loadGuessingType(String optionalDescription,
InputStream is) |
protected boolean |
loadUncompressedXML(String filename,
int... swcTypes) |
protected boolean |
multipleTreesExist() |
NearPoint |
nearestPointOnAnyPath(Collection<Path> paths,
PointInCanvas pic,
double distanceLimit) |
protected NearPoint |
nearestPointOnAnyPath(Collection<Path> paths,
PointInImage pim,
double distanceLimitSquared,
boolean unScaledPositions) |
NearPoint |
nearestPointOnAnyPath(double x,
double y,
double z,
double distanceLimit) |
void |
pathChanged(sc.fiji.snt.PathChangeEvent event) |
protected void |
rebuildRelationships()
Rebuild relationships.
|
protected void |
reloadFills(int[] selectedIndices) |
protected void |
resetIDs() |
void |
resetListeners(Path justAdded) |
protected void |
resetListeners(Path justAdded,
boolean expandAll) |
protected void |
resetSpatialSettings(boolean alsoResetPaths) |
protected boolean |
savetoFileOrFileSeries(File file) |
void |
setHeadless(boolean headless)
Sets whether this PathAndFillManager instance should run headless.
|
protected void |
setSelected(Collection<Path> selectedPaths,
Object sourceOfMessage) |
int |
size()
Returns the number of Paths in the PathAndFillManager list.
|
void |
startElement(String uri,
String localName,
String qName,
Attributes attributes) |
protected void |
syncSpatialSettingsWithPlugin() |
void |
transformationFinished(View view) |
void |
transformationStarted(View view) |
void |
transformationUpdated(View view) |
PathAndFillManager |
transformPaths(PathTransformer transformation,
ij.ImagePlus templateImage,
ij.ImagePlus modelImage) |
void |
universeClosed()
Deprecated.
|
protected void |
update3DViewerContents() |
protected void |
updateBoundingBox() |
protected boolean |
usingNonPhysicalUnits() |
protected void |
writeXML(String fileName,
boolean compress) |
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
protected static final int TRACES_FILE_TYPE_COMPRESSED_XML
protected static final int TRACES_FILE_TYPE_UNCOMPRESSED_XML
protected static final int TRACES_FILE_TYPE_SWC
protected static final int TRACES_FILE_TYPE_ML_JSON
protected SNT plugin
protected boolean enableUIupdates
public PathAndFillManager()
protected PathAndFillManager(SNT plugin)
public PathAndFillManager(double x_spacing, double y_spacing, double z_spacing, String spacing_units)
Path
s created under
this instance, will adopt the specified spacing details.x_spacing
- the 'voxel width'y_spacing
- the 'voxel height'z_spacing
- the 'voxel depth'spacing_units
- the spacing units (e.g., 'um', 'mm)protected void syncSpatialSettingsWithPlugin()
protected void assignSpatialSettings(ij.ImagePlus imp)
protected ij.measure.Calibration assignSpatialSettings(Dataset dataset)
protected void resetSpatialSettings(boolean alsoResetPaths)
protected void rebuildRelationships()
public int size()
public void addPathAndFillListener(sc.fiji.snt.PathAndFillListener listener)
listener
- the listenerpublic Path getPath(int i)
i
- the index of the Pathpublic Path getPathFromName(String name, boolean caseSensitive)
name
- the name of the Path to be retrievedcaseSensitive
- If true, case considerations are ignoredpublic Path getPathFromID(int id)
id
- the id of the Path to be retrievedprotected void setSelected(Collection<Path> selectedPaths, Object sourceOfMessage)
public boolean isSelected(Path path)
path
- the path to be checkedpublic Set<Path> getSelectedPaths()
public Collection<Path> getPathsInROI(Roi roi)
public boolean anySelected()
public boolean exportAllPathsAsSWC(String baseFilename)
baseFilename
- the file path (including common basename) for exported
files. The .swc
extension can be omitted. Each
traced structure will be saved into a dedicated file
using a 3-digits identifier. E.g., if only a single
structure exists, specifying /path/to/results
,
generates a /path/to/results-000.swc
file.public boolean exportTree(int treeIndex, File file)
protected boolean savetoFileOrFileSeries(File file)
protected boolean exportConnectedStructureAsSWC(Path primaryPath, File swcFile)
public void setHeadless(boolean headless)
headless
- true to activate headless calls, otherwise falseprotected void flushSWCPoints(List<SWCPoint> swcPoints, PrintWriter pw)
protected boolean usingNonPhysicalUnits()
protected void updateBoundingBox()
public BoundingBox getBoundingBox(boolean compute)
compute
- If true, BoundingBox dimensions will be computed for all the
existing Paths. If false, the last computed BoundingBox will be
returned. Also, if BoundingBox is not scaled, its spacing will be
computed from the smallest inter-node distance of an arbitrary '
large' Path. Computations of Path boundaries typically occur
during import operations.protected boolean allPathsShareSameSpatialCalibration()
public Path[] getPathsStructured()
public Collection<Tree> getTrees()
protected boolean multipleTreesExist()
public Path[] getPathsStructured(Collection<Path> paths)
public List<SWCPoint> getSWCFor(Collection<Path> paths) throws sc.fiji.snt.SWCExportException
sc.fiji.snt.SWCExportException
public List<SWCPoint> getSWCForOld(Collection<Path> paths) throws sc.fiji.snt.SWCExportException
paths
- the paths from which to retrieve the listpaths
sc.fiji.snt.SWCExportException
- if list could not be retrievedpublic void resetListeners(Path justAdded)
protected void resetListeners(Path justAdded, boolean expandAll)
public void addTree(Tree tree)
Tree
.tree
- the collection of paths to be addedpublic void addPath(Path p)
p
- the Path to be addedpublic void addPath(Path p, boolean retainTags)
public void addPath(Path p, boolean forceNewName, boolean forceNewId)
protected void addPath(Path p, boolean forceNewName, boolean forceNewId, boolean assumeMaxUsedTreeID)
public void addPath(Path p, int id, int treeID)
public boolean deletePath(int index)
index
- the index (zero-based) of the Path to be deletedpublic boolean deletePath(Path p)
p
- the path to be deletedpublic boolean deletePaths(Collection<Path> paths)
paths
- the collection to be deletedpublic int getPathIndex(Path p)
p
- the Path for which the index should be retrievedpublic void deletePaths(int[] indices)
indices
- the indices to be deletedprotected void addFill(Fill fill)
protected void deleteFills(int[] indices)
public Map<Fill,FillerThread> getLoadedFills()
protected void reloadFills(int[] selectedIndices)
protected void writeXML(String fileName, boolean compress) throws IOException
IOException
public void startElement(String uri, String localName, String qName, Attributes attributes) throws sc.fiji.snt.TracesFileFormatException
startElement
in interface ContentHandler
startElement
in class DefaultHandler
sc.fiji.snt.TracesFileFormatException
public void endElement(String uri, String localName, String qName) throws sc.fiji.snt.TracesFileFormatException
endElement
in interface ContentHandler
endElement
in class DefaultHandler
sc.fiji.snt.TracesFileFormatException
public static PathAndFillManager createFromFile(String filePath, int... swcTypes)
filePath
- the absolute path of the file to be imported as per
load(String, int...)
public static PathAndFillManager createFromNodes(Collection<SWCPoint> nodes)
nodes
- the collection of reconstruction nodes. Nodes will be sorted by
id and any duplicate entries pruned.public static PathAndFillManager createFromGraph(DirectedWeightedGraph graph, boolean keepTreePathStructure)
graph
- The input graphkeepTreePathStructure
- Whether to maintain the path hierarchy of the Tree backing the input graph.
If this is set to true, the graph must have been created from operations on
at least one Tree.
Note that even if the graph is backed by a Tree, this may not always be possible.
For instance, consider the case where two graphs oriented in opposing directions
are merged at an edge. One graph will need to be re-oriented, which will change
the Path hierarchy of the result.protected void importGraph(DirectedWeightedGraph graph)
protected void importGraphWithPathStructure(DirectedWeightedGraph graph)
public void clear()
protected void resetIDs()
public boolean importSWC(String descriptor, String urlOrFilePath)
descriptor
- the identifier for the imported dataurlOrFilePath
- the URL pointing to the SWC file or the absolute file
path of a local file. Note that with URLs, https may not be
supported.NeuroMorphoLoader
,
importSWC(String, boolean)
public List<Tree> importSWCs(Map<String,String> swcs, ColorRGB color)
swcs
- the HashMap containing the absolute file paths (or URLs) of
files to be imported as values and a file descriptor as keys.color
- the color to be applied to imported Paths. If null, paths from
each file will assigned unique colorsTree
s labeled after the file
descriptor. The returned list will not contain null elements: If a
file was not successfully imported an empty Tree will be generatedTree.isEmpty()
,
Tree.getLabel()
,
SNTColor.getDistinctColors(int)
protected boolean importSWC(BufferedReader br, String descriptor, boolean assumeCoordinatesInVoxels, double xOffset, double yOffset, double zOffset, double xScale, double yScale, double zScale, boolean replaceAllPaths, int... swcTypes)
Annoyingly, While the SWC specification details the usage of of world coordinates in microns, some published SWC files have adopted image (pixel) coordinates, which is inappropriate and less useful (an example of the latter seems to part of the DIADEM Challenge data set). In addition, it's not clear what the "radius" column is meant to mean in such files.
descriptor
- the label describing the Tree associated with the databr
- the character stream containing the dataassumeCoordinatesInVoxels
- If true, the SWC coordinates are assumed
to be in image coordinates ("pixels"). Note that in this case,
radii will be scaled by the minimum voxel separation. This
workaround seems to be required to properly import unscaled filesxOffset
- the offset to be applied to all X coordinates. May be useful
to import data obtained from multiple "un-stitched" fields of
view. Default is 0.yOffset
- the offset to be applied to all Y coordinates. May be useful
to import data obtained from multiple "un-stitched" fields of
view. Default is 0.zOffset
- the offset to be applied to all Z coordinates. May be useful
to import data obtained from multiple "un-stitched" fields of
view. Default is 0.xScale
- the scaling factor for all X coordinates. Useful to import
data onto downsampled images. Default is 1.yScale
- the scaling factor for all Y coordinates. Useful to import
data onto downsampled images. Default is 1.zScale
- the scaling factor for all Z coordinates. Useful to import
data onto downsampled images. Default is 1.replaceAllPaths
- If true, all existing Paths will be deleted before
the import. Default is false.public Map<String,Tree> importNeurons(Map<String,TreeSet<SWCPoint>> map, ColorRGB color, String spatialUnit)
map
- the input map of reconstruction nodescolor
- the color to be applied to imported Paths. If null, paths
from each ID will assigned unique colorsspatialUnit
- the spatial unit (um, mm, etc) associated with imported
nodes. If null, "um" are assumedSNTColor.getDistinctColors(int)
protected boolean importSWC(String filePath, boolean ignoreCalibration)
filePath
- the absolute path of the file to be importedignoreCalibration
- the ignore calibrationpublic boolean importSWC(String filePath, boolean assumeCoordinatesInVoxels, double xOffset, double yOffset, double zOffset, double xScale, double yScale, double zScale, boolean replaceAllPaths, int... swcTypes)
filePath
- the absolute file path to the imported fileassumeCoordinatesInVoxels
- If true, the SWC coordinates are assumed
to be in image coordinates ("pixels"). Note that in this case,
radii will be scaled by the minimum voxel separation. This
workaround seems to be required to properly import unscaled filesxOffset
- the offset to be applied to all X coordinates. May be useful
to import data obtained from multiple "un-stitched" fields of
view. Default is 0.yOffset
- the offset to be applied to all Y coordinates. May be useful
to import data obtained from multiple "un-stitched" fields of
view. Default is 0.zOffset
- the offset to be applied to all Z coordinates. May be useful
to import data obtained from multiple "un-stitched" fields of
view. Default is 0.xScale
- the scaling factor for all X coordinates. Useful to import
data onto downsampled images. Default is 1.yScale
- the scaling factor for all Y coordinates. Useful to import
data onto downsampled images. Default is 1.zScale
- the scaling factor for all Z coordinates. Useful to import
data onto downsampled images. Default is 1.replaceAllPaths
- If true, all existing Paths will be deleted before
the import.protected int guessTracesFileType(String filename)
protected boolean loadCompressedXML(String filename)
protected boolean loadUncompressedXML(String filename, int... swcTypes)
public boolean load(String filePath, int... swcTypes)
filePath
- the absolute path to the file (.Traces, SWC or JSON) to be
importedswcTypes
- (Optional) The SWC type(s) (e.g., Path.SWC_AXON
,
Path.SWC_DENDRITE
, etc.) to be considered in the
import. Ignored if filePath
encodes a .TRACES file.public boolean loadGuessingType(String optionalDescription, InputStream is) throws IOException
IOException
public ArrayList<Path> getPaths()
public List<Path> getPathsFiltered()
public void transformationStarted(View view)
transformationStarted
in interface UniverseListener
public void transformationUpdated(View view)
transformationUpdated
in interface UniverseListener
public void transformationFinished(View view)
transformationFinished
in interface UniverseListener
@Deprecated public void contentAdded(Content c)
contentAdded
in interface UniverseListener
@Deprecated public void contentRemoved(Content c)
contentRemoved
in interface UniverseListener
@Deprecated public void contentChanged(Content c)
contentChanged
in interface UniverseListener
@Deprecated public void contentSelected(Content c)
contentSelected
in interface UniverseListener
@Deprecated public void canvasResized()
canvasResized
in interface UniverseListener
@Deprecated public void universeClosed()
universeClosed
in interface UniverseListener
public NearPoint nearestPointOnAnyPath(double x, double y, double z, double distanceLimit)
protected List<Path> getAllPathsRenderedInViewPort(TracerCanvas canvas)
protected List<Path> getSelectedPathsRenderedInViewPort(TracerCanvas canvas)
protected List<Path> getUnSelectedPathsRenderedInViewPort(TracerCanvas canvas)
public NearPoint nearestPointOnAnyPath(Collection<Path> paths, PointInCanvas pic, double distanceLimit)
protected NearPoint nearestPointOnAnyPath(Collection<Path> paths, PointInImage pim, double distanceLimitSquared, boolean unScaledPositions)
public Iterator<PointInImage> allPointsIterator()
public List<NearPoint> getCorrespondences(PathAndFillManager other, double maxDistance)
other
- the other PathAndFillManager holding the corresponding PathsmaxDistance
- the distance limit below which the NearPoint is
consideredNearPoint
correspondencespublic void exportFillsAsCSV(File outputFile) throws IOException
outputFile
- the output fileIOException
- Signals that an I/O exception has occurred.public void exportToCSV(File outputFile) throws IOException
outputFile
- the output fileIOException
- if data could not be storedprotected void update3DViewerContents()
public PathAndFillManager transformPaths(PathTransformer transformation, ij.ImagePlus templateImage, ij.ImagePlus modelImage)
public void downsampleAll(double maximumPermittedDistance)
maximumPermittedDistance
- the maximum permitted distance between
nodes.public SNT getPlugin()
SNT
instance associated with this
PathManager (if any)public void pathChanged(sc.fiji.snt.PathChangeEvent event)
Copyright © 2015–2021 Fiji. All rights reserved.