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.11 by greg, Wed Jan 10 19:25:57 1996 UTC vs.
Revision 2.28 by greg, Tue Jun 8 19:48:29 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 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 + *  External symbols declared in view.h
8   */
9  
10 < #include  "standard.h"
10 > #include "copyright.h"
11  
12 + #include  "rtio.h"
13 + #include  "rtmath.h"
14 + #include  "paths.h"
15   #include  "view.h"
16  
15 #include  "resolu.h"
17  
17 #include  "paths.h"
18
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 + static gethfunc gethview;
25  
26 +
27   char *
28   setview(v)              /* set hvec and vvec, return message on error */
29   register VIEW  *v;
# Line 30 | Line 31 | register VIEW  *v;
31          static char  ill_horiz[] = "illegal horizontal view size";
32          static char  ill_vert[] = "illegal vertical view size";
33          
34 <        if (v->vfore < -FTINY || v->vaft < -FTINY ||
34 <                        (v->vaft > FTINY && v->vaft <= v->vfore))
34 >        if (v->vaft < -FTINY || (v->vaft > FTINY && v->vaft <= v->vfore))
35                  return("illegal fore/aft clipping plane");
36  
37          if (normalize(v->vdir) == 0.0)          /* normalize direction */
# Line 109 | Line 109 | register VIEW  *v;
109   }
110  
111  
112 + void
113   normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
114   double  va;                     /* view aspect ratio */
115   double  *ap;                    /* pixel aspect in (or out if 0) */
# Line 200 | Line 201 | double  x, y;
201   }
202  
203  
204 + void
205   viewloc(ip, v, p)               /* find image location for point */
206   FVECT  ip;
207   register VIEW  *v;
208   FVECT  p;
209   {
210 <        double  d;
210 >        double  d, d2;
211          FVECT  disp;
212  
213          disp[0] = p[0] - v->vp[0];
# Line 218 | Line 220 | FVECT  p;
220                  break;
221          case VT_PER:                    /* perspective view */
222                  d = DOT(disp,v->vdir);
223 <                ip[2] = sqrt(DOT(disp,disp));
223 >                ip[2] = VLEN(disp);
224                  if (d < 0.0) {          /* fold pyramid */
225                          ip[2] = -ip[2];
226                          d = -d;
# Line 240 | Line 242 | FVECT  p;
242                  ip[2] -= v->vfore;
243                  break;
244          case VT_CYL:                    /* cylindrical panorama */
243                ip[2] = DOT(disp,v->vdir);
245                  d = DOT(disp,v->hvec);
246 <                ip[0] = 180.0/PI * atan2(d,ip[2]) / v->horiz + 0.5 - v->hoff;
247 <                ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
248 <                if (v->vfore > FTINY)
249 <                        ip[2] = sqrt(DOT(disp,disp)) *
250 <                                (1.0 - v->vfore/sqrt(d*d + ip[2]*ip[2]));
251 <                else
251 <                        ip[2] = sqrt(DOT(disp,disp));
246 >                d2 = DOT(disp,v->vdir);
247 >                ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
248 >                d = 1.0/sqrt(d*d + d2*d2);
249 >                ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
250 >                ip[2] = VLEN(disp);
251 >                ip[2] *= (1.0 - v->vfore*d);
252                  return;
253          case VT_ANG:                    /* angular fisheye */
254                  ip[0] = 0.5 - v->hoff;
# Line 271 | Line 271 | FVECT  p;
271   }
272  
273  
274 + void
275   pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
276 < FLOAT  loc[2];
276 > RREAL  loc[2];
277   register RESOLU  *rp;
278   int  px, py;
279   {
280          register int  x, y;
281  
282 <        if (rp->or & YMAJOR) {
282 >        if (rp->rt & YMAJOR) {
283                  x = px;
284                  y = py;
285          } else {
286                  x = py;
287                  y = px;
288          }
289 <        if (rp->or & XDECR)
289 >        if (rp->rt & XDECR)
290                  x = rp->xr-1 - x;
291 <        if (rp->or & YDECR)
291 >        if (rp->rt & YDECR)
292                  y = rp->yr-1 - y;
293          loc[0] = (x+.5)/rp->xr;
294          loc[1] = (y+.5)/rp->yr;
295   }
296  
297  
298 + void
299   loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
300   int  pp[2];
301   register RESOLU  *rp;
# Line 303 | Line 305 | double  lx, ly;
305  
306          x = lx * rp->xr;
307          y = ly * rp->yr;
308 <        if (rp->or & XDECR)
308 >        if (rp->rt & XDECR)
309                  x = rp->xr-1 - x;
310 <        if (rp->or & YDECR)
310 >        if (rp->rt & YDECR)
311                  y = rp->yr-1 - y;
312 <        if (rp->or & YMAJOR) {
312 >        if (rp->rt & YMAJOR) {
313                  pp[0] = x;
314                  pp[1] = y;
315          } else {
# Line 394 | Line 396 | register char  *s;
396          int  na;
397          int  nvopts = 0;
398  
399 +        while (*s == ' ')
400 +                s++;
401          if (*s != '-')
402 <                s = sskip(s);
402 >                s = sskip2(s,1);
403          while (*s) {
404                  ac = 0;
405                  do {
406 <                        av[ac++] = s;
406 >                        if (ac || *s == '-')
407 >                                av[ac++] = s;
408                          while (*s && *s != ' ')
409                                  s++;
410                          while (*s == ' ')
# Line 416 | Line 421 | register char  *s;
421   }
422  
423  
424 + void
425   fprintview(vp, fp)                      /* write out view parameters */
426   register VIEW  *vp;
427   FILE  *fp;
# Line 488 | Line 494 | int
494   isview(s)                               /* is this a view string? */
495   char  *s;
496   {
497 <        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL};
497 >        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","rvu","rpiece","pinterp",NULL};
498          extern char  *progname;
499          register char  *cp;
500          register char  **an;
# Line 519 | Line 525 | struct myview {
525   };
526  
527  
528 < static
529 < gethview(s, v)                          /* get view from header */
530 < char  *s;
531 < register struct myview  *v;
528 > static int
529 > gethview(                               /* get view from header */
530 >        char  *s,
531 >        void  *v
532 > )
533   {
534 <        if (isview(s) && sscanview(v->hv, s) > 0)
535 <                v->ok++;
534 >        if (isview(s) && sscanview(((struct myview*)v)->hv, s) > 0)
535 >                ((struct myview*)v)->ok++;
536 >        return(0);
537   }
538  
539  
# Line 538 | Line 546 | RESOLU  *rp;
546          struct myview   mvs;
547          FILE  *fp;
548  
549 <        if ((fp = fopen(fname, "r")) == NULL)
549 >        if (fname == NULL || !strcmp(fname, "-"))
550 >                fp = stdin;
551 >        else if ((fp = fopen(fname, "r")) == NULL)
552                  return(-1);
553  
554          mvs.hv = vp;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines