8 |
|
#include <signal.h> |
9 |
|
#include <ctype.h> |
10 |
|
|
11 |
< |
#include "platform.h" |
11 |
> |
#include "paths.h" /* win_popen() */ |
12 |
|
#include "mkillum.h" |
13 |
– |
#include "random.h" |
13 |
|
|
14 |
|
/* default parameters */ |
15 |
|
#define SAMPDENS 48 /* points per projected steradian */ |
22 |
|
#define S_COMPL 2 /* select all but element */ |
23 |
|
#define S_ALL 3 /* select all */ |
24 |
|
|
26 |
– |
/* rtrace command and defaults */ |
27 |
– |
char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-", |
28 |
– |
"-ab", "2", "-ad", "1024", "-as", "512", "-aa", ".1", }; |
29 |
– |
int rtargc = 14; |
30 |
– |
/* overriding rtrace options */ |
31 |
– |
char *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-", |
32 |
– |
"-fff", "-y", "0", NULL }; |
33 |
– |
|
34 |
– |
struct rtproc rt0; /* head of rtrace process list */ |
35 |
– |
|
25 |
|
struct illum_args thisillum = { /* our illum and default values */ |
26 |
|
0, |
27 |
|
DFLMAT, |
36 |
|
char matcheck[MAXSTR]; /* current material to include or exclude */ |
37 |
|
int matselect = S_ALL; /* selection criterion */ |
38 |
|
|
50 |
– |
FUN ofun[NUMOTYPE] = INIT_OTYPE; /* object types */ |
51 |
– |
|
52 |
– |
char persistfn[] = "pfXXXXXX"; /* persist file name */ |
53 |
– |
|
39 |
|
int gargc; /* global argc */ |
40 |
|
char **gargv; /* global argv */ |
56 |
– |
#define progname gargv[0] |
41 |
|
|
42 |
|
int doneheader = 0; /* printed header yet? */ |
43 |
|
#define checkhead() if (!doneheader++) printhead(gargc,gargv) |
44 |
|
|
45 |
|
int warnings = 1; /* print warnings? */ |
46 |
|
|
47 |
< |
int done_rprocs(struct rtproc *rtp); |
48 |
< |
void init(int np); |
65 |
< |
void filter(register FILE *infp, char *name); |
47 |
> |
void init(char *octnm, int np); |
48 |
> |
void filter(FILE *infp, char *name); |
49 |
|
void xoptions(char *s, char *nm); |
50 |
|
void printopts(void); |
51 |
< |
void printhead(register int ac, register char **av); |
51 |
> |
void printhead(int ac, char **av); |
52 |
|
void xobject(FILE *fp, char *nm); |
53 |
|
|
54 |
|
|
59 |
|
) |
60 |
|
{ |
61 |
|
int nprocs = 1; |
79 |
– |
char *rtpath; |
62 |
|
FILE *fp; |
63 |
< |
register int i; |
63 |
> |
int rval; |
64 |
> |
int i; |
65 |
|
/* set global arguments */ |
66 |
|
gargv = argv; |
67 |
< |
/* check for -n option */ |
68 |
< |
if (!strcmp(argv[1], "-n")) { |
69 |
< |
nprocs = atoi(argv[2]); |
70 |
< |
if (nprocs <= 0) |
71 |
< |
error(USER, "illegal number of processes"); |
72 |
< |
i = 3; |
73 |
< |
} else |
74 |
< |
i = 1; |
75 |
< |
/* set up rtrace command */ |
76 |
< |
for ( ; i < argc; i++) { |
77 |
< |
if (argv[i][0] == '<' && argv[i][1] == '\0') |
67 |
> |
progname = gargv[0]; |
68 |
> |
/* set up rendering defaults */ |
69 |
> |
dstrsrc = 0.5; |
70 |
> |
directrelay = 3; |
71 |
> |
ambounce = 2; |
72 |
> |
/* get options from command line */ |
73 |
> |
for (i = 1; i < argc; i++) { |
74 |
> |
while ((rval = expandarg(&argc, &argv, i)) > 0) |
75 |
> |
; |
76 |
> |
if (rval < 0) { |
77 |
> |
sprintf(errmsg, "cannot expand '%s'", argv[i]); |
78 |
> |
error(SYSTEM, errmsg); |
79 |
> |
} |
80 |
> |
if (argv[i][0] != '-') |
81 |
|
break; |
82 |
< |
rtargv[rtargc++] = argv[i]; |
83 |
< |
if (argv[i][0] == '-' && argv[i][1] == 'w') |
84 |
< |
switch (argv[i][2]) { |
99 |
< |
case '\0': |
100 |
< |
warnings = !warnings; |
101 |
< |
break; |
102 |
< |
case '+': |
103 |
< |
case 'T': case 't': |
104 |
< |
case 'Y': case 'y': |
105 |
< |
case '1': |
106 |
< |
warnings = 1; |
107 |
< |
break; |
108 |
< |
case '-': |
109 |
< |
case 'F': case 'f': |
110 |
< |
case 'N': case 'n': |
111 |
< |
case '0': |
112 |
< |
warnings = 0; |
113 |
< |
break; |
114 |
< |
} |
115 |
< |
} |
116 |
< |
gargc = i; |
117 |
< |
if (!strcmp(rtargv[--rtargc], "-defaults")) |
118 |
< |
nprocs = 0; |
119 |
< |
if (nprocs > 1) { /* add persist file if parallel invocation */ |
120 |
< |
rtargv[rtargc++] = "-PP"; |
121 |
< |
rtargv[rtargc++] = mktemp(persistfn); |
122 |
< |
} |
123 |
< |
/* add "mandatory" rtrace options */ |
124 |
< |
for (i = 0; myrtopts[i] != NULL; i++) |
125 |
< |
rtargv[rtargc++] = myrtopts[i]; |
126 |
< |
/* finally, put back final argument */ |
127 |
< |
rtargv[rtargc++] = argv[gargc-1]; |
128 |
< |
rtargv[rtargc] = NULL; |
129 |
< |
if (!nprocs) { /* just asking for defaults? */ |
130 |
< |
printopts(); fflush(stdout); |
131 |
< |
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
132 |
< |
if (rtpath == NULL) { |
133 |
< |
eputs(rtargv[0]); |
134 |
< |
eputs(": command not found\n"); |
135 |
< |
exit(1); |
82 |
> |
if (!strcmp(argv[i], "-w")) { |
83 |
> |
warnings = 0; |
84 |
> |
continue; |
85 |
|
} |
86 |
< |
execv(rtpath, rtargv); |
87 |
< |
perror(rtpath); /* execv() should not return */ |
88 |
< |
exit(1); |
86 |
> |
if (!strcmp(argv[i], "-n")) { |
87 |
> |
nprocs = atoi(argv[++i]); |
88 |
> |
if (nprocs <= 0) |
89 |
> |
error(USER, "illegal number of processes"); |
90 |
> |
continue; |
91 |
> |
} |
92 |
> |
if (!strcmp(argv[i], "-defaults")) { |
93 |
> |
printopts(); |
94 |
> |
print_rdefaults(); |
95 |
> |
quit(0); |
96 |
> |
} |
97 |
> |
rval = getrenderopt(argc-i, argv+i); |
98 |
> |
if (rval < 0) { |
99 |
> |
sprintf(errmsg, "bad render option at '%s'", argv[i]); |
100 |
> |
error(USER, errmsg); |
101 |
> |
} |
102 |
> |
i += rval; |
103 |
|
} |
104 |
< |
if (gargc < 2 || argv[gargc-1][0] == '-') |
104 |
> |
gargc = ++i; |
105 |
> |
/* add "mandatory" render options */ |
106 |
> |
do_irrad = 0; |
107 |
> |
if (gargc > argc || argv[gargc-1][0] == '-') |
108 |
|
error(USER, "missing octree argument"); |
109 |
|
/* else initialize and run our calculation */ |
110 |
< |
init(nprocs); |
111 |
< |
if (gargc+1 < argc) |
110 |
> |
init(argv[gargc-1], nprocs); |
111 |
> |
if (gargc < argc) { |
112 |
> |
if (gargc == argc-1 || argv[gargc][0] != '<' || argv[gargc][1]) |
113 |
> |
error(USER, "use '< file1 file2 ..' for multiple inputs"); |
114 |
|
for (i = gargc+1; i < argc; i++) { |
115 |
|
if ((fp = fopen(argv[i], "r")) == NULL) { |
116 |
|
sprintf(errmsg, |
120 |
|
filter(fp, argv[i]); |
121 |
|
fclose(fp); |
122 |
|
} |
123 |
< |
else |
123 |
> |
} else |
124 |
|
filter(stdin, "standard input"); |
125 |
|
quit(0); |
126 |
+ |
return 0; /* pro forma return */ |
127 |
|
} |
128 |
|
|
160 |
– |
static void |
161 |
– |
killpersist(void) /* kill persistent rtrace process */ |
162 |
– |
{ |
163 |
– |
FILE *fp = fopen(persistfn, "r"); |
164 |
– |
int pid; |
129 |
|
|
166 |
– |
if (fp == NULL) |
167 |
– |
return; |
168 |
– |
if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0) |
169 |
– |
unlink(persistfn); |
170 |
– |
fclose(fp); |
171 |
– |
} |
172 |
– |
|
173 |
– |
int |
174 |
– |
done_rprocs(struct rtproc *rtp) |
175 |
– |
{ |
176 |
– |
int st0, st1 = 0; |
177 |
– |
|
178 |
– |
if (rtp->next != NULL) { /* close last opened first! */ |
179 |
– |
st1 = done_rprocs(rtp->next); |
180 |
– |
free((void *)rtp->next); |
181 |
– |
rtp->next = NULL; |
182 |
– |
} |
183 |
– |
st0 = close_process(&rtp->pd); |
184 |
– |
if (st0 < 0) |
185 |
– |
error(WARNING, "unknown return status from rtrace process"); |
186 |
– |
else if (st0 > 0) |
187 |
– |
return(st0); |
188 |
– |
return(st1); |
189 |
– |
} |
190 |
– |
|
130 |
|
void |
131 |
< |
quit(int status) /* exit with status */ |
131 |
> |
init(char *octnm, int np) /* start rendering process(es) */ |
132 |
|
{ |
194 |
– |
int rtstat; |
195 |
– |
|
196 |
– |
if (rt0.next != NULL) /* terminate persistent rtrace */ |
197 |
– |
killpersist(); |
198 |
– |
/* clean up rtrace process(es) */ |
199 |
– |
rtstat = done_rprocs(&rt0); |
200 |
– |
if (status == 0) |
201 |
– |
status = rtstat; |
202 |
– |
exit(status); |
203 |
– |
} |
204 |
– |
|
205 |
– |
void |
206 |
– |
init(int np) /* start rtrace and set up buffers */ |
207 |
– |
{ |
208 |
– |
struct rtproc *rtp; |
209 |
– |
int i; |
210 |
– |
int maxbytes; |
211 |
– |
/* set up object functions */ |
212 |
– |
ofun[OBJ_FACE].funp = o_face; |
213 |
– |
ofun[OBJ_SPHERE].funp = o_sphere; |
214 |
– |
ofun[OBJ_RING].funp = o_ring; |
133 |
|
/* set up signal handling */ |
134 |
|
signal(SIGINT, quit); |
135 |
|
#ifdef SIGHUP |
141 |
|
#ifdef SIGPIPE |
142 |
|
signal(SIGPIPE, quit); |
143 |
|
#endif |
144 |
< |
rtp = &rt0; /* start rtrace process(es) */ |
145 |
< |
for (i = 0; i++ < np; ) { |
228 |
< |
errno = 0; |
229 |
< |
maxbytes = open_process(&rtp->pd, rtargv); |
230 |
< |
if (maxbytes == 0) { |
231 |
< |
eputs(rtargv[0]); |
232 |
< |
eputs(": command not found\n"); |
233 |
< |
exit(1); |
234 |
< |
} |
235 |
< |
if (maxbytes < 0) |
236 |
< |
error(SYSTEM, "cannot start rtrace process"); |
237 |
< |
rtp->bsiz = maxbytes/(6*sizeof(float)); |
238 |
< |
rtp->buf = (float *)malloc(6*sizeof(float)*rtp->bsiz--); |
239 |
< |
rtp->dest = (float **)calloc(rtp->bsiz, sizeof(float *)); |
240 |
< |
if (rtp->buf == NULL || rtp->dest == NULL) |
241 |
< |
error(SYSTEM, "out of memory in init"); |
242 |
< |
rtp->nrays = 0; |
243 |
< |
if (i == np) /* last process? */ |
244 |
< |
break; |
245 |
< |
if (np > 1) |
246 |
< |
sleep(2); /* wait for persist file */ |
247 |
< |
rtp->next = (struct rtproc *)malloc(sizeof(struct rtproc)); |
248 |
< |
if (rtp->next == NULL) |
249 |
< |
error(SYSTEM, "out of memory in init"); |
250 |
< |
rtp = rtp->next; |
251 |
< |
} |
252 |
< |
rtp->next = NULL; |
253 |
< |
/* set up urand */ |
254 |
< |
initurand(16384); |
144 |
> |
/* start rendering process(es) */ |
145 |
> |
ray_pinit(octnm, np); |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
void |
150 |
|
eputs( /* put string to stderr */ |
151 |
< |
register char *s |
151 |
> |
char *s |
152 |
|
) |
153 |
|
{ |
154 |
|
static int midline = 0; |
173 |
|
|
174 |
|
|
175 |
|
void |
176 |
+ |
quit(ec) /* make sure exit is called */ |
177 |
+ |
int ec; |
178 |
+ |
{ |
179 |
+ |
if (ray_pnprocs > 0) /* close children if any */ |
180 |
+ |
ray_pclose(0); |
181 |
+ |
exit(ec); |
182 |
+ |
} |
183 |
+ |
|
184 |
+ |
|
185 |
+ |
void |
186 |
|
filter( /* process stream */ |
187 |
< |
register FILE *infp, |
187 |
> |
FILE *infp, |
188 |
|
char *name |
189 |
|
) |
190 |
|
{ |
191 |
|
char buf[512]; |
192 |
|
FILE *pfp; |
193 |
< |
register int c; |
193 |
> |
int c; |
194 |
|
|
195 |
|
while ((c = getc(infp)) != EOF) { |
196 |
|
if (isspace(c)) |
222 |
|
char *nm |
223 |
|
) |
224 |
|
{ |
324 |
– |
extern FILE *freopen(); |
225 |
|
char buf[64]; |
226 |
+ |
int negax; |
227 |
|
int nerrs = 0; |
228 |
< |
register char *cp; |
228 |
> |
char *cp; |
229 |
|
|
230 |
|
if (strncmp(s, "#@mkillum", 9) || !isspace(s[9])) { |
231 |
|
fputs(s, stdout); /* not for us */ |
303 |
|
} |
304 |
|
cp = sskip(cp); |
305 |
|
continue; |
306 |
< |
case 'd': /* point sample density */ |
306 |
> |
case 'd': /* sample density */ |
307 |
|
if (*++cp != '=') |
308 |
|
break; |
309 |
< |
if (!isintd(++cp, " \t\n\r")) |
310 |
< |
break; |
311 |
< |
thisillum.sampdens = atoi(cp); |
309 |
> |
if (!*++cp || isspace(*cp)) |
310 |
> |
continue; |
311 |
> |
if (isintd(cp, " \t\n\r")) { |
312 |
> |
thisillum.sampdens = atoi(cp); |
313 |
> |
} else { |
314 |
> |
error(WARNING, "direct BSDF input unsupported"); |
315 |
> |
goto opterr; |
316 |
> |
} |
317 |
|
cp = sskip(cp); |
318 |
|
continue; |
319 |
< |
case 's': /* point super-samples */ |
319 |
> |
case 's': /* surface super-samples */ |
320 |
|
if (*++cp != '=') |
321 |
|
break; |
322 |
|
if (!isintd(++cp, " \t\n\r")) |
400 |
|
printf("l+\t\t\t\t# light type on\n"); |
401 |
|
else |
402 |
|
printf("l-\t\t\t\t# light type off\n"); |
403 |
< |
printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens); |
404 |
< |
printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps); |
403 |
> |
printf("d=%d\t\t\t\t# density of directions\n", thisillum.sampdens); |
404 |
> |
printf("s=%d\t\t\t\t# samples per direction\n", thisillum.nsamps); |
405 |
|
printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt); |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
void |
410 |
|
printhead( /* print out header */ |
411 |
< |
register int ac, |
412 |
< |
register char **av |
411 |
> |
int ac, |
412 |
> |
char **av |
413 |
|
) |
414 |
|
{ |
415 |
|
putchar('#'); |
476 |
|
checkhead(); |
477 |
|
/* process object */ |
478 |
|
if (doit) |
479 |
< |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt0, nm); |
479 |
> |
switch (thisobj.otype) { |
480 |
> |
case OBJ_FACE: |
481 |
> |
my_face(&thisobj, &thisillum, nm); |
482 |
> |
break; |
483 |
> |
case OBJ_SPHERE: |
484 |
> |
my_sphere(&thisobj, &thisillum, nm); |
485 |
> |
break; |
486 |
> |
case OBJ_RING: |
487 |
> |
my_ring(&thisobj, &thisillum, nm); |
488 |
> |
break; |
489 |
> |
default: |
490 |
> |
my_default(&thisobj, &thisillum, nm); |
491 |
> |
break; |
492 |
> |
} |
493 |
|
else |
494 |
|
printobj(thisillum.altmat, &thisobj); |
495 |
|
/* free arguments */ |
496 |
|
freefargs(&thisobj.oargs); |
497 |
|
return; |
498 |
|
readerr: |
499 |
< |
sprintf(errmsg, "(%s): error reading scene", nm); |
499 |
> |
sprintf(errmsg, "(%s): error reading input", nm); |
500 |
|
error(USER, errmsg); |
501 |
|
} |