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

Comparing ray/src/cv/bsdf2klems.c (file contents):
Revision 2.3 by greg, Tue Apr 23 23:19:09 2013 UTC vs.
Revision 2.9 by greg, Sun Aug 11 14:32:34 2013 UTC

# Line 17 | Line 17 | static const char RCSid[] = "$Id$";
17   #include "calcomp.h"
18   #include "bsdfrep.h"
19   #include "bsdf_m.h"
20 +                                /* assumed maximum # Klems patches */
21 + #define MAXPATCHES      145
22                                  /* global argv[0] */
23   char                    *progname;
24                                  /* selected basis function name */
# Line 172 | Line 174 | eval_bsdf(const char *fname)
174                      sum = 0;                    /* average over patches */
175                      for (n = npsamps; n-- > 0; ) {
176                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
177 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
177 >                        fi_getvec(vin, i+urand(n), abp);
178                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
179                          if (ec != SDEnone)
180                                  goto err;
# Line 193 | Line 195 | eval_bsdf(const char *fname)
195                      sum = 0;                    /* average over patches */
196                      for (n = npsamps; n-- > 0; ) {
197                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
198 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
198 >                        bi_getvec(vin, i+urand(n), abp);
199                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
200                          if (ec != SDEnone)
201                                  goto err;
# Line 214 | Line 216 | eval_bsdf(const char *fname)
216                      sum = 0;                    /* average over patches */
217                      for (n = npsamps; n-- > 0; ) {
218                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
219 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
219 >                        fi_getvec(vin, i+urand(n), abp);
220                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
221                          if (ec != SDEnone)
222                                  goto err;
# Line 227 | Line 229 | eval_bsdf(const char *fname)
229              data_epilogue();
230          }
231                                                  /* back transmission */
232 <        if (bsd.tb != NULL) {
232 >        if ((bsd.tb != NULL) | (bsd.tf != NULL)) {
233              input_orient = -1; output_orient = 1;
234              data_prologue();
235              for (j = 0; j < abp->nangles; j++) {
236                  for (i = 0; i < abp->nangles; i++) {
237 <                    sum = 0;                    /* average over patches */
237 >                    sum = 0;            /* average over patches */
238                      for (n = npsamps; n-- > 0; ) {
239                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
240 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
240 >                        bi_getvec(vin, i+urand(n), abp);
241                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
242                          if (ec != SDEnone)
243                                  goto err;
# Line 259 | Line 261 | static void
261   eval_function(char *funame)
262   {
263          ANGLE_BASIS     *abp = get_basis(kbasis);
264 +        int             assignD = (fundefined(funame) < 6);
265          double          iovec[6];
266          double          sum;
267          int             i, j, n;
268  
269 +        initurand(npsamps);
270          data_prologue();                        /* begin output */
271          for (j = 0; j < abp->nangles; j++) {    /* run through directions */
272              for (i = 0; i < abp->nangles; i++) {
# Line 274 | Line 278 | eval_function(char *funame)
278                          bo_getvec(iovec+3, j+(n+frandom())/npsamps, abp);
279  
280                      if (input_orient > 0)
281 <                        fi_getvec(iovec, i+(n+frandom())/npsamps, abp);
281 >                        fi_getvec(iovec, i+urand(n), abp);
282                      else
283 <                        bi_getvec(iovec, i+(n+frandom())/npsamps, abp);
283 >                        bi_getvec(iovec, i+urand(n), abp);
284  
285 +                    if (assignD) {
286 +                        varset("Dx", '=', -iovec[3]);
287 +                        varset("Dy", '=', -iovec[4]);
288 +                        varset("Dz", '=', -iovec[5]);
289 +                        ++eclock;
290 +                    }
291                      sum += funvalue(funame, 6, iovec);
292                  }
293                  printf("\t%.3e\n", sum/npsamps);
# Line 291 | Line 301 | eval_function(char *funame)
301   static void
302   eval_rbf(void)
303   {
294 #define MAXPATCHES      145
304          ANGLE_BASIS     *abp = get_basis(kbasis);
305          float           bsdfarr[MAXPATCHES*MAXPATCHES];
306          FVECT           vin, vout;
# Line 324 | Line 333 | eval_rbf(void)
333                  }
334                  bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps;
335              }
336 +            if (rbf != NULL)
337 +                free(rbf);
338          }
339          n = 0;                                  /* write out our matrix */
340          for (j = 0; j < abp->nangles; j++) {
# Line 332 | Line 343 | eval_rbf(void)
343              putchar('\n');
344          }
345          data_epilogue();                        /* finish output */
335 #undef MAXPATCHES
346   }
347  
348   /* Read in BSDF and interpolate as Klems matrix representation */
# Line 383 | Line 393 | main(int argc, char *argv[])
393                          fprintf(stderr,
394          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
395                                          progname);
396 +                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n",
397 +                                        progname);
398                          goto userr;
399                  }
400 +                ++eclock;
401                  xml_header(argc, argv);                 /* start XML output */
402                  xml_prologue(NULL);
403                  if (dofwd) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines