--- ray/src/util/findglare.c 1991/03/18 16:21:09 1.4 +++ ray/src/util/findglare.c 1991/04/05 14:26:47 1.15 @@ -19,7 +19,7 @@ static char SCCSid[] = "$SunId$ LBL"; char *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"}; int rtargc = 4; -VIEW ourview; /* our view */ +VIEW ourview = STDVIEW; /* our view */ VIEW pictview = STDVIEW; /* picture view */ VIEW leftview, rightview; /* leftmost and rightmost views */ @@ -29,6 +29,8 @@ char *octree = NULL; /* octree file name */ int verbose = 0; /* verbose reporting */ char *progname; /* global argv[0] */ +double threshold = 0.; /* glare threshold */ + int sampdens = SAMPDENS; /* sample density */ ANGLE glarang[180] = {AEND}; /* glare calculation angles */ int nglarangs = 0; @@ -38,7 +40,10 @@ int hlim; /* central limit of horizontal */ struct illum *indirect; /* array of indirect illuminances */ +long npixinvw; /* number of pixels in view */ +long npixmiss; /* number of pixels missed */ + main(argc, argv) int argc; char *argv[]; @@ -57,6 +62,9 @@ char *argv[]; continue; } switch (argv[i][1]) { + case 't': + threshold = atof(argv[++i]); + break; case 'r': sampdens = atoi(argv[++i])/2; break; @@ -168,7 +176,8 @@ char *argv[]; exit(1); } init(); /* initialize program */ - comp_thresh(); /* compute glare threshold */ + if (threshold <= FTINY) + comp_thresh(); /* compute glare threshold */ analyze(); /* analyze view */ cleanup(); /* tidy up */ /* print header */ @@ -198,25 +207,26 @@ init() /* initialize global variables */ /* set direction vectors */ for (i = 0; glarang[i] != AEND; i++) ; - if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) { + if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { fprintf(stderr, "%s: glare angles must be between 1 and 179\n", progname); exit(1); } nglarangs = i; /* nglardirs = 2*nglarangs + 1; */ - /* vsize = sampdens; */ + /* vsize = sampdens - 1; */ if (nglarangs > 0) maxtheta = (PI/180.)*glarang[nglarangs-1]; else maxtheta = 0.0; hlim = sampdens*maxtheta; - hsize = sampdens + hlim; + hsize = hlim + sampdens - 1; if (hsize > (int)(PI*sampdens)) hsize = PI*sampdens; indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); if (indirect == NULL) memerr("indirect illuminances"); + npixinvw = npixmiss = 0L; copystruct(&leftview, &ourview); copystruct(&rightview, &ourview); spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta); @@ -225,22 +235,22 @@ init() /* initialize global variables */ setview(&rightview); indirect[nglarangs].lcos = indirect[nglarangs].rcos = cos(maxtheta); - indirect[nglarangs].lsin = - -(indirect[nglarangs].rsin = sin(maxtheta)); + indirect[nglarangs].rsin = + -(indirect[nglarangs].lsin = sin(maxtheta)); indirect[nglarangs].theta = 0.0; for (i = 0; i < nglarangs; i++) { d = (glarang[nglarangs-1] - glarang[i])*(PI/180.); indirect[nglarangs-i-1].lcos = indirect[nglarangs+i+1].rcos = cos(d); - indirect[nglarangs-i-1].lsin = - -(indirect[nglarangs+i+1].rsin = sin(d)); + indirect[nglarangs+i+1].rsin = + -(indirect[nglarangs-i-1].lsin = sin(d)); d = (glarang[nglarangs-1] + glarang[i])*(PI/180.); indirect[nglarangs-i-1].rcos = indirect[nglarangs+i+1].lcos = cos(d); - indirect[nglarangs+i+1].lsin = - -(indirect[nglarangs-i-1].rsin = sin(d)); - indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i]; - indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i]; + indirect[nglarangs-i-1].rsin = + -(indirect[nglarangs+i+1].lsin = sin(d)); + indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i]; + indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i]; } /* open picture */ if (picture != NULL) { @@ -270,6 +280,9 @@ cleanup() /* close files, wait for children */ close_pict(); if (octree != NULL) done_rtrace(); + if (npixinvw < 100*npixmiss) + fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", + progname, 100L*npixmiss/npixinvw); } @@ -277,47 +290,41 @@ compdir(vd, x, y) /* compute direction for x,y */ FVECT vd; int x, y; { + static int cury = 10000; + static double err, cmpval; + long t; FVECT org; /* dummy variable */ if (x <= -hlim) /* left region */ return(viewray(org, vd, &leftview, - (x+hlim)/(2.*sampdens)+.5, - y/(2.*sampdens)+.5)); + (double)(x+hlim)/(2*sampdens)+.5, + (double)y/(2*sampdens)+.5)); if (x >= hlim) /* right region */ return(viewray(org, vd, &rightview, - (x-hlim)/(2.*sampdens)+.5, - y/(2.*sampdens)+.5)); - /* central region */ - if (viewray(org, vd, &ourview, .5, y/(2.*sampdens)+.5) < 0) + (double)(x-hlim)/(2*sampdens)+.5, + (double)y/(2*sampdens)+.5)); + /* central region */ + /* avoid over-counting of poles */ + if (cury != y) { + err = 0.0; + cmpval = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); + cury = y; + } + err += cmpval; + if (err <= 0.5) return(-1); + err -= 1.0; + if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) + return(-1); spinvector(vd, vd, ourview.vup, h_theta(x)); return(0); } -spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ -FVECT vres, vorig, vnorm; -double theta; -{ - extern double sin(), cos(); - double sint, cost, dotp; - FVECT vperp; - register int i; - - sint = sin(theta); - cost = cos(theta); - dotp = DOT(vorig, vnorm); - fcross(vperp, vnorm, vorig); - for (i = 0; i < 3; i++) - vres[i] = vnorm[i]*dotp*(1.-cost) + - vorig[i]*cost + vperp[i]*sint; -} - - memerr(s) /* malloc failure */ char *s; { - fprintf(stderr, "%s: out of memory for %s\n", s); + fprintf(stderr, "%s: out of memory for %s\n", progname, s); exit(1); } @@ -341,7 +348,8 @@ printillum() /* print out indirect illuminances */ printf("BEGIN indirect illuminance\n"); for (i = 0; i < nglardirs; i++) - printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, - PI * indirect[i].sum / (double)indirect[i].n); + if (indirect[i].n > FTINY) + printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, + PI * indirect[i].sum / indirect[i].n); printf("END indirect illuminance\n"); }