ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdf2rad.c
Revision: 2.2
Committed: Thu Oct 31 18:03:13 2013 UTC (10 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +30 -13 lines
Log Message:
Added -p option to output peak positions as spheres

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: bsdf2rad.c,v 2.1 2013/10/22 04:29:27 greg Exp $";
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 int showPeaks = 0;
30 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 if (argc > 1 && !strcmp(argv[1], "-p")) {
39 ++showPeaks;
40 ++argv; --argc;
41 }
42 if (argc < 4) {
43 fprintf(stderr, "Usage: %s [-p] bsdf.sir theta1 phi1 .. > output.rad\n", progname);
44 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 progname, argv[1]);
50 return(1);
51 }
52 if (!load_bsdf_rep(fp))
53 return(1);
54 fclose(fp);
55 min_log = log(bsdf_min*.5);
56 /* output BSDF rep. */
57 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 fprintf(stderr, "Computing DSF for incident direction (%.1f,%.1f)\n",
63 get_theta180(dir), get_phi360(dir));
64 rbf = advect_rbf(dir, 15000);
65 if (rbf == NULL)
66 fputs("NULL RBF\n", stderr);
67 else
68 fprintf(stderr, "Hemispherical reflectance: %.3f\n", rbf->vtotal);
69 printf("void trans tmat\n0\n0\n7 %f %f %f .04 .04 .9 1\n",
70 colarr[n][0], colarr[n][1], colarr[n][2]);
71 if (showPeaks && rbf != NULL) {
72 printf("void plastic pmat\n0\n0\n5 %f %f %f .04 .08\n",
73 1.-colarr[n][0], 1.-colarr[n][1], 1.-colarr[n][2]);
74 for (i = 0; i < rbf->nrbf; i++) {
75 ovec_from_pos(dir, rbf->rbfa[i].gx, rbf->rbfa[i].gy);
76 bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]);
77 bsdf = log(bsdf) - min_log;
78 printf("pmat sphere p%d\n0\n0\n4 %f %f %f %f\n",
79 i+1, dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf,
80 .007*bsdf);
81 }
82 }
83 fflush(stdout);
84 sprintf(buf, "gensurf tmat bsdf - - - %d %d", GRIDRES-1, GRIDRES-1);
85 fp = popen(buf, "w");
86 if (fp == NULL) {
87 fprintf(stderr, "%s: cannot open '| %s'\n", progname, buf);
88 return(1);
89 }
90 for (i = 0; i < GRIDRES; i++)
91 for (j = 0; j < GRIDRES; j++) {
92 ovec_from_pos(dir, i, j);
93 bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]);
94 bsdf = log(bsdf) - min_log;
95 fprintf(fp, "%.8e %.8e %.8e\n",
96 dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf);
97 }
98 if (rbf != NULL)
99 free(rbf);
100 if (pclose(fp))
101 return(1);
102 }
103 return(0);
104 }