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

Comparing ray/src/common/image.c (file contents):
Revision 1.3 by greg, Sun Dec 10 16:19:54 1989 UTC vs.
Revision 1.10 by greg, Thu Sep 13 08:34:15 1990 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *     10/17/85
11   */
12  
13 #include  <ctype.h>
14
13   #include  "standard.h"
14  
15   #include  "view.h"
16  
17 < VIEW  stdview = STDVIEW(512);           /* default view parameters */
17 > VIEW  stdview = STDVIEW;                /* default view parameters */
18  
19  
20   char *
21 < sskip(s)                /* skip a word */
24 < register char  *s;
25 < {
26 <        while (isspace(*s)) s++;
27 <        while (*s && !isspace(*s)) s++;
28 <        return(s);
29 < }
30 <
31 <
32 < char *
33 < setview(v)              /* set vhinc and vvinc, return message on error */
21 > setview(v)              /* set hvec and vvec, return message on error */
22   register VIEW  *v;
23   {
24 <        double  tan(), dt;
25 <        
24 >        extern double  tan(), normalize();
25 >
26          if (normalize(v->vdir) == 0.0)          /* normalize direction */
27                  return("zero view direction");
40                
41        fcross(v->vhinc, v->vdir, v->vup);      /* compute horiz dir */
28  
29 <        if (normalize(v->vhinc) == 0.0)
29 >        fcross(v->hvec, v->vdir, v->vup);       /* compute horiz dir */
30 >
31 >        if (normalize(v->hvec) == 0.0)
32                  return("illegal view up vector");
45                
46        fcross(v->vvinc, v->vhinc, v->vdir);    /* compute vert dir */
33  
34 +        fcross(v->vvec, v->hvec, v->vdir);      /* compute vert dir */
35 +
36          if (v->type == VT_PAR)
37 <                dt =  v->horiz;
37 >                v->hn2 = v->horiz;
38          else if (v->type == VT_PER)
39 <                dt = 2.0 * tan(v->horiz*(PI/180.0/2.0));
39 >                v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0));
40          else
41                  return("unknown view type");
42  
43 <        if (dt <= FTINY || dt >= FHUGE)
43 >        if (v->hn2 <= FTINY || v->hn2 >= FHUGE)
44                  return("illegal horizontal view size");
45  
46 <        if (v->hresolu <= 0)
47 <                return("illegal horizontal resolution");
46 >        v->hvec[0] *= v->hn2;
47 >        v->hvec[1] *= v->hn2;
48 >        v->hvec[2] *= v->hn2;
49 >        v->hn2 *= v->hn2;
50  
61        dt /= (double)v->hresolu;
62        v->vhinc[0] *= dt;
63        v->vhinc[1] *= dt;
64        v->vhinc[2] *= dt;
65
51          if (v->type == VT_PAR)
52 <                dt = v->vert;
52 >                v->vn2 = v->vert;
53          else
54 <                dt = 2.0 * tan(v->vert*(PI/180.0/2.0));
54 >                v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
55  
56 <        if (dt <= FTINY || dt >= FHUGE)
56 >        if (v->vn2 <= FTINY || v->vn2 >= FHUGE)
57                  return("illegal vertical view size");
58  
59 <        if (v->vresolu <= 0)
60 <                return("illegal vertical resolution");
61 <        
62 <        dt /= (double)v->vresolu;
78 <        v->vvinc[0] *= dt;
79 <        v->vvinc[1] *= dt;
80 <        v->vvinc[2] *= dt;
59 >        v->vvec[0] *= v->vn2;
60 >        v->vvec[1] *= v->vn2;
61 >        v->vvec[2] *= v->vn2;
62 >        v->vn2 *= v->vn2;
63  
82        v->vhs2 = 1.0/DOT(v->vhinc,v->vhinc);
83        v->vvs2 = 1.0/DOT(v->vvinc,v->vvinc);
84
64          return(NULL);
65   }
66  
67  
68 < rayview(orig, direc, v, x, y)           /* compute ray origin and direction */
68 > normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
69 > double  va;                     /* view aspect ratio */
70 > double  *ap;                    /* pixel aspect in (or out if 0) */
71 > int  *xp, *yp;                  /* x and y resolution in (or out if *ap!=0) */
72 > {
73 >        if (*ap <= FTINY)
74 >                *ap = va * *xp / *yp;           /* compute pixel aspect */
75 >        else if (va * *xp > *ap * *yp)
76 >                *xp = *yp / va * *ap + .5;      /* reduce x resolution */
77 >        else
78 >                *yp = *xp * va / *ap + .5;      /* reduce y resolution */
79 > }
80 >
81 >
82 > viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
83   FVECT  orig, direc;
84   register VIEW  *v;
85   double  x, y;
86   {
87 <        x -= 0.5 * v->hresolu;
88 <        y -= 0.5 * v->vresolu;
87 >        x += v->hoff - 0.5;
88 >        y += v->voff - 0.5;
89  
90          if (v->type == VT_PAR) {        /* parallel view */
91 <                orig[0] = v->vp[0] + x*v->vhinc[0] + y*v->vvinc[0];
92 <                orig[1] = v->vp[1] + x*v->vhinc[1] + y*v->vvinc[1];
93 <                orig[2] = v->vp[2] + x*v->vhinc[2] + y*v->vvinc[2];
91 >                orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0];
92 >                orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1];
93 >                orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2];
94                  VCOPY(direc, v->vdir);
95          } else {                        /* perspective view */
96                  VCOPY(orig, v->vp);
97 <                direc[0] = v->vdir[0] + x*v->vhinc[0] + y*v->vvinc[0];
98 <                direc[1] = v->vdir[1] + x*v->vhinc[1] + y*v->vvinc[1];
99 <                direc[2] = v->vdir[2] + x*v->vhinc[2] + y*v->vvinc[2];
97 >                direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
98 >                direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
99 >                direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
100                  normalize(direc);
101          }
102   }
103  
104  
105 < pixelview(xp, yp, zp, v, p)             /* find image location for point */
105 > viewpixel(xp, yp, zp, v, p)             /* find image location for point */
106   double  *xp, *yp, *zp;
107   register VIEW  *v;
108   FVECT  p;
# Line 117 | Line 110 | FVECT  p;
110          extern double  sqrt();
111          double  d;
112          FVECT  disp;
113 <        
113 >
114          disp[0] = p[0] - v->vp[0];
115          disp[1] = p[1] - v->vp[1];
116          disp[2] = p[2] - v->vp[2];
# Line 136 | Line 129 | FVECT  p;
129                  disp[1] *= d;
130                  disp[2] *= d;
131          }
132 <        *xp = DOT(disp,v->vhinc)*v->vhs2 + 0.5*v->hresolu;
133 <        *yp = DOT(disp,v->vvinc)*v->vvs2 + 0.5*v->vresolu;
132 >        *xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
133 >        *yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
134   }
135  
136  
137 < sscanview(vp, s)                        /* get view parameters */
138 < register VIEW  *vp;
137 > int
138 > getviewopt(v, ac, av)                   /* process view argument */
139 > register VIEW  *v;
140 > int  ac;
141 > register char  *av[];
142 > {
143 > #define check(c,n)      if ((av[0][c]&&av[0][c]!=' ') || n>=ac) return(-1)
144 >        extern double  atof();
145 >
146 >        if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
147 >                return(-1);
148 >        switch (av[0][2]) {
149 >        case 't':                       /* type */
150 >                if (!av[0][3] || av[0][3]==' ')
151 >                        return(-1);
152 >                check(4,0);
153 >                v->type = av[0][3];
154 >                return(0);
155 >        case 'p':                       /* point */
156 >                check(3,3);
157 >                v->vp[0] = atof(av[1]);
158 >                v->vp[1] = atof(av[2]);
159 >                v->vp[2] = atof(av[3]);
160 >                return(3);
161 >        case 'd':                       /* direction */
162 >                check(3,3);
163 >                v->vdir[0] = atof(av[1]);
164 >                v->vdir[1] = atof(av[2]);
165 >                v->vdir[2] = atof(av[3]);
166 >                return(3);
167 >        case 'u':                       /* up */
168 >                check(3,3);
169 >                v->vup[0] = atof(av[1]);
170 >                v->vup[1] = atof(av[2]);
171 >                v->vup[2] = atof(av[3]);
172 >                return(3);
173 >        case 'h':                       /* horizontal size */
174 >                check(3,1);
175 >                v->horiz = atof(av[1]);
176 >                return(1);
177 >        case 'v':                       /* vertical size */
178 >                check(3,1);
179 >                v->vert = atof(av[1]);
180 >                return(1);
181 >        case 's':                       /* shift */
182 >                check(3,1);
183 >                v->hoff = atof(av[1]);
184 >                return(1);
185 >        case 'l':                       /* lift */
186 >                check(3,1);
187 >                v->voff = atof(av[1]);
188 >                return(1);
189 >        default:
190 >                return(-1);
191 >        }
192 > #undef check
193 > }
194 >
195 >
196 > int
197 > sscanview(vp, s)                        /* get view parameters from string */
198 > VIEW  *vp;
199   register char  *s;
200   {
201 <        for ( ; ; )
202 <                switch (*s++) {
203 <                case '\0':
204 <                case '\n':
205 <                        return(0);
206 <                case '-':
207 <                        switch (*s++) {
208 <                        case '\0':
209 <                                return(-1);
210 <                        case 'x':
211 <                                if (sscanf(s, "%d", &vp->hresolu) != 1)
212 <                                        return(-1);
213 <                                s = sskip(s);
214 <                                continue;
215 <                        case 'y':
216 <                                if (sscanf(s, "%d", &vp->vresolu) != 1)
217 <                                        return(-1);
218 <                                s = sskip(s);
219 <                                continue;
220 <                        case 'v':
221 <                                switch (*s++) {
222 <                                case '\0':
223 <                                        return(-1);
224 <                                case 't':
172 <                                        vp->type = *s++;
173 <                                        continue;
174 <                                case 'p':
175 <                                        if (sscanf(s, "%lf %lf %lf",
176 <                                                        &vp->vp[0],
177 <                                                        &vp->vp[1],
178 <                                                        &vp->vp[2]) != 3)
179 <                                                return(-1);
180 <                                        s = sskip(sskip(sskip(s)));
181 <                                        continue;
182 <                                case 'd':
183 <                                        if (sscanf(s, "%lf %lf %lf",
184 <                                                        &vp->vdir[0],
185 <                                                        &vp->vdir[1],
186 <                                                        &vp->vdir[2]) != 3)
187 <                                                return(-1);
188 <                                        s = sskip(sskip(sskip(s)));
189 <                                        continue;
190 <                                case 'u':
191 <                                        if (sscanf(s, "%lf %lf %lf",
192 <                                                        &vp->vup[0],
193 <                                                        &vp->vup[1],
194 <                                                        &vp->vup[2]) != 3)
195 <                                                return(-1);
196 <                                        s = sskip(sskip(sskip(s)));
197 <                                        continue;
198 <                                case 'h':
199 <                                        if (sscanf(s, "%lf",
200 <                                                        &vp->horiz) != 1)
201 <                                                return(-1);
202 <                                        s = sskip(s);
203 <                                        continue;
204 <                                case 'v':
205 <                                        if (sscanf(s, "%lf",
206 <                                                        &vp->vert) != 1)
207 <                                                return(-1);
208 <                                        s = sskip(s);
209 <                                        continue;
210 <                                }
211 <                                continue;
212 <                        }
213 <                        continue;
214 <                }
201 >        int  ac;
202 >        char  *av[4];
203 >        int  na;
204 >        int  nvopts = 0;
205 >
206 >        while (*s == ' ')
207 >                s++;
208 >        while (*s) {
209 >                ac = 0;
210 >                do {
211 >                        av[ac++] = s;
212 >                        while (*s && *s != ' ')
213 >                                s++;
214 >                        while (*s == ' ')
215 >                                s++;
216 >                } while (*s && ac < 4);
217 >                if ((na = getviewopt(vp, ac, av)) >= 0) {
218 >                        if (na+1 < ac)
219 >                                s = av[na+1];
220 >                        nvopts++;
221 >                } else if (ac > 1)
222 >                        s = av[1];
223 >        }
224 >        return(nvopts);
225   }
226  
227  
# Line 224 | Line 234 | FILE  *fp;
234          fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
235          fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
236          fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
237 <        fprintf(fp, " -x %d -y %d", vp->hresolu, vp->vresolu);
237 >        fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff);
238   }
239  
240  
# Line 241 | Line 251 | char  *s;
251  
252          for (an = altname; *an != NULL; an++)
253                  if (!strncmp(*an, s, strlen(*an))) {
254 <                        if (sscanview(hview, s+strlen(*an)) == 0)
254 >                        if (sscanview(hview, s+strlen(*an)) > 0)
255                                  gothview++;
256                          return;
257                  }
# Line 249 | Line 259 | char  *s;
259  
260  
261   int
262 < viewfile(fname, vp)                     /* get view from file */
262 > viewfile(fname, vp, xp, yp)             /* get view from file */
263   char  *fname;
264   VIEW  *vp;
265 + int  *xp, *yp;
266   {
267          extern char  *progname;
268          FILE  *fp;
# Line 264 | Line 275 | VIEW  *vp;
275          gothview = 0;
276  
277          getheader(fp, gethview);
278 +
279 +        if (xp != NULL && yp != NULL
280 +                        && fgetresolu(xp, yp, fp) == -1)
281 +                gothview = 0;
282  
283          fclose(fp);
284  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines