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

Comparing ray/src/px/pcond4.c (file contents):
Revision 3.2 by greg, Thu Oct 3 20:14:20 1996 UTC vs.
Revision 3.9 by greg, Thu Oct 10 16:36:39 1996 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "pcond.h"
12  
13 + /************** VEILING STUFF *****************/
14  
15   #define VADAPT          0.08            /* fraction of adaptation from veil */
16  
# Line 98 | Line 99 | compveil()                             /* compute veiling image */
99                                          t2 = DOT(rdirscan(py)[px],
100                                                          rdirscan(y)[x]);
101                                          if (t2 <= FTINY) continue;
102 +                                        /*      use approximation instead
103                                          t2 = acos(t2);
104                                          t2 = 1./(t2*t2);
105 +                                        */
106 +                                        t2 = .5 / (1. - t2);
107                                          copycolor(ctmp, fovscan(y)[x]);
108                                          scalecolor(ctmp, t2);
109                                          addcolor(vsum, ctmp);
# Line 122 | Line 126 | int    y;
126          register int    x, i;
127  
128          vy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
129 <        if (vy >= fvyr-1) vy--;
129 >        while (vy >= fvyr-1) vy--;
130          dy -= (double)vy;
131          for (x = 0; x < scanlen(&inpres); x++) {
132                  vx = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
133 <                if (vx >= fvxr-1) vx--;
133 >                while (vx >= fvxr-1) vx--;
134                  dx -= (double)vx;
135                  for (i = 0; i < 3; i++) {
136                          lv = (1.-dy)*colval(veilscan(vy)[vx],i) +
# Line 137 | Line 141 | int    y;
141                                          (1.-dx)*lv + dx*uv;
142                  }
143          }
144 + }
145 +
146 +
147 + /****************** ACUITY STUFF *******************/
148 +
149 + typedef struct {
150 +        short   sampe;          /* sample area size (exponent of 2) */
151 +        short   nscans;         /* number of scanlines in this bar */
152 +        int     len;            /* individual scanline length */
153 +        int     nread;          /* number of scanlines loaded */
154 +        COLOR   *sdata;         /* scanbar data */
155 + } SCANBAR;
156 +
157 + #define bscan(sb,y)     ((COLOR *)(sb)->sdata+((y)%(sb)->nscans)*(sb)->len)
158 +
159 + SCANBAR *rootbar;               /* root scan bar (lowest resolution) */
160 +
161 + float   *inpacuD;               /* input acuity data (cycles/degree) */
162 +
163 + #define tsampr(x,y)     inpacuD[(y)*fvxr+(x)]
164 +
165 +
166 + double
167 + hacuity(La)                     /* return visual acuity in cycles/degree */
168 + double  La;
169 + {                               /* data due to S. Shaler (we should fit it!) */
170 + #define NPOINTS 20
171 +        static float    l10lum[NPOINTS] = {
172 +                -3.10503,-2.66403,-2.37703,-2.09303,-1.64403,-1.35803,
173 +                -1.07403,-0.67203,-0.38503,-0.10103,0.29397,0.58097,0.86497,
174 +                1.25697,1.54397,1.82797,2.27597,2.56297,2.84697,3.24897
175 +        };
176 +        static float    resfreq[NPOINTS] = {
177 +                2.09,3.28,3.79,4.39,6.11,8.83,10.94,18.66,23.88,31.05,37.42,
178 +                37.68,41.60,43.16,45.30,47.00,48.43,48.32,51.06,51.09
179 +        };
180 +        double  l10La;
181 +        register int    i;
182 +                                        /* check limits */
183 +        if (La <= 7.85e-4)
184 +                return(resfreq[0]);
185 +        if (La >= 1.78e3)
186 +                return(resfreq[NPOINTS-1]);
187 +                                        /* interpolate data */
188 +        l10La = log10(La);
189 +        for (i = 0; i < NPOINTS-2 && l10lum[i+1] <= l10La; i++)
190 +                ;
191 +        return( ( (l10lum[i+1] - l10La)*resfreq[i] +
192 +                        (l10La - l10lum[i])*resfreq[i+1] ) /
193 +                        (l10lum[i+1] - l10lum[i]) );
194 + #undef NPOINTS
195 + }
196 +
197 +
198 + COLOR *
199 + getascan(sb, y)                 /* find/read scanline y for scanbar sb */
200 + register SCANBAR        *sb;
201 + int     y;
202 + {
203 +        register COLOR  *sl0, *sl1, *mysl;
204 +        register int    i;
205 +
206 +        if (y < sb->nread - sb->nscans)                 /* too far back? */
207 +                return(NULL);
208 +        for ( ; y >= sb->nread; sb->nread++) {          /* read as necessary */
209 +                mysl = bscan(sb, sb->nread);
210 +                if (sb->sampe == 0) {
211 +                        if (freadscan(mysl, sb->len, infp) < 0) {
212 +                                fprintf(stderr, "%s: %s: scanline read error\n",
213 +                                                progname, infn);
214 +                                exit(1);
215 +                        }
216 +                } else {
217 +                        sl0 = getascan(sb+1, 2*y);
218 +                        if (sl0 == NULL)
219 +                                return(NULL);
220 +                        sl1 = getascan(sb+1, 2*y+1);
221 +                        for (i = 0; i < sb->len; i++) {
222 +                                copycolor(mysl[i], sl0[2*i]);
223 +                                addcolor(mysl[i], sl0[2*i+1]);
224 +                                addcolor(mysl[i], sl1[2*i]);
225 +                                addcolor(mysl[i], sl1[2*i+1]);
226 +                                scalecolor(mysl[i], 0.25);
227 +                        }
228 +                }
229 +        }
230 +        return(bscan(sb, y));
231 + }
232 +
233 +
234 + acuscan(scln, y)                /* get acuity-sampled scanline */
235 + COLOR   *scln;
236 + int     y;
237 + {
238 +        double  sr;
239 +        double  dx, dy;
240 +        int     ix, iy;
241 +        register int    x;
242 +                                        /* compute foveal y position */
243 +        iy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
244 +        while (iy >= fvyr-1) iy--;
245 +        dy -= (double)iy;
246 +        for (x = 0; x < scanlen(&inpres); x++) {
247 +                                        /* compute foveal x position */
248 +                ix = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
249 +                while (ix >= fvxr-1) ix--;
250 +                dx -= (double)ix;
251 +                                        /* interpolate sample rate */
252 +                sr = (1.-dy)*((1.-dx)*tsampr(ix,iy) + dx*tsampr(ix+1,iy)) +
253 +                        dy*((1.-dx)*tsampr(ix,iy+1) + dx*tsampr(ix+1,iy+1));
254 +
255 +                acusample(scln[x], x, y, sr);   /* compute sample */
256 +        }
257 + }
258 +
259 +
260 + acusample(col, x, y, sr)        /* interpolate sample at (x,y) using rate sr */
261 + COLOR   col;
262 + int     x, y;
263 + double  sr;
264 + {
265 +        COLOR   c1;
266 +        double  d;
267 +        register SCANBAR        *sb0;
268 +
269 +        for (sb0 = rootbar; sb0->sampe != 0 && 1<<sb0[1].sampe > sr; sb0++)
270 +                ;
271 +        ascanval(col, x, y, sb0);
272 +        if (sb0->sampe == 0)            /* don't extrapolate highest */
273 +                return;
274 +        ascanval(c1, x, y, sb0+1);
275 +        d = ((1<<sb0->sampe) - sr)/(1<<sb0[1].sampe);
276 +        scalecolor(col, 1.-d);
277 +        scalecolor(c1, d);
278 +        addcolor(col, c1);
279 + }
280 +
281 +
282 + ascanval(col, x, y, sb)         /* interpolate scanbar at orig. coords (x,y) */
283 + COLOR   col;
284 + int     x, y;
285 + SCANBAR *sb;
286 + {
287 +        COLOR   *sl0, *sl1, c1, c1y;
288 +        double  dx, dy;
289 +        int     ix, iy;
290 +
291 +        if (sb->sampe == 0) {           /* no need to interpolate */
292 +                sl0 = getascan(sb, y);
293 +                copycolor(col, sl0[x]);
294 +                return;
295 +        }
296 +                                        /* compute coordinates for sb */
297 +        ix = dx = (x+.5)/(1<<sb->sampe) - .5;
298 +        while (ix >= sb->len-1) ix--;
299 +        dx -= (double)ix;
300 +        iy = dy = (y+.5)/(1<<sb->sampe) - .5;
301 +        while (iy >= (numscans(&inpres)>>sb->sampe)-1) iy--;
302 +        dy -= (double)iy;
303 +                                        /* get scanlines */
304 +        sl0 = getascan(sb, iy);
305 + #ifdef DEBUG
306 +        if (sl0 == NULL) {
307 +                fprintf(stderr, "%s: internal - cannot backspace in ascanval\n",
308 +                                progname);
309 +                abort();
310 +        }
311 + #endif
312 +        sl1 = getascan(sb, iy+1);
313 +                                        /* 2D linear interpolation */
314 +        copycolor(col, sl0[ix]);
315 +        scalecolor(col, 1.-dx);
316 +        copycolor(c1, sl0[ix+1]);
317 +        scalecolor(c1, dx);
318 +        addcolor(col, c1);
319 +        copycolor(c1y, sl1[ix]);
320 +        scalecolor(c1y, 1.-dx);
321 +        copycolor(c1, sl1[ix+1]);
322 +        scalecolor(c1, dx);
323 +        addcolor(c1y, c1);
324 +        scalecolor(col, 1.-dy);
325 +        scalecolor(c1y, dy);
326 +        addcolor(col, c1y);
327 +        for (ix = 0; ix < 3; ix++)      /* make sure no negative */
328 +                if (colval(col,ix) < 0.)
329 +                        colval(col,ix) = 0.;
330 + }
331 +
332 +
333 + SCANBAR *
334 + sballoc(se, ns, sl)             /* allocate scanbar */
335 + int     se;             /* sampling rate exponent */
336 + int     ns;             /* number of scanlines */
337 + int     sl;             /* original scanline length */
338 + {
339 +        SCANBAR *sbarr;
340 +        register SCANBAR        *sb;
341 +
342 +        sbarr = sb = (SCANBAR *)malloc((se+1)*sizeof(SCANBAR));
343 +        if (sb == NULL)
344 +                syserror("malloc");
345 +        do {
346 +                sb->sampe = se;
347 +                sb->len = sl>>se;
348 +                sb->nscans = ns;
349 +                sb->sdata = (COLOR *)malloc(sb->len*ns*sizeof(COLOR));
350 +                if (sb->sdata == NULL)
351 +                        syserror("malloc");
352 +                sb->nread = 0;
353 +                ns <<= 1;
354 +                sb++;
355 +        } while (--se >= 0);
356 +        return(sbarr);
357 + }
358 +
359 +
360 + initacuity()                    /* initialize variable acuity sampling */
361 + {
362 +        FVECT   diffx, diffy, cp;
363 +        double  omega, maxsr;
364 +        register int    x, y, i;
365 +
366 +        compraydir();                   /* compute ray directions */
367 +
368 +        inpacuD = (float *)malloc(fvxr*fvyr*sizeof(float));
369 +        if (inpacuD == NULL)
370 +                syserror("malloc");
371 +        maxsr = 1.;                     /* compute internal sample rates */
372 +        for (y = 1; y < fvyr-1; y++)
373 +                for (x = 1; x < fvxr-1; x++) {
374 +                        for (i = 0; i < 3; i++) {
375 +                                diffx[i] = 0.5*fvxr/scanlen(&inpres) *
376 +                                                (rdirscan(y)[x+1][i] -
377 +                                                rdirscan(y)[x-1][i]);
378 +                                diffy[i] = 0.5*fvyr/numscans(&inpres) *
379 +                                                (rdirscan(y+1)[x][i] -
380 +                                                rdirscan(y-1)[x][i]);
381 +                        }
382 +                        fcross(cp, diffx, diffy);
383 +                        omega = 0.5 * sqrt(DOT(cp,cp));
384 +                        if (omega <= FTINY)
385 +                                tsampr(x,y) = 1.;
386 +                        else if ((tsampr(x,y) = PI/180. / sqrt(omega) /
387 +                                        hacuity(plum(fovscan(y)[x]))) > maxsr)
388 +                                maxsr = tsampr(x,y);
389 +                }
390 +                                        /* copy perimeter (easier) */
391 +        for (x = 1; x < fvxr-1; x++) {
392 +                tsampr(x,0) = tsampr(x,1);
393 +                tsampr(x,fvyr-1) = tsampr(x,fvyr-2);
394 +        }
395 +        for (y = 0; y < fvyr; y++) {
396 +                tsampr(0,y) = tsampr(1,y);
397 +                tsampr(fvxr-1,y) = tsampr(fvxr-2,y);
398 +        }
399 +                                        /* initialize with next power of two */
400 +        rootbar = sballoc((int)(log(maxsr)/log(2.))+1, 2, scanlen(&inpres));
401   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines