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.8 by greg, Tue Feb 5 06:00:19 2013 UTC vs.
Revision 2.12 by greg, Thu Jun 6 20:21:10 2013 UTC

# Line 108 | Line 108 | double sky_clearness;                  /* Sky clearness */
108   double solar_rad;                       /* Solar radiance */
109   double sun_zenith;                      /* Sun zenith angle (radians) */
110   int     input = 0;                              /* Input type */
111 + int     output = 0;                             /* Output type */
112  
113   extern double dmax( double, double );
114   extern double CalcAirMass();
# Line 208 | Line 209 | static const CategoryBounds SkyClearCat[8] =
209          { 1.950, 2.800 },
210          { 2.800, 4.500 },
211          { 4.500, 6.200 },
212 <        { 6.200, 12.00 }        /* Clear */
212 >        { 6.200, 12.01 }        /* Clear */
213   };
214  
215   /* Luminous efficacy model coefficients */
# Line 247 | Line 248 | static const ModelCoeff DirectLumEff[8] =
248   };
249  
250   #ifndef NSUNPATCH
251 < #define NSUNPATCH       4               /* # patches to spread sun into */
251 > #define NSUNPATCH       4               /* max. # patches to spread sun into */
252   #endif
253  
254   extern int jdate(int month, int day);
# Line 260 | Line 261 | extern double  s_latitude;
261   extern double  s_longitude;
262   extern double  s_meridian;
263  
264 + int             nsuns = NSUNPATCH;      /* number of sun patches to use */
265 + double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
266 +
267   int             verbose = 0;            /* progress reports to stderr? */
268  
269   int             outfmt = 'a';           /* output format */
# Line 327 | Line 331 | main(int argc, char *argv[])
331                                  goto userr;
332                          }
333                          break;
334 +                case 'O':                       /* output type */
335 +                        switch (argv[i][2]) {
336 +                        case '0':
337 +                                output = 0;
338 +                                break;
339 +                        case '1':
340 +                                output = 1;
341 +                                break;
342 +                        default:
343 +                                goto userr;
344 +                        }
345 +                        if (argv[i][3])
346 +                                goto userr;
347 +                        break;
348                  case 'm':                       /* Reinhart subdivisions */
349                          rhsubdiv = atoi(argv[++i]);
350                          break;
# Line 350 | Line 368 | main(int argc, char *argv[])
368                                  goto userr;
369                          rotation = atof(argv[++i]);
370                          break;
371 +                case '5':                       /* 5-phase calculation */
372 +                        nsuns = 1;
373 +                        fixed_sun_sa = 6.797e-05;
374 +                        break;
375                  default:
376                          goto userr;
377                  }
# Line 503 | Line 525 | main(int argc, char *argv[])
525                  fprintf(stderr, "%s: done.\n", progname);
526          exit(0);
527   userr:
528 <        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",
528 >        fprintf(stderr, "Usage: %s [-v][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n",
529                          progname);
530          exit(1);
531   fmterr:
# Line 556 | Line 578 | ComputeSky(float *parr)
578                  sky_brightness = CalcSkyBrightness();
579                  sky_clearness =  CalcSkyClearness();
580  
581 +                /* Limit sky clearness */
582 +                if (sky_clearness > 11.9)
583 +                        sky_clearness = 11.9;
584 +
585 +                /* Limit sky brightness */
586 +                if (sky_brightness < 0.01)
587 +                        sky_brightness = 0.01;
588 +
589                  /* Calculate illuminance */
590                  index = GetCategoryIndex();
591                  diff_illum = diff_irrad * CalcDiffuseIllumRatio(index);
# Line 567 | Line 597 | ComputeSky(float *parr)
597                  index = CalcSkyParamFromIllum();
598          }
599  
600 +        if (output == 1) {                      /* hack for solar radiance */
601 +                diff_illum = diff_irrad * WHTEFFICACY;
602 +                dir_illum = dir_irrad * WHTEFFICACY;
603 +        }
604 +
605          if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
606                  memset(parr, 0, sizeof(float)*3*nskypatch);
607                  return;
# Line 609 | Line 644 | AddDirect(float *parr)
644  
645          if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
646                  return;
647 <                                        /* identify NSUNPATCH closest patches */
648 <        for (i = NSUNPATCH; i--; )
647 >                                        /* identify nsuns closest patches */
648 >        if (nsuns > NSUNPATCH)
649 >                nsuns = NSUNPATCH;
650 >        else if (nsuns <= 0)
651 >                nsuns = 1;
652 >        for (i = nsuns; i--; )
653                  near_dprod[i] = -1.;
654          vector(svec, altitude, azimuth);
655          for (p = 1; p < nskypatch; p++) {
# Line 618 | Line 657 | AddDirect(float *parr)
657                  double  dprod;
658                  rh_vector(pvec, p);
659                  dprod = DOT(pvec, svec);
660 <                for (i = 0; i < NSUNPATCH; i++)
660 >                for (i = 0; i < nsuns; i++)
661                          if (dprod > near_dprod[i]) {
662 <                                for (j = NSUNPATCH; --j > i; ) {
662 >                                for (j = nsuns; --j > i; ) {
663                                          near_dprod[j] = near_dprod[j-1];
664                                          near_patch[j] = near_patch[j-1];
665                                  }
# Line 630 | Line 669 | AddDirect(float *parr)
669                          }
670          }
671          wtot = 0;                       /* weight by proximity */
672 <        for (i = NSUNPATCH; i--; )
672 >        for (i = nsuns; i--; )
673                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
674                                          /* add to nearest patch radiances */
675 <        for (i = NSUNPATCH; i--; ) {
675 >        for (i = nsuns; i--; ) {
676                  float   *pdest = parr + 3*near_patch[i];
677 <                float   val_add = wta[i] * dir_illum /
678 <                                (WHTEFFICACY * wtot * rh_dom[near_patch[i]]);
677 >                float   val_add = wta[i] * dir_illum / (WHTEFFICACY * wtot);
678 >
679 >                val_add /= (fixed_sun_sa > 0)   ? fixed_sun_sa
680 >                                                : rh_dom[near_patch[i]] ;
681                  *pdest++ += val_add*suncolor[0];
682                  *pdest++ += val_add*suncolor[1];
683                  *pdest++ += val_add*suncolor[2];
# Line 780 | Line 821 | double CalcSkyClearness()
821          double sz_cubed;        /* Sun zenith angle cubed */
822  
823          /* Calculate sun zenith angle cubed */
824 <        sz_cubed = pow(sun_zenith, 3.0);
824 >        sz_cubed = sun_zenith*sun_zenith*sun_zenith;
825  
826          return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 *
827                          sz_cubed) / (1.0 + 1.041 * sz_cubed);
# Line 811 | Line 852 | double CalcDiffuseIrradiance()
852   double CalcDirectIrradiance()
853   {
854          return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041
855 <                        * pow(sun_zenith, 3.0)));
855 >                        * sun_zenith*sun_zenith*sun_zenith));
856   }
857  
858   /* Calculate sky brightness and clearness from illuminance values */
# Line 837 | Line 878 | int CalcSkyParamFromIllum()
878                  sky_clearness = 12.0;
879  
880          /* Limit sky brightness */
881 <        if (sky_brightness < 0.05)
881 >        if (sky_brightness < 0.01)
882                          sky_brightness = 0.01;
883  
884          while (((fabs(diff_irrad - test1) > 10.0) ||
# Line 861 | Line 902 | int CalcSkyParamFromIllum()
902                          sky_clearness = 12.0;
903          
904                  /* Limit sky brightness */
905 <                if (sky_brightness < 0.05)
905 >                if (sky_brightness < 0.01)
906                          sky_brightness = 0.01;
907          }
908  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines