include/gui.h

00001 #include <assert.h>
00002 #include <math.h>
00003 #include <signal.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include <getopt.h>
00008 #include <unistd.h>
00009 #include <sys/time.h>
00010 // GUI settings
00011 static int win,height,width;
00012 static int gui_pause = 0;
00013 static int viewport_width = 0;
00014 static int viewport_height = 0;
00015 static int show_samples = 1;
00016 static double res,offsetx,offsety,mouse_offsetx,mouse_offsety;
00017 // Mapping phases
00018 
00019 // Local functions
00020 static void process();
00021 
00022 // Key callback
00023 void win_key(unsigned char key, int x, int y)
00024 {
00025   // Show the samples
00026   if (key == 'T' || key == 't')
00027   {
00028     show_samples = !show_samples;
00029     glutPostRedisplay();
00030   }
00031 
00032   // Pause
00033   else if (key == ' ')
00034   {
00035     if (!gui_pause)
00036       fprintf(stderr, "paused\n");
00037     else
00038       fprintf(stderr, "running\n");
00039     gui_pause = !gui_pause;
00040   }
00041 
00042   // Save the current map
00043   else if (key == 'W' || key == 'w')
00044   {
00045     //save();
00046   }
00047   
00048   return;
00049 }
00050 
00051 
00052 
00053 // Mouse callback
00054 void win_mouse(int button, int state, int x, int y)
00055 {
00056   if (state == GLUT_DOWN)
00057   {
00058     mouse_offsetx = 2 * x * res;
00059     mouse_offsety = 2 * y * res;      
00060   }
00061   else if (state == GLUT_UP)
00062   {
00063     offsetx += 2 * x * res - mouse_offsetx;
00064     offsety -= 2 * y * res - mouse_offsety;
00065     glutPostRedisplay();
00066   }
00067 
00068   return;
00069 }
00070 // Handle window reshape events
00071 void win_reshape(int width, int height)
00072 {
00073   glViewport(0, 0, width, height);
00074   viewport_width = width;
00075   viewport_height = height;
00076   return;
00077 }
00078 // Redraw the window
00079 void win_redraw()
00080 {
00081   double left, right, top, bot;
00082   glClearColor(0.7, 0.7, 0.7, 1);
00083   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00084 
00085   left  = -res * width;
00086   right = +res * width;
00087   top   = -res * height;
00088   bot   = +res * height;
00089 
00090   glMatrixMode(GL_PROJECTION);
00091   glLoadIdentity();
00092   glOrtho(left, right, top, bot, -1, +10);
00093 
00094   glMatrixMode(GL_MODELVIEW);
00095   glLoadIdentity();
00096   glTranslatef(offsetx,offsety, 0.0);
00097 
00098   // Draw the grid map
00099   // pmap_draw_map(pmap, opt_scale);
00100 
00101   // Draw the origin marker
00102   glColor3f(0, 0, 0);
00103   glBegin(GL_LINE_LOOP);
00104   glVertex3f(-1, -1, 0);
00105   glVertex3f(+1, -1, 0);
00106   glVertex3f(+1, +1, 0);
00107   glVertex3f(-1, +1, 0);
00108   glEnd();
00109   // draw the map
00110   glutSwapBuffers();
00111   return;
00112 }
00113 
00114 
00115 // Idle callback
00116 void win_idle()
00117 {
00118   if (!gui_pause)
00119   {
00120     process();
00121     glutPostRedisplay();
00122   }
00123   else
00124     usleep(100000);
00125   return;
00126 }
00127 // Trap SIGINTS
00128 void signal_handle(int arg)
00129 {
00130   // Save current state
00131 
00132   // Move on to fine phase or exit
00133   
00134   return;
00135 };
00136 // Run the GUI
00137 int win_run(int w, int h , double resolution)
00138 {
00139   width = w;
00140   height = h;
00141   res = resolution;
00142   // Register signal handlers
00143   assert(signal(SIGINT, signal_handle) != SIG_ERR);
00144   int argc;
00145   char **argv;
00146   printf("\n AM HERE 1"); fflush(stdout);
00147   glutInit(&argc, argv);
00148   printf("\n AM HERE 2"); fflush(stdout);
00149   // Create a window
00150   glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
00151   glutInitWindowSize( w + 16, h + 16);
00152   win = glutCreateWindow("Map Building Viewer");
00153   glutReshapeFunc(win_reshape);
00154   glutDisplayFunc(win_redraw);
00155   glutKeyboardFunc(win_key);
00156   glutMouseFunc(win_mouse);
00157   // Idle loop callback
00158   glutIdleFunc(win_idle);
00159   glutMainLoop();
00160   return 0;
00161 }
00162 // Do some appropriate form of processing
00163 void process()
00164 {
00165   cout<<"\nUpdating";
00166   return;
00167 }
00168 
00169 

Generated on Tue Aug 1 16:54:04 2006 for MapReferenceICP by  doxygen 1.4.6