1 |
+ |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
+ |
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
14 |
|
|
15 |
|
#include <fcntl.h> |
16 |
|
|
17 |
+ |
#include <ctype.h> |
18 |
+ |
|
19 |
|
#include "view.h" |
20 |
|
|
21 |
|
#include "color.h" |
22 |
|
|
23 |
+ |
#include "resolu.h" |
24 |
+ |
|
25 |
|
#ifndef BSD |
26 |
|
#define vfork fork |
27 |
|
#endif |
32 |
|
#define F_FORE 1 /* fill foreground */ |
33 |
|
#define F_BACK 2 /* fill background */ |
34 |
|
|
35 |
< |
#define PACKSIZ 42 /* calculation packet size */ |
35 |
> |
#define PACKSIZ 256 /* max. calculation packet size */ |
36 |
|
|
37 |
< |
#define RTCOM "rtrace -h -ovl -fff %s" |
37 |
> |
#define RTCOM "rtrace -h- -ovl -fff " |
38 |
|
|
39 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
40 |
|
|
63 |
|
|
64 |
|
VIEW theirview = STDVIEW; /* input view */ |
65 |
|
int gotview; /* got input view? */ |
66 |
< |
int thresolu, tvresolu; /* input resolution */ |
66 |
> |
int wrongformat = 0; /* input in another format? */ |
67 |
> |
RESOLU tresolu; /* input resolution */ |
68 |
|
double theirexp; /* input picture exposure */ |
69 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
70 |
+ |
int hasmatrix = 0; /* has transformation matrix */ |
71 |
|
|
72 |
< |
int childpid = -1; /* id of fill process */ |
73 |
< |
FILE *psend, *precv; /* pipes to/from fill calculation */ |
74 |
< |
int queue[PACKSIZ][2]; /* pending pixels */ |
72 |
> |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
73 |
> |
#define childpid (PDesc[2]) |
74 |
> |
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
75 |
> |
int packsiz; /* actual packet size */ |
76 |
|
int queuesiz; /* number of pixels pending */ |
77 |
|
|
78 |
|
|
80 |
|
int argc; |
81 |
|
char *argv[]; |
82 |
|
{ |
83 |
< |
#define check(olen,narg) if (argv[i][olen] || narg >= argc-i) goto badopt |
84 |
< |
extern double atof(); |
83 |
> |
#define check(ol,al) if (argv[i][ol] || \ |
84 |
> |
badarg(argc-i-1,argv+i+1,al)) \ |
85 |
> |
goto badopt |
86 |
|
int gotvfile = 0; |
87 |
|
char *zfile = NULL; |
88 |
|
char *err; |
98 |
|
} |
99 |
|
switch (argv[i][1]) { |
100 |
|
case 't': /* threshold */ |
101 |
< |
check(2,1); |
101 |
> |
check(2,"f"); |
102 |
|
zeps = atof(argv[++i]); |
103 |
|
break; |
104 |
|
case 'n': /* dist. normalized? */ |
105 |
< |
check(2,0); |
105 |
> |
check(2,NULL); |
106 |
|
normdist = !normdist; |
107 |
|
break; |
108 |
|
case 'f': /* fill type */ |
109 |
|
switch (argv[i][2]) { |
110 |
|
case '0': /* none */ |
111 |
< |
check(3,0); |
111 |
> |
check(3,NULL); |
112 |
|
fillo = 0; |
113 |
|
break; |
114 |
|
case 'f': /* foreground */ |
115 |
< |
check(3,0); |
115 |
> |
check(3,NULL); |
116 |
|
fillo = F_FORE; |
117 |
|
break; |
118 |
|
case 'b': /* background */ |
119 |
< |
check(3,0); |
119 |
> |
check(3,NULL); |
120 |
|
fillo = F_BACK; |
121 |
|
break; |
122 |
|
case 'a': /* all */ |
123 |
< |
check(3,0); |
123 |
> |
check(3,NULL); |
124 |
|
fillo = F_FORE|F_BACK; |
125 |
|
break; |
126 |
|
case 's': /* sample */ |
127 |
< |
check(3,1); |
127 |
> |
check(3,"i"); |
128 |
|
fillsamp = atoi(argv[++i]); |
129 |
|
break; |
130 |
|
case 'c': /* color */ |
131 |
< |
check(3,3); |
131 |
> |
check(3,"fff"); |
132 |
|
fillfunc = backfill; |
133 |
|
setcolr(backcolr, atof(argv[i+1]), |
134 |
|
atof(argv[i+2]), atof(argv[i+3])); |
135 |
|
i += 3; |
136 |
|
break; |
137 |
|
case 'z': /* z value */ |
138 |
< |
check(3,1); |
138 |
> |
check(3,"f"); |
139 |
|
fillfunc = backfill; |
140 |
|
backz = atof(argv[++i]); |
141 |
|
break; |
142 |
|
case 'r': /* rtrace */ |
143 |
< |
check(3,1); |
143 |
> |
check(3,"s"); |
144 |
|
fillfunc = rcalfill; |
145 |
|
calstart(RTCOM, argv[++i]); |
146 |
|
break; |
149 |
|
} |
150 |
|
break; |
151 |
|
case 'z': /* z file */ |
152 |
< |
check(2,1); |
152 |
> |
check(2,"s"); |
153 |
|
zfile = argv[++i]; |
154 |
|
break; |
155 |
|
case 'x': /* x resolution */ |
156 |
< |
check(2,1); |
156 |
> |
check(2,"i"); |
157 |
|
hresolu = atoi(argv[++i]); |
158 |
|
break; |
159 |
|
case 'y': /* y resolution */ |
160 |
< |
check(2,1); |
160 |
> |
check(2,"i"); |
161 |
|
vresolu = atoi(argv[++i]); |
162 |
|
break; |
163 |
|
case 'p': /* pixel aspect */ |
164 |
< |
check(2,1); |
164 |
> |
if (argv[i][2] != 'a') |
165 |
> |
goto badopt; |
166 |
> |
check(3,"f"); |
167 |
|
pixaspect = atof(argv[++i]); |
168 |
|
break; |
169 |
|
case 'v': /* view file */ |
170 |
|
if (argv[i][2] != 'f') |
171 |
|
goto badopt; |
172 |
< |
check(3,1); |
172 |
> |
check(3,"s"); |
173 |
|
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
174 |
|
if (gotvfile < 0) { |
175 |
|
perror(argv[i]); |
190 |
|
/* check arguments */ |
191 |
|
if ((argc-i)%2) |
192 |
|
goto userr; |
193 |
+ |
if (fillsamp == 1) |
194 |
+ |
fillo &= ~F_BACK; |
195 |
|
/* set view */ |
196 |
|
if (err = setview(&ourview)) { |
197 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
224 |
|
fputaspect(pixaspect, stdout); |
225 |
|
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
226 |
|
fputexpos(ourexp, stdout); |
227 |
+ |
fputformat(COLRFMT, stdout); |
228 |
|
putc('\n', stdout); |
229 |
|
/* write picture */ |
230 |
|
writepicture(); |
245 |
|
headline(s) /* process header string */ |
246 |
|
char *s; |
247 |
|
{ |
248 |
< |
static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; |
234 |
< |
register char **an; |
248 |
> |
char fmt[32]; |
249 |
|
|
250 |
+ |
if (isformat(s)) { |
251 |
+ |
formatval(fmt, s); |
252 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
253 |
+ |
return; |
254 |
+ |
} |
255 |
|
putc('\t', stdout); |
256 |
|
fputs(s, stdout); |
257 |
|
|
259 |
|
theirexp *= exposval(s); |
260 |
|
return; |
261 |
|
} |
262 |
< |
for (an = altname; *an != NULL; an++) |
263 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
245 |
< |
if (sscanview(&theirview, s+strlen(*an)) > 0) |
246 |
< |
gotview++; |
247 |
< |
break; |
248 |
< |
} |
262 |
> |
if (isview(s) && sscanview(&theirview, s) > 0) |
263 |
> |
gotview++; |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
addpicture(pfile, zspec) /* add picture to output */ |
268 |
|
char *pfile, *zspec; |
269 |
|
{ |
255 |
– |
extern double atof(); |
270 |
|
FILE *pfp; |
271 |
|
int zfd; |
272 |
|
char *err; |
283 |
|
theirexp = 1.0; |
284 |
|
gotview = 0; |
285 |
|
printf("%s:\n", pfile); |
286 |
< |
getheader(pfp, headline); |
287 |
< |
if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) |
288 |
< |
!= (YMAJOR|YDECR)) { |
275 |
< |
fprintf(stderr, "%s: picture view error\n", pfile); |
286 |
> |
getheader(pfp, headline, NULL); |
287 |
> |
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
288 |
> |
fprintf(stderr, "%s: picture format error\n", pfile); |
289 |
|
exit(1); |
290 |
|
} |
291 |
|
if (ourexp <= 0) |
297 |
|
exit(1); |
298 |
|
} |
299 |
|
/* compute transformation */ |
300 |
< |
pixform(theirs2ours, &theirview, &ourview); |
300 |
> |
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
301 |
|
/* allocate scanlines */ |
302 |
< |
scanin = (COLR *)malloc(thresolu*sizeof(COLR)); |
303 |
< |
zin = (float *)malloc(thresolu*sizeof(float)); |
304 |
< |
plast = (struct position *)calloc(thresolu, sizeof(struct position)); |
302 |
> |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
303 |
> |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
304 |
> |
plast = (struct position *)calloc(scanlen(&tresolu), |
305 |
> |
sizeof(struct position)); |
306 |
|
if (scanin == NULL || zin == NULL || plast == NULL) |
307 |
|
syserror(); |
308 |
|
/* get z specification or file */ |
313 |
|
perror(zspec); |
314 |
|
exit(1); |
315 |
|
} |
316 |
< |
for (x = 0; x < thresolu; x++) |
316 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) |
317 |
|
zin[x] = zvalue; |
318 |
|
} |
319 |
|
/* load image */ |
320 |
< |
for (y = tvresolu-1; y >= 0; y--) { |
321 |
< |
if (freadcolrs(scanin, thresolu, pfp) < 0) { |
320 |
> |
for (y = 0; y < numscans(&tresolu); y++) { |
321 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
322 |
|
fprintf(stderr, "%s: read error\n", pfile); |
323 |
|
exit(1); |
324 |
|
} |
325 |
< |
if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float)) |
326 |
< |
< thresolu*sizeof(float)) { |
325 |
> |
if (zfd != -1 && read(zfd,(char *)zin, |
326 |
> |
scanlen(&tresolu)*sizeof(float)) |
327 |
> |
< scanlen(&tresolu)*sizeof(float)) { |
328 |
|
fprintf(stderr, "%s: read error\n", zspec); |
329 |
|
exit(1); |
330 |
|
} |
346 |
|
{ |
347 |
|
double m4t[4][4]; |
348 |
|
|
349 |
+ |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
350 |
+ |
return(0); |
351 |
+ |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
352 |
+ |
return(0); |
353 |
|
setident4(xfmat); |
354 |
|
xfmat[0][0] = vw1->hvec[0]; |
355 |
|
xfmat[0][1] = vw1->hvec[1]; |
377 |
|
m4t[2][2] = vw2->vdir[2]; |
378 |
|
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
379 |
|
multmat4(xfmat, xfmat, m4t); |
380 |
+ |
return(1); |
381 |
|
} |
382 |
|
|
383 |
|
|
388 |
|
struct position *lasty; /* input/output */ |
389 |
|
{ |
390 |
|
extern double sqrt(); |
391 |
< |
double pos[3]; |
391 |
> |
FVECT pos; |
392 |
|
struct position lastx, newpos; |
393 |
|
register int x; |
394 |
|
|
395 |
|
lastx.z = 0; |
396 |
< |
for (x = thresolu-1; x >= 0; x--) { |
397 |
< |
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
378 |
< |
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
396 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) { |
397 |
> |
pix2loc(pos, &tresolu, x, y); |
398 |
|
pos[2] = zline[x]; |
399 |
< |
if (theirview.type == VT_PER) { |
381 |
< |
if (normdist) /* adjust for eye-ray distance */ |
382 |
< |
pos[2] /= sqrt( 1. |
383 |
< |
+ pos[0]*pos[0]*theirview.hn2 |
384 |
< |
+ pos[1]*pos[1]*theirview.vn2 ); |
385 |
< |
pos[0] *= pos[2]; |
386 |
< |
pos[1] *= pos[2]; |
387 |
< |
} |
388 |
< |
multp3(pos, pos, theirs2ours); |
389 |
< |
if (pos[2] <= 0) { |
399 |
> |
if (movepixel(pos) < 0) { |
400 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
401 |
|
continue; |
402 |
|
} |
393 |
– |
if (ourview.type == VT_PER) { |
394 |
– |
pos[0] /= pos[2]; |
395 |
– |
pos[1] /= pos[2]; |
396 |
– |
} |
397 |
– |
pos[0] += .5 - ourview.hoff; |
398 |
– |
pos[1] += .5 - ourview.voff; |
403 |
|
newpos.x = pos[0] * hresolu; |
404 |
|
newpos.y = pos[1] * vresolu; |
405 |
|
newpos.z = zline[x]; |
458 |
|
y1 = p0->y + c1*s1y/l1; |
459 |
|
for (c2 = l2; c2-- > 0; ) { |
460 |
|
x = x1 + c2*s2x/l2; |
461 |
+ |
if (x < 0 || x >= hresolu) |
462 |
+ |
continue; |
463 |
|
y = y1 + c2*s2y/l2; |
464 |
+ |
if (y < 0 || y >= vresolu) |
465 |
+ |
continue; |
466 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
467 |
|
> zeps*zscan(y)[x]) { |
468 |
|
zscan(y)[x] = z; |
473 |
|
} |
474 |
|
|
475 |
|
|
476 |
+ |
movepixel(pos) /* reposition image point */ |
477 |
+ |
FVECT pos; |
478 |
+ |
{ |
479 |
+ |
FVECT pt, direc; |
480 |
+ |
|
481 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
482 |
+ |
return(-1); |
483 |
+ |
if (hasmatrix) { |
484 |
+ |
pos[0] += theirview.hoff - .5; |
485 |
+ |
pos[1] += theirview.voff - .5; |
486 |
+ |
if (theirview.type == VT_PER) { |
487 |
+ |
if (normdist) /* adjust for eye-ray distance */ |
488 |
+ |
pos[2] /= sqrt( 1. |
489 |
+ |
+ pos[0]*pos[0]*theirview.hn2 |
490 |
+ |
+ pos[1]*pos[1]*theirview.vn2 ); |
491 |
+ |
pos[0] *= pos[2]; |
492 |
+ |
pos[1] *= pos[2]; |
493 |
+ |
} |
494 |
+ |
multp3(pos, pos, theirs2ours); |
495 |
+ |
if (pos[2] <= 0) |
496 |
+ |
return(-1); |
497 |
+ |
if (ourview.type == VT_PER) { |
498 |
+ |
pos[0] /= pos[2]; |
499 |
+ |
pos[1] /= pos[2]; |
500 |
+ |
} |
501 |
+ |
pos[0] += .5 - ourview.hoff; |
502 |
+ |
pos[1] += .5 - ourview.voff; |
503 |
+ |
return(0); |
504 |
+ |
} |
505 |
+ |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) |
506 |
+ |
return(-1); |
507 |
+ |
pt[0] += direc[0]*pos[2]; |
508 |
+ |
pt[1] += direc[1]*pos[2]; |
509 |
+ |
pt[2] += direc[2]*pos[2]; |
510 |
+ |
viewloc(pos, &ourview, pt); |
511 |
+ |
if (pos[2] <= 0) |
512 |
+ |
return(-1); |
513 |
+ |
return(0); |
514 |
+ |
} |
515 |
+ |
|
516 |
+ |
|
517 |
|
backpicture(fill, samp) /* background fill algorithm */ |
518 |
|
int (*fill)(); |
519 |
|
int samp; |
520 |
|
{ |
521 |
|
int *yback, xback; |
522 |
|
int y; |
474 |
– |
COLR pfill; |
523 |
|
register int x, i; |
524 |
|
/* get back buffer */ |
525 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
567 |
|
} |
568 |
|
/* |
569 |
|
* If we have no background for this pixel, |
522 |
– |
* or if the background is too distant, |
570 |
|
* use the given fill function. |
571 |
|
*/ |
572 |
< |
if ((xback < 0 && yback[x] < 0) |
573 |
< |
|| (samp > 0 |
527 |
< |
&& ABS(x-xback) >= samp |
528 |
< |
&& ABS(y-yback[y]) >= samp)) { |
529 |
< |
(*fill)(x,y); |
530 |
< |
if (fill != backfill) { /* reuse */ |
531 |
< |
yback[x] = -2; |
532 |
< |
xback = -2; |
533 |
< |
} |
534 |
< |
continue; |
535 |
< |
} |
572 |
> |
if (xback < 0 && yback[x] < 0) |
573 |
> |
goto fillit; |
574 |
|
/* |
575 |
|
* Compare, and use the background that is |
576 |
|
* farther, unless one of them is next to us. |
577 |
+ |
* If the background is too distant, call |
578 |
+ |
* the fill function. |
579 |
|
*/ |
580 |
|
if ( yback[x] < 0 |
581 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
582 |
|
|| ( ABS(y-yback[x]) > 1 |
583 |
|
&& zscan(yback[x])[x] |
584 |
|
< zscan(y)[xback] ) ) { |
585 |
+ |
if (samp > 0 && ABS(x-xback) >= samp) |
586 |
+ |
goto fillit; |
587 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
588 |
|
zscan(y)[x] = zscan(y)[xback]; |
589 |
|
} else { |
590 |
+ |
if (samp > 0 && ABS(y-yback[x]) > samp) |
591 |
+ |
goto fillit; |
592 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
593 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
594 |
|
} |
595 |
+ |
continue; |
596 |
+ |
fillit: |
597 |
+ |
(*fill)(x,y); |
598 |
+ |
if (fill == rcalfill) { /* use it */ |
599 |
+ |
clearqueue(); |
600 |
+ |
xback = x; |
601 |
+ |
yback[x] = y; |
602 |
+ |
} |
603 |
|
} else { /* full pixel */ |
604 |
|
yback[x] = -2; |
605 |
|
xback = -2; |
625 |
|
{ |
626 |
|
int y; |
627 |
|
|
628 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
628 |
> |
fprtresolu(hresolu, vresolu, stdout); |
629 |
|
for (y = vresolu-1; y >= 0; y--) |
630 |
|
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
631 |
|
syserror(); |
652 |
|
if (donorm) { |
653 |
|
double vx, yzn2; |
654 |
|
register int x; |
655 |
< |
yzn2 = y - .5*(vresolu-1); |
655 |
> |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
656 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
657 |
|
for (x = 0; x < hresolu; x++) { |
658 |
< |
vx = x - .5*(hresolu-1); |
658 |
> |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
659 |
|
zout[x] = zscan(y)[x] |
660 |
|
* sqrt(vx*vx*ourview.hn2 + yzn2); |
661 |
|
} |
694 |
|
} |
695 |
|
|
696 |
|
|
697 |
< |
calstart(prog, args) /* start fill calculation */ |
697 |
> |
calstart(prog, args) /* start fill calculation */ |
698 |
|
char *prog, *args; |
699 |
|
{ |
700 |
|
char combuf[512]; |
701 |
< |
int p0[2], p1[2]; |
701 |
> |
char *argv[64]; |
702 |
> |
int rval; |
703 |
> |
register char **wp, *cp; |
704 |
|
|
705 |
|
if (childpid != -1) { |
706 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
707 |
|
exit(1); |
708 |
|
} |
709 |
< |
sprintf(combuf, prog, args); |
710 |
< |
if (pipe(p0) < 0 || pipe(p1) < 0) |
711 |
< |
syserror(); |
712 |
< |
if ((childpid = vfork()) == 0) { /* fork calculation */ |
713 |
< |
close(p0[1]); |
714 |
< |
close(p1[0]); |
715 |
< |
if (p0[0] != 0) { |
716 |
< |
dup2(p0[0], 0); |
717 |
< |
close(p0[0]); |
718 |
< |
} |
719 |
< |
if (p1[1] != 1) { |
666 |
< |
dup2(p1[1], 1); |
667 |
< |
close(p1[1]); |
668 |
< |
} |
669 |
< |
execl("/bin/sh", "sh", "-c", combuf, 0); |
670 |
< |
perror("/bin/sh"); |
671 |
< |
_exit(127); |
709 |
> |
strcpy(combuf, prog); |
710 |
> |
strcat(combuf, args); |
711 |
> |
cp = combuf; |
712 |
> |
wp = argv; |
713 |
> |
for ( ; ; ) { |
714 |
> |
while (isspace(*cp)) cp++; |
715 |
> |
if (!*cp) break; |
716 |
> |
*wp++ = cp; |
717 |
> |
while (!isspace(*cp)) |
718 |
> |
if (!*cp++) goto done; |
719 |
> |
*cp++ = '\0'; |
720 |
|
} |
721 |
< |
if (childpid == -1) |
721 |
> |
done: |
722 |
> |
*wp = NULL; |
723 |
> |
/* start process */ |
724 |
> |
if ((rval = open_process(PDesc, argv)) < 0) |
725 |
|
syserror(); |
726 |
< |
close(p0[0]); |
727 |
< |
close(p1[1]); |
728 |
< |
if ((psend = fdopen(p0[1], "w")) == NULL) |
729 |
< |
syserror(); |
730 |
< |
if ((precv = fdopen(p1[0], "r")) == NULL) |
731 |
< |
syserror(); |
726 |
> |
if (rval == 0) { |
727 |
> |
fprintf(stderr, "%s: command not found\n", argv[0]); |
728 |
> |
exit(1); |
729 |
> |
} |
730 |
> |
packsiz = rval/(6*sizeof(float)) - 1; |
731 |
> |
if (packsiz > PACKSIZ) |
732 |
> |
packsiz = PACKSIZ; |
733 |
|
queuesiz = 0; |
734 |
|
} |
735 |
|
|
736 |
|
|
737 |
< |
caldone() /* done with calculation */ |
737 |
> |
caldone() /* done with calculation */ |
738 |
|
{ |
687 |
– |
int pid; |
688 |
– |
|
739 |
|
if (childpid == -1) |
740 |
|
return; |
741 |
|
clearqueue(); |
742 |
< |
fclose(psend); |
693 |
< |
fclose(precv); |
694 |
< |
while ((pid = wait(0)) != -1 && pid != childpid) |
695 |
< |
; |
742 |
> |
close_process(PDesc); |
743 |
|
childpid = -1; |
744 |
|
} |
745 |
|
|
747 |
|
rcalfill(x, y) /* fill with ray-calculated pixel */ |
748 |
|
int x, y; |
749 |
|
{ |
750 |
< |
if (queuesiz >= PACKSIZ) /* flush queue if needed */ |
750 |
> |
if (queuesiz >= packsiz) /* flush queue if needed */ |
751 |
|
clearqueue(); |
752 |
|
/* add position to queue */ |
753 |
|
queue[queuesiz][0] = x; |
759 |
|
clearqueue() /* process queue */ |
760 |
|
{ |
761 |
|
FVECT orig, dir; |
762 |
< |
float fbuf[6]; |
762 |
> |
float fbuf[6*(PACKSIZ+1)]; |
763 |
> |
register float *fbp; |
764 |
|
register int i; |
765 |
|
|
766 |
+ |
fbp = fbuf; |
767 |
|
for (i = 0; i < queuesiz; i++) { |
768 |
|
viewray(orig, dir, &ourview, |
769 |
|
(queue[i][0]+.5)/hresolu, |
770 |
|
(queue[i][1]+.5)/vresolu); |
771 |
< |
fbuf[0] = orig[0]; fbuf[1] = orig[1]; fbuf[2] = orig[2]; |
772 |
< |
fbuf[3] = dir[0]; fbuf[4] = dir[1]; fbuf[5] = dir[2]; |
724 |
< |
fwrite((char *)fbuf, sizeof(float), 6, psend); |
771 |
> |
*fbp++ = orig[0]; *fbp++ = orig[1]; *fbp++ = orig[2]; |
772 |
> |
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
773 |
|
} |
774 |
< |
/* flush output and get results */ |
775 |
< |
fbuf[3] = fbuf[4] = fbuf[5] = 0.0; /* mark */ |
776 |
< |
fwrite((char *)fbuf, sizeof(float), 6, psend); |
777 |
< |
if (fflush(psend) == EOF) |
778 |
< |
syserror(); |
774 |
> |
/* mark end and get results */ |
775 |
> |
bzero((char *)fbp, 6*sizeof(float)); |
776 |
> |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
777 |
> |
6*sizeof(float)*(queuesiz+1)) != |
778 |
> |
4*sizeof(float)*queuesiz) { |
779 |
> |
fprintf(stderr, "%s: error reading from rtrace process\n", |
780 |
> |
progname); |
781 |
> |
exit(1); |
782 |
> |
} |
783 |
> |
fbp = fbuf; |
784 |
|
for (i = 0; i < queuesiz; i++) { |
732 |
– |
if (fread((char *)fbuf, sizeof(float), 4, precv) < 4) { |
733 |
– |
fprintf(stderr, "%s: read error in clearqueue\n", |
734 |
– |
progname); |
735 |
– |
exit(1); |
736 |
– |
} |
785 |
|
if (ourexp > 0 && ourexp != 1.0) { |
786 |
< |
fbuf[0] *= ourexp; |
787 |
< |
fbuf[1] *= ourexp; |
788 |
< |
fbuf[2] *= ourexp; |
786 |
> |
fbp[0] *= ourexp; |
787 |
> |
fbp[1] *= ourexp; |
788 |
> |
fbp[2] *= ourexp; |
789 |
|
} |
790 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
791 |
< |
fbuf[0], fbuf[1], fbuf[2]); |
792 |
< |
zscan(queue[i][1])[queue[i][0]] = fbuf[3]; |
791 |
> |
fbp[0], fbp[1], fbp[2]); |
792 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
793 |
> |
fbp += 4; |
794 |
|
} |
795 |
|
queuesiz = 0; |
796 |
|
} |