-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbgl.cpp
67 lines (54 loc) · 1.81 KB
/
bgl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <fstream>
#include <string>
#include <boost/graph/graphviz.hpp>
using namespace boost;
using namespace std;
#include <stdio.h>
// see also : http://www.informit.com/articles/article.aspx?p=673259&seqNum=7
int main (int argc, char* argv[])
{
// typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> Graph;
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS> Graph;
// typedef graph_traits<Graph> Traits;
typedef typename Graph::vertex_descriptor vertex_descriptor;
typedef typename Graph::edge_property_type edge_property;
//const typename Config::edge_property_type& p,
// typedef adjacency_list< vecS, vecS, directedS> Graph;
Graph g;
// now read the graph
FILE * pFile;
pFile = fopen ( "waynodes.bin" , "r" );
if (!pFile) {
printf("file could not be opened\n");
return 2;
}
int waycount;
int i=0;
int br=fread ((void*)&waycount , sizeof(int), 1 , pFile ); // count of ways
for (i =0; i < waycount; i++) {
int j;
int i2;
fread ((void*)&i2 , sizeof(int), 1 , pFile ); // index
if (i2 != i)
{
printf("Reading way index %d failed with a different %d\n",i,i2);
return 1;
}
fread ((void*)&j , sizeof(int), 1 , pFile ); // size
int waynodes[j];
fread ((void*)&waynodes, sizeof(int), j , pFile ); // data
// now we can process the edges...
int j2=0;
vertex_descriptor prev = (int)waynodes[0];
for (j2 =1; j2< j; j2++) {
vertex_descriptor to = (int)waynodes[j2];
// edges are from the nodes to each other, not from the way to the edge
boost::add_edge(prev,to, g);
prev= to;
}
}
boost::write_graphviz(std::cout, g);
fclose (pFile);
}