[vtkusers] Problem to Visualize vtk directed graph with provided vtkPoints
Sonali Patil
sonalidec12 at gmail.com
Sun Jun 24 01:57:53 EDT 2012
I have written the code to visualize the Directed graph which works fine if
I use some default layout and fails if I provide vtkPoints and use pass
through strategy i.e. I get undirected graph
The following is my code snippet:
//DirectedG->SetPoints(points);
DirectedG->GetVertexData()->AddArray(label);
DirectedG->GetEdgeData()->AddArray(edgeColors);
vtkSmartPointer<vtkGraphLayout> layout =
vtkSmartPointer<vtkGraphLayout>::New();
vtkSmartPointer<vtkSimple2DLayoutStrategy> strategy =
vtkSmartPointer<vtkSimple2DLayoutStrategy>::New();
layout->SetInput(DirectedG);
layout->SetLayoutStrategy(strategy);
layout->Update();
vtkSmartPointer<vtkGraphLayoutView> graphLayoutView =
vtkSmartPointer<vtkGraphLayoutView>::New();
graphLayoutView->SetLayoutStrategyToPassThrough();
graphLayoutView->SetEdgeLayoutStrategyToPassThrough();
graphLayoutView->ScaledGlyphsOn();
graphLayoutView->SetScalingArrayName("Scales");
graphLayoutView->SetEdgeColorArrayName("Color");
graphLayoutView->ColorEdgesOn();
// Add the graph to the view. This will render vertices and edges,
// but not edge arrows.
graphLayoutView->AddRepresentationFromInputConnection(layout->GetOutputPort());
//graphLayoutView->AddRepresentationFromInput(DirectedG);
vtkSmartPointer<vtkGraphToPolyData> graphToPoly =
vtkSmartPointer<vtkGraphToPolyData>::New();
graphToPoly->SetInputConnection(layout->GetOutputPort());
//graphToPoly->SetInput(DirectedG);
graphToPoly->EdgeGlyphOutputOn();
graphToPoly->SetEdgeGlyphPosition(0.98);
graphToPoly->Update();
// Make a simple edge arrow for glyphing.
vtkSmartPointer<vtkGlyphSource2D> arrowSource =
vtkSmartPointer<vtkGlyphSource2D>::New();
arrowSource->SetGlyphTypeToEdgeArrow();
arrowSource->SetScale(0.1);
arrowSource->SetColor(1,0,0);
arrowSource->Update();
vtkSmartPointer<vtkGlyph3D> arrowGlyph =
vtkSmartPointer<vtkGlyph3D>::New();
arrowGlyph->SetInputConnection(0, graphToPoly->GetOutputPort(1));
arrowGlyph->SetInputConnection(1, arrowSource->GetOutputPort());
arrowGlyph->Update();
// Add the edge arrow actor to the view.
vtkSmartPointer<vtkPolyDataMapper> arrowMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
arrowMapper->SetInputConnection(arrowGlyph->GetOutputPort());
//arrowMapper->SetInputConnection(graphToPolyData->GetOutputPort());
vtkSmartPointer<vtkActor> arrowActor =
vtkSmartPointer<vtkActor>::New();
arrowActor->SetMapper(arrowMapper);
//arrowActor->GetProperty()->SetColor(0,0,1);
graphLayoutView->SetVertexLabelVisibility(true);
graphLayoutView->SetVertexLabelArrayName("node label");
graphLayoutView->GetRenderer()->AddActor(arrowActor);
vtkSmartPointer<vtkViewTheme> theme =
vtkSmartPointer<vtkViewTheme>::New();
theme->SetCellLookupTable(lookupTable);
graphLayoutView->ApplyViewTheme(theme);
graphLayoutView->ResetCamera();
graphLayoutView->Render();
graphLayoutView->GetInteractor()->Start();
It works fine with default layout and when I uncomment
DirectedG->SetPoints(points);
line I do get new points position but then I don't get directed graph. I
tried to use the same code without using Graphlayout too i.e. trying to
render the polydata in the renderwindow but no success.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120624/bbbf2aeb/attachment.htm>
More information about the vtkusers
mailing list