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.31 by greg, Wed May 31 02:41:52 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 275 | Line 276 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
276   {
277          const double    arrow_len = 1.2*bsdf_rad;
278          const double    tip_len = 0.2*bsdf_rad;
279 +        static int      cnt = 1;
280          FVECT           refl;
281          int             i;
282  
# Line 282 | Line 284 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
284          refl[1] = 2.*nrm[2]*nrm[1];
285          refl[2] = 2.*nrm[2]*nrm[2] - 1.;
286  
287 <        printf("\n# Mirror arrow\n");
288 <        printf("\nshaft_mat cylinder inc_dir\n0\n0\n7");
287 >        printf("\n# Mirror arrow #%d\n", cnt);
288 >        printf("\nshaft_mat cylinder inc_dir%d\n0\n0\n7", cnt);
289          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
290                          origin[0], origin[1], origin[2]+arrow_len,
291                          origin[0], origin[1], origin[2],
292                          arrow_rad);
293 <        printf("\nshaft_mat cylinder mir_dir\n0\n0\n7");
293 >        printf("\nshaft_mat cylinder mir_dir%d\n0\n0\n7", cnt);
294          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
295                          origin[0], origin[1], origin[2],
296                          origin[0] + arrow_len*refl[0],
297                          origin[1] + arrow_len*refl[1],
298                          origin[2] + arrow_len*refl[2],
299                          arrow_rad);
300 <        printf("\ntip_mat cone mir_tip\n0\n0\n8");
300 >        printf("\ntip_mat cone mir_tip%d\n0\n0\n8", cnt);
301          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n",
302                          origin[0] + (arrow_len-.5*tip_len)*refl[0],
303                          origin[1] + (arrow_len-.5*tip_len)*refl[1],
# Line 304 | Line 306 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
306                          origin[1] + (arrow_len+.5*tip_len)*refl[1],
307                          origin[2] + (arrow_len+.5*tip_len)*refl[2],
308                          2.*arrow_rad);
309 +        ++cnt;
310   }
311  
312   /* Put out transmitted direction arrow for the given incident vector */
# Line 312 | Line 315 | put_trans_arrow(const FVECT origin)
315   {
316          const double    arrow_len = 1.2*bsdf_rad;
317          const double    tip_len = 0.2*bsdf_rad;
318 +        static int      cnt = 1;
319          int             i;
320  
321 <        printf("\n# Transmission arrow\n");
322 <        printf("\nshaft_mat cylinder trans_dir\n0\n0\n7");
321 >        printf("\n# Transmission arrow #%d\n", cnt);
322 >        printf("\nshaft_mat cylinder trans_dir%d\n0\n0\n7", cnt);
323          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
324                          origin[0], origin[1], origin[2],
325                          origin[0], origin[1], origin[2]-arrow_len,
326                          arrow_rad);
327 <        printf("\ntip_mat cone trans_tip\n0\n0\n8");
327 >        printf("\ntip_mat cone trans_tip%d\n0\n0\n8", cnt);
328          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n",
329                          origin[0], origin[1], origin[2]-arrow_len+.5*tip_len,
330                          origin[0], origin[1], origin[2]-arrow_len-.5*tip_len,
331 <                        2.*arrow_rad);  
331 >                        2.*arrow_rad);
332 >        ++cnt;
333   }
334  
335   /* Compute rotation (x,y,z) => (xp,yp,zp) */
# Line 669 | 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 703 | 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 731 | 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 749 | 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