24 |
|
printf(" i\t\t\t\t Report general information (metadata)\n"); |
25 |
|
printf(" c\t\t\t\t Report diffuse and specular components\n"); |
26 |
|
printf(" q theta_i phi_i theta_o phi_o\t Query BSDF for given path (CIE-XYZ)\n"); |
27 |
< |
printf(" s N theta phi\t\t\t Generate N ray directions at given incidence\n"); |
28 |
< |
printf(" h theta phi\t\t\t Report hemispherical total at given incidence\n"); |
29 |
< |
printf(" r theta phi\t\t\t Report hemispherical reflection at given incidence\n"); |
30 |
< |
printf(" t theta phi\t\t\t Report hemispherical transmission at given incidence\n"); |
27 |
> |
printf(" s[r|t][s|d] N theta phi\t Generate N ray directions & colors at given incidence\n"); |
28 |
> |
printf(" h[s|d] theta phi\t\t Report hemispherical scattering at given incidence\n"); |
29 |
> |
printf(" r[s|d] theta phi\t\t Report hemispherical reflection at given incidence\n"); |
30 |
> |
printf(" t[s|d] theta phi\t\t Report hemispherical transmission at given incidence\n"); |
31 |
|
printf(" a theta phi [t2 p2]\t\t Report resolution (in proj. steradians) for given direction(s)\n"); |
32 |
|
printf(" ^D\t\t\t\t Quit program\n"); |
33 |
|
} |
47 |
|
static void |
48 |
|
printXYZ(const char *intro, const SDValue *vp) |
49 |
|
{ |
50 |
+ |
if (vp->cieY <= 1e-9) { |
51 |
+ |
printf("%s0 0 0\n", intro); |
52 |
+ |
return; |
53 |
+ |
} |
54 |
|
printf("%s%.3e %.3e %.3e\n", intro, |
55 |
|
vp->spec.cx/vp->spec.cy*vp->cieY, |
56 |
|
vp->cieY, |
75 |
|
SDretainSet = SDretainBSDFs; /* keep BSDFs in memory */ |
76 |
|
|
77 |
|
/* loop on command */ |
78 |
< |
while (fgets(inp, sizeof(inp), stdin) != NULL) { |
78 |
> |
while (fgets(inp, sizeof(inp), stdin)) { |
79 |
|
int sflags = SDsampAll; |
80 |
|
char *cp = inp; |
81 |
|
char *cp2; |
82 |
|
FVECT vin, vout; |
83 |
|
double proja[2]; |
84 |
< |
int n; |
84 |
> |
int n, i; |
85 |
|
SDValue val; |
86 |
|
|
87 |
|
while (isspace(*cp)) cp++; |
102 |
|
bsdf = SDcacheFile(path); |
103 |
|
continue; |
104 |
|
case 'I': /* report general info. */ |
105 |
< |
if (bsdf == NULL) |
105 |
> |
if (!bsdf) |
106 |
|
goto noBSDFerr; |
107 |
|
printf("Material: '%s'\n", bsdf->matn); |
108 |
|
printf("Manufacturer: '%s'\n", bsdf->makr); |
109 |
|
printf("Width, Height, Thickness (m): %.4e, %.4e, %.4e\n", |
110 |
|
bsdf->dim[0], bsdf->dim[1], bsdf->dim[2]); |
111 |
< |
printf("Has geometry: %s\n", bsdf->mgf!=NULL ? "yes" : "no"); |
111 |
> |
if (bsdf->mgf) |
112 |
> |
printf("Has geometry: %lu bytes\n", |
113 |
> |
(unsigned long)strlen(bsdf->mgf)); |
114 |
> |
else |
115 |
> |
printf("Has geometry: no\n"); |
116 |
|
continue; |
117 |
|
case 'C': /* report constant values */ |
118 |
< |
if (bsdf == NULL) |
118 |
> |
if (!bsdf) |
119 |
|
goto noBSDFerr; |
120 |
< |
if (bsdf->rf != NULL) |
120 |
> |
if (bsdf->rf) |
121 |
|
printf("Peak front hemispherical reflectance: %.3e\n", |
122 |
|
bsdf->rLambFront.cieY + |
123 |
|
bsdf->rf->maxHemi); |
124 |
< |
if (bsdf->rb != NULL) |
124 |
> |
if (bsdf->rb) |
125 |
|
printf("Peak back hemispherical reflectance: %.3e\n", |
126 |
|
bsdf->rLambBack.cieY + |
127 |
|
bsdf->rb->maxHemi); |
128 |
< |
if (bsdf->tf != NULL) |
128 |
> |
if (bsdf->tf) |
129 |
|
printf("Peak front hemispherical transmittance: %.3e\n", |
130 |
|
bsdf->tLamb.cieY + bsdf->tf->maxHemi); |
131 |
< |
if (bsdf->tb != NULL) |
131 |
> |
if (bsdf->tb) |
132 |
|
printf("Peak back hemispherical transmittance: %.3e\n", |
133 |
|
bsdf->tLamb.cieY + bsdf->tb->maxHemi); |
134 |
|
printXYZ("Diffuse Front Reflectance: ", &bsdf->rLambFront); |
136 |
|
printXYZ("Diffuse Transmittance: ", &bsdf->tLamb); |
137 |
|
continue; |
138 |
|
case 'Q': /* query BSDF value */ |
139 |
< |
if (bsdf == NULL) |
139 |
> |
if (!bsdf) |
140 |
|
goto noBSDFerr; |
141 |
|
if (!*sskip2(cp,4)) |
142 |
|
break; |
146 |
|
printXYZ("", &val); |
147 |
|
continue; |
148 |
|
case 'S': /* sample BSDF */ |
149 |
< |
if (bsdf == NULL) |
149 |
> |
if (!bsdf) |
150 |
|
goto noBSDFerr; |
151 |
|
if (!*sskip2(cp,3)) |
152 |
|
break; |
153 |
< |
n = atoi(sskip2(cp,1)); |
153 |
> |
if (toupper(cp[1]) == 'R') { |
154 |
> |
sflags &= ~SDsampT; |
155 |
> |
++cp; |
156 |
> |
} else if (toupper(cp[1]) == 'T') { |
157 |
> |
sflags &= ~SDsampR; |
158 |
> |
++cp; |
159 |
> |
} |
160 |
> |
if (toupper(cp[1]) == 'S') |
161 |
> |
sflags &= ~SDsampDf; |
162 |
> |
else if (toupper(cp[1]) == 'D') |
163 |
> |
sflags &= ~SDsampSp; |
164 |
> |
i = n = atoi(sskip2(cp,1)); |
165 |
|
vec_from_deg(vin, atof(sskip2(cp,2)), atof(sskip2(cp,3))); |
166 |
< |
while (n-- > 0) { |
167 |
< |
if (SDreportError(SDsampBSDF(&val, vin, |
168 |
< |
rand()*(1./(RAND_MAX+.5)), |
166 |
> |
while (i-- > 0) { |
167 |
> |
VCOPY(vout, vin); |
168 |
> |
if (SDreportError(SDsampBSDF(&val, vout, |
169 |
> |
(i+rand()*(1./(RAND_MAX+.5)))/(double)n, |
170 |
|
sflags, bsdf), stderr)) |
171 |
|
break; |
172 |
< |
printf("%.8f %.8f %.8f\n", vin[0], vin[1], vin[2]); |
172 |
> |
printf("%.8f %.8f %.8f ", vout[0], vout[1], vout[2]); |
173 |
> |
printXYZ("", &val); |
174 |
|
} |
175 |
|
continue; |
176 |
< |
case 'H': /* hemispherical totals */ |
176 |
> |
case 'H': /* hemispherical values */ |
177 |
|
case 'R': |
178 |
|
case 'T': |
179 |
< |
if (bsdf == NULL) |
179 |
> |
if (!bsdf) |
180 |
|
goto noBSDFerr; |
181 |
|
if (!*sskip2(cp,2)) |
182 |
|
break; |
183 |
< |
if (tolower(*cp) == 'r') |
183 |
> |
if (toupper(cp[0]) == 'R') |
184 |
|
sflags &= ~SDsampT; |
185 |
< |
else if (tolower(*cp) == 't') |
185 |
> |
else if (toupper(cp[0]) == 'T') |
186 |
|
sflags &= ~SDsampR; |
187 |
+ |
if (toupper(cp[1]) == 'S') |
188 |
+ |
sflags &= ~SDsampDf; |
189 |
+ |
else if (toupper(cp[1]) == 'D') |
190 |
+ |
sflags &= ~SDsampSp; |
191 |
|
vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); |
192 |
|
printf("%.4e\n", SDdirectHemi(vin, sflags, bsdf)); |
193 |
|
continue; |
194 |
|
case 'A': /* resolution in proj. steradians */ |
195 |
< |
if (bsdf == NULL) |
195 |
> |
if (!bsdf) |
196 |
|
goto noBSDFerr; |
197 |
|
if (!*sskip2(cp,2)) |
198 |
|
break; |
199 |
|
vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); |
200 |
|
if (*sskip2(cp,4)) { |
201 |
|
vec_from_deg(vout, atof(sskip2(cp,3)), atof(sskip2(cp,4))); |
202 |
< |
if (SDreportError(SDsizeBSDF(proja, vin, vout, |
202 |
> |
if (SDreportError(SDsizeBSDF(proja, vout, vin, |
203 |
|
SDqueryMin+SDqueryMax, bsdf), stderr)) |
204 |
|
continue; |
205 |
|
} else if (SDreportError(SDsizeBSDF(proja, vin, NULL, |