-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
217 lines (200 loc) · 8.69 KB
/
Copy pathmain.cpp
File metadata and controls
217 lines (200 loc) · 8.69 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include <iostream>
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/ext.hpp"
#include "includes.h"
#include "utilities/Ray.h"
#include "geometry/mesh.h"
#include <Python.h>
#include "python/pythonfunction.h"
#include "python/python3dloader.h"
#include "utilities/meshmanagers.h"
#include "utilities/sfmlimage.h"
#include "utilities/camera.h"
#include "python/pythonsceneloader.h"
#include "intersections/intersections.h"
#include "intersections/intersectionnaivemoller.h"
#include "intersections/intersectionnaivenaive.h"
#include "intersections/intersectiongrid.h"
#include "intersections/intersectionkdtreespacemedian.h"
#include "intersections/intersectionkdtreegeometrymedian.h"
#include "intersections/intersectionkdtreesah.h"
#include "intersections/intersectionkdtreesahnlogn.h"
#include <getopt.h>
using namespace std;
Real sigmoid(Real x) {
double invgamma = 0.45;
return std::pow(1.0 - std::exp(-0.66 * x), invgamma);
}
int raytrace(Camera &cameratemp, Image* image, Scene &scene, IntersectionMethod *inter_method, ULARGE_INTEGER time, int offset = -1){
int nb = 0;
for (uint y = 0; y < cameratemp.height; ++y) {
for (uint x = 0; x < cameratemp.width; ++x) {
if (offset >= 0 && getTimeElapsed(time) > offset) {
return -1;
}
Ray ray = cameratemp.shoot(x, y);
uint tri = 0;
Real t = inter_method->intersect(ray, &tri);
Color color(0.8, 1, 0.9);
if (t >= 0) {
nb += 1;
Real gradient = std::abs(dot(ray.direction, scene.triangles[tri].normal));
color = Color(gradient, gradient, gradient);
}
image->putPixelFloat(x, y, color.r, color.g, color.b);
}
}
return nb;
}
int main(int argc, char *argv[])
{
if (argc <= 1) {
std::cout<<"Il faut spécifier au moins une scéne à rendre\n";
return -1;
}
int opt;
int long_index = 1;
static struct option long_options[] = {
{"traversal", required_argument, 0, 't' },
{"Ki", required_argument, 0, 'i' },
{"Kt", required_argument, 0, 'p' },
{"build", required_argument, 0, 'b' },
{"complexity", required_argument, 0, 'c' },
{"heuristic", required_argument, 0, 'h' },
{"method", required_argument, 0, 'm' },
{"size", required_argument, 0, 's' },
{"output", required_argument, 0, 'o' },
{"time", required_argument, 0, 'l' },
{0, 0, 0, 0 }
};
std::map<std::string, std::string> params;
std::string file = std::string(argv[1]);
params["traversal"] = "rec";
params["Ki"] = "20";
params["Kt"] = "15";
params["build"] = "seq";
params["complexity"] = "nlogn";
params["heuristic"] = "sah";
params["method"] = "kdtree";
params["size"] = "10";
params["output"] = "out.png";
params["time"] = "120";
while ((opt = getopt_long(argc, argv,"t:i:p:b:c:h:m:s:o:l:", long_options, &long_index )) != -1)
{
switch (opt) {
case 't' : params["traversal"] = lower(std::string(optarg));
break;
case 'i' : params["Ki"] = lower(std::string(optarg));
break;
case 'p' : params["Kt"] = lower(std::string(optarg));
break;
case 'b' : params["build"] = lower(std::string(optarg));
break;
case 'c' : params["complexity"] = lower(std::string(optarg));
break;
case 'h' : params["heuristic"] = lower(std::string(optarg));
break;
case 'm' : params["method"] = lower(std::string(optarg));
break;
case 's' : params["size"] = lower(std::string(optarg));
break;
case 'o' : params["output"] = lower(std::string(optarg));
break;
case 'l' : params["time"] = lower(std::string(optarg));
break;
default: continue;
return -1;
}
}
PythonContext context;
Scene scene;
context.setCWD("python");
Camera cameratemp;
PythonSceneLoader loader_scenes(file);
//std::cout<<"loading========================\n";
loader_scenes.load(&cameratemp, &scene);
/*for (auto it = scene.meshes.begin(); it != scene.meshes.end(); ++it) {
std::cout<<"manager->Mesh: "<<it->first<<" -> "<<&(it->second)<<"\n";
std::cout<<" Faces: "<<it->second->triangles.size()
<<" Vertices: "<<it->second->vertices.size()<<"\n";
}
std::cout<<"end loading========================\n";
//*/
int time_limit = stringTo<int>(params["time"]);
IntersectionMethod *inter_method = 0;
if (params["method"] == "kdtree") {
if (params["heuristic"] == "sah") {
if (params["complexity"] == "nlogn") {
inter_method = new IntersectionKdTreeSAHnlogn(&scene,
stringTo<Real>(params["Ki"]),
stringTo<Real>(params["Kt"]),
params["traversal"] == "rec");
} else if (params["complexity"] == "nlog2n") {
inter_method = new IntersectionKdTreeSAH(&scene,
stringTo<Real>(params["Ki"]),
stringTo<Real>(params["Kt"]),
params["traversal"] == "rec",
NLOG2N);
} else if (params["complexity"] == "nlog2nc") {
inter_method = new IntersectionKdTreeSAH(&scene,
stringTo<Real>(params["Ki"]),
stringTo<Real>(params["Kt"]),
params["traversal"] == "rec",
NLOG2NC);
} else {
inter_method = new IntersectionKdTreeSAH(&scene,
stringTo<Real>(params["Ki"]),
stringTo<Real>(params["Kt"]),
params["traversal"] == "rec",
N2);
}
} else if (params["heuristic"] == "geometry") {
inter_method = new IntersectionKdTreeGeometryMedian(&scene,
params["traversal"] == "rec");
} else {
inter_method = new IntersectionKdTreeSpaceMedian(&scene,
params["traversal"] == "rec");
}
} else if (params["method"] == "naive") {
inter_method = new IntersectionNaiveNaive(&scene);
} else if (params["method"] == "grid") {
inter_method = new IntersectionGrid(&scene,
stringTo<Real>(params["size"]),
params["build"] == "dfs");
} else {
inter_method = new IntersectionNaiveMoller(&scene);
}
Image *image = 0;
//if (params["output"] == "sfml")
image = new SFMLImage(cameratemp.width, cameratemp.height);
//else
// image = new Image(cameratemp.width, cameratemp.height);
ULARGE_INTEGER time = getTime();
inter_method->build(time_limit);
/*IntersectionMethod* im = new IntersectionKdTreeSAH(&scene, 15, 20, true, N2);
im->build(time_limit);
std::cout<<((IntersectionKdTreeSAH*)(im))->_depth.size()<<" vs "<<((IntersectionKdTreeSAH*)(inter_method))->_depth.size()<<"\n";
delete im;*/
if (inter_method->finished) {
std::cout<<"build: "<<getTimeElapsed(time)<<"\n";
time = getTime();
int nb = raytrace(cameratemp, image, scene, inter_method, time, time_limit);
Real dt = getTimeElapsed(time);
std::cout<<"triangles: "<<nb<<"\n";
if (nb >= 0) {
std::cout<<"task: "<<dt<<"\n";
} else {
std::cout<<"task: "<<"INFTY"<<"\n";
}
// image->saveTo(params["output"]);
std::cout<<"tri/ray: "<<COUNTS::NB_TESTS_TRI_RAY<<"\n";
std::cout<<"box/ray: "<<COUNTS::NB_TESTS_TRI_VOXEL<<"\n";
}
else {
std::cout<<"build: "<<"INFTY"<<"\n";
}
delete inter_method;
delete image;
return 0;
}