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.14 by greg, Thu Apr 2 16:40:32 2015 UTC vs.
Revision 2.21 by greg, Fri Oct 14 00:54:22 2016 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 79 | Line 83 | struct s_dfile {
83  
84   int             ndataf = 0;             /* number of data files */
85  
86 + int             unlink_datafiles = 0;   /* unlink data files when done */
87 +
88   const char      *spectr_file[MAXFILES]; /* custom spectral curve input */
89  
90   const char      top_level_name[] = "WindowElement";
# Line 160 | Line 166 | input2str(const char *inpspec)
166                          fprintf(stderr, "%s: cannot open\n", inpspec);
167                          return "";
168                  }
169 < #ifndef _WIN32                          /* XXX somehow broken on Windows */
169 > #if !defined(_WIN32) && !defined(_WIN64)
170 >                                /* XXX somehow broken on Windows */
171                  len = lseek(fd, 0L, SEEK_END);
172                  if (len > 0) {
173                          lseek(fd, 0L, SEEK_SET);
# Line 388 | Line 395 | determine_angle_basis(const char *fn, ezxml_t wtl)
395   static int
396   filter_klems_matrix(FILE *fp)
397   {
391 #define MAX_COLUMNS     145
398          const char      *bn = klems_basis_name[angle_basis];
393        float           col_corr[MAX_COLUMNS];
399          int             i, j, n = nabases;
400                                          /* get angle basis */
401          while (n-- > 0)
# Line 398 | Line 403 | filter_klems_matrix(FILE *fp)
403                          break;
404          if (n < 0)
405                  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]);
406                                          /* read/correct/write matrix */
407          for (i = 0; i < abase_list[n].nangles; i++) {
408 +            const double        corr = 1./io_getohm(i, &abase_list[n]);
409              for (j = 0; j < abase_list[n].nangles; j++) {
410                  double  d;
411                  if (fscanf(fp, "%lf", &d) != 1)
# Line 415 | Line 414 | filter_klems_matrix(FILE *fp)
414                          fputs("Negative BSDF data!\n", stderr);
415                          return 0;
416                  }
417 <                printf(" %.3e", d*col_corr[j]*(d > 0));
417 >                printf(" %.3e", d*corr*(d > 0));
418              }
419              fputc('\n', stdout);
420          }
# Line 425 | Line 424 | filter_klems_matrix(FILE *fp)
424                          return 0;
425                  }
426          return 1;                       /* all is good */
428 #undef MAX_COLUMNS
427   }
428  
429   /* Write out BSDF data block with surrounding tags */
# Line 585 | Line 583 | writeBSDF(const char *caller, ezxml_t fl)
583                  free(xml);
584                  return 0;
585          }
586 +        puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
587 +        for (i = 0; i < ncomm; i++)
588 +                printf("<!-- %s -->\n", commlist[i]);
589          fflush(stdout);                         /* write previous XML info. */
590          if (write(fileno(stdout), xml, ei) != ei) {
591                  free(xml);
# Line 598 | Line 599 | writeBSDF(const char *caller, ezxml_t fl)
599          fputs(xml+ei, stdout);                  /* write trailer */
600          free(xml);                              /* free string */
601          fputc('\n', stdout);
602 <        return (fflush(stdout) == 0);
602 >        if (fflush(stdout) != 0)
603 >                return 0;
604 >                                                /* unlink data files if req. */
605 >        for (i = ndataf*(unlink_datafiles != 0); i--; )
606 >                if (data_file[i].fname != stdin_name &&
607 >                                data_file[i].fname[0] != '!')
608 >                        unlink(data_file[i].fname);
609 >        if (unlink_datafiles > 1 && mgf_geometry != NULL &&
610 >                        mgf_geometry != stdin_name &&
611 >                        mgf_geometry[0] != '!')
612 >                unlink(mgf_geometry);
613 >        return 1;
614   }
615  
616   /* Insert BSDF data into XML wrapper */
# Line 717 | Line 729 | UsageExit(const char *pname)
729          fputs("Usage: ", stderr);
730          fputs(pname, stderr);
731          fputs(" [-W][-c][-a {kf|kh|kq|t3|t4}][-u unit][-g geom][-f 'x=string;y=string']", stderr);
732 <        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp]", stderr);
732 >        fputs(" [-s spectr][-tb inp][-tf inp][-rb inp][-rf inp][-C comm]", stderr);
733          fputs(" [input.xml]\n", stderr);
734          exit(1);
735   }
# Line 762 | Line 774 | main(int argc, char *argv[])
774                          }
775                          attr_unit = argv[i];
776                          continue;
777 +                case 'U':               /* unlink data files when done */
778 +                        unlink_datafiles = 1 + (argv[i][2] == 'U');
779 +                        continue;
780                  case 'a':               /* angle basis */
781                          if (++i >= argc)
782                                  UsageExit(argv[0]);
# Line 785 | Line 800 | main(int argc, char *argv[])
800                          continue;
801                  case 'c':               /* correct solid angle */
802                          correct_solid_angle = 1;
803 +                        continue;
804 +                case 'C':               /* comment */
805 +                        if (ncomm >= MAXCOMM) {
806 +                                fprintf(stderr, "%s: too many comments\n",
807 +                                                argv[0]);
808 +                                return 1;
809 +                        }
810 +                        if (strchr(argv[++i], '>') != NULL) {
811 +                                fprintf(stderr, "%s: illegal character in comment\n",
812 +                                                argv[0]);
813 +                                return 1;
814 +                        }
815 +                        commlist[ncomm++] = argv[i];
816                          continue;
817                  case 't':               /* transmission */
818                          if (i >= argc-1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines