-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
68 lines (55 loc) · 2.22 KB
/
main.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
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QImage>
#include <QtCore>
#include <iostream>
#include "pathtracer.h"
#include "scene/scene.h"
#include <QImage>
#include "util/CS123Common.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("config", "Path of the config file.");
parser.process(a);
auto positionalArgs = parser.positionalArguments();
if (positionalArgs.size() != 1) {
std::cerr << "Not enough arguments. Please provide a path to a config file (.ini) as a command-line argument." << std::endl;
a.exit(1);
return 1;
}
QSettings settings( positionalArgs[0], QSettings::IniFormat );
QString inputScenePath = settings.value("IO/scene").toString();
QString outputImagePath = settings.value("IO/output").toString();
int imageWidth = settings.value("Settings/imageWidth").toInt();
int imageHeight = settings.value("Settings/imageHeight").toInt();
QImage image(imageWidth, imageHeight, QImage::Format_RGB32);
Scene *scene;
if(!Scene::load(inputScenePath, &scene, imageWidth, imageHeight)) {
std::cerr << "Error parsing scene file " << inputScenePath.toStdString() << std::endl;
a.exit(1);
return 1;
}
PathTracer tracer(imageWidth, imageHeight);
tracer.settings = {
.samplesPerPixel = settings.value("Settings/samplesPerPixel").toInt(),
.directLightingOnly = settings.value("Settings/directLightingOnly").toBool(),
.numDirectLightingSamples = settings.value("Settings/numDirectLightingSamples").toInt(),
.pathContinuationProb = settings.value("Settings/pathContinuationProb").toFloat(),
};
QRgb *data = reinterpret_cast<QRgb *>(image.bits());
tracer.traceScene(data, *scene);
delete scene;
bool success = image.save(outputImagePath);
if(!success) {
success = image.save(outputImagePath, "PNG");
}
if(success) {
std::cout << "Wrote rendered image to " << outputImagePath.toStdString() << std::endl;
} else {
std::cerr << "Error: failed to write image to " << outputImagePath.toStdString() << std::endl;
}
a.exit();
}