13 #define M_PI 3.1415926535897 43 double latitude_range[2] = {0.0, 0.0},
44 longitude_range[2] = {0.0, 0.0};
45 double cartesian_range_x[2] = {0.0, 0.0},
46 cartesian_range_y[2] = {0.0, 0.0};
48 vector<OSMVertex> vertices;
50 vector<OSMEdge> edges;
52 static double degreeToRadians(
double deg) {
53 return deg *
M_PI / 180.;
57 void recomputeCartesianRange() {
58 cartesian_range_x[0] = 1000000.;
59 cartesian_range_x[1] = -1000000.;
60 cartesian_range_y[0] = 1000000.;
61 cartesian_range_y[1] = -1000000.;
63 OSMVertex v1 (0, latitude_range[0], longitude_range[0]);
64 OSMVertex v2 (1, latitude_range[1], longitude_range[1]);
65 OSMVertex v3 (2, latitude_range[0], longitude_range[1]);
66 OSMVertex v4 (3, latitude_range[1], longitude_range[0]);
72 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
73 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
74 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
75 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
79 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
80 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
81 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
82 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
86 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
87 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
88 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
89 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
93 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
94 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
95 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
96 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
109 latitude_range[0] = lat_range[0];
110 latitude_range[1] = lat_range[1];
111 longitude_range[0] = longit_range[0];
112 longitude_range[1] = longit_range[1];
113 recomputeCartesianRange();
122 double long_min,
double long_max) {
123 latitude_range[0] = lat_min;
124 latitude_range[1] = lat_max;
125 longitude_range[0] = long_min;
126 longitude_range[1] = long_max;
127 recomputeCartesianRange();
150 double xrange[2], yrange[2];
151 this->getCartesianCoordsRange(xrange, yrange);
153 cout <<
"Range(Cartesian):" << xrange[0] <<
"," << xrange[1] <<
154 yrange[0] <<
"," << yrange[1] << endl;
160 double tx = xrange[0];
161 double ty = yrange[0];
164 double sx = 1000. / (xrange[1] - xrange[0]);
165 double sy = 1000. / (yrange[1] - yrange[0]);
168 cout <<
"Translate:" << tx <<
"," << ty << endl;
169 cout <<
"Scale:" << sx <<
"," << sy << endl;
172 std::unordered_map<OSMVertex::OSMVertexID, int> vert_map;
176 for (
int k = 0; k < vertices.size(); k++) {
179 if (vert_map.find(vertices[k].getVertexID()) == vert_map.end()) {
181 vert_map[vertices[k].getVertexID()] = k;
184 vertices[k].getCartesianCoords(coords);
187 double x = coords[0];
188 double y = coords[1];
189 gr->
getVertex(k)->getVisualizer()->setLocation( x, y);
193 for (
int k = 0; k < edges.size(); k++) {
196 gr->
addEdge(vert_map[edges[k].getSourceVertex()], vert_map[edges[k].getDestinationVertex()],
197 edges[k].getEdgeLength() );
201 cout <<
"Num vertices, Edges: " << vertices.size() <<
"," << edges.size() << endl;
235 lat_range[0] = latitude_range[0];
236 lat_range[1] = latitude_range[1];
237 longit_range[0] = longitude_range[0];
238 longit_range[1] = longitude_range[1];
247 xrange[0] = cartesian_range_x[0];
248 xrange[1] = cartesian_range_x[1];
249 yrange[0] = cartesian_range_y[0];
250 yrange[1] = cartesian_range_y[1];
272 latitude_range[0] = 1000000.;
273 latitude_range[1] = -1000000.;
274 longitude_range[0] = 1000000.;
275 longitude_range[1] = -1000000.;
276 double lat, longit, cart_coords[2];
277 for (
auto& v : vertices) {
278 lat = v.getLatitude();
279 longit = v.getLongitude();
280 latitude_range[0] = (std::min)(latitude_range[0], lat);
282 latitude_range[1] = (std::max)(latitude_range[0], lat);
283 longitude_range[0] = (std::min)(longitude_range[1], longit);
284 longitude_range[1] = (std::max)(longitude_range[1], longit);
286 recomputeCartesianRange();
318 const double R = 6378.;
319 double lat_rad = degreeToRadians(lat);
320 double longit_rad = degreeToRadians(longit);
321 coords[0] = R * cos(lat_rad) * cos (longit_rad);
322 coords[1] = R * cos(lat_rad) * sin (longit_rad);
const vector< OSMEdge > & getEdges() const
get edges.
Definition: OSMData.h:296
static void toCartesianCoords(double lat, double longit, double *coords)
Definition: OSMData.h:317
const vector< OSMVertex > & getVertices() const
Definition: OSMData.h:259
#define M_PI
Definition: OSMData.h:13
This class provides methods to represent adjacency list based graphs.
Definition: Element.h:19
void getCartesianCoordsRange(double *xrange, double *yrange) const
get the range of dataset in Cartesian coords
Definition: OSMData.h:246
void setName(const string &n)
change the name of the dataset
Definition: OSMData.h:224
const Element< E1 > * getVertex(const K &key) const
Return the vertex corresponding to a key.
Definition: GraphAdjList.h:383
OSMData()
Definition: OSMData.h:207
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:51
void addVertex(const K &k, const E1 &e=E1())
Adds a vertex to the graph.
Definition: GraphAdjList.h:174
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
void setVertices(const vector< OSMVertex > &verts)
replace the vertices stored by this new set.
Definition: OSMData.h:269
const string & getName() const
get the name of the dataset
Definition: OSMData.h:215
void setLatLongRange(double *lat_range, double *longit_range)
set the latitude and longitude range of the dataset
Definition: OSMData.h:108
void getGraph(GraphAdjList< int, OSMVertex, double > *gr) const
Definition: OSMData.h:143
void setLatLongRange(double lat_min, double lat_max, double long_min, double long_max)
set the range of the dataset
Definition: OSMData.h:121
Class that hold Open Street Map Data.
Definition: OSMData.h:34
void getLatLongRange(double *lat_range, double *longit_range) const
Definition: OSMData.h:234
void getCartesianCoords(double *coords) const
Definition: OSMVertex.h:119
void setEdges(const vector< OSMEdge > &e)
set edges
Definition: OSMData.h:307
void addEdge(const K &src, const K &dest, const E2 &data=E2())
Add an edge with data.
Definition: GraphAdjList.h:197
Class that hold Open Street Map vertices.
Definition: OSMVertex.h:28