Package sc.fiji.snt.analysis.graph
Class DirectedWeightedGraph
java.lang.Object
org.jgrapht.graph.AbstractGraph<SWCPoint,SWCWeightedEdge>
org.jgrapht.graph.AbstractBaseGraph<SWCPoint,SWCWeightedEdge>
sc.fiji.snt.analysis.graph.SNTGraph<SWCPoint,SWCWeightedEdge>
sc.fiji.snt.analysis.graph.DirectedWeightedGraph
- All Implemented Interfaces:
Serializable,Cloneable,org.jgrapht.Graph<SWCPoint,SWCWeightedEdge>
- Direct Known Subclasses:
SparseDirectedWeightedGraph
Class for accessing a reconstruction as a graph structure.
- Author:
- Tiago Ferreira, Cameron Arshadi
- See Also:
-
Field Summary
Fields inherited from interface org.jgrapht.Graph
DEFAULT_EDGE_WEIGHT -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates an empty DirectedWeightedGraph.DirectedWeightedGraph(Collection<SWCPoint> nodes, boolean assignDistancesToWeight) Creates a DirectedWeightedGraph from a collection of reconstruction nodes.protectedDirectedWeightedGraph(Supplier<SWCPoint> vertexSupplier, Supplier<SWCWeightedEdge> edgeSupplier, org.jgrapht.GraphType type, org.jgrapht.graph.GraphSpecificsStrategy<SWCPoint, SWCWeightedEdge> specificsStrategy) Subclass hook for installing a customGraphSpecificsStrategy.DirectedWeightedGraph(Tree tree) Creates a DirectedWeightedGraph from a Tree with edge weights corresponding to inter-node distances.DirectedWeightedGraph(Tree tree, boolean assignDistancesToWeight) Creates a DirectedWeightedGraph from a Tree, with the option to assign edge weights corresponding to inter-node distances. -
Method Summary
Modifier and TypeMethodDescriptionaddVertex(double x, double y, double z) voidFor all edges, sets the Euclidean distance between the source and target vertex as the weight.getBPs()Gets the branch points (junctions) of the graph.org.jgrapht.traverse.BreadthFirstIterator<SWCPoint, SWCWeightedEdge> Gets aBreadthFirstIterator, using the graph root as start vertex.org.jgrapht.traverse.BreadthFirstIterator<SWCPoint, SWCWeightedEdge> getBreadthFirstIterator(SWCPoint startVertex) Gets aBreadthFirstIterator, using the specified start vertex.Return the connected components of this graph as a list of newDirectedWeightedGraphs.org.jgrapht.traverse.DepthFirstIterator<SWCPoint, SWCWeightedEdge> Gets aDepthFirstIterator, using the graph root as start vertex.org.jgrapht.traverse.DepthFirstIterator<SWCPoint, SWCWeightedEdge> getDepthFirstIterator(SWCPoint startVertex) Gets aDepthFirstIterator, using the specified start vertex.getLongestPath(boolean useDirected) Return the sequence of nodes representing the longest shortest-path in the graph, as aPath.getLongestPathVertices(boolean useDirected) Return the sequence of nodes representing the longest shortest-path in the graph, as aDeque.Gets a NodeStatistics instance for the vertex setgetNodeStatistics(String type) Gets a NodeStatistics instance for the nodes in the vertex set of the specified typegetRoot()Gets the root of this graph.getShortestPath(SWCPoint v1, SWCPoint v2) Gets the shortest path between source and target vertex as aPathobject.getShortestPathVertices(SWCPoint v1, SWCPoint v2) Gets the shortest path between source and target vertex as aDequeof SWCPoint objects.Returns a simplified graph in which slab nodes are removed and the graph is represented only by root, branch nodes and leaves.getSubgraph(Set<SWCPoint> nodeSubset) Returns the subgraph defined by the supplied subset of vertices, including their edges.getTips()Gets the end points (tips) of the graph.org.jgrapht.traverse.TopologicalOrderIterator<SWCPoint, SWCWeightedEdge> Gets aTopologicalOrderIteratorfor this graph.getTree()Returns a new tree associated with this graph, using the current state of the graph to build the tree.getTree(boolean createNewTree) Returns a tree associated with this graph.getTrees()Return the connected components of this graph as a list ofTreesAttempt to build a new Tree with the samePathhierarchy as the source Tree.protected voidinit(Collection<SWCPoint> nodes, boolean assignDistancesToWeights) voidscale(double xScale, double yScale, double zScale, boolean updateEdgeWeightsEuclidean) Scales the point coordinates of each vertex by the specified factors.voidSets the root of the tree.show()Displays this graph in a new instance of SNT's "Dendrogram Viewer".doubleGets the sum of all edge weights.voidRe-assigns a unique Integer identifier to each vertex based on visit order during Depth First Search.vertexSet(char lr) Returns the subset of vertices contained in the given hemisphereMethods inherited from class sc.fiji.snt.analysis.graph.SNTGraph
applyEdges, applyVertices, filterEdges, filterVertices, getEdgeColor, getEdgeColorRGBMap, getVertexColor, getVertexColorRGBMap, getVertexValue, getVertexValueMap, setEdgeColor, setVertexColor, setVertexValueMethods inherited from class org.jgrapht.graph.AbstractBaseGraph
addEdge, addEdge, addVertex, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getType, getVertexSupplier, incomingEdgesOf, inDegreeOf, iterables, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSupplier, setEdgeWeight, setVertexSupplier, vertexSetMethods inherited from class org.jgrapht.graph.AbstractGraph
assertVertexExist, containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSetsMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jgrapht.Graph
containsEdge, removeAllEdges, removeAllEdges, removeAllVertices, setEdgeWeight
-
Constructor Details
-
DirectedWeightedGraph
Creates a DirectedWeightedGraph from a Tree with edge weights corresponding to inter-node distances.- Parameters:
tree- the Tree to be converted- Throws:
IllegalArgumentException- if Tree contains multiple roots
-
DirectedWeightedGraph
Creates a DirectedWeightedGraph from a Tree, with the option to assign edge weights corresponding to inter-node distances.- Parameters:
tree- the Tree to be convertedassignDistancesToWeight- whether to assign inter-node distances between adjacent points as edge weights- Throws:
IllegalArgumentException- if Tree contains multiple roots
-
DirectedWeightedGraph
public DirectedWeightedGraph()Creates an empty DirectedWeightedGraph. Edges added to the graph are unweighted until a weight is assigned manually.- See Also:
-
DirectedWeightedGraph
protected DirectedWeightedGraph(Supplier<SWCPoint> vertexSupplier, Supplier<SWCWeightedEdge> edgeSupplier, org.jgrapht.GraphType type, org.jgrapht.graph.GraphSpecificsStrategy<SWCPoint, SWCWeightedEdge> specificsStrategy) Subclass hook for installing a customGraphSpecificsStrategy. Not part of the public API — used bySparseDirectedWeightedGraphto swap jgrapht's defaultFastLookupDirectedSpecificsfor a CSR-backed variant without otherwise altering this class's behavior. -
DirectedWeightedGraph
Creates a DirectedWeightedGraph from a collection of reconstruction nodes.- Parameters:
nodes- the collections of SWC nodesassignDistancesToWeight- if true, inter-node Euclidean distances are used as edge weights
-
-
Method Details
-
init
-
getSimplifiedGraph
Returns a simplified graph in which slab nodes are removed and the graph is represented only by root, branch nodes and leaves. An edge weight in this graph corresponds to the sum of edge weights along the path between the corresponding vertices in the base graph.- Returns:
- the simplified graph
- Throws:
IllegalStateException- if the base graph does not have exactly one root
-
addVertex
-
assignEdgeWeightsEuclidean
public void assignEdgeWeightsEuclidean()For all edges, sets the Euclidean distance between the source and target vertex as the weight. -
scale
public void scale(double xScale, double yScale, double zScale, boolean updateEdgeWeightsEuclidean) Scales the point coordinates of each vertex by the specified factors.- Parameters:
xScale- the scaling factor for x coordinatesyScale- the scaling factor for y coordinateszScale- the scaling factor for z coordinatesupdateEdgeWeightsEuclidean- if true, update all edge weights with inter-node Euclidean distances
-
sumEdgeWeights
public double sumEdgeWeights()Gets the sum of all edge weights.- Returns:
- the sum of all edge weights
-
getDepthFirstIterator
Gets aDepthFirstIterator, using the graph root as start vertex.- Returns:
- the DepthFirstIterator
- Throws:
IllegalStateException- if the graph does not have exactly one root
-
getDepthFirstIterator
public org.jgrapht.traverse.DepthFirstIterator<SWCPoint,SWCWeightedEdge> getDepthFirstIterator(SWCPoint startVertex) Gets aDepthFirstIterator, using the specified start vertex.- Parameters:
startVertex- the start vertex- Returns:
- the DepthFirstIterator
-
getBreadthFirstIterator
public org.jgrapht.traverse.BreadthFirstIterator<SWCPoint,SWCWeightedEdge> getBreadthFirstIterator()Gets aBreadthFirstIterator, using the graph root as start vertex.- Returns:
- the BreadthFirstIterator
- Throws:
IllegalStateException- if the graph does not have exactly one root
-
getBreadthFirstIterator
public org.jgrapht.traverse.BreadthFirstIterator<SWCPoint,SWCWeightedEdge> getBreadthFirstIterator(SWCPoint startVertex) Gets aBreadthFirstIterator, using the specified start vertex.- Parameters:
startVertex- the start vertex- Returns:
- the BreadthFirstIterator
-
getTopologicalOrderIterator
public org.jgrapht.traverse.TopologicalOrderIterator<SWCPoint,SWCWeightedEdge> getTopologicalOrderIterator()Gets aTopologicalOrderIteratorfor this graph.- Returns:
- the TopologicalOrderIterator
-
getLongestPath
Return the sequence of nodes representing the longest shortest-path in the graph, as aPath.- Parameters:
useDirected- whether to treat the graph as directed. If true, the longest shortest-path will always include the root and a terminal node.- Returns:
- the longest shortest-path
- Throws:
IllegalStateException- if the graph does not have exactly one root
-
getLongestPathVertices
Return the sequence of nodes representing the longest shortest-path in the graph, as aDeque. This eliminates the computational overhead of converting the vertex sequence to aPathobject, if aPathis not desired.- Parameters:
useDirected- whether to treat the graph as directed. If true, the longest shortest-path will always include the root and a terminal node.- Returns:
- the longest shortest-path
- Throws:
IllegalStateException- if the graph does not have exactly one root
-
getShortestPath
Gets the shortest path between source and target vertex as aPathobject. Since underlying edge direction is ignored, a shortest path will always exist between any two vertices that share a connected component.- Parameters:
v1- the source vertexv2- the target vertex- Returns:
- the shortest Path between source v1 and target v2, or null if no path exists
- Throws:
IllegalArgumentException- if the graph does not contain both v1 and v2
-
getShortestPathVertices
Gets the shortest path between source and target vertex as aDequeof SWCPoint objects. This eliminates the computational overhead of creating aPathobject from the vertex sequence, if aPathis not desired. Since underlying edge direction is ignored, a shortest path will always exist between any two vertices that share a connected component.- Parameters:
v1- the source vertexv2- the target vertex- Returns:
- the shortest path between source v1 and target v2, or null if no path exists
- Throws:
IllegalArgumentException- if the graph does not contain both v1 and v2
-
updateVertexProperties
public void updateVertexProperties()Re-assigns a unique Integer identifier to each vertex based on visit order during Depth First Search. Also updates the parent and previousPoint fields of each SWCPoint vertex contained in the Graph.- Throws:
IllegalStateException- if the graph does not contain exactly one root
-
getBPs
Gets the branch points (junctions) of the graph.- Returns:
- the list of branch points
-
getTips
Gets the end points (tips) of the graph.- Returns:
- the list of end points
-
getNodeStatistics
Gets a NodeStatistics instance for the vertex set- Returns:
- the NodeStatistics instance
-
getNodeStatistics
Gets a NodeStatistics instance for the nodes in the vertex set of the specified type- Parameters:
type- the vertex type (e.g., "tips"/"end-points", "junctions"/"branch points", "all")- Returns:
- the NodeStatistics instance
-
getRoot
Gets the root of this graph.- Returns:
- the root node.
- Throws:
IllegalStateException- if the graph does not contain exactly one root
-
getTree
Returns a new tree associated with this graph, using the current state of the graph to build the tree.- Returns:
- the tree
- Throws:
IllegalStateException- if the graph does not have exactly one root
-
getTree
Returns a tree associated with this graph.- Parameters:
createNewTree- If true, reassembles a tree from this graph's data. If false, returns the cached tree if it exists or null if it does not exist- Returns:
- the tree
-
getTreeWithSamePathStructure
Attempt to build a new Tree with the samePathhierarchy as the source Tree.- Returns:
- the tree
-
getComponents
Return the connected components of this graph as a list of newDirectedWeightedGraphs.- Returns:
- the list of DirectedWeightedGraph objects
-
getTrees
Return the connected components of this graph as a list ofTrees- Returns:
- the list of Tree objects
-
getSubgraph
Returns the subgraph defined by the supplied subset of vertices, including their edges.- Parameters:
nodeSubset- a subset of this graph's vertex set- Returns:
- the subgraph
-
vertexSet
Returns the subset of vertices contained in the given hemisphere- Parameters:
lr- the hemisphere (i.e.,BrainAnnotation.LEFT_HEMISPHERE,BrainAnnotation.RIGHT_HEMISPHERE,BrainAnnotation.ANY_HEMISPHERE- Returns:
- the vertex subset
-
setRoot
Sets the root of the tree. This modifies the edge directions such that all other nodes in the graph have the new root as ancestor.- Parameters:
newRoot- the new root of the tree, which must be an existing vertex of the graph- Throws:
IllegalArgumentException- if the graph does not contain newRoot
-
getNodesFromRootToLeaves
-
getNodesFromLeavesToRoot
-
show
Displays this graph in a new instance of SNT's "Dendrogram Viewer".- Returns:
- a reference to the displayed window.
- Throws:
IllegalStateException- if the graph does not have exactly one root
-