| 20 |
|
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
| 21 |
|
#endif |
| 22 |
|
|
| 23 |
< |
int treebufsiz = BUFSIZ; /* current tree buffer size */ |
| 23 |
> |
size_t treebufsiz = BUFSIZ; /* current tree buffer size */ |
| 24 |
|
|
| 25 |
|
typedef double DCOLOR[3]; /* double-precision color */ |
| 26 |
|
|
| 92 |
|
struct rtproc *next; /* next in list of processes */ |
| 93 |
|
SUBPROC pd; /* rtrace pipe descriptors */ |
| 94 |
|
unsigned long raynum; /* ray number for this tree */ |
| 95 |
< |
int bsiz; /* ray tree buffer length */ |
| 95 |
> |
size_t bsiz; /* ray tree buffer length */ |
| 96 |
|
char *buf; /* ray tree buffer */ |
| 97 |
< |
int nbr; /* number of bytes from rtrace */ |
| 97 |
> |
size_t nbr; /* number of bytes from rtrace */ |
| 98 |
|
}; /* rtrace process buffer */ |
| 99 |
|
|
| 100 |
|
/* rtrace command and defaults */ |
| 107 |
|
char *myrtopts[] = { "-h-", "-x", "1", "-y", "0", |
| 108 |
|
"-dt", "0", "-as", "0", "-aa", "0", NULL }; |
| 109 |
|
|
| 110 |
< |
#define RTCOEFF "-o~~TmWdp" /* compute coefficients only */ |
| 111 |
< |
#define RTCONTRIB "-o~~TmVdp" /* compute ray contributions */ |
| 110 |
> |
#define RTCOEFF "-o~~~TmWdp" /* compute coefficients only */ |
| 111 |
> |
#define RTCONTRIB "-o~~~TmVdp" /* compute ray contributions */ |
| 112 |
|
|
| 113 |
|
struct rtproc rt0; /* head of rtrace process list */ |
| 114 |
|
|
| 340 |
|
case 'b': /* bin expression/count */ |
| 341 |
|
if (i >= argc-2) break; |
| 342 |
|
if (argv[i][2] == 'n') { |
| 343 |
< |
bincnt = atoi(argv[++i]); |
| 343 |
> |
bincnt = (int)(eval(argv[++i]) + .5); |
| 344 |
|
continue; |
| 345 |
|
} |
| 346 |
|
if (argv[i][2]) break; |
| 378 |
|
rtargv[rtargc++] = contrib ? RTCONTRIB : RTCOEFF; |
| 379 |
|
/* just asking for defaults? */ |
| 380 |
|
if (!strcmp(argv[i], "-defaults")) { |
| 381 |
< |
char sxres[16], syres[16]; |
| 381 |
> |
char nps[8], sxres[16], syres[16]; |
| 382 |
|
char *rtpath; |
| 383 |
– |
printf("-n %-2d\t\t\t\t# number of processes\n", nprocs); |
| 383 |
|
printf("-c %-5d\t\t\t# accumulated rays per record\n", |
| 384 |
|
accumulate); |
| 385 |
|
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
| 386 |
|
contrib ? "contributions" : "coefficients"); |
| 387 |
|
fflush(stdout); /* report OUR options */ |
| 388 |
+ |
rtargv[rtargc++] = "-n"; |
| 389 |
+ |
sprintf(nps, "%d", nprocs); |
| 390 |
+ |
rtargv[rtargc++] = nps; |
| 391 |
|
rtargv[rtargc++] = header ? "-h+" : "-h-"; |
| 392 |
|
sprintf(fmt, "-f%c%c", inpfmt, outfmt); |
| 393 |
|
rtargv[rtargc++] = fmt; |
| 545 |
|
raysleft = 0; |
| 546 |
|
if ((account = accumulate) > 0) |
| 547 |
|
raysleft *= accumulate; |
| 548 |
< |
waitflush = xres; |
| 548 |
> |
waitflush = (yres > 0) & (xres > 1) ? 0 : xres; |
| 549 |
|
if (!recover) |
| 550 |
|
return; |
| 551 |
|
/* recover previous values */ |
| 582 |
|
error(USER, errmsg); |
| 583 |
|
} |
| 584 |
|
if (nmods >= MAXMODLIST) |
| 585 |
< |
error(USER, "too many modifiers"); |
| 585 |
> |
error(INTERNAL, "too many modifiers"); |
| 586 |
|
modname[nmods++] = modn; /* XXX assumes static string */ |
| 587 |
|
lep->key = modn; /* XXX assumes static string */ |
| 588 |
|
mp = (MODCONT *)malloc(sizeof(MODCONT)); |
| 590 |
|
error(SYSTEM, "out of memory in addmodifier"); |
| 591 |
|
mp->outspec = outf; /* XXX assumes static string */ |
| 592 |
|
mp->modname = modn; /* XXX assumes static string */ |
| 593 |
< |
if (binv != NULL) |
| 594 |
< |
mp->binv = eparse(binv); |
| 595 |
< |
else |
| 596 |
< |
mp->binv = eparse("0"); |
| 597 |
< |
mp->nbins = 1; |
| 593 |
> |
if (binv == NULL) |
| 594 |
> |
binv = "0"; /* use single bin if unspecified */ |
| 595 |
> |
mp->binv = eparse(binv); |
| 596 |
> |
if (mp->binv->type == NUM) { /* check value if constant */ |
| 597 |
> |
bincnt = (int)(evalue(mp->binv) + 1.5); |
| 598 |
> |
if (bincnt != 1) { |
| 599 |
> |
sprintf(errmsg, "illegal non-zero constant for bin (%s)", |
| 600 |
> |
binv); |
| 601 |
> |
error(USER, errmsg); |
| 602 |
> |
} |
| 603 |
> |
} |
| 604 |
> |
mp->nbins = 1; /* initialize results holder */ |
| 605 |
|
setcolor(mp->cbin[0], 0., 0., 0.); |
| 606 |
< |
if (mp->binv->type == NUM) /* assume one bin if constant */ |
| 598 |
< |
bincnt = 1; |
| 599 |
< |
else if (bincnt > 1) |
| 606 |
> |
if (bincnt > 1) |
| 607 |
|
mp = growmodifier(mp, bincnt); |
| 608 |
|
lep->data = (char *)mp; |
| 609 |
|
/* allocate output streams */ |
| 666 |
|
mnp = cp; |
| 667 |
|
break; |
| 668 |
|
case 'd': |
| 669 |
+ |
case 'i': |
| 670 |
+ |
case 'o': |
| 671 |
+ |
case 'x': |
| 672 |
+ |
case 'X': |
| 673 |
|
if (bnp != NULL) |
| 674 |
|
return -1; |
| 675 |
|
bnp = cp; |
| 702 |
|
printheader(FILE *fout, const char *info) |
| 703 |
|
{ |
| 704 |
|
extern char VersionID[]; |
| 705 |
< |
FILE *fin = fopen(octree, "r"); |
| 706 |
< |
|
| 707 |
< |
if (fin == NULL) |
| 708 |
< |
quit(1); |
| 709 |
< |
checkheader(fin, "ignore", fout); /* copy octree header */ |
| 710 |
< |
fclose(fin); |
| 705 |
> |
/* copy octree header */ |
| 706 |
> |
if (octree[0] == '!') { |
| 707 |
> |
newheader("RADIANCE", fout); |
| 708 |
> |
fputs(octree+1, fout); |
| 709 |
> |
if (octree[strlen(octree)-1] != '\n') |
| 710 |
> |
fputc('\n', fout); |
| 711 |
> |
} else { |
| 712 |
> |
FILE *fin = fopen(octree, "r"); |
| 713 |
> |
if (fin == NULL) |
| 714 |
> |
quit(1); |
| 715 |
> |
checkheader(fin, "ignore", fout); |
| 716 |
> |
fclose(fin); |
| 717 |
> |
} |
| 718 |
|
printargs(gargc-1, gargv, fout); /* add our command */ |
| 719 |
|
fprintf(fout, "SOFTWARE= %s\n", VersionID); |
| 720 |
|
fputnow(fout); |
| 743 |
|
{ |
| 744 |
|
if ((xr > 0) & (yr > 0)) /* resolution string */ |
| 745 |
|
fprtresolu(xr, yr, fout); |
| 728 |
– |
if (xres > 0) /* global flush flag */ |
| 729 |
– |
fflush(fout); |
| 746 |
|
} |
| 747 |
|
|
| 748 |
|
/* Get output stream pointer (open and write header if new and noopen==0) */ |
| 763 |
|
if (header) |
| 764 |
|
printheader(stdout, NULL); |
| 765 |
|
printresolu(stdout, xres, yres); |
| 766 |
+ |
if (waitflush > 0) |
| 767 |
+ |
fflush(stdout); |
| 768 |
|
stdos.xr = xres; stdos.yr = yres; |
| 769 |
|
using_stdout = 1; |
| 770 |
|
} |
| 833 |
|
if (outfmt == 'a') |
| 834 |
|
putc('\n', sop->ofp); |
| 835 |
|
} |
| 836 |
< |
if (xres > 0) |
| 836 |
> |
if (waitflush > 0) |
| 837 |
|
fflush(sop->ofp); |
| 838 |
|
} |
| 839 |
|
sop->reclen += noopen; /* add to length if noopen */ |
| 1000 |
|
if (using_stdout & (outfmt == 'a')) |
| 1001 |
|
putc('\n', stdout); |
| 1002 |
|
if (!waitflush) { |
| 1003 |
< |
waitflush = xres; |
| 1003 |
> |
waitflush = (yres > 0) & (xres > 1) ? 0 : xres; |
| 1004 |
|
if (using_stdout) |
| 1005 |
|
fflush(stdout); |
| 1006 |
|
} |
| 1082 |
|
{ |
| 1083 |
|
struct rtproc *rtfree = NULL; |
| 1084 |
|
fd_set readset, errset; |
| 1085 |
< |
int nr; |
| 1085 |
> |
ssize_t nr; |
| 1086 |
|
struct rtproc *rt; |
| 1087 |
|
int n; |
| 1088 |
|
|
| 1113 |
|
continue; |
| 1114 |
|
if (rt->buf == NULL) { |
| 1115 |
|
rt->bsiz = treebufsiz; |
| 1116 |
< |
rt->buf = (char *)malloc(treebufsiz); |
| 1116 |
> |
rt->buf = (char *)malloc(rt->bsiz); |
| 1117 |
|
} else if (rt->nbr + BUFSIZ > rt->bsiz) { |
| 1118 |
|
if (rt->bsiz + BUFSIZ <= treebufsiz) |
| 1119 |
|
rt->bsiz = treebufsiz; |
| 1127 |
|
if (nr <= 0) |
| 1128 |
|
error(USER, "rtrace process died"); |
| 1129 |
|
rt->nbr += nr; /* advance & check */ |
| 1130 |
< |
if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4, |
| 1131 |
< |
"~\t~\t", 4)) { |
| 1132 |
< |
rt->nbr -= 4; /* elide terminator */ |
| 1130 |
> |
if (rt->nbr >= 6 && !memcmp(rt->buf+rt->nbr-6, |
| 1131 |
> |
"~\t~\t~\t", 6)) { |
| 1132 |
> |
rt->nbr -= 6; /* elide terminator */ |
| 1133 |
|
queue_raytree(rt); |
| 1134 |
|
rtfree = rt; /* ready for next ray */ |
| 1135 |
|
} |
| 1166 |
|
"dummy ray(s) ignored during accumulation\n"); |
| 1167 |
|
continue; |
| 1168 |
|
} |
| 1169 |
< |
if (!iblen || /* need reset? */ |
| 1169 |
> |
if (!iblen || /* need flush/reset? */ |
| 1170 |
|
queue_length() > 10*nrtprocs() || |
| 1171 |
|
lastray+1 < lastray) { |
| 1172 |
|
while (wait_rproc() != NULL) |
| 1173 |
|
process_queue(); |
| 1174 |
< |
if (lastray+1 < lastray) |
| 1157 |
< |
lastdone = lastray = 0; |
| 1174 |
> |
lastdone = lastray = 0; |
| 1175 |
|
} |
| 1176 |
|
rtp = get_rproc(); /* get avail. rtrace process */ |
| 1177 |
|
rtp->raynum = ++lastray; /* assign ray */ |
| 1178 |
|
if (iblen) { /* trace ray if valid */ |
| 1179 |
|
writebuf(rtp->pd.w, inpbuf, iblen); |
| 1180 |
|
} else { /* else bypass dummy ray */ |
| 1181 |
< |
queue_raytree(rtp); /* empty tree */ |
| 1182 |
< |
if ((yres <= 0) | (waitflush > 1)) |
| 1183 |
< |
waitflush = 1; /* flush after this */ |
| 1181 |
> |
queue_raytree(rtp); /* queue empty ray/record */ |
| 1182 |
> |
if ((yres <= 0) | (xres <= 0)) |
| 1183 |
> |
waitflush = 1; /* flush right after */ |
| 1184 |
|
} |
| 1185 |
|
process_queue(); /* catch up with results */ |
| 1186 |
|
if (raysleft && !--raysleft) |