1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Make illum sources for optimizing rendering process |
6 |
|
*/ |
7 |
|
|
11 |
– |
#include "mkillum.h" |
12 |
– |
|
8 |
|
#include <signal.h> |
14 |
– |
|
9 |
|
#include <ctype.h> |
10 |
|
|
11 |
+ |
#include "platform.h" |
12 |
+ |
#include "mkillum.h" |
13 |
+ |
#include "random.h" |
14 |
+ |
|
15 |
|
/* default parameters */ |
16 |
|
#define SAMPDENS 48 /* points per projected steradian */ |
17 |
|
#define NSAMPS 32 /* samples per point */ |
23 |
|
#define S_COMPL 2 /* select all but element */ |
24 |
|
#define S_ALL 3 /* select all */ |
25 |
|
|
28 |
– |
/* rtrace command and defaults */ |
29 |
– |
char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-di+", |
30 |
– |
"-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", }; |
31 |
– |
int rtargc = 14; |
32 |
– |
/* overriding rtrace options */ |
33 |
– |
char *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", NULL }; |
34 |
– |
|
35 |
– |
struct rtproc rt; /* our rtrace process */ |
36 |
– |
|
26 |
|
struct illum_args thisillum = { /* our illum and default values */ |
27 |
|
0, |
28 |
|
DFLMAT, |
37 |
|
char matcheck[MAXSTR]; /* current material to include or exclude */ |
38 |
|
int matselect = S_ALL; /* selection criterion */ |
39 |
|
|
51 |
– |
FUN ofun[NUMOTYPE] = INIT_OTYPE; /* object types */ |
52 |
– |
|
40 |
|
int gargc; /* global argc */ |
41 |
|
char **gargv; /* global argv */ |
55 |
– |
#define progname gargv[0] |
42 |
|
|
43 |
|
int doneheader = 0; /* printed header yet? */ |
44 |
|
#define checkhead() if (!doneheader++) printhead(gargc,gargv) |
45 |
|
|
46 |
|
int warnings = 1; /* print warnings? */ |
47 |
|
|
48 |
< |
extern char *fgetline(), *fgetword(), *sskip(), |
49 |
< |
*atos(), *iskip(), *fskip(), *strcpy(); |
50 |
< |
extern FILE *popen(); |
48 |
> |
void init(char *octnm, int np); |
49 |
> |
void filter(register FILE *infp, char *name); |
50 |
> |
void xoptions(char *s, char *nm); |
51 |
> |
void printopts(void); |
52 |
> |
void printhead(register int ac, register char **av); |
53 |
> |
void xobject(FILE *fp, char *nm); |
54 |
|
|
55 |
|
|
56 |
< |
main(argc, argv) /* compute illum distributions using rtrace */ |
57 |
< |
int argc; |
58 |
< |
char *argv[]; |
56 |
> |
int |
57 |
> |
main( /* compute illum distributions using rtrace */ |
58 |
> |
int argc, |
59 |
> |
char *argv[] |
60 |
> |
) |
61 |
|
{ |
62 |
< |
extern char *getenv(), *getpath(); |
72 |
< |
char *rtpath; |
62 |
> |
int nprocs = 1; |
63 |
|
FILE *fp; |
64 |
+ |
int rval; |
65 |
|
register int i; |
66 |
|
/* set global arguments */ |
67 |
|
gargv = argv; |
68 |
< |
/* set up rtrace command */ |
69 |
< |
for (i = 1; i < argc; i++) { |
70 |
< |
if (argv[i][0] == '<' && !argv[i][1]) |
68 |
> |
progname = gargv[0]; |
69 |
> |
/* set up rendering defaults */ |
70 |
> |
dstrsrc = 0.25; |
71 |
> |
directrelay = 3; |
72 |
> |
directvis = 0; |
73 |
> |
ambounce = 2; |
74 |
> |
/* get options from command line */ |
75 |
> |
for (i = 1; i < argc-1; i++) { |
76 |
> |
while ((rval = expandarg(&argc, &argv, i)) > 0) |
77 |
> |
; |
78 |
> |
if (rval < 0) { |
79 |
> |
sprintf(errmsg, "cannot expand '%s'", argv[i]); |
80 |
> |
error(SYSTEM, errmsg); |
81 |
> |
} |
82 |
> |
if (argv[i][0] != '-') |
83 |
|
break; |
84 |
< |
rtargv[rtargc++] = argv[i]; |
85 |
< |
if (argv[i][0] == '-' && argv[i][1] == 'w') |
86 |
< |
warnings = !warnings; |
84 |
< |
} |
85 |
< |
if ((gargc = i) < 2) |
86 |
< |
error(USER, "too few arguments"); |
87 |
< |
rtargc--; |
88 |
< |
for (i = 0; myrtopts[i] != NULL; i++) |
89 |
< |
rtargv[rtargc++] = myrtopts[i]; |
90 |
< |
rtargv[rtargc++] = argv[gargc-1]; |
91 |
< |
rtargv[rtargc] = NULL; |
92 |
< |
/* just asking for defaults? */ |
93 |
< |
if (!strcmp(argv[gargc-1], "-defaults")) { |
94 |
< |
printopts(); fflush(stdout); |
95 |
< |
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
96 |
< |
if (rtpath == NULL) { |
97 |
< |
eputs(rtargv[0]); |
98 |
< |
eputs(": command not found\n"); |
99 |
< |
exit(1); |
84 |
> |
if (!strcmp(argv[i], "-w")) { |
85 |
> |
warnings = 0; |
86 |
> |
continue; |
87 |
|
} |
88 |
< |
execv(rtpath, rtargv); |
89 |
< |
perror(rtpath); |
90 |
< |
exit(1); |
88 |
> |
if (!strcmp(argv[i], "-n")) { |
89 |
> |
nprocs = atoi(argv[++i]); |
90 |
> |
if (nprocs <= 0) |
91 |
> |
error(USER, "illegal number of processes"); |
92 |
> |
continue; |
93 |
> |
} |
94 |
> |
if (!strcmp(argv[i], "-defaults")) { |
95 |
> |
printopts(); |
96 |
> |
print_rdefaults(); |
97 |
> |
quit(0); |
98 |
> |
} |
99 |
> |
rval = getrenderopt(argc-i, argv+i); |
100 |
> |
if (rval < 0) { |
101 |
> |
sprintf(errmsg, "bad render option at '%s'", argv[i]); |
102 |
> |
error(USER, errmsg); |
103 |
> |
} |
104 |
> |
i += rval; |
105 |
|
} |
106 |
+ |
gargc = ++i; |
107 |
+ |
/* add "mandatory" render options */ |
108 |
+ |
do_irrad = 0; |
109 |
+ |
if (gargc > argc || argv[gargc-1][0] == '-') |
110 |
+ |
error(USER, "missing octree argument"); |
111 |
|
/* else initialize and run our calculation */ |
112 |
< |
init(); |
113 |
< |
if (gargc+1 < argc) |
112 |
> |
init(argv[gargc-1], nprocs); |
113 |
> |
if (gargc < argc) { |
114 |
> |
if (gargc == argc-1 || argv[gargc][0] != '<' || argv[gargc][1]) |
115 |
> |
error(USER, "Use '< file1 file2 ..' for multiple inputs"); |
116 |
|
for (i = gargc+1; i < argc; i++) { |
117 |
|
if ((fp = fopen(argv[i], "r")) == NULL) { |
118 |
|
sprintf(errmsg, |
122 |
|
filter(fp, argv[i]); |
123 |
|
fclose(fp); |
124 |
|
} |
125 |
< |
else |
125 |
> |
} else |
126 |
|
filter(stdin, "standard input"); |
127 |
|
quit(0); |
128 |
+ |
return 0; /* pro forma return */ |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
< |
quit(status) /* exit with status */ |
133 |
< |
int status; |
132 |
> |
void |
133 |
> |
init(char *octnm, int np) /* start rendering process(es) */ |
134 |
|
{ |
126 |
– |
int rtstat; |
127 |
– |
|
128 |
– |
rtstat = close_process(rt.pd); |
129 |
– |
if (status == 0) |
130 |
– |
if (rtstat < 0) |
131 |
– |
error(WARNING, |
132 |
– |
"unknown return status from rtrace process"); |
133 |
– |
else |
134 |
– |
status = rtstat; |
135 |
– |
exit(status); |
136 |
– |
} |
137 |
– |
|
138 |
– |
|
139 |
– |
init() /* start rtrace and set up buffers */ |
140 |
– |
{ |
141 |
– |
extern int o_face(), o_sphere(), o_ring(); |
142 |
– |
int maxbytes; |
143 |
– |
/* set up object functions */ |
144 |
– |
ofun[OBJ_FACE].funp = o_face; |
145 |
– |
ofun[OBJ_SPHERE].funp = o_sphere; |
146 |
– |
ofun[OBJ_RING].funp = o_ring; |
135 |
|
/* set up signal handling */ |
136 |
+ |
signal(SIGINT, quit); |
137 |
+ |
#ifdef SIGHUP |
138 |
+ |
signal(SIGHUP, quit); |
139 |
+ |
#endif |
140 |
+ |
#ifdef SIGTERM |
141 |
+ |
signal(SIGTERM, quit); |
142 |
+ |
#endif |
143 |
+ |
#ifdef SIGPIPE |
144 |
|
signal(SIGPIPE, quit); |
145 |
< |
/* start rtrace process */ |
146 |
< |
errno = 0; |
147 |
< |
maxbytes = open_process(rt.pd, rtargv); |
152 |
< |
if (maxbytes == 0) { |
153 |
< |
eputs(rtargv[0]); |
154 |
< |
eputs(": command not found\n"); |
155 |
< |
exit(1); |
156 |
< |
} |
157 |
< |
if (maxbytes < 0) |
158 |
< |
error(SYSTEM, "cannot start rtrace process"); |
159 |
< |
rt.bsiz = maxbytes/(6*sizeof(float)); |
160 |
< |
rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--); |
161 |
< |
rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz); |
162 |
< |
if (rt.buf == NULL || rt.dest == NULL) |
163 |
< |
error(SYSTEM, "out of memory in init"); |
164 |
< |
rt.nrays = 0; |
165 |
< |
/* set up urand */ |
166 |
< |
initurand(2048); |
145 |
> |
#endif |
146 |
> |
/* start rendering process(es) */ |
147 |
> |
ray_pinit(octnm, np); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
< |
eputs(s) /* put string to stderr */ |
152 |
< |
register char *s; |
151 |
> |
void |
152 |
> |
eputs( /* put string to stderr */ |
153 |
> |
register char *s |
154 |
> |
) |
155 |
|
{ |
156 |
|
static int midline = 0; |
157 |
|
|
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
+ |
void |
169 |
|
wputs(s) /* print warning if enabled */ |
170 |
|
char *s; |
171 |
|
{ |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
< |
filter(infp, name) /* process stream */ |
178 |
< |
register FILE *infp; |
179 |
< |
char *name; |
177 |
> |
void |
178 |
> |
filter( /* process stream */ |
179 |
> |
register FILE *infp, |
180 |
> |
char *name |
181 |
> |
) |
182 |
|
{ |
183 |
|
char buf[512]; |
184 |
|
FILE *pfp; |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
< |
xoptions(s, nm) /* process options in string s */ |
212 |
< |
char *s; |
213 |
< |
char *nm; |
211 |
> |
void |
212 |
> |
xoptions( /* process options in string s */ |
213 |
> |
char *s, |
214 |
> |
char *nm |
215 |
> |
) |
216 |
|
{ |
217 |
|
extern FILE *freopen(); |
218 |
|
char buf[64]; |
229 |
|
case ' ': |
230 |
|
case '\t': |
231 |
|
case '\n': |
232 |
+ |
case '\r': |
233 |
+ |
case '\f': |
234 |
|
cp++; |
235 |
|
continue; |
236 |
|
case 'm': /* material name */ |
237 |
|
if (*++cp != '=') |
238 |
|
break; |
239 |
< |
if (!*++cp) |
239 |
> |
if (!*++cp || isspace(*cp)) |
240 |
|
break; |
241 |
|
atos(thisillum.matname, MAXSTR, cp); |
242 |
|
cp = sskip(cp); |
248 |
|
case 'f': /* data file name */ |
249 |
|
if (*++cp != '=') |
250 |
|
break; |
251 |
< |
if (!*++cp) { |
251 |
> |
if (!*++cp || isspace(*cp)) { |
252 |
|
strcpy(thisillum.datafile,thisillum.matname); |
253 |
|
thisillum.dfnum = 0; |
254 |
|
thisillum.flags &= ~IL_DATCLB; |
298 |
|
case 'd': /* point sample density */ |
299 |
|
if (*++cp != '=') |
300 |
|
break; |
301 |
< |
if (!isintd(++cp, " \t\n")) |
301 |
> |
if (!isintd(++cp, " \t\n\r")) |
302 |
|
break; |
303 |
|
thisillum.sampdens = atoi(cp); |
304 |
|
cp = sskip(cp); |
306 |
|
case 's': /* point super-samples */ |
307 |
|
if (*++cp != '=') |
308 |
|
break; |
309 |
< |
if (!isintd(++cp, " \t\n")) |
309 |
> |
if (!isintd(++cp, " \t\n\r")) |
310 |
|
break; |
311 |
|
thisillum.nsamps = atoi(cp); |
312 |
|
cp = sskip(cp); |
324 |
|
case 'b': /* brightness */ |
325 |
|
if (*++cp != '=') |
326 |
|
break; |
327 |
< |
if (!isfltd(++cp, " \t\n")) |
327 |
> |
if (!isfltd(++cp, " \t\n\r")) |
328 |
|
break; |
329 |
|
thisillum.minbrt = atof(cp); |
330 |
|
if (thisillum.minbrt < 0.) |
334 |
|
case 'o': /* output file */ |
335 |
|
if (*++cp != '=') |
336 |
|
break; |
337 |
< |
if (!*++cp) |
337 |
> |
if (!*++cp || isspace(*cp)) |
338 |
|
break; |
339 |
|
atos(buf, sizeof(buf), cp); |
340 |
|
cp = sskip(cp); |
352 |
|
return; |
353 |
|
} |
354 |
|
opterr: /* skip faulty option */ |
355 |
< |
cp = sskip(cp); |
355 |
> |
while (*cp && !isspace(*cp)) |
356 |
> |
cp++; |
357 |
|
nerrs++; |
358 |
|
} |
359 |
|
/* print header? */ |
371 |
|
printf("# %s", s+2); |
372 |
|
} |
373 |
|
|
374 |
< |
|
375 |
< |
printopts() /* print out option default values */ |
374 |
> |
void |
375 |
> |
printopts(void) /* print out option default values */ |
376 |
|
{ |
377 |
|
printf("m=%-15s\t\t# material name\n", thisillum.matname); |
378 |
|
printf("f=%-15s\t\t# data file name\n", thisillum.datafile); |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
< |
printhead(ac, av) /* print out header */ |
397 |
< |
register int ac; |
398 |
< |
register char **av; |
396 |
> |
void |
397 |
> |
printhead( /* print out header */ |
398 |
> |
register int ac, |
399 |
> |
register char **av |
400 |
> |
) |
401 |
|
{ |
402 |
|
putchar('#'); |
403 |
|
while (ac-- > 0) { |
408 |
|
} |
409 |
|
|
410 |
|
|
411 |
< |
xobject(fp, nm) /* translate an object from fp */ |
412 |
< |
FILE *fp; |
413 |
< |
char *nm; |
411 |
> |
void |
412 |
> |
xobject( /* translate an object from fp */ |
413 |
> |
FILE *fp, |
414 |
> |
char *nm |
415 |
> |
) |
416 |
|
{ |
417 |
|
OBJREC thisobj; |
418 |
|
char str[MAXSTR]; |
423 |
|
if (fgetword(str, MAXSTR, fp) == NULL) |
424 |
|
goto readerr; |
425 |
|
/* is it an alias? */ |
426 |
< |
if (!strcmp(str, ALIASID)) { |
426 |
> |
if (!strcmp(str, ALIASKEY)) { |
427 |
|
if (fgetword(str, MAXSTR, fp) == NULL) |
428 |
|
goto readerr; |
429 |
< |
printf("\n%s %s %s", thisillum.altmat, ALIASID, str); |
429 |
> |
printf("\n%s %s %s", thisillum.altmat, ALIASKEY, str); |
430 |
|
if (fgetword(str, MAXSTR, fp) == NULL) |
431 |
|
goto readerr; |
432 |
|
printf("\t%s\n", str); |
463 |
|
checkhead(); |
464 |
|
/* process object */ |
465 |
|
if (doit) |
466 |
< |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm); |
466 |
> |
switch (thisobj.otype) { |
467 |
> |
case OBJ_FACE: |
468 |
> |
my_face(&thisobj, &thisillum, nm); |
469 |
> |
break; |
470 |
> |
case OBJ_SPHERE: |
471 |
> |
my_sphere(&thisobj, &thisillum, nm); |
472 |
> |
break; |
473 |
> |
case OBJ_RING: |
474 |
> |
my_ring(&thisobj, &thisillum, nm); |
475 |
> |
break; |
476 |
> |
default: |
477 |
> |
my_default(&thisobj, &thisillum, nm); |
478 |
> |
break; |
479 |
> |
} |
480 |
|
else |
481 |
|
printobj(thisillum.altmat, &thisobj); |
482 |
|
/* free arguments */ |
483 |
|
freefargs(&thisobj.oargs); |
484 |
|
return; |
485 |
|
readerr: |
486 |
< |
sprintf(errmsg, "(%s): error reading scene", nm); |
486 |
> |
sprintf(errmsg, "(%s): error reading input", nm); |
487 |
|
error(USER, errmsg); |
488 |
|
} |