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.1 by greg, Thu Feb 2 10:34:34 1989 UTC vs.
Revision 1.6 by greg, Tue Jan 9 09:08:09 1990 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include  "standard.h"
14  
15 #include  "color.h"
16
15   #include  "view.h"
16  
17 < VIEW  stdview = STDVIEW(512);           /* default view parameters */
17 > VIEW  stdview = STDVIEW;                /* default view parameters */
18  
19  
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
20   char *
21 < 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");
44                
45        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");
49                
50        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  
65        dt /= (double)v->hresolu;
66        v->vhinc[0] *= dt;
67        v->vhinc[1] *= dt;
68        v->vhinc[2] *= dt;
69
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;
82 <        v->vvinc[0] *= dt;
83 <        v->vvinc[1] *= dt;
84 <        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  
64          return(NULL);
65   }
66  
67  
68 < rayview(orig, direc, v, x, y)           /* compute ray origin and direction */
68 > normaspect(vp, ap, xp, yp)              /* fix pixel aspect or resolution */
69 > VIEW  *vp;
70 > double  *ap;
71 > int  *xp, *yp;
72 > {
73 >        double  va = viewaspect(vp);
74 >
75 >        if (*ap <= FTINY)
76 >                *ap = (double)*yp / *xp / va;   /* compute pixel aspect */
77 >        else if (va * *xp > *ap * *yp)
78 >                *xp = *yp / va * *ap;           /* reduce x resolution */
79 >        else
80 >                *yp = *xp * va / *ap;           /* reduce y resolution */
81 > }
82 >
83 >
84 > viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
85   FVECT  orig, direc;
86   register VIEW  *v;
87   double  x, y;
88   {
89 <        register int  i;
89 >        x += v->hoff - 0.5;
90 >        y += v->voff - 0.5;
91  
97        x -= 0.5 * v->hresolu;
98        y -= 0.5 * v->vresolu;
99
92          if (v->type == VT_PAR) {        /* parallel view */
93 <                for (i = 0; i < 3; i++)
94 <                        orig[i] = v->vp[i] + x*v->vhinc[i] + y*v->vvinc[i];
93 >                orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0];
94 >                orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1];
95 >                orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2];
96                  VCOPY(direc, v->vdir);
97          } else {                        /* perspective view */
98                  VCOPY(orig, v->vp);
99 <                for (i = 0; i < 3; i++)
100 <                        direc[i] = v->vdir[i] + x*v->vhinc[i] + y*v->vvinc[i];
99 >                direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
100 >                direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
101 >                direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
102                  normalize(direc);
103          }
104   }
105  
106  
107 < sscanview(vp, s)                        /* get view parameters */
108 < register VIEW  *vp;
107 > viewpixel(xp, yp, zp, v, p)             /* find image location for point */
108 > double  *xp, *yp, *zp;
109 > register VIEW  *v;
110 > FVECT  p;
111 > {
112 >        extern double  sqrt();
113 >        double  d;
114 >        FVECT  disp;
115 >
116 >        disp[0] = p[0] - v->vp[0];
117 >        disp[1] = p[1] - v->vp[1];
118 >        disp[2] = p[2] - v->vp[2];
119 >
120 >        if (v->type == VT_PAR) {        /* parallel view */
121 >                if (zp != NULL)
122 >                        *zp = DOT(disp,v->vdir);
123 >        } else {                        /* perspective view */
124 >                d = 1.0/DOT(disp,v->vdir);
125 >                if (zp != NULL) {
126 >                        *zp = sqrt(DOT(disp,disp));
127 >                        if (d < 0.0)
128 >                                *zp = -*zp;
129 >                }
130 >                disp[0] *= d;
131 >                disp[1] *= d;
132 >                disp[2] *= d;
133 >        }
134 >        *xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
135 >        *yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
136 > }
137 >
138 >
139 > int
140 > getviewopt(v, ac, av)                   /* process view argument */
141 > register VIEW  *v;
142 > int  ac;
143 > register char  *av[];
144 > {
145 > #define check(c,n)      if ((av[0][c]&&av[0][c]!=' ') || n>=ac) return(-1)
146 >        extern double  atof();
147 >
148 >        if (av[0][0] != '-' || av[0][1] != 'v')
149 >                return(-1);
150 >        switch (av[0][2]) {
151 >        case 't':                       /* type */
152 >                if (!av[0][3] || av[0][3]==' ')
153 >                        return(-1);
154 >                check(4,0);
155 >                v->type = av[0][3];
156 >                return(0);
157 >        case 'p':                       /* point */
158 >                check(3,3);
159 >                v->vp[0] = atof(av[1]);
160 >                v->vp[1] = atof(av[2]);
161 >                v->vp[2] = atof(av[3]);
162 >                return(3);
163 >        case 'd':                       /* direction */
164 >                check(3,3);
165 >                v->vdir[0] = atof(av[1]);
166 >                v->vdir[1] = atof(av[2]);
167 >                v->vdir[2] = atof(av[3]);
168 >                return(3);
169 >        case 'u':                       /* up */
170 >                check(3,3);
171 >                v->vup[0] = atof(av[1]);
172 >                v->vup[1] = atof(av[2]);
173 >                v->vup[2] = atof(av[3]);
174 >                return(3);
175 >        case 'h':                       /* horizontal size */
176 >                check(3,1);
177 >                v->horiz = atof(av[1]);
178 >                return(1);
179 >        case 'v':                       /* vertical size */
180 >                check(3,1);
181 >                v->vert = atof(av[1]);
182 >                return(1);
183 >        case 's':                       /* shift */
184 >                check(3,1);
185 >                v->hoff = atof(av[1]);
186 >                return(1);
187 >        case 'l':                       /* lift */
188 >                check(3,1);
189 >                v->voff = atof(av[1]);
190 >                return(1);
191 >        default:
192 >                return(-1);
193 >        }
194 > #undef check
195 > }
196 >
197 >
198 > int
199 > sscanview(vp, s)                        /* get view parameters from string */
200 > VIEW  *vp;
201   register char  *s;
202   {
203 <        for ( ; ; )
204 <                switch (*s++) {
205 <                case '\0':
206 <                case '\n':
207 <                        return(0);
208 <                case '-':
209 <                        switch (*s++) {
210 <                        case '\0':
211 <                                return(-1);
212 <                        case 'x':
213 <                                if (sscanf(s, "%d", &vp->hresolu) != 1)
214 <                                        return(-1);
215 <                                s = sskip(s);
216 <                                continue;
217 <                        case 'y':
218 <                                if (sscanf(s, "%d", &vp->vresolu) != 1)
219 <                                        return(-1);
220 <                                s = sskip(s);
221 <                                continue;
222 <                        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;
203 >        int  ac;
204 >        char  *av[4];
205 >        int  na;
206 >        int  nvopts = 0;
207 >
208 >        while (*s == ' ')
209 >                s++;
210 >        do {
211 >                ac = 0;
212 >                do {
213 >                        av[ac++] = s;
214 >                        while (*s && *s != ' ')
215 >                                s++;
216 >                        while (*s == ' ')
217 >                                s++;
218 >                } while (*s && ac < 4);
219 >                if ((na = getviewopt(vp, ac, av)) >= 0) {
220 >                        if (na+1 < ac)
221 >                                s = av[na+1];
222 >                        nvopts++;
223                  }
224 +        } while (*s);
225 +        return(nvopts);
226   }
227  
228  
# Line 193 | Line 235 | FILE  *fp;
235          fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
236          fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
237          fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
238 <        fprintf(fp, " -x %d -y %d", vp->hresolu, vp->vresolu);
238 >        fprintf(fp, " -vs %d -vl %d", vp->hoff, vp->voff);
239   }
240  
241  
242   static VIEW  *hview;                    /* view from header */
243   static int  gothview;                   /* success indicator */
244 < static char  *altname[] = {NULL,"rpict","rview",VIEWSTR,NULL};
244 > static char  *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL};
245  
246  
247   static
# Line 210 | Line 252 | char  *s;
252  
253          for (an = altname; *an != NULL; an++)
254                  if (!strncmp(*an, s, strlen(*an))) {
255 <                        if (sscanview(hview, s+strlen(*an)) == 0)
255 >                        if (sscanview(hview, s+strlen(*an)) > 0)
256                                  gothview++;
257                          return;
258                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines