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 "rtio.h" |
10 |
|
#include "paths.h" |
11 |
|
#include "rtmath.h" |
13 |
– |
#include "resolu.h" |
12 |
|
#include "bsdfrep.h" |
13 |
|
|
14 |
|
#ifndef NINCIDENT |
41 |
|
#define bsdf_rad (sph_rad*.25) |
42 |
|
#define arrow_rad (bsdf_rad*.015) |
43 |
|
|
46 |
– |
#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) |
47 |
– |
|
44 |
|
#define set_minlog() overall_min = (overall_min < 1e-5) ? 1e-5 : overall_min; \ |
45 |
|
min_log10 = log10(overall_min) - .1 |
46 |
|
|
144 |
|
SDValue sval; |
145 |
|
double bsdf; |
146 |
|
ovec_from_pos(ovec, i*GRIDSTEP, j*GRIDSTEP); |
147 |
< |
if (SDreportError(SDevalBSDF(&sval, ovec, |
148 |
< |
ivec, sd), stderr)) |
147 |
> |
if (SDreportError(SDevalBSDF(&sval, ivec, |
148 |
> |
ovec, sd), stderr)) |
149 |
|
return(0); |
150 |
|
if (sval.cieY > overall_max) |
151 |
|
overall_max = sval.cieY; |
346 |
|
return(4); |
347 |
|
} |
348 |
|
theta = atan2(yp[2], zp[2]); |
349 |
< |
if (!FEQ(theta,0.0)) { |
349 |
> |
if (!FABSEQ(theta,0.0)) { |
350 |
|
sprintf(xf, " -rx %f", theta*(180./PI)); |
351 |
|
while (*xf) ++xf; |
352 |
|
n += 2; |
353 |
|
} |
354 |
|
theta = Asin(-xp[2]); |
355 |
< |
if (!FEQ(theta,0.0)) { |
355 |
> |
if (!FABSEQ(theta,0.0)) { |
356 |
|
sprintf(xf, " -ry %f", theta*(180./PI)); |
357 |
|
while (*xf) ++xf; |
358 |
|
n += 2; |
359 |
|
} |
360 |
|
theta = atan2(xp[1], xp[0]); |
361 |
< |
if (!FEQ(theta,0.0)) { |
361 |
> |
if (!FABSEQ(theta,0.0)) { |
362 |
|
sprintf(xf, " -rz %f", theta*(180./PI)); |
363 |
|
/* while (*xf) ++xf; */ |
364 |
|
n += 2; |
638 |
|
if ((fp = popen(cmdbuf, "r")) == NULL || |
639 |
|
fscanf(fp, "%f %f %f %f %f %f", |
640 |
|
&xmin, &xmax, &ymin, &ymax, &zmin, &zmax) != 6 |
641 |
< |
|| pclose(fp) < 0) { |
641 |
> |
|| pclose(fp) != 0) { |
642 |
|
fprintf(stderr, "%s: error reading from command: %s\n", |
643 |
|
progname, cmdbuf); |
644 |
|
return; |
672 |
|
static int |
673 |
|
rbf_headline(char *s, void *p) |
674 |
|
{ |
675 |
< |
char fmt[64]; |
675 |
> |
char fmt[MAXFMTLEN]; |
676 |
|
|
677 |
|
if (formatval(fmt, s)) { |
678 |
|
if (strcmp(fmt, BSDFREP_FMT)) |
706 |
|
main(int argc, char *argv[]) |
707 |
|
{ |
708 |
|
int inpXML = -1; |
709 |
+ |
double myLim[2]; |
710 |
|
SDData myBSDF; |
711 |
< |
int n; |
711 |
> |
int a, n; |
712 |
|
/* check arguments */ |
713 |
|
progname = argv[0]; |
714 |
< |
if (argc > 1 && (n = strlen(argv[1])-4) > 0) { |
715 |
< |
if (!strcasecmp(argv[1]+n, ".xml")) |
714 |
> |
a = 1; |
715 |
> |
myLim[0] = -1; myLim[1] = -2; /* specified BSDF range? */ |
716 |
> |
if (argc > a+3 && argv[a][0] == '-' && argv[a][1] == 'r') { |
717 |
> |
myLim[0] = atof(argv[++a]); |
718 |
> |
myLim[1] = atof(argv[++a]); |
719 |
> |
++a; |
720 |
> |
} |
721 |
> |
if (argc > a && (n = strlen(argv[a])-4) > 0) { |
722 |
> |
if (!strcasecmp(argv[a]+n, ".xml")) |
723 |
|
inpXML = 1; |
724 |
< |
else if (!strcasecmp(argv[1]+n, ".sir")) |
724 |
> |
else if (!strcasecmp(argv[a]+n, ".sir")) |
725 |
|
inpXML = 0; |
726 |
|
} |
727 |
< |
if (inpXML < 0 || inpXML & (argc > 2)) { |
728 |
< |
fprintf(stderr, "Usage: %s bsdf.xml > output.rad\n", progname); |
729 |
< |
fprintf(stderr, " Or: %s hemi1.sir hemi2.sir .. > output.rad\n", progname); |
727 |
> |
if (inpXML < 0 || inpXML & (argc > a+1)) { |
728 |
> |
fprintf(stderr, "Usage: %s [-r min max] bsdf.xml > output.rad\n", progname); |
729 |
> |
fprintf(stderr, " Or: %s [-r min max] hemi1.sir hemi2.sir .. > output.rad\n", progname); |
730 |
|
return(1); |
731 |
|
} |
732 |
|
fputs("# ", stdout); /* copy our command */ |
733 |
|
printargs(argc, argv, stdout); |
734 |
|
/* evaluate BSDF */ |
735 |
|
if (inpXML) { |
736 |
< |
SDclearBSDF(&myBSDF, argv[1]); |
737 |
< |
if (SDreportError(SDloadFile(&myBSDF, argv[1]), stderr)) |
736 |
> |
SDclearBSDF(&myBSDF, argv[a]); |
737 |
> |
if (SDreportError(SDloadFile(&myBSDF, argv[a]), stderr)) |
738 |
|
return(1); |
739 |
|
if (myBSDF.rf != NULL) front_comp |= SDsampR; |
740 |
|
if (myBSDF.tf != NULL) front_comp |= SDsampT; |
742 |
|
if (myBSDF.tb != NULL) back_comp |= SDsampT; |
743 |
|
if (!front_comp & !back_comp) { |
744 |
|
fprintf(stderr, "%s: nothing to plot in '%s'\n", |
745 |
< |
progname, argv[1]); |
745 |
> |
progname, argv[a]); |
746 |
|
return(1); |
747 |
|
} |
748 |
< |
if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI) |
749 |
< |
overall_min = myBSDF.rLambFront.cieY/PI; |
750 |
< |
if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI) |
751 |
< |
overall_min = myBSDF.rLambBack.cieY/PI; |
752 |
< |
if ((front_comp|back_comp) & SDsampT && |
753 |
< |
myBSDF.tLamb.cieY < overall_min*PI) |
754 |
< |
overall_min = myBSDF.tLamb.cieY/PI; |
748 |
> |
if (myLim[0] >= 0) |
749 |
> |
overall_min = myLim[0]; |
750 |
> |
else { |
751 |
> |
if (front_comp & SDsampR && myBSDF.rLambFront.cieY < overall_min*PI) |
752 |
> |
overall_min = myBSDF.rLambFront.cieY/PI; |
753 |
> |
if (back_comp & SDsampR && myBSDF.rLambBack.cieY < overall_min*PI) |
754 |
> |
overall_min = myBSDF.rLambBack.cieY/PI; |
755 |
> |
if (front_comp & SDsampT && myBSDF.tLambFront.cieY < overall_min*PI) |
756 |
> |
overall_min = myBSDF.tLambFront.cieY/PI; |
757 |
> |
if (back_comp & SDsampT && myBSDF.tLambBack.cieY < overall_min*PI) |
758 |
> |
overall_min = myBSDF.tLambBack.cieY/PI; |
759 |
> |
} |
760 |
|
set_minlog(); |
761 |
|
if (!build_wBSDF(&myBSDF)) |
762 |
|
return(1); |
765 |
|
else |
766 |
|
strcpy(bsdf_name, myBSDF.name); |
767 |
|
strcpy(bsdf_manuf, myBSDF.makr); |
768 |
< |
put_matBSDF(argv[1]); |
768 |
> |
put_matBSDF(argv[a]); |
769 |
|
} else { |
770 |
|
FILE *fp[4]; |
771 |
< |
if (argc > 5) { |
771 |
> |
if (argc > a+4) { |
772 |
|
fprintf(stderr, "%s: more than 4 hemispheres!\n", progname); |
773 |
|
return(1); |
774 |
|
} |
775 |
< |
for (n = 1; n < argc; n++) { |
776 |
< |
fp[n-1] = fopen(argv[n], "rb"); |
777 |
< |
if (fp[n-1] == NULL) { |
775 |
> |
for (n = a; n < argc; n++) { |
776 |
> |
fp[n-a] = fopen(argv[n], "rb"); |
777 |
> |
if (fp[n-a] == NULL) { |
778 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
779 |
|
progname, argv[n]); |
780 |
|
return(1); |
781 |
|
} |
782 |
< |
if (getheader(fp[n-1], rbf_headline, NULL) < 0) { |
782 |
> |
if (getheader(fp[n-a], rbf_headline, NULL) < 0) { |
783 |
|
fprintf(stderr, "%s: bad BSDF interpolant '%s'\n", |
784 |
|
progname, argv[n]); |
785 |
|
return(1); |
786 |
|
} |
787 |
|
} |
788 |
+ |
if (myLim[0] >= 0) |
789 |
+ |
overall_min = myLim[0]; |
790 |
|
set_minlog(); |
791 |
< |
for (n = 1; n < argc; n++) { |
792 |
< |
if (fseek(fp[n-1], 0L, SEEK_SET) < 0) { |
791 |
> |
for (n = a; n < argc; n++) { |
792 |
> |
if (fseek(fp[n-a], 0L, SEEK_SET) < 0) { |
793 |
|
fprintf(stderr, "%s: cannot seek on '%s'\n", |
794 |
|
progname, argv[n]); |
795 |
|
return(1); |
796 |
|
} |
797 |
< |
if (!load_bsdf_rep(fp[n-1])) |
797 |
> |
if (!load_bsdf_rep(fp[n-a])) |
798 |
|
return(1); |
799 |
< |
fclose(fp[n-1]); |
799 |
> |
fclose(fp[n-a]); |
800 |
|
if (!build_wRBF()) |
801 |
|
return(1); |
802 |
|
} |
803 |
|
put_matBSDF(NULL); |
804 |
|
} |
805 |
+ |
if (myLim[1] > myLim[0]) /* override maximum BSDF? */ |
806 |
+ |
overall_max = myLim[1]; |
807 |
|
put_source(); /* before hemispheres & labels */ |
808 |
|
put_hemispheres(); |
809 |
|
put_scale(); |