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; |
148 |
|
} |
149 |
|
rMtx[1][0] = rMtx[0][1]; |
150 |
+ |
rMtx[2][0] = rMtx[0][2]; |
151 |
|
rMtx[2][1] = rMtx[1][2]; |
152 |
|
nvs = rMtx[2][2]; |
153 |
|
if (SDinvXform(rMtx, rMtx) != SDEnone) |
154 |
< |
return(0); |
154 |
> |
return(1); /* colinear values */ |
155 |
|
A = DOT(rMtx[0], xvec); |
156 |
|
B = DOT(rMtx[1], xvec); |
157 |
|
C = DOT(rMtx[2], xvec); |
164 |
|
} |
165 |
|
if (sqerr <= nvs*SMOOTH_MSE) /* below absolute MSE threshold? */ |
166 |
|
return(1); |
167 |
< |
/* below relative MSE threshold? */ |
167 |
> |
/* OR below relative MSE threshold? */ |
168 |
|
return(sqerr*nvs <= xvec[2]*xvec[2]*SMOOTH_MSER); |
169 |
|
} |
170 |
|
|
224 |
|
if (!nleaves) /* nothing but branches? */ |
225 |
|
return(nadded); |
226 |
|
/* combine 4 leaves into 1? */ |
227 |
< |
if (nleaves == 4 && x1-x0 < MAX_RAD && smooth_region(x0, x1, y0, y1)) |
227 |
> |
if ((nleaves == 4) & (x1-x0 <= MAX_RAD) && |
228 |
> |
smooth_region(x0, x1, y0, y1)) |
229 |
|
return(0); |
230 |
|
/* need more array space? */ |
231 |
|
if ((*np+nleaves-1)>>RBFALLOCB != (*np-1)>>RBFALLOCB) { |