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.4 by greg, Thu Nov 8 23:11:41 2012 UTC vs.
Revision 2.34 by greg, Fri Jan 29 16:21:55 2016 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) */
28   static int              nchild = 0;
29  
30 < typedef struct {
31 <        int             nrows, ncols;   /* array size (matches migration) */
32 <        float           *price;         /* migration prices */
33 <        short           *sord;          /* sort for each row, low to high */
34 < } PRICEMAT;                     /* sorted pricing matrix */
30 > /* Compute average DSF value at the given radius from central vector */
31 > static double
32 > eval_DSFsurround(const RBFNODE *rbf, const FVECT outvec, const double rad)
33 > {
34 >        const int       ninc = 12;
35 >        const double    phinc = 2.*M_PI/ninc;
36 >        double          sum = 0;
37 >        int             n = 0;
38 >        FVECT           tvec;
39 >        int             i;
40 >                                                /* compute initial vector */
41 >        if (output_orient*outvec[2] >= 1.-FTINY) {
42 >                tvec[0] = tvec[2] = 0;
43 >                tvec[1] = 1;
44 >        } else {
45 >                tvec[0] = tvec[1] = 0;
46 >                tvec[2] = 1;
47 >        }
48 >        geodesic(tvec, outvec, tvec, rad, GEOD_RAD);
49 >                                                /* average surrounding DSF */
50 >        for (i = 0; i < ninc; i++) {
51 >                if (i) spinvector(tvec, tvec, outvec, phinc);
52 >                if (tvec[2] > 0 ^ output_orient > 0)
53 >                        continue;
54 >                sum += eval_rbfrep(rbf, tvec) * COSF(tvec[2]);
55 >                ++n;
56 >        }
57 >        if (n < 2)                              /* should never happen! */
58 >                return(sum);
59 >        return(sum/(double)n);
60 > }
61  
62 < #define pricerow(p,i)   ((p)->price + (i)*(p)->ncols)
63 < #define psortrow(p,i)   ((p)->sord + (i)*(p)->ncols)
62 > /* Estimate single-lobe radius for DSF at the given outgoing angle */
63 > static double
64 > est_DSFrad(const RBFNODE *rbf, const FVECT outvec)
65 > {
66 >        const double    rad_epsilon = 0.03;
67 >        const double    DSFtarget = 0.60653066 * eval_rbfrep(rbf,outvec) *
68 >                                                        COSF(outvec[2]);
69 >        double          inside_rad = rad_epsilon;
70 >        double          outside_rad = 0.5;
71 >        double          DSFinside = eval_DSFsurround(rbf, outvec, inside_rad);
72 >        double          DSFoutside = eval_DSFsurround(rbf, outvec, outside_rad);
73 > #define interp_rad      inside_rad + (outside_rad-inside_rad) * \
74 >                                (DSFtarget-DSFinside) / (DSFoutside-DSFinside)
75 >                                                /* Newton's method (sort of) */
76 >        do {
77 >                double  test_rad = interp_rad;
78 >                double  DSFtest;
79 >                if (test_rad >= outside_rad)
80 >                        return(test_rad);
81 >                if (test_rad <= inside_rad)
82 >                        return(test_rad*(test_rad>0));
83 >                DSFtest = eval_DSFsurround(rbf, outvec, test_rad);
84 >                if (DSFtest > DSFtarget) {
85 >                        inside_rad = test_rad;
86 >                        DSFinside = DSFtest;
87 >                } else {
88 >                        outside_rad = test_rad;
89 >                        DSFoutside = DSFtest;
90 >                }
91 >                if (DSFoutside >= DSFinside)
92 >                        return(test_rad);
93 >        } while (outside_rad-inside_rad > rad_epsilon);
94 >        return(interp_rad);
95 > #undef interp_rad
96 > }
97  
98 + /* Compute average BSDF peak from current DSF's */
99 + static void
100 + comp_bsdf_spec(void)
101 + {
102 +        const double    max_hemi = 0.9;
103 +        double          peak_sum = 0;
104 +        double          rad_sum = 0;
105 +        int             n = 0;
106 +        RBFNODE         *rbf;
107 +        FVECT           sdv;
108 +
109 +        if (dsf_list == NULL) {
110 +                bsdf_spec_peak = 0;
111 +                bsdf_spec_rad = 0;
112 +                return;
113 +        }
114 +        for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) {
115 +                sdv[0] = -rbf->invec[0];
116 +                sdv[1] = -rbf->invec[1];
117 +                sdv[2] = rbf->invec[2]*(2*(input_orient==output_orient) - 1);
118 +                peak_sum += eval_rbfrep(rbf, sdv);
119 +                rad_sum += est_DSFrad(rbf, sdv);
120 +                ++n;
121 +        }
122 +        bsdf_spec_peak = peak_sum/(double)n;
123 +        bsdf_spec_rad = rad_sum/(double)n;
124 +        if ((2.*M_PI)*bsdf_spec_peak*bsdf_spec_rad*bsdf_spec_rad > max_hemi)
125 +                bsdf_spec_peak = max_hemi/((2.*M_PI)*bsdf_spec_rad*bsdf_spec_rad);
126 + }
127 +
128   /* Create a new migration holder (sharing memory for multiprocessing) */
129   static MIGRATION *
130   new_migration(RBFNODE *from_rbf, RBFNODE *to_rbf)
# Line 119 | Line 212 | run_subprocess(void)
212                  if (pid < 0) {
213                          fprintf(stderr, "%s: cannot fork subprocess\n",
214                                          progname);
215 +                        await_children(nchild);
216                          exit(1);
217                  }
218                  ++nchild;                       /* subprocess started */
# Line 133 | Line 227 | run_subprocess(void)
227  
228   #endif  /* ! _WIN32 */
229  
230 < /* Comparison routine needed for sorting price row */
137 < static int
138 < msrt_cmp(void *b, const void *p1, const void *p2)
139 < {
140 <        PRICEMAT        *pm = (PRICEMAT *)b;
141 <        int             ri = ((const short *)p1 - pm->sord) / pm->ncols;
142 <        float           c1 = pricerow(pm,ri)[*(const short *)p1];
143 <        float           c2 = pricerow(pm,ri)[*(const short *)p2];
144 <
145 <        if (c1 > c2) return(1);
146 <        if (c1 < c2) return(-1);
147 <        return(0);
148 < }
149 <
150 < /* Compute (and allocate) migration price matrix for optimization */
230 > /* Compute normalized distribution scattering functions for comparison */
231   static void
232 < price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, const RBFNODE *to_rbf)
232 > compute_nDSFs(const RBFNODE *rbf0, const RBFNODE *rbf1)
233   {
234 <        FVECT   *vto = (FVECT *)malloc(sizeof(FVECT) * to_rbf->nrbf);
235 <        int     i, j;
234 >        const double    nf0 = (GRIDRES*GRIDRES) / rbf0->vtotal;
235 >        const double    nf1 = (GRIDRES*GRIDRES) / rbf1->vtotal;
236 >        int             x, y;
237 >        FVECT           dv;
238  
239 <        pm->nrows = from_rbf->nrbf;
240 <        pm->ncols = to_rbf->nrbf;
241 <        pm->price = (float *)malloc(sizeof(float) * pm->nrows*pm->ncols);
242 <        pm->sord = (short *)malloc(sizeof(short) * pm->nrows*pm->ncols);
243 <        
162 <        if ((pm->price == NULL) | (pm->sord == NULL) | (vto == NULL)) {
163 <                fprintf(stderr, "%s: Out of memory in migration_costs()\n",
164 <                                progname);
165 <                exit(1);
166 <        }
167 <        for (j = to_rbf->nrbf; j--; )           /* save repetitive ops. */
168 <                ovec_from_pos(vto[j], to_rbf->rbfa[j].gx, to_rbf->rbfa[j].gy);
169 <
170 <        for (i = from_rbf->nrbf; i--; ) {
171 <            const double        from_ang = R2ANG(from_rbf->rbfa[i].crad);
172 <            FVECT               vfrom;
173 <            ovec_from_pos(vfrom, from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy);
174 <            for (j = to_rbf->nrbf; j--; ) {
175 <                pricerow(pm,i)[j] = acos(DOT(vfrom, vto[j])) +
176 <                                fabs(R2ANG(to_rbf->rbfa[j].crad) - from_ang);
177 <                psortrow(pm,i)[j] = j;
239 >        for (x = GRIDRES; x--; )
240 >            for (y = GRIDRES; y--; ) {
241 >                ovec_from_pos(dv, x, y);        /* cube root (brightness) */
242 >                dsf_grid[x][y].val[0] = pow(nf0*eval_rbfrep(rbf0, dv), .3333);
243 >                dsf_grid[x][y].val[1] = pow(nf1*eval_rbfrep(rbf1, dv), .3333);
244              }
245 <            qsort_r(psortrow(pm,i), pm->ncols, sizeof(short), pm, &msrt_cmp);
180 <        }
181 <        free(vto);
182 < }
245 > }      
246  
247 < /* Free price matrix */
185 < static void
186 < free_routes(PRICEMAT *pm)
187 < {
188 <        free(pm->price); pm->price = NULL;
189 <        free(pm->sord); pm->sord = NULL;
190 < }
191 <
192 < /* Compute minimum (optimistic) cost for moving the given source material */
247 > /* Compute neighborhood distance-squared (dissimilarity) */
248   static double
249 < min_cost(double amt2move, const double *avail, const PRICEMAT *pm, int s)
249 > neighborhood_dist2(int x0, int y0, int x1, int y1)
250   {
251 <        double          total_cost = 0;
252 <        int             j;
253 <
254 <        if (amt2move <= FTINY)                  /* pre-emptive check */
255 <                return(0.);
256 <                                                /* move cheapest first */
257 <        for (j = 0; j < pm->ncols && amt2move > FTINY; j++) {
258 <                int     d = psortrow(pm,s)[j];
259 <                double  amt = (amt2move < avail[d]) ? amt2move : avail[d];
260 <
206 <                total_cost += amt * pricerow(pm,s)[d];
207 <                amt2move -= amt;
251 >        int     rad = GRIDRES>>5;
252 >        double  sum2 = 0.;
253 >        double  d;
254 >        int     p[4];
255 >        int     i, j;
256 >                                                /* check radius */
257 >        p[0] = x0; p[1] = y0; p[2] = x1; p[3] = y1;
258 >        for (i = 4; i--; ) {
259 >                if (p[i] < rad) rad = p[i];
260 >                if (GRIDRES-1-p[i] < rad) rad = GRIDRES-1-p[i];
261          }
262 <        return(total_cost);
262 >        for (i = -rad; i <= rad; i++)
263 >            for (j = -rad; j <= rad; j++) {
264 >                d = dsf_grid[x0+i][y0+j].val[0] -
265 >                        dsf_grid[x1+i][y1+j].val[1];
266 >                sum2 += d*d;
267 >            }
268 >        return(sum2 / (4*rad*(rad+1) + 1));
269   }
270  
271 < /* Take a step in migration by choosing optimal bucket to transfer */
272 < static double
273 < migration_step(MIGRATION *mig, double *src_rem, double *dst_rem, const PRICEMAT *pm)
271 > /* Compute distance between two RBF lobes */
272 > double
273 > lobe_distance(RBFVAL *rbf1, RBFVAL *rbf2)
274   {
275 <        const double    maxamt = 1./(double)pm->ncols;
276 <        const double    minamt = maxamt*5e-6;
277 <        static double   *src_cost = NULL;
278 <        static int      n_alloc = 0;
279 <        struct {
280 <                int     s, d;   /* source and destination */
281 <                double  price;  /* price estimate per amount moved */
282 <                double  amt;    /* amount we can move */
283 <        } cur, best;
284 <        int             i;
285 <
286 <        if (pm->nrows > n_alloc) {              /* allocate cost array */
287 <                if (n_alloc)
229 <                        free(src_cost);
230 <                src_cost = (double *)malloc(sizeof(double)*pm->nrows);
231 <                if (src_cost == NULL) {
232 <                        fprintf(stderr, "%s: Out of memory in migration_step()\n",
233 <                                        progname);
234 <                        exit(1);
235 <                }
236 <                n_alloc = pm->nrows;
237 <        }
238 <        for (i = pm->nrows; i--; )              /* starting costs for diff. */
239 <                src_cost[i] = min_cost(src_rem[i], dst_rem, pm, i);
240 <
241 <                                                /* find best source & dest. */
242 <        best.s = best.d = -1; best.price = FHUGE; best.amt = 0;
243 <        for (cur.s = pm->nrows; cur.s--; ) {
244 <            double      cost_others = 0;
245 <            if (src_rem[cur.s] <= minamt)
246 <                    continue;
247 <                                                /* examine cheapest dest. */
248 <            for (i = 0; i < pm->ncols; i++)
249 <                if (dst_rem[cur.d = psortrow(pm,cur.s)[i]] > minamt)
250 <                        break;
251 <            if (i >= pm->ncols)
252 <                    return(.0);
253 <            if ((cur.price = pricerow(pm,cur.s)[cur.d]) >= best.price)
254 <                    continue;                   /* no point checking further */
255 <            cur.amt = (src_rem[cur.s] < dst_rem[cur.d]) ?
256 <                                src_rem[cur.s] : dst_rem[cur.d];
257 <            if (cur.amt > maxamt) cur.amt = maxamt;
258 <            dst_rem[cur.d] -= cur.amt;          /* add up differential costs */
259 <            for (i = pm->nrows; i--; )
260 <                if (i != cur.s)
261 <                        cost_others += min_cost(src_rem[i], dst_rem, pm, i)
262 <                                        - src_cost[i];
263 <            dst_rem[cur.d] += cur.amt;          /* undo trial move */
264 <            cur.price += cost_others/cur.amt;   /* adjust effective price */
265 <            if (cur.price < best.price)         /* are we better than best? */
266 <                    best = cur;
267 <        }
268 <        if ((best.s < 0) | (best.d < 0))
269 <                return(.0);
270 <                                                /* make the actual move */
271 <        mtx_coef(mig,best.s,best.d) += best.amt;
272 <        src_rem[best.s] -= best.amt;
273 <        dst_rem[best.d] -= best.amt;
274 <        return(best.amt);
275 >        FVECT   vfrom, vto;
276 >        double  d, res;
277 >                                        /* quadratic cost function */
278 >        ovec_from_pos(vfrom, rbf1->gx, rbf1->gy);
279 >        ovec_from_pos(vto, rbf2->gx, rbf2->gy);
280 >        d = Acos(DOT(vfrom, vto));
281 >        res = d*d;
282 >        d = R2ANG(rbf2->crad) - R2ANG(rbf1->crad);
283 >        res += d*d;
284 >                                        /* neighborhood difference */
285 >        res += NEIGH_FACT2 * neighborhood_dist2( rbf1->gx, rbf1->gy,
286 >                                                rbf2->gx, rbf2->gy );
287 >        return(res);
288   }
289  
277 #ifdef DEBUG
278 static char *
279 thetaphi(const FVECT v)
280 {
281        static char     buf[128];
282        double          theta, phi;
290  
284        theta = 180./M_PI*acos(v[2]);
285        phi = 180./M_PI*atan2(v[1],v[0]);
286        sprintf(buf, "(%.0f,%.0f)", theta, phi);
287
288        return(buf);
289 }
290 #endif
291
291   /* Compute and insert migration along directed edge (may fork child) */
292   static MIGRATION *
293   create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf)
294   {
296        const double    end_thresh = 5e-6;
297        PRICEMAT        pmtx;
295          MIGRATION       *newmig;
296 <        double          *src_rem, *dst_rem;
300 <        double          total_rem = 1., move_amt;
301 <        int             i;
296 >        int             i, j;
297                                                  /* check if exists already */
298          for (newmig = from_rbf->ejl; newmig != NULL;
299                          newmig = nextedge(from_rbf,newmig))
300                  if (newmig->rbfv[1] == to_rbf)
301                          return(NULL);
302                                                  /* else allocate */
308        newmig = new_migration(from_rbf, to_rbf);
309        if (run_subprocess())
310                return(newmig);                 /* child continues */
311        price_routes(&pmtx, from_rbf, to_rbf);
312        src_rem = (double *)malloc(sizeof(double)*from_rbf->nrbf);
313        dst_rem = (double *)malloc(sizeof(double)*to_rbf->nrbf);
314        if ((src_rem == NULL) | (dst_rem == NULL)) {
315                fprintf(stderr, "%s: Out of memory in create_migration()\n",
316                                progname);
317                exit(1);
318        }
303   #ifdef DEBUG
304 <        fprintf(stderr, "Building path from (theta,phi) %s ",
305 <                        thetaphi(from_rbf->invec));
306 <        fprintf(stderr, "to %s with %d x %d matrix\n",
307 <                        thetaphi(to_rbf->invec),
304 >        fprintf(stderr, "Building path from (theta,phi) (%.1f,%.1f) ",
305 >                        get_theta180(from_rbf->invec),
306 >                        get_phi360(from_rbf->invec));
307 >        fprintf(stderr, "to (%.1f,%.1f) with %d x %d matrix\n",
308 >                        get_theta180(to_rbf->invec),
309 >                        get_phi360(to_rbf->invec),
310                          from_rbf->nrbf, to_rbf->nrbf);
311   #endif
312 <                                                /* starting quantities */
313 <        memset(newmig->mtx, 0, sizeof(float)*from_rbf->nrbf*to_rbf->nrbf);
314 <        for (i = from_rbf->nrbf; i--; )
315 <                src_rem[i] = rbf_volume(&from_rbf->rbfa[i]) / from_rbf->vtotal;
316 <        for (i = to_rbf->nrbf; i--; )
317 <                dst_rem[i] = rbf_volume(&to_rbf->rbfa[i]) / to_rbf->vtotal;
318 <        do {                                    /* move a bit at a time */
319 <                move_amt = migration_step(newmig, src_rem, dst_rem, &pmtx);
334 <                total_rem -= move_amt;
335 < #ifdef DEBUG
336 <                if (!nchild)
337 <                        fprintf(stderr, "\r%.9f remaining...", total_rem);
338 < #endif
339 <        } while ((total_rem > end_thresh) & (move_amt > 0));
340 < #ifdef DEBUG
341 <        if (!nchild) fputs("done.\n", stderr);
342 <        else fprintf(stderr, "finished with %.9f remaining\n", total_rem);
343 < #endif
312 >        newmig = new_migration(from_rbf, to_rbf);
313 >        if (run_subprocess())
314 >                return(newmig);                 /* child continues */
315 >
316 >                                                /* compute transport plan */
317 >        compute_nDSFs(from_rbf, to_rbf);
318 >        plan_transport(newmig);
319 >
320          for (i = from_rbf->nrbf; i--; ) {       /* normalize final matrix */
321 <            float       nf = rbf_volume(&from_rbf->rbfa[i]);
346 <            int         j;
321 >            double      nf = rbf_volume(&from_rbf->rbfa[i]);
322              if (nf <= FTINY) continue;
323              nf = from_rbf->vtotal / nf;
324              for (j = to_rbf->nrbf; j--; )
325 <                mtx_coef(newmig,i,j) *= nf;
325 >                mtx_coef(newmig,i,j) *= nf;     /* row now sums to 1.0 */
326          }
327          end_subprocess();                       /* exit here if subprocess */
353        free_routes(&pmtx);                     /* free working arrays */
354        free(src_rem);
355        free(dst_rem);
328          return(newmig);
329   }
330  
# Line 382 | Line 354 | overlaps_tri(const RBFNODE *bv0, const RBFNODE *bv1, c
354          return(vother[im_rev] != NULL);
355   }
356  
357 < /* Find context hull vertex to complete triangle (oriented call) */
357 > /* Find convex hull vertex to complete triangle (oriented call) */
358   static RBFNODE *
359   find_chull_vert(const RBFNODE *rbf0, const RBFNODE *rbf1)
360   {
# Line 403 | Line 375 | find_chull_vert(const RBFNODE *rbf0, const RBFNODE *rb
375                  if (DOT(vp, vmid) <= FTINY)
376                          continue;               /* wrong orientation */
377                  area2 = .25*DOT(vp,vp);
378 <                VSUB(vp, rbf->invec, rbf0->invec);
378 >                VSUB(vp, rbf->invec, vmid);
379                  dprod = -DOT(vp, vejn);
380                  VSUM(vp, vp, vejn, dprod);      /* above guarantees non-zero */
381                  dprod = DOT(vp, vmid) / VLEN(vp);
# Line 442 | Line 414 | mesh_from_edge(MIGRATION *edge)
414                                  ej1 = create_migration(tvert[0], edge->rbfv[1]);
415                          mesh_from_edge(ej0);
416                          mesh_from_edge(ej1);
417 +                        return;
418                  }
419 <        } else if (tvert[1] == NULL) {          /* grow mesh on left */
419 >        }
420 >        if (tvert[1] == NULL) {                 /* grow mesh on left */
421                  tvert[1] = find_chull_vert(edge->rbfv[1], edge->rbfv[0]);
422                  if (tvert[1] != NULL) {
423                          if (tvert[1]->ord > edge->rbfv[0]->ord)
# Line 459 | Line 433 | mesh_from_edge(MIGRATION *edge)
433                  }
434          }
435   }
436 +
437 + /* Add normal direction if missing */
438 + static void
439 + check_normal_incidence(void)
440 + {
441 +        static FVECT            norm_vec = {.0, .0, 1.};
442 +        const int               saved_nprocs = nprocs;
443 +        RBFNODE                 *near_rbf, *mir_rbf, *rbf;
444 +        double                  bestd;
445 +        int                     n;
446 +
447 +        if (dsf_list == NULL)
448 +                return;                         /* XXX should be error? */
449 +        near_rbf = dsf_list;
450 +        bestd = input_orient*near_rbf->invec[2];
451 +        if (single_plane_incident) {            /* ordered plane incidence? */
452 +                if (bestd >= 1.-2.*FTINY)
453 +                        return;                 /* already have normal */
454 +        } else {
455 +                switch (inp_coverage) {
456 +                case INP_QUAD1:
457 +                case INP_QUAD2:
458 +                case INP_QUAD3:
459 +                case INP_QUAD4:
460 +                        break;                  /* quadrilateral symmetry? */
461 +                default:
462 +                        return;                 /* else we can interpolate */
463 +                }
464 +                for (rbf = near_rbf->next; rbf != NULL; rbf = rbf->next) {
465 +                        const double    d = input_orient*rbf->invec[2];
466 +                        if (d >= 1.-2.*FTINY)
467 +                                return;         /* seems we have normal */
468 +                        if (d > bestd) {
469 +                                near_rbf = rbf;
470 +                                bestd = d;
471 +                        }
472 +                }
473 +        }
474 +        if (mig_list != NULL) {                 /* need to be called first */
475 +                fprintf(stderr, "%s: Late call to check_normal_incidence()\n",
476 +                                progname);
477 +                exit(1);
478 +        }
479 + #ifdef DEBUG
480 +        fprintf(stderr, "Interpolating normal incidence by mirroring (%.1f,%.1f)\n",
481 +                        get_theta180(near_rbf->invec), get_phi360(near_rbf->invec));
482 + #endif
483 +                                                /* mirror nearest incidence */
484 +        n = sizeof(RBFNODE) + sizeof(RBFVAL)*(near_rbf->nrbf-1);
485 +        mir_rbf = (RBFNODE *)malloc(n);
486 +        if (mir_rbf == NULL)
487 +                goto memerr;
488 +        memcpy(mir_rbf, near_rbf, n);
489 +        mir_rbf->ord = near_rbf->ord - 1;       /* not used, I think */
490 +        mir_rbf->next = NULL;
491 +        mir_rbf->ejl = NULL;
492 +        rev_rbf_symmetry(mir_rbf, MIRROR_X|MIRROR_Y);
493 +        nprocs = 1;                             /* compute migration matrix */
494 +        if (create_migration(mir_rbf, near_rbf) == NULL)
495 +                exit(1);                        /* XXX should never happen! */
496 +        norm_vec[2] = input_orient;             /* interpolate normal dist. */
497 +        rbf = e_advect_rbf(mig_list, norm_vec, 0);
498 +        nprocs = saved_nprocs;                  /* final clean-up */
499 +        free(mir_rbf);
500 +        free(mig_list);
501 +        mig_list = near_rbf->ejl = NULL;
502 +        insert_dsf(rbf);                        /* insert interpolated normal */
503 +        return;
504 + memerr:
505 +        fprintf(stderr, "%s: Out of memory in check_normal_incidence()\n",
506 +                                progname);
507 +        exit(1);
508 + }
509          
510   /* Build our triangle mesh from recorded RBFs */
511   void
# Line 467 | Line 514 | build_mesh(void)
514          double          best2 = M_PI*M_PI;
515          RBFNODE         *shrt_edj[2];
516          RBFNODE         *rbf0, *rbf1;
517 +                                                /* average specular peak */
518 +        comp_bsdf_spec();
519 +                                                /* add normal if needed */
520 +        check_normal_incidence();
521                                                  /* check if isotropic */
522          if (single_plane_incident) {
523                  for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines