13 |
|
#include "resolu.h" |
14 |
|
#include "bsdfrep.h" |
15 |
|
|
16 |
< |
#define NINCIDENT 25 /* number of samples/hemisphere */ |
16 |
> |
#define NINCIDENT 37 /* number of samples/hemisphere */ |
17 |
|
|
18 |
|
#define GRIDSTEP 2 /* our grid step size */ |
19 |
|
#define SAMPRES (GRIDRES/GRIDSTEP) |
26 |
|
|
27 |
|
char ourTempDir[TEMPLEN] = ""; /* our temporary directory */ |
28 |
|
|
29 |
< |
const FVECT Xaxis = {1., 0., 0.}; |
30 |
< |
const FVECT Yaxis = {0., 1., 0.}; |
31 |
< |
const FVECT Zaxis = {0., 0., 1.}; |
32 |
< |
|
33 |
< |
const char frpref[] = "frefl"; |
34 |
< |
const char ftpref[] = "ftrans"; |
35 |
< |
const char brpref[] = "brefl"; |
36 |
< |
const char btpref[] = "btrans"; |
29 |
> |
const char frpref[] = "rf"; |
30 |
> |
const char ftpref[] = "tf"; |
31 |
> |
const char brpref[] = "rb"; |
32 |
> |
const char btpref[] = "tb"; |
33 |
|
const char dsuffix[] = ".txt"; |
34 |
|
|
35 |
< |
const char sph_mat[] = "BSDFmat"; |
35 |
> |
const char sph_fmat[] = "fBSDFmat"; |
36 |
> |
const char sph_bmat[] = "bBSDFmat"; |
37 |
|
const double sph_rad = 10.; |
38 |
|
const double sph_xoffset = 15.; |
39 |
|
|
42 |
|
|
43 |
|
#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) |
44 |
|
|
45 |
< |
#define set_minlog() (min_log10 = log10(overall_min + 1e-5) - .1) |
45 |
> |
#define set_minlog() overall_min = (overall_min < 1e-5) ? 1e-5 : overall_min; \ |
46 |
> |
min_log10 = log10(overall_min) - .1 |
47 |
|
|
48 |
|
char *progname; |
49 |
|
|
50 |
|
/* Get Fibonacci sphere vector (0 to NINCIDENT-1) */ |
51 |
< |
static void |
51 |
> |
static RREAL * |
52 |
|
get_ivector(FVECT iv, int i) |
53 |
|
{ |
56 |
– |
const double zstep = 1./(2*NINCIDENT-1); |
54 |
|
const double phistep = PI*(3. - 2.236067978); |
55 |
|
double r; |
56 |
|
|
57 |
< |
iv[2] = 1. - (i+.5)*zstep; |
57 |
> |
iv[2] = 1. - (i+.5)*(1./NINCIDENT); |
58 |
|
r = sqrt(1. - iv[2]*iv[2]); |
59 |
|
iv[0] = r * cos((i+1.)*phistep); |
60 |
|
iv[1] = r * sin((i+1.)*phistep); |
61 |
+ |
|
62 |
+ |
return(iv); |
63 |
|
} |
64 |
|
|
65 |
+ |
/* Convert incident vector into sphere position */ |
66 |
+ |
static RREAL * |
67 |
+ |
cvt_sposition(FVECT sp, const FVECT iv, int inc_side) |
68 |
+ |
{ |
69 |
+ |
sp[0] = -iv[0]*sph_rad + inc_side*sph_xoffset; |
70 |
+ |
sp[1] = -iv[1]*sph_rad; |
71 |
+ |
sp[2] = iv[2]*sph_rad; |
72 |
+ |
|
73 |
+ |
return(sp); |
74 |
+ |
} |
75 |
+ |
|
76 |
|
/* Get temporary file name */ |
77 |
|
static char * |
78 |
|
tfile_name(const char *prefix, const char *suffix, int i) |
259 |
|
RBFNODE *rbf; |
260 |
|
get_ivector(ivec, i); |
261 |
|
if (input_orient < 0) { |
262 |
< |
ivec[0] = -ivec[0]; ivec[1] = -ivec[1]; ivec[2] = -ivec[2]; |
262 |
> |
ivec[0] = -ivec[0]; ivec[2] = -ivec[2]; |
263 |
|
} |
264 |
|
rbf = advect_rbf(ivec, 15000); |
265 |
|
if (!plotRBF(tfile_name(pref, dsuffix, i), rbf)) |
271 |
|
|
272 |
|
/* Put out mirror arrow for the given incident vector */ |
273 |
|
static void |
274 |
< |
put_mirror_arrow(const FVECT ivec, int inc_side) |
274 |
> |
put_mirror_arrow(const FVECT origin, const FVECT nrm) |
275 |
|
{ |
276 |
|
const double arrow_len = 1.2*bsdf_rad; |
277 |
|
const double tip_len = 0.2*bsdf_rad; |
278 |
< |
FVECT origin, refl; |
278 |
> |
FVECT refl; |
279 |
|
int i; |
280 |
|
|
281 |
< |
for (i = 3; i--; ) origin[i] = ivec[i]*sph_rad; |
282 |
< |
origin[0] -= inc_side*sph_xoffset; |
281 |
> |
refl[0] = 2.*nrm[2]*nrm[0]; |
282 |
> |
refl[1] = 2.*nrm[2]*nrm[1]; |
283 |
> |
refl[2] = 2.*nrm[2]*nrm[2] - 1.; |
284 |
|
|
274 |
– |
refl[0] = 2.*ivec[2]*ivec[0]; |
275 |
– |
refl[1] = 2.*ivec[2]*ivec[1]; |
276 |
– |
refl[2] = 2.*ivec[2]*ivec[2] - 1.; |
277 |
– |
|
285 |
|
printf("\n# Mirror arrow\n"); |
286 |
< |
printf("\narrow_mat cylinder inc_dir\n0\n0\n7"); |
286 |
> |
printf("\nshaft_mat cylinder inc_dir\n0\n0\n7"); |
287 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n", |
288 |
|
origin[0], origin[1], origin[2]+arrow_len, |
289 |
|
origin[0], origin[1], origin[2], |
290 |
|
arrow_rad); |
291 |
< |
printf("\narrow_mat cylinder mir_dir\n0\n0\n7"); |
291 |
> |
printf("\nshaft_mat cylinder mir_dir\n0\n0\n7"); |
292 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n", |
293 |
|
origin[0], origin[1], origin[2], |
294 |
|
origin[0] + arrow_len*refl[0], |
295 |
|
origin[1] + arrow_len*refl[1], |
296 |
|
origin[2] + arrow_len*refl[2], |
297 |
|
arrow_rad); |
298 |
< |
printf("\narrow_mat cone mir_tip\n0\n0\n8"); |
298 |
> |
printf("\ntip_mat cone mir_tip\n0\n0\n8"); |
299 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n", |
300 |
|
origin[0] + (arrow_len-.5*tip_len)*refl[0], |
301 |
|
origin[1] + (arrow_len-.5*tip_len)*refl[1], |
308 |
|
|
309 |
|
/* Put out transmitted direction arrow for the given incident vector */ |
310 |
|
static void |
311 |
< |
put_trans_arrow(const FVECT ivec, int inc_side) |
311 |
> |
put_trans_arrow(const FVECT origin) |
312 |
|
{ |
313 |
|
const double arrow_len = 1.2*bsdf_rad; |
314 |
|
const double tip_len = 0.2*bsdf_rad; |
308 |
– |
FVECT origin; |
315 |
|
int i; |
316 |
|
|
311 |
– |
for (i = 3; i--; ) origin[i] = ivec[i]*sph_rad; |
312 |
– |
origin[0] -= inc_side*sph_xoffset; |
313 |
– |
|
317 |
|
printf("\n# Transmission arrow\n"); |
318 |
< |
printf("\narrow_mat cylinder trans_dir\n0\n0\n7"); |
318 |
> |
printf("\nshaft_mat cylinder trans_dir\n0\n0\n7"); |
319 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n", |
320 |
|
origin[0], origin[1], origin[2], |
321 |
|
origin[0], origin[1], origin[2]-arrow_len, |
322 |
|
arrow_rad); |
323 |
< |
printf("\narrow_mat cone trans_tip\n0\n0\n8"); |
323 |
> |
printf("\ntip_mat cone trans_tip\n0\n0\n8"); |
324 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n", |
325 |
|
origin[0], origin[1], origin[2]-arrow_len+.5*tip_len, |
326 |
|
origin[0], origin[1], origin[2]-arrow_len-.5*tip_len, |
368 |
|
put_BSDFs(void) |
369 |
|
{ |
370 |
|
const double scalef = bsdf_rad/(log10(overall_max) - min_log10); |
371 |
< |
FVECT ivec; |
371 |
> |
FVECT ivec, sorg, nrm, upv; |
372 |
|
RREAL vMtx[3][3]; |
373 |
|
char *fname; |
374 |
|
char cmdbuf[256]; |
375 |
< |
char xfargs[128]; |
376 |
< |
int nxfa; |
375 |
> |
char rotargs[64]; |
376 |
> |
int nrota; |
377 |
|
int i; |
378 |
|
|
379 |
|
printf("\n# Gensurf output corresponding to %d incident directions\n", |
380 |
|
NINCIDENT); |
381 |
|
|
382 |
< |
printf("\nvoid glow arrow_glow\n0\n0\n4 1 0 1 0\n"); |
383 |
< |
printf("\nvoid mixfunc arrow_mat\n4 arrow_glow void .5 .\n0\n0\n"); |
382 |
> |
printf("\nvoid glow tip_mat\n0\n0\n4 1 0 1 0\n"); |
383 |
> |
printf("\nvoid mixfunc shaft_mat\n4 tip_mat void 0.25 .\n0\n0\n"); |
384 |
|
|
385 |
< |
if (front_comp & SDsampR) |
386 |
< |
for (i = 0; i < NINCIDENT; i++) { |
387 |
< |
get_ivector(ivec, i); |
388 |
< |
put_mirror_arrow(ivec, 1); |
389 |
< |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
390 |
< |
ivec[0]*sph_rad - sph_xoffset, |
391 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
392 |
< |
nxfa = 6; |
385 |
> |
for (i = 0; i < NINCIDENT; i++) { |
386 |
> |
get_ivector(ivec, i); |
387 |
> |
nrm[0] = -ivec[0]; nrm[1] = -ivec[1]; nrm[2] = ivec[2]; |
388 |
> |
upv[0] = nrm[0]*nrm[1]*(nrm[2] - 1.); |
389 |
> |
upv[1] = nrm[0]*nrm[0] + nrm[1]*nrm[1]*nrm[2]; |
390 |
> |
upv[2] = -nrm[1]*(nrm[0]*nrm[0] + nrm[1]*nrm[1]); |
391 |
> |
if (SDcompXform(vMtx, nrm, upv) != SDEnone) |
392 |
> |
continue; |
393 |
> |
nrota = addrot(rotargs, vMtx[0], vMtx[1], vMtx[2]); |
394 |
> |
if (front_comp) { |
395 |
> |
cvt_sposition(sorg, ivec, 1); |
396 |
|
printf("\nvoid colorfunc scale_pat\n"); |
397 |
< |
printf("%d bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n\t%s\n0\n0\n", |
398 |
< |
4+nxfa, xfargs); |
397 |
> |
printf("10 bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n"); |
398 |
> |
printf("\t-s %f -t %f %f %f\n0\n0\n", |
399 |
> |
bsdf_rad, sorg[0], sorg[1], sorg[2]); |
400 |
|
printf("\nscale_pat glow scale_mat\n0\n0\n4 1 1 1 0\n"); |
401 |
< |
SDcompXform(vMtx, ivec, Yaxis); |
402 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
403 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
397 |
< |
scalef, ivec[0]*sph_rad - sph_xoffset, |
398 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
399 |
< |
nxfa += 6; |
401 |
> |
} |
402 |
> |
if (front_comp & SDsampR) { |
403 |
> |
put_mirror_arrow(sorg, nrm); |
404 |
|
fname = tfile_name(frpref, dsuffix, i); |
405 |
< |
sprintf(cmdbuf, "gensurf scale_mat %s%d %s %s %s %d %d | xform -mx -my %s", |
406 |
< |
frpref, i+1, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
407 |
< |
xfargs); |
405 |
> |
sprintf(cmdbuf, |
406 |
> |
"gensurf scale_mat %s%d %s %s %s %d %d | xform %s -s %f -t %f %f %f", |
407 |
> |
frpref, i, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
408 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
409 |
|
if (!run_cmd(cmdbuf)) |
410 |
|
return(0); |
411 |
|
} |
412 |
< |
if (front_comp & SDsampT) |
413 |
< |
for (i = 0; i < NINCIDENT; i++) { |
409 |
< |
get_ivector(ivec, i); |
410 |
< |
put_trans_arrow(ivec, 1); |
411 |
< |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
412 |
< |
ivec[0]*sph_rad - sph_xoffset, |
413 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
414 |
< |
nxfa = 6; |
415 |
< |
printf("\nvoid colorfunc scale_pat\n"); |
416 |
< |
printf("%d bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n\t%s\n0\n0\n", |
417 |
< |
4+nxfa, xfargs); |
418 |
< |
printf("\nscale_pat glow scale_mat\n0\n0\n4 1 1 1 0\n"); |
419 |
< |
SDcompXform(vMtx, ivec, Yaxis); |
420 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
421 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
422 |
< |
scalef, ivec[0]*sph_rad - sph_xoffset, |
423 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
424 |
< |
nxfa += 6; |
412 |
> |
if (front_comp & SDsampT) { |
413 |
> |
put_trans_arrow(sorg); |
414 |
|
fname = tfile_name(ftpref, dsuffix, i); |
415 |
< |
sprintf(cmdbuf, "gensurf scale_mat %s%d %s %s %s %d %d | xform -I -mx -my %s", |
416 |
< |
ftpref, i+1, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
417 |
< |
xfargs); |
415 |
> |
sprintf(cmdbuf, |
416 |
> |
"gensurf scale_mat %s%d %s %s %s %d %d | xform -I %s -s %f -t %f %f %f", |
417 |
> |
ftpref, i, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
418 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
419 |
|
if (!run_cmd(cmdbuf)) |
420 |
|
return(0); |
421 |
|
} |
422 |
< |
if (back_comp & SDsampR) |
423 |
< |
for (i = 0; i < NINCIDENT; i++) { |
434 |
< |
get_ivector(ivec, i); |
435 |
< |
put_mirror_arrow(ivec, -1); |
436 |
< |
fname = tfile_name(brpref, dsuffix, i); |
437 |
< |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
438 |
< |
ivec[0]*sph_rad + sph_xoffset, |
439 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
440 |
< |
nxfa = 6; |
422 |
> |
if (back_comp) { |
423 |
> |
cvt_sposition(sorg, ivec, -1); |
424 |
|
printf("\nvoid colorfunc scale_pat\n"); |
425 |
< |
printf("%d bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n\t%s\n0\n0\n", |
426 |
< |
4+nxfa, xfargs); |
425 |
> |
printf("10 bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n"); |
426 |
> |
printf("\t-s %f -t %f %f %f\n0\n0\n", |
427 |
> |
bsdf_rad, sorg[0], sorg[1], sorg[2]); |
428 |
|
printf("\nscale_pat glow scale_mat\n0\n0\n4 1 1 1 0\n"); |
429 |
< |
SDcompXform(vMtx, ivec, Yaxis); |
430 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
431 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
448 |
< |
scalef, ivec[0]*sph_rad + sph_xoffset, |
449 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
450 |
< |
nxfa += 6; |
429 |
> |
} |
430 |
> |
if (back_comp & SDsampR) { |
431 |
> |
put_mirror_arrow(sorg, nrm); |
432 |
|
fname = tfile_name(brpref, dsuffix, i); |
433 |
< |
sprintf(cmdbuf, "gensurf scale_mat %s%d %s %s %s %d %d | xform -I -ry 180 -mx -my %s", |
434 |
< |
brpref, i+1, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
435 |
< |
xfargs); |
433 |
> |
sprintf(cmdbuf, |
434 |
> |
"gensurf scale_mat %s%d %s %s %s %d %d | xform -I -ry 180 %s -s %f -t %f %f %f", |
435 |
> |
brpref, i, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
436 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
437 |
|
if (!run_cmd(cmdbuf)) |
438 |
|
return(0); |
439 |
|
} |
440 |
< |
if (back_comp & SDsampT) |
441 |
< |
for (i = 0; i < NINCIDENT; i++) { |
460 |
< |
get_ivector(ivec, i); |
461 |
< |
put_trans_arrow(ivec, -1); |
440 |
> |
if (back_comp & SDsampT) { |
441 |
> |
put_trans_arrow(sorg); |
442 |
|
fname = tfile_name(btpref, dsuffix, i); |
443 |
< |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
444 |
< |
ivec[0]*sph_rad + sph_xoffset, |
445 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
446 |
< |
nxfa = 6; |
467 |
< |
printf("\nvoid colorfunc scale_pat\n"); |
468 |
< |
printf("%d bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n\t%s\n0\n0\n", |
469 |
< |
4+nxfa, xfargs); |
470 |
< |
printf("\nscale_pat glow scale_mat\n0\n0\n4 1 1 1 0\n"); |
471 |
< |
SDcompXform(vMtx, ivec, Yaxis); |
472 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
473 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
474 |
< |
scalef, ivec[0]*sph_rad + sph_xoffset, |
475 |
< |
ivec[1]*sph_rad, ivec[2]*sph_rad); |
476 |
< |
nxfa += 6; |
477 |
< |
fname = tfile_name(btpref, dsuffix, i); |
478 |
< |
sprintf(cmdbuf, "gensurf scale_mat %s%d %s %s %s %d %d | xform -ry 180 -mx -my %s", |
479 |
< |
btpref, i+1, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
480 |
< |
xfargs); |
443 |
> |
sprintf(cmdbuf, |
444 |
> |
"gensurf scale_mat %s%d %s %s %s %d %d | xform -ry 180 %s -s %f -t %f %f %f", |
445 |
> |
btpref, i, fname, fname, fname, SAMPRES-1, SAMPRES-1, |
446 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
447 |
|
if (!run_cmd(cmdbuf)) |
448 |
|
return(0); |
449 |
|
} |
450 |
+ |
} |
451 |
|
return(1); |
452 |
|
} |
453 |
|
|
461 |
|
printf("\n# Simplified material because we have no XML input\n"); |
462 |
|
printf("\nvoid brightfunc latlong\n2 latlong bsdf2rad.cal\n0\n0\n"); |
463 |
|
if ((front_comp|back_comp) & SDsampT) |
464 |
< |
printf("\nlatlong trans %s\n0\n0\n7 .75 .75 .75 0 0 .5 .8\n", |
465 |
< |
sph_mat); |
464 |
> |
printf("\nlatlong trans %s\n0\n0\n7 .75 .75 .75 0 .04 .5 .8\n", |
465 |
> |
sph_fmat); |
466 |
|
else |
467 |
|
printf("\nlatlong plastic %s\n0\n0\n5 .5 .5 .5 0 0\n", |
468 |
< |
sph_mat); |
468 |
> |
sph_fmat); |
469 |
> |
printf("\ninherit alias %s %s\n", sph_bmat, sph_fmat); |
470 |
|
return; |
471 |
|
} |
472 |
|
switch (XMLfile[0]) { /* avoid RAYPATH search */ |
473 |
|
case '.': |
474 |
+ |
case '~': |
475 |
|
CASEDIRSEP: |
476 |
|
curdir = ""; |
477 |
|
break; |
480 |
|
exit(1); |
481 |
|
break; |
482 |
|
} |
483 |
< |
printf("\n# Actual BSDF material for rendering the hemispheres\n"); |
484 |
< |
printf("\nvoid BSDF BSDFmat\n6 0 \"%s%s\" 0 1 0 .\n0\n0\n", |
483 |
> |
printf("\n# Actual BSDF materials for rendering the hemispheres\n"); |
484 |
> |
printf("\nvoid BSDF BSDF_f\n6 0 \"%s%s\" upx upy upz bsdf2rad.cal\n0\n0\n", |
485 |
|
curdir, XMLfile); |
486 |
|
printf("\nvoid plastic black\n0\n0\n5 0 0 0 0 0\n"); |
487 |
< |
printf("\nvoid mixfunc %s\n4 BSDFmat black latlong bsdf2rad.cal\n0\n0\n", |
488 |
< |
sph_mat); |
487 |
> |
printf("\nvoid mixfunc %s\n4 BSDF_f black latlong bsdf2rad.cal\n0\n0\n", |
488 |
> |
sph_fmat); |
489 |
> |
printf("\nvoid BSDF BSDF_b\n8 0 \"%s%s\" upx upy upz bsdf2rad.cal -ry 180\n0\n0\n", |
490 |
> |
curdir, XMLfile); |
491 |
> |
printf("\nvoid mixfunc %s\n4 BSDF_b black latlong bsdf2rad.cal\n0\n0\n", |
492 |
> |
sph_bmat); |
493 |
|
} |
494 |
|
|
495 |
|
/* Put out overhead parallel light source */ |
497 |
|
put_source(void) |
498 |
|
{ |
499 |
|
printf("\n# Overhead parallel light source\n"); |
500 |
< |
printf("\nvoid light bright\n0\n0\n3 1000 1000 1000\n"); |
500 |
> |
printf("\nvoid light bright\n0\n0\n3 2500 2500 2500\n"); |
501 |
|
printf("\nbright source light\n0\n0\n4 0 0 1 2\n"); |
502 |
|
printf("\n# Material used for labels\n"); |
503 |
|
printf("\nvoid trans vellum\n0\n0\n7 1 1 1 0 0 .5 0\n"); |
507 |
|
static void |
508 |
|
put_hemispheres(void) |
509 |
|
{ |
510 |
+ |
const int nsegs = 131; |
511 |
+ |
|
512 |
|
printf("\n# Hemisphere(s) for showing BSDF appearance (if XML file)\n"); |
538 |
– |
printf("\nvoid antimatter anti_sph\n2 void %s\n0\n0\n", sph_mat); |
513 |
|
if (front_comp) { |
514 |
< |
printf("\n%s sphere Front\n0\n0\n4 %f 0 0 %f\n", |
515 |
< |
sph_mat, -sph_xoffset, sph_rad); |
516 |
< |
printf("\n!genbox anti_sph sph_eraser %f %f %f | xform -t %f %f %f\n", |
543 |
< |
2.02*sph_rad, 2.02*sph_rad, 1.02*sph_rad, |
544 |
< |
-1.01*sph_rad - sph_xoffset, -1.01*sph_rad, -1.01*sph_rad); |
514 |
> |
printf( |
515 |
> |
"\n!genrev %s Front \"R*sin(A*t)\" \"R*cos(A*t)\" %d -e \"R:%g;A:%f\" -s | xform -t %g 0 0\n", |
516 |
> |
sph_fmat, nsegs, sph_rad, 0.495*PI, sph_xoffset); |
517 |
|
printf("\nvoid brighttext front_text\n3 helvet.fnt . FRONT\n0\n"); |
518 |
|
printf("12\n\t%f %f 0\n\t%f 0 0\n\t0 %f 0\n\t.01 1 -.1\n", |
519 |
< |
-.22*sph_rad - sph_xoffset, -1.2*sph_rad, |
519 |
> |
-.22*sph_rad + sph_xoffset, -1.4*sph_rad, |
520 |
|
.35/5.*sph_rad, -1.6*.35/5.*sph_rad); |
521 |
|
printf("\nfront_text alias front_label_mat vellum\n"); |
522 |
|
printf("\nfront_label_mat polygon front_label\n0\n0\n12"); |
523 |
|
printf("\n\t%f %f 0\n\t%f %f 0\n\t%f %f 0\n\t%f %f 0\n", |
524 |
< |
-.25*sph_rad - sph_xoffset, -1.1*sph_rad, |
525 |
< |
-.25*sph_rad - sph_xoffset, (-1.2-1.6*.35/5.-.1)*sph_rad, |
526 |
< |
.25*sph_rad - sph_xoffset, (-1.2-1.6*.35/5.-.1)*sph_rad, |
527 |
< |
.25*sph_rad - sph_xoffset, -1.1*sph_rad ); |
524 |
> |
-.25*sph_rad + sph_xoffset, -1.3*sph_rad, |
525 |
> |
-.25*sph_rad + sph_xoffset, (-1.4-1.6*.35/5.-.1)*sph_rad, |
526 |
> |
.25*sph_rad + sph_xoffset, (-1.4-1.6*.35/5.-.1)*sph_rad, |
527 |
> |
.25*sph_rad + sph_xoffset, -1.3*sph_rad ); |
528 |
|
} |
529 |
|
if (back_comp) { |
530 |
< |
printf("\n%s bubble Back\n0\n0\n4 %f 0 0 %f\n", |
531 |
< |
sph_mat, sph_xoffset, sph_rad); |
532 |
< |
printf("\n!genbox anti_sph sph_eraser %f %f %f | xform -t %f %f %f\n", |
561 |
< |
2.02*sph_rad, 2.02*sph_rad, 1.02*sph_rad, |
562 |
< |
-1.01*sph_rad + sph_xoffset, -1.01*sph_rad, -1.01*sph_rad); |
530 |
> |
printf( |
531 |
> |
"\n!genrev %s Back \"R*cos(A*t)\" \"R*sin(A*t)\" %d -e \"R:%g;A:%f\" -s | xform -t %g 0 0\n", |
532 |
> |
sph_bmat, nsegs, sph_rad, 0.495*PI, -sph_xoffset); |
533 |
|
printf("\nvoid brighttext back_text\n3 helvet.fnt . BACK\n0\n"); |
534 |
|
printf("12\n\t%f %f 0\n\t%f 0 0\n\t0 %f 0\n\t.01 1 -.1\n", |
535 |
< |
-.22*sph_rad + sph_xoffset, -1.2*sph_rad, |
535 |
> |
-.22*sph_rad - sph_xoffset, -1.4*sph_rad, |
536 |
|
.35/4.*sph_rad, -1.6*.35/4.*sph_rad); |
537 |
|
printf("\nback_text alias back_label_mat vellum\n"); |
538 |
|
printf("\nback_label_mat polygon back_label\n0\n0\n12"); |
539 |
|
printf("\n\t%f %f 0\n\t%f %f 0\n\t%f %f 0\n\t%f %f 0\n", |
540 |
< |
-.25*sph_rad + sph_xoffset, -1.1*sph_rad, |
541 |
< |
-.25*sph_rad + sph_xoffset, (-1.2-1.6*.35/4.-.1)*sph_rad, |
542 |
< |
.25*sph_rad + sph_xoffset, (-1.2-1.6*.35/4.-.1)*sph_rad, |
543 |
< |
.25*sph_rad + sph_xoffset, -1.1*sph_rad ); |
540 |
> |
-.25*sph_rad - sph_xoffset, -1.3*sph_rad, |
541 |
> |
-.25*sph_rad - sph_xoffset, (-1.4-1.6*.35/4.-.1)*sph_rad, |
542 |
> |
.25*sph_rad - sph_xoffset, (-1.4-1.6*.35/4.-.1)*sph_rad, |
543 |
> |
.25*sph_rad - sph_xoffset, -1.3*sph_rad ); |
544 |
|
} |
545 |
|
} |
546 |
|
|
549 |
|
put_scale(void) |
550 |
|
{ |
551 |
|
const double max_log10 = log10(overall_max); |
552 |
< |
const double leg_width = 2.*.75*(sph_xoffset - sph_rad); |
552 |
> |
const double leg_width = 2.*.75*(fabs(sph_xoffset) - sph_rad); |
553 |
|
const double leg_height = 2.*sph_rad; |
554 |
|
const int text_lines = 6; |
555 |
< |
const int text_digits = 7; |
555 |
> |
const int text_digits = 8; |
556 |
|
char fmt[16]; |
557 |
|
int i; |
558 |
|
|
559 |
|
printf("\n# BSDF legend with falsecolor scale\n"); |
560 |
|
printf("\nvoid colorfunc lscale\n10 sca_red(Py) sca_grn(Py) sca_blu(Py)"); |
561 |
|
printf("\n\tbsdf2rad.cal -s %f -t 0 %f 0\n0\n0\n", leg_height, -.5*leg_height); |
562 |
< |
sprintf(fmt, "%%%dg", text_digits-2); |
562 |
> |
sprintf(fmt, "%%.%df", text_digits-3); |
563 |
|
for (i = 0; i < text_lines; i++) { |
564 |
|
char vbuf[16]; |
565 |
|
sprintf(vbuf, fmt, pow(10., (i+.5)/text_lines*(max_log10-min_log10)+min_log10)); |
566 |
|
printf("\nlscale brighttext lscale\n"); |
567 |
|
printf("3 helvet.fnt . %s\n0\n12\n", vbuf); |
568 |
|
printf("\t%f %f 0\n", -.45*leg_width, ((i+.9)/text_lines-.5)*leg_height); |
569 |
< |
printf("\t%f 0 0\n", .9*leg_width/strlen(vbuf)); |
569 |
> |
printf("\t%f 0 0\n", .8*leg_width/strlen(vbuf)); |
570 |
|
printf("\t0 %f 0\n", -.9/text_lines*leg_height); |
571 |
|
printf("\t.01 1 -.1\n"); |
572 |
|
} |
593 |
|
return; |
594 |
|
printf("\nvoid brighttext BSDFname\n3 helvet.fnt . \"%s\"\n0\n12\n", bsdf_name); |
595 |
|
printf("\t%f %f 0\n", -.95*leg_width, -.6*leg_height); |
596 |
< |
printf("\t%f 0 0\n", .4/strlen(bsdf_name)*leg_width); |
596 |
> |
printf("\t%f 0 0\n", 1.8/strlen(bsdf_name)*leg_width); |
597 |
|
printf("\t0 %f 0\n", -.1*leg_height); |
598 |
|
printf("\t.01 1 -.1\n"); |
599 |
|
printf("\nBSDFname alias name_mat vellum\n"); |
648 |
|
sprintf(cmdbuf, "xform -t %f %f %f -s %f -t %f %f 0 %s", |
649 |
|
-.5*(xmin+xmax), -.5*(ymin+ymax), -zmax, |
650 |
|
1.5*sph_rad/max_dim, |
651 |
< |
-sph_xoffset, -2.5*sph_rad, |
651 |
> |
sph_xoffset, -2.5*sph_rad, |
652 |
|
radfn); |
653 |
|
if (!run_cmd(cmdbuf)) |
654 |
|
return; |
658 |
|
sprintf(cmdbuf, "xform -t %f %f %f -s %f -ry 180 -t %f %f 0 %s", |
659 |
|
-.5*(xmin+xmax), -.5*(ymin+ymax), -zmin, |
660 |
|
1.5*sph_rad/max_dim, |
661 |
< |
sph_xoffset, -2.5*sph_rad, |
661 |
> |
-sph_xoffset, -2.5*sph_rad, |
662 |
|
radfn); |
663 |
|
if (!run_cmd(cmdbuf)) |
664 |
|
return; |
751 |
|
strcpy(bsdf_manuf, myBSDF.makr); |
752 |
|
put_matBSDF(argv[1]); |
753 |
|
} else { |
754 |
< |
FILE *fp; |
754 |
> |
FILE *fp[4]; |
755 |
> |
if (argc > 5) { |
756 |
> |
fprintf(stderr, "%s: more than 4 hemispheres!\n", progname); |
757 |
> |
return(1); |
758 |
> |
} |
759 |
|
for (n = 1; n < argc; n++) { |
760 |
< |
fp = fopen(argv[n], "rb"); |
761 |
< |
if (fp == NULL) { |
760 |
> |
fp[n-1] = fopen(argv[n], "rb"); |
761 |
> |
if (fp[n-1] == NULL) { |
762 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
763 |
|
progname, argv[n]); |
764 |
|
return(1); |
765 |
|
} |
766 |
< |
if (getheader(fp, rbf_headline, NULL) < 0) { |
766 |
> |
if (getheader(fp[n-1], rbf_headline, NULL) < 0) { |
767 |
|
fprintf(stderr, "%s: bad BSDF interpolant '%s'\n", |
768 |
|
progname, argv[n]); |
769 |
|
return(1); |
770 |
|
} |
797 |
– |
fclose(fp); |
771 |
|
} |
772 |
|
set_minlog(); |
773 |
|
for (n = 1; n < argc; n++) { |
774 |
< |
fp = fopen(argv[n], "rb"); |
775 |
< |
if (!load_bsdf_rep(fp)) |
774 |
> |
if (fseek(fp[n-1], 0L, SEEK_SET) < 0) { |
775 |
> |
fprintf(stderr, "%s: cannot seek on '%s'\n", |
776 |
> |
progname, argv[n]); |
777 |
|
return(1); |
778 |
< |
fclose(fp); |
778 |
> |
} |
779 |
> |
if (!load_bsdf_rep(fp[n-1])) |
780 |
> |
return(1); |
781 |
> |
fclose(fp[n-1]); |
782 |
|
if (!build_wRBF()) |
783 |
|
return(1); |
784 |
|
} |
789 |
|
put_scale(); |
790 |
|
if (inpXML && myBSDF.mgf) |
791 |
|
convert_mgf(myBSDF.mgf); |
792 |
< |
if (!put_BSDFs()) |
792 |
> |
if (!put_BSDFs()) /* most of the output happens here */ |
793 |
|
return(1); |
794 |
|
cleanup_tmp(); |
795 |
|
return(0); |