$search
00001 /* -*- mode: C++ -*- */ 00002 /* 00003 * Copyright (C) 2007 Tarun Nimmagadda, Mickey Ristroph, Patrick Beeson 00004 * Copyright (C) 2010 Jack O'Quin 00005 * 00006 * License: Modified BSD Software License Agreement 00007 * 00008 * $Id: Graph.h 588 2010-09-16 02:59:00Z jack.oquin $ 00009 */ 00010 00018 #ifndef __GRAPH_h__ 00019 #define __GRAPH_h__ 00020 00021 #include <vector> 00022 #include <algorithm> 00023 #include <fstream> 00024 #include <cstdlib> 00025 00026 #include <art_map/coordinates.h> 00027 #include <art_map/types.h> 00028 00029 typedef std::vector<WayPointEdge> WayPointEdgeList; 00030 typedef std::vector<WayPointNode> WayPointNodeList; 00031 typedef std::vector<WayPointNodeList> ZoneList; 00032 typedef std::vector<int> intList; 00033 00034 00035 00036 class Graph{ 00037 public: 00038 Graph(){ 00039 nodes_size = 0; 00040 edges_size = 0; 00041 nodes=NULL; 00042 edges.clear(); 00043 }; 00044 00045 Graph(uint num_nodes, uint num_edges, 00046 const WayPointNode nnodes[], 00047 const WayPointEdge nedges[]) { 00048 nodes_size=num_nodes; 00049 nodes = new WayPointNode[nodes_size]; 00050 for (uint i=0; i< num_nodes; i++) 00051 nodes[i]=nnodes[i]; 00052 00053 edges_size=num_edges; 00054 edges.clear(); 00055 for (uint i=0; i< num_edges; i++) 00056 edges.push_back(nedges[i]); 00057 }; 00058 00059 Graph(Graph& that){ 00060 this->nodes_size=that.nodes_size; 00061 this->nodes = new WayPointNode[this->nodes_size]; 00062 for (uint i=0; i< (uint)this->nodes_size; i++) 00063 this->nodes[i] = that.nodes[i]; 00064 00065 this->edges_size=that.edges_size; 00066 this->edges=that.edges; 00067 }; 00068 00069 00070 ~Graph(){ 00071 if (this->nodes !=NULL) 00072 delete[] this->nodes; 00073 edges.clear(); 00074 }; 00075 00076 //Operators 00077 //bool operator==(const Graph &that); 00078 bool compare(const Graph &that) 00079 { 00080 bool size_check = (this->nodes_size == that.nodes_size 00081 && this->edges_size == that.edges_size); 00082 bool node_check = true, edge_check = true; 00083 //REVERSE THIS BOOLEAN CHECK 00084 for (uint i=0; i< (uint)this->nodes_size; i++){ 00085 node_check = (this->nodes[i] == that.nodes[i]) && node_check; 00086 if (!node_check) printf("Node Number %d\n", i); 00087 } 00088 //REVERSE THIS BOOLEAN CHECK 00089 for (uint i=0; i< (uint)this->edges_size; i++) 00090 edge_check = (this->edges[i] == that.edges[i]) && edge_check; 00091 00092 if (!size_check) printf("Graph Sizes don't match\n"); 00093 if (!node_check) printf("Graph Nodes don't match\n"); 00094 if (!edge_check) printf("Graph Edges don't match\n"); 00095 return (size_check && node_check && edge_check); 00096 } 00097 00098 WayPointEdgeList edges_from(const waypt_index_t index) const; 00099 WayPointEdgeList edges_leaving_segment(const segment_id_t seg) const; 00100 00101 00102 // Hooks to save, reload Graph state 00103 void save(const char* fName); 00104 bool load(const char* fName); 00105 00106 void clear(); 00107 void find_mapxy(void); 00108 void find_implicit_edges(); 00109 void xy_rndf(); 00110 bool rndf_is_gps(); 00111 00112 void printNodes(); 00113 void printEdges(); 00114 00115 // Print to a file (MQ 8/15/07) 00116 void printNodesFile(const char* fName); 00117 void printEdgesFile(const char* fName); 00118 00119 // get node by ElementID (JOQ 8/25/07) 00120 WayPointNode *get_node_by_id(const ElementID id) const; 00121 WayPointNode* get_node_by_index(const waypt_index_t index) const; 00122 00123 WayPointNode* get_closest_node(const MapXY &p) const; 00124 WayPointNode* get_closest_node_within_radius(const MapXY &p) const; 00125 00126 WayPointNode* nodes; 00127 std::vector<WayPointEdge> edges; 00128 uint32_t nodes_size; 00129 uint32_t edges_size; 00130 bool passing_allowed(int index, int index2, bool left); 00131 00132 bool lanes_in_same_direction(int index1,int index2, bool& left_lane); 00133 }; 00134 00135 int parse_integer(std::string line, std::string token, 00136 bool& valid); 00137 00138 WayPointNode parse_node(std::string line, bool& valid); 00139 WayPointEdge parse_edge(std::string line, bool& valid); 00140 00141 #endif