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.5 by greg, Wed Jan 20 19:43:34 2016 UTC vs.
Revision 2.6 by greg, Sat Jan 30 17:34:17 2016 UTC

# Line 55 | Line 55 | readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt)
55   int
56   main(int argc, char *argv[])
57   {
58 +        int     repXYZ = 0;
59          int     inpXML = -1;
60          int     inpfmt = 'a';
61          int     outfmt = 'a';
# Line 65 | Line 66 | main(int argc, char *argv[])
66          int     n;
67                                                  /* check arguments */
68          progname = argv[0];
69 <        if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'f' &&
70 <                        argv[1][2] && strchr("afd", argv[1][2]) != NULL) {
71 <                inpfmt = outfmt = argv[1][2];
72 <                if (argv[1][3] && strchr("afd", argv[1][3]) != NULL)
73 <                        outfmt = argv[1][3];
69 >        while (argc > 2 && argv[1][0] == '-') {
70 >                switch (argv[1][1]) {
71 >                case 'c':                       /* color output */
72 >                        repXYZ = 1;
73 >                        break;
74 >                case 'f':                       /* i/o format */
75 >                        if (!argv[1][2] || strchr("afd", argv[1][2]) == NULL)
76 >                                goto userr;
77 >                        inpfmt = outfmt = argv[1][2];
78 >                        if (argv[1][3] && strchr("afd", argv[1][3]) != NULL)
79 >                                outfmt = argv[1][3];
80 >                        break;
81 >                default:
82 >                        goto userr;
83 >                }
84                  ++argv; --argc;
85          }
86          if (argc > 1 && (n = strlen(argv[1])-4) > 0) {
# Line 78 | Line 89 | main(int argc, char *argv[])
89                  else if (!strcasecmp(argv[1]+n, ".sir"))
90                          inpXML = 0;
91          }
92 <        if ((argc != 2) | (inpXML < 0)) {
93 <                fprintf(stderr, "Usage: %s [-fio] bsdf.{sir|xml}\n", progname);
83 <                return(1);
84 <        }
92 >        if ((argc != 2) | (inpXML < 0))
93 >                goto userr;
94                                                  /* load BSDF representation */
95          if (inpXML) {
96                  SDclearBSDF(&myBSDF, argv[1]);
# Line 100 | Line 109 | main(int argc, char *argv[])
109          }
110                                                  /* query BSDF values */
111          while (readIOdir(idir, odir, stdin, inpfmt)) {
112 <                double  bsdf;
104 <                float   fval;
112 >                SDValue sval;
113                  if (inpXML) {
106                        SDValue sval;
114                          if (SDreportError(SDevalBSDF(&sval, odir,
115                                                  idir, &myBSDF), stderr))
116                                  return(1);
110                        bsdf = sval.cieY;
117                  } else {
118                          int32   inpDir = encodedir(idir);
119                          if (inpDir != prevInpDir) {
# Line 125 | Line 131 | main(int argc, char *argv[])
131                                                  progname);
132                                  return(1);
133                          }
134 <                        bsdf = eval_rbfrep(rbf, odir);
134 >                        if (SDreportError(eval_rbfcol(&sval, rbf, odir), stderr))
135 >                                return(1);
136                  }
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':
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 >                                fwrite(cieXYZ, sizeof(double), 3, stdout);
158 >                        } else
159 >                                fwrite(&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 >                                fwrite(cieXYZ, sizeof(float), 3, stdout);
169 >                        } else {
170 >                                float   cieY = sval.cieY;
171 >                                fwrite(&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