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.1 by greg, Thu Oct 3 16:52:51 1996 UTC vs.
Revision 3.6 by greg, Sat Oct 5 08:05:27 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 22 | Line 23 | static COLOR   *veilimg;               /* veiling image */
23  
24   #define veilscan(y)     (veilimg+(y)*fvxr)
25  
26 < static FVECT    *raydir = NULL;         /* ray direction for each pixel */
26 > static float    (*raydir)[3] = NULL;    /* ray direction for each pixel */
27  
28   #define rdirscan(y)     (raydir+(y)*fvxr)
29  
30  
31   compraydir()                            /* compute ray directions */
32   {
33 <        FVECT   rorg;
33 >        FVECT   rorg, rdir;
34          double  h, v;
35          register int    x, y;
36  
37          if (raydir != NULL)             /* already done? */
38                  return;
39 <        raydir = (FVECT *)malloc(fvxr*fvyr*sizeof(FVECT));
39 >        raydir = (float (*)[3])malloc(fvxr*fvyr*3*sizeof(float));
40          if (raydir == NULL)
41                  syserror("malloc");
42  
# Line 61 | Line 62 | compraydir()                           /* compute ray directions */
62                          case YDECR: case YDECR|XDECR:
63                                  v = 1. - (x+.5)/fvxr; break;
64                          }
65 <                        if (viewray(rorg, rdirscan(y)[x], &ourview, h, v)
66 <                                        < -FTINY) {
65 >                        if (viewray(rorg, rdir, &ourview, h, v)
66 >                                        >= -FTINY) {
67 >                                rdirscan(y)[x][0] = rdir[0];
68 >                                rdirscan(y)[x][1] = rdir[1];
69 >                                rdirscan(y)[x][2] = rdir[2];
70 >                        } else {
71                                  rdirscan(y)[x][0] =
72                                  rdirscan(y)[x][1] =
73                                  rdirscan(y)[x][2] = 0.0;
# Line 94 | 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 133 | Line 141 | int    y;
141                                          (1.-dx)*lv + dx*uv;
142                  }
143          }
144 + }
145 +
146 +
147 + /****************** ACUITY STUFF *******************/
148 +
149 + typedef struct scanbar {
150 +        short   sampr;          /* sample area size (power of 2) */
151 +        short   nscans;         /* number of scanlines in this bar */
152 +        int     len;            /* individual scanline length */
153 +        struct scanbar  *next;  /* next higher resolution scanbar */
154 +        int     nread;          /* number of scanlines loaded */
155 +                        /* followed by the scanline data */
156 + } SCANBAR;
157 +
158 + #define bscan(sb,y)     ((COLOR *)((sb)+1)+((y)%(sb)->nscans)*(sb)->len)
159 +
160 + SCANBAR *rootbar;               /* root scan bar (lowest resolution) */
161 +
162 + float   *inpacuD;               /* input acuity data (cycles/degree) */
163 +
164 + #define tsampr(x,y)     inpacuD[(y)*fvxr+(x)]
165 +
166 +
167 + double
168 + hacuity(La)                     /* return visual acuity in cycles/degree */
169 + double  La;
170 + {                               /* data due to S. Shaler (we should fit it!) */
171 + #define NPOINTS 20
172 +        static float    l10lum[NPOINTS] = {
173 +                -3.10503,-2.66403,-2.37703,-2.09303,-1.64403,-1.35803,
174 +                -1.07403,-0.67203,-0.38503,-0.10103,0.29397,0.58097,0.86497,
175 +                1.25697,1.54397,1.82797,2.27597,2.56297,2.84697,3.24897
176 +        };
177 +        static float    resfreq[NPOINTS] = {
178 +                2.09,3.28,3.79,4.39,6.11,8.83,10.94,18.66,23.88,31.05,37.42,
179 +                37.68,41.60,43.16,45.30,47.00,48.43,48.32,51.06,51.09
180 +        };
181 +        double  l10La;
182 +        register int    i;
183 +                                        /* check limits */
184 +        if (La <= 7.85e-4)
185 +                return(resfreq[0]);
186 +        if (La >= 1.78e3)
187 +                return(resfreq[NPOINTS-1]);
188 +                                        /* interpolate data */
189 +        l10La = log10(La);
190 +        for (i = 0; i < NPOINTS-2 && l10lum[i+1] <= l10La; i++)
191 +                ;
192 +        return( ( (l10lum[i+1] - l10La)*resfreq[i] +
193 +                        (l10La - l10lum[i])*resfreq[i+1] ) /
194 +                        (l10lum[i+1] - l10lum[i]) );
195 + #undef NPOINTS
196 + }
197 +
198 +
199 + COLOR *
200 + getascan(sb, y)                 /* find/read scanline y for scanbar sb */
201 + register SCANBAR        *sb;
202 + int     y;
203 + {
204 +        register COLOR  *sl0, *sl1, *mysl;
205 +        register int    i;
206 +
207 +        if (y < sb->nread - sb->nscans)                 /* too far back? */
208 +                return(NULL);
209 +        for ( ; y >= sb->nread; sb->nread++) {          /* read as necessary */
210 +                mysl = bscan(sb, sb->nread);
211 +                if (sb->sampr == 1) {
212 +                        if (freadscan(mysl, sb->len, infp) < 0) {
213 +                                fprintf(stderr, "%s: %s: scanline read error\n",
214 +                                                progname, infn);
215 +                                exit(1);
216 +                        }
217 +                } else {
218 +                        sl0 = getascan(sb->next, 2*y);
219 +                        if (sl0 == NULL)
220 +                                return(NULL);
221 +                        sl1 = getascan(sb->next, 2*y+1);
222 +                        for (i = 0; i < sb->len; i++) {
223 +                                copycolor(mysl[i], sl0[2*i]);
224 +                                addcolor(mysl[i], sl0[2*i+1]);
225 +                                addcolor(mysl[i], sl1[2*i]);
226 +                                addcolor(mysl[i], sl1[2*i+1]);
227 +                                scalecolor(mysl[i], 0.25);
228 +                        }
229 +                }
230 +        }
231 +        return(bscan(sb, y));
232 + }
233 +
234 +
235 + acuscan(scln, y)                /* get acuity-sampled scanline */
236 + COLOR   *scln;
237 + int     y;
238 + {
239 +        double  sr;
240 +        double  dx, dy;
241 +        int     ix, iy;
242 +        register int    x;
243 +                                        /* compute foveal y position */
244 +        iy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
245 +        if (iy >= fvyr-1) iy--;
246 +        dy -= (double)iy;
247 +        for (x = 0; x < scanlen(&inpres); x++) {
248 +                                        /* compute foveal x position */
249 +                ix = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
250 +                if (ix >= fvxr-1) ix--;
251 +                dx -= (double)ix;
252 +                                        /* interpolate sample rate */
253 +                sr = (1.-dy)*((1.-dx)*tsampr(ix,iy) + dx*tsampr(ix+1,iy)) +
254 +                        dy*((1.-dx)*tsampr(ix,iy+1) + dx*tsampr(ix+1,iy+1));
255 +
256 +                acusample(scln[x], x, y, sr);   /* compute sample */
257 +        }
258 + }
259 +
260 +
261 + acusample(col, x, y, sr)        /* interpolate sample at (x,y) using rate sr */
262 + COLOR   col;
263 + int     x, y;
264 + double  sr;
265 + {
266 +        COLOR   c1;
267 +        double  d;
268 +        register SCANBAR        *sb0;
269 +
270 +        for (sb0 = rootbar; sb0->next != NULL && sb0->next->sampr > sr;
271 +                        sb0 = sb0->next)
272 +                ;
273 +        ascanval(col, x, y, sb0);
274 +        if (sb0->next == NULL)          /* don't extrapolate highest */
275 +                return;
276 +        ascanval(c1, x, y, sb0->next);
277 +        d = (sb0->sampr - sr)/(sb0->sampr - sb0->next->sampr);
278 +        scalecolor(col, 1.-d);
279 +        scalecolor(c1, d);
280 +        addcolor(col, c1);
281 + }
282 +
283 +
284 + ascanval(col, x, y, sb)         /* interpolate scanbar at orig. coords (x,y) */
285 + COLOR   col;
286 + int     x, y;
287 + SCANBAR *sb;
288 + {
289 +        COLOR   *sl0, *sl1, c1, c1y;
290 +        double  dx, dy;
291 +        int     ix, iy;
292 +
293 +        if (sb->sampr == 1) {           /* no need to interpolate */
294 +                sl0 = getascan(sb, y);
295 +                copycolor(col, sl0[x]);
296 +                return;
297 +        }
298 +                                        /* compute coordinates for sb */
299 +        ix = dx = (x+.5)/sb->sampr - .5;
300 +        if (ix >= sb->len-1) ix--;
301 +        dx -= (double)ix;
302 +        iy = dy = (y+.5)/sb->sampr - .5;
303 +        if (iy >= numscans(&inpres)/sb->sampr-1) iy--;
304 +        dy -= (double)iy;
305 +                                        /* get scanlines */
306 +        sl0 = getascan(sb, iy);
307 +        if (sl0 == NULL) {
308 +                fprintf(stderr, "%s: internal - cannot backspace in ascanval\n",
309 +                                progname);
310 +                exit(1);
311 +        }
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 + }
328 +
329 +
330 + SCANBAR *
331 + sballoc(sr, ns, sl)             /* allocate scanbar */
332 + int     sr;             /* sampling rate */
333 + int     ns;             /* number of scanlines */
334 + int     sl;             /* original scanline length */
335 + {
336 +        register SCANBAR        *sb;
337 +
338 +        sb = (SCANBAR *)malloc(sizeof(SCANBAR)+(sl/sr)*ns*sizeof(COLOR));
339 +        if (sb == NULL)
340 +                syserror("malloc");
341 +        sb->nscans = ns;
342 +        sb->len = sl/sr;
343 +        sb->nread = 0;
344 +        if ((sb->sampr = sr) > 1)
345 +                sb->next = sballoc(sr/2, ns*2, sl);
346 +        else
347 +                sb->next = NULL;
348 +        return(sb);
349 + }
350 +
351 +
352 + initacuity()                    /* initialize variable acuity sampling */
353 + {
354 +        FVECT   diffx, diffy, cp;
355 +        double  omega, maxsr;
356 +        register int    x, y, i;
357 +
358 +        compraydir();                   /* compute ray directions */
359 +
360 +        inpacuD = (float *)malloc(fvxr*fvyr*sizeof(float));
361 +        if (inpacuD == NULL)
362 +                syserror("malloc");
363 +        maxsr = 1.;                     /* compute internal sample rates */
364 +        for (y = 1; y < fvyr-1; y++)
365 +                for (x = 1; x < fvxr-1; x++) {
366 +                        for (i = 0; i < 3; i++) {
367 +                                diffx[i] = 0.5*fvxr/scanlen(&inpres) *
368 +                                                (rdirscan(y)[x+1][i] -
369 +                                                rdirscan(y)[x-1][i]);
370 +                                diffy[i] = 0.5*fvyr/numscans(&inpres) *
371 +                                                (rdirscan(y+1)[x][i] -
372 +                                                rdirscan(y-1)[x][i]);
373 +                        }
374 +                        fcross(cp, diffx, diffy);
375 +                        omega = 0.5 * sqrt(DOT(cp,cp));
376 +                        if (omega <= FTINY)
377 +                                tsampr(x,y) = 1.;
378 +                        else if ((tsampr(x,y) = PI/180. / sqrt(omega) /
379 +                                        hacuity(plum(fovscan(y)[x]))) > maxsr)
380 +                                maxsr = tsampr(x,y);
381 +                }
382 +                                        /* copy perimeter (easier) */
383 +        for (x = 1; x < fvxr-1; x++) {
384 +                tsampr(x,0) = tsampr(x,1);
385 +                tsampr(x,fvyr-1) = tsampr(x,fvyr-2);
386 +        }
387 +        for (y = 0; y < fvyr; y++) {
388 +                tsampr(y,0) = tsampr(y,1);
389 +                tsampr(y,fvxr-1) = tsampr(y,fvxr-2);
390 +        }
391 +                                        /* initialize with next power of two */
392 +        rootbar = sballoc(2<<(int)(log(maxsr)/log(2.)), 2, scanlen(&inpres));
393   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines