| 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 |
> |
if (myRCmanager.xres > 0) |
| 51 |
> |
printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres); |
| 52 |
> |
printf("-y %-9d\t\t\t# y resolution\n", myRCmanager.yres); |
| 53 |
> |
printf(myRCmanager.HasFlag(RTlimDist) ? |
| 54 |
> |
"-ld+\t\t\t\t# limit distance on\n" : |
| 55 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
| 56 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
| 57 |
|
inpfmt, outfmt, formstr(inpfmt), formstr(outfmt)); |
| 75 |
|
_exit(signo); |
| 76 |
|
|
| 77 |
|
#ifdef SIGALRM |
| 78 |
< |
alarm(15); /* allow 15 seconds to clean up */ |
| 78 |
> |
alarm(180); /* allow 3 minutes to clean up */ |
| 79 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 80 |
|
#endif |
| 81 |
|
eputs("signal - "); |
| 96 |
|
sigerr[signo] = msg; |
| 97 |
|
} |
| 98 |
|
|
| 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 |
– |
|
| 99 |
|
/* set input/output format */ |
| 100 |
|
static void |
| 101 |
|
setformat(const char *fmt) |
| 132 |
|
error(USER, errmsg); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
+ |
/* Set default options */ |
| 136 |
+ |
static void |
| 137 |
+ |
default_options(void) |
| 138 |
+ |
{ |
| 139 |
+ |
rand_samp = 1; |
| 140 |
+ |
dstrsrc = 0.9; |
| 141 |
+ |
directrelay = 3; |
| 142 |
+ |
vspretest = 512; |
| 143 |
+ |
srcsizerat = .2; |
| 144 |
+ |
specthresh = .02; |
| 145 |
+ |
specjitter = 1.; |
| 146 |
+ |
maxdepth = -10; |
| 147 |
+ |
minweight = 2e-3; |
| 148 |
+ |
ambres = 256; |
| 149 |
+ |
ambdiv = 350; |
| 150 |
+ |
ambounce = 1; |
| 151 |
+ |
} |
| 152 |
|
|
| 153 |
|
/* Set overriding options */ |
| 154 |
|
static void |
| 159 |
|
ambacc = 0; |
| 160 |
|
} |
| 161 |
|
|
| 163 |
– |
|
| 162 |
|
int |
| 163 |
|
main(int argc, char *argv[]) |
| 164 |
|
{ |
| 189 |
|
/* initialize calcomp routines early */ |
| 190 |
|
initfunc(); |
| 191 |
|
calcontext(RCCONTEXT); |
| 192 |
+ |
/* set rcontrib defaults */ |
| 193 |
+ |
default_options(); |
| 194 |
|
/* option city */ |
| 195 |
|
for (i = 1; i < argc; i++) { |
| 196 |
|
/* expand arguments */ |
| 218 |
|
continue; |
| 219 |
|
} |
| 220 |
|
switch (argv[i][1]) { |
| 221 |
< |
case 'n': /* number of cores */ |
| 221 |
> |
case 'n': /* number of processes */ |
| 222 |
|
check(2,"i"); |
| 223 |
|
nproc = atoi(argv[++i]); |
| 224 |
|
if (nproc < 0 && (nproc += RadSimulManager::GetNCores()) <= 0) |
| 225 |
|
nproc = 1; |
| 226 |
|
break; |
| 227 |
< |
case 'V': /* output contributions */ |
| 228 |
< |
check_bool(2,contrib); |
| 227 |
> |
case 'V': /* output contributions? */ |
| 228 |
> |
rval = myRCmanager.HasFlag(RCcontrib); |
| 229 |
> |
check_bool(2,rval); |
| 230 |
> |
myRCmanager.SetFlag(RCcontrib, rval); |
| 231 |
|
break; |
| 232 |
|
case 'x': /* x resolution */ |
| 233 |
|
check(2,"i"); |
| 234 |
< |
xres = atoi(argv[++i]); |
| 234 |
> |
myRCmanager.xres = atoi(argv[++i]); |
| 235 |
|
break; |
| 236 |
|
case 'y': /* y resolution */ |
| 237 |
|
check(2,"i"); |
| 238 |
< |
yres = atoi(argv[++i]); |
| 238 |
> |
myRCmanager.yres = atoi(argv[++i]); |
| 239 |
|
break; |
| 240 |
< |
case 'w': /* warnings */ |
| 240 |
> |
case 'w': /* warnings on/off */ |
| 241 |
|
rval = (erract[WARNING].pf != NULL); |
| 242 |
|
check_bool(2,rval); |
| 243 |
|
if (rval) erract[WARNING].pf = wputs; |
| 244 |
|
else erract[WARNING].pf = NULL; |
| 245 |
|
break; |
| 246 |
< |
case 'e': /* expression */ |
| 246 |
> |
case 'e': /* .cal expression */ |
| 247 |
|
check(2,"s"); |
| 248 |
|
scompile(argv[++i], NULL, 0); |
| 249 |
|
break; |
| 250 |
|
case 'l': /* limit distance */ |
| 251 |
|
if (argv[i][2] != 'd') |
| 252 |
|
goto badopt; |
| 253 |
< |
check_bool(3,lim_dist); |
| 253 |
> |
rval = myRCmanager.HasFlag(RTlimDist); |
| 254 |
> |
check_bool(3,rval); |
| 255 |
> |
myRCmanager.SetFlag(RTlimDist, rval); |
| 256 |
|
break; |
| 257 |
|
case 'I': /* immed. irradiance */ |
| 258 |
< |
check_bool(2,imm_irrad); |
| 258 |
> |
rval = myRCmanager.HasFlag(RTimmIrrad); |
| 259 |
> |
check_bool(2,rval); |
| 260 |
> |
myRCmanager.SetFlag(RTimmIrrad, rval); |
| 261 |
|
break; |
| 262 |
< |
case 'f': /* file or force or format */ |
| 262 |
> |
case 'f': /* .cal file or force or format */ |
| 263 |
|
if (!argv[i][2]) { |
| 264 |
|
check(2,"s"); |
| 265 |
|
loadfunc(argv[++i]); |
| 272 |
|
setformat(argv[i]+2); |
| 273 |
|
myRCmanager.SetDataFormat(outfmt); |
| 274 |
|
break; |
| 275 |
< |
case 'o': /* output */ |
| 275 |
> |
case 'o': /* output file */ |
| 276 |
|
check(2,"s"); |
| 277 |
|
curout = argv[++i]; |
| 278 |
|
break; |
| 300 |
|
check(2,"s"); |
| 301 |
|
myRCmanager.AddModifier(argv[++i], curout, prms, binval, bincnt); |
| 302 |
|
break; |
| 303 |
< |
case 'M': /* modifier file */ |
| 303 |
> |
case 'M': /* file of modifier names */ |
| 304 |
|
check(2,"s"); |
| 305 |
|
myRCmanager.AddModFile(argv[++i], curout, prms, binval, bincnt); |
| 306 |
|
break; |
| 314 |
|
} |
| 315 |
|
if (i != argc-1) |
| 316 |
|
error(USER, "expected single octree argument"); |
| 317 |
+ |
|
| 318 |
+ |
override_options(); /* override some option settings */ |
| 319 |
+ |
|
| 320 |
+ |
if (!myRCmanager.GetOutput()) // check that we have work to do |
| 321 |
+ |
error(USER, "missing required modifier argument"); |
| 322 |
|
// get ready to rock... |
| 323 |
|
if (setspectrsamp(CNDX, WLPART) < 0) |
| 324 |
|
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(); |
| 325 |
|
/* set up signal handling */ |
| 326 |
|
sigdie(SIGINT, "Interrupt"); |
| 327 |
|
#ifdef SIGHUP |
| 354 |
|
myRCmanager.outOp = RCOnew; |
| 355 |
|
// rval = # rows recovered |
| 356 |
|
rval = myRCmanager.PrepOutput(); |
| 357 |
< |
// check if all done |
| 358 |
< |
if (recover && rval >= myRCmanager.GetRowMax()) { |
| 357 |
> |
// check if recovered everything |
| 358 |
> |
if (rval >= myRCmanager.GetRowMax()) { |
| 359 |
|
error(WARNING, "nothing left to compute"); |
| 360 |
|
quit(0); |
| 361 |
< |
} // add processes as requested |
| 356 |
< |
myRCmanager.SetThreadCount(nproc); |
| 357 |
< |
|
| 361 |
> |
} |
| 362 |
|
rxcontrib(rval); /* trace ray contributions (loop) */ |
| 363 |
|
|
| 364 |
|
quit(0); /* exit clean */ |
| 413 |
|
int n2go = myRCmanager.accum; |
| 414 |
|
|
| 415 |
|
switch (inpfmt) { |
| 416 |
< |
case 'a': // ASCII input |
| 416 |
> |
case 'a': // ASCII input |
| 417 |
|
if (!orig_dir) |
| 418 |
|
return skipWords(6*n2go); |
| 419 |
|
while (n2go-- > 0) { |
| 426 |
|
orig_dir += 2; |
| 427 |
|
} |
| 428 |
|
break; |
| 429 |
< |
case 'f': // float input |
| 429 |
> |
case 'f': // float input |
| 430 |
|
if (!orig_dir) |
| 431 |
|
return skipBytes(6*sizeof(float)*n2go); |
| 432 |
|
#ifdef SMLFLT |
| 433 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 434 |
|
return false; |
| 435 |
+ |
orig_dir += 2*n2go; |
| 436 |
|
#else |
| 437 |
|
while (n2go-- > 0) { |
| 438 |
|
float fvecs[6]; |
| 444 |
|
} |
| 445 |
|
#endif |
| 446 |
|
break; |
| 447 |
< |
case 'd': // double input |
| 447 |
> |
case 'd': // double input |
| 448 |
|
if (!orig_dir) |
| 449 |
|
return skipBytes(6*sizeof(double)*n2go); |
| 450 |
|
#ifndef SMLFLT |
| 451 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 452 |
|
return false; |
| 453 |
+ |
orig_dir += 2*n2go; |
| 454 |
|
#else |
| 455 |
|
while (n2go-- > 0) { |
| 456 |
|
double dvecs[6]; |
| 466 |
|
error(INTERNAL, "unsupported format in getRayBundle()"); |
| 467 |
|
return false; |
| 468 |
|
} |
| 469 |
< |
int warned = 0; // normalize directions |
| 464 |
< |
n2go = myRCmanager.accum; |
| 469 |
> |
n2go = myRCmanager.accum; // normalize directions |
| 470 |
|
while (n2go-- > 0) { |
| 471 |
|
orig_dir -= 2; |
| 472 |
< |
if (normalize(orig_dir[1]) == 0) |
| 468 |
< |
if (!warned++) |
| 469 |
< |
error(WARNING, "zero ray direction on input"); |
| 472 |
> |
normalize(orig_dir[1]); |
| 473 |
|
} |
| 474 |
|
return true; |
| 475 |
|
} |
| 497 |
|
} |
| 498 |
|
last_report = tstart = time(0); |
| 499 |
|
} |
| 500 |
< |
while (r < totRows) { // getting to work... |
| 500 |
> |
// start children as requested |
| 501 |
> |
myRCmanager.SetThreadCount(nproc); |
| 502 |
> |
|
| 503 |
> |
while (r < totRows) { // loop until done |
| 504 |
|
time_t tnow; |
| 505 |
|
if (!getRayBundle(odarr)) |
| 506 |
|
goto readerr; |
| 507 |
< |
if (myRCmanager.ComputeRecord(odarr) < 0) |
| 507 |
> |
if (myRCmanager.ComputeRecord(odarr) <= 0) |
| 508 |
|
return; // error reported, hopefully... |
| 509 |
|
r++; |
| 510 |
|
if (report_intvl <= 0) |
| 511 |
|
continue; |
| 512 |
< |
if ((r < totRows) & ((tnow = time(0)) < last_report+report_intvl)) |
| 512 |
> |
tnow = time(0); // time to report progress? |
| 513 |
> |
if (r == totRows) // finished? |
| 514 |
> |
myRCmanager.SetThreadCount(1); |
| 515 |
> |
else if (tnow < last_report+report_intvl) |
| 516 |
|
continue; |
| 517 |
|
sprintf(errmsg, "%.2f%% done after %.3f hours\n", |
| 518 |
< |
100.*r/totRows, (1./3600.)*(tnow - tstart)); |
| 518 |
> |
100.*myRCmanager.GetRowFinished()/totRows, |
| 519 |
> |
(1./3600.)*(tnow - tstart)); |
| 520 |
|
eputs(errmsg); |
| 521 |
|
last_report = tnow; |
| 522 |
|
} |
| 534 |
|
const char *s |
| 535 |
|
) |
| 536 |
|
{ |
| 537 |
+ |
if (!erract[WARNING].pf) return; |
| 538 |
|
int lasterrno = errno; |
| 539 |
|
eputs(s); |
| 540 |
|
errno = lasterrno; |
| 562 |
|
} |
| 563 |
|
|
| 564 |
|
|
| 565 |
< |
/* Quit program */ |
| 565 |
> |
/* Exit program */ |
| 566 |
|
void |
| 567 |
|
quit( |
| 568 |
|
int code |