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.3 by greg, Tue Apr 28 09:36:42 1992 UTC vs.
Revision 2.53 by greg, Wed Jan 12 21:07:39 2022 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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  <ctype.h>
13 + #include  "rtio.h"
14 + #include  "rtmath.h"
15 + #include  "paths.h"
16   #include  "view.h"
17  
17 #include  "resolu.h"
18
18   VIEW  stdview = STDVIEW;                /* default view parameters */
19  
20 + static gethfunc gethview;
21  
22 +
23   char *
24 < setview(v)              /* set hvec and vvec, return message on error */
25 < register VIEW  *v;
24 > setview(                /* set hvec and vvec, return message on error */
25 > VIEW  *v
26 > )
27   {
28          static char  ill_horiz[] = "illegal horizontal view size";
29          static char  ill_vert[] = "illegal vertical view size";
30          
31 <        if (normalize(v->vdir) == 0.0)          /* normalize direction */
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 (v->vdist <= FTINY)
36 >                return("illegal view distance");
37 >        v->vdist *= normalize(v->vdir);         /* normalize direction */
38 >        if (v->vdist == 0.0)
39                  return("zero view direction");
40  
41          if (normalize(v->vup) == 0.0)           /* normalize view up */
# Line 54 | Line 63 | register VIEW  *v;
63                          return(ill_horiz);
64                  if (v->vert >= 180.0-FTINY)
65                          return(ill_vert);
66 <                v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0));
67 <                v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
66 >                v->hn2 = 2.0 * tan(v->horiz*(PI/360.));
67 >                v->vn2 = 2.0 * tan(v->vert*(PI/360.));
68                  break;
69 +        case VT_CYL:                            /* cylindrical panorama */
70 +                if (v->horiz > 360.0+FTINY)
71 +                        return(ill_horiz);
72 +                if (v->vert >= 180.0-FTINY)
73 +                        return(ill_vert);
74 +                v->hn2 = v->horiz * (PI/180.0);
75 +                v->vn2 = 2.0 * tan(v->vert*(PI/360.));
76 +                break;
77          case VT_ANG:                            /* angular fisheye */
78                  if (v->horiz > 360.0+FTINY)
79                          return(ill_horiz);
80                  if (v->vert > 360.0+FTINY)
81                          return(ill_vert);
82 <                v->hn2 = v->horiz / 90.0;
83 <                v->vn2 = v->vert / 90.0;
82 >                v->hn2 = v->horiz * (PI/180.0);
83 >                v->vn2 = v->vert * (PI/180.0);
84                  break;
85          case VT_HEM:                            /* hemispherical fisheye */
86                  if (v->horiz > 180.0+FTINY)
87                          return(ill_horiz);
88                  if (v->vert > 180.0+FTINY)
89                          return(ill_vert);
90 <                v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0));
91 <                v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0));
90 >                v->hn2 = 2.0 * sin(v->horiz*(PI/360.));
91 >                v->vn2 = 2.0 * sin(v->vert*(PI/360.));
92                  break;
93 +        case VT_PLS:                            /* planispheric fisheye */
94 +                if (v->horiz >= 360.0-FTINY)
95 +                        return(ill_horiz);
96 +                if (v->vert >= 360.0-FTINY)
97 +                        return(ill_vert);
98 +                v->hn2 = 2.*sin(v->horiz*(PI/360.)) /
99 +                                (1.0 + cos(v->horiz*(PI/360.)));
100 +                v->vn2 = 2.*sin(v->vert*(PI/360.)) /
101 +                                (1.0 + cos(v->vert*(PI/360.)));
102 +                break;
103          default:
104                  return("unknown view type");
105          }
106 <        if (v->type != VT_ANG) {
107 <                v->hvec[0] *= v->hn2;
108 <                v->hvec[1] *= v->hn2;
109 <                v->hvec[2] *= v->hn2;
106 >        if (v->type != VT_ANG && v->type != VT_PLS) {
107 >                if (v->type != VT_CYL) {
108 >                        v->hvec[0] *= v->hn2;
109 >                        v->hvec[1] *= v->hn2;
110 >                        v->hvec[2] *= v->hn2;
111 >                }
112                  v->vvec[0] *= v->vn2;
113                  v->vvec[1] *= v->vn2;
114                  v->vvec[2] *= v->vn2;
# Line 91 | Line 120 | register VIEW  *v;
120   }
121  
122  
123 < normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
124 < double  va;                     /* view aspect ratio */
125 < double  *ap;                    /* pixel aspect in (or out if 0) */
126 < int  *xp, *yp;                  /* x and y resolution in (or out if *ap!=0) */
123 > char *
124 > cropview(                       /* crop a view to the indicated bounds */
125 > VIEW *v,
126 > double x0,
127 > double y0,
128 > double x1,
129 > double y1
130 > )
131   {
132 +        static char     ill_crop[] = "zero crop area";
133 +        static char     ill_hemi[] = "illegal crop for hemispherical view";
134 +        double  d;
135 +                                        /* order crop extrema */
136 +        if (x0 > x1) { d=x0; x0=x1; x1=d; }
137 +        if (y0 > y1) { d=y0; y0=y1; y1=d; }
138 +
139 +        d = x1 - x0;
140 +        if (d == .0)
141 +                return(ill_crop);
142 +        if (!FABSEQ(d, 1.))             /* adjust horizontal size? */
143 +                switch (v->type) {
144 +                case VT_PER:
145 +                        v->horiz = 360./PI*atan( d*tan(PI/360.*v->horiz) );
146 +                        break;
147 +                case VT_PAR:
148 +                case VT_ANG:
149 +                case VT_CYL:
150 +                        v->horiz *= d;
151 +                        break;
152 +                case VT_HEM:
153 +                        d *= sin(PI/360.*v->horiz);
154 +                        if (d > 1.)
155 +                                return(ill_hemi);
156 +                        v->horiz = 360./PI*asin( d );
157 +                        break;
158 +                case VT_PLS:
159 +                        d *= sin(PI/360.*v->horiz) /
160 +                                        (1. + cos(PI/360.*v->horiz));
161 +                        v->horiz = 360./PI*acos( (1. - d*d) / (1. + d*d) );
162 +                        break;
163 +                }
164 +        d = y1 - y0;
165 +        if (d == .0)
166 +                return(ill_crop);
167 +        if (!FABSEQ(d, 1.))             /* adjust vertical size? */
168 +                switch (v->type) {
169 +                case VT_PER:
170 +                case VT_CYL:
171 +                        v->vert = 360./PI*atan( d*tan(PI/360.*v->vert) );
172 +                        break;
173 +                case VT_PAR:
174 +                case VT_ANG:
175 +                        v->vert *= d;
176 +                        break;
177 +                case VT_HEM:
178 +                        d *= sin(PI/360.*v->vert);
179 +                        if (d > 1.)
180 +                                return(ill_hemi);
181 +                        v->vert = 360./PI*asin( d );
182 +                        break;
183 +                case VT_PLS:
184 +                        d *= sin(PI/360.*v->vert) /
185 +                                        (1. + cos(PI/360.*v->vert));
186 +                        v->vert = 360./PI*acos( (1. - d*d) / (1. + d*d) );
187 +                        break;
188 +                }
189 +                                        /* fix offsets */
190 +        v->hoff = ((x0 + x1)*.5 - .5 + v->hoff) / (x1 - x0);
191 +        v->voff = ((y0 + y1)*.5 - .5 + v->voff) / (y1 - y0);
192 +
193 +        return(setview(v));             /* final error checks & set-up */
194 + }
195 +
196 +
197 + void
198 + normaspect(                             /* fix pixel aspect or resolution */
199 + double  va,                     /* view aspect ratio */
200 + double  *ap,                    /* pixel aspect in (or out if 0) */
201 + int  *xp,
202 + int  *yp                        /* x and y resolution in (or out if *ap!=0) */
203 + )
204 + {
205          if (*ap <= FTINY)
206                  *ap = va * *xp / *yp;           /* compute pixel aspect */
207          else if (va * *xp > *ap * *yp)
# Line 105 | Line 211 | int  *xp, *yp;                 /* x and y resolution in (or out if *
211   }
212  
213  
214 < viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
215 < FVECT  orig, direc;
216 < register VIEW  *v;
217 < double  x, y;
214 > double
215 > viewray(                                /* compute ray origin and direction */
216 > FVECT  orig,
217 > FVECT  direc,
218 > VIEW  *v,
219 > double  x,
220 > double  y
221 > )
222   {
223          double  d, z;
224          
# Line 117 | Line 227 | double  x, y;
227  
228          switch(v->type) {
229          case VT_PAR:                    /* parallel view */
230 <                orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0];
231 <                orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1];
232 <                orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2];
230 >                orig[0] = v->vp[0] + v->vfore*v->vdir[0]
231 >                                + x*v->hvec[0] + y*v->vvec[0];
232 >                orig[1] = v->vp[1] + v->vfore*v->vdir[1]
233 >                                + x*v->hvec[1] + y*v->vvec[1];
234 >                orig[2] = v->vp[2] + v->vfore*v->vdir[2]
235 >                                + x*v->hvec[2] + y*v->vvec[2];
236                  VCOPY(direc, v->vdir);
237 <                return(0);
237 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
238          case VT_PER:                    /* perspective view */
126                VCOPY(orig, v->vp);
239                  direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
240                  direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
241                  direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
242 <                normalize(direc);
243 <                return(0);
242 >                VSUM(orig, v->vp, direc, v->vfore);
243 >                d = normalize(direc);
244 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
245          case VT_HEM:                    /* hemispherical fisheye */
246                  z = 1.0 - x*x*v->hn2 - y*y*v->vn2;
247                  if (z < 0.0)
248 <                        return(-1);
248 >                        return(-1.0);
249                  z = sqrt(z);
137                VCOPY(orig, v->vp);
250                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
251                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
252                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
253 <                return(0);
253 >                VSUM(orig, v->vp, direc, v->vfore);
254 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
255 >        case VT_CYL:                    /* cylindrical panorama */
256 >                d = x * v->horiz * (PI/180.0);
257 >                z = cos(d);
258 >                x = sin(d);
259 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
260 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
261 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
262 >                VSUM(orig, v->vp, direc, v->vfore);
263 >                d = normalize(direc);
264 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
265          case VT_ANG:                    /* angular fisheye */
266 <                x *= v->horiz/180.0;
267 <                y *= v->vert/180.0;
266 >                x *= (1.0/180.0)*v->horiz;
267 >                y *= (1.0/180.0)*v->vert;
268                  d = x*x + y*y;
269                  if (d > 1.0)
270 <                        return(-1);
148 <                VCOPY(orig, v->vp);
149 <                if (d <= FTINY) {
150 <                        VCOPY(direc, v->vdir);
151 <                        return(0);
152 <                }
270 >                        return(-1.0);
271                  d = sqrt(d);
272                  z = cos(PI*d);
273 <                d = sqrt(1 - z*z)/d;
273 >                d = d <= FTINY ? PI : sqrt(1.0 - z*z)/d;
274                  x *= d;
275                  y *= d;
276                  direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
277                  direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
278                  direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
279 <                return(0);
279 >                VSUM(orig, v->vp, direc, v->vfore);
280 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
281 >        case VT_PLS:                    /* planispheric fisheye */
282 >                x *= sqrt(v->hn2);
283 >                y *= sqrt(v->vn2);
284 >                d = x*x + y*y;
285 >                z = (1. - d)/(1. + d);
286 >                x *= (1. + z);
287 >                y *= (1. + z);
288 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
289 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
290 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
291 >                VSUM(orig, v->vp, direc, v->vfore);
292 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
293          }
294 <        return(-1);
294 >        return(-1.0);
295   }
296  
297  
298 < viewloc(ip, v, p)               /* find image location for point */
299 < FVECT  ip;
300 < register VIEW  *v;
301 < FVECT  p;
298 > int
299 > viewloc(                        /* find image location for point */
300 > FVECT  ip,
301 > VIEW  *v,
302 > FVECT  p
303 > )       /* Use VL_* flags to interpret return value */
304   {
305 <        double  d;
305 >        int     rflags = VL_GOOD;
306 >        double  d, d2;
307          FVECT  disp;
308  
309 <        disp[0] = p[0] - v->vp[0];
176 <        disp[1] = p[1] - v->vp[1];
177 <        disp[2] = p[2] - v->vp[2];
309 >        VSUB(disp, p, v->vp);
310  
311          switch (v->type) {
312          case VT_PAR:                    /* parallel view */
313 <                ip[2] = DOT(disp,v->vdir);
313 >                ip[2] = DOT(disp,v->vdir) - v->vfore;
314                  break;
315          case VT_PER:                    /* perspective view */
316                  d = DOT(disp,v->vdir);
317 <                ip[2] = sqrt(DOT(disp,disp));
318 <                if (d < 0.0) {          /* fold pyramid */
317 >                if ((v->vaft > FTINY) & (d >= v->vaft))
318 >                        rflags |= VL_BEYOND;
319 >                ip[2] = VLEN(disp);
320 >                if (d < -FTINY) {       /* fold pyramid */
321                          ip[2] = -ip[2];
322                          d = -d;
323 <                } else if (d > FTINY) {
324 <                        d = 1.0/d;
325 <                        disp[0] *= d;
326 <                        disp[1] *= d;
327 <                        disp[2] *= d;
328 <                }
323 >                } else if (d <= FTINY)
324 >                        return(VL_BAD); /* at infinite edge */
325 >                d = 1.0/d;
326 >                disp[0] *= d;
327 >                disp[1] *= d;
328 >                disp[2] *= d;
329 >                if (ip[2] < 0.0) d = -d;
330 >                ip[2] *= (1.0 - v->vfore*d);
331                  break;
332          case VT_HEM:                    /* hemispherical fisheye */
333                  d = normalize(disp);
# Line 199 | Line 335 | FVECT  p;
335                          ip[2] = -d;
336                  else
337                          ip[2] = d;
338 +                ip[2] -= v->vfore;
339                  break;
340 +        case VT_CYL:                    /* cylindrical panorama */
341 +                d = DOT(disp,v->hvec);
342 +                d2 = DOT(disp,v->vdir);
343 +                ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
344 +                d2 = d*d + d2*d2;
345 +                if (d2 <= FTINY*FTINY)
346 +                        return(VL_BAD); /* at pole */
347 +                if ((v->vaft > FTINY) & (d2 >= v->vaft*v->vaft))
348 +                        rflags |= VL_BEYOND;
349 +                d = 1.0/sqrt(d2);
350 +                ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
351 +                ip[2] = VLEN(disp);
352 +                ip[2] *= (1.0 - v->vfore*d);
353 +                goto gotall;
354          case VT_ANG:                    /* angular fisheye */
355                  ip[0] = 0.5 - v->hoff;
356                  ip[1] = 0.5 - v->voff;
357 <                ip[2] = normalize(disp);
357 >                ip[2] = normalize(disp) - v->vfore;
358                  d = DOT(disp,v->vdir);
359                  if (d >= 1.0-FTINY)
360 <                        return;
360 >                        goto gotall;
361                  if (d <= -(1.0-FTINY)) {
362 <                        ip[1] += 180.0/v->horiz;
363 <                        ip[2] += 180.0/v->vert;
213 <                        return;
362 >                        ip[0] += 180.0/v->horiz;
363 >                        goto gotall;
364                  }
365 <                d = acos(d)/PI / sqrt(1.0 - d*d);
366 <                ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz;
367 <                ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert;
368 <                return;
365 >                d = (180.0/PI)*acos(d) / sqrt(1.0 - d*d);
366 >                ip[0] += DOT(disp,v->hvec)*d/v->horiz;
367 >                ip[1] += DOT(disp,v->vvec)*d/v->vert;
368 >                goto gotall;
369 >        case VT_PLS:                    /* planispheric fisheye */
370 >                ip[0] = 0.5 - v->hoff;
371 >                ip[1] = 0.5 - v->voff;
372 >                ip[2] = normalize(disp) - v->vfore;
373 >                d = DOT(disp,v->vdir);
374 >                if (d >= 1.0-FTINY)
375 >                        goto gotall;
376 >                if (d <= -(1.0-FTINY))
377 >                        return(VL_BAD);
378 >                ip[0] += DOT(disp,v->hvec)/((1. + d)*sqrt(v->hn2));
379 >                ip[1] += DOT(disp,v->vvec)/((1. + d)*sqrt(v->vn2));
380 >                goto gotall;
381 >        default:
382 >                return(VL_BAD);
383          }
384          ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
385          ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
386 + gotall:                                 /* add appropriate return flags */
387 +        if (ip[2] <= 0.0)
388 +                rflags |= VL_BEHIND;
389 +        else if ((v->type != VT_PER) & (v->type != VT_CYL))
390 +                rflags |= VL_BEYOND*((v->vaft > FTINY) &
391 +                                        (ip[2] >= v->vaft - v->vfore));
392 +        rflags |= VL_OUTSIDE*((0.0 >= ip[0]) | (ip[0] >= 1.0) |
393 +                                (0.0 >= ip[1]) | (ip[1] >= 1.0));
394 +        return(rflags);
395   }
396  
397  
398 < pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
399 < FLOAT  loc[2];
400 < register RESOLU  *rp;
401 < int  px, py;
398 > void
399 > pix2loc(                /* compute image location from pixel pos. */
400 > RREAL  loc[2],
401 > RESOLU  *rp,
402 > int  px,
403 > int  py
404 > )
405   {
406 <        register int  x, y;
406 >        int  x, y;
407  
408 <        if (rp->or & YMAJOR) {
408 >        if (rp->rt & YMAJOR) {
409                  x = px;
410                  y = py;
411          } else {
412                  x = py;
413                  y = px;
414          }
415 <        if (rp->or & XDECR)
415 >        if (rp->rt & XDECR)
416                  x = rp->xr-1 - x;
417 <        if (rp->or & YDECR)
417 >        if (rp->rt & YDECR)
418                  y = rp->yr-1 - y;
419          loc[0] = (x+.5)/rp->xr;
420          loc[1] = (y+.5)/rp->yr;
421   }
422  
423  
424 < loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
425 < int  pp[2];
426 < register RESOLU  *rp;
427 < double  lx, ly;
424 > void
425 > loc2pix(                        /* compute pixel pos. from image location */
426 > int  pp[2],
427 > RESOLU  *rp,
428 > double  lx,
429 > double  ly
430 > )
431   {
432 <        register int  x, y;
432 >        int  x, y;
433  
434 <        x = lx * rp->xr;
435 <        y = ly * rp->yr;
436 <        if (rp->or & XDECR)
434 >        x = (int)(lx*rp->xr + .5 - (lx < 0.0));
435 >        y = (int)(ly*rp->yr + .5 - (ly < 0.0));
436 >
437 >        if (rp->rt & XDECR)
438                  x = rp->xr-1 - x;
439 <        if (rp->or & YDECR)
439 >        if (rp->rt & YDECR)
440                  y = rp->yr-1 - y;
441 <        if (rp->or & YMAJOR) {
441 >        if (rp->rt & YMAJOR) {
442                  pp[0] = x;
443                  pp[1] = y;
444          } else {
# Line 269 | Line 449 | double  lx, ly;
449  
450  
451   int
452 < getviewopt(v, ac, av)                   /* process view argument */
453 < register VIEW  *v;
454 < int  ac;
455 < register char  *av[];
452 > getviewopt(                             /* process view argument */
453 > VIEW  *v,
454 > int  ac,
455 > char  *av[]
456 > )
457   {
458 < #define check(c,l)      if ((av[0][c]&&av[0][c]!=' ') || \
458 > #define check(c,l)      if ((av[0][c]&&!isspace(av[0][c])) || \
459                          badarg(ac-1,av+1,l)) return(-1)
460  
461          if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
462                  return(-1);
463          switch (av[0][2]) {
464          case 't':                       /* type */
465 <                if (!av[0][3] || av[0][3]==' ')
465 >                if (!av[0][3] || isspace(av[0][3]))
466                          return(-1);
467                  check(4,"");
468                  v->type = av[0][3];
# Line 297 | Line 478 | register char  *av[];
478                  v->vdir[0] = atof(av[1]);
479                  v->vdir[1] = atof(av[2]);
480                  v->vdir[2] = atof(av[3]);
481 +                v->vdist = 1.;
482                  return(3);
483          case 'u':                       /* up */
484                  check(3,"fff");
# Line 312 | Line 494 | register char  *av[];
494                  check(3,"f");
495                  v->vert = atof(av[1]);
496                  return(1);
497 +        case 'o':                       /* fore clipping plane */
498 +                check(3,"f");
499 +                v->vfore = atof(av[1]);
500 +                return(1);
501 +        case 'a':                       /* aft clipping plane */
502 +                check(3,"f");
503 +                v->vaft = atof(av[1]);
504 +                return(1);
505          case 's':                       /* shift */
506                  check(3,"f");
507                  v->hoff = atof(av[1]);
# Line 328 | Line 518 | register char  *av[];
518  
519  
520   int
521 < sscanview(vp, s)                        /* get view parameters from string */
522 < VIEW  *vp;
523 < register char  *s;
521 > sscanview(                              /* get view parameters from string */
522 > VIEW  *vp,
523 > char  *s
524 > )
525   {
526          int  ac;
527          char  *av[4];
528          int  na;
529          int  nvopts = 0;
530  
531 <        if (*s != '-')
532 <                s = sskip(s);
531 >        while (isspace(*s))
532 >                if (!*s++)
533 >                        return(0);
534          while (*s) {
535                  ac = 0;
536                  do {
537 <                        av[ac++] = s;
538 <                        while (*s && *s != ' ')
537 >                        if (ac || *s == '-')
538 >                                av[ac++] = s;
539 >                        while (*s && !isspace(*s))
540                                  s++;
541 <                        while (*s == ' ')
541 >                        while (isspace(*s))
542                                  s++;
543                  } while (*s && ac < 4);
544                  if ((na = getviewopt(vp, ac, av)) >= 0) {
# Line 359 | Line 552 | register char  *s;
552   }
553  
554  
555 < fprintview(vp, fp)                      /* write out view parameters */
556 < register VIEW  *vp;
557 < FILE  *fp;
555 > void
556 > fprintview(                             /* write out view parameters */
557 > VIEW  *vp,
558 > FILE  *fp
559 > )
560   {
561          fprintf(fp, " -vt%c", vp->type);
562          fprintf(fp, " -vp %.6g %.6g %.6g", vp->vp[0], vp->vp[1], vp->vp[2]);
563 <        fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
563 >        fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0]*vp->vdist,
564 >                                                vp->vdir[1]*vp->vdist,
565 >                                                vp->vdir[2]*vp->vdist);
566          fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
567          fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
568 +        fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft);
569          fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff);
570   }
571  
572  
573 + char *
574 + viewopt(                                /* translate to minimal view string */
575 + VIEW  *vp
576 + )
577 + {
578 +        static char  vwstr[128];
579 +        char  *cp = vwstr;
580 +
581 +        *cp = '\0';
582 +        if (vp->type != stdview.type) {
583 +                sprintf(cp, " -vt%c", vp->type);
584 +                cp += strlen(cp);
585 +        }
586 +        if (!VABSEQ(vp->vp,stdview.vp)) {
587 +                sprintf(cp, " -vp %.6g %.6g %.6g",
588 +                                vp->vp[0], vp->vp[1], vp->vp[2]);
589 +                cp += strlen(cp);
590 +        }
591 +        if (!FABSEQ(vp->vdist,stdview.vdist) || !VABSEQ(vp->vdir,stdview.vdir)) {
592 +                sprintf(cp, " -vd %.6g %.6g %.6g",
593 +                                vp->vdir[0]*vp->vdist,
594 +                                vp->vdir[1]*vp->vdist,
595 +                                vp->vdir[2]*vp->vdist);
596 +                cp += strlen(cp);
597 +        }
598 +        if (!VABSEQ(vp->vup,stdview.vup)) {
599 +                sprintf(cp, " -vu %.6g %.6g %.6g",
600 +                                vp->vup[0], vp->vup[1], vp->vup[2]);
601 +                cp += strlen(cp);
602 +        }
603 +        if (!FABSEQ(vp->horiz,stdview.horiz)) {
604 +                sprintf(cp, " -vh %.6g", vp->horiz);
605 +                cp += strlen(cp);
606 +        }
607 +        if (!FABSEQ(vp->vert,stdview.vert)) {
608 +                sprintf(cp, " -vv %.6g", vp->vert);
609 +                cp += strlen(cp);
610 +        }
611 +        if (!FABSEQ(vp->vfore,stdview.vfore)) {
612 +                sprintf(cp, " -vo %.6g", vp->vfore);
613 +                cp += strlen(cp);
614 +        }
615 +        if (!FABSEQ(vp->vaft,stdview.vaft)) {
616 +                sprintf(cp, " -va %.6g", vp->vaft);
617 +                cp += strlen(cp);
618 +        }
619 +        if (!FABSEQ(vp->hoff,stdview.hoff)) {
620 +                sprintf(cp, " -vs %.6g", vp->hoff);
621 +                cp += strlen(cp);
622 +        }
623 +        if (!FABSEQ(vp->voff,stdview.voff)) {
624 +                sprintf(cp, " -vl %.6g", vp->voff);
625 +                cp += strlen(cp);
626 +        }
627 +        return(vwstr);
628 + }
629 +
630 +
631   int
632 < isview(s)                               /* is this a view string? */
633 < char  *s;
632 > isview(                                 /* is this a view string? */
633 > char  *s
634 > )
635   {
636 <        static char  *altname[]={NULL,"rpict","rview","pinterp",VIEWSTR,NULL};
637 <        extern char  *progname, *rindex();
638 <        register char  *cp;
639 <        register char  **an;
636 >        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","rvu","rpiece","pinterp",NULL};
637 >        extern char  *progname;
638 >        char  *cp;
639 >        char  **an;
640                                          /* add program name to list */
641 <        if (altname[0] == NULL)
642 <                if ((cp = rindex(progname, '/')) != NULL)
643 <                        altname[0] = cp+1;
644 <                else
645 <                        altname[0] = progname;
641 >        if (altname[0] == NULL) {
642 >                for (cp = progname; *cp; cp++)
643 >                        ;
644 >                while (cp > progname && !ISDIRSEP(cp[-1]))
645 >                        cp--;
646 >                altname[0] = cp;
647 >        }
648                                          /* skip leading path */
649          cp = s;
650 <        while (*cp && *cp != ' ')
650 >        while (*cp && !isspace(*cp))
651                  cp++;
652 <        while (cp > s && cp[-1] != '/')
652 >        while (cp > s && !ISDIRSEP(cp[-1]))
653                  cp--;
654          for (an = altname; *an != NULL; an++)
655                  if (!strncmp(*an, cp, strlen(*an)))
# Line 405 | Line 664 | struct myview {
664   };
665  
666  
667 < static
668 < gethview(s, v)                          /* get view from header */
669 < char  *s;
670 < register struct myview  *v;
667 > static int
668 > gethview(                               /* get view from header */
669 >        char  *s,
670 >        void  *v
671 > )
672   {
673 <        if (isview(s) && sscanview(v->hv, s) > 0)
674 <                v->ok++;
673 >        if (isview(s) && sscanview(((struct myview*)v)->hv, s) > 0)
674 >                ((struct myview*)v)->ok++;
675 >        return(0);
676   }
677  
678  
679   int
680 < viewfile(fname, vp, rp)                 /* get view from file */
681 < char  *fname;
682 < VIEW  *vp;
683 < RESOLU  *rp;
680 > viewfile(                               /* get view from file */
681 > char  *fname,
682 > VIEW  *vp,
683 > RESOLU  *rp
684 > )
685   {
686          struct myview   mvs;
687          FILE  *fp;
688  
689 <        if ((fp = fopen(fname, "r")) == NULL)
689 >        if (fname == NULL || !strcmp(fname, "-"))
690 >                fp = stdin;
691 >        else if ((fp = fopen(fname, "r")) == NULL)
692                  return(-1);
693  
694          mvs.hv = vp;
# Line 435 | Line 699 | RESOLU  *rp;
699          if (rp != NULL && !fgetsresolu(rp, fp))
700                  mvs.ok = 0;
701  
702 <        fclose(fp);
702 >        if (fp != stdin)
703 >                fclose(fp);
704  
705          return(mvs.ok);
706   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines