-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.cpp
More file actions
99 lines (79 loc) · 3.11 KB
/
Copy pathvisualize.cpp
File metadata and controls
99 lines (79 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "visualize.h"
#include "cs225/PNG.h"
#include "cs225/HSLAPixel.h"
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <math.h>
#include "circle.h"
#include "line.h"
#include "vector2.h"
#include "color.h"
#include <fstream>
using namespace cs225;
using namespace std;
//input: sorted vector of airport ids output: gif file
//find coordinates of airport -> create a dictionary that takes airport id as key and coordinate as a value.
//function that convert longitude and latitude into coordinate in map
//input: latitude and longitude variable, ouput: coordinates
//function that changes the color of pixel of the coordinates -> to create a point for the airport position
//input: coordinate class variable, reference to the png variable output: void
//function that draws a line between two coordinates
//input: coordinate class variable start, coordinate class variable end, reference to the png variable output:void
Vector2 Visualize::maptocoord(double longitude, double latitude){
int height = 318;
int width = 637;
double latRad = latitude * M_PI/180;
double mercN = log(tan((M_PI/4)+(latRad/2)));
// std::cout<<"Longi"<<longitude<<"Lati"<<latitude<<std::endl;
int x = fmod((width*(180+longitude)/360), (width + (width/2)));//(int) (longitude/180*((int)width/2)+width/2); //
int y = (height/2) - (width*mercN/(2*M_PI));//(int) (latitude/90*((int)height/2)+height/2); //
// std::cout<<"x"<<x<<"y"<<y<<std::endl;
return Vector2(x, y);
}
//create a circle with radius 5 and draw on png
void Visualize::drawPixel(int x, int y, PNG & png){
Circle circle(Vector2(x, y), color::BLUE, 2);
circle.draw(&png);
}
void Visualize::drawLine(int x1, int y1, int x2, int y2, PNG & png){
Line line(Vector2(x1, y1), Vector2(x2, y2), color::DARKGRAY);
line.draw(&png);
}
PNG Visualize::visualize(std::vector<std::string> input) {
PNG* map = new PNG();
map->readFromFile("map.png");
unsigned width = map->width();
unsigned height = map->height();
PNG* output = new PNG(*map);
std::unordered_map<std::string, Vector2> airportLocations;
// airportLocations[''] = Coordinate(30, 10); template for the map
// airportLocations['']
std::ifstream fin("Data/airport.csv");
int count = 0;
std::vector<std::string> row;
std::string line, word, temp;
fin>>temp;
while (fin >> line) {
row.resize(0);
std::stringstream s(line);
for (unsigned i = 0; i < 6; i++) {
std::getline(s, word, ',');
row.push_back(word);
}
Vector2 cur = maptocoord(stod(row[5]),stod(row[4]));
airportLocations[row[3]] = cur;
}
for(int i = 0; i < (int)input.size()-1; i++){
Vector2 & cur = airportLocations[input[i]];
Vector2 & next = airportLocations[input[i+1]];
drawPixel(cur.x(), cur.y(), *output);
drawPixel(next.x(), next.y(), *output);
drawLine(cur.x(), cur.y(), next.x(), next.y(), *output);
}
return *output;
// output -> writeToFile("answer.png");
// delete output;
// delete map;
}