--- ray/src/cv/bsdfmesh.c 2012/11/09 02:16:29 2.6 +++ ray/src/cv/bsdfmesh.c 2013/09/26 14:57:18 2.10 @@ -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.10 2013/09/26 14:57:18 greg Exp $"; #endif /* * Create BSDF advection mesh from radial basis functions. @@ -27,6 +27,7 @@ typedef struct { int nrows, ncols; /* array size (matches migration) */ float *price; /* migration prices */ short *sord; /* sort for each row, low to high */ + float *prow; /* current price row */ } PRICEMAT; /* sorted pricing matrix */ #define pricerow(p,i) ((p)->price + (i)*(p)->ncols) @@ -139,9 +140,8 @@ static int msrt_cmp(void *b, const void *p1, const void *p2) { PRICEMAT *pm = (PRICEMAT *)b; - int ri = ((const short *)p1 - pm->sord) / pm->ncols; - float c1 = pricerow(pm,ri)[*(const short *)p1]; - float c2 = pricerow(pm,ri)[*(const short *)p2]; + float c1 = pm->prow[*(const short *)p1]; + float c2 = pm->prow[*(const short *)p2]; if (c1 > c2) return(1); if (c1 < c2) return(-1); @@ -171,13 +171,17 @@ price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, co for (i = from_rbf->nrbf; i--; ) { const double from_ang = R2ANG(from_rbf->rbfa[i].crad); FVECT vfrom; + short *srow; ovec_from_pos(vfrom, from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy); + pm->prow = pricerow(pm,i); + srow = psortrow(pm,i); for (j = to_rbf->nrbf; j--; ) { - pricerow(pm,i)[j] = acos(DOT(vfrom, vto[j])) + + double dprod = DOT(vfrom, vto[j]); + pm->prow[j] = ((dprod >= 1.) ? .0 : acos(dprod)) + fabs(R2ANG(to_rbf->rbfa[j].crad) - from_ang); - psortrow(pm,i)[j] = j; + srow[j] = j; } - qsort_r(psortrow(pm,i), pm->ncols, sizeof(short), pm, &msrt_cmp); + qsort_r(srow, pm->ncols, sizeof(short), pm, &msrt_cmp); } free(vto); } @@ -288,6 +292,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 +312,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--; )