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.2 by greg, Fri Jan 18 19:56:03 2013 UTC vs.
Revision 2.9 by greg, Sat Feb 9 00:20:24 2013 UTC

# Line 246 | Line 246 | static const ModelCoeff DirectLumEff[8] =
246          { 101.18,  1.58, -1.10,  -8.29 }
247   };
248  
249 + #ifndef NSUNPATCH
250 + #define NSUNPATCH       4               /* # patches to spread sun into */
251 + #endif
252 +
253   extern int jdate(int month, int day);
254   extern double stadj(int  jd);
255   extern double sdec(int  jd);
# Line 256 | Line 260 | extern double  s_latitude;
260   extern double  s_longitude;
261   extern double  s_meridian;
262  
259 double          grefl = 0.2;            /* diffuse ground reflectance */
260
263   int             verbose = 0;            /* progress reports to stderr? */
264  
265   int             outfmt = 'a';           /* output format */
266  
267   int             rhsubdiv = 1;           /* Reinhart sky subdivisions */
268  
269 < float           skycolor[3] = {.96, 1.004, 1.118};      /* sky coloration */
269 > COLOR           skycolor = {.96, 1.004, 1.118}; /* sky coloration */
270 > COLOR           suncolor = {1., 1., 1.};        /* sun color */
271 > COLOR           grefl = {.2, .2, .2};           /* ground reflectance */
272  
269 int             do_sun = 1;             /* output direct solar contribution? */
270
273   int             nskypatch;              /* number of Reinhart patches */
274   float           *rh_palt;               /* sky patch altitudes (radians) */
275   float           *rh_pazi;               /* sky patch azimuths (radians) */
# Line 290 | Line 292 | int
292   main(int argc, char *argv[])
293   {
294          char    buf[256];
295 +        double  rotation = 0;           /* site rotation (degrees) */
296          double  elevation;              /* site elevation (meters) */
297          int     dir_is_horiz;           /* direct is meas. on horizontal? */
298          float   *mtx_data = NULL;       /* our matrix data */
# Line 305 | Line 308 | main(int argc, char *argv[])
308                                          /* get options */
309          for (i = 1; i < argc && argv[i][0] == '-'; i++)
310                  switch (argv[i][1]) {
311 <                case 'g':
312 <                        grefl = atof(argv[++i]);
311 >                case 'g':                       /* ground reflectance */
312 >                        grefl[0] = atof(argv[++i]);
313 >                        grefl[1] = atof(argv[++i]);
314 >                        grefl[2] = atof(argv[++i]);
315                          break;
316 <                case 'v':
316 >                case 'v':                       /* verbose progress reports */
317                          verbose++;
318                          break;
319 <                case 'o':
319 >                case 'o':                       /* output format */
320                          switch (argv[i][2]) {
321                          case 'f':
322                          case 'd':
# Line 322 | Line 327 | main(int argc, char *argv[])
327                                  goto userr;
328                          }
329                          break;
330 <                case 'm':
330 >                case 'm':                       /* Reinhart subdivisions */
331                          rhsubdiv = atoi(argv[++i]);
332                          break;
333 <                case 'c':
333 >                case 'c':                       /* sky color */
334                          skycolor[0] = atof(argv[++i]);
335                          skycolor[1] = atof(argv[++i]);
336                          skycolor[2] = atof(argv[++i]);
337                          break;
338 <                case 'd':
334 <                        do_sun = 1;
338 >                case 'd':                       /* solar (direct) only */
339                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
340 +                        if (suncolor[1] <= 1e-4)
341 +                                suncolor[0] = suncolor[1] = suncolor[2] = 1;
342                          break;
343 <                case 's':
344 <                        do_sun = 0;
343 >                case 's':                       /* sky only (no direct) */
344 >                        suncolor[0] = suncolor[1] = suncolor[2] = 0;
345                          if (skycolor[1] <= 1e-4)
346                                  skycolor[0] = skycolor[1] = skycolor[2] = 1;
347                          break;
348 +                case 'r':                       /* rotate distribution */
349 +                        if (argv[i][2] && argv[i][2] != 'z')
350 +                                goto userr;
351 +                        rotation = atof(argv[++i]);
352 +                        break;
353                  default:
354                          goto userr;
355                  }
# Line 393 | Line 404 | main(int argc, char *argv[])
404                                  progname, s_latitude, s_longitude);
405                  fprintf(stderr, "%s: %d sky patches per time step\n",
406                                  progname, nskypatch);
407 +                if (rotation != 0)
408 +                        fprintf(stderr, "%s: rotating output %.0f degrees\n",
409 +                                        progname, rotation);
410          }
411                                          /* convert quantities to radians */
412          s_latitude = DegToRad(s_latitude);
# Line 416 | Line 430 | main(int argc, char *argv[])
430                  sda = sdec(julian_date);
431                  sta = stadj(julian_date);
432                  altitude = salt(sda, hr+sta);
433 <                azimuth = sazi(sda, hr+sta) + PI;
433 >                azimuth = sazi(sda, hr+sta) + PI - DegToRad(rotation);
434                                          /* convert measured values */
435                  if (dir_is_horiz && altitude > 0.)
436                          dir /= sin(altitude);
# Line 429 | Line 443 | main(int argc, char *argv[])
443                  }
444                                          /* compute sky patch values */
445                  ComputeSky(mtx_data+mtx_offset);
446 <                if (do_sun)
433 <                        AddDirect(mtx_data+mtx_offset);
446 >                AddDirect(mtx_data+mtx_offset);
447          }
448                                          /* check for junk at end */
449          while ((i = fgetc(stdin)) != EOF)
# Line 455 | Line 468 | main(int argc, char *argv[])
468                  switch (outfmt) {
469                  case 'a':
470                          for (j = 0; j < ntsteps; j++) {
471 <                                printf("%.3e %.3e %.3e\n", mtx_data[mtx_offset],
471 >                                printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset],
472                                                  mtx_data[mtx_offset+1],
473                                                  mtx_data[mtx_offset+2]);
474                                  mtx_offset += 3*nskypatch;
# Line 490 | Line 503 | main(int argc, char *argv[])
503                  fprintf(stderr, "%s: done.\n", progname);
504          exit(0);
505   userr:
506 <        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g refl][-c r g b][-o{f|d}] [tape.wea]\n",
506 >        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",
507                          progname);
508          exit(1);
509   fmterr:
# Line 511 | Line 524 | ComputeSky(float *parr)
524   {
525          int index;                      /* Category index */
526          double norm_diff_illum;         /* Normalized diffuse illuimnance */
514        double zlumin;                  /* Zenith luminance */
527          int i;
528          
529          /* Calculate atmospheric precipitable water content */
530          apwc = CalcPrecipWater(dew_point);
531  
532 <        /* Limit solar altitude to keep circumsolar off zenith */
533 <        if (altitude > DegToRad(87.0))
534 <                altitude = DegToRad(87.0);
532 >        /* Calculate sun zenith angle (don't let it dip below horizon) */
533 >        /* Also limit minimum angle to keep circumsolar off zenith */
534 >        if (altitude <= 0.0)
535 >                sun_zenith = DegToRad(90.0);
536 >        else if (altitude >= DegToRad(87.0))
537 >                sun_zenith = DegToRad(3.0);
538 >        else
539 >                sun_zenith = DegToRad(90.0) - altitude;
540  
524        /* Calculate sun zenith angle */
525        sun_zenith = DegToRad(90.0) - altitude;
526
541          /* Compute the inputs for the calculation of the sky distribution */
542          
543          if (input == 0)                                 /* XXX never used */
# Line 542 | Line 556 | ComputeSky(float *parr)
556                  sky_brightness = CalcSkyBrightness();
557                  sky_clearness =  CalcSkyClearness();
558  
559 +                /* Limit sky clearness */
560 +                if (sky_clearness > 11.9)
561 +                        sky_clearness = 11.9;
562 +
563 +                /* Limit sky brightness */
564 +                if (sky_brightness < 0.01)
565 +                        sky_brightness = 0.01;
566 +
567                  /* Calculate illuminance */
568                  index = GetCategoryIndex();
569                  diff_illum = diff_irrad * CalcDiffuseIllumRatio(index);
# Line 558 | Line 580 | ComputeSky(float *parr)
580                  return;
581          }
582          /* Compute ground radiance (include solar contribution if any) */
583 <        parr[0] = diff_illum * (1./PI/WHTEFFICACY);
583 >        parr[0] = diff_illum;
584          if (altitude > 0)
585 <                parr[0] += dir_illum * sin(altitude) * (1./PI/WHTEFFICACY);
586 <        parr[2] = parr[1] = parr[0];
585 >                parr[0] += dir_illum * sin(altitude);
586 >        parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
587 >        multcolor(parr, grefl);
588  
589          /* Calculate Perez sky model parameters */
590          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
# Line 575 | Line 598 | ComputeSky(float *parr)
598          /* Normalization coefficient */
599          norm_diff_illum = diff_illum / norm_diff_illum;
600  
578        /* Calculate relative zenith luminance */
579        zlumin = CalcRelLuminance(sun_zenith, 0.0);
580
581        /* Calculate absolute zenith illuminance */
582        zlumin *= norm_diff_illum;
583
601          /* Apply to sky patches to get absolute radiance values */
602          for (i = 1; i < nskypatch; i++) {
603 <                scalecolor(parr+3*i, zlumin*(1./WHTEFFICACY));
603 >                scalecolor(parr+3*i, norm_diff_illum*(1./WHTEFFICACY));
604                  multcolor(parr+3*i, skycolor);
605          }
606   }
# Line 593 | Line 610 | void
610   AddDirect(float *parr)
611   {
612          FVECT   svec;
613 <        double  near_dprod[4];
614 <        int     near_patch[4];
615 <        double  wta[4], wtot;
613 >        double  near_dprod[NSUNPATCH];
614 >        int     near_patch[NSUNPATCH];
615 >        double  wta[NSUNPATCH], wtot;
616          int     i, j, p;
617  
618 <        if (!do_sun || dir_illum < 1e-4)
618 >        if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
619                  return;
620 <                                        /* identify 4 closest patches */
621 <        for (i = 4; i--; )
620 >                                        /* identify NSUNPATCH closest patches */
621 >        for (i = NSUNPATCH; i--; )
622                  near_dprod[i] = -1.;
623          vector(svec, altitude, azimuth);
624          for (p = 1; p < nskypatch; p++) {
# Line 609 | Line 626 | AddDirect(float *parr)
626                  double  dprod;
627                  rh_vector(pvec, p);
628                  dprod = DOT(pvec, svec);
629 <                for (i = 0; i < 4; i++)
629 >                for (i = 0; i < NSUNPATCH; i++)
630                          if (dprod > near_dprod[i]) {
631 <                                for (j = 4; --j > i; ) {
631 >                                for (j = NSUNPATCH; --j > i; ) {
632                                          near_dprod[j] = near_dprod[j-1];
633                                          near_patch[j] = near_patch[j-1];
634                                  }
# Line 621 | Line 638 | AddDirect(float *parr)
638                          }
639          }
640          wtot = 0;                       /* weight by proximity */
641 <        for (i = 4; i--; )
641 >        for (i = NSUNPATCH; i--; )
642                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
643                                          /* add to nearest patch radiances */
644 <        for (i = 4; i--; ) {
644 >        for (i = NSUNPATCH; i--; ) {
645                  float   *pdest = parr + 3*near_patch[i];
646                  float   val_add = wta[i] * dir_illum /
647                                  (WHTEFFICACY * wtot * rh_dom[near_patch[i]]);
648 <                *pdest++ += val_add;
649 <                *pdest++ += val_add;
650 <                *pdest++ += val_add;
648 >                *pdest++ += val_add*suncolor[0];
649 >                *pdest++ += val_add*suncolor[1];
650 >                *pdest++ += val_add*suncolor[2];
651          }
652   }
653  
# Line 665 | Line 682 | rh_init(void)
682          for (i = 0; i < NROW*rhsubdiv; i++) {
683                  const float     ralt = alpha*(i + .5);
684                  const int       ninrow = tnaz[i/rhsubdiv]*rhsubdiv;
685 <                const float     dom = (sin(alpha*(i+1)) - sin(alpha*i))/ninrow;
685 >                const float     dom = 2.*PI*(sin(alpha*(i+1)) - sin(alpha*i)) /
686 >                                                (double)ninrow;
687                  for (j = 0; j < ninrow; j++) {
688                          rh_palt[p] = ralt;
689                          rh_pazi[p] = 2.*PI * j / (double)ninrow;
# Line 827 | Line 845 | int CalcSkyParamFromIllum()
845                  sky_clearness = 12.0;
846  
847          /* Limit sky brightness */
848 <        if (sky_brightness < 0.05)
848 >        if (sky_brightness < 0.01)
849                          sky_brightness = 0.01;
850  
851          while (((fabs(diff_irrad - test1) > 10.0) ||
# Line 851 | Line 869 | int CalcSkyParamFromIllum()
869                          sky_clearness = 12.0;
870          
871                  /* Limit sky brightness */
872 <                if (sky_brightness < 0.05)
872 >                if (sky_brightness < 0.01)
873                          sky_brightness = 0.01;
874          }
875  
# Line 937 | Line 955 | double CalcRelHorzIllum( float *parr )
955          double rh_illum = 0.0;  /* Relative horizontal illuminance */
956  
957          for (i = 1; i < nskypatch; i++)
958 <                rh_illum += parr[3*i+1] * rh_cos(i);
958 >                rh_illum += parr[3*i+1] * rh_cos(i) * rh_dom[i];
959  
960 <        return rh_illum * (2.0 * PI / (nskypatch-1));
960 >        return rh_illum;
961   }
962  
963   /* Calculate earth orbit eccentricity correction factor */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines