ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdfrep.h
Revision: 2.17
Committed: Wed Mar 19 19:48:57 2014 UTC (10 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.16: +3 -1 lines
Log Message:
Fixed potential bug due with closely-spaced incident angles

File Contents

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