Boost logo

Boost Users :

From: Andrew Chapman (andrew.chapman_at_[hidden])
Date: 2004-11-16 13:29:35


Hi everyone, I've got a fairly simple use for boost::graph, and I've
been trying to get it working, but the documentation, whilst thorough,
isn't being too helpful in getting me started.

What I'm trying to do, is build a graph of polygon mesh edges, which are
simply pairs of unsigned ints. I need to find contiguous edge lists.
Here's the setup code:

   // setup graph
   typedef std::pair<int, int> Edge;
   typedef adjacency_list<vecS, vecS, undirectedS> Graph;
   Graph g;

   // add an edge
   add_edge(6,7, g);

   cout << "Total number of vertices: " << num_vertices(g) << endl;

Which then outputs that I have 8 vertices in my graph (0 through 7),
instead of just the one I've added. So, it appears that the vertex list
is automatically managed to be contiguous.

Should I instead be adding all my edges, not caring about their vertex
index, and adding a per-vertex property to keep track of their
associated polygon mesh vertex numbers?

If so, then I presume my code for adding the edges becomes something
like (only psuedo-code here):

   vertex_descriptor v1 = add_vertex(g);
   vertex_descriptor v2 = add_vertex(g);
   set_property(v1, MyIndexProperty, 6);
   set_property(v2, MyIndexProperty, 7);
   add_edge(v1,v2,g);

..instead of what I had:

   add_edge(6,7, g);

Does that sound right?

In that case, is there a quick way of locating vertex_descriptor in a
graph based on a vertex property? Something like:

   find_vertex(g, MyIndexProperty, 6);

Sorry for all the lack of understanding, but it is quite a simple thing
I'm wanting to use the library for, and I'm finding the documentation
quite overwhelming. I suppose it is intended for when you're using the
graphs in a much more complex scenario.

Thanks in advance for any tips.

AC.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net