1 |
greg |
2.1 |
#ifndef lint |
2 |
|
|
static const char RCSid[] = "$Id$"; |
3 |
|
|
#endif |
4 |
|
|
/* |
5 |
|
|
* Load measured BSDF data in PAB-Opto format. |
6 |
|
|
* |
7 |
|
|
* G. Ward |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <stdio.h> |
11 |
|
|
#include <string.h> |
12 |
|
|
#include <ctype.h> |
13 |
|
|
#include "platform.h" |
14 |
|
|
#include "bsdfrep.h" |
15 |
|
|
/* global argv[0] */ |
16 |
|
|
char *progname; |
17 |
|
|
|
18 |
|
|
/* Load a set of measurements corresponding to a particular incident angle */ |
19 |
|
|
static int |
20 |
|
|
load_pabopto_meas(const char *fname) |
21 |
|
|
{ |
22 |
|
|
FILE *fp = fopen(fname, "r"); |
23 |
|
|
int inp_is_DSF = -1; |
24 |
|
|
double new_theta, new_phi, theta_out, phi_out, val; |
25 |
|
|
char buf[2048]; |
26 |
|
|
int n, c; |
27 |
|
|
|
28 |
|
|
if (fp == NULL) { |
29 |
|
|
fputs(fname, stderr); |
30 |
|
|
fputs(": cannot open\n", stderr); |
31 |
|
|
return(0); |
32 |
|
|
} |
33 |
|
|
#ifdef DEBUG |
34 |
|
|
fprintf(stderr, "Loading measurement file '%s'...\n", fname); |
35 |
|
|
#endif |
36 |
|
|
/* read header information */ |
37 |
|
|
while ((c = getc(fp)) == '#' || c == EOF) { |
38 |
|
|
if (fgets(buf, sizeof(buf), fp) == NULL) { |
39 |
|
|
fputs(fname, stderr); |
40 |
|
|
fputs(": unexpected EOF\n", stderr); |
41 |
|
|
fclose(fp); |
42 |
|
|
return(0); |
43 |
|
|
} |
44 |
|
|
if (!strcmp(buf, "format: theta phi DSF\n")) { |
45 |
|
|
inp_is_DSF = 1; |
46 |
|
|
continue; |
47 |
|
|
} |
48 |
|
|
if (!strcmp(buf, "format: theta phi BSDF\n")) { |
49 |
|
|
inp_is_DSF = 0; |
50 |
|
|
continue; |
51 |
|
|
} |
52 |
|
|
if (sscanf(buf, "intheta %lf", &new_theta) == 1) |
53 |
|
|
continue; |
54 |
|
|
if (sscanf(buf, "inphi %lf", &new_phi) == 1) |
55 |
|
|
continue; |
56 |
|
|
if (sscanf(buf, "incident_angle %lf %lf", |
57 |
|
|
&new_theta, &new_phi) == 2) |
58 |
|
|
continue; |
59 |
|
|
} |
60 |
|
|
ungetc(c, fp); |
61 |
|
|
if (inp_is_DSF < 0) { |
62 |
|
|
fputs(fname, stderr); |
63 |
|
|
fputs(": unknown format\n", stderr); |
64 |
|
|
fclose(fp); |
65 |
|
|
return(0); |
66 |
|
|
} |
67 |
|
|
/* prepare input grid */ |
68 |
|
|
new_bsdf_data(new_theta, new_phi); |
69 |
|
|
/* read actual data */ |
70 |
|
|
while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3) |
71 |
|
|
add_bsdf_data(theta_out, phi_out, val, inp_is_DSF); |
72 |
|
|
n = 0; |
73 |
|
|
while ((c = getc(fp)) != EOF) |
74 |
|
|
n += !isspace(c); |
75 |
|
|
if (n) |
76 |
|
|
fprintf(stderr, |
77 |
|
|
"%s: warning: %d unexpected characters past EOD\n", |
78 |
|
|
fname, n); |
79 |
|
|
fclose(fp); |
80 |
|
|
return(1); |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
/* Read in PAB-Opto BSDF files and output RBF interpolant */ |
84 |
|
|
int |
85 |
|
|
main(int argc, char *argv[]) |
86 |
|
|
{ |
87 |
|
|
extern int nprocs; |
88 |
|
|
int i; |
89 |
|
|
/* start header */ |
90 |
|
|
SET_FILE_BINARY(stdout); |
91 |
|
|
newheader("RADIANCE", stdout); |
92 |
|
|
printargs(argc, argv, stdout); |
93 |
|
|
fputnow(stdout); |
94 |
|
|
progname = argv[0]; /* get options */ |
95 |
|
|
while (argc > 2 && argv[1][0] == '-') { |
96 |
|
|
switch (argv[1][1]) { |
97 |
|
|
case 'n': |
98 |
|
|
nprocs = atoi(argv[2]); |
99 |
|
|
break; |
100 |
|
|
default: |
101 |
|
|
goto userr; |
102 |
|
|
} |
103 |
|
|
argv += 2; argc -= 2; |
104 |
|
|
} |
105 |
|
|
if (argc < 3) |
106 |
|
|
goto userr; |
107 |
|
|
for (i = 1; i < argc; i++) { /* compile measurements */ |
108 |
|
|
if (!load_pabopto_meas(argv[i])) |
109 |
|
|
return(1); |
110 |
|
|
make_rbfrep(); |
111 |
|
|
} |
112 |
|
|
build_mesh(); /* create interpolation */ |
113 |
|
|
save_bsdf_rep(stdout); /* write it out */ |
114 |
|
|
return(0); |
115 |
|
|
userr: |
116 |
|
|
fprintf(stderr, "Usage: %s [-n nproc] meas1.dat meas2.dat .. > bsdf.sir\n", |
117 |
|
|
progname); |
118 |
|
|
return(1); |
119 |
|
|
} |