13 #define M_PI 3.1415926535897 49 double latitude_range[2] = {0.0, 0.0},
50 longitude_range[2] = {0.0, 0.0};
51 double cartesian_range_x[2] = {0.0, 0.0},
52 cartesian_range_y[2] = {0.0, 0.0};
54 vector<OSMVertex> vertices;
56 vector<OSMEdge> edges;
58 static double degreeToRadians(
double deg) {
59 return deg *
M_PI / 180.;
63 void recomputeCartesianRange() {
64 cartesian_range_x[0] = 1000000.;
65 cartesian_range_x[1] = -1000000.;
66 cartesian_range_y[0] = 1000000.;
67 cartesian_range_y[1] = -1000000.;
69 OSMVertex v1 (0, latitude_range[0], longitude_range[0]);
70 OSMVertex v2 (1, latitude_range[1], longitude_range[1]);
71 OSMVertex v3 (2, latitude_range[0], longitude_range[1]);
72 OSMVertex v4 (3, latitude_range[1], longitude_range[0]);
78 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
79 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
80 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
81 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
85 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
86 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
87 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
88 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
92 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
93 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
94 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
95 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
99 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
100 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
101 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
102 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
115 latitude_range[0] = lat_range[0];
116 latitude_range[1] = lat_range[1];
117 longitude_range[0] = longit_range[0];
118 longitude_range[1] = longit_range[1];
119 recomputeCartesianRange();
128 double long_min,
double long_max) {
129 latitude_range[0] = lat_min;
130 latitude_range[1] = lat_max;
131 longitude_range[0] = long_min;
132 longitude_range[1] = long_max;
133 recomputeCartesianRange();
156 double xrange[2], yrange[2];
157 this->getCartesianCoordsRange(xrange, yrange);
159 cout <<
"Range(Cartesian):" << xrange[0] <<
"," << xrange[1] <<
160 yrange[0] <<
"," << yrange[1] << endl;
166 double tx = xrange[0];
167 double ty = yrange[0];
170 double sx = 1000. / (xrange[1] - xrange[0]);
171 double sy = 1000. / (yrange[1] - yrange[0]);
174 cout <<
"Translate:" << tx <<
"," << ty << endl;
175 cout <<
"Scale:" << sx <<
"," << sy << endl;
178 std::unordered_map<OSMVertex::OSMVertexID, int> vert_map;
182 for (
int k = 0; k < vertices.size(); k++) {
185 if (vert_map.find(vertices[k].getVertexID()) == vert_map.end()) {
187 vert_map[vertices[k].getVertexID()] = k;
190 vertices[k].getCartesianCoords(coords);
193 double x = coords[0];
194 double y = coords[1];
195 gr->
getVertex(k)->getVisualizer()->setLocation( x, y);
199 for (
int k = 0; k < edges.size(); k++) {
202 gr->
addEdge(vert_map[edges[k].getSourceVertex()], vert_map[edges[k].getDestinationVertex()],
203 edges[k].getEdgeLength() );
207 cout <<
"Num vertices, Edges: " << vertices.size() <<
"," << edges.size() << endl;
241 lat_range[0] = latitude_range[0];
242 lat_range[1] = latitude_range[1];
243 longit_range[0] = longitude_range[0];
244 longit_range[1] = longitude_range[1];
253 xrange[0] = cartesian_range_x[0];
254 xrange[1] = cartesian_range_x[1];
255 yrange[0] = cartesian_range_y[0];
256 yrange[1] = cartesian_range_y[1];
278 latitude_range[0] = 1000000.;
279 latitude_range[1] = -1000000.;
280 longitude_range[0] = 1000000.;
281 longitude_range[1] = -1000000.;
282 double lat, longit, cart_coords[2];
283 for (
auto& v : vertices) {
284 lat = v.getLatitude();
285 longit = v.getLongitude();
286 latitude_range[0] = (std::min)(latitude_range[0], lat);
288 latitude_range[1] = (std::max)(latitude_range[0], lat);
289 longitude_range[0] = (std::min)(longitude_range[1], longit);
290 longitude_range[1] = (std::max)(longitude_range[1], longit);
292 recomputeCartesianRange();
324 const double R = 6378.;
325 double lat_rad = degreeToRadians(lat);
326 double longit_rad = degreeToRadians(longit);
327 coords[0] = R * cos(lat_rad) * cos (longit_rad);
328 coords[1] = R * cos(lat_rad) * sin (longit_rad);
const vector< OSMEdge > & getEdges() const
get edges.
Definition: OSMData.h:302
static void toCartesianCoords(double lat, double longit, double *coords)
Definition: OSMData.h:323
const vector< OSMVertex > & getVertices() const
Definition: OSMData.h:265
#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:252
void setName(const string &n)
change the name of the dataset
Definition: OSMData.h:230
const Element< E1 > * getVertex(const K &key) const
Return the vertex corresponding to a key.
Definition: GraphAdjList.h:408
OSMData()
Definition: OSMData.h:213
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:177
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:275
const string & getName() const
get the name of the dataset
Definition: OSMData.h:221
void setLatLongRange(double *lat_range, double *longit_range)
set the latitude and longitude range of the dataset
Definition: OSMData.h:114
void getGraph(GraphAdjList< int, OSMVertex, double > *gr) const
Definition: OSMData.h:149
void setLatLongRange(double lat_min, double lat_max, double long_min, double long_max)
set the range of the dataset
Definition: OSMData.h:127
Class that hold Open Street Map Data.
Definition: OSMData.h:40
void getLatLongRange(double *lat_range, double *longit_range) const
Definition: OSMData.h:240
void getCartesianCoords(double *coords) const
Definition: OSMVertex.h:125
void setEdges(const vector< OSMEdge > &e)
set edges
Definition: OSMData.h:313
void addEdge(const K &src, const K &dest, const E2 &data=E2())
Definition: GraphAdjList.h:200
Class that hold Open Street Map vertices.
Definition: OSMVertex.h:34