| 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 |
+ |
lwmin -= FTINY; |
| 111 |
+ |
lwmax += FTINY; |
| 112 |
+ |
if (lwmin < LMIN) lwmin = LMIN; |
| 113 |
+ |
if (lwmax > LMAX) lwmax = LMAX; |
| 114 |
+ |
bwmin = Bl(lwmin); |
| 115 |
+ |
bwmax = Bl(lwmax); |
| 116 |
+ |
/* (re)compute histogram */ |
| 117 |
+ |
bwavg = 0.; |
| 118 |
+ |
histot = 0.; |
| 119 |
+ |
for (x = 0; x < HISTRES; x++) |
| 120 |
+ |
bwhist[x] = 0.; |
| 121 |
+ |
/* global average */ |
| 122 |
+ |
if (!(what2do&DO_FIXHIST) || fixfrac < 1.-FTINY) |
| 123 |
+ |
for (y = 0; y < fvyr; y++) |
| 124 |
+ |
for (x = 0; x < fvxr; x++) { |
| 125 |
+ |
l = plum(fovscan(y)[x]); |
| 126 |
+ |
if (l < lwmin) continue; |
| 127 |
+ |
if (l > lwmax) continue; |
| 128 |
+ |
b = Bl(l); |
| 129 |
+ |
bwavg += b; |
| 130 |
+ |
w = what2do&DO_CWEIGHT ? centprob(x,y) : 1.; |
| 131 |
+ |
bwhist[bwhi(b)] += w; |
| 132 |
+ |
histot += w; |
| 133 |
+ |
} |
| 134 |
+ |
/* average fixation points */ |
| 135 |
+ |
if (what2do&DO_FIXHIST && nfixations > 0) { |
| 136 |
+ |
if (histot > FTINY) |
| 137 |
+ |
w = fixfrac/(1.-fixfrac)*histot/nfixations; |
| 138 |
+ |
else |
| 139 |
+ |
w = 1.; |
| 140 |
+ |
for (x = 0; x < nfixations; x++) { |
| 141 |
+ |
l = plum(fovscan(fixlst[x][1])[fixlst[x][0]]); |
| 142 |
+ |
if (l < lwmin) continue; |
| 143 |
+ |
if (l > lwmax) continue; |
| 144 |
+ |
b = Bl(l); |
| 145 |
+ |
bwavg += b; |
| 146 |
+ |
bwhist[bwhi(b)] += w; |
| 147 |
+ |
histot += w; |
| 148 |
+ |
} |
| 149 |
+ |
} |
| 150 |
+ |
bwavg /= histot; |
| 151 |
+ |
} |
| 152 |
+ |
|
| 153 |
+ |
|
| 154 |
|
mkcumf() /* make cumulative distribution function */ |
| 155 |
|
{ |
| 156 |
|
register int i; |