--- ray/src/cv/bsdfmesh.c 2014/03/09 01:51:48 2.21 +++ ray/src/cv/bsdfmesh.c 2014/03/26 00:11:30 2.26 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdfmesh.c,v 2.21 2014/03/09 01:51:48 greg Exp $"; +static const char RCSid[] = "$Id: bsdfmesh.c,v 2.26 2014/03/26 00:11:30 greg Exp $"; #endif /* * Create BSDF advection mesh from radial basis functions. @@ -165,9 +165,6 @@ neighborhood_dist2(int x0, int y0, int x1, int y1) double d; int p[4]; int i, j; - - if ((x0 == x1) & (y0 == y1)) - return(0.); /* check radius */ p[0] = x0; p[1] = y0; p[2] = x1; p[3] = y1; for (i = 4; i--; ) { @@ -386,6 +383,42 @@ memerr: #undef discount } +#ifdef DUMP_MATRIX +/* Dump transport plan and corresponding price matrix to a text file */ +static void +dump_matrix(const MIGRATION *me, const PRICEMAT *pm) +{ + char fname[256]; + FILE *fp; + int i, j; + + sprintf(fname, "edge_%d-%d.txt", me->rbfv[0]->ord, me->rbfv[1]->ord); + if ((fp = fopen(fname, "w")) == NULL) + return; + for (j = 0; j < 2; j++) { + fprintf(fp, "Available from %d source RBF lobes in node %d:\n", + me->rbfv[j]->nrbf, me->rbfv[j]->ord); + for (i = 0; i < me->rbfv[j]->nrbf; i++) + fprintf(fp, " %.4e", rbf_volume(&me->rbfv[j]->rbfa[i]) / + me->rbfv[j]->vtotal); + fputc('\n', fp); + } + fprintf(fp, "Price (quadratic distance metric) matrix:\n"); + for (i = 0; i < pm->nrows; i++) { + for (j = 0; j < pm->ncols; j++) + fprintf(fp, " %.4e", pricerow(pm,i)[j]); + fputc('\n', fp); + } + fprintf(fp, "Solution matrix (transport plan):\n"); + for (i = 0; i < mtx_nrows(me); i++) { + for (j = 0; j < mtx_ncols(me); j++) + fprintf(fp, " %.4e", mtx_coef(me,i,j)); + fputc('\n', fp); + } + fclose(fp); +} +#endif + /* Compute and insert migration along directed edge (may fork child) */ static MIGRATION * create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) @@ -441,6 +474,9 @@ create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) for (j = to_rbf->nrbf; j--; ) mtx_coef(newmig,i,j) *= nf; /* row now sums to 1.0 */ } +#ifdef DUMP_MATRIX + dump_matrix(newmig, &pmtx); +#endif end_subprocess(); /* exit here if subprocess */ free_routes(&pmtx); /* free working arrays */ free(src_rem); @@ -556,7 +592,7 @@ mesh_from_edge(MIGRATION *edge) static void check_normal_incidence(void) { - static const FVECT norm_vec = {.0, .0, 1.}; + static FVECT norm_vec = {.0, .0, 1.}; const int saved_nprocs = nprocs; RBFNODE *near_rbf, *mir_rbf, *rbf; double bestd; @@ -606,11 +642,12 @@ check_normal_incidence(void) memcpy(mir_rbf, near_rbf, n); mir_rbf->ord = near_rbf->ord - 1; /* not used, I think */ mir_rbf->next = NULL; + mir_rbf->ejl = NULL; rev_rbf_symmetry(mir_rbf, MIRROR_X|MIRROR_Y); nprocs = 1; /* compute migration matrix */ - if (mig_list != create_migration(mir_rbf, near_rbf)) + if (create_migration(mir_rbf, near_rbf) == NULL) exit(1); /* XXX should never happen! */ - /* interpolate normal dist. */ + norm_vec[2] = input_orient; /* interpolate normal dist. */ rbf = e_advect_rbf(mig_list, norm_vec, 2*near_rbf->nrbf); nprocs = saved_nprocs; /* final clean-up */ free(mir_rbf);