]> Pileus Git - grits/blob - src/gis/roam.h
c2558122169a4d8936b35a524f50e88018a36489
[grits] / 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
23 /* Roam */
24 typedef struct _RoamPoint    RoamPoint;
25 typedef struct _RoamTriangle RoamTriangle;
26 typedef struct _RoamDiamond  RoamDiamond;
27 typedef struct _RoamSphere   RoamSphere;
28 typedef void (*RoamTriFunc)(RoamTriangle *triangle, gpointer user_data);
29 typedef void (*RoamHeightFunc)(RoamPoint *point, gpointer user_data);
30
31 /*************
32  * RoamPoint *
33  *************/
34 struct _RoamPoint {
35         double x,y,z;
36         double coords;  // Texture coordinantes 
37         double norm[3]; // Vertex normal
38         int    refs;    // Reference count
39 };
40 RoamPoint *roam_point_new(double x, double y, double z);
41 void roam_point_add_triangle(RoamPoint *point, RoamTriangle *triangle);
42 void roam_point_remove_triangle(RoamPoint *point, RoamTriangle *triangle);
43
44 /****************
45  * RoamTriangle *
46  ****************/
47 struct _RoamTriangle {
48         struct { RoamPoint    *l,*m,*r; } p;
49         struct { RoamTriangle *l,*b,*r; } t;
50         RoamDiamond *diamond;
51         double norm[3];
52         double error;
53         GPQueueHandle handle;
54 };
55 RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r);
56 void roam_triangle_add(RoamTriangle *triangle,
57                 RoamTriangle *left, RoamTriangle *base, RoamTriangle *right,
58                 RoamSphere *sphere);
59 void roam_triangle_remove(RoamTriangle *triangle, RoamSphere *sphere);
60 void roam_triangle_update_error(RoamTriangle *triangle, RoamSphere *sphere, GPQueue *triangles);
61 void roam_triangle_split(RoamTriangle *triangle, RoamSphere *sphere);
62 void roam_triangle_draw_normal(RoamTriangle *triangle);
63
64 /***************
65  * RoamDiamond *
66  ***************/
67 struct _RoamDiamond {
68         RoamTriangle *kid[4];
69         RoamTriangle *parent[2];
70         double error;
71         gboolean active;
72         GPQueueHandle handle;
73 };
74 RoamDiamond *roam_diamond_new(
75                 RoamTriangle *parent0, RoamTriangle *parent1,
76                 RoamTriangle *kid0, RoamTriangle *kid1,
77                 RoamTriangle *kid2, RoamTriangle *kid3);
78 void roam_diamond_add(RoamDiamond *diamond, RoamSphere *sphere);
79 void roam_diamond_remove(RoamDiamond *diamond, RoamSphere *sphere);
80 void roam_diamond_merge(RoamDiamond *diamond, RoamSphere *sphere);
81 void roam_diamond_update_error(RoamDiamond *self, RoamSphere *sphere, GPQueue *diamonds);
82
83 /**************
84  * RoamSphere *
85  **************/
86 struct _RoamSphere {
87         GPQueue *triangles;
88         GPQueue *diamonds;
89         RoamTriFunc tri_func;
90         RoamHeightFunc height_func;
91         gpointer user_data;
92         gint polys;
93 };
94 RoamSphere *roam_sphere_new(RoamTriFunc tri_func, RoamHeightFunc height_func, gpointer user_data);
95 void roam_sphere_update_errors(RoamSphere *sphere);
96 void roam_sphere_update_point(RoamSphere *sphere, RoamPoint *point);
97 void roam_sphere_split_one(RoamSphere *sphere);
98 void roam_sphere_merge_one(RoamSphere *sphere);
99 gint roam_sphere_split_merge(RoamSphere *sphere);
100 void roam_sphere_draw(RoamSphere *sphere);
101 void roam_sphere_draw_normals(RoamSphere *sphere);
102 void roam_sphere_free(RoamSphere *sphere);
103
104 #endif