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" |
18 |
|
#include "triangulate.h" |
19 |
|
#include "platform.h" |
20 |
|
|
20 |
– |
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
21 |
– |
#undef getc |
22 |
– |
#define getc getc_unlocked |
23 |
– |
#endif |
24 |
– |
|
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 |
– |
|
21 |
|
#define MAXRCARG 512 |
22 |
|
|
23 |
|
char *progname; /* global argv[0] */ |
24 |
|
|
25 |
< |
int verbose = 0; /* verbose mode? */ |
25 |
> |
int verbose = 0; /* verbose mode (< 0 no warnings) */ |
26 |
|
|
27 |
|
char *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"}; |
28 |
|
int nrcargs = 2; |
64 |
|
FVECT uva[2]; /* tangent axes */ |
65 |
|
int ntris; /* number of triangles */ |
66 |
|
struct ptri { |
67 |
< |
float afrac; /* fraction of total area */ |
67 |
> |
double afrac; /* fraction of total area */ |
68 |
|
short vndx[3]; /* vertex indices */ |
69 |
|
} tri[1]; /* triangle array (extends struct) */ |
70 |
|
} POLYTRIS; /* triangulated polygon */ |
71 |
|
|
72 |
|
typedef struct param_s { |
73 |
< |
char hemis[32]; /* hemispherical sampling spec. */ |
73 |
> |
char sign; /* '-' for axis reversal */ |
74 |
> |
char hemis[31]; /* hemispherical sampling spec. */ |
75 |
|
int hsiz; /* hemisphere basis size */ |
76 |
|
int nsurfs; /* number of surfaces */ |
77 |
|
SURF *slist; /* list of surfaces */ |
78 |
|
FVECT vup; /* up vector (zero if unset) */ |
79 |
|
FVECT nrm; /* average normal direction */ |
80 |
< |
FVECT udir, vdir; /* v-up tangent axes */ |
80 |
> |
FVECT udir, vdir; /* tangent axes */ |
81 |
|
char *outfn; /* output file name (receiver) */ |
82 |
|
int (*sample_basis)(struct param_s *p, int, FILE *); |
83 |
|
} PARAMS; /* sender/receiver parameters */ |
132 |
|
static char * |
133 |
|
oconv_command(int ac, char *av[]) |
134 |
|
{ |
135 |
< |
static char oconvbuf[2048] = "!oconv -f"; |
136 |
< |
char *cp = oconvbuf + 9; |
137 |
< |
|
135 |
> |
static char oconvbuf[2048] = "!oconv -f "; |
136 |
> |
char *cp = oconvbuf + 10; |
137 |
> |
char *recv = *av++; |
138 |
> |
|
139 |
> |
if (ac-- <= 0) |
140 |
> |
return(NULL); |
141 |
> |
if (verbose < 0) { /* turn off warnings */ |
142 |
> |
strcpy(cp, "-w- "); |
143 |
> |
cp += 4; |
144 |
> |
} |
145 |
|
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++ = ' '; |
146 |
|
strcpy(cp, *av++); |
147 |
|
while (*cp) cp++; |
148 |
+ |
*cp++ = ' '; |
149 |
+ |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) |
150 |
+ |
goto overrun; |
151 |
|
} |
152 |
< |
*cp = '\0'; |
152 |
> |
/* receiver goes last */ |
153 |
> |
if (matchany(recv, SPECIALS)) { |
154 |
> |
*cp++ = QUOTCHAR; |
155 |
> |
while (*recv) { |
156 |
> |
if (cp >= oconvbuf+(sizeof(oconvbuf)-3)) |
157 |
> |
goto overrun; |
158 |
> |
*cp++ = *recv++; |
159 |
> |
} |
160 |
> |
*cp++ = QUOTCHAR; |
161 |
> |
*cp = '\0'; |
162 |
> |
} else |
163 |
> |
strcpy(cp, recv); |
164 |
|
return(oconvbuf); |
165 |
+ |
overrun: |
166 |
+ |
fputs(progname, stderr); |
167 |
+ |
fputs(": too many file arguments!\n", stderr); |
168 |
+ |
exit(1); |
169 |
|
} |
170 |
|
|
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 |
– |
|
171 |
|
/* Open a pipe to/from a command given as an argument list */ |
172 |
|
static FILE * |
173 |
|
popen_arglist(char *av[], char *mode) |
179 |
|
fputs(": command line too long in popen_arglist()\n", stderr); |
180 |
|
return(NULL); |
181 |
|
} |
182 |
< |
if (verbose) |
182 |
> |
if (verbose > 0) |
183 |
|
fprintf(stderr, "%s: opening pipe %s: %s\n", |
184 |
|
progname, (*mode=='w') ? "to" : "from", cmd); |
185 |
|
return(popen(cmd, mode)); |
186 |
|
} |
187 |
|
|
188 |
< |
#ifdef _WIN32 |
188 |
> |
#if defined(_WIN32) || defined(_WIN64) |
189 |
|
/* Execute system command (Windows version) */ |
190 |
|
static int |
191 |
|
my_exec(char *av[]) |
197 |
|
fputs(": command line too long in my_exec()\n", stderr); |
198 |
|
return(1); |
199 |
|
} |
200 |
< |
if (verbose) |
200 |
> |
if (verbose > 0) |
201 |
|
fprintf(stderr, "%s: running: %s\n", progname, cmd); |
202 |
|
return(system(cmd)); |
203 |
|
} |
212 |
|
fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]); |
213 |
|
return(1); |
214 |
|
} |
215 |
< |
if (verbose) { |
215 |
> |
if (verbose > 0) { |
216 |
|
char cmd[4096]; |
217 |
|
if (!convert_commandline(cmd, sizeof(cmd), av)) |
218 |
|
strcpy(cmd, "COMMAND TOO LONG TO SHOW"); |
270 |
|
{ |
271 |
|
char *cp = pargs; |
272 |
|
int nparams = 0; |
273 |
+ |
int quot; |
274 |
|
int i; |
275 |
|
|
276 |
< |
for ( ; ; ) |
276 |
> |
for ( ; ; ) { |
277 |
|
switch (*cp++) { |
278 |
|
case 'h': |
279 |
|
if (*cp++ != '=') |
280 |
|
break; |
281 |
+ |
if ((*cp == '+') | (*cp == '-')) |
282 |
+ |
p->sign = *cp++; |
283 |
+ |
else |
284 |
+ |
p->sign = '+'; |
285 |
|
p->hsiz = 0; |
286 |
|
i = 0; |
287 |
|
while (*cp && !isspace(*cp)) { |
300 |
|
break; |
301 |
|
if (!get_direction(p->vup, cp)) |
302 |
|
break; |
303 |
+ |
while (*cp && !isspace(*cp++)) |
304 |
+ |
; |
305 |
|
++nparams; |
306 |
|
continue; |
307 |
|
case 'o': |
308 |
|
if (*cp++ != '=') |
309 |
|
break; |
310 |
+ |
quot = 0; |
311 |
+ |
if ((*cp == '"') | (*cp == '\'')) |
312 |
+ |
quot = *cp++; |
313 |
|
i = 0; |
314 |
< |
while (*cp && !isspace(*cp++)) |
315 |
< |
i++; |
314 |
> |
while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) { |
315 |
> |
i++; cp++; |
316 |
> |
} |
317 |
|
if (!i) |
318 |
|
break; |
319 |
< |
*--cp = '\0'; |
319 |
> |
if (!*cp) { |
320 |
> |
if (quot) |
321 |
> |
break; |
322 |
> |
cp[1] = '\0'; |
323 |
> |
} |
324 |
> |
*cp = '\0'; |
325 |
|
p->outfn = savqstr(cp-i); |
326 |
< |
*cp++ = ' '; |
326 |
> |
*cp++ = quot ? quot : ' '; |
327 |
|
++nparams; |
328 |
|
continue; |
329 |
|
case ' ': |
336 |
|
default: |
337 |
|
break; |
338 |
|
} |
339 |
< |
fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs); |
339 |
> |
break; |
340 |
> |
} |
341 |
> |
fprintf(stderr, "%s: bad parameter string: %s", progname, pargs); |
342 |
|
exit(1); |
343 |
|
return(-1); /* pro forma return */ |
344 |
|
} |
376 |
|
fputs(": undefined normal for hemisphere sampling\n", stderr); |
377 |
|
exit(1); |
378 |
|
} |
379 |
< |
if (normalize(curparams.vup) == 0) |
379 |
> |
if (normalize(curparams.vup) == 0) { |
380 |
|
if (fabs(curparams.nrm[2]) < .7) |
381 |
|
curparams.vup[2] = 1; |
382 |
|
else |
383 |
|
curparams.vup[1] = 1; |
384 |
+ |
} |
385 |
|
/* determine sample type/bin */ |
386 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
387 |
< |
binv = "0"; /* uniform sampling -- one bin */ |
386 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { |
387 |
> |
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
388 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
389 |
> |
binv = savqstr(sbuf); |
390 |
> |
nbins = "1"; /* uniform sampling -- one bin */ |
391 |
|
uniform = 1; |
392 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
393 |
|
tolower(curparams.hemis[1]) == 'c') { |
398 |
|
exit(1); |
399 |
|
} |
400 |
|
calfn = shirchiufn; shirchiufn = NULL; |
401 |
< |
sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
401 |
> |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
402 |
|
curparams.hsiz, |
403 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
404 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
404 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
405 |
> |
curparams.sign); |
406 |
|
params = savqstr(sbuf); |
407 |
|
binv = "scbin"; |
408 |
|
nbins = "SCdim*SCdim"; |
409 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
410 |
|
(tolower(curparams.hemis[0]) == 't')) { |
411 |
|
calfn = reinhfn; reinhfn = NULL; |
412 |
< |
sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
412 |
> |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
413 |
|
curparams.hsiz, |
414 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
415 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
415 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
416 |
> |
curparams.sign); |
417 |
|
params = savqstr(sbuf); |
418 |
|
binv = "rbin"; |
419 |
|
nbins = "Nrbins"; |
441 |
|
progname, curparams.hemis); |
442 |
|
exit(1); |
443 |
|
} |
444 |
+ |
if (tolower(curparams.hemis[0]) == 'k') { |
445 |
+ |
sprintf(sbuf, "RHS=%c1", curparams.sign); |
446 |
+ |
params = savqstr(sbuf); |
447 |
+ |
} |
448 |
|
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
449 |
|
SURF *sp; |
450 |
|
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
492 |
|
{ |
493 |
|
int i; |
494 |
|
|
495 |
< |
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) { |
495 |
> |
if (!getperpendicular(uva[0], nrm, 1)) { |
496 |
|
fputs(progname, stderr); |
497 |
|
fputs(": bad surface normal in make_axes!\n", stderr); |
498 |
|
exit(1); |
499 |
|
} |
500 |
< |
uva[1][i] = 1.0; |
522 |
< |
VCROSS(uva[0], uva[1], nrm); |
523 |
< |
normalize(uva[0]); |
524 |
< |
VCROSS(uva[1], nrm, uva[0]); |
500 |
> |
fcross(uva[1], nrm, uva[0]); |
501 |
|
} |
502 |
|
|
503 |
|
/* Illegal sender surfaces end up here */ |
606 |
|
sp->priv = (void *)ptp; |
607 |
|
} |
608 |
|
/* pick triangle by partial area */ |
609 |
< |
for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) |
609 |
> |
for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) |
610 |
|
x -= ptp->tri[i].afrac; |
611 |
|
SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); |
612 |
|
samp2[0] *= samp2[1] = sqrt(samp2[1]); |
636 |
|
/* special case for lone surface */ |
637 |
|
if (p->nsurfs == 1) { |
638 |
|
sp = p->slist; |
639 |
< |
if (DOT(sp->snrm, rdir) >= -FTINY) { |
639 |
> |
if (DOT(sp->snrm, rdir) >= FTINY) { |
640 |
|
fprintf(stderr, |
641 |
|
"%s: internal - sample behind sender '%s'\n", |
642 |
|
progname, sp->sname); |
647 |
|
if (p->nsurfs > nall) { /* (re)allocate surface area cache */ |
648 |
|
if (projsa) free(projsa); |
649 |
|
projsa = (double *)malloc(sizeof(double)*p->nsurfs); |
650 |
< |
if (!projsa) return(0); |
650 |
> |
if (projsa == NULL) { |
651 |
> |
fputs(progname, stderr); |
652 |
> |
fputs(": out of memory in sample_origin!\n", stderr); |
653 |
> |
exit(1); |
654 |
> |
} |
655 |
|
nall = p->nsurfs; |
656 |
|
} |
657 |
|
/* compute projected areas */ |
694 |
|
duvw[2]*p->nrm[i] ; |
695 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
696 |
|
return(0); |
697 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
697 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
698 |
|
return(0); |
699 |
|
} |
700 |
|
return(1); |
724 |
|
duvw[2]*p->nrm[i] ; |
725 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
726 |
|
return(0); |
727 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
727 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
728 |
|
return(0); |
729 |
|
} |
730 |
|
return(1); |
763 |
|
alt = (row+samp3[1])*RAH; |
764 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
765 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
766 |
< |
duvw[0] = tcos(azi)*duvw[2]; |
767 |
< |
duvw[1] = tsin(azi)*duvw[2]; |
766 |
> |
duvw[0] = tsin(azi)*duvw[2]; |
767 |
> |
duvw[1] = tcos(azi)*duvw[2]; |
768 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
769 |
|
for (i = 3; i--; ) |
770 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
772 |
|
duvw[2]*p->nrm[i] ; |
773 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
774 |
|
return(0); |
775 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
775 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
776 |
|
return(0); |
777 |
|
} |
778 |
|
return(1); |
815 |
|
|
816 |
|
while (n--) { /* stratified sampling */ |
817 |
|
SDmultiSamp(samp2, 2, (n+frandom())/sampcnt); |
818 |
< |
if (!bo_getvec(duvw, b+samp2[1], kbasis[bi])) |
818 |
> |
if (!fo_getvec(duvw, b+samp2[1], kbasis[bi])) |
819 |
|
return(0); |
820 |
|
for (i = 3; i--; ) |
821 |
< |
orig_dir[1][i] = duvw[0]*p->udir[i] + |
822 |
< |
duvw[1]*p->vdir[i] + |
821 |
> |
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
822 |
> |
duvw[1]*p->vdir[i] - |
823 |
|
duvw[2]*p->nrm[i] ; |
824 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
825 |
|
return(0); |
826 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
826 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
827 |
|
return(0); |
828 |
|
} |
829 |
|
return(1); |
838 |
|
fputs(": no sender surface!\n", stderr); |
839 |
|
return(-1); |
840 |
|
} |
841 |
< |
if (curparams.outfn != NULL) /* misplaced output file spec. */ |
841 |
> |
/* misplaced output file spec. */ |
842 |
> |
if ((curparams.outfn != NULL) & (verbose >= 0)) |
843 |
|
fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n", |
844 |
|
progname, curparams.outfn); |
845 |
|
/* check/set basis hemisphere */ |
853 |
|
fputs(": undefined normal for sender sampling\n", stderr); |
854 |
|
return(-1); |
855 |
|
} |
856 |
< |
if (normalize(curparams.vup) == 0) |
856 |
> |
if (normalize(curparams.vup) == 0) { |
857 |
|
if (fabs(curparams.nrm[2]) < .7) |
858 |
|
curparams.vup[2] = 1; |
859 |
|
else |
860 |
|
curparams.vup[1] = 1; |
861 |
< |
VCROSS(curparams.udir, curparams.vup, curparams.nrm); |
861 |
> |
} |
862 |
> |
fcross(curparams.udir, curparams.vup, curparams.nrm); |
863 |
|
if (normalize(curparams.udir) == 0) { |
864 |
|
fputs(progname, stderr); |
865 |
|
fputs(": up vector coincides with sender normal\n", stderr); |
866 |
|
return(-1); |
867 |
|
} |
868 |
< |
VCROSS(curparams.vdir, curparams.nrm, curparams.udir); |
869 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
868 |
> |
fcross(curparams.vdir, curparams.nrm, curparams.udir); |
869 |
> |
if (curparams.sign == '-') { /* left-handed coordinate system? */ |
870 |
> |
curparams.udir[0] *= -1.; |
871 |
> |
curparams.udir[1] *= -1.; |
872 |
> |
curparams.udir[2] *= -1.; |
873 |
> |
} |
874 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
875 |
|
curparams.sample_basis = sample_uniform; |
876 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
877 |
|
tolower(curparams.hemis[1]) == 'c') |
950 |
|
snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1)); |
951 |
|
if (snew == NULL) { |
952 |
|
fputs(progname, stderr); |
953 |
< |
fputs(": out of memory!\n", stderr); |
953 |
> |
fputs(": out of memory in add_surface!\n", stderr); |
954 |
|
exit(1); |
955 |
|
} |
956 |
|
strncpy(snew->sname, oname, sizeof(snew->sname)-1); |
987 |
|
case ST_SOURCE: |
988 |
|
if (snew->nfargs != 4) |
989 |
|
goto badcount; |
990 |
< |
VCOPY(snew->snrm, snew->farg); |
990 |
> |
for (n = 3; n--; ) /* need to reverse "normal" */ |
991 |
> |
snew->snrm[n] = -snew->farg[n]; |
992 |
|
if (normalize(snew->snrm) == 0) |
993 |
|
goto badnorm; |
994 |
|
snew->area = sin((PI/180./2.)*snew->farg[3]); |
995 |
|
snew->area *= PI*snew->area; |
996 |
|
break; |
997 |
|
} |
998 |
< |
if (snew->area <= FTINY) { |
998 |
> |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
999 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
1000 |
|
progname, oname); |
1001 |
|
free(snew); |
1051 |
|
return(1); |
1052 |
|
} |
1053 |
|
/* else skip arguments */ |
1054 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1054 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1055 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
1056 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1056 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1057 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
1058 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1058 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1059 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
1060 |
|
return(0); |
1061 |
|
} |
1065 |
|
add_send_object(FILE *fp) |
1066 |
|
{ |
1067 |
|
int st; |
1068 |
< |
char otype[32], oname[128]; |
1068 |
> |
char thismod[128], otype[32], oname[128]; |
1069 |
|
int n; |
1070 |
|
|
1071 |
< |
if (fscanf(fp, "%*s %s %s", otype, oname) != 2) |
1071 |
> |
if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3) |
1072 |
|
return(0); /* must have hit EOF! */ |
1073 |
|
if (!strcmp(otype, "alias")) { |
1074 |
|
fscanf(fp, "%*s"); /* skip alias */ |
1081 |
|
fputs(": cannot use source as a sender!\n", stderr); |
1082 |
|
return(-1); |
1083 |
|
} |
1084 |
+ |
if (strcmp(thismod, curmod)) { |
1085 |
+ |
if (curmod[0]) { |
1086 |
+ |
fputs(progname, stderr); |
1087 |
+ |
fputs(": warning - multiple modifiers in sender\n", |
1088 |
+ |
stderr); |
1089 |
+ |
} |
1090 |
+ |
strcpy(curmod, thismod); |
1091 |
+ |
} |
1092 |
|
parse_params(&curparams, newparams); |
1093 |
|
newparams[0] = '\0'; |
1094 |
|
add_surface(st, oname, fp); /* read & store surface */ |
1095 |
|
return(0); |
1096 |
|
} |
1097 |
|
/* else skip arguments */ |
1098 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1098 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1099 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
1100 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1100 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1101 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
1102 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1102 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1103 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
1104 |
|
return(0); |
1105 |
|
} |
1142 |
|
strcat(newparams, inpbuf); |
1143 |
|
continue; |
1144 |
|
} |
1145 |
< |
while ((c = getc(fp)) != EOF && c != '\n'); |
1145 |
> |
while ((c = getc(fp)) != EOF && c != '\n') |
1146 |
|
; /* else skipping comment */ |
1147 |
|
continue; |
1148 |
|
} |
1167 |
|
{ |
1168 |
|
char fmtopt[6] = "-faa"; /* default output is ASCII */ |
1169 |
|
char *xrs=NULL, *yrs=NULL, *ldopt=NULL; |
1170 |
+ |
char *iropt = NULL; |
1171 |
|
char *sendfn; |
1172 |
|
char sampcntbuf[32], nsbinbuf[32]; |
1173 |
|
FILE *rcfp; |
1175 |
|
int a, i; |
1176 |
|
/* screen rcontrib options */ |
1177 |
|
progname = argv[0]; |
1178 |
< |
for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) { |
1179 |
< |
int na = 1; /* !! Keep consistent !! */ |
1180 |
< |
switch (argv[a][1]) { |
1178 |
> |
for (a = 1; a < argc-2; a++) { |
1179 |
> |
int na; |
1180 |
> |
/* check for argument expansion */ |
1181 |
> |
while ((na = expandarg(&argc, &argv, a)) > 0) |
1182 |
> |
; |
1183 |
> |
if (na < 0) { |
1184 |
> |
fprintf(stderr, "%s: cannot expand '%s'\n", |
1185 |
> |
progname, argv[a]); |
1186 |
> |
return(1); |
1187 |
> |
} |
1188 |
> |
if (argv[a][0] != '-' || !argv[a][1]) |
1189 |
> |
break; |
1190 |
> |
na = 1; |
1191 |
> |
switch (argv[a][1]) { /* !! Keep consistent !! */ |
1192 |
|
case 'v': /* verbose mode */ |
1193 |
< |
verbose = !verbose; |
1193 |
> |
verbose = 1; |
1194 |
|
na = 0; |
1195 |
|
continue; |
1196 |
|
case 'f': /* special case for -fo, -ff, etc. */ |
1226 |
|
goto userr; |
1227 |
|
na = 0; /* we re-add this later */ |
1228 |
|
continue; |
1229 |
< |
case 'V': /* options without arguments */ |
1222 |
< |
case 'w': |
1223 |
< |
case 'u': |
1229 |
> |
case 'I': /* only for pass-through mode */ |
1230 |
|
case 'i': |
1231 |
+ |
iropt = argv[a]; |
1232 |
+ |
na = 0; |
1233 |
+ |
continue; |
1234 |
+ |
case 'w': /* options without arguments */ |
1235 |
+ |
if (argv[a][2] != '+') verbose = -1; |
1236 |
+ |
case 'V': |
1237 |
+ |
case 'u': |
1238 |
|
case 'h': |
1239 |
|
case 'r': |
1240 |
|
break; |
1258 |
|
if (argv[a][2] != 'v') na = 2; |
1259 |
|
break; |
1260 |
|
case 'a': /* special case */ |
1261 |
< |
na = (argv[a][2] == 'v') ? 4 : 2; |
1261 |
> |
if (argv[a][2] == 'p') { |
1262 |
> |
na = 2; /* photon map [+ bandwidth(s)] */ |
1263 |
> |
if (a < argc-3 && atoi(argv[a+1]) > 0) |
1264 |
> |
na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0); |
1265 |
> |
} else |
1266 |
> |
na = (argv[a][2] == 'v') ? 4 : 2; |
1267 |
|
break; |
1268 |
|
case 'm': /* special case */ |
1269 |
|
if (!argv[a][2]) goto userr; |
1270 |
|
na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2; |
1271 |
|
break; |
1254 |
– |
case '\0': /* pass-through mode */ |
1255 |
– |
goto done_opts; |
1272 |
|
default: /* anything else is verbotten */ |
1273 |
|
goto userr; |
1274 |
|
} |
1278 |
|
while (--na) /* + arguments if any */ |
1279 |
|
rcarg[nrcargs++] = argv[++a]; |
1280 |
|
} |
1265 |
– |
done_opts: |
1281 |
|
if (a > argc-2) |
1282 |
|
goto userr; /* check at end of options */ |
1283 |
|
sendfn = argv[a++]; /* assign sender & receiver inputs */ |
1284 |
|
if (sendfn[0] == '-') { /* user wants pass-through mode? */ |
1285 |
|
if (sendfn[1]) goto userr; |
1286 |
|
sendfn = NULL; |
1287 |
+ |
if (iropt) { |
1288 |
+ |
CHECKARGC(1); |
1289 |
+ |
rcarg[nrcargs++] = iropt; |
1290 |
+ |
} |
1291 |
|
if (xrs) { |
1292 |
|
CHECKARGC(2); |
1293 |
|
rcarg[nrcargs++] = "-x"; |
1303 |
|
rcarg[nrcargs++] = ldopt; |
1304 |
|
} |
1305 |
|
if (sampcnt <= 0) sampcnt = 1; |
1306 |
< |
} else { /* else FVECT determines input format */ |
1307 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1306 |
> |
} else { /* else in sampling mode */ |
1307 |
> |
if (iropt) { |
1308 |
> |
fputs(progname, stderr); |
1309 |
> |
fputs(": -i, -I supported for pass-through only\n", stderr); |
1310 |
> |
return(1); |
1311 |
> |
} |
1312 |
> |
#ifdef SMLFLT |
1313 |
> |
fmtopt[2] = 'f'; |
1314 |
> |
#else |
1315 |
> |
fmtopt[2] = 'd'; |
1316 |
> |
#endif |
1317 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1318 |
|
} |
1319 |
|
sprintf(sampcntbuf, "%d", sampcnt); |
1332 |
|
return(my_exec(rcarg)); /* rcontrib does everything */ |
1333 |
|
} |
1334 |
|
clear_params(&curparams, 0); /* else load sender surface & params */ |
1335 |
+ |
curmod[0] = '\0'; |
1336 |
|
if (load_scene(sendfn, add_send_object) < 0) |
1337 |
|
return(1); |
1338 |
|
if ((nsbins = prepare_sampler()) <= 0) |
1350 |
|
#ifdef getc_unlocked |
1351 |
|
flockfile(rcfp); |
1352 |
|
#endif |
1353 |
< |
if (verbose) { |
1353 |
> |
if (verbose > 0) { |
1354 |
|
fprintf(stderr, "%s: sampling %d directions", progname, nsbins); |
1355 |
|
if (curparams.nsurfs > 1) |
1356 |
|
fprintf(stderr, " (%d elements)\n", curparams.nsurfs); |
1360 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
1361 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
1362 |
|
return(1); |
1363 |
< |
return(pclose(rcfp) == 0); /* all finished! */ |
1363 |
> |
return(pclose(rcfp) < 0); /* all finished! */ |
1364 |
|
userr: |
1365 |
|
if (a < argc-2) |
1366 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |
1367 |
< |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n", |
1367 |
> |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n", |
1368 |
|
progname); |
1369 |
|
return(1); |
1370 |
|
} |