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.4 by greg, Mon Mar 18 16:21:09 1991 UTC vs.
Revision 1.23 by greg, Wed May 1 16:14:13 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) */
38   int     hsize;                          /* horizontal size */
37 int     hlim;                           /* central limit of horizontal */
39  
40   struct illum    *indirect;              /* array of indirect illuminances */
41  
42 + long    npixinvw;                       /* number of pixels in view */
43 + long    npixmiss;                       /* number of pixels missed */
44  
45 +
46   main(argc, argv)
47   int     argc;
48   char    *argv[];
49   {
50 +        int     combine = 1;
51          int     gotview = 0;
52          int     rval, i;
53          char    *err;
# Line 57 | 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;
# Line 93 | Line 101 | char   *argv[];
101                  case 'p':
102                          picture = argv[++i];
103                          break;
104 +                case 'c':
105 +                        combine = !combine;
106 +                        break;
107                  case 'd':
108                  case 'l':
109                          rtargv[rtargc++] = argv[i];
# Line 168 | Line 179 | char   *argv[];
179                  exit(1);
180          }
181          init();                                 /* initialize program */
182 <        comp_thresh();                          /* compute glare threshold */
182 >        if (threshold <= FTINY)
183 >                comp_thresh();                  /* compute glare threshold */
184          analyze();                              /* analyze view */
185 +        if (combine)
186 +                absorb_specks();                /* eliminate tiny sources */
187          cleanup();                              /* tidy up */
188                                                  /* print header */
189          printargs(argc, argv, stdout);
190          fputs(VIEWSTR, stdout);
191          fprintview(&ourview, stdout);
192 <        printf("\n\n");
192 >        printf("\n");
193 >        fputformat("ascii", stdout);
194 >        printf("\n");
195          printsources();                         /* print glare sources */
196          printillum();                           /* print illuminances */
197          exit(0);
# Line 187 | Line 203 | userr:
203   }
204  
205  
206 + int
207 + angcmp(ap1, ap2)                /* compare two angles */
208 + ANGLE   *ap1, *ap2;
209 + {
210 +        register int    a1, a2;
211 +
212 +        a1 = *ap1;
213 +        a2 = *ap2;
214 +        if (a1 == a2) {
215 +                fprintf(stderr, "%s: duplicate glare angle (%d)\n",
216 +                                progname, a1);
217 +                exit(1);
218 +        }
219 +        return(a1-a2);
220 + }
221 +
222 +
223   init()                          /* initialize global variables */
224   {
225          double  d;
# Line 198 | Line 231 | init()                         /* initialize global variables */
231                                                  /* set direction vectors */
232          for (i = 0; glarang[i] != AEND; i++)
233                  ;
234 <        if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) {
235 <                fprintf(stderr, "%s: glare angles must be between 1 and 179\n",
234 >        qsort(glarang, i, sizeof(ANGLE), angcmp);
235 >        if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) {
236 >                fprintf(stderr, "%s: glare angles must be between 1 and 180\n",
237                                  progname);
238                  exit(1);
239          }
240          nglarangs = i;
241          /* nglardirs = 2*nglarangs + 1; */
242 <        /* vsize = sampdens; */
242 >        /* vsize = sampdens - 1; */
243          if (nglarangs > 0)
244                  maxtheta = (PI/180.)*glarang[nglarangs-1];
245          else
246                  maxtheta = 0.0;
247 <        hlim = sampdens*maxtheta;
214 <        hsize = sampdens + hlim;
247 >        hsize = hlim(0) + sampdens - 1;
248          if (hsize > (int)(PI*sampdens))
249                  hsize = PI*sampdens;
250          indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum));
251          if (indirect == NULL)
252                  memerr("indirect illuminances");
253 +        npixinvw = npixmiss = 0L;
254          copystruct(&leftview, &ourview);
255          copystruct(&rightview, &ourview);
256          spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta);
# Line 225 | Line 259 | init()                         /* initialize global variables */
259          setview(&rightview);
260          indirect[nglarangs].lcos =
261          indirect[nglarangs].rcos = cos(maxtheta);
262 <        indirect[nglarangs].lsin =
263 <        -(indirect[nglarangs].rsin = sin(maxtheta));
262 >        indirect[nglarangs].rsin =
263 >        -(indirect[nglarangs].lsin = sin(maxtheta));
264          indirect[nglarangs].theta = 0.0;
265          for (i = 0; i < nglarangs; i++) {
266                  d = (glarang[nglarangs-1] - glarang[i])*(PI/180.);
267                  indirect[nglarangs-i-1].lcos =
268                  indirect[nglarangs+i+1].rcos = cos(d);
269 <                indirect[nglarangs-i-1].lsin =
270 <                -(indirect[nglarangs+i+1].rsin = sin(d));
269 >                indirect[nglarangs+i+1].rsin =
270 >                -(indirect[nglarangs-i-1].lsin = sin(d));
271                  d = (glarang[nglarangs-1] + glarang[i])*(PI/180.);
272                  indirect[nglarangs-i-1].rcos =
273                  indirect[nglarangs+i+1].lcos = cos(d);
274 <                indirect[nglarangs+i+1].lsin =
275 <                -(indirect[nglarangs-i-1].rsin = sin(d));
276 <                indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i];
277 <                indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i];
274 >                indirect[nglarangs-i-1].rsin =
275 >                -(indirect[nglarangs+i+1].lsin = sin(d));
276 >                indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i];
277 >                indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i];
278          }
279                                                  /* open picture */
280          if (picture != NULL) {
# Line 265 | Line 299 | init()                         /* initialize global variables */
299   cleanup()                               /* close files, wait for children */
300   {
301          if (verbose)
302 <                fprintf(stderr, "%s: cleaning up...\n", progname);
302 >                fprintf(stderr, "%s: cleaning up...        \n", progname);
303          if (picture != NULL)
304                  close_pict();
305          if (octree != NULL)
306                  done_rtrace();
307 +        if (npixinvw < 100*npixmiss)
308 +                fprintf(stderr, "%s: warning -- missing %ld%% of samples\n",
309 +                                progname, 100L*npixmiss/npixinvw);
310   }
311  
312  
# Line 277 | Line 314 | compdir(vd, x, y)                      /* compute direction for x,y */
314   FVECT   vd;
315   int     x, y;
316   {
317 +        int     hl;
318          FVECT   org;                    /* dummy variable */
319  
320 <        if (x <= -hlim)                 /* left region */
320 >        hl = hlim(y);
321 >        if (x <= -hl) {                 /* left region */
322 >                if (x <= -hl-sampdens)
323 >                        return(-1);
324                  return(viewray(org, vd, &leftview,
325 <                                (x+hlim)/(2.*sampdens)+.5,
326 <                                y/(2.*sampdens)+.5));
327 <        if (x >= hlim)                  /* right region */
325 >                                (double)(x+hl)/(2*sampdens)+.5,
326 >                                (double)y/(2*sampdens)+.5));
327 >        }
328 >        if (x >= hl) {                  /* right region */
329 >                if (x >= hl+sampdens)
330 >                        return(-1);
331                  return(viewray(org, vd, &rightview,
332 <                                (x-hlim)/(2.*sampdens)+.5,
333 <                                y/(2.*sampdens)+.5));
334 <                                                /* central region */
335 <        if (viewray(org, vd, &ourview, .5, y/(2.*sampdens)+.5) < 0)
332 >                                (double)(x-hl)/(2*sampdens)+.5,
333 >                                (double)y/(2*sampdens)+.5));
334 >        }
335 >                                        /* central region */
336 >        if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0)
337                  return(-1);
338 <        spinvector(vd, vd, ourview.vup, h_theta(x));
338 >        spinvector(vd, vd, ourview.vup, h_theta(x,y));
339          return(0);
340   }
341  
342  
343 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
344 < FVECT  vres, vorig, vnorm;
345 < double  theta;
343 > double
344 > pixsize(x, y)           /* return the solid angle of pixel at (x,y) */
345 > int     x, y;
346   {
347 <        extern double  sin(), cos();
348 <        double  sint, cost, dotp;
349 <        FVECT  vperp;
350 <        register int  i;
351 <        
352 <        sint = sin(theta);
353 <        cost = cos(theta);
354 <        dotp = DOT(vorig, vnorm);
355 <        fcross(vperp, vnorm, vorig);
356 <        for (i = 0; i < 3; i++)
357 <                vres[i] = vnorm[i]*dotp*(1.-cost) +
358 <                                vorig[i]*cost + vperp[i]*sint;
347 >        register int    hl, xo;
348 >        double  disc;
349 >
350 >        hl = hlim(y);
351 >        if (x < -hl)
352 >                xo = x+hl;
353 >        else if (x > hl)
354 >                xo = x-hl;
355 >        else
356 >                xo = 0;
357 >        disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens);
358 >        if (disc <= FTINY)
359 >                return(0.);
360 >        return(1./(sampdens*sampdens*sqrt(disc)));
361   }
362  
363  
364   memerr(s)                       /* malloc failure */
365   char    *s;
366   {
367 <        fprintf(stderr, "%s: out of memory for %s\n", s);
367 >        fprintf(stderr, "%s: out of memory for %s\n", progname, s);
368          exit(1);
369   }
370  
# Line 341 | Line 388 | printillum()                   /* print out indirect illuminances */
388  
389          printf("BEGIN indirect illuminance\n");
390          for (i = 0; i < nglardirs; i++)
391 <                printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta,
392 <                                PI * indirect[i].sum / (double)indirect[i].n);
391 >                if (indirect[i].n > FTINY)
392 >                        printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta,
393 >                                        PI * indirect[i].sum / indirect[i].n);
394          printf("END indirect illuminance\n");
395   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines