【问题标题】:Visualize boost graph topology after layout algorithm is performed执行布局算法后可视化提升图拓扑
【发布时间】:2020-11-03 22:43:33
【问题描述】:

我在我的图表上使用fruchterman_reingold_force_directed_layout 算法 获得无集群布局。下面是我的顶点和边的代码

using RectTopology = boost::rectangle_topology<>;
using point = RectTopology::point_type;

class MyVertex{
public:
    MyVertex(){ myObject = NULL; }
    Mybject* myObject;
    point position;
    std::string name;
};

class MyEdge{
public:
    MyEdge(){ myLine = NULL; }
    MyLine* myLine;
    double weight;
};

//Boost graph defination
using graphT = boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, MyVertex, MyEdge>;
using vertexT = boost::graph_traits<graphT>::vertex_descriptor; //Define Vertex
using vertexIt = boost::graph_traits<graphT>::vertex_iterator; //Vertex Iterator
using edgeT = boost::graph_traits<graphT>::edge_descriptor; //Define Edge
using edgeIt = boost::graph_traits<graphT>::edge_iterator; //Edge Iterator


forcedDirLay(){
    boost::minstd_rand gen;
    RectTopology rect_top(gen, 0, 0, 1, 1);
    boost::random_graph_layout(myGraph, boost::get(&SLDVertex::position, myGraph), rect_top);
    boost::fruchterman_reingold_force_directed_layout(myGraph, boost::get(&SLDVertex::position, myGraph), rect_top);
}

现在想象一下,我有一个图表并执行我的布局算法,一切正常 我有每个顶点的位置信息。

如何在布局算法之后可视化每个顶点 完成的 ?有没有办法将位置信息获取到 Dot 文件,我可以可视化 点文件?

我有一个函数可以将我的图形转换为点文件,但不知道如何 获取位置信息到点 文件。提前致谢。

GraphToDotFile(){
    std::ofstream dot(".\\graph.dot");
    boost::write_graphviz(dot, myGraph, 
        boost::make_label_writer(boost::get(&MyVertex::name, myGraph)));
    dot.close();
}

【问题讨论】:

    标签: boost layout boost-graph topology


    【解决方案1】:

    您可以使用动态属性来添加graphviz属性,参见示例:

    https://www.boost.org/doc/libs/1_74_0/libs/graph/example/graphviz.cpp

    在graphviz中指定位置的属性是here

    节点或样条控制点的位置。

    对于节点,位置表示节点的中心。输出时, 坐标以点为单位。

    neatofdp中,可以使用pos来设置一个初始位置 节点。默认情况下,坐标以英寸为单位。 但是,-s 命令行标志可用于指定不同的 单位。由于输出坐标以点为单位,因此输出 Graphviz 程序在neatofdp 中布置的图形几乎 始终需要 -s 标志。

    -n 命令行标志与neato 一起使用时,假定 位置已由布局程序之一设置,并且是 因此在积分。因此,neato -n 可以正确接受输入,而无需 需要 -s 标志,实际上忽略任何此类标志。

    适用于:边、节点。

    【讨论】:

      【解决方案2】:

      neato -n 技巧就像一个冠军。
      在上面加一点, yourProg 生成 graph.dot;然后
      neato -n -Tpng graph.dot >graph.png
      您可能需要摆弄 yourProg 以确保 graph.dot 具有所有必需的属性、单位正确等。您可以手动制作一个小示例,然后
      dot -Tdot tiny.gv >tiny.dot 并比较两个 .dot 文件

      【讨论】:

        猜你喜欢
        • 2013-11-09
        • 1970-01-01
        • 2011-01-04
        • 1970-01-01
        • 2015-12-13
        • 1970-01-01
        • 2020-01-08
        • 2021-01-05
        • 1970-01-01
        相关资源
        最近更新 更多