ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdfrep.h
Revision: 2.10
Committed: Mon Oct 21 18:33:15 2013 UTC (10 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.9: +2 -2 lines
Log Message:
Major overhaul/redesign of radial basis function derivation

File Contents

# Content
1 /* RCSid $Id: bsdfrep.h,v 2.9 2013/10/19 00:11:50 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 struct {
20 float vsum; /* DSF sum */
21 unsigned int nval; /* number of values in sum */
22 unsigned short crad; /* radius (coded angle) */
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 /* active grid resolution */
61 extern int grid_res;
62 /* coverage/symmetry using INP_QUAD? flags */
63 extern int inp_coverage;
64
65 /* all incident angles in-plane so far? */
66 extern int single_plane_incident;
67
68 /* input/output orientations */
69 extern int input_orient;
70 extern int output_orient;
71
72 /* log BSDF histogram */
73 #define HISTLEN 256
74 #define BSDF2BIG (1./M_PI)
75 #define BSDF2SML 1e-8
76 #define HISTLNR 17.2759509 /* log(BSDF2BIG/BSDF2SML) */
77 extern unsigned long bsdf_hist[HISTLEN];
78 #define histndx(v) (int)(log((v)*(1./BSDF2SML))*(HISTLEN/HISTLNR))
79 #define histval(i) (exp(((i)+.5)*(HISTLNR/HISTLEN))*BSDF2SML)
80
81 /* BSDF value for boundary regions */
82 extern double bsdf_min;
83
84 /* processed incident DSF measurements */
85 extern RBFNODE *dsf_list;
86
87 /* RBF-linking matrices (edges) */
88 extern MIGRATION *mig_list;
89
90 #define mtx_nrows(m) (m)->rbfv[0]->nrbf
91 #define mtx_ncols(m) (m)->rbfv[1]->nrbf
92 #define mtx_coef(m,i,j) (m)->mtx[(i)*mtx_ncols(m) + (j)]
93 #define is_src(rbf,m) ((rbf) == (m)->rbfv[0])
94 #define is_dest(rbf,m) ((rbf) == (m)->rbfv[1])
95 #define nextedge(rbf,m) (m)->enxt[is_dest(rbf,m)]
96 #define opp_rbf(rbf,m) (m)->rbfv[is_src(rbf,m)]
97
98 #define round(v) (int)((v) + .5 - ((v) < -.5))
99
100 #define BSDFREP_FMT "BSDF_RBFmesh"
101
102 /* global argv[0] */
103 extern char *progname;
104
105 /* get theta value in degrees [0,180) range */
106 #define get_theta180(v) ((180./M_PI)*acos((v)[2]))
107 /* get phi value in degrees, [0,360) range */
108 #define get_phi360(v) ((180./M_PI)*atan2((v)[1],(v)[0]) + 360.*((v)[1]<0))
109
110 /* our loaded grid for this incident angle */
111 extern double theta_in_deg, phi_in_deg;
112 extern GRIDVAL dsf_grid[GRIDRES][GRIDRES];
113
114 /* Register new input direction */
115 extern int new_input_direction(double new_theta, double new_phi);
116
117 #define new_input_vector(v)\
118 new_input_direction(get_theta180(v),get_phi360(v))
119
120 /* Apply symmetry to the given vector based on distribution */
121 extern int use_symmetry(FVECT vec);
122
123 /* Reverse symmetry based on what was done before */
124 extern void rev_symmetry(FVECT vec, int sym);
125
126 /* Reverse symmetry for an RBF distribution */
127 extern void rev_rbf_symmetry(RBFNODE *rbf, int sym);
128
129 /* Rotate RBF to correspond to given incident vector */
130 extern void rotate_rbf(RBFNODE *rbf, const FVECT invec);
131
132 /* Compute volume associated with Gaussian lobe */
133 extern double rbf_volume(const RBFVAL *rbfp);
134
135 /* Compute outgoing vector from grid position */
136 extern void ovec_from_pos(FVECT vec, int xpos, int ypos);
137
138 /* Compute grid position from normalized input/output vector */
139 extern void pos_from_vec(int pos[2], const FVECT vec);
140
141 /* Evaluate RBF for DSF at the given normalized outgoing direction */
142 extern double eval_rbfrep(const RBFNODE *rp, const FVECT outvec);
143
144 /* Insert a new directional scattering function in our global list */
145 extern int insert_dsf(RBFNODE *newrbf);
146
147 /* Get the DSF indicated by its ordinal position */
148 extern RBFNODE * get_dsf(int ord);
149
150 /* Get triangle surface orientation (unnormalized) */
151 extern void tri_orient(FVECT vres, const FVECT v1,
152 const FVECT v2, const FVECT v3);
153
154 /* Determine if vertex order is reversed (inward normal) */
155 extern int is_rev_tri(const FVECT v1,
156 const FVECT v2, const FVECT v3);
157
158 /* Find vertices completing triangles on either side of the given edge */
159 extern int get_triangles(RBFNODE *rbfv[2], const MIGRATION *mig);
160
161 /* Clear our BSDF representation and free memory */
162 extern void clear_bsdf_rep(void);
163
164 /* Write our BSDF mesh interpolant out to the given binary stream */
165 extern void save_bsdf_rep(FILE *ofp);
166
167 /* Read a BSDF mesh interpolant from the given binary stream */
168 extern int load_bsdf_rep(FILE *ifp);
169
170 /* Start new DSF input grid */
171 extern void new_bsdf_data(double new_theta, double new_phi);
172
173 /* Add BSDF data point */
174 extern void add_bsdf_data(double theta_out, double phi_out,
175 double val, int isDSF);
176
177 /* Count up filled nodes and build RBF representation from current grid */
178 extern RBFNODE * make_rbfrep(void);
179
180 /* Build our triangle mesh from recorded RBFs */
181 extern void build_mesh(void);
182
183 /* Find edge(s) for interpolating the given vector, applying symmetry */
184 extern int get_interp(MIGRATION *miga[3], FVECT invec);
185
186 /* Partially advect between recorded incident angles and allocate new RBF */
187 extern RBFNODE * advect_rbf(const FVECT invec, int lobe_lim);