ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/gendaymtx.c
(Generate patch)

Comparing ray/src/gen/gendaymtx.c (file contents):
Revision 2.3 by greg, Sat Jan 19 20:38:36 2013 UTC vs.
Revision 2.10 by greg, Sat Apr 6 00:44:59 2013 UTC

# Line 247 | Line 247 | static const ModelCoeff DirectLumEff[8] =
247   };
248  
249   #ifndef NSUNPATCH
250 < #define NSUNPATCH       4               /* # patches to spread sun into */
250 > #define NSUNPATCH       4               /* max. # patches to spread sun into */
251   #endif
252  
253   extern int jdate(int month, int day);
# Line 260 | Line 260 | extern double  s_latitude;
260   extern double  s_longitude;
261   extern double  s_meridian;
262  
263 < double          grefl = 0.2;            /* diffuse ground reflectance */
263 > int             nsuns = NSUNPATCH;      /* number of sun patches to use */
264 > double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
265  
266   int             verbose = 0;            /* progress reports to stderr? */
267  
# Line 268 | Line 269 | int            outfmt = 'a';           /* output format */
269  
270   int             rhsubdiv = 1;           /* Reinhart sky subdivisions */
271  
272 < float           skycolor[3] = {.96, 1.004, 1.118};      /* sky coloration */
272 > COLOR           skycolor = {.96, 1.004, 1.118}; /* sky coloration */
273 > COLOR           suncolor = {1., 1., 1.};        /* sun color */
274 > COLOR           grefl = {.2, .2, .2};           /* ground reflectance */
275  
273 int             do_sun = 1;             /* output direct solar contribution? */
274
276   int             nskypatch;              /* number of Reinhart patches */
277   float           *rh_palt;               /* sky patch altitudes (radians) */
278   float           *rh_pazi;               /* sky patch azimuths (radians) */
# Line 294 | Line 295 | int
295   main(int argc, char *argv[])
296   {
297          char    buf[256];
298 +        double  rotation = 0;           /* site rotation (degrees) */
299          double  elevation;              /* site elevation (meters) */
300          int     dir_is_horiz;           /* direct is meas. on horizontal? */
301          float   *mtx_data = NULL;       /* our matrix data */
# Line 309 | Line 311 | main(int argc, char *argv[])
311                                          /* get options */
312          for (i = 1; i < argc && argv[i][0] == '-'; i++)
313                  switch (argv[i][1]) {
314 <                case 'g':
315 <                        grefl = atof(argv[++i]);
314 >                case 'g':                       /* ground reflectance */
315 >                        grefl[0] = atof(argv[++i]);
316 >                        grefl[1] = atof(argv[++i]);
317 >                        grefl[2] = atof(argv[++i]);
318                          break;
319 <                case 'v':
319 >                case 'v':                       /* verbose progress reports */
320                          verbose++;
321                          break;
322 <                case 'o':
322 >                case 'o':                       /* output format */
323                          switch (argv[i][2]) {
324                          case 'f':
325                          case 'd':
# Line 326 | Line 330 | main(int argc, char *argv[])
330                                  goto userr;
331                          }
332                          break;
333 <                case 'm':
333 >                case 'm':                       /* Reinhart subdivisions */
334                          rhsubdiv = atoi(argv[++i]);
335                          break;
336 <                case 'c':
336 >                case 'c':                       /* sky color */
337                          skycolor[0] = atof(argv[++i]);
338                          skycolor[1] = atof(argv[++i]);
339                          skycolor[2] = atof(argv[++i]);
340                          break;
341 <                case 'd':
338 <                        do_sun = 1;
341 >                case 'd':                       /* solar (direct) only */
342                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
343 +                        if (suncolor[1] <= 1e-4)
344 +                                suncolor[0] = suncolor[1] = suncolor[2] = 1;
345                          break;
346 <                case 's':
347 <                        do_sun = 0;
346 >                case 's':                       /* sky only (no direct) */
347 >                        suncolor[0] = suncolor[1] = suncolor[2] = 0;
348                          if (skycolor[1] <= 1e-4)
349                                  skycolor[0] = skycolor[1] = skycolor[2] = 1;
350                          break;
351 +                case 'r':                       /* rotate distribution */
352 +                        if (argv[i][2] && argv[i][2] != 'z')
353 +                                goto userr;
354 +                        rotation = atof(argv[++i]);
355 +                        break;
356 +                case '5':                       /* 5-phase calculation */
357 +                        nsuns = 1;
358 +                        fixed_sun_sa = 6.797e-05;
359 +                        break;
360                  default:
361                          goto userr;
362                  }
# Line 397 | Line 411 | main(int argc, char *argv[])
411                                  progname, s_latitude, s_longitude);
412                  fprintf(stderr, "%s: %d sky patches per time step\n",
413                                  progname, nskypatch);
414 +                if (rotation != 0)
415 +                        fprintf(stderr, "%s: rotating output %.0f degrees\n",
416 +                                        progname, rotation);
417          }
418                                          /* convert quantities to radians */
419          s_latitude = DegToRad(s_latitude);
# Line 420 | Line 437 | main(int argc, char *argv[])
437                  sda = sdec(julian_date);
438                  sta = stadj(julian_date);
439                  altitude = salt(sda, hr+sta);
440 <                azimuth = sazi(sda, hr+sta) + PI;
440 >                azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation);
441                                          /* convert measured values */
442                  if (dir_is_horiz && altitude > 0.)
443                          dir /= sin(altitude);
# Line 433 | Line 450 | main(int argc, char *argv[])
450                  }
451                                          /* compute sky patch values */
452                  ComputeSky(mtx_data+mtx_offset);
453 <                if (do_sun)
437 <                        AddDirect(mtx_data+mtx_offset);
453 >                AddDirect(mtx_data+mtx_offset);
454          }
455                                          /* check for junk at end */
456          while ((i = fgetc(stdin)) != EOF)
# Line 494 | Line 510 | main(int argc, char *argv[])
510                  fprintf(stderr, "%s: done.\n", progname);
511          exit(0);
512   userr:
513 <        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g refl][-c r g b][-o{f|d}] [tape.wea]\n",
513 >        fprintf(stderr, "Usage: %s [-v][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}] [tape.wea]\n",
514                          progname);
515          exit(1);
516   fmterr:
# Line 515 | Line 531 | ComputeSky(float *parr)
531   {
532          int index;                      /* Category index */
533          double norm_diff_illum;         /* Normalized diffuse illuimnance */
518        double zlumin;                  /* Zenith luminance */
534          int i;
535          
536          /* Calculate atmospheric precipitable water content */
537          apwc = CalcPrecipWater(dew_point);
538  
539 <        /* Limit solar altitude to keep circumsolar off zenith */
540 <        if (altitude > DegToRad(87.0))
541 <                altitude = DegToRad(87.0);
539 >        /* Calculate sun zenith angle (don't let it dip below horizon) */
540 >        /* Also limit minimum angle to keep circumsolar off zenith */
541 >        if (altitude <= 0.0)
542 >                sun_zenith = DegToRad(90.0);
543 >        else if (altitude >= DegToRad(87.0))
544 >                sun_zenith = DegToRad(3.0);
545 >        else
546 >                sun_zenith = DegToRad(90.0) - altitude;
547  
528        /* Calculate sun zenith angle */
529        sun_zenith = DegToRad(90.0) - altitude;
530
548          /* Compute the inputs for the calculation of the sky distribution */
549          
550          if (input == 0)                                 /* XXX never used */
# Line 546 | Line 563 | ComputeSky(float *parr)
563                  sky_brightness = CalcSkyBrightness();
564                  sky_clearness =  CalcSkyClearness();
565  
566 +                /* Limit sky clearness */
567 +                if (sky_clearness > 11.9)
568 +                        sky_clearness = 11.9;
569 +
570 +                /* Limit sky brightness */
571 +                if (sky_brightness < 0.01)
572 +                        sky_brightness = 0.01;
573 +
574                  /* Calculate illuminance */
575                  index = GetCategoryIndex();
576                  diff_illum = diff_irrad * CalcDiffuseIllumRatio(index);
# Line 565 | Line 590 | ComputeSky(float *parr)
590          parr[0] = diff_illum;
591          if (altitude > 0)
592                  parr[0] += dir_illum * sin(altitude);
593 <        parr[2] = parr[1] = parr[0] *= grefl*(1./PI/WHTEFFICACY);
593 >        parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
594 >        multcolor(parr, grefl);
595  
596          /* Calculate Perez sky model parameters */
597          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
# Line 579 | Line 605 | ComputeSky(float *parr)
605          /* Normalization coefficient */
606          norm_diff_illum = diff_illum / norm_diff_illum;
607  
582        /* Calculate relative zenith luminance */
583        zlumin = CalcRelLuminance(sun_zenith, 0.0);
584
585        /* Calculate absolute zenith illuminance */
586        zlumin *= norm_diff_illum;
587
608          /* Apply to sky patches to get absolute radiance values */
609          for (i = 1; i < nskypatch; i++) {
610 <                scalecolor(parr+3*i, zlumin*(1./WHTEFFICACY));
610 >                scalecolor(parr+3*i, norm_diff_illum*(1./WHTEFFICACY));
611                  multcolor(parr+3*i, skycolor);
612          }
613   }
# Line 602 | Line 622 | AddDirect(float *parr)
622          double  wta[NSUNPATCH], wtot;
623          int     i, j, p;
624  
625 <        if (!do_sun || dir_illum < 1e-4)
625 >        if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
626                  return;
627 <                                        /* identify NSUNPATCH closest patches */
628 <        for (i = NSUNPATCH; i--; )
627 >                                        /* identify nsuns closest patches */
628 >        if (nsuns > NSUNPATCH)
629 >                nsuns = NSUNPATCH;
630 >        else if (nsuns <= 0)
631 >                nsuns = 1;
632 >        for (i = nsuns; i--; )
633                  near_dprod[i] = -1.;
634          vector(svec, altitude, azimuth);
635          for (p = 1; p < nskypatch; p++) {
# Line 613 | Line 637 | AddDirect(float *parr)
637                  double  dprod;
638                  rh_vector(pvec, p);
639                  dprod = DOT(pvec, svec);
640 <                for (i = 0; i < NSUNPATCH; i++)
640 >                for (i = 0; i < nsuns; i++)
641                          if (dprod > near_dprod[i]) {
642 <                                for (j = NSUNPATCH; --j > i; ) {
642 >                                for (j = nsuns; --j > i; ) {
643                                          near_dprod[j] = near_dprod[j-1];
644                                          near_patch[j] = near_patch[j-1];
645                                  }
# Line 625 | Line 649 | AddDirect(float *parr)
649                          }
650          }
651          wtot = 0;                       /* weight by proximity */
652 <        for (i = NSUNPATCH; i--; )
652 >        for (i = nsuns; i--; )
653                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
654                                          /* add to nearest patch radiances */
655 <        for (i = NSUNPATCH; i--; ) {
655 >        for (i = nsuns; i--; ) {
656                  float   *pdest = parr + 3*near_patch[i];
657 <                float   val_add = wta[i] * dir_illum /
658 <                                (WHTEFFICACY * wtot * rh_dom[near_patch[i]]);
659 <                *pdest++ += val_add;
660 <                *pdest++ += val_add;
661 <                *pdest++ += val_add;
657 >                float   val_add = wta[i] * dir_illum / (WHTEFFICACY * wtot);
658 >
659 >                val_add /= (fixed_sun_sa > 0)   ? fixed_sun_sa
660 >                                                : rh_dom[near_patch[i]] ;
661 >                *pdest++ += val_add*suncolor[0];
662 >                *pdest++ += val_add*suncolor[1];
663 >                *pdest++ += val_add*suncolor[2];
664          }
665   }
666  
# Line 832 | Line 858 | int CalcSkyParamFromIllum()
858                  sky_clearness = 12.0;
859  
860          /* Limit sky brightness */
861 <        if (sky_brightness < 0.05)
861 >        if (sky_brightness < 0.01)
862                          sky_brightness = 0.01;
863  
864          while (((fabs(diff_irrad - test1) > 10.0) ||
# Line 856 | Line 882 | int CalcSkyParamFromIllum()
882                          sky_clearness = 12.0;
883          
884                  /* Limit sky brightness */
885 <                if (sky_brightness < 0.05)
885 >                if (sky_brightness < 0.01)
886                          sky_brightness = 0.01;
887          }
888  
# Line 942 | Line 968 | double CalcRelHorzIllum( float *parr )
968          double rh_illum = 0.0;  /* Relative horizontal illuminance */
969  
970          for (i = 1; i < nskypatch; i++)
971 <                rh_illum += parr[3*i+1] * rh_cos(i);
971 >                rh_illum += parr[3*i+1] * rh_cos(i) * rh_dom[i];
972  
973 <        return rh_illum * (2.0 * PI / (nskypatch-1));
973 >        return rh_illum;
974   }
975  
976   /* Calculate earth orbit eccentricity correction factor */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines