【发布时间】: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