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"; |
14 |
|
|
15 |
|
#include "view.h" |
16 |
|
|
17 |
+ |
#include "resolu.h" |
18 |
+ |
|
19 |
|
VIEW stdview = STDVIEW; /* default view parameters */ |
20 |
|
|
21 |
|
|
29 |
|
if (normalize(v->vdir) == 0.0) /* normalize direction */ |
30 |
|
return("zero view direction"); |
31 |
|
|
32 |
+ |
if (normalize(v->vup) == 0.0) /* normalize view up */ |
33 |
+ |
return("zero view up vector"); |
34 |
+ |
|
35 |
|
fcross(v->hvec, v->vdir, v->vup); /* compute horiz dir */ |
36 |
|
|
37 |
|
if (normalize(v->hvec) == 0.0) |
38 |
< |
return("illegal view up vector"); |
38 |
> |
return("view up parallel to view direction"); |
39 |
|
|
40 |
|
fcross(v->vvec, v->hvec, v->vdir); /* compute vert dir */ |
41 |
|
|
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
< |
viewpixel(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 |
|
{ |
178 |
|
|
179 |
|
switch (v->type) { |
180 |
|
case VT_PAR: /* parallel view */ |
181 |
< |
if (zp != NULL) |
177 |
< |
*zp = DOT(disp,v->vdir); |
181 |
> |
ip[2] = DOT(disp,v->vdir); |
182 |
|
break; |
183 |
|
case VT_PER: /* perspective view */ |
184 |
|
d = DOT(disp,v->vdir); |
185 |
< |
if (zp != NULL) { |
186 |
< |
*zp = sqrt(DOT(disp,disp)); |
187 |
< |
if (d < 0.0) |
184 |
< |
*zp = -*zp; |
185 |
< |
} |
186 |
< |
if (d < 0.0) /* fold pyramid */ |
185 |
> |
ip[2] = sqrt(DOT(disp,disp)); |
186 |
> |
if (d < 0.0) { /* fold pyramid */ |
187 |
> |
ip[2] = -ip[2]; |
188 |
|
d = -d; |
189 |
< |
if (d > FTINY) { |
189 |
> |
} else if (d > FTINY) { |
190 |
|
d = 1.0/d; |
191 |
|
disp[0] *= d; |
192 |
|
disp[1] *= d; |
195 |
|
break; |
196 |
|
case VT_HEM: /* hemispherical fisheye */ |
197 |
|
d = normalize(disp); |
198 |
< |
if (zp != NULL) { |
199 |
< |
if (DOT(disp,v->vdir) < 0.0) |
200 |
< |
*zp = -d; |
201 |
< |
else |
201 |
< |
*zp = d; |
202 |
< |
} |
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 |
< |
d = normalize(disp); |
205 |
< |
if (zp != NULL) |
206 |
< |
*zp = d; |
208 |
< |
*xp = 0.5 - v->hoff; |
209 |
< |
*yp = 0.5 - v->voff; |
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 |
< |
*xp += 180.0/v->horiz; |
212 |
< |
*yp += 180.0/v->vert; |
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 |
< |
*xp += DOT(disp,v->hvec)*d*180.0/v->horiz; |
217 |
< |
*yp += DOT(disp,v->vvec)*d*180.0/v->vert; |
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->hvec)/v->hn2 + 0.5 - v->hoff; |
221 |
< |
*yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
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 |
+ |
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,n) if ((av[0][c]&&av[0][c]!=' ') || n>=ac) return(-1) |
278 |
< |
extern double atof(); |
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); |
283 |
|
case 't': /* type */ |
284 |
|
if (!av[0][3] || av[0][3]==' ') |
285 |
|
return(-1); |
286 |
< |
check(4,0); |
286 |
> |
check(4,""); |
287 |
|
v->type = av[0][3]; |
288 |
|
return(0); |
289 |
|
case 'p': /* point */ |
290 |
< |
check(3,3); |
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,3); |
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,3); |
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,1); |
308 |
> |
check(3,"f"); |
309 |
|
v->horiz = atof(av[1]); |
310 |
|
return(1); |
311 |
|
case 'v': /* vertical size */ |
312 |
< |
check(3,1); |
312 |
> |
check(3,"f"); |
313 |
|
v->vert = atof(av[1]); |
314 |
|
return(1); |
315 |
|
case 's': /* shift */ |
316 |
< |
check(3,1); |
316 |
> |
check(3,"f"); |
317 |
|
v->hoff = atof(av[1]); |
318 |
|
return(1); |
319 |
|
case 'l': /* lift */ |
320 |
< |
check(3,1); |
320 |
> |
check(3,"f"); |
321 |
|
v->voff = atof(av[1]); |
322 |
|
return(1); |
323 |
|
default: |
337 |
|
int na; |
338 |
|
int nvopts = 0; |
339 |
|
|
340 |
< |
while (*s == ' ') |
341 |
< |
s++; |
340 |
> |
if (*s != '-') |
341 |
> |
s = sskip(s); |
342 |
|
while (*s) { |
343 |
|
ac = 0; |
344 |
|
do { |
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 |
< |
|
343 |
< |
for (an = altname; *an != NULL; an++) |
344 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
345 |
< |
if (sscanview(hview, s+strlen(*an)) > 0) |
346 |
< |
gothview++; |
347 |
< |
return; |
348 |
< |
} |
413 |
> |
if (isview(s) && sscanview(v->hv, s) > 0) |
414 |
> |
v->ok++; |
415 |
|
} |
416 |
|
|
417 |
|
|
418 |
|
int |
419 |
< |
viewfile(fname, vp, xp, yp) /* get view from file */ |
419 |
> |
viewfile(fname, vp, rp) /* get view from file */ |
420 |
|
char *fname; |
421 |
|
VIEW *vp; |
422 |
< |
int *xp, *yp; |
422 |
> |
RESOLU *rp; |
423 |
|
{ |
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; |
366 |
< |
gothview = 0; |
430 |
> |
mvs.hv = vp; |
431 |
> |
mvs.ok = 0; |
432 |
|
|
433 |
< |
getheader(fp, gethview); |
433 |
> |
getheader(fp, gethview, &mvs); |
434 |
|
|
435 |
< |
if (xp != NULL && yp != NULL |
436 |
< |
&& fgetresolu(xp, yp, fp) == -1) |
372 |
< |
gothview = 0; |
435 |
> |
if (rp != NULL && !fgetsresolu(rp, fp)) |
436 |
> |
mvs.ok = 0; |
437 |
|
|
438 |
|
fclose(fp); |
439 |
|
|
440 |
< |
return(gothview); |
440 |
> |
return(mvs.ok); |
441 |
|
} |