| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#define _USE_MATH_DEFINES |
| 11 |
– |
#include <stdio.h> |
| 11 |
|
#include <stdlib.h> |
| 13 |
– |
#include <string.h> |
| 12 |
|
#include <math.h> |
| 13 |
|
#include "random.h" |
| 14 |
|
#include "platform.h" |
| 29 |
|
static const char klems_quarter[] = "LBNL/Klems Quarter"; |
| 30 |
|
static const char *kbasis = klems_full; |
| 31 |
|
/* number of BSDF samples per patch */ |
| 32 |
< |
static int npsamps = 256; |
| 32 |
> |
static int npsamps = 1024; |
| 33 |
|
/* limit on number of RBF lobes */ |
| 34 |
|
static int lobe_lim = 15000; |
| 35 |
|
/* progress bar length */ |
| 200 |
|
goto err; |
| 201 |
|
sum += sdv.cieY; |
| 202 |
|
if (rbf_colorimetry == RBCtristimulus) { |
| 205 |
– |
c_ccvt(&sdv.spec, C_CSXY); |
| 203 |
|
xsum += sdv.cieY * sdv.spec.cx; |
| 204 |
|
ysum += sdv.cieY * sdv.spec.cy; |
| 205 |
|
} |
| 249 |
|
goto err; |
| 250 |
|
sum += sdv.cieY; |
| 251 |
|
if (rbf_colorimetry == RBCtristimulus) { |
| 255 |
– |
c_ccvt(&sdv.spec, C_CSXY); |
| 252 |
|
xsum += sdv.cieY * sdv.spec.cx; |
| 253 |
|
ysum += sdv.cieY * sdv.spec.cy; |
| 254 |
|
} |
| 297 |
|
goto err; |
| 298 |
|
sum += sdv.cieY; |
| 299 |
|
if (rbf_colorimetry == RBCtristimulus) { |
| 304 |
– |
c_ccvt(&sdv.spec, C_CSXY); |
| 300 |
|
xsum += sdv.cieY * sdv.spec.cx; |
| 301 |
|
ysum += sdv.cieY * sdv.spec.cy; |
| 302 |
|
} |
| 346 |
|
goto err; |
| 347 |
|
sum += sdv.cieY; |
| 348 |
|
if (rbf_colorimetry == RBCtristimulus) { |
| 354 |
– |
c_ccvt(&sdv.spec, C_CSXY); |
| 349 |
|
xsum += sdv.cieY * sdv.spec.cx; |
| 350 |
|
ysum += sdv.cieY * sdv.spec.cy; |
| 351 |
|
} |
| 429 |
|
static void |
| 430 |
|
eval_rbf(void) |
| 431 |
|
{ |
| 432 |
< |
ANGLE_BASIS *abp = get_basis(kbasis); |
| 433 |
< |
float (*XZarr)[2] = NULL; |
| 434 |
< |
float bsdfarr[MAXPATCHES*MAXPATCHES]; |
| 435 |
< |
FILE *cfp[3]; |
| 436 |
< |
FVECT vin, vout; |
| 437 |
< |
double sum, xsum, ysum; |
| 438 |
< |
int i, j, n; |
| 439 |
< |
/* sanity check */ |
| 440 |
< |
if (abp->nangles > MAXPATCHES) { |
| 441 |
< |
fprintf(stderr, "%s: too many patches!\n", progname); |
| 442 |
< |
exit(1); |
| 443 |
< |
} |
| 444 |
< |
if (rbf_colorimetry == RBCtristimulus) |
| 445 |
< |
XZarr = (float (*)[2])malloc(sizeof(float)*2*abp->nangles*abp->nangles); |
| 446 |
< |
for (i = 0; i < abp->nangles; i++) { |
| 447 |
< |
RBFNODE *rbf; |
| 448 |
< |
if (input_orient > 0) /* use incident patch center */ |
| 449 |
< |
fi_getvec(vin, i+.5*(i>0), abp); |
| 450 |
< |
else |
| 451 |
< |
bi_getvec(vin, i+.5*(i>0), abp); |
| 432 |
> |
ANGLE_BASIS *abp = get_basis(kbasis); |
| 433 |
> |
float (*XZarr)[2] = NULL; |
| 434 |
> |
float bsdfarr[MAXPATCHES*MAXPATCHES]; |
| 435 |
> |
FILE *cfp[3]; |
| 436 |
> |
FVECT vin, vout; |
| 437 |
> |
double sum, xsum, ysum, normf; |
| 438 |
> |
int i, j, ni, no, nisamps, nosamps; |
| 439 |
> |
/* sanity check */ |
| 440 |
> |
if (abp->nangles > MAXPATCHES) { |
| 441 |
> |
fprintf(stderr, "%s: too many patches!\n", progname); |
| 442 |
> |
exit(1); |
| 443 |
> |
} |
| 444 |
> |
memset(bsdfarr, 0, sizeof(bsdfarr)); |
| 445 |
> |
if (rbf_colorimetry == RBCtristimulus) |
| 446 |
> |
XZarr = (float (*)[2])calloc(abp->nangles*abp->nangles, 2*sizeof(float)); |
| 447 |
> |
nosamps = (int)(pow((double)npsamps, 0.67) + .5); |
| 448 |
> |
nisamps = (npsamps + (nosamps>>1)) / nosamps; |
| 449 |
> |
normf = 1./(double)(nisamps*nosamps); |
| 450 |
> |
for (i = 0; i < abp->nangles; i++) { |
| 451 |
> |
for (ni = nisamps; ni--; ) { /* sample over incident patch */ |
| 452 |
> |
RBFNODE *rbf; |
| 453 |
> |
if (input_orient > 0) /* vary incident patch loc. */ |
| 454 |
> |
fi_getvec(vin, i+urand(ni), abp); |
| 455 |
> |
else |
| 456 |
> |
bi_getvec(vin, i+urand(ni), abp); |
| 457 |
|
|
| 458 |
< |
rbf = advect_rbf(vin, lobe_lim); /* compute radial basis func */ |
| 458 |
> |
rbf = advect_rbf(vin, lobe_lim); /* compute radial basis func */ |
| 459 |
|
|
| 460 |
< |
for (j = 0; j < abp->nangles; j++) { |
| 461 |
< |
sum = 0; /* sample over exiting patch */ |
| 460 |
> |
for (j = 0; j < abp->nangles; j++) { |
| 461 |
> |
sum = 0; /* sample over exiting patch */ |
| 462 |
|
xsum = ysum = 0; |
| 463 |
< |
for (n = npsamps; n--; ) { |
| 463 |
> |
for (no = nosamps; no--; ) { |
| 464 |
|
SDValue sdv; |
| 465 |
|
if (output_orient > 0) |
| 466 |
< |
fo_getvec(vout, j+(n+frandom())/npsamps, abp); |
| 466 |
> |
fo_getvec(vout, j+(no+frandom())/nosamps, abp); |
| 467 |
|
else |
| 468 |
< |
bo_getvec(vout, j+(n+frandom())/npsamps, abp); |
| 468 |
> |
bo_getvec(vout, j+(no+frandom())/nosamps, abp); |
| 469 |
|
|
| 470 |
|
eval_rbfcol(&sdv, rbf, vout); |
| 471 |
|
sum += sdv.cieY; |
| 472 |
|
if (rbf_colorimetry == RBCtristimulus) { |
| 474 |
– |
c_ccvt(&sdv.spec, C_CSXY); |
| 473 |
|
xsum += sdv.cieY * sdv.spec.cx; |
| 474 |
|
ysum += sdv.cieY * sdv.spec.cy; |
| 475 |
< |
} |
| 475 |
> |
} |
| 476 |
|
} |
| 477 |
< |
n = j*abp->nangles + i; |
| 478 |
< |
bsdfarr[n] = sum / npsamps; |
| 477 |
> |
no = j*abp->nangles + i; |
| 478 |
> |
bsdfarr[no] += sum * normf; |
| 479 |
|
if (rbf_colorimetry == RBCtristimulus) { |
| 480 |
< |
XZarr[n][0] = xsum*sum/(npsamps*ysum); |
| 481 |
< |
XZarr[n][1] = (sum - xsum - ysum)*sum/(npsamps*ysum); |
| 480 |
> |
XZarr[no][0] += xsum*sum*normf/ysum; |
| 481 |
> |
XZarr[no][1] += (sum - xsum - ysum)*sum*normf/ysum; |
| 482 |
|
} |
| 483 |
|
} |
| 484 |
< |
if (rbf != NULL) |
| 484 |
> |
if (rbf != NULL) |
| 485 |
|
free(rbf); |
| 488 |
– |
prog_show((i+1.)/abp->nangles); |
| 486 |
|
} |
| 487 |
< |
/* write out our matrix */ |
| 488 |
< |
cfp[CIE_Y] = open_component_file(CIE_Y); |
| 489 |
< |
n = 0; |
| 490 |
< |
for (j = 0; j < abp->nangles; j++) { |
| 491 |
< |
for (i = 0; i < abp->nangles; i++, n++) |
| 492 |
< |
fprintf(cfp[CIE_Y], "\t%.3e\n", bsdfarr[n]); |
| 493 |
< |
fputc('\n', cfp[CIE_Y]); |
| 494 |
< |
} |
| 495 |
< |
prog_done(); |
| 496 |
< |
if (fclose(cfp[CIE_Y])) { |
| 497 |
< |
fprintf(stderr, "%s: error writing Y output\n", progname); |
| 498 |
< |
exit(1); |
| 499 |
< |
} |
| 500 |
< |
if (XZarr == NULL) /* no color? */ |
| 501 |
< |
return; |
| 502 |
< |
cfp[CIE_X] = open_component_file(CIE_X); |
| 503 |
< |
cfp[CIE_Z] = open_component_file(CIE_Z); |
| 504 |
< |
n = 0; |
| 505 |
< |
for (j = 0; j < abp->nangles; j++) { |
| 506 |
< |
for (i = 0; i < abp->nangles; i++, n++) { |
| 507 |
< |
fprintf(cfp[CIE_X], "\t%.3e\n", XZarr[n][0]); |
| 508 |
< |
fprintf(cfp[CIE_Z], "\t%.3e\n", XZarr[n][1]); |
| 509 |
< |
} |
| 510 |
< |
fputc('\n', cfp[CIE_X]); |
| 511 |
< |
fputc('\n', cfp[CIE_Z]); |
| 512 |
< |
} |
| 513 |
< |
free(XZarr); |
| 514 |
< |
if (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z])) { |
| 515 |
< |
fprintf(stderr, "%s: error writing X/Z output\n", progname); |
| 516 |
< |
exit(1); |
| 517 |
< |
} |
| 487 |
> |
prog_show((i+1.)/abp->nangles); |
| 488 |
> |
} |
| 489 |
> |
/* write out our matrix */ |
| 490 |
> |
cfp[CIE_Y] = open_component_file(CIE_Y); |
| 491 |
> |
no = 0; |
| 492 |
> |
for (j = 0; j < abp->nangles; j++) { |
| 493 |
> |
for (i = 0; i < abp->nangles; i++, no++) |
| 494 |
> |
fprintf(cfp[CIE_Y], "\t%.3e\n", bsdfarr[no]); |
| 495 |
> |
fputc('\n', cfp[CIE_Y]); |
| 496 |
> |
} |
| 497 |
> |
prog_done(); |
| 498 |
> |
if (fclose(cfp[CIE_Y])) { |
| 499 |
> |
fprintf(stderr, "%s: error writing Y output\n", progname); |
| 500 |
> |
exit(1); |
| 501 |
> |
} |
| 502 |
> |
if (XZarr == NULL) /* no color? */ |
| 503 |
> |
return; |
| 504 |
> |
cfp[CIE_X] = open_component_file(CIE_X); |
| 505 |
> |
cfp[CIE_Z] = open_component_file(CIE_Z); |
| 506 |
> |
no = 0; |
| 507 |
> |
for (j = 0; j < abp->nangles; j++) { |
| 508 |
> |
for (i = 0; i < abp->nangles; i++, no++) { |
| 509 |
> |
fprintf(cfp[CIE_X], "\t%.3e\n", XZarr[no][0]); |
| 510 |
> |
fprintf(cfp[CIE_Z], "\t%.3e\n", XZarr[no][1]); |
| 511 |
> |
} |
| 512 |
> |
fputc('\n', cfp[CIE_X]); |
| 513 |
> |
fputc('\n', cfp[CIE_Z]); |
| 514 |
> |
} |
| 515 |
> |
free(XZarr); |
| 516 |
> |
if (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z])) { |
| 517 |
> |
fprintf(stderr, "%s: error writing X/Z output\n", progname); |
| 518 |
> |
exit(1); |
| 519 |
> |
} |
| 520 |
|
} |
| 521 |
|
|
| 522 |
|
#if defined(_WIN32) || defined(_WIN64) |
| 606 |
|
add_wbsdf("-f", 1); |
| 607 |
|
add_wbsdf(argv[i], 1); |
| 608 |
|
} else { |
| 609 |
< |
fcompile(argv[i]); |
| 609 |
> |
char *fpath = getpath(argv[i], |
| 610 |
> |
getrlibpath(), 0); |
| 611 |
> |
if (fpath == NULL) { |
| 612 |
> |
fprintf(stderr, |
| 613 |
> |
"%s: cannot find file '%s'\n", |
| 614 |
> |
argv[0], argv[i]); |
| 615 |
> |
return(1); |
| 616 |
> |
} |
| 617 |
> |
fcompile(fpath); |
| 618 |
|
single_plane_incident = 0; |
| 619 |
|
} |
| 620 |
|
} else |