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

Comparing ray/src/cv/bsdfquery.c (file contents):
Revision 2.1 by greg, Thu Nov 21 23:57:28 2013 UTC vs.
Revision 2.9 by greg, Thu Apr 13 00:14:36 2017 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   *  Query values from the given BSDF (scattering interpolant or XML repres.)
6   *  Input query is incident and exiting vectors directed away from surface.
7   *  We normalize.  Output is a BSDF value for the vector pair.
8 + *  A zero length in or out vector is ignored, causing output to be flushed.
9   *  It is wise to sort the input directions to keep identical ones together
10   *  when using a scattering interpolant representation.
11   */
# Line 14 | Line 15 | static const char RCSid[] = "$Id$";
15   #include <string.h>
16   #include <stdlib.h>
17   #include "rtmath.h"
18 + #include "rtio.h"
19   #include "bsdfrep.h"
20  
21   char    *progname;
# Line 24 | Line 26 | readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt)
26   {
27          double  dvec[6];
28          float   fvec[6];
29 <
29 > tryagain:
30          switch (fmt) {
31          case 'a':
32 <                if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
33 <                        dvec, dvec+1, dvec+2, dvec+3, dvec+4, dvec+5) != 6)
32 >                if (fscanf(fp, FVFORMAT, &idir[0], &idir[1], &idir[2]) != 3 ||
33 >                                fscanf(fp, FVFORMAT, &odir[0], &odir[1], &odir[2]) != 3)
34                          return(0);
33                VCOPY(idir, dvec);
34                VCOPY(odir, dvec+3);
35                  break;
36          case 'd':
37 <                if (fread(dvec, sizeof(double), 6, fp) != 6)
37 >                if (getbinary(dvec, sizeof(double), 6, fp) != 6)
38                          return(0);
39                  VCOPY(idir, dvec);
40                  VCOPY(odir, dvec+3);
41                  break;
42          case 'f':
43 <                if (fread(fvec, sizeof(float), 6, fp) != 6)
43 >                if (getbinary(fvec, sizeof(float), 6, fp) != 6)
44                          return(0);
45                  VCOPY(idir, fvec);
46                  VCOPY(odir, fvec+3);
47                  break;
48          }
49          if ((normalize(idir) == 0) | (normalize(odir) == 0)) {
50 <                fprintf(stderr, "%s: zero input vector!\n", progname);
51 <                return(0);
50 >                fflush(stdout);         /* desired side-effect? */
51 >                goto tryagain;
52          }
53          return(1);
54   }
# Line 57 | Line 57 | readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt)
57   int
58   main(int argc, char *argv[])
59   {
60 +        int     repXYZ = 0;
61          int     inpXML = -1;
62          int     inpfmt = 'a';
63          int     outfmt = 'a';
# Line 67 | Line 68 | main(int argc, char *argv[])
68          int     n;
69                                                  /* check arguments */
70          progname = argv[0];
71 <        if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'f' &&
72 <                        argv[1][2] && strchr("afd", argv[1][2]) != NULL) {
73 <                inpfmt = outfmt = argv[1][2];
74 <                if (argv[1][3] && strchr("afd", argv[1][3]) != NULL)
75 <                        outfmt = argv[1][3];
71 >        while (argc > 2 && argv[1][0] == '-') {
72 >                switch (argv[1][1]) {
73 >                case 'c':                       /* color output */
74 >                        repXYZ = 1;
75 >                        break;
76 >                case 'f':                       /* i/o format */
77 >                        if (!argv[1][2] || strchr("afd", argv[1][2]) == NULL)
78 >                                goto userr;
79 >                        inpfmt = outfmt = argv[1][2];
80 >                        if (argv[1][3] && strchr("afd", argv[1][3]) != NULL)
81 >                                outfmt = argv[1][3];
82 >                        break;
83 >                default:
84 >                        goto userr;
85 >                }
86                  ++argv; --argc;
87          }
88 <        if ((n = strlen(argv[1])-4) > 0) {
88 >        if (argc > 1 && (n = strlen(argv[1])-4) > 0) {
89                  if (!strcasecmp(argv[1]+n, ".xml"))
90                          inpXML = 1;
91                  else if (!strcasecmp(argv[1]+n, ".sir"))
92                          inpXML = 0;
93          }
94 <        if (inpXML < 0) {
95 <                fprintf(stderr, "Usage: %s [-fio] bsdf.{sir|xml}\n", progname);
85 <                return(1);
86 <        }
94 >        if ((argc != 2) | (inpXML < 0))
95 >                goto userr;
96                                                  /* load BSDF representation */
97          if (inpXML) {
98                  SDclearBSDF(&myBSDF, argv[1]);
# Line 102 | Line 111 | main(int argc, char *argv[])
111          }
112                                                  /* query BSDF values */
113          while (readIOdir(idir, odir, stdin, inpfmt)) {
114 <                double  bsdf;
106 <                float   fval;
114 >                SDValue sval;
115                  if (inpXML) {
108                        SDValue sval;
116                          if (SDreportError(SDevalBSDF(&sval, odir,
117                                                  idir, &myBSDF), stderr))
118                                  return(1);
112                        bsdf = sval.cieY;
119                  } else {
120                          int32   inpDir = encodedir(idir);
121                          if (inpDir != prevInpDir) {
# Line 127 | Line 133 | main(int argc, char *argv[])
133                                                  progname);
134                                  return(1);
135                          }
136 <                        bsdf = eval_rbfrep(rbf, odir)/(output_orient*odir[2]);
136 >                        if (SDreportError(eval_rbfcol(&sval, rbf, odir), stderr))
137 >                                return(1);
138                  }
139 +
140                  switch (outfmt) {               /* write to stdout */
141                  case 'a':
142 <                        printf("%.6e\n", bsdf);
142 >                        if (repXYZ) {
143 >                                double  cieX = sval.spec.cx/sval.spec.cy*sval.cieY;
144 >                                double  cieZ = (1. - sval.spec.cx - sval.spec.cy) /
145 >                                                sval.spec.cy * sval.cieY;
146 >                                printf("%.6e %.6e %.6e\n", cieX, sval.cieY, cieZ);
147 >                        } else
148 >                                printf("%.6e\n", sval.cieY);
149                          break;
150                  case 'd':
151 <                        fwrite(&bsdf, sizeof(double), 1, stdout);
151 >                        if (repXYZ) {
152 >                                double  cieXYZ[3];
153 >                                cieXYZ[0] = sval.spec.cx/sval.spec.cy*sval.cieY;
154 >                                cieXYZ[1] = sval.cieY;
155 >                                cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) /
156 >                                                sval.spec.cy * sval.cieY;
157 >                                putbinary(cieXYZ, sizeof(double), 3, stdout);
158 >                        } else
159 >                                putbinary(&sval.cieY, sizeof(double), 1, stdout);
160                          break;
161                  case 'f':
162 <                        fval = bsdf;
163 <                        fwrite(&fval, sizeof(float), 1, stdout);
162 >                        if (repXYZ) {
163 >                                float   cieXYZ[3];
164 >                                cieXYZ[0] = sval.spec.cx/sval.spec.cy*sval.cieY;
165 >                                cieXYZ[1] = sval.cieY;
166 >                                cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) /
167 >                                                sval.spec.cy * sval.cieY;
168 >                                putbinary(cieXYZ, sizeof(float), 3, stdout);
169 >                        } else {
170 >                                float   cieY = sval.cieY;
171 >                                putbinary(&cieY, sizeof(float), 1, stdout);
172 >                        }
173                          break;
174                  }
175          }
176 +        /* if (rbf != NULL) free(rbf); */
177          return(0);
178 + userr:
179 +        fprintf(stderr, "Usage: %s [-c][-fio] bsdf.{sir|xml}\n", progname);
180 +        return(1);
181   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines