VTK/Examples/Cxx/InfoVis/XGMLReader

From KitwarePublic

Jump to: navigation, search
VTK Examples Baseline InfoVis TestXGMLReader.png

This example reads and displays the graph from a gml file. You can test this with VTKData/Data/Infovis/fsm.gml.

XGMLReader.cxx

#include <vtkPolyData.h>
#include <vtkXGMLReader.h>
#include <vtkSmartPointer.h>
#include <vtkUndirectedGraph.h>
#include <vtkGraphLayoutStrategy.h>
#include <vtkGraphLayoutView.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSimple2DLayoutStrategy.h>
 
int main(int argc, char *argv[])
{
  if(argc != 2)
    {
    std::cout << "Required parameters: Filename" << std::endl;
    return EXIT_FAILURE;
    }
 
  std::string inputFilename = argv[1];
 
  vtkSmartPointer<vtkXGMLReader> reader = 
    vtkSmartPointer<vtkXGMLReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();
 
  vtkUndirectedGraph* g = reader->GetOutput();
 
  vtkSmartPointer<vtkGraphLayoutView> graphLayoutView = 
    vtkSmartPointer<vtkGraphLayoutView>::New();
  graphLayoutView->AddRepresentationFromInput(g);
  graphLayoutView->SetLayoutStrategy("Simple 2D");
  graphLayoutView->ResetCamera();
  graphLayoutView->Render();
 
  graphLayoutView->GetInteractor()->Start();
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
PROJECT(XGMLReader)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
if (APPLE)
  add_executable(XGMLReader MACOSX_BUNDLE XGMLReader.cxx)
else()
  add_executable(XGMLReader XGMLReader.cxx)
endif()
 
if(VTK_LIBRARIES)
  target_link_libraries(XGMLReader ${VTK_LIBRARIES})
else()
  target_link_libraries(XGMLReader vtkHybrid )
endif()
Personal tools