-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·418 lines (254 loc) · 8.82 KB
/
main.cpp
File metadata and controls
executable file
·418 lines (254 loc) · 8.82 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
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
#include <iostream>
#include <pangolin/pangolin.h>
#include <thread>
#include <chrono>
#include <vector>
#include <sstream>
#include <fstream>
#include <iostream>
#include "Parse.h"
typedef struct {
double r,g,b;
} COLOUR;
COLOUR GetColour(double v,double vmin,double vmax)
{
COLOUR c = {1.0,1.0,1.0}; // white
double dv;
if (v < vmin)
v = vmin;
if (v > vmax)
v = vmax;
dv = vmax - vmin;
if (v < (vmin + 0.25 * dv)) {
c.r = 0;
c.g = 4 * (v - vmin) / dv;
} else if (v < (vmin + 0.5 * dv)) {
c.r = 0;
c.b = 1 + 4 * (vmin + 0.25 * dv - v) / dv;
} else if (v < (vmin + 0.75 * dv)) {
c.r = 4 * (v - vmin - 0.5 * dv) / dv;
c.b = 0;
} else {
c.g = 1 + 4 * (vmin + 0.75 * dv - v) / dv;
c.b = 0;
}
return(c);
}
using std::vector;
struct Surfel {
float r,g,b;
float nx,ny,nz;
float x,y,z,t,c;
};
struct CustomType
{
CustomType()
: x(0), y(0.0f) {}
CustomType(int x, float y, std::string z)
: x(x), y(y), z(z) {}
int x;
float y;
std::string z;
};
std::ostream& operator<< (std::ostream& os, const CustomType& o){
os << o.x << " " << o.y << " " << o.z;
return os;
}
std::istream& operator>> (std::istream& is, CustomType& o){
is >> o.x;
is >> o.y;
is >> o.z;
return is;
}
void SampleMethod()
{
std::cout << "You typed ctrl-r or pushed reset" << std::endl;
}
void Load(std::string *filename,vector<Surfel> * Surfel_load) {
FILE *fp;
fp = fopen(filename->c_str(), "r");
float r, g, b;
float nx, ny, nz;
float x, y, z, t, c;
while (fscanf(fp, "%f %f %f %f %f %f %f %f %f %f %f", &x, &y, &z, &t, &c, &nx, &ny, &nz, &r, &g, &b) != EOF) {
Surfel tmp;
tmp.x = x;
tmp.y = y;
tmp.z = z;
tmp.t = t;
tmp.c = c;
tmp.nx = nx;
tmp.ny = ny;
tmp.nz = nz;
tmp.r = r;
tmp.g = g;
tmp.b = b;
Surfel_load->push_back(tmp);
}
fclose(fp);
}
void ListDrawSurfels(GLuint * disp_list,vector<Surfel> * Surfel_load,int draw_type,float rad,float min_confi) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
*disp_list=glGenLists(1);
glNewList(*disp_list,GL_COMPILE);
glEnable(GL_DEPTH_TEST);
GLfloat mat_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat mat_diffuse[] = { 0.7, 0.0, 0.2, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
//glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_LIGHTING);
//glLoadIdentity();
pangolin::glDrawAxis(100);
Surfel o = Surfel_load->at(Surfel_load->size()-1);
float maxt = o.t;
//while(fscanf(fp, "%f %f %f %f %f",&x,&y,&z,&t,&c)!=EOF)
for(int k = 0;k <Surfel_load->size();k++)
{
Surfel o = Surfel_load->at(k);
if(o.c>min_confi){
glPushMatrix();
if(draw_type == 0)
{
glColor3f(o.r,o.g,o.b);
}else if(draw_type == 1)
{
COLOUR c = GetColour(o.t,0,maxt);
glColor3f(c.r,c.g,c.b);
}else if(draw_type == 2)
{
COLOUR c = GetColour(o.c,0,50.0);
glColor3f(c.r,c.g,c.b);
}
else
glColor3f(o.r,o.g,o.b);
glTranslatef(o.x/1000,o.y/1000,o.z/1000);
float rx,ry,rz;
rz = 0;
ry = atan2(o.nx,o.nz)/3.141592*180;
rx = 0;
rx = atan2(o.ny,sqrt(o.nx*o.nx+o.nz*o.nz))/3.141592*180;
glRotatef(rz,0.0f,0.0f,1.0f);
glRotatef(ry,0.0f,1.0f,0.0f);
glRotatef(-rx,1.0f,0.0f,0.0f);
/*
glRotatef(o.nz,0.0f,0.0f,1.0f);
glRotatef(o.ny,0.0f,1.0f,0.0f);
glRotatef(o.nx,1.0f,0.0f,0.0f);
*/
pangolin::glDrawCircle( 0, 0, rad);
//pangolin::glDrawAxis(1);
glPopMatrix();
}
}
glEndList();
}
int main(int argc, char* argv[])
{
std::string filename;
Parse::get().arg(argc, argv, "-l", filename);
// Load configuration data
pangolin::ParseVarsFile("app.cfg");
// Create OpenGL window in single line
pangolin::CreateWindowAndBind("Surfel Viewer",640,480);
// 3D Mouse handler requires depth testing to be enabled
glEnable(GL_DEPTH_TEST);
// Define Camera Render Object (for view / scene browsing)
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-0,0.5,3, 0,0,0, pangolin::AxisY)
);
const int UI_WIDTH = 180;
// Add named OpenGL viewport to window and provide 3D Handler
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
// Add named Panel and bind to variables beginning 'ui'
// A Panel is just a View with a default layout and input handling
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
// Safe and efficient binding of named variables.
// Specialisations mean no conversions take place for exact types
// and conversions between scalar types are cheap.
pangolin::Var<bool> filereload("ui.Load",false,false);
pangolin::Var<bool> updateclick("ui.UpdateSetting",false,false);
pangolin::Var<double> confidence_val("ui.confi",1,0,50);
pangolin::Var<double> rad_val("ui.rad",0.3,0,1);
pangolin::Var<bool> time_checkbox("ui.Time",false,true);
pangolin::Var<bool> confidence_checkbox("ui.Confidence",false,true);
pangolin::Var<bool> normal_checkbox("ui.Normal",false,true);
pangolin::Var<int> num_surfels("ui.Surfels",2);
//pangolin::Var<CustomType> any_type("ui.Some_Type", CustomType(0,1.2f,"Hello") );
pangolin::Var<bool> save_window("ui.Save_Window",false,false);
pangolin::Var<bool> save_view("ui.Save_View",false,false);
pangolin::Var<bool> record_cube("ui.Record_Cube",false,false);
// std::function objects can be used for Var's too. These work great with C++11 closures.
pangolin::Var<std::function<void(void)> > reset("ui.Reset", SampleMethod);
// Demonstration of how we can register a keyboard hook to alter a Var
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'b', pangolin::SetVarFunctor<double>("ui.A Double", 3.5));
// Demonstration of how we can register a keyboard hook to trigger a method
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);
// surfel map related
vector<Surfel> Surfel_load;
GLuint disp_list;
// load data from file
Load(&filename,&Surfel_load);
ListDrawSurfels(&disp_list,&Surfel_load,0,rad_val,confidence_val);
// Default hooks for exiting (Esc) and fullscreen (tab).
while( !pangolin::ShouldQuit() )
{
// Clear entire screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reload pointcloud file
if( pangolin::Pushed(filereload) ){
Load(&filename,&Surfel_load);
ListDrawSurfels(&disp_list,&Surfel_load,0,rad_val,confidence_val);
}
// Update settings and redraw
if( pangolin::Pushed(updateclick) )
{
int draw_type=0;
if( time_checkbox )
draw_type=1; // color by time
if( confidence_checkbox )
draw_type=2; // color by confidence
if( normal_checkbox )
draw_type = 0; // otherwise
// reset the draw list
ListDrawSurfels(&disp_list,&Surfel_load,draw_type,rad_val,confidence_val);
}
num_surfels = Surfel_load.size();
// button handlers
if( pangolin::Pushed(save_window) )// save whole window
pangolin::SaveWindowOnRender("window");
if( pangolin::Pushed(save_view) )// save the view only
d_cam.SaveOnRender("view");
if( pangolin::Pushed(record_cube) )// record a video
pangolin::DisplayBase().RecordOnRender("ffmpeg:[fps=50,bps=8388608,unique_filename]//screencap.avi");
d_cam.Activate(s_cam);
// call the list, this will redraw the serfels when view changed
glCallList(disp_list);
/*
pangolin::glDrawAxis(1);
glTranslatef(1,1,1);
glRotatef(0,0.0f,0.0f,1.0f);
glRotatef(45.0f,0.0f,1.0f,0.0f);
glRotatef(-35.24f,1.0f,0.0f,0.0f);
pangolin::glDrawCircle( 0, 0, 0.5);
pangolin::glDrawAxis(1);
*/
pangolin::FinishFrame();
}
return 0;
}