-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths2.cpp
More file actions
73 lines (63 loc) · 2.08 KB
/
Copy paths2.cpp
File metadata and controls
73 lines (63 loc) · 2.08 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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include "pgm/Image.h"
#include "Validation.h"
#include "Sphere.h"
using namespace std;
int SPHERE_ARGS[] = {2,3,4};
int main(int argc, const char * argv[]) {
if (argc != 6) {
cerr << "ERROR: Invalid number of arguments." << endl;
exit(-1);
}
const char* input_params_fname = argv[1];
const char* output_fname = argv[5];
vector<const char*> sphere_fnames;
for (int i=0; i < argc - 3; i++){
sphere_fnames.push_back(argv[SPHERE_ARGS[i]]);
}
// Create new sphere images from files, add to vector
vector<Image*> sphere_images;
for(int i=0; i < sphere_fnames.size(); i++){
Image* img = new Image;
if (readImage(img, sphere_fnames[i]) < 0) {
cerr << "ERROR: Something went wrong reading the input image" << endl;
exit(-1);
}
sphere_images.push_back(img);
}
// Create first sphere from params file and add to vector
Sphere* sphere_from_file = new Sphere(sphere_images[0], input_params_fname);
vector<Sphere*> spheres;
spheres.push_back(sphere_from_file);
// Create remaining spheres, add to vector
for(int i=1; i < sphere_images.size(); i++){
Sphere* s = new Sphere(sphere_images[i], sphere_from_file->getCenter(), sphere_from_file->getRadius());
spheres.push_back(s);
}
// Open output file
ofstream writef;
writef.open(output_fname);
if (writef.fail()) {
cerr << "ERROR: Something went wrong reading the output file" << endl;
exit(-1);
}
// Write brightness vector of each sphere to file
if (writef.is_open()) {
for(int i=0; i < spheres.size(); i++){
Matrix ls = spheres[i]->findLightSource();
writef << ls.getValue(0,0) << " ";
writef << ls.getValue(0,1) << " ";
writef << ls.getValue(0,2) << endl;
}
}
writef.close();
// Clean up and return
for (int i=0; i < spheres.size(); i++){
delete spheres[i];
delete sphere_images[i];
}
return 0;
}