77d292073ac1b7edcfdde234274d8c58586cf7d7
[laserbrain_demo] / src / blobs / metasurf.h
1 /*
2 metasurf - a library for implicit surface polygonization
3 Copyright (C) 2011-2015  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 /* this is pulled from: https://github.com/jtsiomb/metasurf */
19 #ifndef METASURF_H_
20 #define METASURF_H_
21
22 #define MSURF_GREATER   1
23 #define MSURF_LESS              0
24
25 struct metasurface;
26
27 typedef float (*msurf_eval_func_t)(struct metasurface *ms, float, float, float);
28 typedef void (*msurf_vertex_func_t)(struct metasurface *ms, float, float, float);
29 typedef void (*msurf_normal_func_t)(struct metasurface *ms, float, float, float);
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 struct metasurface *msurf_create(void);
36 void msurf_free(struct metasurface *ms);
37
38 void msurf_set_user_data(struct metasurface *ms, void *udata);
39 void *msurf_get_user_data(struct metasurface *ms);
40
41 /* which is inside above or below the threshold */
42 void msurf_set_inside(struct metasurface *ms, int inside);
43 int msurf_get_inside(struct metasurface *ms);
44
45 /* set a scalar field evaluator function */
46 void msurf_eval_func(struct metasurface *ms, msurf_eval_func_t func);
47
48 /* set a generated vertex callback function */
49 void msurf_vertex_func(struct metasurface *ms, msurf_vertex_func_t func);
50
51 /* set a generated surface normal callback function (unused yet) */
52 void msurf_normal_func(struct metasurface *ms, msurf_normal_func_t func);
53
54 /* set the bounding box (default: -1, -1, -1, 1, 1, 1)
55  * keep this as tight as possible to avoid wasting grid resolution
56  */
57 void msurf_set_bounds(struct metasurface *ms, float xmin, float ymin, float zmin, float xmax, float ymax, float zmax);
58 void msurf_get_bounds(struct metasurface *ms, float *xmin, float *ymin, float *zmin, float *xmax, float *ymax, float *zmax);
59
60 /* resolution of the 3D evaluation grid, the bigger, the better, the slower
61  * (default: 40, 40, 40)
62  */
63 void msurf_set_resolution(struct metasurface *ms, int xres, int yres, int zres);
64 void msurf_get_resolution(struct metasurface *ms, int *xres, int *yres, int *zres);
65
66 /* isosurface threshold value (default: 0) */
67 void msurf_set_threshold(struct metasurface *ms, float thres);
68 float msurf_get_threshold(struct metasurface *ms);
69
70
71 /* finally call this to perform the polygonization */
72 int msurf_polygonize(struct metasurface *ms);
73
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #endif  /* METASURF_H_ */