[英]C++ Boost Graph Library: outputting custom vertex properties
I am struggling to get a custom property writer to work with BGL. 我正在努力让自定义属性编写器与BGL一起工作。
struct IkGraph_VertexProperty {
int id_ ;
int type_ ;
std::pair<int,int> gaussians_ ; // Type of Joint, Ids of Gaussians
};
struct IkGraph_VertexPropertyTag
{
typedef edge_property_tag kind;
static std::size_t const num;
};
std::size_t const IkGraph_VertexPropertyTag::num = (std::size_t)&IkGraph_VertexPropertyTag::num;
typedef property<IkGraph_VertexPropertyTag, IkGraph_VertexProperty> vertex_info_type;
...custom graph defined in method ...方法中定义的自定义图形
typedef adjacency_list<setS, vecS, bidirectionalS, vertex_info_type, IkGraph_EdgeProperty> TGraph ;
TGraph testGraph ;
std::ofstream outStr(filename) ;
write_graphviz(outStr, testGraph, OurVertexPropertyWriter<TGraph,IkGraph_VertexPropertyTag, IkGraph_VertexProperty>(testGraph));
... ...
template <class Graph, class VertexPropertyTag, class VertexProperty>
struct OurVertexPropertyWriter {
OurVertexPropertyWriter(Graph &g_) : g(g_) {}
template <class Vertex>
void operator() (std::ostream &out, Vertex v) {
VertexProperty p = get (VertexPropertyTag(), g, v);
out << "[label=" << p.gaussians_.first << "]";
}
Graph &g;
};
This produces a stream of errors. 这会产生错误流。
What I would really like to do (and no idea if this is possible) is to be able to generalize this and be pass which custom properties exist / which I would like outputting. 我真正想做的事情(并且不知道这是否可行)是能够概括这一点并传递哪些自定义属性/我想要输出。
I won't correct your code, because I'm not able to verify that it will work as expected. 我不会更正您的代码,因为我无法验证它是否会按预期工作。 But since I got stuck at the same problem, I will post the relevant parts of my code as an example for you and others.
但是由于我遇到了同样的问题,我会将我的代码的相关部分作为一个例子发给你和其他人。 I hope this might be helpful.
我希望这可能会有所帮助。
Definition of graph 图的定义
typedef boost::adjacency_list<boost::vecS,
boost::vecS,
boost::bidirectionalS,
boost::no_property,
EdgeProp, //this is the type of the edge properties
boost::no_property,
boost::listS> Graph;
Edge Properties 边缘属性
struct EdgeProp
{
char name;
//...
};
property writer for edges 边缘的属性作者
template <class Name>
class myEdgeWriter {
public:
myEdgeWriter(Name _name) : name(_name) {}
template <class VertexOrEdge>
void operator()(std::ostream& out, const VertexOrEdge& v) const {
out << "[label=\"" << name[v].name << "\"]";
}
private:
Name name;
};
The properties have to be attached to the edge in advance. 必须事先将属性附加到边缘。 eg
例如
EdgeProp p;
p.name = 'a';
g[edge_descriptor] = p;
Call to boost to create graphviz file 调用boost来创建graphviz文件
myEdgeWriter<Graph> w(g);
ofstream outf("net.gv");
boost::write_graphviz(outf,g,boost::default_writer(),w);
For the vertex property writer we just use the default writer. 对于顶点属性编写器,我们只使用默认编写器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.