[vtkusers] vtkGraph: Specifying distances between all pairs of nodes for Force Directed placement
David Doria
daviddoria at gmail.com
Mon Oct 25 08:46:51 EDT 2010
On Mon, Oct 25, 2010 at 8:39 AM, Eric E. Monson <emonson at cs.duke.edu> wrote:
>
> 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
I believe Amina is looking to also specify distances between vertices
that do not have an edge between them:
> "given distances between all pairs of nodes"
Is that correct Amina?
David
More information about the vtkusers
mailing list