10 |
|
#ifndef _OBJUTIL_H_ |
11 |
|
#define _OBJUTIL_H_ |
12 |
|
|
13 |
+ |
#ifdef __cplusplus |
14 |
+ |
extern "C" { |
15 |
+ |
#endif |
16 |
+ |
|
17 |
|
#ifndef DUP_CHECK_REVERSE |
18 |
|
#define DUP_CHECK_REVERSE 1 /* eliminate flipped duplicates */ |
19 |
|
#endif |
21 |
|
#define POPEN_SUPPORT 1 /* support "!command" i/o */ |
22 |
|
#endif |
23 |
|
/* face flags */ |
24 |
< |
#define FACE_SELECTED 01 |
25 |
< |
#define FACE_DEGENERATE 02 |
26 |
< |
#define FACE_DUPLICATE 04 |
24 |
> |
#define FACE_DEGENERATE 01 |
25 |
> |
#define FACE_DUPLICATE 02 |
26 |
> |
#define FACE_SELECTED 04 |
27 |
> |
#define FACE_CUSTOM(n) (FACE_SELECTED<<(n)) |
28 |
> |
#define FACE_RESERVED (1<<15) |
29 |
|
|
30 |
|
struct Face; /* forward declaration */ |
31 |
|
|
84 |
|
int nfaces; /* count of faces */ |
85 |
|
} Scene; |
86 |
|
|
81 |
– |
#ifdef __cplusplus |
82 |
– |
extern "C" { |
83 |
– |
#endif |
84 |
– |
|
87 |
|
/* Allocate a new scene holder */ |
88 |
< |
Scene * newScene(void); |
88 |
> |
extern Scene * newScene(void); |
89 |
|
|
90 |
|
/* Add a .OBJ file to a scene */ |
91 |
< |
Scene * loadOBJ(Scene *sc, const char *fspec); |
91 |
> |
extern Scene * loadOBJ(Scene *sc, const char *fspec); |
92 |
|
|
93 |
< |
/* Duplicate a scene */ |
94 |
< |
Scene * dupScene(const Scene *sc); |
93 |
> |
/* Duplicate a scene, optionally selecting faces */ |
94 |
> |
extern Scene * dupScene(const Scene *sc, int flreq, int flexc); |
95 |
|
|
96 |
+ |
/* Add one scene to another, not checking for redundancies */ |
97 |
+ |
extern int addScene(Scene *scdst, const Scene *scsrc); |
98 |
+ |
|
99 |
|
/* Transform entire scene */ |
100 |
< |
int xfScene(Scene *sc, int xac, char *xav[]); |
101 |
< |
int xfmScene(Scene *sc, const char *xfm); |
100 |
> |
extern int xfScene(Scene *sc, int xac, char *xav[]); |
101 |
> |
extern int xfmScene(Scene *sc, const char *xfm); |
102 |
|
|
103 |
|
/* Add a descriptive comment */ |
104 |
< |
void addComment(Scene *sc, const char *comment); |
104 |
> |
extern void addComment(Scene *sc, const char *comment); |
105 |
|
|
106 |
+ |
/* Find index for comment containing the given string (starting from n) */ |
107 |
+ |
extern int findComment(Scene *sc, const char *match, int n); |
108 |
+ |
|
109 |
|
/* Clear comments */ |
110 |
< |
void clearComments(Scene *sc); |
110 |
> |
extern void clearComments(Scene *sc); |
111 |
|
|
112 |
|
/* Write a .OBJ file, return # faces written or -1 on error */ |
113 |
< |
int toOBJ(Scene *sc, FILE *fp); |
114 |
< |
int writeOBJ(Scene *sc, const char *fspec); |
113 |
> |
extern int toOBJ(Scene *sc, FILE *fp); |
114 |
> |
extern int writeOBJ(Scene *sc, const char *fspec); |
115 |
|
|
116 |
|
/* Convert indicated faces to Radiance, return # written or -1 on error */ |
117 |
< |
int toRadiance(Scene *sc, FILE *fp, int flreq, int flexc); |
118 |
< |
int writeRadiance(Scene *sc, const char *fspec, |
117 |
> |
extern int toRadiance(Scene *sc, FILE *fp, int flreq, int flexc); |
118 |
> |
extern int writeRadiance(Scene *sc, const char *fspec, |
119 |
|
int flreq, int flexc); |
120 |
|
|
121 |
|
/* Compute face area (and normal) */ |
122 |
< |
double faceArea(const Scene *sc, const Face *f, Normal nrm); |
122 |
> |
extern double faceArea(const Scene *sc, const Face *f, Normal nrm); |
123 |
|
|
124 |
|
/* Eliminate duplicate vertices, return # joined */ |
125 |
< |
int coalesceVertices(Scene *sc, double eps); |
125 |
> |
extern int coalesceVertices(Scene *sc, double eps); |
126 |
|
|
127 |
|
/* Identify duplicate faces */ |
128 |
< |
int findDuplicateFaces(Scene *sc); |
128 |
> |
extern int findDuplicateFaces(Scene *sc); |
129 |
|
|
130 |
|
/* Delete indicated faces, return # deleted */ |
131 |
< |
int deleteFaces(Scene *sc, int flreq, int flexc); |
131 |
> |
extern int deleteFaces(Scene *sc, int flreq, int flexc); |
132 |
|
|
133 |
|
/* Clear face selection */ |
134 |
< |
void clearSelection(Scene *sc, int set); |
134 |
> |
extern void clearSelection(Scene *sc, int set); |
135 |
|
|
136 |
|
/* Invert face selection */ |
137 |
< |
void invertSelection(Scene *sc); |
137 |
> |
extern void invertSelection(Scene *sc); |
138 |
|
|
139 |
|
/* Count number of faces selected */ |
140 |
< |
int numberSelected(Scene *sc); |
140 |
> |
extern int numberSelected(Scene *sc); |
141 |
|
|
142 |
|
/* Select faces by object name (modifies current) */ |
143 |
< |
void selectGroup(Scene *sc, const char *gname, int invert); |
143 |
> |
extern void selectGroup(Scene *sc, const char *gname, int invert); |
144 |
|
|
145 |
|
/* Select faces by material name (modifies current) */ |
146 |
< |
void selectMaterial(Scene *sc, const char *mname, int invert); |
146 |
> |
extern void selectMaterial(Scene *sc, const char *mname, int invert); |
147 |
|
|
148 |
|
/* Execute callback on indicated faces */ |
149 |
< |
int foreachFace(Scene *sc, int (*cb)(Scene *, Face *, void *), |
149 |
> |
extern int foreachFace(Scene *sc, int (*cb)(Scene *, Face *, void *), |
150 |
|
int flreq, int flexc, void *c_data); |
151 |
|
|
152 |
|
/* Remove texture coordinates from the indicated faces */ |
153 |
< |
int removeTexture(Scene *sc, int flreq, int flexc); |
153 |
> |
extern int removeTexture(Scene *sc, int flreq, int flexc); |
154 |
|
|
155 |
|
/* Remove surface normals from the indicated faces */ |
156 |
< |
int removeNormals(Scene *sc, int flreq, int flexc); |
156 |
> |
extern int removeNormals(Scene *sc, int flreq, int flexc); |
157 |
|
|
158 |
|
/* Change group for the indicated faces */ |
159 |
< |
int changeGroup(Scene *sc, const char *gname, |
159 |
> |
extern int changeGroup(Scene *sc, const char *gname, |
160 |
|
int flreq, int flexc); |
161 |
|
|
162 |
|
/* Change material for the indicated faces */ |
163 |
< |
int changeMaterial(Scene *sc, const char *mname, |
163 |
> |
extern int changeMaterial(Scene *sc, const char *mname, |
164 |
|
int flreq, int flexc); |
165 |
|
|
166 |
|
/* Add a vertex to our scene, returning index */ |
167 |
< |
int addVertex(Scene *sc, double x, double y, double z); |
167 |
> |
extern int addVertex(Scene *sc, double x, double y, double z); |
168 |
|
|
169 |
|
/* Add a texture coordinate to our scene, returning index */ |
170 |
< |
int addTexture(Scene *sc, double u, double v); |
170 |
> |
extern int addTexture(Scene *sc, double u, double v); |
171 |
|
|
172 |
|
/* Add a surface normal to our scene, returning index */ |
173 |
< |
int addNormal(Scene *sc, double xn, double yn, double zn); |
173 |
> |
extern int addNormal(Scene *sc, double xn, double yn, double zn); |
174 |
|
|
175 |
|
/* Set current group (sc->lastgrp) to given ID */ |
176 |
< |
void setGroup(Scene *sc, const char *nm); |
176 |
> |
extern void setGroup(Scene *sc, const char *nm); |
177 |
|
|
178 |
|
/* Set current material (sc->lastmat) to given ID */ |
179 |
< |
void setMaterial(Scene *sc, const char *nm); |
179 |
> |
extern void setMaterial(Scene *sc, const char *nm); |
180 |
|
|
181 |
|
/* Add a new face to our scene, using current group and material */ |
182 |
< |
Face * addFace(Scene *sc, VNDX vid[], int nv); |
182 |
> |
extern Face * addFace(Scene *sc, VNDX vid[], int nv); |
183 |
|
|
184 |
+ |
/* Get neighbor vertices: malloc array with valence in index[0] */ |
185 |
+ |
extern int * getVertexNeighbors(Scene *sc, int vid); |
186 |
+ |
|
187 |
+ |
/* Expand bounding box min & max (initialize bbox to all zeroes) */ |
188 |
+ |
extern int growBoundingBox(Scene *sc, double bbox[2][3], |
189 |
+ |
int flreq, int flexc); |
190 |
+ |
|
191 |
+ |
/* Convert all faces with > 3 vertices to triangles */ |
192 |
+ |
extern int triangulateScene(Scene *sc); |
193 |
+ |
|
194 |
+ |
/* Delete unreferenced vertices, normals, texture coords */ |
195 |
+ |
extern void deleteUnreferenced(Scene *sc); |
196 |
+ |
|
197 |
|
/* Free a scene */ |
198 |
< |
void freeScene(Scene *sc); |
198 |
> |
extern void freeScene(Scene *sc); |
199 |
|
|
200 |
|
/* Find an existing name in a list of names */ |
201 |
< |
int findName(const char *nm, const char **nmlist, int n); |
201 |
> |
extern int findName(const char *nm, const char **nmlist, int n); |
202 |
|
|
203 |
|
/* Verbose mode global */ |
204 |
|
extern int verbose; |
206 |
|
extern char *emalloc(unsigned int n); |
207 |
|
extern char *ecalloc(unsigned int ne, unsigned int n); |
208 |
|
extern char *erealloc(char *cp, unsigned int n); |
209 |
< |
extern void efree(char *cp); |
209 |
> |
extern void efree(char *cp); |
210 |
|
|
211 |
< |
#define CHUNKSIZ 128 /* object allocation chunk size */ |
211 |
> |
#define getGroupID(sc,nm) findName(nm, (const char **)(sc)->grpname, (sc)->ngrps) |
212 |
> |
#define getMaterialID(sc,nm) findName(nm, (const char **)(sc)->matname, (sc)->nmats) |
213 |
|
|
214 |
+ |
#define CHUNKBITS 7 /* object allocation chunk bits */ |
215 |
+ |
#define CHUNKSIZ (1<<CHUNKBITS) /* object allocation chunk size */ |
216 |
+ |
|
217 |
|
#define chunk_alloc(typ, arr, nold) \ |
218 |
< |
((nold)%CHUNKSIZ ? (arr) : \ |
219 |
< |
(typ *)erealloc((char *)(arr), sizeof(typ)*((nold)+CHUNKSIZ))) |
218 |
> |
((nold)&(CHUNKSIZ-1) ? (arr) : \ |
219 |
> |
(typ *)erealloc(arr, sizeof(typ)*((nold)+CHUNKSIZ))) |
220 |
|
|
221 |
|
#ifdef __cplusplus |
222 |
|
} |