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();
148 double xrange[2], yrange[2];
149 this->getCartesianCoordsRange(xrange, yrange);
151 cout <<
"Range(Cartesian):" << xrange[0] <<
"," << xrange[1] <<
152 yrange[0] <<
"," << yrange[1] << endl;
158 double tx = xrange[0];
159 double ty = yrange[0];
162 double sx = 1000. / (xrange[1] - xrange[0]);
163 double sy = 1000. / (yrange[1] - yrange[0]);
166 cout <<
"Translate:" << tx <<
"," << ty << endl;
167 cout <<
"Scale:" << sx <<
"," << sy << endl;
170 std::unordered_map<OSMVertex::OSMVertexID, int> vert_map;
174 for (
int k = 0; k < vertices.size(); k++) {
177 if (vert_map.find(vertices[k].getVertexID()) == vert_map.end()) {
179 vert_map[vertices[k].getVertexID()] = k;
182 vertices[k].getCartesianCoords(coords);
185 double x = coords[0];
186 double y = coords[1];
187 gr->
getVertex(k)->getVisualizer()->setLocation( x, y);
191 for (
int k = 0; k < edges.size(); k++) {
194 gr->
addEdge(vert_map[edges[k].getSourceVertex()], vert_map[edges[k].getDestinationVertex()],
195 edges[k].getEdgeLength() );
199 cout <<
"Num vertices, Edges: " << vertices.size() <<
"," << edges.size() << endl;
233 lat_range[0] = latitude_range[0];
234 lat_range[1] = latitude_range[1];
235 longit_range[0] = longitude_range[0];
236 longit_range[1] = longitude_range[1];
245 xrange[0] = cartesian_range_x[0];
246 xrange[1] = cartesian_range_x[1];
247 yrange[0] = cartesian_range_y[0];
248 yrange[1] = cartesian_range_y[1];
270 latitude_range[0] = 1000000.;
271 latitude_range[1] = -1000000.;
272 longitude_range[0] = 1000000.;
273 longitude_range[1] = -1000000.;
274 double lat, longit, cart_coords[2];
275 for (
auto& v : vertices) {
276 lat = v.getLatitude();
277 longit = v.getLongitude();
278 latitude_range[0] = (std::min)(latitude_range[0], lat);
280 latitude_range[1] = (std::max)(latitude_range[0], lat);
281 longitude_range[0] = (std::min)(longitude_range[1], longit);
282 longitude_range[1] = (std::max)(longitude_range[1], longit);
284 recomputeCartesianRange();
313 const double R = 6378.;
314 double lat_rad = degreeToRadians(lat);
315 double longit_rad = degreeToRadians(longit);
316 coords[0] = R * cos(lat_rad) * cos (longit_rad);
317 coords[1] = R * cos(lat_rad) * sin (longit_rad);
const vector< OSMEdge > & getEdges() const
get edges.
Definition: OSMData.h:294
static void toCartesianCoords(double lat, double longit, double *coords)
Definition: OSMData.h:312
const vector< OSMVertex > & getVertices() const
Definition: OSMData.h:257
#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:244
void setName(const string &n)
change the name of the dataset
Definition: OSMData.h:222
const Element< E1 > * getVertex(const K &key) const
Definition: GraphAdjList.h:305
OSMData()
Definition: OSMData.h:205
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())
Definition: GraphAdjList.h:96
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:267
const string & getName() const
get the name of the dataset
Definition: OSMData.h:213
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:141
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 vertices.
Definition: OSMData.h:34
void getLatLongRange(double *lat_range, double *longit_range) const
Definition: OSMData.h:232
void getCartesianCoords(double *coords) const
Definition: OSMVertex.h:105
void setEdges(const vector< OSMEdge > &e)
set edges
Definition: OSMData.h:305
void addEdge(const K &src, const K &dest, const E2 &data=E2())
add an edge with data.
Definition: GraphAdjList.h:119
Class that hold Open Street Map vertices.
Definition: OSMVertex.h:28