1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
10 |
|
* 10/17/85 |
11 |
|
*/ |
12 |
|
|
13 |
– |
#include <ctype.h> |
14 |
– |
|
13 |
|
#include "standard.h" |
14 |
|
|
15 |
|
#include "view.h" |
16 |
|
|
17 |
< |
VIEW stdview = STDVIEW(512); /* default view parameters */ |
17 |
> |
#include "resolu.h" |
18 |
|
|
19 |
+ |
VIEW stdview = STDVIEW; /* default view parameters */ |
20 |
|
|
22 |
– |
char * |
23 |
– |
sskip(s) /* skip a word */ |
24 |
– |
register char *s; |
25 |
– |
{ |
26 |
– |
while (isspace(*s)) s++; |
27 |
– |
while (*s && !isspace(*s)) s++; |
28 |
– |
return(s); |
29 |
– |
} |
21 |
|
|
31 |
– |
|
22 |
|
char * |
23 |
< |
setview(v) /* set vhinc and vvinc, return message on error */ |
23 |
> |
setview(v) /* set hvec and vvec, return message on error */ |
24 |
|
register VIEW *v; |
25 |
|
{ |
26 |
< |
double tan(), dt; |
26 |
> |
static char ill_horiz[] = "illegal horizontal view size"; |
27 |
> |
static char ill_vert[] = "illegal vertical view size"; |
28 |
|
|
29 |
|
if (normalize(v->vdir) == 0.0) /* normalize direction */ |
30 |
|
return("zero view direction"); |
40 |
– |
|
41 |
– |
fcross(v->vhinc, v->vdir, v->vup); /* compute horiz dir */ |
31 |
|
|
32 |
< |
if (normalize(v->vhinc) == 0.0) |
33 |
< |
return("illegal view up vector"); |
45 |
< |
|
46 |
< |
fcross(v->vvinc, v->vhinc, v->vdir); /* compute vert dir */ |
32 |
> |
if (normalize(v->vup) == 0.0) /* normalize view up */ |
33 |
> |
return("zero view up vector"); |
34 |
|
|
35 |
< |
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"); |
35 |
> |
fcross(v->hvec, v->vdir, v->vup); /* compute horiz dir */ |
36 |
|
|
37 |
< |
if (dt <= FTINY || dt >= FHUGE) |
38 |
< |
return("illegal horizontal view size"); |
37 |
> |
if (normalize(v->hvec) == 0.0) |
38 |
> |
return("view up parallel to view direction"); |
39 |
|
|
40 |
< |
if (v->hresolu <= 0) |
59 |
< |
return("illegal horizontal resolution"); |
40 |
> |
fcross(v->vvec, v->hvec, v->vdir); /* compute vert dir */ |
41 |
|
|
42 |
< |
dt /= (double)v->hresolu; |
43 |
< |
v->vhinc[0] *= dt; |
44 |
< |
v->vhinc[1] *= dt; |
45 |
< |
v->vhinc[2] *= dt; |
42 |
> |
if (v->horiz <= FTINY) |
43 |
> |
return(ill_horiz); |
44 |
> |
if (v->vert <= FTINY) |
45 |
> |
return(ill_vert); |
46 |
|
|
47 |
< |
if (v->type == VT_PAR) |
48 |
< |
dt = v->vert; |
49 |
< |
else |
50 |
< |
dt = 2.0 * tan(v->vert*(PI/180.0/2.0)); |
47 |
> |
switch (v->type) { |
48 |
> |
case VT_PAR: /* parallel view */ |
49 |
> |
v->hn2 = v->horiz; |
50 |
> |
v->vn2 = v->vert; |
51 |
> |
break; |
52 |
> |
case VT_PER: /* perspective view */ |
53 |
> |
if (v->horiz >= 180.0-FTINY) |
54 |
> |
return(ill_horiz); |
55 |
> |
if (v->vert >= 180.0-FTINY) |
56 |
> |
return(ill_vert); |
57 |
> |
v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0)); |
58 |
> |
v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0)); |
59 |
> |
break; |
60 |
> |
case VT_ANG: /* angular fisheye */ |
61 |
> |
if (v->horiz > 360.0+FTINY) |
62 |
> |
return(ill_horiz); |
63 |
> |
if (v->vert > 360.0+FTINY) |
64 |
> |
return(ill_vert); |
65 |
> |
v->hn2 = v->horiz / 90.0; |
66 |
> |
v->vn2 = v->vert / 90.0; |
67 |
> |
break; |
68 |
> |
case VT_HEM: /* hemispherical fisheye */ |
69 |
> |
if (v->horiz > 180.0+FTINY) |
70 |
> |
return(ill_horiz); |
71 |
> |
if (v->vert > 180.0+FTINY) |
72 |
> |
return(ill_vert); |
73 |
> |
v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0)); |
74 |
> |
v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0)); |
75 |
> |
break; |
76 |
> |
default: |
77 |
> |
return("unknown view type"); |
78 |
> |
} |
79 |
> |
if (v->type != VT_ANG) { |
80 |
> |
v->hvec[0] *= v->hn2; |
81 |
> |
v->hvec[1] *= v->hn2; |
82 |
> |
v->hvec[2] *= v->hn2; |
83 |
> |
v->vvec[0] *= v->vn2; |
84 |
> |
v->vvec[1] *= v->vn2; |
85 |
> |
v->vvec[2] *= v->vn2; |
86 |
> |
} |
87 |
> |
v->hn2 *= v->hn2; |
88 |
> |
v->vn2 *= v->vn2; |
89 |
|
|
90 |
< |
if (dt <= FTINY || dt >= FHUGE) |
91 |
< |
return("illegal vertical view size"); |
90 |
> |
return(NULL); |
91 |
> |
} |
92 |
|
|
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; |
93 |
|
|
94 |
< |
v->vhs2 = 1.0/DOT(v->vhinc,v->vhinc); |
95 |
< |
v->vvs2 = 1.0/DOT(v->vvinc,v->vvinc); |
96 |
< |
|
97 |
< |
return(NULL); |
94 |
> |
normaspect(va, ap, xp, yp) /* fix pixel aspect or resolution */ |
95 |
> |
double va; /* view aspect ratio */ |
96 |
> |
double *ap; /* pixel aspect in (or out if 0) */ |
97 |
> |
int *xp, *yp; /* x and y resolution in (or out if *ap!=0) */ |
98 |
> |
{ |
99 |
> |
if (*ap <= FTINY) |
100 |
> |
*ap = va * *xp / *yp; /* compute pixel aspect */ |
101 |
> |
else if (va * *xp > *ap * *yp) |
102 |
> |
*xp = *yp / va * *ap + .5; /* reduce x resolution */ |
103 |
> |
else |
104 |
> |
*yp = *xp * va / *ap + .5; /* reduce y resolution */ |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
< |
rayview(orig, direc, v, x, y) /* compute ray origin and direction */ |
108 |
> |
viewray(orig, direc, v, x, y) /* compute ray origin and direction */ |
109 |
|
FVECT orig, direc; |
110 |
|
register VIEW *v; |
111 |
|
double x, y; |
112 |
|
{ |
113 |
< |
x -= 0.5 * v->hresolu; |
114 |
< |
y -= 0.5 * v->vresolu; |
113 |
> |
double d, z; |
114 |
> |
|
115 |
> |
x += v->hoff - 0.5; |
116 |
> |
y += v->voff - 0.5; |
117 |
|
|
118 |
< |
if (v->type == VT_PAR) { /* parallel view */ |
119 |
< |
orig[0] = v->vp[0] + x*v->vhinc[0] + y*v->vvinc[0]; |
120 |
< |
orig[1] = v->vp[1] + x*v->vhinc[1] + y*v->vvinc[1]; |
121 |
< |
orig[2] = v->vp[2] + x*v->vhinc[2] + y*v->vvinc[2]; |
118 |
> |
switch(v->type) { |
119 |
> |
case VT_PAR: /* parallel view */ |
120 |
> |
orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0]; |
121 |
> |
orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1]; |
122 |
> |
orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2]; |
123 |
|
VCOPY(direc, v->vdir); |
124 |
< |
} else { /* perspective view */ |
124 |
> |
return(0); |
125 |
> |
case VT_PER: /* perspective view */ |
126 |
|
VCOPY(orig, v->vp); |
127 |
< |
direc[0] = v->vdir[0] + x*v->vhinc[0] + y*v->vvinc[0]; |
128 |
< |
direc[1] = v->vdir[1] + x*v->vhinc[1] + y*v->vvinc[1]; |
129 |
< |
direc[2] = v->vdir[2] + x*v->vhinc[2] + y*v->vvinc[2]; |
127 |
> |
direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
128 |
> |
direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
129 |
> |
direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
130 |
|
normalize(direc); |
131 |
+ |
return(0); |
132 |
+ |
case VT_HEM: /* hemispherical fisheye */ |
133 |
+ |
z = 1.0 - x*x*v->hn2 - y*y*v->vn2; |
134 |
+ |
if (z < 0.0) |
135 |
+ |
return(-1); |
136 |
+ |
z = sqrt(z); |
137 |
+ |
VCOPY(orig, v->vp); |
138 |
+ |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
139 |
+ |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
140 |
+ |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
141 |
+ |
return(0); |
142 |
+ |
case VT_ANG: /* angular fisheye */ |
143 |
+ |
x *= v->horiz/180.0; |
144 |
+ |
y *= v->vert/180.0; |
145 |
+ |
d = x*x + y*y; |
146 |
+ |
if (d > 1.0) |
147 |
+ |
return(-1); |
148 |
+ |
VCOPY(orig, v->vp); |
149 |
+ |
if (d <= FTINY) { |
150 |
+ |
VCOPY(direc, v->vdir); |
151 |
+ |
return(0); |
152 |
+ |
} |
153 |
+ |
d = sqrt(d); |
154 |
+ |
z = cos(PI*d); |
155 |
+ |
d = sqrt(1 - z*z)/d; |
156 |
+ |
x *= d; |
157 |
+ |
y *= d; |
158 |
+ |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
159 |
+ |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
160 |
+ |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
161 |
+ |
return(0); |
162 |
|
} |
163 |
+ |
return(-1); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
< |
pixelview(xp, yp, zp, v, p) /* find image location for point */ |
168 |
< |
double *xp, *yp, *zp; |
167 |
> |
viewloc(ip, v, p) /* find image location for point */ |
168 |
> |
FVECT ip; |
169 |
|
register VIEW *v; |
170 |
|
FVECT p; |
171 |
|
{ |
117 |
– |
extern double sqrt(); |
172 |
|
double d; |
173 |
|
FVECT disp; |
174 |
< |
|
174 |
> |
|
175 |
|
disp[0] = p[0] - v->vp[0]; |
176 |
|
disp[1] = p[1] - v->vp[1]; |
177 |
|
disp[2] = p[2] - v->vp[2]; |
178 |
|
|
179 |
< |
if (v->type == VT_PAR) { /* parallel view */ |
180 |
< |
if (zp != NULL) |
181 |
< |
*zp = DOT(disp,v->vdir); |
182 |
< |
} else { /* perspective view */ |
183 |
< |
d = 1.0/DOT(disp,v->vdir); |
184 |
< |
if (zp != NULL) { |
185 |
< |
*zp = sqrt(DOT(disp,disp)); |
186 |
< |
if (d < 0.0) |
187 |
< |
*zp = -*zp; |
179 |
> |
switch (v->type) { |
180 |
> |
case VT_PAR: /* parallel view */ |
181 |
> |
ip[2] = DOT(disp,v->vdir); |
182 |
> |
break; |
183 |
> |
case VT_PER: /* perspective view */ |
184 |
> |
d = DOT(disp,v->vdir); |
185 |
> |
ip[2] = sqrt(DOT(disp,disp)); |
186 |
> |
if (d < 0.0) { /* fold pyramid */ |
187 |
> |
ip[2] = -ip[2]; |
188 |
> |
d = -d; |
189 |
> |
} else if (d > FTINY) { |
190 |
> |
d = 1.0/d; |
191 |
> |
disp[0] *= d; |
192 |
> |
disp[1] *= d; |
193 |
> |
disp[2] *= d; |
194 |
|
} |
195 |
< |
disp[0] *= d; |
196 |
< |
disp[1] *= d; |
197 |
< |
disp[2] *= d; |
195 |
> |
break; |
196 |
> |
case VT_HEM: /* hemispherical fisheye */ |
197 |
> |
d = normalize(disp); |
198 |
> |
if (DOT(disp,v->vdir) < 0.0) |
199 |
> |
ip[2] = -d; |
200 |
> |
else |
201 |
> |
ip[2] = d; |
202 |
> |
break; |
203 |
> |
case VT_ANG: /* angular fisheye */ |
204 |
> |
ip[0] = 0.5 - v->hoff; |
205 |
> |
ip[1] = 0.5 - v->voff; |
206 |
> |
ip[2] = normalize(disp); |
207 |
> |
d = DOT(disp,v->vdir); |
208 |
> |
if (d >= 1.0-FTINY) |
209 |
> |
return; |
210 |
> |
if (d <= -(1.0-FTINY)) { |
211 |
> |
ip[1] += 180.0/v->horiz; |
212 |
> |
ip[2] += 180.0/v->vert; |
213 |
> |
return; |
214 |
> |
} |
215 |
> |
d = acos(d)/PI / sqrt(1.0 - d*d); |
216 |
> |
ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz; |
217 |
> |
ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert; |
218 |
> |
return; |
219 |
|
} |
220 |
< |
*xp = DOT(disp,v->vhinc)*v->vhs2 + 0.5*v->hresolu; |
221 |
< |
*yp = DOT(disp,v->vvinc)*v->vvs2 + 0.5*v->vresolu; |
220 |
> |
ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
221 |
> |
ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
< |
sscanview(vp, s) /* get view parameters */ |
226 |
< |
register VIEW *vp; |
225 |
> |
pix2loc(loc, rp, px, py) /* compute image location from pixel pos. */ |
226 |
> |
FLOAT loc[2]; |
227 |
> |
register RESOLU *rp; |
228 |
> |
int px, py; |
229 |
> |
{ |
230 |
> |
register int x, y; |
231 |
> |
|
232 |
> |
if (rp->or & YMAJOR) { |
233 |
> |
x = px; |
234 |
> |
y = py; |
235 |
> |
} else { |
236 |
> |
x = py; |
237 |
> |
y = px; |
238 |
> |
} |
239 |
> |
if (rp->or & XDECR) |
240 |
> |
x = rp->xr-1 - x; |
241 |
> |
if (rp->or & YDECR) |
242 |
> |
y = rp->yr-1 - y; |
243 |
> |
loc[0] = (x+.5)/rp->xr; |
244 |
> |
loc[1] = (y+.5)/rp->yr; |
245 |
> |
} |
246 |
> |
|
247 |
> |
|
248 |
> |
loc2pix(pp, rp, lx, ly) /* compute pixel pos. from image location */ |
249 |
> |
int pp[2]; |
250 |
> |
register RESOLU *rp; |
251 |
> |
double lx, ly; |
252 |
> |
{ |
253 |
> |
register int x, y; |
254 |
> |
|
255 |
> |
x = lx * rp->xr; |
256 |
> |
y = ly * rp->yr; |
257 |
> |
if (rp->or & XDECR) |
258 |
> |
x = rp->xr-1 - x; |
259 |
> |
if (rp->or & YDECR) |
260 |
> |
y = rp->yr-1 - y; |
261 |
> |
if (rp->or & YMAJOR) { |
262 |
> |
pp[0] = x; |
263 |
> |
pp[1] = y; |
264 |
> |
} else { |
265 |
> |
pp[0] = y; |
266 |
> |
pp[1] = x; |
267 |
> |
} |
268 |
> |
} |
269 |
> |
|
270 |
> |
|
271 |
> |
int |
272 |
> |
getviewopt(v, ac, av) /* process view argument */ |
273 |
> |
register VIEW *v; |
274 |
> |
int ac; |
275 |
> |
register char *av[]; |
276 |
> |
{ |
277 |
> |
#define check(c,l) if ((av[0][c]&&av[0][c]!=' ') || \ |
278 |
> |
badarg(ac-1,av+1,l)) return(-1) |
279 |
> |
|
280 |
> |
if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v') |
281 |
> |
return(-1); |
282 |
> |
switch (av[0][2]) { |
283 |
> |
case 't': /* type */ |
284 |
> |
if (!av[0][3] || av[0][3]==' ') |
285 |
> |
return(-1); |
286 |
> |
check(4,""); |
287 |
> |
v->type = av[0][3]; |
288 |
> |
return(0); |
289 |
> |
case 'p': /* point */ |
290 |
> |
check(3,"fff"); |
291 |
> |
v->vp[0] = atof(av[1]); |
292 |
> |
v->vp[1] = atof(av[2]); |
293 |
> |
v->vp[2] = atof(av[3]); |
294 |
> |
return(3); |
295 |
> |
case 'd': /* direction */ |
296 |
> |
check(3,"fff"); |
297 |
> |
v->vdir[0] = atof(av[1]); |
298 |
> |
v->vdir[1] = atof(av[2]); |
299 |
> |
v->vdir[2] = atof(av[3]); |
300 |
> |
return(3); |
301 |
> |
case 'u': /* up */ |
302 |
> |
check(3,"fff"); |
303 |
> |
v->vup[0] = atof(av[1]); |
304 |
> |
v->vup[1] = atof(av[2]); |
305 |
> |
v->vup[2] = atof(av[3]); |
306 |
> |
return(3); |
307 |
> |
case 'h': /* horizontal size */ |
308 |
> |
check(3,"f"); |
309 |
> |
v->horiz = atof(av[1]); |
310 |
> |
return(1); |
311 |
> |
case 'v': /* vertical size */ |
312 |
> |
check(3,"f"); |
313 |
> |
v->vert = atof(av[1]); |
314 |
> |
return(1); |
315 |
> |
case 's': /* shift */ |
316 |
> |
check(3,"f"); |
317 |
> |
v->hoff = atof(av[1]); |
318 |
> |
return(1); |
319 |
> |
case 'l': /* lift */ |
320 |
> |
check(3,"f"); |
321 |
> |
v->voff = atof(av[1]); |
322 |
> |
return(1); |
323 |
> |
default: |
324 |
> |
return(-1); |
325 |
> |
} |
326 |
> |
#undef check |
327 |
> |
} |
328 |
> |
|
329 |
> |
|
330 |
> |
int |
331 |
> |
sscanview(vp, s) /* get view parameters from string */ |
332 |
> |
VIEW *vp; |
333 |
|
register char *s; |
334 |
|
{ |
335 |
< |
for ( ; ; ) |
336 |
< |
switch (*s++) { |
337 |
< |
case '\0': |
338 |
< |
case '\n': |
339 |
< |
return(0); |
340 |
< |
case '-': |
341 |
< |
switch (*s++) { |
342 |
< |
case '\0': |
343 |
< |
return(-1); |
344 |
< |
case 'x': |
345 |
< |
if (sscanf(s, "%d", &vp->hresolu) != 1) |
346 |
< |
return(-1); |
347 |
< |
s = sskip(s); |
348 |
< |
continue; |
349 |
< |
case 'y': |
350 |
< |
if (sscanf(s, "%d", &vp->vresolu) != 1) |
351 |
< |
return(-1); |
352 |
< |
s = sskip(s); |
353 |
< |
continue; |
354 |
< |
case 'v': |
355 |
< |
switch (*s++) { |
356 |
< |
case '\0': |
357 |
< |
return(-1); |
358 |
< |
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 |
< |
} |
335 |
> |
int ac; |
336 |
> |
char *av[4]; |
337 |
> |
int na; |
338 |
> |
int nvopts = 0; |
339 |
> |
|
340 |
> |
if (*s != '-') |
341 |
> |
s = sskip(s); |
342 |
> |
while (*s) { |
343 |
> |
ac = 0; |
344 |
> |
do { |
345 |
> |
av[ac++] = s; |
346 |
> |
while (*s && *s != ' ') |
347 |
> |
s++; |
348 |
> |
while (*s == ' ') |
349 |
> |
s++; |
350 |
> |
} while (*s && ac < 4); |
351 |
> |
if ((na = getviewopt(vp, ac, av)) >= 0) { |
352 |
> |
if (na+1 < ac) |
353 |
> |
s = av[na+1]; |
354 |
> |
nvopts++; |
355 |
> |
} else if (ac > 1) |
356 |
> |
s = av[1]; |
357 |
> |
} |
358 |
> |
return(nvopts); |
359 |
|
} |
360 |
|
|
361 |
|
|
368 |
|
fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]); |
369 |
|
fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]); |
370 |
|
fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert); |
371 |
< |
fprintf(fp, " -x %d -y %d", vp->hresolu, vp->vresolu); |
371 |
> |
fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff); |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
< |
static VIEW *hview; /* view from header */ |
376 |
< |
static int gothview; /* success indicator */ |
377 |
< |
static char *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL}; |
375 |
> |
int |
376 |
> |
isview(s) /* is this a view string? */ |
377 |
> |
char *s; |
378 |
> |
{ |
379 |
> |
static char *altname[]={NULL,"rpict","rview","pinterp",VIEWSTR,NULL}; |
380 |
> |
extern char *progname, *rindex(); |
381 |
> |
register char *cp; |
382 |
> |
register char **an; |
383 |
> |
/* add program name to list */ |
384 |
> |
if (altname[0] == NULL) |
385 |
> |
if ((cp = rindex(progname, '/')) != NULL) |
386 |
> |
altname[0] = cp+1; |
387 |
> |
else |
388 |
> |
altname[0] = progname; |
389 |
> |
/* skip leading path */ |
390 |
> |
cp = s; |
391 |
> |
while (*cp && *cp != ' ') |
392 |
> |
cp++; |
393 |
> |
while (cp > s && 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; |
405 |
+ |
}; |
406 |
+ |
|
407 |
+ |
|
408 |
|
static |
409 |
< |
gethview(s) /* get view from header */ |
409 |
> |
gethview(s, v) /* get view from header */ |
410 |
|
char *s; |
411 |
+ |
register struct myview *v; |
412 |
|
{ |
413 |
< |
register char **an; |
414 |
< |
|
242 |
< |
for (an = altname; *an != NULL; an++) |
243 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
244 |
< |
if (sscanview(hview, s+strlen(*an)) == 0) |
245 |
< |
gothview++; |
246 |
< |
return; |
247 |
< |
} |
413 |
> |
if (isview(s) && sscanview(v->hv, s) > 0) |
414 |
> |
v->ok++; |
415 |
|
} |
416 |
|
|
417 |
|
|
418 |
|
int |
419 |
< |
viewfile(fname, vp) /* get view from file */ |
419 |
> |
viewfile(fname, vp, rp) /* get view from file */ |
420 |
|
char *fname; |
421 |
|
VIEW *vp; |
422 |
+ |
RESOLU *rp; |
423 |
|
{ |
424 |
< |
extern char *progname; |
424 |
> |
struct myview mvs; |
425 |
|
FILE *fp; |
426 |
|
|
427 |
|
if ((fp = fopen(fname, "r")) == NULL) |
428 |
|
return(-1); |
429 |
|
|
430 |
< |
altname[0] = progname; |
431 |
< |
hview = vp; |
264 |
< |
gothview = 0; |
430 |
> |
mvs.hv = vp; |
431 |
> |
mvs.ok = 0; |
432 |
|
|
433 |
< |
getheader(fp, gethview); |
433 |
> |
getheader(fp, gethview, &mvs); |
434 |
|
|
435 |
+ |
if (rp != NULL && !fgetsresolu(rp, fp)) |
436 |
+ |
mvs.ok = 0; |
437 |
+ |
|
438 |
|
fclose(fp); |
439 |
|
|
440 |
< |
return(gothview); |
440 |
> |
return(mvs.ok); |
441 |
|
} |