ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcond4.c
Revision: 3.1
Committed: Thu Oct 3 16:52:51 1996 UTC (27 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 /* Copyright (c) 1996 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Routines for veiling glare and loss of acuity.
9 */
10
11 #include "pcond.h"
12
13
14 #define VADAPT 0.08 /* fraction of adaptation from veil */
15
16 extern COLOR *fovimg; /* foveal (1 degree) averaged image */
17 extern short fvxr, fvyr; /* foveal image resolution */
18
19 #define fovscan(y) (fovimg+(y)*fvxr)
20
21 static COLOR *veilimg; /* veiling image */
22
23 #define veilscan(y) (veilimg+(y)*fvxr)
24
25 static FVECT *raydir = NULL; /* ray direction for each pixel */
26
27 #define rdirscan(y) (raydir+(y)*fvxr)
28
29
30 compraydir() /* compute ray directions */
31 {
32 FVECT rorg;
33 double h, v;
34 register int x, y;
35
36 if (raydir != NULL) /* already done? */
37 return;
38 raydir = (FVECT *)malloc(fvxr*fvyr*sizeof(FVECT));
39 if (raydir == NULL)
40 syserror("malloc");
41
42 for (y = 0; y < fvyr; y++) {
43 switch (inpres.or) {
44 case YMAJOR: case YMAJOR|XDECR:
45 v = (y+.5)/fvyr; break;
46 case YMAJOR|YDECR: case YMAJOR|YDECR|XDECR:
47 v = 1. - (y+.5)/fvyr; break;
48 case 0: case YDECR:
49 h = (y+.5)/fvyr; break;
50 case XDECR: case XDECR|YDECR:
51 h = 1. - (y+.5)/fvyr; break;
52 }
53 for (x = 0; x < fvxr; x++) {
54 switch (inpres.or) {
55 case YMAJOR: case YMAJOR|YDECR:
56 h = (x+.5)/fvxr; break;
57 case YMAJOR|XDECR: case YMAJOR|XDECR|YDECR:
58 h = 1. - (x+.5)/fvxr; break;
59 case 0: case XDECR:
60 v = (x+.5)/fvxr; break;
61 case YDECR: case YDECR|XDECR:
62 v = 1. - (x+.5)/fvxr; break;
63 }
64 if (viewray(rorg, rdirscan(y)[x], &ourview, h, v)
65 < -FTINY) {
66 rdirscan(y)[x][0] =
67 rdirscan(y)[x][1] =
68 rdirscan(y)[x][2] = 0.0;
69 }
70 }
71 }
72 }
73
74
75 compveil() /* compute veiling image */
76 {
77 double t2, t2sum;
78 COLOR ctmp, vsum;
79 int px, py;
80 register int x, y;
81 /* compute ray directions */
82 compraydir();
83 /* compute veil image */
84 veilimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR));
85 if (veilimg == NULL)
86 syserror("malloc");
87 for (py = 0; py < fvyr; py++)
88 for (px = 0; px < fvxr; px++) {
89 t2sum = 0.;
90 setcolor(vsum, 0., 0., 0.);
91 for (y = 0; y < fvyr; y++)
92 for (x = 0; x < fvxr; x++) {
93 if (x == px && y == py) continue;
94 t2 = DOT(rdirscan(py)[px],
95 rdirscan(y)[x]);
96 if (t2 <= FTINY) continue;
97 t2 = acos(t2);
98 t2 = 1./(t2*t2);
99 copycolor(ctmp, fovscan(y)[x]);
100 scalecolor(ctmp, t2);
101 addcolor(vsum, ctmp);
102 t2sum += t2;
103 }
104 /* VADAPT of original is subtracted in addveil() */
105 scalecolor(vsum, VADAPT/t2sum);
106 copycolor(veilscan(py)[px], vsum);
107 }
108 }
109
110
111 addveil(sl, y) /* add veil to scanline */
112 COLOR *sl;
113 int y;
114 {
115 int vx, vy;
116 double dx, dy;
117 double lv, uv;
118 register int x, i;
119
120 vy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
121 if (vy >= fvyr-1) vy--;
122 dy -= (double)vy;
123 for (x = 0; x < scanlen(&inpres); x++) {
124 vx = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
125 if (vx >= fvxr-1) vx--;
126 dx -= (double)vx;
127 for (i = 0; i < 3; i++) {
128 lv = (1.-dy)*colval(veilscan(vy)[vx],i) +
129 dy*colval(veilscan(vy+1)[vx],i);
130 uv = (1.-dy)*colval(veilscan(vy)[vx+1],i) +
131 dy*colval(veilscan(vy+1)[vx+1],i);
132 colval(sl[x],i) = (1.-VADAPT)*colval(sl[x],i) +
133 (1.-dx)*lv + dx*uv;
134 }
135 }
136 }