-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
executable file
·433 lines (378 loc) · 11.3 KB
/
main.cc
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/**
* Point Based Renderer
*
* Author : Ricardo Marroquim
*
* Date created : 12-01-2007
*
**/
#include "application.h"
#include "GL/glut.h"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
// Initial window width
static int windows_width = 1024;
static int windows_height = 1024;
bool depth_test;
bool back_face_culling;
int button_pressed;
bool active_shift;
bool active_ctrl;
bool active_alt;
int mask_size;
double reconstruction_filter_size;
double prefilter_size;
int material;
bool auto_rotate;
bool elliptical_weight;
double minimum_radius_size;
Application *application;
void display( void )
{
// static int frame = 0, time, timebase = 0;
// float fps;
// frame++;
// time = glutGet(GLUT_ELAPSED_TIME);
// if (time - timebase > 1000) {
// fps = frame*1000.0/(float)(time-timebase);
// cout << fps << endl;
// timebase = time;
// frame = 0;
// }
application->draw();
// Make sure changes appear onscreen
glutSwapBuffers();
}
void idle( void ) {
// if (auto_rotate)
display();
}
void reshape(GLint width, GLint height)
{
windows_width = width;
windows_height = height;
application->reshape(width, height);
application->changeMaterial(material);
application->setBackFaceCulling ( back_face_culling );
application->setEllipticalWeight( elliptical_weight );
application->setGpuMask ( mask_size );
}
/// Keyboard keys function
/// @param key Pressed key
/// @param x X coordinate of mouse pointer
/// @param y Y coordinate of mouse pointer
void keyboard(unsigned char key_pressed, int x, int y) {
switch (key_pressed) {
case 27 :
case 'q' :
case 'Q' :
delete application;
exit(0);
break;
case '0' :
material = 0;
break;
case '1' :
material = 1;
break;
case '2' :
material = 2;
break;
case '3' :
material = 3;
break;
case '4' :
material = 4;
break;
case '5' :
material = 5;
break;
case '6' :
material = 6;
break;
case '7' :
material = 7;
break;
case 'r':
auto_rotate = !auto_rotate;
application->setAutoRotate( auto_rotate );
break;
case 'w':
elliptical_weight = !elliptical_weight;
application->setEllipticalWeight( elliptical_weight );
cout << "Elliptical weight : " << elliptical_weight << endl;
break;
case 'd' :
depth_test = !depth_test;
application->setDepthTest ( depth_test );
break;
case 'b' :
back_face_culling = !back_face_culling;
application->setBackFaceCulling ( back_face_culling );
break;
case '.':
application->increaseSelected ( );
break;
case ',':
application->decreaseSelected ( );
break;
case '+' :
mask_size ++;
application->setGpuMask ( mask_size );
break;
case '-' :
if (mask_size > 0)
mask_size --;
application->setGpuMask ( mask_size );
break;
case ']' :
if (reconstruction_filter_size < 0.1)
reconstruction_filter_size += 0.01;
else
reconstruction_filter_size += 0.1;
application->setReconstructionFilter ( reconstruction_filter_size );
cout << "filter size : " << reconstruction_filter_size << endl;
break;
case '[' :
if (reconstruction_filter_size > 0.15)
reconstruction_filter_size -= 0.1;
else if (reconstruction_filter_size > 0.0)
reconstruction_filter_size -= 0.01;
application->setReconstructionFilter ( reconstruction_filter_size );
cout << "filter size : " << reconstruction_filter_size << endl;
break;
case '>' :
minimum_radius_size += 0.01;
application->setMinimumRadius ( minimum_radius_size );
cout << "Minimum radius size : " << minimum_radius_size << endl;
break;
case '<' :
minimum_radius_size -= 0.01;
if (minimum_radius_size < 0.0)
minimum_radius_size = 0.0;
application->setMinimumRadius ( minimum_radius_size );
cout << "Minimum radius size : " << minimum_radius_size << endl;
break;
}
// material change
switch (key_pressed) {
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
application->changeMaterial ( material );
}
glutPostRedisplay();
}
/// Keyboard keys function
/// @param key Pressed key
/// @param x X coordinate of mouse pointer
/// @param y Y coordinate of mouse pointer
void keyboardSpecial(int key_pressed, int x, int y) {
switch (key_pressed) {
case GLUT_KEY_F1 :
application->changeRendererType ( 0 );
cout << "PYRAMID POINTS" << endl;
break;
case GLUT_KEY_F2 :
application->changeRendererType ( 1 );
cout << "PYRAMID POINTS WITH COLOR" << endl;
break;
case GLUT_KEY_F3 :
// application->changeRendererType ( 2 );
cout << "PYRAMID TEMPLATES WITH COLOR NOT READY" << endl;
break;
case GLUT_KEY_F4 :
// application->changeRendererType ( 3 );
cout << "PYRAMID ELIPSES NOT READY" << endl;
break;
}
// reset values
switch (key_pressed) {
case GLUT_KEY_F1 :
case GLUT_KEY_F2 :
// case GLUT_KEY_F3 :
// case GLUT_KEY_F4 :
application->setGpuMask ( mask_size );
application->changeMaterial ( material );
application->setReconstructionFilter ( reconstruction_filter_size );
application->setPrefilter ( prefilter_size );
application->setDepthTest( depth_test );
application->setBackFaceCulling( back_face_culling );
application->setEllipticalWeight( elliptical_weight );
break;
}
glutPostRedisplay();
}
/// Mouse click function
/// @param button Clicked button
/// @param state Button state (clicked or released)
/// @param x X coordinate of mouse click
/// @param y Y coordinate of mouse click
void mouse(int button, int state, int x, int y) {
button_pressed = button;
if (state == GLUT_DOWN) {
active_shift = active_ctrl = active_alt = 0;
switch (glutGetModifiers()) {
case GLUT_ACTIVE_SHIFT : active_shift = 1; break;
case GLUT_ACTIVE_CTRL : active_ctrl = 1; break;
case GLUT_ACTIVE_ALT : active_alt = 1; break;
case GLUT_ACTIVE_SHIFT | GLUT_ACTIVE_CTRL : active_shift = 1; active_ctrl = 1; break;
case GLUT_ACTIVE_SHIFT | GLUT_ACTIVE_ALT : active_shift = 1; active_alt = 1; break;
case GLUT_ACTIVE_CTRL | GLUT_ACTIVE_ALT : active_ctrl = 1; active_alt = 1; break;
case GLUT_ACTIVE_SHIFT | GLUT_ACTIVE_CTRL | GLUT_ACTIVE_ALT : active_shift = 1; active_ctrl = 1; active_alt = 1; break;
}
if (button == GLUT_LEFT_BUTTON) {
application->mouseLeftButton(x, y, active_shift, active_ctrl, active_alt );
}
else if (button == GLUT_MIDDLE_BUTTON) {
application->mouseMiddleButton(x, y, active_shift, active_ctrl, active_alt );
}
else if (button == GLUT_RIGHT_BUTTON) {
application->mouseRightButton(x, y, active_shift, active_ctrl, active_alt );
}
}
else if (state == GLUT_UP) {
if (button == GLUT_LEFT_BUTTON) {
application->mouseReleaseLeftButton(x, y, active_shift, active_ctrl, active_alt );
}
else if (button == GLUT_MIDDLE_BUTTON) {
application->mouseReleaseMiddleButton(x, y, active_shift, active_ctrl, active_alt );
}
else if (button == GLUT_RIGHT_BUTTON) {
application->mouseReleaseRightButton(x, y, active_shift, active_ctrl, active_alt );
}
else if (button == 3) {
application->mouseWheel(+1, active_shift, active_ctrl, active_alt );
}
else if (button == 4) {
application->mouseWheel(-1, active_shift, active_ctrl, active_alt );
}
button_pressed = -1;
active_shift = 0;
active_ctrl = 0;
}
glutPostRedisplay();
}
// void mouseWheel(int button, int dir, int x, int y) {
// if (dir > 0)
// application->mouseWheel(1);
// else
// application->mouseWheel(-1);
// }
/// Mouse movement func
/// @param x X coordinate of mouse pointer
/// @param y Y coordinate of mouse pointer
void mouseMotion(int x, int y) {
// Point click = unproject (Point (x, y, 0.0));
if (button_pressed == GLUT_LEFT_BUTTON)
application->mouseLeftMotion(x, y, active_shift, active_ctrl, active_alt );
else if (button_pressed == GLUT_MIDDLE_BUTTON)
application->mouseMiddleMotion(x, y, active_shift, active_ctrl, active_alt );
else if (button_pressed == GLUT_RIGHT_BUTTON)
application->mouseRightMotion(x, y, active_shift, active_ctrl, active_alt );
glutPostRedisplay();
}
/*function... might want it in some class?*/
int getFilesFromDirectory (string dir, vector<string> &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
files.push_back(string(dirp->d_name));
}
closedir(dp);
return 0;
}
/// Main Program
int main(int argc, char * argv []) {
// GLUT Window Initialization:
glutInit (&argc, argv);
glutInitWindowSize (windows_width, windows_height);
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(150, 0);
glutCreateWindow ("Point Based Rendering");
mask_size = 2;
reconstruction_filter_size = 1.0;
prefilter_size = 1.0;
material = 3;
auto_rotate = false;
elliptical_weight = true;
depth_test = true;
back_face_culling = true;
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
exit(0);
}
//application = new Application(PYRAMID_TEMPLATES);
application = new Application(PYRAMID_POINTS, windows_width, windows_height);
if (argc < 2) {
cerr << " Usage :" << endl << " pyramid-point-renderer <ply_file>" << endl;
exit(0);
}
// directory
if (strcmp (argv[1], "-d") == 0) {
string dir = string(argv[2]);
vector<string> files = vector<string>();
getFilesFromDirectory(dir,files);
// remove non ply files in directory
for (unsigned int i = 0; i < files.size(); i++){
if (files[i].rfind("ply") == string::npos) {
files.erase(files.begin()+i);
--i;
}
}
int pts = 0;
// for every ply file in directory
for (unsigned int i = 0; i < files.size(); i++) {
pts += application->appendFile( (dir + files[i]).c_str() );
cout << i+1 << "/" << files.size() << " : " << (dir + files[i]).c_str() << endl;
cout << "points : " << setiosflags(ios::fixed) << setprecision(2) << pts/1000000.0 << "M" << endl;
}
application->finishFileReading();
material = 5;
back_face_culling = true;
}
// eliptical surfel file
else if (strcmp (argv[1], "-l") == 0) {
application->readFile( argv[2], true );
cout << "elipses : " << application->getNumberPoints() << endl;
}
// single file
else {
application->readFile( argv[1] );
cout << "points : " << application->getNumberPoints() << endl;
}
// Set initial values
application->setReconstructionFilter ( reconstruction_filter_size );
application->setPrefilter ( prefilter_size );
application->setMinimumRadius( minimum_radius_size );
application->setDepthTest( depth_test );
application->changeMaterial(material);
application->setBackFaceCulling ( back_face_culling );
application->setEllipticalWeight( elliptical_weight );
application->setGpuMask ( mask_size );
//GLUT callback functions
glutDisplayFunc(display);
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
// glutMouseWheelFunc(mouseWheel);
glutKeyboardFunc(keyboard);
glutSpecialFunc(keyboardSpecial);
glutMainLoop();
return 0;
}