7 |
|
* G. Ward |
8 |
|
*/ |
9 |
|
|
10 |
+ |
/**************************************************************** |
11 |
+ |
1) Collect samples into a grid using the Shirley-Chiu |
12 |
+ |
angular mapping from a hemisphere to a square. |
13 |
+ |
|
14 |
+ |
2) Compute an adaptive quadtree by subdividing the grid so that |
15 |
+ |
each leaf node has at least one sample up to as many |
16 |
+ |
samples as fit nicely on a plane to within a certain |
17 |
+ |
MSE tolerance. |
18 |
+ |
|
19 |
+ |
3) Place one Gaussian lobe at each leaf node in the quadtree, |
20 |
+ |
sizing it to have a radius equal to the leaf size and |
21 |
+ |
a volume equal to the energy in that node. |
22 |
+ |
*****************************************************************/ |
23 |
+ |
|
24 |
|
#define _USE_MATH_DEFINES |
25 |
|
#include <stdio.h> |
26 |
|
#include <stdlib.h> |
136 |
|
for (y = y0; y < y1; y++) |
137 |
|
if ((n = dsf_grid[x][y].nval) > 0) { |
138 |
|
double z = dsf_grid[x][y].vsum; |
139 |
< |
rMtx[0][0] += n*x*x; |
140 |
< |
rMtx[0][1] += n*x*y; |
141 |
< |
rMtx[0][2] += n*x; |
142 |
< |
rMtx[1][1] += n*y*y; |
143 |
< |
rMtx[1][2] += n*y; |
144 |
< |
rMtx[2][2] += n; |
139 |
> |
rMtx[0][0] += x*x*(double)n; |
140 |
> |
rMtx[0][1] += x*y*(double)n; |
141 |
> |
rMtx[0][2] += x*(double)n; |
142 |
> |
rMtx[1][1] += y*y*(double)n; |
143 |
> |
rMtx[1][2] += y*(double)n; |
144 |
> |
rMtx[2][2] += (double)n; |
145 |
|
xvec[0] += x*z; |
146 |
|
xvec[1] += y*z; |
147 |
|
xvec[2] += z; |
163 |
|
} |
164 |
|
if (sqerr <= nvs*SMOOTH_MSE) /* below absolute MSE threshold? */ |
165 |
|
return(1); |
166 |
< |
/* below relative MSE threshold? */ |
166 |
> |
/* OR below relative MSE threshold? */ |
167 |
|
return(sqerr*nvs <= xvec[2]*xvec[2]*SMOOTH_MSER); |
168 |
|
} |
169 |
|
|