ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdfmesh.c
(Generate patch)

Comparing ray/src/cv/bsdfmesh.c (file contents):
Revision 2.18 by greg, Thu Mar 6 00:40:37 2014 UTC vs.
Revision 2.24 by greg, Sat Mar 15 18:11:37 2014 UTC

# Line 18 | Line 18 | static const char RCSid[] = "$Id$";
18   #include <string.h>
19   #include <math.h>
20   #include "bsdfrep.h"
21 +
22 + #ifndef NEIGH_FACT2
23 + #define NEIGH_FACT2     0.1     /* empirical neighborhood distance weight */
24 + #endif
25                                  /* number of processes to run */
26   int                     nprocs = 1;
27                                  /* number of children (-1 in child) */
# Line 135 | Line 139 | run_subprocess(void)
139  
140   #endif  /* ! _WIN32 */
141  
142 + /* Compute normalized distribution scattering functions for comparison */
143 + static void
144 + compute_nDSFs(const RBFNODE *rbf0, const RBFNODE *rbf1)
145 + {
146 +        const double    nf0 = (GRIDRES*GRIDRES) / rbf0->vtotal;
147 +        const double    nf1 = (GRIDRES*GRIDRES) / rbf1->vtotal;
148 +        int             x, y;
149 +        FVECT           dv;
150 +
151 +        for (x = GRIDRES; x--; )
152 +            for (y = GRIDRES; y--; ) {
153 +                ovec_from_pos(dv, x, y);        /* cube root (brightness) */
154 +                dsf_grid[x][y].val[0] = pow(nf0*eval_rbfrep(rbf0, dv), .3333);
155 +                dsf_grid[x][y].val[1] = pow(nf1*eval_rbfrep(rbf1, dv), .3333);
156 +            }
157 + }      
158 +
159 + /* Compute neighborhood distance-squared (dissimilarity) */
160 + static double
161 + neighborhood_dist2(int x0, int y0, int x1, int y1)
162 + {
163 +        int     rad = GRIDRES>>5;
164 +        double  sum2 = 0.;
165 +        double  d;
166 +        int     p[4];
167 +        int     i, j;
168 +                                                /* check radius */
169 +        p[0] = x0; p[1] = y0; p[2] = x1; p[3] = y1;
170 +        for (i = 4; i--; ) {
171 +                if (p[i] < rad) rad = p[i];
172 +                if (GRIDRES-1-p[i] < rad) rad = GRIDRES-1-p[i];
173 +        }
174 +        for (i = -rad; i <= rad; i++)
175 +            for (j = -rad; j <= rad; j++) {
176 +                d = dsf_grid[x0+i][y0+j].val[0] -
177 +                        dsf_grid[x1+i][y1+j].val[1];
178 +                sum2 += d*d;
179 +            }
180 +        return(sum2 / (4*rad*(rad+1) + 1));
181 + }
182 +
183   /* Comparison routine needed for sorting price row */
184   static int
185   msrt_cmp(void *b, const void *p1, const void *p2)
# Line 155 | Line 200 | price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, co
200          FVECT   *vto = (FVECT *)malloc(sizeof(FVECT) * to_rbf->nrbf);
201          int     i, j;
202  
203 +        compute_nDSFs(from_rbf, to_rbf);
204          pm->nrows = from_rbf->nrbf;
205          pm->ncols = to_rbf->nrbf;
206          pm->price = (float *)malloc(sizeof(float) * pm->nrows*pm->ncols);
# Line 176 | Line 222 | price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, co
222              pm->prow = pricerow(pm,i);
223              srow = psortrow(pm,i);
224              for (j = to_rbf->nrbf; j--; ) {
225 <                double          d;              /* quadratic cost function */
225 >                double  d;                      /* quadratic cost function */
226                  d = Acos(DOT(vfrom, vto[j]));
227                  pm->prow[j] = d*d;
228                  d = R2ANG(to_rbf->rbfa[j].crad) - from_ang;
229 <                pm->prow[j] += d*d;    
229 >                pm->prow[j] += d*d;
230 >                                                /* neighborhood difference */
231 >                pm->prow[j] += NEIGH_FACT2 * neighborhood_dist2(
232 >                                from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy,
233 >                                to_rbf->rbfa[j].gx, to_rbf->rbfa[j].gy );
234                  srow[j] = j;
235              }
236              qsort_r(srow, pm->ncols, sizeof(short), pm, &msrt_cmp);
# Line 509 | Line 559 | check_normal_incidence(void)
559          double                  bestd;
560          int                     n;
561  
562 +
563          if (dsf_list == NULL)
564                  return;                         /* XXX should be error? */
565          near_rbf = dsf_list;
# Line 553 | Line 604 | check_normal_incidence(void)
604          memcpy(mir_rbf, near_rbf, n);
605          mir_rbf->ord = near_rbf->ord - 1;       /* not used, I think */
606          mir_rbf->next = NULL;
607 +        mir_rbf->ejl = NULL;
608          rev_rbf_symmetry(mir_rbf, MIRROR_X|MIRROR_Y);
609          nprocs = 1;                             /* compute migration matrix */
610 <        if (mig_list != create_migration(mir_rbf, near_rbf))
610 >        if (create_migration(mir_rbf, near_rbf) == NULL)
611                  exit(1);                        /* XXX should never happen! */
612                                                  /* interpolate normal dist. */
613          rbf = e_advect_rbf(mig_list, norm_vec, 2*near_rbf->nrbf);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines