#include <GL/glut.h>#include <iostream>#include <MC_particle_engine.hpp>#include <MC_grid_3d_scalar.hpp>#include <MC_grid_3d_scalar_marching_cube.hpp>#include <MC_potential_sphere.hpp>#include <mesh_converter.hpp>#include <vector>#include <algorithm>
Go to the source code of this file.
Defines | |
| #define | GLUT_SPACE 32 |
Functions | |
| static void | display_callback () |
| static void | reshape_callback (int width, int height) |
| static void | keyboard_callback (unsigned char key, int x, int y) |
| static void | idle_callback (int value) |
| static void | motion_callback (int x, int y) |
| static void | mouse_callback (int button, int action, int x, int y) |
| void | draw_orientation () |
| void | draw_pointer () |
| void | draw_fps () |
| void | draw_extra () |
| void | draw_sphere (const MC_v3d ¢er, const double &radius) |
| int | setup_opengl (int argc, char **argv) |
| int | draw_scene () |
| void | init_parameters () |
| double | get_rand () |
| int | evolve () |
| void | update_potential () |
| void | update_marching_cube () |
| void | draw_plane () |
| void | plane_clear () |
| void | update_plane (const unsigned int &N) |
| void | update_plane_density () |
| void | export_scene (unsigned int number) |
| void | engine_run () |
| void | set_light () |
| int | main (int argc, char *argv[]) |
Variables | |
| bool | is_shift_on = false |
| bool | is_draw_grid = false |
| bool | is_draw_sphere = true |
| bool | is_run = false |
| bool | is_draw_force = false |
| bool | is_draw_isosurface = false |
| bool | is_plane = false |
| bool | is_plane_cleared |
| bool | is_throw_ball = false |
| bool | is_collision_detection = true |
| bool | is_potential = false |
| unsigned int | counter_global = 0 |
| GLuint | id_draw_sphere = 0 |
| unsigned int | counter = 0 |
| mesh_conv::MC_navigator_tool | navigator |
| unsigned int | thrower_timer = 0 |
| mesh_conv::MC_particle_engine | engine |
| mesh_conv::MC_v3d_vector | COLOR_TABLE |
| mesh_conv::MC_grid_3d_scalar | potential |
| mesh_conv::MC_mesh_index_vector_draw | mesh_iso |
| double | isovalue = 2 |
| unsigned int | N_smooth = 2 |
| unsigned int | thrower_time = 90 |
| double | sphere_radius = 0.03 |
| unsigned int | dim_grid_3d = 30 |
| double | plane_Lz = 0.0 |
| double | plane_L = 0.5 |
| mesh_conv::MC_mesh_index_vector_draw | plane_mesh |
| unsigned int | engine_timer = 0 |
| #define GLUT_SPACE 32 |
| static void display_callback | ( | ) | [static] |
Definition at line 389 of file main.cpp.
References mesh_conv::MC_quaternion::conjugated(), counter, mesh_conv::MC_navigator_tool::current_time, mesh_conv::MC_navigator_tool::delta_time(), mesh_conv::MC_navigator_tool::dist_cam1, draw_fps(), draw_orientation(), draw_pointer(), draw_scene(), mesh_conv::MC_navigator_tool::increase_frame_number(), mesh_conv::MC_quaternion::matrix(), mesh_conv::MC_matrix::pointer(), mesh_conv::MC_navigator_tool::projection_param(), mesh_conv::MC_trackball::quaternion(), mesh_conv::MC_matrix::to_matrix4(), mesh_conv::MC_navigator_tool::tr_cam1, mesh_conv::MC_navigator_tool::trackball_cam1, mesh_conv::MC_navigator_tool::update_fps(), mesh_conv::MC_navigator_tool::x_screen_size_1, and mesh_conv::MC_navigator_tool::y_screen_size_1.
Referenced by setup_opengl().
00390 { 00391 00392 00393 //vieport (all screen) 00394 glViewport (0, 0, navigator.x_screen_size_1,navigator.y_screen_size_1); 00395 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00396 00397 //Projection 00398 glMatrixMode(GL_PROJECTION); 00399 glLoadIdentity (); 00400 mesh_conv::MC_double_vector proj_param=navigator.projection_param(); 00401 glFrustum(proj_param[0], -proj_param[0], proj_param[1], -proj_param[1], proj_param[2], proj_param[3]); 00402 00403 00404 //Modelview 00405 glMatrixMode(GL_MODELVIEW); 00406 glLoadIdentity(); 00407 00408 glTranslated(0,0,static_cast<GLdouble>(navigator.dist_cam1)); //zoom 00409 MC_matrix temp_rotation = navigator.trackball_cam1.quaternion().conjugated().matrix().to_matrix4(); 00410 glMultMatrixd(temp_rotation.pointer()); //rotation 00411 glTranslated(static_cast<GLdouble>(navigator.tr_cam1[0]),static_cast<GLdouble>(navigator.tr_cam1[1]),static_cast<GLdouble>(navigator.tr_cam1[2])); //translation 00412 00413 00414 //draw 00415 draw_scene(); 00416 00417 //draw_pointer 00418 draw_pointer(); 00419 00420 //draw orientation (clear DEPTH-BUFFER) 00421 draw_orientation(); 00422 00423 //update fps 00424 navigator.increase_frame_number(); 00425 navigator.current_time=glutGet(GLUT_ELAPSED_TIME); 00426 if(navigator.delta_time()>1000) 00427 {navigator.update_fps();} 00428 00429 //draw fps 00430 draw_fps(); 00431 00432 //error OpenGL_drawer_2 00433 GLenum errCode; 00434 const GLubyte *errString; 00435 if((errCode=glGetError()) != GL_NO_ERROR) 00436 { 00437 errString = gluErrorString(errCode); 00438 std::cout<<"OPENGL ERROR : "<<errString<<std::endl; 00439 exit(-2); 00440 } 00441 00442 counter++; 00443 00444 00445 //redraw 00446 glFlush (); 00447 glutSwapBuffers (); 00448 00449 }

| void draw_extra | ( | ) |
Definition at line 287 of file main.cpp.
Referenced by draw_scene().
00288 { 00289 glEnable(GL_LIGHTING); 00290 glColor3d(0.8,0.8,0.8); 00291 00292 //draw what you want 00293 00294 }

| void draw_fps | ( | ) |
Definition at line 763 of file main.cpp.
References mesh_conv::MC_navigator_tool::current_fps, mesh_conv::MC_particle_engine::particle_system(), and mesh_conv::MC_string_converter::to_string().
Referenced by display_callback().
00764 { 00765 glDisable(GL_DEPTH_TEST); 00766 00767 int int_fps=int(navigator.current_fps); 00768 int deci_fps=int(10*(navigator.current_fps-int_fps)); 00769 double truncated_fps=int_fps+double(deci_fps)/10.0; 00770 00771 std::string fps=(mesh_conv::MC_string_converter::to_string(truncated_fps)+" fps"); 00772 00773 glPushMatrix(); 00774 glLoadIdentity(); 00775 glRasterPos3f(-0.5f,-0.5f,-1.4f); 00776 for (unsigned int k=0,N=fps.length();k<N;++k) 00777 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,fps[k]); 00778 glPopMatrix(); 00779 00780 std::string particles=(mesh_conv::MC_string_converter::to_string(engine.particle_system().size())+" particles"); 00781 glPushMatrix(); 00782 glLoadIdentity(); 00783 glRasterPos3f(-0.5f,+0.5f,-1.4f); 00784 for (unsigned int k=0,N=particles.length();k<N;++k) 00785 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,particles[k]); 00786 glPopMatrix(); 00787 00788 glEnable(GL_DEPTH_TEST); 00789 }


