author | Don Pellegrino <don@drexel.edu> | 2009-07-06 21:22:31 (GMT) |
---|---|---|
committer | Don Pellegrino <don@drexel.edu> | 2009-07-06 21:22:31 (GMT) |
commit | f0817d6a70052e49e45661529c7999f25baa528b (patch) (side-by-side diff) | |
tree | 7780c1074ce167f0196715ecb506cdb6fa598e53 | |
parent | ae129719e6ff1cb0691638e9483b4e21a93aa7f5 (diff) | |
download | exp005-f0817d6a70052e49e45661529c7999f25baa528b.zip exp005-f0817d6a70052e49e45661529c7999f25baa528b.tar.gz exp005-f0817d6a70052e49e45661529c7999f25baa528b.tar.bz2 |
Added a density legend to the display. Disabled the depth test so
that the alpha blending and point overlays work as expected for an
orthographic projection.
-rw-r--r-- | r/connect.R | 2 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/controller/exp004reshape.c | 11 | ||||
-rw-r--r-- | src/model/density_legend_geometry.c | 81 | ||||
-rw-r--r-- | src/model/density_legend_geometry.h | 9 | ||||
-rw-r--r-- | src/model/display_list_index.h | 6 | ||||
-rw-r--r-- | src/model/exp004state.h | 14 | ||||
-rw-r--r-- | src/util/check_error.c | 6 | ||||
-rw-r--r-- | src/view/exp004geometry.c | 7 | ||||
-rw-r--r-- | src/view/exp004init.c | 8 | ||||
-rw-r--r-- | src/view/exp004view.c | 4 |
11 files changed, 124 insertions, 27 deletions
diff --git a/r/connect.R b/r/connect.R index b42b8bb..75e84df 100644 --- a/r/connect.R +++ b/r/connect.R @@ -9,6 +9,8 @@ dbGetQuery (conn, "SELECT COUNT(*) FROM vis_collect"); d <- dbReadTable (conn, "vis_collect"); +summary (d); + hist (d$"N_CITES"); dbDisconnect (conn); diff --git a/src/Makefile.am b/src/Makefile.am index abedab7..9fd441c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,6 +12,7 @@ exp004viz_SOURCES = \ controller/set_ortho.c \ db/dbconnect.c \ exp004viz.c \ + model/density_legend_geometry.c \ model/exp004base.c \ model/protein_geometry.c \ model/selection_info_init.c \ @@ -36,7 +37,7 @@ noinst_HEADERS = \ controller/selsave.h \ controller/set_ortho.h \ db/dbconnect.h \ - model/display_list_index.h \ + model/density_legend_geometry.h \ model/exp004base.h \ model/exp004state.h \ model/protein_geometry.h \ diff --git a/src/controller/exp004reshape.c b/src/controller/exp004reshape.c index 82f134d..891de08 100644 --- a/src/controller/exp004reshape.c +++ b/src/controller/exp004reshape.c @@ -1,6 +1,7 @@ #include "exp004reshape.h" #include "set_ortho.h" #include "../view/exp004state0.h" +#include "../model/density_legend_geometry.h" #include <GL/glut.h> #define S exp004state0 @@ -22,13 +23,13 @@ exp004reshape (int w, int h) { S.ortho.min_x = S.ortho_min; S.ortho.max_x = S.ortho_max; - S.ortho.min_y = S.ortho_min * (GLfloat) h / (GLfloat) w; - S.ortho.max_y = S.ortho_max * (GLfloat) h / (GLfloat) w; + S.ortho.min_y = S.ortho_min * (double) h / (double) w; + S.ortho.max_y = S.ortho_max * (double) h / (double) w; } else { - S.ortho.min_x = S.ortho_min * (GLfloat) w / (GLfloat) h; - S.ortho.max_x = S.ortho_max * (GLfloat) w / (GLfloat) h; + S.ortho.min_x = S.ortho_min * (double) w / (double) h; + S.ortho.max_x = S.ortho_max * (double) w / (double) h; S.ortho.min_y = S.ortho_min; S.ortho.max_y = S.ortho_max; } @@ -43,5 +44,7 @@ exp004reshape (int w, int h) S.viewport.w = w; S.viewport.h = h; + density_legend_geometry (); + return; } diff --git a/src/model/density_legend_geometry.c b/src/model/density_legend_geometry.c new file mode 100644 index 0000000..ab3e46c --- a/dev/null +++ b/src/model/density_legend_geometry.c @@ -0,0 +1,81 @@ +#include "density_legend_geometry.h" +#include "../view/exp004state0.h" +#include "../controller/exp004reshape.h" +#include <GL/glut.h> +#include <stdio.h> + +#define S exp004state0 + +void +density_legend_geometry (void) +{ + glNewList (S.list_offset + DENSITY_LEGEND_GEOMETRY, GL_COMPILE); + glPolygonMode (GL_FRONT, GL_FILL); + glColor4f (DEFAULT_COLOR_R, DEFAULT_COLOR_G, DEFAULT_COLOR_B, + DEFAULT_COLOR_A); + + /* + * This value should be a percentage of the world height so that it + * remains a fixed number of pixels tall when the window is resized + * or zoomed. + */ + double legend_height = 0.5; + + /* + * Calculate the bounding box for the legend. + */ + + double a[2]; + double b[2]; + double c[2]; + double d[2]; + + const double *left; + const double *right; + const double *top; + + if (S.zoom.active) + { + left = &S.zoom.coords[0]; + right = &S.zoom.coords[1]; + top = &S.zoom.coords[3]; + } + else + { + left = &S.ortho.min_x; + top = &S.ortho.max_y; + right = &S.ortho.max_x; + } + + a[0] = *left; + a[1] = *top; + b[0] = *right; + b[1] = *top; + c[0] = *right; + c[1] = *top - legend_height; + d[0] = *left; + d[1] = *top - legend_height; + + /* + * Overlay a legend from default saturation / alpha to full saturation. + */ + for (int i = 1; i <= 1 / DEFAULT_COLOR_A; i++) + { + glBegin (GL_QUADS); + glVertex2dv (a); + glVertex2dv (b); + glVertex2dv (c); + glVertex2dv (d); + glEnd (); + + /* + * Step left to right along the x-coordinate. + */ + a[0] = *left + (*right - *left) * (DEFAULT_COLOR_A * i); + d[0] = a[0]; + } + + glEndList (); + + return; +} diff --git a/src/model/density_legend_geometry.h b/src/model/density_legend_geometry.h new file mode 100644 index 0000000..4745ac0 --- a/dev/null +++ b/src/model/density_legend_geometry.h @@ -0,0 +1,9 @@ +#ifndef DENSITY_LEGEND_GEOMETRY_H +#define DENSITY_LEGEND_GEOMETRY_H + +/* + * Define the geometry to redner the density legend. + */ +void density_legend_geometry (void); + +#endif // DENSITY_LEGEND_GEOMETRY_H diff --git a/src/model/display_list_index.h b/src/model/display_list_index.h deleted file mode 100644 index a68f8a7..0000000 --- a/src/model/display_list_index.h +++ b/dev/null @@ -1,6 +0,0 @@ -#ifndef DISPLAY_LIST_INDEX -#define DISPLAY_LIST_INDEX - -#define PROTEIN_GEOMETRY 0 - -#endif // DISPLAY_LIST_INDEX diff --git a/src/model/exp004state.h b/src/model/exp004state.h index 1af8a5b..5a9761a 100644 --- a/src/model/exp004state.h +++ b/src/model/exp004state.h @@ -16,14 +16,16 @@ #define DEFAULT_COLOR_R 0.00 #define DEFAULT_COLOR_G 0.00 #define DEFAULT_COLOR_B 0.01 -#define DEFAULT_COLOR_A 0.25 +#define DEFAULT_COLOR_A (1.0 / 7.0) #define SELECT_COLOR_R 0.00 #define SELECT_COLOR_G 0.00 #define SELECT_COLOR_B 0.00 #define SELECT_COLOR_A 0.75 -typedef enum { PROTEIN_GEOMETRY } LISTS; +typedef enum +{ PROTEIN_GEOMETRY, DENSITY_LEGEND_GEOMETRY } LISTS; +#define NUM_LISTS 2 /* * Maintain state of the model. @@ -61,10 +63,10 @@ typedef struct */ struct { - float min_x; - float max_x; - float min_y; - float max_y; + double min_x; + double max_x; + double min_y; + double max_y; } ortho; /* diff --git a/src/util/check_error.c b/src/util/check_error.c index cd00439..c47ca43 100644 --- a/src/util/check_error.c +++ b/src/util/check_error.c @@ -1,6 +1,7 @@ #include <GL/glut.h> #include <error.h> #include <errno.h> +#include <stdlib.h> #include "sqlinfoprint.h" extern struct sqlca sqlca; @@ -15,14 +16,15 @@ check_error (const char *filename, const unsigned int linenum) if (errCode != GL_NO_ERROR) { const GLubyte *errString = gluErrorString (errCode); - error_at_line (-1, errno, filename, linenum, + error_at_line (EXIT_FAILURE, errno, filename, linenum, "OpenGL Error %s", errString); } /* * Check for an error from the Database API. */ - sqlinfoprint ("DB Error", &sqlca, filename, linenum); + if (sqlinfoprint ("DB Error", &sqlca, filename, linenum) == 1) + exit (EXIT_FAILURE); return; } diff --git a/src/view/exp004geometry.c b/src/view/exp004geometry.c index e7193fd..6f3bc17 100644 --- a/src/view/exp004geometry.c +++ b/src/view/exp004geometry.c @@ -21,13 +21,14 @@ exp004geometry (GLenum mode) { glLoadName (i); glPushMatrix (); - glTranslatef (S.base_vertices_data[i][0], - S.base_vertices_data[i][1], - 0.0); + glTranslatef (S.base_vertices_data[i][0], + S.base_vertices_data[i][1], 0.0); glColor4fv (S.base_colors_data[i]); glCallList (S.list_offset + PROTEIN_GEOMETRY); glPopMatrix (); } + glCallList (S.list_offset + DENSITY_LEGEND_GEOMETRY); + return; } diff --git a/src/view/exp004init.c b/src/view/exp004init.c index e7da51d..ab12d2a 100644 --- a/src/view/exp004init.c +++ b/src/view/exp004init.c @@ -1,5 +1,7 @@ #include "exp004init.h" #include "exp004state0.h" +#include "../model/density_legend_geometry.h" +#include "../model/protein_geometry.h" #include "../model/selection_info_init.h" #include "../model/zoom_info_init.h" #include <GL/glut.h> @@ -12,7 +14,9 @@ exp004init (void) selection_info_init (&S.selection); zoom_info_init (&S.zoom); - S.list_offset = glGenLists (1); - + S.list_offset = glGenLists (NUM_LISTS); + protein_geometry (); + density_legend_geometry (); + return; } diff --git a/src/view/exp004view.c b/src/view/exp004view.c index 68a4e79..33198ad 100644 --- a/src/view/exp004view.c +++ b/src/view/exp004view.c @@ -4,7 +4,6 @@ #include "../controller/keyboard.h" #include "../db/dbconnect.h" #include "../model/exp004base.h" -#include "../model/protein_geometry.h" #include "exp004init.h" #include "exp004state0.h" #include "exp004view.h" @@ -25,7 +24,7 @@ exp004view (void) glClearColor (CLEAR_COLOR); glColor3f (DRAW_COLOR); glEnable (GL_AUTO_NORMAL); - glEnable (GL_DEPTH_TEST); + glDisable (GL_DEPTH_TEST); glEnable (GL_MAP1_VERTEX_3); glShadeModel (GL_SMOOTH); @@ -43,7 +42,6 @@ exp004view (void) // Initialize the model. exp004base (); exp004init (); - protein_geometry (); // Callbacks (Controllers) glutDisplayFunc (exp004display); |