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.6 by greg, Sat Jan 30 17:34:17 2016 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, FVFORMAT, &idir[0], &idir[1], &idir[2]) != 3 ||
# Line 32 | Line 34 | readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt)
34                          return(0);
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 134 | Line 136 | main(int argc, char *argv[])
136                          if (SDreportError(eval_rbfcol(&sval, rbf, odir), stderr))
137                                  return(1);
138                  }
137                if (repXYZ)                     /* ensure we have CIE (x,y) */
138                        c_ccvt(&sval.spec, C_CSXY);
139  
140                  switch (outfmt) {               /* write to stdout */
141                  case 'a':
# Line 154 | Line 154 | main(int argc, char *argv[])
154                                  cieXYZ[1] = sval.cieY;
155                                  cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) /
156                                                  sval.spec.cy * sval.cieY;
157 <                                fwrite(cieXYZ, sizeof(double), 3, stdout);
157 >                                putbinary(cieXYZ, sizeof(double), 3, stdout);
158                          } else
159 <                                fwrite(&sval.cieY, sizeof(double), 1, stdout);
159 >                                putbinary(&sval.cieY, sizeof(double), 1, stdout);
160                          break;
161                  case 'f':
162                          if (repXYZ) {
# Line 165 | Line 165 | main(int argc, char *argv[])
165                                  cieXYZ[1] = sval.cieY;
166                                  cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) /
167                                                  sval.spec.cy * sval.cieY;
168 <                                fwrite(cieXYZ, sizeof(float), 3, stdout);
168 >                                putbinary(cieXYZ, sizeof(float), 3, stdout);
169                          } else {
170                                  float   cieY = sval.cieY;
171 <                                fwrite(&cieY, sizeof(float), 1, stdout);
171 >                                putbinary(&cieY, sizeof(float), 1, stdout);
172                          }
173                          break;
174                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines