Package sc.fiji.snt

Class Tree

java.lang.Object
sc.fiji.snt.Tree
All Implemented Interfaces:
Cloneable, TreeProperties

public class Tree extends Object implements TreeProperties, Cloneable
Utility class to access a Collection of Paths (typically a complete reconstruction). A Tree is the preferred way to group, access and manipulate 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 Details

  • Constructor Details

    • Tree

      public Tree()
      Instantiates a new empty Tree.
    • Tree

      public Tree(Collection<Path> paths)
      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 and Path.getUseFitted() is true, its fitted 'flavor' is used.
    • Tree

      public Tree(Collection<SWCPoint> nodes, String label)
      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

      public Tree(DirectedWeightedGraph graph, String label)
      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

      public Tree(DirectedWeightedGraph graph, String label, boolean keepTreePathStructure)
      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 Tree
      keepTreePathStructure - if true, preserves the original tree path structure during conversion; if false, allows reorganization for optimization
      See Also:
    • Tree

      public Tree(String filename) throws IllegalArgumentException
      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

      public Tree(String filename, String compartment) throws IllegalArgumentException
      Instantiates a new tree from a SWC, TRACES or JSON file with filtering.
      Parameters:
      filename - the absolute file path of the imported file
      compartment - 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.
      Throws:
      IllegalArgumentException - if file path is not valid
    • Tree

      public Tree(String filename, int... swcTypes) throws IllegalArgumentException
      Instantiates a new tree from a filtered SWC, TRACES or JSON file.
      Parameters:
      filename - the absolute file path of the imported file
      swcTypes - 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.
      Throws:
      IllegalArgumentException - if file path is not valid
  • Method Details

    • add

      public boolean add(Path p)
      Adds a new Path to this Tree.
      Parameters:
      p - the Path to be added
      Returns:
      true, if Path successful added
    • merge

      public boolean merge(Tree tree)
      Appends all paths of a specified Tree to this one.
      Parameters:
      tree - the Tree to be merged
      Returns:
      true if this Tree changed as a result of the merge
    • replaceAll

      public void replaceAll(List<Path> paths)
      Replaces all Paths in this Tree.
      Parameters:
      paths - the replacing Paths
    • get

      public Path get(int index)
      Returns the Path at the specified position.
      Parameters:
      index - index of the element to return
      Returns:
      the element at the specified position
    • indexOf

      public int indexOf(Path path)
      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

      public boolean remove(Path p)
      Removes a path from this tree.
      Parameters:
      p - the Path to be removed
      Returns:
      true if this tree contained p
    • list

      public List<Path> 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 assigned BrainAnnotations (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 per Path.downsample(double).

      Parameters:
      internodeSpacing - the maximum allowed distance between path nodes.
      See Also:
    • downSample

      @Deprecated public void downSample(double internodeSpacing)
      Deprecated.
      Use downsample(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

      public Tree subTree(String... swcTypes)
      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

      public Tree subTree(int... swcTypes)
      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

      public void applyProperties(Tree tree)
      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

      public void setSWCType(String type)
      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

      public Set<Integer> 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

      public Set<Integer> getSWCTypes(boolean includeSoma)
      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, excludes Path.SWC_SOMA from 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

      public Set<String> getSWCTypeNames(boolean includeSoma)
      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, excludes Path.SWC_SOMA from 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

      public Viewer3D show3D()
      Displays this Tree in Viewer3D.
      Returns:
      the Viewer3D instance displaying this Tree
    • show2D

      public Viewer2D show2D()
      Displays this Tree in Viewer2D.
      Returns:
      the Viewer2D instance displaying this Tree
    • show

      public void show()
      Displays this Tree in an appropriate viewer (3D if the tree has depth, 2D otherwise).
    • getSomaNodes

      public List<PointInImage> getSomaNodes()
      Gets the list of all nodes tagged as Path.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 with Path.SWC_SOMA.
      Returns:
      Returns true, if soma annotation is valid.
    • getRoot

      public PointInImage 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

      public List<SWCPoint> getBPs()
      Gets the branch points (junctions) of the graph. This is simply an alias for DirectedWeightedGraph.getBPs().
      Returns:
      the list of branch points
      Throws:
      IllegalArgumentException - if tree contains multiple roots or loops
    • getTips

      public List<SWCPoint> getTips()
      Gets the end points (tips) of the graph. This is simply an alias for DirectedWeightedGraph.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 a TracerCanvas. 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 offset
      yOffset - the y offset
      zOffset - 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 coordinates
      yScale - the scaling factor for y coordinates
      zScale - 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 coordinates
      yScale - the scaling factor for y coordinates
      zScale - the scaling factor for z coordinates
      radiusScale - the scaling factor for node radii.
    • rotate

      public void rotate(int axis, double angle)
      Rotates the tree.
      Parameters:
      axis - the rotation axis. Either X_AXIS, Y_AXIS, or Z_AXIS.
      angle - the rotation angle in degrees. Ignored if 0.
    • 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

      public List<PointInImage> 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

      public boolean is3D() throws IllegalArgumentException
      Assesses whether this Tree has depth.
      Returns:
      true, if is 3D
      Throws:
      IllegalArgumentException - if tree is empty
    • setBoundingBox

      public void setBoundingBox(BoundingBox box)
      Associates a bounding box to this tree.
      Parameters:
      box - the BoundingBox, typically referring to the image associated with this tree
    • getBoundingBox

      public BoundingBox getBoundingBox()
      Gets the bounding box associated with this tree.
      Returns:
      the BoundingBox. It will be computed if no boundaries have been set.
    • getBoundingBox

      public BoundingBox getBoundingBox(boolean computeIfUnset)
      Gets the bounding box associated with this tree.
      Parameters:
      computeIfUnset - if true no 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_PLANE
      bitDepth - 8, 16 or 32 (float)
      Returns:
      the empty ImagePlus container
    • skeletonize

      public void skeletonize(ij.ImagePlus destinationImp, int value) throws IllegalArgumentException
      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, see TreeToRaster.
      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

      public void setColor(String 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, 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]
    • setColor

      public void setColor(String color, double transparencyPercent)
      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 form r,g,b and 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

      public Properties 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

      public void setLabel(String label)
      Sets an identifying label for this Tree.
      Parameters:
      label - the identifying string
    • getLabel

      public 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

      public List<SWCPoint> getNodesAsSWCPoints() throws IllegalArgumentException
      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 by 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.
    • getSparseGraph

      public SparseDirectedWeightedGraph getSparseGraph() throws IllegalArgumentException
      Assembles a memory-efficient CSR-backed DirectedWeightedGraph from this Tree. Functionally equivalent to getGraph() (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

      public DirectedWeightedGraph getGraph(boolean simplify) throws IllegalArgumentException
      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

      public static Tree fromFile(String filePath)
      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 of Trees 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 if tracesOrJsonFile is not a valid, readable file.
      Throws:
      IllegalArgumentException
    • listFromDir

      public static List<Tree> listFromDir(String dir)
      Retrieves a list of Trees 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 if dir is not a valid, readable directory.
    • listFromDir

      public static List<Tree> listFromDir(String dir, String pattern)
      Retrieves a list of Trees 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 containing pattern will be imported from the directory. null allowed.
      Returns:
      the list of imported Trees. An empty list is retrieved if dir is not a valid, readable directory.
    • listFromDir

      public static List<Tree> listFromDir(String dir, String pattern, String... swcTypes)
      Retrieves a list of Trees 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 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, or 'all'.
      Returns:
      the list of imported Trees. An empty list is retrieved if dir is not a valid, readable directory.
    • getSWCTypeMap

      public static Map<Integer,String> 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

      public boolean saveAsSWC(String filePath)
      Saves this Tree to an SWC file.
      Parameters:
      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.).
      Returns:
      true, if file successfully saved.
      See Also:
    • save

      public boolean save(String filePath)
      Saves this Tree to a .TRACES (XML, compressed) file.
      Parameters:
      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.
      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

      public Tree 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.

      Overrides:
      clone in class Object
      Returns:
      a new Tree that is a deep copy of this tree
    • assignUniqueColors

      @Deprecated public static void assignUniqueColors(Collection<Tree> trees)
    • assignUniqueColors

      @Deprecated public static void assignUniqueColors(Collection<Tree> trees, String excludedHue)
    • 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.
      Parameters:
      axis1 - the first axis. Either X_AXIS, Y_AXIS, or Z_AXIS
      axis2 - the second axis. Either X_AXIS, Y_AXIS, or Z_AXIS
    • transform

      public void transform(String transformOptions)
      Transforms this tree in place using standardized flags.
      Parameters:
      transformOptions - Space-separated String indicating projection, translation, and rotation. 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

      public Tree transformedCopy(String transformOptions)
      Retrieves a transformed duplicate of this tree.
      Parameters:
      transformOptions - see transform(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 transformed
      transformOptions - Space-separated String indicating projection, translation, and rotation. 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

      public AbstractConvexHull 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) or ConvexHull3D (if this tree is three-dimensional)
    • getConvexHull

      public AbstractConvexHull getConvexHull(String type)
      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) or ConvexHull3D (if this tree is three-dimensional)
    • main

      public static void main(String[] args)