]> Pileus Git - grits/blob - src/plugins/marching.h
Fix compiling plugins
[grits] / src / plugins / marching.h
1 /**
2  * Copyright (c) 2002 Jamie Zawinski <jwz@jwz.org>
3  * Copyright (c) 2009 Andy Spencer <andy753421@gmail.com>
4  *
5  * Utility functions to create "marching cubes" meshes from 3d fields.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and its
8  * documentation for any purpose is hereby granted without fee, provided that
9  * the above copyright notice appear in all copies and that both that
10  * copyright notice and this permission notice appear in supporting
11  * documentation.  No representations are made about the suitability of this
12  * software for any purpose.  It is provided "as is" without express or 
13  * implied warranty.
14  */
15
16 #ifndef __MARCHING_H__
17 #define __MARCHING_H__
18
19 typedef struct {
20         double x;
21         double y;
22         double z;
23 } XYZ;
24
25 typedef struct {
26    XYZ p[3];
27 } TRIANGLE;
28
29 typedef struct {
30    XYZ p[8];
31    double val[8];
32 } GRIDCELL;
33
34 int march_one_cube(GRIDCELL grid, double isolevel, TRIANGLE *triangles);
35
36 void do_function_normal (double x, double y, double z,
37                 double (*compute_fn) (double x, double y, double z,
38                         void *closure),
39                 void *c);
40
41 XYZ calc_normal (XYZ p, XYZ p1, XYZ p2);
42
43 void do_normal(float x1, float y1, float z1,
44                 float x2, float y2, float z2,
45                 float x3, float y3, float z3);
46
47
48 /* Given a function capable of generating a value at any XYZ position,
49    creates OpenGL faces for the solids defined.
50
51    init_fn is called at the beginning for initial, and returns an object.
52    free_fn is called at the end.
53
54    compute_fn is called for each XYZ in the specified grid, and returns
55    the double value of that coordinate.  If smoothing is on, then
56    compute_fn will also be called twice more for each emitted vertex,
57    in order to calculate vertex normals (so don't assume it will only
58    be called with values falling on the grid boundaries.)
59
60    Points are inside an object if the are less than `isolevel', and
61    outside otherwise.
62
63    If polygon_count is specified, the number of faces generated will be
64    returned there.
65 */
66 extern void
67 marching_cubes (int grid_size,     /* density of the mesh */
68                 double isolevel,   /* cutoff point for "in" versus "out" */
69                 int wireframe_p,   /* wireframe, or solid */
70                 int smooth_p,      /* smooth, or faceted */
71
72                 void * (*init_fn)    (double grid_size, void *closure1),
73                 double (*compute_fn) (double x, double y, double z,
74                                       void *closure2),
75                 void   (*free_fn)    (void *closure2),
76                 void *closure1,
77
78                 unsigned long *polygon_count);
79
80 #endif /* __MARCHING_H__ */