00001 #ifndef GRAPHER_H
00002 #define GRAPHER_H
00003
00004 #include <GL/glew.h>
00005 #include <OpenGL/gl.h>
00006 #include <OpenGL/glu.h>
00007 #include <GLUT/glut.h>
00008
00009 #include <list>
00010 #include <map>
00011
00012 #include "shader_primitive.h"
00013 #include "scalar_field.h"
00014 #include "stopwatch.h"
00015 #include "function.h"
00016 #include "contour.h"
00017 #include "p_curve.h"
00018 #include "screen.h"
00019 #include "vector.h"
00020 #include "color.h"
00021 #include "curve.h"
00022 #include "point.h"
00023 #include "flow.h"
00024
00025 using namespace std;
00026
00027 namespace glot {
00028
00033 enum display_opt { AXES_OFF = 0,
00034 GRID_OFF = 0,
00035 X_LIN = 0,
00036 Y_LIN = 0,
00037 AXES_ON = 1,
00038 GRID_ON = 2,
00039 X_LOG = 4,
00040 Y_LOG = 8 };
00041
00046 enum keyboard_opt { ZOOM_KEYS_OFF = 0,
00047 AXES_KEYS_OFF = 0,
00048 GRID_KEYS_OFF = 0,
00049 QUIT_KEYS_OFF = 0,
00050 ZOOM_KEYS_ON = 1,
00051 AXES_KEYS_ON = 2,
00052 GRID_KEYS_ON = 4,
00053 QUIT_KEYS_ON = 8 };
00054
00064 class grapher {
00065
00066 public:
00067
00075 typedef void (*keyboard_function)(unsigned char key, GLint x, GLint y);
00076
00084 typedef void (*click_function)(GLint button, GLint x, GLint y);
00085
00090 typedef void (*idle_function)(void);
00091
00104 static int initialize(int argc, char ** argv, short int options = AXES_ON | GRID_ON | X_LIN | Y_LIN, short int k_options = ZOOM_KEYS_ON | AXES_KEYS_ON | GRID_KEYS_ON | QUIT_KEYS_ON);
00105
00113 static void run();
00114
00121 static void redraw();
00122
00130 static void add(primitive& p);
00131
00137 static void remove(primitive& p);
00138
00146 static void add(point& p);
00147
00155 static void remove(point& p);
00156
00176 static void set_keyboard_function(keyboard_function k);
00177
00186 static void set_click_function(click_function c);
00187
00196 static void set_idle_function(idle_function i);
00197
00205 static void zoom(double scale);
00206
00214 static double get_x_coord(GLint x);
00215
00223 static double get_y_coord(GLint y);
00224
00229 static point get_point(GLint x, GLint y);
00230
00231 private:
00232
00243 static void refresh();
00244
00255 static double y_coord_transform(double y);
00256
00267 static double x_coord_transform(double x);
00268
00274
00275 static double x_plot_coord(double x);
00276 static double x_screen_coord(double x);
00277 static double y_plot_coord(double y);
00278 static double y_screen_coord(double y);
00279
00280
00286 static GLint axes_dl_gen();
00287
00293 static GLint grid_dl_gen();
00294
00297 static int init_open_gl();
00298
00305 static void display();
00306
00314 static void reshape(int w, int h);
00315
00327 static void keyboard(unsigned char key, int x, int y);
00328
00344 static void mouse(int button, int state, int x, int y);
00345
00346 static void idle();
00347
00358 static void motion(int x, int y);
00359
00366 static void refresh_dls();
00367
00373 static short int display_options;
00374
00381 static short int keyboard_options;
00382
00383 static screen scr;
00384
00386 static GLint axes_dl;
00388 static GLint grid_dl;
00389
00391 static int startx;
00392 static int starty;
00393
00395 static keyboard_function user_keyboard_function;
00396
00398 static click_function user_click_function;
00399
00400 static idle_function user_idle_function;
00401
00403 static map<primitive*, GLint> primitives;
00404
00406 static list<point*> points;
00407
00408 static stopwatch timer;
00409 static stopwatch wall;
00410
00411 static int framecount;
00412
00413 };
00414
00415 }
00416
00417 #endif