[vtkusers] graph

Jeff Baumes jeff.baumes at kitware.com
Thu May 31 09:17:22 EDT 2007


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



More information about the vtkusers mailing list