1 |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* rmain.c - main for ray tracing programs |
9 |
* |
10 |
* 3/24/87 |
11 |
*/ |
12 |
|
13 |
/* for flaky pre-processors */ |
14 |
#ifndef RPICT |
15 |
#define RPICT 0 |
16 |
#endif |
17 |
#ifndef RTRACE |
18 |
#define RTRACE 0 |
19 |
#endif |
20 |
#ifndef RVIEW |
21 |
#define RVIEW 0 |
22 |
#endif |
23 |
|
24 |
#include "ray.h" |
25 |
|
26 |
#include "random.h" |
27 |
|
28 |
#include "resolu.h" |
29 |
|
30 |
#include "octree.h" |
31 |
|
32 |
#include <sys/types.h> |
33 |
|
34 |
#include <signal.h> |
35 |
|
36 |
#include "view.h" |
37 |
|
38 |
#include "paths.h" |
39 |
/* persistent processes define */ |
40 |
#ifdef F_SETLKW |
41 |
#if RPICT|RTRACE |
42 |
#define PERSIST 1 /* normal persist */ |
43 |
#define PARALLEL 2 /* parallel persist */ |
44 |
#define PCHILD 3 /* child of normal persist */ |
45 |
#endif |
46 |
#endif |
47 |
|
48 |
char *progname; /* argv[0] */ |
49 |
|
50 |
char *octname; /* octree name */ |
51 |
|
52 |
char *getlibpath(); /* library directory list */ |
53 |
|
54 |
char *sigerr[NSIG]; /* signal error messages */ |
55 |
|
56 |
char *shm_boundary = NULL; /* boundary of shared memory */ |
57 |
|
58 |
extern char VersionID[]; /* version ID string */ |
59 |
|
60 |
int (*trace)() = NULL; /* trace call */ |
61 |
int do_irrad = 0; /* compute irradiance? */ |
62 |
|
63 |
char *errfile = NULL; /* error output file */ |
64 |
|
65 |
extern time_t time(); |
66 |
time_t tstart; /* start time */ |
67 |
|
68 |
extern int ambnotify(); /* new object notify functions */ |
69 |
#if RTRACE |
70 |
extern int tranotify(); |
71 |
int (*addobjnotify[])() = {ambnotify, tranotify, NULL}; |
72 |
extern char *tralist[]; /* trace include/exclude list */ |
73 |
extern int traincl; /* include == 1, exclude == 0 */ |
74 |
#else |
75 |
int (*addobjnotify[])() = {ambnotify, NULL}; |
76 |
#endif |
77 |
|
78 |
CUBE thescene; /* our scene */ |
79 |
OBJECT nsceneobjs; /* number of objects in our scene */ |
80 |
|
81 |
extern unsigned long raynum, nrays; /* ray counts */ |
82 |
|
83 |
extern int imm_irrad; /* calculate immediate irradiance? */ |
84 |
extern int lim_dist; /* limit distance? */ |
85 |
|
86 |
extern int ralrm; /* seconds between reports */ |
87 |
|
88 |
extern int greyscale; /* map colors to brightness? */ |
89 |
extern char *devname; /* output device name */ |
90 |
extern double exposure; /* exposure compensation */ |
91 |
|
92 |
extern char *formstr(); /* string from format */ |
93 |
extern int inform; /* input format */ |
94 |
extern int outform; /* output format */ |
95 |
extern char *outvals; /* output values */ |
96 |
|
97 |
extern VIEW ourview; /* viewing parameters */ |
98 |
|
99 |
extern char rifname[]; /* rad input file name */ |
100 |
|
101 |
extern int hresolu; /* horizontal resolution */ |
102 |
extern int vresolu; /* vertical resolution */ |
103 |
extern double pixaspect; /* pixel aspect ratio */ |
104 |
|
105 |
extern int psample; /* pixel sample size */ |
106 |
extern double maxdiff; /* max. sample difference */ |
107 |
extern double dstrpix; /* square pixel distribution */ |
108 |
|
109 |
extern double mblur; /* motion blur parameter */ |
110 |
|
111 |
extern double dstrsrc; /* square source distribution */ |
112 |
extern double shadthresh; /* shadow threshold */ |
113 |
extern double shadcert; /* shadow testing certainty */ |
114 |
extern int directrelay; /* number of source relays */ |
115 |
extern int vspretest; /* virtual source pretest density */ |
116 |
extern int directvis; /* light sources visible to eye? */ |
117 |
extern double srcsizerat; /* maximum source size/dist. ratio */ |
118 |
|
119 |
extern double specthresh; /* specular sampling threshold */ |
120 |
extern double specjitter; /* specular sampling jitter */ |
121 |
|
122 |
extern COLOR cextinction; /* global extinction coefficient */ |
123 |
extern COLOR salbedo; /* global scattering albedo */ |
124 |
extern double seccg; /* global scattering eccentricity */ |
125 |
extern double ssampdist; /* scatter sampling distance */ |
126 |
|
127 |
extern int backvis; /* back face visibility */ |
128 |
|
129 |
extern int maxdepth; /* maximum recursion depth */ |
130 |
extern double minweight; /* minimum ray weight */ |
131 |
|
132 |
extern COLOR ambval; /* ambient value */ |
133 |
extern int ambvwt; /* initial weight for ambient value */ |
134 |
extern double ambacc; /* ambient accuracy */ |
135 |
extern int ambres; /* ambient resolution */ |
136 |
extern int ambdiv; /* ambient divisions */ |
137 |
extern int ambssamp; /* ambient super-samples */ |
138 |
extern int ambounce; /* ambient bounces */ |
139 |
extern char *amblist[]; /* ambient include/exclude list */ |
140 |
extern int ambincl; /* include == 1, exclude == 0 */ |
141 |
|
142 |
|
143 |
main(argc, argv) |
144 |
int argc; |
145 |
char *argv[]; |
146 |
{ |
147 |
#define check(ol,al) if (argv[i][ol] || \ |
148 |
badarg(argc-i-1,argv+i+1,al)) \ |
149 |
goto badopt |
150 |
#define bool(olen,var) switch (argv[i][olen]) { \ |
151 |
case '\0': var = !var; break; \ |
152 |
case 'y': case 'Y': case 't': case 'T': \ |
153 |
case '+': case '1': var = 1; break; \ |
154 |
case 'n': case 'N': case 'f': case 'F': \ |
155 |
case '-': case '0': var = 0; break; \ |
156 |
default: goto badopt; } |
157 |
char *err; |
158 |
char *recover = NULL; |
159 |
char *outfile = NULL; |
160 |
char *zfile = NULL; |
161 |
char *ambfile = NULL; |
162 |
int loadflags = ~IO_FILES; |
163 |
int seqstart = 0; |
164 |
int persist = 0; |
165 |
char **amblp; |
166 |
char **tralp; |
167 |
int duped1; |
168 |
int rval; |
169 |
int i; |
170 |
/* record start time */ |
171 |
tstart = time((time_t *)NULL); |
172 |
/* global program name */ |
173 |
progname = argv[0] = fixargv0(argv[0]); |
174 |
/* initialize object types */ |
175 |
initotypes(); |
176 |
/* initialize urand */ |
177 |
initurand(2048); |
178 |
/* option city */ |
179 |
for (i = 1; i < argc; i++) { |
180 |
/* expand arguments */ |
181 |
while (rval = expandarg(&argc, &argv, i)) |
182 |
if (rval < 0) { |
183 |
sprintf(errmsg, "cannot expand '%s'", argv[i]); |
184 |
error(SYSTEM, errmsg); |
185 |
} |
186 |
if (argv[i] == NULL || argv[i][0] != '-') |
187 |
break; /* break from options */ |
188 |
if (!strcmp(argv[i], "-version")) { |
189 |
puts(VersionID); |
190 |
quit(0); |
191 |
} |
192 |
if (!strcmp(argv[i], "-defaults") || |
193 |
!strcmp(argv[i], "-help")) { |
194 |
printdefaults(); |
195 |
quit(0); |
196 |
} |
197 |
#if RVIEW |
198 |
if (!strcmp(argv[i], "-devices")) { |
199 |
printdevices(); |
200 |
quit(0); |
201 |
} |
202 |
#endif |
203 |
#if RPICT|RVIEW |
204 |
rval = getviewopt(&ourview, argc-i, argv+i); |
205 |
if (rval >= 0) { |
206 |
i += rval; |
207 |
continue; |
208 |
} |
209 |
#endif |
210 |
switch (argv[i][1]) { |
211 |
#if RPICT|RVIEW |
212 |
case 'v': /* view file */ |
213 |
if (argv[i][2] != 'f') |
214 |
goto badopt; |
215 |
check(3,"s"); |
216 |
rval = viewfile(argv[++i], &ourview, NULL); |
217 |
if (rval < 0) { |
218 |
sprintf(errmsg, |
219 |
"cannot open view file \"%s\"", |
220 |
argv[i]); |
221 |
error(SYSTEM, errmsg); |
222 |
} else if (rval == 0) { |
223 |
sprintf(errmsg, |
224 |
"bad view file \"%s\"", |
225 |
argv[i]); |
226 |
error(USER, errmsg); |
227 |
} |
228 |
break; |
229 |
#endif |
230 |
case 'b': /* back face vis. */ |
231 |
if (argv[i][2] == 'v') { |
232 |
bool(3,backvis); |
233 |
break; |
234 |
} |
235 |
#if RVIEW |
236 |
bool(2,greyscale); |
237 |
break; |
238 |
#else |
239 |
goto badopt; |
240 |
#endif |
241 |
case 'd': /* direct */ |
242 |
switch (argv[i][2]) { |
243 |
case 't': /* threshold */ |
244 |
check(3,"f"); |
245 |
shadthresh = atof(argv[++i]); |
246 |
break; |
247 |
case 'c': /* certainty */ |
248 |
check(3,"f"); |
249 |
shadcert = atof(argv[++i]); |
250 |
break; |
251 |
case 'j': /* jitter */ |
252 |
check(3,"f"); |
253 |
dstrsrc = atof(argv[++i]); |
254 |
break; |
255 |
case 'r': /* relays */ |
256 |
check(3,"i"); |
257 |
directrelay = atoi(argv[++i]); |
258 |
break; |
259 |
case 'p': /* pretest */ |
260 |
check(3,"i"); |
261 |
vspretest = atoi(argv[++i]); |
262 |
break; |
263 |
case 'v': /* visibility */ |
264 |
bool(3,directvis); |
265 |
break; |
266 |
case 's': /* size */ |
267 |
check(3,"f"); |
268 |
srcsizerat = atof(argv[++i]); |
269 |
break; |
270 |
default: |
271 |
goto badopt; |
272 |
} |
273 |
break; |
274 |
case 's': /* specular */ |
275 |
switch (argv[i][2]) { |
276 |
case 't': /* threshold */ |
277 |
check(3,"f"); |
278 |
specthresh = atof(argv[++i]); |
279 |
break; |
280 |
case 'j': /* jitter */ |
281 |
check(3,"f"); |
282 |
specjitter = atof(argv[++i]); |
283 |
break; |
284 |
default: |
285 |
goto badopt; |
286 |
} |
287 |
break; |
288 |
#if RPICT|RVIEW |
289 |
case 'p': /* pixel */ |
290 |
switch (argv[i][2]) { |
291 |
case 's': /* sample */ |
292 |
check(3,"i"); |
293 |
psample = atoi(argv[++i]); |
294 |
break; |
295 |
case 't': /* threshold */ |
296 |
check(3,"f"); |
297 |
maxdiff = atof(argv[++i]); |
298 |
break; |
299 |
#if RPICT |
300 |
case 'j': /* jitter */ |
301 |
check(3,"f"); |
302 |
dstrpix = atof(argv[++i]); |
303 |
break; |
304 |
case 'a': /* aspect */ |
305 |
check(3,"f"); |
306 |
pixaspect = atof(argv[++i]); |
307 |
break; |
308 |
case 'm': /* motion */ |
309 |
check(3,"f"); |
310 |
mblur = atof(argv[++i]); |
311 |
break; |
312 |
#endif |
313 |
#if RVIEW |
314 |
case 'e': /* exposure */ |
315 |
check(3,"f"); |
316 |
exposure = atof(argv[++i]); |
317 |
if (argv[i][0] == '+' || argv[i][0] == '-') |
318 |
exposure = pow(2.0, exposure); |
319 |
break; |
320 |
#endif |
321 |
default: |
322 |
goto badopt; |
323 |
} |
324 |
break; |
325 |
#endif |
326 |
#if RPICT|RTRACE |
327 |
case 'x': /* x resolution */ |
328 |
check(2,"i"); |
329 |
hresolu = atoi(argv[++i]); |
330 |
break; |
331 |
case 'y': /* y resolution */ |
332 |
check(2,"i"); |
333 |
vresolu = atoi(argv[++i]); |
334 |
break; |
335 |
#endif |
336 |
case 'w': /* warnings */ |
337 |
rval = erract[WARNING].pf != NULL; |
338 |
bool(2,rval); |
339 |
if (rval) erract[WARNING].pf = wputs; |
340 |
else erract[WARNING].pf = NULL; |
341 |
break; |
342 |
case 'e': /* error file */ |
343 |
check(2,"s"); |
344 |
errfile = argv[++i]; |
345 |
break; |
346 |
case 'l': /* limit */ |
347 |
switch (argv[i][2]) { |
348 |
case 'r': /* recursion */ |
349 |
check(3,"i"); |
350 |
maxdepth = atoi(argv[++i]); |
351 |
break; |
352 |
case 'w': /* weight */ |
353 |
check(3,"f"); |
354 |
minweight = atof(argv[++i]); |
355 |
break; |
356 |
#if RTRACE |
357 |
case 'd': /* distance */ |
358 |
bool(3,lim_dist); |
359 |
break; |
360 |
#endif |
361 |
default: |
362 |
goto badopt; |
363 |
} |
364 |
break; |
365 |
case 'i': /* irradiance */ |
366 |
bool(2,do_irrad); |
367 |
break; |
368 |
#if RPICT |
369 |
case 'S': /* slave index */ |
370 |
check(2,"i"); |
371 |
seqstart = atoi(argv[++i]); |
372 |
break; |
373 |
case 'o': /* output file */ |
374 |
check(2,"s"); |
375 |
outfile = argv[++i]; |
376 |
break; |
377 |
case 'z': /* z file */ |
378 |
check(2,"s"); |
379 |
zfile = argv[++i]; |
380 |
break; |
381 |
case 'r': /* recover file */ |
382 |
if (argv[i][2] == 'o') { /* +output */ |
383 |
check(3,"s"); |
384 |
outfile = argv[i+1]; |
385 |
} else |
386 |
check(2,"s"); |
387 |
recover = argv[++i]; |
388 |
break; |
389 |
case 't': /* timer */ |
390 |
check(2,"i"); |
391 |
ralrm = atoi(argv[++i]); |
392 |
break; |
393 |
#endif |
394 |
case 'a': /* ambient */ |
395 |
switch (argv[i][2]) { |
396 |
case 'v': /* value */ |
397 |
check(3,"fff"); |
398 |
setcolor(ambval, atof(argv[i+1]), |
399 |
atof(argv[i+2]), |
400 |
atof(argv[i+3])); |
401 |
i += 3; |
402 |
break; |
403 |
case 'w': /* weight */ |
404 |
check(3,"i"); |
405 |
ambvwt = atoi(argv[++i]); |
406 |
break; |
407 |
case 'a': /* accuracy */ |
408 |
check(3,"f"); |
409 |
ambacc = atof(argv[++i]); |
410 |
break; |
411 |
case 'r': /* resolution */ |
412 |
check(3,"i"); |
413 |
ambres = atoi(argv[++i]); |
414 |
break; |
415 |
case 'd': /* divisions */ |
416 |
check(3,"i"); |
417 |
ambdiv = atoi(argv[++i]); |
418 |
break; |
419 |
case 's': /* super-samp */ |
420 |
check(3,"i"); |
421 |
ambssamp = atoi(argv[++i]); |
422 |
break; |
423 |
case 'b': /* bounces */ |
424 |
check(3,"i"); |
425 |
ambounce = atoi(argv[++i]); |
426 |
break; |
427 |
case 'i': /* include */ |
428 |
case 'I': |
429 |
check(3,"s"); |
430 |
if (ambincl != 1) { |
431 |
ambincl = 1; |
432 |
amblp = amblist; |
433 |
} |
434 |
if (argv[i][2] == 'I') { /* file */ |
435 |
rval = wordfile(amblp, |
436 |
getpath(argv[++i],getlibpath(),R_OK)); |
437 |
if (rval < 0) { |
438 |
sprintf(errmsg, |
439 |
"cannot open ambient include file \"%s\"", |
440 |
argv[i]); |
441 |
error(SYSTEM, errmsg); |
442 |
} |
443 |
amblp += rval; |
444 |
} else { |
445 |
*amblp++ = argv[++i]; |
446 |
*amblp = NULL; |
447 |
} |
448 |
break; |
449 |
case 'e': /* exclude */ |
450 |
case 'E': |
451 |
check(3,"s"); |
452 |
if (ambincl != 0) { |
453 |
ambincl = 0; |
454 |
amblp = amblist; |
455 |
} |
456 |
if (argv[i][2] == 'E') { /* file */ |
457 |
rval = wordfile(amblp, |
458 |
getpath(argv[++i],getlibpath(),R_OK)); |
459 |
if (rval < 0) { |
460 |
sprintf(errmsg, |
461 |
"cannot open ambient exclude file \"%s\"", |
462 |
argv[i]); |
463 |
error(SYSTEM, errmsg); |
464 |
} |
465 |
amblp += rval; |
466 |
} else { |
467 |
*amblp++ = argv[++i]; |
468 |
*amblp = NULL; |
469 |
} |
470 |
break; |
471 |
case 'f': /* file */ |
472 |
check(3,"s"); |
473 |
ambfile= argv[++i]; |
474 |
break; |
475 |
default: |
476 |
goto badopt; |
477 |
} |
478 |
break; |
479 |
case 'm': /* medium */ |
480 |
switch (argv[i][2]) { |
481 |
case 'e': /* extinction */ |
482 |
check(3,"fff"); |
483 |
setcolor(cextinction, atof(argv[i+1]), |
484 |
atof(argv[i+2]), |
485 |
atof(argv[i+3])); |
486 |
i += 3; |
487 |
break; |
488 |
case 'a': /* albedo */ |
489 |
check(3,"fff"); |
490 |
setcolor(salbedo, atof(argv[i+1]), |
491 |
atof(argv[i+2]), |
492 |
atof(argv[i+3])); |
493 |
i += 3; |
494 |
break; |
495 |
case 'g': /* eccentr. */ |
496 |
check(3,"f"); |
497 |
seccg = atof(argv[++i]); |
498 |
break; |
499 |
case 's': /* sampling */ |
500 |
check(3,"f"); |
501 |
ssampdist = atof(argv[++i]); |
502 |
break; |
503 |
default: |
504 |
goto badopt; |
505 |
} |
506 |
break; |
507 |
#if RTRACE |
508 |
case 'I': /* immed. irradiance */ |
509 |
bool(2,imm_irrad); |
510 |
break; |
511 |
case 'f': /* format i/o */ |
512 |
switch (argv[i][2]) { |
513 |
case 'a': /* ascii */ |
514 |
case 'f': /* float */ |
515 |
case 'd': /* double */ |
516 |
inform = argv[i][2]; |
517 |
break; |
518 |
default: |
519 |
goto badopt; |
520 |
} |
521 |
switch (argv[i][3]) { |
522 |
case '\0': |
523 |
outform = inform; |
524 |
break; |
525 |
case 'a': /* ascii */ |
526 |
case 'f': /* float */ |
527 |
case 'd': /* double */ |
528 |
case 'c': /* color */ |
529 |
check(4,""); |
530 |
outform = argv[i][3]; |
531 |
break; |
532 |
default: |
533 |
goto badopt; |
534 |
} |
535 |
break; |
536 |
case 'o': /* output */ |
537 |
outvals = argv[i]+2; |
538 |
break; |
539 |
case 'h': /* header output */ |
540 |
rval = loadflags & IO_INFO; |
541 |
bool(2,rval); |
542 |
loadflags = rval ? loadflags | IO_INFO : |
543 |
loadflags & ~IO_INFO; |
544 |
break; |
545 |
case 't': /* trace */ |
546 |
switch (argv[i][2]) { |
547 |
case 'i': /* include */ |
548 |
case 'I': |
549 |
check(3,"s"); |
550 |
if (traincl != 1) { |
551 |
traincl = 1; |
552 |
tralp = tralist; |
553 |
} |
554 |
if (argv[i][2] == 'I') { /* file */ |
555 |
rval = wordfile(tralp, |
556 |
getpath(argv[++i],getlibpath(),R_OK)); |
557 |
if (rval < 0) { |
558 |
sprintf(errmsg, |
559 |
"cannot open trace include file \"%s\"", |
560 |
argv[i]); |
561 |
error(SYSTEM, errmsg); |
562 |
} |
563 |
tralp += rval; |
564 |
} else { |
565 |
*tralp++ = argv[++i]; |
566 |
*tralp = NULL; |
567 |
} |
568 |
break; |
569 |
case 'e': /* exclude */ |
570 |
case 'E': |
571 |
check(3,"s"); |
572 |
if (traincl != 0) { |
573 |
traincl = 0; |
574 |
tralp = tralist; |
575 |
} |
576 |
if (argv[i][2] == 'E') { /* file */ |
577 |
rval = wordfile(tralp, |
578 |
getpath(argv[++i],getlibpath(),R_OK)); |
579 |
if (rval < 0) { |
580 |
sprintf(errmsg, |
581 |
"cannot open trace exclude file \"%s\"", |
582 |
argv[i]); |
583 |
error(SYSTEM, errmsg); |
584 |
} |
585 |
tralp += rval; |
586 |
} else { |
587 |
*tralp++ = argv[++i]; |
588 |
*tralp = NULL; |
589 |
} |
590 |
break; |
591 |
default: |
592 |
goto badopt; |
593 |
} |
594 |
break; |
595 |
#endif |
596 |
#if RVIEW |
597 |
case 'o': /* output device */ |
598 |
check(2,"s"); |
599 |
devname = argv[++i]; |
600 |
break; |
601 |
case 'R': /* render input file */ |
602 |
check(2,"s"); |
603 |
strcpy(rifname, argv[++i]); |
604 |
break; |
605 |
#endif |
606 |
#ifdef PERSIST |
607 |
case 'P': /* persist file */ |
608 |
if (argv[i][2] == 'P') { |
609 |
check(3,"s"); |
610 |
persist = PARALLEL; |
611 |
} else { |
612 |
check(2,"s"); |
613 |
persist = PERSIST; |
614 |
} |
615 |
persistfile(argv[++i]); |
616 |
break; |
617 |
#endif |
618 |
default: |
619 |
goto badopt; |
620 |
} |
621 |
} |
622 |
#if RPICT|RVIEW |
623 |
err = setview(&ourview); /* set viewing parameters */ |
624 |
if (err != NULL) |
625 |
error(USER, err); |
626 |
#endif |
627 |
/* set up signal handling */ |
628 |
sigdie(SIGINT, "Interrupt"); |
629 |
sigdie(SIGHUP, "Hangup"); |
630 |
sigdie(SIGTERM, "Terminate"); |
631 |
sigdie(SIGPIPE, "Broken pipe"); |
632 |
sigdie(SIGALRM, "Alarm clock"); |
633 |
#ifdef SIGXCPU |
634 |
sigdie(SIGXCPU, "CPU limit exceeded"); |
635 |
sigdie(SIGXFSZ, "File size exceeded"); |
636 |
#endif |
637 |
/* open error file */ |
638 |
if (errfile != NULL) { |
639 |
if (freopen(errfile, "a", stderr) == NULL) |
640 |
quit(2); |
641 |
fprintf(stderr, "**************\n*** PID %5d: ", |
642 |
getpid()); |
643 |
printargs(argc, argv, stderr); |
644 |
putc('\n', stderr); |
645 |
fflush(stderr); |
646 |
} |
647 |
#ifdef NICE |
648 |
nice(NICE); /* lower priority */ |
649 |
#endif |
650 |
/* get octree */ |
651 |
#if RVIEW |
652 |
loadflags &= ~IO_INFO; |
653 |
#endif |
654 |
if (i == argc) |
655 |
octname = NULL; |
656 |
else if (i == argc-1) |
657 |
octname = argv[i]; |
658 |
else |
659 |
goto badopt; |
660 |
if ( |
661 |
#if RPICT |
662 |
seqstart > 0 && |
663 |
#endif |
664 |
octname == NULL) |
665 |
error(USER, "missing octree argument"); |
666 |
/* set up output */ |
667 |
#ifdef PERSIST |
668 |
if (persist) { |
669 |
#if RPICT |
670 |
if (recover != NULL) |
671 |
error(USER, "persist option used with recover file"); |
672 |
if (seqstart <= 0) |
673 |
error(USER, "persist option only for sequences"); |
674 |
if (outfile == NULL) |
675 |
#endif |
676 |
duped1 = dup(fileno(stdout)); /* don't lose our output */ |
677 |
openheader(); |
678 |
} |
679 |
#if RPICT |
680 |
else |
681 |
#endif |
682 |
#endif |
683 |
#if RPICT |
684 |
if (outfile != NULL) |
685 |
openheader(); |
686 |
#endif |
687 |
#ifdef MSDOS |
688 |
#if RTRACE |
689 |
if (outform != 'a') |
690 |
#endif |
691 |
setmode(fileno(stdout), O_BINARY); |
692 |
if (octname == NULL) |
693 |
setmode(fileno(stdin), O_BINARY); |
694 |
#endif |
695 |
readoct(octname, loadflags, &thescene, NULL); |
696 |
nsceneobjs = nobjects; |
697 |
|
698 |
if (loadflags & IO_INFO) { /* print header */ |
699 |
printargs(i, argv, stdout); |
700 |
printf("SOFTWARE= %s\n", VersionID); |
701 |
#if RTRACE |
702 |
fputformat(formstr(outform), stdout); |
703 |
putchar('\n'); |
704 |
#endif |
705 |
} |
706 |
|
707 |
marksources(); /* find and mark sources */ |
708 |
|
709 |
setambient(ambfile); /* initialize ambient calculation */ |
710 |
|
711 |
#ifdef PERSIST |
712 |
if (persist) { |
713 |
fflush(stdout); |
714 |
if (outfile == NULL) { /* reconnect stdout */ |
715 |
dup2(duped1, fileno(stdout)); |
716 |
close(duped1); |
717 |
} |
718 |
if (persist == PARALLEL) { /* multiprocessing */ |
719 |
preload_objs(); /* preload scene */ |
720 |
strcpy(shm_boundary=bmalloc(16), "SHM_BOUNDARY"); |
721 |
while ((rval=fork()) == 0) { /* keep on forkin' */ |
722 |
pflock(1); |
723 |
pfhold(); |
724 |
tstart = time((time_t *)NULL); |
725 |
} |
726 |
if (rval < 0) |
727 |
error(SYSTEM, "cannot fork child for persist function"); |
728 |
pfdetach(); /* parent exits */ |
729 |
} |
730 |
} |
731 |
runagain: |
732 |
if (persist) |
733 |
if (outfile == NULL) /* if out to stdout */ |
734 |
dupheader(); /* send header */ |
735 |
else /* if out to file */ |
736 |
duped1 = dup(fileno(stdout)); /* hang onto pipe */ |
737 |
#endif |
738 |
#if RPICT |
739 |
rpict(seqstart, outfile, zfile, recover); |
740 |
#endif |
741 |
#if RTRACE |
742 |
rtrace(NULL); |
743 |
#endif |
744 |
#if RVIEW |
745 |
rview(); |
746 |
#endif |
747 |
ambsync(); /* flush ambient file */ |
748 |
#ifdef PERSIST |
749 |
if (persist == PERSIST) { /* first run-through */ |
750 |
if ((rval=fork()) == 0) { /* child loops until killed */ |
751 |
pflock(1); |
752 |
persist = PCHILD; |
753 |
} else { /* original process exits */ |
754 |
if (rval < 0) |
755 |
error(SYSTEM, "cannot fork child for persist function"); |
756 |
pfdetach(); /* parent exits */ |
757 |
} |
758 |
} |
759 |
if (persist == PCHILD) { /* wait for a signal then go again */ |
760 |
if (outfile != NULL) |
761 |
close(duped1); /* release output handle */ |
762 |
pfhold(); |
763 |
tstart = time((time_t *)NULL); /* reinitialize */ |
764 |
raynum = nrays = 0; |
765 |
goto runagain; |
766 |
} |
767 |
#endif |
768 |
quit(0); |
769 |
|
770 |
badopt: |
771 |
sprintf(errmsg, "command line error at '%s'", argv[i]); |
772 |
error(USER, errmsg); |
773 |
|
774 |
#undef check |
775 |
#undef bool |
776 |
} |
777 |
|
778 |
|
779 |
wputs(s) /* warning output function */ |
780 |
char *s; |
781 |
{ |
782 |
int lasterrno = errno; |
783 |
eputs(s); |
784 |
errno = lasterrno; |
785 |
} |
786 |
|
787 |
|
788 |
eputs(s) /* put string to stderr */ |
789 |
register char *s; |
790 |
{ |
791 |
static int midline = 0; |
792 |
|
793 |
if (!*s) |
794 |
return; |
795 |
if (!midline++) { |
796 |
fputs(progname, stderr); |
797 |
fputs(": ", stderr); |
798 |
} |
799 |
fputs(s, stderr); |
800 |
if (s[strlen(s)-1] == '\n') { |
801 |
fflush(stderr); |
802 |
midline = 0; |
803 |
} |
804 |
} |
805 |
|
806 |
|
807 |
onsig(signo) /* fatal signal */ |
808 |
int signo; |
809 |
{ |
810 |
static int gotsig = 0; |
811 |
|
812 |
if (gotsig++) /* two signals and we're gone! */ |
813 |
_exit(signo); |
814 |
|
815 |
alarm(15); /* allow 15 seconds to clean up */ |
816 |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
817 |
eputs("signal - "); |
818 |
eputs(sigerr[signo]); |
819 |
eputs("\n"); |
820 |
quit(3); |
821 |
} |
822 |
|
823 |
|
824 |
sigdie(signo, msg) /* set fatal signal */ |
825 |
int signo; |
826 |
char *msg; |
827 |
{ |
828 |
if (signal(signo, onsig) == SIG_IGN) |
829 |
signal(signo, SIG_IGN); |
830 |
sigerr[signo] = msg; |
831 |
} |
832 |
|
833 |
|
834 |
printdefaults() /* print default values to stdout */ |
835 |
{ |
836 |
register char *cp; |
837 |
|
838 |
#if RTRACE |
839 |
if (imm_irrad) |
840 |
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
841 |
else |
842 |
#endif |
843 |
printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" : |
844 |
"-i-\t\t\t\t# irradiance calculation off\n"); |
845 |
#if RVIEW |
846 |
printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" : |
847 |
"-b-\t\t\t\t# greyscale off\n"); |
848 |
#endif |
849 |
#if RPICT|RVIEW |
850 |
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
851 |
ourview.type==VT_PER ? "perspective" : |
852 |
ourview.type==VT_PAR ? "parallel" : |
853 |
ourview.type==VT_HEM ? "hemispherical" : |
854 |
ourview.type==VT_ANG ? "angular" : |
855 |
ourview.type==VT_CYL ? "cylindrical" : |
856 |
"unknown"); |
857 |
printf("-vp %f %f %f\t# view point\n", |
858 |
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
859 |
printf("-vd %f %f %f\t# view direction\n", |
860 |
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
861 |
printf("-vu %f %f %f\t# view up\n", |
862 |
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
863 |
printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz); |
864 |
printf("-vv %f\t\t\t# view vertical size\n", ourview.vert); |
865 |
printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore); |
866 |
printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft); |
867 |
printf("-vs %f\t\t\t# view shift\n", ourview.hoff); |
868 |
printf("-vl %f\t\t\t# view lift\n", ourview.voff); |
869 |
#endif |
870 |
#if RPICT|RTRACE |
871 |
printf("-x %-9d\t\t\t# x resolution\n", hresolu); |
872 |
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
873 |
#endif |
874 |
#if RPICT |
875 |
printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect); |
876 |
printf("-pj %f\t\t\t# pixel jitter\n", dstrpix); |
877 |
printf("-pm %f\t\t\t# pixel motion\n", mblur); |
878 |
#endif |
879 |
#if RVIEW |
880 |
printf("-pe %f\t\t\t# pixel exposure\n", exposure); |
881 |
#endif |
882 |
#if RPICT|RVIEW |
883 |
printf("-ps %-9d\t\t\t# pixel sample\n", psample); |
884 |
printf("-pt %f\t\t\t# pixel threshold\n", maxdiff); |
885 |
#endif |
886 |
printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" : |
887 |
"-bv-\t\t\t\t# back face visibility off\n"); |
888 |
printf("-dt %f\t\t\t# direct threshold\n", shadthresh); |
889 |
printf("-dc %f\t\t\t# direct certainty\n", shadcert); |
890 |
printf("-dj %f\t\t\t# direct jitter\n", dstrsrc); |
891 |
printf("-ds %f\t\t\t# direct sampling\n", srcsizerat); |
892 |
printf("-dr %-9d\t\t\t# direct relays\n", directrelay); |
893 |
printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest); |
894 |
printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" : |
895 |
"-dv-\t\t\t\t# direct visibility off\n"); |
896 |
printf("-sj %f\t\t\t# specular jitter\n", specjitter); |
897 |
printf("-st %f\t\t\t# specular threshold\n", specthresh); |
898 |
printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED), |
899 |
colval(ambval,GRN), colval(ambval, BLU)); |
900 |
printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt); |
901 |
printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce); |
902 |
printf("-aa %f\t\t\t# ambient accuracy\n", ambacc); |
903 |
printf("-ar %-9d\t\t\t# ambient resolution\n", ambres); |
904 |
printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv); |
905 |
printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp); |
906 |
printf("-me %.2e %.2e %.2e\t# mist extinction coefficient\n", |
907 |
colval(cextinction,RED), |
908 |
colval(cextinction,GRN), |
909 |
colval(cextinction,BLU)); |
910 |
printf("-ma %f %f %f\t# mist scattering albedo\n", colval(salbedo,RED), |
911 |
colval(salbedo,GRN), colval(salbedo,BLU)); |
912 |
printf("-mg %f\t\t\t# mist scattering eccentricity\n", seccg); |
913 |
printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist); |
914 |
printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth); |
915 |
printf("-lw %f\t\t\t# limit weight\n", minweight); |
916 |
#if RTRACE |
917 |
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
918 |
"-ld-\t\t\t\t# limit distance off\n"); |
919 |
#endif |
920 |
#if RPICT |
921 |
printf("-t %-9d\t\t\t# time between reports\n", ralrm); |
922 |
#endif |
923 |
#if RVIEW |
924 |
printf("-o %s\t\t\t\t# output device\n", devname); |
925 |
#endif |
926 |
#if RTRACE |
927 |
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
928 |
inform, outform, formstr(inform), formstr(outform)); |
929 |
printf("-o%s\t\t\t\t# output", outvals); |
930 |
for (cp = outvals; *cp; cp++) |
931 |
switch (*cp) { |
932 |
case 't': printf(" trace"); break; |
933 |
case 'o': printf(" origin"); break; |
934 |
case 'd': printf(" direction"); break; |
935 |
case 'v': printf(" value"); break; |
936 |
case 'l': printf(" length"); break; |
937 |
case 'L': printf(" first_length"); break; |
938 |
case 'p': printf(" point"); break; |
939 |
case 'n': printf(" normal"); break; |
940 |
case 'N': printf(" unperturbed_normal"); break; |
941 |
case 's': printf(" surface"); break; |
942 |
case 'w': printf(" weight"); break; |
943 |
case 'm': printf(" modifier"); break; |
944 |
} |
945 |
putchar('\n'); |
946 |
#endif |
947 |
printf(erract[WARNING].pf != NULL ? |
948 |
"-w+\t\t\t\t# warning messages on\n" : |
949 |
"-w-\t\t\t\t# warning messages off\n"); |
950 |
} |