Class Tree
- All Implemented Interfaces:
Cloneable,TreeProperties
Paths that share something in common, specially when scripting SNT.
Note that a "Tree" here is literally a collection of Paths. Very few
restrictions are imposed on its topology, although it is generally assumed
that the Collection of paths describes a single-rooted structure with no
loops.- Author:
- Tiago Ferreira, Cameron Arshadi
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intFields inherited from interface sc.fiji.snt.TreeProperties
AXONAL, DENDRITIC, KEY_COLOR, KEY_COMPARTMENT, KEY_FRAME_POS, KEY_ID, KEY_IMG, KEY_IMG_CHANNEL, KEY_IMG_FRAME, KEY_LABEL, KEY_SOURCE, KEY_SPATIAL_UNIT, SOMATIC, UNSET -
Constructor Summary
ConstructorsConstructorDescriptionTree()Instantiates a new empty Tree.Instantiates a new tree from a SWC, TRACES or JSON file.Instantiates a new tree from a filtered SWC, TRACES or JSON file.Instantiates a new tree from a SWC, TRACES or JSON file with filtering.Tree(Collection<Path> paths) Instantiates a new Tree from a set of paths.Tree(Collection<SWCPoint> nodes, String label) Instantiates a Tree from a collection of reconstruction nodes.Tree(DirectedWeightedGraph graph, String label) Instantiates a new Tree from a DirectedWeightedGraph with the specified label.Tree(DirectedWeightedGraph graph, String label, boolean keepTreePathStructure) Instantiates a new Tree from a DirectedWeightedGraph with control over path structure preservation. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a new Path to this Tree.voidapplyCanvasOffset(double xOffset, double yOffset, double zOffset) Specifies the offset to be used when rendering this Tree in aTracerCanvas.voidapplyProperties(Tree tree) Applies properties from another Tree to this Tree.voidapplyZCorrection(double correctionFactor) Applies a Z-shrinkage correction to all nodes in this tree.voidassignImage(ij.ImagePlus imp) Assigns the spatial calibration of an image to this Tree.voidassignImage(net.imagej.Dataset dataset) Assigns spatial calibration from a Dataset to this Tree.voidassignImage(net.imagej.ImgPlus<?> imgPlus) Assigns spatial calibration from an ImgPlus to this Tree.static voidassignUniqueColors(Collection<Tree> trees) Deprecated.static voidassignUniqueColors(Collection<Tree> trees, String excludedHue) Deprecated.voidassignValue(double value) Assigns a numeric property to this Tree.clone()Creates a deep copy of this Tree.voiddownsample(double internodeSpacing) Downsamples the tree, i.e., reduces the density of its nodes by increasing internode spacing.voiddownSample(double internodeSpacing) Deprecated.Usedownsample(double)instead.intfitRadii(ij.ImagePlus imp) Fits radii to all paths in this Tree by fitting circular cross-sections to the image signal.static TreeScript-friendly method for loading a Tree from a reconstruction file.get(int index) Returns the Path at the specified position.doubleRetrieves an approximate estimate of Tree's surface are by approximating the surface area of each path, and summing to total.doubleRetrieves an approximate estimate of Tree's volume by approximating the volume of each path, and summing to total.doubleRetrieves the numeric property assigned to this Tree.Gets the bounding box associated with this tree.getBoundingBox(boolean computeIfUnset) Gets the bounding box associated with this tree.getBPs()Gets the branch points (junctions) of the graph.org.scijava.util.ColorRGBgetColor()Gets the color assigned to this Tree.Retrieves the convex hull defined by all the nodes of this tree.getConvexHull(String type) Retrieves the convex hull of this tree.getGraph()Assembles a DirectedGraph from this Tree.getGraph(boolean simplify) Assembles a DirectedGraph from this Tree.ij.ImagePlusgetImpContainer(int multiDThreePaneView, int bitDepth) Gets an empty image capable of holding the skeletonized version of this tree.getLabel()Returns the identifying label of this tree.getNodes()Gets all the nodes (path points) forming this tree.longGets the total number of nodes across all paths in this Tree.Returns the Properties instance holding the persistent set of properties.getRoot()Gets the first node of the main primary path of this treeij.ImagePlusRetrieves the rasterized skeleton of this tree at 1:1 scaling.ij.ImagePlusgetSkeleton(int pixelValue) Retrieves the rasterized skeleton of this tree at 1:1 scaling.ij.ImagePlusRetrieves a 2D projection of the rasterized skeleton of this tree at 1:1 scaling.ij.ImagePlusgetSkeleton2D(int pixelValue) Retrieves a 2D projection of the rasterized skeleton of this tree at 1:1 scaling.Gets the list of all nodes tagged asPath.SWC_SOMA.Assembles a memory-efficient CSR-backedDirectedWeightedGraphfrom this Tree.Returns the SWC Type flags used by SNT.getSWCTypeNames(boolean includeSoma) Gets the set of SWC type labels present in this tree with optional soma inclusion in a readable form.Extracts the SWC-type flags present in this Tree.getSWCTypes(boolean includeSoma) Gets the set of SWC types present in this tree with optional soma inclusion.getTips()Gets the end points (tips) of the graph.intReturns the index of the specified Path in this Tree.booleanis3D()Assesses whether this Tree has depth.booleanChecks if the nodes of this Tree have been assignedBrainAnnotations (neuropil labels).booleanisEmpty()Checks if this Tree is empty.list()Gets all the paths from this tree.listFromDir(String dir) Retrieves a list ofTrees from reconstruction files stored in a common directory.listFromDir(String dir, String pattern) Retrieves a list ofTrees from reconstruction files stored in a common directory matching the specified criteria.listFromDir(String dir, String pattern, String... swcTypes) Retrieves a list ofTrees from reconstruction files stored in a common directory matching the specified criteria.static Collection<Tree> listFromFile(String tracesOrJsonFile) Retrieves a list ofTrees from a single file.static voidbooleanAppends all paths of a specifiedTreeto this one.voidRe-assembles the DirectedGraph object returned bygetGraph()ensuring that no untracked changes exist.booleanRemoves a path from this tree.voidreplaceAll(List<Path> paths) Replaces all Paths in this Tree.voidrotate(int axis, double angle) Rotates the tree.booleanSaves this Tree to a .TRACES (XML, compressed) file.booleanSaves this Tree to an SWC file.voidscale(double xScale, double yScale, double zScale) Scales the tree by the specified factors.voidscale(double xScale, double yScale, double zScale, double radiusScale) Scales the tree by the specified factors.voidAssociates a bounding box to this tree.voidAssigns a color to all the paths in this tree.voidAssigns a color to all the paths in this tree.voidsetColor(org.scijava.util.ColorRGB color) Assigns a color to all the paths in this tree.voidSets an identifying label for this Tree.voidsetRadii(double r) Assigns a fixed radius to all the nodes in this tree.voidsetSWCType(String type) Assigns an SWC type label to all the Paths in this Tree.voidsetType(int type) Assigns an SWC type label to all the Paths in this Tree.voidshow()Displays this Tree in an appropriate viewer (3D if the tree has depth, 2D otherwise).show2D()Displays this Tree in Viewer2D.show3D()Displays this Tree in Viewer3D.intsize()Retrieves the number of paths in this tree.voidskeletonize(ij.ImagePlus destinationImp, int value) Skeletonizes (rasterizes) this tree on the specified image using Bresenham’s Algorithm (3D).subTree(int... swcTypes) Extracts the subset of paths matching the specified criteria.Extracts the subset of paths matching the specified criteria (script friendly method)voidswapAxes(int axis1, int axis2) Swaps the coordinates of two axes in this Tree.voidTransforms this tree in place using standardized flags.static Collection<Tree> transform(Collection<Tree> trees, String transformOptions, boolean inPlace) Transforms a collection of trees using standardized flags.transformedCopy(String transformOptions) Retrieves a transformed duplicate of this tree.voidtranslate(double xOffset, double yOffset, double zOffset) Translates the tree by the specified offset.voidupsample(double internodeSpacing) Downsamples the tree, i.e., increases the density of its nodes by decreasing internode spacing.booleanChecks whether this Tree has a valid soma annotation, i.e., only a single primary path tagged withPath.SWC_SOMA.
-
Field Details
-
X_AXIS
public static final int X_AXIS- See Also:
-
Y_AXIS
public static final int Y_AXIS- See Also:
-
Z_AXIS
public static final int Z_AXIS- See Also:
-
-
Constructor Details
-
Tree
public Tree()Instantiates a new empty Tree. -
Tree
Instantiates a new Tree from a set of paths.- Parameters:
paths- the Collection of paths forming this tree. Null not allowed. Note that when a Path has been fitted andPath.getUseFitted()is true, its fitted 'flavor' is used.
-
Tree
Instantiates a Tree from a collection of reconstruction nodes.- Parameters:
nodes- the collection of reconstruction nodes. Nodes will be sorted by id and any duplicate entries pruned.label- the identifying label for this Tree.
-
Tree
Instantiates a new Tree from a DirectedWeightedGraph with the specified label.The graph's nodes and edges are transformed into the path-based representation used by SNT. This constructor uses the default behavior of not preserving the original tree path structure during conversion.
- Parameters:
graph- the DirectedWeightedGraph to convert into a Tree. Must not be null.label- the label to assign to this Tree- See Also:
-
Tree
Instantiates a new Tree from a DirectedWeightedGraph with control over path structure preservation.- Parameters:
graph- the DirectedWeightedGraph to convert into a Tree. Must not be null.label- the label to assign to this TreekeepTreePathStructure- if true, preserves the original tree path structure during conversion; if false, allows reorganization for optimization- See Also:
-
Tree
Instantiates a new tree from a SWC, TRACES or JSON file.- Parameters:
filename- the absolute file path of the imported file- Throws:
IllegalArgumentException- if file path is not valid
-
Tree
Instantiates a new tree from a SWC, TRACES or JSON file with filtering.- Parameters:
filename- the absolute file path of the imported filecompartment- A case-insensitive string with at least 2 characters describing the sub-cellular compartment (axonal or dendritic) to be imported (e.g., 'axon', 'dendrites', 'axn', 'dnd', etc.). It is ignored iffilenameencodes a .TRACES file.- Throws:
IllegalArgumentException- if file path is not valid
-
Tree
Instantiates a new tree from a filtered SWC, TRACES or JSON file.- Parameters:
filename- the absolute file path of the imported fileswcTypes- only paths matching the specified SWC type(s) (e.g.,Path.SWC_AXON,Path.SWC_DENDRITE, etc.) will be imported. Ignored iffilenameencodes a .TRACES file.- Throws:
IllegalArgumentException- if file path is not valid
-
-
Method Details
-
add
Adds a new Path to this Tree.- Parameters:
p- the Path to be added- Returns:
- true, if Path successful added
-
merge
Appends all paths of a specifiedTreeto this one.- Parameters:
tree- the Tree to be merged- Returns:
- true if this Tree changed as a result of the merge
-
replaceAll
Replaces all Paths in this Tree.- Parameters:
paths- the replacing Paths
-
get
Returns the Path at the specified position.- Parameters:
index- index of the element to return- Returns:
- the element at the specified position
-
indexOf
Returns the index of the specified Path in this Tree.- Parameters:
path- the Path to be searched for- Returns:
- the path index, or -1 if it was not found
-
remove
Removes a path from this tree.- Parameters:
p- the Path to be removed- Returns:
- true if this tree contained p
-
list
Gets all the paths from this tree.- Returns:
- the paths forming this tree
-
isEmpty
public boolean isEmpty()Checks if this Tree is empty.- Returns:
- true if this tree contains no Paths, false otherwise
-
isAnnotated
public boolean isAnnotated()Checks if the nodes of this Tree have been assignedBrainAnnotations (neuropil labels).- Returns:
- true if at least one node in the Tree has a valid annotation, false otherwise
-
downsample
public void downsample(double internodeSpacing) Downsamples the tree, i.e., reduces the density of its nodes by increasing internode spacing.Note that 1) upsampling is not supported (cf.
Path.upsample(double)), and 2) the position of nodes at branch points and tips remains unaltered during downsampling, as perPath.downsample(double).- Parameters:
internodeSpacing- the maximum allowed distance between path nodes.- See Also:
-
downSample
Deprecated.Usedownsample(double)instead. -
upsample
public void upsample(double internodeSpacing) Downsamples the tree, i.e., increases the density of its nodes by decreasing internode spacing.The upscaling will include all the original nodes plus additional interpolated nodes placed at regular intervals between them, approximately equal to the specified distance. The original nodes are preserved in the upsampled tree. If the distance between two adjacent original nodes is less than the specified pacing, no additional nodes are added between them.
- Parameters:
internodeSpacing- the desired distance between adjacent nodes in the upsampled path- Throws:
IllegalArgumentException- if spacing is less than or equal to zero- See Also:
-
subTree
Extracts the subset of paths matching the specified criteria (script friendly method)- Parameters:
swcTypes- SWC type(s) a string with at least 2 characters describing the SWC type allowed in the subtree (e.g., 'soma', 'axn', or 'dendrite')- Returns:
- the subset of paths matching the filtering criteria, or an empty Tree if no hits were retrieved
-
subTree
Extracts the subset of paths matching the specified criteria.- Parameters:
swcTypes- SWC type(s) (e.g.,Path.SWC_AXON,Path.SWC_DENDRITE, etc.) allowed in the subtree- Returns:
- the subset of paths matching the filtering criteria, or an empty Tree if no hits were retrieved
-
applyProperties
Applies properties from another Tree to this Tree.- Parameters:
tree- the Tree whose properties should be copied
-
setType
public void setType(int type) Assigns an SWC type label to all the Paths in this Tree.- Parameters:
type- the SWC type (e.g.,Path.SWC_AXON,Path.SWC_DENDRITE, etc.)
-
setSWCType
Assigns an SWC type label to all the Paths in this Tree.- Parameters:
type- the SWC type (e.g., "soma", "axon", "(basal) dendrite", "apical dendrite", etc.)
-
getSWCTypes
Extracts the SWC-type flags present in this Tree.- Returns:
- the set of SWC type(s) (e.g.,
Path.SWC_AXON,Path.SWC_DENDRITE, etc.) present in the tree
-
getSWCTypes
Gets the set of SWC types present in this tree with optional soma inclusion.- Parameters:
includeSoma- if true, includes the soma type in the returned set; if false, excludesPath.SWC_SOMAfrom the result- Returns:
- a Set containing the SWC type constants (e.g.,
Path.SWC_AXON,Path.SWC_DENDRITE, etc.) present in the tree - See Also:
-
getSWCTypeNames
Gets the set of SWC type labels present in this tree with optional soma inclusion in a readable form.- Parameters:
includeSoma- if true, includes soma in the returned set; if false, excludesPath.SWC_SOMAfrom the result- Returns:
- a Set containing the SWC type labels (e.g.,
Path.SWC_AXON_LABEL,Path.SWC_DENDRITE_LABEL, etc.) present in the tree - See Also:
-
show3D
Displays this Tree in Viewer3D.- Returns:
- the
Viewer3Dinstance displaying this Tree
-
show2D
Displays this Tree in Viewer2D.- Returns:
- the
Viewer2Dinstance displaying this Tree
-
show
public void show()Displays this Tree in an appropriate viewer (3D if the tree has depth, 2D otherwise). -
getSomaNodes
Gets the list of all nodes tagged asPath.SWC_SOMA.- Returns:
- the soma nodes or null if no Paths are tagged as soma.
- See Also:
-
validSoma
public boolean validSoma()Checks whether this Tree has a valid soma annotation, i.e., only a single primary path tagged withPath.SWC_SOMA.- Returns:
- Returns true, if soma annotation is valid.
-
getRoot
Gets the first node of the main primary path of this tree- Returns:
- the root node, or null if the main primary path is undefined for this tree.
-
getBPs
Gets the branch points (junctions) of the graph. This is simply an alias forDirectedWeightedGraph.getBPs().- Returns:
- the list of branch points
- Throws:
IllegalArgumentException- if tree contains multiple roots or loops
-
getTips
Gets the end points (tips) of the graph. This is simply an alias forDirectedWeightedGraph.getTips().- Returns:
- the list of end points
- Throws:
IllegalArgumentException- if tree contains multiple roots or loops
-
applyCanvasOffset
public void applyCanvasOffset(double xOffset, double yOffset, double zOffset) Specifies the offset to be used when rendering this Tree in aTracerCanvas. Path coordinates remain unaltered.- Parameters:
xOffset- the x offset (in pixels)yOffset- the y offset (in pixels)zOffset- the z offset (in pixels)
-
translate
public void translate(double xOffset, double yOffset, double zOffset) Translates the tree by the specified offset.- Parameters:
xOffset- the x offsetyOffset- the y offsetzOffset- the z offset
-
scale
public void scale(double xScale, double yScale, double zScale) Scales the tree by the specified factors.- Parameters:
xScale- the scaling factor for x coordinatesyScale- the scaling factor for y coordinateszScale- the scaling factor for z coordinates
-
scale
public void scale(double xScale, double yScale, double zScale, double radiusScale) Scales the tree by the specified factors.- Parameters:
xScale- the scaling factor for x coordinatesyScale- the scaling factor for y coordinateszScale- the scaling factor for z coordinatesradiusScale- the scaling factor for node radii.
-
rotate
public void rotate(int axis, double angle) Rotates the tree. -
applyZCorrection
public void applyZCorrection(double correctionFactor) Applies a Z-shrinkage correction to all nodes in this tree. This is typically used to compensate for tissue compression along the Z-axis during histological processing or mounting (e.g., paraffin embedding, cryosectioning). The correction factor is the ratio of the actual (cut) thickness to the measured (mounted) thickness.- Parameters:
correctionFactor- the Z scaling factor (e.g., 2.0 to double all Z coordinates). Must be positive and non-zero.- Throws:
IllegalArgumentException- if the correction factor is not positive
-
getNodes
Gets all the nodes (path points) forming this tree.- Returns:
- the points
-
getNodesCount
public long getNodesCount()Gets the total number of nodes across all paths in this Tree.- Returns:
- the total node count
-
is3D
Assesses whether this Tree has depth.- Returns:
- true, if is 3D
- Throws:
IllegalArgumentException- if tree is empty
-
setBoundingBox
Associates a bounding box to this tree.- Parameters:
box- the BoundingBox, typically referring to the image associated with this tree
-
getBoundingBox
Gets the bounding box associated with this tree.- Returns:
- the BoundingBox. It will be computed if no boundaries have been set.
-
getBoundingBox
Gets the bounding box associated with this tree.- Parameters:
computeIfUnset- iftrueno BoundingBox has been explicitly set, and, a BoundingBox will be computed from all the nodes of this Tree- Returns:
- the BoundingBox
-
getImpContainer
public ij.ImagePlus getImpContainer(int multiDThreePaneView, int bitDepth) Gets an empty image capable of holding the skeletonized version of this tree.- Parameters:
multiDThreePaneView- the pane flag indicating the SNT view for this image e.g.,MultiDThreePanes.XY_PLANEbitDepth- 8, 16 or 32 (float)- Returns:
- the empty
ImagePluscontainer
-
skeletonize
Skeletonizes (rasterizes) this tree on the specified image using Bresenham’s Algorithm (3D).- Parameters:
destinationImp- the destination image (16-bit). It is assumed that the image dimensions are suitable, and that the spatial calibration of the image is compatible with that of this tree. Out of bound locations will be silently ignored.value- the pixel intensity of the skeleton- Throws:
IllegalArgumentException- If image is not 16-bit grayscale (unsigned)
-
getSkeleton
public ij.ImagePlus getSkeleton()Retrieves the rasterized skeleton of this tree at 1:1 scaling. This produces a 1-pixel-wide Bresenham rasterization suitable for topological analysis. For a volumetric rendering that respects node radii, seeTreeToRaster.- Returns:
- the skeletonized 8-bit binary image: (skeleton: 255, background: 0).
- See Also:
-
getSkeleton
public ij.ImagePlus getSkeleton(int pixelValue) Retrieves the rasterized skeleton of this tree at 1:1 scaling.- Parameters:
pixelValue- the voxel intensities of the skeleton. If-1, each path in the tree is rendered uniquely (labels image)- Returns:
- the skeletonized 16-bit binary image
- See Also:
-
getSkeleton2D
public ij.ImagePlus getSkeleton2D()Retrieves a 2D projection of the rasterized skeleton of this tree at 1:1 scaling.- Returns:
- the skeletonized 8-bit binary image: (skeleton: 255, background: 0).
- See Also:
-
getSkeleton2D
public ij.ImagePlus getSkeleton2D(int pixelValue) Retrieves a 2D projection of the rasterized skeleton of this tree at 1:1 scaling.- Parameters:
pixelValue- the pixel intensities of the skeleton. If-1, each path in the tree is rendered uniquely (labels image)- Returns:
- the skeletonized 16-bit binary image
- See Also:
-
size
public int size()Retrieves the number of paths in this tree.- Returns:
- Returns the number of paths in this tree.
-
setColor
public void setColor(org.scijava.util.ColorRGB color) Assigns a color to all the paths in this tree. Note that assigning a non-null color will remove node colors from Paths.- Parameters:
color- the color to be applied.- See Also:
-
setColor
Assigns a color to all the paths in this tree. Note that assigning a non-null color will remove node colors from Paths.- Parameters:
color- the color to be applied, either a 1) HTML color codes starting with hash (#), a color preset ("red", "blue", etc.), or integer triples of the formr,g,band range[0, 255]
-
setColor
Assigns a color to all the paths in this tree. Note that assigning a non-null color will remove node colors from Paths.- Parameters:
color- the color to be applied, either a 1) HTML color codes starting with hash (#), a color preset ("red", "blue", etc.), or integer triples of the formr,g,band range[0, 255]transparencyPercent- the color transparency (in percentage)
-
getColor
public org.scijava.util.ColorRGB getColor()Gets the color assigned to this Tree.- Returns:
- the Tree color, or null if no color has been assigned
-
setRadii
public void setRadii(double r) Assigns a fixed radius to all the nodes in this tree.- Parameters:
r- the radius to be assigned. Setting it to 0 or Double.NaN removes the radius attribute from the Tree
-
getProperties
Returns the Properties instance holding the persistent set of properties. Useful to associate metadata to this tree. E.g.getProperties().setProperty(Tree.KEY_SPATIAL_UNIT, "um"); String unit = getProperties().getProperty(Tree.KEY_SPATIAL_UNIT); getProperties().setProperty(Tree.KEY_COMPARTMENT, Tree.DENDRITIC);- Returns:
- the Properties instance
-
setLabel
Sets an identifying label for this Tree.- Parameters:
label- the identifying string
-
getLabel
Returns the identifying label of this tree. When importing files, the label typically defaults to the imported filename,- Returns:
- the Tree label (or null) if none has been set.
-
getNodesAsSWCPoints
- Throws:
IllegalArgumentException
-
getGraph
Assembles a DirectedGraph from this Tree.- Returns:
- the Tree's graph with edge weights corresponding to inter-node distances
- Throws:
IllegalArgumentException- if tree contains multiple roots or loops
-
rebuildGraph
public void rebuildGraph()Re-assembles the DirectedGraph object returned bygetGraph()ensuring that no untracked changes exist. Usually, calling this method is not necessary since most changes to this Tree percolate to its graph representation. -
getSparseGraph
Assembles a memory-efficient CSR-backedDirectedWeightedGraphfrom this Tree. Functionally equivalent togetGraph()(same vertex / edge content, same edge weights), but the underlying storage uses ~20x less heap per vertex than the default jgrapht specifics. Useful in batch workflows where many trees' graphs are held simultaneously, or where an analyzer is run across very large neuron collections.Trade-off:
getEdge(v1, v2)is O(out-degree of v1) instead of O(1), and per-vertex edge iteration is in reverse insertion order. Both are negligible for permutation-invariant analyses such as Strahler ordering.- Returns:
- the Tree's CSR-backed graph (cached on the Tree instance, separately from
getGraph()) - Throws:
IllegalArgumentException- if tree contains multiple roots or loops- See Also:
-
getGraph
Assembles a DirectedGraph from this Tree.- Parameters:
simplify- if true, graph will be simplified so that Tree is only represented by root, branch-points and tips.- Returns:
- the Tree's graph with edge weights corresponding to branch lengths
- Throws:
IllegalArgumentException- if tree contains multiple roots or loops
-
fromFile
Script-friendly method for loading a Tree from a reconstruction file.- Parameters:
filePath- the absolute path to the file (.Traces, (e)SWC or JSON) to be imported- Returns:
- the Tree instance, or null if file could not be imported
-
listFromFile
public static Collection<Tree> listFromFile(String tracesOrJsonFile) throws IllegalArgumentException Retrieves a list ofTrees from a single file.- Parameters:
tracesOrJsonFile- the file containing the reconstructions (typically a .traces or .json extension). A directory is also supported.- Returns:
- the collection of imported
Trees. An empty list is retrieved iftracesOrJsonFileis not a valid, readable file. - Throws:
IllegalArgumentException
-
listFromDir
Retrieves a list ofTrees from reconstruction files stored in a common directory.- Parameters:
dir- the directory containing the reconstruction files (.(e)swc, .traces, .json extension)- Returns:
- the list of imported
Trees. An empty list is retrieved ifdiris not a valid, readable directory.
-
listFromDir
Retrieves a list ofTrees from reconstruction files stored in a common directory matching the specified criteria.- Parameters:
dir- the directory containing the reconstruction files (.(e)swc, .traces, .json extension)pattern- the filename substring (case-sensitive) to be matched. Only filenames containingpatternwill be imported from the directory.nullallowed.- Returns:
- the list of imported
Trees. An empty list is retrieved ifdiris not a valid, readable directory.
-
listFromDir
Retrieves a list ofTrees from reconstruction files stored in a common directory matching the specified criteria.- Parameters:
dir- the directory containing the reconstruction files (.(e)swc, .traces, .json extension)pattern- the filename substring (case-sensitive) to be matched. Only filenames containingpatternwill be imported from the directory.nullallowed.swcTypes- SWC type(s) a string with at least 2 characters describing the SWC type allowed in the subtree (e.g., 'soma', 'axn', or 'dendrite'). Ignored whennull, or 'all'.- Returns:
- the list of imported
Trees. An empty list is retrieved ifdiris not a valid, readable directory.
-
getSWCTypeMap
Returns the SWC Type flags used by SNT.- Returns:
- the map mapping swct type flags (e.g.,
Path.SWC_AXON,Path.SWC_DENDRITE, etc.) and their respective labels
-
saveAsSWC
Saves this Tree to an SWC file.- Parameters:
filePath- the absolute path of the output file..swcis automatically appended iffilePathdoes not include an extension. If a label has been assigned,filePathcan also be a directory. If this Tree contains multiple roots, each rooted structure will be saved on a series of files with 3-digit identifiers appended to the specified file path (e.g., -000.swc, -001.swc, etc.).- Returns:
- true, if file successfully saved.
- See Also:
-
save
Saves this Tree to a .TRACES (XML, compressed) file.- Parameters:
filePath- the absolute path of the output file..tracesis automatically appended iffilePathdoes not include an extension. If a label has been assigned,filePathcan also be a directory.- Returns:
- true, if file successfully saved.
- See Also:
-
assignValue
public void assignValue(double value) Assigns a numeric property to this Tree.- Parameters:
value- the value to be assigned to this Tree.- See Also:
-
getApproximatedVolume
public double getApproximatedVolume()Retrieves an approximate estimate of Tree's volume by approximating the volume of each path, and summing to total. The volume of each path is computed assuming the volume of each of inter-node segment to be that of a truncated cone (Frustum).- Returns:
- the approximate volume or NaN if this Tree's paths have no radius
- See Also:
-
getApproximatedSurface
public double getApproximatedSurface()Retrieves an approximate estimate of Tree's surface are by approximating the surface area of each path, and summing to total. The surface of each path is computed assuming the lateral surface area of a conical frustum between nodes.- Returns:
- the approximate surface area or NaN if this Tree's paths have no radius
- See Also:
-
getAssignedValue
public double getAssignedValue()Retrieves the numeric property assigned to this Tree.- Returns:
- the assigned value.
- See Also:
-
clone
Creates a deep copy of this Tree.This method creates a complete copy of the tree including all paths and their relationships. Each path is cloned individually, and then the parent-child relationships are reconstructed in the cloned tree. This ensures that the cloned tree maintains the same structure as the original while being completely independent.
-
assignUniqueColors
Deprecated. -
assignUniqueColors
Deprecated. -
assignImage
public void assignImage(ij.ImagePlus imp) Assigns the spatial calibration of an image to this Tree.- Parameters:
imp- the image providing the spatial calibration. Null allowed.
-
assignImage
public void assignImage(net.imagej.Dataset dataset) Assigns spatial calibration from a Dataset to this Tree.- Parameters:
dataset- the Dataset providing the spatial calibration. Null allowed.
-
assignImage
public void assignImage(net.imagej.ImgPlus<?> imgPlus) Assigns spatial calibration from an ImgPlus to this Tree.- Parameters:
imgPlus- the ImgPlus providing the spatial calibration. Null allowed.
-
fitRadii
public int fitRadii(ij.ImagePlus imp) Fits radii to all paths in this Tree by fitting circular cross-sections to the image signal. Paths are fitted in parallel; results are applied sequentially. This is the scripting equivalent of the UI's "Fit Paths" action. Node positions are not modified; only radii and tangent vectors are computed.- Parameters:
imp- the image containing the signal to fit against- Returns:
- the number of paths successfully fitted
- Throws:
IllegalArgumentException- if the image is null- See Also:
-
swapAxes
public void swapAxes(int axis1, int axis2) Swaps the coordinates of two axes in this Tree. -
transform
Transforms this tree in place using standardized flags.- Parameters:
transformOptions- Space-separated String indicatingprojection,translation, androtation. E.g.,"zero-origin upright".projection flags: - "zy": ZY projection - "xz": XZ projection translation flags: - "zero-origin": each tree is translated so that its root has (0,0,0) coordinates rotation flags: - "upright": each tree is rotated to vertically align its graph geodesic - "r#": With # specifying a positive integer (e.g., r90): each tree is rotated by the specified angle (in degrees)- See Also:
-
transformedCopy
Retrieves a transformed duplicate of this tree.- Parameters:
transformOptions- seetransform(String)- Returns:
- the duplicated copy of this Tree transformed according to transformOptions
-
transform
public static Collection<Tree> transform(Collection<Tree> trees, String transformOptions, boolean inPlace) Transforms a collection of trees using standardized flags.- Parameters:
trees- the collection of Trees to be transformedtransformOptions- Space-separated String indicatingprojection,translation, androtation. E.g.,"zero-origin upright".projection flags: - "zy": ZY projection - "xz": XZ projection translation flags: - "zero-origin": each tree is translated so that its root has (0,0,0) coordinates rotation flags: - "upright-geodesic": each tree is rotated to vertically align its graph geodesic - "upright-tips": each tree is rotated to vertically align its [root, tips centroid] vector - "r#": With # specifying a positive integer (e.g., r90): each tree is rotated by the specified angle (in degrees)inPlace- If false, input trees are not affected, and transformations occur on a duplicated collection. Ignored if transformationOptions are not valid- Returns:
- the collection with transformed trees, or the input collection if transformOptions were invalid
-
getConvexHull
Retrieves the convex hull defined by all the nodes of this tree.- Returns:
- the convex hull. Either
ConvexHull2D(if this tree is two-dimensional) orConvexHull3D(if this tree is three-dimensional)
-
getConvexHull
Retrieves the convex hull of this tree.- Parameters:
type- the description of the point cloud defining the convex hull (i.e., "tips"/"end-points", "junctions"/"branch points", or "all" (default))- Returns:
- the convex hull. Either
ConvexHull2D(if this tree is two-dimensional) orConvexHull3D(if this tree is three-dimensional)
-
main
-
TreeUtils.assignUniqueColors(Collection)