]> Pileus Git - grits/blobdiff - src/plugins/srtm.c
Update copyright and email address
[grits] / src / plugins / srtm.c
index ad3eff30e930c225105ef21757d96a25c437a4a5..f127af7a4b2a0cbc8a475cb88ce193c86aae8a0b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
  *
  * 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
@@ -65,6 +65,10 @@ static gdouble _height_func(gdouble lat, gdouble lon, gpointer _self)
        guint x_flr = (int)x;
        guint y_flr = (int)y;
 
+       //if (lon == 180 || lon == -180)
+       //      g_message("lon=%f w=%d min=%f max=%f dist=%f x=%f rem=%f flr=%d",
+       //                 lon,   w,  xmin,  xmax,  xdist,   x, x_rem, x_flr);
+
        /* TODO: Fix interpolation at edges:
         *   - Pad these at the edges instead of wrapping/truncating
         *   - Figure out which pixels to index (is 0,0 edge, center, etc) */
@@ -88,6 +92,7 @@ static gdouble _height_func(gdouble lat, gdouble lon, gpointer _self)
 #define LOAD_OPENGL FALSE
 struct _LoadTileData {
        GisPluginSrtm    *self;
+       gchar            *path;
        GisTile          *tile;
        GdkPixbuf        *pixbuf;
        struct _TileData *data;
@@ -141,8 +146,8 @@ static guint _load_opengl(GdkPixbuf *pixbuf)
                        (alpha ? GL_RGBA : GL_RGB), GL_UNSIGNED_BYTE, pixels);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-       //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
-       //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
 
        g_debug("GisPluginSrtm: load_opengl %d", opengl);
        return opengl;
@@ -150,19 +155,23 @@ static guint _load_opengl(GdkPixbuf *pixbuf)
 static gboolean _load_tile_cb(gpointer _load)
 {
        struct _LoadTileData *load = _load;
+       g_debug("GisPluginSrtm: _load_tile_cb: %s", load->path);
        GisPluginSrtm    *self   = load->self;
        GisTile          *tile   = load->tile;
        GdkPixbuf        *pixbuf = load->pixbuf;
        struct _TileData *data   = load->data;
+       g_free(load->path);
        g_free(load);
 
        if (LOAD_OPENGL)
                data->opengl = _load_opengl(pixbuf);
 
+       tile->data = data;
+
        /* Do necessasairy processing */
        /* TODO: Lock this and move to thread, can remove self from _load then */
        if (LOAD_BIL)
-               gis_opengl_set_height_func(self->opengl, tile, _height_func, self, TRUE);
+               gis_viewer_set_height_func(self->viewer, tile, _height_func, self, TRUE);
 
        /* Cleanup unneeded things */
        if (!LOAD_BIL)
@@ -170,26 +179,24 @@ static gboolean _load_tile_cb(gpointer _load)
        if (LOAD_OPENGL)
                g_object_unref(pixbuf);
 
-       tile->data = data;
        return FALSE;
 }
 static void _load_tile(GisTile *tile, gpointer _self)
 {
        GisPluginSrtm *self = _self;
 
-       g_debug("GisPluginSrtm: _load_tile");
-       gchar *path = gis_wms_make_local(self->wms, tile);
        struct _LoadTileData *load = g_new0(struct _LoadTileData, 1);
+       load->path = gis_wms_make_local(self->wms, tile);
+       g_debug("GisPluginSrtm: _load_tile: %s", load->path);
        load->self = self;
        load->tile = tile;
        load->data = g_new0(struct _TileData, 1);
        if (LOAD_BIL || LOAD_OPENGL)
-               load->data->bil = _load_bil(path);
+               load->data->bil = _load_bil(load->path);
        if (LOAD_OPENGL)
                load->pixbuf = _load_pixbuf(load->data->bil);
 
        g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, load, NULL);
-       g_free(path);
 }
 
 static gboolean _free_tile_cb(gpointer _data)
@@ -205,7 +212,7 @@ static gboolean _free_tile_cb(gpointer _data)
 static void _free_tile(GisTile *tile, gpointer _self)
 {
        GisPluginSrtm *self = _self;
-       g_debug("GisPluginSrtm: _free_tile: %p=%d", tile->data, *(guint*)tile->data);
+       g_debug("GisPluginSrtm: _free_tile: %p", tile->data);
        g_idle_add_full(G_PRIORITY_LOW, _free_tile_cb, tile->data, NULL);
 }
 
