mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-02 16:28:51 +02:00
[graph] add nodesFromNode method based on reverse dfs visit
Get the whole node chain from a start node to the graph leaves following graph edges
This commit is contained in:
parent
924dbc8d32
commit
516f909db4
2 changed files with 52 additions and 0 deletions
|
@ -1492,6 +1492,30 @@ class Graph(BaseObject):
|
|||
flowEdges.append(link)
|
||||
return flowEdges
|
||||
|
||||
def nodesFromNode(self, startNode, filterType=None):
|
||||
"""
|
||||
Return the node chain from startNode to the graph leaves.
|
||||
|
||||
Args:
|
||||
startNode (Node): the node to start the visit from.
|
||||
filterType (str): (optional) only return the nodes of the given type
|
||||
(does not stop the visit, this is a post-process only)
|
||||
Returns:
|
||||
The list of nodes from startNode to the graph leaves following edges.
|
||||
"""
|
||||
nodes = []
|
||||
edges = []
|
||||
visitor = Visitor()
|
||||
|
||||
def discoverVertex(vertex, graph):
|
||||
if not filterType or vertex.nodeType == filterType:
|
||||
nodes.append(vertex)
|
||||
|
||||
visitor.discoverVertex = discoverVertex
|
||||
visitor.examineEdge = lambda edge, graph: edges.append(edge)
|
||||
self.dfs(visitor=visitor, startNodes=[startNode], reverse=True)
|
||||
return nodes, edges
|
||||
|
||||
def _applyExpr(self):
|
||||
with GraphModification(self):
|
||||
for node in self._nodes:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue