--- ray/src/util/vwrays.c 2003/10/22 02:06:35 3.9 +++ ray/src/util/vwrays.c 2009/06/22 00:12:04 3.14 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: vwrays.c,v 3.9 2003/10/22 02:06:35 greg Exp $"; +static const char RCSid[] = "$Id: vwrays.c,v 3.14 2009/06/22 00:12:04 greg Exp $"; #endif /* * Compute rays corresponding to a given picture or view. @@ -7,11 +7,17 @@ static const char RCSid[] = "$Id: vwrays.c,v 3.9 2003/ #include "platform.h" #include "standard.h" +#include "random.h" #include "view.h" -extern int putf(), putd(), puta(); +typedef void putfunc(FVECT ro, FVECT rd); +static putfunc puta; +static putfunc putf; +static putfunc putd; +static void pix2rays(FILE *fp); +static void putrays(void); -int (*putr)() = puta; +static putfunc *putr = puta; VIEW vw = STDVIEW; @@ -19,6 +25,8 @@ RESOLU rs = {PIXSTANDARD, 512, 512}; double pa = 1.; +double pj = 0.; + int zfd = -1; int fromstdin = 0; @@ -26,9 +34,11 @@ int fromstdin = 0; char *progname; -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { char *err; int rval, getdim = 0; @@ -46,9 +56,11 @@ char *argv[]; break; case 'f': /* float */ putr = putf; + SET_FILE_BINARY(stdout); break; case 'd': /* double */ putr = putd; + SET_FILE_BINARY(stdout); break; default: goto userr; @@ -89,8 +101,13 @@ char *argv[]; exit(1); } break; - case 'p': /* pixel aspect ratio */ - pa = atof(argv[++i]); + 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; @@ -140,25 +157,36 @@ userr: } -pix2rays(FILE *fp) +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 +) +{ static FVECT rorg, rdir; float zval; double px, py; + RREAL loc[2]; int pp[2]; double d; register 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 || @@ -169,7 +197,8 @@ pix2rays(FILE *fp) 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.; @@ -190,11 +219,12 @@ pix2rays(FILE *fp) } -putrays() +static void +putrays(void) { - static RREAL loc[2]; - static FVECT rorg, rdir; - float *zbuf; + RREAL loc[2]; + FVECT rorg, rdir; + float *zbuf = NULL; int sc; double d; register int si, i; @@ -217,6 +247,7 @@ putrays() } for (si = 0; si < scanlen(&rs); si++) { 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] = @@ -237,8 +268,11 @@ putrays() } -puta(ro, rd) /* put out ray in ASCII format */ -FVECT ro, rd; +static void +puta( /* put out ray in ASCII format */ + FVECT ro, + FVECT rd +) { printf("%.5e %.5e %.5e %.5e %.5e %.5e\n", ro[0], ro[1], ro[2], @@ -246,8 +280,11 @@ FVECT ro, rd; } -putf(ro, rd) /* put out ray in float format */ -FVECT ro, rd; +static void +putf( /* put out ray in float format */ + FVECT ro, + FVECT rd +) { float v[6]; @@ -257,8 +294,11 @@ FVECT ro, rd; } -putd(ro, rd) /* put out ray in double format */ -FVECT ro, rd; +static void +putd( /* put out ray in double format */ + FVECT ro, + FVECT rd +) { double v[6];