C++ 提升图形库:输出自定义顶点属性
C++ Boost Graph Library: outputting custom vertex properties
我正在努力让自定义属性编写器与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;
。方法中定义的自定义图形
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;
};
这会产生一系列错误。
我真正想做的(不知道这是否可能)是能够概括这一点并传递哪些自定义属性存在/我想输出。
我不会更正您的代码,因为我无法验证它是否会按预期工作。但是由于我遇到了同样的问题,我将发布我的代码的相关部分作为您和其他人的示例。我希望这可能会有所帮助。
图的定义
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;
边缘属性
struct EdgeProp
{
char name;
//...
};
边缘属性编写器
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;
};
这些属性必须提前附加到边缘。例如
EdgeProp p;
p.name = 'a';
g[edge_descriptor] = p;
调用 boost 以创建图形可视化文件
myEdgeWriter<Graph> w(g);
ofstream outf("net.gv");
boost::write_graphviz(outf,g,boost::default_writer(),w);
对于顶点属性编写器,我们只使用默认编写器。
相关文章:
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- C++自定义比较函数
- 如何比较自定义类的std::变体
- std::设置自定义比较器
- 如何正确实现和访问运算符的各种自定义枚举器
- DIRECTX9 中自定义顶点的虚拟析构函数
- 如何使用每个顶点的自定义信息创建CGAL约束的delaunay三角测量
- DirectX Toolkit加载了带有自定义HLSL着色器"顶点"着色器输入签名的模型
- 包含相邻顶点列表的自定义顶点类型[图形]:不完整类型错误
- 打印带有自定义顶点标签的助推图
- 尝试将顶点添加到自定义Graph数据结构时出现分段错误
- 将自定义顶点结构传递给 GLSL 着色器
- C++ 提升图形库:输出自定义顶点属性
- 自定义顶点处理器不起作用 - 矩阵乘法错误或其他什么?
- 将自定义属性添加到Boost图库中的网格顶点
- 几何着色器输入与自定义顶点计数在OpenGL
- 我如何定义一个自定义的方法来组合顶点
- 具有自定义顶点和边的Boost Graph
- 自定义顶点属性