[Paraview] Converting a graph to a tree
Tim Gallagher
tim.gallagher at gatech.edu
Thu Oct 8 22:50:07 EDT 2015
Hi all,
I am working on visualization of topological features and I have hit a VTK wall. I have a 2D structured grid that has been built into a vtkMutableDirectedGraph with the vertices as the nodes and the connections between vertices as the edges (not all vertices will end up connected eventually). I am trying to create a breadth-first search tree from my graph so then I can find leaf nodes and prune them unless they meet certain criteria.
I am working in Python but have been digging through the VTK C++ examples to figure out how to do it. The example for the vtkBoostBreadthFirstSearchTree says it can be used to convert a graph into a tree so that's what I have tried. My code to do the conversion looks like:
bfs_tree = vtk.vtkBoostBreadthFirstSearchTree()
bfs_tree.SetOriginVertex(0)
bfs_tree.SetInput(self.graph)
bfs_tree.Update()
tree = bfs_tree.GetOutput()
This appears to work (no errors are thrown). I then try to iterate over the tree to find the leaves. I create and loop over my iterator with:
tree_iterator = vtk.vtkTreeBFSIterator()
tree_iterator.SetStartVertex(0)
tree_iterator.SetTree(tree)
while tree_iterator.HasNext():
node = tree_iterator.Next()
print node, tree.GetLevel(node)
where my print statement is just to debug what is happening. The printout looks like:
0 0
1 1
2 2
3 3
4 4
5 5
so my tree is just a straight line. This is a 20x20 fully connected (for now) structured mesh, so my tree should have more than 5 nodes to it and shouldn't be a straight line.
Am I missing something in how this works? Or have I gone about this in a totally backwards way?
Related question -- will the value of the node from the iterator match that of the graph or does the tree renumber things?
Thanks,
Tim
More information about the ParaView
mailing list