84 |
|
} POLYTRIS; /* triangulated polygon */ |
85 |
|
|
86 |
|
typedef struct param_s { |
87 |
< |
char hemis[32]; /* hemispherical sampling spec. */ |
87 |
> |
char sign; /* '-' for axis reversal */ |
88 |
> |
char hemis[31]; /* hemispherical sampling spec. */ |
89 |
|
int hsiz; /* hemisphere basis size */ |
90 |
|
int nsurfs; /* number of surfaces */ |
91 |
|
SURF *slist; /* list of surfaces */ |
92 |
|
FVECT vup; /* up vector (zero if unset) */ |
93 |
|
FVECT nrm; /* average normal direction */ |
94 |
< |
FVECT udir, vdir; /* v-up tangent axes */ |
94 |
> |
FVECT udir, vdir; /* tangent axes */ |
95 |
|
char *outfn; /* output file name (receiver) */ |
96 |
|
int (*sample_basis)(struct param_s *p, int, FILE *); |
97 |
|
} PARAMS; /* sender/receiver parameters */ |
142 |
|
return(ST_NONE); |
143 |
|
} |
144 |
|
|
145 |
+ |
/* Check if any of the characters in str2 are found in str1 */ |
146 |
+ |
static int |
147 |
+ |
matchany(const char *str1, const char *str2) |
148 |
+ |
{ |
149 |
+ |
while (*str1) { |
150 |
+ |
const char *cp = str2; |
151 |
+ |
while (*cp) |
152 |
+ |
if (*cp++ == *str1) |
153 |
+ |
return(*str1); |
154 |
+ |
++str1; |
155 |
+ |
} |
156 |
+ |
return(0); |
157 |
+ |
} |
158 |
+ |
|
159 |
|
/* Add arguments to oconv command */ |
160 |
|
static char * |
161 |
|
oconv_command(int ac, char *av[]) |
170 |
|
strcpy(cp, *av++); |
171 |
|
while (*cp) cp++; |
172 |
|
*cp++ = ' '; |
173 |
< |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) { |
174 |
< |
fputs(progname, stderr); |
160 |
< |
fputs(": too many file arguments!\n", stderr); |
161 |
< |
exit(1); |
162 |
< |
} |
173 |
> |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) |
174 |
> |
goto overrun; |
175 |
|
} |
176 |
< |
strcpy(cp, recv); /* receiver goes last */ |
176 |
> |
/* receiver goes last */ |
177 |
> |
if (matchany(recv, SPECIALS)) { |
178 |
> |
*cp++ = QUOTCHAR; |
179 |
> |
while (*recv) { |
180 |
> |
if (cp >= oconvbuf+(sizeof(oconvbuf)-3)) |
181 |
> |
goto overrun; |
182 |
> |
*cp++ = *recv++; |
183 |
> |
} |
184 |
> |
*cp++ = QUOTCHAR; |
185 |
> |
*cp = '\0'; |
186 |
> |
} else |
187 |
> |
strcpy(cp, recv); |
188 |
|
return(oconvbuf); |
189 |
+ |
overrun: |
190 |
+ |
fputs(progname, stderr); |
191 |
+ |
fputs(": too many file arguments!\n", stderr); |
192 |
+ |
exit(1); |
193 |
|
} |
194 |
|
|
168 |
– |
/* Check if any of the characters in str2 are found in str1 */ |
169 |
– |
static int |
170 |
– |
matchany(const char *str1, const char *str2) |
171 |
– |
{ |
172 |
– |
while (*str1) { |
173 |
– |
const char *cp = str2; |
174 |
– |
while (*cp) |
175 |
– |
if (*cp++ == *str1) |
176 |
– |
return(*str1); |
177 |
– |
++str1; |
178 |
– |
} |
179 |
– |
return(0); |
180 |
– |
} |
181 |
– |
|
182 |
– |
|
195 |
|
/* Convert a set of arguments into a command line for pipe() or system() */ |
196 |
|
static char * |
197 |
|
convert_commandline(char *cmd, const int len, char *av[]) |
205 |
|
fputs(progname, stderr); |
206 |
|
return(NULL); |
207 |
|
} |
208 |
< |
if ((match = matchany(*av, SPECIALS))) { |
208 |
> |
if (matchany(*av, SPECIALS)) { |
209 |
|
const int quote = |
210 |
|
#ifdef ALTQUOT |
211 |
< |
(match == QUOTCHAR) ? ALTQUOT : |
211 |
> |
strchr(*av, QUOTCHAR) ? ALTQUOT : |
212 |
|
#endif |
213 |
|
QUOTCHAR; |
214 |
|
*cp++ = quote; |
336 |
|
case 'h': |
337 |
|
if (*cp++ != '=') |
338 |
|
break; |
339 |
+ |
if ((*cp == '+') | (*cp == '-')) |
340 |
+ |
p->sign = *cp++; |
341 |
+ |
else |
342 |
+ |
p->sign = '+'; |
343 |
|
p->hsiz = 0; |
344 |
|
i = 0; |
345 |
|
while (*cp && !isspace(*cp)) { |
378 |
|
case ' ': |
379 |
|
case '\t': |
380 |
|
case '\r': |
365 |
– |
continue; |
381 |
|
case '\n': |
382 |
+ |
continue; |
383 |
|
case '\0': |
384 |
|
return(nparams); |
385 |
|
default: |
433 |
|
} |
434 |
|
/* determine sample type/bin */ |
435 |
|
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
436 |
< |
binv = "0"; /* uniform sampling -- one bin */ |
436 |
> |
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
437 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
438 |
> |
binv = savqstr(sbuf); |
439 |
> |
nbins = "1"; /* uniform sampling -- one bin */ |
440 |
|
uniform = 1; |
441 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
442 |
|
tolower(curparams.hemis[1]) == 'c') { |
447 |
|
exit(1); |
448 |
|
} |
449 |
|
calfn = shirchiufn; shirchiufn = NULL; |
450 |
< |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", |
450 |
> |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
451 |
|
curparams.hsiz, |
452 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
453 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
453 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
454 |
> |
curparams.sign); |
455 |
|
params = savqstr(sbuf); |
456 |
|
binv = "scbin"; |
457 |
|
nbins = "SCdim*SCdim"; |
458 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
459 |
|
(tolower(curparams.hemis[0]) == 't')) { |
460 |
|
calfn = reinhfn; reinhfn = NULL; |
461 |
< |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", |
461 |
> |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
462 |
|
curparams.hsiz, |
463 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
464 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
464 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
465 |
> |
curparams.sign); |
466 |
|
params = savqstr(sbuf); |
467 |
|
binv = "rbin"; |
468 |
|
nbins = "Nrbins"; |
490 |
|
progname, curparams.hemis); |
491 |
|
exit(1); |
492 |
|
} |
493 |
+ |
if (tolower(curparams.hemis[0]) == 'k') { |
494 |
+ |
sprintf(sbuf, "RHS=%c1", curparams.sign); |
495 |
+ |
params = savqstr(sbuf); |
496 |
+ |
} |
497 |
|
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
498 |
|
SURF *sp; |
499 |
|
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
541 |
|
{ |
542 |
|
int i; |
543 |
|
|
544 |
< |
uva[1][0] = 0.5 - frandom(); |
520 |
< |
uva[1][1] = 0.5 - frandom(); |
521 |
< |
uva[1][2] = 0.5 - frandom(); |
522 |
< |
for (i = 3; i--; ) |
523 |
< |
if ((-0.6 < nrm[i]) & (nrm[i] < 0.6)) |
524 |
< |
break; |
525 |
< |
if (i < 0) { |
544 |
> |
if (!getperpendicular(uva[0], nrm, 1)) { |
545 |
|
fputs(progname, stderr); |
546 |
|
fputs(": bad surface normal in make_axes!\n", stderr); |
547 |
|
exit(1); |
548 |
|
} |
549 |
< |
uva[1][i] = 1.0; |
531 |
< |
VCROSS(uva[0], uva[1], nrm); |
532 |
< |
normalize(uva[0]); |
533 |
< |
VCROSS(uva[1], nrm, uva[0]); |
549 |
> |
fcross(uva[1], nrm, uva[0]); |
550 |
|
} |
551 |
|
|
552 |
|
/* Illegal sender surfaces end up here */ |
685 |
|
/* special case for lone surface */ |
686 |
|
if (p->nsurfs == 1) { |
687 |
|
sp = p->slist; |
688 |
< |
if (DOT(sp->snrm, rdir) >= -FTINY) { |
688 |
> |
if (DOT(sp->snrm, rdir) >= FTINY) { |
689 |
|
fprintf(stderr, |
690 |
|
"%s: internal - sample behind sender '%s'\n", |
691 |
|
progname, sp->sname); |
808 |
|
alt = (row+samp3[1])*RAH; |
809 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
810 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
811 |
< |
duvw[0] = tcos(azi)*duvw[2]; |
812 |
< |
duvw[1] = tsin(azi)*duvw[2]; |
811 |
> |
duvw[0] = tsin(azi)*duvw[2]; |
812 |
> |
duvw[1] = tcos(azi)*duvw[2]; |
813 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
814 |
|
for (i = 3; i--; ) |
815 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
860 |
|
|
861 |
|
while (n--) { /* stratified sampling */ |
862 |
|
SDmultiSamp(samp2, 2, (n+frandom())/sampcnt); |
863 |
< |
if (!bi_getvec(duvw, b+samp2[1], kbasis[bi])) |
863 |
> |
if (!fo_getvec(duvw, b+samp2[1], kbasis[bi])) |
864 |
|
return(0); |
865 |
|
for (i = 3; i--; ) |
866 |
< |
orig_dir[1][i] = duvw[0]*p->udir[i] + |
867 |
< |
duvw[1]*p->vdir[i] + |
866 |
> |
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
867 |
> |
duvw[1]*p->vdir[i] - |
868 |
|
duvw[2]*p->nrm[i] ; |
869 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
870 |
|
return(0); |
904 |
|
else |
905 |
|
curparams.vup[1] = 1; |
906 |
|
} |
907 |
< |
VCROSS(curparams.udir, curparams.vup, curparams.nrm); |
907 |
> |
fcross(curparams.udir, curparams.vup, curparams.nrm); |
908 |
|
if (normalize(curparams.udir) == 0) { |
909 |
|
fputs(progname, stderr); |
910 |
|
fputs(": up vector coincides with sender normal\n", stderr); |
911 |
|
return(-1); |
912 |
|
} |
913 |
< |
VCROSS(curparams.vdir, curparams.nrm, curparams.udir); |
913 |
> |
fcross(curparams.vdir, curparams.nrm, curparams.udir); |
914 |
> |
if (curparams.sign == '-') { /* left-handed coordinate system? */ |
915 |
> |
curparams.udir[0] *= -1.; |
916 |
> |
curparams.udir[1] *= -1.; |
917 |
> |
curparams.udir[2] *= -1.; |
918 |
> |
} |
919 |
|
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
920 |
|
curparams.sample_basis = sample_uniform; |
921 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
1110 |
|
add_send_object(FILE *fp) |
1111 |
|
{ |
1112 |
|
int st; |
1113 |
< |
char otype[32], oname[128]; |
1113 |
> |
char thismod[128], otype[32], oname[128]; |
1114 |
|
int n; |
1115 |
|
|
1116 |
< |
if (fscanf(fp, "%*s %s %s", otype, oname) != 2) |
1116 |
> |
if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3) |
1117 |
|
return(0); /* must have hit EOF! */ |
1118 |
|
if (!strcmp(otype, "alias")) { |
1119 |
|
fscanf(fp, "%*s"); /* skip alias */ |
1126 |
|
fputs(": cannot use source as a sender!\n", stderr); |
1127 |
|
return(-1); |
1128 |
|
} |
1129 |
+ |
if (strcmp(thismod, curmod)) { |
1130 |
+ |
if (curmod[0]) { |
1131 |
+ |
fputs(progname, stderr); |
1132 |
+ |
fputs(": warning - multiple modifiers in sender\n", |
1133 |
+ |
stderr); |
1134 |
+ |
} |
1135 |
+ |
strcpy(curmod, thismod); |
1136 |
+ |
} |
1137 |
|
parse_params(&curparams, newparams); |
1138 |
|
newparams[0] = '\0'; |
1139 |
|
add_surface(st, oname, fp); /* read & store surface */ |
1303 |
|
if (argv[a][2] != 'v') na = 2; |
1304 |
|
break; |
1305 |
|
case 'a': /* special case */ |
1306 |
< |
na = (argv[a][2] == 'v') ? 4 : 2; |
1306 |
> |
if (argv[a][2] == 'p') { |
1307 |
> |
na = 2; /* photon map [+ bandwidth(s)] */ |
1308 |
> |
if (a < argc-3 && atoi(argv[a+1]) > 0) |
1309 |
> |
na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0); |
1310 |
> |
} else |
1311 |
> |
na = (argv[a][2] == 'v') ? 4 : 2; |
1312 |
|
break; |
1313 |
|
case 'm': /* special case */ |
1314 |
|
if (!argv[a][2]) goto userr; |
1373 |
|
return(my_exec(rcarg)); /* rcontrib does everything */ |
1374 |
|
} |
1375 |
|
clear_params(&curparams, 0); /* else load sender surface & params */ |
1376 |
+ |
curmod[0] = '\0'; |
1377 |
|
if (load_scene(sendfn, add_send_object) < 0) |
1378 |
|
return(1); |
1379 |
|
if ((nsbins = prepare_sampler()) <= 0) |
1391 |
|
#ifdef getc_unlocked |
1392 |
|
flockfile(rcfp); |
1393 |
|
#endif |
1394 |
< |
if (verbose) { |
1394 |
> |
if (verbose > 0) { |
1395 |
|
fprintf(stderr, "%s: sampling %d directions", progname, nsbins); |
1396 |
|
if (curparams.nsurfs > 1) |
1397 |
|
fprintf(stderr, " (%d elements)\n", curparams.nsurfs); |
1401 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
1402 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
1403 |
|
return(1); |
1404 |
< |
return(pclose(rcfp) == 0); /* all finished! */ |
1404 |
> |
return(pclose(rcfp) < 0); /* all finished! */ |
1405 |
|
userr: |
1406 |
|
if (a < argc-2) |
1407 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |