[vtkusers] graph

debbie larson debbielarson_9 at hotmail.com
Fri Jun 1 12:43:52 EDT 2007


Hi,

I tried to set the coordinates of the vertices and then visualize the graph 
with vtkGraphLayout but it seems it doesnt care about the positions of the 
vertices. I must be missing something when I set the coordinates of those 
vertices. But what? Here it is the code

//Add vertices
VTK_CREATE(vtkPoints,pts);
VTK_CREATE(vtkGraph,graph);
graph->AddVertex();
for loop
      pts->InsertNextPoint(x,y,0);
       graph->AddVertex();
end loop
graph->SetPoints(pts);

//Add Edges
for loop
   graph->AddEdge(v,p);
end loop

//view
VTK_CREATE(vtkGraphLayoutViewer,viewer);
  viewer->SetInput(graph);
   viewer->SetLayoutStrategy("Simple2D");//Tried also ForceDirected

   VTK_CREATE(vtkRenderer,ren);
   VTK_CREATE(vtkRenderWindow,win);
     win->AddRenderer(ren);
     VTK_CREATE(vtkRenderWindowInteractor,interact);
     interact->SetRenderWindow(win);
     viewer->SetRenderWindow(win);
     win->GetInteractor()->Initialize();
     win->GetInteractor()->Start();


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

_________________________________________________________________
Need a break? Find your escape route with Live Search Maps. 
http://maps.live.com/default.aspx?ss=Restaurants~Hotels~Amusement%20Park&cp=33.832922~-117.915659&style=r&lvl=13&tilt=-90&dir=0&alt=-1000&scene=1118863&encType=1&FORM=MGAC01




More information about the vtkusers mailing list