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.6 by greg, Fri Jan 25 23:17:31 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 305 | Line 307 | main(int argc, char *argv[])
307                                          /* get options */
308          for (i = 1; i < argc && argv[i][0] == '-'; i++)
309                  switch (argv[i][1]) {
310 <                case 'g':
311 <                        grefl = atof(argv[++i]);
310 >                case 'g':                       /* ground reflectance */
311 >                        grefl[0] = atof(argv[++i]);
312 >                        grefl[1] = atof(argv[++i]);
313 >                        grefl[2] = atof(argv[++i]);
314                          break;
315 <                case 'v':
315 >                case 'v':                       /* verbose progress reports */
316                          verbose++;
317                          break;
318 <                case 'o':
318 >                case 'o':                       /* output format */
319                          switch (argv[i][2]) {
320                          case 'f':
321                          case 'd':
# Line 322 | Line 326 | main(int argc, char *argv[])
326                                  goto userr;
327                          }
328                          break;
329 <                case 'm':
329 >                case 'm':                       /* Reinhart subdivisions */
330                          rhsubdiv = atoi(argv[++i]);
331                          break;
332 <                case 'c':
332 >                case 'c':                       /* sky color */
333                          skycolor[0] = atof(argv[++i]);
334                          skycolor[1] = atof(argv[++i]);
335                          skycolor[2] = atof(argv[++i]);
336                          break;
337 <                case 'd':
334 <                        do_sun = 1;
337 >                case 'd':                       /* solar (direct) only */
338                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
339 +                        if (suncolor[1] <= 1e-4)
340 +                                suncolor[0] = suncolor[1] = suncolor[2] = 1;
341                          break;
342 <                case 's':
343 <                        do_sun = 0;
342 >                case 's':                       /* sky only (no direct) */
343 >                        suncolor[0] = suncolor[1] = suncolor[2] = 0;
344                          if (skycolor[1] <= 1e-4)
345                                  skycolor[0] = skycolor[1] = skycolor[2] = 1;
346                          break;
# Line 429 | Line 434 | main(int argc, char *argv[])
434                  }
435                                          /* compute sky patch values */
436                  ComputeSky(mtx_data+mtx_offset);
437 <                if (do_sun)
433 <                        AddDirect(mtx_data+mtx_offset);
437 >                AddDirect(mtx_data+mtx_offset);
438          }
439                                          /* check for junk at end */
440          while ((i = fgetc(stdin)) != EOF)
# Line 455 | Line 459 | main(int argc, char *argv[])
459                  switch (outfmt) {
460                  case 'a':
461                          for (j = 0; j < ntsteps; j++) {
462 <                                printf("%.3e %.3e %.3e\n", mtx_data[mtx_offset],
462 >                                printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset],
463                                                  mtx_data[mtx_offset+1],
464                                                  mtx_data[mtx_offset+2]);
465                                  mtx_offset += 3*nskypatch;
# Line 490 | Line 494 | main(int argc, char *argv[])
494                  fprintf(stderr, "%s: done.\n", progname);
495          exit(0);
496   userr:
497 <        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g refl][-c r g b][-o{f|d}] [tape.wea]\n",
497 >        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g r g b][-c r g b][-o{f|d}] [tape.wea]\n",
498                          progname);
499          exit(1);
500   fmterr:
# Line 517 | Line 521 | ComputeSky(float *parr)
521          /* Calculate atmospheric precipitable water content */
522          apwc = CalcPrecipWater(dew_point);
523  
524 <        /* Limit solar altitude to keep circumsolar off zenith */
525 <        if (altitude > DegToRad(87.0))
526 <                altitude = DegToRad(87.0);
524 >        /* Calculate sun zenith angle (don't let it dip below horizon) */
525 >        /* Also limit minimum angle to keep circumsolar off zenith */
526 >        if (altitude <= 0.0)
527 >                sun_zenith = DegToRad(90.0);
528 >        else if (altitude >= DegToRad(87.0))
529 >                sun_zenith = DegToRad(3.0);
530 >        else
531 >                sun_zenith = DegToRad(90.0) - altitude;
532  
524        /* Calculate sun zenith angle */
525        sun_zenith = DegToRad(90.0) - altitude;
526
533          /* Compute the inputs for the calculation of the sky distribution */
534          
535          if (input == 0)                                 /* XXX never used */
# Line 558 | Line 564 | ComputeSky(float *parr)
564                  return;
565          }
566          /* Compute ground radiance (include solar contribution if any) */
567 <        parr[0] = diff_illum * (1./PI/WHTEFFICACY);
567 >        parr[0] = diff_illum;
568          if (altitude > 0)
569 <                parr[0] += dir_illum * sin(altitude) * (1./PI/WHTEFFICACY);
570 <        parr[2] = parr[1] = parr[0];
569 >                parr[0] += dir_illum * sin(altitude);
570 >        parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
571 >        multcolor(parr, grefl);
572  
573          /* Calculate Perez sky model parameters */
574          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
# Line 593 | Line 600 | void
600   AddDirect(float *parr)
601   {
602          FVECT   svec;
603 <        double  near_dprod[4];
604 <        int     near_patch[4];
605 <        double  wta[4], wtot;
603 >        double  near_dprod[NSUNPATCH];
604 >        int     near_patch[NSUNPATCH];
605 >        double  wta[NSUNPATCH], wtot;
606          int     i, j, p;
607  
608 <        if (!do_sun || dir_illum < 1e-4)
608 >        if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
609                  return;
610 <                                        /* identify 4 closest patches */
611 <        for (i = 4; i--; )
610 >                                        /* identify NSUNPATCH closest patches */
611 >        for (i = NSUNPATCH; i--; )
612                  near_dprod[i] = -1.;
613          vector(svec, altitude, azimuth);
614          for (p = 1; p < nskypatch; p++) {
# Line 609 | Line 616 | AddDirect(float *parr)
616                  double  dprod;
617                  rh_vector(pvec, p);
618                  dprod = DOT(pvec, svec);
619 <                for (i = 0; i < 4; i++)
619 >                for (i = 0; i < NSUNPATCH; i++)
620                          if (dprod > near_dprod[i]) {
621 <                                for (j = 4; --j > i; ) {
621 >                                for (j = NSUNPATCH; --j > i; ) {
622                                          near_dprod[j] = near_dprod[j-1];
623                                          near_patch[j] = near_patch[j-1];
624                                  }
# Line 621 | Line 628 | AddDirect(float *parr)
628                          }
629          }
630          wtot = 0;                       /* weight by proximity */
631 <        for (i = 4; i--; )
631 >        for (i = NSUNPATCH; i--; )
632                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
633                                          /* add to nearest patch radiances */
634 <        for (i = 4; i--; ) {
634 >        for (i = NSUNPATCH; i--; ) {
635                  float   *pdest = parr + 3*near_patch[i];
636                  float   val_add = wta[i] * dir_illum /
637                                  (WHTEFFICACY * wtot * rh_dom[near_patch[i]]);
638 <                *pdest++ += val_add;
639 <                *pdest++ += val_add;
640 <                *pdest++ += val_add;
638 >                *pdest++ += val_add*suncolor[0];
639 >                *pdest++ += val_add*suncolor[1];
640 >                *pdest++ += val_add*suncolor[2];
641          }
642   }
643  
# Line 665 | Line 672 | rh_init(void)
672          for (i = 0; i < NROW*rhsubdiv; i++) {
673                  const float     ralt = alpha*(i + .5);
674                  const int       ninrow = tnaz[i/rhsubdiv]*rhsubdiv;
675 <                const float     dom = (sin(alpha*(i+1)) - sin(alpha*i))/ninrow;
675 >                const float     dom = 2.*PI*(sin(alpha*(i+1)) - sin(alpha*i)) /
676 >                                                (double)ninrow;
677                  for (j = 0; j < ninrow; j++) {
678                          rh_palt[p] = ralt;
679                          rh_pazi[p] = 2.*PI * j / (double)ninrow;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines