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.11 by greg, Sat Dec 28 18:05:14 2019 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   */
12  
13   #define _USE_MATH_DEFINES
13 #include <stdio.h>
14 #include <string.h>
14   #include <stdlib.h>
15   #include "rtmath.h"
16 + #include "rtio.h"
17   #include "bsdfrep.h"
18  
19   char    *progname;
# Line 24 | Line 24 | readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt)
24   {
25          double  dvec[6];
26          float   fvec[6];
27 <
27 > tryagain:
28          switch (fmt) {
29          case 'a':
30                  if (fscanf(fp, FVFORMAT, &idir[0], &idir[1], &idir[2]) != 3 ||
# Line 32 | Line 32 | readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt)
32                          return(0);
33                  break;
34          case 'd':
35 <                if (fread(dvec, sizeof(double), 6, fp) != 6)
35 >                if (getbinary(dvec, sizeof(double), 6, fp) != 6)
36                          return(0);
37                  VCOPY(idir, dvec);
38                  VCOPY(odir, dvec+3);
39                  break;
40          case 'f':
41 <                if (fread(fvec, sizeof(float), 6, fp) != 6)
41 >                if (getbinary(fvec, sizeof(float), 6, fp) != 6)
42                          return(0);
43                  VCOPY(idir, fvec);
44                  VCOPY(odir, fvec+3);
45                  break;
46          }
47          if ((normalize(idir) == 0) | (normalize(odir) == 0)) {
48 <                fprintf(stderr, "%s: zero input vector!\n", progname);
49 <                return(0);
48 >                fflush(stdout);         /* desired side-effect? */
49 >                goto tryagain;
50          }
51          return(1);
52   }
# Line 55 | Line 55 | readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt)
55   int
56   main(int argc, char *argv[])
57   {
58 +        int     unbuffered = 0;
59          int     repXYZ = 0;
60          int     inpXML = -1;
61          int     inpfmt = 'a';
# Line 68 | Line 69 | main(int argc, char *argv[])
69          progname = argv[0];
70          while (argc > 2 && argv[1][0] == '-') {
71                  switch (argv[1][1]) {
72 +                case 'u':                       /* unbuffered output */\
73 +                        unbuffered = 1;
74 +                        break;
75                  case 'c':                       /* color output */
76                          repXYZ = 1;
77                          break;
# Line 134 | Line 138 | main(int argc, char *argv[])
138                          if (SDreportError(eval_rbfcol(&sval, rbf, odir), stderr))
139                                  return(1);
140                  }
137                if (repXYZ)                     /* ensure we have CIE (x,y) */
138                        c_ccvt(&sval.spec, C_CSXY);
141  
142                  switch (outfmt) {               /* write to stdout */
143                  case 'a':
# Line 154 | Line 156 | main(int argc, char *argv[])
156                                  cieXYZ[1] = sval.cieY;
157                                  cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) /
158                                                  sval.spec.cy * sval.cieY;
159 <                                fwrite(cieXYZ, sizeof(double), 3, stdout);
159 >                                putbinary(cieXYZ, sizeof(double), 3, stdout);
160                          } else
161 <                                fwrite(&sval.cieY, sizeof(double), 1, stdout);
161 >                                putbinary(&sval.cieY, sizeof(double), 1, stdout);
162                          break;
163                  case 'f':
164                          if (repXYZ) {
# Line 165 | Line 167 | main(int argc, char *argv[])
167                                  cieXYZ[1] = sval.cieY;
168                                  cieXYZ[2] = (1. - sval.spec.cx - sval.spec.cy) /
169                                                  sval.spec.cy * sval.cieY;
170 <                                fwrite(cieXYZ, sizeof(float), 3, stdout);
170 >                                putbinary(cieXYZ, sizeof(float), 3, stdout);
171                          } else {
172                                  float   cieY = sval.cieY;
173 <                                fwrite(&cieY, sizeof(float), 1, stdout);
173 >                                putbinary(&cieY, sizeof(float), 1, stdout);
174                          }
175                          break;
176                  }
177 +                if (unbuffered)
178 +                        fflush(stdout);
179          }
180          /* if (rbf != NULL) free(rbf); */
181          return(0);
182   userr:
183 <        fprintf(stderr, "Usage: %s [-c][-fio] bsdf.{sir|xml}\n", progname);
183 >        fprintf(stderr, "Usage: %s [-u][-c][-fio] bsdf.{sir|xml}\n", progname);
184          return(1);
185   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines