vtk实战(六)—读取".gml"文件

.gml格式,用于描述图结构的ASCII文本格式文件;说明图中基于文本的层次结构的结构,并包括组成该图中的节点,边和属性。该格式可以形容家谱,流程图,网络等图形结构。
主要到的类:

vtkXGMLReader()

该类主要用于读取”.gml”格式的文件。
程序代码:

#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[])
{

    std::string inputFilename = "fsm.gml";

    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;
}

vtk实战(六)—读取".gml"文件_第1张图片

程序链接:http://pan.baidu.com/s/1kVzsL87

你可能感兴趣的:(VTK)