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.34 by greg, Fri Jul 20 00:50:40 2018 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   #include "resolu.h"
14   #include "bsdfrep.h"
15  
16 + #ifndef NINCIDENT
17   #define NINCIDENT       37              /* number of samples/hemisphere */
18 <
18 > #endif
19 > #ifndef GRIDSTEP
20   #define GRIDSTEP        2               /* our grid step size */
21 + #endif
22   #define SAMPRES         (GRIDRES/GRIDSTEP)
23  
24   int     front_comp = 0;                 /* front component flags (SDsamp*) */
# Line 24 | Line 27 | double overall_min = 1./PI;            /* overall minimum BSDF v
27   double  min_log10;                      /* smallest log10 value for plotting */
28   double  overall_max = .0;               /* overall maximum BSDF value */
29  
30 < char    ourTempDir[TEMPLEN] = "";       /* our temporary directory */
30 > char    ourTempDir[TEMPLEN+1] = "";     /* our temporary directory */
31  
32   const char      frpref[] = "rf";
33   const char      ftpref[] = "tf";
# Line 77 | Line 80 | cvt_sposition(FVECT sp, const FVECT iv, int inc_side)
80   static char *
81   tfile_name(const char *prefix, const char *suffix, int i)
82   {
83 <        static char     buf[128];
83 >        static char     buf[256];
84  
85          if (!ourTempDir[0]) {           /* create temporary directory */
86                  mktemp(strcpy(ourTempDir,TEMPLATE));
# Line 275 | Line 278 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
278   {
279          const double    arrow_len = 1.2*bsdf_rad;
280          const double    tip_len = 0.2*bsdf_rad;
281 +        static int      cnt = 1;
282          FVECT           refl;
283          int             i;
284  
# Line 282 | Line 286 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
286          refl[1] = 2.*nrm[2]*nrm[1];
287          refl[2] = 2.*nrm[2]*nrm[2] - 1.;
288  
289 <        printf("\n# Mirror arrow\n");
290 <        printf("\nshaft_mat cylinder inc_dir\n0\n0\n7");
289 >        printf("\n# Mirror arrow #%d\n", cnt);
290 >        printf("\nshaft_mat cylinder inc_dir%d\n0\n0\n7", cnt);
291          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
292                          origin[0], origin[1], origin[2]+arrow_len,
293                          origin[0], origin[1], origin[2],
294                          arrow_rad);
295 <        printf("\nshaft_mat cylinder mir_dir\n0\n0\n7");
295 >        printf("\nshaft_mat cylinder mir_dir%d\n0\n0\n7", cnt);
296          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
297                          origin[0], origin[1], origin[2],
298                          origin[0] + arrow_len*refl[0],
299                          origin[1] + arrow_len*refl[1],
300                          origin[2] + arrow_len*refl[2],
301                          arrow_rad);
302 <        printf("\ntip_mat cone mir_tip\n0\n0\n8");
302 >        printf("\ntip_mat cone mir_tip%d\n0\n0\n8", cnt);
303          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n",
304                          origin[0] + (arrow_len-.5*tip_len)*refl[0],
305                          origin[1] + (arrow_len-.5*tip_len)*refl[1],
# Line 304 | Line 308 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
308                          origin[1] + (arrow_len+.5*tip_len)*refl[1],
309                          origin[2] + (arrow_len+.5*tip_len)*refl[2],
310                          2.*arrow_rad);
311 +        ++cnt;
312   }
313  
314   /* Put out transmitted direction arrow for the given incident vector */
# Line 312 | Line 317 | put_trans_arrow(const FVECT origin)
317   {
318          const double    arrow_len = 1.2*bsdf_rad;
319          const double    tip_len = 0.2*bsdf_rad;
320 +        static int      cnt = 1;
321          int             i;
322  
323 <        printf("\n# Transmission arrow\n");
324 <        printf("\nshaft_mat cylinder trans_dir\n0\n0\n7");
323 >        printf("\n# Transmission arrow #%d\n", cnt);
324 >        printf("\nshaft_mat cylinder trans_dir%d\n0\n0\n7", cnt);
325          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
326                          origin[0], origin[1], origin[2],
327                          origin[0], origin[1], origin[2]-arrow_len,
328                          arrow_rad);
329 <        printf("\ntip_mat cone trans_tip\n0\n0\n8");
329 >        printf("\ntip_mat cone trans_tip%d\n0\n0\n8", cnt);
330          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n",
331                          origin[0], origin[1], origin[2]-arrow_len+.5*tip_len,
332                          origin[0], origin[1], origin[2]-arrow_len-.5*tip_len,
333 <                        2.*arrow_rad);  
333 >                        2.*arrow_rad);
334 >        ++cnt;
335   }
336  
337   /* Compute rotation (x,y,z) => (xp,yp,zp) */
# Line 703 | Line 710 | int
710   main(int argc, char *argv[])
711   {
712          int     inpXML = -1;
713 +        double  myLim[2];
714          SDData  myBSDF;
715 <        int     n;
715 >        int     a, n;
716                                                  /* check arguments */
717          progname = argv[0];
718 <        if (argc > 1 && (n = strlen(argv[1])-4) > 0) {
719 <                if (!strcasecmp(argv[1]+n, ".xml"))
718 >        a = 1;
719 >        myLim[0] = -1; myLim[1] = -2;           /* specified BSDF range? */
720 >        if (argc > a+3 && argv[a][0] == '-' && argv[a][1] == 'r') {
721 >                myLim[0] = atof(argv[++a]);
722 >                myLim[1] = atof(argv[++a]);
723 >                ++a;
724 >        }
725 >        if (argc > a && (n = strlen(argv[a])-4) > 0) {
726 >                if (!strcasecmp(argv[a]+n, ".xml"))
727                          inpXML = 1;
728 <                else if (!strcasecmp(argv[1]+n, ".sir"))
728 >                else if (!strcasecmp(argv[a]+n, ".sir"))
729                          inpXML = 0;
730          }
731 <        if (inpXML < 0 || inpXML & (argc > 2)) {
732 <                fprintf(stderr, "Usage: %s bsdf.xml > output.rad\n", progname);
733 <                fprintf(stderr, "   Or: %s hemi1.sir hemi2.sir .. > output.rad\n", progname);
731 >        if (inpXML < 0 || inpXML & (argc > a+1)) {
732 >                fprintf(stderr, "Usage: %s [-r min max] bsdf.xml > output.rad\n", progname);
733 >                fprintf(stderr, "   Or: %s [-r min max] hemi1.sir hemi2.sir .. > output.rad\n", progname);
734                  return(1);
735          }
736          fputs("# ", stdout);                    /* copy our command */
737          printargs(argc, argv, stdout);
738                                                  /* evaluate BSDF */
739          if (inpXML) {
740 <                SDclearBSDF(&myBSDF, argv[1]);
741 <                if (SDreportError(SDloadFile(&myBSDF, argv[1]), stderr))
740 >                SDclearBSDF(&myBSDF, argv[a]);
741 >                if (SDreportError(SDloadFile(&myBSDF, argv[a]), stderr))
742                          return(1);
743                  if (myBSDF.rf != NULL) front_comp |= SDsampR;
744                  if (myBSDF.tf != NULL) front_comp |= SDsampT;
# Line 731 | Line 746 | main(int argc, char *argv[])
746                  if (myBSDF.tb != NULL) back_comp |= SDsampT;
747                  if (!front_comp & !back_comp) {
748                          fprintf(stderr, "%s: nothing to plot in '%s'\n",
749 <                                        progname, argv[1]);
749 >                                        progname, argv[a]);
750                          return(1);
751                  }
752 <                if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI)
753 <                        overall_min = myBSDF.rLambFront.cieY/PI;
754 <                if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI)
755 <                        overall_min = myBSDF.rLambBack.cieY/PI;
756 <                if ((front_comp|back_comp) & SDsampT &&
757 <                                myBSDF.tLamb.cieY < overall_min*PI)
758 <                        overall_min = myBSDF.tLamb.cieY/PI;
752 >                if (myLim[0] >= 0)
753 >                        overall_min = myLim[0];
754 >                else {
755 >                        if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI)
756 >                                overall_min = myBSDF.rLambFront.cieY/PI;
757 >                        if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI)
758 >                                overall_min = myBSDF.rLambBack.cieY/PI;
759 >                        if ((front_comp|back_comp) & SDsampT &&
760 >                                        myBSDF.tLamb.cieY < overall_min*PI)
761 >                                overall_min = myBSDF.tLamb.cieY/PI;
762 >                }
763                  set_minlog();
764                  if (!build_wBSDF(&myBSDF))
765                          return(1);
# Line 749 | Line 768 | main(int argc, char *argv[])
768                  else
769                          strcpy(bsdf_name, myBSDF.name);
770                  strcpy(bsdf_manuf, myBSDF.makr);
771 <                put_matBSDF(argv[1]);
771 >                put_matBSDF(argv[a]);
772          } else {
773                  FILE    *fp[4];
774 <                if (argc > 5) {
774 >                if (argc > a+4) {
775                          fprintf(stderr, "%s: more than 4 hemispheres!\n", progname);
776                          return(1);
777                  }
778 <                for (n = 1; n < argc; n++) {
779 <                        fp[n-1] = fopen(argv[n], "rb");
780 <                        if (fp[n-1] == NULL) {
778 >                for (n = a; n < argc; n++) {
779 >                        fp[n-a] = fopen(argv[n], "rb");
780 >                        if (fp[n-a] == NULL) {
781                                  fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n",
782                                                  progname, argv[n]);
783                                  return(1);
784                          }
785 <                        if (getheader(fp[n-1], rbf_headline, NULL) < 0) {
785 >                        if (getheader(fp[n-a], rbf_headline, NULL) < 0) {
786                                  fprintf(stderr, "%s: bad BSDF interpolant '%s'\n",
787                                                  progname, argv[n]);
788                                  return(1);
789                          }
790                  }
791 +                if (myLim[0] >= 0)
792 +                        overall_min = myLim[0];
793                  set_minlog();
794 <                for (n = 1; n < argc; n++) {
795 <                        if (fseek(fp[n-1], 0L, SEEK_SET) < 0) {
794 >                for (n = a; n < argc; n++) {
795 >                        if (fseek(fp[n-a], 0L, SEEK_SET) < 0) {
796                                  fprintf(stderr, "%s: cannot seek on '%s'\n",
797                                                  progname, argv[n]);
798                                  return(1);
799                          }
800 <                        if (!load_bsdf_rep(fp[n-1]))
800 >                        if (!load_bsdf_rep(fp[n-a]))
801                                  return(1);
802 <                        fclose(fp[n-1]);
802 >                        fclose(fp[n-a]);
803                          if (!build_wRBF())
804                                  return(1);
805                  }
806                  put_matBSDF(NULL);
807          }
808 +        if (myLim[1] > myLim[0])        /* override maximum BSDF? */
809 +                overall_max = myLim[1];
810          put_source();                   /* before hemispheres & labels */
811          put_hemispheres();
812          put_scale();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines