Commit f37cf039114d48ceace8e27047b4c7071195ef46
1 parent
31c961c7
added transitional visualization using the tag --interp
Showing
2 changed files
with
54 additions
and
14 deletions
Show diff stats
CMakeLists.txt
... | ... | @@ -17,6 +17,11 @@ if ( MSVC ) |
17 | 17 | add_definitions(-D_SCL_SECURE_NO_WARNINGS) |
18 | 18 | endif ( MSVC ) |
19 | 19 | |
20 | +if( CMAKE_COMPILER_IS_GNUCC ) | |
21 | + set(CMAKE_C_FLAGS "-O3") | |
22 | + set(CMAKE_CXX_FLAGS "-O3 -std=c++11 -fpermissive") | |
23 | +endif( CMAKE_COMPILER_IS_GNUCC ) | |
24 | + | |
20 | 25 | #find the STIM library |
21 | 26 | find_package(STIM REQUIRED) |
22 | 27 | ... | ... |
main.cpp
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | stim::camera cam; |
18 | 18 | int mx, my; //mouse coordinates in the window space |
19 | 19 | |
20 | -stim::spharmonics<double> S; | |
20 | +stim::gl_spharmonics<double> S; | |
21 | 21 | stim::gl_spharmonics<double> R; //spherical harmonics to render |
22 | 22 | |
23 | 23 | float d = 1.5; //initial distance between the camera and the sphere |
... | ... | @@ -31,8 +31,8 @@ bool zaxis = false; //render the z-axis (set via a command line flag) |
31 | 31 | /// INTERPOLATION |
32 | 32 | stim::gl_spharmonics<double> Si; |
33 | 33 | bool interp = false; //if we are interpolating |
34 | -float alpha = 0.0; //alpha value for interpolation | |
35 | -float dalpha = 0.1; //change in alpha value with a key press | |
34 | +double alpha = 0.0; //alpha value for interpolation | |
35 | +double dalpha = 0.1; //change in alpha value with a key press | |
36 | 36 | |
37 | 37 | bool init(){ |
38 | 38 | |
... | ... | @@ -72,12 +72,16 @@ void display(){ |
72 | 72 | |
73 | 73 | //specify the camera parameters to OpenGL |
74 | 74 | gluLookAt(p[0], p[1], p[2], d[0], d[1], d[2], u[0], u[1], u[2]); |
75 | + if(interp) | |
76 | + { | |
77 | + R=S*(1.0-alpha)+Si*alpha; | |
78 | + R.glInit(); | |
79 | + interp = false; | |
80 | + } | |
81 | + std::cout << "R " << R.str() << std::endl; | |
75 | 82 | |
76 | 83 | //draw the sphere |
77 | - if (interp) | |
78 | - R = (S * (1.0f - alpha) + Si * alpha); | |
79 | - else | |
80 | - R = S; | |
84 | + | |
81 | 85 | R.glRender(); |
82 | 86 | |
83 | 87 | |
... | ... | @@ -97,6 +101,23 @@ void display(){ |
97 | 101 | glutSwapBuffers(); |
98 | 102 | } |
99 | 103 | |
104 | +//Process Arrow Key presses. | |
105 | +void | |
106 | +processSpecialKeys(int key, int xx, int yy) | |
107 | +{ | |
108 | + switch(key) | |
109 | + { | |
110 | + case GLUT_KEY_UP: | |
111 | + alpha = alpha + dalpha; | |
112 | + break; | |
113 | + case GLUT_KEY_DOWN: | |
114 | + alpha = alpha - dalpha; | |
115 | + break; | |
116 | + } | |
117 | + interp = true; | |
118 | + glutPostRedisplay(); | |
119 | +} | |
120 | + | |
100 | 121 | void mouse_press(int button, int state, int x, int y){ |
101 | 122 | |
102 | 123 | //set the camera motion mode based on the mouse button pressed |
... | ... | @@ -206,18 +227,27 @@ void process_arguments(int argc, char* argv[]){ |
206 | 227 | if(args["zaxis"].is_set()) |
207 | 228 | zaxis = true; |
208 | 229 | |
209 | - if (args["interp"]) { //if an interpolation harmonic is provided | |
210 | - for (unsigned int a = 0; a < args["interp"].nargs(); a++) | |
211 | - Si.push(args["interp"].as_float(a)); | |
212 | - } | |
213 | - | |
214 | 230 | //if arguments are specified, push them as coefficients |
215 | - if(args.nargs() > 0){ | |
231 | + if(args.nargs() > 0 && !args["interp"]){ | |
216 | 232 | //push all of the arguments to the spherical harmonics class as coefficients |
217 | - for(unsigned int a = 0; a < args.nargs(); a++) | |
233 | + for(unsigned int a = 0; a < args.nargs(); a++){ | |
218 | 234 | S.push(atof(args.arg(a).c_str())); |
235 | + R = S; | |
236 | + } | |
219 | 237 | } |
238 | + else if(args.nargs() > 0 && args["interp"]){ | |
239 | + for(unsigned int a = 0; a < args.nargs(); a++){ | |
240 | + S.push(atof(args.arg(a).c_str())); | |
241 | + } | |
242 | + | |
243 | + for (unsigned int a = 0; a < args["interp"].nargs(); a++) | |
244 | + Si.push(args["interp"].as_float(a)); | |
245 | + | |
246 | + R = S+Si*0.0; | |
220 | 247 | |
248 | + | |
249 | + | |
250 | + } | |
221 | 251 | //if the user wants to use a random set of SH coefficients |
222 | 252 | else if(args["rand"].is_set()){ |
223 | 253 | |
... | ... | @@ -350,6 +380,7 @@ void process_arguments(int argc, char* argv[]){ |
350 | 380 | { |
351 | 381 | std::cout << i << sphere[i] << " " << weights[i] << std::endl; |
352 | 382 | } |
383 | + //std::cout << i << sphere[i] << " " << weights[i] << std::endl; | |
353 | 384 | stim::vec3<float> sph = sphere[i].cart2sph(); |
354 | 385 | S.mcSample(sph[1], sph[2], weights[i]); |
355 | 386 | } |
... | ... | @@ -429,6 +460,8 @@ void process_arguments(int argc, char* argv[]){ |
429 | 460 | std::cout<<args.str(); |
430 | 461 | exit(0); |
431 | 462 | } |
463 | + | |
464 | + R = S; | |
432 | 465 | } |
433 | 466 | |
434 | 467 | int main(int argc, char *argv[]){ |
... | ... | @@ -459,6 +492,8 @@ int main(int argc, char *argv[]){ |
459 | 492 | //set the mouse motion function (which will be called any time the mouse is dragged) |
460 | 493 | glutMotionFunc(mouse_drag); |
461 | 494 | |
495 | + glutSpecialFunc(processSpecialKeys); | |
496 | + | |
462 | 497 | //run the initialization function |
463 | 498 | if(!init()) |
464 | 499 | return 1; //return an error if it fails | ... | ... |