-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (87 loc) · 2.72 KB
/
Copy pathmain.cpp
File metadata and controls
103 lines (87 loc) · 2.72 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
#include "raytracer.h"
#include "utils.h"
#include <chrono>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
struct Arguments {
std::string sceneFile;
int width;
int height;
int sphereCount;
};
bool parseArguments(int argc, char **argv, Arguments &args) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " [-d width height] <sceneFile>"
<< std::endl;
return false;
}
args.width = 800; // Default width
args.height = 600; // Default height
args.sphereCount = 0; // Default sphere count
int index = 1;
// Check for the "-d" flag
if (strcmp(argv[1], "-d") == 0) {
if (argc < 5) {
std::cerr << "Usage: " << argv[0] << " [-d width height] <sceneFile>"
<< std::endl;
return false;
}
args.width = std::stoi(argv[2]);
args.height = std::stoi(argv[3]);
index = 4;
}
// The last argument should be the scene file
if (index >= argc) {
std::cerr << "Error: Scene file not provided." << std::endl;
return false;
}
args.sceneFile = argv[index];
// Read the sphere count from the scene file
std::ifstream sceneFile(args.sceneFile);
if (!sceneFile.is_open()) {
std::cerr << "Error: Could not open scene file " << args.sceneFile
<< std::endl;
return false;
}
sceneFile >> args.sphereCount;
if (sceneFile.fail()) {
std::cerr << "Error: Could not read sphere count from scene file "
<< args.sceneFile << std::endl;
return false;
}
return true;
}
std::string generateOutputFilename(const std::string &sceneFile,
const std::string &prefix) {
size_t startPos = sceneFile.find_last_of('/');
if (startPos == std::string::npos) {
startPos = 0;
} else {
startPos++;
}
size_t endPos = sceneFile.find_last_of('.');
std::string baseName = sceneFile.substr(startPos, endPos - startPos);
return prefix + baseName + ".ppm";
}
void render(int width, int height, const std::string &sceneFile,
const std::string &outputFile);
int main(int argc, char **argv) {
Arguments args;
if (!parseArguments(argc, argv, args)) {
return 1;
}
for (int i = 0; i < 10; i++) {
std::string outputFile =
generateOutputFilename(args.sceneFile, "output_sequential_");
auto start = std::chrono::high_resolution_clock::now();
render(args.width, args.height, args.sceneFile, outputFile);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "CPU Rendering Time: " << diff.count() << " s\n";
writeTrialToCsv(diff.count(), args.width, args.height, args.sceneFile,
"sequential", args.sphereCount);
}
return 0;
}