2 * Copyright (c) 2002 Jamie Zawinski <jwz@jwz.org>
3 * Copyright (c) 2009 Andy Spencer <andy753421@gmail.com>
5 * Utility functions to create "marching cubes" meshes from 3d fields.
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
16 #ifndef __MARCHING_H__
17 #define __MARCHING_H__
34 int march_one_cube(GRIDCELL grid, double isolevel, TRIANGLE *triangles);
36 void do_function_normal (double x, double y, double z,
37 double (*compute_fn) (double x, double y, double z,
41 XYZ calc_normal (XYZ p, XYZ p1, XYZ p2);
43 void do_normal(float x1, float y1, float z1,
44 float x2, float y2, float z2,
45 float x3, float y3, float z3);
48 /* Given a function capable of generating a value at any XYZ position,
49 creates OpenGL faces for the solids defined.
51 init_fn is called at the beginning for initial, and returns an object.
52 free_fn is called at the end.
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.)
60 Points are inside an object if the are less than `isolevel', and
63 If polygon_count is specified, the number of faces generated will be
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 */
72 void * (*init_fn) (double grid_size, void *closure1),
73 double (*compute_fn) (double x, double y, double z,
75 void (*free_fn) (void *closure2),
78 unsigned long *polygon_count);
80 #endif /* __MARCHING_H__ */