VTK/Examples/Cxx/Graphs/RandomGraphSource

From KitwarePublic

Jump to: navigation, search
VTK Examples Baseline Graphs TestRandomGraphSource.png

RandomGraphSource.cxx

#include <vtkSmartPointer.h>
 
#include <vtkGraphLayoutView.h>
#include <vtkGraphWriter.h>
#include <vtkRandomGraphSource.h>
#include <vtkRenderWindowInteractor.h>
 
int main(int, char *[])
{
  vtkSmartPointer<vtkRandomGraphSource> randomGraphSource = 
    vtkSmartPointer<vtkRandomGraphSource>::New();
  randomGraphSource->SetNumberOfVertices(5);
  randomGraphSource->SetNumberOfEdges(4);
  randomGraphSource->SetSeed(0); // This ensures repeatable results for testing. Turn this off for real use.
  randomGraphSource->Update();
 
  vtkSmartPointer<vtkGraphLayoutView> graphLayoutView = 
    vtkSmartPointer<vtkGraphLayoutView>::New();
  graphLayoutView->AddRepresentationFromInput(
    randomGraphSource->GetOutput());
  graphLayoutView->ResetCamera();
  graphLayoutView->Render();
  graphLayoutView->GetInteractor()->Start();
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
PROJECT(RandomGraphSource)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(RandomGraphSource RandomGraphSource.cxx)
TARGET_LINK_LIBRARIES(RandomGraphSource vtkHybrid  vtkViews)
Personal tools