| 11 |
|
#include <stdlib.h> |
| 12 |
|
#include "rtio.h" |
| 13 |
|
#include "rtmath.h" |
| 14 |
+ |
#include "rtprocess.h" |
| 15 |
|
#include "bsdf.h" |
| 16 |
|
#include "bsdf_m.h" |
| 17 |
|
#include "random.h" |
| 36 |
|
|
| 37 |
|
char *progname; /* global argv[0] */ |
| 38 |
|
|
| 39 |
< |
int verbose = 0; /* verbose mode? */ |
| 39 |
> |
int verbose = 0; /* verbose mode (< 0 no warnings) */ |
| 40 |
|
|
| 41 |
|
char *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"}; |
| 42 |
|
int nrcargs = 2; |
| 54 |
|
char *khalffn = "klems_half.cal"; |
| 55 |
|
char *kquarterfn = "klems_quarter.cal"; |
| 56 |
|
|
| 57 |
< |
#define PARAMSTART "@rfluxmtx" /* string indicating parameters */ |
| 57 |
> |
/* string indicating parameters */ |
| 58 |
> |
const char PARAMSTART[] = "@rfluxmtx"; |
| 59 |
|
|
| 60 |
|
/* surface type IDs */ |
| 61 |
|
#define ST_NONE 0 |
| 68 |
|
void *priv; /* private data (malloc'ed) */ |
| 69 |
|
char sname[32]; /* surface name */ |
| 70 |
|
FVECT snrm; /* surface normal */ |
| 71 |
< |
double area; /* surface area (or solid angle) */ |
| 71 |
> |
double area; /* surface area / proj. solid angle */ |
| 72 |
|
short styp; /* surface type */ |
| 73 |
|
short nfargs; /* number of real arguments */ |
| 74 |
|
double farg[1]; /* real values (extends struct) */ |
| 97 |
|
|
| 98 |
|
PARAMS curparams; |
| 99 |
|
char curmod[128]; |
| 100 |
+ |
char newparams[1024]; |
| 101 |
|
|
| 102 |
|
typedef int SURFSAMP(FVECT, SURF *, double); |
| 103 |
|
|
| 111 |
|
static void |
| 112 |
|
clear_params(PARAMS *p, int reset_only) |
| 113 |
|
{ |
| 111 |
– |
curmod[0] = '\0'; |
| 114 |
|
while (p->slist != NULL) { |
| 115 |
|
SURF *sdel = p->slist; |
| 116 |
|
p->slist = sdel->next; |
| 125 |
|
p->outfn = NULL; |
| 126 |
|
return; |
| 127 |
|
} |
| 128 |
< |
memset(p, 0, sizeof(curparams)); |
| 128 |
> |
memset(p, 0, sizeof(PARAMS)); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
/* Get surface type from name */ |
| 145 |
|
static char * |
| 146 |
|
oconv_command(int ac, char *av[]) |
| 147 |
|
{ |
| 148 |
< |
static char oconvbuf[2048] = "!oconv -f"; |
| 149 |
< |
char *cp = oconvbuf + 9; |
| 150 |
< |
|
| 148 |
> |
static char oconvbuf[2048] = "!oconv -f "; |
| 149 |
> |
char *cp = oconvbuf + 10; |
| 150 |
> |
char *recv = *av++; |
| 151 |
> |
|
| 152 |
> |
if (ac-- <= 0) |
| 153 |
> |
return(NULL); |
| 154 |
|
while (ac-- > 0) { |
| 155 |
+ |
strcpy(cp, *av++); |
| 156 |
+ |
while (*cp) cp++; |
| 157 |
+ |
*cp++ = ' '; |
| 158 |
|
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) { |
| 159 |
|
fputs(progname, stderr); |
| 160 |
|
fputs(": too many file arguments!\n", stderr); |
| 161 |
|
exit(1); |
| 162 |
|
} |
| 155 |
– |
*cp++ = ' '; |
| 156 |
– |
strcpy(cp, *av++); |
| 157 |
– |
while (*cp) cp++; |
| 163 |
|
} |
| 164 |
< |
*cp = '\0'; |
| 164 |
> |
strcpy(cp, recv); /* receiver goes last */ |
| 165 |
|
return(oconvbuf); |
| 166 |
|
} |
| 167 |
|
|
| 226 |
|
fputs(": command line too long in popen_arglist()\n", stderr); |
| 227 |
|
return(NULL); |
| 228 |
|
} |
| 229 |
< |
if (verbose) |
| 229 |
> |
if (verbose > 0) |
| 230 |
|
fprintf(stderr, "%s: opening pipe %s: %s\n", |
| 231 |
|
progname, (*mode=='w') ? "to" : "from", cmd); |
| 232 |
|
return(popen(cmd, mode)); |
| 244 |
|
fputs(": command line too long in my_exec()\n", stderr); |
| 245 |
|
return(1); |
| 246 |
|
} |
| 247 |
< |
if (verbose) |
| 247 |
> |
if (verbose > 0) |
| 248 |
|
fprintf(stderr, "%s: running: %s\n", progname, cmd); |
| 249 |
|
return(system(cmd)); |
| 250 |
|
} |
| 259 |
|
fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]); |
| 260 |
|
return(1); |
| 261 |
|
} |
| 262 |
< |
if (verbose) { |
| 262 |
> |
if (verbose > 0) { |
| 263 |
|
char cmd[4096]; |
| 264 |
|
if (!convert_commandline(cmd, sizeof(cmd), av)) |
| 265 |
|
strcpy(cmd, "COMMAND TOO LONG TO SHOW"); |
| 313 |
|
|
| 314 |
|
/* Parse program parameters (directives) */ |
| 315 |
|
static int |
| 316 |
< |
parse_params(char *pargs) |
| 316 |
> |
parse_params(PARAMS *p, char *pargs) |
| 317 |
|
{ |
| 318 |
|
char *cp = pargs; |
| 319 |
|
int nparams = 0; |
| 320 |
|
int i; |
| 321 |
|
|
| 322 |
< |
for ( ; ; ) |
| 322 |
> |
for ( ; ; ) { |
| 323 |
|
switch (*cp++) { |
| 324 |
|
case 'h': |
| 325 |
|
if (*cp++ != '=') |
| 326 |
|
break; |
| 327 |
< |
curparams.hsiz = 0; |
| 327 |
> |
p->hsiz = 0; |
| 328 |
|
i = 0; |
| 329 |
|
while (*cp && !isspace(*cp)) { |
| 330 |
|
if (isdigit(*cp)) |
| 331 |
< |
curparams.hsiz = 10*curparams.hsiz + |
| 332 |
< |
*cp - '0'; |
| 328 |
< |
curparams.hemis[i++] = *cp++; |
| 331 |
> |
p->hsiz = 10*p->hsiz + *cp - '0'; |
| 332 |
> |
p->hemis[i++] = *cp++; |
| 333 |
|
} |
| 334 |
|
if (!i) |
| 335 |
|
break; |
| 336 |
< |
curparams.hemis[i] = '\0'; |
| 337 |
< |
curparams.hsiz += !curparams.hsiz; |
| 336 |
> |
p->hemis[i] = '\0'; |
| 337 |
> |
p->hsiz += !p->hsiz; |
| 338 |
|
++nparams; |
| 339 |
|
continue; |
| 340 |
|
case 'u': |
| 341 |
|
if (*cp++ != '=') |
| 342 |
|
break; |
| 343 |
< |
if (!get_direction(curparams.vup, cp)) |
| 343 |
> |
if (!get_direction(p->vup, cp)) |
| 344 |
|
break; |
| 345 |
+ |
while (*cp && !isspace(*cp++)) |
| 346 |
+ |
; |
| 347 |
|
++nparams; |
| 348 |
|
continue; |
| 349 |
|
case 'o': |
| 355 |
|
if (!i) |
| 356 |
|
break; |
| 357 |
|
*--cp = '\0'; |
| 358 |
< |
curparams.outfn = savqstr(cp-i); |
| 358 |
> |
p->outfn = savqstr(cp-i); |
| 359 |
|
*cp++ = ' '; |
| 360 |
|
++nparams; |
| 361 |
|
continue; |
| 362 |
|
case ' ': |
| 363 |
|
case '\t': |
| 364 |
|
case '\r': |
| 359 |
– |
case '\n': |
| 365 |
|
continue; |
| 366 |
+ |
case '\n': |
| 367 |
|
case '\0': |
| 368 |
|
return(nparams); |
| 369 |
|
default: |
| 370 |
|
break; |
| 371 |
|
} |
| 372 |
< |
fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs); |
| 372 |
> |
break; |
| 373 |
> |
} |
| 374 |
> |
fprintf(stderr, "%s: bad parameter string: %s", progname, pargs); |
| 375 |
|
exit(1); |
| 376 |
|
return(-1); /* pro forma return */ |
| 377 |
|
} |
| 380 |
|
static void |
| 381 |
|
finish_receiver(void) |
| 382 |
|
{ |
| 383 |
+ |
char sbuf[256]; |
| 384 |
+ |
int uniform = 0; |
| 385 |
|
char *calfn = NULL; |
| 386 |
+ |
char *params = NULL; |
| 387 |
|
char *binv = NULL; |
| 388 |
|
char *binf = NULL; |
| 389 |
|
char *nbins = NULL; |
| 379 |
– |
char sbuf[256]; |
| 390 |
|
|
| 391 |
|
if (!curmod[0]) { |
| 392 |
|
fputs(progname, stderr); |
| 398 |
|
rcarg[nrcargs++] = "-o"; |
| 399 |
|
rcarg[nrcargs++] = curparams.outfn; |
| 400 |
|
} |
| 401 |
< |
/* add bin specification */ |
| 401 |
> |
/* check arguments */ |
| 402 |
|
if (!curparams.hemis[0]) { |
| 403 |
|
fputs(progname, stderr); |
| 404 |
|
fputs(": missing hemisphere sampling type!\n", stderr); |
| 409 |
|
fputs(": undefined normal for hemisphere sampling\n", stderr); |
| 410 |
|
exit(1); |
| 411 |
|
} |
| 412 |
< |
if (normalize(curparams.vup) == 0) |
| 412 |
> |
if (normalize(curparams.vup) == 0) { |
| 413 |
|
if (fabs(curparams.nrm[2]) < .7) |
| 414 |
|
curparams.vup[2] = 1; |
| 415 |
|
else |
| 416 |
|
curparams.vup[1] = 1; |
| 417 |
+ |
} |
| 418 |
+ |
/* determine sample type/bin */ |
| 419 |
|
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
| 420 |
< |
binv = "0"; |
| 420 |
> |
binv = "0"; /* uniform sampling -- one bin */ |
| 421 |
> |
uniform = 1; |
| 422 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
| 423 |
|
tolower(curparams.hemis[1]) == 'c') { |
| 424 |
|
/* assign parameters */ |
| 427 |
|
fputs(": missing size for Shirley-Chiu sampling!\n", stderr); |
| 428 |
|
exit(1); |
| 429 |
|
} |
| 430 |
< |
sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
| 430 |
> |
calfn = shirchiufn; shirchiufn = NULL; |
| 431 |
> |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", |
| 432 |
|
curparams.hsiz, |
| 433 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
| 434 |
|
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
| 435 |
< |
CHECKARGC(2); |
| 422 |
< |
rcarg[nrcargs++] = "-p"; |
| 423 |
< |
rcarg[nrcargs++] = savqstr(sbuf); |
| 424 |
< |
calfn = shirchiufn; shirchiufn = NULL; |
| 435 |
> |
params = savqstr(sbuf); |
| 436 |
|
binv = "scbin"; |
| 437 |
|
nbins = "SCdim*SCdim"; |
| 438 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
| 439 |
|
(tolower(curparams.hemis[0]) == 't')) { |
| 440 |
|
calfn = reinhfn; reinhfn = NULL; |
| 441 |
< |
/* XXX Need to set number of divisions */ |
| 442 |
< |
binf = "rhbin"; |
| 443 |
< |
nbins = "Nrhbins"; |
| 441 |
> |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", |
| 442 |
> |
curparams.hsiz, |
| 443 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
| 444 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
| 445 |
> |
params = savqstr(sbuf); |
| 446 |
> |
binv = "rbin"; |
| 447 |
> |
nbins = "Nrbins"; |
| 448 |
|
} else if (tolower(curparams.hemis[0]) == 'k' && |
| 449 |
|
!curparams.hemis[1] | |
| 450 |
|
(tolower(curparams.hemis[1]) == 'f') | |
| 469 |
|
progname, curparams.hemis); |
| 470 |
|
exit(1); |
| 471 |
|
} |
| 472 |
+ |
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
| 473 |
+ |
SURF *sp; |
| 474 |
+ |
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
| 475 |
+ |
if (fabs(sp->area - PI) > 1e-3) { |
| 476 |
+ |
fprintf(stderr, "%s: source '%s' must be 180-degrees\n", |
| 477 |
+ |
progname, sp->sname); |
| 478 |
+ |
exit(1); |
| 479 |
+ |
} |
| 480 |
+ |
} |
| 481 |
|
if (calfn != NULL) { /* add cal file if needed */ |
| 482 |
|
CHECKARGC(2); |
| 483 |
|
rcarg[nrcargs++] = "-f"; |
| 484 |
|
rcarg[nrcargs++] = calfn; |
| 485 |
|
} |
| 486 |
+ |
if (params != NULL) { /* parameters _after_ cal file */ |
| 487 |
+ |
CHECKARGC(2); |
| 488 |
+ |
rcarg[nrcargs++] = "-p"; |
| 489 |
+ |
rcarg[nrcargs++] = params; |
| 490 |
+ |
} |
| 491 |
|
if (nbins != NULL) { /* add #bins if set */ |
| 492 |
|
CHECKARGC(2); |
| 493 |
|
rcarg[nrcargs++] = "-bn"; |
| 494 |
|
rcarg[nrcargs++] = nbins; |
| 495 |
|
} |
| 496 |
< |
if (binfv != NULL) { |
| 496 |
> |
if (binv != NULL) { |
| 497 |
|
CHECKARGC(2); /* assign bin variable */ |
| 498 |
|
rcarg[nrcargs++] = "-b"; |
| 499 |
|
rcarg[nrcargs++] = binv; |
| 500 |
|
} else if (binf != NULL) { |
| 501 |
|
CHECKARGC(2); /* assign bin function */ |
| 502 |
+ |
rcarg[nrcargs++] = "-b"; |
| 503 |
|
sprintf(sbuf, "%s(%g,%g,%g,%g,%g,%g)", binf, |
| 504 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
| 505 |
|
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
| 476 |
– |
rcarg[nrcargs++] = "-b"; |
| 506 |
|
rcarg[nrcargs++] = savqstr(sbuf); |
| 507 |
|
} |
| 508 |
|
CHECKARGC(2); /* modifier argument goes last */ |
| 562 |
|
sp->priv = (void *)uva; |
| 563 |
|
} |
| 564 |
|
SDmultiSamp(samp2, 2, x); |
| 565 |
< |
samp2[0] = sp->farg[6] + sqrt(samp2[0]*sp->area*(1./PI)); |
| 565 |
> |
samp2[0] = sqrt(samp2[0]*sp->area*(1./PI) + sp->farg[6]*sp->farg[6]); |
| 566 |
|
samp2[1] *= 2.*PI; |
| 567 |
|
uv[0] = samp2[0]*tcos(samp2[1]); |
| 568 |
|
uv[1] = samp2[0]*tsin(samp2[1]); |
| 615 |
|
} |
| 616 |
|
ptp->ntris = 0; |
| 617 |
|
v2l->p = (void *)ptp; |
| 618 |
< |
if (!polyTriangulate(v2l, add_triangle)) |
| 618 |
> |
if (!polyTriangulate(v2l, add_triangle)) { |
| 619 |
> |
fprintf(stderr, |
| 620 |
> |
"%s: cannot triangulate polygon '%s'\n", |
| 621 |
> |
progname, sp->sname); |
| 622 |
|
return(0); |
| 623 |
+ |
} |
| 624 |
|
for (i = ptp->ntris; i--; ) { |
| 625 |
|
int a = ptp->tri[i].vndx[0]; |
| 626 |
|
int b = ptp->tri[i].vndx[1]; |
| 669 |
|
/* special case for lone surface */ |
| 670 |
|
if (p->nsurfs == 1) { |
| 671 |
|
sp = p->slist; |
| 672 |
< |
if (DOT(sp->snrm, rdir) >= -FTINY) |
| 673 |
< |
return(0); /* behind surface! */ |
| 672 |
> |
if (DOT(sp->snrm, rdir) >= -FTINY) { |
| 673 |
> |
fprintf(stderr, |
| 674 |
> |
"%s: internal - sample behind sender '%s'\n", |
| 675 |
> |
progname, sp->sname); |
| 676 |
> |
return(0); |
| 677 |
> |
} |
| 678 |
|
return((*orig_in_surf[sp->styp])(orig, sp, x)); |
| 679 |
|
} |
| 680 |
|
if (p->nsurfs > nall) { /* (re)allocate surface area cache */ |
| 688 |
|
projsa[i] = -DOT(sp->snrm, rdir) * sp->area; |
| 689 |
|
tarea += projsa[i] *= (double)(projsa[i] > FTINY); |
| 690 |
|
} |
| 691 |
< |
if (tarea <= FTINY) /* wrong side of sender? */ |
| 691 |
> |
if (tarea <= FTINY) { /* wrong side of sender? */ |
| 692 |
> |
fputs(progname, stderr); |
| 693 |
> |
fputs(": internal - sample behind all sender elements!\n", |
| 694 |
> |
stderr); |
| 695 |
|
return(0); |
| 696 |
+ |
} |
| 697 |
|
tarea *= x; /* get surface from list */ |
| 698 |
|
for (i = 0, sp = p->slist; tarea > projsa[i]; sp = sp->next) |
| 699 |
|
tarea -= projsa[i++]; |
| 766 |
|
#define T_NALT 7 |
| 767 |
|
static const int tnaz[T_NALT] = {30, 30, 24, 24, 18, 12, 6}; |
| 768 |
|
const int RowMax = T_NALT*p->hsiz + 1; |
| 769 |
< |
const double RAH = (.25*PI)/(RowMax-.5); |
| 769 |
> |
const double RAH = (.5*PI)/(RowMax-.5); |
| 770 |
|
#define rnaz(r) (r >= RowMax-1 ? 1 : p->hsiz*tnaz[r/p->hsiz]) |
| 771 |
|
int n = sampcnt; |
| 772 |
|
int row, col; |
| 791 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
| 792 |
|
alt = (row+samp3[1])*RAH; |
| 793 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
| 794 |
< |
duvw[2] = tcos(alt); /* measured from horizon */ |
| 794 |
> |
duvw[2] = cos(alt); /* measured from horizon */ |
| 795 |
|
duvw[0] = tcos(azi)*duvw[2]; |
| 796 |
|
duvw[1] = tsin(azi)*duvw[2]; |
| 797 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
| 867 |
|
fputs(": no sender surface!\n", stderr); |
| 868 |
|
return(-1); |
| 869 |
|
} |
| 870 |
< |
if (curparams.outfn != NULL) /* misplaced output file spec. */ |
| 870 |
> |
/* misplaced output file spec. */ |
| 871 |
> |
if ((curparams.outfn != NULL) & (verbose >= 0)) |
| 872 |
|
fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n", |
| 873 |
|
progname, curparams.outfn); |
| 874 |
|
/* check/set basis hemisphere */ |
| 882 |
|
fputs(": undefined normal for sender sampling\n", stderr); |
| 883 |
|
return(-1); |
| 884 |
|
} |
| 885 |
< |
if (normalize(curparams.vup) == 0) |
| 885 |
> |
if (normalize(curparams.vup) == 0) { |
| 886 |
|
if (fabs(curparams.nrm[2]) < .7) |
| 887 |
|
curparams.vup[2] = 1; |
| 888 |
|
else |
| 889 |
|
curparams.vup[1] = 1; |
| 890 |
+ |
} |
| 891 |
|
VCROSS(curparams.udir, curparams.vup, curparams.nrm); |
| 892 |
|
if (normalize(curparams.udir) == 0) { |
| 893 |
|
fputs(progname, stderr); |
| 1011 |
|
case ST_SOURCE: |
| 1012 |
|
if (snew->nfargs != 4) |
| 1013 |
|
goto badcount; |
| 1014 |
< |
VCOPY(snew->snrm, snew->farg); |
| 1014 |
> |
for (n = 3; n--; ) /* need to reverse "normal" */ |
| 1015 |
> |
snew->snrm[n] = -snew->farg[n]; |
| 1016 |
|
if (normalize(snew->snrm) == 0) |
| 1017 |
|
goto badnorm; |
| 1018 |
< |
snew->area = 2.*PI*(1. - cos((PI/180./2.)*snew->farg[3])); |
| 1018 |
> |
snew->area = sin((PI/180./2.)*snew->farg[3]); |
| 1019 |
> |
snew->area *= PI*snew->area; |
| 1020 |
|
break; |
| 1021 |
|
} |
| 1022 |
< |
if (snew->area <= FTINY) { |
| 1022 |
> |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
| 1023 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
| 1024 |
|
progname, oname); |
| 1025 |
|
free(snew); |
| 1031 |
|
curparams.nsurfs++; |
| 1032 |
|
return; |
| 1033 |
|
badcount: |
| 1034 |
< |
fprintf(stderr, "%s: bad argument count for surface '%s'\n", |
| 1034 |
> |
fprintf(stderr, "%s: bad argument count for surface element '%s'\n", |
| 1035 |
|
progname, oname); |
| 1036 |
|
exit(1); |
| 1037 |
|
badnorm: |
| 1038 |
< |
fprintf(stderr, "%s: bad orientation for surface '%s'\n", |
| 1038 |
> |
fprintf(stderr, "%s: bad orientation for surface element '%s'\n", |
| 1039 |
|
progname, oname); |
| 1040 |
|
exit(1); |
| 1041 |
|
} |
| 1067 |
|
finish_receiver(); |
| 1068 |
|
clear_params(&curparams, 1); |
| 1069 |
|
} |
| 1070 |
+ |
parse_params(&curparams, newparams); |
| 1071 |
+ |
newparams[0] = '\0'; |
| 1072 |
|
strcpy(curmod, thismod); |
| 1073 |
|
} |
| 1074 |
|
add_surface(st, oname, fp); /* read & store surface */ |
| 1075 |
|
return(1); |
| 1076 |
|
} |
| 1077 |
|
/* else skip arguments */ |
| 1078 |
< |
if (!fscanf(fp, "%d", &n)) return; |
| 1078 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
| 1079 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
| 1080 |
< |
if (!fscanf(fp, "%d", &n)) return; |
| 1080 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
| 1081 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
| 1082 |
< |
if (!fscanf(fp, "%d", &n)) return; |
| 1082 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
| 1083 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
| 1084 |
|
return(0); |
| 1085 |
|
} |
| 1105 |
|
fputs(": cannot use source as a sender!\n", stderr); |
| 1106 |
|
return(-1); |
| 1107 |
|
} |
| 1108 |
+ |
parse_params(&curparams, newparams); |
| 1109 |
+ |
newparams[0] = '\0'; |
| 1110 |
|
add_surface(st, oname, fp); /* read & store surface */ |
| 1111 |
|
return(0); |
| 1112 |
|
} |
| 1113 |
|
/* else skip arguments */ |
| 1114 |
< |
if (!fscanf(fp, "%d", &n)) return; |
| 1114 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
| 1115 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
| 1116 |
< |
if (!fscanf(fp, "%d", &n)) return; |
| 1116 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
| 1117 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
| 1118 |
< |
if (!fscanf(fp, "%d", &n)) return; |
| 1118 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
| 1119 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
| 1120 |
|
return(0); |
| 1121 |
|
} |
| 1150 |
|
continue; |
| 1151 |
|
} |
| 1152 |
|
if (c == '#') { /* parameters/comment */ |
| 1153 |
< |
if (fscanf(fp, "%s", inpbuf) == 1 && |
| 1153 |
> |
if ((c = getc(fp)) == EOF || ungetc(c,fp) == EOF) |
| 1154 |
> |
break; |
| 1155 |
> |
if (!isspace(c) && fscanf(fp, "%s", inpbuf) == 1 && |
| 1156 |
|
!strcmp(inpbuf, PARAMSTART)) { |
| 1157 |
|
if (fgets(inpbuf, sizeof(inpbuf), fp) != NULL) |
| 1158 |
< |
parse_params(inpbuf); |
| 1158 |
> |
strcat(newparams, inpbuf); |
| 1159 |
|
continue; |
| 1160 |
|
} |
| 1161 |
< |
while ((c = getc(fp)) != EOF && c != '\n'); |
| 1161 |
> |
while ((c = getc(fp)) != EOF && c != '\n') |
| 1162 |
|
; /* else skipping comment */ |
| 1163 |
|
continue; |
| 1164 |
|
} |
| 1182 |
|
main(int argc, char *argv[]) |
| 1183 |
|
{ |
| 1184 |
|
char fmtopt[6] = "-faa"; /* default output is ASCII */ |
| 1185 |
+ |
char *xrs=NULL, *yrs=NULL, *ldopt=NULL; |
| 1186 |
+ |
char *iropt = NULL; |
| 1187 |
|
char *sendfn; |
| 1188 |
|
char sampcntbuf[32], nsbinbuf[32]; |
| 1189 |
|
FILE *rcfp; |
| 1191 |
|
int a, i; |
| 1192 |
|
/* screen rcontrib options */ |
| 1193 |
|
progname = argv[0]; |
| 1194 |
< |
for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) { |
| 1195 |
< |
int na = 1; /* !! Keep consistent !! */ |
| 1196 |
< |
switch (argv[a][1]) { |
| 1194 |
> |
for (a = 1; a < argc-2; a++) { |
| 1195 |
> |
int na; |
| 1196 |
> |
/* check for argument expansion */ |
| 1197 |
> |
while ((na = expandarg(&argc, &argv, a)) > 0) |
| 1198 |
> |
; |
| 1199 |
> |
if (na < 0) { |
| 1200 |
> |
fprintf(stderr, "%s: cannot expand '%s'\n", |
| 1201 |
> |
progname, argv[a]); |
| 1202 |
> |
return(1); |
| 1203 |
> |
} |
| 1204 |
> |
if (argv[a][0] != '-' || !argv[a][1]) |
| 1205 |
> |
break; |
| 1206 |
> |
na = 1; |
| 1207 |
> |
switch (argv[a][1]) { /* !! Keep consistent !! */ |
| 1208 |
|
case 'v': /* verbose mode */ |
| 1209 |
< |
verbose = !verbose; |
| 1209 |
> |
verbose = 1; |
| 1210 |
|
na = 0; |
| 1211 |
|
continue; |
| 1212 |
|
case 'f': /* special case for -fo, -ff, etc. */ |
| 1219 |
|
case 'f': |
| 1220 |
|
case 'd': |
| 1221 |
|
case 'c': |
| 1222 |
< |
if (!(fmtopt[4] = argv[a][3])) |
| 1223 |
< |
fmtopt[4] = argv[a][2]; |
| 1224 |
< |
fmtopt[3] = argv[a][2]; |
| 1222 |
> |
if (!(fmtopt[3] = argv[a][3])) |
| 1223 |
> |
fmtopt[3] = argv[a][2]; |
| 1224 |
> |
fmtopt[2] = argv[a][2]; |
| 1225 |
|
na = 0; |
| 1226 |
|
continue; /* will pass later */ |
| 1227 |
|
default: |
| 1228 |
|
goto userr; |
| 1229 |
|
} |
| 1230 |
|
break; |
| 1231 |
+ |
case 'x': /* x-resolution */ |
| 1232 |
+ |
xrs = argv[++a]; |
| 1233 |
+ |
na = 0; |
| 1234 |
+ |
continue; |
| 1235 |
+ |
case 'y': /* y-resolution */ |
| 1236 |
+ |
yrs = argv[++a]; |
| 1237 |
+ |
na = 0; |
| 1238 |
+ |
continue; |
| 1239 |
|
case 'c': /* number of samples */ |
| 1240 |
< |
sampcnt = atoi(argv[a+1]); |
| 1240 |
> |
sampcnt = atoi(argv[++a]); |
| 1241 |
|
if (sampcnt <= 0) |
| 1242 |
|
goto userr; |
| 1243 |
|
na = 0; /* we re-add this later */ |
| 1244 |
|
continue; |
| 1245 |
< |
case 'V': /* options without arguments */ |
| 1174 |
< |
case 'w': |
| 1175 |
< |
case 'u': |
| 1245 |
> |
case 'I': /* only for pass-through mode */ |
| 1246 |
|
case 'i': |
| 1247 |
+ |
iropt = argv[a]; |
| 1248 |
+ |
na = 0; |
| 1249 |
+ |
continue; |
| 1250 |
+ |
case 'w': /* options without arguments */ |
| 1251 |
+ |
if (argv[a][2] != '+') verbose = -1; |
| 1252 |
+ |
case 'V': |
| 1253 |
+ |
case 'u': |
| 1254 |
|
case 'h': |
| 1255 |
+ |
case 'r': |
| 1256 |
|
break; |
| 1257 |
|
case 'n': /* options with 1 argument */ |
| 1258 |
|
case 's': |
| 1263 |
|
if (argv[a][2] != 'v') goto userr; |
| 1264 |
|
break; |
| 1265 |
|
case 'l': /* special case */ |
| 1266 |
< |
if (argv[a][2] == 'd') goto userr; |
| 1266 |
> |
if (argv[a][2] == 'd') { |
| 1267 |
> |
ldopt = argv[a]; |
| 1268 |
> |
na = 0; |
| 1269 |
> |
continue; |
| 1270 |
> |
} |
| 1271 |
|
na = 2; |
| 1272 |
|
break; |
| 1273 |
|
case 'd': /* special case */ |
| 1280 |
|
if (!argv[a][2]) goto userr; |
| 1281 |
|
na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2; |
| 1282 |
|
break; |
| 1201 |
– |
case '\0': /* pass-through mode */ |
| 1202 |
– |
goto done_opts; |
| 1283 |
|
default: /* anything else is verbotten */ |
| 1284 |
|
goto userr; |
| 1285 |
|
} |
| 1289 |
|
while (--na) /* + arguments if any */ |
| 1290 |
|
rcarg[nrcargs++] = argv[++a]; |
| 1291 |
|
} |
| 1212 |
– |
done_opts: |
| 1292 |
|
if (a > argc-2) |
| 1293 |
|
goto userr; /* check at end of options */ |
| 1294 |
|
sendfn = argv[a++]; /* assign sender & receiver inputs */ |
| 1295 |
|
if (sendfn[0] == '-') { /* user wants pass-through mode? */ |
| 1296 |
|
if (sendfn[1]) goto userr; |
| 1297 |
|
sendfn = NULL; |
| 1298 |
+ |
if (iropt) { |
| 1299 |
+ |
CHECKARGC(1); |
| 1300 |
+ |
rcarg[nrcargs++] = iropt; |
| 1301 |
+ |
} |
| 1302 |
+ |
if (xrs) { |
| 1303 |
+ |
CHECKARGC(2); |
| 1304 |
+ |
rcarg[nrcargs++] = "-x"; |
| 1305 |
+ |
rcarg[nrcargs++] = xrs; |
| 1306 |
+ |
} |
| 1307 |
+ |
if (yrs) { |
| 1308 |
+ |
CHECKARGC(2); |
| 1309 |
+ |
rcarg[nrcargs++] = "-y"; |
| 1310 |
+ |
rcarg[nrcargs++] = yrs; |
| 1311 |
+ |
} |
| 1312 |
+ |
if (ldopt) { |
| 1313 |
+ |
CHECKARGC(1); |
| 1314 |
+ |
rcarg[nrcargs++] = ldopt; |
| 1315 |
+ |
} |
| 1316 |
|
if (sampcnt <= 0) sampcnt = 1; |
| 1317 |
< |
} else { /* else FVECT determines input format */ |
| 1318 |
< |
fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
| 1317 |
> |
} else { /* else in sampling mode */ |
| 1318 |
> |
if (iropt) { |
| 1319 |
> |
fputs(progname, stderr); |
| 1320 |
> |
fputs(": -i, -I supported for pass-through only\n", stderr); |
| 1321 |
> |
return(1); |
| 1322 |
> |
} |
| 1323 |
> |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
| 1324 |
|
if (sampcnt <= 0) sampcnt = 10000; |
| 1325 |
|
} |
| 1326 |
|
sprintf(sampcntbuf, "%d", sampcnt); |
| 1359 |
|
if (verbose) { |
| 1360 |
|
fprintf(stderr, "%s: sampling %d directions", progname, nsbins); |
| 1361 |
|
if (curparams.nsurfs > 1) |
| 1362 |
< |
fprintf(stderr, " (%d surfaces)\n", curparams.nsurfs); |
| 1362 |
> |
fprintf(stderr, " (%d elements)\n", curparams.nsurfs); |
| 1363 |
|
else |
| 1364 |
|
fputc('\n', stderr); |
| 1365 |
|
} |
| 1370 |
|
userr: |
| 1371 |
|
if (a < argc-2) |
| 1372 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |
| 1373 |
< |
fprintf(stderr, "Usage: %s [rcontrib options] sender.rad receiver.rad [system.rad ..]\n", |
| 1373 |
> |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n", |
| 1374 |
|
progname); |
| 1375 |
|
return(1); |
| 1376 |
|
} |