[Paraview] Converting a graph to a tree

Tim Gallagher tim.gallagher at gatech.edu
Thu Oct 8 23:31:16 EDT 2015


Well... I figured out the answers to my own questions! 

My tree was poorly formed because I needed to change my start location to a known location (and in my case, reverse the edges) so that it actually built the full tree. Once that was done, I get the expected tree iterator. 

And to answer my own questions at the end, the graph nodes need to be stored on the tree by doing:

     bfs_tree.CreateGraphVertexIdArrayOn()
     ...
     graph_ids = tree.GetVertexData().GetArray("GraphVertexId")

Tim

----- Original Message -----
From: "Tim Gallagher" <tim.gallagher at gatech.edu>
To: "ParaView list" <paraview at paraview.org>
Sent: Thursday, October 8, 2015 10:50:07 PM
Subject: [Paraview] Converting a graph to a tree

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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview


More information about the ParaView mailing list