ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/objutil.h
Revision: 2.6
Committed: Sat May 2 00:12:45 2020 UTC (4 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +7 -1 lines
Log Message:
Made addFace() into a public routine as well, so tools can add geometry

File Contents

# Content
1 /* RCSid $Id: objutil.h,v 2.5 2020/05/01 18:55:34 greg Exp $ */
2 /*
3 * Declarations for .OBJ file utility
4 *
5 * Include after <stdio.h>
6 *
7 * Created by Greg Ward on Wed Feb 11 2004.
8 */
9
10 #ifndef _OBJUTIL_H_
11 #define _OBJUTIL_H_
12
13 #ifndef DUP_CHECK_REVERSE
14 #define DUP_CHECK_REVERSE 1 /* eliminate flipped duplicates */
15 #endif
16 #ifndef POPEN_SUPPORT
17 #define POPEN_SUPPORT 1 /* support "!command" i/o */
18 #endif
19 /* face flags */
20 #define FACE_SELECTED 01
21 #define FACE_DEGENERATE 02
22 #define FACE_DUPLICATE 04
23
24 struct Face; /* forward declaration */
25
26 typedef int VNDX[3]; /* vertex indices (point,map,normal) */
27
28 /* Structure to hold vertex indices and link back to face list */
29 typedef struct {
30 int vid; /* vertex id */
31 int tid; /* texture id */
32 int nid; /* normal id */
33 struct Face *fnext; /* next in vertex face list */
34 } VertEnt;
35
36 /* Structure to hold face and its vertex references */
37 typedef struct Face {
38 struct Face *next; /* next face in main list */
39 short flags; /* face selected, etc */
40 short nv; /* number of vertices */
41 short grp; /* group/object index */
42 short mat; /* material index */
43 /* in cases where the same vertex appears twice, first has link */
44 VertEnt v[3]; /* vertex list (extends struct) */
45 } Face;
46
47 /* Structure to hold vertex */
48 typedef struct {
49 double p[3]; /* 3-D position */
50 Face *vflist; /* linked face list (no repeats) */
51 } Vertex;
52
53 /* Structure to hold texture coordinate */
54 typedef struct {
55 float u, v; /* 2-D local texture coordinate */
56 } TexCoord;
57
58 /* Array to hold surface normal */
59 typedef float Normal[3];
60
61 /* Structure to hold a loaded .OBJ file */
62 typedef struct {
63 char **descr; /* descriptive comments */
64 int ndescr; /* number of comments */
65 char **grpname; /* object/group name list */
66 int ngrps; /* number of group names */
67 int lastgrp; /* last group seen */
68 char **matname; /* material name list */
69 int nmats; /* number of materials */
70 int lastmat; /* last material seen */
71 Vertex *vert; /* vertex array */
72 int nverts; /* number of vertices */
73 TexCoord *tex; /* texture coordinate array */
74 int ntex; /* number of texture coord's */
75 Normal *norm; /* surface normal array */
76 int nnorms; /* number of surface normals */
77 Face *flist; /* linked face list */
78 int nfaces; /* count of faces */
79 } Scene;
80
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84
85 /* Allocate a new scene holder */
86 Scene * newScene(void);
87
88 /* Add a .OBJ file to a scene */
89 Scene * loadOBJ(Scene *sc, const char *fspec);
90
91 /* Duplicate a scene */
92 Scene * dupScene(const Scene *sc);
93
94 /* Transform entire scene */
95 int xfScene(Scene *sc, int xac, char *xav[]);
96 int xfmScene(Scene *sc, const char *xfm);
97
98 /* Add a descriptive comment */
99 void addComment(Scene *sc, const char *comment);
100
101 /* Clear comments */
102 void clearComments(Scene *sc);
103
104 /* Write a .OBJ file, return # faces written or -1 on error */
105 int toOBJ(Scene *sc, FILE *fp);
106 int writeOBJ(Scene *sc, const char *fspec);
107
108 /* Convert indicated faces to Radiance, return # written or -1 on error */
109 int toRadiance(Scene *sc, FILE *fp, int flreq, int flexc);
110 int writeRadiance(Scene *sc, const char *fspec,
111 int flreq, int flexc);
112
113 /* Compute face area (and normal) */
114 double faceArea(const Scene *sc, const Face *f, Normal nrm);
115
116 /* Eliminate duplicate vertices, return # joined */
117 int coalesceVertices(Scene *sc, double eps);
118
119 /* Identify duplicate faces */
120 int findDuplicateFaces(Scene *sc);
121
122 /* Delete indicated faces, return # deleted */
123 int deleteFaces(Scene *sc, int flreq, int flexc);
124
125 /* Clear face selection */
126 void clearSelection(Scene *sc, int set);
127
128 /* Invert face selection */
129 void invertSelection(Scene *sc);
130
131 /* Count number of faces selected */
132 int numberSelected(Scene *sc);
133
134 /* Select faces by object name (modifies current) */
135 void selectGroup(Scene *sc, const char *gname, int invert);
136
137 /* Select faces by material name (modifies current) */
138 void selectMaterial(Scene *sc, const char *mname, int invert);
139
140 /* Execute callback on indicated faces */
141 int foreachFace(Scene *sc, int (*cb)(Scene *, Face *, void *),
142 int flreq, int flexc, void *c_data);
143
144 /* Remove texture coordinates from the indicated faces */
145 int removeTexture(Scene *sc, int flreq, int flexc);
146
147 /* Remove surface normals from the indicated faces */
148 int removeNormals(Scene *sc, int flreq, int flexc);
149
150 /* Change group for the indicated faces */
151 int changeGroup(Scene *sc, const char *gname,
152 int flreq, int flexc);
153
154 /* Change material for the indicated faces */
155 int changeMaterial(Scene *sc, const char *mname,
156 int flreq, int flexc);
157
158 /* Add a vertex to our scene */
159 int addVertex(Scene *sc, double x, double y, double z);
160
161 /* Add a texture coordinate to our scene */
162 int addTexture(Scene *sc, double u, double v);
163
164 /* Add a surface normal to our scene */
165 int addNormal(Scene *sc, double xn, double yn, double zn);
166
167 /* Set current (last) group */
168 void setGroup(Scene *sc, const char *nm);
169
170 /* Set current (last) material */
171 void setMaterial(Scene *sc, const char *nm);
172
173 /* Add a new face to our scene (using current group and material */
174 Face * addFace(Scene *sc, VNDX vid[], int nv);
175
176 /* Free a scene */
177 void freeScene(Scene *sc);
178
179 /* Find an existing name in a list of names */
180 int findName(const char *nm, const char **nmlist, int n);
181
182 /* Verbose mode global */
183 extern int verbose;
184
185 extern char *emalloc(unsigned int n);
186 extern char *ecalloc(unsigned int ne, unsigned int n);
187 extern char *erealloc(char *cp, unsigned int n);
188 extern void efree(char *cp);
189
190 #define CHUNKSIZ 128 /* object allocation chunk size */
191
192 #define chunk_alloc(typ, arr, nold) \
193 ((nold)%CHUNKSIZ ? (arr) : \
194 (typ *)erealloc((char *)(arr), sizeof(typ)*((nold)+CHUNKSIZ)))
195
196 #ifdef __cplusplus
197 }
198 #endif
199
200 #endif /* ! _OBJUTIL_H_ */