1 |
greg |
2.1 |
#ifndef lint |
2 |
greg |
2.3 |
static const char RCSid[] = "$Id: bsdf2rad.c,v 2.2 2013/10/31 18:03:13 greg Exp $"; |
3 |
greg |
2.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Plot 3-D BSDF output based on scattering interpolant representation |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#define _USE_MATH_DEFINES |
9 |
|
|
#include <stdio.h> |
10 |
|
|
#include <stdlib.h> |
11 |
|
|
#include <math.h> |
12 |
|
|
#include "bsdfrep.h" |
13 |
|
|
|
14 |
|
|
const float colarr[6][3] = { |
15 |
|
|
.7, 1., .7, |
16 |
|
|
1., .7, .7, |
17 |
|
|
.7, .7, 1., |
18 |
|
|
1., .5, 1., |
19 |
|
|
1., 1., .5, |
20 |
|
|
.5, 1., 1. |
21 |
|
|
}; |
22 |
|
|
|
23 |
|
|
char *progname; |
24 |
|
|
|
25 |
|
|
/* Produce a Radiance model plotting the indicated incident direction(s) */ |
26 |
|
|
int |
27 |
|
|
main(int argc, char *argv[]) |
28 |
|
|
{ |
29 |
greg |
2.2 |
int showPeaks = 0; |
30 |
greg |
2.1 |
char buf[128]; |
31 |
|
|
FILE *fp; |
32 |
|
|
RBFNODE *rbf; |
33 |
|
|
double bsdf, min_log; |
34 |
|
|
FVECT dir; |
35 |
|
|
int i, j, n; |
36 |
|
|
|
37 |
|
|
progname = argv[0]; |
38 |
greg |
2.2 |
if (argc > 1 && !strcmp(argv[1], "-p")) { |
39 |
|
|
++showPeaks; |
40 |
|
|
++argv; --argc; |
41 |
|
|
} |
42 |
greg |
2.1 |
if (argc < 4) { |
43 |
greg |
2.2 |
fprintf(stderr, "Usage: %s [-p] bsdf.sir theta1 phi1 .. > output.rad\n", progname); |
44 |
greg |
2.1 |
return(1); |
45 |
|
|
} |
46 |
|
|
/* load input */ |
47 |
|
|
if ((fp = fopen(argv[1], "rb")) == NULL) { |
48 |
|
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
49 |
greg |
2.2 |
progname, argv[1]); |
50 |
greg |
2.1 |
return(1); |
51 |
|
|
} |
52 |
|
|
if (!load_bsdf_rep(fp)) |
53 |
|
|
return(1); |
54 |
|
|
fclose(fp); |
55 |
|
|
min_log = log(bsdf_min*.5); |
56 |
greg |
2.2 |
/* output BSDF rep. */ |
57 |
greg |
2.1 |
for (n = 0; (n < 6) & (2*n+3 < argc); n++) { |
58 |
|
|
dir[2] = sin((M_PI/180.)*atof(argv[2*n+2])); |
59 |
|
|
dir[0] = dir[2] * cos((M_PI/180.)*atof(argv[2*n+3])); |
60 |
|
|
dir[1] = dir[2] * sin((M_PI/180.)*atof(argv[2*n+3])); |
61 |
|
|
dir[2] = input_orient * sqrt(1. - dir[2]*dir[2]); |
62 |
greg |
2.3 |
#ifdef DEBUG |
63 |
greg |
2.1 |
fprintf(stderr, "Computing DSF for incident direction (%.1f,%.1f)\n", |
64 |
|
|
get_theta180(dir), get_phi360(dir)); |
65 |
greg |
2.3 |
#endif |
66 |
greg |
2.1 |
rbf = advect_rbf(dir, 15000); |
67 |
greg |
2.3 |
#ifdef DEBUG |
68 |
greg |
2.1 |
if (rbf == NULL) |
69 |
|
|
fputs("NULL RBF\n", stderr); |
70 |
|
|
else |
71 |
|
|
fprintf(stderr, "Hemispherical reflectance: %.3f\n", rbf->vtotal); |
72 |
greg |
2.3 |
#endif |
73 |
greg |
2.2 |
printf("void trans tmat\n0\n0\n7 %f %f %f .04 .04 .9 1\n", |
74 |
|
|
colarr[n][0], colarr[n][1], colarr[n][2]); |
75 |
|
|
if (showPeaks && rbf != NULL) { |
76 |
|
|
printf("void plastic pmat\n0\n0\n5 %f %f %f .04 .08\n", |
77 |
|
|
1.-colarr[n][0], 1.-colarr[n][1], 1.-colarr[n][2]); |
78 |
|
|
for (i = 0; i < rbf->nrbf; i++) { |
79 |
|
|
ovec_from_pos(dir, rbf->rbfa[i].gx, rbf->rbfa[i].gy); |
80 |
|
|
bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]); |
81 |
|
|
bsdf = log(bsdf) - min_log; |
82 |
|
|
printf("pmat sphere p%d\n0\n0\n4 %f %f %f %f\n", |
83 |
|
|
i+1, dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
84 |
|
|
.007*bsdf); |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
fflush(stdout); |
88 |
|
|
sprintf(buf, "gensurf tmat bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
89 |
|
|
fp = popen(buf, "w"); |
90 |
|
|
if (fp == NULL) { |
91 |
|
|
fprintf(stderr, "%s: cannot open '| %s'\n", progname, buf); |
92 |
|
|
return(1); |
93 |
|
|
} |
94 |
greg |
2.1 |
for (i = 0; i < GRIDRES; i++) |
95 |
|
|
for (j = 0; j < GRIDRES; j++) { |
96 |
|
|
ovec_from_pos(dir, i, j); |
97 |
|
|
bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]); |
98 |
|
|
bsdf = log(bsdf) - min_log; |
99 |
|
|
fprintf(fp, "%.8e %.8e %.8e\n", |
100 |
|
|
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
101 |
|
|
} |
102 |
|
|
if (rbf != NULL) |
103 |
|
|
free(rbf); |
104 |
|
|
if (pclose(fp)) |
105 |
|
|
return(1); |
106 |
|
|
} |
107 |
|
|
return(0); |
108 |
|
|
} |