ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/objutil.h
Revision: 2.9
Committed: Fri Feb 12 01:57:49 2021 UTC (3 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.8: +6 -3 lines
Log Message:
feat: added ability to choose faces when duplicating scene

File Contents

# User Rev Content
1 greg 2.9 /* RCSid $Id: objutil.h,v 2.8 2020/06/23 19:29:40 greg Exp $ */
2 greg 2.1 /*
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 greg 2.6 typedef int VNDX[3]; /* vertex indices (point,map,normal) */
27    
28     /* Structure to hold vertex indices and link back to face list */
29 greg 2.1 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 greg 2.9 /* Duplicate a scene, optionally selecting faces */
92     Scene * dupScene(const Scene *sc, int flreq, int flexc);
93 greg 2.1
94 greg 2.2 /* Transform entire scene */
95 greg 2.3 int xfScene(Scene *sc, int xac, char *xav[]);
96 greg 2.2 int xfmScene(Scene *sc, const char *xfm);
97    
98 greg 2.1 /* Add a descriptive comment */
99     void addComment(Scene *sc, const char *comment);
100    
101 greg 2.8 /* Find index for comment containing the given string (starting from n) */
102     int findComment(Scene *sc, const char *match, int n);
103    
104 greg 2.1 /* Clear comments */
105     void clearComments(Scene *sc);
106    
107     /* Write a .OBJ file, return # faces written or -1 on error */
108     int toOBJ(Scene *sc, FILE *fp);
109     int writeOBJ(Scene *sc, const char *fspec);
110    
111     /* Convert indicated faces to Radiance, return # written or -1 on error */
112     int toRadiance(Scene *sc, FILE *fp, int flreq, int flexc);
113     int writeRadiance(Scene *sc, const char *fspec,
114     int flreq, int flexc);
115    
116     /* Compute face area (and normal) */
117     double faceArea(const Scene *sc, const Face *f, Normal nrm);
118    
119     /* Eliminate duplicate vertices, return # joined */
120     int coalesceVertices(Scene *sc, double eps);
121    
122     /* Identify duplicate faces */
123     int findDuplicateFaces(Scene *sc);
124    
125     /* Delete indicated faces, return # deleted */
126     int deleteFaces(Scene *sc, int flreq, int flexc);
127    
128     /* Clear face selection */
129     void clearSelection(Scene *sc, int set);
130    
131     /* Invert face selection */
132     void invertSelection(Scene *sc);
133    
134     /* Count number of faces selected */
135     int numberSelected(Scene *sc);
136    
137     /* Select faces by object name (modifies current) */
138     void selectGroup(Scene *sc, const char *gname, int invert);
139    
140     /* Select faces by material name (modifies current) */
141     void selectMaterial(Scene *sc, const char *mname, int invert);
142    
143     /* Execute callback on indicated faces */
144     int foreachFace(Scene *sc, int (*cb)(Scene *, Face *, void *),
145     int flreq, int flexc, void *c_data);
146    
147     /* Remove texture coordinates from the indicated faces */
148     int removeTexture(Scene *sc, int flreq, int flexc);
149    
150     /* Remove surface normals from the indicated faces */
151     int removeNormals(Scene *sc, int flreq, int flexc);
152    
153     /* Change group for the indicated faces */
154     int changeGroup(Scene *sc, const char *gname,
155     int flreq, int flexc);
156    
157     /* Change material for the indicated faces */
158     int changeMaterial(Scene *sc, const char *mname,
159     int flreq, int flexc);
160    
161 greg 2.7 /* Add a vertex to our scene, returning index */
162 greg 2.5 int addVertex(Scene *sc, double x, double y, double z);
163    
164 greg 2.7 /* Add a texture coordinate to our scene, returning index */
165 greg 2.5 int addTexture(Scene *sc, double u, double v);
166    
167 greg 2.7 /* Add a surface normal to our scene, returning index */
168 greg 2.5 int addNormal(Scene *sc, double xn, double yn, double zn);
169    
170 greg 2.7 /* Set current group (sc->lastgrp) to given ID */
171 greg 2.5 void setGroup(Scene *sc, const char *nm);
172    
173 greg 2.7 /* Set current material (sc->lastmat) to given ID */
174 greg 2.5 void setMaterial(Scene *sc, const char *nm);
175    
176 greg 2.7 /* Add a new face to our scene, using current group and material */
177 greg 2.6 Face * addFace(Scene *sc, VNDX vid[], int nv);
178    
179 greg 2.9 /* Delete unreferenced vertices, normals, texture coords */
180     void deleteUnreferenced(Scene *sc);
181    
182 greg 2.1 /* Free a scene */
183     void freeScene(Scene *sc);
184    
185     /* Find an existing name in a list of names */
186     int findName(const char *nm, const char **nmlist, int n);
187    
188     /* Verbose mode global */
189     extern int verbose;
190    
191     extern char *emalloc(unsigned int n);
192     extern char *ecalloc(unsigned int ne, unsigned int n);
193     extern char *erealloc(char *cp, unsigned int n);
194     extern void efree(char *cp);
195    
196     #define CHUNKSIZ 128 /* object allocation chunk size */
197    
198     #define chunk_alloc(typ, arr, nold) \
199     ((nold)%CHUNKSIZ ? (arr) : \
200     (typ *)erealloc((char *)(arr), sizeof(typ)*((nold)+CHUNKSIZ)))
201    
202     #ifdef __cplusplus
203     }
204     #endif
205    
206     #endif /* ! _OBJUTIL_H_ */