/
main.cpp
91 lines (76 loc) · 1.81 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <fstream>
#include <iostream>
#include <mutex>
#include <random>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include "image.h"
#include "scene.h"
#include "pathtracer.h"
#include "random.h"
#include "pm.h"
#include "meshsimp1.h"
using namespace std;
void PT (const json &scene);
void PPM (const json &scene);
void MeshSimplify (int argc, char **argv);
int main (int argc, char **argv)
{
if (argc < 2)
{
cerr << "Usage: ./raytr <scene.json> | ./raytr m <mesh.json> <simp_ratio>" << endl ;
exit(1);
}
if (string(argv[1]) == "m")
{
MeshSimplify(argc - 1, argv + 1);
return 0;
}
auto scene_file = json::parse(ifstream(argv[1]));
if (scene_file.count("pm_params"))
PPM(scene_file);
else if (scene_file.count("pt_params"))
PT(scene_file);
return 0;
}
void PPM (const json &j)
{
PMParams params;
params.LoadFrom(j.at("pm_params"));
omp_set_num_threads(params.n_threads);
Scene scene = Scene::Load(j);
Image image(scene.Width() * 2, scene.Height(), "tmp/ph_last", params.display);
PM pm(scene, image, params);
if (j.at("pm_params").at("algo").get<string>() == "ppm")
pm.PPM();
else
pm.PPPM();
image.Show();
image.Dump(-1);
image.Show();
}
void PT (const json &j)
{
PTParams params;
params.LoadFrom(j.at("pt_params"));
omp_set_num_threads(params.n_threads);
Scene scene = Scene::Load(j);
Image image(scene.Width() * 2, scene.Height(), "tmp/im_last", params.display);
PathTracer pathTracer(scene, image, params);
Ray ray;
rand_data rd;
rand_init(&rd);
scene.GetCamera()->Project(&rd, 818, 1800 - 1043, ray);
pathTracer.Trace(&rd, ray);
pathTracer.PT();
image.Show();
image.Dump(-1);
image.Show();
}
void MeshSimplify (int argc, char **argv)
{
MeshSimplifier1 reducer(argv[1]);
double target_ratio = argc > 2 ? std::stof(argv[2]) : 0.9;
reducer.Run(target_ratio);
}