ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/image.c
Revision: 1.1
Committed: Thu Feb 2 10:34:34 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 /* Copyright (c) 1986 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * image.c - routines for image generation.
9 *
10 * 10/17/85
11 */
12
13 #include "standard.h"
14
15 #include "color.h"
16
17 #include "view.h"
18
19 VIEW stdview = STDVIEW(512); /* default view parameters */
20
21
22 bigdiff(c1, c2, md) /* c1 delta c2 > md? */
23 register COLOR c1, c2;
24 double md;
25 {
26 register int i;
27
28 for (i = 0; i < 3; i++)
29 if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) ||
30 colval(c2,i)-colval(c1,i) > md*colval(c1,i))
31 return(1);
32 return(0);
33 }
34
35
36 char *
37 setview(v) /* set vhinc and vvinc, return message on error */
38 register VIEW *v;
39 {
40 double tan(), dt;
41
42 if (normalize(v->vdir) == 0.0) /* normalize direction */
43 return("zero view direction");
44
45 fcross(v->vhinc, v->vdir, v->vup); /* compute horiz dir */
46
47 if (normalize(v->vhinc) == 0.0)
48 return("illegal view up vector");
49
50 fcross(v->vvinc, v->vhinc, v->vdir); /* compute vert dir */
51
52 if (v->type == VT_PAR)
53 dt = v->horiz;
54 else if (v->type == VT_PER)
55 dt = 2.0 * tan(v->horiz*(PI/180.0/2.0));
56 else
57 return("unknown view type");
58
59 if (dt <= FTINY || dt >= FHUGE)
60 return("illegal horizontal view size");
61
62 if (v->hresolu <= 0)
63 return("illegal horizontal resolution");
64
65 dt /= (double)v->hresolu;
66 v->vhinc[0] *= dt;
67 v->vhinc[1] *= dt;
68 v->vhinc[2] *= dt;
69
70 if (v->type == VT_PAR)
71 dt = v->vert;
72 else
73 dt = 2.0 * tan(v->vert*(PI/180.0/2.0));
74
75 if (dt <= FTINY || dt >= FHUGE)
76 return("illegal vertical view size");
77
78 if (v->vresolu <= 0)
79 return("illegal vertical resolution");
80
81 dt /= (double)v->vresolu;
82 v->vvinc[0] *= dt;
83 v->vvinc[1] *= dt;
84 v->vvinc[2] *= dt;
85
86 return(NULL);
87 }
88
89
90 rayview(orig, direc, v, x, y) /* compute ray origin and direction */
91 FVECT orig, direc;
92 register VIEW *v;
93 double x, y;
94 {
95 register int i;
96
97 x -= 0.5 * v->hresolu;
98 y -= 0.5 * v->vresolu;
99
100 if (v->type == VT_PAR) { /* parallel view */
101 for (i = 0; i < 3; i++)
102 orig[i] = v->vp[i] + x*v->vhinc[i] + y*v->vvinc[i];
103 VCOPY(direc, v->vdir);
104 } else { /* perspective view */
105 VCOPY(orig, v->vp);
106 for (i = 0; i < 3; i++)
107 direc[i] = v->vdir[i] + x*v->vhinc[i] + y*v->vvinc[i];
108 normalize(direc);
109 }
110 }
111
112
113 sscanview(vp, s) /* get view parameters */
114 register VIEW *vp;
115 register char *s;
116 {
117 for ( ; ; )
118 switch (*s++) {
119 case '\0':
120 case '\n':
121 return(0);
122 case '-':
123 switch (*s++) {
124 case '\0':
125 return(-1);
126 case 'x':
127 if (sscanf(s, "%d", &vp->hresolu) != 1)
128 return(-1);
129 s = sskip(s);
130 continue;
131 case 'y':
132 if (sscanf(s, "%d", &vp->vresolu) != 1)
133 return(-1);
134 s = sskip(s);
135 continue;
136 case 'v':
137 switch (*s++) {
138 case '\0':
139 return(-1);
140 case 't':
141 vp->type = *s++;
142 continue;
143 case 'p':
144 if (sscanf(s, "%lf %lf %lf",
145 &vp->vp[0],
146 &vp->vp[1],
147 &vp->vp[2]) != 3)
148 return(-1);
149 s = sskip(sskip(sskip(s)));
150 continue;
151 case 'd':
152 if (sscanf(s, "%lf %lf %lf",
153 &vp->vdir[0],
154 &vp->vdir[1],
155 &vp->vdir[2]) != 3)
156 return(-1);
157 s = sskip(sskip(sskip(s)));
158 continue;
159 case 'u':
160 if (sscanf(s, "%lf %lf %lf",
161 &vp->vup[0],
162 &vp->vup[1],
163 &vp->vup[2]) != 3)
164 return(-1);
165 s = sskip(sskip(sskip(s)));
166 continue;
167 case 'h':
168 if (sscanf(s, "%lf",
169 &vp->horiz) != 1)
170 return(-1);
171 s = sskip(s);
172 continue;
173 case 'v':
174 if (sscanf(s, "%lf",
175 &vp->vert) != 1)
176 return(-1);
177 s = sskip(s);
178 continue;
179 }
180 continue;
181 }
182 continue;
183 }
184 }
185
186
187 fprintview(vp, fp) /* write out view parameters */
188 register VIEW *vp;
189 FILE *fp;
190 {
191 fprintf(fp, " -vt%c", vp->type);
192 fprintf(fp, " -vp %.6g %.6g %.6g", vp->vp[0], vp->vp[1], vp->vp[2]);
193 fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
194 fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
195 fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
196 fprintf(fp, " -x %d -y %d", vp->hresolu, vp->vresolu);
197 }
198
199
200 static VIEW *hview; /* view from header */
201 static int gothview; /* success indicator */
202 static char *altname[] = {NULL,"rpict","rview",VIEWSTR,NULL};
203
204
205 static
206 gethview(s) /* get view from header */
207 char *s;
208 {
209 register char **an;
210
211 for (an = altname; *an != NULL; an++)
212 if (!strncmp(*an, s, strlen(*an))) {
213 if (sscanview(hview, s+strlen(*an)) == 0)
214 gothview++;
215 return;
216 }
217 }
218
219
220 int
221 viewfile(fname, vp) /* get view from file */
222 char *fname;
223 VIEW *vp;
224 {
225 extern char *progname;
226 FILE *fp;
227
228 if ((fp = fopen(fname, "r")) == NULL)
229 return(-1);
230
231 altname[0] = progname;
232 hview = vp;
233 gothview = 0;
234
235 getheader(fp, gethview);
236
237 fclose(fp);
238
239 return(gothview);
240 }