--- ray/src/util/vwrays.c 2012/06/14 05:19:05 3.17 +++ ray/src/util/vwrays.c 2021/12/03 17:22:28 3.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: vwrays.c,v 3.17 2012/06/14 05:19:05 greg Exp $"; +static const char RCSid[] = "$Id: vwrays.c,v 3.22 2021/12/03 17:22:28 greg Exp $"; #endif /* * Compute rays corresponding to a given picture or view. @@ -133,14 +133,10 @@ main( fprintf(stderr, "%s: no view in picture\n", argv[i]); exit(1); } - if (i+1 < argc) { - zfd = open(argv[i+1], O_RDONLY); - if (zfd < 0) { - fprintf(stderr, - "%s: cannot open depth buffer\n", - argv[i+1]); + if (!getdim & (i+1 < argc)) { + zfd = open_float_depth(argv[i+1], (long)rs.xr*rs.yr); + if (zfd < 0) exit(1); - } } } if ((err = setview(&vw)) != NULL) { @@ -151,7 +147,7 @@ main( normaspect(viewaspect(&vw), &pa, &rs.xr, &rs.yr); if (getdim) { printf("-x %d -y %d -ld%c\n", rs.xr, rs.yr, - vw.vaft > FTINY ? '+' : '-'); + (i+1 == argc) & (vw.vaft > FTINY) ? '+' : '-'); exit(0); } if (fromstdin) @@ -190,12 +186,18 @@ pix2rays( RREAL loc[2]; int pp[2]; double d; - int i; + int i, c; while (fscanf(fp, "%lf %lf", &px, &py) == 2) { px += .5; py += .5; loc[0] = px/rs.xr; loc[1] = py/rs.yr; if (zfd >= 0) { + if ((loc[0] < 0) | (loc[0] >= 1) | + (loc[1] < 0) | (loc[1] >= 1)) { + fprintf(stderr, "%s: input pixel outside image\n", + progname); + exit(1); + } loc2pix(pp, &rs, loc[0], loc[1]); if (lseek(zfd, (pp[1]*scanlen(&rs)+pp[0])*sizeof(float), @@ -207,20 +209,25 @@ pix2rays( exit(1); } } - jitterloc(loc); - d = viewray(rorg, rdir, &vw, loc[0], loc[1]); - if (d < -FTINY) - rorg[0] = rorg[1] = rorg[2] = - rdir[0] = rdir[1] = rdir[2] = 0.; - else if (zfd >= 0) - for (i = 0; i < 3; i++) { - rorg[i] += rdir[i]*zval; - rdir[i] = -rdir[i]; + for (c = repeatcnt; c-- > 0; ) { + jitterloc(loc); + d = viewray(rorg, rdir, &vw, loc[0], loc[1]); + if (d < -FTINY) + rorg[0] = rorg[1] = rorg[2] = + rdir[0] = rdir[1] = rdir[2] = 0.; + else if (zfd >= 0) + for (i = 0; i < 3; i++) { + rorg[i] += rdir[i]*zval; + rdir[i] = -rdir[i]; + } + else if (d > FTINY) { + rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; } - else if (d > FTINY) { - rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; + (*putr)(rorg, rdir); + if (c) { + loc[0] = px/rs.xr; loc[1] = py/rs.yr; + } } - (*putr)(rorg, rdir); if (unbuffered) fflush(stdout); } @@ -267,8 +274,8 @@ putrays(void) rdir[0] = rdir[1] = rdir[2] = 0.; else if (zfd >= 0) for (i = 0; i < 3; i++) { - rorg[i] += rdir[i]*zbuf[si]; - rdir[i] = -rdir[i]; + rdir[i] = -rdir[i]*zbuf[si]; + rorg[i] -= rdir[i]; } else if (d > FTINY) { rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; @@ -304,7 +311,7 @@ putf( /* put out ray in float format */ v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2]; v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2]; - fwrite(v, sizeof(float), 6, stdout); + putbinary(v, sizeof(float), 6, stdout); } @@ -318,5 +325,5 @@ putd( /* put out ray in double format */ v[0] = ro[0]; v[1] = ro[1]; v[2] = ro[2]; v[3] = rd[0]; v[4] = rd[1]; v[5] = rd[2]; - fwrite(v, sizeof(double), 6, stdout); + putbinary(v, sizeof(double), 6, stdout); }