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.5 by greg, Tue Sep 8 10:04:30 1992 UTC vs.
Revision 2.28 by greg, Tue Jun 8 19:48:29 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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  "rtmath.h"
14 + #include  "paths.h"
15   #include  "view.h"
16  
17 #include  "resolu.h"
17  
18 < #include  "paths.h"
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 28 | 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->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 */
38                  return("zero view direction");
39  
# Line 59 | 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 79 | 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 93 | 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 107 | Line 124 | int  *xp, *yp;                 /* x and y resolution in (or out if *
124   }
125  
126  
127 + double
128   viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
129   FVECT  orig, direc;
130   register VIEW  *v;
# Line 119 | Line 137 | double  x, y;
137  
138          switch(v->type) {
139          case VT_PAR:                    /* parallel view */
140 <                orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0];
141 <                orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1];
142 <                orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2];
140 >                orig[0] = v->vp[0] + v->vfore*v->vdir[0]
141 >                                + x*v->hvec[0] + y*v->vvec[0];
142 >                orig[1] = v->vp[1] + v->vfore*v->vdir[1]
143 >                                + x*v->hvec[1] + y*v->vvec[1];
144 >                orig[2] = v->vp[2] + v->vfore*v->vdir[2]
145 >                                + x*v->hvec[2] + y*v->vvec[2];
146                  VCOPY(direc, v->vdir);
147 <                return(0);
147 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
148          case VT_PER:                    /* perspective view */
128                VCOPY(orig, v->vp);
149                  direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
150                  direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
151                  direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
152 <                normalize(direc);
153 <                return(0);
152 >                orig[0] = v->vp[0] + v->vfore*direc[0];
153 >                orig[1] = v->vp[1] + v->vfore*direc[1];
154 >                orig[2] = v->vp[2] + v->vfore*direc[2];
155 >                d = normalize(direc);
156 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
157          case VT_HEM:                    /* hemispherical fisheye */
158                  z = 1.0 - x*x*v->hn2 - y*y*v->vn2;
159                  if (z < 0.0)
160 <                        return(-1);
160 >                        return(-1.0);
161                  z = sqrt(z);
139                VCOPY(orig, v->vp);
162                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
163                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
164                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
165 <                return(0);
165 >                orig[0] = v->vp[0] + v->vfore*direc[0];
166 >                orig[1] = v->vp[1] + v->vfore*direc[1];
167 >                orig[2] = v->vp[2] + v->vfore*direc[2];
168 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
169 >        case VT_CYL:                    /* cylindrical panorama */
170 >                d = x * v->horiz * (PI/180.0);
171 >                z = cos(d);
172 >                x = sin(d);
173 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
174 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
175 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
176 >                orig[0] = v->vp[0] + v->vfore*direc[0];
177 >                orig[1] = v->vp[1] + v->vfore*direc[1];
178 >                orig[2] = v->vp[2] + v->vfore*direc[2];
179 >                d = normalize(direc);
180 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
181          case VT_ANG:                    /* angular fisheye */
182                  x *= v->horiz/180.0;
183                  y *= v->vert/180.0;
184                  d = x*x + y*y;
185                  if (d > 1.0)
186 <                        return(-1);
150 <                VCOPY(orig, v->vp);
151 <                if (d <= FTINY) {
152 <                        VCOPY(direc, v->vdir);
153 <                        return(0);
154 <                }
186 >                        return(-1.0);
187                  d = sqrt(d);
188                  z = cos(PI*d);
189 <                d = sqrt(1 - z*z)/d;
189 >                d = d <= FTINY ? PI : sqrt(1 - z*z)/d;
190                  x *= d;
191                  y *= d;
192                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
193                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
194                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
195 <                return(0);
195 >                orig[0] = v->vp[0] + v->vfore*direc[0];
196 >                orig[1] = v->vp[1] + v->vfore*direc[1];
197 >                orig[2] = v->vp[2] + v->vfore*direc[2];
198 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
199          }
200 <        return(-1);
200 >        return(-1.0);
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 180 | Line 216 | FVECT  p;
216  
217          switch (v->type) {
218          case VT_PAR:                    /* parallel view */
219 <                ip[2] = DOT(disp,v->vdir);
219 >                ip[2] = DOT(disp,v->vdir) - v->vfore;
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;
227 <                } else if (d > FTINY) {
227 >                }
228 >                if (d > FTINY) {
229                          d = 1.0/d;
230                          disp[0] *= d;
231                          disp[1] *= d;
232                          disp[2] *= d;
233                  }
234 +                ip[2] *= (1.0 - v->vfore*d);
235                  break;
236          case VT_HEM:                    /* hemispherical fisheye */
237                  d = normalize(disp);
# Line 201 | Line 239 | FVECT  p;
239                          ip[2] = -d;
240                  else
241                          ip[2] = d;
242 +                ip[2] -= v->vfore;
243                  break;
244 +        case VT_CYL:                    /* cylindrical panorama */
245 +                d = DOT(disp,v->hvec);
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;
255                  ip[1] = 0.5 - v->voff;
256 <                ip[2] = normalize(disp);
256 >                ip[2] = normalize(disp) - v->vfore;
257                  d = DOT(disp,v->vdir);
258                  if (d >= 1.0-FTINY)
259                          return;
260                  if (d <= -(1.0-FTINY)) {
261 <                        ip[1] += 180.0/v->horiz;
214 <                        ip[2] += 180.0/v->vert;
261 >                        ip[0] += 180.0/v->horiz;
262                          return;
263                  }
264                  d = acos(d)/PI / sqrt(1.0 - d*d);
# Line 224 | 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 256 | 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 314 | Line 363 | register char  *av[];
363                  check(3,"f");
364                  v->vert = atof(av[1]);
365                  return(1);
366 +        case 'o':                       /* fore clipping plane */
367 +                check(3,"f");
368 +                v->vfore = atof(av[1]);
369 +                return(1);
370 +        case 'a':                       /* aft clipping plane */
371 +                check(3,"f");
372 +                v->vaft = atof(av[1]);
373 +                return(1);
374          case 's':                       /* shift */
375                  check(3,"f");
376                  v->hoff = atof(av[1]);
# Line 339 | 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 361 | 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 370 | Line 431 | FILE  *fp;
431          fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
432          fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
433          fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
434 +        fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft);
435          fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff);
436   }
437  
438  
439 + char *
440 + viewopt(vp)                             /* translate to minimal view string */
441 + register VIEW  *vp;
442 + {
443 +        static char  vwstr[128];
444 +        register char  *cp = vwstr;
445 +
446 +        if (vp->type != stdview.type) {
447 +                sprintf(cp, " -vt%c", vp->type);
448 +                cp += strlen(cp);
449 +        }
450 +        if (!VEQ(vp->vp,stdview.vp)) {
451 +                sprintf(cp, " -vp %.6g %.6g %.6g",
452 +                                vp->vp[0], vp->vp[1], vp->vp[2]);
453 +                cp += strlen(cp);
454 +        }
455 +        if (!VEQ(vp->vdir,stdview.vdir)) {
456 +                sprintf(cp, " -vd %.6g %.6g %.6g",
457 +                                vp->vdir[0], vp->vdir[1], vp->vdir[2]);
458 +                cp += strlen(cp);
459 +        }
460 +        if (!VEQ(vp->vup,stdview.vup)) {
461 +                sprintf(cp, " -vu %.6g %.6g %.6g",
462 +                                vp->vup[0], vp->vup[1], vp->vup[2]);
463 +                cp += strlen(cp);
464 +        }
465 +        if (!FEQ(vp->horiz,stdview.horiz)) {
466 +                sprintf(cp, " -vh %.6g", vp->horiz);
467 +                cp += strlen(cp);
468 +        }
469 +        if (!FEQ(vp->vert,stdview.vert)) {
470 +                sprintf(cp, " -vv %.6g", vp->vert);
471 +                cp += strlen(cp);
472 +        }
473 +        if (!FEQ(vp->vfore,stdview.vfore)) {
474 +                sprintf(cp, " -vo %.6g", vp->vfore);
475 +                cp += strlen(cp);
476 +        }
477 +        if (!FEQ(vp->vaft,stdview.vaft)) {
478 +                sprintf(cp, " -va %.6g", vp->vaft);
479 +                cp += strlen(cp);
480 +        }
481 +        if (!FEQ(vp->hoff,stdview.hoff)) {
482 +                sprintf(cp, " -vs %.6g", vp->hoff);
483 +                cp += strlen(cp);
484 +        }
485 +        if (!FEQ(vp->voff,stdview.voff)) {
486 +                sprintf(cp, " -vl %.6g", vp->voff);
487 +                cp += strlen(cp);
488 +        }
489 +        return(vwstr);
490 + }
491 +
492 +
493   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 409 | 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 428 | 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