执行布局算法后可视化升压图拓扑

问题描述

我在图形上使用{ "character" : { "-MLEm-8ehLQ4repmeKtl" : { "age" : 36,"exp" : { "current" : 0,"toLvlUp" : 125,"total" : 0 },"gender" : "Male","level" : 1,"name" : "Aleksandr Brightwood" },"-MLEm-7fhLQ5rehltKjk" : { "age" : 22,"gender" : "Female","name" : "Sarah Autumn" } } } 算法 获得无簇的布局。下面是我的顶点和边的代码

fruchterman_reingold_force_directed_layout

想象一下,现在我有一个图并执行我的布局算法,这一切都很好 而且我有每个顶点的位置信息。

在布局算法后,如何可视化每个顶点最终到达的位置 完成了吗?有没有一种方法可以将位置信息获取到Dot文件中,并且我可以可视化 点文件

我具有将图形转换为点文件功能,但不知道如何 获取点位信息 文件。预先感谢。

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,1,1);
    boost::random_graph_layout(myGraph,boost::get(&SLDVertex::position,myGraph),rect_top);
    boost::fruchterman_reingold_force_directed_layout(myGraph,rect_top);
}

解决方法

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

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

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

enter image description here

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

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

neatofdp中,pos可用于设置广告的初始位置 节点。默认情况下,假定坐标为英寸。 但是,-s命令行标志可用于指定其他 单位。由于输出坐标以点为单位,因此输入 由Graphviz程序布置到neatofdp中的图形 始终需要-s标志。

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

适用于:边,节点。

,

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