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.10 by greg, Thu Aug 24 11:55:03 1995 UTC vs.
Revision 2.27 by greg, Thu Feb 12 18:55:50 2004 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  "standard.h"
10 > #include "copyright.h"
11  
12 + #include  "rtio.h"
13 + #include  "paths.h"
14   #include  "view.h"
15  
17 #include  "resolu.h"
16  
17 < #include  "paths.h"
17 > #define  FEQ(x,y)       (fabs((x)-(y)) <= FTINY)
18 > #define  VEQ(v,w)       (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \
19 >                                && FEQ((v)[2],(w)[2]))
20  
21   VIEW  stdview = STDVIEW;                /* default view parameters */
22  
23 + static gethfunc gethview;
24  
25 +
26   char *
27   setview(v)              /* set hvec and vvec, return message on error */
28   register VIEW  *v;
# Line 28 | Line 30 | register VIEW  *v;
30          static char  ill_horiz[] = "illegal horizontal view size";
31          static char  ill_vert[] = "illegal vertical view size";
32          
33 <        if (v->vfore < -FTINY || v->vaft < -FTINY ||
32 <                        (v->vaft > FTINY && v->vaft <= v->vfore))
33 >        if (v->vaft < -FTINY || (v->vaft > FTINY && v->vaft <= v->vfore))
34                  return("illegal fore/aft clipping plane");
35  
36          if (normalize(v->vdir) == 0.0)          /* normalize direction */
# Line 107 | Line 108 | register VIEW  *v;
108   }
109  
110  
111 + void
112   normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
113   double  va;                     /* view aspect ratio */
114   double  *ap;                    /* pixel aspect in (or out if 0) */
# Line 198 | Line 200 | double  x, y;
200   }
201  
202  
203 + void
204   viewloc(ip, v, p)               /* find image location for point */
205   FVECT  ip;
206   register VIEW  *v;
207   FVECT  p;
208   {
209 <        double  d;
209 >        double  d, d2;
210          FVECT  disp;
211  
212          disp[0] = p[0] - v->vp[0];
# Line 216 | Line 219 | FVECT  p;
219                  break;
220          case VT_PER:                    /* perspective view */
221                  d = DOT(disp,v->vdir);
222 <                ip[2] = sqrt(DOT(disp,disp));
222 >                ip[2] = VLEN(disp);
223                  if (d < 0.0) {          /* fold pyramid */
224                          ip[2] = -ip[2];
225                          d = -d;
# Line 238 | Line 241 | FVECT  p;
241                  ip[2] -= v->vfore;
242                  break;
243          case VT_CYL:                    /* cylindrical panorama */
241                ip[2] = DOT(disp,v->vdir);
244                  d = DOT(disp,v->hvec);
245 <                ip[0] = 180.0/PI * atan2(d,ip[2]) / v->horiz + 0.5 - v->hoff;
246 <                ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
247 <                if (v->vfore > FTINY)
248 <                        ip[2] = sqrt(DOT(disp,disp)) *
249 <                                (1.0 - v->vfore/sqrt(d*d + ip[2]*ip[2]));
250 <                else
249 <                        ip[2] = sqrt(DOT(disp,disp));
245 >                d2 = DOT(disp,v->vdir);
246 >                ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
247 >                d = 1.0/sqrt(d*d + d2*d2);
248 >                ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
249 >                ip[2] = VLEN(disp);
250 >                ip[2] *= (1.0 - v->vfore*d);
251                  return;
252          case VT_ANG:                    /* angular fisheye */
253                  ip[0] = 0.5 - v->hoff;
# Line 269 | Line 270 | FVECT  p;
270   }
271  
272  
273 + void
274   pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
275 < FLOAT  loc[2];
275 > RREAL  loc[2];
276   register RESOLU  *rp;
277   int  px, py;
278   {
279          register int  x, y;
280  
281 <        if (rp->or & YMAJOR) {
281 >        if (rp->rt & YMAJOR) {
282                  x = px;
283                  y = py;
284          } else {
285                  x = py;
286                  y = px;
287          }
288 <        if (rp->or & XDECR)
288 >        if (rp->rt & XDECR)
289                  x = rp->xr-1 - x;
290 <        if (rp->or & YDECR)
290 >        if (rp->rt & YDECR)
291                  y = rp->yr-1 - y;
292          loc[0] = (x+.5)/rp->xr;
293          loc[1] = (y+.5)/rp->yr;
294   }
295  
296  
297 + void
298   loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
299   int  pp[2];
300   register RESOLU  *rp;
# Line 301 | Line 304 | double  lx, ly;
304  
305          x = lx * rp->xr;
306          y = ly * rp->yr;
307 <        if (rp->or & XDECR)
307 >        if (rp->rt & XDECR)
308                  x = rp->xr-1 - x;
309 <        if (rp->or & YDECR)
309 >        if (rp->rt & YDECR)
310                  y = rp->yr-1 - y;
311 <        if (rp->or & YMAJOR) {
311 >        if (rp->rt & YMAJOR) {
312                  pp[0] = x;
313                  pp[1] = y;
314          } else {
# Line 392 | Line 395 | register char  *s;
395          int  na;
396          int  nvopts = 0;
397  
398 +        while (*s == ' ')
399 +                s++;
400          if (*s != '-')
401 <                s = sskip(s);
401 >                s = sskip2(s,1);
402          while (*s) {
403                  ac = 0;
404                  do {
405 <                        av[ac++] = s;
405 >                        if (ac || *s == '-')
406 >                                av[ac++] = s;
407                          while (*s && *s != ' ')
408                                  s++;
409                          while (*s == ' ')
# Line 414 | Line 420 | register char  *s;
420   }
421  
422  
423 + void
424   fprintview(vp, fp)                      /* write out view parameters */
425   register VIEW  *vp;
426   FILE  *fp;
# Line 428 | Line 435 | FILE  *fp;
435   }
436  
437  
438 + char *
439 + viewopt(vp)                             /* translate to minimal view string */
440 + register VIEW  *vp;
441 + {
442 +        static char  vwstr[128];
443 +        register char  *cp = vwstr;
444 +
445 +        if (vp->type != stdview.type) {
446 +                sprintf(cp, " -vt%c", vp->type);
447 +                cp += strlen(cp);
448 +        }
449 +        if (!VEQ(vp->vp,stdview.vp)) {
450 +                sprintf(cp, " -vp %.6g %.6g %.6g",
451 +                                vp->vp[0], vp->vp[1], vp->vp[2]);
452 +                cp += strlen(cp);
453 +        }
454 +        if (!VEQ(vp->vdir,stdview.vdir)) {
455 +                sprintf(cp, " -vd %.6g %.6g %.6g",
456 +                                vp->vdir[0], vp->vdir[1], vp->vdir[2]);
457 +                cp += strlen(cp);
458 +        }
459 +        if (!VEQ(vp->vup,stdview.vup)) {
460 +                sprintf(cp, " -vu %.6g %.6g %.6g",
461 +                                vp->vup[0], vp->vup[1], vp->vup[2]);
462 +                cp += strlen(cp);
463 +        }
464 +        if (!FEQ(vp->horiz,stdview.horiz)) {
465 +                sprintf(cp, " -vh %.6g", vp->horiz);
466 +                cp += strlen(cp);
467 +        }
468 +        if (!FEQ(vp->vert,stdview.vert)) {
469 +                sprintf(cp, " -vv %.6g", vp->vert);
470 +                cp += strlen(cp);
471 +        }
472 +        if (!FEQ(vp->vfore,stdview.vfore)) {
473 +                sprintf(cp, " -vo %.6g", vp->vfore);
474 +                cp += strlen(cp);
475 +        }
476 +        if (!FEQ(vp->vaft,stdview.vaft)) {
477 +                sprintf(cp, " -va %.6g", vp->vaft);
478 +                cp += strlen(cp);
479 +        }
480 +        if (!FEQ(vp->hoff,stdview.hoff)) {
481 +                sprintf(cp, " -vs %.6g", vp->hoff);
482 +                cp += strlen(cp);
483 +        }
484 +        if (!FEQ(vp->voff,stdview.voff)) {
485 +                sprintf(cp, " -vl %.6g", vp->voff);
486 +                cp += strlen(cp);
487 +        }
488 +        return(vwstr);
489 + }
490 +
491 +
492   int
493   isview(s)                               /* is this a view string? */
494   char  *s;
495   {
496 <        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL};
496 >        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","rvu","rpiece","pinterp",NULL};
497          extern char  *progname;
498          register char  *cp;
499          register char  **an;
# Line 463 | Line 524 | struct myview {
524   };
525  
526  
527 < static
528 < gethview(s, v)                          /* get view from header */
529 < char  *s;
530 < register struct myview  *v;
527 > static int
528 > gethview(                               /* get view from header */
529 >        char  *s,
530 >        void  *v
531 > )
532   {
533 <        if (isview(s) && sscanview(v->hv, s) > 0)
534 <                v->ok++;
533 >        if (isview(s) && sscanview(((struct myview*)v)->hv, s) > 0)
534 >                ((struct myview*)v)->ok++;
535 >        return(0);
536   }
537  
538  
# Line 482 | Line 545 | RESOLU  *rp;
545          struct myview   mvs;
546          FILE  *fp;
547  
548 <        if ((fp = fopen(fname, "r")) == NULL)
548 >        if (fname == NULL || !strcmp(fname, "-"))
549 >                fp = stdin;
550 >        else if ((fp = fopen(fname, "r")) == NULL)
551                  return(-1);
552  
553          mvs.hv = vp;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines