]> Pileus Git - grits/blobdiff - src/plugin-radar.c
adding some RSL patches, and support for velocity/spectum width color maps
[grits] / src / plugin-radar.c
index 1fe30f6bcc936a96613dfbb088f2a80d029d4af6..269383302db2bd1e38ae1b92a2b254f26ab28a45 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <config.h>
 #include <gtk/gtk.h>
 #include <gtk/gtkgl.h>
@@ -70,6 +87,21 @@ static void bscan_sweep(Sweep *sweep, guint8 **data, int *width, int *height)
        *data   = buf;
 }
 
+static void load_color_table(char *table)
+{
+       /* TODO: replace this with a better color table */
+       g_message("loading color table");
+       if (g_str_equal(table, "Velocity"))
+               RSL_load_vel_color_table();
+       else if (g_str_equal(table, "Spectrum width"))
+               RSL_load_sw_color_table();
+       else
+               RSL_load_refl_color_table();
+       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);
+}
+
 /* Load a sweep as the active texture */
 static void load_sweep(Sweep *sweep)
 {
@@ -112,6 +144,7 @@ static void load_radar_gui(Radar *radar)
                        char *label = g_strdup_printf("Tilt: %.2f (%s)", sweep->h.elev, vol->h.type_str);
                        button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button), label);
                        g_object_set(button, "draw-indicator", FALSE, NULL);
+                       g_signal_connect_swapped(button, "clicked", G_CALLBACK(load_color_table), vol->h.type_str);
                        g_signal_connect_swapped(button, "clicked", G_CALLBACK(load_sweep), sweep);
                        gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, TRUE, 0);
                        g_free(label);
@@ -140,13 +173,6 @@ static void load_radar_rsl(GPid pid, gint status, gpointer _path)
                return;
        }
 
-       /* TODO: replace this with a better color table */
-       g_message("loading color table");
-       RSL_load_refl_color_table();
-       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);
-
        /* Load the first sweep by default */
        if (radar->h.nvolumes < 1 || radar->v[0]->h.nsweeps < 1) {
                g_warning("No sweeps found\n");
@@ -156,6 +182,7 @@ static void load_radar_rsl(GPid pid, gint status, gpointer _path)
                        if (radar->v[vi]== NULL) continue;
                        for (int si = 0; si < radar->v[vi]->h.nsweeps; si++) {
                                if (radar->v[vi]->sweep[si]== NULL) continue;
+                               load_color_table(radar->v[vi]->h.type_str);
                                load_sweep(radar->v[vi]->sweep[si]);
                                break;
                        }
@@ -173,14 +200,16 @@ static void load_radar(char *path, gpointer user_data)
        if (g_file_test(raw, G_FILE_TEST_EXISTS)) {
                load_radar_rsl(0, 0, raw);
        } else {
-               char *argv[] = {"./wsr88ddec", path, raw, NULL};
+               char *argv[] = {"wsr88ddec", path, raw, NULL};
                GPid pid;
                GError *error = NULL;
                g_spawn_async(
                        NULL,    // const gchar *working_directory,
                        argv,    // gchar **argv,
                        NULL,    // gchar **envp,
-                       G_SPAWN_DO_NOT_REAP_CHILD, // GSpawnFlags flags,
+                       G_SPAWN_SEARCH_PATH|
+                       G_SPAWN_DO_NOT_REAP_CHILD, 
+                                // GSpawnFlags flags,
                        NULL,    // GSpawnChildSetupFunc child_setup,
                        NULL,    // gpointer user_data,
                        &pid,    // GPid *child_pid,
@@ -207,6 +236,7 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
        glPushMatrix();
        glBindTexture(GL_TEXTURE_2D, sweep_tex);
        glEnable(GL_TEXTURE_2D);
+       glDisable(GL_ALPHA_TEST);
        glColor4f(1,1,1,1);
        glBegin(GL_QUAD_STRIP);
        for (int ri = 0; ri <= sweep->h.nrays+1; ri++) {
@@ -246,6 +276,7 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
 
        /* Print the color table */
        glDisable(GL_TEXTURE_2D);
+       glDisable(GL_DEPTH_TEST);
        glMatrixMode(GL_MODELVIEW ); glPushMatrix(); glLoadIdentity();
        glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
        glBegin(GL_QUADS);
@@ -258,6 +289,8 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
                glVertex3f(-0.9, (float)((i  ) - nred/2)/(nred/2), 0.0); // bot right
        }
        glEnd();
+       glEnable(GL_DEPTH_TEST);
+       glEnable(GL_ALPHA_TEST);
         glMatrixMode(GL_PROJECTION); glPopMatrix(); 
        glMatrixMode(GL_MODELVIEW ); glPopMatrix();
        return FALSE;