From: Andy Spencer Date: Wed, 10 Feb 2010 12:27:19 +0000 (+0000) Subject: Fix up primitive datatypes X-Git-Tag: v0.4~38 X-Git-Url: http://pileus.org/git/?p=grits;a=commitdiff_plain;h=5350256efff1c97426e0db60e404bfd8a6cb08be Fix up primitive datatypes - Move GisPoint to gis-util.[ch] - Add a GisBBox for n,s,e,w coords --- diff --git a/src/gis-util.c b/src/gis-util.c index 587dd5c..951b452 100644 --- a/src/gis-util.c +++ b/src/gis-util.c @@ -73,6 +73,48 @@ #include "gis-util.h" +/************ + * GisPoint * + ************/ +/** + * gis_point_set_lle: + * @point: the point to modify + * @lat: the new latitude + * @lon: the new longitude + * @elev: the new elevation + * + * Set the latitude, longitude, and elevation for a point. + */ +void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev) +{ + point->lat = lat; + point->lon = lon; + point->elev = elev; +} + + +/*********** + * GisBBox * + ***********/ +/** + * gis_bbox_set_bounds: + * @n: the north edge + * @s: the south edge + * @e: the east edge + * @w: the west edge + * + * Set the north, south, east, and west edges of the bounding box + */ +void gis_bbox_set_bounds(GisBBox *bbox, + gdouble n, gdouble s, gdouble e, gdouble w) +{ + bbox->n = n; + bbox->s = s; + bbox->e = e; + bbox->w = w; +} + + /****************** * Global helpers * ******************/ diff --git a/src/gis-util.h b/src/gis-util.h index c783896..1b03f2f 100644 --- a/src/gis-util.h +++ b/src/gis-util.h @@ -146,6 +146,29 @@ #define rad2deg(rad) (((rad)*180.0)/G_PI) +/************* + * Datatypes * + *************/ + +/* GisPoint */ +typedef struct _GisPoint GisPoint; +struct _GisPoint { + gdouble lat, lon, elev; +}; + +void gis_point_set_lle(GisPoint *point, + gdouble lat, gdouble lon, gdouble elev); + +/* GisBBox */ +typedef struct _GisBBox GisBBox; +struct _GisBBox { + gdouble n, s, e, w; +}; + +void gis_bbox_set_bounds(GisBBox *bbox, + gdouble n, gdouble s, gdouble e, gdouble w); + + /******** * Misc * ********/ diff --git a/src/objects/gis-object.c b/src/objects/gis-object.c index 84e5c47..9eff935 100644 --- a/src/objects/gis-object.c +++ b/src/objects/gis-object.c @@ -17,7 +17,7 @@ /** * SECTION:gis-object - * @short_description: Base classes for drawing operations + * @short_description: Base class for drawing operations * * Objects in libgis are things which can be added to the viewer and will be * displayed to the user. Each object has information such as it's location and @@ -31,48 +31,6 @@ #include #include "gis-object.h" -/************ - * GisPoint * - ************/ -/** - * gis_point_new: - * - * Create a new #GisPoint - * - * Returns: the new point - */ -GisPoint *gis_point_new() -{ - return g_new0(GisPoint, 1); -} - -/** - * gis_point_set_lle: - * @point: the point to modify - * @lat: the new latitude - * @lon: the new longitude - * @elev: the new elevation - * - * Set the latitude, longitude, and elevation for a point. - */ -void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev) -{ - point->lat = lat; - point->lon = lon; - point->elev = elev; -} - -/** - * gis_point_free: - * @point: The point to free - * - * Free data used by a #GisPoint - */ -void gis_point_free(GisPoint *point) -{ - g_free(point); -} - /************* * GisObject * diff --git a/src/objects/gis-object.h b/src/objects/gis-object.h index 4f105d8..1777fce 100644 --- a/src/objects/gis-object.h +++ b/src/objects/gis-object.h @@ -20,18 +20,7 @@ #include #include - -/* GisPoint */ -typedef struct _GisPoint GisPoint; - -struct _GisPoint { - gdouble lat, lon, elev; -}; - -GisPoint *gis_point_new(); -void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev); -void gis_point_free(GisPoint *point); - +#include "gis-util.h" /* GisObject */ #define GIS_TYPE_OBJECT (gis_object_get_type()) diff --git a/src/objects/gis-tile.c b/src/objects/gis-tile.c index 9a2a298..24214ad 100644 --- a/src/objects/gis-tile.c +++ b/src/objects/gis-tile.c @@ -33,7 +33,6 @@ */ #include -#include "gis-util.h" #include "gis-tile.h" gchar *gis_tile_path_table[2][2] = { @@ -58,11 +57,8 @@ GisTile *gis_tile_new(GisTile *parent, { GisTile *tile = g_object_new(GIS_TYPE_TILE, NULL); tile->parent = parent; - tile->edge.n = n; - tile->edge.s = s; - tile->edge.e = e; - tile->edge.w = w; tile->atime = time(NULL); + gis_bbox_set_bounds(&tile->edge, n, s, e, w); return tile; } @@ -93,38 +89,35 @@ gchar *gis_tile_get_path(GisTile *child) return g_string_free(path, FALSE); } -static gdouble _gis_tile_get_min_dist( - gdouble lat, gdouble lon, gdouble elev, - gdouble n, gdouble s, gdouble e, gdouble w) +static gdouble _gis_tile_get_min_dist(GisPoint *eye, GisBBox *bounds) { - gdouble tlat = lat > n ? n : - lat < s ? s : lat; - gdouble tlon = lon > e ? e : - lon < w ? w : lon; - gdouble telev = 0; // TODO: elevation at rlat,rlon - //if (lat == tlat && lon == tlon) + GisPoint pos = {}; + pos.lat = eye->lat > bounds->n ? bounds->n : + eye->lat < bounds->s ? bounds->s : eye->lat; + pos.lon = eye->lon > bounds->e ? bounds->e : + eye->lon < bounds->w ? bounds->w : eye->lon; + //if (eye->lat == pos.lat && eye->lon == pos.lon) // return elev; /* Shortcut? */ gdouble a[3], b[3]; - lle2xyz( lat, lon, elev, a+0, a+1, a+2); - lle2xyz(tlat, tlon, telev, b+0, b+1, b+2); + lle2xyz(eye->lat, eye->lon, eye->elev, a+0, a+1, a+2); + lle2xyz(pos.lat, pos.lon, pos.elev, b+0, b+1, b+2); return distd(a, b); } -static gboolean _gis_tile_precise( - gdouble lat, gdouble lon, gdouble elev, - gdouble n, gdouble s, gdouble e, gdouble w, +static gboolean _gis_tile_precise(GisPoint *eye, GisBBox *bounds, gdouble max_res, gint width, gint height) { - gdouble min_dist = _gis_tile_get_min_dist(lat, lon, elev, n, s, e, w); + gdouble min_dist = _gis_tile_get_min_dist(eye, bounds); gdouble view_res = MPPX(min_dist); - gdouble lat_point = n < 0 ? n : s > 0 ? s : 0; - gdouble lon_dist = e - w; + gdouble lat_point = bounds->n < 0 ? bounds->n : + bounds->s > 0 ? bounds->s : 0; + gdouble lon_dist = bounds->e - bounds->w; gdouble tile_res = ll2m(lon_dist, lat_point)/width; /* This isn't really right, but it helps with memory since we don't (yet?) test if the tile * would be drawn */ - gdouble scale = elev / min_dist; + gdouble scale = eye->elev / min_dist; view_res /= scale; //view_res /= 1.4; /* make it a little nicer, not sure why this is needed */ //g_message("tile=(%7.2f %7.2f %7.2f %7.2f) " @@ -141,12 +134,10 @@ static gboolean _gis_tile_precise( /** * gis_tile_update: * @root: the root tile to split + * @eye: the point the tile is viewed from, for calculating distances * @res: a maximum resolution in meters per pixel to split tiles to * @width: width in pixels of the image associated with the tile * @height: height in pixels of the image associated with the tile - * @lat: latitude of the eye point - * @lon: longitude of the eye point - * @elev: elevation of the eye point * @load_func: function used to load the image when a new tile is created * @user_data: user data to past to the load function * @@ -156,9 +147,8 @@ static gboolean _gis_tile_precise( * the tile is recursively subdivided until a sufficient resolution is * achieved. */ -void gis_tile_update(GisTile *root, +void gis_tile_update(GisTile *root, GisPoint *eye, gdouble res, gint width, gint height, - gdouble lat, gdouble lon, gdouble elev, GisTileLoadFunc load_func, gpointer user_data) { root->atime = time(NULL); @@ -173,19 +163,20 @@ void gis_tile_update(GisTile *root, int row, col; gis_tile_foreach_index(root, row, col) { GisTile **child = &root->children[row][col]; - const gdouble n = root->edge.n-(lat_step*(row+0)); - const gdouble s = root->edge.n-(lat_step*(row+1)); - const gdouble e = root->edge.w+(lon_step*(col+1)); - const gdouble w = root->edge.w+(lon_step*(col+0)); - if (!_gis_tile_precise(lat,lon,elev, n,s,e,w, - res,width/cols,height/rows)) { + GisBBox edge; + edge.n = root->edge.n-(lat_step*(row+0)); + edge.s = root->edge.n-(lat_step*(row+1)); + edge.e = root->edge.w+(lon_step*(col+1)); + edge.w = root->edge.w+(lon_step*(col+0)); + if (!_gis_tile_precise(eye, &edge, res, + width/cols, height/rows)) { if (!*child) { - *child = gis_tile_new(root, n,s,e,w); + *child = gis_tile_new(root, edge.n, edge.s, + edge.e, edge.w); load_func(*child, user_data); } - gis_tile_update(*child, + gis_tile_update(*child, eye, res, width, height, - lat, lon, elev, load_func, user_data); } } diff --git a/src/objects/gis-tile.h b/src/objects/gis-tile.h index 98052c6..4ebf7ef 100644 --- a/src/objects/gis-tile.h +++ b/src/objects/gis-tile.h @@ -39,9 +39,7 @@ struct _GisTile { gpointer data; /* North,South,East,West limits */ - struct { - gdouble n,s,e,w; - } edge; + GisBBox edge; /* Pointers to parent/child nodes */ GisTile *parent; @@ -112,10 +110,9 @@ GisTile *gis_tile_new(GisTile *parent, gchar *gis_tile_get_path(GisTile *child); /* Update a root tile */ -/* Based on eye distance (lat,lon,elev) */ -void gis_tile_update(GisTile *root, +/* Based on eye distance */ +void gis_tile_update(GisTile *root, GisPoint *eye, gdouble res, gint width, gint height, - gdouble lat, gdouble lon, gdouble elev, GisTileLoadFunc load_func, gpointer user_data); /* Find the leaf tile containing lat-lon */ diff --git a/src/plugins/elev.c b/src/plugins/elev.c index 9279b08..a8f9df1 100644 --- a/src/plugins/elev.c +++ b/src/plugins/elev.c @@ -248,11 +248,10 @@ static gpointer _update_tiles(gpointer _elev) GisPluginElev *elev = _elev; if (!g_mutex_trylock(elev->mutex)) return NULL; - gdouble lat, lon, elevation; - gis_viewer_get_location(elev->viewer, &lat, &lon, &elevation); - gis_tile_update(elev->tiles, + GisPoint eye; + gis_viewer_get_location(elev->viewer, &eye.lat, &eye.lon, &eye.elev); + gis_tile_update(elev->tiles, &eye, MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH, - lat, lon, elevation, _load_tile, elev); gis_tile_gc(elev->tiles, time(NULL)-10, _free_tile, elev); diff --git a/src/plugins/map.c b/src/plugins/map.c index 7a2d66d..0ae8ef6 100644 --- a/src/plugins/map.c +++ b/src/plugins/map.c @@ -136,11 +136,10 @@ static gpointer _update_tiles(gpointer _map) GisPluginMap *map = _map; if (!g_mutex_trylock(map->mutex)) return NULL; - gdouble lat, lon, elev; - gis_viewer_get_location(map->viewer, &lat, &lon, &elev); - gis_tile_update(map->tiles, + GisPoint eye; + gis_viewer_get_location(map->viewer, &eye.lat, &eye.lon, &eye.elev); + gis_tile_update(map->tiles, &eye, MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH, - lat, lon, elev, _load_tile, map); gis_tile_gc(map->tiles, time(NULL)-10, _free_tile, map); diff --git a/src/plugins/sat.c b/src/plugins/sat.c index 1af0bfc..66150be 100644 --- a/src/plugins/sat.c +++ b/src/plugins/sat.c @@ -127,11 +127,10 @@ static gpointer _update_tiles(gpointer _sat) GisPluginSat *sat = _sat; if (!g_mutex_trylock(sat->mutex)) return NULL; - gdouble lat, lon, elev; - gis_viewer_get_location(sat->viewer, &lat, &lon, &elev); - gis_tile_update(sat->tiles, + GisPoint eye; + gis_viewer_get_location(sat->viewer, &eye.lat, &eye.lon, &eye.elev); + gis_tile_update(sat->tiles, &eye, MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH, - lat, lon, elev, _load_tile, sat); gis_tile_gc(sat->tiles, time(NULL)-10, _free_tile, sat);