| 2 |
|
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
|
/* |
| 5 |
< |
* Plot 3-D BSDF output based on scattering interpolant representation |
| 5 |
> |
* Plot 3-D BSDF output based on scattering interpolant or XML representation |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
#define _USE_MATH_DEFINES |
| 9 |
|
#include <stdio.h> |
| 10 |
+ |
#include <string.h> |
| 11 |
|
#include <stdlib.h> |
| 12 |
|
#include <math.h> |
| 13 |
|
#include "bsdfrep.h" |
| 28 |
|
main(int argc, char *argv[]) |
| 29 |
|
{ |
| 30 |
|
int showPeaks = 0; |
| 31 |
< |
char buf[128]; |
| 31 |
> |
int doTrans = 0; |
| 32 |
> |
int inpXML = -1; |
| 33 |
> |
RBFNODE *rbf = NULL; |
| 34 |
|
FILE *fp; |
| 35 |
< |
RBFNODE *rbf; |
| 35 |
> |
char buf[128]; |
| 36 |
> |
SDData myBSDF; |
| 37 |
|
double bsdf, min_log; |
| 38 |
< |
FVECT dir; |
| 38 |
> |
FVECT idir, odir; |
| 39 |
|
int i, j, n; |
| 40 |
< |
|
| 40 |
> |
/* check arguments */ |
| 41 |
|
progname = argv[0]; |
| 42 |
|
if (argc > 1 && !strcmp(argv[1], "-p")) { |
| 43 |
|
++showPeaks; |
| 44 |
|
++argv; --argc; |
| 45 |
|
} |
| 46 |
< |
if (argc < 4) { |
| 46 |
> |
if (argc > 1 && !strcmp(argv[1], "-t")) { |
| 47 |
> |
++doTrans; |
| 48 |
> |
++argv; --argc; |
| 49 |
> |
} |
| 50 |
> |
if (argc >= 4 && (n = strlen(argv[1])-4) > 0) { |
| 51 |
> |
if (!strcasecmp(argv[1]+n, ".xml")) |
| 52 |
> |
inpXML = 1; |
| 53 |
> |
else if (!strcasecmp(argv[1]+n, ".sir")) |
| 54 |
> |
inpXML = 0; |
| 55 |
> |
} |
| 56 |
> |
if (inpXML < 0) { |
| 57 |
|
fprintf(stderr, "Usage: %s [-p] bsdf.sir theta1 phi1 .. > output.rad\n", progname); |
| 58 |
+ |
fprintf(stderr, " Or: %s [-t] bsdf.xml theta1 phi1 .. > output.rad\n", progname); |
| 59 |
|
return(1); |
| 60 |
|
} |
| 61 |
|
/* load input */ |
| 62 |
< |
if ((fp = fopen(argv[1], "rb")) == NULL) { |
| 63 |
< |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
| 64 |
< |
progname, argv[1]); |
| 65 |
< |
return(1); |
| 62 |
> |
if (inpXML) { |
| 63 |
> |
SDclearBSDF(&myBSDF, argv[1]); |
| 64 |
> |
if (SDreportError(SDloadFile(&myBSDF, argv[1]), stderr)) |
| 65 |
> |
return(1); |
| 66 |
> |
bsdf_min = 1./M_PI; |
| 67 |
> |
if (myBSDF.rf != NULL && myBSDF.rLambFront.cieY < bsdf_min*M_PI) |
| 68 |
> |
bsdf_min = myBSDF.rLambFront.cieY/M_PI; |
| 69 |
> |
if (myBSDF.rb != NULL && myBSDF.rLambBack.cieY < bsdf_min*M_PI) |
| 70 |
> |
bsdf_min = myBSDF.rLambBack.cieY/M_PI; |
| 71 |
> |
if ((myBSDF.tf != NULL) | (myBSDF.tb != NULL) && |
| 72 |
> |
myBSDF.tLamb.cieY < bsdf_min*M_PI) |
| 73 |
> |
bsdf_min = myBSDF.tLamb.cieY/M_PI; |
| 74 |
> |
if (doTrans && (myBSDF.tf == NULL) & (myBSDF.tb == NULL)) { |
| 75 |
> |
fprintf(stderr, "%s: no transmitted component in '%s'\n", |
| 76 |
> |
progname, argv[1]); |
| 77 |
> |
return(1); |
| 78 |
> |
} |
| 79 |
> |
} else { |
| 80 |
> |
fp = fopen(argv[1], "rb"); |
| 81 |
> |
if (fp == NULL) { |
| 82 |
> |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
| 83 |
> |
progname, argv[1]); |
| 84 |
> |
return(1); |
| 85 |
> |
} |
| 86 |
> |
if (!load_bsdf_rep(fp)) |
| 87 |
> |
return(1); |
| 88 |
> |
fclose(fp); |
| 89 |
|
} |
| 90 |
< |
if (!load_bsdf_rep(fp)) |
| 91 |
< |
return(1); |
| 92 |
< |
fclose(fp); |
| 90 |
> |
#ifdef DEBUG |
| 91 |
> |
fprintf(stderr, "Minimum BSDF set to %.4f\n", bsdf_min); |
| 92 |
> |
#endif |
| 93 |
|
min_log = log(bsdf_min*.5); |
| 94 |
|
/* output BSDF rep. */ |
| 95 |
|
for (n = 0; (n < 6) & (2*n+3 < argc); n++) { |
| 96 |
< |
dir[2] = sin((M_PI/180.)*atof(argv[2*n+2])); |
| 97 |
< |
dir[0] = dir[2] * cos((M_PI/180.)*atof(argv[2*n+3])); |
| 98 |
< |
dir[1] = dir[2] * sin((M_PI/180.)*atof(argv[2*n+3])); |
| 99 |
< |
dir[2] = input_orient * sqrt(1. - dir[2]*dir[2]); |
| 100 |
< |
fprintf(stderr, "Computing DSF for incident direction (%.1f,%.1f)\n", |
| 101 |
< |
get_theta180(dir), get_phi360(dir)); |
| 102 |
< |
rbf = advect_rbf(dir, 15000); |
| 103 |
< |
if (rbf == NULL) |
| 104 |
< |
fputs("NULL RBF\n", stderr); |
| 96 |
> |
double theta = atof(argv[2*n+2]); |
| 97 |
> |
if (inpXML) { |
| 98 |
> |
input_orient = (theta <= 90.) ? 1 : -1; |
| 99 |
> |
output_orient = doTrans ? -input_orient : input_orient; |
| 100 |
> |
} |
| 101 |
> |
idir[2] = sin((M_PI/180.)*theta); |
| 102 |
> |
idir[0] = idir[2] * cos((M_PI/180.)*atof(argv[2*n+3])); |
| 103 |
> |
idir[1] = idir[2] * sin((M_PI/180.)*atof(argv[2*n+3])); |
| 104 |
> |
idir[2] = input_orient * sqrt(1. - idir[2]*idir[2]); |
| 105 |
> |
#ifdef DEBUG |
| 106 |
> |
fprintf(stderr, "Computing BSDF for incident direction (%.1f,%.1f)\n", |
| 107 |
> |
get_theta180(idir), get_phi360(idir)); |
| 108 |
> |
#endif |
| 109 |
> |
if (!inpXML) |
| 110 |
> |
rbf = advect_rbf(idir, 15000); |
| 111 |
> |
#ifdef DEBUG |
| 112 |
> |
if (inpXML) |
| 113 |
> |
fprintf(stderr, "Hemispherical %s: %.3f\n", |
| 114 |
> |
(output_orient > 0 ? "reflection" : "transmission"), |
| 115 |
> |
SDdirectHemi(idir, SDsampSp|SDsampDf | |
| 116 |
> |
(output_orient > 0 ? |
| 117 |
> |
SDsampR : SDsampT), &myBSDF)); |
| 118 |
> |
else if (rbf == NULL) |
| 119 |
> |
fputs("Empty RBF\n", stderr); |
| 120 |
|
else |
| 121 |
< |
fprintf(stderr, "Hemispherical reflectance: %.3f\n", rbf->vtotal); |
| 121 |
> |
fprintf(stderr, "Hemispherical %s: %.3f\n", |
| 122 |
> |
(output_orient > 0 ? "reflection" : "transmission"), |
| 123 |
> |
rbf->vtotal); |
| 124 |
> |
#endif |
| 125 |
|
printf("void trans tmat\n0\n0\n7 %f %f %f .04 .04 .9 1\n", |
| 126 |
|
colarr[n][0], colarr[n][1], colarr[n][2]); |
| 127 |
|
if (showPeaks && rbf != NULL) { |
| 128 |
|
printf("void plastic pmat\n0\n0\n5 %f %f %f .04 .08\n", |
| 129 |
|
1.-colarr[n][0], 1.-colarr[n][1], 1.-colarr[n][2]); |
| 130 |
|
for (i = 0; i < rbf->nrbf; i++) { |
| 131 |
< |
ovec_from_pos(dir, rbf->rbfa[i].gx, rbf->rbfa[i].gy); |
| 132 |
< |
bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]); |
| 131 |
> |
ovec_from_pos(odir, rbf->rbfa[i].gx, rbf->rbfa[i].gy); |
| 132 |
> |
bsdf = eval_rbfrep(rbf, odir) / (output_orient*odir[2]); |
| 133 |
|
bsdf = log(bsdf) - min_log; |
| 134 |
|
printf("pmat sphere p%d\n0\n0\n4 %f %f %f %f\n", |
| 135 |
< |
i+1, dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
| 135 |
> |
i+1, odir[0]*bsdf, odir[1]*bsdf, odir[2]*bsdf, |
| 136 |
|
.007*bsdf); |
| 137 |
|
} |
| 138 |
|
} |
| 145 |
|
} |
| 146 |
|
for (i = 0; i < GRIDRES; i++) |
| 147 |
|
for (j = 0; j < GRIDRES; j++) { |
| 148 |
< |
ovec_from_pos(dir, i, j); |
| 149 |
< |
bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]); |
| 148 |
> |
ovec_from_pos(odir, i, j); |
| 149 |
> |
if (inpXML) { |
| 150 |
> |
SDValue sval; |
| 151 |
> |
if (SDreportError(SDevalBSDF(&sval, odir, |
| 152 |
> |
idir, &myBSDF), stderr)) |
| 153 |
> |
return(1); |
| 154 |
> |
bsdf = sval.cieY; |
| 155 |
> |
} else |
| 156 |
> |
bsdf = eval_rbfrep(rbf, odir) / |
| 157 |
> |
(output_orient*odir[2]); |
| 158 |
|
bsdf = log(bsdf) - min_log; |
| 159 |
|
fprintf(fp, "%.8e %.8e %.8e\n", |
| 160 |
< |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
| 160 |
> |
odir[0]*bsdf, odir[1]*bsdf, odir[2]*bsdf); |
| 161 |
|
} |
| 162 |
|
if (rbf != NULL) |
| 163 |
|
free(rbf); |