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.7 by greg, Tue Dec 20 20:15:04 1994 UTC vs.
Revision 2.22 by schorsch, Fri Nov 14 17:22:06 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  "standard.h"
10 > #include "copyright.h"
11  
12 + #include  "rtio.h"
13   #include  "view.h"
14  
17 #include  "resolu.h"
15  
16 < #include  "paths.h"
16 > #define  FEQ(x,y)       (fabs((x)-(y)) <= FTINY)
17 > #define  VEQ(v,w)       (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \
18 >                                && FEQ((v)[2],(w)[2]))
19  
20   VIEW  stdview = STDVIEW;                /* default view parameters */
21  
# Line 28 | Line 27 | register VIEW  *v;
27          static char  ill_horiz[] = "illegal horizontal view size";
28          static char  ill_vert[] = "illegal vertical view size";
29          
30 <        if (v->vfore < -FTINY || v->vaft < -FTINY ||
32 <                        (v->vaft > FTINY && v->vaft <= v->vfore))
30 >        if (v->vaft < -FTINY || (v->vaft > FTINY && v->vaft <= v->vfore))
31                  return("illegal fore/aft clipping plane");
32  
33          if (normalize(v->vdir) == 0.0)          /* normalize direction */
# Line 63 | Line 61 | register VIEW  *v;
61                  v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0));
62                  v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
63                  break;
64 +        case VT_CYL:                            /* cylindrical panorama */
65 +                if (v->horiz > 360.0+FTINY)
66 +                        return(ill_horiz);
67 +                if (v->vert >= 180.0-FTINY)
68 +                        return(ill_vert);
69 +                v->hn2 = v->horiz * (PI/180.0);
70 +                v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
71 +                break;
72          case VT_ANG:                            /* angular fisheye */
73                  if (v->horiz > 360.0+FTINY)
74                          return(ill_horiz);
75                  if (v->vert > 360.0+FTINY)
76                          return(ill_vert);
77 <                v->hn2 = v->horiz / 90.0;
78 <                v->vn2 = v->vert / 90.0;
77 >                v->hn2 = v->horiz * (PI/180.0);
78 >                v->vn2 = v->vert * (PI/180.0);
79                  break;
80          case VT_HEM:                            /* hemispherical fisheye */
81                  if (v->horiz > 180.0+FTINY)
# Line 83 | Line 89 | register VIEW  *v;
89                  return("unknown view type");
90          }
91          if (v->type != VT_ANG) {
92 <                v->hvec[0] *= v->hn2;
93 <                v->hvec[1] *= v->hn2;
94 <                v->hvec[2] *= v->hn2;
92 >                if (v->type != VT_CYL) {
93 >                        v->hvec[0] *= v->hn2;
94 >                        v->hvec[1] *= v->hn2;
95 >                        v->hvec[2] *= v->hn2;
96 >                }
97                  v->vvec[0] *= v->vn2;
98                  v->vvec[1] *= v->vn2;
99                  v->vvec[2] *= v->vn2;
# Line 97 | Line 105 | register VIEW  *v;
105   }
106  
107  
108 + void
109   normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
110   double  va;                     /* view aspect ratio */
111   double  *ap;                    /* pixel aspect in (or out if 0) */
# Line 131 | Line 140 | double  x, y;
140                  orig[2] = v->vp[2] + v->vfore*v->vdir[2]
141                                  + x*v->hvec[2] + y*v->vvec[2];
142                  VCOPY(direc, v->vdir);
143 <                return(v->vaft - v->vfore);
143 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
144          case VT_PER:                    /* perspective view */
145                  direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
146                  direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
# Line 140 | Line 149 | double  x, y;
149                  orig[1] = v->vp[1] + v->vfore*direc[1];
150                  orig[2] = v->vp[2] + v->vfore*direc[2];
151                  d = normalize(direc);
152 <                return((v->vaft - v->vfore)*d);
152 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
153          case VT_HEM:                    /* hemispherical fisheye */
154                  z = 1.0 - x*x*v->hn2 - y*y*v->vn2;
155                  if (z < 0.0)
# Line 152 | Line 161 | double  x, y;
161                  orig[0] = v->vp[0] + v->vfore*direc[0];
162                  orig[1] = v->vp[1] + v->vfore*direc[1];
163                  orig[2] = v->vp[2] + v->vfore*direc[2];
164 <                return(v->vaft - v->vfore);
164 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
165 >        case VT_CYL:                    /* cylindrical panorama */
166 >                d = x * v->horiz * (PI/180.0);
167 >                z = cos(d);
168 >                x = sin(d);
169 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
170 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
171 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
172 >                orig[0] = v->vp[0] + v->vfore*direc[0];
173 >                orig[1] = v->vp[1] + v->vfore*direc[1];
174 >                orig[2] = v->vp[2] + v->vfore*direc[2];
175 >                d = normalize(direc);
176 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
177          case VT_ANG:                    /* angular fisheye */
178                  x *= v->horiz/180.0;
179                  y *= v->vert/180.0;
# Line 170 | Line 191 | double  x, y;
191                  orig[0] = v->vp[0] + v->vfore*direc[0];
192                  orig[1] = v->vp[1] + v->vfore*direc[1];
193                  orig[2] = v->vp[2] + v->vfore*direc[2];
194 <                return(v->vaft - v->vfore);
194 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
195          }
196          return(-1.0);
197   }
198  
199  
200 + void
201   viewloc(ip, v, p)               /* find image location for point */
202   FVECT  ip;
203   register VIEW  *v;
204   FVECT  p;
205   {
206 <        double  d;
206 >        double  d, d2;
207          FVECT  disp;
208  
209          disp[0] = p[0] - v->vp[0];
# Line 194 | Line 216 | FVECT  p;
216                  break;
217          case VT_PER:                    /* perspective view */
218                  d = DOT(disp,v->vdir);
219 <                ip[2] = sqrt(DOT(disp,disp));
219 >                ip[2] = VLEN(disp);
220                  if (d < 0.0) {          /* fold pyramid */
221                          ip[2] = -ip[2];
222                          d = -d;
# Line 215 | Line 237 | FVECT  p;
237                          ip[2] = d;
238                  ip[2] -= v->vfore;
239                  break;
240 +        case VT_CYL:                    /* cylindrical panorama */
241 +                d = DOT(disp,v->hvec);
242 +                d2 = DOT(disp,v->vdir);
243 +                ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
244 +                d = 1.0/sqrt(d*d + d2*d2);
245 +                ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
246 +                ip[2] = VLEN(disp);
247 +                ip[2] *= (1.0 - v->vfore*d);
248 +                return;
249          case VT_ANG:                    /* angular fisheye */
250                  ip[0] = 0.5 - v->hoff;
251                  ip[1] = 0.5 - v->voff;
# Line 224 | Line 255 | FVECT  p;
255                          return;
256                  if (d <= -(1.0-FTINY)) {
257                          ip[0] += 180.0/v->horiz;
227                        ip[1] += 180.0/v->vert;
258                          return;
259                  }
260                  d = acos(d)/PI / sqrt(1.0 - d*d);
# Line 237 | Line 267 | FVECT  p;
267   }
268  
269  
270 + void
271   pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
272 < FLOAT  loc[2];
272 > RREAL  loc[2];
273   register RESOLU  *rp;
274   int  px, py;
275   {
276          register int  x, y;
277  
278 <        if (rp->or & YMAJOR) {
278 >        if (rp->rt & YMAJOR) {
279                  x = px;
280                  y = py;
281          } else {
282                  x = py;
283                  y = px;
284          }
285 <        if (rp->or & XDECR)
285 >        if (rp->rt & XDECR)
286                  x = rp->xr-1 - x;
287 <        if (rp->or & YDECR)
287 >        if (rp->rt & YDECR)
288                  y = rp->yr-1 - y;
289          loc[0] = (x+.5)/rp->xr;
290          loc[1] = (y+.5)/rp->yr;
291   }
292  
293  
294 + void
295   loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
296   int  pp[2];
297   register RESOLU  *rp;
# Line 269 | Line 301 | double  lx, ly;
301  
302          x = lx * rp->xr;
303          y = ly * rp->yr;
304 <        if (rp->or & XDECR)
304 >        if (rp->rt & XDECR)
305                  x = rp->xr-1 - x;
306 <        if (rp->or & YDECR)
306 >        if (rp->rt & YDECR)
307                  y = rp->yr-1 - y;
308 <        if (rp->or & YMAJOR) {
308 >        if (rp->rt & YMAJOR) {
309                  pp[0] = x;
310                  pp[1] = y;
311          } else {
# Line 360 | Line 392 | register char  *s;
392          int  na;
393          int  nvopts = 0;
394  
395 +        while (*s == ' ')
396 +                s++;
397          if (*s != '-')
398 <                s = sskip(s);
398 >                s = sskip2(s,1);
399          while (*s) {
400                  ac = 0;
401                  do {
402 <                        av[ac++] = s;
402 >                        if (ac || *s == '-')
403 >                                av[ac++] = s;
404                          while (*s && *s != ' ')
405                                  s++;
406                          while (*s == ' ')
# Line 382 | Line 417 | register char  *s;
417   }
418  
419  
420 + void
421   fprintview(vp, fp)                      /* write out view parameters */
422   register VIEW  *vp;
423   FILE  *fp;
# Line 396 | Line 432 | FILE  *fp;
432   }
433  
434  
435 + char *
436 + viewopt(vp)                             /* translate to minimal view string */
437 + register VIEW  *vp;
438 + {
439 +        static char  vwstr[128];
440 +        register char  *cp = vwstr;
441 +
442 +        if (vp->type != stdview.type) {
443 +                sprintf(cp, " -vt%c", vp->type);
444 +                cp += strlen(cp);
445 +        }
446 +        if (!VEQ(vp->vp,stdview.vp)) {
447 +                sprintf(cp, " -vp %.6g %.6g %.6g",
448 +                                vp->vp[0], vp->vp[1], vp->vp[2]);
449 +                cp += strlen(cp);
450 +        }
451 +        if (!VEQ(vp->vdir,stdview.vdir)) {
452 +                sprintf(cp, " -vd %.6g %.6g %.6g",
453 +                                vp->vdir[0], vp->vdir[1], vp->vdir[2]);
454 +                cp += strlen(cp);
455 +        }
456 +        if (!VEQ(vp->vup,stdview.vup)) {
457 +                sprintf(cp, " -vu %.6g %.6g %.6g",
458 +                                vp->vup[0], vp->vup[1], vp->vup[2]);
459 +                cp += strlen(cp);
460 +        }
461 +        if (!FEQ(vp->horiz,stdview.horiz)) {
462 +                sprintf(cp, " -vh %.6g", vp->horiz);
463 +                cp += strlen(cp);
464 +        }
465 +        if (!FEQ(vp->vert,stdview.vert)) {
466 +                sprintf(cp, " -vv %.6g", vp->vert);
467 +                cp += strlen(cp);
468 +        }
469 +        if (!FEQ(vp->vfore,stdview.vfore)) {
470 +                sprintf(cp, " -vo %.6g", vp->vfore);
471 +                cp += strlen(cp);
472 +        }
473 +        if (!FEQ(vp->vaft,stdview.vaft)) {
474 +                sprintf(cp, " -va %.6g", vp->vaft);
475 +                cp += strlen(cp);
476 +        }
477 +        if (!FEQ(vp->hoff,stdview.hoff)) {
478 +                sprintf(cp, " -vs %.6g", vp->hoff);
479 +                cp += strlen(cp);
480 +        }
481 +        if (!FEQ(vp->voff,stdview.voff)) {
482 +                sprintf(cp, " -vl %.6g", vp->voff);
483 +                cp += strlen(cp);
484 +        }
485 +        return(vwstr);
486 + }
487 +
488 +
489   int
490   isview(s)                               /* is this a view string? */
491   char  *s;
# Line 431 | Line 521 | struct myview {
521   };
522  
523  
524 < static
524 > static int
525   gethview(s, v)                          /* get view from header */
526   char  *s;
527   register struct myview  *v;
528   {
529          if (isview(s) && sscanview(v->hv, s) > 0)
530                  v->ok++;
531 +        return(0);
532   }
533  
534  
# Line 450 | Line 541 | RESOLU  *rp;
541          struct myview   mvs;
542          FILE  *fp;
543  
544 <        if ((fp = fopen(fname, "r")) == NULL)
544 >        if (fname == NULL || !strcmp(fname, "-"))
545 >                fp = stdin;
546 >        else if ((fp = fopen(fname, "r")) == NULL)
547                  return(-1);
548  
549          mvs.hv = vp;
550          mvs.ok = 0;
551  
552 <        getheader(fp, gethview, &mvs);
552 >        getheader(fp, (int (*)(char *, char *))&gethview, (char *)&mvs);
553  
554          if (rp != NULL && !fgetsresolu(rp, fp))
555                  mvs.ok = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines