ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pinterp.c
Revision: 2.12
Committed: Mon Apr 12 09:58:09 1993 UTC (31 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.11: +0 -1 lines
Log Message:
fixed incomplete change

File Contents

# Content
1 /* Copyright (c) 1993 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Interpolate and extrapolate pictures with different view parameters.
9 *
10 * Greg Ward 09Dec89
11 */
12
13 #include "standard.h"
14
15 #include <ctype.h>
16
17 #include "view.h"
18
19 #include "color.h"
20
21 #include "resolu.h"
22
23 #define pscan(y) (ourpict+(y)*hresolu)
24 #define zscan(y) (ourzbuf+(y)*hresolu)
25
26 #define F_FORE 1 /* fill foreground */
27 #define F_BACK 2 /* fill background */
28
29 #define PACKSIZ 256 /* max. calculation packet size */
30
31 #define RTCOM "rtrace -h- -ovl -fff "
32
33 #define ABS(x) ((x)>0?(x):-(x))
34
35 struct position {int x,y; float z;};
36
37 VIEW ourview = STDVIEW; /* desired view */
38 int hresolu = 512; /* horizontal resolution */
39 int vresolu = 512; /* vertical resolution */
40 double pixaspect = 1.0; /* pixel aspect ratio */
41
42 double zeps = .02; /* allowed z epsilon */
43
44 COLR *ourpict; /* output picture */
45 float *ourzbuf; /* corresponding z-buffer */
46
47 char *progname;
48
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 (*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? */
56 double ourexp = -1; /* output picture exposure */
57
58 VIEW theirview = STDVIEW; /* input view */
59 int gotview; /* got input view? */
60 int wrongformat = 0; /* input in another format? */
61 RESOLU tresolu; /* input resolution */
62 double theirexp; /* input picture exposure */
63 double theirs2ours[4][4]; /* transformation matrix */
64 int hasmatrix = 0; /* has transformation matrix */
65
66 int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */
67 #define childpid (PDesc[2])
68 unsigned short queue[PACKSIZ][2]; /* pending pixels */
69 int packsiz; /* actual packet size */
70 int queuesiz; /* number of pixels pending */
71
72
73 main(argc, argv) /* interpolate pictures */
74 int argc;
75 char *argv[];
76 {
77 #define check(ol,al) if (argv[i][ol] || \
78 badarg(argc-i-1,argv+i+1,al)) \
79 goto badopt
80 int gotvfile = 0;
81 char *zfile = NULL;
82 char *err;
83 int i, rval;
84
85 progname = argv[0];
86
87 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
88 rval = getviewopt(&ourview, argc-i, argv+i);
89 if (rval >= 0) {
90 i += rval;
91 continue;
92 }
93 switch (argv[i][1]) {
94 case 't': /* threshold */
95 check(2,"f");
96 zeps = atof(argv[++i]);
97 break;
98 case 'n': /* dist. normalized? */
99 check(2,NULL);
100 normdist = !normdist;
101 break;
102 case 'f': /* fill type */
103 switch (argv[i][2]) {
104 case '0': /* none */
105 check(3,NULL);
106 fillo = 0;
107 break;
108 case 'f': /* foreground */
109 check(3,NULL);
110 fillo = F_FORE;
111 break;
112 case 'b': /* background */
113 check(3,NULL);
114 fillo = F_BACK;
115 break;
116 case 'a': /* all */
117 check(3,NULL);
118 fillo = F_FORE|F_BACK;
119 break;
120 case 's': /* sample */
121 check(3,"i");
122 fillsamp = atoi(argv[++i]);
123 break;
124 case 'c': /* color */
125 check(3,"fff");
126 fillfunc = backfill;
127 setcolr(backcolr, atof(argv[i+1]),
128 atof(argv[i+2]), atof(argv[i+3]));
129 i += 3;
130 break;
131 case 'z': /* z value */
132 check(3,"f");
133 fillfunc = backfill;
134 backz = atof(argv[++i]);
135 break;
136 case 'r': /* rtrace */
137 check(3,"s");
138 fillfunc = rcalfill;
139 calstart(RTCOM, argv[++i]);
140 break;
141 default:
142 goto badopt;
143 }
144 break;
145 case 'z': /* z file */
146 check(2,"s");
147 zfile = argv[++i];
148 break;
149 case 'x': /* x resolution */
150 check(2,"i");
151 hresolu = atoi(argv[++i]);
152 break;
153 case 'y': /* y resolution */
154 check(2,"i");
155 vresolu = atoi(argv[++i]);
156 break;
157 case 'p': /* pixel aspect */
158 if (argv[i][2] != 'a')
159 goto badopt;
160 check(3,"f");
161 pixaspect = atof(argv[++i]);
162 break;
163 case 'v': /* view file */
164 if (argv[i][2] != 'f')
165 goto badopt;
166 check(3,"s");
167 gotvfile = viewfile(argv[++i], &ourview, 0, 0);
168 if (gotvfile < 0)
169 syserror(argv[i]);
170 else if (gotvfile == 0) {
171 fprintf(stderr, "%s: bad view file\n",
172 argv[i]);
173 exit(1);
174 }
175 break;
176 default:
177 badopt:
178 fprintf(stderr, "%s: command line error at '%s'\n",
179 progname, argv[i]);
180 goto userr;
181 }
182 }
183 /* check arguments */
184 if ((argc-i)%2)
185 goto userr;
186 if (fillsamp == 1)
187 fillo &= ~F_BACK;
188 /* set view */
189 if (err = setview(&ourview)) {
190 fprintf(stderr, "%s: %s\n", progname, err);
191 exit(1);
192 }
193 normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu);
194 /* allocate frame */
195 ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR));
196 ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float));
197 if (ourpict == NULL || ourzbuf == NULL)
198 syserror(progname);
199 bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float));
200 /* get input */
201 for ( ; i < argc; i += 2)
202 addpicture(argv[i], argv[i+1]);
203 /* fill in spaces */
204 if (fillo&F_BACK)
205 backpicture(fillfunc, fillsamp);
206 else
207 fillpicture(fillfunc);
208 /* close calculation */
209 caldone();
210 /* add to header */
211 printargs(argc, argv, stdout);
212 if (gotvfile) {
213 fputs(VIEWSTR, stdout);
214 fprintview(&ourview, stdout);
215 putc('\n', stdout);
216 }
217 if (pixaspect < .99 || pixaspect > 1.01)
218 fputaspect(pixaspect, stdout);
219 if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
220 fputexpos(ourexp, stdout);
221 fputformat(COLRFMT, stdout);
222 putc('\n', stdout);
223 /* write picture */
224 writepicture();
225 /* write z file */
226 if (zfile != NULL)
227 writedistance(zfile);
228
229 exit(0);
230 userr:
231 fprintf(stderr,
232 "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n",
233 progname);
234 exit(1);
235 #undef check
236 }
237
238
239 headline(s) /* process header string */
240 char *s;
241 {
242 char fmt[32];
243
244 if (isformat(s)) {
245 formatval(fmt, s);
246 wrongformat = strcmp(fmt, COLRFMT);
247 return;
248 }
249 putc('\t', stdout);
250 fputs(s, stdout);
251
252 if (isexpos(s)) {
253 theirexp *= exposval(s);
254 return;
255 }
256 if (isview(s) && sscanview(&theirview, s) > 0)
257 gotview++;
258 }
259
260
261 addpicture(pfile, zspec) /* add picture to output */
262 char *pfile, *zspec;
263 {
264 FILE *pfp;
265 int zfd;
266 char *err;
267 COLR *scanin;
268 float *zin;
269 struct position *plast;
270 int y;
271 /* open picture file */
272 if ((pfp = fopen(pfile, "r")) == NULL)
273 syserror(pfile);
274 /* get header with exposure and view */
275 theirexp = 1.0;
276 gotview = 0;
277 printf("%s:\n", pfile);
278 getheader(pfp, headline, NULL);
279 if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) {
280 fprintf(stderr, "%s: picture format error\n", pfile);
281 exit(1);
282 }
283 if (ourexp <= 0)
284 ourexp = theirexp;
285 else if (ABS(theirexp-ourexp) > .01*ourexp)
286 fprintf(stderr, "%s: different exposure (warning)\n", pfile);
287 if (err = setview(&theirview)) {
288 fprintf(stderr, "%s: %s\n", pfile, err);
289 exit(1);
290 }
291 /* compute transformation */
292 hasmatrix = pixform(theirs2ours, &theirview, &ourview);
293 /* allocate scanlines */
294 scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR));
295 zin = (float *)malloc(scanlen(&tresolu)*sizeof(float));
296 plast = (struct position *)calloc(scanlen(&tresolu),
297 sizeof(struct position));
298 if (scanin == NULL || zin == NULL || plast == NULL)
299 syserror(progname);
300 /* get z specification or file */
301 if ((zfd = open(zspec, O_RDONLY)) == -1) {
302 double zvalue;
303 register int x;
304 if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0)
305 syserror(zspec);
306 for (x = scanlen(&tresolu); x-- > 0; )
307 zin[x] = zvalue;
308 }
309 /* load image */
310 for (y = 0; y < numscans(&tresolu); y++) {
311 if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) {
312 fprintf(stderr, "%s: read error\n", pfile);
313 exit(1);
314 }
315 if (zfd != -1 && read(zfd,(char *)zin,
316 scanlen(&tresolu)*sizeof(float))
317 < scanlen(&tresolu)*sizeof(float)) {
318 fprintf(stderr, "%s: read error\n", zspec);
319 exit(1);
320 }
321 addscanline(y, scanin, zin, plast);
322 }
323 /* clean up */
324 free((char *)scanin);
325 free((char *)zin);
326 free((char *)plast);
327 fclose(pfp);
328 if (zfd != -1)
329 close(zfd);
330 }
331
332
333 pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */
334 register double xfmat[4][4];
335 register VIEW *vw1, *vw2;
336 {
337 double m4t[4][4];
338
339 if (vw1->type != VT_PER && vw1->type != VT_PAR)
340 return(0);
341 if (vw2->type != VT_PER && vw2->type != VT_PAR)
342 return(0);
343 setident4(xfmat);
344 xfmat[0][0] = vw1->hvec[0];
345 xfmat[0][1] = vw1->hvec[1];
346 xfmat[0][2] = vw1->hvec[2];
347 xfmat[1][0] = vw1->vvec[0];
348 xfmat[1][1] = vw1->vvec[1];
349 xfmat[1][2] = vw1->vvec[2];
350 xfmat[2][0] = vw1->vdir[0];
351 xfmat[2][1] = vw1->vdir[1];
352 xfmat[2][2] = vw1->vdir[2];
353 xfmat[3][0] = vw1->vp[0];
354 xfmat[3][1] = vw1->vp[1];
355 xfmat[3][2] = vw1->vp[2];
356 setident4(m4t);
357 m4t[0][0] = vw2->hvec[0]/vw2->hn2;
358 m4t[1][0] = vw2->hvec[1]/vw2->hn2;
359 m4t[2][0] = vw2->hvec[2]/vw2->hn2;
360 m4t[3][0] = -DOT(vw2->vp,vw2->hvec)/vw2->hn2;
361 m4t[0][1] = vw2->vvec[0]/vw2->vn2;
362 m4t[1][1] = vw2->vvec[1]/vw2->vn2;
363 m4t[2][1] = vw2->vvec[2]/vw2->vn2;
364 m4t[3][1] = -DOT(vw2->vp,vw2->vvec)/vw2->vn2;
365 m4t[0][2] = vw2->vdir[0];
366 m4t[1][2] = vw2->vdir[1];
367 m4t[2][2] = vw2->vdir[2];
368 m4t[3][2] = -DOT(vw2->vp,vw2->vdir);
369 multmat4(xfmat, xfmat, m4t);
370 return(1);
371 }
372
373
374 addscanline(y, pline, zline, lasty) /* add scanline to output */
375 int y;
376 COLR *pline;
377 float *zline;
378 struct position *lasty; /* input/output */
379 {
380 FVECT pos;
381 struct position lastx, newpos;
382 register int x;
383
384 lastx.z = 0;
385 for (x = scanlen(&tresolu); x-- > 0; ) {
386 pix2loc(pos, &tresolu, x, y);
387 pos[2] = zline[x];
388 if (movepixel(pos) < 0) {
389 lasty[x].z = lastx.z = 0; /* mark invalid */
390 continue;
391 }
392 newpos.x = pos[0] * hresolu;
393 newpos.y = pos[1] * vresolu;
394 newpos.z = zline[x];
395 /* add pixel to our image */
396 if (pos[0] >= 0 && newpos.x < hresolu
397 && pos[1] >= 0 && newpos.y < vresolu) {
398 addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]);
399 lasty[x].x = lastx.x = newpos.x;
400 lasty[x].y = lastx.y = newpos.y;
401 lasty[x].z = lastx.z = newpos.z;
402 } else
403 lasty[x].z = lastx.z = 0; /* mark invalid */
404 }
405 }
406
407
408 addpixel(p0, p1, p2, pix, z) /* fill in pixel parallelogram */
409 struct position *p0, *p1, *p2;
410 COLR pix;
411 double z;
412 {
413 double zt = 2.*zeps*p0->z; /* threshold */
414 int s1x, s1y, s2x, s2y; /* step sizes */
415 int l1, l2, c1, c2; /* side lengths and counters */
416 int p1isy; /* p0p1 along y? */
417 int x1, y1; /* p1 position */
418 register int x, y; /* final position */
419
420 /* compute vector p0p1 */
421 if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) {
422 s1x = p1->x - p0->x;
423 s1y = p1->y - p0->y;
424 l1 = ABS(s1x);
425 if (p1isy = (ABS(s1y) > l1))
426 l1 = ABS(s1y);
427 } else {
428 l1 = s1x = s1y = 1;
429 p1isy = -1;
430 }
431 /* compute vector p0p2 */
432 if (fillo&F_FORE && ABS(p2->z-p0->z) <= zt) {
433 s2x = p2->x - p0->x;
434 s2y = p2->y - p0->y;
435 if (p1isy == 1)
436 l2 = ABS(s2x);
437 else {
438 l2 = ABS(s2y);
439 if (p1isy != 0 && ABS(s2x) > l2)
440 l2 = ABS(s2x);
441 }
442 } else
443 l2 = s2x = s2y = 1;
444 /* fill the parallelogram */
445 for (c1 = l1; c1-- > 0; ) {
446 x1 = p0->x + c1*s1x/l1;
447 y1 = p0->y + c1*s1y/l1;
448 for (c2 = l2; c2-- > 0; ) {
449 x = x1 + c2*s2x/l2;
450 if (x < 0 || x >= hresolu)
451 continue;
452 y = y1 + c2*s2y/l2;
453 if (y < 0 || y >= vresolu)
454 continue;
455 if (zscan(y)[x] <= 0 || zscan(y)[x]-z
456 > zeps*zscan(y)[x]) {
457 zscan(y)[x] = z;
458 copycolr(pscan(y)[x], pix);
459 }
460 }
461 }
462 }
463
464
465 movepixel(pos) /* reposition image point */
466 FVECT pos;
467 {
468 FVECT pt, direc;
469
470 if (pos[2] <= 0) /* empty pixel */
471 return(-1);
472 if (hasmatrix) {
473 pos[0] += theirview.hoff - .5;
474 pos[1] += theirview.voff - .5;
475 if (theirview.type == VT_PER) {
476 if (normdist) /* adjust for eye-ray distance */
477 pos[2] /= sqrt( 1.
478 + pos[0]*pos[0]*theirview.hn2
479 + pos[1]*pos[1]*theirview.vn2 );
480 pos[0] *= pos[2];
481 pos[1] *= pos[2];
482 }
483 multp3(pos, pos, theirs2ours);
484 if (pos[2] <= 0)
485 return(-1);
486 if (ourview.type == VT_PER) {
487 pos[0] /= pos[2];
488 pos[1] /= pos[2];
489 }
490 pos[0] += .5 - ourview.hoff;
491 pos[1] += .5 - ourview.voff;
492 return(0);
493 }
494 if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0)
495 return(-1);
496 pt[0] += direc[0]*pos[2];
497 pt[1] += direc[1]*pos[2];
498 pt[2] += direc[2]*pos[2];
499 viewloc(pos, &ourview, pt);
500 if (pos[2] <= 0)
501 return(-1);
502 return(0);
503 }
504
505
506 backpicture(fill, samp) /* background fill algorithm */
507 int (*fill)();
508 int samp;
509 {
510 int *yback, xback;
511 int y;
512 register int x, i;
513 /* get back buffer */
514 yback = (int *)malloc(hresolu*sizeof(int));
515 if (yback == NULL)
516 syserror(progname);
517 for (x = 0; x < hresolu; x++)
518 yback[x] = -2;
519 /*
520 * Xback and yback are the pixel locations of suitable
521 * background values in each direction.
522 * A value of -2 means unassigned, and -1 means
523 * that there is no suitable background in this direction.
524 */
525 /* fill image */
526 for (y = 0; y < vresolu; y++) {
527 xback = -2;
528 for (x = 0; x < hresolu; x++)
529 if (zscan(y)[x] <= 0) { /* empty pixel */
530 /*
531 * First, find background from above or below.
532 * (farthest assigned pixel)
533 */
534 if (yback[x] == -2) {
535 for (i = y+1; i < vresolu; i++)
536 if (zscan(i)[x] > 0)
537 break;
538 if (i < vresolu
539 && (y <= 0 || zscan(y-1)[x] < zscan(i)[x]))
540 yback[x] = i;
541 else
542 yback[x] = y-1;
543 }
544 /*
545 * Next, find background from left or right.
546 */
547 if (xback == -2) {
548 for (i = x+1; i < hresolu; i++)
549 if (zscan(y)[i] > 0)
550 break;
551 if (i < hresolu
552 && (x <= 0 || zscan(y)[x-1] < zscan(y)[i]))
553 xback = i;
554 else
555 xback = x-1;
556 }
557 /*
558 * If we have no background for this pixel,
559 * use the given fill function.
560 */
561 if (xback < 0 && yback[x] < 0)
562 goto fillit;
563 /*
564 * Compare, and use the background that is
565 * farther, unless one of them is next to us.
566 * If the background is too distant, call
567 * the fill function.
568 */
569 if ( yback[x] < 0
570 || (xback >= 0 && ABS(x-xback) <= 1)
571 || ( ABS(y-yback[x]) > 1
572 && zscan(yback[x])[x]
573 < zscan(y)[xback] ) ) {
574 if (samp > 0 && ABS(x-xback) >= samp)
575 goto fillit;
576 copycolr(pscan(y)[x],pscan(y)[xback]);
577 zscan(y)[x] = zscan(y)[xback];
578 } else {
579 if (samp > 0 && ABS(y-yback[x]) > samp)
580 goto fillit;
581 copycolr(pscan(y)[x],pscan(yback[x])[x]);
582 zscan(y)[x] = zscan(yback[x])[x];
583 }
584 continue;
585 fillit:
586 (*fill)(x,y);
587 if (fill == rcalfill) { /* use it */
588 clearqueue();
589 xback = x;
590 yback[x] = y;
591 }
592 } else { /* full pixel */
593 yback[x] = -2;
594 xback = -2;
595 }
596 }
597 free((char *)yback);
598 }
599
600
601 fillpicture(fill) /* paint in empty pixels using fill */
602 int (*fill)();
603 {
604 register int x, y;
605
606 for (y = 0; y < vresolu; y++)
607 for (x = 0; x < hresolu; x++)
608 if (zscan(y)[x] <= 0)
609 (*fill)(x,y);
610 }
611
612
613 writepicture() /* write out picture */
614 {
615 int y;
616
617 fprtresolu(hresolu, vresolu, stdout);
618 for (y = vresolu-1; y >= 0; y--)
619 if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
620 syserror(progname);
621 }
622
623
624 writedistance(fname) /* write out z file */
625 char *fname;
626 {
627 int donorm = normdist && ourview.type == VT_PER;
628 int fd;
629 int y;
630 float *zout;
631
632 if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
633 syserror(fname);
634 if (donorm
635 && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
636 syserror(progname);
637 for (y = vresolu-1; y >= 0; y--) {
638 if (donorm) {
639 double vx, yzn2;
640 register int x;
641 yzn2 = (y+.5)/vresolu + ourview.voff - .5;
642 yzn2 = 1. + yzn2*yzn2*ourview.vn2;
643 for (x = 0; x < hresolu; x++) {
644 vx = (x+.5)/hresolu + ourview.hoff - .5;
645 zout[x] = zscan(y)[x]
646 * sqrt(vx*vx*ourview.hn2 + yzn2);
647 }
648 } else
649 zout = zscan(y);
650 if (write(fd, (char *)zout, hresolu*sizeof(float))
651 < hresolu*sizeof(float))
652 syserror(fname);
653 }
654 if (donorm)
655 free((char *)zout);
656 close(fd);
657 }
658
659
660 isfloat(s) /* see if string is floating number */
661 register char *s;
662 {
663 for ( ; *s; s++)
664 if ((*s < '0' || *s > '9') && *s != '.' && *s != '-'
665 && *s != 'e' && *s != 'E' && *s != '+')
666 return(0);
667 return(1);
668 }
669
670
671 backfill(x, y) /* fill pixel with background */
672 int x, y;
673 {
674 register BYTE *dest = pscan(y)[x];
675
676 copycolr(dest, backcolr);
677 zscan(y)[x] = backz;
678 }
679
680
681 calstart(prog, args) /* start fill calculation */
682 char *prog, *args;
683 {
684 char combuf[512];
685 char *argv[64];
686 int rval;
687 register char **wp, *cp;
688
689 if (childpid != -1) {
690 fprintf(stderr, "%s: too many calculations\n", progname);
691 exit(1);
692 }
693 strcpy(combuf, prog);
694 strcat(combuf, args);
695 cp = combuf;
696 wp = argv;
697 for ( ; ; ) {
698 while (isspace(*cp)) /* nullify spaces */
699 *cp++ = '\0';
700 if (!*cp) /* all done? */
701 break;
702 *wp++ = cp; /* add argument to list */
703 while (*++cp && !isspace(*cp))
704 ;
705 }
706 *wp = NULL;
707 /* start process */
708 if ((rval = open_process(PDesc, argv)) < 0)
709 syserror(progname);
710 if (rval == 0) {
711 fprintf(stderr, "%s: command not found\n", argv[0]);
712 exit(1);
713 }
714 packsiz = rval/(6*sizeof(float)) - 1;
715 if (packsiz > PACKSIZ)
716 packsiz = PACKSIZ;
717 queuesiz = 0;
718 }
719
720
721 caldone() /* done with calculation */
722 {
723 if (childpid == -1)
724 return;
725 clearqueue();
726 close_process(PDesc);
727 childpid = -1;
728 }
729
730
731 rcalfill(x, y) /* fill with ray-calculated pixel */
732 int x, y;
733 {
734 if (queuesiz >= packsiz) /* flush queue if needed */
735 clearqueue();
736 /* add position to queue */
737 queue[queuesiz][0] = x;
738 queue[queuesiz][1] = y;
739 queuesiz++;
740 }
741
742
743 clearqueue() /* process queue */
744 {
745 FVECT orig, dir;
746 float fbuf[6*(PACKSIZ+1)];
747 register float *fbp;
748 register int i;
749
750 if (queuesiz == 0)
751 return;
752 fbp = fbuf;
753 for (i = 0; i < queuesiz; i++) {
754 viewray(orig, dir, &ourview,
755 (queue[i][0]+.5)/hresolu,
756 (queue[i][1]+.5)/vresolu);
757 *fbp++ = orig[0]; *fbp++ = orig[1]; *fbp++ = orig[2];
758 *fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2];
759 }
760 /* mark end and get results */
761 bzero((char *)fbp, 6*sizeof(float));
762 if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz,
763 6*sizeof(float)*(queuesiz+1)) !=
764 4*sizeof(float)*queuesiz) {
765 fprintf(stderr, "%s: error reading from rtrace process\n",
766 progname);
767 exit(1);
768 }
769 fbp = fbuf;
770 for (i = 0; i < queuesiz; i++) {
771 if (ourexp > 0 && ourexp != 1.0) {
772 fbp[0] *= ourexp;
773 fbp[1] *= ourexp;
774 fbp[2] *= ourexp;
775 }
776 setcolr(pscan(queue[i][1])[queue[i][0]],
777 fbp[0], fbp[1], fbp[2]);
778 zscan(queue[i][1])[queue[i][0]] = fbp[3];
779 fbp += 4;
780 }
781 queuesiz = 0;
782 }
783
784
785 syserror(s) /* report error and exit */
786 char *s;
787 {
788 perror(s);
789 exit(1);
790 }