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