5 |
|
* rpmain.c - main for rpict batch rendering program |
6 |
|
*/ |
7 |
|
|
8 |
< |
/* ==================================================================== |
9 |
< |
* The Radiance Software License, Version 1.0 |
10 |
< |
* |
11 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
12 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
13 |
< |
* |
14 |
< |
* Redistribution and use in source and binary forms, with or without |
15 |
< |
* modification, are permitted provided that the following conditions |
16 |
< |
* are met: |
17 |
< |
* |
18 |
< |
* 1. Redistributions of source code must retain the above copyright |
19 |
< |
* notice, this list of conditions and the following disclaimer. |
20 |
< |
* |
21 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
22 |
< |
* notice, this list of conditions and the following disclaimer in |
23 |
< |
* the documentation and/or other materials provided with the |
24 |
< |
* distribution. |
25 |
< |
* |
26 |
< |
* 3. The end-user documentation included with the redistribution, |
27 |
< |
* if any, must include the following acknowledgment: |
28 |
< |
* "This product includes Radiance software |
29 |
< |
* (http://radsite.lbl.gov/) |
30 |
< |
* developed by the Lawrence Berkeley National Laboratory |
31 |
< |
* (http://www.lbl.gov/)." |
32 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
33 |
< |
* if and wherever such third-party acknowledgments normally appear. |
34 |
< |
* |
35 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
36 |
< |
* and "The Regents of the University of California" must |
37 |
< |
* not be used to endorse or promote products derived from this |
38 |
< |
* software without prior written permission. For written |
39 |
< |
* permission, please contact [email protected]. |
40 |
< |
* |
41 |
< |
* 5. Products derived from this software may not be called "Radiance", |
42 |
< |
* nor may "Radiance" appear in their name, without prior written |
43 |
< |
* permission of Lawrence Berkeley National Laboratory. |
44 |
< |
* |
45 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
46 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
47 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
48 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
49 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
50 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
51 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
52 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
53 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
54 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
55 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 |
< |
* SUCH DAMAGE. |
57 |
< |
* ==================================================================== |
58 |
< |
* |
59 |
< |
* This software consists of voluntary contributions made by many |
60 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
61 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
62 |
< |
* <http://www.lbl.gov/>. |
63 |
< |
*/ |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include <time.h> |
11 |
> |
#include <signal.h> |
12 |
|
|
13 |
+ |
#include "platform.h" |
14 |
+ |
#include "rtprocess.h" /* getpid() */ |
15 |
+ |
#include "ray.h" |
16 |
|
#include "source.h" |
68 |
– |
|
17 |
|
#include "ambient.h" |
70 |
– |
|
18 |
|
#include "random.h" |
72 |
– |
|
19 |
|
#include "paths.h" |
74 |
– |
|
75 |
– |
#include <sys/types.h> |
76 |
– |
|
77 |
– |
#include <signal.h> |
78 |
– |
|
20 |
|
#include "view.h" |
21 |
+ |
#include "pmapray.h" |
22 |
|
|
81 |
– |
#include "paths.h" |
23 |
|
/* persistent processes define */ |
24 |
|
#ifdef F_SETLKW |
25 |
|
#define PERSIST 1 /* normal persist */ |
28 |
|
#endif |
29 |
|
|
30 |
|
char *progname; /* argv[0] */ |
90 |
– |
|
31 |
|
char *octname; /* octree name */ |
92 |
– |
|
32 |
|
char *sigerr[NSIG]; /* signal error messages */ |
94 |
– |
|
33 |
|
char *shm_boundary = NULL; /* boundary of shared memory */ |
96 |
– |
|
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(); |
117 |
< |
void sigdie(); |
118 |
< |
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 |
+ |
/* rpict additional features */ |
59 |
+ |
#ifdef PERSIST |
60 |
+ |
#define RPICT_FEATURES "Persist\nParallelPersist\n" \ |
61 |
+ |
"Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \ |
62 |
+ |
"HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \ |
63 |
+ |
"PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \ |
64 |
+ |
"SmallSourceDrawing\nViewSequence\nProgressReporting\n" \ |
65 |
+ |
"AdaptiveShadowTesting\nOutputs=v,l\n" |
66 |
+ |
#else |
67 |
+ |
#define RPICT_FEATURES "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \ |
68 |
+ |
"HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \ |
69 |
+ |
"PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \ |
70 |
+ |
"SmallSourceDrawing\nViewSequence\nProgressReporting\n" \ |
71 |
+ |
"AdaptiveShadowTesting\nOutputs=v,l\n" |
72 |
+ |
#endif |
73 |
|
|
74 |
+ |
|
75 |
|
int |
76 |
< |
main(argc, argv) |
123 |
< |
int argc; |
124 |
< |
char *argv[]; |
76 |
> |
main(int argc, char *argv[]) |
77 |
|
{ |
78 |
|
#define check(ol,al) if (argv[i][ol] || \ |
79 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
80 |
|
goto badopt |
81 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
81 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
82 |
|
case '\0': var = !var; break; \ |
83 |
|
case 'y': case 'Y': case 't': case 'T': \ |
84 |
|
case '+': case '1': var = 1; break; \ |
92 |
|
int loadflags = ~IO_FILES; |
93 |
|
int seqstart = 0; |
94 |
|
int persist = 0; |
95 |
< |
int duped1; |
95 |
> |
int duped1 = -1; |
96 |
|
int rval; |
97 |
|
int i; |
98 |
|
/* record start time */ |
99 |
|
tstart = time((time_t *)NULL); |
100 |
|
/* global program name */ |
101 |
|
progname = argv[0] = fixargv0(argv[0]); |
102 |
+ |
/* feature check only? */ |
103 |
+ |
strcat(RFeatureList, RPICT_FEATURES); |
104 |
+ |
if (argc > 1 && !strcmp(argv[1], "-features")) |
105 |
+ |
return feature_status(argc-2, argv+2); |
106 |
|
/* option city */ |
107 |
|
for (i = 1; i < argc; i++) { |
108 |
|
/* expand arguments */ |
174 |
|
check(3,"f"); |
175 |
|
mblur = atof(argv[++i]); |
176 |
|
break; |
177 |
+ |
case 'd': /* aperture */ |
178 |
+ |
check(3,"f"); |
179 |
+ |
dblur = atof(argv[++i]); |
180 |
+ |
break; |
181 |
|
default: |
182 |
|
goto badopt; |
183 |
|
} |
228 |
|
#endif |
229 |
|
case 'w': /* warnings */ |
230 |
|
rval = erract[WARNING].pf != NULL; |
231 |
< |
bool(2,rval); |
231 |
> |
check_bool(2,rval); |
232 |
|
if (rval) erract[WARNING].pf = wputs; |
233 |
|
else erract[WARNING].pf = NULL; |
234 |
|
break; |
246 |
|
/* initialize object types */ |
247 |
|
initotypes(); |
248 |
|
/* initialize urand */ |
249 |
< |
initurand(2048); |
249 |
> |
if (rand_samp) { |
250 |
> |
srandom((long)time(0)); |
251 |
> |
initurand(0); |
252 |
> |
} else { |
253 |
> |
srandom(0L); |
254 |
> |
initurand(2048); |
255 |
> |
} |
256 |
|
/* set up signal handling */ |
257 |
|
sigdie(SIGINT, "Interrupt"); |
258 |
+ |
#ifdef SIGHUP |
259 |
|
sigdie(SIGHUP, "Hangup"); |
260 |
+ |
#endif |
261 |
|
sigdie(SIGTERM, "Terminate"); |
262 |
+ |
#ifdef SIGPIPE |
263 |
|
sigdie(SIGPIPE, "Broken pipe"); |
264 |
+ |
#endif |
265 |
+ |
#ifdef SIGALRM |
266 |
|
sigdie(SIGALRM, "Alarm clock"); |
267 |
+ |
#endif |
268 |
|
#ifdef SIGXCPU |
269 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
270 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
305 |
|
#endif |
306 |
|
if (outfile != NULL) |
307 |
|
openheader(); |
308 |
< |
#ifdef MSDOS |
337 |
< |
setmode(fileno(stdout), O_BINARY); |
308 |
> |
SET_FILE_BINARY(stdout); |
309 |
|
if (octname == NULL) |
310 |
< |
setmode(fileno(stdin), O_BINARY); |
340 |
< |
#endif |
310 |
> |
SET_FILE_BINARY(stdin); |
311 |
|
readoct(octname, loadflags, &thescene, NULL); |
312 |
|
nsceneobjs = nobjects; |
313 |
|
|
314 |
|
if (loadflags & IO_INFO) { /* print header */ |
315 |
|
printargs(i, argv, stdout); |
316 |
|
printf("SOFTWARE= %s\n", VersionID); |
347 |
– |
fputnow(stdout); |
317 |
|
} |
318 |
+ |
|
319 |
+ |
ray_init_pmap(); /* PMAP: set up & load photon maps */ |
320 |
|
|
321 |
|
marksources(); /* find and mark sources */ |
322 |
|
|
323 |
|
setambient(); /* initialize ambient calculation */ |
324 |
+ |
|
325 |
+ |
fflush(stdout); /* in case we're duplicating header */ |
326 |
|
|
327 |
|
#ifdef PERSIST |
328 |
|
if (persist) { |
356 |
– |
fflush(stdout); |
329 |
|
if (outfile == NULL) { /* reconnect stdout */ |
330 |
|
dup2(duped1, fileno(stdout)); |
331 |
|
close(duped1); |
338 |
|
pflock(1); |
339 |
|
pfhold(); |
340 |
|
tstart = time((time_t *)NULL); |
341 |
+ |
ambsync(); /* load new values */ |
342 |
|
} |
343 |
|
if (rval < 0) |
344 |
|
error(SYSTEM, "cannot fork child for persist function"); |
345 |
< |
pfdetach(); /* parent exits */ |
345 |
> |
pfdetach(); /* parent will run then exit */ |
346 |
|
} |
347 |
|
} |
348 |
|
runagain: |
349 |
< |
if (persist) |
349 |
> |
if (persist) { |
350 |
|
if (outfile == NULL) /* if out to stdout */ |
351 |
|
dupheader(); /* send header */ |
352 |
|
else /* if out to file */ |
353 |
|
duped1 = dup(fileno(stdout)); /* hang onto pipe */ |
354 |
+ |
} |
355 |
|
#endif |
356 |
|
/* batch render picture(s) */ |
357 |
|
rpict(seqstart, outfile, zfile, recover); |
377 |
|
goto runagain; |
378 |
|
} |
379 |
|
#endif |
380 |
+ |
|
381 |
+ |
|
382 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
383 |
+ |
|
384 |
|
quit(0); |
385 |
|
|
386 |
|
badopt: |
387 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
388 |
|
error(USER, errmsg); |
389 |
+ |
return 1; /* pro forma return */ |
390 |
|
|
391 |
|
#undef check |
392 |
< |
#undef bool |
392 |
> |
#undef check_bool |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
|
void |
397 |
< |
wputs(s) /* warning output function */ |
398 |
< |
char *s; |
397 |
> |
wputs( /* warning output function */ |
398 |
> |
char *s |
399 |
> |
) |
400 |
|
{ |
401 |
|
int lasterrno = errno; |
402 |
|
eputs(s); |
405 |
|
|
406 |
|
|
407 |
|
void |
408 |
< |
eputs(s) /* put string to stderr */ |
409 |
< |
register char *s; |
408 |
> |
eputs( /* put string to stderr */ |
409 |
> |
char *s |
410 |
> |
) |
411 |
|
{ |
412 |
|
static int midline = 0; |
413 |
|
|
425 |
|
} |
426 |
|
|
427 |
|
|
428 |
< |
void |
429 |
< |
onsig(signo) /* fatal signal */ |
430 |
< |
int signo; |
428 |
> |
static void |
429 |
> |
onsig( /* fatal signal */ |
430 |
> |
int signo |
431 |
> |
) |
432 |
|
{ |
433 |
|
static int gotsig = 0; |
434 |
|
|
435 |
|
if (gotsig++) /* two signals and we're gone! */ |
436 |
|
_exit(signo); |
437 |
|
|
438 |
+ |
#ifdef SIGALRM /* XXX how critical is this? */ |
439 |
|
alarm(15); /* allow 15 seconds to clean up */ |
440 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
441 |
+ |
#endif |
442 |
|
eputs("signal - "); |
443 |
|
eputs(sigerr[signo]); |
444 |
|
eputs("\n"); |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
< |
void |
450 |
< |
sigdie(signo, msg) /* set fatal signal */ |
451 |
< |
int signo; |
452 |
< |
char *msg; |
449 |
> |
static void |
450 |
> |
sigdie( /* set fatal signal */ |
451 |
> |
int signo, |
452 |
> |
char *msg |
453 |
> |
) |
454 |
|
{ |
455 |
|
if (signal(signo, onsig) == SIG_IGN) |
456 |
|
signal(signo, SIG_IGN); |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
< |
void |
462 |
< |
printdefaults() /* print default values to stdout */ |
461 |
> |
static void |
462 |
> |
printdefaults(void) /* print default values to stdout */ |
463 |
|
{ |
479 |
– |
register char *cp; |
480 |
– |
|
464 |
|
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
465 |
|
ourview.type==VT_PER ? "perspective" : |
466 |
|
ourview.type==VT_PAR ? "parallel" : |
467 |
|
ourview.type==VT_HEM ? "hemispherical" : |
468 |
|
ourview.type==VT_ANG ? "angular" : |
469 |
|
ourview.type==VT_CYL ? "cylindrical" : |
470 |
+ |
ourview.type==VT_PLS ? "planisphere" : |
471 |
|
"unknown"); |
472 |
|
printf("-vp %f %f %f\t# view point\n", |
473 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
486 |
|
printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect); |
487 |
|
printf("-pj %f\t\t\t# pixel jitter\n", dstrpix); |
488 |
|
printf("-pm %f\t\t\t# pixel motion\n", mblur); |
489 |
+ |
printf("-pd %f\t\t\t# pixel depth-of-field\n", dblur); |
490 |
|
printf("-ps %-9d\t\t\t# pixel sample\n", psample); |
491 |
|
printf("-pt %f\t\t\t# pixel threshold\n", maxdiff); |
492 |
|
printf("-t %-9d\t\t\t# time between reports\n", ralrm); |