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.22 by greg, Fri Mar 21 23:11:44 2014 UTC vs.
Revision 2.28 by greg, Fri Jan 29 16:21:56 2016 UTC

# Line 21 | Line 21 | char                   *progname;
21  
22   typedef struct {
23          const char      *fname;         /* input file path */
24 <        double          theta, phi;     /* input angles */
24 >        double          theta, phi;     /* input angles (degrees) */
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 60 | 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 72 | 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;
90 <                        }
91 <                        if (!strcasecmp(typ, "BSDF")) {
89 >                        else if (!strcasecmp(typ, "BSDF") ||
90 >                                        !strcasecmp(typ, "BRDF") ||
91 >                                        !strcasecmp(typ, "BTDF"))
92                                  inpfile[i].isDSF = 0;
93 <                                continue;
83 <                        }
93 >                        continue;
94                  }
95 +                if (sscanf(buf, "upphi %lf", &inpfile[i].up_phi) == 1)
96 +                        continue;
97                  if (sscanf(buf, "intheta %lf", &inpfile[i].theta) == 1)
98                          continue;
99                  if (sscanf(buf, "inphi %lf", &inpfile[i].phi) == 1)
# Line 102 | Line 114 | init_pabopto_inp(const int i, const char *fname)
114                  fputs(": unknown incident angle\n", stderr);
115                  return(0);
116          }
117 +                                /* convert to Y-up orientation */
118 +        inpfile[i].phi += 90.-inpfile[i].up_phi;
119                                  /* convert angle to grid position */
120          dv[2] = sin(M_PI/180.*inpfile[i].theta);
121          dv[0] = cos(M_PI/180.*inpfile[i].phi)*dv[2];
# Line 116 | 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 132 | 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)
158 <                add_bsdf_data(theta_out, phi_out, val, inpfile[i].isDSF);
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 184 | Line 209 | main(int argc, char *argv[])
209          for (i = 0; i < ninpfiles; i++)
210                  if (!init_pabopto_inp(i, argv[i+1]))
211                          return(1);
212 <        qsort(inpfile, ninpfiles, sizeof(PGINPUT), &cmp_indir);
212 >        qsort(inpfile, ninpfiles, sizeof(PGINPUT), cmp_indir);
213                                                  /* compile measurements */
214          for (i = 0; i < ninpfiles; i++)
215                  if (!add_pabopto_inp(i))
# Line 231 | 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 /
264 <                                (dsf_grid[i][j].sum.n*output_orient*dir[2]);
264 >                           ((double)dsf_grid[i][j].sum.n*output_orient*dir[2]);
265                          if (bsdf <= bsdf_min*.6)
266                                  continue;
267                          bsdf = log(bsdf + 1e-5) - min_log;
# Line 252 | Line 277 | main(int argc, char *argv[])
277          for (n = 0; n < dsf_list->nrbf; n++) {
278                  RBFVAL  *rbf = &dsf_list->rbfa[n];
279                  ovec_from_pos(dir, rbf->gx, rbf->gy);
280 <                bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]);
280 >                bsdf = eval_rbfrep(dsf_list, dir);
281                  bsdf = log(bsdf + 1e-5) - min_log;
282                  printf("red sphere p%04d\n0\n0\n", ++n);
283                  printf("4 %.6g %.6g %.6g %.6g\n\n",
# Line 263 | 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) / (output_orient*dir[2]);
300 >                bsdf = eval_rbfrep(dsf_list, dir);
301                  bsdf = log(bsdf + 1e-5) - min_log;
302                  fprintf(pfp, "%.8e %.8e %.8e\n",
303                                  dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines