| 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[] = "frefl"; |
| 30 |
< |
const char ftpref[] = "ftrans"; |
| 31 |
< |
const char brpref[] = "brefl"; |
| 32 |
< |
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 |
|
|
| 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) |
| 43 |
> |
#define set_minlog() overall_min = (overall_min < 1e-5) ? 1e-5 : overall_min; \ |
| 44 |
> |
min_log10 = log10(overall_min) - .1 |
| 45 |
|
|
| 44 |
– |
#define set_minlog() (min_log10 = log10(overall_min + 1e-5) - .1) |
| 45 |
– |
|
| 46 |
– |
char *progname; |
| 47 |
– |
|
| 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; |
| 267 |
|
|
| 268 |
|
/* Put out mirror arrow for the given incident vector */ |
| 269 |
|
static void |
| 270 |
< |
put_mirror_arrow(const FVECT ivec, int inc_side) |
| 270 |
> |
put_mirror_arrow(const FVECT origin, const FVECT nrm) |
| 271 |
|
{ |
| 272 |
|
const double arrow_len = 1.2*bsdf_rad; |
| 273 |
|
const double tip_len = 0.2*bsdf_rad; |
| 274 |
< |
FVECT origin, refl; |
| 274 |
> |
static int cnt = 1; |
| 275 |
> |
FVECT refl; |
| 276 |
|
int i; |
| 277 |
|
|
| 278 |
< |
cvt_sposition(origin, ivec, inc_side); |
| 278 |
> |
refl[0] = 2.*nrm[2]*nrm[0]; |
| 279 |
> |
refl[1] = 2.*nrm[2]*nrm[1]; |
| 280 |
> |
refl[2] = 2.*nrm[2]*nrm[2] - 1.; |
| 281 |
|
|
| 282 |
< |
refl[0] = -2.*ivec[2]*ivec[0]; |
| 283 |
< |
refl[1] = -2.*ivec[2]*ivec[1]; |
| 283 |
< |
refl[2] = 2.*ivec[2]*ivec[2] - 1.; |
| 284 |
< |
|
| 285 |
< |
printf("\n# Mirror arrow\n"); |
| 286 |
< |
printf("\narrow_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("\narrow_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("\narrow_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 */ |
| 308 |
|
static void |
| 309 |
< |
put_trans_arrow(const FVECT ivec, int inc_side) |
| 309 |
> |
put_trans_arrow(const FVECT origin) |
| 310 |
|
{ |
| 311 |
|
const double arrow_len = 1.2*bsdf_rad; |
| 312 |
|
const double tip_len = 0.2*bsdf_rad; |
| 313 |
< |
FVECT origin; |
| 313 |
> |
static int cnt = 1; |
| 314 |
|
int i; |
| 315 |
|
|
| 316 |
< |
cvt_sposition(origin, ivec, inc_side); |
| 317 |
< |
|
| 320 |
< |
printf("\n# Transmission arrow\n"); |
| 321 |
< |
printf("\narrow_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("\narrow_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; |
| 368 |
|
put_BSDFs(void) |
| 369 |
|
{ |
| 370 |
|
const double scalef = bsdf_rad/(log10(overall_max) - min_log10); |
| 371 |
< |
FVECT ivec, sorg, upv; |
| 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 0.25 .\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) /* front reflection */ |
| 386 |
< |
for (i = 0; i < NINCIDENT; i++) { |
| 387 |
< |
get_ivector(ivec, i); |
| 388 |
< |
put_mirror_arrow(ivec, 1); |
| 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); |
| 393 |
– |
ivec[0] = -ivec[0]; ivec[1] = -ivec[1]; /* normal */ |
| 394 |
– |
upv[0] = ivec[0]*ivec[1]*(ivec[2] - 1.); |
| 395 |
– |
upv[1] = ivec[0]*ivec[0] + ivec[1]*ivec[1]*ivec[2]; |
| 396 |
– |
upv[2] = -ivec[1]*(ivec[0]*ivec[0] + ivec[1]*ivec[1]); |
| 397 |
– |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
| 398 |
– |
sorg[0], sorg[1], sorg[2]); |
| 399 |
– |
nxfa = 6; |
| 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 |
< |
if (SDcompXform(vMtx, ivec, upv) != SDEnone) |
| 402 |
< |
continue; |
| 403 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
| 407 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
| 408 |
< |
scalef, sorg[0], sorg[1], sorg[2]); |
| 409 |
< |
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 %s", |
| 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 |
< |
xfargs); |
| 408 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
| 409 |
|
if (!run_cmd(cmdbuf)) |
| 410 |
|
return(0); |
| 411 |
|
} |
| 412 |
< |
if (front_comp & SDsampT) /* front transmission */ |
| 413 |
< |
for (i = 0; i < NINCIDENT; i++) { |
| 419 |
< |
get_ivector(ivec, i); |
| 420 |
< |
put_trans_arrow(ivec, 1); |
| 421 |
< |
cvt_sposition(sorg, ivec, 1); |
| 422 |
< |
ivec[0] = -ivec[0]; ivec[1] = -ivec[1]; /* normal */ |
| 423 |
< |
upv[0] = ivec[0]*ivec[1]*(ivec[2] - 1.); |
| 424 |
< |
upv[1] = ivec[0]*ivec[0] + ivec[1]*ivec[1]*ivec[2]; |
| 425 |
< |
upv[2] = -ivec[1]*(ivec[0]*ivec[0] + ivec[1]*ivec[1]); |
| 426 |
< |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
| 427 |
< |
sorg[0], sorg[1], sorg[2]); |
| 428 |
< |
nxfa = 6; |
| 429 |
< |
printf("\nvoid colorfunc scale_pat\n"); |
| 430 |
< |
printf("%d bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n\t%s\n0\n0\n", |
| 431 |
< |
4+nxfa, xfargs); |
| 432 |
< |
printf("\nscale_pat glow scale_mat\n0\n0\n4 1 1 1 0\n"); |
| 433 |
< |
if (SDcompXform(vMtx, ivec, upv) != SDEnone) |
| 434 |
< |
continue; |
| 435 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
| 436 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
| 437 |
< |
scalef, sorg[0], sorg[1], sorg[2]); |
| 438 |
< |
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 %s", |
| 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 |
< |
xfargs); |
| 418 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
| 419 |
|
if (!run_cmd(cmdbuf)) |
| 420 |
|
return(0); |
| 421 |
|
} |
| 422 |
< |
if (back_comp & SDsampR) /* rear reflection */ |
| 447 |
< |
for (i = 0; i < NINCIDENT; i++) { |
| 448 |
< |
get_ivector(ivec, i); |
| 449 |
< |
put_mirror_arrow(ivec, -1); |
| 422 |
> |
if (back_comp) { |
| 423 |
|
cvt_sposition(sorg, ivec, -1); |
| 451 |
– |
ivec[0] = -ivec[0]; ivec[1] = -ivec[1]; /* normal */ |
| 452 |
– |
upv[0] = ivec[0]*ivec[1]*(ivec[2] - 1.); |
| 453 |
– |
upv[1] = ivec[0]*ivec[0] + ivec[1]*ivec[1]*ivec[2]; |
| 454 |
– |
upv[2] = -ivec[1]*(ivec[0]*ivec[0] + ivec[1]*ivec[1]); |
| 455 |
– |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
| 456 |
– |
sorg[0], sorg[1], sorg[2]); |
| 457 |
– |
nxfa = 6; |
| 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 |
< |
if (SDcompXform(vMtx, ivec, upv) != SDEnone) |
| 430 |
< |
continue; |
| 431 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
| 465 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
| 466 |
< |
scalef, sorg[0], sorg[1], sorg[2]); |
| 467 |
< |
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 %s", |
| 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 |
< |
xfargs); |
| 436 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
| 437 |
|
if (!run_cmd(cmdbuf)) |
| 438 |
|
return(0); |
| 439 |
|
} |
| 440 |
< |
if (back_comp & SDsampT) /* rear transmission */ |
| 441 |
< |
for (i = 0; i < NINCIDENT; i++) { |
| 477 |
< |
get_ivector(ivec, i); |
| 478 |
< |
put_trans_arrow(ivec, -1); |
| 479 |
< |
cvt_sposition(sorg, ivec, -1); |
| 480 |
< |
ivec[0] = -ivec[0]; ivec[1] = -ivec[1]; /* normal */ |
| 481 |
< |
upv[0] = ivec[0]*ivec[1]*(ivec[2] - 1.); |
| 482 |
< |
upv[1] = ivec[0]*ivec[0] + ivec[1]*ivec[1]*ivec[2]; |
| 483 |
< |
upv[2] = -ivec[1]*(ivec[0]*ivec[0] + ivec[1]*ivec[1]); |
| 484 |
< |
sprintf(xfargs, "-s %f -t %f %f %f", bsdf_rad, |
| 485 |
< |
sorg[0], sorg[1], sorg[2]); |
| 486 |
< |
nxfa = 6; |
| 487 |
< |
printf("\nvoid colorfunc scale_pat\n"); |
| 488 |
< |
printf("%d bsdf_red bsdf_grn bsdf_blu bsdf2rad.cal\n\t%s\n0\n0\n", |
| 489 |
< |
4+nxfa, xfargs); |
| 490 |
< |
printf("\nscale_pat glow scale_mat\n0\n0\n4 1 1 1 0\n"); |
| 491 |
< |
if (SDcompXform(vMtx, ivec, upv) != SDEnone) |
| 492 |
< |
continue; |
| 493 |
< |
nxfa = addrot(xfargs, vMtx[0], vMtx[1], vMtx[2]); |
| 494 |
< |
sprintf(xfargs+strlen(xfargs), " -s %f -t %f %f %f", |
| 495 |
< |
scalef, sorg[0], sorg[1], sorg[2]); |
| 496 |
< |
nxfa += 6; |
| 440 |
> |
if (back_comp & SDsampT) { |
| 441 |
> |
put_trans_arrow(sorg); |
| 442 |
|
fname = tfile_name(btpref, dsuffix, i); |
| 443 |
< |
sprintf(cmdbuf, "gensurf scale_mat %s%d %s %s %s %d %d | xform -ry 180 %s", |
| 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 |
< |
xfargs); |
| 446 |
> |
rotargs, scalef, sorg[0], sorg[1], sorg[2]); |
| 447 |
|
if (!run_cmd(cmdbuf)) |
| 448 |
|
return(0); |
| 449 |
|
} |
| 450 |
+ |
} |
| 451 |
|
return(1); |
| 452 |
|
} |
| 453 |
|
|
| 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 .04 .5 .8\n", |
| 465 |
< |
sph_mat); |
| 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\" upx upy upz bsdf2rad.cal\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 */ |
| 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_mat, 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_mat, 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; |
| 769 |
< |
for (n = 1; n < argc; n++) { |
| 770 |
< |
fp = fopen(argv[n], "rb"); |
| 771 |
< |
if (fp == NULL) { |
| 768 |
> |
FILE *fp[4]; |
| 769 |
> |
if (argc > a+4) { |
| 770 |
> |
fprintf(stderr, "%s: more than 4 hemispheres!\n", progname); |
| 771 |
> |
return(1); |
| 772 |
> |
} |
| 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, 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 |
|
} |
| 814 |
– |
fclose(fp); |
| 785 |
|
} |
| 786 |
+ |
if (myLim[0] >= 0) |
| 787 |
+ |
overall_min = myLim[0]; |
| 788 |
|
set_minlog(); |
| 789 |
< |
for (n = 1; n < argc; n++) { |
| 790 |
< |
fp = fopen(argv[n], "rb"); |
| 791 |
< |
if (!load_bsdf_rep(fp)) |
| 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 |
< |
fclose(fp); |
| 794 |
> |
} |
| 795 |
> |
if (!load_bsdf_rep(fp[n-a])) |
| 796 |
> |
return(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(); |
| 808 |
|
if (inpXML && myBSDF.mgf) |
| 809 |
|
convert_mgf(myBSDF.mgf); |
| 810 |
< |
if (!put_BSDFs()) |
| 810 |
> |
if (!put_BSDFs()) /* most of the output happens here */ |
| 811 |
|
return(1); |
| 812 |
|
cleanup_tmp(); |
| 813 |
|
return(0); |