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.8 by greg, Wed Dec 21 09:07:19 1994 UTC vs.
Revision 2.14 by gwlarson, Tue Oct 27 08:44:29 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1994 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 6 | Line 6 | static char SCCSid[] = "$SunId$ LBL";
6  
7   /*
8   *  image.c - routines for image generation.
9 *
10 *     10/17/85
9   */
10  
11   #include  "standard.h"
# Line 18 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "paths.h"
18  
19 + #define  FEQ(x,y)       (fabs((x)-(y)) <= FTINY)
20 + #define  VEQ(v,w)       (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \
21 +                                && FEQ((v)[2],(w)[2]))
22 +
23   VIEW  stdview = STDVIEW;                /* default view parameters */
24  
25  
# Line 63 | Line 65 | register VIEW  *v;
65                  v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0));
66                  v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
67                  break;
68 +        case VT_CYL:                            /* cylindrical panorama */
69 +                if (v->horiz > 360.0+FTINY)
70 +                        return(ill_horiz);
71 +                if (v->vert >= 180.0-FTINY)
72 +                        return(ill_vert);
73 +                v->hn2 = v->horiz * (PI/180.0);
74 +                v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
75 +                break;
76          case VT_ANG:                            /* angular fisheye */
77                  if (v->horiz > 360.0+FTINY)
78                          return(ill_horiz);
79                  if (v->vert > 360.0+FTINY)
80                          return(ill_vert);
81 <                v->hn2 = v->horiz / 90.0;
82 <                v->vn2 = v->vert / 90.0;
81 >                v->hn2 = v->horiz * (PI/180.0);
82 >                v->vn2 = v->vert * (PI/180.0);
83                  break;
84          case VT_HEM:                            /* hemispherical fisheye */
85                  if (v->horiz > 180.0+FTINY)
# Line 83 | Line 93 | register VIEW  *v;
93                  return("unknown view type");
94          }
95          if (v->type != VT_ANG) {
96 <                v->hvec[0] *= v->hn2;
97 <                v->hvec[1] *= v->hn2;
98 <                v->hvec[2] *= v->hn2;
96 >                if (v->type != VT_CYL) {
97 >                        v->hvec[0] *= v->hn2;
98 >                        v->hvec[1] *= v->hn2;
99 >                        v->hvec[2] *= v->hn2;
100 >                }
101                  v->vvec[0] *= v->vn2;
102                  v->vvec[1] *= v->vn2;
103                  v->vvec[2] *= v->vn2;
# Line 153 | Line 165 | double  x, y;
165                  orig[1] = v->vp[1] + v->vfore*direc[1];
166                  orig[2] = v->vp[2] + v->vfore*direc[2];
167                  return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
168 +        case VT_CYL:                    /* cylindrical panorama */
169 +                d = x * v->horiz * (PI/180.0);
170 +                z = cos(d);
171 +                x = sin(d);
172 +                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
173 +                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
174 +                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
175 +                orig[0] = v->vp[0] + v->vfore*direc[0];
176 +                orig[1] = v->vp[1] + v->vfore*direc[1];
177 +                orig[2] = v->vp[2] + v->vfore*direc[2];
178 +                d = normalize(direc);
179 +                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
180          case VT_ANG:                    /* angular fisheye */
181                  x *= v->horiz/180.0;
182                  y *= v->vert/180.0;
# Line 181 | Line 205 | 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 194 | 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 215 | Line 239 | FVECT  p;
239                          ip[2] = d;
240                  ip[2] -= v->vfore;
241                  break;
242 +        case VT_CYL:                    /* cylindrical panorama */
243 +                d = DOT(disp,v->hvec);
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 +                if (v->vfore > FTINY)
250 +                        ip[2] *= (1.0 - v->vfore*d);
251 +                return;
252          case VT_ANG:                    /* angular fisheye */
253                  ip[0] = 0.5 - v->hoff;
254                  ip[1] = 0.5 - v->voff;
# Line 224 | Line 258 | FVECT  p;
258                          return;
259                  if (d <= -(1.0-FTINY)) {
260                          ip[0] += 180.0/v->horiz;
227                        ip[1] += 180.0/v->vert;
261                          return;
262                  }
263                  d = acos(d)/PI / sqrt(1.0 - d*d);
# Line 361 | Line 394 | register char  *s;
394          int  nvopts = 0;
395  
396          if (*s != '-')
397 <                s = sskip(s);
397 >                s = sskip2(s,1);
398          while (*s) {
399                  ac = 0;
400                  do {
# Line 396 | Line 429 | FILE  *fp;
429   }
430  
431  
432 + char *
433 + viewopt(vp)                             /* translate to minimal view string */
434 + register VIEW  *vp;
435 + {
436 +        static char  vwstr[128];
437 +        register char  *cp = vwstr;
438 +
439 +        if (vp->type != stdview.type) {
440 +                sprintf(cp, " -vt%c", vp->type);
441 +                cp += strlen(cp);
442 +        }
443 +        if (!VEQ(vp->vp,stdview.vp)) {
444 +                sprintf(cp, " -vp %.6g %.6g %.6g",
445 +                                vp->vp[0], vp->vp[1], vp->vp[2]);
446 +                cp += strlen(cp);
447 +        }
448 +        if (!VEQ(vp->vdir,stdview.vdir)) {
449 +                sprintf(cp, " -vd %.6g %.6g %.6g",
450 +                                vp->vdir[0], vp->vdir[1], vp->vdir[2]);
451 +                cp += strlen(cp);
452 +        }
453 +        if (!VEQ(vp->vup,stdview.vup)) {
454 +                sprintf(cp, " -vu %.6g %.6g %.6g",
455 +                                vp->vup[0], vp->vup[1], vp->vup[2]);
456 +                cp += strlen(cp);
457 +        }
458 +        if (!FEQ(vp->horiz,stdview.horiz)) {
459 +                sprintf(cp, " -vh %.6g", vp->horiz);
460 +                cp += strlen(cp);
461 +        }
462 +        if (!FEQ(vp->vert,stdview.vert)) {
463 +                sprintf(cp, " -vv %.6g", vp->vert);
464 +                cp += strlen(cp);
465 +        }
466 +        if (!FEQ(vp->vfore,stdview.vfore)) {
467 +                sprintf(cp, " -vo %.6g", vp->vfore);
468 +                cp += strlen(cp);
469 +        }
470 +        if (!FEQ(vp->vaft,stdview.vaft)) {
471 +                sprintf(cp, " -va %.6g", vp->vaft);
472 +                cp += strlen(cp);
473 +        }
474 +        if (!FEQ(vp->hoff,stdview.hoff)) {
475 +                sprintf(cp, " -vs %.6g", vp->hoff);
476 +                cp += strlen(cp);
477 +        }
478 +        if (!FEQ(vp->voff,stdview.voff)) {
479 +                sprintf(cp, " -vl %.6g", vp->voff);
480 +                cp += strlen(cp);
481 +        }
482 +        return(vwstr);
483 + }
484 +
485 +
486   int
487   isview(s)                               /* is this a view string? */
488   char  *s;
# Line 431 | Line 518 | struct myview {
518   };
519  
520  
521 < static
521 > static int
522   gethview(s, v)                          /* get view from header */
523   char  *s;
524   register struct myview  *v;
525   {
526          if (isview(s) && sscanview(v->hv, s) > 0)
527                  v->ok++;
528 +        return(0);
529   }
530  
531  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines