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.18 by greg, Thu Apr 18 15:18:22 1991 UTC vs.
Revision 2.2 by greg, Tue May 12 09:36:14 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 107 | Line 106 | char   *argv[];
106                          break;
107                  case 'd':
108                  case 'l':
109 +                case 's':
110                          rtargv[rtargc++] = argv[i];
111                          rtargv[rtargc++] = argv[++i];
112                          break;
# Line 191 | Line 191 | char   *argv[];
191          fputs(VIEWSTR, stdout);
192          fprintview(&ourview, stdout);
193          printf("\n");
194 <        fputformat("ASCII", stdout);
194 >        fputformat("ascii", stdout);
195          printf("\n");
196          printsources();                         /* print glare sources */
197          printillum();                           /* print illuminances */
# Line 204 | Line 204 | userr:
204   }
205  
206  
207 + int
208 + angcmp(ap1, ap2)                /* compare two angles */
209 + ANGLE   *ap1, *ap2;
210 + {
211 +        register int    a1, a2;
212 +
213 +        a1 = *ap1;
214 +        a2 = *ap2;
215 +        if (a1 == a2) {
216 +                fprintf(stderr, "%s: duplicate glare angle (%d)\n",
217 +                                progname, a1);
218 +                exit(1);
219 +        }
220 +        return(a1-a2);
221 + }
222 +
223 +
224   init()                          /* initialize global variables */
225   {
226          double  d;
# Line 215 | Line 232 | init()                         /* initialize global variables */
232                                                  /* set direction vectors */
233          for (i = 0; glarang[i] != AEND; i++)
234                  ;
235 <        if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) {
236 <                fprintf(stderr, "%s: glare angles must be between 1 and 179\n",
235 >        qsort(glarang, i, sizeof(ANGLE), angcmp);
236 >        if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) {
237 >                fprintf(stderr, "%s: glare angles must be between 1 and 180\n",
238                                  progname);
239                  exit(1);
240          }
# Line 227 | Line 245 | init()                         /* initialize global variables */
245                  maxtheta = (PI/180.)*glarang[nglarangs-1];
246          else
247                  maxtheta = 0.0;
248 <        hlim = sampdens*maxtheta;
231 <        hsize = hlim + sampdens - 1;
248 >        hsize = hlim(0) + sampdens - 1;
249          if (hsize > (int)(PI*sampdens))
250                  hsize = PI*sampdens;
251          indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum));
# Line 294 | Line 311 | cleanup()                              /* close files, wait for children */
311   }
312  
313  
314 < compdir(vd, x, y, se)                   /* compute direction for x,y */
314 > compdir(vd, x, y)                       /* compute direction for x,y */
315   FVECT   vd;
316   int     x, y;
300 SPANERR *se;
317   {
318 +        int     hl;
319          FVECT   org;                    /* dummy variable */
320  
321 <        if (x <= -hlim)                 /* left region */
321 >        hl = hlim(y);
322 >        if (x <= -hl) {                 /* left region */
323 >                if (x <= -hl-sampdens)
324 >                        return(-1);
325                  return(viewray(org, vd, &leftview,
326 <                                (double)(x+hlim)/(2*sampdens)+.5,
326 >                                (double)(x+hl)/(2*sampdens)+.5,
327                                  (double)y/(2*sampdens)+.5));
328 <        if (x >= hlim)                  /* right region */
328 >        }
329 >        if (x >= hl) {                  /* right region */
330 >                if (x >= hl+sampdens)
331 >                        return(-1);
332                  return(viewray(org, vd, &rightview,
333 <                                (double)(x-hlim)/(2*sampdens)+.5,
333 >                                (double)(x-hl)/(2*sampdens)+.5,
334                                  (double)y/(2*sampdens)+.5));
312                                        /* central region */
313        if (se != NULL) {       /* avoid over-counting of poles */
314                se->err += se->prob;
315                if (se->err <= 0.5)
316                        return(-1);
317                se->err -= 1.0;
335          }
336 +                                        /* central region */
337          if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0)
338                  return(-1);
339 <        spinvector(vd, vd, ourview.vup, h_theta(x));
339 >        spinvector(vd, vd, ourview.vup, h_theta(x,y));
340          return(0);
341   }
342  
343  
344 < setspanerr(se, y)               /* initialize span error at y */
345 < register SPANERR        *se;
346 < int     y;
344 > double
345 > pixsize(x, y)           /* return the solid angle of pixel at (x,y) */
346 > int     x, y;
347   {
348 <        se->err = 0.0;
349 <        se->prob = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize));
348 >        register int    hl, xo;
349 >        double  disc;
350 >
351 >        hl = hlim(y);
352 >        if (x < -hl)
353 >                xo = x+hl;
354 >        else if (x > hl)
355 >                xo = x-hl;
356 >        else
357 >                xo = 0;
358 >        disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens);
359 >        if (disc <= FTINY)
360 >                return(0.);
361 >        return(1./(sampdens*sampdens*sqrt(disc)));
362   }
363  
364  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines