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

Comparing ray/src/cv/bsdf2rad.c (file contents):
Revision 2.32 by greg, Thu Aug 3 19:50:12 2017 UTC vs.
Revision 2.36 by greg, Fri Jul 19 17:37:56 2019 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   *  Plot 3-D BSDF output based on scattering interpolant or XML representation
6   */
7  
8 #include <stdio.h>
9 #include <string.h>
8   #include <stdlib.h>
9 + #include "rtio.h"
10   #include "paths.h"
11   #include "rtmath.h"
13 #include "resolu.h"
12   #include "bsdfrep.h"
13  
14 + #ifndef NINCIDENT
15   #define NINCIDENT       37              /* number of samples/hemisphere */
16 <
16 > #endif
17 > #ifndef GRIDSTEP
18   #define GRIDSTEP        2               /* our grid step size */
19 + #endif
20   #define SAMPRES         (GRIDRES/GRIDSTEP)
21  
22   int     front_comp = 0;                 /* front component flags (SDsamp*) */
# Line 24 | Line 25 | double overall_min = 1./PI;            /* overall minimum BSDF v
25   double  min_log10;                      /* smallest log10 value for plotting */
26   double  overall_max = .0;               /* overall maximum BSDF value */
27  
28 < char    ourTempDir[TEMPLEN] = "";       /* our temporary directory */
28 > char    ourTempDir[TEMPLEN+1] = "";     /* our temporary directory */
29  
30   const char      frpref[] = "rf";
31   const char      ftpref[] = "tf";
# Line 77 | Line 78 | cvt_sposition(FVECT sp, const FVECT iv, int inc_side)
78   static char *
79   tfile_name(const char *prefix, const char *suffix, int i)
80   {
81 <        static char     buf[128];
81 >        static char     buf[256];
82  
83          if (!ourTempDir[0]) {           /* create temporary directory */
84                  mktemp(strcpy(ourTempDir,TEMPLATE));
# Line 673 | Line 674 | convert_mgf(const char *mgfdata)
674   static int
675   rbf_headline(char *s, void *p)
676   {
677 <        char    fmt[64];
677 >        char    fmt[MAXFMTLEN];
678  
679          if (formatval(fmt, s)) {
680                  if (strcmp(fmt, BSDFREP_FMT))
# Line 707 | Line 708 | int
708   main(int argc, char *argv[])
709   {
710          int     inpXML = -1;
711 +        double  myLim[2];
712          SDData  myBSDF;
713 <        int     n;
713 >        int     a, n;
714                                                  /* check arguments */
715          progname = argv[0];
716 <        if (argc > 1 && (n = strlen(argv[1])-4) > 0) {
717 <                if (!strcasecmp(argv[1]+n, ".xml"))
716 >        a = 1;
717 >        myLim[0] = -1; myLim[1] = -2;           /* specified BSDF range? */
718 >        if (argc > a+3 && argv[a][0] == '-' && argv[a][1] == 'r') {
719 >                myLim[0] = atof(argv[++a]);
720 >                myLim[1] = atof(argv[++a]);
721 >                ++a;
722 >        }
723 >        if (argc > a && (n = strlen(argv[a])-4) > 0) {
724 >                if (!strcasecmp(argv[a]+n, ".xml"))
725                          inpXML = 1;
726 <                else if (!strcasecmp(argv[1]+n, ".sir"))
726 >                else if (!strcasecmp(argv[a]+n, ".sir"))
727                          inpXML = 0;
728          }
729 <        if (inpXML < 0 || inpXML & (argc > 2)) {
730 <                fprintf(stderr, "Usage: %s bsdf.xml > output.rad\n", progname);
731 <                fprintf(stderr, "   Or: %s hemi1.sir hemi2.sir .. > output.rad\n", progname);
729 >        if (inpXML < 0 || inpXML & (argc > a+1)) {
730 >                fprintf(stderr, "Usage: %s [-r min max] bsdf.xml > output.rad\n", progname);
731 >                fprintf(stderr, "   Or: %s [-r min max] hemi1.sir hemi2.sir .. > output.rad\n", progname);
732                  return(1);
733          }
734          fputs("# ", stdout);                    /* copy our command */
735          printargs(argc, argv, stdout);
736                                                  /* evaluate BSDF */
737          if (inpXML) {
738 <                SDclearBSDF(&myBSDF, argv[1]);
739 <                if (SDreportError(SDloadFile(&myBSDF, argv[1]), stderr))
738 >                SDclearBSDF(&myBSDF, argv[a]);
739 >                if (SDreportError(SDloadFile(&myBSDF, argv[a]), stderr))
740                          return(1);
741                  if (myBSDF.rf != NULL) front_comp |= SDsampR;
742                  if (myBSDF.tf != NULL) front_comp |= SDsampT;
# Line 735 | Line 744 | main(int argc, char *argv[])
744                  if (myBSDF.tb != NULL) back_comp |= SDsampT;
745                  if (!front_comp & !back_comp) {
746                          fprintf(stderr, "%s: nothing to plot in '%s'\n",
747 <                                        progname, argv[1]);
747 >                                        progname, argv[a]);
748                          return(1);
749                  }
750 <                if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI)
751 <                        overall_min = myBSDF.rLambFront.cieY/PI;
752 <                if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI)
753 <                        overall_min = myBSDF.rLambBack.cieY/PI;
754 <                if ((front_comp|back_comp) & SDsampT &&
755 <                                myBSDF.tLamb.cieY < overall_min*PI)
756 <                        overall_min = myBSDF.tLamb.cieY/PI;
750 >                if (myLim[0] >= 0)
751 >                        overall_min = myLim[0];
752 >                else {
753 >                        if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI)
754 >                                overall_min = myBSDF.rLambFront.cieY/PI;
755 >                        if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI)
756 >                                overall_min = myBSDF.rLambBack.cieY/PI;
757 >                        if ((front_comp|back_comp) & SDsampT &&
758 >                                        myBSDF.tLamb.cieY < overall_min*PI)
759 >                                overall_min = myBSDF.tLamb.cieY/PI;
760 >                }
761                  set_minlog();
762                  if (!build_wBSDF(&myBSDF))
763                          return(1);
# Line 753 | Line 766 | main(int argc, char *argv[])
766                  else
767                          strcpy(bsdf_name, myBSDF.name);
768                  strcpy(bsdf_manuf, myBSDF.makr);
769 <                put_matBSDF(argv[1]);
769 >                put_matBSDF(argv[a]);
770          } else {
771                  FILE    *fp[4];
772 <                if (argc > 5) {
772 >                if (argc > a+4) {
773                          fprintf(stderr, "%s: more than 4 hemispheres!\n", progname);
774                          return(1);
775                  }
776 <                for (n = 1; n < argc; n++) {
777 <                        fp[n-1] = fopen(argv[n], "rb");
778 <                        if (fp[n-1] == NULL) {
776 >                for (n = a; n < argc; n++) {
777 >                        fp[n-a] = fopen(argv[n], "rb");
778 >                        if (fp[n-a] == NULL) {
779                                  fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n",
780                                                  progname, argv[n]);
781                                  return(1);
782                          }
783 <                        if (getheader(fp[n-1], rbf_headline, NULL) < 0) {
783 >                        if (getheader(fp[n-a], rbf_headline, NULL) < 0) {
784                                  fprintf(stderr, "%s: bad BSDF interpolant '%s'\n",
785                                                  progname, argv[n]);
786                                  return(1);
787                          }
788                  }
789 +                if (myLim[0] >= 0)
790 +                        overall_min = myLim[0];
791                  set_minlog();
792 <                for (n = 1; n < argc; n++) {
793 <                        if (fseek(fp[n-1], 0L, SEEK_SET) < 0) {
792 >                for (n = a; n < argc; n++) {
793 >                        if (fseek(fp[n-a], 0L, SEEK_SET) < 0) {
794                                  fprintf(stderr, "%s: cannot seek on '%s'\n",
795                                                  progname, argv[n]);
796                                  return(1);
797                          }
798 <                        if (!load_bsdf_rep(fp[n-1]))
798 >                        if (!load_bsdf_rep(fp[n-a]))
799                                  return(1);
800 <                        fclose(fp[n-1]);
800 >                        fclose(fp[n-a]);
801                          if (!build_wRBF())
802                                  return(1);
803                  }
804                  put_matBSDF(NULL);
805          }
806 +        if (myLim[1] > myLim[0])        /* override maximum BSDF? */
807 +                overall_max = myLim[1];
808          put_source();                   /* before hemispheres & labels */
809          put_hemispheres();
810          put_scale();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines