| 15 |
|
|
| 16 |
|
#define DEGREE (PI/180.) |
| 17 |
|
|
| 18 |
< |
#define MAXNT 180 /* maximum number of theta divisions */ |
| 18 |
> |
#define MAXNT 181 /* maximum number of theta divisions */ |
| 19 |
|
#define MAXNP 360 /* maximum number of phi divisions */ |
| 20 |
|
|
| 21 |
|
extern char *progname; /* global argv[0] */ |
| 207 |
|
char *sfile |
| 208 |
|
) |
| 209 |
|
{ |
| 210 |
+ |
int warnedneg; |
| 211 |
|
char linebuf[8192]; |
| 212 |
+ |
int last_pos_val = 0; |
| 213 |
|
int nelem = 1000; |
| 214 |
|
float *sarr = (float *)malloc(sizeof(float)*nelem); |
| 215 |
|
FILE *fp; |
| 245 |
|
} |
| 246 |
|
++ntp[1]; |
| 247 |
|
} |
| 248 |
+ |
warnedneg = 0; |
| 249 |
|
ntp[0] = 0; /* get thetas + data */ |
| 250 |
|
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) { |
| 251 |
|
++ntp[0]; |
| 263 |
|
cp = fskip(cp); |
| 264 |
|
if (cp == NULL) |
| 265 |
|
break; |
| 266 |
+ |
if (i && sarr[i] < .0) { |
| 267 |
+ |
if (!warnedneg++) { |
| 268 |
+ |
sprintf(errmsg, |
| 269 |
+ |
"Negative value(s) in sensor file '%s' (ignored)\n", sfile); |
| 270 |
+ |
error(WARNING, errmsg); |
| 271 |
+ |
} |
| 272 |
+ |
sarr[i] = .0; |
| 273 |
+ |
} else if (i > ntp[0]*(ntp[1]+1) && sarr[i] > FTINY) |
| 274 |
+ |
last_pos_val = i; |
| 275 |
|
++i; |
| 276 |
|
} |
| 277 |
|
if (i == ntp[0]*(ntp[1]+1)) |
| 290 |
|
error(USER, errmsg); |
| 291 |
|
} |
| 292 |
|
} |
| 293 |
< |
nelem = i; |
| 293 |
> |
/* truncate zero region */ |
| 294 |
> |
ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1; |
| 295 |
> |
nelem = (ntp[0]+1)*(ntp[1]+1); |
| 296 |
|
fclose(fp); |
| 297 |
|
errmsg[0] = '\0'; /* sanity checks */ |
| 298 |
+ |
if (!last_pos_val) |
| 299 |
+ |
sprintf(errmsg, "no positive sensor values in file '%s'", sfile); |
| 300 |
|
if (ntp[0] <= 0) |
| 301 |
|
sprintf(errmsg, "no data in sensor file '%s'", sfile); |
| 302 |
|
else if (fabs(sarr[ntp[1]+1]) > FTINY) |
| 311 |
|
sfile); |
| 312 |
|
else if (sarr[ntp[0]*(ntp[1]+1)] <= FTINY) |
| 313 |
|
sprintf(errmsg, |
| 314 |
< |
"maximum theta must be positive in sensor file '%s'", |
| 315 |
< |
sfile); |
| 314 |
> |
"maximum theta (%f) must be positive in sensor file '%s'", |
| 315 |
> |
sarr[ntp[0]*(ntp[1]+1)], sfile); |
| 316 |
|
if (errmsg[0]) |
| 317 |
|
error(USER, errmsg); |
| 318 |
|
return((float *)realloc((void *)sarr, sizeof(float)*nelem)); |
| 404 |
|
tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + |
| 405 |
|
frac*cos(thdiv[t+1]) ); |
| 406 |
|
/* offset b/c sensor values are centered */ |
| 407 |
< |
if (t <= 0 || frac > 0.5) |
| 407 |
> |
if ((t < sntp[0]-1) & (!t | (frac >= 0.5))) { |
| 408 |
|
frac -= 0.5; |
| 409 |
< |
else if (t >= sntp[0]-1 || frac < 0.5) { |
| 409 |
> |
} else { |
| 410 |
|
frac += 0.5; |
| 411 |
|
--t; |
| 412 |
|
} |
| 419 |
|
if ((prob -= (1.-frac)*rowp[p]/rowsum[t] + |
| 420 |
|
frac*rowp1[p]/rowsum[t+1]) <= .0) |
| 421 |
|
break; |
| 422 |
< |
if (p >= sntp[1]) { |
| 422 |
> |
if (p >= sntp[1]) { /* should never happen? */ |
| 423 |
|
p = sntp[1] - 1; |
| 424 |
|
prob = .5; |
| 425 |
|
} |
| 430 |
|
} |
| 431 |
|
pvals[i*(nphi+1) + nphi] = phdiv[sntp[1]]; |
| 432 |
|
} |
| 433 |
+ |
/* duplicate final row */ |
| 434 |
+ |
memcpy(pvals+ntheta*(nphi+1), pvals+(ntheta-1)*(nphi+1), |
| 435 |
+ |
sizeof(*pvals)*(nphi+1)); |
| 436 |
|
tvals[0] = .0f; |
| 437 |
|
tvals[ntheta] = (float)tsize; |
| 438 |
|
} |
| 479 |
|
int t, p; |
| 480 |
|
|
| 481 |
|
dv[2] = DOT(dvec, ourview.vdir); |
| 482 |
< |
theta = (float)((1./DEGREE) * acos(dv[2])); |
| 482 |
> |
theta = acos(dv[2]); |
| 483 |
|
if (theta >= maxtheta) |
| 484 |
|
return(.0f); |
| 485 |
|
dv[0] = DOT(dvec, ourview.hvec); |
| 486 |
|
dv[1] = DOT(dvec, ourview.vvec); |
| 487 |
< |
phi = (float)((1./DEGREE) * atan2(-dv[0], dv[1])); |
| 488 |
< |
while (phi < .0f) phi += 360.f; |
| 487 |
> |
phi = atan2(-dv[0], dv[1]); |
| 488 |
> |
while (phi < .0f) phi += (float)(2.*PI); |
| 489 |
|
t = (int)(theta/maxtheta * sntp[0]); |
| 490 |
< |
p = (int)(phi*(1./360.) * sntp[1]); |
| 490 |
> |
p = (int)(phi*(1./(2.*PI)) * sntp[1]); |
| 491 |
|
/* hack for non-uniform sensor grid */ |
| 492 |
+ |
theta *= (float)(1./DEGREE); |
| 493 |
+ |
phi *= (float)(1./DEGREE); |
| 494 |
|
while (t+1 < sntp[0] && theta >= s_theta(t+1)) |
| 495 |
|
++t; |
| 496 |
|
while (t-1 >= 0 && theta <= s_theta(t-1)) |
| 553 |
|
continue; |
| 554 |
|
} |
| 555 |
|
rr.rmax = .0; |
| 556 |
< |
rayorigin(&rr, PRIMARY, NULL, NULL); |
| 556 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
| 557 |
|
scalecolor(rr.rcoef, sf); |
| 558 |
|
if (ray_pqueue(&rr) == 1) |
| 559 |
|
addcolor(vsum, rr.rcol); |
| 569 |
|
continue; |
| 570 |
|
} |
| 571 |
|
rr.rmax = .0; |
| 572 |
< |
rayorigin(&rr, PRIMARY, NULL, NULL); |
| 572 |
> |
rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); |
| 573 |
|
scalecolor(rr.rcoef, sf); |
| 574 |
|
if (ray_pqueue(&rr) == 1) |
| 575 |
|
addcolor(vsum, rr.rcol); |