From bde76a7f3a02f8ce6b5cad6079430d70cffb971d Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 22 Jun 2008 22:12:11 +0000 Subject: [PATCH] Whooo, radar displays! (but it's really slow ): --- src/aweather.c | 2 +- src/radar.c | 75 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/aweather.c b/src/aweather.c index ebd8ce3..56d9979 100644 --- a/src/aweather.c +++ b/src/aweather.c @@ -69,8 +69,8 @@ int main(int argc, char *argv[]) /* Load plugins */ opengl_init(GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); - cube_init (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); radar_init (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); + cube_init (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); gtk_widget_show_all(window); gtk_main(); diff --git a/src/radar.c b/src/radar.c index f3fcbdb..d31343a 100644 --- a/src/radar.c +++ b/src/radar.c @@ -11,6 +11,9 @@ static GtkWidget *rotate_button; static Radar *radar; +static Sweep *sweep; +static int nred, ngreen, nblue; +static unsigned char red[256], green[256], blue[256]; static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data) { @@ -24,21 +27,59 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data) glShadeModel(GL_FLAT); - glBegin (GL_TRIANGLE_FAN); - glVertex3f(0., 0., 0.); - glVertex3f(0., .5, 0.); - - int angle; - for (angle = 1; angle <= 360; angle++) { - double rad = (angle*M_PI)/180.0; - double x = sin(rad); - double y = cos(rad); - //g_printf("tick.. %d - %5.3f: (%5.2f,%5.2f)\n", angle, rad, x, y); - glColor3f((float)angle/360.0, 0., 0.); - glVertex3f(x/2., y/2., 0.); + glBegin(GL_QUADS); + + int rayi; + for (rayi = 0; rayi < sweep->h.nrays; rayi++) { + Ray *ray = sweep->ray[rayi]; + + /* right and left with respect to north */ + double right = ((ray->h.azimuth + ray->h.beam_width)*M_PI)/180.0; + double left = ((ray->h.azimuth - ray->h.beam_width)*M_PI)/180.0; + + double rx = sin(right), ry = cos(right); + double lx = sin(left), ly = cos(left); + + int nbins = ray->h.nbins; + //int nbins = 20; + int max_dist = nbins * ray->h.gate_size + ray->h.range_bin1; + int bini, dist = ray->h.range_bin1; + for (bini = 0; bini < nbins; bini++, dist += ray->h.gate_size) { + if (ray->range[bini] == BADVAL) continue; + + /* (find middle of bin) / scale for opengl */ + double nd = ((double)dist - ((double)ray->h.gate_size)/2.) / (double)max_dist; + double fd = ((double)dist + ((double)ray->h.gate_size)/2.) / (double)max_dist; + + glColor3ub( + red[(unsigned char)ray->h.f(ray->range[bini])], + green[(unsigned char)ray->h.f(ray->range[bini])], + blue[(unsigned char)ray->h.f(ray->range[bini])] + ); + + glVertex3f(lx*nd, ly*nd, 0.); // near left + glVertex3f(lx*fd, ly*fd, 0.); // far left + glVertex3f(rx*fd, ry*fd, 0.); // far right + glVertex3f(rx*nd, ry*nd, 0.); // near right + + } + + g_print("\n"); } - glEnd (); + glEnd(); + + /* Print the color table */ + glBegin(GL_QUADS); + int i; + for (i = 0; i < nred; i++) { + glColor3ub(red[i], green[i], blue[i]); + glVertex3f(-1., (float)((i ) - nred/2)/(nred/2), 0.); // bot left + glVertex3f(-1., (float)((i+1) - nred/2)/(nred/2), 0.); // top left + glVertex3f(-.9, (float)((i+1) - nred/2)/(nred/2), 0.); // top right + glVertex3f(-.9, (float)((i ) - nred/2)/(nred/2), 0.); // bot right + } + glEnd(); glPopMatrix (); @@ -59,5 +100,11 @@ gboolean radar_init(GtkDrawingArea *drawing, GtkNotebook *config) RSL_read_these_sweeps("0", NULL); radar = RSL_wsr88d_to_radar("/scratch/aweather/src/KABR_20080609_0224", "KABR"); RSL_load_refl_color_table(); - RSL_volume_to_gif(radar->v[DZ_INDEX], "dz_sweep", 400, 400, 200.0); + RSL_get_color_table(RSL_RED_TABLE, red, &nred); + RSL_get_color_table(RSL_GREEN_TABLE, green, &ngreen); + RSL_get_color_table(RSL_BLUE_TABLE, blue, &nblue); + if (radar->h.nvolumes < 1 || radar->v[0]->h.nsweeps < 1) + g_print("No sweeps found\n"); + sweep = radar->v[0]->sweep[0]; + RSL_volume_to_gif(radar->v[DZ_INDEX], "dz_sweep", 1024, 1024, 200.0); } -- 2.43.2