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.34 by greg, Fri Jan 29 16:21:55 2016 UTC vs.
Revision 2.38 by greg, Tue May 16 20:41:03 2017 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *      G. Ward
8   */
9  
10 < #ifndef _WIN32
10 > #if !defined(_WIN32) && !defined(_WIN64)
11   #include <unistd.h>
12   #include <sys/wait.h>
13   #include <sys/mman.h>
# 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 <        const double    max_hemi = 0.9;
103 <        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          }
122        bsdf_spec_peak = peak_sum/(double)n;
154          bsdf_spec_rad = rad_sum/(double)n;
155 <        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);
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) */
# Line 132 | Line 162 | new_migration(RBFNODE *from_rbf, RBFNODE *to_rbf)
162          size_t          memlen = sizeof(MIGRATION) +
163                                  sizeof(float)*(from_rbf->nrbf*to_rbf->nrbf - 1);
164          MIGRATION       *newmig;
165 < #ifdef _WIN32
165 > #if defined(_WIN32) || defined(_WIN64)
166          if (nprocs > 1)
167                  fprintf(stderr, "%s: warning - multiprocessing not supported\n",
168                                  progname);
# Line 163 | Line 193 | new_migration(RBFNODE *from_rbf, RBFNODE *to_rbf)
193          return(mig_list = newmig);
194   }
195  
196 < #ifdef _WIN32
196 > #if defined(_WIN32) || defined(_WIN64)
197   #define await_children(n)       (void)(n)
198   #define run_subprocess()        0
199   #define end_subprocess()        (void)0
# Line 461 | Line 491 | check_normal_incidence(void)
491                  default:
492                          return;                 /* else we can interpolate */
493                  }
494 <                for (rbf = near_rbf->next; rbf != NULL; rbf = rbf->next) {
494 >                for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) {
495                          const double    d = input_orient*rbf->invec[2];
496                          if (d >= 1.-2.*FTINY)
497                                  return;         /* seems we have normal */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines