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.7 by greg, Mon Oct 21 18:33:15 2013 UTC vs.
Revision 2.17 by greg, Tue Mar 18 19:08:24 2014 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14   #include <math.h>
15   #include "platform.h"
16   #include "bsdfrep.h"
17 + #include "resolu.h"
18                                  /* global argv[0] */
19   char                    *progname;
20  
# Line 24 | Line 25 | typedef struct {
25          long            dstart;         /* data start offset in file */
26   } PGINPUT;
27  
28 + const double    ANGLE_EPS = 180./2./GRIDRES;
29 +
30   PGINPUT         *inpfile;       /* input files sorted by incidence */
31   int             ninpfiles;      /* number of input files */
32  
# Line 34 | Line 37 | cmp_inang(const void *p1, const void *p2)
37          const PGINPUT   *inp1 = (const PGINPUT *)p1;
38          const PGINPUT   *inp2 = (const PGINPUT *)p2;
39          
40 <        if (inp1->theta > inp2->theta+FTINY)
40 >        if (inp1->theta > inp2->theta+ANGLE_EPS)
41                  return(1);
42 <        if (inp1->theta < inp2->theta-FTINY)
42 >        if (inp1->theta < inp2->theta-ANGLE_EPS)
43                  return(-1);
44 <        if (inp1->phi > inp2->phi+FTINY)
44 >        if (inp1->phi > inp2->phi+ANGLE_EPS)
45                  return(1);
46 <        if (inp1->phi < inp2->phi-FTINY)
46 >        if (inp1->phi < inp2->phi-ANGLE_EPS)
47                  return(-1);
48          return(0);
49   }
# Line 70 | Line 73 | init_pabopto_inp(const int i, const char *fname)
73                          fclose(fp);
74                          return(0);
75                  }
76 +                if (sscanf(buf, "sample_name \"%[^\"]\"", bsdf_name) == 1)
77 +                        continue;
78                  if (sscanf(buf, "format: theta phi %s", typ) == 1) {
79                          if (!strcasecmp(typ, "DSF")) {
80                                  inpfile[i].isDSF = 1;
# Line 145 | Line 150 | add_pabopto_inp(const int i)
150          return(1);
151   }
152  
153 < #if 1
153 > #ifndef TEST_MAIN
154   /* Read in PAB-Opto BSDF files and output RBF interpolant */
155   int
156   main(int argc, char *argv[])
# Line 214 | Line 219 | main(int argc, char *argv[])
219                  return(1);
220                                                  /* reduce data set */
221          make_rbfrep();
222 <                                                /* produce spheres at meas. */
222 > #ifdef DEBUG
223 >        fprintf(stderr, "Minimum BSDF = %.4f\n", bsdf_min);
224 > #endif
225 >        min_log = log(bsdf_min*.5 + 1e-5);
226 > #if 1                                           /* produce spheres at meas. */
227          puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n");
219        min_log = log(bsdf_min*.5);
228          n = 0;
229          for (i = 0; i < GRIDRES; i++)
230              for (j = 0; j < GRIDRES; j++)
231 <                if (dsf_grid[i][j].nval > 0) {
231 >                if (dsf_grid[i][j].sum.n > 0) {
232                          ovec_from_pos(dir, i, j);
233 <                        bsdf = dsf_grid[i][j].vsum/(dsf_grid[i][j].nval*dir[2]);
233 >                        bsdf = dsf_grid[i][j].sum.v /
234 >                                (dsf_grid[i][j].sum.n*output_orient*dir[2]);
235                          if (bsdf <= bsdf_min*.6)
236                                  continue;
237 <                        bsdf = log(bsdf) - min_log;
237 >                        bsdf = log(bsdf + 1e-5) - min_log;
238                          ovec_from_pos(dir, i, j);
239                          printf("yellow sphere s%04d\n0\n0\n", ++n);
240                          printf("4 %.6g %.6g %.6g %.6g\n\n",
241                                          dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf,
242                                          .007*bsdf);
243                  }
244 <                                                /* output continuous surface */
244 > #endif
245 > #if 1                                           /* spheres at RBF peaks */
246 >        puts("void plastic red\n0\n0\n5 .8 .01 .01 .04 .08\n");
247 >        for (n = 0; n < dsf_list->nrbf; n++) {
248 >                RBFVAL  *rbf = &dsf_list->rbfa[n];
249 >                ovec_from_pos(dir, rbf->gx, rbf->gy);
250 >                bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]);
251 >                bsdf = log(bsdf + 1e-5) - min_log;
252 >                printf("red sphere p%04d\n0\n0\n", ++n);
253 >                printf("4 %.6g %.6g %.6g %.6g\n\n",
254 >                                dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf,
255 >                                .011*bsdf);
256 >        }
257 > #endif
258 > #if 1                                           /* output continuous surface */
259          puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n");
260          fflush(stdout);
261          sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1);
262          pfp = popen(buf, "w");
263          if (pfp == NULL) {
264 <                fputs(buf, stderr);
242 <                fputs(": cannot start command\n", stderr);
264 >                fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf);
265                  return(1);
266          }
267          for (i = 0; i < GRIDRES; i++)
268              for (j = 0; j < GRIDRES; j++) {
269                  ovec_from_pos(dir, i, j);
270 <                bsdf = eval_rbfrep(dsf_list, dir) / dir[2];
271 <                bsdf = log(bsdf) - min_log;
270 >                bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]);
271 >                bsdf = log(bsdf + 1e-5) - min_log;
272                  fprintf(pfp, "%.8e %.8e %.8e\n",
273                                  dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf);
274              }
275 <        return(pclose(pfp)==0 ? 0 : 1);
275 >        if (pclose(pfp) != 0)
276 >                return(1);
277 > #endif
278 >        return(0);
279   }
280   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines