]> Pileus Git - grits/blob - src/objects/marching.h
Add clicked signal to GritsObject
[grits] / src / objects / marching.h
1 /*
2  * Copyright (C) 2002 Jamie Zawinski <jwz@jwz.org>
3  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
4  *
5  * Marching cubes implementation based on code from from the xscreensaver
6  * package.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef __VOLUME_H__
23 #define __VOLUME_H__
24
25 #include <glib.h>
26
27 /* VolCoord */
28 typedef struct {
29         double x, y, z;
30 } VolCoord;
31
32 /* VolPoint */
33 typedef struct {
34         VolCoord c;     /* Coordinate of the point */
35         double   value; /* Function value at point */
36 } VolPoint;
37
38 /* VolVertex */
39 typedef struct {
40         VolCoord c;    /* Coordinate of the vertex */
41         gint     tris; /* Count of associated triangles */
42         VolCoord norm; /* Vertex normal */
43 } VolVertex;
44
45 /* VolTriangle */
46 typedef struct {
47         VolVertex *v[3]; /* Vertices */
48         VolCoord   norm; /* Surface normal */
49 } VolTriangle;
50
51 /* VolCell */
52 typedef struct {
53         VolPoint  *corner[8]; /* Corners */
54         VolVertex *edge[12];  /* Points along the edges (for caching) */
55 } VolCell;
56
57 /* VolGrid */
58 typedef struct {
59         int xs, ys, zs; /* Dimensions of points */
60         gpointer data;  /* 3-D grid of points */
61 } VolGrid;
62
63 /* Find triangles on an isosurface that pass through the cell */
64 GList *march_one_cube(VolCell *cell, double level);
65
66 /* Find triangles along an isosurface in a grid of points */
67 GList *marching_cubes(VolGrid *grid, double level);
68
69 /* Free/unref data for triangle */
70 void vol_triangle_free(VolTriangle *tri);
71
72 /* Grid functions */
73 static inline VolPoint *vol_grid_get(VolGrid *grid, int x, int y, int z)
74 {
75         VolPoint (*points)[grid->ys][grid->zs] = grid->data;
76         return &points[x][y][z];
77 }
78 VolGrid *vol_grid_new(int xs, int ys, int zs);
79 void vol_grid_free(VolGrid *grid);
80
81
82 #endif