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

Comparing ray/src/px/pcond3.c (file contents):
Revision 3.9 by greg, Fri Apr 11 18:34:39 1997 UTC vs.
Revision 3.10 by gwlarson, Thu Mar 12 15:47:34 1998 UTC

# Line 13 | Line 13 | static char SCCSid[] = "$SunId$ LBL";
13  
14   #define CVRATIO         0.025           /* fraction of samples allowed > env. */
15  
16 < #define exp10(x)        exp(2.302585093*(x))
16 > #define LN_10           2.30258509299404568402
17 > #define exp10(x)        exp(LN_10*(x))
18  
19   float   modhist[HISTRES];               /* modified histogram */
20   double  mhistot;                        /* modified histogram total */
# Line 81 | Line 82 | FILE   *fp;
82   }
83  
84  
85 + gethisto(fp)                    /* load precomputed luminance histogram */
86 + FILE    *fp;
87 + {
88 +        float   histo[MAXPREHIST];
89 +        double  histart, histep;
90 +        double  l, b, lastb, w;
91 +        int     n;
92 +        register int    i;
93 +                                        /* load data */
94 +        for (i = 0; i < MAXPREHIST &&
95 +                        fscanf(fp, "%lf %f", &b, &histo[i]) == 2; i++) {
96 +                if (i > 1 && fabs(b - lastb - histep) > 1e-3) {
97 +                        fprintf(stderr,
98 +                                "%s: uneven step size in histogram data\n",
99 +                                        progname);
100 +                        exit(1);
101 +                }
102 +                if (i == 1)
103 +                        histep = b - (histart = lastb);
104 +                lastb = b;
105 +        }
106 +        if (i < 2 || !feof(fp)) {
107 +                fprintf(stderr,
108 +                "%s: format/length error loading histogram (log10L %f at %d)\n",
109 +                                progname, b, i);
110 +                exit(1);
111 +        }
112 +        n = i;
113 +        histart *= LN_10;
114 +        histep *= LN_10;
115 +                                        /* find extrema */
116 +        for (i = 0; i < n && histo[i] <= FTINY; i++)
117 +                ;
118 +        bwmin = histart + i*histep;
119 +        for (i = n; i-- && histo[i] <= FTINY; )
120 +                ;
121 +        bwmax = histart + i*histep;
122 +        if (bwmax > Bl(LMAX))
123 +                bwmax = Bl(LMAX);
124 +        if (bwmin < Bl(LMIN))
125 +                bwmin = Bl(LMIN);
126 +        else                            /* duplicate bottom bin */
127 +                bwmin = bwmax - (bwmax-bwmin)*HISTRES/(HISTRES-1);
128 +                                        /* convert histogram */
129 +        bwavg = 0.; histot = 0.;
130 +        for (i = 0; i < HISTRES; i++)
131 +                bwhist[i] = 0.;
132 +        for (i = 0, b = histart; i < n; i++, b += histep) {
133 +                if (b < bwmin) continue;
134 +                if (b > bwmax) break;
135 +                w = histo[i];
136 +                bwavg += w*b;
137 +                bwhist[bwhi(b)] += w;
138 +                histot += w;
139 +        }
140 +        bwavg /= histot;
141 +        if (bwmin > Bl(LMIN)+FTINY) {   /* add false samples at bottom */
142 +                bwhist[1] *= 0.5;
143 +                bwhist[0] += bwhist[1];
144 +        }
145 + }
146 +
147 +
148   double
149   centprob(x, y)                  /* center-weighting probability function */
150   int     x, y;
# Line 98 | Line 162 | comphist()                     /* create foveal sampling histogram */
162   {
163          double  l, b, w, lwmin, lwmax;
164          register int    x, y;
165 <
165 >                                        /* check for precalculated histogram */
166 >        if (what2do&DO_PREHIST)
167 >                return;
168          lwmin = 1e10;                   /* find extrema */
169          lwmax = 0.;
170          for (y = 0; y < fvyr; y++)
# Line 131 | Line 197 | comphist()                     /* create foveal sampling histogram */
197                                  if (l < lwmin) continue;
198                                  if (l > lwmax) continue;
199                                  b = Bl(l);
134                                bwavg += b;
200                                  w = what2do&DO_CWEIGHT ? centprob(x,y) : 1.;
201 +                                bwavg += w*b;
202                                  bwhist[bwhi(b)] += w;
203                                  histot += w;
204                          }
# Line 147 | Line 213 | comphist()                     /* create foveal sampling histogram */
213                          if (l < lwmin) continue;
214                          if (l > lwmax) continue;
215                          b = Bl(l);
216 <                        bwavg += b;
216 >                        bwavg += w*b;
217                          bwhist[bwhi(b)] += w;
218                          histot += w;
219                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines