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