ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/objutil.h
Revision: 2.3
Committed: Thu Apr 2 22:14:01 2020 UTC (4 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +2 -1 lines
Log Message:
Added interface for transform from pre-parsed words

File Contents

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