| 28 |
|
|
| 29 |
|
#define PACKSIZ 42 /* calculation packet size */ |
| 30 |
|
|
| 31 |
< |
#define RTCOM "rtrace -h -ovl -fff -x %d %s" |
| 31 |
> |
#define RTCOM "rtrace -h -ovl -fff %s" |
| 32 |
|
|
| 33 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
| 34 |
|
|
| 46 |
|
|
| 47 |
|
char *progname; |
| 48 |
|
|
| 49 |
< |
int fill = F_FORE|F_BACK; /* selected fill algorithm */ |
| 49 |
> |
int fillo = F_FORE|F_BACK; /* selected fill options */ |
| 50 |
> |
int fillsamp = 0; /* sample separation (0 == inf) */ |
| 51 |
|
extern int backfill(), rcalfill(); /* fill functions */ |
| 52 |
< |
int (*deffill)() = backfill; /* selected fill function */ |
| 52 |
> |
int (*fillfunc)() = backfill; /* selected fill function */ |
| 53 |
|
COLR backcolr = BLKCOLR; /* background color */ |
| 54 |
|
double backz = 0.0; /* background z value */ |
| 55 |
|
int normdist = 1; /* normalized distance? */ |
| 99 |
|
switch (argv[i][2]) { |
| 100 |
|
case '0': /* none */ |
| 101 |
|
check(3,0); |
| 102 |
< |
fill = 0; |
| 102 |
> |
fillo = 0; |
| 103 |
|
break; |
| 104 |
|
case 'f': /* foreground */ |
| 105 |
|
check(3,0); |
| 106 |
< |
fill = F_FORE; |
| 106 |
> |
fillo = F_FORE; |
| 107 |
|
break; |
| 108 |
|
case 'b': /* background */ |
| 109 |
|
check(3,0); |
| 110 |
< |
fill = F_BACK; |
| 110 |
> |
fillo = F_BACK; |
| 111 |
|
break; |
| 112 |
|
case 'a': /* all */ |
| 113 |
|
check(3,0); |
| 114 |
< |
fill = F_FORE|F_BACK; |
| 114 |
> |
fillo = F_FORE|F_BACK; |
| 115 |
|
break; |
| 116 |
+ |
case 's': /* sample */ |
| 117 |
+ |
check(3,1); |
| 118 |
+ |
fillsamp = atoi(argv[++i]); |
| 119 |
+ |
break; |
| 120 |
|
case 'c': /* color */ |
| 121 |
|
check(3,3); |
| 122 |
< |
deffill = backfill; |
| 122 |
> |
fillfunc = backfill; |
| 123 |
|
setcolr(backcolr, atof(argv[i+1]), |
| 124 |
|
atof(argv[i+2]), atof(argv[i+3])); |
| 125 |
|
i += 3; |
| 126 |
|
break; |
| 127 |
|
case 'z': /* z value */ |
| 128 |
|
check(3,1); |
| 129 |
< |
deffill = backfill; |
| 129 |
> |
fillfunc = backfill; |
| 130 |
|
backz = atof(argv[++i]); |
| 131 |
|
break; |
| 132 |
|
case 'r': /* rtrace */ |
| 133 |
|
check(3,1); |
| 134 |
< |
deffill = rcalfill; |
| 134 |
> |
fillfunc = rcalfill; |
| 135 |
|
calstart(RTCOM, argv[++i]); |
| 136 |
|
break; |
| 137 |
|
default: |
| 193 |
|
for ( ; i < argc; i += 2) |
| 194 |
|
addpicture(argv[i], argv[i+1]); |
| 195 |
|
/* fill in spaces */ |
| 196 |
< |
if (fill&F_BACK) |
| 197 |
< |
backpicture(); |
| 196 |
> |
if (fillo&F_BACK) |
| 197 |
> |
backpicture(fillfunc, fillsamp); |
| 198 |
|
else |
| 199 |
< |
fillpicture(); |
| 199 |
> |
fillpicture(fillfunc); |
| 200 |
|
/* close calculation */ |
| 201 |
|
caldone(); |
| 202 |
|
/* add to header */ |
| 203 |
|
printargs(argc, argv, stdout); |
| 204 |
|
if (gotvfile) { |
| 205 |
< |
printf(VIEWSTR); |
| 205 |
> |
fputs(VIEWSTR, stdout); |
| 206 |
|
fprintview(&ourview, stdout); |
| 207 |
< |
printf("\n"); |
| 207 |
> |
putc('\n', stdout); |
| 208 |
|
} |
| 209 |
|
if (pixaspect < .99 || pixaspect > 1.01) |
| 210 |
|
fputaspect(pixaspect, stdout); |
| 211 |
|
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
| 212 |
|
fputexpos(ourexp, stdout); |
| 213 |
< |
printf("\n"); |
| 213 |
> |
putc('\n', stdout); |
| 214 |
|
/* write picture */ |
| 215 |
|
writepicture(); |
| 216 |
|
/* write z file */ |
| 230 |
|
headline(s) /* process header string */ |
| 231 |
|
char *s; |
| 232 |
|
{ |
| 233 |
< |
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
| 233 |
> |
static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; |
| 234 |
|
register char **an; |
| 235 |
|
|
| 236 |
< |
printf("\t%s", s); |
| 236 |
> |
putc('\t', stdout); |
| 237 |
> |
fputs(s, stdout); |
| 238 |
|
|
| 239 |
|
if (isexpos(s)) { |
| 240 |
|
theirexp *= exposval(s); |
| 425 |
|
register int x, y; /* final position */ |
| 426 |
|
|
| 427 |
|
/* compute vector p0p1 */ |
| 428 |
< |
if (fill&F_FORE && ABS(p1->z-p0->z) <= zt) { |
| 428 |
> |
if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { |
| 429 |
|
s1x = p1->x - p0->x; |
| 430 |
|
s1y = p1->y - p0->y; |
| 431 |
|
l1 = ABS(s1x); |
| 436 |
|
p1isy = -1; |
| 437 |
|
} |
| 438 |
|
/* compute vector p0p2 */ |
| 439 |
< |
if (fill&F_FORE && ABS(p2->z-p0->z) <= zt) { |
| 439 |
> |
if (fillo&F_FORE && ABS(p2->z-p0->z) <= zt) { |
| 440 |
|
s2x = p2->x - p0->x; |
| 441 |
|
s2y = p2->y - p0->y; |
| 442 |
|
if (p1isy == 1) |
| 454 |
|
y1 = p0->y + c1*s1y/l1; |
| 455 |
|
for (c2 = l2; c2-- > 0; ) { |
| 456 |
|
x = x1 + c2*s2x/l2; |
| 457 |
+ |
if (x < 0 || x >= hresolu) |
| 458 |
+ |
continue; |
| 459 |
|
y = y1 + c2*s2y/l2; |
| 460 |
+ |
if (y < 0 || y >= vresolu) |
| 461 |
+ |
continue; |
| 462 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
| 463 |
|
> zeps*zscan(y)[x]) { |
| 464 |
|
zscan(y)[x] = z; |
| 469 |
|
} |
| 470 |
|
|
| 471 |
|
|
| 472 |
< |
backpicture() /* background fill algorithm */ |
| 472 |
> |
backpicture(fill, samp) /* background fill algorithm */ |
| 473 |
> |
int (*fill)(); |
| 474 |
> |
int samp; |
| 475 |
|
{ |
| 476 |
|
int *yback, xback; |
| 477 |
|
int y; |
| 522 |
|
xback = x-1; |
| 523 |
|
} |
| 524 |
|
/* |
| 525 |
< |
* Check to see if we have no background for |
| 526 |
< |
* this pixel. If not, use background color. |
| 525 |
> |
* If we have no background for this pixel, |
| 526 |
> |
* use the given fill function. |
| 527 |
|
*/ |
| 528 |
< |
if (xback < 0 && yback[x] < 0) { |
| 529 |
< |
(*deffill)(x,y); |
| 518 |
< |
continue; |
| 519 |
< |
} |
| 528 |
> |
if (xback < 0 && yback[x] < 0) |
| 529 |
> |
goto fillit; |
| 530 |
|
/* |
| 531 |
|
* Compare, and use the background that is |
| 532 |
|
* farther, unless one of them is next to us. |
| 533 |
+ |
* If the background is too distant, call |
| 534 |
+ |
* the fill function. |
| 535 |
|
*/ |
| 536 |
|
if ( yback[x] < 0 |
| 537 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
| 538 |
|
|| ( ABS(y-yback[x]) > 1 |
| 539 |
|
&& zscan(yback[x])[x] |
| 540 |
|
< zscan(y)[xback] ) ) { |
| 541 |
+ |
if (samp > 0 && ABS(x-xback) >= samp) |
| 542 |
+ |
goto fillit; |
| 543 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
| 544 |
|
zscan(y)[x] = zscan(y)[xback]; |
| 545 |
|
} else { |
| 546 |
+ |
if (samp > 0 && ABS(y-yback[x]) > samp) |
| 547 |
+ |
goto fillit; |
| 548 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
| 549 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
| 550 |
|
} |
| 551 |
+ |
continue; |
| 552 |
+ |
fillit: |
| 553 |
+ |
(*fill)(x,y); |
| 554 |
+ |
if (fill == rcalfill) { /* use it */ |
| 555 |
+ |
clearqueue(); |
| 556 |
+ |
xback = x; |
| 557 |
+ |
yback[x] = y; |
| 558 |
+ |
} |
| 559 |
|
} else { /* full pixel */ |
| 560 |
|
yback[x] = -2; |
| 561 |
|
xback = -2; |
| 565 |
|
} |
| 566 |
|
|
| 567 |
|
|
| 568 |
< |
fillpicture() /* paint in empty pixels with default */ |
| 568 |
> |
fillpicture(fill) /* paint in empty pixels using fill */ |
| 569 |
> |
int (*fill)(); |
| 570 |
|
{ |
| 571 |
|
register int x, y; |
| 572 |
|
|
| 573 |
|
for (y = 0; y < vresolu; y++) |
| 574 |
|
for (x = 0; x < hresolu; x++) |
| 575 |
|
if (zscan(y)[x] <= 0) |
| 576 |
< |
(*deffill)(x,y); |
| 576 |
> |
(*fill)(x,y); |
| 577 |
|
} |
| 578 |
|
|
| 579 |
|
|
| 608 |
|
if (donorm) { |
| 609 |
|
double vx, yzn2; |
| 610 |
|
register int x; |
| 611 |
< |
yzn2 = y - .5*(vresolu-1); |
| 611 |
> |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 612 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 613 |
|
for (x = 0; x < hresolu; x++) { |
| 614 |
< |
vx = x - .5*(hresolu-1); |
| 614 |
> |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 615 |
|
zout[x] = zscan(y)[x] |
| 616 |
|
* sqrt(vx*vx*ourview.hn2 + yzn2); |
| 617 |
|
} |
| 660 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
| 661 |
|
exit(1); |
| 662 |
|
} |
| 663 |
< |
sprintf(combuf, prog, PACKSIZ, args); |
| 663 |
> |
sprintf(combuf, prog, args); |
| 664 |
|
if (pipe(p0) < 0 || pipe(p1) < 0) |
| 665 |
|
syserror(); |
| 666 |
|
if ((childpid = vfork()) == 0) { /* fork calculation */ |
| 696 |
|
|
| 697 |
|
if (childpid == -1) |
| 698 |
|
return; |
| 699 |
< |
clearqueue(1); |
| 699 |
> |
clearqueue(); |
| 700 |
> |
fclose(psend); |
| 701 |
> |
fclose(precv); |
| 702 |
|
while ((pid = wait(0)) != -1 && pid != childpid) |
| 703 |
|
; |
| 704 |
|
childpid = -1; |
| 709 |
|
int x, y; |
| 710 |
|
{ |
| 711 |
|
if (queuesiz >= PACKSIZ) /* flush queue if needed */ |
| 712 |
< |
clearqueue(0); |
| 712 |
> |
clearqueue(); |
| 713 |
|
/* add position to queue */ |
| 714 |
|
queue[queuesiz][0] = x; |
| 715 |
|
queue[queuesiz][1] = y; |
| 717 |
|
} |
| 718 |
|
|
| 719 |
|
|
| 720 |
< |
clearqueue(done) /* process queue */ |
| 694 |
< |
int done; |
| 720 |
> |
clearqueue() /* process queue */ |
| 721 |
|
{ |
| 722 |
|
FVECT orig, dir; |
| 723 |
|
float fbuf[6]; |
| 731 |
|
fbuf[3] = dir[0]; fbuf[4] = dir[1]; fbuf[5] = dir[2]; |
| 732 |
|
fwrite((char *)fbuf, sizeof(float), 6, psend); |
| 733 |
|
} |
| 734 |
< |
if ((done ? fclose(psend) : fflush(psend)) == EOF) |
| 734 |
> |
/* flush output and get results */ |
| 735 |
> |
fbuf[3] = fbuf[4] = fbuf[5] = 0.0; /* mark */ |
| 736 |
> |
fwrite((char *)fbuf, sizeof(float), 6, psend); |
| 737 |
> |
if (fflush(psend) == EOF) |
| 738 |
|
syserror(); |
| 739 |
|
for (i = 0; i < queuesiz; i++) { |
| 740 |
|
if (fread((char *)fbuf, sizeof(float), 4, precv) < 4) { |
| 751 |
|
fbuf[0], fbuf[1], fbuf[2]); |
| 752 |
|
zscan(queue[i][1])[queue[i][0]] = fbuf[3]; |
| 753 |
|
} |
| 725 |
– |
if (done) |
| 726 |
– |
fclose(precv); |
| 754 |
|
queuesiz = 0; |
| 755 |
|
} |
| 756 |
|
|