ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/findglare.c
(Generate patch)

Comparing ray/src/util/findglare.c (file contents):
Revision 1.2 by greg, Mon Mar 18 14:32:12 1991 UTC vs.
Revision 1.15 by greg, Fri Apr 5 14:26:47 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19   char    *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"};
20   int     rtargc = 4;
21  
22 < VIEW    ourview;                        /* our view */
22 > VIEW    ourview = STDVIEW;              /* our view */
23   VIEW    pictview = STDVIEW;             /* picture view */
24   VIEW    leftview, rightview;            /* leftmost and rightmost views */
25  
# Line 29 | Line 29 | char   *octree = NULL;                 /* octree file name */
29   int     verbose = 0;                    /* verbose reporting */
30   char    *progname;                      /* global argv[0] */
31  
32 + double  threshold = 0.;                 /* glare threshold */
33 +
34 + int     sampdens = SAMPDENS;            /* sample density */
35   ANGLE   glarang[180] = {AEND};          /* glare calculation angles */
36   int     nglarangs = 0;
37   double  maxtheta;                       /* maximum angle (in radians) */
# Line 37 | Line 40 | int    hlim;                           /* central limit of horizontal */
40  
41   struct illum    *indirect;              /* array of indirect illuminances */
42  
43 + long    npixinvw;                       /* number of pixels in view */
44 + long    npixmiss;                       /* number of pixels missed */
45  
46 +
47   main(argc, argv)
48   int     argc;
49   char    *argv[];
# Line 56 | Line 62 | char   *argv[];
62                          continue;
63                  }
64                  switch (argv[i][1]) {
65 +                case 't':
66 +                        threshold = atof(argv[++i]);
67 +                        break;
68 +                case 'r':
69 +                        sampdens = atoi(argv[++i])/2;
70 +                        break;
71                  case 'v':
72                          if (argv[i][2] == '\0') {
73                                  verbose++;
# Line 164 | Line 176 | char   *argv[];
176                  exit(1);
177          }
178          init();                                 /* initialize program */
179 <        comp_thresh();                          /* compute glare threshold */
179 >        if (threshold <= FTINY)
180 >                comp_thresh();                  /* compute glare threshold */
181          analyze();                              /* analyze view */
182          cleanup();                              /* tidy up */
183                                                  /* print header */
# Line 194 | Line 207 | init()                         /* initialize global variables */
207                                                  /* set direction vectors */
208          for (i = 0; glarang[i] != AEND; i++)
209                  ;
210 <        if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) {
210 >        if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) {
211                  fprintf(stderr, "%s: glare angles must be between 1 and 179\n",
212                                  progname);
213                  exit(1);
214          }
215          nglarangs = i;
216          /* nglardirs = 2*nglarangs + 1; */
217 <        /* vsize = SAMPDENS; */
217 >        /* vsize = sampdens - 1; */
218          if (nglarangs > 0)
219                  maxtheta = (PI/180.)*glarang[nglarangs-1];
220          else
221                  maxtheta = 0.0;
222 <        hlim = SAMPDENS*maxtheta;
223 <        hsize = SAMPDENS + hlim;
224 <        if (hsize > (int)(PI*SAMPDENS))
225 <                hsize = PI*SAMPDENS;
222 >        hlim = sampdens*maxtheta;
223 >        hsize = hlim + sampdens - 1;
224 >        if (hsize > (int)(PI*sampdens))
225 >                hsize = PI*sampdens;
226          indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum));
227          if (indirect == NULL)
228                  memerr("indirect illuminances");
229 +        npixinvw = npixmiss = 0L;
230          copystruct(&leftview, &ourview);
231          copystruct(&rightview, &ourview);
232 <        spinvector(leftview.vdir, ourview.vdir, ourview.vup, -maxtheta);
233 <        spinvector(rightview.vdir, ourview.vdir, ourview.vup, maxtheta);
232 >        spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta);
233 >        spinvector(rightview.vdir, ourview.vdir, ourview.vup, -maxtheta);
234          setview(&leftview);
235          setview(&rightview);
236          indirect[nglarangs].lcos =
237          indirect[nglarangs].rcos = cos(maxtheta);
238 <        indirect[nglarangs].lsin =
239 <        -(indirect[nglarangs].rsin = sin(maxtheta));
238 >        indirect[nglarangs].rsin =
239 >        -(indirect[nglarangs].lsin = sin(maxtheta));
240          indirect[nglarangs].theta = 0.0;
241          for (i = 0; i < nglarangs; i++) {
242                  d = (glarang[nglarangs-1] - glarang[i])*(PI/180.);
243                  indirect[nglarangs-i-1].lcos =
244                  indirect[nglarangs+i+1].rcos = cos(d);
245 <                indirect[nglarangs-i-1].lsin =
246 <                -(indirect[nglarangs+i+1].rsin = sin(d));
245 >                indirect[nglarangs+i+1].rsin =
246 >                -(indirect[nglarangs-i-1].lsin = sin(d));
247                  d = (glarang[nglarangs-1] + glarang[i])*(PI/180.);
248                  indirect[nglarangs-i-1].rcos =
249                  indirect[nglarangs+i+1].lcos = cos(d);
250 <                indirect[nglarangs+i+1].lsin =
251 <                -(indirect[nglarangs-i-1].rsin = sin(d));
252 <                indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i];
253 <                indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i];
250 >                indirect[nglarangs-i-1].rsin =
251 >                -(indirect[nglarangs+i+1].lsin = sin(d));
252 >                indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i];
253 >                indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i];
254          }
255                                                  /* open picture */
256          if (picture != NULL) {
# Line 266 | Line 280 | cleanup()                              /* close files, wait for children */
280                  close_pict();
281          if (octree != NULL)
282                  done_rtrace();
283 +        if (npixinvw < 100*npixmiss)
284 +                fprintf(stderr, "%s: warning -- missing %ld%% of samples\n",
285 +                                progname, 100L*npixmiss/npixinvw);
286   }
287  
288  
# Line 273 | Line 290 | compdir(vd, x, y)                      /* compute direction for x,y */
290   FVECT   vd;
291   int     x, y;
292   {
293 +        static int      cury = 10000;
294 +        static double   err, cmpval;
295 +        long    t;
296          FVECT   org;                    /* dummy variable */
297  
298          if (x <= -hlim)                 /* left region */
299                  return(viewray(org, vd, &leftview,
300 <                                (x+hlim)/(2.*SAMPDENS)+.5,
301 <                                y/(2.*SAMPDENS)+.5));
300 >                                (double)(x+hlim)/(2*sampdens)+.5,
301 >                                (double)y/(2*sampdens)+.5));
302          if (x >= hlim)                  /* right region */
303                  return(viewray(org, vd, &rightview,
304 <                                (x-hlim)/(2.*SAMPDENS)+.5,
305 <                                y/(2.*SAMPDENS)+.5));
306 <                                                /* central region */
307 <        if (viewray(org, vd, &ourview, .5, y/(2.*SAMPDENS)+.5) < 0)
304 >                                (double)(x-hlim)/(2*sampdens)+.5,
305 >                                (double)y/(2*sampdens)+.5));
306 >                                        /* central region */
307 >                                /* avoid over-counting of poles */
308 >        if (cury != y) {
309 >                err = 0.0;
310 >                cmpval = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize));
311 >                cury = y;
312 >        }
313 >        err += cmpval;
314 >        if (err <= 0.5)
315                  return(-1);
316 +        err -= 1.0;
317 +        if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0)
318 +                return(-1);
319          spinvector(vd, vd, ourview.vup, h_theta(x));
320          return(0);
321   }
322  
323  
294 spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
295 FVECT  vres, vorig, vnorm;
296 double  theta;
297 {
298        extern double  sin(), cos();
299        double  sint, cost, dotp;
300        FVECT  vperp;
301        register int  i;
302        
303        sint = sin(theta);
304        cost = cos(theta);
305        dotp = DOT(vorig, vnorm);
306        fcross(vperp, vnorm, vorig);
307        for (i = 0; i < 3; i++)
308                vres[i] = vnorm[i]*dotp*(1.-cost) +
309                                vorig[i]*cost + vperp[i]*sint;
310 }
311
312
324   memerr(s)                       /* malloc failure */
325   char    *s;
326   {
327 <        fprintf(stderr, "%s: out of memory for %s\n", s);
327 >        fprintf(stderr, "%s: out of memory for %s\n", progname, s);
328          exit(1);
329   }
330  
# Line 337 | Line 348 | printillum()                   /* print out indirect illuminances */
348  
349          printf("BEGIN indirect illuminance\n");
350          for (i = 0; i < nglardirs; i++)
351 <                printf("\t%f\t%f\n", (180.0/PI)*indirect[i].theta,
352 <                                PI * indirect[i].sum / (double)indirect[i].n);
351 >                if (indirect[i].n > FTINY)
352 >                        printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta,
353 >                                        PI * indirect[i].sum / indirect[i].n);
354          printf("END indirect illuminance\n");
355   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines