[vtkusers] vtkGraph: Specifying distances between all pairs of nodes for Force Directed placement

Eric E. Monson emonson at cs.duke.edu
Mon Oct 25 08:39:38 EDT 2010


Hello Amina,

The graph layout strategies (at least the force-directed types I'm familiar with) work with the concept of an edge "weight" instead of a distance. So, because a strong weight would tend to end up as a short distance after the layout, you might be able to get your desired results by inverting your distances to make weights. I hope you realize, though, that it's impossible to flatten an arbitrary graph into 2D while specifying all of the node-node distances, so some of the spacings may not end up exactly as you hope.

One way to construct the graph is to create a table with three columns. The first two contain indices that specify which vertices edges will run between, and the third column is the edge weight. Then, use vtkTableToGraph to create the graph (and the graph edges will contain the weight). If column 1 is called "index1", and column 2 is called "index2" (and column 3 is called "weight"), you would run something like (this is Python):

tgraph = vtk.vtkTableToGraph()
tgraph.SetInput(table)
tgraph.AddLinkVertex('index2', 'stuff', False)
tgraph.AddLinkVertex('index1', 'stuff', False)
tgraph.AddLinkEdge('index2', 'index1')

Other examples are linked from the doc page:
http://www.vtk.org/doc/nightly/html/classvtkTableToGraph.html

Hope this helps get you started,
-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


On Oct 24, 2010, at 8:04 PM, Amina Shabbeer wrote:

> I am trying to produce a graph layout using Force Directed placement (FDP) given distances between all pairs of nodes.  I dont understand how to specify distances between all pairs of nodes for vtkGraphs. 
> any help would be appreciated.
> Thanks,
> AS
> _______________________________________________
> 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 VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list