ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdfrep.h
Revision: 2.24
Committed: Sat Jan 30 01:31:57 2016 UTC (8 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad5R1, rad5R3
Changes since 2.23: +2 -2 lines
Log Message:
Improved grazing lobe estimation by using lowest 25% of DSFs

File Contents

# User Rev Content
1 greg 2.24 /* RCSid $Id: bsdfrep.h,v 2.23 2016/01/29 16:21:56 greg Exp $ */
2 greg 2.1 /*
3     * Definitions for BSDF representation used to interpolate measured data.
4     *
5     * G. Ward
6     */
7    
8 greg 2.19 #ifndef _BSDFREP_H_
9     #define _BSDFREP_H_
10    
11 greg 2.1 #include "bsdf.h"
12    
13 greg 2.19 #ifdef __cplusplus
14     extern "C" {
15     #endif
16    
17 greg 2.1 #ifndef GRIDRES
18 greg 2.10 #define GRIDRES (1<<8) /* grid resolution per side */
19 greg 2.1 #endif
20     /* convert to/from coded radians */
21     #define ANG2R(r) (int)((r)*((1<<16)/M_PI))
22     #define R2ANG(c) (((c)+.5)*(M_PI/(1<<16)))
23    
24 greg 2.22 /* moderated cosine factor */
25     #define COSF(z) (fabs(z)*0.98 + 0.02)
26    
27 greg 2.15 typedef union {
28     struct {
29     float v; /* DSF sum */
30     unsigned int n; /* number of values in sum */
31     } sum; /* sum for averaging */
32     float val[2]; /* comparison values */
33 greg 2.1 } GRIDVAL; /* grid value */
34    
35     typedef struct {
36     float peak; /* lobe value at peak */
37 greg 2.23 C_CHROMA chroma; /* encoded chromaticity */
38 greg 2.1 unsigned short crad; /* radius (coded angle) */
39 greg 2.23 unsigned short gx, gy; /* grid position */
40 greg 2.1 } RBFVAL; /* radial basis function value */
41    
42     struct s_rbfnode; /* forward declaration of RBF struct */
43    
44     typedef struct s_migration {
45     struct s_migration *next; /* next in global edge list */
46     struct s_rbfnode *rbfv[2]; /* from,to vertex */
47     struct s_migration *enxt[2]; /* next from,to sibling */
48     float mtx[1]; /* matrix (extends struct) */
49     } MIGRATION; /* migration link (winged edge structure) */
50    
51     typedef struct s_rbfnode {
52     int ord; /* ordinal position in list */
53     struct s_rbfnode *next; /* next in global RBF list */
54     MIGRATION *ejl; /* edge list for this vertex */
55     FVECT invec; /* incident vector direction */
56     double vtotal; /* volume for normalization */
57     int nrbf; /* number of RBFs */
58     RBFVAL rbfa[1]; /* RBF array (extends struct) */
59     } RBFNODE; /* RBF representation of DSF @ 1 incidence */
60    
61     /* symmetry operations */
62     #define MIRROR_X 1 /* mirror(ed) x-coordinate */
63     #define MIRROR_Y 2 /* mirror(ed) y-coordinate */
64    
65     /* represented incident quadrants */
66     #define INP_QUAD1 1 /* 0-90 degree quadrant */
67     #define INP_QUAD2 2 /* 90-180 degree quadrant */
68     #define INP_QUAD3 4 /* 180-270 degree quadrant */
69     #define INP_QUAD4 8 /* 270-360 degree quadrant */
70    
71 greg 2.11 /* name and manufacturer if known */
72     extern char bsdf_name[];
73     extern char bsdf_manuf[];
74 greg 2.5 /* active grid resolution */
75     extern int grid_res;
76 greg 2.3 /* coverage/symmetry using INP_QUAD? flags */
77 greg 2.1 extern int inp_coverage;
78    
79     /* all incident angles in-plane so far? */
80     extern int single_plane_incident;
81    
82     /* input/output orientations */
83     extern int input_orient;
84     extern int output_orient;
85    
86 greg 2.23 /* represented colorimetry */
87     typedef enum {RBCphotopic, RBCtristimulus, RBCspectral, RBCunknown} RBColor;
88    
89     extern RBColor rbf_colorimetry;
90    
91     extern const char *RBCident[];
92    
93 greg 2.7 /* log BSDF histogram */
94     #define HISTLEN 256
95     #define BSDF2BIG (1./M_PI)
96     #define BSDF2SML 1e-8
97     #define HISTLNR 17.2759509 /* log(BSDF2BIG/BSDF2SML) */
98 greg 2.9 extern unsigned long bsdf_hist[HISTLEN];
99 greg 2.7 #define histndx(v) (int)(log((v)*(1./BSDF2SML))*(HISTLEN/HISTLNR))
100     #define histval(i) (exp(((i)+.5)*(HISTLNR/HISTLEN))*BSDF2SML)
101    
102     /* BSDF value for boundary regions */
103     extern double bsdf_min;
104 greg 2.24 extern double bsdf_spec_val;
105 greg 2.21 extern double bsdf_spec_rad;
106 greg 2.7
107 greg 2.1 /* processed incident DSF measurements */
108     extern RBFNODE *dsf_list;
109    
110     /* RBF-linking matrices (edges) */
111     extern MIGRATION *mig_list;
112    
113 greg 2.3 #define mtx_nrows(m) (m)->rbfv[0]->nrbf
114     #define mtx_ncols(m) (m)->rbfv[1]->nrbf
115 greg 2.2 #define mtx_coef(m,i,j) (m)->mtx[(i)*mtx_ncols(m) + (j)]
116 greg 2.1 #define is_src(rbf,m) ((rbf) == (m)->rbfv[0])
117     #define is_dest(rbf,m) ((rbf) == (m)->rbfv[1])
118     #define nextedge(rbf,m) (m)->enxt[is_dest(rbf,m)]
119     #define opp_rbf(rbf,m) (m)->rbfv[is_src(rbf,m)]
120    
121     #define round(v) (int)((v) + .5 - ((v) < -.5))
122    
123 greg 2.2 #define BSDFREP_FMT "BSDF_RBFmesh"
124 greg 2.1
125 greg 2.23 #define BSDFREP_MAGIC 0x5a3c
126    
127 greg 2.1 /* global argv[0] */
128     extern char *progname;
129    
130     /* get theta value in degrees [0,180) range */
131 greg 2.13 #define get_theta180(v) ((180./M_PI)*Acos((v)[2]))
132 greg 2.1 /* get phi value in degrees, [0,360) range */
133 greg 2.4 #define get_phi360(v) ((180./M_PI)*atan2((v)[1],(v)[0]) + 360.*((v)[1]<0))
134 greg 2.1
135     /* our loaded grid for this incident angle */
136     extern double theta_in_deg, phi_in_deg;
137     extern GRIDVAL dsf_grid[GRIDRES][GRIDRES];
138 greg 2.23 extern float (*spec_grid)[GRIDRES][GRIDRES];
139     extern int nspec_grid;
140 greg 2.1
141     /* Register new input direction */
142     extern int new_input_direction(double new_theta, double new_phi);
143    
144     #define new_input_vector(v)\
145     new_input_direction(get_theta180(v),get_phi360(v))
146    
147     /* Apply symmetry to the given vector based on distribution */
148     extern int use_symmetry(FVECT vec);
149    
150     /* Reverse symmetry based on what was done before */
151     extern void rev_symmetry(FVECT vec, int sym);
152    
153     /* Reverse symmetry for an RBF distribution */
154     extern void rev_rbf_symmetry(RBFNODE *rbf, int sym);
155    
156 greg 2.6 /* Rotate RBF to correspond to given incident vector */
157     extern void rotate_rbf(RBFNODE *rbf, const FVECT invec);
158    
159 greg 2.1 /* Compute volume associated with Gaussian lobe */
160     extern double rbf_volume(const RBFVAL *rbfp);
161    
162     /* Compute outgoing vector from grid position */
163     extern void ovec_from_pos(FVECT vec, int xpos, int ypos);
164    
165     /* Compute grid position from normalized input/output vector */
166     extern void pos_from_vec(int pos[2], const FVECT vec);
167    
168 greg 2.20 /* Evaluate BSDF at the given normalized outgoing direction */
169 greg 2.1 extern double eval_rbfrep(const RBFNODE *rp, const FVECT outvec);
170    
171 greg 2.23 extern SDError eval_rbfcol(SDValue *sv,
172     const RBFNODE *rp, const FVECT outvec);
173    
174 greg 2.1 /* Insert a new directional scattering function in our global list */
175     extern int insert_dsf(RBFNODE *newrbf);
176    
177     /* Get the DSF indicated by its ordinal position */
178     extern RBFNODE * get_dsf(int ord);
179    
180     /* Get triangle surface orientation (unnormalized) */
181     extern void tri_orient(FVECT vres, const FVECT v1,
182     const FVECT v2, const FVECT v3);
183    
184     /* Determine if vertex order is reversed (inward normal) */
185     extern int is_rev_tri(const FVECT v1,
186     const FVECT v2, const FVECT v3);
187    
188     /* Find vertices completing triangles on either side of the given edge */
189     extern int get_triangles(RBFNODE *rbfv[2], const MIGRATION *mig);
190    
191 greg 2.3 /* Clear our BSDF representation and free memory */
192     extern void clear_bsdf_rep(void);
193    
194 greg 2.1 /* Write our BSDF mesh interpolant out to the given binary stream */
195     extern void save_bsdf_rep(FILE *ofp);
196    
197     /* Read a BSDF mesh interpolant from the given binary stream */
198     extern int load_bsdf_rep(FILE *ifp);
199    
200 greg 2.23 /* Set up visible spectrum sampling */
201     extern void set_spectral_samples(int nspec);
202    
203 greg 2.1 /* Start new DSF input grid */
204     extern void new_bsdf_data(double new_theta, double new_phi);
205    
206     /* Add BSDF data point */
207     extern void add_bsdf_data(double theta_out, double phi_out,
208 greg 2.23 const double val[], int isDSF);
209 greg 2.1
210     /* Count up filled nodes and build RBF representation from current grid */
211     extern RBFNODE * make_rbfrep(void);
212    
213     /* Build our triangle mesh from recorded RBFs */
214     extern void build_mesh(void);
215    
216     /* Find edge(s) for interpolating the given vector, applying symmetry */
217     extern int get_interp(MIGRATION *miga[3], FVECT invec);
218    
219 greg 2.20 /* Return single-lobe specular RBF for the given incident direction */
220     extern RBFNODE * def_rbf_spec(const FVECT invec);
221    
222 greg 2.12 /* Advect and allocate new RBF along edge (internal call) */
223     extern RBFNODE * e_advect_rbf(const MIGRATION *mig,
224     const FVECT invec, int lobe_lim);
225    
226 greg 2.19 /* Compute distance between two RBF lobes (internal call) */
227     extern double lobe_distance(RBFVAL *rbf1, RBFVAL *rbf2);
228    
229     /* Compute mass transport plan (internal call) */
230     extern void plan_transport(MIGRATION *mig);
231    
232 greg 2.1 /* Partially advect between recorded incident angles and allocate new RBF */
233 greg 2.8 extern RBFNODE * advect_rbf(const FVECT invec, int lobe_lim);
234 greg 2.19
235     #ifdef __cplusplus
236     }
237     #endif
238     #endif /* _BSDFREP_H_ */