ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdfrep.h
Revision: 2.3
Committed: Tue Oct 23 05:10:42 2012 UTC (11 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +8 -10 lines
Log Message:
Hopeful bug fix in BSDF interpolation code

File Contents

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