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

Comparing ray/src/util/wrapBSDF.c (file contents):
Revision 2.15 by greg, Fri May 29 07:16:49 2015 UTC vs.
Revision 2.23 by greg, Wed Apr 3 23:50:25 2019 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *      G. Ward         February 2015
8   */
9  
10 + #include "platform.h"
11   #include <ctype.h>
12   #include "rtio.h"
13 < #include "rtprocess.h"
13 > #include "paths.h"
14   #include "ezxml.h"
15   #include "bsdf.h"
16   #include "bsdf_m.h"
# Line 25 | Line 26 | const char     *attr_unit = "meter";
26   const char      legal_units[] = "meter|foot|inch|centimeter|millimeter";
27                                          /* system materials & geometry */
28   const char      *mgf_geometry = NULL;
29 <
29 >                                        /* comment list */
30 > #define MAXCOMM         30
31 > const char      *commlist[MAXCOMM];
32 > int             ncomm = 0;
33                                          /* angle bases */
34   enum { ABdefault=-1, ABklemsFull=0, ABklemsHalf, ABklemsQuarter,
35                  ABtensorTree3, ABtensorTree4, ABend };
# Line 48 | Line 52 | struct s_fieldID {
52   } XMLfieldID[] = {
53          {"m", 0, 1, "Manufacturer"},
54          {"n", 0, 1, "Name"},
55 +        {"d", 0, 0, "DeviceType"},
56          {"c", 0, 0, "ThermalConductivity"},
57          {"ef", 0, 0, "EmissivityFront"},
58          {"eb", 0, 0, "EmissivityBack"},
# Line 59 | Line 64 | struct s_fieldID {
64          {"\0", 0, 0, NULL}      /* terminator */
65   };
66                                          /* field assignments */
67 < #define MAXASSIGN       12
67 > #define MAXASSIGN       16
68   const char      *field_assignment[MAXASSIGN];
69   int             nfield_assign = 0;
70   #define FASEP   ';'
# Line 79 | Line 84 | struct s_dfile {
84  
85   int             ndataf = 0;             /* number of data files */
86  
87 + int             unlink_datafiles = 0;   /* unlink data files when done */
88 +
89   const char      *spectr_file[MAXFILES]; /* custom spectral curve input */
90  
91   const char      top_level_name[] = "WindowElement";
# Line 115 | Line 122 | static char    basis_definition[][256] = {
122          "\t</DataDefinition>\n",
123   };
124  
125 + /* Check that the last-added data file is unique */
126 + static int
127 + check_new_data_file()
128 + {
129 +        int     i = ndataf;
130 +
131 +        while (i-- > 0)
132 +                if ((data_file[i].spectrum == data_file[ndataf].spectrum) &
133 +                                (data_file[i].type == data_file[ndataf].type)) {
134 +                        fprintf(stderr,
135 +                                "%s: warning - ignoring duplicate component\n",
136 +                                        data_file[ndataf].fname);
137 +                        return 0;
138 +                }
139 +        return 1;
140 + }
141 +
142   /* Copy data from file descriptor to stdout and close */
143   static int
144   copy_and_close(int fd)
# Line 160 | Line 184 | input2str(const char *inpspec)
184                          fprintf(stderr, "%s: cannot open\n", inpspec);
185                          return "";
186                  }
187 < #ifndef _WIN32                          /* XXX somehow broken on Windows */
187 > #if !defined(_WIN32) && !defined(_WIN64)
188 >                                /* XXX somehow broken on Windows */
189                  len = lseek(fd, 0L, SEEK_END);
190                  if (len > 0) {
191                          lseek(fd, 0L, SEEK_SET);
# Line 388 | Line 413 | determine_angle_basis(const char *fn, ezxml_t wtl)
413   static int
414   filter_klems_matrix(FILE *fp)
415   {
391 #define MAX_COLUMNS     145
416          const char      *bn = klems_basis_name[angle_basis];
393        float           col_corr[MAX_COLUMNS];
417          int             i, j, n = nabases;
418                                          /* get angle basis */
419          while (n-- > 0)
# Line 398 | Line 421 | filter_klems_matrix(FILE *fp)
421                          break;
422          if (n < 0)
423                  return 0;
401        if (abase_list[n].nangles > MAX_COLUMNS) {
402                fputs("Internal error - too many Klems columns!\n", stderr);
403                return 0;
404        }
405                                        /* get correction factors */
406        for (j = abase_list[n].nangles; j--; )
407                col_corr[j] = 1.f / io_getohm(j, &abase_list[n]);
424                                          /* read/correct/write matrix */
425          for (i = 0; i < abase_list[n].nangles; i++) {
426 +            const double        corr = 1./io_getohm(i, &abase_list[n]);
427              for (j = 0; j < abase_list[n].nangles; j++) {
428                  double  d;
429                  if (fscanf(fp, "%lf", &d) != 1)
# Line 415 | Line 432 | filter_klems_matrix(FILE *fp)
432                          fputs("Negative BSDF data!\n", stderr);
433                          return 0;
434                  }
435 <                printf(" %.3e", d*col_corr[j]*(d > 0));
435 >                printf(" %.3e", d*corr*(d > 0));
436              }
437              fputc('\n', stdout);
438          }
# Line 425 | Line 442 | filter_klems_matrix(FILE *fp)
442                          return 0;
443                  }
444          return 1;                       /* all is good */
428 #undef MAX_COLUMNS
445   }
446  
447   /* Write out BSDF data block with surrounding tags */
# Line 586 | Line 602 | writeBSDF(const char *caller, ezxml_t fl)
602                  return 0;
603          }
604          puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
605 +        for (i = 0; i < ncomm; i++)
606 +                printf("<!-- %s -->\n", commlist[i]);
607          fflush(stdout);                         /* write previous XML info. */
608          if (write(fileno(stdout), xml, ei) != ei) {
609                  free(xml);
# Line 599 | Line 617 | writeBSDF(const char *caller, ezxml_t fl)
617          fputs(xml+ei, stdout);                  /* write trailer */
618          free(xml);                              /* free string */
619          fputc('\n', stdout);
620 <        return (fflush(stdout) == 0);
620 >        if (fflush(stdout) != 0)
621 >                return 0;
622 >                                                /* unlink data files if req. */
623 >        for (i = ndataf*(unlink_datafiles != 0); i--; )
624 >                if (data_file[i].fname != stdin_name &&
625 >                                data_file[i].fname[0] != '!')
626 >                        unlink(data_file[i].fname);
627 >        if (unlink_datafiles > 1 && mgf_geometry != NULL &&
628 >                        mgf_geometry != stdin_name &&
629 >                        mgf_geometry[0] != '!')
630 >                unlink(mgf_geometry);
631 >        return 1;
632   }
633  
634   /* Insert BSDF data into XML wrapper */
# Line 718 | Line 747 | UsageExit(const char *pname)
747          fputs("Usage: ", stderr);
748          fputs(pname, stderr);
749          fputs(" [-W][-c][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr);
750 <        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp]", stderr);
750 >        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp][-C comm]", stderr);
751          fputs(" [input.xml]\n", stderr);
752          exit(1);
753   }
# Line 763 | Line 792 | main(int argc, char *argv[])
792                          }
793                          attr_unit = argv[i];
794                          continue;
795 +                case 'U':               /* unlink data files when done */
796 +                        unlink_datafiles = 1 + (argv[i][2] == 'U');
797 +                        continue;
798                  case 'a':               /* angle basis */
799                          if (++i >= argc)
800                                  UsageExit(argv[0]);
# Line 787 | Line 819 | main(int argc, char *argv[])
819                  case 'c':               /* correct solid angle */
820                          correct_solid_angle = 1;
821                          continue;
822 +                case 'C':               /* comment */
823 +                        if (ncomm >= MAXCOMM) {
824 +                                fprintf(stderr, "%s: too many comments\n",
825 +                                                argv[0]);
826 +                                return 1;
827 +                        }
828 +                        if (strchr(argv[++i], '>') != NULL) {
829 +                                fprintf(stderr, "%s: illegal character in comment\n",
830 +                                                argv[0]);
831 +                                return 1;
832 +                        }
833 +                        commlist[ncomm++] = argv[i];
834 +                        continue;
835                  case 't':               /* transmission */
836                          if (i >= argc-1)
837                                  UsageExit(argv[0]);
# Line 807 | Line 852 | main(int argc, char *argv[])
852                          }
853                          data_file[ndataf].fname = argv[i];
854                          data_file[ndataf].spectrum = cur_spectrum;
855 <                        ndataf++;
855 >                        ndataf += check_new_data_file();
856                          continue;
857                  case 'r':               /* reflection */
858                          if (i >= argc-1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines