11 |
|
#include <stdlib.h> |
12 |
|
#include <string.h> |
13 |
|
#include <ctype.h> |
14 |
+ |
#include <math.h> |
15 |
|
#include "platform.h" |
16 |
|
#include "bsdfrep.h" |
17 |
|
/* global argv[0] */ |
145 |
|
return(1); |
146 |
|
} |
147 |
|
|
148 |
+ |
#if 1 |
149 |
|
/* Read in PAB-Opto BSDF files and output RBF interpolant */ |
150 |
|
int |
151 |
|
main(int argc, char *argv[]) |
192 |
|
progname); |
193 |
|
return(1); |
194 |
|
} |
195 |
+ |
#else |
196 |
+ |
/* Test main produces a Radiance model from the given input file */ |
197 |
+ |
int |
198 |
+ |
main(int argc, char *argv[]) |
199 |
+ |
{ |
200 |
+ |
PGINPUT pginp; |
201 |
+ |
char buf[128]; |
202 |
+ |
FILE *pfp; |
203 |
+ |
double bsdf, min_log; |
204 |
+ |
FVECT dir; |
205 |
+ |
int i, j, n; |
206 |
+ |
|
207 |
+ |
if (argc != 2) { |
208 |
+ |
fprintf(stderr, "Usage: %s input.dat > output.rad\n", argv[0]); |
209 |
+ |
return(1); |
210 |
+ |
} |
211 |
+ |
ninpfiles = 1; |
212 |
+ |
inpfile = &pginp; |
213 |
+ |
if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0)) |
214 |
+ |
return(1); |
215 |
+ |
/* reduce data set */ |
216 |
+ |
make_rbfrep(); |
217 |
+ |
/* produce spheres at meas. */ |
218 |
+ |
puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n"); |
219 |
+ |
puts("void plastic pink\n0\n0\n5 .5 .05 .9 .04 .08\n"); |
220 |
+ |
min_log = log(bsdf_min*.5); |
221 |
+ |
n = 0; |
222 |
+ |
for (i = 0; i < GRIDRES; i++) |
223 |
+ |
for (j = 0; j < GRIDRES; j++) |
224 |
+ |
if (dsf_grid[i][j].vsum > .0f) { |
225 |
+ |
ovec_from_pos(dir, i, j); |
226 |
+ |
bsdf = dsf_grid[i][j].vsum / dir[2]; |
227 |
+ |
if (bsdf <= bsdf_min*.6) |
228 |
+ |
continue; |
229 |
+ |
bsdf = log(bsdf) - min_log; |
230 |
+ |
if (dsf_grid[i][j].nval) { |
231 |
+ |
printf("pink cone c%04d\n0\n0\n8\n", ++n); |
232 |
+ |
printf("\t%.6g %.6g %.6g\n", |
233 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
234 |
+ |
printf("\t%.6g %.6g %.6g\n", |
235 |
+ |
dir[0]*bsdf*1.02, dir[1]*bsdf*1.02, |
236 |
+ |
dir[2]*bsdf*1.02); |
237 |
+ |
printf("\t%.6g\t0\n", .02*bsdf); |
238 |
+ |
} else { |
239 |
+ |
ovec_from_pos(dir, i, j); |
240 |
+ |
printf("yellow sphere s%04d\n0\n0\n", ++n); |
241 |
+ |
printf("4 %.6g %.6g %.6g %.6g\n\n", |
242 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
243 |
+ |
.01*bsdf); |
244 |
+ |
} |
245 |
+ |
} |
246 |
+ |
/* output continuous surface */ |
247 |
+ |
puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n"); |
248 |
+ |
fflush(stdout); |
249 |
+ |
sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
250 |
+ |
pfp = popen(buf, "w"); |
251 |
+ |
if (pfp == NULL) { |
252 |
+ |
fputs(buf, stderr); |
253 |
+ |
fputs(": cannot start command\n", stderr); |
254 |
+ |
return(1); |
255 |
+ |
} |
256 |
+ |
for (i = 0; i < GRIDRES; i++) |
257 |
+ |
for (j = 0; j < GRIDRES; j++) { |
258 |
+ |
ovec_from_pos(dir, i, j); |
259 |
+ |
bsdf = eval_rbfrep(dsf_list, dir) / dir[2]; |
260 |
+ |
bsdf = log(bsdf) - min_log; |
261 |
+ |
fprintf(pfp, "%.8e %.8e %.8e\n", |
262 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
263 |
+ |
} |
264 |
+ |
return(pclose(pfp)==0 ? 0 : 1); |
265 |
+ |
} |
266 |
+ |
#endif |