问题描述
作为新升压图形库,我发现它往往很难梳理出并列什么的例子件的具体例子,哪些部分是普遍的用法。
作为练习,我试图做一个简单的图形,颜色属性分配给顶点,并输出结果的Graphviz使颜色显示为得到呈现颜色属性。任何帮助将是AP preciated!这里是我到目前为止(更具体的用法的问题是在这里评论)
的#includefstream的
#包括升压/图/ graphviz.hpp
#包括升压/图/ adjacency_list.hpp结构vertex_info {
INT色;
};TYPEDEF提振::的adjacency_list<促进血管内皮细胞::,促进血管内皮细胞::,提振:: undirectedS,vertex_info>图形;
的typedef的std ::对< INT,INT>边缘;诠释主要(无效){
图克;
的add_edge(0,1,G);
的add_edge(1,2,G); //一些穿越和颜色分配给3个顶点替换此...
//我应该使用这个捆绑的属性?
//目前还不清楚我怎么会得到write_graphviz承认捆绑属性作为颜色属性
政[0]。颜色= 1; 的std :: ofstream的OUTF(min.gv);
write_graphviz(OUTF,G); //我怎样才能使write_graphviz输出顶点颜色?
}
尝试:
的boost :: dynamic_properties的DP;
dp.property(色,得到(安培; vertex_info ::色,G));
dp.property(NODE_ID,得到(升压::的vertex_index,g)条);
write_graphviz_dp(OUTF,G DP);
而不是你的 write_graphviz
通话。请参见获得这样的一个例子。请注意,code我会贴写出来的颜色像点的整数,而不是颜色名称要求。
Being new to the boost graph library, I find it's often difficult to tease out what pieces of the examples are tied to the particular example and which parts are universal to usage.
As an exercise, I'm trying to make a simple graph, assign a color property to the vertices, and output the result to graphviz so colors appear as color attributes that get rendered. Any help would be appreciated! Here's what I have so far (more specific usage questions are in the comments here):
#include "fstream"
#include "boost/graph/graphviz.hpp"
#include "boost/graph/adjacency_list.hpp"
struct vertex_info {
int color;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, vertex_info> Graph;
typedef std::pair<int, int> Edge;
int main(void) {
Graph g;
add_edge(0, 1, g);
add_edge(1, 2, g);
// replace this with some traversing and assigning of colors to the 3 vertices ...
// should I use bundled properties for this?
// it's unclear how I would get write_graphviz to recognize a bundled property as the color attribute
g[0].color = 1;
std::ofstream outf("min.gv");
write_graphviz(outf, g); // how can I make write_graphviz output the vertex colors?
}
Try:
boost::dynamic_properties dp;
dp.property("color", get(&vertex_info::color, g));
dp.property("node_id", get(boost::vertex_index, g));
write_graphviz_dp(outf, g, dp);
instead of your write_graphviz
call. See http://www.boost.org/doc/libs/1_47_0/libs/graph/example/graphviz.cpp for an example of this. Note that the code I posted will write out the colors as integers, not color names like Dot requires.
这篇关于Boost图库 - 顶点颜色和输出graphviz的小例子,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!