1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 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 |
+ |
#include "paths.h" |
20 |
+ |
|
21 |
|
VIEW stdview = STDVIEW; /* default view parameters */ |
22 |
|
|
23 |
|
|
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
< |
viewpixel(xp, yp, zp, v, p) /* find image location for point */ |
170 |
< |
double *xp, *yp, *zp; |
169 |
> |
viewloc(ip, v, p) /* find image location for point */ |
170 |
> |
FVECT ip; |
171 |
|
register VIEW *v; |
172 |
|
FVECT p; |
173 |
|
{ |
180 |
|
|
181 |
|
switch (v->type) { |
182 |
|
case VT_PAR: /* parallel view */ |
183 |
< |
if (zp != NULL) |
180 |
< |
*zp = DOT(disp,v->vdir); |
183 |
> |
ip[2] = DOT(disp,v->vdir); |
184 |
|
break; |
185 |
|
case VT_PER: /* perspective view */ |
186 |
|
d = DOT(disp,v->vdir); |
187 |
< |
if (zp != NULL) { |
188 |
< |
*zp = sqrt(DOT(disp,disp)); |
189 |
< |
if (d < 0.0) |
187 |
< |
*zp = -*zp; |
188 |
< |
} |
189 |
< |
if (d < 0.0) /* fold pyramid */ |
187 |
> |
ip[2] = sqrt(DOT(disp,disp)); |
188 |
> |
if (d < 0.0) { /* fold pyramid */ |
189 |
> |
ip[2] = -ip[2]; |
190 |
|
d = -d; |
191 |
< |
if (d > FTINY) { |
191 |
> |
} else if (d > FTINY) { |
192 |
|
d = 1.0/d; |
193 |
|
disp[0] *= d; |
194 |
|
disp[1] *= d; |
197 |
|
break; |
198 |
|
case VT_HEM: /* hemispherical fisheye */ |
199 |
|
d = normalize(disp); |
200 |
< |
if (zp != NULL) { |
201 |
< |
if (DOT(disp,v->vdir) < 0.0) |
202 |
< |
*zp = -d; |
203 |
< |
else |
204 |
< |
*zp = d; |
205 |
< |
} |
200 |
> |
if (DOT(disp,v->vdir) < 0.0) |
201 |
> |
ip[2] = -d; |
202 |
> |
else |
203 |
> |
ip[2] = d; |
204 |
|
break; |
205 |
|
case VT_ANG: /* angular fisheye */ |
206 |
< |
d = normalize(disp); |
207 |
< |
if (zp != NULL) |
208 |
< |
*zp = d; |
211 |
< |
*xp = 0.5 - v->hoff; |
212 |
< |
*yp = 0.5 - v->voff; |
206 |
> |
ip[0] = 0.5 - v->hoff; |
207 |
> |
ip[1] = 0.5 - v->voff; |
208 |
> |
ip[2] = normalize(disp); |
209 |
|
d = DOT(disp,v->vdir); |
210 |
|
if (d >= 1.0-FTINY) |
211 |
|
return; |
212 |
|
if (d <= -(1.0-FTINY)) { |
213 |
< |
*xp += 180.0/v->horiz; |
214 |
< |
*yp += 180.0/v->vert; |
213 |
> |
ip[1] += 180.0/v->horiz; |
214 |
> |
ip[2] += 180.0/v->vert; |
215 |
|
return; |
216 |
|
} |
217 |
|
d = acos(d)/PI / sqrt(1.0 - d*d); |
218 |
< |
*xp += DOT(disp,v->hvec)*d*180.0/v->horiz; |
219 |
< |
*yp += DOT(disp,v->vvec)*d*180.0/v->vert; |
218 |
> |
ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz; |
219 |
> |
ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert; |
220 |
|
return; |
221 |
|
} |
222 |
< |
*xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
223 |
< |
*yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
222 |
> |
ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
223 |
> |
ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
+ |
pix2loc(loc, rp, px, py) /* compute image location from pixel pos. */ |
228 |
+ |
FLOAT loc[2]; |
229 |
+ |
register RESOLU *rp; |
230 |
+ |
int px, py; |
231 |
+ |
{ |
232 |
+ |
register int x, y; |
233 |
+ |
|
234 |
+ |
if (rp->or & YMAJOR) { |
235 |
+ |
x = px; |
236 |
+ |
y = py; |
237 |
+ |
} else { |
238 |
+ |
x = py; |
239 |
+ |
y = px; |
240 |
+ |
} |
241 |
+ |
if (rp->or & XDECR) |
242 |
+ |
x = rp->xr-1 - x; |
243 |
+ |
if (rp->or & YDECR) |
244 |
+ |
y = rp->yr-1 - y; |
245 |
+ |
loc[0] = (x+.5)/rp->xr; |
246 |
+ |
loc[1] = (y+.5)/rp->yr; |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
|
250 |
+ |
loc2pix(pp, rp, lx, ly) /* compute pixel pos. from image location */ |
251 |
+ |
int pp[2]; |
252 |
+ |
register RESOLU *rp; |
253 |
+ |
double lx, ly; |
254 |
+ |
{ |
255 |
+ |
register int x, y; |
256 |
+ |
|
257 |
+ |
x = lx * rp->xr; |
258 |
+ |
y = ly * rp->yr; |
259 |
+ |
if (rp->or & XDECR) |
260 |
+ |
x = rp->xr-1 - x; |
261 |
+ |
if (rp->or & YDECR) |
262 |
+ |
y = rp->yr-1 - y; |
263 |
+ |
if (rp->or & YMAJOR) { |
264 |
+ |
pp[0] = x; |
265 |
+ |
pp[1] = y; |
266 |
+ |
} else { |
267 |
+ |
pp[0] = y; |
268 |
+ |
pp[1] = x; |
269 |
+ |
} |
270 |
+ |
} |
271 |
+ |
|
272 |
+ |
|
273 |
|
int |
274 |
|
getviewopt(v, ac, av) /* process view argument */ |
275 |
|
register VIEW *v; |
276 |
|
int ac; |
277 |
|
register char *av[]; |
278 |
|
{ |
279 |
< |
#define check(c,n) if ((av[0][c]&&av[0][c]!=' ') || n>=ac) return(-1) |
280 |
< |
extern double atof(); |
279 |
> |
#define check(c,l) if ((av[0][c]&&av[0][c]!=' ') || \ |
280 |
> |
badarg(ac-1,av+1,l)) return(-1) |
281 |
|
|
282 |
|
if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v') |
283 |
|
return(-1); |
285 |
|
case 't': /* type */ |
286 |
|
if (!av[0][3] || av[0][3]==' ') |
287 |
|
return(-1); |
288 |
< |
check(4,0); |
288 |
> |
check(4,""); |
289 |
|
v->type = av[0][3]; |
290 |
|
return(0); |
291 |
|
case 'p': /* point */ |
292 |
< |
check(3,3); |
292 |
> |
check(3,"fff"); |
293 |
|
v->vp[0] = atof(av[1]); |
294 |
|
v->vp[1] = atof(av[2]); |
295 |
|
v->vp[2] = atof(av[3]); |
296 |
|
return(3); |
297 |
|
case 'd': /* direction */ |
298 |
< |
check(3,3); |
298 |
> |
check(3,"fff"); |
299 |
|
v->vdir[0] = atof(av[1]); |
300 |
|
v->vdir[1] = atof(av[2]); |
301 |
|
v->vdir[2] = atof(av[3]); |
302 |
|
return(3); |
303 |
|
case 'u': /* up */ |
304 |
< |
check(3,3); |
304 |
> |
check(3,"fff"); |
305 |
|
v->vup[0] = atof(av[1]); |
306 |
|
v->vup[1] = atof(av[2]); |
307 |
|
v->vup[2] = atof(av[3]); |
308 |
|
return(3); |
309 |
|
case 'h': /* horizontal size */ |
310 |
< |
check(3,1); |
310 |
> |
check(3,"f"); |
311 |
|
v->horiz = atof(av[1]); |
312 |
|
return(1); |
313 |
|
case 'v': /* vertical size */ |
314 |
< |
check(3,1); |
314 |
> |
check(3,"f"); |
315 |
|
v->vert = atof(av[1]); |
316 |
|
return(1); |
317 |
|
case 's': /* shift */ |
318 |
< |
check(3,1); |
318 |
> |
check(3,"f"); |
319 |
|
v->hoff = atof(av[1]); |
320 |
|
return(1); |
321 |
|
case 'l': /* lift */ |
322 |
< |
check(3,1); |
322 |
> |
check(3,"f"); |
323 |
|
v->voff = atof(av[1]); |
324 |
|
return(1); |
325 |
|
default: |
339 |
|
int na; |
340 |
|
int nvopts = 0; |
341 |
|
|
342 |
< |
while (*s == ' ') |
343 |
< |
s++; |
342 |
> |
if (*s != '-') |
343 |
> |
s = sskip(s); |
344 |
|
while (*s) { |
345 |
|
ac = 0; |
346 |
|
do { |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
static char *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL}; |
377 |
> |
int |
378 |
> |
isview(s) /* is this a view string? */ |
379 |
> |
char *s; |
380 |
> |
{ |
381 |
> |
static char *altname[]={NULL,"rpict","rview","pinterp",VIEWSTR,NULL}; |
382 |
> |
extern char *progname, *rindex(); |
383 |
> |
register char *cp; |
384 |
> |
register char **an; |
385 |
> |
/* add program name to list */ |
386 |
> |
if (altname[0] == NULL) |
387 |
> |
if ((cp = rindex(progname, DIRSEP)) != NULL) |
388 |
> |
altname[0] = cp+1; |
389 |
> |
else |
390 |
> |
altname[0] = progname; |
391 |
> |
/* skip leading path */ |
392 |
> |
cp = s; |
393 |
> |
while (*cp && *cp != ' ') |
394 |
> |
cp++; |
395 |
> |
while (cp > s && cp[-1] != DIRSEP) |
396 |
> |
cp--; |
397 |
> |
for (an = altname; *an != NULL; an++) |
398 |
> |
if (!strncmp(*an, cp, strlen(*an))) |
399 |
> |
return(1); |
400 |
> |
return(0); |
401 |
> |
} |
402 |
|
|
403 |
+ |
|
404 |
|
struct myview { |
405 |
|
VIEW *hv; |
406 |
|
int ok; |
412 |
|
char *s; |
413 |
|
register struct myview *v; |
414 |
|
{ |
415 |
< |
register char **an; |
416 |
< |
|
350 |
< |
for (an = altname; *an != NULL; an++) |
351 |
< |
if (!strncmp(*an, s, strlen(*an))) { |
352 |
< |
if (sscanview(v->hv, s+strlen(*an)) > 0) |
353 |
< |
v->ok++; |
354 |
< |
return; |
355 |
< |
} |
415 |
> |
if (isview(s) && sscanview(v->hv, s) > 0) |
416 |
> |
v->ok++; |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
int |
421 |
< |
viewfile(fname, vp, xp, yp) /* get view from file */ |
421 |
> |
viewfile(fname, vp, rp) /* get view from file */ |
422 |
|
char *fname; |
423 |
|
VIEW *vp; |
424 |
< |
int *xp, *yp; |
424 |
> |
RESOLU *rp; |
425 |
|
{ |
365 |
– |
extern char *progname; |
426 |
|
struct myview mvs; |
427 |
|
FILE *fp; |
428 |
|
|
429 |
|
if ((fp = fopen(fname, "r")) == NULL) |
430 |
|
return(-1); |
431 |
|
|
372 |
– |
altname[0] = progname; |
432 |
|
mvs.hv = vp; |
433 |
|
mvs.ok = 0; |
434 |
|
|
435 |
|
getheader(fp, gethview, &mvs); |
436 |
|
|
437 |
< |
if (xp != NULL && yp != NULL |
379 |
< |
&& fgetresolu(xp, yp, fp) == -1) |
437 |
> |
if (rp != NULL && !fgetsresolu(rp, fp)) |
438 |
|
mvs.ok = 0; |
439 |
|
|
440 |
|
fclose(fp); |