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.4 by greg, Fri Dec 22 08:21:53 1989 UTC vs.
Revision 2.13 by gregl, Tue Dec 9 16:41:03 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 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  
13 #include  <ctype.h>
14
11   #include  "standard.h"
12  
13   #include  "view.h"
14  
15 < VIEW  stdview = STDVIEW(512);           /* default view parameters */
15 > #include  "resolu.h"
16  
17 + #include  "paths.h"
18  
19 < char *
20 < sskip(s)                /* skip a word */
21 < register char  *s;
25 < {
26 <        while (isspace(*s)) s++;
27 <        while (*s && !isspace(*s)) s++;
28 <        return(s);
29 < }
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 +
26   char *
27 < setview(v)              /* set vhinc and vvinc, return message on error */
27 > setview(v)              /* set hvec and vvec, return message on error */
28   register VIEW  *v;
29   {
30 <        double  tan(), dt;
30 >        static char  ill_horiz[] = "illegal horizontal view size";
31 >        static char  ill_vert[] = "illegal vertical view size";
32          
33 +        if (v->vfore < -FTINY || v->vaft < -FTINY ||
34 +                        (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");
40                
41        fcross(v->vhinc, v->vdir, v->vup);      /* compute horiz dir */
39  
40 <        if (normalize(v->vhinc) == 0.0)
41 <                return("illegal view up vector");
45 <                
46 <        fcross(v->vvinc, v->vhinc, v->vdir);    /* compute vert dir */
40 >        if (normalize(v->vup) == 0.0)           /* normalize view up */
41 >                return("zero view up vector");
42  
43 <        if (v->type == VT_PAR)
49 <                dt =  v->horiz;
50 <        else if (v->type == VT_PER)
51 <                dt = 2.0 * tan(v->horiz*(PI/180.0/2.0));
52 <        else
53 <                return("unknown view type");
43 >        fcross(v->hvec, v->vdir, v->vup);       /* compute horiz dir */
44  
45 <        if (dt <= FTINY || dt >= FHUGE)
46 <                return("illegal horizontal view size");
45 >        if (normalize(v->hvec) == 0.0)
46 >                return("view up parallel to view direction");
47  
48 <        if (v->hresolu <= 0)
59 <                return("illegal horizontal resolution");
48 >        fcross(v->vvec, v->hvec, v->vdir);      /* compute vert dir */
49  
50 <        dt /= (double)v->hresolu;
51 <        v->vhinc[0] *= dt;
52 <        v->vhinc[1] *= dt;
53 <        v->vhinc[2] *= dt;
50 >        if (v->horiz <= FTINY)
51 >                return(ill_horiz);
52 >        if (v->vert <= FTINY)
53 >                return(ill_vert);
54  
55 <        if (v->type == VT_PAR)
56 <                dt = v->vert;
57 <        else
58 <                dt = 2.0 * tan(v->vert*(PI/180.0/2.0));
55 >        switch (v->type) {
56 >        case VT_PAR:                            /* parallel view */
57 >                v->hn2 = v->horiz;
58 >                v->vn2 = v->vert;
59 >                break;
60 >        case VT_PER:                            /* perspective view */
61 >                if (v->horiz >= 180.0-FTINY)
62 >                        return(ill_horiz);
63 >                if (v->vert >= 180.0-FTINY)
64 >                        return(ill_vert);
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 * (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)
86 >                        return(ill_horiz);
87 >                if (v->vert > 180.0+FTINY)
88 >                        return(ill_vert);
89 >                v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0));
90 >                v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0));
91 >                break;
92 >        default:
93 >                return("unknown view type");
94 >        }
95 >        if (v->type != VT_ANG) {
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;
104 >        }
105 >        v->hn2 *= v->hn2;
106 >        v->vn2 *= v->vn2;
107  
108 <        if (dt <= FTINY || dt >= FHUGE)
109 <                return("illegal vertical view size");
108 >        return(NULL);
109 > }
110  
74        if (v->vresolu <= 0)
75                return("illegal vertical resolution");
76        
77        dt /= (double)v->vresolu;
78        v->vvinc[0] *= dt;
79        v->vvinc[1] *= dt;
80        v->vvinc[2] *= dt;
111  
112 <        v->vhn2 = DOT(v->vhinc,v->vhinc);
113 <        v->vvn2 = DOT(v->vvinc,v->vvinc);
114 <
115 <        return(NULL);
112 > normaspect(va, ap, xp, yp)              /* fix pixel aspect or resolution */
113 > double  va;                     /* view aspect ratio */
114 > double  *ap;                    /* pixel aspect in (or out if 0) */
115 > int  *xp, *yp;                  /* x and y resolution in (or out if *ap!=0) */
116 > {
117 >        if (*ap <= FTINY)
118 >                *ap = va * *xp / *yp;           /* compute pixel aspect */
119 >        else if (va * *xp > *ap * *yp)
120 >                *xp = *yp / va * *ap + .5;      /* reduce x resolution */
121 >        else
122 >                *yp = *xp * va / *ap + .5;      /* reduce y resolution */
123   }
124  
125  
126 < rayview(orig, direc, v, x, y)           /* compute ray origin and direction */
126 > double
127 > viewray(orig, direc, v, x, y)           /* compute ray origin and direction */
128   FVECT  orig, direc;
129   register VIEW  *v;
130   double  x, y;
131   {
132 <        x -= 0.5 * v->hresolu;
133 <        y -= 0.5 * v->vresolu;
132 >        double  d, z;
133 >        
134 >        x += v->hoff - 0.5;
135 >        y += v->voff - 0.5;
136  
137 <        if (v->type == VT_PAR) {        /* parallel view */
138 <                orig[0] = v->vp[0] + x*v->vhinc[0] + y*v->vvinc[0];
139 <                orig[1] = v->vp[1] + x*v->vhinc[1] + y*v->vvinc[1];
140 <                orig[2] = v->vp[2] + x*v->vhinc[2] + y*v->vvinc[2];
137 >        switch(v->type) {
138 >        case VT_PAR:                    /* parallel view */
139 >                orig[0] = v->vp[0] + v->vfore*v->vdir[0]
140 >                                + x*v->hvec[0] + y*v->vvec[0];
141 >                orig[1] = v->vp[1] + v->vfore*v->vdir[1]
142 >                                + x*v->hvec[1] + y*v->vvec[1];
143 >                orig[2] = v->vp[2] + v->vfore*v->vdir[2]
144 >                                + x*v->hvec[2] + y*v->vvec[2];
145                  VCOPY(direc, v->vdir);
146 <        } else {                        /* perspective view */
147 <                VCOPY(orig, v->vp);
148 <                direc[0] = v->vdir[0] + x*v->vhinc[0] + y*v->vvinc[0];
149 <                direc[1] = v->vdir[1] + x*v->vhinc[1] + y*v->vvinc[1];
150 <                direc[2] = v->vdir[2] + x*v->vhinc[2] + y*v->vvinc[2];
151 <                normalize(direc);
146 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
147 >        case VT_PER:                    /* perspective view */
148 >                direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
149 >                direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
150 >                direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
151 >                orig[0] = v->vp[0] + v->vfore*direc[0];
152 >                orig[1] = v->vp[1] + v->vfore*direc[1];
153 >                orig[2] = v->vp[2] + v->vfore*direc[2];
154 >                d = normalize(direc);
155 >                return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0);
156 >        case VT_HEM:                    /* hemispherical fisheye */
157 >                z = 1.0 - x*x*v->hn2 - y*y*v->vn2;
158 >                if (z < 0.0)
159 >                        return(-1.0);
160 >                z = sqrt(z);
161 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
162 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
163 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
164 >                orig[0] = v->vp[0] + v->vfore*direc[0];
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;
183 >                d = x*x + y*y;
184 >                if (d > 1.0)
185 >                        return(-1.0);
186 >                d = sqrt(d);
187 >                z = cos(PI*d);
188 >                d = d <= FTINY ? PI : sqrt(1 - z*z)/d;
189 >                x *= d;
190 >                y *= d;
191 >                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
192 >                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
193 >                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
194 >                orig[0] = v->vp[0] + v->vfore*direc[0];
195 >                orig[1] = v->vp[1] + v->vfore*direc[1];
196 >                orig[2] = v->vp[2] + v->vfore*direc[2];
197 >                return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0);
198          }
199 +        return(-1.0);
200   }
201  
202  
203 < pixelview(xp, yp, zp, v, p)             /* find image location for point */
204 < double  *xp, *yp, *zp;
203 > viewloc(ip, v, p)               /* find image location for point */
204 > FVECT  ip;
205   register VIEW  *v;
206   FVECT  p;
207   {
208 <        extern double  sqrt();
118 <        double  d;
208 >        double  d, d2;
209          FVECT  disp;
210 <        
210 >
211          disp[0] = p[0] - v->vp[0];
212          disp[1] = p[1] - v->vp[1];
213          disp[2] = p[2] - v->vp[2];
214  
215 <        if (v->type == VT_PAR) {        /* parallel view */
216 <                if (zp != NULL)
217 <                        *zp = DOT(disp,v->vdir);
218 <        } else {                        /* perspective view */
219 <                d = 1.0/DOT(disp,v->vdir);
220 <                if (zp != NULL) {
221 <                        *zp = sqrt(DOT(disp,disp));
222 <                        if (d < 0.0)
223 <                                *zp = -*zp;
215 >        switch (v->type) {
216 >        case VT_PAR:                    /* parallel view */
217 >                ip[2] = DOT(disp,v->vdir) - v->vfore;
218 >                break;
219 >        case VT_PER:                    /* perspective view */
220 >                d = DOT(disp,v->vdir);
221 >                ip[2] = VLEN(disp);
222 >                if (d < 0.0) {          /* fold pyramid */
223 >                        ip[2] = -ip[2];
224 >                        d = -d;
225                  }
226 <                disp[0] *= d;
227 <                disp[1] *= d;
228 <                disp[2] *= d;
226 >                if (d > FTINY) {
227 >                        d = 1.0/d;
228 >                        disp[0] *= d;
229 >                        disp[1] *= d;
230 >                        disp[2] *= d;
231 >                }
232 >                ip[2] *= (1.0 - v->vfore*d);
233 >                break;
234 >        case VT_HEM:                    /* hemispherical fisheye */
235 >                d = normalize(disp);
236 >                if (DOT(disp,v->vdir) < 0.0)
237 >                        ip[2] = -d;
238 >                else
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;
255 >                ip[2] = normalize(disp) - v->vfore;
256 >                d = DOT(disp,v->vdir);
257 >                if (d >= 1.0-FTINY)
258 >                        return;
259 >                if (d <= -(1.0-FTINY)) {
260 >                        ip[0] += 180.0/v->horiz;
261 >                        return;
262 >                }
263 >                d = acos(d)/PI / sqrt(1.0 - d*d);
264 >                ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz;
265 >                ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert;
266 >                return;
267          }
268 <        *xp = DOT(disp,v->vhinc)/v->vhn2 + 0.5*v->hresolu;
269 <        *yp = DOT(disp,v->vvinc)/v->vvn2 + 0.5*v->vresolu;
268 >        ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
269 >        ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
270   }
271  
272  
273 < sscanview(vp, s)                        /* get view parameters */
274 < register VIEW  *vp;
273 > pix2loc(loc, rp, px, py)        /* compute image location from pixel pos. */
274 > FLOAT  loc[2];
275 > register RESOLU  *rp;
276 > int  px, py;
277 > {
278 >        register int  x, y;
279 >
280 >        if (rp->or & YMAJOR) {
281 >                x = px;
282 >                y = py;
283 >        } else {
284 >                x = py;
285 >                y = px;
286 >        }
287 >        if (rp->or & XDECR)
288 >                x = rp->xr-1 - x;
289 >        if (rp->or & YDECR)
290 >                y = rp->yr-1 - y;
291 >        loc[0] = (x+.5)/rp->xr;
292 >        loc[1] = (y+.5)/rp->yr;
293 > }
294 >
295 >
296 > loc2pix(pp, rp, lx, ly)         /* compute pixel pos. from image location */
297 > int  pp[2];
298 > register RESOLU  *rp;
299 > double  lx, ly;
300 > {
301 >        register int  x, y;
302 >
303 >        x = lx * rp->xr;
304 >        y = ly * rp->yr;
305 >        if (rp->or & XDECR)
306 >                x = rp->xr-1 - x;
307 >        if (rp->or & YDECR)
308 >                y = rp->yr-1 - y;
309 >        if (rp->or & YMAJOR) {
310 >                pp[0] = x;
311 >                pp[1] = y;
312 >        } else {
313 >                pp[0] = y;
314 >                pp[1] = x;
315 >        }
316 > }
317 >
318 >
319 > int
320 > getviewopt(v, ac, av)                   /* process view argument */
321 > register VIEW  *v;
322 > int  ac;
323 > register char  *av[];
324 > {
325 > #define check(c,l)      if ((av[0][c]&&av[0][c]!=' ') || \
326 >                        badarg(ac-1,av+1,l)) return(-1)
327 >
328 >        if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
329 >                return(-1);
330 >        switch (av[0][2]) {
331 >        case 't':                       /* type */
332 >                if (!av[0][3] || av[0][3]==' ')
333 >                        return(-1);
334 >                check(4,"");
335 >                v->type = av[0][3];
336 >                return(0);
337 >        case 'p':                       /* point */
338 >                check(3,"fff");
339 >                v->vp[0] = atof(av[1]);
340 >                v->vp[1] = atof(av[2]);
341 >                v->vp[2] = atof(av[3]);
342 >                return(3);
343 >        case 'd':                       /* direction */
344 >                check(3,"fff");
345 >                v->vdir[0] = atof(av[1]);
346 >                v->vdir[1] = atof(av[2]);
347 >                v->vdir[2] = atof(av[3]);
348 >                return(3);
349 >        case 'u':                       /* up */
350 >                check(3,"fff");
351 >                v->vup[0] = atof(av[1]);
352 >                v->vup[1] = atof(av[2]);
353 >                v->vup[2] = atof(av[3]);
354 >                return(3);
355 >        case 'h':                       /* horizontal size */
356 >                check(3,"f");
357 >                v->horiz = atof(av[1]);
358 >                return(1);
359 >        case 'v':                       /* vertical size */
360 >                check(3,"f");
361 >                v->vert = atof(av[1]);
362 >                return(1);
363 >        case 'o':                       /* fore clipping plane */
364 >                check(3,"f");
365 >                v->vfore = atof(av[1]);
366 >                return(1);
367 >        case 'a':                       /* aft clipping plane */
368 >                check(3,"f");
369 >                v->vaft = atof(av[1]);
370 >                return(1);
371 >        case 's':                       /* shift */
372 >                check(3,"f");
373 >                v->hoff = atof(av[1]);
374 >                return(1);
375 >        case 'l':                       /* lift */
376 >                check(3,"f");
377 >                v->voff = atof(av[1]);
378 >                return(1);
379 >        default:
380 >                return(-1);
381 >        }
382 > #undef check
383 > }
384 >
385 >
386 > int
387 > sscanview(vp, s)                        /* get view parameters from string */
388 > VIEW  *vp;
389   register char  *s;
390   {
391 <        for ( ; ; )
392 <                switch (*s++) {
393 <                case '\0':
394 <                case '\n':
395 <                        return(0);
396 <                case '-':
397 <                        switch (*s++) {
398 <                        case '\0':
399 <                                return(-1);
400 <                        case 'x':
401 <                                if (sscanf(s, "%d", &vp->hresolu) != 1)
402 <                                        return(-1);
403 <                                s = sskip(s);
404 <                                continue;
405 <                        case 'y':
406 <                                if (sscanf(s, "%d", &vp->vresolu) != 1)
407 <                                        return(-1);
408 <                                s = sskip(s);
409 <                                continue;
410 <                        case 'v':
411 <                                switch (*s++) {
412 <                                case '\0':
413 <                                        return(-1);
414 <                                case 't':
172 <                                        vp->type = *s++;
173 <                                        continue;
174 <                                case 'p':
175 <                                        if (sscanf(s, "%lf %lf %lf",
176 <                                                        &vp->vp[0],
177 <                                                        &vp->vp[1],
178 <                                                        &vp->vp[2]) != 3)
179 <                                                return(-1);
180 <                                        s = sskip(sskip(sskip(s)));
181 <                                        continue;
182 <                                case 'd':
183 <                                        if (sscanf(s, "%lf %lf %lf",
184 <                                                        &vp->vdir[0],
185 <                                                        &vp->vdir[1],
186 <                                                        &vp->vdir[2]) != 3)
187 <                                                return(-1);
188 <                                        s = sskip(sskip(sskip(s)));
189 <                                        continue;
190 <                                case 'u':
191 <                                        if (sscanf(s, "%lf %lf %lf",
192 <                                                        &vp->vup[0],
193 <                                                        &vp->vup[1],
194 <                                                        &vp->vup[2]) != 3)
195 <                                                return(-1);
196 <                                        s = sskip(sskip(sskip(s)));
197 <                                        continue;
198 <                                case 'h':
199 <                                        if (sscanf(s, "%lf",
200 <                                                        &vp->horiz) != 1)
201 <                                                return(-1);
202 <                                        s = sskip(s);
203 <                                        continue;
204 <                                case 'v':
205 <                                        if (sscanf(s, "%lf",
206 <                                                        &vp->vert) != 1)
207 <                                                return(-1);
208 <                                        s = sskip(s);
209 <                                        continue;
210 <                                }
211 <                                continue;
212 <                        }
213 <                        continue;
214 <                }
391 >        int  ac;
392 >        char  *av[4];
393 >        int  na;
394 >        int  nvopts = 0;
395 >
396 >        if (*s != '-')
397 >                s = sskip2(s,1);
398 >        while (*s) {
399 >                ac = 0;
400 >                do {
401 >                        av[ac++] = s;
402 >                        while (*s && *s != ' ')
403 >                                s++;
404 >                        while (*s == ' ')
405 >                                s++;
406 >                } while (*s && ac < 4);
407 >                if ((na = getviewopt(vp, ac, av)) >= 0) {
408 >                        if (na+1 < ac)
409 >                                s = av[na+1];
410 >                        nvopts++;
411 >                } else if (ac > 1)
412 >                        s = av[1];
413 >        }
414 >        return(nvopts);
415   }
416  
417  
# Line 224 | Line 424 | FILE  *fp;
424          fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]);
425          fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]);
426          fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert);
427 <        fprintf(fp, " -x %d -y %d", vp->hresolu, vp->vresolu);
427 >        fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft);
428 >        fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff);
429   }
430  
431  
432 < static VIEW  *hview;                    /* view from header */
433 < static int  gothview;                   /* success indicator */
434 < static char  *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL};
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 < static
486 < gethview(s)                             /* get view from header */
485 >
486 > int
487 > isview(s)                               /* is this a view string? */
488   char  *s;
489   {
490 +        static char  *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL};
491 +        extern char  *progname;
492 +        register char  *cp;
493          register char  **an;
494 <
494 >                                        /* add program name to list */
495 >        if (altname[0] == NULL) {
496 >                for (cp = progname; *cp; cp++)
497 >                        ;
498 >                while (cp > progname && !ISDIRSEP(cp[-1]))
499 >                        cp--;
500 >                altname[0] = cp;
501 >        }
502 >                                        /* skip leading path */
503 >        cp = s;
504 >        while (*cp && *cp != ' ')
505 >                cp++;
506 >        while (cp > s && !ISDIRSEP(cp[-1]))
507 >                cp--;
508          for (an = altname; *an != NULL; an++)
509 <                if (!strncmp(*an, s, strlen(*an))) {
510 <                        if (sscanview(hview, s+strlen(*an)) == 0)
511 <                                gothview++;
246 <                        return;
247 <                }
509 >                if (!strncmp(*an, cp, strlen(*an)))
510 >                        return(1);
511 >        return(0);
512   }
513  
514  
515 + struct myview {
516 +        VIEW    *hv;
517 +        int     ok;
518 + };
519 +
520 +
521 + static
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 + }
529 +
530 +
531   int
532 < viewfile(fname, vp)                     /* get view from file */
532 > viewfile(fname, vp, rp)                 /* get view from file */
533   char  *fname;
534   VIEW  *vp;
535 + RESOLU  *rp;
536   {
537 <        extern char  *progname;
537 >        struct myview   mvs;
538          FILE  *fp;
539  
540          if ((fp = fopen(fname, "r")) == NULL)
541                  return(-1);
542  
543 <        altname[0] = progname;
544 <        hview = vp;
264 <        gothview = 0;
543 >        mvs.hv = vp;
544 >        mvs.ok = 0;
545  
546 <        getheader(fp, gethview);
546 >        getheader(fp, gethview, &mvs);
547  
548 +        if (rp != NULL && !fgetsresolu(rp, fp))
549 +                mvs.ok = 0;
550 +
551          fclose(fp);
552  
553 <        return(gothview);
553 >        return(mvs.ok);
554   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines