| 17 |
|
#define pscan(y) (ourpict+(y)*ourview.hresolu) |
| 18 |
|
#define zscan(y) (ourzbuf+(y)*ourview.hresolu) |
| 19 |
|
|
| 20 |
< |
#define F_FORE 1 /* fill foreground */ |
| 21 |
< |
#define F_BACK 2 /* fill background */ |
| 20 |
> |
#define F_FORE 1 /* fill foreground */ |
| 21 |
> |
#define F_BACK 2 /* fill background */ |
| 22 |
|
|
| 23 |
+ |
#define PACKSIZ 42 /* calculation packet size */ |
| 24 |
+ |
|
| 25 |
+ |
#define RTCOM "rtrace -h -ovl -fff -x %d %s" |
| 26 |
+ |
|
| 27 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
| 28 |
|
|
| 29 |
|
VIEW ourview = STDVIEW(512); /* desired view */ |
| 38 |
|
VIEW theirview = STDVIEW(512); /* input view */ |
| 39 |
|
int gotview; /* got input view? */ |
| 40 |
|
|
| 41 |
< |
int fill = F_FORE|F_BACK; /* fill level */ |
| 41 |
> |
int fill = F_FORE|F_BACK; /* selected fill algorithm */ |
| 42 |
> |
extern int backfill(), calfill(); /* fill functions */ |
| 43 |
> |
int (*deffill)() = backfill; /* selected fill function */ |
| 44 |
|
COLR backcolr = BLKCOLR; /* background color */ |
| 45 |
+ |
double backz = 0.0; /* background z value */ |
| 46 |
|
|
| 47 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
| 48 |
|
int normdist = 1; /* normalized distance? */ |
| 49 |
|
|
| 50 |
+ |
FILE *psend, *precv; /* pipes to/from fill calculation */ |
| 51 |
+ |
int childpid; /* child's process id */ |
| 52 |
+ |
int queue[PACKSIZ][2]; /* pending pixels */ |
| 53 |
+ |
int queuesiz; /* number of pixels pending */ |
| 54 |
|
|
| 55 |
+ |
|
| 56 |
|
main(argc, argv) /* interpolate pictures */ |
| 57 |
|
int argc; |
| 58 |
|
char *argv[]; |
| 96 |
|
break; |
| 97 |
|
case 'c': /* color */ |
| 98 |
|
check(3,3); |
| 99 |
+ |
deffill = backfill; |
| 100 |
|
setcolr(backcolr, atof(argv[i+1]), |
| 101 |
|
atof(argv[i+2]), atof(argv[i+3])); |
| 102 |
|
i += 3; |
| 103 |
|
break; |
| 104 |
+ |
case 'z': /* z value */ |
| 105 |
+ |
check(3,1); |
| 106 |
+ |
deffill = backfill; |
| 107 |
+ |
backz = atof(argv[++i]); |
| 108 |
+ |
break; |
| 109 |
+ |
case 'r': /* rtrace */ |
| 110 |
+ |
check(3,1); |
| 111 |
+ |
deffill = calfill; |
| 112 |
+ |
calstart(RTCOM, argv[++i]); |
| 113 |
+ |
break; |
| 114 |
|
default: |
| 115 |
|
goto badopt; |
| 116 |
|
} |
| 182 |
|
goto userr; |
| 183 |
|
} |
| 184 |
|
/* check arguments */ |
| 185 |
< |
if (argc-i < 2 || (argc-i)%2) |
| 185 |
> |
if ((argc-i)%2) |
| 186 |
|
goto userr; |
| 187 |
|
/* set view */ |
| 188 |
|
if (err = setview(&ourview)) { |
| 190 |
|
exit(1); |
| 191 |
|
} |
| 192 |
|
/* allocate frame */ |
| 193 |
< |
ourpict = (COLR *)calloc(ourview.hresolu*ourview.vresolu,sizeof(COLR)); |
| 193 |
> |
ourpict = (COLR *)malloc(ourview.hresolu*ourview.vresolu*sizeof(COLR)); |
| 194 |
|
ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float)); |
| 195 |
|
if (ourpict == NULL || ourzbuf == NULL) { |
| 196 |
|
perror(progname); |
| 201 |
|
addpicture(argv[i], argv[i+1]); |
| 202 |
|
/* fill in spaces */ |
| 203 |
|
if (fill&F_BACK) |
| 181 |
– |
fillpicture(); |
| 182 |
– |
else |
| 204 |
|
backpicture(); |
| 205 |
+ |
else |
| 206 |
+ |
fillpicture(); |
| 207 |
+ |
/* close calculation */ |
| 208 |
+ |
if (deffill == calfill) |
| 209 |
+ |
caldone(); |
| 210 |
|
/* add to header */ |
| 211 |
|
printargs(argc, argv, stdout); |
| 212 |
|
if (gotvfile) { |
| 442 |
|
} |
| 443 |
|
|
| 444 |
|
|
| 445 |
< |
fillpicture() /* fill in empty spaces */ |
| 445 |
> |
backpicture() /* background fill algorithm */ |
| 446 |
|
{ |
| 447 |
|
int *yback, xback; |
| 448 |
|
int y; |
| 499 |
|
* this pixel. If not, use background color. |
| 500 |
|
*/ |
| 501 |
|
if (xback < 0 && yback[x] < 0) { |
| 502 |
< |
copycolr(pscan(y)[x], backcolr); |
| 502 |
> |
(*deffill)(x,y); |
| 503 |
|
continue; |
| 504 |
|
} |
| 505 |
|
/* |
| 510 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
| 511 |
|
|| ( ABS(y-yback[x]) > 1 |
| 512 |
|
&& zscan(yback[x])[x] |
| 513 |
< |
< zscan(y)[xback] ) ) |
| 513 |
> |
< zscan(y)[xback] ) ) { |
| 514 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
| 515 |
< |
else |
| 515 |
> |
zscan(y)[x] = zscan(y)[xback]; |
| 516 |
> |
} else { |
| 517 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
| 518 |
+ |
zscan(y)[x] = zscan(yback[x])[x]; |
| 519 |
+ |
} |
| 520 |
|
} else { /* full pixel */ |
| 521 |
|
yback[x] = -2; |
| 522 |
|
xback = -2; |
| 526 |
|
} |
| 527 |
|
|
| 528 |
|
|
| 529 |
< |
backpicture() /* paint in empty pixels */ |
| 529 |
> |
fillpicture() /* paint in empty pixels with default */ |
| 530 |
|
{ |
| 531 |
|
register int x, y; |
| 532 |
|
|
| 533 |
|
for (y = 0; y < ourview.vresolu; y++) |
| 534 |
|
for (x = 0; x < ourview.hresolu; x++) |
| 535 |
|
if (zscan(y)[x] <= 0) |
| 536 |
< |
copycolr(pscan(y)[x], backcolr); |
| 536 |
> |
(*deffill)(x,y); |
| 537 |
|
} |
| 538 |
|
|
| 539 |
|
|
| 601 |
|
&& *s != 'e' && *s != 'E' && *s != '+') |
| 602 |
|
return(0); |
| 603 |
|
return(1); |
| 604 |
+ |
} |
| 605 |
+ |
|
| 606 |
+ |
|
| 607 |
+ |
backfill(x, y) /* fill pixel with background */ |
| 608 |
+ |
int x, y; |
| 609 |
+ |
{ |
| 610 |
+ |
register BYTE *dest = pscan(y)[x]; |
| 611 |
+ |
|
| 612 |
+ |
copycolr(dest, backcolr); |
| 613 |
+ |
zscan(y)[x] = backz; |
| 614 |
+ |
} |
| 615 |
+ |
|
| 616 |
+ |
|
| 617 |
+ |
calstart(prog, args) /* start fill calculation */ |
| 618 |
+ |
char *prog, *args; |
| 619 |
+ |
{ |
| 620 |
+ |
char combuf[512]; |
| 621 |
+ |
int p0[2], p1[2]; |
| 622 |
+ |
|
| 623 |
+ |
sprintf(combuf, prog, PACKSIZ, args); |
| 624 |
+ |
if (pipe(p0) < 0 || pipe(p1) < 0) |
| 625 |
+ |
goto syserr; |
| 626 |
+ |
if ((childpid = vfork()) == 0) { /* fork calculation */ |
| 627 |
+ |
close(p0[1]); |
| 628 |
+ |
close(p1[0]); |
| 629 |
+ |
if (p0[0] != 0) { |
| 630 |
+ |
dup2(p0[0], 0); |
| 631 |
+ |
close(p0[0]); |
| 632 |
+ |
} |
| 633 |
+ |
if (p1[1] != 1) { |
| 634 |
+ |
dup2(p1[1], 1); |
| 635 |
+ |
close(p1[1]); |
| 636 |
+ |
} |
| 637 |
+ |
execl("/bin/sh", "sh", "-c", combuf, 0); |
| 638 |
+ |
perror("/bin/sh"); |
| 639 |
+ |
_exit(127); |
| 640 |
+ |
} |
| 641 |
+ |
if (childpid < 0) |
| 642 |
+ |
goto syserr; |
| 643 |
+ |
close(p0[0]); |
| 644 |
+ |
close(p1[1]); |
| 645 |
+ |
if ((psend = fdopen(p0[1], "w")) == NULL) |
| 646 |
+ |
goto syserr; |
| 647 |
+ |
if ((precv = fdopen(p1[0], "r")) == NULL) |
| 648 |
+ |
goto syserr; |
| 649 |
+ |
queuesiz = 0; |
| 650 |
+ |
return; |
| 651 |
+ |
syserr: |
| 652 |
+ |
perror(progname); |
| 653 |
+ |
exit(1); |
| 654 |
+ |
} |
| 655 |
+ |
|
| 656 |
+ |
|
| 657 |
+ |
caldone() /* done with calculation */ |
| 658 |
+ |
{ |
| 659 |
+ |
int pid; |
| 660 |
+ |
|
| 661 |
+ |
fclose(psend); |
| 662 |
+ |
clearqueue(); |
| 663 |
+ |
fclose(precv); |
| 664 |
+ |
while ((pid = wait(0)) != -1 && pid != childpid) |
| 665 |
+ |
; |
| 666 |
+ |
} |
| 667 |
+ |
|
| 668 |
+ |
|
| 669 |
+ |
calfill(x, y) /* fill with calculated pixel */ |
| 670 |
+ |
int x, y; |
| 671 |
+ |
{ |
| 672 |
+ |
FVECT orig, dir; |
| 673 |
+ |
float outbuf[6]; |
| 674 |
+ |
|
| 675 |
+ |
if (queuesiz >= PACKSIZ) { /* flush queue */ |
| 676 |
+ |
fflush(psend); |
| 677 |
+ |
clearqueue(); |
| 678 |
+ |
} |
| 679 |
+ |
/* send new ray */ |
| 680 |
+ |
rayview(orig, dir, &ourview, x+.5, y+.5); |
| 681 |
+ |
outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2]; |
| 682 |
+ |
outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2]; |
| 683 |
+ |
fwrite(outbuf, sizeof(float), 6, psend); |
| 684 |
+ |
/* remember it */ |
| 685 |
+ |
queue[queuesiz][0] = x; |
| 686 |
+ |
queue[queuesiz][1] = y; |
| 687 |
+ |
queuesiz++; |
| 688 |
+ |
} |
| 689 |
+ |
|
| 690 |
+ |
|
| 691 |
+ |
clearqueue() /* get results from queue */ |
| 692 |
+ |
{ |
| 693 |
+ |
float inbuf[4]; |
| 694 |
+ |
register int i; |
| 695 |
+ |
|
| 696 |
+ |
for (i = 0; i < queuesiz; i++) { |
| 697 |
+ |
fread(inbuf, sizeof(float), 4, precv); |
| 698 |
+ |
setcolr(pscan(queue[i][1])[queue[i][0]], |
| 699 |
+ |
inbuf[0], inbuf[1], inbuf[2]); |
| 700 |
+ |
zscan(queue[i][1])[queue[i][0]] = inbuf[3]; |
| 701 |
+ |
} |
| 702 |
+ |
queuesiz = 0; |
| 703 |
|
} |