| 5 |
|
* Plot 3-D BSDF output based on scattering interpolant or XML representation |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
– |
#include <stdio.h> |
| 9 |
– |
#include <string.h> |
| 8 |
|
#include <stdlib.h> |
| 9 |
< |
#include "paths.h" |
| 9 |
> |
#include "rtio.h" |
| 10 |
|
#include "rtmath.h" |
| 13 |
– |
#include "resolu.h" |
| 11 |
|
#include "bsdfrep.h" |
| 12 |
|
|
| 13 |
+ |
#ifndef NINCIDENT |
| 14 |
|
#define NINCIDENT 37 /* number of samples/hemisphere */ |
| 15 |
< |
|
| 15 |
> |
#endif |
| 16 |
> |
#ifndef GRIDSTEP |
| 17 |
|
#define GRIDSTEP 2 /* our grid step size */ |
| 18 |
+ |
#endif |
| 19 |
|
#define SAMPRES (GRIDRES/GRIDSTEP) |
| 20 |
|
|
| 21 |
|
int front_comp = 0; /* front component flags (SDsamp*) */ |
| 24 |
|
double min_log10; /* smallest log10 value for plotting */ |
| 25 |
|
double overall_max = .0; /* overall maximum BSDF value */ |
| 26 |
|
|
| 27 |
< |
char ourTempDir[TEMPLEN] = ""; /* our temporary directory */ |
| 27 |
> |
char ourTempDir[TEMPLEN+1] = ""; /* our temporary directory */ |
| 28 |
|
|
| 29 |
|
const char frpref[] = "rf"; |
| 30 |
|
const char ftpref[] = "tf"; |
| 40 |
|
#define bsdf_rad (sph_rad*.25) |
| 41 |
|
#define arrow_rad (bsdf_rad*.015) |
| 42 |
|
|
| 43 |
– |
#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) |
| 44 |
– |
|
| 43 |
|
#define set_minlog() overall_min = (overall_min < 1e-5) ? 1e-5 : overall_min; \ |
| 44 |
|
min_log10 = log10(overall_min) - .1 |
| 45 |
|
|
| 48 |
– |
char *progname; |
| 49 |
– |
|
| 46 |
|
/* Get Fibonacci sphere vector (0 to NINCIDENT-1) */ |
| 47 |
|
static RREAL * |
| 48 |
|
get_ivector(FVECT iv, int i) |
| 73 |
|
static char * |
| 74 |
|
tfile_name(const char *prefix, const char *suffix, int i) |
| 75 |
|
{ |
| 76 |
< |
static char buf[128]; |
| 76 |
> |
static char buf[256]; |
| 77 |
|
|
| 78 |
|
if (!ourTempDir[0]) { /* create temporary directory */ |
| 79 |
|
mktemp(strcpy(ourTempDir,TEMPLATE)); |
| 141 |
|
SDValue sval; |
| 142 |
|
double bsdf; |
| 143 |
|
ovec_from_pos(ovec, i*GRIDSTEP, j*GRIDSTEP); |
| 144 |
< |
if (SDreportError(SDevalBSDF(&sval, ovec, |
| 145 |
< |
ivec, sd), stderr)) |
| 144 |
> |
if (SDreportError(SDevalBSDF(&sval, ivec, |
| 145 |
> |
ovec, sd), stderr)) |
| 146 |
|
return(0); |
| 147 |
|
if (sval.cieY > overall_max) |
| 148 |
|
overall_max = sval.cieY; |
| 271 |
|
{ |
| 272 |
|
const double arrow_len = 1.2*bsdf_rad; |
| 273 |
|
const double tip_len = 0.2*bsdf_rad; |
| 274 |
+ |
static int cnt = 1; |
| 275 |
|
FVECT refl; |
| 276 |
|
int i; |
| 277 |
|
|
| 279 |
|
refl[1] = 2.*nrm[2]*nrm[1]; |
| 280 |
|
refl[2] = 2.*nrm[2]*nrm[2] - 1.; |
| 281 |
|
|
| 282 |
< |
printf("\n# Mirror arrow\n"); |
| 283 |
< |
printf("\nshaft_mat cylinder inc_dir\n0\n0\n7"); |
| 282 |
> |
printf("\n# Mirror arrow #%d\n", cnt); |
| 283 |
> |
printf("\nshaft_mat cylinder inc_dir%d\n0\n0\n7", cnt); |
| 284 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n", |
| 285 |
|
origin[0], origin[1], origin[2]+arrow_len, |
| 286 |
|
origin[0], origin[1], origin[2], |
| 287 |
|
arrow_rad); |
| 288 |
< |
printf("\nshaft_mat cylinder mir_dir\n0\n0\n7"); |
| 288 |
> |
printf("\nshaft_mat cylinder mir_dir%d\n0\n0\n7", cnt); |
| 289 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n", |
| 290 |
|
origin[0], origin[1], origin[2], |
| 291 |
|
origin[0] + arrow_len*refl[0], |
| 292 |
|
origin[1] + arrow_len*refl[1], |
| 293 |
|
origin[2] + arrow_len*refl[2], |
| 294 |
|
arrow_rad); |
| 295 |
< |
printf("\ntip_mat cone mir_tip\n0\n0\n8"); |
| 295 |
> |
printf("\ntip_mat cone mir_tip%d\n0\n0\n8", cnt); |
| 296 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n", |
| 297 |
|
origin[0] + (arrow_len-.5*tip_len)*refl[0], |
| 298 |
|
origin[1] + (arrow_len-.5*tip_len)*refl[1], |
| 301 |
|
origin[1] + (arrow_len+.5*tip_len)*refl[1], |
| 302 |
|
origin[2] + (arrow_len+.5*tip_len)*refl[2], |
| 303 |
|
2.*arrow_rad); |
| 304 |
+ |
++cnt; |
| 305 |
|
} |
| 306 |
|
|
| 307 |
|
/* Put out transmitted direction arrow for the given incident vector */ |
| 310 |
|
{ |
| 311 |
|
const double arrow_len = 1.2*bsdf_rad; |
| 312 |
|
const double tip_len = 0.2*bsdf_rad; |
| 313 |
+ |
static int cnt = 1; |
| 314 |
|
int i; |
| 315 |
|
|
| 316 |
< |
printf("\n# Transmission arrow\n"); |
| 317 |
< |
printf("\nshaft_mat cylinder trans_dir\n0\n0\n7"); |
| 316 |
> |
printf("\n# Transmission arrow #%d\n", cnt); |
| 317 |
> |
printf("\nshaft_mat cylinder trans_dir%d\n0\n0\n7", cnt); |
| 318 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f\n", |
| 319 |
|
origin[0], origin[1], origin[2], |
| 320 |
|
origin[0], origin[1], origin[2]-arrow_len, |
| 321 |
|
arrow_rad); |
| 322 |
< |
printf("\ntip_mat cone trans_tip\n0\n0\n8"); |
| 322 |
> |
printf("\ntip_mat cone trans_tip%d\n0\n0\n8", cnt); |
| 323 |
|
printf("\n\t%f %f %f\n\t%f %f %f\n\t%f 0\n", |
| 324 |
|
origin[0], origin[1], origin[2]-arrow_len+.5*tip_len, |
| 325 |
|
origin[0], origin[1], origin[2]-arrow_len-.5*tip_len, |
| 326 |
< |
2.*arrow_rad); |
| 326 |
> |
2.*arrow_rad); |
| 327 |
> |
++cnt; |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
/* Compute rotation (x,y,z) => (xp,yp,zp) */ |
| 343 |
|
return(4); |
| 344 |
|
} |
| 345 |
|
theta = atan2(yp[2], zp[2]); |
| 346 |
< |
if (!FEQ(theta,0.0)) { |
| 346 |
> |
if (!FABSEQ(theta,0.0)) { |
| 347 |
|
sprintf(xf, " -rx %f", theta*(180./PI)); |
| 348 |
|
while (*xf) ++xf; |
| 349 |
|
n += 2; |
| 350 |
|
} |
| 351 |
|
theta = Asin(-xp[2]); |
| 352 |
< |
if (!FEQ(theta,0.0)) { |
| 352 |
> |
if (!FABSEQ(theta,0.0)) { |
| 353 |
|
sprintf(xf, " -ry %f", theta*(180./PI)); |
| 354 |
|
while (*xf) ++xf; |
| 355 |
|
n += 2; |
| 356 |
|
} |
| 357 |
|
theta = atan2(xp[1], xp[0]); |
| 358 |
< |
if (!FEQ(theta,0.0)) { |
| 358 |
> |
if (!FABSEQ(theta,0.0)) { |
| 359 |
|
sprintf(xf, " -rz %f", theta*(180./PI)); |
| 360 |
|
/* while (*xf) ++xf; */ |
| 361 |
|
n += 2; |
| 513 |
|
if (front_comp) { |
| 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); |
| 516 |
> |
sph_fmat, nsegs, sph_rad, 0.5*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.4*sph_rad, |
| 529 |
|
if (back_comp) { |
| 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); |
| 532 |
> |
sph_bmat, nsegs, sph_rad, 0.5*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.4*sph_rad, |
| 635 |
|
if ((fp = popen(cmdbuf, "r")) == NULL || |
| 636 |
|
fscanf(fp, "%f %f %f %f %f %f", |
| 637 |
|
&xmin, &xmax, &ymin, &ymax, &zmin, &zmax) != 6 |
| 638 |
< |
|| pclose(fp) < 0) { |
| 638 |
> |
|| pclose(fp) != 0) { |
| 639 |
|
fprintf(stderr, "%s: error reading from command: %s\n", |
| 640 |
|
progname, cmdbuf); |
| 641 |
|
return; |
| 669 |
|
static int |
| 670 |
|
rbf_headline(char *s, void *p) |
| 671 |
|
{ |
| 672 |
< |
char fmt[64]; |
| 672 |
> |
char fmt[MAXFMTLEN]; |
| 673 |
|
|
| 674 |
|
if (formatval(fmt, s)) { |
| 675 |
|
if (strcmp(fmt, BSDFREP_FMT)) |
| 703 |
|
main(int argc, char *argv[]) |
| 704 |
|
{ |
| 705 |
|
int inpXML = -1; |
| 706 |
+ |
double myLim[2]; |
| 707 |
|
SDData myBSDF; |
| 708 |
< |
int n; |
| 708 |
> |
int a, n; |
| 709 |
> |
/* set global progname */ |
| 710 |
> |
fixargv0(argv[0]); |
| 711 |
|
/* check arguments */ |
| 712 |
< |
progname = argv[0]; |
| 713 |
< |
if (argc > 1 && (n = strlen(argv[1])-4) > 0) { |
| 714 |
< |
if (!strcasecmp(argv[1]+n, ".xml")) |
| 712 |
> |
a = 1; |
| 713 |
> |
myLim[0] = -1; myLim[1] = -2; /* specified BSDF range? */ |
| 714 |
> |
if (argc > a+3 && argv[a][0] == '-' && argv[a][1] == 'r') { |
| 715 |
> |
myLim[0] = atof(argv[++a]); |
| 716 |
> |
myLim[1] = atof(argv[++a]); |
| 717 |
> |
++a; |
| 718 |
> |
} |
| 719 |
> |
if (argc > a && (n = strlen(argv[a])-4) > 0) { |
| 720 |
> |
if (!strcasecmp(argv[a]+n, ".xml")) |
| 721 |
|
inpXML = 1; |
| 722 |
< |
else if (!strcasecmp(argv[1]+n, ".sir")) |
| 722 |
> |
else if (!strcasecmp(argv[a]+n, ".sir")) |
| 723 |
|
inpXML = 0; |
| 724 |
|
} |
| 725 |
< |
if (inpXML < 0 || inpXML & (argc > 2)) { |
| 726 |
< |
fprintf(stderr, "Usage: %s bsdf.xml > output.rad\n", progname); |
| 727 |
< |
fprintf(stderr, " Or: %s hemi1.sir hemi2.sir .. > output.rad\n", progname); |
| 725 |
> |
if (inpXML < 0 || inpXML & (argc > a+1)) { |
| 726 |
> |
fprintf(stderr, "Usage: %s [-r min max] bsdf.xml > output.rad\n", progname); |
| 727 |
> |
fprintf(stderr, " Or: %s [-r min max] hemi1.sir hemi2.sir .. > output.rad\n", progname); |
| 728 |
|
return(1); |
| 729 |
|
} |
| 730 |
|
fputs("# ", stdout); /* copy our command */ |
| 731 |
|
printargs(argc, argv, stdout); |
| 732 |
|
/* evaluate BSDF */ |
| 733 |
|
if (inpXML) { |
| 734 |
< |
SDclearBSDF(&myBSDF, argv[1]); |
| 735 |
< |
if (SDreportError(SDloadFile(&myBSDF, argv[1]), stderr)) |
| 734 |
> |
SDclearBSDF(&myBSDF, argv[a]); |
| 735 |
> |
if (SDreportError(SDloadFile(&myBSDF, argv[a]), stderr)) |
| 736 |
|
return(1); |
| 737 |
|
if (myBSDF.rf != NULL) front_comp |= SDsampR; |
| 738 |
|
if (myBSDF.tf != NULL) front_comp |= SDsampT; |
| 740 |
|
if (myBSDF.tb != NULL) back_comp |= SDsampT; |
| 741 |
|
if (!front_comp & !back_comp) { |
| 742 |
|
fprintf(stderr, "%s: nothing to plot in '%s'\n", |
| 743 |
< |
progname, argv[1]); |
| 743 |
> |
progname, argv[a]); |
| 744 |
|
return(1); |
| 745 |
|
} |
| 746 |
< |
if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI) |
| 747 |
< |
overall_min = myBSDF.rLambFront.cieY/PI; |
| 748 |
< |
if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI) |
| 749 |
< |
overall_min = myBSDF.rLambBack.cieY/PI; |
| 750 |
< |
if ((front_comp|back_comp) & SDsampT && |
| 751 |
< |
myBSDF.tLamb.cieY < overall_min*PI) |
| 752 |
< |
overall_min = myBSDF.tLamb.cieY/PI; |
| 746 |
> |
if (myLim[0] >= 0) |
| 747 |
> |
overall_min = myLim[0]; |
| 748 |
> |
else { |
| 749 |
> |
if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI) |
| 750 |
> |
overall_min = myBSDF.rLambFront.cieY/PI; |
| 751 |
> |
if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI) |
| 752 |
> |
overall_min = myBSDF.rLambBack.cieY/PI; |
| 753 |
> |
if (front_comp & SDsampT && myBSDF.tLambFront.cieY < overall_min*PI) |
| 754 |
> |
overall_min = myBSDF.tLambFront.cieY/PI; |
| 755 |
> |
if (back_comp & SDsampT && myBSDF.tLambBack.cieY < overall_min*PI) |
| 756 |
> |
overall_min = myBSDF.tLambBack.cieY/PI; |
| 757 |
> |
} |
| 758 |
|
set_minlog(); |
| 759 |
|
if (!build_wBSDF(&myBSDF)) |
| 760 |
|
return(1); |
| 763 |
|
else |
| 764 |
|
strcpy(bsdf_name, myBSDF.name); |
| 765 |
|
strcpy(bsdf_manuf, myBSDF.makr); |
| 766 |
< |
put_matBSDF(argv[1]); |
| 766 |
> |
put_matBSDF(argv[a]); |
| 767 |
|
} else { |
| 768 |
|
FILE *fp[4]; |
| 769 |
< |
if (argc > 5) { |
| 769 |
> |
if (argc > a+4) { |
| 770 |
|
fprintf(stderr, "%s: more than 4 hemispheres!\n", progname); |
| 771 |
|
return(1); |
| 772 |
|
} |
| 773 |
< |
for (n = 1; n < argc; n++) { |
| 774 |
< |
fp[n-1] = fopen(argv[n], "rb"); |
| 775 |
< |
if (fp[n-1] == NULL) { |
| 773 |
> |
for (n = a; n < argc; n++) { |
| 774 |
> |
fp[n-a] = fopen(argv[n], "rb"); |
| 775 |
> |
if (fp[n-a] == NULL) { |
| 776 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
| 777 |
|
progname, argv[n]); |
| 778 |
|
return(1); |
| 779 |
|
} |
| 780 |
< |
if (getheader(fp[n-1], rbf_headline, NULL) < 0) { |
| 780 |
> |
if (getheader(fp[n-a], rbf_headline, NULL) < 0) { |
| 781 |
|
fprintf(stderr, "%s: bad BSDF interpolant '%s'\n", |
| 782 |
|
progname, argv[n]); |
| 783 |
|
return(1); |
| 784 |
|
} |
| 785 |
|
} |
| 786 |
+ |
if (myLim[0] >= 0) |
| 787 |
+ |
overall_min = myLim[0]; |
| 788 |
|
set_minlog(); |
| 789 |
< |
for (n = 1; n < argc; n++) { |
| 790 |
< |
if (fseek(fp[n-1], 0L, SEEK_SET) < 0) { |
| 789 |
> |
for (n = a; n < argc; n++) { |
| 790 |
> |
if (fseek(fp[n-a], 0L, SEEK_SET) < 0) { |
| 791 |
|
fprintf(stderr, "%s: cannot seek on '%s'\n", |
| 792 |
|
progname, argv[n]); |
| 793 |
|
return(1); |
| 794 |
|
} |
| 795 |
< |
if (!load_bsdf_rep(fp[n-1])) |
| 795 |
> |
if (!load_bsdf_rep(fp[n-a])) |
| 796 |
|
return(1); |
| 797 |
< |
fclose(fp[n-1]); |
| 797 |
> |
fclose(fp[n-a]); |
| 798 |
|
if (!build_wRBF()) |
| 799 |
|
return(1); |
| 800 |
|
} |
| 801 |
|
put_matBSDF(NULL); |
| 802 |
|
} |
| 803 |
+ |
if (myLim[1] > myLim[0]) /* override maximum BSDF? */ |
| 804 |
+ |
overall_max = myLim[1]; |
| 805 |
|
put_source(); /* before hemispheres & labels */ |
| 806 |
|
put_hemispheres(); |
| 807 |
|
put_scale(); |