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.15 by greg, Fri Apr 5 14:26:47 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 = STDVIEW;              /* our view */
# Line 36 | Line 36 | ANGLE  glarang[180] = {AEND};          /* glare calculation ang
36   int     nglarangs = 0;
37   double  maxtheta;                       /* maximum angle (in radians) */
38   int     hsize;                          /* horizontal size */
39 int     hlim;                           /* central limit of horizontal */
39  
40   struct illum    *indirect;              /* array of indirect illuminances */
41  
# Line 48 | Line 47 | 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 75 | 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 101 | 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 127 | 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 179 | Line 191 | char   *argv[];
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 196 | 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 207 | 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          }
# Line 219 | Line 253 | init()                         /* initialize global variables */
253                  maxtheta = (PI/180.)*glarang[nglarangs-1];
254          else
255                  maxtheta = 0.0;
256 <        hlim = sampdens*maxtheta;
223 <        hsize = hlim + sampdens - 1;
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));
# Line 275 | 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 %ld%% of samples\n",
318 <                                progname, 100L*npixmiss/npixinvw);
317 >                fprintf(stderr, "%s: warning -- missing %d%% of samples\n",
318 >                                progname, (int)(100L*npixmiss/npixinvw));
319   }
320  
321  
# Line 290 | Line 323 | compdir(vd, x, y)                      /* compute direction for x,y */
323   FVECT   vd;
324   int     x, y;
325   {
326 <        static int      cury = 10000;
294 <        static double   err, cmpval;
295 <        long    t;
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 <                                (double)(x+hlim)/(2*sampdens)+.5,
334 >                                (double)(x+hl)/(2*sampdens)+.5,
335                                  (double)y/(2*sampdens)+.5));
336 <        if (x >= hlim)                  /* right region */
336 >        }
337 >        if (x >= hl) {                  /* right region */
338 >                if (x >= hl+sampdens)
339 >                        return(-1);
340                  return(viewray(org, vd, &rightview,
341 <                                (double)(x-hlim)/(2*sampdens)+.5,
341 >                                (double)(x-hl)/(2*sampdens)+.5,
342                                  (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;
343          }
344 <        err += cmpval;
314 <        if (err <= 0.5)
315 <                return(-1);
316 <        err -= 1.0;
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 + double
353 + pixsize(x, y)           /* return the solid angle of pixel at (x,y) */
354 + int     x, y;
355 + {
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines