From 8060da4427ab86674362a745e9d4af15b8e48f95 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 9 Nov 2009 11:16:51 +0000 Subject: [PATCH] Move height_func to RoamPoint and add lat-lon cache --- src/gis-world.c | 7 +++++++ src/gis-world.h | 3 +++ src/roam.c | 26 ++++++++++++++------------ src/roam.h | 18 +++++++++--------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/gis-world.c b/src/gis-world.c index 6e9beaa..c4d74b8 100644 --- a/src/gis-world.c +++ b/src/gis-world.c @@ -151,6 +151,13 @@ void xyz2lle(gdouble x, gdouble y, gdouble z, *elev = rad2elev(rad); } +void xyz2ll(gdouble x, gdouble y, gdouble z, + gdouble *lat, gdouble *lon) +{ + gdouble rad = sqrt(x*x + y*y + z*z); + *lat = incl2lat(acos(y / rad)); + *lon = azim2lon(atan2(x,z)); +} gdouble ll2m(gdouble lon_dist, gdouble lat) { diff --git a/src/gis-world.h b/src/gis-world.h index 7994df2..93c47e3 100644 --- a/src/gis-world.h +++ b/src/gis-world.h @@ -86,6 +86,9 @@ void lle2xyz(gdouble lat, gdouble lon, gdouble elev, void xyz2lle(gdouble x, gdouble y, gdouble z, gdouble *lat, gdouble *lon, gdouble *elev); +void xyz2ll(gdouble x, gdouble y, gdouble z, + gdouble *lat, gdouble *lon); + gdouble ll2m(gdouble lon_dist, gdouble lat); gdouble distd(gdouble *a, gdouble *b); diff --git a/src/roam.c b/src/roam.c index aab62b1..54ae2c6 100644 --- a/src/roam.c +++ b/src/roam.c @@ -70,6 +70,8 @@ RoamPoint *roam_point_new(gdouble x, gdouble y, gdouble z) self->x = x; self->y = y; self->z = z; + /* For get_intersect */ + xyz2ll(x, y, z, &self->lat, &self->lon); return self; } RoamPoint *roam_point_dup(RoamPoint *self) @@ -99,10 +101,13 @@ void roam_point_remove_triangle(RoamPoint *self, RoamTriangle *triangle) for (int i = 0; i < 3; i++) self->norm[i] /= self->tris; } -void roam_point_update_height(RoamPoint *self, RoamSphere *sphere) +void roam_point_update_height(RoamPoint *self) { - if (sphere->height_func) { - sphere->height_func(self, sphere->user_data); + if (self->height_func) { + gdouble elev = self->height_func( + self->lat, self->lon, self->height_data); + lle2xyz(self->lat, self->lon, elev, + &self->x, &self->y, &self->z); } else { gdouble dist = sqrt(self->x * self->x + self->y * self->y + @@ -147,7 +152,10 @@ RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r) (l->x + r->x)/2, (l->y + r->y)/2, (l->z + r->z)/2); - + /* TODO: Move this back to sphere, or actually use the nesting */ + self->split->height_func = m->height_func; + self->split->height_data = m->height_data; + roam_point_update_height(self->split); /* Update normal */ double pa[3]; @@ -286,11 +294,6 @@ void roam_triangle_split(RoamTriangle *self, RoamSphere *sphere) RoamTriangle *bl = roam_triangle_new(base->p.m, mid, base->p.l); // Base Left RoamTriangle *br = roam_triangle_new(base->p.r, mid, base->p.m); // Base Right - roam_point_update_height(sl->split, sphere); - roam_point_update_height(sr->split, sphere); - roam_point_update_height(bl->split, sphere); - roam_point_update_height(br->split, sphere); - /* tri,l, base, r, sphere */ roam_triangle_add(sl, sr, self->t.l, br, sphere); roam_triangle_add(sr, bl, self->t.r, sl, sphere); @@ -442,10 +445,9 @@ void roam_diamond_update_errors(RoamDiamond *self, RoamSphere *sphere) /************** * RoamSphere * **************/ -RoamSphere *roam_sphere_new(gpointer user_data) +RoamSphere *roam_sphere_new() { RoamSphere *self = g_new0(RoamSphere, 1); - self->user_data = user_data; self->polys = 8; self->triangles = g_pqueue_new((GCompareDataFunc)tri_cmp, NULL); self->diamonds = g_pqueue_new((GCompareDataFunc)dia_cmp, NULL); @@ -471,7 +473,7 @@ RoamSphere *roam_sphere_new(gpointer user_data) }; for (int i = 0; i < 6; i++) - roam_point_update_height(vertexes[i], self); + roam_point_update_height(vertexes[i]); for (int i = 0; i < 8; i++) self->roots[i] = roam_triangle_new( vertexes[_triangles[i][0][0]], diff --git a/src/roam.h b/src/roam.h index ebcc3a3..da4f508 100644 --- a/src/roam.h +++ b/src/roam.h @@ -19,7 +19,6 @@ #define __ROAM_H__ #include "gpqueue.h" -#include "wms.h" /* Roam */ typedef struct _RoamView RoamView; @@ -27,7 +26,7 @@ typedef struct _RoamPoint RoamPoint; typedef struct _RoamTriangle RoamTriangle; typedef struct _RoamDiamond RoamDiamond; typedef struct _RoamSphere RoamSphere; -typedef void (*RoamHeightFunc)(RoamPoint *point, gpointer user_data); +typedef gdouble (*RoamHeightFunc)(gdouble lat, gdouble lon, gpointer user_data); /* Misc */ struct _RoamView { @@ -48,12 +47,17 @@ struct _RoamPoint { gint tris; // Associated triangles gdouble norm[3]; // Vertex normal - WmsCacheNode *node; // TODO: don't depend on wms + /* For get_intersect */ + gdouble lat, lon; + + /* For terrain */ + RoamHeightFunc height_func; + gpointer height_data; }; RoamPoint *roam_point_new(double x, double y, double z); void roam_point_add_triangle(RoamPoint *point, RoamTriangle *triangle); void roam_point_remove_triangle(RoamPoint *point, RoamTriangle *triangle); -void roam_point_update_height(RoamPoint *point, RoamSphere *sphere); +void roam_point_update_height(RoamPoint *point); void roam_point_update_projection(RoamPoint *point, RoamSphere *sphere); /**************** @@ -67,8 +71,6 @@ struct _RoamTriangle { double norm[3]; double error; GPQueueHandle handle; - - WmsCacheNode *nodes[5]; // TODO: don't depend on wms }; RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r); void roam_triangle_add(RoamTriangle *triangle, @@ -105,14 +107,12 @@ struct _RoamSphere { GPQueue *triangles; GPQueue *diamonds; RoamView *view; - RoamHeightFunc height_func; - gpointer user_data; gint polys; /* For get_intersect */ RoamTriangle *roots[8]; }; -RoamSphere *roam_sphere_new(gpointer user_data); +RoamSphere *roam_sphere_new(); void roam_sphere_update_errors(RoamSphere *sphere); void roam_sphere_split_one(RoamSphere *sphere); void roam_sphere_merge_one(RoamSphere *sphere); -- 2.43.2