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

Comparing ray/src/cv/pabopto2bsdf.c (file contents):
Revision 2.27 by greg, Fri Oct 3 21:57:06 2014 UTC vs.
Revision 2.28 by greg, Fri Jan 29 16:21:56 2016 UTC

# Line 25 | Line 25 | typedef struct {
25          double          up_phi;         /* azimuth for "up" direction */
26          int             igp[2];         /* input grid position */
27          int             isDSF;          /* data is DSF (rather than BSDF)? */
28 +        int             nspec;          /* number of spectral samples */
29          long            dstart;         /* data start offset in file */
30   } PGINPUT;
31  
# Line 61 | Line 62 | init_pabopto_inp(const int i, const char *fname)
62          }
63          inpfile[i].fname = fname;
64          inpfile[i].isDSF = -1;
65 +        inpfile[i].nspec = 0;
66          inpfile[i].up_phi = 0;
67          inpfile[i].theta = inpfile[i].phi = -10001.;
68                                  /* read header information */
69          while ((c = getc(fp)) == '#' || c == EOF) {
70 <                char    typ[32];
70 >                char    typ[64];
71                  if (fgets(buf, sizeof(buf), fp) == NULL) {
72                          fputs(fname, stderr);
73                          fputs(": unexpected EOF\n", stderr);
# Line 74 | Line 76 | init_pabopto_inp(const int i, const char *fname)
76                  }
77                  if (sscanf(buf, "sample_name \"%[^\"]\"", bsdf_name) == 1)
78                          continue;
79 +                if (sscanf(buf, "colorimetry: %s", typ) == 1) {
80 +                        if (!strcasecmp(typ, "CIE-XYZ"))
81 +                                inpfile[i].nspec = 3;
82 +                        else if (!strcasecmp(typ, "CIE-Y"))
83 +                                inpfile[i].nspec = 1;
84 +                        continue;
85 +                }
86                  if (sscanf(buf, "format: theta phi %s", typ) == 1) {
87 <                        if (!strcasecmp(typ, "DSF")) {
87 >                        if (!strcasecmp(typ, "DSF"))
88                                  inpfile[i].isDSF = 1;
89 <                                continue;
81 <                        }
82 <                        if (!strcasecmp(typ, "BSDF") ||
89 >                        else if (!strcasecmp(typ, "BSDF") ||
90                                          !strcasecmp(typ, "BRDF") ||
91 <                                        !strcasecmp(typ, "BTDF")) {
91 >                                        !strcasecmp(typ, "BTDF"))
92                                  inpfile[i].isDSF = 0;
93 <                                continue;
87 <                        }
93 >                        continue;
94                  }
95                  if (sscanf(buf, "upphi %lf", &inpfile[i].up_phi) == 1)
96                          continue;
# Line 124 | Line 130 | static int
130   add_pabopto_inp(const int i)
131   {
132          FILE            *fp = fopen(inpfile[i].fname, "r");
133 <        double          theta_out, phi_out, val;
133 >        double          theta_out, phi_out, val[3];
134          int             n, c;
135          
136          if (fp == NULL || fseek(fp, inpfile[i].dstart, 0) == EOF) {
# Line 140 | Line 146 | add_pabopto_inp(const int i)
146                  fprintf(stderr, "New incident (theta,phi)=(%.1f,%.1f)\n",
147                                          inpfile[i].theta, inpfile[i].phi);
148   #endif
149 +                if (inpfile[i].nspec)
150 +                        set_spectral_samples(inpfile[i].nspec);
151                  new_bsdf_data(inpfile[i].theta, inpfile[i].phi);
152          }
153   #ifdef DEBUG
154          fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname);
155   #endif
156                                          /* read scattering data */
157 <        while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3)
157 >        while (fscanf(fp, "%lf %lf %lf", &theta_out, &phi_out, val) == 3) {
158 >                for (n = 1; n < inpfile[i].nspec; n++)
159 >                        if (fscanf(fp, "%lf", val+n) != 1) {
160 >                                fprintf(stderr, "%s: warning: unexpected EOF\n",
161 >                                                inpfile[i].fname);
162 >                                fclose(fp);
163 >                                return(1);
164 >                        }
165                  add_bsdf_data(theta_out, phi_out+90.-inpfile[i].up_phi,
166                                  val, inpfile[i].isDSF);
167 +        }
168          n = 0;
169          while ((c = getc(fp)) != EOF)
170                  n += !isspace(c);
# Line 240 | Line 256 | main(int argc, char *argv[])
256   #if 1                                           /* produce spheres at meas. */
257          puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n");
258          n = 0;
259 <        for (i = 0; i < GRIDRES; i++)
260 <            for (j = 0; j < GRIDRES; j++)
259 >        for (i = 0; i < grid_res; i++)
260 >            for (j = 0; j < grid_res; j++)
261                  if (dsf_grid[i][j].sum.n > 0) {
262                          ovec_from_pos(dir, i, j);
263                          bsdf = dsf_grid[i][j].sum.v /
# Line 272 | Line 288 | main(int argc, char *argv[])
288   #if 1                                           /* output continuous surface */
289          puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n");
290          fflush(stdout);
291 <        sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1);
291 >        sprintf(buf, "gensurf tgreen bsdf - - - %d %d", grid_res-1, grid_res-1);
292          pfp = popen(buf, "w");
293          if (pfp == NULL) {
294                  fprintf(stderr, "%s: cannot open '| %s'\n", progname, buf);
295                  return(1);
296          }
297 <        for (i = 0; i < GRIDRES; i++)
298 <            for (j = 0; j < GRIDRES; j++) {
297 >        for (i = 0; i < grid_res; i++)
298 >            for (j = 0; j < grid_res; j++) {
299                  ovec_from_pos(dir, i, j);
300                  bsdf = eval_rbfrep(dsf_list, dir);
301                  bsdf = log(bsdf + 1e-5) - min_log;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines