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.9 by greg, Fri Apr 11 18:34:39 1997 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 20 | Line 20 | double mhistot;                        /* modified histogram total */
20   float   cumf[HISTRES+1];                /* cumulative distribution function */
21  
22  
23 + getfixations(fp)                /* load fixation history list */
24 + FILE    *fp;
25 + {
26 + #define FIXHUNK         128
27 +        RESOLU  fvres;
28 +        int     pos[2];
29 +        register int    px, py, i;
30 +                                /* initialize our resolution struct */
31 +        if ((fvres.or=inpres.or)&YMAJOR) {
32 +                fvres.xr = fvxr;
33 +                fvres.yr = fvyr;
34 +        } else {
35 +                fvres.xr = fvyr;
36 +                fvres.yr = fvxr;
37 +        }
38 +                                /* read each picture position */
39 +        while (fscanf(fp, "%d %d", &pos[0], &pos[1]) == 2) {
40 +                                /* convert to closest index in foveal image */
41 +                loc2pix(pos, &fvres,
42 +                                (pos[0]+.5)/inpres.xr, (pos[1]+.5)/inpres.yr);
43 +                                /* include nine neighborhood samples */
44 +                for (px = pos[0]-1; px <= pos[0]+1; px++) {
45 +                        if (px < 0 || px >= fvxr)
46 +                                continue;
47 +                        for (py = pos[1]-1; py <= pos[1]+1; py++) {
48 +                                if (py < 0 || py >= fvyr)
49 +                                        continue;
50 +                                for (i = nfixations; i-- > 0; )
51 +                                        if (fixlst[i][0] == px &&
52 +                                                        fixlst[i][1] == py)
53 +                                                break;
54 +                                if (i >= 0)
55 +                                        continue;       /* already there */
56 +                                if (nfixations % FIXHUNK == 0) {
57 +                                        if (nfixations)
58 +                                                fixlst = (short (*)[2])
59 +                                                        realloc((char *)fixlst,
60 +                                                        (nfixations+FIXHUNK)*
61 +                                                        2*sizeof(short));
62 +                                        else
63 +                                                fixlst = (short (*)[2])malloc(
64 +                                                        FIXHUNK*2*sizeof(short)
65 +                                                        );
66 +                                        if (fixlst == NULL)
67 +                                                syserror("malloc");
68 +                                }
69 +                                fixlst[nfixations][0] = px;
70 +                                fixlst[nfixations][1] = py;
71 +                                nfixations++;
72 +                        }
73 +                }
74 +        }
75 +        if (!feof(fp)) {
76 +                fprintf(stderr, "%s: format error reading fixation data\n",
77 +                                progname);
78 +                exit(1);
79 +        }
80 + #undef  FIXHUNK
81 + }
82 +
83 +
84 + double
85 + centprob(x, y)                  /* center-weighting probability function */
86 + int     x, y;
87 + {
88 +        double  xr, yr, p;
89 +                                /* paraboloid, 0 at 90 degrees from center */
90 +        xr = (x - .5*(fvxr-1))/90.;     /* 180 degree fisheye has fv?r == 90 */
91 +        yr = (y - .5*(fvyr-1))/90.;
92 +        p = 1. - xr*xr - yr*yr;
93 +        return(p < 0. ? 0. : p);
94 + }
95 +
96 +
97 + comphist()                      /* create foveal sampling histogram */
98 + {
99 +        double  l, b, w, lwmin, lwmax;
100 +        register int    x, y;
101 +
102 +        lwmin = 1e10;                   /* find extrema */
103 +        lwmax = 0.;
104 +        for (y = 0; y < fvyr; y++)
105 +                for (x = 0; x < fvxr; x++) {
106 +                        l = plum(fovscan(y)[x]);
107 +                        if (l < lwmin) lwmin = l;
108 +                        if (l > lwmax) lwmax = l;
109 +                }
110 +        lwmax *= 1.01;
111 +        if (lwmax > LMAX)
112 +                lwmax = LMAX;
113 +        bwmax = Bl(lwmax);
114 +        if (lwmin < LMIN) {
115 +                lwmin = LMIN;
116 +                bwmin = Bl(LMIN);
117 +        } else {                        /* duplicate bottom bin */
118 +                bwmin = bwmax - (bwmax-Bl(lwmin))*HISTRES/(HISTRES-1);
119 +                lwmin = Lb(bwmin);
120 +        }
121 +                                        /* (re)compute histogram */
122 +        bwavg = 0.;
123 +        histot = 0.;
124 +        for (x = 0; x < HISTRES; x++)
125 +                bwhist[x] = 0.;
126 +                                        /* global average */
127 +        if (!(what2do&DO_FIXHIST) || fixfrac < 1.-FTINY)
128 +                for (y = 0; y < fvyr; y++)
129 +                        for (x = 0; x < fvxr; x++) {
130 +                                l = plum(fovscan(y)[x]);
131 +                                if (l < lwmin) continue;
132 +                                if (l > lwmax) continue;
133 +                                b = Bl(l);
134 +                                bwavg += b;
135 +                                w = what2do&DO_CWEIGHT ? centprob(x,y) : 1.;
136 +                                bwhist[bwhi(b)] += w;
137 +                                histot += w;
138 +                        }
139 +                                        /* average fixation points */
140 +        if (what2do&DO_FIXHIST && nfixations > 0) {
141 +                if (histot > FTINY)
142 +                        w = fixfrac/(1.-fixfrac)*histot/nfixations;
143 +                else
144 +                        w = 1.;
145 +                for (x = 0; x < nfixations; x++) {
146 +                        l = plum(fovscan(fixlst[x][1])[fixlst[x][0]]);
147 +                        if (l < lwmin) continue;
148 +                        if (l > lwmax) continue;
149 +                        b = Bl(l);
150 +                        bwavg += b;
151 +                        bwhist[bwhi(b)] += w;
152 +                        histot += w;
153 +                }
154 +        }
155 +        bwavg /= histot;
156 +        if (lwmin > LMIN+FTINY) {       /* add false samples at bottom */
157 +                bwhist[1] *= 0.5;
158 +                bwhist[0] += bwhist[1];
159 +        }
160 + }
161 +
162 +
163   mkcumf()                        /* make cumulative distribution function */
164   {
165          register int    i;
# Line 185 | Line 325 | FILE   *fp;
325   {
326          double  b, s;
327          register int    i;
328 <        double  wlum, sf;
328 >        double  wlum, sf, dlum;
329  
330          sf = scalef*inpexp;
331          if (lumf == cielum) sf *= WHTEFFICACY;
332          s = (bwmax - bwmin)/HISTRES;
333          for (i = 0, b = bwmin + .5*s; i < HISTRES; i++, b += s) {
334                  wlum = Lb(b);
335 <                if (what2do&DO_LINEAR)
336 <                        fprintf(fp, "%e %e\n", wlum, sf*wlum);
337 <                else
335 >                if (what2do&DO_LINEAR) {
336 >                        dlum = sf*wlum;
337 >                        if (dlum > ldmax) dlum = ldmax;
338 >                        else if (dlum < ldmin) dlum = ldmin;
339 >                        fprintf(fp, "%e %e\n", wlum, dlum);
340 >                } else
341                          fprintf(fp, "%e %e\n", wlum, Lb(BLw(wlum)));
342          }
343   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines