1 /* xscreensaver, Copyright (c) 2002 Jamie Zawinski <jwz@jwz.org>
2 * Utility functions to create "marching cubes" meshes from 3d fields.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
13 #ifndef __MARCHING_H__
14 #define __MARCHING_H__
16 /* Given a function capable of generating a value at any XYZ position,
17 creates OpenGL faces for the solids defined.
19 init_fn is called at the beginning for initial, and returns an object.
20 free_fn is called at the end.
22 compute_fn is called for each XYZ in the specified grid, and returns
23 the double value of that coordinate. If smoothing is on, then
24 compute_fn will also be called twice more for each emitted vertex,
25 in order to calculate vertex normals (so don't assume it will only
26 be called with values falling on the grid boundaries.)
28 Points are inside an object if the are less than `isolevel', and
31 If polygon_count is specified, the number of faces generated will be
35 marching_cubes (int grid_size, /* density of the mesh */
36 double isolevel, /* cutoff point for "in" versus "out" */
37 int wireframe_p, /* wireframe, or solid */
38 int smooth_p, /* smooth, or faceted */
40 void * (*init_fn) (double grid_size, void *closure1),
41 double (*compute_fn) (double x, double y, double z,
43 void (*free_fn) (void *closure2),
46 unsigned long *polygon_count);
48 #endif /* __MARCHING_H__ */