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.9 by greg, Sat Feb 9 00:20:24 2013 UTC vs.
Revision 2.20 by greg, Sat Aug 1 23:27:04 2015 UTC

# Line 86 | Line 86 | static const char RCSid[] = "$Id$";
86   #include <string.h>
87   #include <ctype.h>
88   #include "rtmath.h"
89 + #include "resolu.h"
90 + #include "platform.h"
91   #include "color.h"
92 + #include "resolu.h"
93  
94   char *progname;                                                         /* Program name */
95   char errmsg[128];                                                       /* Error message buffer */
# Line 108 | Line 111 | double sky_clearness;                  /* Sky clearness */
111   double solar_rad;                       /* Solar radiance */
112   double sun_zenith;                      /* Sun zenith angle (radians) */
113   int     input = 0;                              /* Input type */
114 + int     output = 0;                             /* Output type */
115  
116   extern double dmax( double, double );
117   extern double CalcAirMass();
# Line 208 | Line 212 | static const CategoryBounds SkyClearCat[8] =
212          { 1.950, 2.800 },
213          { 2.800, 4.500 },
214          { 4.500, 6.200 },
215 <        { 6.200, 12.00 }        /* Clear */
215 >        { 6.200, 12.01 }        /* Clear */
216   };
217  
218   /* Luminous efficacy model coefficients */
# Line 247 | Line 251 | static const ModelCoeff DirectLumEff[8] =
251   };
252  
253   #ifndef NSUNPATCH
254 < #define NSUNPATCH       4               /* # patches to spread sun into */
254 > #define NSUNPATCH       4               /* max. # patches to spread sun into */
255   #endif
256  
257   extern int jdate(int month, int day);
# Line 260 | Line 264 | extern double  s_latitude;
264   extern double  s_longitude;
265   extern double  s_meridian;
266  
267 + int             nsuns = NSUNPATCH;      /* number of sun patches to use */
268 + double          fixed_sun_sa = -1;      /* fixed solid angle per sun? */
269 +
270   int             verbose = 0;            /* progress reports to stderr? */
271  
272   int             outfmt = 'a';           /* output format */
# Line 288 | Line 295 | extern int     rh_init(void);
295   extern float *  resize_dmatrix(float *mtx_data, int nsteps, int npatch);
296   extern void     AddDirect(float *parr);
297  
298 +
299 + static const char *
300 + getfmtname(int fmt)
301 + {
302 +        switch (fmt) {
303 +        case 'a':
304 +                return("ascii");
305 +        case 'f':
306 +                return("float");
307 +        case 'd':
308 +                return("double");
309 +        }
310 +        return("unknown");
311 + }
312 +
313 +
314   int
315   main(int argc, char *argv[])
316   {
317          char    buf[256];
318 +        int     doheader = 1;           /* output header? */
319          double  rotation = 0;           /* site rotation (degrees) */
320          double  elevation;              /* site elevation (meters) */
321          int     dir_is_horiz;           /* direct is meas. on horizontal? */
322          float   *mtx_data = NULL;       /* our matrix data */
323          int     ntsteps = 0;            /* number of rows in matrix */
324 +        int     step_alloc = 0;
325          int     last_monthly = 0;       /* month of last report */
326          int     mo, da;                 /* month (1-12) and day (1-31) */
327          double  hr;                     /* hour (local standard time) */
# Line 316 | Line 341 | main(int argc, char *argv[])
341                  case 'v':                       /* verbose progress reports */
342                          verbose++;
343                          break;
344 +                case 'h':                       /* turn off header */
345 +                        doheader = 0;
346 +                        break;
347                  case 'o':                       /* output format */
348                          switch (argv[i][2]) {
349                          case 'f':
# Line 327 | Line 355 | main(int argc, char *argv[])
355                                  goto userr;
356                          }
357                          break;
358 +                case 'O':                       /* output type */
359 +                        switch (argv[i][2]) {
360 +                        case '0':
361 +                                output = 0;
362 +                                break;
363 +                        case '1':
364 +                                output = 1;
365 +                                break;
366 +                        default:
367 +                                goto userr;
368 +                        }
369 +                        if (argv[i][3])
370 +                                goto userr;
371 +                        break;
372                  case 'm':                       /* Reinhart subdivisions */
373                          rhsubdiv = atoi(argv[++i]);
374                          break;
# Line 350 | Line 392 | main(int argc, char *argv[])
392                                  goto userr;
393                          rotation = atof(argv[++i]);
394                          break;
395 +                case '5':                       /* 5-phase calculation */
396 +                        nsuns = 1;
397 +                        fixed_sun_sa = PI/360.*atof(argv[++i]);
398 +                        fixed_sun_sa *= fixed_sun_sa*PI;
399 +                        break;
400                  default:
401                          goto userr;
402                  }
# Line 417 | Line 464 | main(int argc, char *argv[])
464                  double          sda, sta;
465                                          /* make space for next time step */
466                  mtx_offset = 3*nskypatch*ntsteps++;
467 <                mtx_data = resize_dmatrix(mtx_data, ntsteps, nskypatch);
467 >                if (ntsteps > step_alloc) {
468 >                        step_alloc += (step_alloc>>1) + ntsteps + 7;
469 >                        mtx_data = resize_dmatrix(mtx_data, step_alloc, nskypatch);
470 >                }
471                  if (dif <= 1e-4) {
472                          memset(mtx_data+mtx_offset, 0, sizeof(float)*3*nskypatch);
473                          continue;
# Line 456 | Line 506 | main(int argc, char *argv[])
506                          break;
507                  }
508                                          /* write out matrix */
509 +        if (outfmt != 'a')
510 +                SET_FILE_BINARY(stdout);
511   #ifdef getc_unlocked
512          flockfile(stdout);
513   #endif
514          if (verbose)
515                  fprintf(stderr, "%s: writing %smatrix with %d time steps...\n",
516                                  progname, outfmt=='a' ? "" : "binary ", ntsteps);
517 +        if (doheader) {
518 +                newheader("RADIANCE", stdout);
519 +                printargs(argc, argv, stdout);
520 +                printf("LATLONG= %.8f %.8f\n", RadToDeg(s_latitude),
521 +                                        -RadToDeg(s_longitude));
522 +                printf("NROWS=%d\n", nskypatch);
523 +                printf("NCOLS=%d\n", ntsteps);
524 +                printf("NCOMP=3\n");
525 +                fputformat((char *)getfmtname(outfmt), stdout);
526 +                putchar('\n');
527 +        }
528                                          /* patches are rows (outer sort) */
529          for (i = 0; i < nskypatch; i++) {
530                  mtx_offset = 3*i;
# Line 503 | Line 566 | main(int argc, char *argv[])
566                  fprintf(stderr, "%s: done.\n", progname);
567          exit(0);
568   userr:
569 <        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",
569 >        fprintf(stderr, "Usage: %s [-v][-h][-d|-s][-r deg][-m N][-g r g b][-c r g b][-o{f|d}][-O{0|1}] [tape.wea]\n",
570                          progname);
571          exit(1);
572   fmterr:
# Line 562 | Line 625 | ComputeSky(float *parr)
625  
626                  /* Limit sky brightness */
627                  if (sky_brightness < 0.01)
628 <                        sky_brightness = 0.01;
628 >                        sky_brightness = 0.01;
629  
630                  /* Calculate illuminance */
631                  index = GetCategoryIndex();
# Line 575 | Line 638 | ComputeSky(float *parr)
638                  index = CalcSkyParamFromIllum();
639          }
640  
641 +        if (output == 1) {                      /* hack for solar radiance */
642 +                diff_illum = diff_irrad * WHTEFFICACY;
643 +                dir_illum = dir_irrad * WHTEFFICACY;
644 +        }
645 +
646          if (bright(skycolor) <= 1e-4) {                 /* 0 sky component? */
647                  memset(parr, 0, sizeof(float)*3*nskypatch);
648                  return;
# Line 595 | Line 663 | ComputeSky(float *parr)
663          /* Calculate relative horizontal illuminance */
664          norm_diff_illum = CalcRelHorzIllum(parr);
665  
666 +        /* Check for zero sky -- make uniform in that case */
667 +        if (norm_diff_illum <= FTINY) {
668 +                for (i = 1; i < nskypatch; i++)
669 +                        setcolor(parr+3*i, 1., 1., 1.);
670 +                norm_diff_illum = PI;
671 +        }
672          /* Normalization coefficient */
673          norm_diff_illum = diff_illum / norm_diff_illum;
674  
# Line 617 | Line 691 | AddDirect(float *parr)
691  
692          if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
693                  return;
694 <                                        /* identify NSUNPATCH closest patches */
695 <        for (i = NSUNPATCH; i--; )
694 >                                        /* identify nsuns closest patches */
695 >        if (nsuns > NSUNPATCH)
696 >                nsuns = NSUNPATCH;
697 >        else if (nsuns <= 0)
698 >                nsuns = 1;
699 >        for (i = nsuns; i--; )
700                  near_dprod[i] = -1.;
701          vector(svec, altitude, azimuth);
702          for (p = 1; p < nskypatch; p++) {
# Line 626 | Line 704 | AddDirect(float *parr)
704                  double  dprod;
705                  rh_vector(pvec, p);
706                  dprod = DOT(pvec, svec);
707 <                for (i = 0; i < NSUNPATCH; i++)
707 >                for (i = 0; i < nsuns; i++)
708                          if (dprod > near_dprod[i]) {
709 <                                for (j = NSUNPATCH; --j > i; ) {
709 >                                for (j = nsuns; --j > i; ) {
710                                          near_dprod[j] = near_dprod[j-1];
711                                          near_patch[j] = near_patch[j-1];
712                                  }
# Line 638 | Line 716 | AddDirect(float *parr)
716                          }
717          }
718          wtot = 0;                       /* weight by proximity */
719 <        for (i = NSUNPATCH; i--; )
719 >        for (i = nsuns; i--; )
720                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
721                                          /* add to nearest patch radiances */
722 <        for (i = NSUNPATCH; i--; ) {
722 >        for (i = nsuns; i--; ) {
723                  float   *pdest = parr + 3*near_patch[i];
724 <                float   val_add = wta[i] * dir_illum /
725 <                                (WHTEFFICACY * wtot * rh_dom[near_patch[i]]);
724 >                float   val_add = wta[i] * dir_illum / (WHTEFFICACY * wtot);
725 >
726 >                val_add /= (fixed_sun_sa > 0)   ? fixed_sun_sa
727 >                                                : rh_dom[near_patch[i]] ;
728                  *pdest++ += val_add*suncolor[0];
729                  *pdest++ += val_add*suncolor[1];
730                  *pdest++ += val_add*suncolor[2];
# Line 788 | Line 868 | double CalcSkyClearness()
868          double sz_cubed;        /* Sun zenith angle cubed */
869  
870          /* Calculate sun zenith angle cubed */
871 <        sz_cubed = pow(sun_zenith, 3.0);
871 >        sz_cubed = sun_zenith*sun_zenith*sun_zenith;
872  
873          return ((diff_irrad + dir_irrad) / diff_irrad + 1.041 *
874                          sz_cubed) / (1.0 + 1.041 * sz_cubed);
# Line 819 | Line 899 | double CalcDiffuseIrradiance()
899   double CalcDirectIrradiance()
900   {
901          return CalcDiffuseIrradiance() * ((sky_clearness - 1.0) * (1 + 1.041
902 <                        * pow(sun_zenith, 3.0)));
902 >                        * sun_zenith*sun_zenith*sun_zenith));
903   }
904  
905   /* Calculate sky brightness and clearness from illuminance values */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines