1 |
|
#ifndef lint |
2 |
< |
static const char RCSid[] = "$Id"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
|
* Replace markers in Radiance scene description with objects or instances. |
7 |
|
* Created: 17 Feb 1991 Greg Ward |
8 |
|
*/ |
9 |
|
|
10 |
– |
#include <stdio.h> |
10 |
|
#include <stdlib.h> |
11 |
|
#include <ctype.h> |
12 |
|
#include <math.h> |
13 |
+ |
#include <stdio.h> |
14 |
|
|
15 |
+ |
#include "platform.h" |
16 |
+ |
#include "rtio.h" |
17 |
+ |
#include "rtprocess.h" |
18 |
|
#include "fvect.h" |
19 |
|
|
20 |
|
#ifdef M_PI |
26 |
|
#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) |
27 |
|
|
28 |
|
#define MAXVERT 6 /* maximum number of vertices for markers */ |
29 |
< |
#define MAXMARK 32 /* maximum number of markers */ |
29 |
> |
#define MAXMARK 128 /* maximum number of markers */ |
30 |
|
|
31 |
+ |
#define USE_XFORM 1 /* use !xform inline command */ |
32 |
+ |
#define USE_INSTANCE 2 /* use instance primitive */ |
33 |
+ |
#define USE_MESH 3 /* use mesh primitive */ |
34 |
+ |
|
35 |
|
typedef struct { |
36 |
|
short beg, end; /* beginning and ending vertex */ |
37 |
|
float len2; /* length squared */ |
42 |
|
double mscale; /* scale by this to get unit */ |
43 |
|
char *modin; /* input modifier indicating marker */ |
44 |
|
char *objname; /* output object file or octree */ |
45 |
< |
int doxform; /* true if xform, false if instance */ |
46 |
< |
} marker[MAXMARK]; /* array of markers */ |
45 |
> |
int usetype; /* one of USE_* above */ |
46 |
> |
} marker[MAXMARK+1]; /* array of markers */ |
47 |
|
int nmarkers = 0; /* number of markers */ |
48 |
|
|
49 |
|
int expand; /* expand commands? */ |
50 |
|
|
51 |
|
char *progname; |
52 |
|
|
53 |
+ |
static void convert(char *name, FILE *fin); |
54 |
+ |
static void cvcomm(char *fname, FILE *fin); |
55 |
+ |
static void cvobject(char *fname, FILE *fin); |
56 |
+ |
static void replace(char *fname, struct mrkr *m, char *mark, FILE *fin); |
57 |
+ |
static int edgecmp(const void *e1, const void *e2); |
58 |
+ |
static int buildxf(char *xf, double markscale, FILE *fin); |
59 |
+ |
static int addrot(char *xf, FVECT xp, FVECT yp, FVECT zp); |
60 |
|
|
61 |
< |
main(argc, argv) |
62 |
< |
int argc; |
63 |
< |
char *argv[]; |
61 |
> |
|
62 |
> |
int |
63 |
> |
main( |
64 |
> |
int argc, |
65 |
> |
char *argv[] |
66 |
> |
) |
67 |
|
{ |
68 |
|
FILE *fp; |
69 |
|
int i, j; |
74 |
|
do { |
75 |
|
switch (argv[i][1]) { |
76 |
|
case 'i': |
77 |
< |
marker[nmarkers].doxform = 0; |
77 |
> |
marker[nmarkers].usetype = USE_INSTANCE; |
78 |
|
marker[nmarkers].objname = argv[++i]; |
79 |
|
break; |
80 |
+ |
case 'I': |
81 |
+ |
marker[nmarkers].usetype = USE_MESH; |
82 |
+ |
marker[nmarkers].objname = argv[++i]; |
83 |
+ |
break; |
84 |
|
case 'x': |
85 |
< |
marker[nmarkers].doxform = 1; |
85 |
> |
marker[nmarkers].usetype = USE_XFORM; |
86 |
|
marker[nmarkers].objname = argv[++i]; |
87 |
|
break; |
88 |
|
case 'e': |
102 |
|
} while (argv[i][0] == '-'); |
103 |
|
if (marker[nmarkers].objname == NULL) |
104 |
|
goto userr; |
105 |
+ |
if (nmarkers >= MAXMARK) { |
106 |
+ |
fprintf(stderr, "%s: too many markers\n", progname); |
107 |
+ |
return 1; |
108 |
+ |
} |
109 |
|
marker[nmarkers++].modin = argv[i++]; |
85 |
– |
if (nmarkers >= MAXMARK) |
86 |
– |
break; |
110 |
|
marker[nmarkers].mscale = marker[nmarkers-1].mscale; |
111 |
|
} |
112 |
|
if (nmarkers == 0) |
129 |
|
convert(argv[i], fp); |
130 |
|
fclose(fp); |
131 |
|
} |
132 |
< |
exit(0); |
132 |
> |
return 0; |
133 |
|
userr: |
134 |
|
fprintf(stderr, |
135 |
< |
"Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname .. [file ..]\n", |
135 |
> |
"Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree|-I mesh} modname .. [file ..]\n", |
136 |
|
progname); |
137 |
< |
exit(1); |
137 |
> |
return 1; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
< |
convert(name, fin) /* replace marks in a stream */ |
142 |
< |
char *name; |
143 |
< |
register FILE *fin; |
141 |
> |
void |
142 |
> |
convert( /* replace marks in a stream */ |
143 |
> |
char *name, |
144 |
> |
register FILE *fin |
145 |
> |
) |
146 |
|
{ |
147 |
|
register int c; |
148 |
|
|
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
< |
cvcomm(fname, fin) /* convert a command */ |
171 |
< |
char *fname; |
172 |
< |
FILE *fin; |
170 |
> |
void |
171 |
> |
cvcomm( /* convert a command */ |
172 |
> |
char *fname, |
173 |
> |
FILE *fin |
174 |
> |
) |
175 |
|
{ |
176 |
< |
FILE *pin, *popen(); |
176 |
> |
FILE *pin; |
177 |
|
char buf[512], *fgetline(); |
178 |
|
|
179 |
|
fgetline(buf, sizeof(buf), fin); |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
< |
cvobject(fname, fin) /* convert an object */ |
195 |
< |
char *fname; |
196 |
< |
FILE *fin; |
194 |
> |
void |
195 |
> |
cvobject( /* convert an object */ |
196 |
> |
char *fname, |
197 |
> |
FILE *fin |
198 |
> |
) |
199 |
|
{ |
200 |
|
extern char *fgetword(); |
201 |
|
char buf[128], typ[16], nam[128]; |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
< |
replace(fname, m, mark, fin) /* replace marker */ |
242 |
< |
char *fname; |
243 |
< |
register struct mrkr *m; |
244 |
< |
char *mark; |
245 |
< |
FILE *fin; |
241 |
> |
void |
242 |
> |
replace( /* replace marker */ |
243 |
> |
char *fname, |
244 |
> |
register struct mrkr *m, |
245 |
> |
char *mark, |
246 |
> |
FILE *fin |
247 |
> |
) |
248 |
|
{ |
249 |
|
int n; |
250 |
|
char buf[256]; |
251 |
|
|
252 |
|
buf[0] = '\0'; /* bug fix thanks to schorsch */ |
253 |
< |
if (m->doxform) { |
254 |
< |
sprintf(buf, "xform -e -n %s", mark); |
253 |
> |
if (m->usetype == USE_XFORM) { |
254 |
> |
sprintf(buf, "xform -n %s", mark); |
255 |
|
if (m->modout != NULL) |
256 |
|
sprintf(buf+strlen(buf), " -m %s", m->modout); |
257 |
|
if (buildxf(buf+strlen(buf), m->mscale, fin) < 0) |
265 |
|
} else { |
266 |
|
if ((n = buildxf(buf, m->mscale, fin)) < 0) |
267 |
|
goto badxf; |
268 |
< |
printf("\n%s instance %s\n", |
269 |
< |
m->modout==NULL?"void":m->modout, mark); |
268 |
> |
printf("\n%s %s %s\n", |
269 |
> |
m->modout==NULL?"void":m->modout, |
270 |
> |
m->usetype==USE_INSTANCE?"instance":"mesh", |
271 |
> |
mark); |
272 |
|
printf("%d %s%s\n0\n0\n", n+1, m->objname, buf); |
273 |
|
} |
274 |
|
return; |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
< |
edgecmp(e1, e2) /* compare two edges, descending order */ |
283 |
< |
EDGE *e1, *e2; |
282 |
> |
int |
283 |
> |
edgecmp( /* compare two edges, descending order */ |
284 |
> |
const void *e1, |
285 |
> |
const void *e2 |
286 |
> |
) |
287 |
|
{ |
288 |
< |
if (e1->len2 > e2->len2) |
288 |
> |
if (((EDGE*)e1)->len2 > ((EDGE*)e2)->len2) |
289 |
|
return(-1); |
290 |
< |
if (e1->len2 < e2->len2) |
290 |
> |
if (((EDGE*)e1)->len2 < ((EDGE*)e2)->len2) |
291 |
|
return(1); |
292 |
|
return(0); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
|
int |
297 |
< |
buildxf(xf, markscale, fin) /* build transform for marker */ |
298 |
< |
register char *xf; |
299 |
< |
double markscale; |
300 |
< |
FILE *fin; |
297 |
> |
buildxf( /* build transform for marker */ |
298 |
> |
register char *xf, |
299 |
> |
double markscale, |
300 |
> |
FILE *fin |
301 |
> |
) |
302 |
|
{ |
303 |
|
static FVECT vlist[MAXVERT]; |
304 |
|
static EDGE elist[MAXVERT]; |
376 |
|
} |
377 |
|
|
378 |
|
|
379 |
< |
addrot(xf, xp, yp, zp) /* compute rotation (x,y,z) => (xp,yp,zp) */ |
380 |
< |
register char *xf; |
381 |
< |
FVECT xp, yp, zp; |
379 |
> |
int |
380 |
> |
addrot( /* compute rotation (x,y,z) => (xp,yp,zp) */ |
381 |
> |
register char *xf, |
382 |
> |
FVECT xp, |
383 |
> |
FVECT yp, |
384 |
> |
FVECT zp |
385 |
> |
) |
386 |
|
{ |
387 |
|
int n; |
388 |
|
double theta; |