23 |
|
#endif |
24 |
|
|
25 |
|
#ifdef _WIN32 |
26 |
< |
#define SPECIALS " \t$*?" |
26 |
> |
#define SPECIALS " \t\"$*?" |
27 |
|
#define QUOTCHAR '"' |
28 |
|
#else |
29 |
< |
#define SPECIALS " \t\n'\"()${}*?[]" |
29 |
> |
#define SPECIALS " \t\n'\"()${}*?[];|&" |
30 |
|
#define QUOTCHAR '\'' |
31 |
|
#define ALTQUOT '"' |
32 |
|
#endif |
45 |
|
#define CHECKARGC(n) if (nrcargs >= MAXRCARG-(n)) \ |
46 |
|
{ fprintf(stderr, overflowerr, progname); exit(1); } |
47 |
|
|
48 |
< |
int sampcnt = 0; /* sample count (unset) */ |
48 |
> |
int sampcnt = 0; /* sample count (0==unset) */ |
49 |
|
|
50 |
< |
char *reinhfn = "reinhart.cal"; |
51 |
< |
char *shirchufn = "disk2square.cal"; |
50 |
> |
char *reinhfn = "reinhartb.cal"; |
51 |
> |
char *shirchiufn = "disk2square.cal"; |
52 |
|
char *kfullfn = "klems_full.cal"; |
53 |
|
char *khalffn = "klems_half.cal"; |
54 |
|
char *kquarterfn = "klems_quarter.cal"; |
66 |
|
void *priv; /* private data (malloc'ed) */ |
67 |
|
char sname[32]; /* surface name */ |
68 |
|
FVECT snrm; /* surface normal */ |
69 |
< |
double area; /* surface area (or solid angle) */ |
69 |
> |
double area; /* surface area / proj. solid angle */ |
70 |
|
short styp; /* surface type */ |
71 |
< |
short nfargs; /* number of arguments */ |
72 |
< |
double farg[1]; /* arguments (extends struct) */ |
71 |
> |
short nfargs; /* number of real arguments */ |
72 |
> |
double farg[1]; /* real values (extends struct) */ |
73 |
|
} SURF; /* surface structure */ |
74 |
|
|
75 |
|
typedef struct { |
372 |
|
static void |
373 |
|
finish_receiver(void) |
374 |
|
{ |
375 |
< |
char binbuf[128]; |
375 |
> |
char sbuf[256]; |
376 |
> |
int uniform = 0; |
377 |
> |
char *calfn = NULL; |
378 |
> |
char *params = NULL; |
379 |
> |
char *binv = NULL; |
380 |
> |
char *binf = NULL; |
381 |
> |
char *nbins = NULL; |
382 |
|
|
383 |
|
if (!curmod[0]) { |
384 |
|
fputs(progname, stderr); |
390 |
|
rcarg[nrcargs++] = "-o"; |
391 |
|
rcarg[nrcargs++] = curparams.outfn; |
392 |
|
} |
393 |
< |
/* add bin specification */ |
393 |
> |
/* check arguments */ |
394 |
|
if (!curparams.hemis[0]) { |
395 |
|
fputs(progname, stderr); |
396 |
|
fputs(": missing hemisphere sampling type!\n", stderr); |
406 |
|
curparams.vup[2] = 1; |
407 |
|
else |
408 |
|
curparams.vup[1] = 1; |
409 |
+ |
/* determine sample type/bin */ |
410 |
|
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
411 |
< |
CHECKARGC(2); |
412 |
< |
rcarg[nrcargs++] = "-b"; |
406 |
< |
rcarg[nrcargs++] = "0"; |
411 |
> |
binv = "0"; /* uniform sampling -- one bin */ |
412 |
> |
uniform = 1; |
413 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
414 |
|
tolower(curparams.hemis[1]) == 'c') { |
415 |
< |
if (shirchufn != NULL) { |
410 |
< |
CHECKARGC(2); |
411 |
< |
rcarg[nrcargs++] = "-f"; |
412 |
< |
rcarg[nrcargs++] = shirchufn; |
413 |
< |
shirchufn = NULL; |
414 |
< |
} |
415 |
< |
fputs("Shirley-Chiu unimplemented...\n",stderr); exit(1); |
415 |
> |
/* assign parameters */ |
416 |
|
if (curparams.hsiz <= 1) { |
417 |
|
fputs(progname, stderr); |
418 |
|
fputs(": missing size for Shirley-Chiu sampling!\n", stderr); |
419 |
|
exit(1); |
420 |
|
} |
421 |
+ |
calfn = shirchiufn; shirchiufn = NULL; |
422 |
+ |
sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
423 |
+ |
curparams.hsiz, |
424 |
+ |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
425 |
+ |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
426 |
+ |
params = savqstr(sbuf); |
427 |
+ |
binv = "scbin"; |
428 |
+ |
nbins = "SCdim*SCdim"; |
429 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
430 |
|
(tolower(curparams.hemis[0]) == 't')) { |
431 |
< |
if (reinhfn != NULL) { |
432 |
< |
CHECKARGC(2); |
433 |
< |
rcarg[nrcargs++] = "-f"; |
434 |
< |
rcarg[nrcargs++] = reinhfn; |
435 |
< |
reinhfn = NULL; |
436 |
< |
} |
437 |
< |
fputs("Reinhart/Tregenza unimplemented...\n",stderr); exit(1); |
431 |
> |
calfn = reinhfn; reinhfn = NULL; |
432 |
> |
sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
433 |
> |
curparams.hsiz, |
434 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
435 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
436 |
> |
params = savqstr(sbuf); |
437 |
> |
binv = "rbin"; |
438 |
> |
nbins = "Nrbins"; |
439 |
|
} else if (tolower(curparams.hemis[0]) == 'k' && |
440 |
|
!curparams.hemis[1] | |
441 |
|
(tolower(curparams.hemis[1]) == 'f') | |
442 |
|
(curparams.hemis[1] == '1')) { |
443 |
< |
if (kfullfn != NULL) { |
444 |
< |
CHECKARGC(2); |
445 |
< |
rcarg[nrcargs++] = "-f"; |
437 |
< |
rcarg[nrcargs++] = kfullfn; |
438 |
< |
kfullfn = NULL; |
439 |
< |
} |
440 |
< |
CHECKARGC(4); |
441 |
< |
sprintf(binbuf, "kbin(%g,%g,%g,%g,%g,%g)", |
442 |
< |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
443 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
444 |
< |
rcarg[nrcargs++] = "-b"; |
445 |
< |
rcarg[nrcargs++] = savqstr(binbuf); |
446 |
< |
rcarg[nrcargs++] = "-bn"; |
447 |
< |
rcarg[nrcargs++] = "Nkbins"; |
443 |
> |
calfn = kfullfn; kfullfn = NULL; |
444 |
> |
binf = "kbin"; |
445 |
> |
nbins = "Nkbins"; |
446 |
|
} else if (tolower(curparams.hemis[0]) == 'k' && |
447 |
|
(tolower(curparams.hemis[1]) == 'h') | |
448 |
|
(curparams.hemis[1] == '2')) { |
449 |
< |
if (khalffn != NULL) { |
450 |
< |
CHECKARGC(2); |
451 |
< |
rcarg[nrcargs++] = "-f"; |
454 |
< |
rcarg[nrcargs++] = khalffn; |
455 |
< |
khalffn = NULL; |
456 |
< |
} |
457 |
< |
CHECKARGC(4); |
458 |
< |
sprintf(binbuf, "khbin(%g,%g,%g,%g,%g,%g)", |
459 |
< |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
460 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
461 |
< |
rcarg[nrcargs++] = "-b"; |
462 |
< |
rcarg[nrcargs++] = savqstr(binbuf); |
463 |
< |
rcarg[nrcargs++] = "-bn"; |
464 |
< |
rcarg[nrcargs++] = "Nkhbins"; |
449 |
> |
calfn = khalffn; khalffn = NULL; |
450 |
> |
binf = "khbin"; |
451 |
> |
nbins = "Nkhbins"; |
452 |
|
} else if (tolower(curparams.hemis[0]) == 'k' && |
453 |
|
(tolower(curparams.hemis[1]) == 'q') | |
454 |
|
(curparams.hemis[1] == '4')) { |
455 |
< |
if (kquarterfn != NULL) { |
456 |
< |
CHECKARGC(2); |
457 |
< |
rcarg[nrcargs++] = "-f"; |
471 |
< |
rcarg[nrcargs++] = kquarterfn; |
472 |
< |
kquarterfn = NULL; |
473 |
< |
} |
474 |
< |
CHECKARGC(4); |
475 |
< |
sprintf(binbuf, "kqbin(%g,%g,%g,%g,%g,%g)", |
476 |
< |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
477 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
478 |
< |
rcarg[nrcargs++] = "-b"; |
479 |
< |
rcarg[nrcargs++] = savqstr(binbuf); |
480 |
< |
rcarg[nrcargs++] = "-bn"; |
481 |
< |
rcarg[nrcargs++] = "Nkqbins"; |
455 |
> |
calfn = kquarterfn; kquarterfn = NULL; |
456 |
> |
binf = "kqbin"; |
457 |
> |
nbins = "Nkqbins"; |
458 |
|
} else { |
459 |
|
fprintf(stderr, "%s: unrecognized hemisphere sampling: h=%s\n", |
460 |
|
progname, curparams.hemis); |
461 |
|
exit(1); |
462 |
|
} |
463 |
< |
CHECKARGC(2); /* modifier argument goes last */ |
463 |
> |
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
464 |
> |
SURF *sp; |
465 |
> |
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
466 |
> |
if (fabs(sp->area - PI) > 1e-3) { |
467 |
> |
fprintf(stderr, "%s: source '%s' must be 180-degrees\n", |
468 |
> |
progname, sp->sname); |
469 |
> |
exit(1); |
470 |
> |
} |
471 |
> |
} |
472 |
> |
if (calfn != NULL) { /* add cal file if needed */ |
473 |
> |
CHECKARGC(2); |
474 |
> |
rcarg[nrcargs++] = "-f"; |
475 |
> |
rcarg[nrcargs++] = calfn; |
476 |
> |
} |
477 |
> |
if (params != NULL) { /* parameters _after_ cal file */ |
478 |
> |
CHECKARGC(2); |
479 |
> |
rcarg[nrcargs++] = "-p"; |
480 |
> |
rcarg[nrcargs++] = params; |
481 |
> |
} |
482 |
> |
if (nbins != NULL) { /* add #bins if set */ |
483 |
> |
CHECKARGC(2); |
484 |
> |
rcarg[nrcargs++] = "-bn"; |
485 |
> |
rcarg[nrcargs++] = nbins; |
486 |
> |
} |
487 |
> |
if (binv != NULL) { |
488 |
> |
CHECKARGC(2); /* assign bin variable */ |
489 |
> |
rcarg[nrcargs++] = "-b"; |
490 |
> |
rcarg[nrcargs++] = binv; |
491 |
> |
} else if (binf != NULL) { |
492 |
> |
CHECKARGC(2); /* assign bin function */ |
493 |
> |
rcarg[nrcargs++] = "-b"; |
494 |
> |
sprintf(sbuf, "%s(%g,%g,%g,%g,%g,%g)", binf, |
495 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
496 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
497 |
> |
rcarg[nrcargs++] = savqstr(sbuf); |
498 |
> |
} |
499 |
> |
CHECKARGC(2); /* modifier argument goes last */ |
500 |
|
rcarg[nrcargs++] = "-m"; |
501 |
|
rcarg[nrcargs++] = savqstr(curmod); |
502 |
|
} |
991 |
|
VCOPY(snew->snrm, snew->farg); |
992 |
|
if (normalize(snew->snrm) == 0) |
993 |
|
goto badnorm; |
994 |
< |
snew->area = 2.*PI*(1. - cos((PI/180./2.)*snew->farg[3])); |
994 |
> |
snew->area = sin((PI/180./2.)*snew->farg[3]); |
995 |
> |
snew->area *= PI*snew->area; |
996 |
|
break; |
997 |
|
} |
998 |
|
if (snew->area <= FTINY) { |
1152 |
|
main(int argc, char *argv[]) |
1153 |
|
{ |
1154 |
|
char fmtopt[6] = "-faa"; /* default output is ASCII */ |
1155 |
+ |
char *xrs=NULL, *yrs=NULL, *ldopt=NULL; |
1156 |
|
char *sendfn; |
1157 |
|
char sampcntbuf[32], nsbinbuf[32]; |
1158 |
|
FILE *rcfp; |
1186 |
|
goto userr; |
1187 |
|
} |
1188 |
|
break; |
1189 |
+ |
case 'x': /* x-resolution */ |
1190 |
+ |
xrs = argv[++a]; |
1191 |
+ |
na = 0; |
1192 |
+ |
continue; |
1193 |
+ |
case 'y': /* y-resolution */ |
1194 |
+ |
yrs = argv[++a]; |
1195 |
+ |
na = 0; |
1196 |
+ |
continue; |
1197 |
|
case 'c': /* number of samples */ |
1198 |
|
sampcnt = atoi(argv[a+1]); |
1199 |
|
if (sampcnt <= 0) |
1205 |
|
case 'u': |
1206 |
|
case 'i': |
1207 |
|
case 'h': |
1208 |
+ |
case 'r': |
1209 |
|
break; |
1210 |
|
case 'n': /* options with 1 argument */ |
1211 |
|
case 's': |
1216 |
|
if (argv[a][2] != 'v') goto userr; |
1217 |
|
break; |
1218 |
|
case 'l': /* special case */ |
1219 |
< |
if (argv[a][2] == 'd') goto userr; |
1219 |
> |
if (argv[a][2] == 'd') { |
1220 |
> |
ldopt = argv[a]; |
1221 |
> |
na = 0; |
1222 |
> |
continue; |
1223 |
> |
} |
1224 |
|
na = 2; |
1225 |
|
break; |
1226 |
|
case 'd': /* special case */ |
1251 |
|
if (sendfn[0] == '-') { /* user wants pass-through mode? */ |
1252 |
|
if (sendfn[1]) goto userr; |
1253 |
|
sendfn = NULL; |
1254 |
+ |
if (xrs) { |
1255 |
+ |
CHECKARGC(2); |
1256 |
+ |
rcarg[nrcargs++] = "-x"; |
1257 |
+ |
rcarg[nrcargs++] = xrs; |
1258 |
+ |
} |
1259 |
+ |
if (yrs) { |
1260 |
+ |
CHECKARGC(2); |
1261 |
+ |
rcarg[nrcargs++] = "-y"; |
1262 |
+ |
rcarg[nrcargs++] = yrs; |
1263 |
+ |
} |
1264 |
+ |
if (ldopt) { |
1265 |
+ |
CHECKARGC(1); |
1266 |
+ |
rcarg[nrcargs++] = ldopt; |
1267 |
+ |
} |
1268 |
|
if (sampcnt <= 0) sampcnt = 1; |
1269 |
|
} else { /* else FVECT determines input format */ |
1270 |
|
fmtopt[3] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |