--- ray/src/cv/bsdfinterp.c 2013/06/29 21:03:25 2.11 +++ ray/src/cv/bsdfinterp.c 2013/09/26 17:15:22 2.13 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdfinterp.c,v 2.11 2013/06/29 21:03:25 greg Exp $"; +static const char RCSid[] = "$Id: bsdfinterp.c,v 2.13 2013/09/26 17:15:22 greg Exp $"; #endif /* * Interpolate BSDF data from radial basis functions in advection mesh. @@ -260,8 +260,9 @@ get_interp(MIGRATION *miga[3], FVECT invec) /* Advect and allocate new RBF along edge */ static RBFNODE * -e_advect_rbf(const MIGRATION *mig, const FVECT invec) +e_advect_rbf(const MIGRATION *mig, const FVECT invec, int lobe_lim) { + double cthresh = FTINY; RBFNODE *rbf; int n, i, j; double t, full_dist; @@ -286,11 +287,17 @@ e_advect_rbf(const MIGRATION *mig, const FVECT invec) rbf->next = NULL; rbf->ejl = NULL; return(rbf); } - t /= full_dist; + t /= full_dist; +tryagain: n = 0; /* count migrating particles */ for (i = 0; i < mtx_nrows(mig); i++) for (j = 0; j < mtx_ncols(mig); j++) - n += (mtx_coef(mig,i,j) > FTINY); + n += (mtx_coef(mig,i,j) > cthresh); + /* are we over our limit? */ + if ((lobe_lim > 0) & (n > lobe_lim)) { + cthresh = cthresh*2. + 10.*FTINY; + goto tryagain; + } #ifdef DEBUG fprintf(stderr, "Input RBFs have %d, %d nodes -> output has %d\n", mig->rbfv[0]->nrbf, mig->rbfv[1]->nrbf, n); @@ -311,7 +318,7 @@ e_advect_rbf(const MIGRATION *mig, const FVECT invec) float mv; ovec_from_pos(v0, rbf0i->gx, rbf0i->gy); for (j = 0; j < mtx_ncols(mig); j++) - if ((mv = mtx_coef(mig,i,j)) > FTINY) { + if ((mv = mtx_coef(mig,i,j)) > cthresh) { const RBFVAL *rbf1j = &mig->rbfv[1]->rbfa[j]; double rad1 = R2ANG(rbf1j->crad); FVECT v; @@ -337,8 +344,9 @@ memerr: /* Partially advect between recorded incident angles and allocate new RBF */ RBFNODE * -advect_rbf(const FVECT invec) +advect_rbf(const FVECT invec, int lobe_lim) { + double cthresh = FTINY; FVECT sivec; MIGRATION *miga[3]; RBFNODE *rbf; @@ -353,7 +361,7 @@ advect_rbf(const FVECT invec) if (sym < 0) /* can't interpolate? */ return(NULL); if (miga[1] == NULL) { /* advect along edge? */ - rbf = e_advect_rbf(miga[0], sivec); + rbf = e_advect_rbf(miga[0], sivec, lobe_lim); if (single_plane_incident) rotate_rbf(rbf, invec); else @@ -379,13 +387,19 @@ advect_rbf(const FVECT invec) geodesic(v1, miga[0]->rbfv[0]->invec, miga[0]->rbfv[1]->invec, s, GEOD_REL); t = acos(DOT(v1,sivec)) / acos(DOT(v1,miga[1]->rbfv[1]->invec)); +tryagain: n = 0; /* count migrating particles */ for (i = 0; i < mtx_nrows(miga[0]); i++) for (j = 0; j < mtx_ncols(miga[0]); j++) - for (k = (mtx_coef(miga[0],i,j) > FTINY) * + for (k = (mtx_coef(miga[0],i,j) > cthresh) * mtx_ncols(miga[2]); k--; ) - n += (mtx_coef(miga[2],i,k) > FTINY || - mtx_coef(miga[1],j,k) > FTINY); + n += (mtx_coef(miga[2],i,k) > cthresh || + mtx_coef(miga[1],j,k) > cthresh); + /* are we over our limit? */ + if ((lobe_lim > 0) & (n > lobe_lim)) { + cthresh = cthresh*2. + 10.*FTINY; + goto tryagain; + } #ifdef DEBUG fprintf(stderr, "Input RBFs have %d, %d, %d nodes -> output has %d\n", miga[0]->rbfv[0]->nrbf, miga[0]->rbfv[1]->nrbf, @@ -413,7 +427,7 @@ advect_rbf(const FVECT invec) const float ma = mtx_coef(miga[0],i,j); const RBFVAL *rbf1j; double rad1j, srad2; - if (ma <= FTINY) + if (ma <= cthresh) continue; rbf1j = &miga[0]->rbfv[1]->rbfa[j]; rad1j = R2ANG(rbf1j->crad); @@ -426,7 +440,7 @@ advect_rbf(const FVECT invec) const RBFVAL *rbf2k; double rad2k; int pos[2]; - if ((mb <= FTINY) & (mc <= FTINY)) + if ((mb <= cthresh) & (mc <= cthresh)) continue; rbf2k = &miga[2]->rbfv[1]->rbfa[k]; rbf->rbfa[n].peak = w0i * ma * (mb*mbfact + mc*mcfact);