202 |
|
{ |
203 |
|
miga[0] = miga[1] = miga[2] = NULL; |
204 |
|
if (single_plane_incident) { /* isotropic BSDF? */ |
205 |
< |
RBFNODE *rbf; /* find edge we're on */ |
206 |
< |
for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) { |
207 |
< |
if (input_orient*rbf->invec[2] < input_orient*invec[2]) |
208 |
< |
break; |
209 |
< |
if (rbf->next != NULL && |
210 |
< |
input_orient*rbf->next->invec[2] < |
205 |
> |
RBFNODE *rbf; /* find edge we're on */ |
206 |
> |
for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) { |
207 |
> |
if (input_orient*rbf->invec[2] < input_orient*invec[2]) |
208 |
> |
break; |
209 |
> |
if (rbf->next != NULL && input_orient*rbf->next->invec[2] < |
210 |
|
input_orient*invec[2]) { |
211 |
< |
for (miga[0] = rbf->ejl; miga[0] != NULL; |
212 |
< |
miga[0] = nextedge(rbf,miga[0])) |
213 |
< |
if (opp_rbf(rbf,miga[0]) == rbf->next) { |
214 |
< |
double nf = 1.-rbf->invec[2]*rbf->invec[2]; |
215 |
< |
if (nf > FTINY) { |
216 |
< |
nf = sqrt((1.-invec[2]*invec[2])/nf); |
217 |
< |
invec[0] = nf*rbf->invec[0]; |
218 |
< |
invec[1] = nf*rbf->invec[1]; |
219 |
< |
} |
220 |
< |
return(0); |
222 |
< |
} |
223 |
< |
break; |
211 |
> |
for (miga[0] = rbf->ejl; miga[0] != NULL; |
212 |
> |
miga[0] = nextedge(rbf,miga[0])) |
213 |
> |
if (opp_rbf(rbf,miga[0]) == rbf->next) { |
214 |
> |
double nf = 1. - rbf->invec[2]*rbf->invec[2]; |
215 |
> |
if (nf > FTINY) { /* rotate to match */ |
216 |
> |
nf = sqrt((1.-invec[2]*invec[2])/nf); |
217 |
> |
invec[0] = nf*rbf->invec[0]; |
218 |
> |
invec[1] = nf*rbf->invec[1]; |
219 |
> |
} |
220 |
> |
return(0); |
221 |
|
} |
222 |
+ |
break; |
223 |
|
} |
224 |
< |
return(-1); /* outside range! */ |
224 |
> |
} |
225 |
> |
return(-1); /* outside range! */ |
226 |
|
} |
227 |
|
{ /* else use triangle mesh */ |
228 |
|
int sym = use_symmetry(invec); |
260 |
|
|
261 |
|
/* Advect and allocate new RBF along edge */ |
262 |
|
static RBFNODE * |
263 |
< |
e_advect_rbf(const MIGRATION *mig, const FVECT invec) |
263 |
> |
e_advect_rbf(const MIGRATION *mig, const FVECT invec, int lobe_lim) |
264 |
|
{ |
265 |
+ |
double cthresh = FTINY; |
266 |
|
RBFNODE *rbf; |
267 |
|
int n, i, j; |
268 |
|
double t, full_dist; |
269 |
|
/* get relative position */ |
270 |
< |
t = acos(DOT(invec, mig->rbfv[0]->invec)); |
270 |
> |
t = Acos(DOT(invec, mig->rbfv[0]->invec)); |
271 |
|
if (t < M_PI/grid_res) { /* near first DSF */ |
272 |
|
n = sizeof(RBFNODE) + sizeof(RBFVAL)*(mig->rbfv[0]->nrbf-1); |
273 |
|
rbf = (RBFNODE *)malloc(n); |
287 |
|
rbf->next = NULL; rbf->ejl = NULL; |
288 |
|
return(rbf); |
289 |
|
} |
290 |
< |
t /= full_dist; |
290 |
> |
t /= full_dist; |
291 |
> |
tryagain: |
292 |
|
n = 0; /* count migrating particles */ |
293 |
|
for (i = 0; i < mtx_nrows(mig); i++) |
294 |
|
for (j = 0; j < mtx_ncols(mig); j++) |
295 |
< |
n += (mtx_coef(mig,i,j) > FTINY); |
295 |
> |
n += (mtx_coef(mig,i,j) > cthresh); |
296 |
> |
/* are we over our limit? */ |
297 |
> |
if ((lobe_lim > 0) & (n > lobe_lim)) { |
298 |
> |
cthresh = cthresh*2. + 10.*FTINY; |
299 |
> |
goto tryagain; |
300 |
> |
} |
301 |
|
#ifdef DEBUG |
302 |
|
fprintf(stderr, "Input RBFs have %d, %d nodes -> output has %d\n", |
303 |
|
mig->rbfv[0]->nrbf, mig->rbfv[1]->nrbf, n); |
318 |
|
float mv; |
319 |
|
ovec_from_pos(v0, rbf0i->gx, rbf0i->gy); |
320 |
|
for (j = 0; j < mtx_ncols(mig); j++) |
321 |
< |
if ((mv = mtx_coef(mig,i,j)) > FTINY) { |
321 |
> |
if ((mv = mtx_coef(mig,i,j)) > cthresh) { |
322 |
|
const RBFVAL *rbf1j = &mig->rbfv[1]->rbfa[j]; |
323 |
|
double rad1 = R2ANG(rbf1j->crad); |
324 |
|
FVECT v; |
344 |
|
|
345 |
|
/* Partially advect between recorded incident angles and allocate new RBF */ |
346 |
|
RBFNODE * |
347 |
< |
advect_rbf(const FVECT invec) |
347 |
> |
advect_rbf(const FVECT invec, int lobe_lim) |
348 |
|
{ |
349 |
+ |
double cthresh = FTINY; |
350 |
|
FVECT sivec; |
351 |
|
MIGRATION *miga[3]; |
352 |
|
RBFNODE *rbf; |
361 |
|
if (sym < 0) /* can't interpolate? */ |
362 |
|
return(NULL); |
363 |
|
if (miga[1] == NULL) { /* advect along edge? */ |
364 |
< |
rbf = e_advect_rbf(miga[0], sivec); |
364 |
> |
rbf = e_advect_rbf(miga[0], sivec, lobe_lim); |
365 |
|
if (single_plane_incident) |
366 |
|
rotate_rbf(rbf, invec); |
367 |
|
else |
387 |
|
geodesic(v1, miga[0]->rbfv[0]->invec, miga[0]->rbfv[1]->invec, |
388 |
|
s, GEOD_REL); |
389 |
|
t = acos(DOT(v1,sivec)) / acos(DOT(v1,miga[1]->rbfv[1]->invec)); |
390 |
+ |
tryagain: |
391 |
|
n = 0; /* count migrating particles */ |
392 |
|
for (i = 0; i < mtx_nrows(miga[0]); i++) |
393 |
|
for (j = 0; j < mtx_ncols(miga[0]); j++) |
394 |
< |
for (k = (mtx_coef(miga[0],i,j) > FTINY) * |
394 |
> |
for (k = (mtx_coef(miga[0],i,j) > cthresh) * |
395 |
|
mtx_ncols(miga[2]); k--; ) |
396 |
< |
n += (mtx_coef(miga[2],i,k) > FTINY || |
397 |
< |
mtx_coef(miga[1],j,k) > FTINY); |
396 |
> |
n += (mtx_coef(miga[2],i,k) > cthresh || |
397 |
> |
mtx_coef(miga[1],j,k) > cthresh); |
398 |
> |
/* are we over our limit? */ |
399 |
> |
if ((lobe_lim > 0) & (n > lobe_lim)) { |
400 |
> |
cthresh = cthresh*2. + 10.*FTINY; |
401 |
> |
goto tryagain; |
402 |
> |
} |
403 |
|
#ifdef DEBUG |
404 |
|
fprintf(stderr, "Input RBFs have %d, %d, %d nodes -> output has %d\n", |
405 |
|
miga[0]->rbfv[0]->nrbf, miga[0]->rbfv[1]->nrbf, |
427 |
|
const float ma = mtx_coef(miga[0],i,j); |
428 |
|
const RBFVAL *rbf1j; |
429 |
|
double rad1j, srad2; |
430 |
< |
if (ma <= FTINY) |
430 |
> |
if (ma <= cthresh) |
431 |
|
continue; |
432 |
|
rbf1j = &miga[0]->rbfv[1]->rbfa[j]; |
433 |
|
rad1j = R2ANG(rbf1j->crad); |
440 |
|
const RBFVAL *rbf2k; |
441 |
|
double rad2k; |
442 |
|
int pos[2]; |
443 |
< |
if ((mb <= FTINY) & (mc <= FTINY)) |
443 |
> |
if ((mb <= cthresh) & (mc <= cthresh)) |
444 |
|
continue; |
445 |
|
rbf2k = &miga[2]->rbfv[1]->rbfa[k]; |
446 |
|
rbf->rbfa[n].peak = w0i * ma * (mb*mbfact + mc*mcfact); |