--- ray/src/common/image.c 1991/12/19 14:45:50 2.2 +++ ray/src/common/image.c 1994/12/20 20:15:04 2.7 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -16,6 +16,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "resolu.h" +#include "paths.h" + VIEW stdview = STDVIEW; /* default view parameters */ @@ -26,6 +28,10 @@ register VIEW *v; static char ill_horiz[] = "illegal horizontal view size"; static char ill_vert[] = "illegal vertical view size"; + if (v->vfore < -FTINY || v->vaft < -FTINY || + (v->vaft > FTINY && v->vaft <= v->vfore)) + return("illegal fore/aft clipping plane"); + if (normalize(v->vdir) == 0.0) /* normalize direction */ return("zero view direction"); @@ -105,6 +111,7 @@ int *xp, *yp; /* x and y resolution in (or out if * } +double viewray(orig, direc, v, x, y) /* compute ray origin and direction */ FVECT orig, direc; register VIEW *v; @@ -117,50 +124,55 @@ double x, y; switch(v->type) { case VT_PAR: /* parallel view */ - orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0]; - orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1]; - orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2]; + orig[0] = v->vp[0] + v->vfore*v->vdir[0] + + x*v->hvec[0] + y*v->vvec[0]; + orig[1] = v->vp[1] + v->vfore*v->vdir[1] + + x*v->hvec[1] + y*v->vvec[1]; + orig[2] = v->vp[2] + v->vfore*v->vdir[2] + + x*v->hvec[2] + y*v->vvec[2]; VCOPY(direc, v->vdir); - return(0); + return(v->vaft - v->vfore); case VT_PER: /* perspective view */ - VCOPY(orig, v->vp); direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; - normalize(direc); - return(0); + orig[0] = v->vp[0] + v->vfore*direc[0]; + orig[1] = v->vp[1] + v->vfore*direc[1]; + orig[2] = v->vp[2] + v->vfore*direc[2]; + d = normalize(direc); + return((v->vaft - v->vfore)*d); case VT_HEM: /* hemispherical fisheye */ z = 1.0 - x*x*v->hn2 - y*y*v->vn2; if (z < 0.0) - return(-1); + return(-1.0); z = sqrt(z); - VCOPY(orig, v->vp); direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; - return(0); + orig[0] = v->vp[0] + v->vfore*direc[0]; + orig[1] = v->vp[1] + v->vfore*direc[1]; + orig[2] = v->vp[2] + v->vfore*direc[2]; + return(v->vaft - v->vfore); case VT_ANG: /* angular fisheye */ x *= v->horiz/180.0; y *= v->vert/180.0; d = x*x + y*y; if (d > 1.0) - return(-1); - VCOPY(orig, v->vp); - if (d <= FTINY) { - VCOPY(direc, v->vdir); - return(0); - } + return(-1.0); d = sqrt(d); z = cos(PI*d); - d = sqrt(1 - z*z)/d; + d = d <= FTINY ? PI : sqrt(1 - z*z)/d; x *= d; y *= d; direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; - return(0); + orig[0] = v->vp[0] + v->vfore*direc[0]; + orig[1] = v->vp[1] + v->vfore*direc[1]; + orig[2] = v->vp[2] + v->vfore*direc[2]; + return(v->vaft - v->vfore); } - return(-1); + return(-1.0); } @@ -178,7 +190,7 @@ FVECT p; switch (v->type) { case VT_PAR: /* parallel view */ - ip[2] = DOT(disp,v->vdir); + ip[2] = DOT(disp,v->vdir) - v->vfore; break; case VT_PER: /* perspective view */ d = DOT(disp,v->vdir); @@ -186,12 +198,14 @@ FVECT p; if (d < 0.0) { /* fold pyramid */ ip[2] = -ip[2]; d = -d; - } else if (d > FTINY) { + } + if (d > FTINY) { d = 1.0/d; disp[0] *= d; disp[1] *= d; disp[2] *= d; } + ip[2] *= (1.0 - v->vfore*d); break; case VT_HEM: /* hemispherical fisheye */ d = normalize(disp); @@ -199,17 +213,18 @@ FVECT p; ip[2] = -d; else ip[2] = d; + ip[2] -= v->vfore; break; case VT_ANG: /* angular fisheye */ ip[0] = 0.5 - v->hoff; ip[1] = 0.5 - v->voff; - ip[2] = normalize(disp); + ip[2] = normalize(disp) - v->vfore; d = DOT(disp,v->vdir); if (d >= 1.0-FTINY) return; if (d <= -(1.0-FTINY)) { - ip[1] += 180.0/v->horiz; - ip[2] += 180.0/v->vert; + ip[0] += 180.0/v->horiz; + ip[1] += 180.0/v->vert; return; } d = acos(d)/PI / sqrt(1.0 - d*d); @@ -312,6 +327,14 @@ register char *av[]; check(3,"f"); v->vert = atof(av[1]); return(1); + case 'o': /* fore clipping plane */ + check(3,"f"); + v->vfore = atof(av[1]); + return(1); + case 'a': /* aft clipping plane */ + check(3,"f"); + v->vaft = atof(av[1]); + return(1); case 's': /* shift */ check(3,"f"); v->hoff = atof(av[1]); @@ -337,8 +360,8 @@ register char *s; int na; int nvopts = 0; - while (*s == ' ') - s++; + if (*s != '-') + s = sskip(s); while (*s) { ac = 0; do { @@ -368,12 +391,40 @@ FILE *fp; fprintf(fp, " -vd %.6g %.6g %.6g", vp->vdir[0], vp->vdir[1], vp->vdir[2]); fprintf(fp, " -vu %.6g %.6g %.6g", vp->vup[0], vp->vup[1], vp->vup[2]); fprintf(fp, " -vh %.6g -vv %.6g", vp->horiz, vp->vert); + fprintf(fp, " -vo %.6g -va %.6g", vp->vfore, vp->vaft); fprintf(fp, " -vs %.6g -vl %.6g", vp->hoff, vp->voff); } -static char *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL}; +int +isview(s) /* is this a view string? */ +char *s; +{ + static char *altname[]={NULL,VIEWSTR,"rpict","rview","pinterp",NULL}; + extern char *progname; + register char *cp; + register char **an; + /* add program name to list */ + if (altname[0] == NULL) { + for (cp = progname; *cp; cp++) + ; + while (cp > progname && !ISDIRSEP(cp[-1])) + cp--; + altname[0] = cp; + } + /* skip leading path */ + cp = s; + while (*cp && *cp != ' ') + cp++; + while (cp > s && !ISDIRSEP(cp[-1])) + cp--; + for (an = altname; *an != NULL; an++) + if (!strncmp(*an, cp, strlen(*an))) + return(1); + return(0); +} + struct myview { VIEW *hv; int ok; @@ -385,14 +436,8 @@ gethview(s, v) /* get view from header */ char *s; register struct myview *v; { - register char **an; - - for (an = altname; *an != NULL; an++) - if (!strncmp(*an, s, strlen(*an))) { - if (sscanview(v->hv, s+strlen(*an)) > 0) - v->ok++; - return; - } + if (isview(s) && sscanview(v->hv, s) > 0) + v->ok++; } @@ -402,14 +447,12 @@ char *fname; VIEW *vp; RESOLU *rp; { - extern char *progname; struct myview mvs; FILE *fp; if ((fp = fopen(fname, "r")) == NULL) return(-1); - altname[0] = progname; mvs.hv = vp; mvs.ok = 0;