Hey everybody,<br><br>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.<br>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.
<br><br>If anyone can help me or point out some of my errors in how to create and visualise graphs it would be great.<br><br>Kind regards - Geofram<br><br>------ insert python-code -----<br><span class="ppt" id="_user_vtkusers@vtk.org">
</span>import vtk<br>import random<br><br>points = vtk.vtkPoints()<br>for i in range(500):<br> points.InsertPoint(i, random.random(),random.random(),random.random())<br><br>layout = vtk.vtkRandomLayoutStrategy()<br>layout.ThreeDimensionalLayoutOn
()<br>layout.AutomaticBoundsComputationOn()<br><br>graphlayout = vtk.vtkGraphLayout()<br>graphlayout.SetLayoutStrategy(layout)<br><br>graph = vtk.vtkGraph()<br>graph.SetPoints(points)<br>graph.SetNumberOfVertices(500)<br>
graphtopoly = vtk.vtkGraphToPolyData()<br>graphtopoly.SetInput(graph)<br><br>mapper = vtk.vtkLabeledDataMapper()<br>mapper.SetInputConnection(graphtopoly.GetOutputPort())<br><br>graphactor = vtk.vtkActor2D()<br>graphactor.SetMapper
(mapper)<br><br>viewer = vtk.infovis.vtkGraphLayoutViewer()<br>viewer.SetInput(graph)<br><br>ren = vtk.vtkRenderer()<br>win = vtk.vtkRenderWindow()<br>win.AddRenderer(ren)<br>interact = vtk.vtkRenderWindowInteractor()<br>
interact.SetRenderWindow(win)<br>viewer.SetRenderWindow(win)<br>win.GetInteractor().Initialize()<br>win.GetInteractor().Start()<br>