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.3 by greg, Sat Jul 3 02:50:22 2010 UTC vs.
Revision 2.6 by greg, Fri Sep 3 23:53:50 2010 UTC

# Line 23 | Line 23 | typedef struct {
23          }       lat[MAXLATS+1];         /* latitudes */
24   } ANGLE_BASIS;
25  
26 < #define MAXABASES       5               /* limit on defined bases */
26 > #define MAXABASES       7               /* limit on defined bases */
27  
28   static ANGLE_BASIS      abase_list[MAXABASES] = {
29          {
# Line 200 | Line 200 | ab_getndxR(            /* get index corresponding to the reverse
200  
201  
202   static void
203 < load_angle_basis(       /* load BSDF angle basis */
203 > load_angle_basis(       /* load custom BSDF angle basis */
204          ezxml_t wab
205   )
206   {
# Line 208 | Line 208 | load_angle_basis(      /* load BSDF angle basis */
208          ezxml_t wbb;
209          int     i;
210          
211 <        if (abname == NULL || !*abname)
211 >        if (!abname || !*abname)
212                  return;
213          for (i = nabases; i--; )
214                  if (!strcmp(abname, abase_list[i].name))
215 <                        return;         /* XXX assume it's the same */
215 >                        return;         /* assume it's the same */
216          if (nabases >= MAXABASES)
217                  error(INTERNAL, "too many angle bases");
218          strcpy(abase_list[nabases].name, abname);
# Line 239 | Line 239 | load_angle_basis(      /* load BSDF angle basis */
239   }
240  
241  
242 + static double
243 + to_meters(              /* return factor to convert given unit to meters */
244 +        const char *unit
245 + )
246 + {
247 +        if (unit == NULL) return(1.);           /* safe assumption? */
248 +        if (!strcasecmp(unit, "Meter")) return(1.);
249 +        if (!strcasecmp(unit, "Foot")) return(.3048);
250 +        if (!strcasecmp(unit, "Inch")) return(.0254);
251 +        if (!strcasecmp(unit, "Centimeter")) return(.01);
252 +        sprintf(errmsg, "unknown dimensional unit '%s'", unit);
253 +        error(USER, errmsg);
254 + }
255 +
256 +
257   static void
258 + load_geometry(          /* load geometric dimensions and description (if any) */
259 +        struct BSDF_data *dp,
260 +        ezxml_t wdb
261 + )
262 + {
263 +        ezxml_t         geom;
264 +        double          cfact;
265 +        const char      *fmt, *mgfstr;
266 +
267 +        dp->dim[0] = dp->dim[1] = dp->dim[2] = 0;
268 +        dp->mgf = NULL;
269 +        if ((geom = ezxml_child(wdb, "Width")) != NULL)
270 +                dp->dim[0] = atof(ezxml_txt(geom)) *
271 +                                to_meters(ezxml_attr(geom, "unit"));
272 +        if ((geom = ezxml_child(wdb, "Height")) != NULL)
273 +                dp->dim[1] = atof(ezxml_txt(geom)) *
274 +                                to_meters(ezxml_attr(geom, "unit"));
275 +        if ((geom = ezxml_child(wdb, "Thickness")) != NULL)
276 +                dp->dim[2] = atof(ezxml_txt(geom)) *
277 +                                to_meters(ezxml_attr(geom, "unit"));
278 +        if ((geom = ezxml_child(wdb, "Geometry")) == NULL ||
279 +                        (mgfstr = ezxml_txt(geom)) == NULL)
280 +                return;
281 +        if ((fmt = ezxml_attr(geom, "format")) != NULL &&
282 +                        strcasecmp(fmt, "MGF")) {
283 +                sprintf(errmsg, "unrecognized geometry format '%s'", fmt);
284 +                error(WARNING, errmsg);
285 +                return;
286 +        }
287 +        cfact = to_meters(ezxml_attr(geom, "unit"));
288 +        dp->mgf = (char *)malloc(strlen(mgfstr)+32);
289 +        if (dp->mgf == NULL)
290 +                error(SYSTEM, "out of memory in load_geometry");
291 +        if (cfact < 0.99 || cfact > 1.01)
292 +                sprintf(dp->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr);
293 +        else
294 +                strcpy(dp->mgf, mgfstr);
295 + }
296 +
297 +
298 + static void
299   load_bsdf_data(         /* load BSDF distribution for this wavelength */
300          struct BSDF_data *dp,
301          ezxml_t wdb
# Line 250 | Line 306 | load_bsdf_data(                /* load BSDF distribution for this wa
306          char  *sdata;
307          int  i;
308          
309 <        if ((cbasis == NULL || !*cbasis) | (rbasis == NULL || !*rbasis)) {
309 >        if ((!cbasis || !*cbasis) | (!rbasis || !*rbasis)) {
310                  error(WARNING, "missing column/row basis for BSDF");
311                  return;
312          }
257        /* XXX need to add routines for loading in foreign bases */
313          for (i = nabases; i--; )
314                  if (!strcmp(cbasis, abase_list[i].name)) {
315                          dp->ninc = abase_list[i].nangles;
# Line 265 | Line 320 | load_bsdf_data(                /* load BSDF distribution for this wa
320                          break;
321                  }
322          if (i < 0) {
323 <                sprintf(errmsg, "unsupported ColumnAngleBasis '%s'", cbasis);
323 >                sprintf(errmsg, "undefined ColumnAngleBasis '%s'", cbasis);
324                  error(WARNING, errmsg);
325                  return;
326          }
# Line 279 | Line 334 | load_bsdf_data(                /* load BSDF distribution for this wa
334                          break;
335                  }
336          if (i < 0) {
337 <                sprintf(errmsg, "unsupported RowAngleBasis '%s'", cbasis);
337 >                sprintf(errmsg, "undefined RowAngleBasis '%s'", cbasis);
338                  error(WARNING, errmsg);
339                  return;
340          }
341                                  /* read BSDF data */
342          sdata  = ezxml_txt(ezxml_child(wdb,"ScatteringData"));
343 <        if (sdata == NULL || !*sdata) {
343 >        if (!sdata || !*sdata) {
344                  error(WARNING, "missing BSDF ScatteringData");
345                  return;
346          }
# Line 309 | Line 364 | load_bsdf_data(                /* load BSDF distribution for this wa
364                  sdata++;
365          if (*sdata) {
366                  sprintf(errmsg, "%d extra characters after BSDF ScatteringData",
367 <                                strlen(sdata));
367 >                                (int)strlen(sdata));
368                  error(WARNING, errmsg);
369          }
370   }
# Line 418 | Line 473 | check_bsdf_data(       /* check that BSDF data is sane */
473          return(1);
474   }
475  
476 +
477   struct BSDF_data *
478   load_BSDF(              /* load BSDF data from file */
479          char *fname
# Line 457 | Line 513 | load_BSDF(             /* load BSDF data from file */
513          load_angle_basis(ezxml_child(ezxml_child(wtl,
514                                  "DataDefinition"), "AngleBasis"));
515          dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data));
516 +        load_geometry(dp, ezxml_child(wtl, "Material"));
517          for (wld = ezxml_child(wtl, "WavelengthData");
518                                  wld != NULL; wld = wld->next) {
519                  if (strcmp(ezxml_txt(ezxml_child(wld,"Wavelength")), "Visible"))
# Line 487 | Line 544 | free_BSDF(             /* free BSDF data structure */
544   {
545          if (b == NULL)
546                  return;
547 +        if (b->mgf != NULL)
548 +                free(b->mgf);
549          if (b->bsdf != NULL)
550                  free(b->bsdf);
551          free(b);
# Line 593 | Line 652 | int
652   getBSDF_xfm(            /* compute BSDF orient. -> world orient. transform */
653          MAT4 xm,
654          FVECT nrm,
655 <        UpDir ud
655 >        UpDir ud,
656 >        char *xfbuf
657   )
658   {
659          char    *xfargs[7];
660          XF      myxf;
661          FVECT   updir, xdest, ydest;
662 +        int     i;
663  
664          updir[0] = updir[1] = updir[2] = 0.;
665          switch (ud) {
# Line 629 | Line 690 | getBSDF_xfm(           /* compute BSDF orient. -> world orient.
690          fcross(ydest, nrm, xdest);
691          xf(&myxf, addrot(xfargs, xdest, ydest, nrm), xfargs);
692          copymat4(xm, myxf.xfm);
693 +        if (xfbuf == NULL)
694 +                return(1);
695 +                                /* return xf arguments as well */
696 +        for (i = 0; xfargs[i] != NULL; i++) {
697 +                *xfbuf++ = ' ';
698 +                strcpy(xfbuf, xfargs[i]);
699 +                while (*xfbuf) ++xfbuf;
700 +        }
701          return(1);
702   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines