[vtkusers] graph

Wylie, Brian bnwylie at sandia.gov
Fri Jun 1 13:18:08 EDT 2007


Hmmmm...

Well good news and bad news....

The good news is that in our sandbox we have a vtkPassThrough strategy
that doesn't change the position of the vertices at all... The bad news
is that it's not yet in vtk. :(

I think the best way to "hack" it until we get that in VTK (like 2 weeks
from now probably) is to do the following....

In vtkGraphLayoutViewer.cxx line 415 ish...

  else if (!strcmp(strategyName, "Simple2D"))
    {
    strategy = vtkSimple2DLayoutStrategy::New();
    vtkSimple2DLayoutStrategy::SafeDownCast(strategy)
      ->SetMaxNumberOfIterations(100);
    vtkSimple2DLayoutStrategy::SafeDownCast(strategy)
      ->SetIterationsPerLayout(100);
    vtkSimple2DLayoutStrategy::SafeDownCast(strategy)
      ->SetInitialTemperature(1);
    }

Change to something like....

  else if (!strcmp(strategyName, "Simple2D"))
    {
    strategy = vtkSimple2DLayoutStrategy::New();
    vtkSimple2DLayoutStrategy::SafeDownCast(strategy)
      ->SetMaxNumberOfIterations(0);
    vtkSimple2DLayoutStrategy::SafeDownCast(strategy)
      ->SetIterationsPerLayout(0);
    vtkSimple2DLayoutStrategy::SafeDownCast(strategy)
      ->SetInitialTemperature(0);
    vtkSimple2DLayoutStrategy::SafeDownCast(strategy)
      ->vtkSetJitter(false);
    }

This means the layout basically shouldn't DO anything


Should work.... Sorry for making you hack the code... Like I said the
'pass-through' strategy should be in soon....

  Brian Wylie - Org 1424
  Sandia National Laboratories
  MS 0822 - Building 880/A1-J
  (505)844-2238 FAX(505)845-0833    
       _______ __
      /_  __(_) /_____ _____
       / / / / __/ __ `/ __ \
      / / / / /_/ /_/ / / / /
     /_/ /_/\__/\__,_/_/ /_/
            VTK Informatics Toolkit
  

> -----Original Message-----
> From: vtkusers-bounces+bnwylie=sandia.gov at vtk.org 
> [mailto:vtkusers-bounces+bnwylie=sandia.gov at vtk.org] On 
> Behalf Of debbie larson
> Sent: Friday, June 01, 2007 10:44 AM
> To: vtkusers at vtk.org
> Subject: Re: [vtkusers] graph
> 
> 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=TX
> T_TAGHM_mi
> >>gration_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~Amusem
> ent%20Park&cp=33.832922~-117.915659&style=r&lvl=13&tilt=-90&di
> r=0&alt=-1000&scene=1118863&encType=1&FORM=MGAC01
> 
> _______________________________________________
> 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
> 
> 




More information about the vtkusers mailing list