]> Pileus Git - aweather/blob - src/gis/roam.h
Roam and Wms optimizations
[aweather] / src / gis / roam.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 __ROAM_H__
19 #define __ROAM_H__
20
21 #include "gpqueue.h"
22 #include "wms.h"
23
24 /* Roam */
25 typedef struct _RoamView     RoamView;
26 typedef struct _RoamPoint    RoamPoint;
27 typedef struct _RoamTriangle RoamTriangle;
28 typedef struct _RoamDiamond  RoamDiamond;
29 typedef struct _RoamSphere   RoamSphere;
30 typedef void (*RoamTriFunc)(RoamTriangle *triangle, gpointer user_data);
31 typedef void (*RoamHeightFunc)(RoamPoint *point, gpointer user_data);
32
33 /* Misc */
34 struct _RoamView {
35         gdouble model[16];
36         gdouble proj[16]; 
37         gint view[4]; 
38 };
39
40 /*************
41  * RoamPoint *
42  *************/
43 struct _RoamPoint {
44         gdouble  x,y,z;     // Model coordinates
45         gdouble  px,py,pz;  // Projected coordinates
46
47         gboolean cached;    // Height/projection cached
48
49         gint     tris;      // Associated triangles
50         gdouble  norm[3];   // Vertex normal
51
52         WmsCacheNode *node; // TODO: don't depend on wms
53 };
54 RoamPoint *roam_point_new(double x, double y, double z);
55 void roam_point_add_triangle(RoamPoint *point, RoamTriangle *triangle);
56 void roam_point_remove_triangle(RoamPoint *point, RoamTriangle *triangle);
57 void roam_point_update(RoamPoint *point, RoamSphere *sphere, gboolean do_height);
58 void roam_point_clear(RoamPoint *self);
59
60 /****************
61  * RoamTriangle *
62  ****************/
63 struct _RoamTriangle {
64         struct { RoamPoint    *l,*m,*r; } p;
65         struct { RoamTriangle *l,*b,*r; } t;
66         RoamDiamond *parent;
67         double norm[3];
68         double error;
69         GPQueueHandle handle;
70
71         WmsCacheNode *nodes[5]; // TODO: don't depend on wms
72 };
73 RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r);
74 void roam_triangle_add(RoamTriangle *triangle,
75                 RoamTriangle *left, RoamTriangle *base, RoamTriangle *right,
76                 RoamSphere *sphere);
77 void roam_triangle_remove(RoamTriangle *triangle, RoamSphere *sphere);
78 void roam_triangle_update(RoamTriangle *triangle, RoamSphere *sphere);
79 void roam_triangle_split(RoamTriangle *triangle, RoamSphere *sphere);
80 void roam_triangle_draw_normal(RoamTriangle *triangle);
81
82 /***************
83  * RoamDiamond *
84  ***************/
85 struct _RoamDiamond {
86         RoamTriangle *kids[4];
87         RoamTriangle *parents[2];
88         double error;
89         gboolean active;
90         GPQueueHandle handle;
91 };
92 RoamDiamond *roam_diamond_new(
93                 RoamTriangle *parent0, RoamTriangle *parent1,
94                 RoamTriangle *kid0, RoamTriangle *kid1,
95                 RoamTriangle *kid2, RoamTriangle *kid3);
96 void roam_diamond_add(RoamDiamond *diamond, RoamSphere *sphere);
97 void roam_diamond_remove(RoamDiamond *diamond, RoamSphere *sphere);
98 void roam_diamond_merge(RoamDiamond *diamond, RoamSphere *sphere);
99 void roam_diamond_update(RoamDiamond *self, RoamSphere *sphere);
100
101 /**************
102  * RoamSphere *
103  **************/
104 struct _RoamSphere {
105         GPQueue *triangles;
106         GPQueue *diamonds;
107         RoamView *view;
108         RoamTriFunc tri_func;
109         RoamHeightFunc height_func;
110         gpointer user_data;
111         gint polys;
112 };
113 RoamSphere *roam_sphere_new(RoamTriFunc tri_func, RoamHeightFunc height_func, gpointer user_data);
114 void roam_sphere_update(RoamSphere *sphere);
115 void roam_sphere_split_one(RoamSphere *sphere);
116 void roam_sphere_merge_one(RoamSphere *sphere);
117 gint roam_sphere_split_merge(RoamSphere *sphere);
118 void roam_sphere_draw(RoamSphere *sphere);
119 void roam_sphere_draw_normals(RoamSphere *sphere);
120 void roam_sphere_free(RoamSphere *sphere);
121
122 #endif