]> Pileus Git - grits/blob - src/gis-tile.h
Add Blue Marble Next Gen plugin and tile rendering code
[grits] / src / gis-tile.h
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GIS_TILE_H__
19 #define __GIS_TILE_H__
20
21 #include <config.h>
22 #include <glib.h>
23
24 typedef struct _GisTile        GisTile;
25
26 #define gis_tile_foreach(tile, child) \
27         for (int _x = 0; _x < G_N_ELEMENTS(tile->children); _x++) \
28         for (int _y = 0; child = tile->children[_x][_y], \
29                 _y < G_N_ELEMENTS(tile->children[_x]); _y++) \
30
31 #define gis_tile_foreach_index(tile, x, y) \
32         for (x = 0; x < G_N_ELEMENTS(tile->children); x++) \
33         for (y = 0; y < G_N_ELEMENTS(tile->children[x]); y++)
34
35 typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data);
36 typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data);
37
38 struct _GisTile {
39         /* Pointer to the tile data */
40         gpointer data;
41
42         /* North,South,East,West limits */
43         struct {
44                 gdouble n,s,e,w;
45         } edge;
46
47         /* Pointers to parent/child nodes */
48         GisTile *parent;
49         GisTile *children[2][2];
50
51         /* Last access time (for garbage collection) */
52         time_t atime;
53 };
54
55 /* Path to string table, keep in sync with tile->children */ 
56 extern gchar *gis_tile_path_table[2][2];
57
58 /* Allocate a new Tile */
59 GisTile *gis_tile_new(GisTile *parent,
60         gdouble n, gdouble s, gdouble e, gdouble w);
61
62 /* Return a string representation of the tile's path */
63 gchar *gis_tile_get_path(GisTile *child);
64
65 /* Update a root tile */
66 /* Based on eye distance (lat,lon,elev) */
67 void gis_tile_update(GisTile *root,
68                 gdouble res, gint width, gint height,
69                 gdouble lat, gdouble lon, gdouble elev,
70                 GisTileLoadFunc load_func, gpointer user_data);
71
72 /* Delete nodes that haven't been accessed since atime */
73 GisTile *gis_tile_gc(GisTile *root, time_t atime,
74                 GisTileFreeFunc free_func, gpointer user_data);
75
76 /* Free a tile and all it's children */
77 void gis_tile_free(GisTile *root,
78                 GisTileFreeFunc free_func, gpointer user_data);
79
80 #endif