| 21 |
|
int inpfmt = 'a'; /* input format */ |
| 22 |
|
int outfmt = 'f'; /* output format */ |
| 23 |
|
|
| 24 |
– |
int contrib = 0; /* computing contributions? */ |
| 25 |
– |
|
| 26 |
– |
int xres = 0; /* horizontal (scan) size */ |
| 27 |
– |
int yres = 0; /* vertical resolution */ |
| 28 |
– |
|
| 29 |
– |
int imm_irrad = 0; /* compute immediate irradiance? */ |
| 30 |
– |
int lim_dist = 0; /* limit distance? */ |
| 31 |
– |
|
| 24 |
|
int report_intvl = 0; /* reporting interval (seconds) */ |
| 25 |
|
|
| 26 |
|
extern char * progname; // global argv[0] |
| 30 |
|
#define RCONTRIB_FEATURES "Multiprocessing\n" \ |
| 31 |
|
"Accumulation\nRecovery\n" \ |
| 32 |
|
"ImmediateIrradiance\n" \ |
| 33 |
< |
"ProgressReporting?\nDistanceLimiting\n" \ |
| 33 |
> |
"ProgressReporting\nDistanceLimiting\n" \ |
| 34 |
|
"InputFormats=a,f,d\nOutputFormats=f,d,c\n" \ |
| 35 |
|
"Outputs=V,W\n" \ |
| 36 |
|
"OutputCS=RGB,spec\n" |
| 41 |
|
printdefaults(void) /* print default values to stdout */ |
| 42 |
|
{ |
| 43 |
|
printf("-c %-5d\t\t\t# accumulated rays per record\n", myRCmanager.accum); |
| 44 |
< |
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
| 45 |
< |
contrib ? "contributions" : "coefficients"); |
| 46 |
< |
if (imm_irrad) |
| 44 |
> |
printf(myRCmanager.HasFlag(RCcontrib) ? |
| 45 |
> |
"-V+\t\t\t\t# output contributions\n" : |
| 46 |
> |
"-V-\t\t\t\t# output coefficients\n"); |
| 47 |
> |
if (myRCmanager.HasFlag(RTimmIrrad)) |
| 48 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
| 49 |
|
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
| 50 |
< |
if (xres > 0) |
| 51 |
< |
printf("-x %-9d\t\t\t# x resolution\n", xres); |
| 52 |
< |
printf("-y %-9d\t\t\t# y resolution\n", yres); |
| 53 |
< |
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
| 50 |
> |
printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres); |
| 51 |
> |
printf("-y %-9d\t\t\t# y resolution\n", myRCmanager.yres); |
| 52 |
> |
printf(myRCmanager.HasFlag(RTlimDist) ? |
| 53 |
> |
"-ld+\t\t\t\t# limit distance on\n" : |
| 54 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
| 55 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
| 56 |
|
inpfmt, outfmt, formstr(inpfmt), formstr(outfmt)); |
| 57 |
|
if (report_intvl > 0) |
| 58 |
< |
printf("-t %-9d\t\t\t# time between reports\n", report_intvl); |
| 58 |
> |
printf("-t %-9d\t\t\t# time between reports\n", report_intvl); |
| 59 |
|
printf(erract[WARNING].pf != NULL ? |
| 60 |
|
"-w+\t\t\t\t# warning messages on\n" : |
| 61 |
|
"-w-\t\t\t\t# warning messages off\n"); |
| 74 |
|
_exit(signo); |
| 75 |
|
|
| 76 |
|
#ifdef SIGALRM |
| 77 |
< |
alarm(15); /* allow 15 seconds to clean up */ |
| 77 |
> |
alarm(600); /* allow 10 minutes to clean up */ |
| 78 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 79 |
|
#endif |
| 80 |
|
eputs("signal - "); |
| 95 |
|
sigerr[signo] = msg; |
| 96 |
|
} |
| 97 |
|
|
| 105 |
– |
const char * |
| 106 |
– |
formstr(int f) // return format identifier |
| 107 |
– |
{ |
| 108 |
– |
switch (f) { |
| 109 |
– |
case 'a': return("ascii"); |
| 110 |
– |
case 'f': return("float"); |
| 111 |
– |
case 'd': return("double"); |
| 112 |
– |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
| 113 |
– |
} |
| 114 |
– |
return("unknown"); |
| 115 |
– |
} |
| 116 |
– |
|
| 98 |
|
/* set input/output format */ |
| 99 |
|
static void |
| 100 |
|
setformat(const char *fmt) |
| 131 |
|
error(USER, errmsg); |
| 132 |
|
} |
| 133 |
|
|
| 134 |
+ |
/* Set default options */ |
| 135 |
+ |
static void |
| 136 |
+ |
default_options(void) |
| 137 |
+ |
{ |
| 138 |
+ |
rand_samp = 1; |
| 139 |
+ |
dstrsrc = 0.9; |
| 140 |
+ |
directrelay = 3; |
| 141 |
+ |
vspretest = 512; |
| 142 |
+ |
srcsizerat = .2; |
| 143 |
+ |
specthresh = .02; |
| 144 |
+ |
specjitter = 1.; |
| 145 |
+ |
maxdepth = -10; |
| 146 |
+ |
minweight = 2e-3; |
| 147 |
+ |
ambres = 256; |
| 148 |
+ |
ambdiv = 350; |
| 149 |
+ |
ambounce = 1; |
| 150 |
+ |
} |
| 151 |
|
|
| 152 |
|
/* Set overriding options */ |
| 153 |
|
static void |
| 158 |
|
ambacc = 0; |
| 159 |
|
} |
| 160 |
|
|
| 163 |
– |
|
| 161 |
|
int |
| 162 |
|
main(int argc, char *argv[]) |
| 163 |
|
{ |
| 188 |
|
/* initialize calcomp routines early */ |
| 189 |
|
initfunc(); |
| 190 |
|
calcontext(RCCONTEXT); |
| 191 |
+ |
/* set rcontrib defaults */ |
| 192 |
+ |
default_options(); |
| 193 |
|
/* option city */ |
| 194 |
|
for (i = 1; i < argc; i++) { |
| 195 |
|
/* expand arguments */ |
| 217 |
|
continue; |
| 218 |
|
} |
| 219 |
|
switch (argv[i][1]) { |
| 220 |
< |
case 'n': /* number of cores */ |
| 220 |
> |
case 'n': /* number of processes */ |
| 221 |
|
check(2,"i"); |
| 222 |
|
nproc = atoi(argv[++i]); |
| 223 |
|
if (nproc < 0 && (nproc += RadSimulManager::GetNCores()) <= 0) |
| 224 |
|
nproc = 1; |
| 225 |
|
break; |
| 226 |
< |
case 'V': /* output contributions */ |
| 227 |
< |
check_bool(2,contrib); |
| 226 |
> |
case 'V': /* output contributions? */ |
| 227 |
> |
rval = myRCmanager.HasFlag(RCcontrib); |
| 228 |
> |
check_bool(2,rval); |
| 229 |
> |
myRCmanager.SetFlag(RCcontrib, rval); |
| 230 |
|
break; |
| 231 |
|
case 'x': /* x resolution */ |
| 232 |
|
check(2,"i"); |
| 233 |
< |
xres = atoi(argv[++i]); |
| 233 |
> |
myRCmanager.xres = atoi(argv[++i]); |
| 234 |
|
break; |
| 235 |
|
case 'y': /* y resolution */ |
| 236 |
|
check(2,"i"); |
| 237 |
< |
yres = atoi(argv[++i]); |
| 237 |
> |
myRCmanager.yres = atoi(argv[++i]); |
| 238 |
|
break; |
| 239 |
< |
case 'w': /* warnings */ |
| 239 |
> |
case 'w': /* warnings on/off */ |
| 240 |
|
rval = (erract[WARNING].pf != NULL); |
| 241 |
|
check_bool(2,rval); |
| 242 |
|
if (rval) erract[WARNING].pf = wputs; |
| 243 |
|
else erract[WARNING].pf = NULL; |
| 244 |
|
break; |
| 244 |
– |
case 'e': /* expression */ |
| 245 |
– |
check(2,"s"); |
| 246 |
– |
scompile(argv[++i], NULL, 0); |
| 247 |
– |
break; |
| 245 |
|
case 'l': /* limit distance */ |
| 246 |
|
if (argv[i][2] != 'd') |
| 247 |
|
goto badopt; |
| 248 |
< |
check_bool(3,lim_dist); |
| 248 |
> |
rval = myRCmanager.HasFlag(RTlimDist); |
| 249 |
> |
check_bool(3,rval); |
| 250 |
> |
myRCmanager.SetFlag(RTlimDist, rval); |
| 251 |
|
break; |
| 252 |
|
case 'I': /* immed. irradiance */ |
| 253 |
< |
check_bool(2,imm_irrad); |
| 253 |
> |
rval = myRCmanager.HasFlag(RTimmIrrad); |
| 254 |
> |
check_bool(2,rval); |
| 255 |
> |
myRCmanager.SetFlag(RTimmIrrad, rval); |
| 256 |
|
break; |
| 257 |
< |
case 'f': /* file or force or format */ |
| 257 |
< |
if (!argv[i][2]) { |
| 258 |
< |
check(2,"s"); |
| 259 |
< |
loadfunc(argv[++i]); |
| 260 |
< |
break; |
| 261 |
< |
} |
| 257 |
> |
case 'f': /* force or format */ |
| 258 |
|
if (argv[i][2] == 'o') { |
| 259 |
|
check_bool(3,force_open); |
| 260 |
|
break; |
| 262 |
|
setformat(argv[i]+2); |
| 263 |
|
myRCmanager.SetDataFormat(outfmt); |
| 264 |
|
break; |
| 265 |
< |
case 'o': /* output */ |
| 265 |
> |
case 'o': /* output file */ |
| 266 |
|
check(2,"s"); |
| 267 |
|
curout = argv[++i]; |
| 268 |
|
break; |
| 290 |
|
check(2,"s"); |
| 291 |
|
myRCmanager.AddModifier(argv[++i], curout, prms, binval, bincnt); |
| 292 |
|
break; |
| 293 |
< |
case 'M': /* modifier file */ |
| 293 |
> |
case 'M': /* file of modifier names */ |
| 294 |
|
check(2,"s"); |
| 295 |
|
myRCmanager.AddModFile(argv[++i], curout, prms, binval, bincnt); |
| 296 |
|
break; |
| 304 |
|
} |
| 305 |
|
if (i != argc-1) |
| 306 |
|
error(USER, "expected single octree argument"); |
| 307 |
+ |
|
| 308 |
+ |
override_options(); /* override some option settings */ |
| 309 |
+ |
|
| 310 |
+ |
if (!myRCmanager.GetOutput()) // check that we have work to do |
| 311 |
+ |
error(USER, "missing required modifier argument"); |
| 312 |
|
// get ready to rock... |
| 313 |
|
if (setspectrsamp(CNDX, WLPART) < 0) |
| 314 |
|
error(USER, "unsupported spectral sampling"); |
| 314 |
– |
|
| 315 |
– |
if (!myRCmanager.GetOutputs(NULL)) // check that we're ready |
| 316 |
– |
error(USER, "missing required modifier argument"); |
| 317 |
– |
/* override some option settings */ |
| 318 |
– |
override_options(); |
| 315 |
|
/* set up signal handling */ |
| 316 |
|
sigdie(SIGINT, "Interrupt"); |
| 317 |
|
#ifdef SIGHUP |
| 335 |
|
myRCmanager.LoadOctree(argv[argc-1]); |
| 336 |
|
// add to header |
| 337 |
|
myRCmanager.AddHeader(argc-1, argv); |
| 338 |
+ |
{ |
| 339 |
+ |
char buf[128] = "SOFTWARE= "; |
| 340 |
+ |
strcpy(buf+10, VersionID); |
| 341 |
+ |
myRCmanager.AddHeader(buf); |
| 342 |
+ |
} |
| 343 |
|
// prepare output files |
| 344 |
|
if (recover) |
| 345 |
|
myRCmanager.outOp = RCOrecover; |
| 349 |
|
myRCmanager.outOp = RCOnew; |
| 350 |
|
// rval = # rows recovered |
| 351 |
|
rval = myRCmanager.PrepOutput(); |
| 352 |
< |
// check if all done |
| 353 |
< |
if (recover && rval >= myRCmanager.GetRowMax()) { |
| 352 |
> |
// check if recovered everything |
| 353 |
> |
if (rval >= myRCmanager.GetRowMax()) { |
| 354 |
|
error(WARNING, "nothing left to compute"); |
| 355 |
|
quit(0); |
| 356 |
< |
} // add processes as requested |
| 356 |
< |
myRCmanager.SetThreadCount(nproc); |
| 357 |
< |
|
| 356 |
> |
} |
| 357 |
|
rxcontrib(rval); /* trace ray contributions (loop) */ |
| 358 |
|
|
| 359 |
|
quit(0); /* exit clean */ |
| 408 |
|
int n2go = myRCmanager.accum; |
| 409 |
|
|
| 410 |
|
switch (inpfmt) { |
| 411 |
< |
case 'a': // ASCII input |
| 411 |
> |
case 'a': // ASCII input |
| 412 |
|
if (!orig_dir) |
| 413 |
|
return skipWords(6*n2go); |
| 414 |
|
while (n2go-- > 0) { |
| 421 |
|
orig_dir += 2; |
| 422 |
|
} |
| 423 |
|
break; |
| 424 |
< |
case 'f': // float input |
| 424 |
> |
case 'f': // float input |
| 425 |
|
if (!orig_dir) |
| 426 |
|
return skipBytes(6*sizeof(float)*n2go); |
| 427 |
|
#ifdef SMLFLT |
| 428 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 429 |
|
return false; |
| 430 |
+ |
orig_dir += 2*n2go; |
| 431 |
|
#else |
| 432 |
|
while (n2go-- > 0) { |
| 433 |
|
float fvecs[6]; |
| 439 |
|
} |
| 440 |
|
#endif |
| 441 |
|
break; |
| 442 |
< |
case 'd': // double input |
| 442 |
> |
case 'd': // double input |
| 443 |
|
if (!orig_dir) |
| 444 |
|
return skipBytes(6*sizeof(double)*n2go); |
| 445 |
|
#ifndef SMLFLT |
| 446 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 447 |
|
return false; |
| 448 |
+ |
orig_dir += 2*n2go; |
| 449 |
|
#else |
| 450 |
|
while (n2go-- > 0) { |
| 451 |
|
double dvecs[6]; |
| 461 |
|
error(INTERNAL, "unsupported format in getRayBundle()"); |
| 462 |
|
return false; |
| 463 |
|
} |
| 464 |
< |
int warned = 0; // normalize directions |
| 464 |
< |
n2go = myRCmanager.accum; |
| 464 |
> |
n2go = myRCmanager.accum; // normalize directions |
| 465 |
|
while (n2go-- > 0) { |
| 466 |
|
orig_dir -= 2; |
| 467 |
< |
if (normalize(orig_dir[1]) == 0) |
| 468 |
< |
if (!warned++) |
| 469 |
< |
error(WARNING, "zero ray direction on input"); |
| 467 |
> |
normalize(orig_dir[1]); |
| 468 |
|
} |
| 469 |
|
return true; |
| 470 |
|
} |
| 492 |
|
} |
| 493 |
|
last_report = tstart = time(0); |
| 494 |
|
} |
| 495 |
< |
while (r < totRows) { // getting to work... |
| 495 |
> |
// start children as requested |
| 496 |
> |
myRCmanager.SetThreadCount(nproc); |
| 497 |
> |
|
| 498 |
> |
while (r < totRows) { // loop until done |
| 499 |
|
time_t tnow; |
| 500 |
|
if (!getRayBundle(odarr)) |
| 501 |
|
goto readerr; |
| 502 |
< |
if (myRCmanager.ComputeRecord(odarr) < 0) |
| 502 |
> |
if (myRCmanager.ComputeRecord(odarr) <= 0) |
| 503 |
|
return; // error reported, hopefully... |
| 504 |
|
r++; |
| 505 |
|
if (report_intvl <= 0) |
| 506 |
|
continue; |
| 507 |
< |
if ((r < totRows) & ((tnow = time(0)) < last_report+report_intvl)) |
| 507 |
> |
if (r == totRows) // need to finish up? |
| 508 |
> |
myRCmanager.SetThreadCount(1); |
| 509 |
> |
tnow = time(0); |
| 510 |
> |
if ((r < totRows) & (tnow < last_report+report_intvl)) |
| 511 |
|
continue; |
| 512 |
|
sprintf(errmsg, "%.2f%% done after %.3f hours\n", |
| 513 |
< |
100.*r/totRows, (1./3600.)*(tnow - tstart)); |
| 513 |
> |
100.*myRCmanager.GetRowFinished()/totRows, |
| 514 |
> |
(1./3600.)*(tnow - tstart)); |
| 515 |
|
eputs(errmsg); |
| 516 |
|
last_report = tnow; |
| 517 |
|
} |
| 529 |
|
const char *s |
| 530 |
|
) |
| 531 |
|
{ |
| 532 |
+ |
if (!erract[WARNING].pf) return; |
| 533 |
|
int lasterrno = errno; |
| 534 |
|
eputs(s); |
| 535 |
|
errno = lasterrno; |
| 557 |
|
} |
| 558 |
|
|
| 559 |
|
|
| 560 |
< |
/* Quit program */ |
| 560 |
> |
/* Exit program */ |
| 561 |
|
void |
| 562 |
|
quit( |
| 563 |
|
int code |
| 564 |
|
) |
| 565 |
|
{ |
| 566 |
< |
if (!code && myRCmanager.Ready()) // clean up on normal exit |
| 561 |
< |
code = myRCmanager.Cleanup(); |
| 566 |
> |
myRCmanager.FlushQueue(); // leave nothing in queue |
| 567 |
|
|
| 568 |
|
exit(code); |
| 569 |
|
} |