| 99 |
|
|
| 100 |
|
/* rtrace command and defaults */ |
| 101 |
|
char *rtargv[256+2*MAXMODLIST] = { "rtrace", |
| 102 |
< |
"-dj", ".5", "-dr", "3", |
| 102 |
> |
"-dj", ".9", "-dr", "3", |
| 103 |
|
"-ab", "1", "-ad", "350", }; |
| 104 |
|
|
| 105 |
|
int rtargc = 9; |
| 131 |
|
int outfmt = 'a'; /* output format */ |
| 132 |
|
|
| 133 |
|
int header = 1; /* output header? */ |
| 134 |
– |
int accumulate = 0; /* accumulate ray values? */ |
| 134 |
|
int force_open = 0; /* truncate existing output? */ |
| 135 |
|
int recover = 0; /* recover previous output? */ |
| 136 |
+ |
int accumulate = 1; /* input rays per output record */ |
| 137 |
|
int xres = 0; /* horiz. output resolution */ |
| 138 |
|
int yres = 0; /* vert. output resolution */ |
| 139 |
|
|
| 140 |
+ |
int account; /* current accumulation count */ |
| 141 |
|
unsigned long raysleft; /* number of rays left to trace */ |
| 142 |
|
long waitflush; /* how long until next flush */ |
| 143 |
|
|
| 167 |
|
|
| 168 |
|
void put_contrib(const DCOLOR cnt, FILE *fout); |
| 169 |
|
void add_contrib(const char *modn); |
| 170 |
< |
void done_contrib(void); |
| 170 |
> |
void done_contrib(int navg); |
| 171 |
|
|
| 172 |
|
/* return number of open rtrace processes */ |
| 173 |
|
static int |
| 275 |
|
continue; |
| 276 |
|
} |
| 277 |
|
break; |
| 278 |
< |
case 'c': /* accumulate ray values */ |
| 279 |
< |
switch (argv[i][2]) { |
| 280 |
< |
case '\0': |
| 281 |
< |
accumulate = !accumulate; |
| 281 |
< |
continue; |
| 282 |
< |
case '+': case '1': |
| 283 |
< |
case 'T': case 't': |
| 284 |
< |
case 'Y': case 'y': |
| 285 |
< |
accumulate = 1; |
| 286 |
< |
continue; |
| 287 |
< |
case '-': case '0': |
| 288 |
< |
case 'F': case 'f': |
| 289 |
< |
case 'N': case 'n': |
| 290 |
< |
accumulate = 0; |
| 291 |
< |
continue; |
| 292 |
< |
} |
| 293 |
< |
break; |
| 278 |
> |
case 'c': /* input rays per output */ |
| 279 |
> |
if (argv[i][2] || i >= argc-2) break; |
| 280 |
> |
accumulate = atoi(argv[++i]); |
| 281 |
> |
continue; |
| 282 |
|
case 'r': /* recover output */ |
| 283 |
|
if (argv[i][2]) break; |
| 284 |
|
recover = 1; |
| 368 |
|
} |
| 369 |
|
rtargv[rtargc++] = argv[i]; /* assume rtrace option */ |
| 370 |
|
} |
| 371 |
< |
if (accumulate) /* no output flushing for single record */ |
| 371 |
> |
if (accumulate <= 0) /* no output flushing for single record */ |
| 372 |
|
xres = yres = 0; |
| 373 |
|
/* set global argument list */ |
| 374 |
|
gargc = argc; gargv = argv; |
| 380 |
|
if (!strcmp(argv[i], "-defaults")) { |
| 381 |
|
char sxres[16], syres[16]; |
| 382 |
|
char *rtpath; |
| 383 |
< |
printf("-n %-2d\t\t\t\t# number of processes\n", nprocs); |
| 383 |
> |
printf("-n %-2d\t\t\t\t# number of processes\n", nprocs); |
| 384 |
> |
printf("-c %-5d\t\t\t# accumulated rays per record\n", |
| 385 |
> |
accumulate); |
| 386 |
|
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
| 387 |
|
contrib ? "contributions" : "coefficients"); |
| 398 |
– |
printf("-c%c\t\t\t\t# %s\n", accumulate ? '+' : '-', |
| 399 |
– |
accumulate ? "accumulate ray values" : |
| 400 |
– |
"one output record per ray"); |
| 388 |
|
fflush(stdout); /* report OUR options */ |
| 389 |
|
rtargv[rtargc++] = header ? "-h+" : "-h-"; |
| 390 |
|
sprintf(fmt, "-f%c%c", inpfmt, outfmt); |
| 541 |
|
raysleft = yres; |
| 542 |
|
} else |
| 543 |
|
raysleft = 0; |
| 544 |
+ |
if ((account = accumulate) > 0) |
| 545 |
+ |
raysleft *= accumulate; |
| 546 |
|
waitflush = xres; |
| 547 |
|
if (!recover) |
| 548 |
|
return; |
| 549 |
|
/* recover previous values */ |
| 550 |
< |
if (accumulate) |
| 550 |
> |
if (accumulate <= 0) |
| 551 |
|
reload_output(); |
| 552 |
|
else |
| 553 |
|
recover_output(stdin); |
| 802 |
|
*cp = '\0'; |
| 803 |
|
printheader(sop->ofp, info); |
| 804 |
|
} |
| 805 |
+ |
if (accumulate > 0) { /* global resolution */ |
| 806 |
+ |
sop->xr = xres; sop->yr = yres; |
| 807 |
+ |
} |
| 808 |
|
printresolu(sop->ofp, sop->xr, sop->yr); |
| 809 |
|
/* play catch-up */ |
| 810 |
< |
for (i = accumulate ? 0 : lastdone; i--; ) { |
| 810 |
> |
for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) { |
| 811 |
|
int j = sop->reclen; |
| 812 |
|
if (j <= 0) j = 1; |
| 813 |
|
while (j--) |
| 949 |
|
|
| 950 |
|
/* output ray tallies and clear for next accumulation */ |
| 951 |
|
void |
| 952 |
< |
done_contrib(void) |
| 952 |
> |
done_contrib(int navg) |
| 953 |
|
{ |
| 954 |
+ |
double sf = 1.; |
| 955 |
|
int i, j; |
| 956 |
|
MODCONT *mp; |
| 957 |
|
STREAMOUT *sop; |
| 958 |
+ |
/* set average scaling */ |
| 959 |
+ |
if (navg > 1) |
| 960 |
+ |
sf = 1. / (double)navg; |
| 961 |
|
/* output modifiers in order */ |
| 962 |
|
for (i = 0; i < nmods; i++) { |
| 963 |
|
mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; |
| 964 |
+ |
if (navg > 1) /* average scaling */ |
| 965 |
+ |
for (j = mp->nbins; j--; ) |
| 966 |
+ |
scalecolor(mp->cbin[j], sf); |
| 967 |
|
sop = getostream(mp->outspec, mp->modname, 0,0); |
| 968 |
|
put_contrib(mp->cbin[0], sop->ofp); |
| 969 |
|
if (mp->nbins > 3 && /* minor optimization */ |
| 1047 |
|
cp += sizeof(float)*9; n -= sizeof(float)*9; |
| 1048 |
|
add_contrib(modname); |
| 1049 |
|
} |
| 1050 |
< |
if (!accumulate) |
| 1051 |
< |
done_contrib(); /* sum up contributions & output */ |
| 1050 |
> |
/* time to produce record? */ |
| 1051 |
> |
if (account > 0 && !--account) |
| 1052 |
> |
done_contrib(account = accumulate); |
| 1053 |
|
lastdone = rtp->raynum; |
| 1054 |
|
if (rtp->buf != NULL) /* free up buffer space */ |
| 1055 |
|
free(rtp->buf); |
| 1136 |
|
void |
| 1137 |
|
trace_contribs(FILE *fin) |
| 1138 |
|
{ |
| 1139 |
+ |
static int ignore_warning_given = 0; |
| 1140 |
|
char inpbuf[128]; |
| 1141 |
|
int iblen; |
| 1142 |
|
struct rtproc *rtp; |
| 1143 |
|
/* loop over input */ |
| 1144 |
|
while ((iblen = getinp(inpbuf, fin)) >= 0) { |
| 1145 |
+ |
if (!iblen && accumulate != 1) { |
| 1146 |
+ |
if (!ignore_warning_given++) |
| 1147 |
+ |
error(WARNING, |
| 1148 |
+ |
"dummy ray(s) ignored during accumulation\n"); |
| 1149 |
+ |
continue; |
| 1150 |
+ |
} |
| 1151 |
|
if (!iblen || /* need reset? */ |
| 1152 |
|
queue_length() > 10*nrtprocs() || |
| 1153 |
|
lastray+1 < lastray) { |
| 1171 |
|
} |
| 1172 |
|
while (wait_rproc() != NULL) /* process outstanding rays */ |
| 1173 |
|
process_queue(); |
| 1174 |
< |
if (accumulate) |
| 1175 |
< |
done_contrib(); /* output tallies */ |
| 1174 |
> |
if (accumulate <= 0) |
| 1175 |
> |
done_contrib(0); /* output tallies */ |
| 1176 |
> |
else if (account < accumulate) { |
| 1177 |
> |
error(WARNING, "partial accumulation in final record"); |
| 1178 |
> |
done_contrib(accumulate - account); |
| 1179 |
> |
} |
| 1180 |
|
if (raysleft) |
| 1181 |
|
error(USER, "unexpected EOF on input"); |
| 1182 |
|
lu_done(&ofiletab); /* close output files */ |
| 1218 |
|
STREAMOUT *sop = (STREAMOUT *)e->data; |
| 1219 |
|
|
| 1220 |
|
if (sop->ofp == NULL) |
| 1221 |
< |
return; |
| 1221 |
> |
return(0); |
| 1222 |
|
fclose(sop->ofp); |
| 1223 |
|
sop->ofp = NULL; |
| 1224 |
+ |
return(0); |
| 1225 |
|
} |
| 1226 |
|
|
| 1227 |
|
/* load previously accumulated values */ |
| 1295 |
|
} |
| 1296 |
|
if ((sout.xr > 0) & (sout.yr > 0) && |
| 1297 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
| 1298 |
< |
xr != sout.xr || |
| 1299 |
< |
yr != sout.yr)) { |
| 1298 |
> |
(xr != sout.xr) | |
| 1299 |
> |
(yr != sout.yr))) { |
| 1300 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
| 1301 |
|
oname); |
| 1302 |
|
error(USER, errmsg); |
| 1303 |
|
} |
| 1304 |
|
} |
| 1293 |
– |
if (oent->key == NULL) /* new file entry */ |
| 1294 |
– |
oent->key = strcpy((char *) |
| 1295 |
– |
malloc(strlen(oname)+1), oname); |
| 1296 |
– |
if (oent->data == NULL) |
| 1297 |
– |
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
| 1298 |
– |
*(STREAMOUT *)oent->data = sout; |
| 1305 |
|
/* read in RGB value */ |
| 1306 |
|
if (!get_contrib(rgbv, sout.ofp)) { |
| 1307 |
< |
if (!j) |
| 1307 |
> |
if (!j) { |
| 1308 |
> |
fclose(sout.ofp); |
| 1309 |
|
break; /* ignore empty file */ |
| 1310 |
< |
if (j && j < mp->nbins) { |
| 1310 |
> |
} |
| 1311 |
> |
if (j < mp->nbins) { |
| 1312 |
|
sprintf(errmsg, "missing data in '%s'", |
| 1313 |
|
oname); |
| 1314 |
|
error(USER, errmsg); |
| 1318 |
|
if (j >= mp->nbins) /* grow modifier size */ |
| 1319 |
|
ment->data = (char *)(mp = growmodifier(mp, j+1)); |
| 1320 |
|
copycolor(mp->cbin[j], rgbv); |
| 1321 |
+ |
if (oent->key == NULL) /* new file entry */ |
| 1322 |
+ |
oent->key = strcpy((char *) |
| 1323 |
+ |
malloc(strlen(oname)+1), oname); |
| 1324 |
+ |
if (oent->data == NULL) |
| 1325 |
+ |
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
| 1326 |
+ |
*(STREAMOUT *)oent->data = sout; |
| 1327 |
|
} |
| 1328 |
|
} |
| 1329 |
|
lu_doall(&ofiletab, myclose, NULL); /* close all files */ |
| 1399 |
|
} else { |
| 1400 |
|
sout.reclen = 0; |
| 1401 |
|
sout.outpipe = 0; |
| 1388 |
– |
sout.xr = xres; sout.yr = yres; |
| 1402 |
|
sout.ofp = NULL; |
| 1403 |
|
} |
| 1404 |
|
if (sout.ofp != NULL) { /* already open? */ |
| 1439 |
|
oname); |
| 1440 |
|
error(USER, errmsg); |
| 1441 |
|
} |
| 1442 |
< |
if ((xres > 0) & (yres > 0) && |
| 1442 |
> |
sout.xr = xres; sout.yr = yres; |
| 1443 |
> |
if ((sout.xr > 0) & (sout.yr > 0) && |
| 1444 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
| 1445 |
< |
xr != xres || |
| 1446 |
< |
yr != yres)) { |
| 1445 |
> |
(xr != sout.xr) | |
| 1446 |
> |
(yr != sout.yr))) { |
| 1447 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
| 1448 |
|
oname); |
| 1449 |
|
error(USER, errmsg); |
| 1472 |
|
error(WARNING, "no output files to recover"); |
| 1473 |
|
return; |
| 1474 |
|
} |
| 1475 |
< |
if (raysleft && lastout >= raysleft) { |
| 1475 |
> |
if (raysleft && lastout >= raysleft/accumulate) { |
| 1476 |
|
error(WARNING, "output appears to be complete"); |
| 1477 |
|
/* XXX should read & discard input? */ |
| 1478 |
|
quit(0); |
| 1484 |
|
for (nvals = 0; nvals < lastout; nvals++) |
| 1485 |
|
if (getinp(oname, fin) < 0) |
| 1486 |
|
error(USER, "unexpected EOF on input"); |
| 1487 |
< |
lastray = lastdone = (unsigned long)lastout; |
| 1487 |
> |
lastray = lastdone = (unsigned long)lastout * accumulate; |
| 1488 |
|
if (raysleft) |
| 1489 |
|
raysleft -= lastray; |
| 1490 |
|
} |