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 2.9 by greg, Fri Aug 18 10:20:10 1995 UTC vs.
Revision 2.17 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  image.c - routines for image generation.
6   *
7 < *     10/17/85
7 > *  External symbols declared in view.h
8   */
9  
10 + #include "copyright.h"
11 +
12   #include  "standard.h"
13  
14   #include  "view.h"
15  
17 #include  "resolu.h"
18
16   #include  "paths.h"
17  
18 + #define  FEQ(x,y)       (fabs((x)-(y)) <= FTINY)
19 + #define  VEQ(v,w)       (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \
20 +                                && FEQ((v)[2],(w)[2]))
21 +
22   VIEW  stdview = STDVIEW;                /* default view parameters */
23  
24  
# Line 28 | Line 29 | register VIEW  *v;
29          static char  ill_horiz[] = "illegal horizontal view size";
30          static char  ill_vert[] = "illegal vertical view size";
31          
32 <        if (v->vfore < -FTINY || v->vaft < -FTINY ||
32 <                        (v->vaft > FTINY && v->vaft <= v->vfore))
32 >        if (v->vaft < -FTINY || (v->vaft > FTINY && v->vaft <= v->vfore))
33                  return("illegal fore/aft clipping plane");
34  
35          if (normalize(v->vdir) == 0.0)          /* normalize direction */
# Line 107 | Line 107 | register VIEW  *v;
107   }
108  
109  
110 + void
111   normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
112   double  va;                     /* view aspect ratio */
113   double  *ap;                    /* pixel aspect in (or out if 0) */
# Line 198 | Line 199 | double  x, y;
199   }
200  
201  
202 + void
203   viewloc(ip, v, p)               /* find image location for point */
204   FVECT  ip;
205   register VIEW  *v;
206   FVECT  p;
207   {
208 <        double  d;
208 >        double  d, d2;
209          FVECT  disp;
210  
211          disp[0] = p[0] - v->vp[0];
# Line 216 | Line 218 | FVECT  p;
218                  break;
219          case VT_PER:                    /* perspective view */
220                  d = DOT(disp,v->vdir);
221 <                ip[2] = sqrt(DOT(disp,disp));
221 >                ip[2] = VLEN(disp);
222                  if (d < 0.0) {          /* fold pyramid */
223                          ip[2] = -ip[2];
224                          d = -d;
# Line 238 | Line 240 | FVECT  p;
240                  ip[2] -= v->vfore;
241                  break;
242          case VT_CYL:                    /* cylindrical panorama */
241                ip[2] = DOT(disp,v->vdir);
243                  d = DOT(disp,v->hvec);
244 <                ip[0] = 180.0/PI * atan2(ip[2],d) / v->horiz + 0.5 - v->hoff;
245 <                ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
246 <                if (v->vfore > FTINY)
247 <                        ip[2] = sqrt(DOT(disp,disp)) *
248 <                                (1.0 - v->vfore/sqrt(d*d + ip[2]*ip[2]));
249 <                else
249 <                        ip[2] = sqrt(DOT(disp,disp));
244 >                d2 = DOT(disp,v->vdir);
245 >                ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
246 >                d = 1.0/sqrt(d*d + d2*d2);
247 >                ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
248 >                ip[2] = VLEN(disp);
249 >                ip[2] *= (1.0 - v->vfore*d);
250                  return;
251          case VT_ANG:                    /* angular fisheye */
252                  ip[0] = 0.5 - v->hoff;
# Line 269 | Line 269 | FVECT  p;
269   }
270  
271  
272 + void
273   pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
274   FLOAT  loc[2];
275   register RESOLU  *rp;
# Line 276 | Line 277 | int  px, py;
277   {
278          register int  x, y;
279  
280 <        if (rp->or & YMAJOR) {
280 >        if (rp->rt & YMAJOR) {
281                  x = px;
282                  y = py;
283          } else {
284                  x = py;
285                  y = px;
286          }
287 <        if (rp->or & XDECR)
287 >        if (rp->rt & XDECR)
288                  x = rp->xr-1 - x;
289 <        if (rp->or & YDECR)
289 >        if (rp->rt & YDECR)
290                  y = rp->yr-1 - y;
291          loc[0] = (x+.5)/rp->xr;
292          loc[1] = (y+.5)/rp->yr;
293   }
294  
295  
296 + void
297   loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
298   int  pp[2];
299   register RESOLU  *rp;
# Line 301 | Line 303 | double  lx, ly;
303  
304          x = lx * rp->xr;
305          y = ly * rp->yr;
306 <        if (rp->or & XDECR)
306 >        if (rp->rt & XDECR)
307                  x = rp->xr-1 - x;
308 <        if (rp->or & YDECR)
308 >        if (rp->rt & YDECR)
309                  y = rp->yr-1 - y;
310 <        if (rp->or & YMAJOR) {
310 >        if (rp->rt & YMAJOR) {
311                  pp[0] = x;
312                  pp[1] = y;
313          } else {
# Line 393 | Line 395 | register char  *s;
395          int  nvopts = 0;
396  
397          if (*s != '-')
398 <                s = sskip(s);
398 >                s = sskip2(s,1);
399          while (*s) {
400                  ac = 0;
401                  do {
# Line 414 | Line 416 | register char  *s;
416   }
417  
418  
419 + void
420   fprintview(vp, fp)                      /* write out view parameters */
421   register VIEW  *vp;
422   FILE  *fp;
# Line 428 | Line 431 | FILE  *fp;
431   }
432  
433  
434 + char *
435 + viewopt(vp)                             /* translate to minimal view string */
436 + register VIEW  *vp;
437 + {
438 +        static char  vwstr[128];
439 +        register char  *cp = vwstr;
440 +
441 +        if (vp->type != stdview.type) {
442 +                sprintf(cp, " -vt%c", vp->type);
443 +                cp += strlen(cp);
444 +        }
445 +        if (!VEQ(vp->vp,stdview.vp)) {
446 +                sprintf(cp, " -vp %.6g %.6g %.6g",
447 +                                vp->vp[0], vp->vp[1], vp->vp[2]);
448 +                cp += strlen(cp);
449 +        }
450 +        if (!VEQ(vp->vdir,stdview.vdir)) {
451 +                sprintf(cp, " -vd %.6g %.6g %.6g",
452 +                                vp->vdir[0], vp->vdir[1], vp->vdir[2]);
453 +                cp += strlen(cp);
454 +        }
455 +        if (!VEQ(vp->vup,stdview.vup)) {
456 +                sprintf(cp, " -vu %.6g %.6g %.6g",
457 +                                vp->vup[0], vp->vup[1], vp->vup[2]);
458 +                cp += strlen(cp);
459 +        }
460 +        if (!FEQ(vp->horiz,stdview.horiz)) {
461 +                sprintf(cp, " -vh %.6g", vp->horiz);
462 +                cp += strlen(cp);
463 +        }
464 +        if (!FEQ(vp->vert,stdview.vert)) {
465 +                sprintf(cp, " -vv %.6g", vp->vert);
466 +                cp += strlen(cp);
467 +        }
468 +        if (!FEQ(vp->vfore,stdview.vfore)) {
469 +                sprintf(cp, " -vo %.6g", vp->vfore);
470 +                cp += strlen(cp);
471 +        }
472 +        if (!FEQ(vp->vaft,stdview.vaft)) {
473 +                sprintf(cp, " -va %.6g", vp->vaft);
474 +                cp += strlen(cp);
475 +        }
476 +        if (!FEQ(vp->hoff,stdview.hoff)) {
477 +                sprintf(cp, " -vs %.6g", vp->hoff);
478 +                cp += strlen(cp);
479 +        }
480 +        if (!FEQ(vp->voff,stdview.voff)) {
481 +                sprintf(cp, " -vl %.6g", vp->voff);
482 +                cp += strlen(cp);
483 +        }
484 +        return(vwstr);
485 + }
486 +
487 +
488   int
489   isview(s)                               /* is this a view string? */
490   char  *s;
# Line 463 | Line 520 | struct myview {
520   };
521  
522  
523 < static
523 > static int
524   gethview(s, v)                          /* get view from header */
525   char  *s;
526   register struct myview  *v;
527   {
528          if (isview(s) && sscanview(v->hv, s) > 0)
529                  v->ok++;
530 +        return(0);
531   }
532  
533  
# Line 482 | Line 540 | RESOLU  *rp;
540          struct myview   mvs;
541          FILE  *fp;
542  
543 <        if ((fp = fopen(fname, "r")) == NULL)
543 >        if (fname == NULL || !strcmp(fname, "-"))
544 >                fp = stdin;
545 >        else if ((fp = fopen(fname, "r")) == NULL)
546                  return(-1);
547  
548          mvs.hv = vp;
549          mvs.ok = 0;
550  
551 <        getheader(fp, gethview, &mvs);
551 >        getheader(fp, (int (*)(char *, char *))&gethview, (char *)&mvs);
552  
553          if (rp != NULL && !fgetsresolu(rp, fp))
554                  mvs.ok = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines