--- ray/src/common/bsdf.h 2012/09/02 15:33:15 2.19 +++ ray/src/common/bsdf.h 2018/01/05 20:15:50 2.25 @@ -1,4 +1,4 @@ -/* RCSid $Id: bsdf.h,v 2.19 2012/09/02 15:33:15 greg Exp $ */ +/* RCSid $Id: bsdf.h,v 2.25 2018/01/05 20:15:50 schorsch Exp $ */ /* * bsdf.h * @@ -25,15 +25,12 @@ #include "fvect.h" #include "ccolor.h" +#include "platform.h" #ifdef __cplusplus extern "C" { #endif -#ifdef _WIN32 -#define strcasecmp stricmp -#endif - #define SDnameLn 128 /* maximum BSDF name length */ #define SDmaxCh 3 /* maximum # spectral channels */ @@ -58,10 +55,13 @@ extern "C" { typedef enum {SDEnone=0, SDEmemory, SDEfile, SDEformat, SDEargument, SDEdata, SDEsupport, SDEinternal, SDEunknown} SDError; -/* English ASCII strings corresponding to ennumerated errors */ +/* English strings corresponding to ennumerated errors */ extern const char *SDerrorEnglish[]; -/* Additional information on last error (ASCII English) */ +/* Pointer to error list in preferred language */ +extern const char **SDerrorList; + +/* Additional information on last error (generally in English) */ extern char SDerrorDetail[]; /* Holder for BSDF value and spectral color */ @@ -84,7 +84,14 @@ extern const SDCDst SDemptyCD; /* empty distribution * typedef struct SDComp_s SDComponent; /* Methods needed to handle BSDF components (nothing is optional) */ +#ifdef __cplusplus +/* in C++, the const puts the type into the local anonymous namespace, + making it a private (and different) type for each file using this header. +*/ +typedef struct { +#else typedef const struct { +#endif /* return non-diffuse BSDF */ int (*getBSDFs)(float coef[SDmaxCh], const FVECT outVec, const FVECT inVec, SDComponent *sdc); @@ -123,7 +130,7 @@ typedef struct { char matn[SDnameLn]; /* material name */ char makr[SDnameLn]; /* manufacturer */ char *mgf; /* geometric description (if any) */ - float dim[3]; /* width, height, thickness (meters) */ + double dim[3]; /* width, height, thickness (meters) */ SDValue rLambFront; /* diffuse front reflectance */ SDValue rLambBack; /* diffuse rear reflectance */ SDValue tLamb; /* diffuse transmission */ @@ -152,8 +159,8 @@ extern int SDretainSet; /* =SDretainNone by default * #define SDisLoaded(sd) ((sd)->rLambFront.spec.flags != 0) -/* Report an error to the indicated stream (in English) */ -extern SDError SDreportEnglish(SDError ec, FILE *fp); +/* Report an error to the indicated stream */ +extern SDError SDreportError(SDError ec, FILE *fp); /* Shorten file path to useable BSDF name, removing suffix */ extern void SDclipName(char res[SDnameLn], const char *fname); @@ -190,10 +197,10 @@ extern SDError SDsampComponent(SDValue *sv, FVECT ioV extern void SDmultiSamp(double t[], int n, double randX); /* Map a [0,1]^2 square to a unit radius disk */ -void SDsquare2disk(double ds[2], double seedx, double seedy); +extern void SDsquare2disk(double ds[2], double seedx, double seedy); /* Map point on unit disk to a unit square in [0,1]^2 range */ -void SDdisk2square(double sq[2], double diskx, double disky); +extern void SDdisk2square(double sq[2], double diskx, double disky); /***************************************************************** * The calls below are the ones most applications require. @@ -201,7 +208,7 @@ void SDdisk2square(double sq[2], double diskx, doubl */ /* Get BSDF from cache (or load and cache it on first call) */ -/* Report any problems to stderr (in English), return NULL on failure */ +/* Report any problems to stderr, return NULL on failure */ extern const SDData *SDcacheFile(const char *fname); /* Free a BSDF from our cache (clear all if sd==NULL) */ @@ -245,66 +252,6 @@ extern SDData *loadBSDF(char *name); /* Application-specific BSDF error translator (not part of our library) */ extern char *transSDError(SDError ec); - -/*################################################################*/ -/*######### DEPRECATED DEFINITIONS AWAITING PERMANENT REMOVAL #######*/ -/* - * Header for BSDF i/o and access routines - */ - -#include "mat4.h" - /* up directions */ -typedef enum { - UDzneg=-3, - UDyneg=-2, - UDxneg=-1, - UDunknown=0, - UDxpos=1, - UDypos=2, - UDzpos=3 -} UpDir; - /* BSDF coordinate calculation routines */ - /* vectors always point away from surface */ - -typedef int b_vecf2(FVECT v, int n, void *cd); -typedef int b_ndxf2(FVECT v, void *cd); -typedef double b_radf2(int n, void *cd); - -/* Bidirectional Scattering Distribution Function */ -struct BSDF_data { - int ninc; /* number of incoming directions */ - int nout; /* number of outgoing directions */ - float dim[3]; /* width, height, thickness (meters) */ - char *mgf; /* geometric description (if any) */ - void *ib_priv; /* input basis private data */ - b_vecf2 *ib_vec; /* get input vector from index */ - b_ndxf2 *ib_ndx; /* get input index from vector */ - b_radf2 *ib_ohm; /* get input radius for index */ - void *ob_priv; /* output basis private data */ - b_vecf2 *ob_vec; /* get output vector from index */ - b_ndxf2 *ob_ndx; /* get output index from vector */ - b_radf2 *ob_ohm; /* get output radius for index */ - float *bsdf; /* scattering distribution data */ -}; /* bidirectional scattering distrib. func. */ - -#define getBSDF_incvec(v,b,i) (*(b)->ib_vec)(v,i,(b)->ib_priv) -#define getBSDF_incndx(b,v) (*(b)->ib_ndx)(v,(b)->ib_priv) -#define getBSDF_incohm(b,i) (*(b)->ib_ohm)(i,(b)->ib_priv) -#define getBSDF_outvec(v,b,o) (*(b)->ob_vec)(v,o,(b)->ob_priv) -#define getBSDF_outndx(b,v) (*(b)->ob_ndx)(v,(b)->ob_priv) -#define getBSDF_outohm(b,o) (*(b)->ob_ohm)(o,(b)->ob_priv) -#define BSDF_value(b,i,o) (b)->bsdf[(o)*(b)->ninc + (i)] - -extern struct BSDF_data *load_BSDF(char *fname); -extern void free_BSDF(struct BSDF_data *b); -extern int r_BSDF_incvec(FVECT v, struct BSDF_data *b, int i, - double rv, MAT4 xm); -extern int r_BSDF_outvec(FVECT v, struct BSDF_data *b, int o, - double rv, MAT4 xm); -extern int getBSDF_xfm(MAT4 xm, FVECT nrm, UpDir ud, char *xfbuf); - -/*######### END DEPRECATED DEFINITIONS #######*/ -/*################################################################*/ #ifdef __cplusplus }