[vtkusers] graph

debbie larson debbielarson_9 at hotmail.com
Thu May 31 14:10:41 EDT 2007


Hi Jeff,

Thanks
Before I try the interactive graph I was trying to visualize just one static 
graph. One thing I know is that the graph can always be represented as a 2D 
graph with the vertices aligned along the horizontal axis in vertical 
layers. I also know that vertices in one layer can only have edges with 
vertices in the layer just above. For example

   v5
    |
   v4
/    \
v2   v3
\    /
  v1

I tried to use vtkGraphLayoutViewer, but what is the appropriate 
SetLayoutStrategy here? ("Random" just gives a jumble in 3D). Or is there a 
better way of displaying this kind of graphs?

Thanks

deb


>From: "Jeff Baumes" <jeff.baumes at kitware.com>
>To: "debbie larson" <debbielarson_9 at hotmail.com>
>CC: vtkusers at vtk.org
>Subject: Re: [vtkusers] graph
>Date: Thu, 31 May 2007 09:17:22 -0400
>
>If you use the CVS version of VTK, the following should give you a
>start.  Recyclying the vertex points and using a low initial
>temperature on the layout strategy gives a jittery but reasonable
>dynamic layout.  I should also point you to vtkGraphLayoutViewer,
>which wraps most of this stuff up (but doesn't allow access to the
>inner workings to do the dynamic graph layout like this), and to
>vtkDynamic2DLabelMapper in VTK/Graphics if you want to label the
>vertices.
>
>I'm using the simple macro
>#define VTK_CREATE(type, name) \
>  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
>
>int main()
>{
>  // Create initial cycle graph
>  VTK_CREATE(vtkGraph, graph);
>  for (int i = 0; i < 100; i++)
>    {
>    graph->AddEdge(i, (i+1)%100);
>    }
>
>  // Set up graph layout pipeline
>  VTK_CREATE(vtkSimple2DLayoutStrategy, strategy);
>  strategy->SetInitialTemperature(0.5);
>  VTK_CREATE(vtkGraphLayout, layout);
>  layout->SetInput(graph);
>  layout->SetLayoutStrategy(strategy);
>  VTK_CREATE(vtkGraphToPolyData, poly);
>  poly->SetInputConnection(layout->GetOutputPort());
>  VTK_CREATE(vtkPolyDataMapper, mapper);
>  mapper->SetInputConnection(poly->GetOutputPort());
>  VTK_CREATE(vtkActor, actor);
>  actor->SetMapper(mapper);
>  VTK_CREATE(vtkGlyphSource2D, glyphSource);
>  glyphSource->SetGlyphTypeToVertex();
>  VTK_CREATE(vtkGlyph3D, glyph);
>  glyph->SetInputConnection(0, poly->GetOutputPort());
>  glyph->SetInputConnection(1, glyphSource->GetOutputPort());
>  VTK_CREATE(vtkPolyDataMapper, vmapper);
>  vmapper->SetInputConnection(glyph->GetOutputPort());
>  VTK_CREATE(vtkActor, vactor);
>  vactor->SetMapper(vmapper);
>  vactor->GetProperty()->SetPointSize(5);
>  vactor->GetProperty()->SetColor(1, 0, 0);
>
>  // Setup renderer / render window
>  VTK_CREATE(vtkRenderer, ren);
>  VTK_CREATE(vtkRenderWindow, win);
>  win->AddRenderer(ren);
>  VTK_CREATE(vtkRenderWindowInteractor, iren);
>  iren->SetRenderWindow(win);
>  VTK_CREATE(vtkInteractorStyleImage, style);
>  iren->SetInteractorStyle(style);
>  ren->AddActor(actor);
>  ren->AddActor(vactor);
>  iren->Initialize();
>
>  // Render in a loop
>  for (int i = 0; i < 400; i++)
>    {
>    // Start the layout with the existing layout
>    graph->SetPoints(layout->GetOutput()->GetPoints());
>    graph->AddEdge((int)(vtkMath::Random()*100), 
>(int)(vtkMath::Random()*100));
>    graph->Modified();
>    ren->ResetCamera();
>    iren->Render();
>    }
>  iren->Start();
>  return 0;
>}
>
>Jeff
>
>On 5/28/07, debbie larson <debbielarson_9 at hotmail.com> wrote:
>>Hi,
>>
>>I would like to plot an evolving (directed) graph. I.e. I would like to
>>display it as nodes and edges are added. The graph is being updated by 
>>some
>>computer code and I want to redraw the graph after a few node/edge 
>>additions
>>to see how it is evolving. I would like to display it in a 2D layout
>>(hopefully without edges intersecting each other). Can this be done in 
>>vtk?
>>Any pointers would be appreciated.
>>
>>Thanks
>>
>>deb
>>
>>_________________________________________________________________
>>More photos, more messages, more storage—get 2GB with Windows Live 
>>Hotmail.
>>http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507
>>
>>_______________________________________________
>>This is the private VTK discussion list.
>>Please keep messages on-topic. Check the FAQ at: 
>>http://www.vtk.org/Wiki/VTK_FAQ
>>Follow this link to subscribe/unsubscribe:
>>http://www.vtk.org/mailman/listinfo/vtkusers
>>
>
>
>--
>Jeff Baumes
>R&D Engineer, Kitware Inc.
>(518) 371-3971 x132
>jeff.baumes at kitware.com

_________________________________________________________________
PC Magazine’s 2007 editors’ choice for best Web mail—award-winning Windows 
Live Hotmail. 
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507




More information about the vtkusers mailing list