]> Pileus Git - grits/commitdiff
Move height_func to RoamPoint and add lat-lon cache
authorAndy Spencer <andy753421@gmail.com>
Mon, 9 Nov 2009 11:16:51 +0000 (11:16 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 9 Nov 2009 11:16:51 +0000 (11:16 +0000)
src/gis-world.c
src/gis-world.h
src/roam.c
src/roam.h

index 6e9beaadbe88987a8cbd7f1cffe08b4fc0e09b0c..c4d74b836e302cfdf32cd42773b034eb1fbe6240 100644 (file)
@@ -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)
 {
index 7994df2a96e70e22504b80228d4ad8407f983fad..93c47e33fd2761a66367749091fa9e5f39ade6f5 100644 (file)
@@ -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);
index aab62b142cf3764d64381395eec671be5194afc1..54ae2c6b641ca445c328c42cce5239c70a80c5cd 100644 (file)
@@ -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]],
index ebcc3a3c0a1380e7d82ae0be56ebbff10c34af15..da4f508561194ba4bbccf3fb81fc933b86f92663 100644 (file)
@@ -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);