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.27 by greg, Wed Apr 12 04:15:08 2017 UTC vs.
Revision 2.37 by greg, Fri Feb 12 00:53:56 2021 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 40 | Line 41 | const double   sph_xoffset = 15.;
41   #define bsdf_rad        (sph_rad*.25)
42   #define arrow_rad       (bsdf_rad*.015)
43  
44 < #define FEQ(a,b)        ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7)
44 > #define set_minlog()    overall_min = (overall_min < 1e-5) ? 1e-5 : overall_min; \
45 >                                min_log10 = log10(overall_min) - .1
46  
45 #define set_minlog()    (min_log10 = log10(overall_min + 1e-5) - .1)
46
47   char    *progname;
48  
49   /* Get Fibonacci sphere vector (0 to NINCIDENT-1) */
# Line 76 | Line 76 | cvt_sposition(FVECT sp, const FVECT iv, int inc_side)
76   static char *
77   tfile_name(const char *prefix, const char *suffix, int i)
78   {
79 <        static char     buf[128];
79 >        static char     buf[256];
80  
81          if (!ourTempDir[0]) {           /* create temporary directory */
82                  mktemp(strcpy(ourTempDir,TEMPLATE));
# Line 274 | Line 274 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
274   {
275          const double    arrow_len = 1.2*bsdf_rad;
276          const double    tip_len = 0.2*bsdf_rad;
277 +        static int      cnt = 1;
278          FVECT           refl;
279          int             i;
280  
# Line 281 | Line 282 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
282          refl[1] = 2.*nrm[2]*nrm[1];
283          refl[2] = 2.*nrm[2]*nrm[2] - 1.;
284  
285 <        printf("\n# Mirror arrow\n");
286 <        printf("\narrow_mat cylinder inc_dir\n0\n0\n7");
285 >        printf("\n# Mirror arrow #%d\n", cnt);
286 >        printf("\nshaft_mat cylinder inc_dir%d\n0\n0\n7", cnt);
287          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
288                          origin[0], origin[1], origin[2]+arrow_len,
289                          origin[0], origin[1], origin[2],
290                          arrow_rad);
291 <        printf("\narrow_mat cylinder mir_dir\n0\n0\n7");
291 >        printf("\nshaft_mat cylinder mir_dir%d\n0\n0\n7", cnt);
292          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
293                          origin[0], origin[1], origin[2],
294                          origin[0] + arrow_len*refl[0],
295                          origin[1] + arrow_len*refl[1],
296                          origin[2] + arrow_len*refl[2],
297                          arrow_rad);
298 <        printf("\narrow_mat cone mir_tip\n0\n0\n8");
298 >        printf("\ntip_mat cone mir_tip%d\n0\n0\n8", cnt);
299          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n",
300                          origin[0] + (arrow_len-.5*tip_len)*refl[0],
301                          origin[1] + (arrow_len-.5*tip_len)*refl[1],
# Line 303 | Line 304 | put_mirror_arrow(const FVECT origin, const FVECT nrm)
304                          origin[1] + (arrow_len+.5*tip_len)*refl[1],
305                          origin[2] + (arrow_len+.5*tip_len)*refl[2],
306                          2.*arrow_rad);
307 +        ++cnt;
308   }
309  
310   /* Put out transmitted direction arrow for the given incident vector */
# Line 311 | Line 313 | put_trans_arrow(const FVECT origin)
313   {
314          const double    arrow_len = 1.2*bsdf_rad;
315          const double    tip_len = 0.2*bsdf_rad;
316 +        static int      cnt = 1;
317          int             i;
318  
319 <        printf("\n# Transmission arrow\n");
320 <        printf("\narrow_mat cylinder trans_dir\n0\n0\n7");
319 >        printf("\n# Transmission arrow #%d\n", cnt);
320 >        printf("\nshaft_mat cylinder trans_dir%d\n0\n0\n7", cnt);
321          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n",
322                          origin[0], origin[1], origin[2],
323                          origin[0], origin[1], origin[2]-arrow_len,
324                          arrow_rad);
325 <        printf("\narrow_mat cone trans_tip\n0\n0\n8");
325 >        printf("\ntip_mat cone trans_tip%d\n0\n0\n8", cnt);
326          printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n",
327                          origin[0], origin[1], origin[2]-arrow_len+.5*tip_len,
328                          origin[0], origin[1], origin[2]-arrow_len-.5*tip_len,
329 <                        2.*arrow_rad);  
329 >                        2.*arrow_rad);
330 >        ++cnt;
331   }
332  
333   /* Compute rotation (x,y,z) => (xp,yp,zp) */
# Line 342 | Line 346 | addrot(char *xf, const FVECT xp, const FVECT yp, const
346                  return(4);
347          }
348          theta = atan2(yp[2], zp[2]);
349 <        if (!FEQ(theta,0.0)) {
349 >        if (!FABSEQ(theta,0.0)) {
350                  sprintf(xf, " -rx %f", theta*(180./PI));
351                  while (*xf) ++xf;
352                  n += 2;
353          }
354          theta = Asin(-xp[2]);
355 <        if (!FEQ(theta,0.0)) {
355 >        if (!FABSEQ(theta,0.0)) {
356                  sprintf(xf, " -ry %f", theta*(180./PI));
357                  while (*xf) ++xf;
358                  n += 2;
359          }
360          theta = atan2(xp[1], xp[0]);
361 <        if (!FEQ(theta,0.0)) {
361 >        if (!FABSEQ(theta,0.0)) {
362                  sprintf(xf, " -rz %f", theta*(180./PI));
363                  /* while (*xf) ++xf; */
364                  n += 2;
# Line 378 | Line 382 | put_BSDFs(void)
382          printf("\n# Gensurf output corresponding to %d incident directions\n",
383                          NINCIDENT);
384  
385 <        printf("\nvoid glow arrow_glow\n0\n0\n4 1 0 1 0\n");
386 <        printf("\nvoid mixfunc arrow_mat\n4 arrow_glow void 0.25 .\n0\n0\n");
385 >        printf("\nvoid glow tip_mat\n0\n0\n4 1 0 1 0\n");
386 >        printf("\nvoid mixfunc shaft_mat\n4 tip_mat void 0.25 .\n0\n0\n");
387  
388          for (i = 0; i < NINCIDENT; i++) {
389                  get_ivector(ivec, i);
# Line 470 | Line 474 | put_matBSDF(const char *XMLfile)
474          }
475          switch (XMLfile[0]) {           /* avoid RAYPATH search */
476          case '.':
477 +        case '~':
478          CASEDIRSEP:
479                  curdir = "";
480                  break;
# Line 511 | Line 516 | put_hemispheres(void)
516          if (front_comp) {
517                  printf(
518   "\n!genrev %s Front \"R*sin(A*t)\" \"R*cos(A*t)\" %d -e \"R:%g;A:%f\" -s | xform -t %g 0 0\n",
519 <                                sph_fmat, nsegs, sph_rad, 0.495*PI, sph_xoffset);
519 >                                sph_fmat, nsegs, sph_rad, 0.5*PI, sph_xoffset);
520                  printf("\nvoid brighttext front_text\n3 helvet.fnt . FRONT\n0\n");
521                  printf("12\n\t%f %f 0\n\t%f 0 0\n\t0 %f 0\n\t.01 1 -.1\n",
522                                  -.22*sph_rad + sph_xoffset, -1.4*sph_rad,
# Line 527 | Line 532 | put_hemispheres(void)
532          if (back_comp) {
533                  printf(
534   "\n!genrev %s Back \"R*cos(A*t)\" \"R*sin(A*t)\" %d -e \"R:%g;A:%f\" -s | xform -t %g 0 0\n",
535 <                                sph_bmat, nsegs, sph_rad, 0.495*PI, -sph_xoffset);
535 >                                sph_bmat, nsegs, sph_rad, 0.5*PI, -sph_xoffset);
536                  printf("\nvoid brighttext back_text\n3 helvet.fnt . BACK\n0\n");
537                  printf("12\n\t%f %f 0\n\t%f 0 0\n\t0 %f 0\n\t.01 1 -.1\n",
538                                  -.22*sph_rad - sph_xoffset, -1.4*sph_rad,
# Line 667 | Line 672 | convert_mgf(const char *mgfdata)
672   static int
673   rbf_headline(char *s, void *p)
674   {
675 <        char    fmt[64];
675 >        char    fmt[MAXFMTLEN];
676  
677          if (formatval(fmt, s)) {
678                  if (strcmp(fmt, BSDFREP_FMT))
# Line 701 | Line 706 | int
706   main(int argc, char *argv[])
707   {
708          int     inpXML = -1;
709 +        double  myLim[2];
710          SDData  myBSDF;
711 <        int     n;
711 >        int     a, n;
712                                                  /* check arguments */
713          progname = argv[0];
714 <        if (argc > 1 && (n = strlen(argv[1])-4) > 0) {
715 <                if (!strcasecmp(argv[1]+n, ".xml"))
714 >        a = 1;
715 >        myLim[0] = -1; myLim[1] = -2;           /* specified BSDF range? */
716 >        if (argc > a+3 && argv[a][0] == '-' && argv[a][1] == 'r') {
717 >                myLim[0] = atof(argv[++a]);
718 >                myLim[1] = atof(argv[++a]);
719 >                ++a;
720 >        }
721 >        if (argc > a && (n = strlen(argv[a])-4) > 0) {
722 >                if (!strcasecmp(argv[a]+n, ".xml"))
723                          inpXML = 1;
724 <                else if (!strcasecmp(argv[1]+n, ".sir"))
724 >                else if (!strcasecmp(argv[a]+n, ".sir"))
725                          inpXML = 0;
726          }
727 <        if (inpXML < 0 || inpXML & (argc > 2)) {
728 <                fprintf(stderr, "Usage: %s bsdf.xml > output.rad\n", progname);
729 <                fprintf(stderr, "   Or: %s hemi1.sir hemi2.sir .. > output.rad\n", progname);
727 >        if (inpXML < 0 || inpXML & (argc > a+1)) {
728 >                fprintf(stderr, "Usage: %s [-r min max] bsdf.xml > output.rad\n", progname);
729 >                fprintf(stderr, "   Or: %s [-r min max] hemi1.sir hemi2.sir .. > output.rad\n", progname);
730                  return(1);
731          }
732          fputs("# ", stdout);                    /* copy our command */
733          printargs(argc, argv, stdout);
734                                                  /* evaluate BSDF */
735          if (inpXML) {
736 <                SDclearBSDF(&myBSDF, argv[1]);
737 <                if (SDreportError(SDloadFile(&myBSDF, argv[1]), stderr))
736 >                SDclearBSDF(&myBSDF, argv[a]);
737 >                if (SDreportError(SDloadFile(&myBSDF, argv[a]), stderr))
738                          return(1);
739                  if (myBSDF.rf != NULL) front_comp |= SDsampR;
740                  if (myBSDF.tf != NULL) front_comp |= SDsampT;
# Line 729 | Line 742 | main(int argc, char *argv[])
742                  if (myBSDF.tb != NULL) back_comp |= SDsampT;
743                  if (!front_comp & !back_comp) {
744                          fprintf(stderr, "%s: nothing to plot in '%s'\n",
745 <                                        progname, argv[1]);
745 >                                        progname, argv[a]);
746                          return(1);
747                  }
748 <                if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI)
749 <                        overall_min = myBSDF.rLambFront.cieY/PI;
750 <                if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI)
751 <                        overall_min = myBSDF.rLambBack.cieY/PI;
752 <                if ((front_comp|back_comp) & SDsampT &&
753 <                                myBSDF.tLamb.cieY < overall_min*PI)
754 <                        overall_min = myBSDF.tLamb.cieY/PI;
748 >                if (myLim[0] >= 0)
749 >                        overall_min = myLim[0];
750 >                else {
751 >                        if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI)
752 >                                overall_min = myBSDF.rLambFront.cieY/PI;
753 >                        if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI)
754 >                                overall_min = myBSDF.rLambBack.cieY/PI;
755 >                        if ((front_comp|back_comp) & SDsampT &&
756 >                                        myBSDF.tLamb.cieY < overall_min*PI)
757 >                                overall_min = myBSDF.tLamb.cieY/PI;
758 >                }
759                  set_minlog();
760                  if (!build_wBSDF(&myBSDF))
761                          return(1);
# Line 747 | Line 764 | main(int argc, char *argv[])
764                  else
765                          strcpy(bsdf_name, myBSDF.name);
766                  strcpy(bsdf_manuf, myBSDF.makr);
767 <                put_matBSDF(argv[1]);
767 >                put_matBSDF(argv[a]);
768          } else {
769                  FILE    *fp[4];
770 <                if (argc > 5) {
771 <                        fprintf(stderr, "%s: too many input files\n", progname);
770 >                if (argc > a+4) {
771 >                        fprintf(stderr, "%s: more than 4 hemispheres!\n", progname);
772                          return(1);
773                  }
774 <                for (n = 1; n < argc; n++) {
775 <                        fp[n-1] = fopen(argv[n], "rb");
776 <                        if (fp[n-1] == NULL) {
774 >                for (n = a; n < argc; n++) {
775 >                        fp[n-a] = fopen(argv[n], "rb");
776 >                        if (fp[n-a] == NULL) {
777                                  fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n",
778                                                  progname, argv[n]);
779                                  return(1);
780                          }
781 <                        if (getheader(fp[n-1], rbf_headline, NULL) < 0) {
781 >                        if (getheader(fp[n-a], rbf_headline, NULL) < 0) {
782                                  fprintf(stderr, "%s: bad BSDF interpolant '%s'\n",
783                                                  progname, argv[n]);
784                                  return(1);
785                          }
786                  }
787 +                if (myLim[0] >= 0)
788 +                        overall_min = myLim[0];
789                  set_minlog();
790 <                for (n = 1; n < argc; n++) {
791 <                        if (fseek(fp[n-1], 0L, SEEK_SET) < 0) {
790 >                for (n = a; n < argc; n++) {
791 >                        if (fseek(fp[n-a], 0L, SEEK_SET) < 0) {
792                                  fprintf(stderr, "%s: cannot seek on '%s'\n",
793                                                  progname, argv[n]);
794                                  return(1);
795                          }
796 <                        if (!load_bsdf_rep(fp[n-1]))
796 >                        if (!load_bsdf_rep(fp[n-a]))
797                                  return(1);
798 <                        fclose(fp[n-1]);
798 >                        fclose(fp[n-a]);
799                          if (!build_wRBF())
800                                  return(1);
801                  }
802                  put_matBSDF(NULL);
803          }
804 +        if (myLim[1] > myLim[0])        /* override maximum BSDF? */
805 +                overall_max = myLim[1];
806          put_source();                   /* before hemispheres & labels */
807          put_hemispheres();
808          put_scale();
809          if (inpXML && myBSDF.mgf)
810                  convert_mgf(myBSDF.mgf);
811 <        if (!put_BSDFs())
811 >        if (!put_BSDFs())               /* most of the output happens here */
812                  return(1);
813          cleanup_tmp();
814          return(0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines