public class Tree
extends java.lang.Object
Path
s that share something in common,
specially when scripting SNT. Most methods are multithreaded. Note that a
"Tree" here is literally a collection of Path
s and it does not
reflect graph theory terminology.Modifier and Type | Field and Description |
---|---|
static int |
X_AXIS |
static int |
Y_AXIS |
static int |
Z_AXIS |
Constructor and Description |
---|
Tree()
Instantiates a new empty Tree.
|
Tree(java.util.Collection<Path> paths)
Instantiates a new Tree from a set of paths.
|
Tree(java.util.Collection<SWCPoint> nodes,
java.lang.String label)
Instantiates a Tree from a collection of reconstruction nodes.
|
Tree(java.lang.String filename)
Instantiates a new tree from a SWC, TRACES or JSON file.
|
Tree(java.lang.String filename,
int... swcTypes)
Instantiates a new tree from a filtered SWC, TRACES or JSON file.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Path p)
Adds a new Path to this Tree.
|
void |
applyCanvasOffset(double xOffset,
double yOffset,
double zOffset)
Specifies the offset to be used when rendering this Tree in a
TracerCanvas . |
Tree |
clone() |
void |
downSample(double maximumAllowedDeviation)
Downsamples the tree.
|
static Tree |
fromFile(java.lang.String filePath)
Script-friendly method for creating a Tree from a reconstruction file.
|
Path |
get(int index)
Returns the Path at the specified position.
|
BoundingBox |
getBoundingBox()
Gets the bounding box associated with this tree.
|
BoundingBox |
getBoundingBox(boolean computeIfUnset)
Gets the bounding box associated with this tree.
|
SNTPoint |
getCentroid() |
org.jgrapht.graph.DefaultDirectedGraph<SWCPoint,org.jgrapht.graph.DefaultWeightedEdge> |
getGraph()
Assembles a DirectedGraph from this Tree.
|
ij.ImagePlus |
getImpContainer(int multiDThreePaneView)
Gets an empty image capable of holding the skeletonized version of this
tree.
|
java.lang.String |
getLabel()
Returns the identifying label of this tree.
|
java.util.List<PointInImage> |
getNodes()
Gets all the nodes (path points) forming this tree.
|
java.util.Collection<SWCPoint> |
getNodesAsSWCPoints() |
PointInImage |
getRoot()
Gets the first node of the main primary path of this tree
|
PointInImage |
getSomaPosition()
Gets the centroid position of all nodes tagged as
Path.SWC_SOMA |
java.util.Set<java.lang.Integer> |
getSWCtypes()
Extracts the SWC-type flags present in this Tree.
|
int |
indexOf(Path path)
Returns the index of the specified Path in this Tree.
|
boolean |
is3D()
Assesses whether this Tree has depth.
|
boolean |
isEmpty()
Checks if is empty.
|
java.util.ArrayList<Path> |
list()
Gets all the paths from this tree.
|
static java.util.List<Tree> |
listFromDir(java.lang.String dir)
Retrieves a list of
Tree s from reconstruction files stored in a
common directory. |
static java.util.List<Tree> |
listFromDir(java.lang.String dir,
java.lang.String pattern)
Retrieves a list of
Tree s from reconstruction files stored in a
common directory matching the specified criteria. |
boolean |
merge(Tree tree)
Appends all paths of a specified
Tree to this one. |
boolean |
remove(Path p)
Removes a path from this tree.
|
void |
replaceAll(java.util.List<Path> paths)
Replaces all Paths in this Tree.
|
void |
rotate(int axis,
double angle)
Rotates the tree.
|
boolean |
save(java.lang.String filePath)
Saves this Tree to a .TRACES (XML, compressed) file.
|
boolean |
saveAsSWC(java.lang.String filePath)
Saves this Tree to an SWC file.
|
void |
scale(double xScale,
double yScale,
double zScale)
Scales the tree by the specified factors.
|
void |
scale(double xScale,
double yScale,
double zScale,
double radiusScale)
Scales the tree by the specified factors.
|
void |
setBoundingBox(BoundingBox box)
Associates a bounding box to this tree.
|
void |
setColor(org.scijava.util.ColorRGB color)
Assigns a color to all the paths in this tree.
|
void |
setColor(java.lang.String color)
Assigns a color to all the paths in this tree.
|
void |
setLabel(java.lang.String label)
Sets an identifying label for this Tree.
|
void |
setRadii(double r)
Assigns a fixed radius to all the nodes in this tree.
|
void |
setSWCType(java.lang.String type)
Assigns an SWC type label to all the Paths in this Tree.
|
void |
setType(int type)
Assigns an SWC type label to all the Paths in this Tree.
|
int |
size()
Retrieves the number of paths in this tree.
|
void |
skeletonize(ij.ImagePlus destinationImp,
int value) |
Tree |
subTree(int... swcTypes)
Extracts the subset of paths matching the specified criteria.
|
Tree |
subTree(java.lang.String... swcTypes)
Extracts the subset of paths matching the specified criteria (script friendly
method)
|
void |
translate(double xOffset,
double yOffset,
double zOffset)
Translates the tree by the specified offset.
|
public static final int X_AXIS
public static final int Y_AXIS
public static final int Z_AXIS
public Tree()
public Tree(java.util.Collection<Path> paths)
paths
- the Collection of paths forming this tree. Null not allowed.
Note that when a Path has been fitted and
Path.getUseFitted()
is true, its fitted 'flavor' is used.public Tree(java.util.Collection<SWCPoint> nodes, java.lang.String label)
nodes
- the collection of reconstruction nodes. Nodes will be sorted by
id and any duplicate entries pruned.label
- the identifying label for this Tree.public Tree(java.lang.String filename) throws java.lang.IllegalArgumentException
filename
- the absolute file path of the imported filejava.lang.IllegalArgumentException
- if file path is not validpublic Tree(java.lang.String filename, int... swcTypes)
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
importedpublic boolean add(Path p)
p
- the Path to be addedpublic boolean merge(Tree tree)
Tree
to this one.tree
- the Tree to be mergedpublic void replaceAll(java.util.List<Path> paths)
paths
- the replacing Pathspublic Path get(int index)
index
- index of the element to returnpublic int indexOf(Path path)
path
- the Path to be searched forpublic boolean remove(Path p)
p
- the Path to be removedpublic java.util.ArrayList<Path> list()
public boolean isEmpty()
public void downSample(double maximumAllowedDeviation)
maximumAllowedDeviation
- the maximum allowed distance between 'shaft'
path nodes. Note that 1) upsampling is not supported, and 2) the
position of nodes at branch points and tips remains unaltered
during downsamplingPathDownsampler
public Tree subTree(java.lang.String... swcTypes)
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')public Tree subTree(int... swcTypes)
swcTypes
- SWC type(s) (e.g., Path.SWC_AXON
,
Path.SWC_DENDRITE
, etc.) allowed in the subtreepublic void setType(int type)
type
- the SWC type (e.g., Path.SWC_AXON
,
Path.SWC_DENDRITE
, etc.)public void setSWCType(java.lang.String type)
type
- the SWC type (e.g., "soma", "axon", "(basal) dendrite", "apical
dendrite", etc.)public java.util.Set<java.lang.Integer> getSWCtypes()
Path.SWC_AXON
,
Path.SWC_DENDRITE
, etc.) present in the treepublic PointInImage getSomaPosition()
Path.SWC_SOMA
public PointInImage getRoot()
public SNTPoint getCentroid()
public void applyCanvasOffset(double xOffset, double yOffset, double zOffset)
TracerCanvas
. Path coordinates remain unaltered.xOffset
- the x offset (in pixels)yOffset
- the y offset (in pixels)zOffset
- the z offset (in pixels)public void translate(double xOffset, double yOffset, double zOffset)
xOffset
- the x offsetyOffset
- the y offsetzOffset
- the z offsetpublic void scale(double xScale, double yScale, double zScale)
xScale
- the scaling factor for x coordinatesyScale
- the scaling factor for y coordinateszScale
- the scaling factor for z coordinatespublic void scale(double xScale, double yScale, double zScale, double radiusScale)
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.public void rotate(int axis, double angle)
public java.util.List<PointInImage> getNodes()
public boolean is3D()
public void setBoundingBox(BoundingBox box)
box
- the BoundingBox, typically referring to the image associated
with this treepublic BoundingBox getBoundingBox()
public BoundingBox getBoundingBox(boolean computeIfUnset)
computeIfUnset
- if true
no BoundingBox has been explicitly
set, and, a BoundingBox will be compute from all the nodes of this
Treepublic ij.ImagePlus getImpContainer(int multiDThreePaneView)
multiDThreePaneView
- the pane flag indicating the SNT view for this
image e.g., MultiDThreePanes.XY_PLANE
ImagePlus
containerpublic void skeletonize(ij.ImagePlus destinationImp, int value)
public int size()
public void setColor(org.scijava.util.ColorRGB color)
color
- the color to be applied.Path.hasNodeColors()
public void setColor(java.lang.String color)
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 form r,g,b
and range
[0, 255]
public void setRadii(double r)
r
- the radius to be assigned. Setting it to 0 or Double.NaN removes
the radius attribute from the Treepublic void setLabel(java.lang.String label)
label
- the identifying stringpublic java.lang.String getLabel()
public java.util.Collection<SWCPoint> getNodesAsSWCPoints() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public org.jgrapht.graph.DefaultDirectedGraph<SWCPoint,org.jgrapht.graph.DefaultWeightedEdge> getGraph()
public static Tree fromFile(java.lang.String filePath)
filePath
- the absolute path to the file (.Traces, (e)SWC or JSON) to be
importedpublic static java.util.List<Tree> listFromDir(java.lang.String dir)
Tree
s from reconstruction files stored in a
common directory.dir
- the directory containg the reconstruction files (.(e)swc, .traces,
.json extension)Tree
s. An empty list is retrieved if
dir
is not a valid, readable directory.public static java.util.List<Tree> listFromDir(java.lang.String dir, java.lang.String pattern)
Tree
s from reconstruction files stored in a
common directory matching the specified criteria.dir
- the directory containing the reconstruction files (.(e)swc,
.traces, .json extension)pattern
- the filename substring (case sensitive) to be matched. Only
filenames containing pattern
will be imported from the
directoryTree
s. An empty list is retrieved if
dir
is not a valid, readable directory.public boolean saveAsSWC(java.lang.String filePath)
filePath
- the absolute path of the output file. .swc
is
automatically appended if filePath
does not include
an extension. If a label has been assigned, filePath
can also be a directory.setLabel(String)
public boolean save(java.lang.String filePath)
filePath
- the absolute path of the output file. .traces
is
automatically appended if filePath
does not include
an extension. If a label has been assigned, filePath
can also be a directory.setLabel(String)
public Tree clone()
clone
in class java.lang.Object