5 |
|
* rtmain.c - main for rtrace per-ray calculation 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 <signal.h> |
11 |
|
|
12 |
+ |
#include "platform.h" |
13 |
+ |
#include "rtprocess.h" /* getpid() */ |
14 |
+ |
#include "resolu.h" |
15 |
+ |
#include "ray.h" |
16 |
|
#include "source.h" |
68 |
– |
|
17 |
|
#include "ambient.h" |
70 |
– |
|
18 |
|
#include "random.h" |
72 |
– |
|
19 |
|
#include "paths.h" |
20 |
|
|
21 |
< |
#include <sys/types.h> |
21 |
> |
extern char *progname; /* global argv[0] */ |
22 |
|
|
23 |
< |
#include <signal.h> |
23 |
> |
extern char *shm_boundary; /* boundary of shared memory */ |
24 |
> |
|
25 |
|
/* persistent processes define */ |
26 |
|
#ifdef F_SETLKW |
27 |
|
#define PERSIST 1 /* normal persist */ |
29 |
|
#define PCHILD 3 /* child of normal persist */ |
30 |
|
#endif |
31 |
|
|
32 |
< |
char *progname; /* argv[0] */ |
32 |
> |
char *sigerr[NSIG]; /* signal error messages */ |
33 |
> |
char *errfile = NULL; /* error output file */ |
34 |
|
|
35 |
< |
char *octname; /* octree name */ |
35 |
> |
int nproc = 1; /* number of processes */ |
36 |
|
|
37 |
< |
char *sigerr[NSIG]; /* signal error messages */ |
37 |
> |
extern char *formstr(); /* string from format */ |
38 |
> |
int inform = 'a'; /* input format */ |
39 |
> |
int outform = 'a'; /* output format */ |
40 |
> |
char *outvals = "v"; /* output specification */ |
41 |
|
|
42 |
< |
char *shm_boundary = NULL; /* boundary of shared memory */ |
42 |
> |
int hresolu = 0; /* horizontal (scan) size */ |
43 |
> |
int vresolu = 0; /* vertical resolution */ |
44 |
|
|
45 |
< |
char *errfile = NULL; /* error output file */ |
45 |
> |
int imm_irrad = 0; /* compute immediate irradiance? */ |
46 |
> |
int lim_dist = 0; /* limit distance? */ |
47 |
|
|
48 |
< |
extern char *formstr(); /* string from format */ |
49 |
< |
extern int inform; /* input format */ |
50 |
< |
extern int outform; /* output format */ |
98 |
< |
extern char *outvals; /* output values */ |
48 |
> |
#ifndef MAXMODLIST |
49 |
> |
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
50 |
> |
#endif |
51 |
|
|
52 |
< |
extern int hresolu; /* horizontal resolution */ |
53 |
< |
extern int vresolu; /* vertical resolution */ |
52 |
> |
extern void (*addobjnotify[])(); /* object notification calls */ |
53 |
> |
extern void tranotify(OBJECT obj); |
54 |
|
|
55 |
< |
extern int imm_irrad; /* compute immediate irradiance? */ |
56 |
< |
extern int lim_dist; /* limit distance? */ |
55 |
> |
char *tralist[MAXMODLIST]; /* list of modifers to trace (or no) */ |
56 |
> |
int traincl = -1; /* include == 1, exclude == 0 */ |
57 |
|
|
58 |
< |
extern char *tralist[]; /* list of modifers to trace (or no) */ |
107 |
< |
extern int traincl; /* include == 1, exclude == 0 */ |
58 |
> |
static int loadflags = ~IO_FILES; /* what to load from octree */ |
59 |
|
|
60 |
< |
void onsig(); |
61 |
< |
void sigdie(); |
62 |
< |
void printdefaults(); |
60 |
> |
static void onsig(int signo); |
61 |
> |
static void sigdie(int signo, char *msg); |
62 |
> |
static void printdefaults(void); |
63 |
|
|
64 |
|
|
65 |
|
int |
66 |
< |
main(argc, argv) |
116 |
< |
int argc; |
117 |
< |
char *argv[]; |
66 |
> |
main(int argc, char *argv[]) |
67 |
|
{ |
68 |
|
#define check(ol,al) if (argv[i][ol] || \ |
69 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
75 |
|
case 'n': case 'N': case 'f': case 'F': \ |
76 |
|
case '-': case '0': var = 0; break; \ |
77 |
|
default: goto badopt; } |
129 |
– |
int loadflags = ~IO_FILES; |
78 |
|
int persist = 0; |
79 |
+ |
char *octnm = NULL; |
80 |
|
char **tralp; |
81 |
|
int duped1; |
82 |
|
int rval; |
83 |
|
int i; |
84 |
|
/* global program name */ |
85 |
|
progname = argv[0] = fixargv0(argv[0]); |
86 |
+ |
/* add trace notify function */ |
87 |
+ |
for (i = 0; addobjnotify[i] != NULL; i++) |
88 |
+ |
; |
89 |
+ |
addobjnotify[i] = tranotify; |
90 |
+ |
/* set our defaults */ |
91 |
+ |
rand_samp = 1; |
92 |
+ |
maxdepth = -10; |
93 |
+ |
minweight = 2e-3; |
94 |
|
/* option city */ |
95 |
|
for (i = 1; i < argc; i++) { |
96 |
|
/* expand arguments */ |
117 |
|
continue; |
118 |
|
} |
119 |
|
switch (argv[i][1]) { |
120 |
+ |
case 'n': /* number of cores */ |
121 |
+ |
check(2,"i"); |
122 |
+ |
nproc = atoi(argv[++i]); |
123 |
+ |
if (nproc <= 0) |
124 |
+ |
error(USER, "bad number of processes"); |
125 |
+ |
break; |
126 |
|
case 'x': /* x resolution */ |
127 |
|
check(2,"i"); |
128 |
|
hresolu = atoi(argv[++i]); |
194 |
|
} |
195 |
|
if (argv[i][2] == 'I') { /* file */ |
196 |
|
rval = wordfile(tralp, |
197 |
< |
getpath(argv[++i],getlibpath(),R_OK)); |
197 |
> |
getpath(argv[++i],getrlibpath(),R_OK)); |
198 |
|
if (rval < 0) { |
199 |
|
sprintf(errmsg, |
200 |
|
"cannot open trace include file \"%s\"", |
216 |
|
} |
217 |
|
if (argv[i][2] == 'E') { /* file */ |
218 |
|
rval = wordfile(tralp, |
219 |
< |
getpath(argv[++i],getlibpath(),R_OK)); |
219 |
> |
getpath(argv[++i],getrlibpath(),R_OK)); |
220 |
|
if (rval < 0) { |
221 |
|
sprintf(errmsg, |
222 |
|
"cannot open trace exclude file \"%s\"", |
249 |
|
goto badopt; |
250 |
|
} |
251 |
|
} |
252 |
+ |
if (nproc > 1) { |
253 |
+ |
if (persist) |
254 |
+ |
error(USER, "multiprocessing incompatible with persist file"); |
255 |
+ |
if (hresolu > 0 && hresolu < nproc) |
256 |
+ |
error(WARNING, "number of cores should not exceed horizontal resolution"); |
257 |
+ |
if (trace != NULL) |
258 |
+ |
error(WARNING, "multiprocessing does not work properly with trace mode"); |
259 |
+ |
} |
260 |
|
/* initialize object types */ |
261 |
|
initotypes(); |
262 |
|
/* initialize urand */ |
263 |
< |
initurand(2048); |
263 |
> |
if (rand_samp) { |
264 |
> |
srandom((long)time(0)); |
265 |
> |
initurand(0); |
266 |
> |
} else { |
267 |
> |
srandom(0L); |
268 |
> |
initurand(2048); |
269 |
> |
} |
270 |
|
/* set up signal handling */ |
271 |
|
sigdie(SIGINT, "Interrupt"); |
272 |
+ |
#ifdef SIGHUP |
273 |
|
sigdie(SIGHUP, "Hangup"); |
274 |
+ |
#endif |
275 |
|
sigdie(SIGTERM, "Terminate"); |
276 |
+ |
#ifdef SIGPIPE |
277 |
|
sigdie(SIGPIPE, "Broken pipe"); |
278 |
+ |
#endif |
279 |
+ |
#ifdef SIGALRM |
280 |
|
sigdie(SIGALRM, "Alarm clock"); |
281 |
+ |
#endif |
282 |
|
#ifdef SIGXCPU |
283 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
284 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
298 |
|
#endif |
299 |
|
/* get octree */ |
300 |
|
if (i == argc) |
301 |
< |
octname = NULL; |
301 |
> |
octnm = NULL; |
302 |
|
else if (i == argc-1) |
303 |
< |
octname = argv[i]; |
303 |
> |
octnm = argv[i]; |
304 |
|
else |
305 |
|
goto badopt; |
306 |
< |
if (octname == NULL) |
306 |
> |
if (octnm == NULL) |
307 |
|
error(USER, "missing octree argument"); |
308 |
|
/* set up output */ |
309 |
|
#ifdef PERSIST |
312 |
|
openheader(); |
313 |
|
} |
314 |
|
#endif |
332 |
– |
#ifdef MSDOS |
315 |
|
if (outform != 'a') |
316 |
< |
setmode(fileno(stdout), O_BINARY); |
317 |
< |
if (octname == NULL) |
336 |
< |
setmode(fileno(stdin), O_BINARY); |
337 |
< |
#endif |
338 |
< |
readoct(octname, loadflags, &thescene, NULL); |
316 |
> |
SET_FILE_BINARY(stdout); |
317 |
> |
readoct(octnm, loadflags, &thescene, NULL); |
318 |
|
nsceneobjs = nobjects; |
319 |
|
|
320 |
|
if (loadflags & IO_INFO) { /* print header */ |
342 |
|
while ((rval=fork()) == 0) { /* keep on forkin' */ |
343 |
|
pflock(1); |
344 |
|
pfhold(); |
345 |
+ |
ambsync(); /* load new values */ |
346 |
|
} |
347 |
|
if (rval < 0) |
348 |
|
error(SYSTEM, "cannot fork child for persist function"); |
349 |
< |
pfdetach(); /* parent exits */ |
349 |
> |
pfdetach(); /* parent will run then exit */ |
350 |
|
} |
351 |
|
} |
352 |
|
runagain: |
354 |
|
dupheader(); /* send header to stdout */ |
355 |
|
#endif |
356 |
|
/* trace rays */ |
357 |
< |
rtrace(NULL); |
357 |
> |
rtrace(NULL, nproc); |
358 |
|
/* flush ambient file */ |
359 |
|
ambsync(); |
360 |
|
#ifdef PERSIST |
369 |
|
} |
370 |
|
} |
371 |
|
if (persist == PCHILD) { /* wait for a signal then go again */ |
392 |
– |
close(duped1); /* release output handle */ |
372 |
|
pfhold(); |
373 |
|
raynum = nrays = 0; /* reinitialize */ |
374 |
|
goto runagain; |
379 |
|
badopt: |
380 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
381 |
|
error(USER, errmsg); |
382 |
+ |
return 1; /* pro forma return */ |
383 |
|
|
384 |
|
#undef check |
385 |
|
#undef bool |
387 |
|
|
388 |
|
|
389 |
|
void |
390 |
< |
wputs(s) /* warning output function */ |
391 |
< |
char *s; |
390 |
> |
wputs( /* warning output function */ |
391 |
> |
char *s |
392 |
> |
) |
393 |
|
{ |
394 |
|
int lasterrno = errno; |
395 |
|
eputs(s); |
398 |
|
|
399 |
|
|
400 |
|
void |
401 |
< |
eputs(s) /* put string to stderr */ |
402 |
< |
register char *s; |
401 |
> |
eputs( /* put string to stderr */ |
402 |
> |
register char *s |
403 |
> |
) |
404 |
|
{ |
405 |
|
static int midline = 0; |
406 |
|
|
418 |
|
} |
419 |
|
|
420 |
|
|
421 |
< |
void |
422 |
< |
onsig(signo) /* fatal signal */ |
423 |
< |
int signo; |
421 |
> |
static void |
422 |
> |
onsig( /* fatal signal */ |
423 |
> |
int signo |
424 |
> |
) |
425 |
|
{ |
426 |
|
static int gotsig = 0; |
427 |
|
|
428 |
|
if (gotsig++) /* two signals and we're gone! */ |
429 |
|
_exit(signo); |
430 |
|
|
431 |
+ |
#ifdef SIGALRM |
432 |
|
alarm(15); /* allow 15 seconds to clean up */ |
433 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
434 |
+ |
#endif |
435 |
|
eputs("signal - "); |
436 |
|
eputs(sigerr[signo]); |
437 |
|
eputs("\n"); |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
< |
void |
443 |
< |
sigdie(signo, msg) /* set fatal signal */ |
444 |
< |
int signo; |
445 |
< |
char *msg; |
442 |
> |
static void |
443 |
> |
sigdie( /* set fatal signal */ |
444 |
> |
int signo, |
445 |
> |
char *msg |
446 |
> |
) |
447 |
|
{ |
448 |
|
if (signal(signo, onsig) == SIG_IGN) |
449 |
|
signal(signo, SIG_IGN); |
451 |
|
} |
452 |
|
|
453 |
|
|
454 |
< |
void |
455 |
< |
printdefaults() /* print default values to stdout */ |
454 |
> |
static void |
455 |
> |
printdefaults(void) /* print default values to stdout */ |
456 |
|
{ |
457 |
|
register char *cp; |
458 |
|
|
459 |
|
if (imm_irrad) |
460 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
461 |
< |
printf("-x %-9d\t\t\t# x resolution\n", hresolu); |
462 |
< |
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
461 |
> |
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
462 |
> |
printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu); |
463 |
> |
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
464 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
465 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
466 |
+ |
printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', |
467 |
+ |
loadflags & IO_INFO ? "output" : "no"); |
468 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
469 |
|
inform, outform, formstr(inform), formstr(outform)); |
470 |
< |
printf("-o%s\t\t\t\t# output", outvals); |
470 |
> |
printf("-o%-9s\t\t\t# output", outvals); |
471 |
|
for (cp = outvals; *cp; cp++) |
472 |
|
switch (*cp) { |
473 |
< |
case 't': printf(" trace"); break; |
473 |
> |
case 't': case 'T': printf(" trace"); break; |
474 |
|
case 'o': printf(" origin"); break; |
475 |
|
case 'd': printf(" direction"); break; |
476 |
|
case 'v': printf(" value"); break; |
477 |
+ |
case 'V': printf(" contribution"); break; |
478 |
|
case 'l': printf(" length"); break; |
479 |
|
case 'L': printf(" first_length"); break; |
480 |
|
case 'p': printf(" point"); break; |
482 |
|
case 'N': printf(" unperturbed_normal"); break; |
483 |
|
case 's': printf(" surface"); break; |
484 |
|
case 'w': printf(" weight"); break; |
485 |
+ |
case 'W': printf(" coefficient"); break; |
486 |
|
case 'm': printf(" modifier"); break; |
487 |
+ |
case 'M': printf(" material"); break; |
488 |
+ |
case '-': printf(" stroke"); break; |
489 |
|
} |
490 |
|
putchar('\n'); |
491 |
|
printf(erract[WARNING].pf != NULL ? |