VTK/Examples/Cxx/Broken/Graphs/TableToGraph

From KitwarePublic

Jump to: navigation, search

Vertex labels are wrong. Edge labels are not displayed.

TableToGraph.cxx

#include <vtkTable.h>
#include <vtkTableToGraph.h>
#include <vtkVariant.h>
#include <vtkVariantArray.h>
#include <vtkSmartPointer.h>
#include <vtkGraphLayoutStrategy.h>
#include <vtkGraphLayoutView.h>
#include <vtkGraphWriter.h>
#include <vtkMutableUndirectedGraph.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSimple2DLayoutStrategy.h>
#include <vtkAdjacencyMatrixToEdgeTable.h>
#include <vtkDenseArray.h>
#include <vtkArrayData.h>
#include <vtkArrayPrint.h>
 
int main(int, char *[])
{
   vtkSmartPointer<vtkDenseArray<double> > array =
    vtkSmartPointer<vtkDenseArray<double> >::New();
 
  array->Resize(3,3);
 
  array->SetValue(0, 0, 0);
  array->SetValue(1, 1, 0);
  array->SetValue(2, 2, 0);
  array->SetValue(0, 1, 10);
  array->SetValue(0, 2, 15);
  array->SetValue(1, 2, 25);
 
  vtkPrintMatrixFormat(std::cout, array.GetPointer());
 
  array->SetDimensionLabel(0, "rows");
  array->SetDimensionLabel(1, "columns");
 
  vtkSmartPointer<vtkArrayData> arrayData =
    vtkSmartPointer<vtkArrayData>::New();
  arrayData->AddArray(array);
 
  vtkSmartPointer<vtkAdjacencyMatrixToEdgeTable> adjacencyMatrixToEdgeTable =
    vtkSmartPointer<vtkAdjacencyMatrixToEdgeTable>::New();
  adjacencyMatrixToEdgeTable->SetInputConnection(arrayData->GetProducerPort());
  adjacencyMatrixToEdgeTable->Update();
 
  adjacencyMatrixToEdgeTable->GetOutput()->Dump();
 
 
  vtkSmartPointer<vtkTableToGraph> tableToGraph =
    vtkSmartPointer<vtkTableToGraph>::New();
  tableToGraph->SetInputConnection(adjacencyMatrixToEdgeTable->GetOutputPort());
  tableToGraph->AddLinkVertex("rows");
  tableToGraph->AddLinkVertex("columns");
 
  tableToGraph->AddLinkEdge("rows", "columns");
  tableToGraph->Update();
 
  vtkSmartPointer<vtkGraphLayoutView> graphLayoutView =
    vtkSmartPointer<vtkGraphLayoutView>::New();
  graphLayoutView->AddRepresentationFromInput(tableToGraph->GetOutput());
  graphLayoutView->SetVertexLabelVisibility(true);
  graphLayoutView->SetEdgeLabelVisibility(true);
  graphLayoutView->SetEdgeLabelArrayName("values");
  graphLayoutView->ResetCamera();
  graphLayoutView->Render();
 
  graphLayoutView->GetInteractor()->Start();
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

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