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.6 by greg, Mon Jun 7 10:31:35 1993 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 +                case 'P':
116                          rtargv[rtargc++] = argv[i];
117                          rtargv[rtargc++] = argv[++i];
118                          break;
119 +                case 'w':
120 +                        rtargv[rtargc++] = argv[i];
121 +                        break;
122                  case 'a':
123                          rtargv[rtargc++] = argv[i];
124                          if (argv[i][2] == 'v') {
# Line 127 | Line 140 | char   *argv[];
140          }
141                                                  /* get view */
142          if (picture != NULL) {
143 <                rval = viewfile(picture, &pictview, 0, 0);
143 >                rval = viewfile(picture, &pictview, NULL);
144                  if (rval < 0) {
145                          fprintf(stderr, "%s: cannot open picture file \"%s\"\n",
146                                          progname, picture);
# Line 179 | Line 192 | char   *argv[];
192          if (threshold <= FTINY)
193                  comp_thresh();                  /* compute glare threshold */
194          analyze();                              /* analyze view */
195 +        if (combine)
196 +                absorb_specks();                /* eliminate tiny sources */
197          cleanup();                              /* tidy up */
198                                                  /* print header */
199          printargs(argc, argv, stdout);
200          fputs(VIEWSTR, stdout);
201          fprintview(&ourview, stdout);
202 <        printf("\n\n");
202 >        printf("\n");
203 >        fputformat("ascii", stdout);
204 >        printf("\n");
205          printsources();                         /* print glare sources */
206          printillum();                           /* print illuminances */
207          exit(0);
# Line 196 | Line 213 | userr:
213   }
214  
215  
216 + int
217 + angcmp(ap1, ap2)                /* compare two angles */
218 + ANGLE   *ap1, *ap2;
219 + {
220 +        register int    a1, a2;
221 +
222 +        a1 = *ap1;
223 +        a2 = *ap2;
224 +        if (a1 == a2) {
225 +                fprintf(stderr, "%s: duplicate glare angle (%d)\n",
226 +                                progname, a1);
227 +                exit(1);
228 +        }
229 +        return(a1-a2);
230 + }
231 +
232 +
233   init()                          /* initialize global variables */
234   {
235          double  d;
# Line 207 | Line 241 | init()                         /* initialize global variables */
241                                                  /* set direction vectors */
242          for (i = 0; glarang[i] != AEND; i++)
243                  ;
244 <        if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) {
245 <                fprintf(stderr, "%s: glare angles must be between 1 and 179\n",
244 >        qsort(glarang, i, sizeof(ANGLE), angcmp);
245 >        if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) {
246 >                fprintf(stderr, "%s: glare angles must be between 1 and 180\n",
247                                  progname);
248                  exit(1);
249          }
# Line 219 | Line 254 | init()                         /* initialize global variables */
254                  maxtheta = (PI/180.)*glarang[nglarangs-1];
255          else
256                  maxtheta = 0.0;
257 <        hlim = sampdens*maxtheta;
223 <        hsize = hlim + sampdens - 1;
257 >        hsize = hlim(0) + sampdens - 1;
258          if (hsize > (int)(PI*sampdens))
259                  hsize = PI*sampdens;
260          indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum));
# Line 275 | Line 309 | init()                         /* initialize global variables */
309   cleanup()                               /* close files, wait for children */
310   {
311          if (verbose)
312 <                fprintf(stderr, "%s: cleaning up...\n", progname);
312 >                fprintf(stderr, "%s: cleaning up...        \n", progname);
313          if (picture != NULL)
314                  close_pict();
315          if (octree != NULL)
316                  done_rtrace();
317          if (npixinvw < 100*npixmiss)
318 <                fprintf(stderr, "%s: warning -- missing %ld%% of samples\n",
319 <                                progname, 100L*npixmiss/npixinvw);
318 >                fprintf(stderr, "%s: warning -- missing %d%% of samples\n",
319 >                                progname, (int)(100L*npixmiss/npixinvw));
320   }
321  
322  
# Line 290 | Line 324 | compdir(vd, x, y)                      /* compute direction for x,y */
324   FVECT   vd;
325   int     x, y;
326   {
327 <        static int      cury = 10000;
294 <        static double   err, cmpval;
295 <        long    t;
327 >        int     hl;
328          FVECT   org;                    /* dummy variable */
329  
330 <        if (x <= -hlim)                 /* left region */
330 >        hl = hlim(y);
331 >        if (x <= -hl) {                 /* left region */
332 >                if (x <= -hl-sampdens)
333 >                        return(-1);
334                  return(viewray(org, vd, &leftview,
335 <                                (double)(x+hlim)/(2*sampdens)+.5,
335 >                                (double)(x+hl)/(2*sampdens)+.5,
336                                  (double)y/(2*sampdens)+.5));
337 <        if (x >= hlim)                  /* right region */
337 >        }
338 >        if (x >= hl) {                  /* right region */
339 >                if (x >= hl+sampdens)
340 >                        return(-1);
341                  return(viewray(org, vd, &rightview,
342 <                                (double)(x-hlim)/(2*sampdens)+.5,
342 >                                (double)(x-hl)/(2*sampdens)+.5,
343                                  (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;
344          }
345 <        err += cmpval;
314 <        if (err <= 0.5)
315 <                return(-1);
316 <        err -= 1.0;
345 >                                        /* central region */
346          if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0)
347                  return(-1);
348 <        spinvector(vd, vd, ourview.vup, h_theta(x));
348 >        spinvector(vd, vd, ourview.vup, h_theta(x,y));
349          return(0);
350 + }
351 +
352 +
353 + double
354 + pixsize(x, y)           /* return the solid angle of pixel at (x,y) */
355 + int     x, y;
356 + {
357 +        register int    hl, xo;
358 +        double  disc;
359 +
360 +        hl = hlim(y);
361 +        if (x < -hl)
362 +                xo = x+hl;
363 +        else if (x > hl)
364 +                xo = x-hl;
365 +        else
366 +                xo = 0;
367 +        disc = 1. - (double)((long)xo*xo + (long)y*y)/((long)sampdens*sampdens);
368 +        if (disc <= FTINY*FTINY)
369 +                return(0.);
370 +        return(1./(sampdens*sampdens*sqrt(disc)));
371   }
372  
373  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines