|
| 1 | +//======================================================================= |
| 2 | +// Copyright 1997-2001 University of Notre Dame. |
| 3 | +// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek |
| 4 | +// |
| 5 | +// Distributed under the Boost Software License, Version 1.0. (See |
| 6 | +// accompanying file LICENSE_1_0.txt or copy at |
| 7 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 8 | +//======================================================================= |
| 9 | + |
| 10 | +#include <boost/config.hpp> |
| 11 | +#include <iostream> |
| 12 | +#include <vector> |
| 13 | +#include <boost/graph/strong_components.hpp> |
| 14 | +#include <boost/graph/adjacency_list.hpp> |
| 15 | +#include <boost/graph/graphviz.hpp> |
| 16 | +#include <boost/graph/graph_utility.hpp> |
| 17 | +#include "FOSMBin.hpp" |
| 18 | + |
| 19 | +typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> Graph; |
| 20 | +typedef typename Graph::vertex_descriptor vertex_descriptor; |
| 21 | +typedef typename Graph::edge_property_type edge_property; |
| 22 | + |
| 23 | + |
| 24 | +int edgecount; |
| 25 | +int read_graph(Graph & g) { |
| 26 | + // now read the graph |
| 27 | + edgecount=0; |
| 28 | + |
| 29 | + FILE * pFile; |
| 30 | + pFile = fopen ( "waynodes.bin" , "r" ); |
| 31 | + if (!pFile) { |
| 32 | + printf("file could not be opened\n"); |
| 33 | + return 2; |
| 34 | + } |
| 35 | + int waycount; |
| 36 | + int i=0; |
| 37 | + int br=fread ((void*)&waycount , sizeof(int), 1 , pFile ); // count of ways |
| 38 | + |
| 39 | + for (i =0; i < waycount; i++) { |
| 40 | + int j; |
| 41 | + int i2; |
| 42 | + fread ((void*)&i2 , sizeof(int), 1 , pFile ); // index |
| 43 | + if (i2 != i) |
| 44 | + { |
| 45 | + printf("Reading way index %d failed with a different %d\n",i,i2); |
| 46 | + return 1; |
| 47 | + } |
| 48 | + |
| 49 | + fread ((void*)&j , sizeof(int), 1 , pFile ); // size |
| 50 | + int waynodes[j]; |
| 51 | + fread ((void*)&waynodes, sizeof(int), j , pFile ); // data |
| 52 | + |
| 53 | + // now we can process the edges... |
| 54 | + |
| 55 | + vertex_descriptor prev = (int)waynodes[0]; |
| 56 | + // boost::add_edge(prev,prev, g); // loop for self |
| 57 | + // edgecount++; |
| 58 | + |
| 59 | + int j2=0; // index of the nodes in the way |
| 60 | + for (j2 =1; j2< j; j2++) { |
| 61 | + vertex_descriptor to = (int)waynodes[j2]; |
| 62 | + // edges are from the nodes to each other, not from the way to the edge |
| 63 | + boost::add_edge(prev,to, g); |
| 64 | + edgecount++; |
| 65 | + |
| 66 | + // boost::add_edge(to,prev, g); |
| 67 | + // edgecount++; |
| 68 | + prev= to; |
| 69 | + } |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + fclose (pFile); |
| 74 | + return 0; |
| 75 | +} |
| 76 | + |
| 77 | +template <class Name> |
| 78 | +void print_graph_dispatch(const Graph& G, Name name) |
| 79 | + { |
| 80 | + boost::graph_traits<Graph>::vertex_iterator ui,ui_end; |
| 81 | + for (boost::tie(ui,ui_end) = vertices(G); ui != ui_end; ++ui) { |
| 82 | + std::cout << get(name,*ui) << " "; // self edge |
| 83 | + boost::graph_traits<Graph>::out_edge_iterator ei, ei_end; |
| 84 | + for(boost::tie(ei,ei_end) = out_edges(*ui,G); ei != ei_end; ++ei) |
| 85 | + std::cout << get(name,target(*ei,G)) << " "; |
| 86 | + std::cout << std::endl; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | +int main(int, char*[]) |
| 91 | +{ |
| 92 | + using namespace boost; |
| 93 | + using namespace std; |
| 94 | + const char* name = "kosovo osm ways"; |
| 95 | + Graph G; |
| 96 | + Geography geo; |
| 97 | + int ok =read_graph(G); |
| 98 | + |
| 99 | + geo.read_data<int> ("nodeindex.bin" , geo.node_id); |
| 100 | + // int nodecount=(int) geo.node_id.size()+1; |
| 101 | + |
| 102 | + int nodecount = num_vertices(G); |
| 103 | + |
| 104 | + if(ok !=0) { |
| 105 | + return ok; |
| 106 | + } |
| 107 | + |
| 108 | + cout << edgecount << " "<< nodecount << endl; |
| 109 | + // print_graph_dispatch(G, get(vertex_index, G)); |
| 110 | + print_graph(G); |
| 111 | + |
| 112 | + return 0; |
| 113 | +} |
0 commit comments