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

Comparing ray/src/common/bsdf.c (file contents):
Revision 2.23 by greg, Wed Apr 20 14:44:05 2011 UTC vs.
Revision 2.32 by greg, Thu Jun 23 16:00:37 2011 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   *
11   */
12  
13 + #define _USE_MATH_DEFINES
14   #include <stdio.h>
15   #include <stdlib.h>
16 + #include <string.h>
17   #include <math.h>
18 + #include <ctype.h>
19   #include "ezxml.h"
20   #include "hilbert.h"
21   #include "bsdf.h"
# Line 106 | Line 109 | SDloadGeometry(SDData *sd, ezxml_t wdb)
109          if ((geom = ezxml_child(wdb, "Geometry")) == NULL ||
110                          (mgfstr = ezxml_txt(geom)) == NULL)
111                  return SDEnone;
112 +        while (isspace(*mgfstr))
113 +                ++mgfstr;
114 +        if (!*mgfstr)
115 +                return SDEnone;
116          if ((fmt = ezxml_attr(geom, "format")) != NULL &&
117                          strcasecmp(fmt, "MGF")) {
118                  sprintf(SDerrorDetail,
# Line 169 | Line 176 | SDloadFile(SDData *sd, const char *fname)
176                                  /* try loading variable resolution data */
177          lastErr = SDloadTre(sd, wtl);
178                                  /* check our result */
179 <        switch (lastErr) {
173 <        case SDEformat:
174 <        case SDEdata:
175 <        case SDEsupport:        /* possibly we just tried the wrong format */
179 >        if (lastErr == SDEsupport)      /* try matrix BSDF if not tree data */
180                  lastErr = SDloadMtx(sd, wtl);
181 <                break;
178 <        default:                /* variable res. OK else serious error */
179 <                break;
180 <        }
181 >                
182                                  /* done with XML file */
183          ezxml_free(fl);
184          
# Line 405 | Line 406 | SDfreeCache(const SDData *sd)
406  
407   /* Sample an individual BSDF component */
408   SDError
409 < SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec,
409 <                        double randX, SDComponent *sdc)
409 > SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc)
410   {
411          float           coef[SDmaxCh];
412          SDError         ec;
413 +        FVECT           inVec;
414          const SDCDst    *cd;
415          double          d;
416          int             n;
417                                          /* check arguments */
418 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL))
418 >        if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL))
419                  return SDEargument;
420                                          /* get cumulative distribution */
421 +        VCOPY(inVec, ioVec);
422          cd = (*sdc->func->getCDist)(inVec, sdc);
423          if (cd == NULL)
424                  return SDEmemory;
425          if (cd->cTotal <= 1e-7) {       /* anything to sample? */
426                  sv->spec = c_dfcolor;
427                  sv->cieY = .0;
428 <                memset(outVec, 0, 3*sizeof(double));
428 >                memset(ioVec, 0, 3*sizeof(double));
429                  return SDEnone;
430          }
431          sv->cieY = cd->cTotal;
432                                          /* compute sample direction */
433 <        ec = (*sdc->func->sampCDist)(outVec, randX, cd);
433 >        ec = (*sdc->func->sampCDist)(ioVec, randX, cd);
434          if (ec)
435                  return ec;
436                                          /* get BSDF color */
437 <        n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
437 >        n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
438          if (n <= 0) {
439                  strcpy(SDerrorDetail, "BSDF sample value error");
440                  return SDEinternal;
# Line 495 | Line 497 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
497          SDError         ec;
498          int             i;
499                                          /* check arguments */
500 <        if ((projSA == NULL) | (v1 == NULL))
500 >        if ((projSA == NULL) | (v1 == NULL) | (sd == NULL))
501                  return SDEargument;
502                                          /* initialize extrema */
503          switch (qflags) {
# Line 515 | Line 517 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
517                  rdf = sd->rf;
518          else
519                  rdf = sd->rb;
520 <        tdf = NULL;                     /* transmitted component? */
521 <        if (v2 != NULL && v1[2] > 0 ^ v2[2] > 0) {
522 <                rdf = NULL;
523 <                tdf = sd->tf;
524 <        }
520 >        tdf = sd->tf;
521 >        if (v2 != NULL)                 /* bidirectional? */
522 >                if (v1[2] > 0 ^ v2[2] > 0)
523 >                        rdf = NULL;
524 >                else
525 >                        tdf = NULL;
526          ec = SDEdata;                   /* run through components */
527          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
528                  ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
529 <                                                qflags, rdf->comp[i].dist);
529 >                                                qflags, &rdf->comp[i]);
530                  if (ec)
531                          return ec;
532          }
533          for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) {
534                  ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2,
535 <                                                qflags, tdf->comp[i].dist);
535 >                                                qflags, &tdf->comp[i]);
536                  if (ec)
537                          return ec;
538          }
# Line 571 | Line 574 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
574          i = (sdf != NULL) ? sdf->ncomp : 0;
575          while (i-- > 0) {
576                  nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec,
577 <                                                        sdf->comp[i].dist);
577 >                                                        &sdf->comp[i]);
578                  while (nch-- > 0) {
579                          c_cmix(&sv->spec, sv->cieY, &sv->spec,
580                                          coef[nch], &sdf->comp[i].cspec[nch]);
# Line 626 | Line 629 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
629  
630   /* Sample BSDF direction based on the given random variable */
631   SDError
632 < SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec,
630 <                        double randX, int sflags, const SDData *sd)
632 > SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd)
633   {
634          SDError         ec;
635 +        FVECT           inVec;
636          int             inFront;
637          SDSpectralDF    *rdf;
638          double          rdiff;
# Line 638 | Line 641 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
641          SDComponent     *sdc;
642          const SDCDst    **cdarr = NULL;
643                                          /* check arguments */
644 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) |
644 >        if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) |
645                          (randX < 0) | (randX >= 1.))
646                  return SDEargument;
647                                          /* whose side are we on? */
648 +        VCOPY(inVec, ioVec);
649          inFront = (inVec[2] > 0);
650                                          /* remember diffuse portions */
651          if (inFront) {
# Line 682 | Line 686 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
686          }
687          if (sv->cieY <= 1e-7) {         /* anything to sample? */
688                  sv->cieY = .0;
689 <                memset(outVec, 0, 3*sizeof(double));
689 >                memset(ioVec, 0, 3*sizeof(double));
690                  return SDEnone;
691          }
692                                          /* scale random variable */
693          randX *= sv->cieY;
694                                          /* diffuse reflection? */
695          if (randX < rdiff) {
696 <                SDdiffuseSamp(outVec, inFront, randX/rdiff);
696 >                SDdiffuseSamp(ioVec, inFront, randX/rdiff);
697                  goto done;
698          }
699          randX -= rdiff;
# Line 697 | Line 701 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
701          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) {
702                  if (randX < sd->tLamb.cieY) {
703                          sv->spec = sd->tLamb.spec;
704 <                        SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY);
704 >                        SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY);
705                          goto done;
706                  }
707                  randX -= sd->tLamb.cieY;
# Line 709 | Line 713 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
713                  return SDEinternal;
714                                          /* compute sample direction */
715          sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr];
716 <        ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]);
716 >        ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]);
717          if (ec)
718                  return ec;
719                                          /* compute color */
720 <        j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
720 >        j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
721          if (j <= 0) {
722                  sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
723                                  sd->name);
# Line 810 | Line 814 | SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT i
814  
815   #include "standard.h"
816   #include "paths.h"
813 #include <ctype.h>
817  
818   #define MAXLATS         46              /* maximum number of latitudes */
819  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines