14 |
|
#include "rtio.h" |
15 |
|
#include "resolu.h" |
16 |
|
#include "bsdfrep.h" |
17 |
+ |
/* active grid resolution */ |
18 |
+ |
int grid_res = GRIDRES; |
19 |
+ |
|
20 |
|
/* coverage/symmetry using INP_QUAD? flags */ |
21 |
|
int inp_coverage = 0; |
22 |
|
/* all incident angles in-plane so far? */ |
56 |
|
new_theta = -new_theta; |
57 |
|
new_phi += 180.; |
58 |
|
} |
59 |
+ |
if ((theta_in_deg = new_theta) < 1.0) |
60 |
+ |
return(1); /* don't rely on phi near normal */ |
61 |
|
while (new_phi < 0) |
62 |
|
new_phi += 360.; |
63 |
|
while (new_phi >= 360.) |
66 |
|
single_plane_incident = (round(new_phi) == round(phi_in_deg)); |
67 |
|
else if (single_plane_incident < 0) |
68 |
|
single_plane_incident = 1; |
64 |
– |
theta_in_deg = new_theta; /* assume it's OK */ |
69 |
|
phi_in_deg = new_phi; |
70 |
|
if ((1. < new_phi) & (new_phi < 89.)) |
71 |
|
inp_coverage |= INP_QUAD1; |
172 |
|
rev_symmetry(rbf->invec, sym); |
173 |
|
if (sym & MIRROR_X) |
174 |
|
for (n = rbf->nrbf; n-- > 0; ) |
175 |
< |
rbf->rbfa[n].gx = GRIDRES-1 - rbf->rbfa[n].gx; |
175 |
> |
rbf->rbfa[n].gx = grid_res-1 - rbf->rbfa[n].gx; |
176 |
|
if (sym & MIRROR_Y) |
177 |
|
for (n = rbf->nrbf; n-- > 0; ) |
178 |
< |
rbf->rbfa[n].gy = GRIDRES-1 - rbf->rbfa[n].gy; |
178 |
> |
rbf->rbfa[n].gy = grid_res-1 - rbf->rbfa[n].gy; |
179 |
|
} |
180 |
|
|
181 |
+ |
/* Rotate RBF to correspond to given incident vector */ |
182 |
+ |
void |
183 |
+ |
rotate_rbf(RBFNODE *rbf, const FVECT invec) |
184 |
+ |
{ |
185 |
+ |
static const FVECT vnorm = {.0, .0, 1.}; |
186 |
+ |
const double phi = atan2(invec[1],invec[0]) - |
187 |
+ |
atan2(rbf->invec[1],rbf->invec[0]); |
188 |
+ |
FVECT outvec; |
189 |
+ |
int pos[2]; |
190 |
+ |
int n; |
191 |
+ |
#ifdef DEBUG |
192 |
+ |
double tdiff = 180./M_PI*fabs(acos(invec[2])-acos(rbf->invec[2])); |
193 |
+ |
if (tdiff >= 1.5) |
194 |
+ |
fprintf(stderr, |
195 |
+ |
"%s: Warning - rotated theta differs by %.1f degrees\n", |
196 |
+ |
progname, tdiff); |
197 |
+ |
#endif |
198 |
+ |
for (n = rbf->nrbf; n-- > 0; ) { |
199 |
+ |
ovec_from_pos(outvec, rbf->rbfa[n].gx, rbf->rbfa[n].gy); |
200 |
+ |
spinvector(outvec, outvec, vnorm, phi); |
201 |
+ |
pos_from_vec(pos, outvec); |
202 |
+ |
rbf->rbfa[n].gx = pos[0]; |
203 |
+ |
rbf->rbfa[n].gy = pos[1]; |
204 |
+ |
} |
205 |
+ |
VCOPY(rbf->invec, invec); |
206 |
+ |
} |
207 |
+ |
|
208 |
|
/* Compute volume associated with Gaussian lobe */ |
209 |
|
double |
210 |
|
rbf_volume(const RBFVAL *rbfp) |
221 |
|
double uv[2]; |
222 |
|
double r2; |
223 |
|
|
224 |
< |
SDsquare2disk(uv, (1./GRIDRES)*(xpos+.5), (1./GRIDRES)*(ypos+.5)); |
224 |
> |
SDsquare2disk(uv, (1./grid_res)*(xpos+.5), (1./grid_res)*(ypos+.5)); |
225 |
|
/* uniform hemispherical projection */ |
226 |
|
r2 = uv[0]*uv[0] + uv[1]*uv[1]; |
227 |
|
vec[0] = vec[1] = sqrt(2. - r2); |
239 |
|
|
240 |
|
SDdisk2square(sq, vec[0]*norm, vec[1]*norm); |
241 |
|
|
242 |
< |
pos[0] = (int)(sq[0]*GRIDRES); |
243 |
< |
pos[1] = (int)(sq[1]*GRIDRES); |
242 |
> |
pos[0] = (int)(sq[0]*grid_res); |
243 |
> |
pos[1] = (int)(sq[1]*grid_res); |
244 |
|
} |
245 |
|
|
246 |
|
/* Evaluate RBF for DSF at the given normalized outgoing direction */ |
382 |
|
inp_coverage = 0; |
383 |
|
single_plane_incident = -1; |
384 |
|
input_orient = output_orient = 0; |
385 |
+ |
grid_res = GRIDRES; |
386 |
|
} |
387 |
|
|
388 |
|
/* Write our BSDF mesh interpolant out to the given binary stream */ |
395 |
|
/* finish header */ |
396 |
|
fprintf(ofp, "SYMMETRY=%d\n", !single_plane_incident * inp_coverage); |
397 |
|
fprintf(ofp, "IO_SIDES= %d %d\n", input_orient, output_orient); |
398 |
+ |
fprintf(ofp, "GRIDRES=%d\n", grid_res); |
399 |
|
fputformat(BSDFREP_FMT, ofp); |
400 |
|
fputc('\n', ofp); |
401 |
|
/* write each DSF */ |
457 |
|
sscanf(s+9, "%d %d", &input_orient, &output_orient); |
458 |
|
return(0); |
459 |
|
} |
460 |
+ |
if (!strncmp(s, "GRIDRES=", 8)) { |
461 |
+ |
sscanf(s+8, "%d", &grid_res); |
462 |
+ |
return(0); |
463 |
+ |
} |
464 |
|
if (formatval(fmt, s) && strcmp(fmt, BSDFREP_FMT)) |
465 |
|
return(-1); |
466 |
|
return(0); |
475 |
|
int i; |
476 |
|
|
477 |
|
clear_bsdf_rep(); |
478 |
+ |
if (ifp == NULL) |
479 |
+ |
return(0); |
480 |
|
if (getheader(ifp, headline, NULL) < 0 || single_plane_incident < 0 | |
481 |
|
!input_orient | !output_orient) { |
482 |
|
fprintf(stderr, "%s: missing/bad format for BSDF interpolant\n", |