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

Comparing ray/src/common/bsdf_m.c (file contents):
Revision 3.4 by greg, Sat Feb 19 01:48:59 2011 UTC vs.
Revision 3.8 by greg, Thu Feb 24 20:14:26 2011 UTC

# Line 157 | Line 157 | SDnewMatrix(int ni, int no)
157   /* Free a BSDF matrix */
158   #define SDfreeMatrix            free
159  
160 < /* get vector for this angle basis index */
160 > /* get vector for this angle basis index (front exiting) */
161   static int
162 < ab_getvec(FVECT v, int ndx, double randX, void *p)
162 > fo_getvec(FVECT v, int ndx, double randX, void *p)
163   {
164          ANGLE_BASIS  *ab = (ANGLE_BASIS *)p;
165          double          rx[2];
# Line 181 | Line 181 | ab_getvec(FVECT v, int ndx, double randX, void *p)
181          return RC_GOOD;
182   }
183  
184 < /* get index corresponding to the given vector */
184 > /* get index corresponding to the given vector (front exiting) */
185   static int
186 < ab_getndx(const FVECT v, void *p)
186 > fo_getndx(const FVECT v, void *p)
187   {
188          ANGLE_BASIS  *ab = (ANGLE_BASIS *)p;
189          int     li, ndx;
# Line 210 | Line 210 | ab_getndx(const FVECT v, void *p)
210   /* compute square of real value */
211   static double sq(double x) { return x*x; }
212  
213 < /* get projected solid angle for this angle basis index */
213 > /* get projected solid angle for this angle basis index (universal) */
214   static double
215 < ab_getohm(int ndx, void *p)
215 > io_getohm(int ndx, void *p)
216   {
217          static int      last_li = -1;
218          static double   last_ohm;
# Line 235 | Line 235 | ab_getohm(int ndx, void *p)
235                                  (double)ab->lat[li].nphis;
236   }
237  
238 < /* get reverse vector for this angle basis index */
238 > /* get vector for this angle basis index (back incident) */
239   static int
240 < ab_getvecR(FVECT v, int ndx, double randX, void *p)
240 > bi_getvec(FVECT v, int ndx, double randX, void *p)
241   {
242 <        int     na = (*(ANGLE_BASIS *)p).nangles;
243 <
244 <        if (!ab_getvec(v, ndx, randX, p))
242 >        if (!fo_getvec(v, ndx, randX, p))
243                  return RC_FAIL;
244  
245          v[0] = -v[0];
# Line 251 | Line 249 | ab_getvecR(FVECT v, int ndx, double randX, void *p)
249          return RC_GOOD;
250   }
251  
252 < /* get index corresponding to the reverse vector */
252 > /* get index corresponding to the vector (back incident) */
253   static int
254 < ab_getndxR(const FVECT v, void *p)
254 > bi_getndx(const FVECT v, void *p)
255   {
256          FVECT  v2;
257          
# Line 261 | Line 259 | ab_getndxR(const FVECT v, void *p)
259          v2[1] = -v[1];
260          v2[2] = -v[2];
261  
262 <        return ab_getndx(v2, p);
262 >        return fo_getndx(v2, p);
263   }
264  
265 + /* get vector for this angle basis index (back exiting) */
266 + static int
267 + bo_getvec(FVECT v, int ndx, double randX, void *p)
268 + {
269 +        if (!fo_getvec(v, ndx, randX, p))
270 +                return RC_FAIL;
271 +
272 +        v[2] = -v[2];
273 +
274 +        return RC_GOOD;
275 + }
276 +
277 + /* get index corresponding to the vector (back exiting) */
278 + static int
279 + bo_getndx(const FVECT v, void *p)
280 + {
281 +        FVECT  v2;
282 +        
283 +        v2[0] = v[0];
284 +        v2[1] = v[1];
285 +        v2[2] = -v[2];
286 +
287 +        return fo_getndx(v2, p);
288 + }
289 +
290 + /* get vector for this angle basis index (front incident) */
291 + static int
292 + fi_getvec(FVECT v, int ndx, double randX, void *p)
293 + {
294 +        if (!fo_getvec(v, ndx, randX, p))
295 +                return RC_FAIL;
296 +
297 +        v[0] = -v[0];
298 +        v[1] = -v[1];
299 +
300 +        return RC_GOOD;
301 + }
302 +
303 + /* get index corresponding to the vector (front incident) */
304 + static int
305 + fi_getndx(const FVECT v, void *p)
306 + {
307 +        FVECT  v2;
308 +        
309 +        v2[0] = -v[0];
310 +        v2[1] = -v[1];
311 +        v2[2] = v[2];
312 +
313 +        return fo_getndx(v2, p);
314 + }
315 +
316   /* load custom BSDF angle basis */
317   static int
318   load_angle_basis(ezxml_t wab)
# Line 346 | Line 395 | get_extrema(SDSpectralDF *df)
395          }
396          free(ohma);
397                                          /* need incoming solid angles, too? */
398 <        if (dp->ninc < dp->nout || dp->ib_ohm != dp->ob_ohm ||
350 <                                dp->ib_priv != dp->ob_priv) {
398 >        if ((dp->ib_ohm != dp->ob_ohm) | (dp->ib_priv != dp->ob_priv)) {
399                  double  ohm;
400                  for (i = dp->ninc; i--; )
401                          if ((ohm = mBSDF_incohm(dp,i)) < df->minProjSA)
# Line 363 | Line 411 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
411          SDSpectralDF    *df;
412          SDMat           *dp;
413          char            *sdata;
414 +        int             tfront;
415          int             inbi, outbi;
416          int             i;
417                                          /* allocate BSDF component */
418          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
419 <        if (!strcasecmp(sdata, "Transmission Front")) {
419 >        /*
420 >         * Remember that front and back are reversed from WINDOW 6 orientations
421 >         */
422 >        if ((tfront = !strcasecmp(sdata, "Transmission Back")) ||
423 >                        (sd->tf == NULL &&
424 >                                !strcasecmp(sdata, "Transmission Front"))) {
425                  if (sd->tf != NULL)
426                          SDfreeSpectralDF(sd->tf);
427                  if ((sd->tf = SDnewSpectralDF(1)) == NULL)
428                          return RC_MEMERR;
429                  df = sd->tf;
430          } else if (!strcasecmp(sdata, "Reflection Front")) {
431 <                if (sd->rf != NULL)
378 <                        SDfreeSpectralDF(sd->rf);
379 <                if ((sd->rf = SDnewSpectralDF(1)) == NULL)
380 <                        return RC_MEMERR;
381 <                df = sd->rf;
382 <        } else if (!strcasecmp(sdata, "Reflection Back")) {
383 <                if (sd->rb != NULL)
431 >                if (sd->rb != NULL)     /* note back-front reversal */
432                          SDfreeSpectralDF(sd->rb);
433                  if ((sd->rb = SDnewSpectralDF(1)) == NULL)
434                          return RC_MEMERR;
435                  df = sd->rb;
436 +        } else if (!strcasecmp(sdata, "Reflection Back")) {
437 +                if (sd->rf != NULL)     /* note front-back reversal */
438 +                        SDfreeSpectralDF(sd->rf);
439 +                if ((sd->rf = SDnewSpectralDF(1)) == NULL)
440 +                        return RC_MEMERR;
441 +                df = sd->rf;
442          } else
443                  return RC_FAIL;
444          /* XXX should also check "ScatteringDataType" for consistency? */
# Line 419 | Line 473 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
473          dp = SDnewMatrix(abase_list[inbi].nangles, abase_list[outbi].nangles);
474          if (dp == NULL)
475                  return RC_MEMERR;
476 <        dp->ib_priv = (void *)&abase_list[inbi];
477 <        dp->ob_priv = (void *)&abase_list[outbi];
476 >        dp->ib_priv = &abase_list[inbi];
477 >        dp->ob_priv = &abase_list[outbi];
478          if (df == sd->tf) {
479 <                dp->ib_vec = ab_getvecR;
480 <                dp->ib_ndx = ab_getndxR;
481 <                dp->ob_vec = ab_getvec;
482 <                dp->ob_ndx = ab_getndx;
479 >                if (tfront) {
480 >                        dp->ib_vec = &fi_getvec;
481 >                        dp->ib_ndx = &fi_getndx;
482 >                        dp->ob_vec = &bo_getvec;
483 >                        dp->ob_ndx = &bo_getndx;
484 >                } else {
485 >                        dp->ib_vec = &bi_getvec;
486 >                        dp->ib_ndx = &bi_getndx;
487 >                        dp->ob_vec = &fo_getvec;
488 >                        dp->ob_ndx = &fo_getndx;
489 >                }
490          } else if (df == sd->rf) {
491 <                dp->ib_vec = ab_getvec;
492 <                dp->ib_ndx = ab_getndx;
493 <                dp->ob_vec = ab_getvec;
494 <                dp->ob_ndx = ab_getndx;
491 >                dp->ib_vec = &fi_getvec;
492 >                dp->ib_ndx = &fi_getndx;
493 >                dp->ob_vec = &fo_getvec;
494 >                dp->ob_ndx = &fo_getndx;
495          } else /* df == sd->rb */ {
496 <                dp->ib_vec = ab_getvecR;
497 <                dp->ib_ndx = ab_getndxR;
498 <                dp->ob_vec = ab_getvecR;
499 <                dp->ob_ndx = ab_getndxR;
496 >                dp->ib_vec = &bi_getvec;
497 >                dp->ib_ndx = &bi_getndx;
498 >                dp->ob_vec = &bo_getvec;
499 >                dp->ob_ndx = &bo_getndx;
500          }
501 <        dp->ib_ohm = ab_getohm;
502 <        dp->ob_ohm = ab_getohm;
501 >        dp->ib_ohm = &io_getohm;
502 >        dp->ob_ohm = &io_getohm;
503          df->comp[0].cspec[0] = c_dfcolor; /* XXX monochrome for now */
504          df->comp[0].dist = dp;
505          df->comp[0].func = &SDhandleMtx;
# Line 590 | Line 651 | static SDError
651   SDqueryMtxProjSA(double *psa, const FVECT vec, int qflags, const void *dist)
652   {
653          const SDMat     *dp = (const SDMat *)dist;
654 <
655 <        if (!(qflags & SDqueryInc+SDqueryOut))
654 >        double          inc_psa, out_psa;
655 >                                        /* check arguments */
656 >        if ((psa == NULL) | (vec == NULL) | (dp == NULL))
657                  return SDEargument;
658 <        if (qflags & SDqueryInc) {
659 <                double  inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, vec));
660 <                if (inc_psa < .0)
661 <                        return SDEinternal;
662 <                switch (qflags & SDqueryMin+SDqueryMax) {
663 <                case SDqueryMax:
664 <                        if (inc_psa > psa[0])
665 <                                psa[0] = inc_psa;
666 <                        break;
667 <                case SDqueryMin+SDqueryMax:
606 <                        if (inc_psa > psa[1])
607 <                                psa[1] = inc_psa;
608 <                        /* fall through */
609 <                case SDqueryMin:
610 <                        if (inc_psa < psa[0])
611 <                                psa[0] = inc_psa;
612 <                        break;
613 <                case 0:
658 >                                        /* get projected solid angles */
659 >        inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, vec));
660 >        out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, vec));
661 >
662 >        switch (qflags) {               /* record based on flag settings */
663 >        case SDqueryVal:
664 >                psa[0] = .0;
665 >                /* fall through */
666 >        case SDqueryMax:
667 >                if (inc_psa > psa[0])
668                          psa[0] = inc_psa;
669 <                        break;
670 <                }
669 >                if (out_psa > psa[0])
670 >                        psa[0] = out_psa;
671 >                break;
672 >        case SDqueryMin+SDqueryMax:
673 >                if (inc_psa > psa[0])
674 >                        psa[1] = inc_psa;
675 >                if (out_psa > psa[0])
676 >                        psa[1] = out_psa;
677 >                /* fall through */
678 >        case SDqueryMin:
679 >                if ((inc_psa > .0) & (inc_psa < psa[0]))
680 >                        psa[0] = inc_psa;
681 >                if ((out_psa > .0) & (out_psa < psa[0]))
682 >                        psa[0] = out_psa;
683 >                break;
684          }
685 <        if (qflags & SDqueryOut) {
686 <                double  out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, vec));
620 <                if (out_psa < .0)
621 <                        return SDEinternal;
622 <                switch (qflags & SDqueryMin+SDqueryMax) {
623 <                case SDqueryMax:
624 <                        if (out_psa > psa[0])
625 <                                psa[0] = out_psa;
626 <                        break;
627 <                case SDqueryMin+SDqueryMax:
628 <                        if (out_psa > psa[1])
629 <                                psa[1] = out_psa;
630 <                        /* fall through */
631 <                case SDqueryMin:
632 <                        if (out_psa < psa[0])
633 <                                psa[0] = out_psa;
634 <                        break;
635 <                case 0:
636 <                        psa[(qflags&SDqueryInc)!=0] = out_psa;
637 <                        break;
638 <                }
639 <        }
640 <        return SDEnone;
685 >                                        /* make sure it's legal */
686 >        return (psa[0] <= .0) ? SDEinternal : SDEnone;
687   }
688  
689   /* Compute new cumulative distribution from BSDF */
# Line 679 | Line 725 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
725          int             reverse;
726          SDMatCDst       myCD;
727          SDMatCDst       *cd, *cdlast;
728 <
729 <        if (dp == NULL)
728 >                                        /* check arguments */
729 >        if ((inVec == NULL) | (dp == NULL))
730                  return NULL;
731          memset(&myCD, 0, sizeof(myCD));
732          myCD.indx = mBSDF_incndx(dp, inVec);
# Line 735 | Line 781 | SDsampMtxCDist(FVECT outVec, double randX, const SDCDs
781          const SDMatCDst *mcd = (const SDMatCDst *)cdp;
782          const unsigned  target = randX*maxval;
783          int             i, iupper, ilower;
784 +                                        /* check arguments */
785 +        if ((outVec == NULL) | (mcd == NULL))
786 +                return SDEargument;
787                                          /* binary search to find index */
788          ilower = 0; iupper = mcd->calen;
789          while ((i = (iupper + ilower) >> 1) != ilower)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines