| 17 |
|
#include "ambient.h" |
| 18 |
|
#include "random.h" |
| 19 |
|
#include "paths.h" |
| 20 |
+ |
#include "pmapray.h" |
| 21 |
|
|
| 22 |
+ |
extern char *progname; /* global argv[0] */ |
| 23 |
+ |
|
| 24 |
+ |
extern char *shm_boundary; /* boundary of shared memory */ |
| 25 |
+ |
|
| 26 |
|
/* persistent processes define */ |
| 27 |
|
#ifdef F_SETLKW |
| 28 |
|
#define PERSIST 1 /* normal persist */ |
| 30 |
|
#define PCHILD 3 /* child of normal persist */ |
| 31 |
|
#endif |
| 32 |
|
|
| 28 |
– |
char *progname; /* argv[0] */ |
| 29 |
– |
char *octname; /* octree name */ |
| 33 |
|
char *sigerr[NSIG]; /* signal error messages */ |
| 31 |
– |
char *shm_boundary = NULL; /* boundary of shared memory */ |
| 34 |
|
char *errfile = NULL; /* error output file */ |
| 35 |
|
|
| 36 |
+ |
int nproc = 1; /* number of processes */ |
| 37 |
+ |
|
| 38 |
|
extern char *formstr(); /* string from format */ |
| 39 |
< |
extern int inform; /* input format */ |
| 40 |
< |
extern int outform; /* output format */ |
| 41 |
< |
extern char *outvals; /* output values */ |
| 39 |
> |
int inform = 'a'; /* input format */ |
| 40 |
> |
int outform = 'a'; /* output format */ |
| 41 |
> |
char *outvals = "v"; /* output specification */ |
| 42 |
|
|
| 43 |
< |
extern int hresolu; /* horizontal resolution */ |
| 44 |
< |
extern int vresolu; /* vertical resolution */ |
| 43 |
> |
int hresolu = 0; /* horizontal (scan) size */ |
| 44 |
> |
int vresolu = 0; /* vertical resolution */ |
| 45 |
|
|
| 46 |
< |
extern int imm_irrad; /* compute immediate irradiance? */ |
| 47 |
< |
extern int lim_dist; /* limit distance? */ |
| 46 |
> |
int imm_irrad = 0; /* compute immediate irradiance? */ |
| 47 |
> |
int lim_dist = 0; /* limit distance? */ |
| 48 |
|
|
| 49 |
< |
extern char *tralist[]; /* list of modifers to trace (or no) */ |
| 50 |
< |
extern int traincl; /* include == 1, exclude == 0 */ |
| 49 |
> |
#ifndef MAXMODLIST |
| 50 |
> |
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
| 51 |
> |
#endif |
| 52 |
|
|
| 53 |
+ |
extern void (*addobjnotify[])(); /* object notification calls */ |
| 54 |
+ |
extern void tranotify(OBJECT obj); |
| 55 |
+ |
|
| 56 |
+ |
char *tralist[MAXMODLIST]; /* list of modifers to trace (or no) */ |
| 57 |
+ |
int traincl = -1; /* include == 1, exclude == 0 */ |
| 58 |
+ |
|
| 59 |
|
static int loadflags = ~IO_FILES; /* what to load from octree */ |
| 60 |
|
|
| 61 |
|
static void onsig(int signo); |
| 69 |
|
#define check(ol,al) if (argv[i][ol] || \ |
| 70 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
| 71 |
|
goto badopt |
| 72 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
| 72 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
| 73 |
|
case '\0': var = !var; break; \ |
| 74 |
|
case 'y': case 'Y': case 't': case 'T': \ |
| 75 |
|
case '+': case '1': var = 1; break; \ |
| 76 |
|
case 'n': case 'N': case 'f': case 'F': \ |
| 77 |
|
case '-': case '0': var = 0; break; \ |
| 78 |
|
default: goto badopt; } |
| 79 |
+ |
extern char *octname; |
| 80 |
|
int persist = 0; |
| 81 |
< |
char **tralp; |
| 82 |
< |
int duped1; |
| 81 |
> |
char *octnm = NULL; |
| 82 |
> |
char **tralp = NULL; |
| 83 |
> |
int duped1 = -1; |
| 84 |
|
int rval; |
| 85 |
|
int i; |
| 86 |
|
/* global program name */ |
| 87 |
|
progname = argv[0] = fixargv0(argv[0]); |
| 88 |
+ |
/* add trace notify function */ |
| 89 |
+ |
for (i = 0; addobjnotify[i] != NULL; i++) |
| 90 |
+ |
; |
| 91 |
+ |
addobjnotify[i] = tranotify; |
| 92 |
+ |
/* set our defaults */ |
| 93 |
+ |
rand_samp = 1; |
| 94 |
+ |
maxdepth = -10; |
| 95 |
+ |
minweight = 2e-3; |
| 96 |
|
/* option city */ |
| 97 |
|
for (i = 1; i < argc; i++) { |
| 98 |
|
/* expand arguments */ |
| 119 |
|
continue; |
| 120 |
|
} |
| 121 |
|
switch (argv[i][1]) { |
| 122 |
+ |
case 'n': /* number of cores */ |
| 123 |
+ |
check(2,"i"); |
| 124 |
+ |
nproc = atoi(argv[++i]); |
| 125 |
+ |
if (nproc <= 0) |
| 126 |
+ |
error(USER, "bad number of processes"); |
| 127 |
+ |
break; |
| 128 |
|
case 'x': /* x resolution */ |
| 129 |
|
check(2,"i"); |
| 130 |
|
hresolu = atoi(argv[++i]); |
| 135 |
|
break; |
| 136 |
|
case 'w': /* warnings */ |
| 137 |
|
rval = erract[WARNING].pf != NULL; |
| 138 |
< |
bool(2,rval); |
| 138 |
> |
check_bool(2,rval); |
| 139 |
|
if (rval) erract[WARNING].pf = wputs; |
| 140 |
|
else erract[WARNING].pf = NULL; |
| 141 |
|
break; |
| 146 |
|
case 'l': /* limit distance */ |
| 147 |
|
if (argv[i][2] != 'd') |
| 148 |
|
goto badopt; |
| 149 |
< |
bool(3,lim_dist); |
| 149 |
> |
check_bool(3,lim_dist); |
| 150 |
|
break; |
| 151 |
|
case 'I': /* immed. irradiance */ |
| 152 |
< |
bool(2,imm_irrad); |
| 152 |
> |
check_bool(2,imm_irrad); |
| 153 |
|
break; |
| 154 |
|
case 'f': /* format i/o */ |
| 155 |
|
switch (argv[i][2]) { |
| 181 |
|
break; |
| 182 |
|
case 'h': /* header output */ |
| 183 |
|
rval = loadflags & IO_INFO; |
| 184 |
< |
bool(2,rval); |
| 184 |
> |
check_bool(2,rval); |
| 185 |
|
loadflags = rval ? loadflags | IO_INFO : |
| 186 |
|
loadflags & ~IO_INFO; |
| 187 |
|
break; |
| 251 |
|
goto badopt; |
| 252 |
|
} |
| 253 |
|
} |
| 254 |
+ |
if (nproc > 1) { |
| 255 |
+ |
if (persist) |
| 256 |
+ |
error(USER, "multiprocessing incompatible with persist file"); |
| 257 |
+ |
if (!vresolu && hresolu > 0 && hresolu < nproc) |
| 258 |
+ |
error(WARNING, "number of cores should not exceed horizontal resolution"); |
| 259 |
+ |
if (trace != NULL) |
| 260 |
+ |
error(WARNING, "multiprocessing does not work properly with trace mode"); |
| 261 |
+ |
} |
| 262 |
|
/* initialize object types */ |
| 263 |
|
initotypes(); |
| 264 |
|
/* initialize urand */ |
| 300 |
|
#endif |
| 301 |
|
/* get octree */ |
| 302 |
|
if (i == argc) |
| 303 |
< |
octname = NULL; |
| 303 |
> |
octnm = NULL; |
| 304 |
|
else if (i == argc-1) |
| 305 |
< |
octname = argv[i]; |
| 305 |
> |
octnm = argv[i]; |
| 306 |
|
else |
| 307 |
|
goto badopt; |
| 308 |
< |
if (octname == NULL) |
| 308 |
> |
if (octnm == NULL) |
| 309 |
|
error(USER, "missing octree argument"); |
| 310 |
|
/* set up output */ |
| 311 |
|
#ifdef PERSIST |
| 316 |
|
#endif |
| 317 |
|
if (outform != 'a') |
| 318 |
|
SET_FILE_BINARY(stdout); |
| 319 |
< |
readoct(octname, loadflags, &thescene, NULL); |
| 319 |
> |
readoct(octname = octnm, loadflags, &thescene, NULL); |
| 320 |
|
nsceneobjs = nobjects; |
| 321 |
|
|
| 322 |
|
if (loadflags & IO_INFO) { /* print header */ |
| 326 |
|
fputformat(formstr(outform), stdout); |
| 327 |
|
putchar('\n'); |
| 328 |
|
} |
| 329 |
< |
|
| 329 |
> |
|
| 330 |
> |
ray_init_pmap(); /* PMAP: set up & load photon maps */ |
| 331 |
> |
|
| 332 |
|
marksources(); /* find and mark sources */ |
| 333 |
|
|
| 334 |
|
setambient(); /* initialize ambient calculation */ |
| 335 |
< |
|
| 335 |
> |
|
| 336 |
|
#ifdef PERSIST |
| 337 |
|
if (persist) { |
| 338 |
|
fflush(stdout); |
| 358 |
|
dupheader(); /* send header to stdout */ |
| 359 |
|
#endif |
| 360 |
|
/* trace rays */ |
| 361 |
< |
rtrace(NULL); |
| 361 |
> |
rtrace(NULL, nproc); |
| 362 |
|
/* flush ambient file */ |
| 363 |
|
ambsync(); |
| 364 |
|
#ifdef PERSIST |
| 373 |
|
} |
| 374 |
|
} |
| 375 |
|
if (persist == PCHILD) { /* wait for a signal then go again */ |
| 339 |
– |
close(duped1); /* release output handle */ |
| 376 |
|
pfhold(); |
| 377 |
|
raynum = nrays = 0; /* reinitialize */ |
| 378 |
|
goto runagain; |
| 379 |
|
} |
| 380 |
|
#endif |
| 381 |
+ |
|
| 382 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
| 383 |
+ |
|
| 384 |
|
quit(0); |
| 385 |
|
|
| 386 |
|
badopt: |
| 389 |
|
return 1; /* pro forma return */ |
| 390 |
|
|
| 391 |
|
#undef check |
| 392 |
< |
#undef bool |
| 392 |
> |
#undef check_bool |
| 393 |
|
} |
| 394 |
|
|
| 395 |
|
|
| 465 |
|
|
| 466 |
|
if (imm_irrad) |
| 467 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
| 468 |
< |
printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu); |
| 469 |
< |
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
| 468 |
> |
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
| 469 |
> |
printf("-x %-9d\t\t\t# %s\n", hresolu, |
| 470 |
> |
vresolu && hresolu ? "x resolution" : "flush interval"); |
| 471 |
> |
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
| 472 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
| 473 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
| 474 |
|
printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', |