| 5 |
|
* Compute rays corresponding to a given picture or view. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
– |
|
| 9 |
– |
#include "standard.h" |
| 10 |
– |
|
| 8 |
|
#include "platform.h" |
| 9 |
+ |
#include "standard.h" |
| 10 |
+ |
#include "random.h" |
| 11 |
|
#include "view.h" |
| 12 |
|
|
| 13 |
< |
extern int putf(), putd(), puta(); |
| 13 |
> |
typedef void putfunc(FVECT ro, FVECT rd); |
| 14 |
> |
static putfunc puta; |
| 15 |
> |
static putfunc putf; |
| 16 |
> |
static putfunc putd; |
| 17 |
> |
static void pix2rays(FILE *fp); |
| 18 |
> |
static void putrays(void); |
| 19 |
|
|
| 20 |
< |
int (*putr)() = puta; |
| 20 |
> |
static putfunc *putr = puta; |
| 21 |
|
|
| 22 |
|
VIEW vw = STDVIEW; |
| 23 |
|
|
| 25 |
|
|
| 26 |
|
double pa = 1.; |
| 27 |
|
|
| 28 |
+ |
double pj = 0.; |
| 29 |
+ |
|
| 30 |
|
int zfd = -1; |
| 31 |
|
|
| 32 |
|
int fromstdin = 0; |
| 34 |
|
char *progname; |
| 35 |
|
|
| 36 |
|
|
| 37 |
< |
main(argc, argv) |
| 38 |
< |
int argc; |
| 39 |
< |
char *argv[]; |
| 37 |
> |
int |
| 38 |
> |
main( |
| 39 |
> |
int argc, |
| 40 |
> |
char *argv[] |
| 41 |
> |
) |
| 42 |
|
{ |
| 43 |
|
char *err; |
| 44 |
|
int rval, getdim = 0; |
| 99 |
|
exit(1); |
| 100 |
|
} |
| 101 |
|
break; |
| 102 |
< |
case 'p': /* pixel aspect ratio */ |
| 103 |
< |
pa = atof(argv[++i]); |
| 102 |
> |
case 'p': /* pixel aspect or jitter */ |
| 103 |
> |
if (argv[i][2] == 'a') |
| 104 |
> |
pa = atof(argv[++i]); |
| 105 |
> |
else if (argv[i][2] == 'j') |
| 106 |
> |
pj= atof(argv[++i]); |
| 107 |
> |
else |
| 108 |
> |
goto userr; |
| 109 |
|
break; |
| 110 |
|
case 'i': /* get pixels from stdin */ |
| 111 |
|
fromstdin = 1; |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
< |
pix2rays(FILE *fp) |
| 158 |
> |
static void |
| 159 |
> |
jitterloc( |
| 160 |
> |
RREAL loc[2] |
| 161 |
> |
) |
| 162 |
|
{ |
| 163 |
+ |
if (pj > FTINY) { |
| 164 |
+ |
loc[0] += pj*(.5 - frandom())/rs.xr; |
| 165 |
+ |
loc[1] += pj*(.5 - frandom())/rs.yr; |
| 166 |
+ |
} |
| 167 |
+ |
} |
| 168 |
+ |
|
| 169 |
+ |
|
| 170 |
+ |
static void |
| 171 |
+ |
pix2rays( |
| 172 |
+ |
FILE *fp |
| 173 |
+ |
) |
| 174 |
+ |
{ |
| 175 |
|
static FVECT rorg, rdir; |
| 176 |
|
float zval; |
| 177 |
|
double px, py; |
| 178 |
+ |
RREAL loc[2]; |
| 179 |
|
int pp[2]; |
| 180 |
|
double d; |
| 181 |
|
register int i; |
| 182 |
|
|
| 183 |
|
while (fscanf(fp, "%lf %lf", &px, &py) == 2) { |
| 184 |
+ |
px += .5; py += .5; |
| 185 |
|
if (px < 0 || px >= rs.xr || |
| 186 |
|
py < 0 || py >= rs.yr) { |
| 187 |
|
fprintf(stderr, |
| 189 |
|
progname, px, py); |
| 190 |
|
exit(1); |
| 191 |
|
} |
| 192 |
+ |
loc[0] = px/rs.xr; loc[1] = py/rs.yr; |
| 193 |
|
if (zfd >= 0) { |
| 194 |
< |
loc2pix(pp, &rs, px/rs.xr, py/rs.yr); |
| 194 |
> |
loc2pix(pp, &rs, loc[0], loc[1]); |
| 195 |
|
if (lseek(zfd, |
| 196 |
< |
(pp[1]*scanlen(&rs)+pp[0])*sizeof(float), 0) |
| 197 |
< |
< 0 || |
| 196 |
> |
(pp[1]*scanlen(&rs)+pp[0])*sizeof(float), |
| 197 |
> |
SEEK_SET) < 0 || |
| 198 |
|
read(zfd, &zval, sizeof(float)) |
| 199 |
< |
< sizeof(float)) { |
| 199 |
> |
< sizeof(float)) { |
| 200 |
|
fprintf(stderr, "%s: depth buffer read error\n", |
| 201 |
|
progname); |
| 202 |
|
exit(1); |
| 203 |
|
} |
| 204 |
|
} |
| 205 |
< |
d = viewray(rorg, rdir, &vw, px/rs.xr, py/rs.yr); |
| 205 |
> |
jitterloc(loc); |
| 206 |
> |
d = viewray(rorg, rdir, &vw, loc[0], loc[1]); |
| 207 |
|
if (d < -FTINY) |
| 208 |
|
rorg[0] = rorg[1] = rorg[2] = |
| 209 |
|
rdir[0] = rdir[1] = rdir[2] = 0.; |
| 224 |
|
} |
| 225 |
|
|
| 226 |
|
|
| 227 |
< |
putrays() |
| 227 |
> |
static void |
| 228 |
> |
putrays(void) |
| 229 |
|
{ |
| 230 |
< |
static RREAL loc[2]; |
| 231 |
< |
static FVECT rorg, rdir; |
| 232 |
< |
float *zbuf; |
| 230 |
> |
RREAL loc[2]; |
| 231 |
> |
FVECT rorg, rdir; |
| 232 |
> |
float *zbuf = NULL; |
| 233 |
|
int sc; |
| 234 |
|
double d; |
| 235 |
|
register int si, i; |
| 252 |
|
} |
| 253 |
|
for (si = 0; si < scanlen(&rs); si++) { |
| 254 |
|
pix2loc(loc, &rs, si, sc); |
| 255 |
+ |
jitterloc(loc); |
| 256 |
|
d = viewray(rorg, rdir, &vw, loc[0], loc[1]); |
| 257 |
|
if (d < -FTINY) |
| 258 |
|
rorg[0] = rorg[1] = rorg[2] = |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
|
| 276 |
< |
puta(ro, rd) /* put out ray in ASCII format */ |
| 277 |
< |
FVECT ro, rd; |
| 276 |
> |
static void |
| 277 |
> |
puta( /* put out ray in ASCII format */ |
| 278 |
> |
FVECT ro, |
| 279 |
> |
FVECT rd |
| 280 |
> |
) |
| 281 |
|
{ |
| 282 |
|
printf("%.5e %.5e %.5e %.5e %.5e %.5e\n", |
| 283 |
|
ro[0], ro[1], ro[2], |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 288 |
< |
putf(ro, rd) /* put out ray in float format */ |
| 289 |
< |
FVECT ro, rd; |
| 288 |
> |
static void |
| 289 |
> |
putf( /* put out ray in float format */ |
| 290 |
> |
FVECT ro, |
| 291 |
> |
FVECT rd |
| 292 |
> |
) |
| 293 |
|
{ |
| 294 |
|
float v[6]; |
| 295 |
|
|
| 299 |
|
} |
| 300 |
|
|
| 301 |
|
|
| 302 |
< |
putd(ro, rd) /* put out ray in double format */ |
| 303 |
< |
FVECT ro, rd; |
| 302 |
> |
static void |
| 303 |
> |
putd( /* put out ray in double format */ |
| 304 |
> |
FVECT ro, |
| 305 |
> |
FVECT rd |
| 306 |
> |
) |
| 307 |
|
{ |
| 308 |
|
double v[6]; |
| 309 |
|
|