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.2 by greg, Thu Dec 19 14:45:50 1991 UTC vs.
Revision 2.9 by greg, Fri Aug 18 10:20:10 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "resolu.h"
18  
19 + #include  "paths.h"
20 +
21   VIEW  stdview = STDVIEW;                /* default view parameters */
22  
23  
# Line 26 | Line 28 | register VIEW  *v;
28          static char  ill_horiz[] = "illegal horizontal view size";
29          static char  ill_vert[] = "illegal vertical view size";
30          
31 +        if (v->vfore < -FTINY || v->vaft < -FTINY ||
32 +                        (v->vaft > FTINY && v->vaft <= v->vfore))
33 +                return("illegal fore/aft clipping plane");
34 +
35          if (normalize(v->vdir) == 0.0)          /* normalize direction */
36                  return("zero view direction");
37  
# Line 57 | Line 63 | register VIEW  *v;
63                  v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0));
64                  v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
65                  break;
66 +        case VT_CYL:                            /* cylindrical panorama */
67 +                if (v->horiz > 360.0+FTINY)
68 +                        return(ill_horiz);
69 +                if (v->vert >= 180.0-FTINY)
70 +                        return(ill_vert);
71 +                v->hn2 = v->horiz * (PI/180.0);
72 +                v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
73 +                break;
74          case VT_ANG:                            /* angular fisheye */
75                  if (v->horiz > 360.0+FTINY)
76                          return(ill_horiz);
77                  if (v->vert > 360.0+FTINY)
78                          return(ill_vert);
79 <                v->hn2 = v->horiz / 90.0;
80 <                v->vn2 = v->vert / 90.0;
79 >                v->hn2 = v->horiz * (PI/180.0);
80 >                v->vn2 = v->vert * (PI/180.0);
81                  break;
82          case VT_HEM:                            /* hemispherical fisheye */
83                  if (v->horiz > 180.0+FTINY)
# Line 77 | Line 91 | register VIEW  *v;
91                  return("unknown view type");
92          }
93          if (v->type != VT_ANG) {
94 <                v->hvec[0] *= v->hn2;
95 <                v->hvec[1] *= v->hn2;
96 <                v->hvec[2] *= v->hn2;
94 >                if (v->type != VT_CYL) {
95 >                        v->hvec[0] *= v->hn2;
96 >                        v->hvec[1] *= v->hn2;
97 >                        v->hvec[2] *= v->hn2;
98 >                }
99                  v->vvec[0] *= v->vn2;
100                  v->vvec[1] *= v->vn2;
101                  v->vvec[2] *= v->vn2;
# Line 105 | Line 121 | int  *xp, *yp;                 /* x and y resolution in (or out if *
121   }
122  
123  
124 + double
125   viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
126   FVECT  orig, direc;
127   register VIEW  *v;
# Line 117 | Line 134 | double  x, y;
134  
135          switch(v->type) {
136          case VT_PAR:                    /* parallel view */
137 <                orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0];
138 <                orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1];
139 <                orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2];
137 >                orig[0] = v->vp[0] + v->vfore*v->vdir[0]
138 >                                + x*v->hvec[0] + y*v->vvec[0];
139 >                orig[1] = v->vp[1] + v->vfore*v->vdir[1]
140 >                                + x*v->hvec[1] + y*v->vvec[1];
141 >                orig[2] = v->vp[2] + v->vfore*v->vdir[2]
142 >                                + x*v->hvec[2] + y*v->vvec[2];
143                  VCOPY(direc, v->vdir);
144 <                return(0);
144 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
145          case VT_PER:                    /* perspective view */
126                VCOPY(orig, v->vp);
146                  direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
147                  direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
148                  direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
149 <                normalize(direc);
150 <                return(0);
149 >                orig[0] = v->vp[0] + v->vfore*direc[0];
150 >                orig[1] = v->vp[1] + v->vfore*direc[1];
151 >                orig[2] = v->vp[2] + v->vfore*direc[2];
152 >                d = normalize(direc);
153 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
154          case VT_HEM:                    /* hemispherical fisheye */
155                  z = 1.0 - x*x*v->hn2 - y*y*v->vn2;
156                  if (z < 0.0)
157 <                        return(-1);
157 >                        return(-1.0);
158                  z = sqrt(z);
137                VCOPY(orig, v->vp);
159                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
160                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
161                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
162 <                return(0);
162 >                orig[0] = v->vp[0] + v->vfore*direc[0];
163 >                orig[1] = v->vp[1] + v->vfore*direc[1];
164 >                orig[2] = v->vp[2] + v->vfore*direc[2];
165 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
166 >        case VT_CYL:                    /* cylindrical panorama */
167 >                d = x * v->horiz * (PI/180.0);
168 >                z = cos(d);
169 >                x = sin(d);
170 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
171 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
172 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
173 >                orig[0] = v->vp[0] + v->vfore*direc[0];
174 >                orig[1] = v->vp[1] + v->vfore*direc[1];
175 >                orig[2] = v->vp[2] + v->vfore*direc[2];
176 >                d = normalize(direc);
177 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
178          case VT_ANG:                    /* angular fisheye */
179                  x *= v->horiz/180.0;
180                  y *= v->vert/180.0;
181                  d = x*x + y*y;
182                  if (d > 1.0)
183 <                        return(-1);
148 <                VCOPY(orig, v->vp);
149 <                if (d <= FTINY) {
150 <                        VCOPY(direc, v->vdir);
151 <                        return(0);
152 <                }
183 >                        return(-1.0);
184                  d = sqrt(d);
185                  z = cos(PI*d);
186 <                d = sqrt(1 - z*z)/d;
186 >                d = d <= FTINY ? PI : sqrt(1 - z*z)/d;
187                  x *= d;
188                  y *= d;
189                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
190                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
191                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
192 <                return(0);
192 >                orig[0] = v->vp[0] + v->vfore*direc[0];
193 >                orig[1] = v->vp[1] + v->vfore*direc[1];
194 >                orig[2] = v->vp[2] + v->vfore*direc[2];
195 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
196          }
197 <        return(-1);
197 >        return(-1.0);
198   }
199  
200  
# Line 178 | Line 212 | FVECT  p;
212  
213          switch (v->type) {
214          case VT_PAR:                    /* parallel view */
215 <                ip[2] = DOT(disp,v->vdir);
215 >                ip[2] = DOT(disp,v->vdir) - v->vfore;
216                  break;
217          case VT_PER:                    /* perspective view */
218                  d = DOT(disp,v->vdir);
# Line 186 | Line 220 | FVECT  p;
220                  if (d < 0.0) {          /* fold pyramid */
221                          ip[2] = -ip[2];
222                          d = -d;
223 <                } else if (d > FTINY) {
223 >                }
224 >                if (d > FTINY) {
225                          d = 1.0/d;
226                          disp[0] *= d;
227                          disp[1] *= d;
228                          disp[2] *= d;
229                  }
230 +                ip[2] *= (1.0 - v->vfore*d);
231                  break;
232          case VT_HEM:                    /* hemispherical fisheye */
233                  d = normalize(disp);
# Line 199 | Line 235 | FVECT  p;
235                          ip[2] = -d;
236                  else
237                          ip[2] = d;
238 +                ip[2] -= v->vfore;
239                  break;
240 +        case VT_CYL:                    /* cylindrical panorama */
241 +                ip[2] = DOT(disp,v->vdir);
242 +                d = DOT(disp,v->hvec);
243 +                ip[0] = 180.0/PI * atan2(ip[2],d) / v->horiz + 0.5 - v->hoff;
244 +                ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
245 +                if (v->vfore > FTINY)
246 +                        ip[2] = sqrt(DOT(disp,disp)) *
247 +                                (1.0 - v->vfore/sqrt(d*d + ip[2]*ip[2]));
248 +                else
249 +                        ip[2] = sqrt(DOT(disp,disp));
250 +                return;
251          case VT_ANG:                    /* angular fisheye */
252                  ip[0] = 0.5 - v->hoff;
253                  ip[1] = 0.5 - v->voff;
254 <                ip[2] = normalize(disp);
254 >                ip[2] = normalize(disp) - v->vfore;
255                  d = DOT(disp,v->vdir);
256                  if (d >= 1.0-FTINY)
257                          return;
258                  if (d <= -(1.0-FTINY)) {
259 <                        ip[1] += 180.0/v->horiz;
212 <                        ip[2] += 180.0/v->vert;
259 >                        ip[0] += 180.0/v->horiz;
260                          return;
261                  }
262                  d = acos(d)/PI / sqrt(1.0 - d*d);
# Line 312 | Line 359 | register char  *av[];
359                  check(3,"f");
360                  v->vert = atof(av[1]);
361                  return(1);
362 +        case 'o':                       /* fore clipping plane */
363 +                check(3,"f");
364 +                v->vfore = atof(av[1]);
365 +                return(1);
366 +        case 'a':                       /* aft clipping plane */
367 +                check(3,"f");
368 +                v->vaft = atof(av[1]);
369 +                return(1);
370          case 's':                       /* shift */
371                  check(3,"f");
372                  v->hoff = atof(av[1]);
# Line 337 | Line 392 | register char  *s;
392          int  na;
393          int  nvopts = 0;
394  
395 <        while (*s == ' ')
396 <                s++;
395 >        if (*s != '-')
396 >                s = sskip(s);
397          while (*s) {
398                  ac = 0;
399                  do {
# Line 368 | Line 423 | FILE  *fp;
423          fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
424          fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
425          fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
426 +        fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft);
427          fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff);
428   }
429  
430  
431 < static char  *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL};
431 > int
432 > isview(s)                               /* is this a view string? */
433 > char  *s;
434 > {
435 >        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL};
436 >        extern char  *progname;
437 >        register char  *cp;
438 >        register char  **an;
439 >                                        /* add program name to list */
440 >        if (altname[0] == NULL) {
441 >                for (cp = progname; *cp; cp++)
442 >                        ;
443 >                while (cp > progname && !ISDIRSEP(cp[-1]))
444 >                        cp--;
445 >                altname[0] = cp;
446 >        }
447 >                                        /* skip leading path */
448 >        cp = s;
449 >        while (*cp && *cp != ' ')
450 >                cp++;
451 >        while (cp > s && !ISDIRSEP(cp[-1]))
452 >                cp--;
453 >        for (an = altname; *an != NULL; an++)
454 >                if (!strncmp(*an, cp, strlen(*an)))
455 >                        return(1);
456 >        return(0);
457 > }
458  
459 +
460   struct myview {
461          VIEW    *hv;
462          int     ok;
# Line 385 | Line 468 | gethview(s, v)                         /* get view from header */
468   char  *s;
469   register struct myview  *v;
470   {
471 <        register char  **an;
472 <
390 <        for (an = altname; *an != NULL; an++)
391 <                if (!strncmp(*an, s, strlen(*an))) {
392 <                        if (sscanview(v->hv, s+strlen(*an)) > 0)
393 <                                v->ok++;
394 <                        return;
395 <                }
471 >        if (isview(s) && sscanview(v->hv, s) > 0)
472 >                v->ok++;
473   }
474  
475  
# Line 402 | Line 479 | char  *fname;
479   VIEW  *vp;
480   RESOLU  *rp;
481   {
405        extern char  *progname;
482          struct myview   mvs;
483          FILE  *fp;
484  
485          if ((fp = fopen(fname, "r")) == NULL)
486                  return(-1);
487  
412        altname[0] = progname;
488          mvs.hv = vp;
489          mvs.ok = 0;
490  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines