public class Tree extends Object implements TreeProperties
Path
s that share something in common, specially when scripting SNT.
Note that a "Tree" here is literally a collection of Path
s. 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.Modifier and Type | Field and Description |
---|---|
static int |
X_AXIS |
static int |
Y_AXIS |
static int |
Z_AXIS |
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 and Description |
---|
Tree()
Instantiates a new empty Tree.
|
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) |
Tree(DirectedWeightedGraph graph,
String label,
boolean keepTreePathStructure) |
Tree(String filename)
Instantiates a new tree from a SWC, TRACES or JSON file.
|
Tree(String filename,
int... swcTypes)
Instantiates a new tree from a filtered SWC, TRACES or JSON file.
|
Tree(String filename,
String compartment)
Instantiates a new tree from a SWC, TRACES or JSON file with filtering.
|
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 . |
void |
applyProperties(Tree tree) |
void |
assignImage(Dataset dataset) |
void |
assignImage(ij.ImagePlus imp)
Assigns the spatial calibration of an image to this Tree.
|
static void |
assignUniqueColors(Collection<Tree> trees) |
void |
assignValue(double value)
Assigns a numeric property to this Tree.
|
Tree |
clone() |
void |
downSample(double maximumAllowedDeviation)
Downsamples the tree.
|
static Tree |
fromFile(String filePath)
Script-friendly method for creating a Tree from a reconstruction file.
|
Path |
get(int index)
Returns the Path at the specified position.
|
double |
getApproximatedVolume()
Retrieves an approximate estimate of Tree's volume by approximating the
volume of each path, and summing to total.
|
double |
getAssignedValue()
Retrieves the numeric property assigned to this Tree.
|
BoundingBox |
getBoundingBox()
Gets the bounding box associated with this tree.
|
BoundingBox |
getBoundingBox(boolean computeIfUnset)
Gets the bounding box associated with this tree.
|
DirectedWeightedGraph |
getGraph()
Assembles a DirectedGraph from this Tree.
|
DirectedWeightedGraph |
getGraph(boolean simplify)
Assembles a DirectedGraph from this Tree.
|
ij.ImagePlus |
getImpContainer(int multiDThreePaneView,
int bitDepth)
Gets an empty image capable of holding the skeletonized version of this tree.
|
String |
getLabel()
Returns the identifying label of this tree.
|
List<PointInImage> |
getNodes()
Gets all the nodes (path points) forming this tree.
|
List<SWCPoint> |
getNodesAsSWCPoints() |
Properties |
getProperties()
Returns the Properties instance holding the persistent set of properties.
|
PointInImage |
getRoot()
Gets the first node of the main primary path of this tree
|
ij.ImagePlus |
getSkeleton()
Retrieves the rasterized skeleton of this tree at 1:1 scaling.
|
protected List<Object> |
getSkeleton2()
Retrieves the rasterized skeleton of this tree at 1:1 scaling.
|
ij.ImagePlus |
getSkeleton2D()
Retrieves a 2D projection of the rasterized skeleton of this tree at 1:1
scaling.
|
List<PointInImage> |
getSomaNodes()
Gets the list of all nodes tagged as
Path.SWC_SOMA . |
static Map<Integer,String> |
getSWCTypeMap()
Returns the SWC Type flags used by SNT.
|
Set<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 |
isAnnotated()
Checks if the nodes of this Tree have been assigned
BrainAnnotation s (neuropil
labels). |
boolean |
isEmpty()
Checks if this Tree is empty.
|
ArrayList<Path> |
list()
Gets all the paths from this tree.
|
static List<Tree> |
listFromDir(String dir)
Retrieves a list of
Tree s from reconstruction files stored in a
common directory. |
static List<Tree> |
listFromDir(String dir,
String pattern)
Retrieves a list of
Tree s from reconstruction files stored in a
common directory matching the specified criteria. |
static List<Tree> |
listFromDir(String dir,
String pattern,
String... swcTypes)
Retrieves a list of
Tree s from reconstruction files stored in a
common directory matching the specified criteria. |
static Collection<Tree> |
listFromFile(String tracesOrJsonFile)
Retrieves a list of
Tree s from a single file. |
static void |
main(String[] args) |
boolean |
merge(Tree tree)
Appends all paths of a specified
Tree to this one. |
void |
rebuildGraph()
Re-assembles the DirectedGraph object returned by
getGraph()
ensuring that no untracked changes exist. |
boolean |
remove(Path p)
Removes a path from this tree.
|
void |
replaceAll(List<Path> paths)
Replaces all Paths in this Tree.
|
void |
rotate(int axis,
double angle)
Rotates the tree.
|
boolean |
save(String filePath)
Saves this Tree to a .TRACES (XML, compressed) file.
|
boolean |
saveAsSWC(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(ColorRGB color)
Assigns a color to all the paths in this tree.
|
void |
setColor(String color)
Assigns a color to all the paths in this tree.
|
void |
setColor(String color,
double transparencyPercent)
Assigns a color to all the paths in this tree.
|
void |
setLabel(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(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.
|
void |
show() |
Viewer2D |
show2D() |
Viewer3D |
show3D() |
int |
size()
Retrieves the number of paths in this tree.
|
void |
skeletonize(ij.ImagePlus destinationImp,
int value)
Skeletonizes (rasterizes) this tree on the specified image using Bresenham’s
Algorithm (3D).
|
Tree |
subTree(int... swcTypes)
Extracts the subset of paths matching the specified criteria.
|
Tree |
subTree(String... swcTypes)
Extracts the subset of paths matching the specified criteria (script friendly
method)
|
void |
swapAxes(int axis1,
int axis2)
Swaps the coordinates of two axes in this Tree.
|
void |
translate(double xOffset,
double yOffset,
double zOffset)
Translates the tree by the specified offset.
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getStandardizedCompartment
public static final int X_AXIS
public static final int Y_AXIS
public static final int Z_AXIS
public Tree()
public Tree(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(Collection<SWCPoint> nodes, 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(DirectedWeightedGraph graph, String label)
public Tree(DirectedWeightedGraph graph, String label, boolean keepTreePathStructure)
public Tree(String filename) throws IllegalArgumentException
filename
- the absolute file path of the imported fileIllegalArgumentException
- if file path is not validpublic Tree(String filename, String compartment) throws IllegalArgumentException
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 if filename
encodes a .TRACES file.IllegalArgumentException
- if file path is not validpublic Tree(String filename, int... swcTypes) throws IllegalArgumentException
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 if filename
encodes a .TRACES
file.IllegalArgumentException
- if file path is not validpublic 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(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 ArrayList<Path> list()
public boolean isEmpty()
public boolean isAnnotated()
BrainAnnotation
s (neuropil
labels).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(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 applyProperties(Tree tree)
public void setType(int type)
type
- the SWC type (e.g., Path.SWC_AXON
,
Path.SWC_DENDRITE
, etc.)public void setSWCType(String type)
type
- the SWC type (e.g., "soma", "axon", "(basal) dendrite", "apical
dendrite", etc.)public Set<Integer> getSWCTypes()
Path.SWC_AXON
,
Path.SWC_DENDRITE
, etc.) present in the treepublic Viewer3D show3D()
public Viewer2D show2D()
public void show()
public List<PointInImage> getSomaNodes()
Path.SWC_SOMA
.getRoot()
public PointInImage getRoot()
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 List<PointInImage> getNodes()
public boolean is3D() throws IllegalArgumentException
IllegalArgumentException
- if tree is emptypublic 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, int bitDepth)
multiDThreePaneView
- the pane flag indicating the SNT view for this
image e.g., MultiDThreePanes.XY_PLANE
bitDepth
- 8, 16 or 32 (float)ImagePlus
containerpublic void skeletonize(ij.ImagePlus destinationImp, int value) throws IllegalArgumentException
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 skeletonIllegalArgumentException
- If image is not 16-bit grayscale (unsigned)public ij.ImagePlus getSkeleton()
skeletonize(ImagePlus, int)
protected List<Object> getSkeleton2()
skeletonize(ImagePlus, int)
public ij.ImagePlus getSkeleton2D()
getSkeleton()
public int size()
public void setColor(ColorRGB color)
color
- the color to be applied.Path.hasNodeColors()
public void setColor(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 setColor(String color, double transparencyPercent)
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]
transparencyPercent
- the color transparency (in percentage)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 Properties getProperties()
getProperties().setProperty(Tree.KEY_SPATIAL_UNIT, "um");
String unit = getProperties().getProperty(Tree.KEY_SPATIAL_UNIT);
getProperties().setProperty(Tree.KEY_COMPARTMENT, Tree.DENDRITIC);
public void setLabel(String label)
label
- the identifying stringpublic String getLabel()
public List<SWCPoint> getNodesAsSWCPoints() throws IllegalArgumentException
IllegalArgumentException
public DirectedWeightedGraph getGraph() throws IllegalArgumentException
IllegalArgumentException
- if tree contains multiple roots or loopspublic void rebuildGraph()
getGraph()
ensuring that no untracked changes exist. Usually, calling this method is not
necessary since most changes to this Tree percolate to its graph
representation.public DirectedWeightedGraph getGraph(boolean simplify) throws IllegalArgumentException
simplify
- if true, graph will be simplified so that Tree is only
represented by root, branch-points and tips.IllegalArgumentException
- if tree contains multiple roots or loopspublic static Tree fromFile(String filePath)
filePath
- the absolute path to the file (.Traces, (e)SWC or JSON) to be
importedpublic static Collection<Tree> listFromFile(String tracesOrJsonFile) throws IllegalArgumentException
Tree
s from a single file.tracesOrJsonFile
- the file containing the reconstructions (typically a
.traces or .json extension). A directory is also
supported.Tree
s. An empty list is retrieved
if tracesOrJsonFile
is not a valid, readable file.IllegalArgumentException
public static List<Tree> listFromDir(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 List<Tree> listFromDir(String dir, 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
directory. null
allowed.Tree
s. An empty list is retrieved if
dir
is not a valid, readable directory.public static List<Tree> listFromDir(String dir, String pattern, String... swcTypes)
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
directory. null
allowed.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 when null
Tree
s. An empty list is retrieved if
dir
is not a valid, readable directory.public static Map<Integer,String> getSWCTypeMap()
Path.SWC_AXON
,
Path.SWC_DENDRITE
, etc.) and their respective labelspublic boolean saveAsSWC(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. 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).setLabel(String)
public boolean save(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 void assignValue(double value)
value
- the value to be assigned to this Tree.getAssignedValue()
public double getApproximatedVolume()
Path.getApproximatedVolume()
public double getAssignedValue()
assignValue(double)
public static void assignUniqueColors(Collection<Tree> trees)
public void assignImage(ij.ImagePlus imp)
imp
- the image providing the spatial calibration. Null allowed.public void assignImage(Dataset dataset)
public void swapAxes(int axis1, int axis2)
public static void main(String[] args)
Copyright © 2015–2021 Fiji. All rights reserved.