--- ray/src/common/image.c 1995/08/24 11:55:03 2.10 +++ ray/src/common/image.c 1998/10/27 08:44:29 2.14 @@ -1,4 +1,4 @@ -/* Copyright (c) 1994 Regents of the University of California */ +/* Copyright (c) 1996 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -6,8 +6,6 @@ static char SCCSid[] = "$SunId$ LBL"; /* * image.c - routines for image generation. - * - * 10/17/85 */ #include "standard.h" @@ -18,6 +16,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include "paths.h" +#define FEQ(x,y) (fabs((x)-(y)) <= FTINY) +#define VEQ(v,w) (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \ + && FEQ((v)[2],(w)[2])) + VIEW stdview = STDVIEW; /* default view parameters */ @@ -203,7 +205,7 @@ FVECT ip; register VIEW *v; FVECT p; { - double d; + double d, d2; FVECT disp; disp[0] = p[0] - v->vp[0]; @@ -216,7 +218,7 @@ FVECT p; break; case VT_PER: /* perspective view */ d = DOT(disp,v->vdir); - ip[2] = sqrt(DOT(disp,disp)); + ip[2] = VLEN(disp); if (d < 0.0) { /* fold pyramid */ ip[2] = -ip[2]; d = -d; @@ -238,15 +240,14 @@ FVECT p; ip[2] -= v->vfore; break; case VT_CYL: /* cylindrical panorama */ - ip[2] = DOT(disp,v->vdir); d = DOT(disp,v->hvec); - ip[0] = 180.0/PI * atan2(d,ip[2]) / v->horiz + 0.5 - v->hoff; - ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; + d2 = DOT(disp,v->vdir); + ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff; + d = 1.0/sqrt(d*d + d2*d2); + ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff; + ip[2] = VLEN(disp); if (v->vfore > FTINY) - ip[2] = sqrt(DOT(disp,disp)) * - (1.0 - v->vfore/sqrt(d*d + ip[2]*ip[2])); - else - ip[2] = sqrt(DOT(disp,disp)); + ip[2] *= (1.0 - v->vfore*d); return; case VT_ANG: /* angular fisheye */ ip[0] = 0.5 - v->hoff; @@ -393,7 +394,7 @@ register char *s; int nvopts = 0; if (*s != '-') - s = sskip(s); + s = sskip2(s,1); while (*s) { ac = 0; do { @@ -428,6 +429,60 @@ FILE *fp; } +char * +viewopt(vp) /* translate to minimal view string */ +register VIEW *vp; +{ + static char vwstr[128]; + register char *cp = vwstr; + + if (vp->type != stdview.type) { + sprintf(cp, " -vt%c", vp->type); + cp += strlen(cp); + } + if (!VEQ(vp->vp,stdview.vp)) { + sprintf(cp, " -vp %.6g %.6g %.6g", + vp->vp[0], vp->vp[1], vp->vp[2]); + cp += strlen(cp); + } + if (!VEQ(vp->vdir,stdview.vdir)) { + sprintf(cp, " -vd %.6g %.6g %.6g", + vp->vdir[0], vp->vdir[1], vp->vdir[2]); + cp += strlen(cp); + } + if (!VEQ(vp->vup,stdview.vup)) { + sprintf(cp, " -vu %.6g %.6g %.6g", + vp->vup[0], vp->vup[1], vp->vup[2]); + cp += strlen(cp); + } + if (!FEQ(vp->horiz,stdview.horiz)) { + sprintf(cp, " -vh %.6g", vp->horiz); + cp += strlen(cp); + } + if (!FEQ(vp->vert,stdview.vert)) { + sprintf(cp, " -vv %.6g", vp->vert); + cp += strlen(cp); + } + if (!FEQ(vp->vfore,stdview.vfore)) { + sprintf(cp, " -vo %.6g", vp->vfore); + cp += strlen(cp); + } + if (!FEQ(vp->vaft,stdview.vaft)) { + sprintf(cp, " -va %.6g", vp->vaft); + cp += strlen(cp); + } + if (!FEQ(vp->hoff,stdview.hoff)) { + sprintf(cp, " -vs %.6g", vp->hoff); + cp += strlen(cp); + } + if (!FEQ(vp->voff,stdview.voff)) { + sprintf(cp, " -vl %.6g", vp->voff); + cp += strlen(cp); + } + return(vwstr); +} + + int isview(s) /* is this a view string? */ char *s; @@ -463,13 +518,14 @@ struct myview { }; -static +static int gethview(s, v) /* get view from header */ char *s; register struct myview *v; { if (isview(s) && sscanview(v->hv, s) > 0) v->ok++; + return(0); }