-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileread.cpp
105 lines (95 loc) · 2.33 KB
/
fileread.cpp
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
100
101
102
103
104
105
#include "fileread.h"
using namespace std;
void printV(vector<double>& v){
if(v.size() == 0){
cout << "{}";
return;
}
cout << "{";
for(int i = 0; i < v.size() - 1; i++){
cout << v[i] << ", ";
}
cout << v[v.size() - 1] << "}";
}
void readLine(string line, vector<double>& target){
target.clear();
stringstream ss(line);
string data;
getline(ss, data, ',');
// skip label
getline(ss, data, ',');
while(ss.good()){
target.push_back(stod(data));
getline(ss, data, ',');
}
}
int polyCounter = 0;
color grey(127, 130, 128);
color base(125, 125, 0);
void addShape(vector<double>& shape,
vector<shared_ptr<ellipse> >& Es,
vector<shared_ptr<Rect> >& Rs,
vector<shared_ptr<Polygon> >& Ps){
vector<color> picker = {grey, color(250,250,250), color(0, 0, 0)};
vector<string> picker2 = {"colourMap[\"base\"]", "colourMap[\"white\"]", "colourMap[\"black\"]"};
if(shape[0] == 0){
//cout << "is ell\n";
cout << "Es.push_back(make_shared<ellipse>("
<< shape[1] << ", "
<< shape[2] << ", "
<< shape[3] << ", "
<< shape[4] << ", "
<< shape[5] << ".0, "
<< picker2[shape[5]] << "));" << endl;
Es.push_back(make_shared<ellipse>(
shape[1],
shape[2],
shape[3],
shape[4],
1.0 * shape[5],
picker[shape[5]]));
}
if(shape[0] == 1){
polyCounter++;
cout << "vector<vec2> verts" << polyCounter << " = {";
for(int i = 1; i < 3; i++){
cout << "vec2(" << shape[i * 2 - 1] << ", " << shape[i * 2] << "), ";
}
cout << "vec2(" << shape[5] << ", " << shape[6] << ")};" << endl;
cout << "Ps.push_back(make_shared<Polygon>(verts"
<< polyCounter << ", 8.0, " << picker2[shape[7]] << "));" << endl;
}
if(shape[0] == 2){
cout << "Rs.push_back(make_shared<Rect>("
<< shape[1] << ", "
<< shape[2] << ", "
<< shape[3] << ", "
<< shape[4] << ", "
<< picker2[shape[5]] << ", "
<< "2.0));" << endl;
Rs.push_back(make_shared<Rect>(
shape[1],
shape[2],
shape[3],
shape[4],
picker[shape[5]],
2.0));
}
}
void readFile(string filename,
vector<shared_ptr<ellipse> >& Es,
vector<shared_ptr<Rect> >& Rs,
vector<shared_ptr<Polygon> >& Ps){
ifstream is;
is.open(filename);
string line;
getline(is, line);
vector<double> data;
int counter = 1;
while(!is.eof()){
readLine(line, data);
addShape(data, Es, Rs, Ps);
getline(is, line);
}
is.close();
}