]> Pileus Git - grits/blob - src/roam.h
Document GisOpenGL
[grits] / src / roam.h
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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
23 /* Roam */
24 typedef struct _RoamView     RoamView;
25 typedef struct _RoamPoint    RoamPoint;
26 typedef struct _RoamTriangle RoamTriangle;
27 typedef struct _RoamDiamond  RoamDiamond;
28 typedef struct _RoamSphere   RoamSphere;
29 typedef gdouble (*RoamHeightFunc)(gdouble lat, gdouble lon, gpointer user_data);
30
31 /* Misc */
32 struct _RoamView {
33         gdouble model[16];
34         gdouble proj[16];
35         gint view[4];
36         gint version;
37 };
38
39 /*************
40  * RoamPoint *
41  *************/
42 struct _RoamPoint {
43         /*< private >*/
44         gdouble  x, y, z;    /* Model coordinates */
45         gdouble  px, py, pz; /* Projected coordinates */
46         gint     pversion;   /* Version of cached projection */
47
48         gint     tris;       /* Count of associated triangles */
49         gdouble  norm[3];    /* Vertex normal */
50
51         /* For get_intersect */
52         gdouble  lat, lon, elev;
53
54         /* For terrain */
55         RoamHeightFunc height_func;
56         gpointer       height_data;
57 };
58 RoamPoint *roam_point_new(double lat, double lon, double elev);
59 void roam_point_add_triangle(RoamPoint *point, RoamTriangle *triangle);
60 void roam_point_remove_triangle(RoamPoint *point, RoamTriangle *triangle);
61 void roam_point_update_height(RoamPoint *point);
62 void roam_point_update_projection(RoamPoint *point, RoamView *view);
63
64 /****************
65  * RoamTriangle *
66  ****************/
67 struct _RoamTriangle {
68         /*< private >*/
69         /* Left, middle and right vertices */
70         struct { RoamPoint    *l,*m,*r; } p;
71
72         /* Left, base, and right neighbor triangles */
73         struct { RoamTriangle *l,*b,*r; } t;
74
75         RoamPoint *split;     /* Split point */
76         RoamDiamond *parent;  /* Parent diamond */
77         double norm[3];       /* Surface normal */
78         double error;         /* Screen space error */
79         GPQueueHandle handle;
80
81         /* For get_intersect */
82         struct { gdouble n,s,e,w; } edge;
83         RoamTriangle *kids[2];
84 };
85 RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r);
86 void roam_triangle_free(RoamTriangle *triangle);
87 void roam_triangle_add(RoamTriangle *triangle,
88                 RoamTriangle *left, RoamTriangle *base, RoamTriangle *right,
89                 RoamSphere *sphere);
90 void roam_triangle_remove(RoamTriangle *triangle, RoamSphere *sphere);
91 void roam_triangle_update_errors(RoamTriangle *triangle, RoamSphere *sphere);
92 void roam_triangle_split(RoamTriangle *triangle, RoamSphere *sphere);
93 void roam_triangle_draw(RoamTriangle *triangle);
94 void roam_triangle_draw_normal(RoamTriangle *triangle);
95
96 /***************
97  * RoamDiamond *
98  ***************/
99 struct _RoamDiamond {
100         /*< private >*/
101         RoamTriangle *kids[4];    /* Child triangles */
102         RoamTriangle *parents[2]; /* Parent triangles */
103         double error;             /* Screen space error */
104         gboolean active;          /* For internal use */
105         GPQueueHandle handle;
106 };
107 RoamDiamond *roam_diamond_new(
108                 RoamTriangle *parent0, RoamTriangle *parent1,
109                 RoamTriangle *kid0, RoamTriangle *kid1,
110                 RoamTriangle *kid2, RoamTriangle *kid3);
111 void roam_diamond_add(RoamDiamond *diamond, RoamSphere *sphere);
112 void roam_diamond_remove(RoamDiamond *diamond, RoamSphere *sphere);
113 void roam_diamond_merge(RoamDiamond *diamond, RoamSphere *sphere);
114 void roam_diamond_update_errors(RoamDiamond *diamond, RoamSphere *sphere);
115
116 /**************
117  * RoamSphere *
118  **************/
119 struct _RoamSphere {
120         /*< private >*/
121         GPQueue *triangles; /* List of triangles */
122         GPQueue *diamonds;  /* List of diamonds */
123         RoamView *view;     /* Current projection */
124         gint polys;         /* Polygon count */
125
126         /* For get_intersect */
127         RoamTriangle *roots[8]; /* Original 8 triangles */
128 };
129 RoamSphere *roam_sphere_new();
130 void roam_sphere_update_view(RoamSphere *sphere);
131 void roam_sphere_update_errors(RoamSphere *sphere);
132 void roam_sphere_split_one(RoamSphere *sphere);
133 void roam_sphere_merge_one(RoamSphere *sphere);
134 gint roam_sphere_split_merge(RoamSphere *sphere);
135 void roam_sphere_draw(RoamSphere *sphere);
136 void roam_sphere_draw_normals(RoamSphere *sphere);
137 GList *roam_sphere_get_intersect(RoamSphere *sphere, gboolean all,
138                 gdouble n, gdouble s, gdouble e, gdouble w);
139 void roam_sphere_free(RoamSphere *sphere);
140
141 #endif