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

Comparing ray/src/util/cmbsdf.c (file contents):
Revision 2.1 by greg, Mon Jan 20 21:29:04 2014 UTC vs.
Revision 2.2 by greg, Mon Jan 20 22:18:29 2014 UTC

# Line 15 | Line 15 | static const char RCSid[] = "$Id$";
15  
16   /* Convert a BSDF to our matrix representation */
17   static CMATRIX *
18 < cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf)
18 > cm_bsdf(const COLOR diffBSDF, const COLOR specCol, const SDMat *bsdf)
19   {
20          CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc);
21          int     nbadohm = 0;
# Line 37 | Line 37 | cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, con
37                          }
38                          copycolor(mp, specCol);
39                          scalecolor(mp, f);
40 <                        addcolor(mp, bsdfLamb);
40 >                        addcolor(mp, diffBSDF);
41                          scalecolor(mp, dom);
42                  }
43          }
# Line 76 | Line 76 | recip_in_from_out(const SDMat *bsdf, int out_recip)
76  
77   /* Convert a BSDF to our matrix representation, applying reciprocity */
78   static CMATRIX *
79 < cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf)
79 > cm_bsdf_recip(const COLOR diffBSDF, const COLOR specCol, const SDMat *bsdf)
80   {
81          CMATRIX *cm = cm_alloc(bsdf->ninc, bsdf->nout);
82          int     nbadohm = 0;
# Line 100 | Line 100 | cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCo
100                          }
101                          copycolor(mp, specCol);
102                          scalecolor(mp, f);
103 <                        addcolor(mp, bsdfLamb);
103 >                        addcolor(mp, diffBSDF);
104                          scalecolor(mp, dom);
105                  }
106          }
# Line 113 | Line 113 | cm_bsdf_recip(const COLOR bsdfLamb, const COLOR specCo
113          return(cm);
114   }
115  
116 < /* Load and convert a matrix BSDF from the given XML file */
116 > /* Return a Lambertian (diffuse) matrix */
117 > static CMATRIX *
118 > cm_bsdf_Lamb(const COLOR diffBSDF)
119 > {
120 >        CMATRIX *cm = cm_alloc(145, 145);       /* this is a hack */
121 >        int     r, c;
122 >
123 >        for (c = 0; c < cm->ncols; c++)
124 >                for (r = 0; r < cm->nrows; r++) {
125 >                        COLORV  *mp = cm_lval(cm,r,c);
126 >                        copycolor(mp, diffBSDF);
127 >                }
128 >        return(cm);
129 > }
130 >
131 > /* Load and convert a matrix BTDF from the given XML file */
132   CMATRIX *
133 < cm_loadBSDF(char *fname, COLOR cLamb)
133 > cm_loadBTDF(char *fname)
134   {
135          CMATRIX         *Tmat;
136          char            *fpath;
# Line 123 | Line 138 | cm_loadBSDF(char *fname, COLOR cLamb)
138          SDError         ec;
139          SDData          myBSDF;
140          SDSpectralDF    *tdf;
141 <        COLOR           bsdfLamb, specCol;
141 >        COLOR           diffBSDF, specCol;
142                                          /* find path to BSDF file */
143          fpath = getpath(fname, getrlibpath(), R_OK);
144          if (fpath == NULL) {
# Line 134 | Line 149 | cm_loadBSDF(char *fname, COLOR cLamb)
149          ec = SDloadFile(&myBSDF, fpath);
150          if (ec)
151                  error(USER, transSDError(ec));
152 <        ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, bsdfLamb);
152 >        ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, diffBSDF);
153          recip = (myBSDF.tb == NULL);
154          tdf = recip ? myBSDF.tf : myBSDF.tb;
155          if (tdf == NULL) {              /* no non-Lambertian transmission? */
141                if (cLamb != NULL)
142                        copycolor(cLamb, bsdfLamb);
156                  SDfreeBSDF(&myBSDF);
157 <                return(NULL);
157 >                return(cm_bsdf_Lamb(diffBSDF));
158          }
159          if (tdf->ncomp != 1 || tdf->comp[0].func != &SDhandleMtx) {
160                  sprintf(errmsg, "unsupported BSDF '%s'", fpath);
# Line 149 | Line 162 | cm_loadBSDF(char *fname, COLOR cLamb)
162          }
163                                          /* convert BTDF to matrix */
164          ccy2rgb(&tdf->comp[0].cspec[0], 1., specCol);
165 <        Tmat = recip ? cm_bsdf_recip(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist)
166 <                        : cm_bsdf(bsdfLamb, specCol, (SDMat *)tdf->comp[0].dist);
154 <        if (cLamb != NULL)              /* Lambertian is included */
155 <                setcolor(cLamb, .0, .0, .0);
165 >        Tmat = recip ? cm_bsdf_recip(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist)
166 >                        : cm_bsdf(diffBSDF, specCol, (SDMat *)tdf->comp[0].dist);
167                                          /* free BSDF and return */
168          SDfreeBSDF(&myBSDF);
169          return(Tmat);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines