ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdfrep.h
Revision: 2.18
Committed: Wed Mar 19 20:49:01 2014 UTC (10 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.17: +1 -3 lines
Log Message:
Removed accidentally inserted DEBUG define

File Contents

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