9 |
|
|
10 |
|
#define _USE_MATH_DEFINES |
11 |
|
#include <stdlib.h> |
12 |
– |
#include <string.h> |
12 |
|
#include <math.h> |
13 |
|
#include "rtio.h" |
14 |
|
#include "resolu.h" |
41 |
|
|
42 |
|
/* BSDF value for boundary regions */ |
43 |
|
double bsdf_min = 0; |
44 |
< |
double bsdf_spec_peak = 0; |
44 |
> |
double bsdf_spec_val = 0; |
45 |
|
double bsdf_spec_rad = 0; |
46 |
|
|
47 |
|
/* processed incident DSF measurements */ |
53 |
|
/* current input direction */ |
54 |
|
double theta_in_deg, phi_in_deg; |
55 |
|
|
56 |
+ |
/* header line sharing callback */ |
57 |
+ |
int (*sir_headshare)(char *s) = NULL; |
58 |
+ |
|
59 |
|
/* Register new input direction */ |
60 |
|
int |
61 |
|
new_input_direction(double new_theta, double new_phi) |
104 |
|
int |
105 |
|
use_symmetry(FVECT vec) |
106 |
|
{ |
107 |
< |
const double phi = get_phi360(vec); |
107 |
> |
double phi = get_phi360(vec); |
108 |
> |
/* because of -0. issue */ |
109 |
> |
while (phi >= 360.) phi -= 360.; |
110 |
> |
while (phi < 0.) phi += 360.; |
111 |
|
|
112 |
|
switch (inp_coverage) { |
113 |
|
case INP_QUAD1|INP_QUAD2|INP_QUAD3|INP_QUAD4: |
228 |
|
void |
229 |
|
ovec_from_pos(FVECT vec, int xpos, int ypos) |
230 |
|
{ |
231 |
< |
double uv[2]; |
231 |
> |
RREAL uv[2]; |
232 |
|
double r2; |
233 |
|
|
234 |
< |
SDsquare2disk(uv, (xpos+.5)/grid_res, (ypos+.5)/grid_res); |
234 |
> |
square2disk(uv, (xpos+.5)/grid_res, (ypos+.5)/grid_res); |
235 |
|
/* uniform hemispherical projection */ |
236 |
|
r2 = uv[0]*uv[0] + uv[1]*uv[1]; |
237 |
|
vec[0] = vec[1] = sqrt(2. - r2); |
244 |
|
void |
245 |
|
pos_from_vec(int pos[2], const FVECT vec) |
246 |
|
{ |
247 |
< |
double sq[2]; /* uniform hemispherical projection */ |
247 |
> |
RREAL sq[2]; /* uniform hemispherical projection */ |
248 |
|
double norm = 1./sqrt(1. + fabs(vec[2])); |
249 |
|
|
250 |
< |
SDdisk2square(sq, vec[0]*norm, vec[1]*norm); |
250 |
> |
disk2square(sq, vec[0]*norm, vec[1]*norm); |
251 |
|
|
252 |
|
pos[0] = (int)(sq[0]*grid_res); |
253 |
|
pos[1] = (int)(sq[1]*grid_res); |
315 |
|
} |
316 |
|
res += val; |
317 |
|
} |
318 |
< |
if ((rbf_colorimetry == RBCtristimulus) & (res > 1e-6)) { |
318 |
> |
sv->cieY = res / COSF(outvec[2]); |
319 |
> |
if (sv->cieY < bsdf_min) { /* never return less than bsdf_min */ |
320 |
> |
sv->cieY = bsdf_min; |
321 |
> |
} else if (rbf_colorimetry == RBCtristimulus) { |
322 |
|
C_CHROMA cres = (int)(usum/res + frandom()); |
323 |
|
cres |= (int)(vsum/res + frandom()) << 8; |
324 |
|
c_decodeChroma(&sv->spec, cres); |
325 |
|
} |
318 |
– |
sv->cieY = res / COSF(outvec[2]); |
319 |
– |
if (sv->cieY < bsdf_min) /* never return less than bsdf_min */ |
320 |
– |
sv->cieY = bsdf_min; |
326 |
|
return(SDEnone); |
327 |
|
} |
328 |
|
|
448 |
|
|
449 |
|
if (input_orient > 0 ^ invec[2] > 0) /* wrong side? */ |
450 |
|
return(NULL); |
451 |
< |
if ((bsdf_spec_peak <= bsdf_min) | (bsdf_spec_rad <= 0)) |
451 |
> |
if ((bsdf_spec_val <= bsdf_min) | (bsdf_spec_rad <= 0)) |
452 |
|
return(NULL); /* nothing set */ |
453 |
|
rbf = (RBFNODE *)malloc(sizeof(RBFNODE)); |
454 |
|
if (rbf == NULL) |
462 |
|
rbf->ejl = NULL; |
463 |
|
VCOPY(rbf->invec, invec); |
464 |
|
rbf->nrbf = 1; |
465 |
< |
rbf->rbfa[0].peak = bsdf_spec_peak * output_orient*ovec[2]; |
465 |
> |
rbf->rbfa[0].peak = bsdf_spec_val * COSF(ovec[2]); |
466 |
|
rbf->rbfa[0].chroma = c_dfchroma; |
467 |
|
rbf->rbfa[0].crad = ANG2R(bsdf_spec_rad); |
468 |
|
rbf->rbfa[0].gx = pos[0]; |
481 |
|
double t, full_dist; |
482 |
|
/* get relative position */ |
483 |
|
t = Acos(DOT(invec, mig->rbfv[0]->invec)); |
484 |
< |
if (t < M_PI/grid_res) { /* near first DSF */ |
484 |
> |
if (t <= .001) { /* near first DSF */ |
485 |
|
n = sizeof(RBFNODE) + sizeof(RBFVAL)*(mig->rbfv[0]->nrbf-1); |
486 |
|
rbf = (RBFNODE *)malloc(n); |
487 |
|
if (rbf == NULL) |
491 |
|
return(rbf); |
492 |
|
} |
493 |
|
full_dist = acos(DOT(mig->rbfv[0]->invec, mig->rbfv[1]->invec)); |
494 |
< |
if (t > full_dist-M_PI/grid_res) { /* near second DSF */ |
494 |
> |
if (t >= full_dist-.001) { /* near second DSF */ |
495 |
|
n = sizeof(RBFNODE) + sizeof(RBFVAL)*(mig->rbfv[1]->nrbf-1); |
496 |
|
rbf = (RBFNODE *)malloc(n); |
497 |
|
if (rbf == NULL) |
587 |
|
input_orient = output_orient = 0; |
588 |
|
rbf_colorimetry = RBCunknown; |
589 |
|
grid_res = GRIDRES; |
590 |
+ |
memset(bsdf_hist, 0, sizeof(bsdf_hist)); |
591 |
|
bsdf_min = 0; |
592 |
< |
bsdf_spec_peak = 0; |
592 |
> |
bsdf_spec_val = 0; |
593 |
|
bsdf_spec_rad = 0; |
594 |
|
} |
595 |
|
|
610 |
|
fprintf(ofp, "COLORIMETRY=%s\n", RBCident[rbf_colorimetry]); |
611 |
|
fprintf(ofp, "GRIDRES=%d\n", grid_res); |
612 |
|
fprintf(ofp, "BSDFMIN=%g\n", bsdf_min); |
613 |
< |
if ((bsdf_spec_peak > bsdf_min) & (bsdf_spec_rad > 0)) |
614 |
< |
fprintf(ofp, "BSDFSPEC= %f %f\n", bsdf_spec_peak, bsdf_spec_rad); |
613 |
> |
if ((bsdf_spec_val > bsdf_min) & (bsdf_spec_rad > 0)) |
614 |
> |
fprintf(ofp, "BSDFSPEC= %f %f\n", bsdf_spec_val, bsdf_spec_rad); |
615 |
|
fputformat(BSDFREP_FMT, ofp); |
616 |
|
fputc('\n', ofp); |
617 |
|
putint(BSDFREP_MAGIC, 2, ofp); |
664 |
|
static int |
665 |
|
headline(char *s, void *p) |
666 |
|
{ |
667 |
< |
char fmt[64]; |
667 |
> |
char fmt[MAXFMTLEN]; |
668 |
|
int i; |
669 |
|
|
670 |
+ |
if (isheadid(s)) |
671 |
+ |
return(0); |
672 |
|
if (!strncmp(s, "NAME=", 5)) { |
673 |
|
strcpy(bsdf_name, s+5); |
674 |
|
bsdf_name[strlen(bsdf_name)-1] = '\0'; |
675 |
+ |
return(1); |
676 |
|
} |
677 |
|
if (!strncmp(s, "MANUFACT=", 9)) { |
678 |
|
strcpy(bsdf_manuf, s+9); |
679 |
|
bsdf_manuf[strlen(bsdf_manuf)-1] = '\0'; |
680 |
+ |
return(1); |
681 |
|
} |
682 |
|
if (!strncmp(s, "SYMMETRY=", 9)) { |
683 |
|
inp_coverage = atoi(s+9); |
684 |
|
single_plane_incident = !inp_coverage; |
685 |
< |
return(0); |
685 |
> |
return(1); |
686 |
|
} |
687 |
|
if (!strncmp(s, "IO_SIDES=", 9)) { |
688 |
|
sscanf(s+9, "%d %d", &input_orient, &output_orient); |
689 |
< |
return(0); |
689 |
> |
return(1); |
690 |
|
} |
691 |
|
if (!strncmp(s, "COLORIMETRY=", 12)) { |
692 |
|
fmt[0] = '\0'; |
697 |
|
if (i < 0) |
698 |
|
return(-1); |
699 |
|
rbf_colorimetry = i; |
700 |
< |
return(0); |
700 |
> |
return(1); |
701 |
|
} |
702 |
|
if (!strncmp(s, "GRIDRES=", 8)) { |
703 |
|
sscanf(s+8, "%d", &grid_res); |
704 |
< |
return(0); |
704 |
> |
return(1); |
705 |
|
} |
706 |
|
if (!strncmp(s, "BSDFMIN=", 8)) { |
707 |
|
sscanf(s+8, "%lf", &bsdf_min); |
708 |
< |
return(0); |
708 |
> |
return(1); |
709 |
|
} |
710 |
|
if (!strncmp(s, "BSDFSPEC=", 9)) { |
711 |
< |
sscanf(s+9, "%lf %lf", &bsdf_spec_peak, &bsdf_spec_rad); |
712 |
< |
return(0); |
711 |
> |
sscanf(s+9, "%lf %lf", &bsdf_spec_val, &bsdf_spec_rad); |
712 |
> |
return(1); |
713 |
|
} |
714 |
< |
if (formatval(fmt, s) && strcmp(fmt, BSDFREP_FMT)) |
715 |
< |
return(-1); |
714 |
> |
if (formatval(fmt, s)) |
715 |
> |
return (strcmp(fmt, BSDFREP_FMT) ? -1 : 0); |
716 |
> |
if (sir_headshare != NULL) |
717 |
> |
return ((*sir_headshare)(s)); |
718 |
|
return(0); |
719 |
|
} |
720 |
|
|