--- ray/src/util/rsensor.c 2011/05/17 19:34:36 2.9 +++ ray/src/util/rsensor.c 2015/04/23 23:34:18 2.15 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rsensor.c,v 2.9 2011/05/17 19:34:36 greg Exp $"; +static const char RCSid[] = "$Id: rsensor.c,v 2.15 2015/04/23 23:34:18 greg Exp $"; #endif /* @@ -15,7 +15,7 @@ static const char RCSid[] = "$Id: rsensor.c,v 2.9 2011 #define DEGREE (PI/180.) -#define MAXNT 180 /* maximum number of theta divisions */ +#define MAXNT 181 /* maximum number of theta divisions */ #define MAXNP 360 /* maximum number of phi divisions */ extern char *progname; /* global argv[0] */ @@ -207,6 +207,7 @@ load_sensor( char *sfile ) { + int warnedneg; char linebuf[8192]; int nelem = 1000; float *sarr = (float *)malloc(sizeof(float)*nelem); @@ -243,6 +244,7 @@ load_sensor( } ++ntp[1]; } + warnedneg = 0; ntp[0] = 0; /* get thetas + data */ while (fgets(linebuf, sizeof(linebuf), fp) != NULL) { ++ntp[0]; @@ -260,6 +262,14 @@ load_sensor( cp = fskip(cp); if (cp == NULL) break; + if (i && sarr[i] < .0) { + if (!warnedneg++) { + sprintf(errmsg, + "Negative value(s) in sensor file '%s' (ignored)\n", sfile); + error(WARNING, errmsg); + } + sarr[i] = .0; + } ++i; } if (i == ntp[0]*(ntp[1]+1)) @@ -388,9 +398,9 @@ init_ptable( tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + frac*cos(thdiv[t+1]) ); /* offset b/c sensor values are centered */ - if (t <= 0 || frac > 0.5) + if ((t < sntp[0]-1) & (!t | (frac >= 0.5))) { frac -= 0.5; - else if (t >= sntp[0]-1 || frac < 0.5) { + } else { frac += 0.5; --t; } @@ -403,7 +413,7 @@ init_ptable( if ((prob -= (1.-frac)*rowp[p]/rowsum[t] + frac*rowp1[p]/rowsum[t+1]) <= .0) break; - if (p >= sntp[1]) { + if (p >= sntp[1]) { /* should never happen? */ p = sntp[1] - 1; prob = .5; } @@ -414,6 +424,9 @@ init_ptable( } pvals[i*(nphi+1) + nphi] = phdiv[sntp[1]]; } + /* duplicate final row */ + memcpy(pvals+ntheta*(nphi+1), pvals+(ntheta-1)*(nphi+1), + sizeof(*pvals)*(nphi+1)); tvals[0] = .0f; tvals[ntheta] = (float)tsize; } @@ -460,16 +473,18 @@ sens_val( int t, p; dv[2] = DOT(dvec, ourview.vdir); - theta = (float)((1./DEGREE) * acos(dv[2])); + theta = acos(dv[2]); if (theta >= maxtheta) return(.0f); dv[0] = DOT(dvec, ourview.hvec); dv[1] = DOT(dvec, ourview.vvec); - phi = (float)((1./DEGREE) * atan2(-dv[0], dv[1])); - while (phi < .0f) phi += 360.f; + phi = atan2(-dv[0], dv[1]); + while (phi < .0f) phi += (float)(2.*PI); t = (int)(theta/maxtheta * sntp[0]); - p = (int)(phi*(1./360.) * sntp[1]); + p = (int)(phi*(1./(2.*PI)) * sntp[1]); /* hack for non-uniform sensor grid */ + theta *= (float)(1./DEGREE); + phi *= (float)(1./DEGREE); while (t+1 < sntp[0] && theta >= s_theta(t+1)) ++t; while (t-1 >= 0 && theta <= s_theta(t-1)) @@ -532,7 +547,7 @@ comp_sensor( continue; } rr.rmax = .0; - rayorigin(&rr, PRIMARY, NULL, NULL); + rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); scalecolor(rr.rcoef, sf); if (ray_pqueue(&rr) == 1) addcolor(vsum, rr.rcol); @@ -548,7 +563,7 @@ comp_sensor( continue; } rr.rmax = .0; - rayorigin(&rr, PRIMARY, NULL, NULL); + rayorigin(&rr, PRIMARY|SPECULAR, NULL, NULL); scalecolor(rr.rcoef, sf); if (ray_pqueue(&rr) == 1) addcolor(vsum, rr.rcol);