| 1 |
/* RCSid $Id: bsdf_m.h,v 3.9 2018/01/05 21:00:24 greg Exp $ */
|
| 2 |
/*
|
| 3 |
* bsdf_m.h
|
| 4 |
*
|
| 5 |
* Support for BSDF matrices.
|
| 6 |
* Assumes "bsdf.h" already included.
|
| 7 |
* Include after "ezxml.h" for SDloadMtx() declaration.
|
| 8 |
*
|
| 9 |
* Created by Greg Ward on 2/2/11.
|
| 10 |
*
|
| 11 |
*/
|
| 12 |
|
| 13 |
#ifndef _BSDF_M_H_
|
| 14 |
#define _BSDF_M_H_
|
| 15 |
|
| 16 |
#ifdef __cplusplus
|
| 17 |
extern "C" {
|
| 18 |
#endif
|
| 19 |
/* Fixed-position coordinate functions */
|
| 20 |
typedef int b_vecf(FVECT vec, double ndxr, void *c_data);
|
| 21 |
typedef int b_ndxf(const FVECT vec, void *c_data);
|
| 22 |
typedef double b_ohmf(int ndx, void *c_data);
|
| 23 |
|
| 24 |
/* Rectangular matrix format BSDF */
|
| 25 |
typedef struct {
|
| 26 |
int ninc; /* number of incoming directions */
|
| 27 |
int nout; /* number of outgoing directions */
|
| 28 |
void *ib_priv; /* input basis private data */
|
| 29 |
b_vecf *ib_vec; /* get input vector from index */
|
| 30 |
b_ndxf *ib_ndx; /* get input index from vector */
|
| 31 |
b_ohmf *ib_ohm; /* get input proj. SA for index */
|
| 32 |
void *ob_priv; /* output basis private data */
|
| 33 |
b_vecf *ob_vec; /* get output vector from index */
|
| 34 |
b_ndxf *ob_ndx; /* get output index from vector */
|
| 35 |
b_ohmf *ob_ohm; /* get output proj. SA for index */
|
| 36 |
C_CHROMA *chroma; /* chromaticity data */
|
| 37 |
float bsdf[1]; /* scattering data (extends struct) */
|
| 38 |
} SDMat;
|
| 39 |
|
| 40 |
/* Matrix BSDF accessors */
|
| 41 |
#define mBSDF_incvec(v,b,ix) (*(b)->ib_vec)(v,ix,(b)->ib_priv)
|
| 42 |
#define mBSDF_incndx(b,v) (*(b)->ib_ndx)(v,(b)->ib_priv)
|
| 43 |
#define mBSDF_incohm(b,i) (*(b)->ib_ohm)(i,(b)->ib_priv)
|
| 44 |
#define mBSDF_outvec(v,b,ox) (*(b)->ob_vec)(v,ox,(b)->ob_priv)
|
| 45 |
#define mBSDF_outndx(b,v) (*(b)->ob_ndx)(v,(b)->ob_priv)
|
| 46 |
#define mBSDF_outohm(b,o) (*(b)->ob_ohm)(o,(b)->ob_priv)
|
| 47 |
#define mBSDF_value(b,o,i) (b)->bsdf[(o)*(b)->ninc + (i)]
|
| 48 |
#define mBSDF_chroma(b,o,i) (b)->chroma[(o)*(b)->ninc + (i)]
|
| 49 |
|
| 50 |
/* Holder for cumulative distribution (sum of BSDF * projSA) */
|
| 51 |
typedef struct SDMatCDst_s {
|
| 52 |
SD_CDIST_BASE(SDMatCDst_s); /* base fields; must come first */
|
| 53 |
int indx; /* incident angle index */
|
| 54 |
void *ob_priv; /* private data for generator */
|
| 55 |
b_vecf *ob_vec; /* outbound vector generator */
|
| 56 |
int calen; /* cumulative array length */
|
| 57 |
unsigned carr[1]; /* cumulative array (extends struct) */
|
| 58 |
} SDMatCDst;
|
| 59 |
|
| 60 |
#ifdef _EZXML_H
|
| 61 |
/* Load a set of BSDF matrices from an open XML file */
|
| 62 |
extern SDError SDloadMtx(SDData *sd, ezxml_t wtl);
|
| 63 |
#endif
|
| 64 |
|
| 65 |
/* Our matrix handling routines */
|
| 66 |
extern const SDFunc SDhandleMtx;
|
| 67 |
|
| 68 |
/******** Klems basis declarations for more intimate access ********/
|
| 69 |
|
| 70 |
#define MAXLATS 46 /* maximum number of latitudes */
|
| 71 |
|
| 72 |
/* BSDF angle specification */
|
| 73 |
typedef struct {
|
| 74 |
char name[64]; /* basis name */
|
| 75 |
int nangles; /* total number of directions */
|
| 76 |
struct {
|
| 77 |
float tmin; /* starting theta */
|
| 78 |
int nphis; /* number of phis (0 term) */
|
| 79 |
} lat[MAXLATS+1]; /* latitudes */
|
| 80 |
} ANGLE_BASIS;
|
| 81 |
|
| 82 |
#define MAXABASES 7 /* limit on defined bases */
|
| 83 |
|
| 84 |
extern ANGLE_BASIS abase_list[MAXABASES];
|
| 85 |
|
| 86 |
extern int nabases; /* current number of defined bases */
|
| 87 |
|
| 88 |
extern C_COLOR mtx_RGB_prim[3]; /* matrix RGB primaries */
|
| 89 |
extern float mtx_RGB_coef[3]; /* corresponding Y coefficients */
|
| 90 |
|
| 91 |
/* Get color or grayscale value for BSDF in the given directions */
|
| 92 |
extern int mBSDF_color(float coef[], const SDMat *b, int i, int o);
|
| 93 |
|
| 94 |
/* Get vector for this angle basis index (front exiting) */
|
| 95 |
extern b_vecf fo_getvec;
|
| 96 |
|
| 97 |
/* Get index corresponding to the given vector (front exiting) */
|
| 98 |
extern b_ndxf fo_getndx;
|
| 99 |
|
| 100 |
/* Get projected solid angle for this angle basis index (universal) */
|
| 101 |
extern b_ohmf io_getohm;
|
| 102 |
|
| 103 |
/* Get vector for this angle basis index (back incident) */
|
| 104 |
extern b_vecf bi_getvec;
|
| 105 |
|
| 106 |
/* Get index corresponding to the vector (back incident) */
|
| 107 |
extern b_ndxf bi_getndx;
|
| 108 |
|
| 109 |
/* Get vector for this angle basis index (back exiting) */
|
| 110 |
extern b_vecf bo_getvec;
|
| 111 |
|
| 112 |
/* Get index corresponding to the vector (back exiting) */
|
| 113 |
extern b_ndxf bo_getndx;
|
| 114 |
|
| 115 |
/* Get vector for this angle basis index (front incident) */
|
| 116 |
extern b_vecf fi_getvec;
|
| 117 |
|
| 118 |
/* Get index corresponding to the vector (front incident) */
|
| 119 |
extern b_ndxf fi_getndx;
|
| 120 |
|
| 121 |
#ifdef __cplusplus
|
| 122 |
}
|
| 123 |
#endif
|
| 124 |
#endif /* ! _BSDF_M_H_ */
|