1 |
– |
/* Copyright (c) 1986 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 "copyright.h" |
11 |
+ |
|
12 |
|
#include "standard.h" |
13 |
|
|
15 |
– |
#include "color.h" |
16 |
– |
|
14 |
|
#include "view.h" |
15 |
|
|
16 |
< |
VIEW stdview = STDVIEW(512); /* default view parameters */ |
16 |
> |
#include "paths.h" |
17 |
|
|
18 |
+ |
#define FEQ(x,y) (fabs((x)-(y)) <= FTINY) |
19 |
+ |
#define VEQ(v,w) (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \ |
20 |
+ |
&& FEQ((v)[2],(w)[2])) |
21 |
|
|
22 |
< |
bigdiff(c1, c2, md) /* c1 delta c2 > md? */ |
23 |
< |
register COLOR c1, c2; |
24 |
< |
double md; |
25 |
< |
{ |
26 |
< |
register int i; |
22 |
> |
VIEW stdview = STDVIEW; /* default view parameters */ |
23 |
|
|
28 |
– |
for (i = 0; i < 3; i++) |
29 |
– |
if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) || |
30 |
– |
colval(c2,i)-colval(c1,i) > md*colval(c1,i)) |
31 |
– |
return(1); |
32 |
– |
return(0); |
33 |
– |
} |
24 |
|
|
35 |
– |
|
25 |
|
char * |
26 |
< |
setview(v) /* set vhinc and vvinc, return message on error */ |
26 |
> |
setview(v) /* set hvec and vvec, return message on error */ |
27 |
|
register VIEW *v; |
28 |
|
{ |
29 |
< |
double tan(), dt; |
29 |
> |
static char ill_horiz[] = "illegal horizontal view size"; |
30 |
> |
static char ill_vert[] = "illegal vertical view size"; |
31 |
|
|
32 |
+ |
if (v->vaft < -FTINY || (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"); |
44 |
– |
|
45 |
– |
fcross(v->vhinc, v->vdir, v->vup); /* compute horiz dir */ |
37 |
|
|
38 |
< |
if (normalize(v->vhinc) == 0.0) |
39 |
< |
return("illegal view up vector"); |
49 |
< |
|
50 |
< |
fcross(v->vvinc, v->vhinc, v->vdir); /* compute vert dir */ |
38 |
> |
if (normalize(v->vup) == 0.0) /* normalize view up */ |
39 |
> |
return("zero view up vector"); |
40 |
|
|
41 |
< |
if (v->type == VT_PAR) |
53 |
< |
dt = v->horiz; |
54 |
< |
else if (v->type == VT_PER) |
55 |
< |
dt = 2.0 * tan(v->horiz*(PI/180.0/2.0)); |
56 |
< |
else |
57 |
< |
return("unknown view type"); |
41 |
> |
fcross(v->hvec, v->vdir, v->vup); /* compute horiz dir */ |
42 |
|
|
43 |
< |
if (dt <= FTINY || dt >= FHUGE) |
44 |
< |
return("illegal horizontal view size"); |
43 |
> |
if (normalize(v->hvec) == 0.0) |
44 |
> |
return("view up parallel to view direction"); |
45 |
|
|
46 |
< |
if (v->hresolu <= 0) |
63 |
< |
return("illegal horizontal resolution"); |
46 |
> |
fcross(v->vvec, v->hvec, v->vdir); /* compute vert dir */ |
47 |
|
|
48 |
< |
dt /= (double)v->hresolu; |
49 |
< |
v->vhinc[0] *= dt; |
50 |
< |
v->vhinc[1] *= dt; |
51 |
< |
v->vhinc[2] *= dt; |
48 |
> |
if (v->horiz <= FTINY) |
49 |
> |
return(ill_horiz); |
50 |
> |
if (v->vert <= FTINY) |
51 |
> |
return(ill_vert); |
52 |
|
|
53 |
< |
if (v->type == VT_PAR) |
54 |
< |
dt = v->vert; |
55 |
< |
else |
56 |
< |
dt = 2.0 * tan(v->vert*(PI/180.0/2.0)); |
53 |
> |
switch (v->type) { |
54 |
> |
case VT_PAR: /* parallel view */ |
55 |
> |
v->hn2 = v->horiz; |
56 |
> |
v->vn2 = v->vert; |
57 |
> |
break; |
58 |
> |
case VT_PER: /* perspective view */ |
59 |
> |
if (v->horiz >= 180.0-FTINY) |
60 |
> |
return(ill_horiz); |
61 |
> |
if (v->vert >= 180.0-FTINY) |
62 |
> |
return(ill_vert); |
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 * (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) |
84 |
> |
return(ill_horiz); |
85 |
> |
if (v->vert > 180.0+FTINY) |
86 |
> |
return(ill_vert); |
87 |
> |
v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0)); |
88 |
> |
v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0)); |
89 |
> |
break; |
90 |
> |
default: |
91 |
> |
return("unknown view type"); |
92 |
> |
} |
93 |
> |
if (v->type != VT_ANG) { |
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; |
102 |
> |
} |
103 |
> |
v->hn2 *= v->hn2; |
104 |
> |
v->vn2 *= v->vn2; |
105 |
|
|
106 |
< |
if (dt <= FTINY || dt >= FHUGE) |
107 |
< |
return("illegal vertical view size"); |
106 |
> |
return(NULL); |
107 |
> |
} |
108 |
|
|
78 |
– |
if (v->vresolu <= 0) |
79 |
– |
return("illegal vertical resolution"); |
80 |
– |
|
81 |
– |
dt /= (double)v->vresolu; |
82 |
– |
v->vvinc[0] *= dt; |
83 |
– |
v->vvinc[1] *= dt; |
84 |
– |
v->vvinc[2] *= dt; |
109 |
|
|
110 |
< |
return(NULL); |
110 |
> |
void |
111 |
> |
normaspect(va, ap, xp, yp) /* fix pixel aspect or resolution */ |
112 |
> |
double va; /* view aspect ratio */ |
113 |
> |
double *ap; /* pixel aspect in (or out if 0) */ |
114 |
> |
int *xp, *yp; /* x and y resolution in (or out if *ap!=0) */ |
115 |
> |
{ |
116 |
> |
if (*ap <= FTINY) |
117 |
> |
*ap = va * *xp / *yp; /* compute pixel aspect */ |
118 |
> |
else if (va * *xp > *ap * *yp) |
119 |
> |
*xp = *yp / va * *ap + .5; /* reduce x resolution */ |
120 |
> |
else |
121 |
> |
*yp = *xp * va / *ap + .5; /* reduce y resolution */ |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
< |
rayview(orig, direc, v, x, y) /* compute ray origin and direction */ |
125 |
> |
double |
126 |
> |
viewray(orig, direc, v, x, y) /* compute ray origin and direction */ |
127 |
|
FVECT orig, direc; |
128 |
|
register VIEW *v; |
129 |
|
double x, y; |
130 |
|
{ |
131 |
< |
register int i; |
131 |
> |
double d, z; |
132 |
> |
|
133 |
> |
x += v->hoff - 0.5; |
134 |
> |
y += v->voff - 0.5; |
135 |
|
|
136 |
< |
x -= 0.5 * v->hresolu; |
137 |
< |
y -= 0.5 * v->vresolu; |
138 |
< |
|
139 |
< |
if (v->type == VT_PAR) { /* parallel view */ |
140 |
< |
for (i = 0; i < 3; i++) |
141 |
< |
orig[i] = v->vp[i] + x*v->vhinc[i] + y*v->vvinc[i]; |
136 |
> |
switch(v->type) { |
137 |
> |
case VT_PAR: /* parallel view */ |
138 |
> |
orig[0] = v->vp[0] + v->vfore*v->vdir[0] |
139 |
> |
+ x*v->hvec[0] + y*v->vvec[0]; |
140 |
> |
orig[1] = v->vp[1] + v->vfore*v->vdir[1] |
141 |
> |
+ x*v->hvec[1] + y*v->vvec[1]; |
142 |
> |
orig[2] = v->vp[2] + v->vfore*v->vdir[2] |
143 |
> |
+ x*v->hvec[2] + y*v->vvec[2]; |
144 |
|
VCOPY(direc, v->vdir); |
145 |
< |
} else { /* perspective view */ |
146 |
< |
VCOPY(orig, v->vp); |
147 |
< |
for (i = 0; i < 3; i++) |
148 |
< |
direc[i] = v->vdir[i] + x*v->vhinc[i] + y*v->vvinc[i]; |
149 |
< |
normalize(direc); |
145 |
> |
return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0); |
146 |
> |
case VT_PER: /* perspective view */ |
147 |
> |
direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
148 |
> |
direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
149 |
> |
direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
150 |
> |
orig[0] = v->vp[0] + v->vfore*direc[0]; |
151 |
> |
orig[1] = v->vp[1] + v->vfore*direc[1]; |
152 |
> |
orig[2] = v->vp[2] + v->vfore*direc[2]; |
153 |
> |
d = normalize(direc); |
154 |
> |
return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0); |
155 |
> |
case VT_HEM: /* hemispherical fisheye */ |
156 |
> |
z = 1.0 - x*x*v->hn2 - y*y*v->vn2; |
157 |
> |
if (z < 0.0) |
158 |
> |
return(-1.0); |
159 |
> |
z = sqrt(z); |
160 |
> |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
161 |
> |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
162 |
> |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
163 |
> |
orig[0] = v->vp[0] + v->vfore*direc[0]; |
164 |
> |
orig[1] = v->vp[1] + v->vfore*direc[1]; |
165 |
> |
orig[2] = v->vp[2] + v->vfore*direc[2]; |
166 |
> |
return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0); |
167 |
> |
case VT_CYL: /* cylindrical panorama */ |
168 |
> |
d = x * v->horiz * (PI/180.0); |
169 |
> |
z = cos(d); |
170 |
> |
x = sin(d); |
171 |
> |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
172 |
> |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
173 |
> |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
174 |
> |
orig[0] = v->vp[0] + v->vfore*direc[0]; |
175 |
> |
orig[1] = v->vp[1] + v->vfore*direc[1]; |
176 |
> |
orig[2] = v->vp[2] + v->vfore*direc[2]; |
177 |
> |
d = normalize(direc); |
178 |
> |
return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0); |
179 |
> |
case VT_ANG: /* angular fisheye */ |
180 |
> |
x *= v->horiz/180.0; |
181 |
> |
y *= v->vert/180.0; |
182 |
> |
d = x*x + y*y; |
183 |
> |
if (d > 1.0) |
184 |
> |
return(-1.0); |
185 |
> |
d = sqrt(d); |
186 |
> |
z = cos(PI*d); |
187 |
> |
d = d <= FTINY ? PI : sqrt(1 - z*z)/d; |
188 |
> |
x *= d; |
189 |
> |
y *= d; |
190 |
> |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
191 |
> |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
192 |
> |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
193 |
> |
orig[0] = v->vp[0] + v->vfore*direc[0]; |
194 |
> |
orig[1] = v->vp[1] + v->vfore*direc[1]; |
195 |
> |
orig[2] = v->vp[2] + v->vfore*direc[2]; |
196 |
> |
return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0); |
197 |
|
} |
198 |
+ |
return(-1.0); |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
< |
sscanview(vp, s) /* get view parameters */ |
203 |
< |
register VIEW *vp; |
204 |
< |
register char *s; |
202 |
> |
void |
203 |
> |
viewloc(ip, v, p) /* find image location for point */ |
204 |
> |
FVECT ip; |
205 |
> |
register VIEW *v; |
206 |
> |
FVECT p; |
207 |
|
{ |
208 |
< |
for ( ; ; ) |
209 |
< |
switch (*s++) { |
210 |
< |
case '\0': |
211 |
< |
case '\n': |
212 |
< |
return(0); |
213 |
< |
case '-': |
214 |
< |
switch (*s++) { |
215 |
< |
case '\0': |
216 |
< |
return(-1); |
217 |
< |
case 'x': |
218 |
< |
if (sscanf(s, "%d", &vp->hresolu) != 1) |
219 |
< |
return(-1); |
220 |
< |
s = sskip(s); |
221 |
< |
continue; |
222 |
< |
case 'y': |
223 |
< |
if (sscanf(s, "%d", &vp->vresolu) != 1) |
224 |
< |
return(-1); |
134 |
< |
s = sskip(s); |
135 |
< |
continue; |
136 |
< |
case 'v': |
137 |
< |
switch (*s++) { |
138 |
< |
case '\0': |
139 |
< |
return(-1); |
140 |
< |
case 't': |
141 |
< |
vp->type = *s++; |
142 |
< |
continue; |
143 |
< |
case 'p': |
144 |
< |
if (sscanf(s, "%lf %lf %lf", |
145 |
< |
&vp->vp[0], |
146 |
< |
&vp->vp[1], |
147 |
< |
&vp->vp[2]) != 3) |
148 |
< |
return(-1); |
149 |
< |
s = sskip(sskip(sskip(s))); |
150 |
< |
continue; |
151 |
< |
case 'd': |
152 |
< |
if (sscanf(s, "%lf %lf %lf", |
153 |
< |
&vp->vdir[0], |
154 |
< |
&vp->vdir[1], |
155 |
< |
&vp->vdir[2]) != 3) |
156 |
< |
return(-1); |
157 |
< |
s = sskip(sskip(sskip(s))); |
158 |
< |
continue; |
159 |
< |
case 'u': |
160 |
< |
if (sscanf(s, "%lf %lf %lf", |
161 |
< |
&vp->vup[0], |
162 |
< |
&vp->vup[1], |
163 |
< |
&vp->vup[2]) != 3) |
164 |
< |
return(-1); |
165 |
< |
s = sskip(sskip(sskip(s))); |
166 |
< |
continue; |
167 |
< |
case 'h': |
168 |
< |
if (sscanf(s, "%lf", |
169 |
< |
&vp->horiz) != 1) |
170 |
< |
return(-1); |
171 |
< |
s = sskip(s); |
172 |
< |
continue; |
173 |
< |
case 'v': |
174 |
< |
if (sscanf(s, "%lf", |
175 |
< |
&vp->vert) != 1) |
176 |
< |
return(-1); |
177 |
< |
s = sskip(s); |
178 |
< |
continue; |
179 |
< |
} |
180 |
< |
continue; |
181 |
< |
} |
182 |
< |
continue; |
208 |
> |
double d, d2; |
209 |
> |
FVECT disp; |
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 |
> |
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 |
+ |
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 |
+ |
ip[2] *= (1.0 - v->vfore*d); |
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) - v->vfore; |
255 |
+ |
d = DOT(disp,v->vdir); |
256 |
+ |
if (d >= 1.0-FTINY) |
257 |
+ |
return; |
258 |
+ |
if (d <= -(1.0-FTINY)) { |
259 |
+ |
ip[0] += 180.0/v->horiz; |
260 |
+ |
return; |
261 |
+ |
} |
262 |
+ |
d = acos(d)/PI / sqrt(1.0 - d*d); |
263 |
+ |
ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz; |
264 |
+ |
ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert; |
265 |
+ |
return; |
266 |
+ |
} |
267 |
+ |
ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
268 |
+ |
ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
+ |
void |
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->rt & YMAJOR) { |
281 |
+ |
x = px; |
282 |
+ |
y = py; |
283 |
+ |
} else { |
284 |
+ |
x = py; |
285 |
+ |
y = px; |
286 |
+ |
} |
287 |
+ |
if (rp->rt & XDECR) |
288 |
+ |
x = rp->xr-1 - x; |
289 |
+ |
if (rp->rt & 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 |
+ |
void |
297 |
+ |
loc2pix(pp, rp, lx, ly) /* compute pixel pos. from image location */ |
298 |
+ |
int pp[2]; |
299 |
+ |
register RESOLU *rp; |
300 |
+ |
double lx, ly; |
301 |
+ |
{ |
302 |
+ |
register int x, y; |
303 |
+ |
|
304 |
+ |
x = lx * rp->xr; |
305 |
+ |
y = ly * rp->yr; |
306 |
+ |
if (rp->rt & XDECR) |
307 |
+ |
x = rp->xr-1 - x; |
308 |
+ |
if (rp->rt & YDECR) |
309 |
+ |
y = rp->yr-1 - y; |
310 |
+ |
if (rp->rt & YMAJOR) { |
311 |
+ |
pp[0] = x; |
312 |
+ |
pp[1] = y; |
313 |
+ |
} else { |
314 |
+ |
pp[0] = y; |
315 |
+ |
pp[1] = x; |
316 |
+ |
} |
317 |
+ |
} |
318 |
+ |
|
319 |
+ |
|
320 |
+ |
int |
321 |
+ |
getviewopt(v, ac, av) /* process view argument */ |
322 |
+ |
register VIEW *v; |
323 |
+ |
int ac; |
324 |
+ |
register char *av[]; |
325 |
+ |
{ |
326 |
+ |
#define check(c,l) if ((av[0][c]&&av[0][c]!=' ') || \ |
327 |
+ |
badarg(ac-1,av+1,l)) return(-1) |
328 |
+ |
|
329 |
+ |
if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v') |
330 |
+ |
return(-1); |
331 |
+ |
switch (av[0][2]) { |
332 |
+ |
case 't': /* type */ |
333 |
+ |
if (!av[0][3] || av[0][3]==' ') |
334 |
+ |
return(-1); |
335 |
+ |
check(4,""); |
336 |
+ |
v->type = av[0][3]; |
337 |
+ |
return(0); |
338 |
+ |
case 'p': /* point */ |
339 |
+ |
check(3,"fff"); |
340 |
+ |
v->vp[0] = atof(av[1]); |
341 |
+ |
v->vp[1] = atof(av[2]); |
342 |
+ |
v->vp[2] = atof(av[3]); |
343 |
+ |
return(3); |
344 |
+ |
case 'd': /* direction */ |
345 |
+ |
check(3,"fff"); |
346 |
+ |
v->vdir[0] = atof(av[1]); |
347 |
+ |
v->vdir[1] = atof(av[2]); |
348 |
+ |
v->vdir[2] = atof(av[3]); |
349 |
+ |
return(3); |
350 |
+ |
case 'u': /* up */ |
351 |
+ |
check(3,"fff"); |
352 |
+ |
v->vup[0] = atof(av[1]); |
353 |
+ |
v->vup[1] = atof(av[2]); |
354 |
+ |
v->vup[2] = atof(av[3]); |
355 |
+ |
return(3); |
356 |
+ |
case 'h': /* horizontal size */ |
357 |
+ |
check(3,"f"); |
358 |
+ |
v->horiz = atof(av[1]); |
359 |
+ |
return(1); |
360 |
+ |
case 'v': /* vertical size */ |
361 |
+ |
check(3,"f"); |
362 |
+ |
v->vert = atof(av[1]); |
363 |
+ |
return(1); |
364 |
+ |
case 'o': /* fore clipping plane */ |
365 |
+ |
check(3,"f"); |
366 |
+ |
v->vfore = atof(av[1]); |
367 |
+ |
return(1); |
368 |
+ |
case 'a': /* aft clipping plane */ |
369 |
+ |
check(3,"f"); |
370 |
+ |
v->vaft = atof(av[1]); |
371 |
+ |
return(1); |
372 |
+ |
case 's': /* shift */ |
373 |
+ |
check(3,"f"); |
374 |
+ |
v->hoff = atof(av[1]); |
375 |
+ |
return(1); |
376 |
+ |
case 'l': /* lift */ |
377 |
+ |
check(3,"f"); |
378 |
+ |
v->voff = atof(av[1]); |
379 |
+ |
return(1); |
380 |
+ |
default: |
381 |
+ |
return(-1); |
382 |
+ |
} |
383 |
+ |
#undef check |
384 |
+ |
} |
385 |
+ |
|
386 |
+ |
|
387 |
+ |
int |
388 |
+ |
sscanview(vp, s) /* get view parameters from string */ |
389 |
+ |
VIEW *vp; |
390 |
+ |
register char *s; |
391 |
+ |
{ |
392 |
+ |
int ac; |
393 |
+ |
char *av[4]; |
394 |
+ |
int na; |
395 |
+ |
int nvopts = 0; |
396 |
+ |
|
397 |
+ |
if (*s != '-') |
398 |
+ |
s = sskip2(s,1); |
399 |
+ |
while (*s) { |
400 |
+ |
ac = 0; |
401 |
+ |
do { |
402 |
+ |
av[ac++] = s; |
403 |
+ |
while (*s && *s != ' ') |
404 |
+ |
s++; |
405 |
+ |
while (*s == ' ') |
406 |
+ |
s++; |
407 |
+ |
} while (*s && ac < 4); |
408 |
+ |
if ((na = getviewopt(vp, ac, av)) >= 0) { |
409 |
+ |
if (na+1 < ac) |
410 |
+ |
s = av[na+1]; |
411 |
+ |
nvopts++; |
412 |
+ |
} else if (ac > 1) |
413 |
+ |
s = av[1]; |
414 |
+ |
} |
415 |
+ |
return(nvopts); |
416 |
+ |
} |
417 |
+ |
|
418 |
+ |
|
419 |
+ |
void |
420 |
|
fprintview(vp, fp) /* write out view parameters */ |
421 |
|
register VIEW *vp; |
422 |
|
FILE *fp; |
426 |
|
fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]); |
427 |
|
fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]); |
428 |
|
fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert); |
429 |
< |
fprintf(fp, " -x %d -y %d", vp->hresolu, vp->vresolu); |
429 |
> |
fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft); |
430 |
> |
fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff); |
431 |
|
} |
432 |
|
|
433 |
|
|
434 |
< |
static VIEW *hview; /* view from header */ |
435 |
< |
static int gothview; /* success indicator */ |
436 |
< |
static char *altname[] = {NULL,"rpict","rview",VIEWSTR,NULL}; |
434 |
> |
char * |
435 |
> |
viewopt(vp) /* translate to minimal view string */ |
436 |
> |
register VIEW *vp; |
437 |
> |
{ |
438 |
> |
static char vwstr[128]; |
439 |
> |
register char *cp = vwstr; |
440 |
|
|
441 |
+ |
if (vp->type != stdview.type) { |
442 |
+ |
sprintf(cp, " -vt%c", vp->type); |
443 |
+ |
cp += strlen(cp); |
444 |
+ |
} |
445 |
+ |
if (!VEQ(vp->vp,stdview.vp)) { |
446 |
+ |
sprintf(cp, " -vp %.6g %.6g %.6g", |
447 |
+ |
vp->vp[0], vp->vp[1], vp->vp[2]); |
448 |
+ |
cp += strlen(cp); |
449 |
+ |
} |
450 |
+ |
if (!VEQ(vp->vdir,stdview.vdir)) { |
451 |
+ |
sprintf(cp, " -vd %.6g %.6g %.6g", |
452 |
+ |
vp->vdir[0], vp->vdir[1], vp->vdir[2]); |
453 |
+ |
cp += strlen(cp); |
454 |
+ |
} |
455 |
+ |
if (!VEQ(vp->vup,stdview.vup)) { |
456 |
+ |
sprintf(cp, " -vu %.6g %.6g %.6g", |
457 |
+ |
vp->vup[0], vp->vup[1], vp->vup[2]); |
458 |
+ |
cp += strlen(cp); |
459 |
+ |
} |
460 |
+ |
if (!FEQ(vp->horiz,stdview.horiz)) { |
461 |
+ |
sprintf(cp, " -vh %.6g", vp->horiz); |
462 |
+ |
cp += strlen(cp); |
463 |
+ |
} |
464 |
+ |
if (!FEQ(vp->vert,stdview.vert)) { |
465 |
+ |
sprintf(cp, " -vv %.6g", vp->vert); |
466 |
+ |
cp += strlen(cp); |
467 |
+ |
} |
468 |
+ |
if (!FEQ(vp->vfore,stdview.vfore)) { |
469 |
+ |
sprintf(cp, " -vo %.6g", vp->vfore); |
470 |
+ |
cp += strlen(cp); |
471 |
+ |
} |
472 |
+ |
if (!FEQ(vp->vaft,stdview.vaft)) { |
473 |
+ |
sprintf(cp, " -va %.6g", vp->vaft); |
474 |
+ |
cp += strlen(cp); |
475 |
+ |
} |
476 |
+ |
if (!FEQ(vp->hoff,stdview.hoff)) { |
477 |
+ |
sprintf(cp, " -vs %.6g", vp->hoff); |
478 |
+ |
cp += strlen(cp); |
479 |
+ |
} |
480 |
+ |
if (!FEQ(vp->voff,stdview.voff)) { |
481 |
+ |
sprintf(cp, " -vl %.6g", vp->voff); |
482 |
+ |
cp += strlen(cp); |
483 |
+ |
} |
484 |
+ |
return(vwstr); |
485 |
+ |
} |
486 |
|
|
487 |
< |
static |
488 |
< |
gethview(s) /* get view from header */ |
487 |
> |
|
488 |
> |
int |
489 |
> |
isview(s) /* is this a view string? */ |
490 |
|
char *s; |
491 |
|
{ |
492 |
+ |
static char *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL}; |
493 |
+ |
extern char *progname; |
494 |
+ |
register char *cp; |
495 |
|
register char **an; |
496 |
< |
|
496 |
> |
/* add program name to list */ |
497 |
> |
if (altname[0] == NULL) { |
498 |
> |
for (cp = progname; *cp; cp++) |
499 |
> |
; |
500 |
> |
while (cp > progname && !ISDIRSEP(cp[-1])) |
501 |
> |
cp--; |
502 |
> |
altname[0] = cp; |
503 |
> |
} |
504 |
> |
/* skip leading path */ |
505 |
> |
cp = s; |
506 |
> |
while (*cp && *cp != ' ') |
507 |
> |
cp++; |
508 |
> |
while (cp > s && !ISDIRSEP(cp[-1])) |
509 |
> |
cp--; |
510 |
|
for (an = altname; *an != NULL; an++) |
511 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
512 |
< |
if (sscanview(hview, s+strlen(*an)) == 0) |
513 |
< |
gothview++; |
215 |
< |
return; |
216 |
< |
} |
511 |
> |
if (!strncmp(*an, cp, strlen(*an))) |
512 |
> |
return(1); |
513 |
> |
return(0); |
514 |
|
} |
515 |
|
|
516 |
|
|
517 |
+ |
struct myview { |
518 |
+ |
VIEW *hv; |
519 |
+ |
int ok; |
520 |
+ |
}; |
521 |
+ |
|
522 |
+ |
|
523 |
+ |
static int |
524 |
+ |
gethview(s, v) /* get view from header */ |
525 |
+ |
char *s; |
526 |
+ |
register struct myview *v; |
527 |
+ |
{ |
528 |
+ |
if (isview(s) && sscanview(v->hv, s) > 0) |
529 |
+ |
v->ok++; |
530 |
+ |
return(0); |
531 |
+ |
} |
532 |
+ |
|
533 |
+ |
|
534 |
|
int |
535 |
< |
viewfile(fname, vp) /* get view from file */ |
535 |
> |
viewfile(fname, vp, rp) /* get view from file */ |
536 |
|
char *fname; |
537 |
|
VIEW *vp; |
538 |
+ |
RESOLU *rp; |
539 |
|
{ |
540 |
< |
extern char *progname; |
540 |
> |
struct myview mvs; |
541 |
|
FILE *fp; |
542 |
|
|
543 |
< |
if ((fp = fopen(fname, "r")) == NULL) |
543 |
> |
if (fname == NULL || !strcmp(fname, "-")) |
544 |
> |
fp = stdin; |
545 |
> |
else if ((fp = fopen(fname, "r")) == NULL) |
546 |
|
return(-1); |
547 |
|
|
548 |
< |
altname[0] = progname; |
549 |
< |
hview = vp; |
233 |
< |
gothview = 0; |
548 |
> |
mvs.hv = vp; |
549 |
> |
mvs.ok = 0; |
550 |
|
|
551 |
< |
getheader(fp, gethview); |
551 |
> |
getheader(fp, (int (*)(char *, char *))&gethview, (char *)&mvs); |
552 |
|
|
553 |
+ |
if (rp != NULL && !fgetsresolu(rp, fp)) |
554 |
+ |
mvs.ok = 0; |
555 |
+ |
|
556 |
|
fclose(fp); |
557 |
|
|
558 |
< |
return(gothview); |
558 |
> |
return(mvs.ok); |
559 |
|
} |