7 |
|
|
8 |
|
#include "copyright.h" |
9 |
|
|
10 |
< |
#include <sys/types.h> |
10 |
> |
#include <time.h> |
11 |
|
#include <signal.h> |
12 |
– |
#ifdef _WIN32 |
13 |
– |
#include <process.h> /* getpid */ |
14 |
– |
#endif |
12 |
|
|
13 |
|
#include "platform.h" |
14 |
+ |
#include "rtprocess.h" /* getpid() */ |
15 |
|
#include "ray.h" |
16 |
|
#include "source.h" |
17 |
|
#include "ambient.h" |
18 |
|
#include "random.h" |
19 |
|
#include "paths.h" |
20 |
|
#include "view.h" |
21 |
+ |
#include "pmapray.h" |
22 |
|
|
23 |
|
/* persistent processes define */ |
24 |
|
#ifdef F_SETLKW |
28 |
|
#endif |
29 |
|
|
30 |
|
char *progname; /* argv[0] */ |
32 |
– |
|
31 |
|
char *octname; /* octree name */ |
34 |
– |
|
32 |
|
char *sigerr[NSIG]; /* signal error messages */ |
36 |
– |
|
33 |
|
char *shm_boundary = NULL; /* boundary of shared memory */ |
38 |
– |
|
34 |
|
char *errfile = NULL; /* error output file */ |
35 |
|
|
36 |
|
extern time_t time(); |
50 |
|
|
51 |
|
extern double mblur; /* motion blur parameter */ |
52 |
|
|
53 |
< |
void onsig(); |
59 |
< |
void sigdie(); |
60 |
< |
void printdefaults(); |
53 |
> |
extern double dblur; /* depth-of-field blur parameter */ |
54 |
|
|
55 |
+ |
static void onsig(int signo); |
56 |
+ |
static void sigdie(int signo, char *msg); |
57 |
+ |
static void printdefaults(void); |
58 |
|
|
59 |
+ |
|
60 |
|
int |
61 |
< |
main(argc, argv) |
65 |
< |
int argc; |
66 |
< |
char *argv[]; |
61 |
> |
main(int argc, char *argv[]) |
62 |
|
{ |
63 |
|
#define check(ol,al) if (argv[i][ol] || \ |
64 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
65 |
|
goto badopt |
66 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
66 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
67 |
|
case '\0': var = !var; break; \ |
68 |
|
case 'y': case 'Y': case 't': case 'T': \ |
69 |
|
case '+': case '1': var = 1; break; \ |
77 |
|
int loadflags = ~IO_FILES; |
78 |
|
int seqstart = 0; |
79 |
|
int persist = 0; |
80 |
< |
int duped1; |
80 |
> |
int duped1 = -1; |
81 |
|
int rval; |
82 |
|
int i; |
83 |
|
/* record start time */ |
155 |
|
check(3,"f"); |
156 |
|
mblur = atof(argv[++i]); |
157 |
|
break; |
158 |
+ |
case 'd': /* aperture */ |
159 |
+ |
check(3,"f"); |
160 |
+ |
dblur = atof(argv[++i]); |
161 |
+ |
break; |
162 |
|
default: |
163 |
|
goto badopt; |
164 |
|
} |
209 |
|
#endif |
210 |
|
case 'w': /* warnings */ |
211 |
|
rval = erract[WARNING].pf != NULL; |
212 |
< |
bool(2,rval); |
212 |
> |
check_bool(2,rval); |
213 |
|
if (rval) erract[WARNING].pf = wputs; |
214 |
|
else erract[WARNING].pf = NULL; |
215 |
|
break; |
227 |
|
/* initialize object types */ |
228 |
|
initotypes(); |
229 |
|
/* initialize urand */ |
230 |
< |
initurand(2048); |
230 |
> |
if (rand_samp) { |
231 |
> |
srandom((long)time(0)); |
232 |
> |
initurand(0); |
233 |
> |
} else { |
234 |
> |
srandom(0L); |
235 |
> |
initurand(2048); |
236 |
> |
} |
237 |
|
/* set up signal handling */ |
238 |
|
sigdie(SIGINT, "Interrupt"); |
239 |
|
#ifdef SIGHUP |
286 |
|
#endif |
287 |
|
if (outfile != NULL) |
288 |
|
openheader(); |
284 |
– |
#ifdef _WIN32 |
289 |
|
SET_FILE_BINARY(stdout); |
290 |
|
if (octname == NULL) |
291 |
|
SET_FILE_BINARY(stdin); |
288 |
– |
#endif |
292 |
|
readoct(octname, loadflags, &thescene, NULL); |
293 |
|
nsceneobjs = nobjects; |
294 |
|
|
296 |
|
printargs(i, argv, stdout); |
297 |
|
printf("SOFTWARE= %s\n", VersionID); |
298 |
|
} |
299 |
+ |
|
300 |
+ |
ray_init_pmap(); /* PMAP: set up & load photon maps */ |
301 |
|
|
302 |
|
marksources(); /* find and mark sources */ |
303 |
|
|
304 |
|
setambient(); /* initialize ambient calculation */ |
305 |
+ |
|
306 |
+ |
fflush(stdout); /* in case we're duplicating header */ |
307 |
|
|
308 |
|
#ifdef PERSIST |
309 |
|
if (persist) { |
303 |
– |
fflush(stdout); |
310 |
|
if (outfile == NULL) { /* reconnect stdout */ |
311 |
|
dup2(duped1, fileno(stdout)); |
312 |
|
close(duped1); |
319 |
|
pflock(1); |
320 |
|
pfhold(); |
321 |
|
tstart = time((time_t *)NULL); |
322 |
+ |
ambsync(); /* load new values */ |
323 |
|
} |
324 |
|
if (rval < 0) |
325 |
|
error(SYSTEM, "cannot fork child for persist function"); |
326 |
< |
pfdetach(); /* parent exits */ |
326 |
> |
pfdetach(); /* parent will run then exit */ |
327 |
|
} |
328 |
|
} |
329 |
|
runagain: |
330 |
< |
if (persist) |
330 |
> |
if (persist) { |
331 |
|
if (outfile == NULL) /* if out to stdout */ |
332 |
|
dupheader(); /* send header */ |
333 |
|
else /* if out to file */ |
334 |
|
duped1 = dup(fileno(stdout)); /* hang onto pipe */ |
335 |
+ |
} |
336 |
|
#endif |
337 |
|
/* batch render picture(s) */ |
338 |
|
rpict(seqstart, outfile, zfile, recover); |
358 |
|
goto runagain; |
359 |
|
} |
360 |
|
#endif |
361 |
+ |
|
362 |
+ |
|
363 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
364 |
+ |
|
365 |
|
quit(0); |
366 |
|
|
367 |
|
badopt: |
368 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
369 |
|
error(USER, errmsg); |
370 |
+ |
return 1; /* pro forma return */ |
371 |
|
|
372 |
|
#undef check |
373 |
< |
#undef bool |
373 |
> |
#undef check_bool |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
void |
378 |
< |
wputs(s) /* warning output function */ |
379 |
< |
char *s; |
378 |
> |
wputs( /* warning output function */ |
379 |
> |
char *s |
380 |
> |
) |
381 |
|
{ |
382 |
|
int lasterrno = errno; |
383 |
|
eputs(s); |
386 |
|
|
387 |
|
|
388 |
|
void |
389 |
< |
eputs(s) /* put string to stderr */ |
390 |
< |
register char *s; |
389 |
> |
eputs( /* put string to stderr */ |
390 |
> |
register char *s |
391 |
> |
) |
392 |
|
{ |
393 |
|
static int midline = 0; |
394 |
|
|
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
< |
void |
410 |
< |
onsig(signo) /* fatal signal */ |
411 |
< |
int signo; |
409 |
> |
static void |
410 |
> |
onsig( /* fatal signal */ |
411 |
> |
int signo |
412 |
> |
) |
413 |
|
{ |
414 |
|
static int gotsig = 0; |
415 |
|
|
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
< |
void |
431 |
< |
sigdie(signo, msg) /* set fatal signal */ |
432 |
< |
int signo; |
433 |
< |
char *msg; |
430 |
> |
static void |
431 |
> |
sigdie( /* set fatal signal */ |
432 |
> |
int signo, |
433 |
> |
char *msg |
434 |
> |
) |
435 |
|
{ |
436 |
|
if (signal(signo, onsig) == SIG_IGN) |
437 |
|
signal(signo, SIG_IGN); |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
< |
void |
443 |
< |
printdefaults() /* print default values to stdout */ |
442 |
> |
static void |
443 |
> |
printdefaults(void) /* print default values to stdout */ |
444 |
|
{ |
428 |
– |
register char *cp; |
429 |
– |
|
445 |
|
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
446 |
|
ourview.type==VT_PER ? "perspective" : |
447 |
|
ourview.type==VT_PAR ? "parallel" : |
448 |
|
ourview.type==VT_HEM ? "hemispherical" : |
449 |
|
ourview.type==VT_ANG ? "angular" : |
450 |
|
ourview.type==VT_CYL ? "cylindrical" : |
451 |
+ |
ourview.type==VT_PLS ? "planisphere" : |
452 |
|
"unknown"); |
453 |
|
printf("-vp %f %f %f\t# view point\n", |
454 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
467 |
|
printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect); |
468 |
|
printf("-pj %f\t\t\t# pixel jitter\n", dstrpix); |
469 |
|
printf("-pm %f\t\t\t# pixel motion\n", mblur); |
470 |
+ |
printf("-pd %f\t\t\t# pixel depth-of-field\n", dblur); |
471 |
|
printf("-ps %-9d\t\t\t# pixel sample\n", psample); |
472 |
|
printf("-pt %f\t\t\t# pixel threshold\n", maxdiff); |
473 |
|
printf("-t %-9d\t\t\t# time between reports\n", ralrm); |