1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#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 |
static char mymess[128]; |
18 |
|
19 |
if (!SDerrorDetail[0]) |
20 |
return(strcpy(mymess, SDerrorEnglish[ec])); |
21 |
sprintf(mymess, "%s: %s", SDerrorEnglish[ec], SDerrorDetail); |
22 |
return(mymess); |
23 |
} |
24 |
|
25 |
/* Make sure we're not over 100% scattering for this component */ |
26 |
static void |
27 |
checkDF(const char *nm, double amt, const SDSpectralDF *dfp, const char *desc) |
28 |
{ |
29 |
if (dfp != NULL) |
30 |
amt += dfp->maxHemi; |
31 |
if (amt <= 1.01) |
32 |
return; |
33 |
sprintf(errmsg, "BSDF \"%s\" has %.1f%% %s", nm, amt*100., desc); |
34 |
error(WARNING, errmsg); |
35 |
} |
36 |
|
37 |
/* Load a BSDF file and perform some basic checks */ |
38 |
SDData * |
39 |
loadBSDF(char *name) |
40 |
{ |
41 |
SDData *sd = SDgetCache(name); |
42 |
SDError ec; |
43 |
char *pname; |
44 |
|
45 |
if (sd == NULL) |
46 |
error(SYSTEM, "out of memory in loadBSDF"); |
47 |
if (SDisLoaded(sd)) |
48 |
return(sd); |
49 |
|
50 |
pname = getpath(name, getrlibpath(), R_OK); |
51 |
if (pname == NULL) { |
52 |
sprintf(errmsg, "cannot find BSDF file \"%s\"", name); |
53 |
error(USER, errmsg); |
54 |
} |
55 |
ec = SDloadFile(sd, pname); |
56 |
if (ec) |
57 |
error(USER, transSDError(ec)); |
58 |
/* simple checks */ |
59 |
checkDF(name, sd->rLambFront.cieY, sd->rf, "front reflection"); |
60 |
checkDF(name, sd->rLambBack.cieY, sd->rb, "rear reflection"); |
61 |
checkDF(name, sd->tLamb.cieY, sd->tf, "transmission"); |
62 |
|
63 |
SDretainSet = SDretainAll; /* keep data in core */ |
64 |
return(sd); |
65 |
} |