ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcond4.c
Revision: 3.2
Committed: Thu Oct 3 20:14:20 1996 UTC (27 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.1: +9 -5 lines
Log Message:
decreased size of raydir array by changing from FVECT to float

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 float (*raydir)[3] = 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, rdir;
33 double h, v;
34 register int x, y;
35
36 if (raydir != NULL) /* already done? */
37 return;
38 raydir = (float (*)[3])malloc(fvxr*fvyr*3*sizeof(float));
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, rdir, &ourview, h, v)
65 >= -FTINY) {
66 rdirscan(y)[x][0] = rdir[0];
67 rdirscan(y)[x][1] = rdir[1];
68 rdirscan(y)[x][2] = rdir[2];
69 } else {
70 rdirscan(y)[x][0] =
71 rdirscan(y)[x][1] =
72 rdirscan(y)[x][2] = 0.0;
73 }
74 }
75 }
76 }
77
78
79 compveil() /* compute veiling image */
80 {
81 double t2, t2sum;
82 COLOR ctmp, vsum;
83 int px, py;
84 register int x, y;
85 /* compute ray directions */
86 compraydir();
87 /* compute veil image */
88 veilimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR));
89 if (veilimg == NULL)
90 syserror("malloc");
91 for (py = 0; py < fvyr; py++)
92 for (px = 0; px < fvxr; px++) {
93 t2sum = 0.;
94 setcolor(vsum, 0., 0., 0.);
95 for (y = 0; y < fvyr; y++)
96 for (x = 0; x < fvxr; x++) {
97 if (x == px && y == py) continue;
98 t2 = DOT(rdirscan(py)[px],
99 rdirscan(y)[x]);
100 if (t2 <= FTINY) continue;
101 t2 = acos(t2);
102 t2 = 1./(t2*t2);
103 copycolor(ctmp, fovscan(y)[x]);
104 scalecolor(ctmp, t2);
105 addcolor(vsum, ctmp);
106 t2sum += t2;
107 }
108 /* VADAPT of original is subtracted in addveil() */
109 scalecolor(vsum, VADAPT/t2sum);
110 copycolor(veilscan(py)[px], vsum);
111 }
112 }
113
114
115 addveil(sl, y) /* add veil to scanline */
116 COLOR *sl;
117 int y;
118 {
119 int vx, vy;
120 double dx, dy;
121 double lv, uv;
122 register int x, i;
123
124 vy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
125 if (vy >= fvyr-1) vy--;
126 dy -= (double)vy;
127 for (x = 0; x < scanlen(&inpres); x++) {
128 vx = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
129 if (vx >= fvxr-1) vx--;
130 dx -= (double)vx;
131 for (i = 0; i < 3; i++) {
132 lv = (1.-dy)*colval(veilscan(vy)[vx],i) +
133 dy*colval(veilscan(vy+1)[vx],i);
134 uv = (1.-dy)*colval(veilscan(vy)[vx+1],i) +
135 dy*colval(veilscan(vy+1)[vx+1],i);
136 colval(sl[x],i) = (1.-VADAPT)*colval(sl[x],i) +
137 (1.-dx)*lv + dx*uv;
138 }
139 }
140 }