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.15 by greg, Thu Apr 18 14:52:55 1991 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:55:38 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "view.h"
16  
17 + #include  "resolu.h"
18 +
19   VIEW  stdview = STDVIEW;                /* default view parameters */
20  
21  
# Line 162 | Line 164 | double  x, y;
164   }
165  
166  
167 < viewpixel(xp, yp, zp, v, p)             /* find image location for point */
168 < double  *xp, *yp, *zp;
167 > viewloc(ip, v, p)               /* find image location for point */
168 > FVECT  ip;
169   register VIEW  *v;
170   FVECT  p;
171   {
# Line 176 | Line 178 | FVECT  p;
178  
179          switch (v->type) {
180          case VT_PAR:                    /* parallel view */
181 <                if (zp != NULL)
180 <                        *zp = DOT(disp,v->vdir);
181 >                ip[2] = DOT(disp,v->vdir);
182                  break;
183          case VT_PER:                    /* perspective view */
184                  d = DOT(disp,v->vdir);
185 <                if (zp != NULL) {
186 <                        *zp = sqrt(DOT(disp,disp));
187 <                        if (d < 0.0)
187 <                                *zp = -*zp;
188 <                }
189 <                if (d < 0.0)            /* fold pyramid */
185 >                ip[2] = sqrt(DOT(disp,disp));
186 >                if (d < 0.0) {          /* fold pyramid */
187 >                        ip[2] = -ip[2];
188                          d = -d;
189 <                if (d > FTINY) {
189 >                } else if (d > FTINY) {
190                          d = 1.0/d;
191                          disp[0] *= d;
192                          disp[1] *= d;
# Line 197 | Line 195 | FVECT  p;
195                  break;
196          case VT_HEM:                    /* hemispherical fisheye */
197                  d = normalize(disp);
198 <                if (zp != NULL) {
199 <                        if (DOT(disp,v->vdir) < 0.0)
200 <                                *zp = -d;
201 <                        else
204 <                                *zp = d;
205 <                }
198 >                if (DOT(disp,v->vdir) < 0.0)
199 >                        ip[2] = -d;
200 >                else
201 >                        ip[2] = d;
202                  break;
203          case VT_ANG:                    /* angular fisheye */
204 <                d = normalize(disp);
205 <                if (zp != NULL)
206 <                        *zp = d;
211 <                *xp = 0.5 - v->hoff;
212 <                *yp = 0.5 - v->voff;
204 >                ip[0] = 0.5 - v->hoff;
205 >                ip[1] = 0.5 - v->voff;
206 >                ip[2] = normalize(disp);
207                  d = DOT(disp,v->vdir);
208                  if (d >= 1.0-FTINY)
209                          return;
210                  if (d <= -(1.0-FTINY)) {
211 <                        *xp += 180.0/v->horiz;
212 <                        *yp += 180.0/v->vert;
211 >                        ip[1] += 180.0/v->horiz;
212 >                        ip[2] += 180.0/v->vert;
213                          return;
214                  }
215                  d = acos(d)/PI / sqrt(1.0 - d*d);
216 <                *xp += DOT(disp,v->hvec)*d*180.0/v->horiz;
217 <                *yp += DOT(disp,v->vvec)*d*180.0/v->vert;
216 >                ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz;
217 >                ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert;
218                  return;
219          }
220 <        *xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
221 <        *yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
220 >        ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
221 >        ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
222   }
223  
224  
225 + pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
226 + FLOAT  loc[2];
227 + register RESOLU  *rp;
228 + int  px, py;
229 + {
230 +        register int  x, y;
231 +
232 +        if (rp->or & YMAJOR) {
233 +                x = px;
234 +                y = py;
235 +        } else {
236 +                x = py;
237 +                y = px;
238 +        }
239 +        if (rp->or & XDECR)
240 +                x = rp->xr-1 - x;
241 +        if (rp->or & YDECR)
242 +                y = rp->yr-1 - y;
243 +        loc[0] = (x+.5)/rp->xr;
244 +        loc[1] = (y+.5)/rp->yr;
245 + }
246 +
247 +
248 + loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
249 + int  pp[2];
250 + register RESOLU  *rp;
251 + double  lx, ly;
252 + {
253 +        register int  x, y;
254 +
255 +        x = lx * rp->xr;
256 +        y = ly * rp->yr;
257 +        if (rp->or & XDECR)
258 +                x = rp->xr-1 - x;
259 +        if (rp->or & YDECR)
260 +                y = rp->yr-1 - y;
261 +        if (rp->or & YMAJOR) {
262 +                pp[0] = x;
263 +                pp[1] = y;
264 +        } else {
265 +                pp[0] = y;
266 +                pp[1] = x;
267 +        }
268 + }
269 +
270 +
271   int
272   getviewopt(v, ac, av)                   /* process view argument */
273   register VIEW  *v;
274   int  ac;
275   register char  *av[];
276   {
277 < #define check(c,n)      if ((av[0][c]&&av[0][c]!=' ') || n>=ac) return(-1)
277 > #define check(c,l)      if ((av[0][c]&&av[0][c]!=' ') || \
278 >                        badarg(ac-1,av+1,l)) return(-1)
279          extern double  atof();
280  
281          if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
# Line 243 | Line 284 | register char  *av[];
284          case 't':                       /* type */
285                  if (!av[0][3] || av[0][3]==' ')
286                          return(-1);
287 <                check(4,0);
287 >                check(4,"");
288                  v->type = av[0][3];
289                  return(0);
290          case 'p':                       /* point */
291 <                check(3,3);
291 >                check(3,"fff");
292                  v->vp[0] = atof(av[1]);
293                  v->vp[1] = atof(av[2]);
294                  v->vp[2] = atof(av[3]);
295                  return(3);
296          case 'd':                       /* direction */
297 <                check(3,3);
297 >                check(3,"fff");
298                  v->vdir[0] = atof(av[1]);
299                  v->vdir[1] = atof(av[2]);
300                  v->vdir[2] = atof(av[3]);
301                  return(3);
302          case 'u':                       /* up */
303 <                check(3,3);
303 >                check(3,"fff");
304                  v->vup[0] = atof(av[1]);
305                  v->vup[1] = atof(av[2]);
306                  v->vup[2] = atof(av[3]);
307                  return(3);
308          case 'h':                       /* horizontal size */
309 <                check(3,1);
309 >                check(3,"f");
310                  v->horiz = atof(av[1]);
311                  return(1);
312          case 'v':                       /* vertical size */
313 <                check(3,1);
313 >                check(3,"f");
314                  v->vert = atof(av[1]);
315                  return(1);
316          case 's':                       /* shift */
317 <                check(3,1);
317 >                check(3,"f");
318                  v->hoff = atof(av[1]);
319                  return(1);
320          case 'l':                       /* lift */
321 <                check(3,1);
321 >                check(3,"f");
322                  v->voff = atof(av[1]);
323                  return(1);
324          default:
# Line 357 | Line 398 | register struct myview  *v;
398  
399  
400   int
401 < viewfile(fname, vp, xp, yp)             /* get view from file */
401 > viewfile(fname, vp, rp)                 /* get view from file */
402   char  *fname;
403   VIEW  *vp;
404 < int  *xp, *yp;
404 > RESOLU  *rp;
405   {
406          extern char  *progname;
407          struct myview   mvs;
# Line 375 | Line 416 | int  *xp, *yp;
416  
417          getheader(fp, gethview, &mvs);
418  
419 <        if (xp != NULL && yp != NULL
379 <                        && fgetresolu(xp, yp, fp) == -1)
419 >        if (rp != NULL && !fgetsresolu(rp, fp))
420                  mvs.ok = 0;
421  
422          fclose(fp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines