[vtkusers] Re: Need some help with vtkGraph representation and visualisation pipeline of graphs.

Geoframer geoframer at gmail.com
Tue May 1 09:41:24 EDT 2007


I managed to actually turn it into a graph instead of the previous weird
visualisation output... however it is still not a 3d graph. Apparently the
layout of the graph is altered dependent on the edges you add, in the
previous code i had no edges.

All comments and remarks are still very welcome, especially on how to create
a 3d graph.

Regards - Geofram
--- insert new code ---
import vtk
import random

points = vtk.vtkPoints()
for i in range(500):
    points.InsertPoint(i, random.random(),random.random(),random.random())

layout = vtk.vtkRandomLayoutStrategy()
layout.ThreeDimensionalLayoutOn()
layout.AutomaticBoundsComputationOn()

graphlayout = vtk.vtkGraphLayout()
graphlayout.SetLayoutStrategy(layout)

graph = vtk.vtkGraph()
graph.SetPoints(points)
graph.SetNumberOfVertices(500)

for i in range(499):
    graph.AddEdge(i,i+1)


graphtopoly = vtk.vtkGraphToPolyData()
graphtopoly.SetInput(graph)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(graphtopoly.GetOutputPort())
mapper.SetInputConnection(graphlayout.GetOutputPort())

graphactor = vtk.vtkActor()
graphactor.SetMapper(mapper)

viewer = vtk.infovis.vtkGraphLayoutViewer()
viewer.SetInput(graph)

ren = vtk.vtkRenderer()
win = vtk.vtkRenderWindow()
win.AddRenderer(ren)
interact = vtk.vtkRenderWindowInteractor()
interact.SetRenderWindow(win)
viewer.SetRenderWindow(win)
win.GetInteractor().Initialize()
win.GetInteractor().Start()
---------
On 5/1/07, Geoframer <geoframer at gmail.com> wrote:
>
> Hey everybody,
>
> I'm relatively new to VTK but have been experimenting a bit. I'm
> particularly interested in the graph representation which is present in the
> Infovis module.
> I have been able to visualise a basic vtkRandomGraphSource (perhaps
> trivial to most of you) but now that i'm trying to create my own (3d) graph
> to visualise i get some unexpected behaviour. Basically what i (am trying
> to) do is create 500 random points (x,y,z) with random values between 0 and
> 1. With these points i want to create a (3d) graph. But as there is no
> documentation or example code on the Infovis module yet i can't seem to get
> it right. The code that i have this far (heavily flawed probably but at
> least it produces some sort of visual result) can be found below.
>
> If anyone can help me or point out some of my errors in how to create and
> visualise graphs it would be great.
>
> Kind regards - Geofram
>
> ------ insert python-code -----
> import vtk
> import random
>
> points = vtk.vtkPoints()
> for i in range(500):
>     points.InsertPoint(i, random.random(),random.random(),random.random())
>
> layout = vtk.vtkRandomLayoutStrategy()
> layout.ThreeDimensionalLayoutOn ()
> layout.AutomaticBoundsComputationOn()
>
> graphlayout = vtk.vtkGraphLayout()
> graphlayout.SetLayoutStrategy(layout)
>
> graph = vtk.vtkGraph()
> graph.SetPoints(points)
> graph.SetNumberOfVertices(500)
> graphtopoly = vtk.vtkGraphToPolyData()
> graphtopoly.SetInput(graph)
>
> mapper = vtk.vtkLabeledDataMapper()
> mapper.SetInputConnection(graphtopoly.GetOutputPort())
>
> graphactor = vtk.vtkActor2D()
> graphactor.SetMapper (mapper)
>
> viewer = vtk.infovis.vtkGraphLayoutViewer()
> viewer.SetInput(graph)
>
> ren = vtk.vtkRenderer()
> win = vtk.vtkRenderWindow()
> win.AddRenderer(ren)
> interact = vtk.vtkRenderWindowInteractor()
> interact.SetRenderWindow(win)
> viewer.SetRenderWindow(win)
> win.GetInteractor().Initialize()
> win.GetInteractor().Start()
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070501/ab7b4700/attachment.htm>


More information about the vtkusers mailing list