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.1 by greg, Fri Feb 18 00:40:25 2011 UTC vs.
Revision 3.4 by greg, Sat Feb 19 01:48:59 2011 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5   *  bsdf_m.c
6   *  
# Line 8 | Line 11
11   *
12   */
13  
14 < #include <stdio.h>
14 > #include "rtio.h"
15   #include <stdlib.h>
16   #include <math.h>
14 #include <strings.h>
17   #include <ctype.h>
18   #include "ezxml.h"
19   #include "bsdf.h"
20   #include "bsdf_m.h"
21  
20 #ifndef FTINY
21 #define FTINY           1e-6
22 #endif
23
22   /* Function return codes */
23   #define RC_GOOD         1
24   #define RC_FAIL         0
# Line 358 | Line 356 | get_extrema(SDSpectralDF *df)
356          return (df->maxHemi <= 1.01);
357   }
358  
361 /* skip integer in string */
362 static char *
363 i_skip(char  *s)
364 {
365        while (isspace(*s))
366                s++;
367        if (*s == '-' || *s == '+')
368                s++;
369        if (!isdigit(*s))
370                return(NULL);
371        do
372                s++;
373        while (isdigit(*s));
374        return(s);
375 }
376
377 /* skip float in string */
378 static char *
379 f_skip(char  *s)
380 {
381        register char  *cp;
382
383        while (isspace(*s))
384                s++;
385        if (*s == '-' || *s == '+')
386                s++;
387        cp = s;
388        while (isdigit(*cp))
389                cp++;
390        if (*cp == '.') {
391                cp++; s++;
392                while (isdigit(*cp))
393                        cp++;
394        }
395        if (cp == s)
396                return(NULL);
397        if (*cp == 'e' || *cp == 'E')
398                return(i_skip(cp+1));
399        return(cp);
400 }
401
359   /* load BSDF distribution for this wavelength */
360   static int
361   load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
362   {
406        char            *cbasis = ezxml_txt(ezxml_child(wdb,"ColumnAngleBasis"));
407        char            *rbasis = ezxml_txt(ezxml_child(wdb,"RowAngleBasis"));
363          SDSpectralDF    *df;
364          SDMat           *dp;
365          char            *sdata;
366          int             inbi, outbi;
367          int             i;
413
414        if ((!cbasis || !*cbasis) | (!rbasis || !*rbasis)) {
415                sprintf(SDerrorDetail, "Missing column/row basis for BSDF '%s'",
416                                sd->name);
417                return RC_FORMERR;
418        }
368                                          /* allocate BSDF component */
369          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
370          if (!strcasecmp(sdata, "Transmission Front")) {
# Line 438 | Line 387 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
387                  df = sd->rb;
388          } else
389                  return RC_FAIL;
390 +        /* XXX should also check "ScatteringDataType" for consistency? */
391                                          /* get angle bases */
392          sdata = ezxml_txt(ezxml_child(wdb,"ColumnAngleBasis"));
393          if (!sdata || !*sdata) {
# Line 446 | Line 396 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
396                  return RC_FORMERR;
397          }
398          for (inbi = nabases; inbi--; )
399 <                if (!strcasecmp(cbasis, abase_list[inbi].name))
399 >                if (!strcasecmp(sdata, abase_list[inbi].name))
400                          break;
401          if (inbi < 0) {
402 <                sprintf(SDerrorDetail, "Undefined ColumnAngleBasis '%s'",
453 <                                cbasis);
402 >                sprintf(SDerrorDetail, "Undefined ColumnAngleBasis '%s'", sdata);
403                  return RC_FORMERR;
404          }
405          sdata = ezxml_txt(ezxml_child(wdb,"RowAngleBasis"));
# Line 460 | Line 409 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
409                  return RC_FORMERR;
410          }
411          for (outbi = nabases; outbi--; )
412 <                if (!strcasecmp(rbasis, abase_list[outbi].name))
412 >                if (!strcasecmp(sdata, abase_list[outbi].name))
413                          break;
414          if (outbi < 0) {
415 <                sprintf(SDerrorDetail, "Undefined RowAngleBasis '%s'", cbasis);
415 >                sprintf(SDerrorDetail, "Undefined RowAngleBasis '%s'", sdata);
416                  return RC_FORMERR;
417          }
418                                          /* allocate BSDF matrix */
# Line 501 | Line 450 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
450                  return RC_FORMERR;
451          }
452          for (i = 0; i < dp->ninc*dp->nout; i++) {
453 <                char  *sdnext = f_skip(sdata);
453 >                char  *sdnext = fskip(sdata);
454                  if (sdnext == NULL) {
455                          sprintf(SDerrorDetail,
456                                  "Bad/missing BSDF ScatteringData in '%s'",
# Line 558 | Line 507 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
507                  c_cmix(&dv->spec, dv->cieY, &dv->spec, ymin, &df->comp[n].cspec[0]);
508                  dv->cieY += ymin;
509          }
510 <        df->maxHemi -= dv->cieY;        /* correct minimum hemispherical */
511 <        dv->spec.clock++;               /* make sure everything is set */
510 >        df->maxHemi -= dv->cieY;        /* adjust minimum hemispherical */
511 >                                        /* make sure everything is set */
512          c_ccvt(&dv->spec, C_CSXY+C_CSSPEC);
513   }
514  
515   /* Load a BSDF matrix from an open XML file */
516   SDError
517 < SDloadMtx(SDData *sd, ezxml_t fl)
517 > SDloadMtx(SDData *sd, ezxml_t wtl)
518   {
519 <        ezxml_t                 wtl, wld, wdb;
519 >        ezxml_t                 wld, wdb;
520          int                     rowIn;
521          struct BSDF_data        *dp;
522          char                    *txt;
523          int                     rval;
524          
525 <        if (strcmp(ezxml_name(fl), "WindowElement")) {
525 >        txt = ezxml_txt(ezxml_child(ezxml_child(wtl,
526 >                        "DataDefinition"), "IncidentDataStructure"));
527 >        if (txt == NULL || !*txt) {
528                  sprintf(SDerrorDetail,
529 <                        "BSDF \"%s\": top level node not 'WindowElement'",
529 >                        "BSDF \"%s\": missing IncidentDataStructure",
530                                  sd->name);
531                  return SDEformat;
532          }
582        wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer");
583        txt = ezxml_txt(ezxml_child(ezxml_child(wtl,
584                        "DataDefinition"), "IncidentDataStructure"));
533          if (!strcasecmp(txt, "Rows"))
534                  rowIn = 1;
535          else if (!strcasecmp(txt, "Columns"))
# Line 596 | Line 544 | SDloadMtx(SDData *sd, ezxml_t fl)
544          rval = load_angle_basis(ezxml_child(ezxml_child(wtl,
545                                  "DataDefinition"), "AngleBasis"));
546          if (rval < 0)
547 <                goto err_return;
547 >                return convert_errcode(rval);
548                                  /* load BSDF components */
549          for (wld = ezxml_child(wtl, "WavelengthData");
550                                  wld != NULL; wld = wld->next) {
# Line 606 | Line 554 | SDloadMtx(SDData *sd, ezxml_t fl)
554                  for (wdb = ezxml_child(wld, "WavelengthDataBlock");
555                                          wdb != NULL; wdb = wdb->next)
556                          if ((rval = load_bsdf_data(sd, wdb, rowIn)) < 0)
557 <                                goto err_return;
557 >                                return convert_errcode(rval);
558          }
559                                  /* separate diffuse components */
560          extract_diffuse(&sd->rLambFront, sd->rf);
# Line 614 | Line 562 | SDloadMtx(SDData *sd, ezxml_t fl)
562          extract_diffuse(&sd->tLamb, sd->tf);
563                                  /* return success */
564          return SDEnone;
617 err_return:                     /* jump here on failure */
618        if (sd->rf != NULL) {
619                SDfreeSpectralDF(sd->rf);
620                sd->rf = NULL;
621        }
622        if (sd->rb != NULL) {
623                SDfreeSpectralDF(sd->rb);
624                sd->rb = NULL;
625        }
626        if (sd->tf != NULL) {
627                SDfreeSpectralDF(sd->tf);
628                sd->tf = NULL;
629        }
630        return convert_errcode(rval);
565   }
566  
567   /* Get Matrix BSDF value */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines