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 2.4 by greg, Mon Dec 7 09:13:58 1992 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include "glare.h"
14  
15 < #define FEQ(a,b)        ((a)-(b)<=FTINY&&(a)-(b)<=FTINY)
15 > #define FEQ(a,b)        ((a)-(b)<=FTINY&&(b)-(a)<=FTINY)
16   #define VEQ(v1,v2)      (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \
17                                  &&FEQ((v1)[2],(v2)[2]))
18  
19 < char    *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"};
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 67 | Line 75 | char   *argv[];
75                          }
76                          if (argv[i][2] != 'f')
77                                  goto userr;
78 <                        rval = viewfile(argv[++i], &ourview, 0, 0);
78 >                        rval = viewfile(argv[++i], &ourview, NULL);
79                          if (rval < 0) {
80                                  fprintf(stderr,
81                                  "%s: cannot open view file \"%s\"\n",
# 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 +                        if (argv[i][2] == 'v') {
109 +                                rtargv[rtargc++] = argv[i];
110 +                                break;
111 +                        }
112 +                        /* FALL THROUGH */
113                  case 'l':
114 +                case 's':
115                          rtargv[rtargc++] = argv[i];
116                          rtargv[rtargc++] = argv[++i];
117                          break;
118 +                case 'w':
119 +                        rtargv[rtargc++] = argv[i];
120 +                        break;
121                  case 'a':
122                          rtargv[rtargc++] = argv[i];
123                          if (argv[i][2] == 'v') {
# Line 119 | Line 139 | char   *argv[];
139          }
140                                                  /* get view */
141          if (picture != NULL) {
142 <                rval = viewfile(picture, &pictview, 0, 0);
142 >                rval = viewfile(picture, &pictview, NULL);
143                  if (rval < 0) {
144                          fprintf(stderr, "%s: cannot open picture file \"%s\"\n",
145                                          progname, picture);
# Line 168 | Line 188 | char   *argv[];
188                  exit(1);
189          }
190          init();                                 /* initialize program */
191 <        comp_thresh();                          /* compute glare threshold */
191 >        if (threshold <= FTINY)
192 >                comp_thresh();                  /* compute glare threshold */
193          analyze();                              /* analyze view */
194 +        if (combine)
195 +                absorb_specks();                /* eliminate tiny sources */
196          cleanup();                              /* tidy up */
197                                                  /* print header */
198          printargs(argc, argv, stdout);
199          fputs(VIEWSTR, stdout);
200          fprintview(&ourview, stdout);
201 <        printf("\n\n");
201 >        printf("\n");
202 >        fputformat("ascii", stdout);
203 >        printf("\n");
204          printsources();                         /* print glare sources */
205          printillum();                           /* print illuminances */
206          exit(0);
# Line 187 | Line 212 | userr:
212   }
213  
214  
215 + int
216 + angcmp(ap1, ap2)                /* compare two angles */
217 + ANGLE   *ap1, *ap2;
218 + {
219 +        register int    a1, a2;
220 +
221 +        a1 = *ap1;
222 +        a2 = *ap2;
223 +        if (a1 == a2) {
224 +                fprintf(stderr, "%s: duplicate glare angle (%d)\n",
225 +                                progname, a1);
226 +                exit(1);
227 +        }
228 +        return(a1-a2);
229 + }
230 +
231 +
232   init()                          /* initialize global variables */
233   {
234          double  d;
# Line 198 | Line 240 | init()                         /* initialize global variables */
240                                                  /* set direction vectors */
241          for (i = 0; glarang[i] != AEND; i++)
242                  ;
243 <        if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) {
244 <                fprintf(stderr, "%s: glare angles must be between 1 and 179\n",
243 >        qsort(glarang, i, sizeof(ANGLE), angcmp);
244 >        if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) {
245 >                fprintf(stderr, "%s: glare angles must be between 1 and 180\n",
246                                  progname);
247                  exit(1);
248          }
249          nglarangs = i;
250          /* nglardirs = 2*nglarangs + 1; */
251 <        /* vsize = sampdens; */
251 >        /* vsize = sampdens - 1; */
252          if (nglarangs > 0)
253                  maxtheta = (PI/180.)*glarang[nglarangs-1];
254          else
255                  maxtheta = 0.0;
256 <        hlim = sampdens*maxtheta;
214 <        hsize = sampdens + hlim;
256 >        hsize = hlim(0) + sampdens - 1;
257          if (hsize > (int)(PI*sampdens))
258                  hsize = PI*sampdens;
259          indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum));
260          if (indirect == NULL)
261                  memerr("indirect illuminances");
262 +        npixinvw = npixmiss = 0L;
263          copystruct(&leftview, &ourview);
264          copystruct(&rightview, &ourview);
265          spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta);
# Line 225 | Line 268 | init()                         /* initialize global variables */
268          setview(&rightview);
269          indirect[nglarangs].lcos =
270          indirect[nglarangs].rcos = cos(maxtheta);
271 <        indirect[nglarangs].lsin =
272 <        -(indirect[nglarangs].rsin = sin(maxtheta));
271 >        indirect[nglarangs].rsin =
272 >        -(indirect[nglarangs].lsin = sin(maxtheta));
273          indirect[nglarangs].theta = 0.0;
274          for (i = 0; i < nglarangs; i++) {
275                  d = (glarang[nglarangs-1] - glarang[i])*(PI/180.);
276                  indirect[nglarangs-i-1].lcos =
277                  indirect[nglarangs+i+1].rcos = cos(d);
278 <                indirect[nglarangs-i-1].lsin =
279 <                -(indirect[nglarangs+i+1].rsin = sin(d));
278 >                indirect[nglarangs+i+1].rsin =
279 >                -(indirect[nglarangs-i-1].lsin = sin(d));
280                  d = (glarang[nglarangs-1] + glarang[i])*(PI/180.);
281                  indirect[nglarangs-i-1].rcos =
282                  indirect[nglarangs+i+1].lcos = cos(d);
283 <                indirect[nglarangs+i+1].lsin =
284 <                -(indirect[nglarangs-i-1].rsin = sin(d));
285 <                indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i];
286 <                indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i];
283 >                indirect[nglarangs-i-1].rsin =
284 >                -(indirect[nglarangs+i+1].lsin = sin(d));
285 >                indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i];
286 >                indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i];
287          }
288                                                  /* open picture */
289          if (picture != NULL) {
# Line 265 | Line 308 | init()                         /* initialize global variables */
308   cleanup()                               /* close files, wait for children */
309   {
310          if (verbose)
311 <                fprintf(stderr, "%s: cleaning up...\n", progname);
311 >                fprintf(stderr, "%s: cleaning up...        \n", progname);
312          if (picture != NULL)
313                  close_pict();
314          if (octree != NULL)
315                  done_rtrace();
316 +        if (npixinvw < 100*npixmiss)
317 +                fprintf(stderr, "%s: warning -- missing %d%% of samples\n",
318 +                                progname, (int)(100L*npixmiss/npixinvw));
319   }
320  
321  
# Line 277 | Line 323 | compdir(vd, x, y)                      /* compute direction for x,y */
323   FVECT   vd;
324   int     x, y;
325   {
326 +        int     hl;
327          FVECT   org;                    /* dummy variable */
328  
329 <        if (x <= -hlim)                 /* left region */
329 >        hl = hlim(y);
330 >        if (x <= -hl) {                 /* left region */
331 >                if (x <= -hl-sampdens)
332 >                        return(-1);
333                  return(viewray(org, vd, &leftview,
334 <                                (x+hlim)/(2.*sampdens)+.5,
335 <                                y/(2.*sampdens)+.5));
336 <        if (x >= hlim)                  /* right region */
334 >                                (double)(x+hl)/(2*sampdens)+.5,
335 >                                (double)y/(2*sampdens)+.5));
336 >        }
337 >        if (x >= hl) {                  /* right region */
338 >                if (x >= hl+sampdens)
339 >                        return(-1);
340                  return(viewray(org, vd, &rightview,
341 <                                (x-hlim)/(2.*sampdens)+.5,
342 <                                y/(2.*sampdens)+.5));
343 <                                                /* central region */
344 <        if (viewray(org, vd, &ourview, .5, y/(2.*sampdens)+.5) < 0)
341 >                                (double)(x-hl)/(2*sampdens)+.5,
342 >                                (double)y/(2*sampdens)+.5));
343 >        }
344 >                                        /* central region */
345 >        if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0)
346                  return(-1);
347 <        spinvector(vd, vd, ourview.vup, h_theta(x));
347 >        spinvector(vd, vd, ourview.vup, h_theta(x,y));
348          return(0);
349   }
350  
351  
352 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
353 < FVECT  vres, vorig, vnorm;
354 < double  theta;
352 > double
353 > pixsize(x, y)           /* return the solid angle of pixel at (x,y) */
354 > int     x, y;
355   {
356 <        extern double  sin(), cos();
357 <        double  sint, cost, dotp;
358 <        FVECT  vperp;
359 <        register int  i;
360 <        
361 <        sint = sin(theta);
362 <        cost = cos(theta);
363 <        dotp = DOT(vorig, vnorm);
364 <        fcross(vperp, vnorm, vorig);
365 <        for (i = 0; i < 3; i++)
366 <                vres[i] = vnorm[i]*dotp*(1.-cost) +
367 <                                vorig[i]*cost + vperp[i]*sint;
356 >        register int    hl, xo;
357 >        double  disc;
358 >
359 >        hl = hlim(y);
360 >        if (x < -hl)
361 >                xo = x+hl;
362 >        else if (x > hl)
363 >                xo = x-hl;
364 >        else
365 >                xo = 0;
366 >        disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens);
367 >        if (disc <= FTINY)
368 >                return(0.);
369 >        return(1./(sampdens*sampdens*sqrt(disc)));
370   }
371  
372  
373   memerr(s)                       /* malloc failure */
374   char    *s;
375   {
376 <        fprintf(stderr, "%s: out of memory for %s\n", s);
376 >        fprintf(stderr, "%s: out of memory for %s\n", progname, s);
377          exit(1);
378   }
379  
# Line 341 | Line 397 | printillum()                   /* print out indirect illuminances */
397  
398          printf("BEGIN indirect illuminance\n");
399          for (i = 0; i < nglardirs; i++)
400 <                printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta,
401 <                                PI * indirect[i].sum / (double)indirect[i].n);
400 >                if (indirect[i].n > FTINY)
401 >                        printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta,
402 >                                        PI * indirect[i].sum / indirect[i].n);
403          printf("END indirect illuminance\n");
404   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines