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.6 by greg, Fri Jan 10 16:48:21 1997 UTC vs.
Revision 3.10 by gwlarson, Thu Mar 12 15:47:34 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1996 Regents of the University of California */
1 > /* Copyright (c) 1997 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# 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 */
21   float   cumf[HISTRES+1];                /* cumulative distribution function */
22  
23  
24 + getfixations(fp)                /* load fixation history list */
25 + FILE    *fp;
26 + {
27 + #define FIXHUNK         128
28 +        RESOLU  fvres;
29 +        int     pos[2];
30 +        register int    px, py, i;
31 +                                /* initialize our resolution struct */
32 +        if ((fvres.or=inpres.or)&YMAJOR) {
33 +                fvres.xr = fvxr;
34 +                fvres.yr = fvyr;
35 +        } else {
36 +                fvres.xr = fvyr;
37 +                fvres.yr = fvxr;
38 +        }
39 +                                /* read each picture position */
40 +        while (fscanf(fp, "%d %d", &pos[0], &pos[1]) == 2) {
41 +                                /* convert to closest index in foveal image */
42 +                loc2pix(pos, &fvres,
43 +                                (pos[0]+.5)/inpres.xr, (pos[1]+.5)/inpres.yr);
44 +                                /* include nine neighborhood samples */
45 +                for (px = pos[0]-1; px <= pos[0]+1; px++) {
46 +                        if (px < 0 || px >= fvxr)
47 +                                continue;
48 +                        for (py = pos[1]-1; py <= pos[1]+1; py++) {
49 +                                if (py < 0 || py >= fvyr)
50 +                                        continue;
51 +                                for (i = nfixations; i-- > 0; )
52 +                                        if (fixlst[i][0] == px &&
53 +                                                        fixlst[i][1] == py)
54 +                                                break;
55 +                                if (i >= 0)
56 +                                        continue;       /* already there */
57 +                                if (nfixations % FIXHUNK == 0) {
58 +                                        if (nfixations)
59 +                                                fixlst = (short (*)[2])
60 +                                                        realloc((char *)fixlst,
61 +                                                        (nfixations+FIXHUNK)*
62 +                                                        2*sizeof(short));
63 +                                        else
64 +                                                fixlst = (short (*)[2])malloc(
65 +                                                        FIXHUNK*2*sizeof(short)
66 +                                                        );
67 +                                        if (fixlst == NULL)
68 +                                                syserror("malloc");
69 +                                }
70 +                                fixlst[nfixations][0] = px;
71 +                                fixlst[nfixations][1] = py;
72 +                                nfixations++;
73 +                        }
74 +                }
75 +        }
76 +        if (!feof(fp)) {
77 +                fprintf(stderr, "%s: format error reading fixation data\n",
78 +                                progname);
79 +                exit(1);
80 +        }
81 + #undef  FIXHUNK
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;
151 + {
152 +        double  xr, yr, p;
153 +                                /* paraboloid, 0 at 90 degrees from center */
154 +        xr = (x - .5*(fvxr-1))/90.;     /* 180 degree fisheye has fv?r == 90 */
155 +        yr = (y - .5*(fvyr-1))/90.;
156 +        p = 1. - xr*xr - yr*yr;
157 +        return(p < 0. ? 0. : p);
158 + }
159 +
160 +
161 + comphist()                      /* create foveal sampling histogram */
162 + {
163 +        double  l, b, w, lwmin, lwmax;
164 +        register int    x, y;
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++)
171 +                for (x = 0; x < fvxr; x++) {
172 +                        l = plum(fovscan(y)[x]);
173 +                        if (l < lwmin) lwmin = l;
174 +                        if (l > lwmax) lwmax = l;
175 +                }
176 +        lwmax *= 1.01;
177 +        if (lwmax > LMAX)
178 +                lwmax = LMAX;
179 +        bwmax = Bl(lwmax);
180 +        if (lwmin < LMIN) {
181 +                lwmin = LMIN;
182 +                bwmin = Bl(LMIN);
183 +        } else {                        /* duplicate bottom bin */
184 +                bwmin = bwmax - (bwmax-Bl(lwmin))*HISTRES/(HISTRES-1);
185 +                lwmin = Lb(bwmin);
186 +        }
187 +                                        /* (re)compute histogram */
188 +        bwavg = 0.;
189 +        histot = 0.;
190 +        for (x = 0; x < HISTRES; x++)
191 +                bwhist[x] = 0.;
192 +                                        /* global average */
193 +        if (!(what2do&DO_FIXHIST) || fixfrac < 1.-FTINY)
194 +                for (y = 0; y < fvyr; y++)
195 +                        for (x = 0; x < fvxr; x++) {
196 +                                l = plum(fovscan(y)[x]);
197 +                                if (l < lwmin) continue;
198 +                                if (l > lwmax) continue;
199 +                                b = Bl(l);
200 +                                w = what2do&DO_CWEIGHT ? centprob(x,y) : 1.;
201 +                                bwavg += w*b;
202 +                                bwhist[bwhi(b)] += w;
203 +                                histot += w;
204 +                        }
205 +                                        /* average fixation points */
206 +        if (what2do&DO_FIXHIST && nfixations > 0) {
207 +                if (histot > FTINY)
208 +                        w = fixfrac/(1.-fixfrac)*histot/nfixations;
209 +                else
210 +                        w = 1.;
211 +                for (x = 0; x < nfixations; x++) {
212 +                        l = plum(fovscan(fixlst[x][1])[fixlst[x][0]]);
213 +                        if (l < lwmin) continue;
214 +                        if (l > lwmax) continue;
215 +                        b = Bl(l);
216 +                        bwavg += w*b;
217 +                        bwhist[bwhi(b)] += w;
218 +                        histot += w;
219 +                }
220 +        }
221 +        bwavg /= histot;
222 +        if (lwmin > LMIN+FTINY) {       /* add false samples at bottom */
223 +                bwhist[1] *= 0.5;
224 +                bwhist[0] += bwhist[1];
225 +        }
226 + }
227 +
228 +
229   mkcumf()                        /* make cumulative distribution function */
230   {
231          register int    i;
# Line 185 | Line 391 | FILE   *fp;
391   {
392          double  b, s;
393          register int    i;
394 <        double  wlum, sf;
394 >        double  wlum, sf, dlum;
395  
396          sf = scalef*inpexp;
397          if (lumf == cielum) sf *= WHTEFFICACY;
398          s = (bwmax - bwmin)/HISTRES;
399          for (i = 0, b = bwmin + .5*s; i < HISTRES; i++, b += s) {
400                  wlum = Lb(b);
401 <                if (what2do&DO_LINEAR)
402 <                        fprintf(fp, "%e %e\n", wlum, sf*wlum);
403 <                else
401 >                if (what2do&DO_LINEAR) {
402 >                        dlum = sf*wlum;
403 >                        if (dlum > ldmax) dlum = ldmax;
404 >                        else if (dlum < ldmin) dlum = ldmin;
405 >                        fprintf(fp, "%e %e\n", wlum, dlum);
406 >                } else
407                          fprintf(fp, "%e %e\n", wlum, Lb(BLw(wlum)));
408          }
409   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines