| 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; |
| 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 |
|
} |
| 156 |
– |
*cp++ = ' '; |
| 157 |
– |
strcpy(cp, *av++); |
| 158 |
– |
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"); |
| 319 |
|
int nparams = 0; |
| 320 |
|
int i; |
| 321 |
|
|
| 322 |
< |
for ( ; ; ) |
| 322 |
> |
for ( ; ; ) { |
| 323 |
|
switch (*cp++) { |
| 324 |
|
case 'h': |
| 325 |
|
if (*cp++ != '=') |
| 342 |
|
break; |
| 343 |
|
if (!get_direction(p->vup, cp)) |
| 344 |
|
break; |
| 345 |
+ |
while (*cp && !isspace(*cp++)) |
| 346 |
+ |
; |
| 347 |
|
++nparams; |
| 348 |
|
continue; |
| 349 |
|
case 'o': |
| 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 |
|
} |
| 516 |
|
{ |
| 517 |
|
int i; |
| 518 |
|
|
| 519 |
< |
uva[1][0] = 0.5 - frandom(); |
| 512 |
< |
uva[1][1] = 0.5 - frandom(); |
| 513 |
< |
uva[1][2] = 0.5 - frandom(); |
| 514 |
< |
for (i = 3; i--; ) |
| 515 |
< |
if ((-0.6 < nrm[i]) & (nrm[i] < 0.6)) |
| 516 |
< |
break; |
| 517 |
< |
if (i < 0) { |
| 519 |
> |
if (!getperpendicular(uva[0], nrm)) { |
| 520 |
|
fputs(progname, stderr); |
| 521 |
|
fputs(": bad surface normal in make_axes!\n", stderr); |
| 522 |
|
exit(1); |
| 523 |
|
} |
| 524 |
< |
uva[1][i] = 1.0; |
| 523 |
< |
VCROSS(uva[0], uva[1], nrm); |
| 524 |
< |
normalize(uva[0]); |
| 525 |
< |
VCROSS(uva[1], nrm, uva[0]); |
| 524 |
> |
fcross(uva[1], nrm, uva[0]); |
| 525 |
|
} |
| 526 |
|
|
| 527 |
|
/* Illegal sender surfaces end up here */ |
| 783 |
|
alt = (row+samp3[1])*RAH; |
| 784 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
| 785 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
| 786 |
< |
duvw[0] = tcos(azi)*duvw[2]; |
| 787 |
< |
duvw[1] = tsin(azi)*duvw[2]; |
| 786 |
> |
duvw[0] = tsin(azi)*duvw[2]; |
| 787 |
> |
duvw[1] = tcos(azi)*duvw[2]; |
| 788 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
| 789 |
|
for (i = 3; i--; ) |
| 790 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
| 835 |
|
|
| 836 |
|
while (n--) { /* stratified sampling */ |
| 837 |
|
SDmultiSamp(samp2, 2, (n+frandom())/sampcnt); |
| 838 |
< |
if (!bo_getvec(duvw, b+samp2[1], kbasis[bi])) |
| 838 |
> |
if (!bi_getvec(duvw, b+samp2[1], kbasis[bi])) |
| 839 |
|
return(0); |
| 840 |
|
for (i = 3; i--; ) |
| 841 |
|
orig_dir[1][i] = duvw[0]*p->udir[i] + |
| 858 |
|
fputs(": no sender surface!\n", stderr); |
| 859 |
|
return(-1); |
| 860 |
|
} |
| 861 |
< |
if (curparams.outfn != NULL) /* misplaced output file spec. */ |
| 861 |
> |
/* misplaced output file spec. */ |
| 862 |
> |
if ((curparams.outfn != NULL) & (verbose >= 0)) |
| 863 |
|
fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n", |
| 864 |
|
progname, curparams.outfn); |
| 865 |
|
/* check/set basis hemisphere */ |
| 1010 |
|
snew->area *= PI*snew->area; |
| 1011 |
|
break; |
| 1012 |
|
} |
| 1013 |
< |
if (snew->area <= FTINY) { |
| 1013 |
> |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
| 1014 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
| 1015 |
|
progname, oname); |
| 1016 |
|
free(snew); |
| 1174 |
|
{ |
| 1175 |
|
char fmtopt[6] = "-faa"; /* default output is ASCII */ |
| 1176 |
|
char *xrs=NULL, *yrs=NULL, *ldopt=NULL; |
| 1177 |
< |
int wantIrradiance = 0; |
| 1177 |
> |
char *iropt = NULL; |
| 1178 |
|
char *sendfn; |
| 1179 |
|
char sampcntbuf[32], nsbinbuf[32]; |
| 1180 |
|
FILE *rcfp; |
| 1182 |
|
int a, i; |
| 1183 |
|
/* screen rcontrib options */ |
| 1184 |
|
progname = argv[0]; |
| 1185 |
< |
for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) { |
| 1186 |
< |
int na = 1; /* !! Keep consistent !! */ |
| 1187 |
< |
switch (argv[a][1]) { |
| 1185 |
> |
for (a = 1; a < argc-2; a++) { |
| 1186 |
> |
int na; |
| 1187 |
> |
/* check for argument expansion */ |
| 1188 |
> |
while ((na = expandarg(&argc, &argv, a)) > 0) |
| 1189 |
> |
; |
| 1190 |
> |
if (na < 0) { |
| 1191 |
> |
fprintf(stderr, "%s: cannot expand '%s'\n", |
| 1192 |
> |
progname, argv[a]); |
| 1193 |
> |
return(1); |
| 1194 |
> |
} |
| 1195 |
> |
if (argv[a][0] != '-' || !argv[a][1]) |
| 1196 |
> |
break; |
| 1197 |
> |
na = 1; |
| 1198 |
> |
switch (argv[a][1]) { /* !! Keep consistent !! */ |
| 1199 |
|
case 'v': /* verbose mode */ |
| 1200 |
< |
verbose = !verbose; |
| 1200 |
> |
verbose = 1; |
| 1201 |
|
na = 0; |
| 1202 |
|
continue; |
| 1203 |
|
case 'f': /* special case for -fo, -ff, etc. */ |
| 1234 |
|
na = 0; /* we re-add this later */ |
| 1235 |
|
continue; |
| 1236 |
|
case 'I': /* only for pass-through mode */ |
| 1237 |
< |
wantIrradiance = 1; |
| 1237 |
> |
case 'i': |
| 1238 |
> |
iropt = argv[a]; |
| 1239 |
|
na = 0; |
| 1240 |
|
continue; |
| 1241 |
< |
case 'V': /* options without arguments */ |
| 1242 |
< |
case 'w': |
| 1241 |
> |
case 'w': /* options without arguments */ |
| 1242 |
> |
if (argv[a][2] != '+') verbose = -1; |
| 1243 |
> |
case 'V': |
| 1244 |
|
case 'u': |
| 1232 |
– |
case 'i': |
| 1245 |
|
case 'h': |
| 1246 |
|
case 'r': |
| 1247 |
|
break; |
| 1271 |
|
if (!argv[a][2]) goto userr; |
| 1272 |
|
na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2; |
| 1273 |
|
break; |
| 1262 |
– |
case '\0': /* pass-through mode */ |
| 1263 |
– |
goto done_opts; |
| 1274 |
|
default: /* anything else is verbotten */ |
| 1275 |
|
goto userr; |
| 1276 |
|
} |
| 1280 |
|
while (--na) /* + arguments if any */ |
| 1281 |
|
rcarg[nrcargs++] = argv[++a]; |
| 1282 |
|
} |
| 1273 |
– |
done_opts: |
| 1283 |
|
if (a > argc-2) |
| 1284 |
|
goto userr; /* check at end of options */ |
| 1285 |
|
sendfn = argv[a++]; /* assign sender & receiver inputs */ |
| 1286 |
|
if (sendfn[0] == '-') { /* user wants pass-through mode? */ |
| 1287 |
|
if (sendfn[1]) goto userr; |
| 1288 |
|
sendfn = NULL; |
| 1289 |
< |
if (wantIrradiance) { |
| 1289 |
> |
if (iropt) { |
| 1290 |
|
CHECKARGC(1); |
| 1291 |
< |
rcarg[nrcargs++] = "-I"; |
| 1291 |
> |
rcarg[nrcargs++] = iropt; |
| 1292 |
|
} |
| 1293 |
|
if (xrs) { |
| 1294 |
|
CHECKARGC(2); |
| 1306 |
|
} |
| 1307 |
|
if (sampcnt <= 0) sampcnt = 1; |
| 1308 |
|
} else { /* else in sampling mode */ |
| 1309 |
< |
if (wantIrradiance) { |
| 1309 |
> |
if (iropt) { |
| 1310 |
|
fputs(progname, stderr); |
| 1311 |
< |
fputs(": -I supported for pass-through only\n", stderr); |
| 1311 |
> |
fputs(": -i, -I supported for pass-through only\n", stderr); |
| 1312 |
|
return(1); |
| 1313 |
|
} |
| 1314 |
|
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
| 1361 |
|
userr: |
| 1362 |
|
if (a < argc-2) |
| 1363 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |
| 1364 |
< |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n", |
| 1364 |
> |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n", |
| 1365 |
|
progname); |
| 1366 |
|
return(1); |
| 1367 |
|
} |