| void draw_orientation | ( | ) |
Definition at line 694 of file main.cpp.
References mesh_conv::MC_quaternion::conjugated(), mesh_conv::MC_quaternion::matrix(), mesh_conv::MC_matrix::pointer(), mesh_conv::MC_trackball::quaternion(), mesh_conv::MC_matrix::to_matrix4(), and mesh_conv::MC_navigator_tool::trackball_cam1.
Referenced by display_callback().
00695 { 00696 glDisable(GL_LIGHTING); 00697 //rotation 00698 glClear(GL_DEPTH_BUFFER_BIT); 00699 glMatrixMode(GL_PROJECTION); 00700 glPushMatrix(); 00701 glLoadIdentity (); 00702 glOrtho(-1,1,1,-1,0.1,10.0); 00703 glMatrixMode(GL_MODELVIEW); 00704 glPushMatrix(); 00705 glLoadIdentity(); 00706 glTranslated(0.78,0.78,-1); 00707 // get pointer 00708 MC_matrix M=navigator.trackball_cam1.quaternion().conjugated().matrix().to_matrix4(); 00709 // rotation 00710 glMultMatrixd(M.pointer()); 00711 00712 double L=0.2; 00713 glBegin(GL_LINES); 00714 glColor3d(1,0,0); 00715 glVertex3d(0,0,0); 00716 glVertex3d(L,0,0); 00717 glColor3d(0,1,0); 00718 glVertex3d(0,0,0); 00719 glVertex3d(0,L,0); 00720 glColor3d(0,0,1); 00721 glVertex3d(0,0,0); 00722 glVertex3d(0,0,L); 00723 glEnd(); 00724 //pop matrices 00725 glPopMatrix(); 00726 glMatrixMode(GL_PROJECTION); 00727 glPopMatrix(); 00728 glMatrixMode(GL_MODELVIEW); 00729 00730 }


| void draw_plane | ( | ) |
| void draw_pointer | ( | ) |
Definition at line 733 of file main.cpp.
References mesh_conv::MC_quaternion::conjugated(), mesh_conv::MC_navigator_tool::dist_cam1, mesh_conv::MC_quaternion::matrix(), mesh_conv::MC_matrix::pointer(), mesh_conv::MC_trackball::quaternion(), mesh_conv::MC_matrix::to_matrix4(), and mesh_conv::MC_navigator_tool::trackball_cam1.
Referenced by display_callback().
00734 { 00735 00736 glPushMatrix(); 00737 glLoadIdentity(); 00738 00739 glTranslatef(0,0,GLfloat(navigator.dist_cam1)); //zoom 00740 MC_matrix temp_m=navigator.trackball_cam1.quaternion().conjugated().matrix().to_matrix4(); 00741 glMultMatrixd(temp_m.pointer()); //rotation 00742 00743 //local basis 00744 double L=0.01; 00745 00746 glBegin(GL_LINES); 00747 glColor3d(1,0,0); 00748 glVertex3d(-L,0,0); 00749 glVertex3d(L,0,0); 00750 glColor3d(0,1,0); 00751 glVertex3d(0,-L,0); 00752 glVertex3d(0,L,0); 00753 glColor3d(0,0,1); 00754 glVertex3d(0,0,-L); 00755 glVertex3d(0,0,L); 00756 glEnd(); 00757 00758 glPopMatrix(); 00759 00760 }


| int draw_scene | ( | ) |
Definition at line 794 of file main.cpp.
References draw_extra(), id_draw_sphere, is_draw_force, is_draw_grid, is_draw_isosurface, is_draw_sphere, is_plane, is_plane_cleared, mesh_conv::MC_particle_engine::particle_system(), mesh_conv::MC_v3d_vector::pointer(), set_light(), and mesh_conv::MC_v3d_vector::size().
Referenced by display_callback().
00795 { 00796 00797 set_light(); 00798 00799 00800 //draw spheres 00801 glColor3d(1,0,0); 00802 if(is_draw_sphere) 00803 { 00804 const std::map<unsigned int,MC_sphere_physic>& particles=engine.particle_system(); 00805 for(std::map<unsigned int,MC_sphere_physic>::const_iterator it=particles.begin(),it_end=particles.end();it!=it_end;++it) 00806 { 00807 const unsigned int& id=it->first; 00808 glColor3dv(COLOR_TABLE[id%COLOR_TABLE.size()].pointer()); 00809 00810 00811 const MC_sphere_physic& current_particle=it->second; 00812 00813 const MC_v3d& c=current_particle.center(); 00814 const double& r=current_particle.radius(); 00815 glPushMatrix(); 00816 glTranslated(c[0],c[1],c[2]); 00817 glScaled(r,r,r); 00818 glCallList(id_draw_sphere); 00819 glPopMatrix(); 00820 00821 //draw forces 00822 glColor3d(0,0,1); 00823 if(is_draw_force) 00824 { 00825 glDisable(GL_LIGHTING); 00826 MC_segment f(c,c+0.01*current_particle.force()); 00827 MC_opengl_drawer::draw(f); 00828 } 00829 00830 } 00831 } 00832 00833 //draw bounding cube 00834 glColor3d(0,0,0); 00835 glDisable(GL_LIGHTING); 00836 MC_opengl_drawer::draw_grid(MC_mesh_index_vector::build_cube()); 00837 00838 00839 00840 //draw isosurface 00841 glEnable(GL_LIGHTING); 00842 if(is_draw_isosurface) 00843 { 00844 glEnable(GL_POLYGON_OFFSET_FILL); 00845 glPolygonOffset(2,2); 00846 glColor3d(0.5,0.5,0.8); 00847 glEnable(GL_LIGHTING); 00848 MC_opengl_drawer::draw(mesh_iso); 00849 00850 glDisable(GL_POLYGON_OFFSET_FILL); 00851 00852 if(is_draw_grid) 00853 { 00854 glColor3d(0.7,0.1,0.1); 00855 glDisable(GL_LIGHTING); 00856 MC_opengl_drawer::draw_grid(mesh_iso); 00857 } 00858 00859 00860 } 00861 00862 00863 //draw plane 00864 { 00865 00866 if(is_plane==true || is_plane_cleared==false) 00867 { 00868 glDisable(GL_LIGHTING); 00869 glColor3d(0.8,0.8,0.8); 00870 glEnable(GL_POLYGON_OFFSET_FILL); 00871 glPolygonOffset(2,2); 00872 MC_opengl_drawer::draw(plane_mesh); 00873 glDisable(GL_POLYGON_OFFSET_FILL); 00874 00875 glDisable(GL_LIGHTING); 00876 glColor3d(0.2,0.2,1); 00877 if(is_draw_grid) 00878 MC_opengl_drawer::draw_grid(plane_mesh); 00879 } 00880 } 00881 00882 00883 00884 draw_extra(); 00885 00886 return 0; 00887 }


| void draw_sphere | ( | const MC_v3d & | center, | |
| const double & | radius | |||
| ) |
| void engine_run | ( | ) |
Definition at line 222 of file main.cpp.
References mesh_conv::MC_particle_engine::evolve(), is_collision_detection, is_draw_isosurface, is_potential, update_marching_cube(), and update_potential().
Referenced by evolve().
00223 { 00224 00225 //run particle system 00226 engine.evolve(is_collision_detection,is_potential); 00227 00228 //update isosurface 00229 if(is_draw_isosurface) 00230 { 00231 update_potential(); 00232 update_marching_cube(); 00233 } 00234 00235 //export_scene(counter_global++); 00236 00237 }


| int evolve | ( | ) |
Definition at line 241 of file main.cpp.
References mesh_conv::MC_particle_engine::add(), mesh_conv::MC_navigator_tool::current_time, engine_run(), engine_timer, is_run, is_throw_ball, sphere_radius, thrower_time, and thrower_timer.
Referenced by idle_callback().
00242 { 00243 //set-up timer 00244 int ut=glutGet(GLUT_ELAPSED_TIME); 00245 00246 00247 if(ut-engine_timer>25) 00248 { 00249 if(is_run) 00250 { 00251 //add new balls 00252 if(is_throw_ball) 00253 { 00254 if(ut-thrower_timer>thrower_time) 00255 { 00256 engine.add(MC_sphere_physic(MC_v3d(0.5,0.5,0.5),sphere_radius,MC_v3d(1,1,2)*1+MC_v3d(1+0.1*cos(navigator.current_time*34232),1+0.2*sin(5245.34*navigator.current_time*34232),1))); 00257 thrower_timer=ut; 00258 } 00259 } 00260 00261 //evolve particles 00262 engine_run(); 00263 engine_timer=ut; 00264 } 00265 } 00266 00267 return 0; 00268 }


| void export_scene | ( | unsigned int | number | ) |
Definition at line 984 of file main.cpp.
References mesh_conv::MC_particle_engine::particle_system().
Referenced by keyboard_callback().
00985 { 00986 std::string dir="exported_data/"; 00987 std::string number_str=MC_string_converter::zero_padding(MC_string_converter::to_string(number),5); 00988 00989 //export mesh 00990 MC_io_obj::write_obj_file(dir+"mesh_"+number_str+".obj",mesh_iso); 00991 00992 //export sphere 00993 std::string sphere_file=dir+"sphere_"+number_str+".sph"; 00994 std::ofstream file(sphere_file.c_str()); 00995 const std::map<unsigned int,MC_sphere_physic>& particles=engine.particle_system(); 00996 for(std::map<unsigned int,MC_sphere_physic>::const_iterator it=particles.begin(),it_end=particles.end();it!=it_end;++it) 00997 file<<it->first<<" "<<it->second.center()[0]<<" "<<it->second.center()[1]<<" "<<it->second.center()[2]<<" "<<it->second.radius()<<std::endl; 00998 file.close(); 00999 }


| double get_rand | ( | ) |
| static void idle_callback | ( | int | value | ) | [static] |
Definition at line 576 of file main.cpp.
References evolve().
Referenced by setup_opengl().
00577 { 00578 value=1;//useless 00579 00580 glutPostRedisplay (); 00581 glutTimerFunc( 10, idle_callback, 1); 00582 00583 00584 evolve(); 00585 }


| void init_parameters | ( | ) |
Definition at line 272 of file main.cpp.
References dim_grid_3d, and id_draw_sphere.
Referenced by main().
00273 { 00274 COLOR_TABLE=MC_v3d_vector(MC_v3d(1,0,0))<<MC_v3d(0,1,0)<<MC_v3d(0,0,1)<<MC_v3d(0,1,1)<<MC_v3d(1,0,1)<<MC_v3d(1,1,0); 00275 id_draw_sphere=MC_opengl_drawer::send_gpu(MC_mesh_fast_draw(MC_mesh_index_vector::build_sphere(2))); 00276 potential=MC_grid_3d_scalar(MC_int_vector(dim_grid_3d,dim_grid_3d,dim_grid_3d),MC_v3d(1,1,1),MC_v3d(0,0,0)); 00277 00278 }

| static void keyboard_callback | ( | unsigned char | key, | |
| int | x, | |||
| int | y | |||
| ) | [static] |
Definition at line 460 of file main.cpp.
References counter_global, mesh_conv::MC_navigator_tool::dist_cam1, export_scene(), mesh_conv::MC_navigator_tool::go_forward_trackball_cam1(), mesh_conv::MC_navigator_tool::go_right_trackball_cam1(), mesh_conv::MC_navigator_tool::go_up_trackball_cam1(), is_draw_force, is_draw_grid, is_draw_isosurface, is_draw_sphere, is_plane, is_plane_cleared, is_run, is_throw_ball, mesh_conv::MC_navigator_tool::tr_cam1, update_marching_cube(), update_plane(), update_plane_density(), update_potential(), and mesh_conv::MC_navigator_tool::write_cam1_file().
Referenced by setup_opengl().
00461 { 00462 00463 x=0;y=0; 00464 double dL=0.001*(1+100*abs(navigator.dist_cam1)); 00465 00466 #define GLUT_SPACE 32 00467 00468 int mod = glutGetModifiers(); 00469 if((mod&GLUT_ACTIVE_CTRL)!=0) 00470 { 00471 std::cout<<"ctrl on"<<std::endl; 00472 00473 } 00474 00475 00476 switch(key) 00477 { 00478 case 'Q'://quit 00479 { 00480 std::cout<<"\n[EXIT OK]\n\n"<<std::endl; 00481 00482 std::string file_cam("saved_position/saved_camera.dat"); 00483 navigator.write_cam1_file(file_cam); 00484 00485 exit(0); 00486 } 00487 break; 00488 00489 00490 case 'z': 00491 navigator.go_forward_trackball_cam1(dL); 00492 break; 00493 case 's': 00494 navigator.go_forward_trackball_cam1(-dL); 00495 break; 00496 case 'q': 00497 navigator.go_right_trackball_cam1(-dL); 00498 break; 00499 case 'd': 00500 navigator.go_right_trackball_cam1(dL); 00501 break; 00502 case 'r': 00503 navigator.go_up_trackball_cam1(dL); 00504 break; 00505 case 'f': 00506 navigator.go_up_trackball_cam1(-dL); 00507 break; 00508 00509 case 'G': 00510 is_draw_grid==1?is_draw_grid=0:is_draw_grid=1; 00511 break; 00512 00513 case 'W'://wireframe 00514 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 00515 break; 00516 case 'F'://Filled 00517 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00518 break; 00519 00520 case 'X'://cursor position 00521 std::cout<<"cursor position: "<<-navigator.tr_cam1<<std::endl; 00522 break; 00523 00524 case 'R'://run 00525 is_run=!is_run; 00526 std::cout<<"run: "<<is_run<<std::endl; 00527 break; 00528 00529 case 'V': //draw forces 00530 is_draw_force=!is_draw_force; 00531 break; 00532 00533 case 'S': //draw sphere 00534 is_draw_sphere=!is_draw_sphere; 00535 break; 00536 00537 case 'I': //isosurface 00538 is_draw_isosurface=!is_draw_isosurface; 00539 if(is_draw_isosurface==true) 00540 { 00541 update_potential(); 00542 update_marching_cube(); 00543 } 00544 break; 00545 00546 case 'U': 00547 { 00548 is_plane==true?is_plane=false:is_plane=true; 00549 is_plane_cleared=false; 00550 update_plane(2); 00551 if(is_plane==false) 00552 { 00553 update_plane(180); 00554 update_plane_density(); 00555 } 00556 } 00557 break; 00558 00559 case 'T': //throw ball 00560 { 00561 is_throw_ball=!is_throw_ball; 00562 00563 } 00564 break; 00565 00566 case 'E': //save 00567 export_scene(counter_global++); 00568 } 00569 00570 00571 00572 glutPostRedisplay (); 00573 }


| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 96 of file main.cpp.
References mesh_conv::MC_particle_engine::add(), dim_grid_3d, init_parameters(), is_collision_detection, is_potential, isovalue, N_smooth, mesh_conv::MC_navigator_tool::read_cam1_file(), setup_opengl(), sphere_radius, thrower_time, mesh_conv::MC_navigator_tool::x_screen_size_1, and mesh_conv::MC_navigator_tool::y_screen_size_1.
00097 { 00098 cout<<"**hello**\n"<<endl; 00099 std::cout<<"run "<<argv[0]<<" with "<<argc-1<<" parameters ... \n"<<std::endl; 00100 00101 00102 //load camera & light 00103 std::string file_cam("saved_position/saved_camera.dat"); 00104 navigator.read_cam1_file(file_cam); 00105 00106 00107 //*************// 00108 //set parameters 00109 //*************// 00110 00111 //size of the 3D grid of the potential 00112 dim_grid_3d=20; 00113 //frequency of the creation of new sphere 00114 thrower_time=90; 00115 //radius of the spheres 00116 sphere_radius=0.03; 00117 //isovalue 00118 isovalue=2; 00119 //smooth the isosurface N times 00120 N_smooth=2; 00121 //does the sphere collide 00122 is_collision_detection=true; 00123 //does the potential interaction force computed 00124 is_potential=false; 00125 00126 00127 00128 //init two spheres 00129 // engine.add(MC_sphere_physic(MC_v3d(0.5,0.2,0.5),sphere_radius,MC_v3d(0,0.1,1))); 00130 // engine.add(MC_sphere_physic(MC_v3d(0.5,0.8,0.5),sphere_radius,MC_v3d(0,-0.1,1))); 00131 engine.add(MC_sphere_physic(MC_v3d(0.5,0.2,0.5),sphere_radius,MC_v3d(0,1,1))); 00132 engine.add(MC_sphere_physic(MC_v3d(0.5,0.8,0.5),sphere_radius,MC_v3d(0,-1,1))); 00133 00134 00135 //*************// 00136 //start OpenGL 00137 //*************// 00138 navigator.x_screen_size_1=800; 00139 navigator.y_screen_size_1=800; 00140 setup_opengl(argc,argv); 00141 00142 00143 00144 //*************// 00145 //load models 00146 //*************// 00147 init_parameters(); 00148 00149 //*************// 00150 //run 00151 //*************// 00152 std::cout<<"**RUN**\n"<<std::endl; 00153 std::cout<<"Navigation with keys:\n"<<std::endl; 00154 std::cout<<"=========================="<<std::endl; 00155 std::cout<<"Space Displacement"<<std::endl; 00156 std::cout<<"=========================="<<std::endl; 00157 std::cout<<" z r"<<std::endl; 00158 std::cout<<"q s d f\n"<<std::endl; 00159 std::cout<<"left mouse: rotate "<<std::endl; 00160 std::cout<<"right mouse: scale "<<std::endl; 00161 std::cout<<"shift+left mouse: translate in-plane "<<std::endl; 00162 std::cout<<"shift+right mouse: translate out-of-plane "<<std::endl<<std::endl; 00163 std::cout<<"=========================="<<std::endl; 00164 std::cout<<"View:"<<std::endl; 00165 std::cout<<"=========================="<<std::endl; 00166 std::cout<<"W: wireframe mode"<<std::endl; 00167 std::cout<<"F: filled mode"<<std::endl; 00168 std::cout<<"G: Grid mode"<<std::endl; 00169 std::cout<<"X: Print cursor coordinates"<<std::endl; 00170 std::cout<<"S: Draw spheres"<<std::endl; 00171 std::cout<<"V: Draw forces"<<std::endl; 00172 std::cout<<"Q: exit"<<std::endl<<std::endl; 00173 std::cout<<"=========================="<<std::endl; 00174 std::cout<<"Run:"<<std::endl; 00175 std::cout<<"=========================="<<std::endl; 00176 std::cout<<"R: Start/Stop simulation"<<std::endl; 00177 std::cout<<"T: Start/Stop add spheres"<<std::endl; 00178 std::cout<<"I: Compute isosurface"<<std::endl; 00179 std::cout<<"U: Create plane (+shift mouse left/shift mouse right)"<<std::endl; 00180 std::cout<<"==========================\n"<<std::endl; 00181 glutMainLoop (); 00182 00183 00184 return 0; 00185 }

| static void motion_callback | ( | int | x, | |
| int | y | |||
| ) | [static] |
Definition at line 589 of file main.cpp.
References mesh_conv::MC_trackball::apply_rotation(), mesh_conv::MC_quaternion::conjugated(), mesh_conv::MC_navigator_tool::dist_cam1, is_plane, is_shift_on, mesh_conv::MC_navigator_tool::left_button, plane_L, plane_Lz, mesh_conv::MC_trackball::quaternion(), mesh_conv::MC_navigator_tool::right_button, mesh_conv::MC_trackball::set_2d_coords(), mesh_conv::MC_navigator_tool::tr_cam1, mesh_conv::MC_navigator_tool::trackball_cam1, update_plane(), mesh_conv::MC_navigator_tool::x_previous, mesh_conv::MC_navigator_tool::x_screen_size_1, mesh_conv::MC_navigator_tool::y_previous, and mesh_conv::MC_navigator_tool::y_screen_size_1.
Referenced by setup_opengl().
00590 { 00591 double x_old=navigator.x_previous,y_old=navigator.y_previous; 00592 double w=navigator.x_screen_size_1,h=navigator.y_screen_size_1; 00593 00594 00595 00596 if ( is_shift_on==false && (navigator.left_button) ) 00597 { 00598 //trackball 00599 double epsilon=1e-6; 00600 double x0=(2.0*x_old-w)/w,y0=(2.0*y_old-h)/h,x1=(2*x-w)/w,y1=(2*y-h)/h; 00601 if(std::sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1))>epsilon) 00602 { 00603 navigator.trackball_cam1.set_2d_coords((2.0*x_old-w)/w,(2.0*y_old-h)/h,(2*x-w)/w,(2*y-h)/h); 00604 navigator.trackball_cam1.apply_rotation(); 00605 } 00606 navigator.x_previous=int(x);navigator.y_previous=int(y); 00607 00608 } 00609 else if ( is_shift_on==false && (navigator.right_button)) 00610 { 00611 double u = y-y_old; 00612 double fu = u/500.0; //factor of magnification 00613 00614 navigator.dist_cam1 += (fabs(navigator.dist_cam1)+1)*fu; navigator.dist_cam1 = min(navigator.dist_cam1,0.0); 00615 navigator.y_previous=int(y); 00616 00617 } 00618 if(is_plane==false && is_shift_on==true && (navigator.left_button) ) 00619 { 00620 //PAN 00621 double dL=0.0001*(1+100*abs(navigator.dist_cam1));//move camera 00622 00623 MC_v3d tr=MC_v3d(x-x_old,y-y_old,0.0); 00624 navigator.tr_cam1 += dL*navigator.trackball_cam1.quaternion().conjugated()*tr; 00625 navigator.x_previous=int(x);navigator.y_previous=int(y); 00626 } 00627 else if( is_plane==false && is_shift_on && (navigator.right_button) ) 00628 { 00629 00630 //PAN 00631 double dL=0.0002*(1+100*abs(navigator.dist_cam1));//move camera 00632 00633 MC_v3d tr=MC_v3d(0,0,y-y_old); 00634 navigator.tr_cam1 += dL*navigator.trackball_cam1.quaternion().conjugated()*tr; 00635 navigator.x_previous=int(x);navigator.y_previous=int(y); 00636 } 00637 00638 00639 if(is_plane==true && is_shift_on && navigator.left_button ) 00640 { 00641 plane_Lz += 0.01*static_cast<double>(y-y_old); 00642 navigator.x_previous=int(x);navigator.y_previous=int(y); 00643 update_plane(2); 00644 } 00645 else if(is_plane==true && is_shift_on && navigator.right_button ) 00646 { 00647 double d1=x-x_old; 00648 double d2=y-y_old; 00649 double d; 00650 00651 plane_L += 0.01*(d1+d2); 00652 navigator.x_previous=int(x);navigator.y_previous=int(y); 00653 update_plane(2); 00654 } 00655 00656 glutPostRedisplay (); 00657 }


| static void mouse_callback | ( | int | button, | |
| int | action, | |||
| int | x, | |||
| int | y | |||
| ) | [static] |
Definition at line 658 of file main.cpp.
References is_shift_on, mesh_conv::MC_navigator_tool::left_button, mesh_conv::MC_navigator_tool::right_button, mesh_conv::MC_navigator_tool::x_previous, and mesh_conv::MC_navigator_tool::y_previous.
Referenced by setup_opengl().
00659 { 00660 navigator.x_previous=x; 00661 navigator.y_previous=y; 00662 00663 int mod = glutGetModifiers(); 00664 if((mod&GLUT_ACTIVE_SHIFT)!=0) 00665 { 00666 is_shift_on=true; 00667 } 00668 else 00669 is_shift_on=false; 00670 00671 if (button == GLUT_LEFT_BUTTON && action == GLUT_DOWN) { 00672 navigator.left_button=true; 00673 } 00674 if (button == GLUT_LEFT_BUTTON && action == GLUT_UP) 00675 navigator.left_button=false; 00676 00677 if (button == GLUT_RIGHT_BUTTON && action == GLUT_DOWN) { 00678 navigator.right_button=true; 00679 } 00680 if (button == GLUT_RIGHT_BUTTON && action == GLUT_UP) 00681 navigator.right_button=false; 00682 00683 glutPostRedisplay (); 00684 }

| void plane_clear | ( | ) |
Definition at line 947 of file main.cpp.
References is_plane_cleared, plane_L, and plane_Lz.
00948 { 00949 plane_L=0.5; 00950 plane_Lz=0.0; 00951 is_plane_cleared=true; 00952 }
| static void reshape_callback | ( | int | width, | |
| int | height | |||
| ) | [static] |
Definition at line 452 of file main.cpp.
References mesh_conv::MC_navigator_tool::x_screen_size_1, and mesh_conv::MC_navigator_tool::y_screen_size_1.
Referenced by setup_opengl().
00453 { 00454 navigator.x_screen_size_1=width;navigator.y_screen_size_1=height; 00455 glViewport(0,0, width, height); 00456 }

| void set_light | ( | ) |
Definition at line 889 of file main.cpp.
References mesh_conv::MC_navigator_tool::axis_cam1(), mesh_conv::MC_navigator_tool::current_cam1(), and mesh_conv::MC_matrix::to_matrix3().
Referenced by draw_scene(), and setup_opengl().
00890 { 00891 MC_v3d_vector axis_cam=navigator.axis_cam1(); 00892 00893 MC_v3d Light_pos=MC_v3d(navigator.current_cam1().to_matrix3().first*(axis_cam[0]))+axis_cam[1]*10;//+eye_n*(+15.0)+eye_up*10.0; 00894 //MC_v3d Light_pos=axis_cam[0]+axis_cam[1]*0.5+axis_cam[2]*0.5; 00895 00896 //light 00897 glEnable(GL_LIGHTING); 00898 glEnable(GL_LIGHT0); 00899 00900 float light_ambient[4]={0.4f,0.4f,0.4f,1.0f}; 00901 float light_diffuse[4]={0.4f,0.4f,0.4f,1.0f}; 00902 float light_specular[4]={1.6f,1.6f,1.6f,1.0f}; 00903 float light_position[4]={Light_pos[0],Light_pos[1],Light_pos[2],1.0}; 00904 00905 float material_ambient [4] = {1.0f,1.0f,1.0f,1.0f}; 00906 float material_diffuse [4] = {1.0f,1.0f,1.0f,1.0f}; 00907 float material_specular [4] = {1.0f,1.0f,1.0f,1.0f}; 00908 float material_exponent [1] = {100.0f}; 00909 00910 00911 00912 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); 00913 glLightfv(GL_LIGHT0, GL_POSITION, light_position); 00914 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 00915 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 00916 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 00917 00918 glEnable(GL_COLOR_MATERIAL); 00919 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_ambient); 00920 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_diffuse); 00921 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular); 00922 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, material_exponent); 00923 }


| int setup_opengl | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 325 of file main.cpp.
References display_callback(), idle_callback(), keyboard_callback(), motion_callback(), mouse_callback(), reshape_callback(), set_light(), mesh_conv::MC_navigator_tool::x_screen_size_1, and mesh_conv::MC_navigator_tool::y_screen_size_1.
Referenced by main().
00326 { 00327 00328 //init window 00329 glutInit (&argc, argv); 00330 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00331 glutInitWindowPosition(0,0); 00332 glutInitWindowSize(navigator.x_screen_size_1,navigator.y_screen_size_1); 00333 glutCreateWindow("win_1"); 00334 00335 00336 //OpenGL set 00337 glClearColor(1.0f,1.0f,1.0f,1.0f); 00338 glPointSize(5); 00339 glLineWidth(2); 00340 00341 glShadeModel(GL_SMOOTH); 00342 glEnable(GL_COLOR_MATERIAL); 00343 //glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); 00344 glEnable(GL_DEPTH_TEST); 00345 glDepthMask(GL_TRUE); 00346 00347 00348 glFrontFace(GL_CCW);//clockwise CW or CCW 00349 glDisable(GL_CULL_FACE); 00350 //glEnable(GL_CULL_FACE); 00351 00352 glDisable(GL_BLEND); 00353 glDisable(GL_TEXTURE_2D); 00354 glDisable(GL_FOG); 00355 00356 glEnable(GL_LIGHTING); 00357 glEnable(GL_LIGHT0); 00358 glFrontFace( GL_CW ) ; 00359 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); 00360 00361 set_light(); 00362 00363 00364 00365 00366 glEnable(GL_NORMALIZE); 00367 00368 00369 00370 00371 00372 glEnable(GL_LINE_SMOOTH); 00373 glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); 00374 00375 //callback 00376 glutDisplayFunc (display_callback); 00377 glutReshapeFunc (reshape_callback); 00378 glutKeyboardFunc(keyboard_callback); 00379 glutTimerFunc(33,idle_callback,1); 00380 glutMotionFunc (motion_callback); 00381 glutMouseFunc (mouse_callback); 00382 00383 return 0; 00384 }


| void update_marching_cube | ( | ) |
Definition at line 208 of file main.cpp.
References isovalue, and mesh_conv::MC_mesh_index_vector_draw::normal_vertex_update().
Referenced by engine_run(), and keyboard_callback().
00209 { 00210 //run the marching cube algorithm 00211 mesh_iso=MC_grid_3d_scalar_marching_cube::marching_cube(potential,isovalue); 00212 00213 //smooth the mesh 00214 //mesh_iso.laplacian_smoothing(0.3,N_smooth,false); 00215 mesh_iso.normal_vertex_update(); 00216 }


| void update_plane | ( | const unsigned int & | N | ) |
Definition at line 930 of file main.cpp.
References mesh_conv::MC_navigator_tool::axis_cam1(), plane_L, plane_Lz, and mesh_conv::MC_navigator_tool::tr_cam1.
Referenced by keyboard_callback(), and motion_callback().
00931 { 00932 //int N=20; 00933 plane_mesh=MC_mesh_index_vector::build_square(N,N); 00934 plane_mesh+=MC_v3d(-0.5,-0.5,0); 00935 00936 MC_v3d_vector axes=navigator.axis_cam1(); 00937 MC_v3d normal=axes[1]; 00938 MC_v3d right=axes[2]; 00939 MC_v3d up=axes[3]; 00940 MC_v3d center=-navigator.tr_cam1; 00941 00942 MC_matrix R1=MC_matrix::rotation_axis_to_axis(MC_v3d(0,0,1),normal); 00943 MC_matrix R2=MC_matrix::rotation_axis_to_axis(R1*MC_v3d(0,1,0),up); 00944 00945 plane_mesh=R2*(R1*plane_L)*plane_mesh+center+plane_Lz*normal; 00946 }


| void update_plane_density | ( | ) |
Definition at line 954 of file main.cpp.
References mesh_conv::MC_mesh_index_vector_draw::color(), isovalue, mesh_conv::MC_mesh_index_vector::point_set(), potential, mesh_conv::MC_v3d_vector::resize(), mesh_conv::MC_v3d_vector::size(), and mesh_conv::MC_mesh_index_vector::vertex_number().
Referenced by keyboard_callback().
00955 { 00956 00957 plane_mesh.color().resize(plane_mesh.point_set().size()); 00958 for(int k=0,N=plane_mesh.vertex_number();k<N;++k) 00959 { 00960 00961 MC_v3d x=plane_mesh.point_set()(k)-MC_v3d(0.0,0.0,0); 00962 00963 double pot=potential(x); 00964 00965 double b=0.0; 00966 double r=0.0; 00967 if(std::fabs(pot-isovalue)/isovalue<0.2) 00968 { 00969 r=0.0; 00970 b=1.0; 00971 } 00972 else 00973 { 00974 double u=std::fabs(pot)/(isovalue); 00975 if(u>1) 00976 u=-log(u)+1; 00977 r=pow(sin(M_PI/2.0*u),2.0); 00978 } 00979 00980 plane_mesh.color()(k)=MC_v3d(r,0,b); 00981 } 00982 }


| void update_potential | ( | ) |
Definition at line 190 of file main.cpp.
References mesh_conv::MC_grid_3d_scalar::add_potential(), mesh_conv::MC_grid_3d_scalar::fill(), and mesh_conv::MC_particle_engine::particle_system().
Referenced by engine_run(), and keyboard_callback().
00191 { 00192 //initial value of the grid initialized at -1 00193 potential.fill(-1.0); 00194 00195 //get every sphere 00196 std::map<unsigned int,MC_sphere_physic> particle=engine.particle_system(); 00197 for(std::map<unsigned int,MC_sphere_physic>::const_iterator it=particle.begin(),it_end=particle.end();it!=it_end;++it) 00198 { 00199 const MC_sphere_physic& s=it->second; 00200 implicit::MC_potential_sphere pot(s); 00201 00202 //add the potential on the sphere 00203 potential.add_potential(pot); 00204 } 00205 }


| unsigned int counter = 0 |
Definition at line 62 of file main.cpp.
Referenced by mesh_conv::MC_mesh_index_vector::average_edge_length(), display_callback(), mesh_conv::MC_matrix::polar_decomposition(), mesh_conv::MC_io_off::read_off(), mesh_conv::MC_polygon::subdivide_barycenter_mid_edge(), and mesh_conv::MC_matrix::transformation().
| unsigned int counter_global = 0 |
Definition at line 59 of file main.cpp.
Referenced by keyboard_callback().
| unsigned int dim_grid_3d = 30 |
Definition at line 76 of file main.cpp.
Referenced by init_parameters(), and main().
| unsigned int engine_timer = 0 |
| GLuint id_draw_sphere = 0 |
Definition at line 61 of file main.cpp.
Referenced by draw_scene(), and init_parameters().
| bool is_collision_detection = true |
Definition at line 56 of file main.cpp.
Referenced by engine_run(), and main().
| bool is_draw_force = false |
Definition at line 51 of file main.cpp.
Referenced by draw_scene(), and keyboard_callback().
| bool is_draw_grid = false |
Definition at line 48 of file main.cpp.
Referenced by draw_scene(), and keyboard_callback().
| bool is_draw_isosurface = false |
Definition at line 52 of file main.cpp.
Referenced by draw_scene(), engine_run(), and keyboard_callback().
| bool is_draw_sphere = true |
Definition at line 49 of file main.cpp.
Referenced by draw_scene(), and keyboard_callback().
| bool is_plane = false |
Definition at line 53 of file main.cpp.
Referenced by draw_scene(), keyboard_callback(), and motion_callback().
| bool is_plane_cleared |
Definition at line 54 of file main.cpp.
Referenced by draw_scene(), keyboard_callback(), and plane_clear().
| bool is_potential = false |
Definition at line 57 of file main.cpp.
Referenced by engine_run(), and main().
| bool is_run = false |
Definition at line 50 of file main.cpp.
Referenced by evolve(), and keyboard_callback().
| bool is_shift_on = false |
Definition at line 47 of file main.cpp.
Referenced by motion_callback(), and mouse_callback().
| bool is_throw_ball = false |
Definition at line 55 of file main.cpp.
Referenced by evolve(), and keyboard_callback().
| double isovalue = 2 |
Definition at line 71 of file main.cpp.
Referenced by main(), update_marching_cube(), and update_plane_density().
| double plane_L = 0.5 |
Definition at line 80 of file main.cpp.
Referenced by motion_callback(), plane_clear(), and update_plane().
| double plane_Lz = 0.0 |
Definition at line 79 of file main.cpp.
Referenced by motion_callback(), plane_clear(), and update_plane().
Definition at line 69 of file main.cpp.
Referenced by mesh_conv::MC_grid_3d_scalar_slicer::slice(), and update_plane_density().
| double sphere_radius = 0.03 |
| unsigned int thrower_time = 90 |
| unsigned int thrower_timer = 0 |
1.6.1