| 29 |
|
#include "bsdfrep.h" |
| 30 |
|
|
| 31 |
|
#ifndef RSCA |
| 32 |
< |
#define RSCA 2.2 /* radius scaling factor (empirical) */ |
| 32 |
> |
#define RSCA 2.0 /* radius scaling factor (empirical) */ |
| 33 |
|
#endif |
| 34 |
|
#ifndef SMOOTH_MSE |
| 35 |
|
#define SMOOTH_MSE 5e-5 /* acceptable mean squared error */ |
| 41 |
|
|
| 42 |
|
#define RBFALLOCB 10 /* RBF allocation block size */ |
| 43 |
|
|
| 44 |
< |
/* our loaded grid or comparison DSFs */ |
| 44 |
> |
/* loaded grid or comparison DSFs */ |
| 45 |
|
GRIDVAL dsf_grid[GRIDRES][GRIDRES]; |
| 46 |
|
|
| 47 |
|
/* Start new DSF input grid */ |
| 172 |
|
{ |
| 173 |
|
double vtot = 0.0; |
| 174 |
|
int nv = 0; |
| 175 |
+ |
double wxsum = 0.0, wysum = 0.0, wtsum = 0.0; |
| 176 |
|
double rad; |
| 177 |
|
int x, y; |
| 178 |
|
/* compute average for region */ |
| 179 |
|
for (x = x0; x < x1; x++) |
| 180 |
< |
for (y = y0; y < y1; y++) { |
| 181 |
< |
vtot += dsf_grid[x][y].sum.v; |
| 182 |
< |
nv += dsf_grid[x][y].sum.n; |
| 183 |
< |
} |
| 180 |
> |
for (y = y0; y < y1; y++) |
| 181 |
> |
if (dsf_grid[x][y].sum.n) { |
| 182 |
> |
const double v = dsf_grid[x][y].sum.v; |
| 183 |
> |
const int n = dsf_grid[x][y].sum.n; |
| 184 |
> |
|
| 185 |
> |
if (v > 0) { |
| 186 |
> |
double wt = v / (double)n; |
| 187 |
> |
wxsum += wt * x; |
| 188 |
> |
wysum += wt * y; |
| 189 |
> |
wtsum += wt; |
| 190 |
> |
} |
| 191 |
> |
vtot += v; |
| 192 |
> |
nv += n; |
| 193 |
> |
} |
| 194 |
|
if (!nv) { |
| 195 |
|
fprintf(stderr, "%s: internal - missing samples in create_lobe\n", |
| 196 |
|
progname); |
| 202 |
|
vtot *= (x1-x0)*(y1-y0)*(2.*M_PI/GRIDRES/GRIDRES)/(double)nv; |
| 203 |
|
rad = (RSCA/(double)GRIDRES)*(x1-x0); |
| 204 |
|
rvp->peak = vtot / ((2.*M_PI) * rad*rad); |
| 205 |
< |
rvp->crad = ANG2R(rad); |
| 206 |
< |
rvp->gx = (x0+x1)>>1; |
| 207 |
< |
rvp->gy = (y0+y1)>>1; |
| 205 |
> |
rvp->crad = ANG2R(rad); /* put peak at centroid */ |
| 206 |
> |
rvp->gx = (int)(wxsum/wtsum + .5); |
| 207 |
> |
rvp->gy = (int)(wysum/wtsum + .5); |
| 208 |
|
return(1); |
| 209 |
|
} |
| 210 |
|
|