| 26 |
|
|
| 27 |
|
unsigned long nsamps = 10000; /* desired number of initial samples */ |
| 28 |
|
unsigned long nssamps = 9000; /* number of super-samples */ |
| 29 |
< |
int ndsamps = 16; /* number of direct samples */ |
| 29 |
> |
int ndsamps = 32; /* number of direct samples */ |
| 30 |
|
int nprocs = 1; /* number of rendering processes */ |
| 31 |
|
|
| 32 |
|
float *sensor = NULL; /* current sensor data */ |
| 38 |
|
int nphi = 0; /* azimuthal angle divisions */ |
| 39 |
|
double gscale = 1.; /* global scaling value */ |
| 40 |
|
|
| 41 |
+ |
#define s_theta(t) sensor[(t+1)*(sntp[1]+1)] |
| 42 |
+ |
#define s_phi(p) sensor[(p)+1] |
| 43 |
+ |
#define s_val(t,p) sensor[(p)+1+(t+1)*(sntp[1]+1)] |
| 44 |
+ |
|
| 45 |
|
static void comp_sensor(char *sfile); |
| 46 |
|
|
| 47 |
|
static void |
| 72 |
|
|
| 73 |
|
progname = argv[0]; |
| 74 |
|
/* set up rendering defaults */ |
| 75 |
< |
dstrsrc = 0.25; |
| 75 |
> |
rand_samp = 1; |
| 76 |
> |
dstrsrc = 0.5; |
| 77 |
> |
srcsizerat = 0.1; |
| 78 |
|
directrelay = 3; |
| 79 |
|
ambounce = 1; |
| 80 |
+ |
maxdepth = -10; |
| 81 |
|
/* just asking defaults? */ |
| 82 |
|
if (argc == 2 && !strcmp(argv[1], "-defaults")) { |
| 83 |
|
print_defaults(); |
| 289 |
|
if (pvals != NULL) |
| 290 |
|
free((void *)pvals); |
| 291 |
|
if (sfile == NULL || !*sfile) { |
| 292 |
+ |
sensor = NULL; |
| 293 |
+ |
sntp[0] = sntp[1] = 0; |
| 294 |
|
pvals = NULL; |
| 295 |
|
ntheta = nphi = 0; |
| 296 |
|
return; |
| 308 |
|
error(INTERNAL, errmsg); |
| 309 |
|
} |
| 310 |
|
/* compute boundary angles */ |
| 311 |
< |
maxtheta = 1.5f*sensor[sntp[0]*(sntp[1]+1)] - |
| 303 |
< |
0.5f*sensor[sntp[0]*sntp[1]]; |
| 311 |
> |
maxtheta = 1.5f*s_theta(sntp[0]-1) - 0.5f*s_theta(sntp[0]-2); |
| 312 |
|
thdiv[0] = .0; |
| 313 |
|
for (t = 1; t < sntp[0]; t++) |
| 314 |
< |
thdiv[t] = DEGREE/2.*(sensor[t*(sntp[1]+1)] + |
| 307 |
< |
sensor[(t+1)*(sntp[1]+1)]); |
| 314 |
> |
thdiv[t] = DEGREE/2.*(s_theta(t-1) + s_theta(t)); |
| 315 |
|
thdiv[sntp[0]] = maxtheta*DEGREE; |
| 316 |
|
phdiv[0] = .0; |
| 317 |
|
for (p = 1; p < sntp[1]; p++) |
| 318 |
< |
phdiv[p] = DEGREE/2.*(sensor[p] + sensor[p+1]); |
| 318 |
> |
phdiv[p] = DEGREE/2.*(s_phi(p-1) + s_phi(p)); |
| 319 |
|
phdiv[sntp[1]] = 2.*PI; |
| 320 |
|
/* size our table */ |
| 321 |
|
tsize = 1. - cos(maxtheta*DEGREE); |
| 322 |
< |
psize = PI*tsize/maxtheta; |
| 322 |
> |
psize = PI*tsize/(maxtheta*DEGREE); |
| 323 |
|
if (sntp[0]*sntp[1] < samptot) /* don't overdo resolution */ |
| 324 |
|
samptot = sntp[0]*sntp[1]; |
| 325 |
< |
ntheta = (int)(sqrt(samptot*tsize/psize) + 0.5); |
| 325 |
> |
ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5); |
| 326 |
|
if (ntheta > MAXNT) |
| 327 |
|
ntheta = MAXNT; |
| 328 |
|
nphi = samptot/ntheta; |
| 331 |
|
error(SYSTEM, "out of memory in init_ptable()"); |
| 332 |
|
gscale = .0; /* compute our inverse table */ |
| 333 |
|
for (i = 0; i < sntp[0]; i++) { |
| 334 |
< |
rowp = sensor + (i+1)*(sntp[1]+1) + 1; |
| 334 |
> |
rowp = &s_val(i,0); |
| 335 |
|
rowsum[i] = 0.; |
| 336 |
|
for (j = 0; j < sntp[1]; j++) |
| 337 |
|
rowsum[i] += *rowp++; |
| 339 |
|
rowomega[i] *= 2.*PI / (double)sntp[1]; |
| 340 |
|
gscale += rowsum[i] * rowomega[i]; |
| 341 |
|
} |
| 342 |
< |
tvals[0] = .0f; |
| 336 |
< |
for (i = 1; i < ntheta; i++) { |
| 342 |
> |
for (i = 0; i < ntheta; i++) { |
| 343 |
|
prob = (double)i / (double)ntheta; |
| 344 |
|
for (t = 0; t < sntp[0]; t++) |
| 345 |
|
if ((prob -= rowsum[t]*rowomega[t]/gscale) <= .0) |
| 349 |
|
frac = 1. + prob/(rowsum[t]*rowomega[t]/gscale); |
| 350 |
|
tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + |
| 351 |
|
frac*cos(thdiv[t+1]) ); |
| 352 |
+ |
/* offset b/c sensor values are centered */ |
| 353 |
+ |
if (t <= 0 || frac > 0.5) |
| 354 |
+ |
frac -= 0.5; |
| 355 |
+ |
else if (t >= sntp[0]-1 || frac < 0.5) { |
| 356 |
+ |
frac += 0.5; |
| 357 |
+ |
--t; |
| 358 |
+ |
} |
| 359 |
|
pvals[i*(nphi+1)] = .0f; |
| 360 |
|
for (j = 1; j < nphi; j++) { |
| 361 |
|
prob = (double)j / (double)nphi; |
| 362 |
< |
rowp = sensor + t*(sntp[1]+1) + 1; |
| 363 |
< |
rowp1 = rowp + sntp[1]+1; |
| 362 |
> |
rowp = &s_val(t,0); |
| 363 |
> |
rowp1 = &s_val(t+1,0); |
| 364 |
|
for (p = 0; p < sntp[1]; p++) { |
| 365 |
< |
if ((prob -= (1.-frac)*rowp[p]/rowsum[t-1] + |
| 366 |
< |
frac*rowp1[p]/rowsum[t]) <= .0) |
| 365 |
> |
if ((prob -= (1.-frac)*rowp[p]/rowsum[t] + |
| 366 |
> |
frac*rowp1[p]/rowsum[t+1]) <= .0) |
| 367 |
|
break; |
| 368 |
|
if (p >= sntp[1]) |
| 369 |
|
error(INTERNAL, |
| 370 |
|
"code error 2 in init_ptable()"); |
| 371 |
< |
frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t-1] |
| 372 |
< |
+ frac*rowp1[p]/rowsum[t]); |
| 371 |
> |
frac1 = 1. + prob/((1.-frac)*rowp[p]/rowsum[t] |
| 372 |
> |
+ frac*rowp1[p]/rowsum[t+1]); |
| 373 |
> |
if (p <= 0 || frac1 > 0.5) |
| 374 |
> |
frac1 -= 0.5; |
| 375 |
> |
else if (p >= sntp[1]-1 || frac1 < 0.5) { |
| 376 |
> |
frac1 += 0.5; |
| 377 |
> |
--p; |
| 378 |
> |
} |
| 379 |
|
pvals[i*(nphi+1) + j] = (1.-frac1)*phdiv[p] + |
| 380 |
|
frac1*phdiv[p+1]; |
| 381 |
|
} |
| 382 |
|
} |
| 383 |
|
pvals[i*(nphi+1) + nphi] = (float)(2.*PI); |
| 384 |
|
} |
| 385 |
+ |
tvals[0] = .0f; |
| 386 |
|
tvals[ntheta] = (float)tsize; |
| 387 |
|
} |
| 388 |
|
|
| 438 |
|
t = (int)(theta/maxtheta * sntp[0]); |
| 439 |
|
p = (int)(phi*(1./360.) * sntp[1]); |
| 440 |
|
/* hack for non-uniform sensor grid */ |
| 441 |
< |
while (t+1 < sntp[0] && theta >= sensor[(t+2)*(sntp[1]+1)]) |
| 441 |
> |
while (t+1 < sntp[0] && theta >= s_theta(t+1)) |
| 442 |
|
++t; |
| 443 |
< |
while (t-1 >= 0 && theta < sensor[t*(sntp[1]+1)]) |
| 443 |
> |
while (t-1 >= 0 && theta <= s_theta(t-1)) |
| 444 |
|
--t; |
| 445 |
< |
while (p+1 < sntp[1] && phi >= sensor[p+2]) |
| 445 |
> |
while (p+1 < sntp[1] && phi >= s_phi(p+1)) |
| 446 |
|
++p; |
| 447 |
< |
while (p-1 >= 0 && phi < sensor[p]) |
| 447 |
> |
while (p-1 >= 0 && phi <= s_phi(p-1)) |
| 448 |
|
--p; |
| 449 |
< |
return(sensor[t*(sntp[1]+1) + p + 1]); |
| 449 |
> |
return(s_val(t,p)); |
| 450 |
|
} |
| 451 |
|
|
| 452 |
|
/* Compute sensor output */ |
| 478 |
|
VCOPY(rr.rorg, ourview.vp); |
| 479 |
|
rr.rmax = .0; |
| 480 |
|
for (i = 0; i < nt; i++) |
| 481 |
< |
for (j =0; j < np; j++) { |
| 482 |
< |
get_direc(rr.rdir, (i+frandom())/nt, |
| 463 |
< |
(j + frandom())/np); |
| 481 |
> |
for (j = 0; j < np; j++) { |
| 482 |
> |
get_direc(rr.rdir, (i+frandom())/nt, (j+frandom())/np); |
| 483 |
|
rayorigin(&rr, PRIMARY, NULL, NULL); |
| 484 |
|
if (ray_pqueue(&rr) == 1) |
| 485 |
|
addcolor(vsum, rr.rcol); |