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.8 by greg, Fri Aug 2 20:56:19 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 152 | Line 154 | static void
154   eval_bsdf(const char *fname)
155   {
156          ANGLE_BASIS     *abp = get_basis(kbasis);
157 +        float           *trans_mtx = NULL;
158          SDData          bsd;
159          SDError         ec;
160          FVECT           vin, vout;
# Line 172 | Line 175 | eval_bsdf(const char *fname)
175                      sum = 0;                    /* average over patches */
176                      for (n = npsamps; n-- > 0; ) {
177                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
178 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
178 >                        fi_getvec(vin, i+urand(n), abp);
179                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
180                          if (ec != SDEnone)
181                                  goto err;
# Line 193 | Line 196 | eval_bsdf(const char *fname)
196                      sum = 0;                    /* average over patches */
197                      for (n = npsamps; n-- > 0; ) {
198                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
199 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
199 >                        bi_getvec(vin, i+urand(n), abp);
200                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
201                          if (ec != SDEnone)
202                                  goto err;
# Line 207 | Line 210 | eval_bsdf(const char *fname)
210          }
211                                                  /* front transmission */
212          if (bsd.tf != NULL || bsd.tLamb.cieY > .002) {
213 +            if (bsd.tb == NULL)
214 +                trans_mtx = (float *)malloc(sizeof(float) *
215 +                                                abp->nangles*abp->nangles);
216              input_orient = 1; output_orient = -1;
217              data_prologue();
218              for (j = 0; j < abp->nangles; j++) {
# Line 214 | Line 220 | eval_bsdf(const char *fname)
220                      sum = 0;                    /* average over patches */
221                      for (n = npsamps; n-- > 0; ) {
222                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
223 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
223 >                        fi_getvec(vin, i+urand(n), abp);
224                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
225                          if (ec != SDEnone)
226                                  goto err;
227                          sum += sv.cieY;
228                      }
229                      printf("\t%.3e\n", sum/npsamps);
230 +                    if (trans_mtx != NULL)
231 +                        trans_mtx[j*abp->nangles + i] = sum/npsamps;
232                  }
233                  putchar('\n');                  /* extra space between rows */
234              }
235              data_epilogue();
236          }
237                                                  /* back transmission */
238 <        if (bsd.tb != NULL) {
238 >        if (bsd.tb != NULL || trans_mtx != NULL) {
239 >            if (bsd.tf == NULL)
240 >                trans_mtx = (float *)malloc(sizeof(float) *
241 >                                                abp->nangles*abp->nangles);
242              input_orient = -1; output_orient = 1;
243              data_prologue();
244              for (j = 0; j < abp->nangles; j++) {
245 <                for (i = 0; i < abp->nangles; i++) {
246 <                    sum = 0;                    /* average over patches */
247 <                    for (n = npsamps; n-- > 0; ) {
248 <                        fo_getvec(vout, j+(n+frandom())/npsamps, abp);
249 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
250 <                        ec = SDevalBSDF(&sv, vout, vin, &bsd);
251 <                        if (ec != SDEnone)
245 >                for (i = 0; i < abp->nangles; i++)
246 >                    if (bsd.tb != NULL) {       /* use tb if we have it */
247 >                        sum = 0;                /* average over patches */
248 >                        for (n = npsamps; n-- > 0; ) {
249 >                            fo_getvec(vout, j+(n+frandom())/npsamps, abp);
250 >                            bi_getvec(vin, i+urand(n), abp);
251 >                            ec = SDevalBSDF(&sv, vout, vin, &bsd);
252 >                            if (ec != SDEnone)
253                                  goto err;
254 <                        sum += sv.cieY;
254 >                            sum += sv.cieY;
255 >                        }
256 >                        printf("\t%.3e\n", sum/npsamps);
257 >                        if (trans_mtx != NULL)
258 >                            trans_mtx[i*abp->nangles + j] = sum/npsamps;
259 >                    } else {                    /* else transpose tf */
260 >                        printf("\t%.3e\n", trans_mtx[i*abp->nangles + j]);
261                      }
244                    printf("\t%.3e\n", sum/npsamps);
245                }
262                  putchar('\n');                  /* extra space between rows */
263              }
264              data_epilogue();
265          }
266 +                                                /* derived front transmission */
267 +        if (bsd.tf == NULL && trans_mtx != NULL) {
268 +            input_orient = 1; output_orient = -1;
269 +            data_prologue();
270 +            for (j = 0; j < abp->nangles; j++) {
271 +                for (i = 0; i < abp->nangles; i++)
272 +                    printf("\t%.3e\n", trans_mtx[j*abp->nangles + i]);
273 +                putchar('\n');                  /* extra space between rows */
274 +            }
275 +            data_epilogue();
276 +        }
277          SDfreeBSDF(&bsd);                       /* all done */
278 +        if (trans_mtx != NULL)
279 +                free(trans_mtx);
280          return;
281   err:
282          SDreportError(ec, stderr);
# Line 259 | Line 288 | static void
288   eval_function(char *funame)
289   {
290          ANGLE_BASIS     *abp = get_basis(kbasis);
291 +        int             assignD = (fundefined(funame) < 6);
292          double          iovec[6];
293          double          sum;
294          int             i, j, n;
295  
296 +        initurand(npsamps);
297          data_prologue();                        /* begin output */
298          for (j = 0; j < abp->nangles; j++) {    /* run through directions */
299              for (i = 0; i < abp->nangles; i++) {
# Line 274 | Line 305 | eval_function(char *funame)
305                          bo_getvec(iovec+3, j+(n+frandom())/npsamps, abp);
306  
307                      if (input_orient > 0)
308 <                        fi_getvec(iovec, i+(n+frandom())/npsamps, abp);
308 >                        fi_getvec(iovec, i+urand(n), abp);
309                      else
310 <                        bi_getvec(iovec, i+(n+frandom())/npsamps, abp);
310 >                        bi_getvec(iovec, i+urand(n), abp);
311  
312 +                    if (assignD) {
313 +                        varset("Dx", '=', -iovec[3]);
314 +                        varset("Dy", '=', -iovec[4]);
315 +                        varset("Dz", '=', -iovec[5]);
316 +                        ++eclock;
317 +                    }
318                      sum += funvalue(funame, 6, iovec);
319                  }
320                  printf("\t%.3e\n", sum/npsamps);
# Line 291 | Line 328 | eval_function(char *funame)
328   static void
329   eval_rbf(void)
330   {
294 #define MAXPATCHES      145
331          ANGLE_BASIS     *abp = get_basis(kbasis);
332          float           bsdfarr[MAXPATCHES*MAXPATCHES];
333          FVECT           vin, vout;
# Line 324 | Line 360 | eval_rbf(void)
360                  }
361                  bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps;
362              }
363 +            if (rbf != NULL)
364 +                free(rbf);
365          }
366          n = 0;                                  /* write out our matrix */
367          for (j = 0; j < abp->nangles; j++) {
# Line 332 | Line 370 | eval_rbf(void)
370              putchar('\n');
371          }
372          data_epilogue();                        /* finish output */
335 #undef MAXPATCHES
373   }
374  
375   /* Read in BSDF and interpolate as Klems matrix representation */
# Line 383 | Line 420 | main(int argc, char *argv[])
420                          fprintf(stderr,
421          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
422                                          progname);
423 +                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n",
424 +                                        progname);
425                          goto userr;
426                  }
427 +                ++eclock;
428                  xml_header(argc, argv);                 /* start XML output */
429                  xml_prologue(NULL);
430                  if (dofwd) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines