-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadInputFile.cpp
More file actions
188 lines (164 loc) · 4.05 KB
/
ReadInputFile.cpp
File metadata and controls
188 lines (164 loc) · 4.05 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "ReadInputFile.h"
void ReadInputFile::readInputandFillSceneElements(string &inputFilename) {
ifstream inputFile(inputFilename);
string line;
int counter = 0;
if (inputFile.is_open()) {
while (getline(inputFile, line)) {
if (counter == 0) {
outputFilename.assign(line);
counter++;
}
else if (counter == 1) {
stringstream ss(line);
ss >> width;
ss >> height;
counter++;
}
else if (counter == 2) {
vec3 eye, at, up;
stringstream ss(line);
ss >> eye.x >> eye.y >> eye.z;
getline(inputFile, line);
ss = stringstream(line);
ss >> at.x >> at.y >> at.z;
getline(inputFile, line);
ss = stringstream(line);
ss >> up.x >> up.y >> up.z;
getline(inputFile, line);
ss = stringstream(line);
float fovY;
ss >> fovY;
camera.eye = eye;
camera.at = at;
camera.up = up;
camera.fovY = fovY;
counter++;
}
else if (counter == 3) {
stringstream ss(line);
ss >> totalNumofLightSources;
counter++;
}
else if (counter == 4) {
for (int i = 0; i < totalNumofLightSources; i++) {
stringstream ss(line);
LightSource lightSource;
float posX, posY, posZ, Ir, Ig, Ib, a, b, c;
ss >> posX >> posY >> posZ >> Ir >> Ig >> Ib >> a >> b >> c;
lightSource.pos = { posX,posY,posZ };
lightSource.Ir = Ir;
lightSource.Ig = Ig;
lightSource.Ib = Ib;
lightSource.a = a;
lightSource.b = b;
lightSource.c = c;
lightSources.push_back(lightSource);
if (i == totalNumofLightSources - 1)
break;
getline(inputFile, line);
}
counter++;
}
else if (counter == 5) {
stringstream ss(line);
ss >> totalNumofPigments;
counter++;
}
else if (counter == 6) {
for (int i = 0; i < totalNumofPigments; i++) {
stringstream ss(line);
Pigment pigment;
string type;
float r, g, b;
ss >> type;
ss >> r >> g >> b;
pigment.type = type;
pigment.r = r;
pigment.g = g;
pigment.b = b;
pigments.push_back(pigment);
if (i == totalNumofPigments - 1)
break;
getline(inputFile, line);
}
counter++;
}
else if (counter == 7) {
stringstream ss(line);
ss >> totalNumofSurfaces;
counter++;
}
else if (counter == 8) {
for (int i = 0; i < totalNumofSurfaces; i++) {
stringstream ss(line);
Surface surface;
float ka, kd, ks, shineness, kr, kt, n2;
ss >> ka >> kd >> ks >> shineness >> kr >> kt >> n2;
surface.ka = ka;
surface.kd = kd;
surface.ks = ks;
surface.kr = kr;
surface.kt = kt;
surface.n2 = n2;
surface.shininess = shineness;
surfaces.push_back(surface);
if (i == totalNumofSurfaces - 1)
break;
getline(inputFile, line);
}
counter++;
}
else if (counter == 9) {
stringstream ss(line);
ss >> totalNumofObj3Ds;
counter++;
}
else if (counter == 10) {
for (int i = 0; i < totalNumofObj3Ds; i++) {
stringstream ss(line);
Object3D object3D;
string type;
int numPigment, numSurface;
float posX, posY, posZ, radius;
ss >> numPigment >> numSurface >> type >> posX >> posY >> posZ >> radius;
object3D.center = { posX, posY, posZ };
object3D.numPigment = numPigment;
object3D.numSurface = numSurface;
object3D.radius = radius;
object3D.type = type;
object3Ds.push_back(object3D);
if (i == totalNumofObj3Ds - 1)
break;
getline(inputFile, line);
}
counter++;
}
}
inputFile.close();
}
}
const string ReadInputFile::getOutputFileName() {
return outputFilename;
}
const int ReadInputFile::getWidth() {
return width;
}
const int ReadInputFile::getHeight() {
return height;
}
const Camera &ReadInputFile::getCamera() {
return camera;
}
const vector<LightSource> &ReadInputFile::getLightSources() {
return lightSources;
}
const vector<Surface> &ReadInputFile::getSurfaces() {
return surfaces;
}
const vector<Pigment> &ReadInputFile::getPigments() {
return pigments;
}
const vector<Object3D> &ReadInputFile::getObject3Ds() {
return object3Ds;
}