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 1.15 by greg, Thu Apr 18 14:52:55 1991 UTC vs.
Revision 2.6 by greg, Sat Dec 5 16:23:37 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "view.h"
16  
17 + #include  "resolu.h"
18 +
19 + #include  "paths.h"
20 +
21   VIEW  stdview = STDVIEW;                /* default view parameters */
22  
23  
# Line 144 | Line 148 | double  x, y;
148                  if (d > 1.0)
149                          return(-1);
150                  VCOPY(orig, v->vp);
147                if (d <= FTINY) {
148                        VCOPY(direc, v->vdir);
149                        return(0);
150                }
151                  d = sqrt(d);
152                  z = cos(PI*d);
153 <                d = sqrt(1 - z*z)/d;
153 >                d = d <= FTINY ? PI : sqrt(1 - z*z)/d;
154                  x *= d;
155                  y *= d;
156                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
# Line 162 | Line 162 | double  x, y;
162   }
163  
164  
165 < viewpixel(xp, yp, zp, v, p)             /* find image location for point */
166 < double  *xp, *yp, *zp;
165 > viewloc(ip, v, p)               /* find image location for point */
166 > FVECT  ip;
167   register VIEW  *v;
168   FVECT  p;
169   {
# Line 176 | Line 176 | FVECT  p;
176  
177          switch (v->type) {
178          case VT_PAR:                    /* parallel view */
179 <                if (zp != NULL)
180 <                        *zp = DOT(disp,v->vdir);
179 >                ip[2] = DOT(disp,v->vdir);
180                  break;
181          case VT_PER:                    /* perspective view */
182                  d = DOT(disp,v->vdir);
183 <                if (zp != NULL) {
184 <                        *zp = sqrt(DOT(disp,disp));
185 <                        if (d < 0.0)
187 <                                *zp = -*zp;
188 <                }
189 <                if (d < 0.0)            /* fold pyramid */
183 >                ip[2] = sqrt(DOT(disp,disp));
184 >                if (d < 0.0) {          /* fold pyramid */
185 >                        ip[2] = -ip[2];
186                          d = -d;
187 <                if (d > FTINY) {
187 >                } else if (d > FTINY) {
188                          d = 1.0/d;
189                          disp[0] *= d;
190                          disp[1] *= d;
# Line 197 | Line 193 | FVECT  p;
193                  break;
194          case VT_HEM:                    /* hemispherical fisheye */
195                  d = normalize(disp);
196 <                if (zp != NULL) {
197 <                        if (DOT(disp,v->vdir) < 0.0)
198 <                                *zp = -d;
199 <                        else
204 <                                *zp = d;
205 <                }
196 >                if (DOT(disp,v->vdir) < 0.0)
197 >                        ip[2] = -d;
198 >                else
199 >                        ip[2] = d;
200                  break;
201          case VT_ANG:                    /* angular fisheye */
202 <                d = normalize(disp);
203 <                if (zp != NULL)
204 <                        *zp = d;
211 <                *xp = 0.5 - v->hoff;
212 <                *yp = 0.5 - v->voff;
202 >                ip[0] = 0.5 - v->hoff;
203 >                ip[1] = 0.5 - v->voff;
204 >                ip[2] = normalize(disp);
205                  d = DOT(disp,v->vdir);
206                  if (d >= 1.0-FTINY)
207                          return;
208                  if (d <= -(1.0-FTINY)) {
209 <                        *xp += 180.0/v->horiz;
210 <                        *yp += 180.0/v->vert;
209 >                        ip[1] += 180.0/v->horiz;
210 >                        ip[2] += 180.0/v->vert;
211                          return;
212                  }
213                  d = acos(d)/PI / sqrt(1.0 - d*d);
214 <                *xp += DOT(disp,v->hvec)*d*180.0/v->horiz;
215 <                *yp += DOT(disp,v->vvec)*d*180.0/v->vert;
214 >                ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz;
215 >                ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert;
216                  return;
217          }
218 <        *xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
219 <        *yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
218 >        ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
219 >        ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
220   }
221  
222  
223 + pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
224 + FLOAT  loc[2];
225 + register RESOLU  *rp;
226 + int  px, py;
227 + {
228 +        register int  x, y;
229 +
230 +        if (rp->or & YMAJOR) {
231 +                x = px;
232 +                y = py;
233 +        } else {
234 +                x = py;
235 +                y = px;
236 +        }
237 +        if (rp->or & XDECR)
238 +                x = rp->xr-1 - x;
239 +        if (rp->or & YDECR)
240 +                y = rp->yr-1 - y;
241 +        loc[0] = (x+.5)/rp->xr;
242 +        loc[1] = (y+.5)/rp->yr;
243 + }
244 +
245 +
246 + loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
247 + int  pp[2];
248 + register RESOLU  *rp;
249 + double  lx, ly;
250 + {
251 +        register int  x, y;
252 +
253 +        x = lx * rp->xr;
254 +        y = ly * rp->yr;
255 +        if (rp->or & XDECR)
256 +                x = rp->xr-1 - x;
257 +        if (rp->or & YDECR)
258 +                y = rp->yr-1 - y;
259 +        if (rp->or & YMAJOR) {
260 +                pp[0] = x;
261 +                pp[1] = y;
262 +        } else {
263 +                pp[0] = y;
264 +                pp[1] = x;
265 +        }
266 + }
267 +
268 +
269   int
270   getviewopt(v, ac, av)                   /* process view argument */
271   register VIEW  *v;
272   int  ac;
273   register char  *av[];
274   {
275 < #define check(c,n)      if ((av[0][c]&&av[0][c]!=' ') || n>=ac) return(-1)
276 <        extern double  atof();
275 > #define check(c,l)      if ((av[0][c]&&av[0][c]!=' ') || \
276 >                        badarg(ac-1,av+1,l)) return(-1)
277  
278          if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
279                  return(-1);
# Line 243 | Line 281 | register char  *av[];
281          case 't':                       /* type */
282                  if (!av[0][3] || av[0][3]==' ')
283                          return(-1);
284 <                check(4,0);
284 >                check(4,"");
285                  v->type = av[0][3];
286                  return(0);
287          case 'p':                       /* point */
288 <                check(3,3);
288 >                check(3,"fff");
289                  v->vp[0] = atof(av[1]);
290                  v->vp[1] = atof(av[2]);
291                  v->vp[2] = atof(av[3]);
292                  return(3);
293          case 'd':                       /* direction */
294 <                check(3,3);
294 >                check(3,"fff");
295                  v->vdir[0] = atof(av[1]);
296                  v->vdir[1] = atof(av[2]);
297                  v->vdir[2] = atof(av[3]);
298                  return(3);
299          case 'u':                       /* up */
300 <                check(3,3);
300 >                check(3,"fff");
301                  v->vup[0] = atof(av[1]);
302                  v->vup[1] = atof(av[2]);
303                  v->vup[2] = atof(av[3]);
304                  return(3);
305          case 'h':                       /* horizontal size */
306 <                check(3,1);
306 >                check(3,"f");
307                  v->horiz = atof(av[1]);
308                  return(1);
309          case 'v':                       /* vertical size */
310 <                check(3,1);
310 >                check(3,"f");
311                  v->vert = atof(av[1]);
312                  return(1);
313          case 's':                       /* shift */
314 <                check(3,1);
314 >                check(3,"f");
315                  v->hoff = atof(av[1]);
316                  return(1);
317          case 'l':                       /* lift */
318 <                check(3,1);
318 >                check(3,"f");
319                  v->voff = atof(av[1]);
320                  return(1);
321          default:
# Line 297 | Line 335 | register char  *s;
335          int  na;
336          int  nvopts = 0;
337  
338 <        while (*s == ' ')
339 <                s++;
338 >        if (*s != '-')
339 >                s = sskip(s);
340          while (*s) {
341                  ac = 0;
342                  do {
# Line 332 | Line 370 | FILE  *fp;
370   }
371  
372  
373 < static char  *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL};
373 > int
374 > isview(s)                               /* is this a view string? */
375 > char  *s;
376 > {
377 >        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL};
378 >        extern char  *progname;
379 >        register char  *cp;
380 >        register char  **an;
381 >                                        /* add program name to list */
382 >        if (altname[0] == NULL) {
383 >                for (cp = progname; *cp; cp++)
384 >                        ;
385 >                while (cp > progname && !ISDIRSEP(cp[-1]))
386 >                        cp--;
387 >                altname[0] = cp;
388 >        }
389 >                                        /* skip leading path */
390 >        cp = s;
391 >        while (*cp && *cp != ' ')
392 >                cp++;
393 >        while (cp > s && !ISDIRSEP(cp[-1]))
394 >                cp--;
395 >        for (an = altname; *an != NULL; an++)
396 >                if (!strncmp(*an, cp, strlen(*an)))
397 >                        return(1);
398 >        return(0);
399 > }
400  
401 +
402   struct myview {
403          VIEW    *hv;
404          int     ok;
# Line 345 | Line 410 | gethview(s, v)                         /* get view from header */
410   char  *s;
411   register struct myview  *v;
412   {
413 <        register char  **an;
414 <
350 <        for (an = altname; *an != NULL; an++)
351 <                if (!strncmp(*an, s, strlen(*an))) {
352 <                        if (sscanview(v->hv, s+strlen(*an)) > 0)
353 <                                v->ok++;
354 <                        return;
355 <                }
413 >        if (isview(s) && sscanview(v->hv, s) > 0)
414 >                v->ok++;
415   }
416  
417  
418   int
419 < viewfile(fname, vp, xp, yp)             /* get view from file */
419 > viewfile(fname, vp, rp)                 /* get view from file */
420   char  *fname;
421   VIEW  *vp;
422 < int  *xp, *yp;
422 > RESOLU  *rp;
423   {
365        extern char  *progname;
424          struct myview   mvs;
425          FILE  *fp;
426  
427          if ((fp = fopen(fname, "r")) == NULL)
428                  return(-1);
429  
372        altname[0] = progname;
430          mvs.hv = vp;
431          mvs.ok = 0;
432  
433          getheader(fp, gethview, &mvs);
434  
435 <        if (xp != NULL && yp != NULL
379 <                        && fgetresolu(xp, yp, fp) == -1)
435 >        if (rp != NULL && !fgetsresolu(rp, fp))
436                  mvs.ok = 0;
437  
438          fclose(fp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines