--- ray/src/util/findglare.c 1991/04/18 15:18:22 1.18 +++ ray/src/util/findglare.c 1992/12/07 09:13:58 2.4 @@ -12,11 +12,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include "glare.h" -#define FEQ(a,b) ((a)-(b)<=FTINY&&(a)-(b)<=FTINY) +#define FEQ(a,b) ((a)-(b)<=FTINY&&(b)-(a)<=FTINY) #define VEQ(v1,v2) (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \ &&FEQ((v1)[2],(v2)[2])) -char *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"}; +char *rtargv[32] = {"rtrace", "-h-", "-ov", "-fff"}; int rtargc = 4; VIEW ourview = STDVIEW; /* our view */ @@ -36,7 +36,6 @@ ANGLE glarang[180] = {AEND}; /* glare calculation ang int nglarangs = 0; double maxtheta; /* maximum angle (in radians) */ int hsize; /* horizontal size */ -int hlim; /* central limit of horizontal */ struct illum *indirect; /* array of indirect illuminances */ @@ -76,7 +75,7 @@ char *argv[]; } if (argv[i][2] != 'f') goto userr; - rval = viewfile(argv[++i], &ourview, 0, 0); + rval = viewfile(argv[++i], &ourview, NULL); if (rval < 0) { fprintf(stderr, "%s: cannot open view file \"%s\"\n", @@ -106,10 +105,19 @@ char *argv[]; combine = !combine; break; case 'd': + if (argv[i][2] == 'v') { + rtargv[rtargc++] = argv[i]; + break; + } + /* FALL THROUGH */ case 'l': + case 's': rtargv[rtargc++] = argv[i]; rtargv[rtargc++] = argv[++i]; break; + case 'w': + rtargv[rtargc++] = argv[i]; + break; case 'a': rtargv[rtargc++] = argv[i]; if (argv[i][2] == 'v') { @@ -131,7 +139,7 @@ char *argv[]; } /* get view */ if (picture != NULL) { - rval = viewfile(picture, &pictview, 0, 0); + rval = viewfile(picture, &pictview, NULL); if (rval < 0) { fprintf(stderr, "%s: cannot open picture file \"%s\"\n", progname, picture); @@ -191,7 +199,7 @@ char *argv[]; fputs(VIEWSTR, stdout); fprintview(&ourview, stdout); printf("\n"); - fputformat("ASCII", stdout); + fputformat("ascii", stdout); printf("\n"); printsources(); /* print glare sources */ printillum(); /* print illuminances */ @@ -204,6 +212,23 @@ userr: } +int +angcmp(ap1, ap2) /* compare two angles */ +ANGLE *ap1, *ap2; +{ + register int a1, a2; + + a1 = *ap1; + a2 = *ap2; + if (a1 == a2) { + fprintf(stderr, "%s: duplicate glare angle (%d)\n", + progname, a1); + exit(1); + } + return(a1-a2); +} + + init() /* initialize global variables */ { double d; @@ -215,8 +240,9 @@ init() /* initialize global variables */ /* set direction vectors */ for (i = 0; glarang[i] != AEND; i++) ; - if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { - fprintf(stderr, "%s: glare angles must be between 1 and 179\n", + qsort(glarang, i, sizeof(ANGLE), angcmp); + if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) { + fprintf(stderr, "%s: glare angles must be between 1 and 180\n", progname); exit(1); } @@ -227,8 +253,7 @@ init() /* initialize global variables */ maxtheta = (PI/180.)*glarang[nglarangs-1]; else maxtheta = 0.0; - hlim = sampdens*maxtheta; - hsize = hlim + sampdens - 1; + hsize = hlim(0) + sampdens - 1; if (hsize > (int)(PI*sampdens)) hsize = PI*sampdens; indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); @@ -289,46 +314,59 @@ cleanup() /* close files, wait for children */ if (octree != NULL) done_rtrace(); if (npixinvw < 100*npixmiss) - fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", - progname, 100L*npixmiss/npixinvw); + fprintf(stderr, "%s: warning -- missing %d%% of samples\n", + progname, (int)(100L*npixmiss/npixinvw)); } -compdir(vd, x, y, se) /* compute direction for x,y */ +compdir(vd, x, y) /* compute direction for x,y */ FVECT vd; int x, y; -SPANERR *se; { + int hl; FVECT org; /* dummy variable */ - if (x <= -hlim) /* left region */ + hl = hlim(y); + if (x <= -hl) { /* left region */ + if (x <= -hl-sampdens) + return(-1); return(viewray(org, vd, &leftview, - (double)(x+hlim)/(2*sampdens)+.5, + (double)(x+hl)/(2*sampdens)+.5, (double)y/(2*sampdens)+.5)); - if (x >= hlim) /* right region */ + } + if (x >= hl) { /* right region */ + if (x >= hl+sampdens) + return(-1); return(viewray(org, vd, &rightview, - (double)(x-hlim)/(2*sampdens)+.5, + (double)(x-hl)/(2*sampdens)+.5, (double)y/(2*sampdens)+.5)); - /* central region */ - if (se != NULL) { /* avoid over-counting of poles */ - se->err += se->prob; - if (se->err <= 0.5) - return(-1); - se->err -= 1.0; } + /* central region */ if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) return(-1); - spinvector(vd, vd, ourview.vup, h_theta(x)); + spinvector(vd, vd, ourview.vup, h_theta(x,y)); return(0); } -setspanerr(se, y) /* initialize span error at y */ -register SPANERR *se; -int y; +double +pixsize(x, y) /* return the solid angle of pixel at (x,y) */ +int x, y; { - se->err = 0.0; - se->prob = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); + register int hl, xo; + double disc; + + hl = hlim(y); + if (x < -hl) + xo = x+hl; + else if (x > hl) + xo = x-hl; + else + xo = 0; + disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens); + if (disc <= FTINY) + return(0.); + return(1./(sampdens*sampdens*sqrt(disc))); }