VTK/Examples/Cxx/Graphs/VisualizeGraph
From KitwarePublic
This example shows how to construct a graph and visualize it. You can select edges and vertices with the mouse.
VisualizeGraph.cxx
#include <vtkSmartPointer.h> #include <vtkGraphLayoutStrategy.h> #include <vtkGraphLayoutView.h> #include <vtkGraphWriter.h> #include <vtkMutableUndirectedGraph.h> #include <vtkRenderWindowInteractor.h> #include <vtkSimple2DLayoutStrategy.h> int main(int, char *[]) { vtkSmartPointer<vtkMutableUndirectedGraph> g = vtkSmartPointer<vtkMutableUndirectedGraph>::New(); vtkIdType v1 = g->AddVertex(); vtkIdType v2 = g->AddVertex(); g->AddEdge(v1, v2); g->AddEdge(v1, v2); vtkSmartPointer<vtkGraphLayoutView> graphLayoutView = vtkSmartPointer<vtkGraphLayoutView>::New(); graphLayoutView->AddRepresentationFromInput(g); graphLayoutView->SetLayoutStrategy("Simple 2D"); graphLayoutView->ResetCamera(); graphLayoutView->Render(); vtkSimple2DLayoutStrategy::SafeDownCast(graphLayoutView->GetLayoutStrategy())->SetRandomSeed(0); graphLayoutView->GetInteractor()->Start(); return EXIT_SUCCESS; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(VisualizeGraph) FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE}) ADD_EXECUTABLE(VisualizeGraph VisualizeGraph.cxx) TARGET_LINK_LIBRARIES(VisualizeGraph vtkHybrid vtkViews)
