12 #define M_PI 3.1415926535897
47 double latitude_range[2] = {0.0, 0.0},
48 longitude_range[2] = {0.0, 0.0};
49 double cartesian_range_x[2] = {0.0, 0.0},
50 cartesian_range_y[2] = {0.0, 0.0};
52 vector<OSMVertex> vertices;
54 vector<OSMEdge> edges;
56 static double degreeToRadians(
double deg) {
57 return deg *
M_PI / 180.;
60 void recomputeCartesianRange() {
61 cartesian_range_x[0] = 1000000.;
62 cartesian_range_x[1] = -1000000.;
63 cartesian_range_y[0] = 1000000.;
64 cartesian_range_y[1] = -1000000.;
66 OSMVertex v1 (0, latitude_range[0], longitude_range[0]);
67 OSMVertex v2 (1, latitude_range[1], longitude_range[1]);
68 OSMVertex v3 (2, latitude_range[0], longitude_range[1]);
69 OSMVertex v4 (3, latitude_range[1], longitude_range[0]);
75 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
76 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
77 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
78 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
82 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
83 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
84 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
85 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
89 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
90 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
91 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
92 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
96 cartesian_range_x[0] = (std::min)(cartesian_range_x[0], coords[0]);
97 cartesian_range_x[1] = (std::max)(cartesian_range_x[1], coords[0]);
98 cartesian_range_y[0] = (std::min)(cartesian_range_y[0], coords[1]);
99 cartesian_range_y[1] = (std::max)(cartesian_range_y[1], coords[1]);
112 latitude_range[0] = lat_range[0];
113 latitude_range[1] = lat_range[1];
114 longitude_range[0] = longit_range[0];
115 longitude_range[1] = longit_range[1];
116 recomputeCartesianRange();
125 double long_min,
double long_max) {
126 latitude_range[0] = lat_min;
127 latitude_range[1] = lat_max;
128 longitude_range[0] = long_min;
129 longitude_range[1] = long_max;
130 recomputeCartesianRange();
153 double xrange[2], yrange[2];
154 this->getCartesianCoordsRange(xrange, yrange);
156 cout <<
"Range(Cartesian):" << xrange[0] <<
"," << xrange[1] <<
157 yrange[0] <<
"," << yrange[1] << endl;
162 double tx = xrange[0];
163 double ty = yrange[0];
166 double sx = 1000. / (xrange[1] - xrange[0]);
167 double sy = 1000. / (yrange[1] - yrange[0]);
170 cout <<
"Translate:" << tx <<
"," << ty << endl;
171 cout <<
"Scale:" << sx <<
"," << sy << endl;
174 std::unordered_map<OSMVertex::OSMVertexID, int> vert_map;
177 for (
int k = 0; k < vertices.size(); k++) {
180 if (vert_map.find(vertices[k].getVertexID()) == vert_map.end()) {
182 vert_map[vertices[k].getVertexID()] = k;
185 vertices[k].getCartesianCoords(coords);
188 double x = coords[0];
189 double y = coords[1];
194 for (
int k = 0; k < edges.size(); k++) {
197 gr->
addEdge(vert_map[edges[k].getSourceVertex()], vert_map[edges[k].getDestinationVertex()],
198 edges[k].getEdgeLength() );
202 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);
#define M_PI
Definition: OSMData.h:12
Class that hold Open Street Map Data.
Definition: OSMData.h:38
const vector< OSMVertex > & getVertices() const
Definition: OSMData.h:259
void setEdges(const vector< OSMEdge > &e)
set edges
Definition: OSMData.h:307
const string & getName() const
get the name of the dataset
Definition: OSMData.h:215
void getGraph(GraphAdjList< int, OSMVertex, double > *gr) const
Definition: OSMData.h:146
static void toCartesianCoords(double lat, double longit, double *coords)
Definition: OSMData.h:317
OSMData()
Definition: OSMData.h:207
void setVertices(const vector< OSMVertex > &verts)
replace the vertices stored by this new set.
Definition: OSMData.h:269
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
void setLatLongRange(double lat_min, double lat_max, double long_min, double long_max)
set the range of the dataset
Definition: OSMData.h:124
void setLatLongRange(double *lat_range, double *longit_range)
set the latitude and longitude range of the dataset
Definition: OSMData.h:111
void getLatLongRange(double *lat_range, double *longit_range) const
Definition: OSMData.h:234
const vector< OSMEdge > & getEdges() const
get edges.
Definition: OSMData.h:296
Class that hold Open Street Map vertices.
Definition: OSMVertex.h:33
void getCartesianCoords(double *coords) const
Definition: OSMVertex.h:123
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:50
ElementVisualizer * getVisualizer()
Get the element visualizer object.
Definition: Element.h:141
void setColor(const Color &col)
Set the color to "col".
Definition: ElementVisualizer.h:94
void setLocation(const double &locX, const double &locY)
Definition: ElementVisualizer.h:157
This class provides methods to represent adjacency list based graphs.
Definition: GraphAdjList.h:110
void addVertex(const K &k, const E1 &e=E1())
Adds a vertex to the graph.
Definition: GraphAdjList.h:175
void addEdge(const K &src, const K &dest, const E2 &data=E2())
Definition: GraphAdjList.h:198
const Element< E1 > * getVertex(const K &key) const
Return the vertex corresponding to a key.
Definition: GraphAdjList.h:405
Support for drawing Bar charts.
Definition: alltypes.h:4