1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#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 |
char buf[128]; |
30 |
FILE *fp; |
31 |
RBFNODE *rbf; |
32 |
double bsdf, min_log; |
33 |
FVECT dir; |
34 |
int i, j, n; |
35 |
|
36 |
progname = argv[0]; |
37 |
if (argc < 4) { |
38 |
fprintf(stderr, "Usage: %s bsdf.sir theta1 phi1 .. > output.rad\n", argv[0]); |
39 |
return(1); |
40 |
} |
41 |
/* load input */ |
42 |
if ((fp = fopen(argv[1], "rb")) == NULL) { |
43 |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
44 |
argv[0], argv[1]); |
45 |
return(1); |
46 |
} |
47 |
if (!load_bsdf_rep(fp)) |
48 |
return(1); |
49 |
fclose(fp); |
50 |
min_log = log(bsdf_min*.5); |
51 |
/* output surface(s) */ |
52 |
for (n = 0; (n < 6) & (2*n+3 < argc); n++) { |
53 |
printf("void trans tmat\n0\n0\n7 %f %f %f .04 .04 .9 1\n", |
54 |
colarr[n][0], colarr[n][1], colarr[n][2]); |
55 |
fflush(stdout); |
56 |
sprintf(buf, "gensurf tmat bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
57 |
fp = popen(buf, "w"); |
58 |
if (fp == NULL) { |
59 |
fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); |
60 |
return(1); |
61 |
} |
62 |
dir[2] = sin((M_PI/180.)*atof(argv[2*n+2])); |
63 |
dir[0] = dir[2] * cos((M_PI/180.)*atof(argv[2*n+3])); |
64 |
dir[1] = dir[2] * sin((M_PI/180.)*atof(argv[2*n+3])); |
65 |
dir[2] = input_orient * sqrt(1. - dir[2]*dir[2]); |
66 |
fprintf(stderr, "Computing DSF for incident direction (%.1f,%.1f)\n", |
67 |
get_theta180(dir), get_phi360(dir)); |
68 |
rbf = advect_rbf(dir, 15000); |
69 |
if (rbf == NULL) |
70 |
fputs("NULL RBF\n", stderr); |
71 |
else |
72 |
fprintf(stderr, "Hemispherical reflectance: %.3f\n", rbf->vtotal); |
73 |
for (i = 0; i < GRIDRES; i++) |
74 |
for (j = 0; j < GRIDRES; j++) { |
75 |
ovec_from_pos(dir, i, j); |
76 |
bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]); |
77 |
bsdf = log(bsdf) - min_log; |
78 |
fprintf(fp, "%.8e %.8e %.8e\n", |
79 |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
80 |
} |
81 |
if (rbf != NULL) |
82 |
free(rbf); |
83 |
if (pclose(fp)) |
84 |
return(1); |
85 |
} |
86 |
return(0); |
87 |
} |