Thanx Jeff,<br><br>That clarification really helps! - Geofram<br><br><div><span class="gmail_quote">On 5/7/07, <b class="gmail_sendername">Jeff Baumes</b> <<a href="mailto:jeff.baumes@kitware.com">jeff.baumes@kitware.com
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Geofram,<br><br>There are a few different ways to display a random graph in VTK. One
<br>way is to set to vertex locations manually:<br><br><code><br>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>graph = vtk.vtkGraph()<br>graph.SetPoints(points)<br>graph.SetNumberOfVertices(500)<br><br>for i in range(499):<br> graph.AddEdge(i,i+1)<br><br>graphtopoly = vtk.vtkGraphToPolyData()<br>graphtopoly.SetInput(graph)
<br><br>mapper = vtk.vtkPolyDataMapper()<br>mapper.SetInputConnection(graphtopoly.GetOutputPort())<br><br>graphactor = vtk.vtkActor()<br>graphactor.SetMapper(mapper)<br><br>ren = vtk.vtkRenderer()<br>ren.AddActor(graphactor)
<br>win = vtk.vtkRenderWindow()<br>win.AddRenderer(ren)<br>interact = vtk.vtkRenderWindowInteractor()<br>interact.SetRenderWindow(win)<br>win.GetInteractor().Initialize()<br>win.GetInteractor().Start()<br></code><br>
<br>The next is to use a random graph layout:<br><code><br>import vtk<br><br>graph = vtk.vtkGraph()<br>graph.SetNumberOfVertices(500)<br><br>for i in range(499):<br> graph.AddEdge(i,i+1)<br><br>layout = vtk.vtkRandomLayoutStrategy
()<br>layout.ThreeDimensionalLayoutOn()<br><br>graphlayout = vtk.vtkGraphLayout()<br>graphlayout.SetInput(graph)<br>graphlayout.SetLayoutStrategy(layout)<br><br>graphtopoly = vtk.vtkGraphToPolyData()<br>graphtopoly.SetInputConnection
(graphlayout.GetOutputPort())<br><br>mapper = vtk.vtkPolyDataMapper()<br>mapper.SetInputConnection(graphtopoly.GetOutputPort())<br><br>graphactor = vtk.vtkActor()<br>graphactor.SetMapper(mapper)<br><br>ren = vtk.vtkRenderer
()<br>ren.AddActor(graphactor)<br>win = vtk.vtkRenderWindow()<br>win.AddRenderer(ren)<br>interact = vtk.vtkRenderWindowInteractor()<br>interact.SetRenderWindow(win)<br>win.GetInteractor().Initialize()<br>win.GetInteractor
().Start()<br></code><br><br>The last way is to use the graph layout viewer, which creates the<br>pipeline/mappers/actors for you:<br><br><code><br>import vtk<br><br>graph = vtk.vtkGraph()<br>graph.SetNumberOfVertices
(500)<br><br>for i in range(499):<br> graph.AddEdge(i,i+1)<br><br>viewer = vtk.infovis.vtkGraphLayoutViewer()<br>viewer.SetInput(graph)<br>viewer.SetLayoutStrategy('Random');<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></code><br><br>A few notes:<br>1. The vtkGraphLayoutViewer always assigns new coordinates to vertices<br>based on a layout strategy. The default behavior is to perform a<br>force directed layout (that is why your graph was showing up as flat
<br>... the layout spread out the graph in the x and y axes).<br>2. vtkGraphLayoutViewer turns edges into lines and also glyphs the<br>vertices. vtkGraphToPolyData only turns edges into lines. You need<br>to use vtkGlyph3D to display vertices if you are not using the viewer.
<br><br>Hope this helps!<br>Jeff<br><br>--<br>Jeff Baumes<br>R&D Engineer, Kitware Inc.<br>(518) 371-3971 x132<br><a href="mailto:jeff.baumes@kitware.com">jeff.baumes@kitware.com</a><br>_______________________________________________
<br>This is the private VTK discussion list.<br>Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br>Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div><br>