C ++ Boost Graph Library: outputting custom vertex properties

I am struggling to create my own property author for working with 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 schedule defined in the 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 creates a stream of errors.

What I really would like (and I don't know if this is possible) is to be able to generalize this and pass on what user properties exist / which I would like to output.

+3
source share
1 answer

I will not correct your code because I cannot verify that it will work as expected. But since I'm stuck in the same problem, I will send the relevant parts of my code as an example for you and others. Hope this can be helpful.

Chart definition

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;
        //...

};

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;

graphviz

myEdgeWriter<Graph> w(g);
ofstream outf("net.gv");
boost::write_graphviz(outf,g,boost::default_writer(),w);

.

+8

All Articles