--- ray/src/util/vwrays.c 2004/03/26 23:34:23 3.10 +++ ray/src/util/vwrays.c 2012/06/14 05:19:05 3.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: vwrays.c,v 3.10 2004/03/26 23:34:23 schorsch Exp $"; +static const char RCSid[] = "$Id: vwrays.c,v 3.17 2012/06/14 05:19:05 greg Exp $"; #endif /* * Compute rays corresponding to a given picture or view. @@ -7,6 +7,7 @@ static const char RCSid[] = "$Id: vwrays.c,v 3.10 2004 #include "platform.h" #include "standard.h" +#include "random.h" #include "view.h" typedef void putfunc(FVECT ro, FVECT rd); @@ -24,10 +25,16 @@ RESOLU rs = {PIXSTANDARD, 512, 512}; double pa = 1.; +double pj = 0.; + int zfd = -1; int fromstdin = 0; +int unbuffered = 0; + +int repeatcnt = 1; + char *progname; @@ -39,7 +46,7 @@ main( { char *err; int rval, getdim = 0; - register int i; + int i; progname = argv[0]; if (argc < 2) @@ -53,9 +60,11 @@ main( break; case 'f': /* float */ putr = putf; + SET_FILE_BINARY(stdout); break; case 'd': /* double */ putr = putd; + SET_FILE_BINARY(stdout); break; default: goto userr; @@ -96,12 +105,23 @@ main( exit(1); } break; - case 'p': /* pixel aspect ratio */ - pa = atof(argv[++i]); + case 'c': /* repeat count */ + repeatcnt = atoi(argv[++i]); break; + case 'p': /* pixel aspect or jitter */ + if (argv[i][2] == 'a') + pa = atof(argv[++i]); + else if (argv[i][2] == 'j') + pj = atof(argv[++i]); + else + goto userr; + break; case 'i': /* get pixels from stdin */ fromstdin = 1; break; + case 'u': /* unbuffered output */ + unbuffered = 1; + break; default: goto userr; } @@ -141,13 +161,25 @@ main( exit(0); userr: fprintf(stderr, - "Usage: %s [ -i -f{a|f|d} | -d ] { view opts .. | picture [zbuf] }\n", + "Usage: %s [ -i -u -f{a|f|d} -c rept | -d ] { view opts .. | picture [zbuf] }\n", progname); exit(1); } static void +jitterloc( + RREAL loc[2] +) +{ + if (pj > FTINY) { + loc[0] += pj*(.5 - frandom())/rs.xr; + loc[1] += pj*(.5 - frandom())/rs.yr; + } +} + + +static void pix2rays( FILE *fp ) @@ -155,20 +187,16 @@ pix2rays( static FVECT rorg, rdir; float zval; double px, py; + RREAL loc[2]; int pp[2]; double d; - register int i; + int i; while (fscanf(fp, "%lf %lf", &px, &py) == 2) { - if (px < 0 || px >= rs.xr || - py < 0 || py >= rs.yr) { - fprintf(stderr, - "%s: (x,y) pair (%.0f,%.0f) out of range\n", - progname, px, py); - exit(1); - } + px += .5; py += .5; + loc[0] = px/rs.xr; loc[1] = py/rs.yr; if (zfd >= 0) { - loc2pix(pp, &rs, px/rs.xr, py/rs.yr); + loc2pix(pp, &rs, loc[0], loc[1]); if (lseek(zfd, (pp[1]*scanlen(&rs)+pp[0])*sizeof(float), SEEK_SET) < 0 || @@ -179,7 +207,8 @@ pix2rays( exit(1); } } - d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr); + 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.; @@ -192,6 +221,8 @@ pix2rays( rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; } (*putr)(rorg, rdir); + if (unbuffered) + fflush(stdout); } if (!feof(fp)) { fprintf(stderr, "%s: expected px py on input\n", progname); @@ -203,12 +234,12 @@ pix2rays( static void putrays(void) { - static RREAL loc[2]; - static FVECT rorg, rdir; + RREAL loc[2]; + FVECT rorg, rdir; float *zbuf = NULL; int sc; double d; - register int si, i; + int si, i, c; if (zfd >= 0) { zbuf = (float *)malloc(scanlen(&rs)*sizeof(float)); @@ -227,7 +258,9 @@ putrays(void) } } for (si = 0; si < scanlen(&rs); si++) { + for (c = repeatcnt; c-- > 0; ) { pix2loc(loc, &rs, si, sc); + jitterloc(loc); d = viewray(rorg, rdir, &vw, loc[0], loc[1]); if (d < -FTINY) rorg[0] = rorg[1] = rorg[2] = @@ -241,6 +274,7 @@ putrays(void) rdir[0] *= d; rdir[1] *= d; rdir[2] *= d; } (*putr)(rorg, rdir); + } } } if (zfd >= 0)