11 |
|
#include <stdlib.h> |
12 |
|
#include "rtio.h" |
13 |
|
#include "rtmath.h" |
14 |
+ |
#include "paths.h" |
15 |
|
#include "bsdf.h" |
16 |
|
#include "bsdf_m.h" |
17 |
|
#include "random.h" |
23 |
|
#define getc getc_unlocked |
24 |
|
#endif |
25 |
|
|
25 |
– |
#ifdef _WIN32 |
26 |
– |
#define SPECIALS " \t\"$*?" |
27 |
– |
#define QUOTCHAR '"' |
28 |
– |
#else |
29 |
– |
#define SPECIALS " \t\n'\"()${}*?[];|&" |
30 |
– |
#define QUOTCHAR '\'' |
31 |
– |
#define ALTQUOT '"' |
32 |
– |
#endif |
33 |
– |
|
26 |
|
#define MAXRCARG 512 |
27 |
|
|
28 |
|
char *progname; /* global argv[0] */ |
29 |
|
|
30 |
< |
int verbose = 0; /* verbose mode? */ |
30 |
> |
int verbose = 0; /* verbose mode (< 0 no warnings) */ |
31 |
|
|
32 |
|
char *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"}; |
33 |
|
int nrcargs = 2; |
75 |
|
} POLYTRIS; /* triangulated polygon */ |
76 |
|
|
77 |
|
typedef struct param_s { |
78 |
< |
char hemis[32]; /* hemispherical sampling spec. */ |
78 |
> |
char sign; /* '-' for axis reversal */ |
79 |
> |
char hemis[31]; /* hemispherical sampling spec. */ |
80 |
|
int hsiz; /* hemisphere basis size */ |
81 |
|
int nsurfs; /* number of surfaces */ |
82 |
|
SURF *slist; /* list of surfaces */ |
83 |
|
FVECT vup; /* up vector (zero if unset) */ |
84 |
|
FVECT nrm; /* average normal direction */ |
85 |
< |
FVECT udir, vdir; /* v-up tangent axes */ |
85 |
> |
FVECT udir, vdir; /* tangent axes */ |
86 |
|
char *outfn; /* output file name (receiver) */ |
87 |
|
int (*sample_basis)(struct param_s *p, int, FILE *); |
88 |
|
} PARAMS; /* sender/receiver parameters */ |
137 |
|
static char * |
138 |
|
oconv_command(int ac, char *av[]) |
139 |
|
{ |
140 |
< |
static char oconvbuf[2048] = "!oconv -f"; |
141 |
< |
char *cp = oconvbuf + 9; |
142 |
< |
|
140 |
> |
static char oconvbuf[2048] = "!oconv -f "; |
141 |
> |
char *cp = oconvbuf + 10; |
142 |
> |
char *recv = *av++; |
143 |
> |
|
144 |
> |
if (ac-- <= 0) |
145 |
> |
return(NULL); |
146 |
|
while (ac-- > 0) { |
151 |
– |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) { |
152 |
– |
fputs(progname, stderr); |
153 |
– |
fputs(": too many file arguments!\n", stderr); |
154 |
– |
exit(1); |
155 |
– |
} |
156 |
– |
*cp++ = ' '; |
147 |
|
strcpy(cp, *av++); |
148 |
|
while (*cp) cp++; |
149 |
+ |
*cp++ = ' '; |
150 |
+ |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) |
151 |
+ |
goto overrun; |
152 |
|
} |
153 |
< |
*cp = '\0'; |
153 |
> |
/* receiver goes last */ |
154 |
> |
if (matchany(recv, SPECIALS)) { |
155 |
> |
*cp++ = QUOTCHAR; |
156 |
> |
while (*recv) { |
157 |
> |
if (cp >= oconvbuf+(sizeof(oconvbuf)-3)) |
158 |
> |
goto overrun; |
159 |
> |
*cp++ = *recv++; |
160 |
> |
} |
161 |
> |
*cp++ = QUOTCHAR; |
162 |
> |
*cp = '\0'; |
163 |
> |
} else |
164 |
> |
strcpy(cp, recv); |
165 |
|
return(oconvbuf); |
166 |
+ |
overrun: |
167 |
+ |
fputs(progname, stderr); |
168 |
+ |
fputs(": too many file arguments!\n", stderr); |
169 |
+ |
exit(1); |
170 |
|
} |
171 |
|
|
164 |
– |
/* Check if any of the characters in str2 are found in str1 */ |
165 |
– |
static int |
166 |
– |
matchany(const char *str1, const char *str2) |
167 |
– |
{ |
168 |
– |
while (*str1) { |
169 |
– |
const char *cp = str2; |
170 |
– |
while (*cp) |
171 |
– |
if (*cp++ == *str1) |
172 |
– |
return(*str1); |
173 |
– |
++str1; |
174 |
– |
} |
175 |
– |
return(0); |
176 |
– |
} |
177 |
– |
|
178 |
– |
|
179 |
– |
/* Convert a set of arguments into a command line for pipe() or system() */ |
180 |
– |
static char * |
181 |
– |
convert_commandline(char *cmd, const int len, char *av[]) |
182 |
– |
{ |
183 |
– |
int match; |
184 |
– |
char *cp; |
185 |
– |
|
186 |
– |
for (cp = cmd; *av != NULL; av++) { |
187 |
– |
const int n = strlen(*av); |
188 |
– |
if (cp+n >= cmd+(len-3)) { |
189 |
– |
fputs(progname, stderr); |
190 |
– |
return(NULL); |
191 |
– |
} |
192 |
– |
if ((match = matchany(*av, SPECIALS))) { |
193 |
– |
const int quote = |
194 |
– |
#ifdef ALTQUOT |
195 |
– |
(match == QUOTCHAR) ? ALTQUOT : |
196 |
– |
#endif |
197 |
– |
QUOTCHAR; |
198 |
– |
*cp++ = quote; |
199 |
– |
strcpy(cp, *av); |
200 |
– |
cp += n; |
201 |
– |
*cp++ = quote; |
202 |
– |
} else { |
203 |
– |
strcpy(cp, *av); |
204 |
– |
cp += n; |
205 |
– |
} |
206 |
– |
*cp++ = ' '; |
207 |
– |
} |
208 |
– |
if (cp <= cmd) |
209 |
– |
return(NULL); |
210 |
– |
*--cp = '\0'; |
211 |
– |
return(cmd); |
212 |
– |
} |
213 |
– |
|
172 |
|
/* Open a pipe to/from a command given as an argument list */ |
173 |
|
static FILE * |
174 |
|
popen_arglist(char *av[], char *mode) |
180 |
|
fputs(": command line too long in popen_arglist()\n", stderr); |
181 |
|
return(NULL); |
182 |
|
} |
183 |
< |
if (verbose) |
183 |
> |
if (verbose > 0) |
184 |
|
fprintf(stderr, "%s: opening pipe %s: %s\n", |
185 |
|
progname, (*mode=='w') ? "to" : "from", cmd); |
186 |
|
return(popen(cmd, mode)); |
198 |
|
fputs(": command line too long in my_exec()\n", stderr); |
199 |
|
return(1); |
200 |
|
} |
201 |
< |
if (verbose) |
201 |
> |
if (verbose > 0) |
202 |
|
fprintf(stderr, "%s: running: %s\n", progname, cmd); |
203 |
|
return(system(cmd)); |
204 |
|
} |
213 |
|
fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]); |
214 |
|
return(1); |
215 |
|
} |
216 |
< |
if (verbose) { |
216 |
> |
if (verbose > 0) { |
217 |
|
char cmd[4096]; |
218 |
|
if (!convert_commandline(cmd, sizeof(cmd), av)) |
219 |
|
strcpy(cmd, "COMMAND TOO LONG TO SHOW"); |
271 |
|
{ |
272 |
|
char *cp = pargs; |
273 |
|
int nparams = 0; |
274 |
+ |
int quot; |
275 |
|
int i; |
276 |
|
|
277 |
< |
for ( ; ; ) |
277 |
> |
for ( ; ; ) { |
278 |
|
switch (*cp++) { |
279 |
|
case 'h': |
280 |
|
if (*cp++ != '=') |
281 |
|
break; |
282 |
+ |
if ((*cp == '+') | (*cp == '-')) |
283 |
+ |
p->sign = *cp++; |
284 |
+ |
else |
285 |
+ |
p->sign = '+'; |
286 |
|
p->hsiz = 0; |
287 |
|
i = 0; |
288 |
|
while (*cp && !isspace(*cp)) { |
301 |
|
break; |
302 |
|
if (!get_direction(p->vup, cp)) |
303 |
|
break; |
304 |
+ |
while (*cp && !isspace(*cp++)) |
305 |
+ |
; |
306 |
|
++nparams; |
307 |
|
continue; |
308 |
|
case 'o': |
309 |
|
if (*cp++ != '=') |
310 |
|
break; |
311 |
+ |
quot = 0; |
312 |
+ |
if ((*cp == '"') | (*cp == '\'')) |
313 |
+ |
quot = *cp++; |
314 |
|
i = 0; |
315 |
< |
while (*cp && !isspace(*cp++)) |
316 |
< |
i++; |
315 |
> |
while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) { |
316 |
> |
i++; cp++; |
317 |
> |
} |
318 |
|
if (!i) |
319 |
|
break; |
320 |
< |
*--cp = '\0'; |
320 |
> |
if (!*cp) { |
321 |
> |
if (quot) |
322 |
> |
break; |
323 |
> |
cp[1] = '\0'; |
324 |
> |
} |
325 |
> |
*cp = '\0'; |
326 |
|
p->outfn = savqstr(cp-i); |
327 |
< |
*cp++ = ' '; |
327 |
> |
*cp++ = quot ? quot : ' '; |
328 |
|
++nparams; |
329 |
|
continue; |
330 |
|
case ' ': |
337 |
|
default: |
338 |
|
break; |
339 |
|
} |
340 |
< |
fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs); |
340 |
> |
break; |
341 |
> |
} |
342 |
> |
fprintf(stderr, "%s: bad parameter string: %s", progname, pargs); |
343 |
|
exit(1); |
344 |
|
return(-1); /* pro forma return */ |
345 |
|
} |
377 |
|
fputs(": undefined normal for hemisphere sampling\n", stderr); |
378 |
|
exit(1); |
379 |
|
} |
380 |
< |
if (normalize(curparams.vup) == 0) |
380 |
> |
if (normalize(curparams.vup) == 0) { |
381 |
|
if (fabs(curparams.nrm[2]) < .7) |
382 |
|
curparams.vup[2] = 1; |
383 |
|
else |
384 |
|
curparams.vup[1] = 1; |
385 |
+ |
} |
386 |
|
/* determine sample type/bin */ |
387 |
|
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
388 |
< |
binv = "0"; /* uniform sampling -- one bin */ |
388 |
> |
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
389 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
390 |
> |
binv = savqstr(sbuf); |
391 |
> |
nbins = "1"; /* uniform sampling -- one bin */ |
392 |
|
uniform = 1; |
393 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
394 |
|
tolower(curparams.hemis[1]) == 'c') { |
399 |
|
exit(1); |
400 |
|
} |
401 |
|
calfn = shirchiufn; shirchiufn = NULL; |
402 |
< |
sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
402 |
> |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
403 |
|
curparams.hsiz, |
404 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
405 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
405 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
406 |
> |
curparams.sign); |
407 |
|
params = savqstr(sbuf); |
408 |
|
binv = "scbin"; |
409 |
|
nbins = "SCdim*SCdim"; |
410 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
411 |
|
(tolower(curparams.hemis[0]) == 't')) { |
412 |
|
calfn = reinhfn; reinhfn = NULL; |
413 |
< |
sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
413 |
> |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
414 |
|
curparams.hsiz, |
415 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
416 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
416 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
417 |
> |
curparams.sign); |
418 |
|
params = savqstr(sbuf); |
419 |
|
binv = "rbin"; |
420 |
|
nbins = "Nrbins"; |
442 |
|
progname, curparams.hemis); |
443 |
|
exit(1); |
444 |
|
} |
445 |
+ |
if (tolower(curparams.hemis[0]) == 'k') { |
446 |
+ |
sprintf(sbuf, "RHS=%c1", curparams.sign); |
447 |
+ |
params = savqstr(sbuf); |
448 |
+ |
} |
449 |
|
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
450 |
|
SURF *sp; |
451 |
|
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
493 |
|
{ |
494 |
|
int i; |
495 |
|
|
496 |
< |
uva[1][0] = 0.5 - frandom(); |
511 |
< |
uva[1][1] = 0.5 - frandom(); |
512 |
< |
uva[1][2] = 0.5 - frandom(); |
513 |
< |
for (i = 3; i--; ) |
514 |
< |
if ((-0.6 < nrm[i]) & (nrm[i] < 0.6)) |
515 |
< |
break; |
516 |
< |
if (i < 0) { |
496 |
> |
if (!getperpendicular(uva[0], nrm, 1)) { |
497 |
|
fputs(progname, stderr); |
498 |
|
fputs(": bad surface normal in make_axes!\n", stderr); |
499 |
|
exit(1); |
500 |
|
} |
501 |
< |
uva[1][i] = 1.0; |
522 |
< |
VCROSS(uva[0], uva[1], nrm); |
523 |
< |
normalize(uva[0]); |
524 |
< |
VCROSS(uva[1], nrm, uva[0]); |
501 |
> |
fcross(uva[1], nrm, uva[0]); |
502 |
|
} |
503 |
|
|
504 |
|
/* Illegal sender surfaces end up here */ |
637 |
|
/* special case for lone surface */ |
638 |
|
if (p->nsurfs == 1) { |
639 |
|
sp = p->slist; |
640 |
< |
if (DOT(sp->snrm, rdir) >= -FTINY) { |
640 |
> |
if (DOT(sp->snrm, rdir) >= FTINY) { |
641 |
|
fprintf(stderr, |
642 |
|
"%s: internal - sample behind sender '%s'\n", |
643 |
|
progname, sp->sname); |
760 |
|
alt = (row+samp3[1])*RAH; |
761 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
762 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
763 |
< |
duvw[0] = tcos(azi)*duvw[2]; |
764 |
< |
duvw[1] = tsin(azi)*duvw[2]; |
763 |
> |
duvw[0] = tsin(azi)*duvw[2]; |
764 |
> |
duvw[1] = tcos(azi)*duvw[2]; |
765 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
766 |
|
for (i = 3; i--; ) |
767 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
812 |
|
|
813 |
|
while (n--) { /* stratified sampling */ |
814 |
|
SDmultiSamp(samp2, 2, (n+frandom())/sampcnt); |
815 |
< |
if (!bo_getvec(duvw, b+samp2[1], kbasis[bi])) |
815 |
> |
if (!fo_getvec(duvw, b+samp2[1], kbasis[bi])) |
816 |
|
return(0); |
817 |
|
for (i = 3; i--; ) |
818 |
< |
orig_dir[1][i] = duvw[0]*p->udir[i] + |
819 |
< |
duvw[1]*p->vdir[i] + |
818 |
> |
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
819 |
> |
duvw[1]*p->vdir[i] - |
820 |
|
duvw[2]*p->nrm[i] ; |
821 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
822 |
|
return(0); |
835 |
|
fputs(": no sender surface!\n", stderr); |
836 |
|
return(-1); |
837 |
|
} |
838 |
< |
if (curparams.outfn != NULL) /* misplaced output file spec. */ |
838 |
> |
/* misplaced output file spec. */ |
839 |
> |
if ((curparams.outfn != NULL) & (verbose >= 0)) |
840 |
|
fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n", |
841 |
|
progname, curparams.outfn); |
842 |
|
/* check/set basis hemisphere */ |
850 |
|
fputs(": undefined normal for sender sampling\n", stderr); |
851 |
|
return(-1); |
852 |
|
} |
853 |
< |
if (normalize(curparams.vup) == 0) |
853 |
> |
if (normalize(curparams.vup) == 0) { |
854 |
|
if (fabs(curparams.nrm[2]) < .7) |
855 |
|
curparams.vup[2] = 1; |
856 |
|
else |
857 |
|
curparams.vup[1] = 1; |
858 |
< |
VCROSS(curparams.udir, curparams.vup, curparams.nrm); |
858 |
> |
} |
859 |
> |
fcross(curparams.udir, curparams.vup, curparams.nrm); |
860 |
|
if (normalize(curparams.udir) == 0) { |
861 |
|
fputs(progname, stderr); |
862 |
|
fputs(": up vector coincides with sender normal\n", stderr); |
863 |
|
return(-1); |
864 |
|
} |
865 |
< |
VCROSS(curparams.vdir, curparams.nrm, curparams.udir); |
865 |
> |
fcross(curparams.vdir, curparams.nrm, curparams.udir); |
866 |
> |
if (curparams.sign == '-') { /* left-handed coordinate system? */ |
867 |
> |
curparams.udir[0] *= -1.; |
868 |
> |
curparams.udir[1] *= -1.; |
869 |
> |
curparams.udir[2] *= -1.; |
870 |
> |
} |
871 |
|
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
872 |
|
curparams.sample_basis = sample_uniform; |
873 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
984 |
|
case ST_SOURCE: |
985 |
|
if (snew->nfargs != 4) |
986 |
|
goto badcount; |
987 |
< |
VCOPY(snew->snrm, snew->farg); |
987 |
> |
for (n = 3; n--; ) /* need to reverse "normal" */ |
988 |
> |
snew->snrm[n] = -snew->farg[n]; |
989 |
|
if (normalize(snew->snrm) == 0) |
990 |
|
goto badnorm; |
991 |
|
snew->area = sin((PI/180./2.)*snew->farg[3]); |
992 |
|
snew->area *= PI*snew->area; |
993 |
|
break; |
994 |
|
} |
995 |
< |
if (snew->area <= FTINY) { |
995 |
> |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
996 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
997 |
|
progname, oname); |
998 |
|
free(snew); |
1048 |
|
return(1); |
1049 |
|
} |
1050 |
|
/* else skip arguments */ |
1051 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1051 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1052 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
1053 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1053 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1054 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
1055 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1055 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1056 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
1057 |
|
return(0); |
1058 |
|
} |
1062 |
|
add_send_object(FILE *fp) |
1063 |
|
{ |
1064 |
|
int st; |
1065 |
< |
char otype[32], oname[128]; |
1065 |
> |
char thismod[128], otype[32], oname[128]; |
1066 |
|
int n; |
1067 |
|
|
1068 |
< |
if (fscanf(fp, "%*s %s %s", otype, oname) != 2) |
1068 |
> |
if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3) |
1069 |
|
return(0); /* must have hit EOF! */ |
1070 |
|
if (!strcmp(otype, "alias")) { |
1071 |
|
fscanf(fp, "%*s"); /* skip alias */ |
1078 |
|
fputs(": cannot use source as a sender!\n", stderr); |
1079 |
|
return(-1); |
1080 |
|
} |
1081 |
+ |
if (strcmp(thismod, curmod)) { |
1082 |
+ |
if (curmod[0]) { |
1083 |
+ |
fputs(progname, stderr); |
1084 |
+ |
fputs(": warning - multiple modifiers in sender\n", |
1085 |
+ |
stderr); |
1086 |
+ |
} |
1087 |
+ |
strcpy(curmod, thismod); |
1088 |
+ |
} |
1089 |
|
parse_params(&curparams, newparams); |
1090 |
|
newparams[0] = '\0'; |
1091 |
|
add_surface(st, oname, fp); /* read & store surface */ |
1092 |
|
return(0); |
1093 |
|
} |
1094 |
|
/* else skip arguments */ |
1095 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1095 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1096 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
1097 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1097 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1098 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
1099 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1099 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1100 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
1101 |
|
return(0); |
1102 |
|
} |
1139 |
|
strcat(newparams, inpbuf); |
1140 |
|
continue; |
1141 |
|
} |
1142 |
< |
while ((c = getc(fp)) != EOF && c != '\n'); |
1142 |
> |
while ((c = getc(fp)) != EOF && c != '\n') |
1143 |
|
; /* else skipping comment */ |
1144 |
|
continue; |
1145 |
|
} |
1164 |
|
{ |
1165 |
|
char fmtopt[6] = "-faa"; /* default output is ASCII */ |
1166 |
|
char *xrs=NULL, *yrs=NULL, *ldopt=NULL; |
1167 |
+ |
char *iropt = NULL; |
1168 |
|
char *sendfn; |
1169 |
|
char sampcntbuf[32], nsbinbuf[32]; |
1170 |
|
FILE *rcfp; |
1172 |
|
int a, i; |
1173 |
|
/* screen rcontrib options */ |
1174 |
|
progname = argv[0]; |
1175 |
< |
for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) { |
1176 |
< |
int na = 1; /* !! Keep consistent !! */ |
1177 |
< |
switch (argv[a][1]) { |
1175 |
> |
for (a = 1; a < argc-2; a++) { |
1176 |
> |
int na; |
1177 |
> |
/* check for argument expansion */ |
1178 |
> |
while ((na = expandarg(&argc, &argv, a)) > 0) |
1179 |
> |
; |
1180 |
> |
if (na < 0) { |
1181 |
> |
fprintf(stderr, "%s: cannot expand '%s'\n", |
1182 |
> |
progname, argv[a]); |
1183 |
> |
return(1); |
1184 |
> |
} |
1185 |
> |
if (argv[a][0] != '-' || !argv[a][1]) |
1186 |
> |
break; |
1187 |
> |
na = 1; |
1188 |
> |
switch (argv[a][1]) { /* !! Keep consistent !! */ |
1189 |
|
case 'v': /* verbose mode */ |
1190 |
< |
verbose = !verbose; |
1190 |
> |
verbose = 1; |
1191 |
|
na = 0; |
1192 |
|
continue; |
1193 |
|
case 'f': /* special case for -fo, -ff, etc. */ |
1223 |
|
goto userr; |
1224 |
|
na = 0; /* we re-add this later */ |
1225 |
|
continue; |
1226 |
< |
case 'V': /* options without arguments */ |
1222 |
< |
case 'w': |
1223 |
< |
case 'u': |
1226 |
> |
case 'I': /* only for pass-through mode */ |
1227 |
|
case 'i': |
1228 |
+ |
iropt = argv[a]; |
1229 |
+ |
na = 0; |
1230 |
+ |
continue; |
1231 |
+ |
case 'w': /* options without arguments */ |
1232 |
+ |
if (argv[a][2] != '+') verbose = -1; |
1233 |
+ |
case 'V': |
1234 |
+ |
case 'u': |
1235 |
|
case 'h': |
1236 |
|
case 'r': |
1237 |
|
break; |
1255 |
|
if (argv[a][2] != 'v') na = 2; |
1256 |
|
break; |
1257 |
|
case 'a': /* special case */ |
1258 |
< |
na = (argv[a][2] == 'v') ? 4 : 2; |
1258 |
> |
if (argv[a][2] == 'p') { |
1259 |
> |
na = 2; /* photon map [+ bandwidth(s)] */ |
1260 |
> |
if (a < argc-3 && atoi(argv[a+1]) > 0) |
1261 |
> |
na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0); |
1262 |
> |
} else |
1263 |
> |
na = (argv[a][2] == 'v') ? 4 : 2; |
1264 |
|
break; |
1265 |
|
case 'm': /* special case */ |
1266 |
|
if (!argv[a][2]) goto userr; |
1267 |
|
na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2; |
1268 |
|
break; |
1254 |
– |
case '\0': /* pass-through mode */ |
1255 |
– |
goto done_opts; |
1269 |
|
default: /* anything else is verbotten */ |
1270 |
|
goto userr; |
1271 |
|
} |
1275 |
|
while (--na) /* + arguments if any */ |
1276 |
|
rcarg[nrcargs++] = argv[++a]; |
1277 |
|
} |
1265 |
– |
done_opts: |
1278 |
|
if (a > argc-2) |
1279 |
|
goto userr; /* check at end of options */ |
1280 |
|
sendfn = argv[a++]; /* assign sender & receiver inputs */ |
1281 |
|
if (sendfn[0] == '-') { /* user wants pass-through mode? */ |
1282 |
|
if (sendfn[1]) goto userr; |
1283 |
|
sendfn = NULL; |
1284 |
+ |
if (iropt) { |
1285 |
+ |
CHECKARGC(1); |
1286 |
+ |
rcarg[nrcargs++] = iropt; |
1287 |
+ |
} |
1288 |
|
if (xrs) { |
1289 |
|
CHECKARGC(2); |
1290 |
|
rcarg[nrcargs++] = "-x"; |
1300 |
|
rcarg[nrcargs++] = ldopt; |
1301 |
|
} |
1302 |
|
if (sampcnt <= 0) sampcnt = 1; |
1303 |
< |
} else { /* else FVECT determines input format */ |
1303 |
> |
} else { /* else in sampling mode */ |
1304 |
> |
if (iropt) { |
1305 |
> |
fputs(progname, stderr); |
1306 |
> |
fputs(": -i, -I supported for pass-through only\n", stderr); |
1307 |
> |
return(1); |
1308 |
> |
} |
1309 |
|
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1310 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1311 |
|
} |
1325 |
|
return(my_exec(rcarg)); /* rcontrib does everything */ |
1326 |
|
} |
1327 |
|
clear_params(&curparams, 0); /* else load sender surface & params */ |
1328 |
+ |
curmod[0] = '\0'; |
1329 |
|
if (load_scene(sendfn, add_send_object) < 0) |
1330 |
|
return(1); |
1331 |
|
if ((nsbins = prepare_sampler()) <= 0) |
1343 |
|
#ifdef getc_unlocked |
1344 |
|
flockfile(rcfp); |
1345 |
|
#endif |
1346 |
< |
if (verbose) { |
1346 |
> |
if (verbose > 0) { |
1347 |
|
fprintf(stderr, "%s: sampling %d directions", progname, nsbins); |
1348 |
|
if (curparams.nsurfs > 1) |
1349 |
|
fprintf(stderr, " (%d elements)\n", curparams.nsurfs); |
1353 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
1354 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
1355 |
|
return(1); |
1356 |
< |
return(pclose(rcfp) == 0); /* all finished! */ |
1356 |
> |
return(pclose(rcfp) < 0); /* all finished! */ |
1357 |
|
userr: |
1358 |
|
if (a < argc-2) |
1359 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |
1360 |
< |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n", |
1360 |
> |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n", |
1361 |
|
progname); |
1362 |
|
return(1); |
1363 |
|
} |