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.33 by greg, Fri Aug 22 05:38:44 2014 UTC vs.
Revision 2.36 by greg, Sat Jan 30 17:34:00 2016 UTC

# Line 95 | Line 95 | est_DSFrad(const RBFNODE *rbf, const FVECT outvec)
95   #undef interp_rad
96   }
97  
98 < /* Compute average BSDF peak from current DSF's */
98 > static int
99 > dbl_cmp(const void *p1, const void *p2)
100 > {
101 >        double  d1 = *(const double *)p1;
102 >        double  d2 = *(const double *)p2;
103 >
104 >        if (d1 > d2) return(1);
105 >        if (d1 < d2) return(-1);
106 >        return(0);
107 > }
108 >
109 > /* Conservative estimate of average BSDF value from current DSF's */
110   static void
111   comp_bsdf_spec(void)
112   {
113 <        double          peak_sum = 0;
113 >        double          vmod_sum = 0;
114          double          rad_sum = 0;
115          int             n = 0;
116 +        double          *cost_list = NULL;
117 +        double          max_cost = 1.;
118          RBFNODE         *rbf;
119          FVECT           sdv;
120 <
121 <        if (dsf_list == NULL) {
122 <                bsdf_spec_peak = 0;
120 >                                                /* sort by incident altitude */
121 >        for (rbf = dsf_list; rbf != NULL; rbf = rbf->next)
122 >                n++;
123 >        if (n >= 10)
124 >                cost_list = (double *)malloc(sizeof(double)*n);
125 >        if (cost_list == NULL) {
126 >                bsdf_spec_val = 0;
127                  bsdf_spec_rad = 0;
128                  return;
129          }
130 +        n = 0;
131 +        for (rbf = dsf_list; rbf != NULL; rbf = rbf->next)
132 +                cost_list[n++] = rbf->invec[2]*input_orient;
133 +        qsort(cost_list, n, sizeof(double), dbl_cmp);
134 +        max_cost = cost_list[(n+3)/4];          /* accept 25% nearest grazing */
135 +        free(cost_list);
136 +        n = 0;
137          for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) {
138 +                double  this_rad, cosfact, vest;
139 +                if (rbf->invec[2]*input_orient > max_cost)
140 +                        continue;
141                  sdv[0] = -rbf->invec[0];
142                  sdv[1] = -rbf->invec[1];
143                  sdv[2] = rbf->invec[2]*(2*(input_orient==output_orient) - 1);
144 <                peak_sum += eval_rbfrep(rbf, sdv);
145 <                rad_sum += est_DSFrad(rbf, sdv);
144 >                cosfact = COSF(sdv[2]);
145 >                this_rad = est_DSFrad(rbf, sdv);
146 >                vest = eval_rbfrep(rbf, sdv) * cosfact *
147 >                                (2.*M_PI) * this_rad*this_rad;
148 >                if (vest > rbf->vtotal)         /* don't over-estimate energy */
149 >                        vest = rbf->vtotal;
150 >                vmod_sum += vest / cosfact;     /* remove cosine factor */
151 >                rad_sum += this_rad;
152                  ++n;
153          }
121        bsdf_spec_peak = peak_sum/(double)n;
154          bsdf_spec_rad = rad_sum/(double)n;
155 +        bsdf_spec_val = vmod_sum/(2.*M_PI*n*bsdf_spec_rad*bsdf_spec_rad);
156   }
157  
158   /* Create a new migration holder (sharing memory for multiprocessing) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines