ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/loadbsdf.c
Revision: 3.2
Committed: Sat Feb 19 01:48:59 2011 UTC (13 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.1: +28 -16 lines
Log Message:
Minor changes and fixes -- first working version of BSDF material

File Contents

# User Rev Content
1 greg 3.1 #ifndef lint
2 greg 3.2 static const char RCSid[] = "$Id: loadbsdf.c,v 3.1 2011/02/18 02:41:55 greg Exp $";
3 greg 3.1 #endif
4     /*
5     * Simple interface for loading BSDF, Radiance-specific search
6     */
7    
8     #include "rtio.h"
9     #include "rterror.h"
10     #include "bsdf.h"
11     #include "paths.h"
12    
13     /* Convert error from BSDF library */
14     char *
15     transSDError(SDError ec)
16     {
17 greg 3.2 if (!SDerrorDetail[0])
18     return(strcpy(errmsg, SDerrorEnglish[ec]));
19 greg 3.1
20 greg 3.2 sprintf(errmsg, "%s: %s", SDerrorEnglish[ec], SDerrorDetail);
21     return(errmsg);
22 greg 3.1 }
23    
24     /* Make sure we're not over 100% scattering for this component */
25     static void
26     checkDF(const char *nm, double amt, const SDSpectralDF *dfp, const char *desc)
27     {
28     if (dfp != NULL)
29     amt += dfp->maxHemi;
30     if (amt <= 1.01)
31     return;
32     sprintf(errmsg, "BSDF \"%s\" has %.1f%% %s", nm, amt*100., desc);
33     error(WARNING, errmsg);
34     }
35    
36     /* Load a BSDF file and perform some basic checks */
37     SDData *
38 greg 3.2 loadBSDF(char *fname)
39 greg 3.1 {
40 greg 3.2 SDData *sd;
41 greg 3.1 SDError ec;
42     char *pname;
43    
44 greg 3.2 sd = SDgetCache(fname); /* look up or allocate */
45 greg 3.1 if (sd == NULL)
46     error(SYSTEM, "out of memory in loadBSDF");
47 greg 3.2 if (SDisLoaded(sd)) /* already in memory? */
48 greg 3.1 return(sd);
49 greg 3.2 /* else find and load it */
50     pname = getpath(fname, getrlibpath(), R_OK);
51 greg 3.1 if (pname == NULL) {
52 greg 3.2 sprintf(errmsg, "cannot find BSDF file \"%s\"", fname);
53 greg 3.1 error(USER, errmsg);
54     }
55     ec = SDloadFile(sd, pname);
56     if (ec)
57     error(USER, transSDError(ec));
58     /* simple checks */
59 greg 3.2 checkDF(sd->name, sd->rLambFront.cieY, sd->rf, "front reflection");
60     checkDF(sd->name, sd->rLambBack.cieY, sd->rb, "rear reflection");
61     checkDF(sd->name, sd->tLamb.cieY, sd->tf, "transmission");
62     fprintf(stderr, "Loaded BSDF '%s' (file \"%s\")\n", sd->name, pname);
63     fprintf(stderr, "Front diffuse reflectance: %.1f%%\n", sd->rLambFront.cieY*100.);
64     fprintf(stderr, "Back diffuse reflectance: %.1f%%\n", sd->rLambBack.cieY*100.);
65     fprintf(stderr, "Diffuse transmittance: %.1f%%\n", sd->tLamb.cieY*100.);
66     if (sd->rf)
67     fprintf(stderr, "Maximum direct hemispherical front reflection: %.1f%%\n",
68     sd->rf->maxHemi*100.);
69     if (sd->rb)
70     fprintf(stderr, "Maximum direct hemispherical back reflection: %.1f%%\n",
71     sd->rb->maxHemi*100.);
72     if (sd->tf)
73     fprintf(stderr, "Maximum direct hemispherical transmission: %.1f%%\n",
74     sd->tf->maxHemi*100.);
75 greg 3.1 SDretainSet = SDretainAll; /* keep data in core */
76     return(sd);
77     }