--- ray/src/cv/bsdfmesh.c 2012/11/09 02:16:29 2.6 +++ ray/src/cv/bsdfmesh.c 2013/03/20 01:00:22 2.8 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdfmesh.c,v 2.6 2012/11/09 02:16:29 greg Exp $"; +static const char RCSid[] = "$Id: bsdfmesh.c,v 2.8 2013/03/20 01:00:22 greg Exp $"; #endif /* * Create BSDF advection mesh from radial basis functions. @@ -173,7 +173,8 @@ price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, co FVECT vfrom; ovec_from_pos(vfrom, from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy); for (j = to_rbf->nrbf; j--; ) { - pricerow(pm,i)[j] = acos(DOT(vfrom, vto[j])) + + double dprod = DOT(vfrom, vto[j]); + pricerow(pm,i)[j] = ((dprod >= 1.) ? .0 : acos(dprod)) + fabs(R2ANG(to_rbf->rbfa[j].crad) - from_ang); psortrow(pm,i)[j] = j; } @@ -288,6 +289,15 @@ create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) if (newmig->rbfv[1] == to_rbf) return(NULL); /* else allocate */ +#ifdef DEBUG + fprintf(stderr, "Building path from (theta,phi) (%.0f,%.0f) ", + get_theta180(from_rbf->invec), + get_phi360(from_rbf->invec)); + fprintf(stderr, "to (%.0f,%.0f) with %d x %d matrix\n", + get_theta180(to_rbf->invec), + get_phi360(to_rbf->invec), + from_rbf->nrbf, to_rbf->nrbf); +#endif newmig = new_migration(from_rbf, to_rbf); if (run_subprocess()) return(newmig); /* child continues */ @@ -299,15 +309,6 @@ create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) progname); exit(1); } -#ifdef DEBUG - fprintf(stderr, "Building path from (theta,phi) (%.0f,%.0f) ", - get_theta180(from_rbf->invec), - get_phi360(from_rbf->invec)); - fprintf(stderr, "to (%.0f,%.0f) with %d x %d matrix\n", - get_theta180(to_rbf->invec), - get_phi360(to_rbf->invec), - from_rbf->nrbf, to_rbf->nrbf); -#endif /* starting quantities */ memset(newmig->mtx, 0, sizeof(float)*from_rbf->nrbf*to_rbf->nrbf); for (i = from_rbf->nrbf; i--; ) @@ -437,6 +438,25 @@ mesh_from_edge(MIGRATION *edge) } } } + +/* Compute minimum BSDF from histogram and clear it */ +static void +comp_bsdf_min() +{ + int cnt; + int i, target; + + cnt = 0; + for (i = HISTLEN; i--; ) + cnt += bsdf_hist[i]; + + target = cnt/100; /* ignore bottom 1% */ + cnt = 0; + for (i = 0; cnt <= target; i++) + cnt += bsdf_hist[i]; + bsdf_min = histval(i-1); + memset(bsdf_hist, 0, sizeof(bsdf_hist)); +} /* Build our triangle mesh from recorded RBFs */ void @@ -472,6 +492,8 @@ build_mesh(void) mesh_from_edge(create_migration(shrt_edj[0], shrt_edj[1])); else mesh_from_edge(create_migration(shrt_edj[1], shrt_edj[0])); + /* compute minimum BSDF */ + comp_bsdf_min(); /* complete migrations */ await_children(nchild); }