@@ -214,7 +221,7 @@ static gpointer _update_tiles(gpointer _self)
        GisPluginSrtm *self = _self;
        g_mutex_lock(self->mutex);
        gdouble lat, lon, elev;
-       gis_view_get_location(self->view, &lat, &lon, &elev);
+       gis_viewer_get_location(self->viewer, &lat, &lon, &elev);
        gis_tile_update(self->tiles,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
                        lat, lon, elev,
@@ -228,40 +235,44 @@ static gpointer _update_tiles(gpointer _self)
 /*************
  * Callbacks *
  *************/
-static void _on_location_changed(GisView *view, gdouble lat, gdouble lon, gdouble elev,
-               GisPluginSrtm *self)
+static void _on_location_changed(GisViewer *viewer,
+               gdouble lat, gdouble lon, gdouble elev, GisPluginSrtm *self)
 {
        g_thread_create(_update_tiles, self, FALSE, NULL);
 }
 
+static gpointer _expose(GisCallback *callback, gpointer _self)
+{
+       GisPluginSrtm *self = GIS_PLUGIN_SRTM(_self);
+       g_debug("GisPluginSrtm: expose tiles=%p data=%p",
+               self->tiles, self->tiles->data);
+       if (LOAD_OPENGL)
+               gis_viewer_render_tiles(self->viewer, self->tiles);
+       return NULL;
+}
+
 /***********
  * Methods *
  ***********/
-GisPluginSrtm *gis_plugin_srtm_new(GisWorld *world, GisView *view, GisOpenGL *opengl)
+GisPluginSrtm *gis_plugin_srtm_new(GisViewer *viewer)
 {
        g_debug("GisPluginSrtm: new");
        GisPluginSrtm *self = g_object_new(GIS_TYPE_PLUGIN_SRTM, NULL);
-       self->view   = view;
-       self->opengl = opengl;
+       self->viewer = g_object_ref(viewer);
 
        /* Load initial tiles */
        _load_tile(self->tiles, self);
        g_thread_create(_update_tiles, self, FALSE, NULL);
 
        /* Connect signals */
-       self->sigid = g_signal_connect(self->view, "location-changed",
+       self->sigid = g_signal_connect(self->viewer, "location-changed",
                        G_CALLBACK(_on_location_changed), self);
 
-       return self;
-}
+       /* Add renderers */
+       GisCallback *callback = gis_callback_new(_expose, self);
+       gis_viewer_add(viewer, GIS_OBJECT(callback), GIS_LEVEL_WORLD, 0);
 
-static void gis_plugin_srtm_expose(GisPlugin *_self)
-{
-       GisPluginSrtm *self = GIS_PLUGIN_SRTM(_self);
-       g_debug("GisPluginSrtm: expose tiles=%p data=%p",
-               self->tiles, self->tiles->data);
-       if (LOAD_OPENGL)
-               gis_opengl_render_tiles(self->opengl, self->tiles);
+       return self;
 }
 
 
@@ -277,7 +288,6 @@ static void gis_plugin_srtm_plugin_init(GisPluginInterface *iface)
 {
        g_debug("GisPluginSrtm: plugin_init");
        /* Add methods to the interface */
-       iface->expose = gis_plugin_srtm_expose;
 }
 /* Class/Object init */
 static void gis_plugin_srtm_init(GisPluginSrtm *self)
@@ -295,9 +305,13 @@ static void gis_plugin_srtm_dispose(GObject *gobject)
        g_debug("GisPluginSrtm: dispose");
        GisPluginSrtm *self = GIS_PLUGIN_SRTM(gobject);
        /* Drop references */
-       g_signal_handler_disconnect(self->view, self->sigid);
        if (LOAD_BIL)
-               gis_opengl_clear_height_func(self->opengl);
+               gis_viewer_clear_height_func(self->viewer);
+       if (self->viewer) {
+               g_signal_handler_disconnect(self->viewer, self->sigid);
+               g_object_unref(self->viewer);
+               self->viewer = NULL;
+       }
        G_OBJECT_CLASS(gis_plugin_srtm_parent_class)->dispose(gobject);
 }
 static void gis_plugin_srtm_finalize(GObject *gobject)