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 |
|
|
21 |
< |
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
22 |
< |
#undef getc |
22 |
< |
#define getc getc_unlocked |
21 |
> |
#ifndef MAXRCARG |
22 |
> |
#define MAXRCARG 10000 |
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 |
– |
|
34 |
– |
#define MAXRCARG 512 |
35 |
– |
|
25 |
|
char *progname; /* global argv[0] */ |
26 |
|
|
27 |
< |
int verbose = 0; /* verbose mode? */ |
27 |
> |
int verbose = 0; /* verbose mode (< 0 no warnings) */ |
28 |
|
|
29 |
|
char *rcarg[MAXRCARG+1] = {"rcontrib", "-fo+"}; |
30 |
|
int nrcargs = 2; |
66 |
|
FVECT uva[2]; /* tangent axes */ |
67 |
|
int ntris; /* number of triangles */ |
68 |
|
struct ptri { |
69 |
< |
float afrac; /* fraction of total area */ |
69 |
> |
double afrac; /* fraction of total area */ |
70 |
|
short vndx[3]; /* vertex indices */ |
71 |
|
} tri[1]; /* triangle array (extends struct) */ |
72 |
|
} POLYTRIS; /* triangulated polygon */ |
73 |
|
|
74 |
|
typedef struct param_s { |
75 |
< |
char hemis[32]; /* hemispherical sampling spec. */ |
75 |
> |
char sign; /* '-' for axis reversal */ |
76 |
> |
char hemis[31]; /* hemispherical sampling spec. */ |
77 |
|
int hsiz; /* hemisphere basis size */ |
78 |
|
int nsurfs; /* number of surfaces */ |
79 |
|
SURF *slist; /* list of surfaces */ |
80 |
|
FVECT vup; /* up vector (zero if unset) */ |
81 |
|
FVECT nrm; /* average normal direction */ |
82 |
< |
FVECT udir, vdir; /* v-up tangent axes */ |
82 |
> |
FVECT udir, vdir; /* tangent axes */ |
83 |
|
char *outfn; /* output file name (receiver) */ |
84 |
|
int (*sample_basis)(struct param_s *p, int, FILE *); |
85 |
|
} PARAMS; /* sender/receiver parameters */ |
134 |
|
static char * |
135 |
|
oconv_command(int ac, char *av[]) |
136 |
|
{ |
137 |
< |
static char oconvbuf[2048] = "!oconv -f"; |
138 |
< |
char *cp = oconvbuf + 9; |
139 |
< |
|
140 |
< |
while (ac-- > 0) { |
141 |
< |
if (cp >= oconvbuf+(sizeof(oconvbuf)-32)) { |
142 |
< |
fputs(progname, stderr); |
143 |
< |
fputs(": too many file arguments!\n", stderr); |
144 |
< |
exit(1); |
145 |
< |
} |
156 |
< |
*cp++ = ' '; |
157 |
< |
strcpy(cp, *av++); |
158 |
< |
while (*cp) cp++; |
137 |
> |
static char oconvbuf[2048] = "!oconv -f "; |
138 |
> |
char *cp = oconvbuf + 10; |
139 |
> |
char *recv = *av++; |
140 |
> |
|
141 |
> |
if (ac-- <= 0) |
142 |
> |
return(NULL); |
143 |
> |
if (verbose < 0) { /* turn off warnings */ |
144 |
> |
strcpy(cp, "-w "); |
145 |
> |
cp += 3; |
146 |
|
} |
147 |
< |
*cp = '\0'; |
148 |
< |
return(oconvbuf); |
149 |
< |
} |
150 |
< |
|
151 |
< |
/* Check if any of the characters in str2 are found in str1 */ |
152 |
< |
static int |
153 |
< |
matchany(const char *str1, const char *str2) |
154 |
< |
{ |
155 |
< |
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; |
147 |
> |
while (ac-- > 0) { /* copy each argument */ |
148 |
> |
int len = strlen(*av); |
149 |
> |
if (cp+len+4 >= oconvbuf+sizeof(oconvbuf)) |
150 |
> |
goto overrun; |
151 |
> |
if (matchany(*av, SPECIALS)) { |
152 |
> |
*cp++ = QUOTCHAR; |
153 |
> |
strcpy(cp, *av++); |
154 |
> |
cp += len; |
155 |
> |
*cp++ = QUOTCHAR; |
156 |
|
} else { |
157 |
< |
strcpy(cp, *av); |
158 |
< |
cp += n; |
157 |
> |
strcpy(cp, *av++); |
158 |
> |
cp += len; |
159 |
|
} |
160 |
|
*cp++ = ' '; |
161 |
|
} |
162 |
< |
if (cp <= cmd) |
163 |
< |
return(NULL); |
164 |
< |
*--cp = '\0'; |
165 |
< |
return(cmd); |
162 |
> |
/* receiver goes last */ |
163 |
> |
if (matchany(recv, SPECIALS)) { |
164 |
> |
*cp++ = QUOTCHAR; |
165 |
> |
while (*recv) { |
166 |
> |
if (cp >= oconvbuf+(sizeof(oconvbuf)-3)) |
167 |
> |
goto overrun; |
168 |
> |
*cp++ = *recv++; |
169 |
> |
} |
170 |
> |
*cp++ = QUOTCHAR; |
171 |
> |
*cp = '\0'; |
172 |
> |
} else |
173 |
> |
strcpy(cp, recv); |
174 |
> |
return(oconvbuf); |
175 |
> |
overrun: |
176 |
> |
fputs(progname, stderr); |
177 |
> |
fputs(": too many file arguments!\n", stderr); |
178 |
> |
exit(1); |
179 |
|
} |
180 |
|
|
181 |
|
/* Open a pipe to/from a command given as an argument list */ |
189 |
|
fputs(": command line too long in popen_arglist()\n", stderr); |
190 |
|
return(NULL); |
191 |
|
} |
192 |
< |
if (verbose) |
192 |
> |
if (verbose > 0) |
193 |
|
fprintf(stderr, "%s: opening pipe %s: %s\n", |
194 |
|
progname, (*mode=='w') ? "to" : "from", cmd); |
195 |
|
return(popen(cmd, mode)); |
196 |
|
} |
197 |
|
|
198 |
< |
#ifdef _WIN32 |
198 |
> |
#if defined(_WIN32) || defined(_WIN64) |
199 |
|
/* Execute system command (Windows version) */ |
200 |
|
static int |
201 |
|
my_exec(char *av[]) |
207 |
|
fputs(": command line too long in my_exec()\n", stderr); |
208 |
|
return(1); |
209 |
|
} |
210 |
< |
if (verbose) |
210 |
> |
if (verbose > 0) |
211 |
|
fprintf(stderr, "%s: running: %s\n", progname, cmd); |
212 |
|
return(system(cmd)); |
213 |
|
} |
222 |
|
fprintf(stderr, "%s: cannot locate %s\n", progname, av[0]); |
223 |
|
return(1); |
224 |
|
} |
225 |
< |
if (verbose) { |
225 |
> |
if (verbose > 0) { |
226 |
|
char cmd[4096]; |
227 |
|
if (!convert_commandline(cmd, sizeof(cmd), av)) |
228 |
|
strcpy(cmd, "COMMAND TOO LONG TO SHOW"); |
280 |
|
{ |
281 |
|
char *cp = pargs; |
282 |
|
int nparams = 0; |
283 |
+ |
int quot; |
284 |
|
int i; |
285 |
|
|
286 |
< |
for ( ; ; ) |
286 |
> |
for ( ; ; ) { |
287 |
|
switch (*cp++) { |
288 |
|
case 'h': |
289 |
|
if (*cp++ != '=') |
290 |
|
break; |
291 |
+ |
if ((*cp == '+') | (*cp == '-')) |
292 |
+ |
p->sign = *cp++; |
293 |
+ |
else |
294 |
+ |
p->sign = '+'; |
295 |
|
p->hsiz = 0; |
296 |
|
i = 0; |
297 |
|
while (*cp && !isspace(*cp)) { |
310 |
|
break; |
311 |
|
if (!get_direction(p->vup, cp)) |
312 |
|
break; |
313 |
+ |
while (*cp && !isspace(*cp++)) |
314 |
+ |
; |
315 |
|
++nparams; |
316 |
|
continue; |
317 |
|
case 'o': |
318 |
|
if (*cp++ != '=') |
319 |
|
break; |
320 |
+ |
quot = 0; |
321 |
+ |
if ((*cp == '"') | (*cp == '\'')) |
322 |
+ |
quot = *cp++; |
323 |
|
i = 0; |
324 |
< |
while (*cp && !isspace(*cp++)) |
325 |
< |
i++; |
324 |
> |
while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) { |
325 |
> |
i++; cp++; |
326 |
> |
} |
327 |
|
if (!i) |
328 |
|
break; |
329 |
< |
*--cp = '\0'; |
329 |
> |
if (!*cp) { |
330 |
> |
if (quot) |
331 |
> |
break; |
332 |
> |
cp[1] = '\0'; |
333 |
> |
} |
334 |
> |
*cp = '\0'; |
335 |
|
p->outfn = savqstr(cp-i); |
336 |
< |
*cp++ = ' '; |
336 |
> |
*cp++ = quot ? quot : ' '; |
337 |
|
++nparams; |
338 |
|
continue; |
339 |
|
case ' ': |
346 |
|
default: |
347 |
|
break; |
348 |
|
} |
349 |
< |
fprintf(stderr, "%s: bad parameter string '%s'\n", progname, pargs); |
349 |
> |
break; |
350 |
> |
} |
351 |
> |
fprintf(stderr, "%s: bad parameter string: %s", progname, pargs); |
352 |
|
exit(1); |
353 |
|
return(-1); /* pro forma return */ |
354 |
|
} |
386 |
|
fputs(": undefined normal for hemisphere sampling\n", stderr); |
387 |
|
exit(1); |
388 |
|
} |
389 |
< |
if (normalize(curparams.vup) == 0) |
389 |
> |
if (normalize(curparams.vup) == 0) { |
390 |
|
if (fabs(curparams.nrm[2]) < .7) |
391 |
|
curparams.vup[2] = 1; |
392 |
|
else |
393 |
|
curparams.vup[1] = 1; |
394 |
+ |
} |
395 |
|
/* determine sample type/bin */ |
396 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
397 |
< |
binv = "0"; /* uniform sampling -- one bin */ |
396 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { |
397 |
> |
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
398 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
399 |
> |
binv = savqstr(sbuf); |
400 |
> |
nbins = "1"; /* uniform sampling -- one bin */ |
401 |
|
uniform = 1; |
402 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
403 |
|
tolower(curparams.hemis[1]) == 'c') { |
408 |
|
exit(1); |
409 |
|
} |
410 |
|
calfn = shirchiufn; shirchiufn = NULL; |
411 |
< |
sprintf(sbuf, "SCdim=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
411 |
> |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
412 |
|
curparams.hsiz, |
413 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
414 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
414 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
415 |
> |
curparams.sign); |
416 |
|
params = savqstr(sbuf); |
417 |
|
binv = "scbin"; |
418 |
|
nbins = "SCdim*SCdim"; |
419 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
420 |
|
(tolower(curparams.hemis[0]) == 't')) { |
421 |
|
calfn = reinhfn; reinhfn = NULL; |
422 |
< |
sprintf(sbuf, "MF=%d,Nx=%g,Ny=%g,Nz=%g,Ux=%g,Uy=%g,Uz=%g", |
422 |
> |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
423 |
|
curparams.hsiz, |
424 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
425 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
425 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
426 |
> |
curparams.sign); |
427 |
|
params = savqstr(sbuf); |
428 |
|
binv = "rbin"; |
429 |
|
nbins = "Nrbins"; |
451 |
|
progname, curparams.hemis); |
452 |
|
exit(1); |
453 |
|
} |
454 |
+ |
if (tolower(curparams.hemis[0]) == 'k') { |
455 |
+ |
sprintf(sbuf, "RHS=%c1", curparams.sign); |
456 |
+ |
params = savqstr(sbuf); |
457 |
+ |
} |
458 |
|
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
459 |
|
SURF *sp; |
460 |
|
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
502 |
|
{ |
503 |
|
int i; |
504 |
|
|
505 |
< |
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) { |
505 |
> |
if (!getperpendicular(uva[0], nrm, 1)) { |
506 |
|
fputs(progname, stderr); |
507 |
|
fputs(": bad surface normal in make_axes!\n", stderr); |
508 |
|
exit(1); |
509 |
|
} |
510 |
< |
uva[1][i] = 1.0; |
522 |
< |
VCROSS(uva[0], uva[1], nrm); |
523 |
< |
normalize(uva[0]); |
524 |
< |
VCROSS(uva[1], nrm, uva[0]); |
510 |
> |
fcross(uva[1], nrm, uva[0]); |
511 |
|
} |
512 |
|
|
513 |
|
/* Illegal sender surfaces end up here */ |
616 |
|
sp->priv = (void *)ptp; |
617 |
|
} |
618 |
|
/* pick triangle by partial area */ |
619 |
< |
for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) |
619 |
> |
for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) |
620 |
|
x -= ptp->tri[i].afrac; |
621 |
|
SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); |
622 |
|
samp2[0] *= samp2[1] = sqrt(samp2[1]); |
646 |
|
/* special case for lone surface */ |
647 |
|
if (p->nsurfs == 1) { |
648 |
|
sp = p->slist; |
649 |
< |
if (DOT(sp->snrm, rdir) >= -FTINY) { |
649 |
> |
if (DOT(sp->snrm, rdir) >= FTINY) { |
650 |
|
fprintf(stderr, |
651 |
|
"%s: internal - sample behind sender '%s'\n", |
652 |
|
progname, sp->sname); |
657 |
|
if (p->nsurfs > nall) { /* (re)allocate surface area cache */ |
658 |
|
if (projsa) free(projsa); |
659 |
|
projsa = (double *)malloc(sizeof(double)*p->nsurfs); |
660 |
< |
if (!projsa) return(0); |
660 |
> |
if (projsa == NULL) { |
661 |
> |
fputs(progname, stderr); |
662 |
> |
fputs(": out of memory in sample_origin!\n", stderr); |
663 |
> |
exit(1); |
664 |
> |
} |
665 |
|
nall = p->nsurfs; |
666 |
|
} |
667 |
|
/* compute projected areas */ |
669 |
|
projsa[i] = -DOT(sp->snrm, rdir) * sp->area; |
670 |
|
tarea += projsa[i] *= (double)(projsa[i] > FTINY); |
671 |
|
} |
672 |
< |
if (tarea <= FTINY) { /* wrong side of sender? */ |
672 |
> |
if (tarea < 0) { /* wrong side of sender? */ |
673 |
|
fputs(progname, stderr); |
674 |
|
fputs(": internal - sample behind all sender elements!\n", |
675 |
|
stderr); |
704 |
|
duvw[2]*p->nrm[i] ; |
705 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
706 |
|
return(0); |
707 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
707 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
708 |
|
return(0); |
709 |
|
} |
710 |
|
return(1); |
734 |
|
duvw[2]*p->nrm[i] ; |
735 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
736 |
|
return(0); |
737 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
737 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
738 |
|
return(0); |
739 |
|
} |
740 |
|
return(1); |
770 |
|
} |
771 |
|
while (n--) { /* stratified sampling */ |
772 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
773 |
+ |
if (row >= RowMax-1) /* avoid crowding at zenith */ |
774 |
+ |
samp3[1] *= samp3[1]; |
775 |
|
alt = (row+samp3[1])*RAH; |
776 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
777 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
778 |
< |
duvw[0] = tcos(azi)*duvw[2]; |
779 |
< |
duvw[1] = tsin(azi)*duvw[2]; |
778 |
> |
duvw[0] = tsin(azi)*duvw[2]; |
779 |
> |
duvw[1] = -tcos(azi)*duvw[2]; |
780 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
781 |
|
for (i = 3; i--; ) |
782 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
784 |
|
duvw[2]*p->nrm[i] ; |
785 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
786 |
|
return(0); |
787 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
787 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
788 |
|
return(0); |
789 |
|
} |
790 |
|
return(1); |
827 |
|
|
828 |
|
while (n--) { /* stratified sampling */ |
829 |
|
SDmultiSamp(samp2, 2, (n+frandom())/sampcnt); |
830 |
< |
if (!bo_getvec(duvw, b+samp2[1], kbasis[bi])) |
830 |
> |
if (!fo_getvec(duvw, b+samp2[1], kbasis[bi])) |
831 |
|
return(0); |
832 |
|
for (i = 3; i--; ) |
833 |
< |
orig_dir[1][i] = duvw[0]*p->udir[i] + |
834 |
< |
duvw[1]*p->vdir[i] + |
833 |
> |
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
834 |
> |
duvw[1]*p->vdir[i] - |
835 |
|
duvw[2]*p->nrm[i] ; |
836 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
837 |
|
return(0); |
838 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
838 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
839 |
|
return(0); |
840 |
|
} |
841 |
|
return(1); |
850 |
|
fputs(": no sender surface!\n", stderr); |
851 |
|
return(-1); |
852 |
|
} |
853 |
< |
if (curparams.outfn != NULL) /* misplaced output file spec. */ |
853 |
> |
/* misplaced output file spec. */ |
854 |
> |
if ((curparams.outfn != NULL) & (verbose >= 0)) |
855 |
|
fprintf(stderr, "%s: warning - ignoring output file in sender ('%s')\n", |
856 |
|
progname, curparams.outfn); |
857 |
|
/* check/set basis hemisphere */ |
865 |
|
fputs(": undefined normal for sender sampling\n", stderr); |
866 |
|
return(-1); |
867 |
|
} |
868 |
< |
if (normalize(curparams.vup) == 0) |
868 |
> |
if (normalize(curparams.vup) == 0) { |
869 |
|
if (fabs(curparams.nrm[2]) < .7) |
870 |
|
curparams.vup[2] = 1; |
871 |
|
else |
872 |
|
curparams.vup[1] = 1; |
873 |
< |
VCROSS(curparams.udir, curparams.vup, curparams.nrm); |
873 |
> |
} |
874 |
> |
fcross(curparams.udir, curparams.vup, curparams.nrm); |
875 |
|
if (normalize(curparams.udir) == 0) { |
876 |
|
fputs(progname, stderr); |
877 |
|
fputs(": up vector coincides with sender normal\n", stderr); |
878 |
|
return(-1); |
879 |
|
} |
880 |
< |
VCROSS(curparams.vdir, curparams.nrm, curparams.udir); |
881 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
880 |
> |
fcross(curparams.vdir, curparams.nrm, curparams.udir); |
881 |
> |
if (curparams.sign == '-') { /* left-handed coordinate system? */ |
882 |
> |
curparams.udir[0] *= -1.; |
883 |
> |
curparams.udir[1] *= -1.; |
884 |
> |
curparams.udir[2] *= -1.; |
885 |
> |
} |
886 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
887 |
|
curparams.sample_basis = sample_uniform; |
888 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
889 |
|
tolower(curparams.hemis[1]) == 'c') |
962 |
|
snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1)); |
963 |
|
if (snew == NULL) { |
964 |
|
fputs(progname, stderr); |
965 |
< |
fputs(": out of memory!\n", stderr); |
965 |
> |
fputs(": out of memory in add_surface!\n", stderr); |
966 |
|
exit(1); |
967 |
|
} |
968 |
|
strncpy(snew->sname, oname, sizeof(snew->sname)-1); |
999 |
|
case ST_SOURCE: |
1000 |
|
if (snew->nfargs != 4) |
1001 |
|
goto badcount; |
1002 |
< |
VCOPY(snew->snrm, snew->farg); |
1002 |
> |
for (n = 3; n--; ) /* need to reverse "normal" */ |
1003 |
> |
snew->snrm[n] = -snew->farg[n]; |
1004 |
|
if (normalize(snew->snrm) == 0) |
1005 |
|
goto badnorm; |
1006 |
|
snew->area = sin((PI/180./2.)*snew->farg[3]); |
1007 |
|
snew->area *= PI*snew->area; |
1008 |
|
break; |
1009 |
|
} |
1010 |
< |
if (snew->area <= FTINY) { |
1010 |
> |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
1011 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
1012 |
|
progname, oname); |
1013 |
|
free(snew); |
1063 |
|
return(1); |
1064 |
|
} |
1065 |
|
/* else skip arguments */ |
1066 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1066 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1067 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
1068 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1068 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1069 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
1070 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1070 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1071 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
1072 |
|
return(0); |
1073 |
|
} |
1077 |
|
add_send_object(FILE *fp) |
1078 |
|
{ |
1079 |
|
int st; |
1080 |
< |
char otype[32], oname[128]; |
1080 |
> |
char thismod[128], otype[32], oname[128]; |
1081 |
|
int n; |
1082 |
|
|
1083 |
< |
if (fscanf(fp, "%*s %s %s", otype, oname) != 2) |
1083 |
> |
if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3) |
1084 |
|
return(0); /* must have hit EOF! */ |
1085 |
|
if (!strcmp(otype, "alias")) { |
1086 |
|
fscanf(fp, "%*s"); /* skip alias */ |
1093 |
|
fputs(": cannot use source as a sender!\n", stderr); |
1094 |
|
return(-1); |
1095 |
|
} |
1096 |
+ |
if (strcmp(thismod, curmod)) { |
1097 |
+ |
if (curmod[0]) { |
1098 |
+ |
fputs(progname, stderr); |
1099 |
+ |
fputs(": warning - multiple modifiers in sender\n", |
1100 |
+ |
stderr); |
1101 |
+ |
} |
1102 |
+ |
strcpy(curmod, thismod); |
1103 |
+ |
} |
1104 |
|
parse_params(&curparams, newparams); |
1105 |
|
newparams[0] = '\0'; |
1106 |
|
add_surface(st, oname, fp); /* read & store surface */ |
1107 |
|
return(0); |
1108 |
|
} |
1109 |
|
/* else skip arguments */ |
1110 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1110 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1111 |
|
while (n-- > 0) fscanf(fp, "%*s"); |
1112 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1112 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1113 |
|
while (n-- > 0) fscanf(fp, "%*d"); |
1114 |
< |
if (!fscanf(fp, "%d", &n)) return; |
1114 |
> |
if (!fscanf(fp, "%d", &n)) return(0); |
1115 |
|
while (n-- > 0) fscanf(fp, "%*f"); |
1116 |
|
return(0); |
1117 |
|
} |
1154 |
|
strcat(newparams, inpbuf); |
1155 |
|
continue; |
1156 |
|
} |
1157 |
< |
while ((c = getc(fp)) != EOF && c != '\n'); |
1157 |
> |
while ((c = getc(fp)) != EOF && c != '\n') |
1158 |
|
; /* else skipping comment */ |
1159 |
|
continue; |
1160 |
|
} |
1179 |
|
{ |
1180 |
|
char fmtopt[6] = "-faa"; /* default output is ASCII */ |
1181 |
|
char *xrs=NULL, *yrs=NULL, *ldopt=NULL; |
1182 |
+ |
char *iropt = NULL; |
1183 |
|
char *sendfn; |
1184 |
|
char sampcntbuf[32], nsbinbuf[32]; |
1185 |
|
FILE *rcfp; |
1187 |
|
int a, i; |
1188 |
|
/* screen rcontrib options */ |
1189 |
|
progname = argv[0]; |
1190 |
< |
for (a = 1; a < argc-2 && argv[a][0] == '-'; a++) { |
1191 |
< |
int na = 1; /* !! Keep consistent !! */ |
1192 |
< |
switch (argv[a][1]) { |
1190 |
> |
for (a = 1; a < argc-2; a++) { |
1191 |
> |
int na; |
1192 |
> |
/* check for argument expansion */ |
1193 |
> |
while ((na = expandarg(&argc, &argv, a)) > 0) |
1194 |
> |
; |
1195 |
> |
if (na < 0) { |
1196 |
> |
fprintf(stderr, "%s: cannot expand '%s'\n", |
1197 |
> |
progname, argv[a]); |
1198 |
> |
return(1); |
1199 |
> |
} |
1200 |
> |
if (argv[a][0] != '-' || !argv[a][1]) |
1201 |
> |
break; |
1202 |
> |
na = 1; |
1203 |
> |
switch (argv[a][1]) { /* !! Keep consistent !! */ |
1204 |
|
case 'v': /* verbose mode */ |
1205 |
< |
verbose = !verbose; |
1205 |
> |
verbose = 1; |
1206 |
|
na = 0; |
1207 |
|
continue; |
1208 |
|
case 'f': /* special case for -fo, -ff, etc. */ |
1238 |
|
goto userr; |
1239 |
|
na = 0; /* we re-add this later */ |
1240 |
|
continue; |
1241 |
< |
case 'V': /* options without arguments */ |
1222 |
< |
case 'w': |
1223 |
< |
case 'u': |
1241 |
> |
case 'I': /* only for pass-through mode */ |
1242 |
|
case 'i': |
1243 |
+ |
iropt = argv[a]; |
1244 |
+ |
na = 0; |
1245 |
+ |
continue; |
1246 |
+ |
case 'w': /* options without arguments */ |
1247 |
+ |
if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL) |
1248 |
+ |
verbose = -1; |
1249 |
+ |
break; |
1250 |
+ |
case 'V': |
1251 |
+ |
case 'u': |
1252 |
|
case 'h': |
1253 |
|
case 'r': |
1254 |
|
break; |
1272 |
|
if (argv[a][2] != 'v') na = 2; |
1273 |
|
break; |
1274 |
|
case 'a': /* special case */ |
1275 |
< |
na = (argv[a][2] == 'v') ? 4 : 2; |
1275 |
> |
if (argv[a][2] == 'p') { |
1276 |
> |
na = 2; /* photon map [+ bandwidth(s)] */ |
1277 |
> |
if (a < argc-3 && atoi(argv[a+1]) > 0) |
1278 |
> |
na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0); |
1279 |
> |
} else |
1280 |
> |
na = (argv[a][2] == 'v') ? 4 : 2; |
1281 |
|
break; |
1282 |
|
case 'm': /* special case */ |
1283 |
|
if (!argv[a][2]) goto userr; |
1284 |
|
na = (argv[a][2] == 'e') | (argv[a][2] == 'a') ? 4 : 2; |
1285 |
|
break; |
1254 |
– |
case '\0': /* pass-through mode */ |
1255 |
– |
goto done_opts; |
1286 |
|
default: /* anything else is verbotten */ |
1287 |
|
goto userr; |
1288 |
|
} |
1292 |
|
while (--na) /* + arguments if any */ |
1293 |
|
rcarg[nrcargs++] = argv[++a]; |
1294 |
|
} |
1265 |
– |
done_opts: |
1295 |
|
if (a > argc-2) |
1296 |
|
goto userr; /* check at end of options */ |
1297 |
|
sendfn = argv[a++]; /* assign sender & receiver inputs */ |
1298 |
|
if (sendfn[0] == '-') { /* user wants pass-through mode? */ |
1299 |
|
if (sendfn[1]) goto userr; |
1300 |
|
sendfn = NULL; |
1301 |
+ |
if (iropt) { |
1302 |
+ |
CHECKARGC(1); |
1303 |
+ |
rcarg[nrcargs++] = iropt; |
1304 |
+ |
} |
1305 |
|
if (xrs) { |
1306 |
|
CHECKARGC(2); |
1307 |
|
rcarg[nrcargs++] = "-x"; |
1317 |
|
rcarg[nrcargs++] = ldopt; |
1318 |
|
} |
1319 |
|
if (sampcnt <= 0) sampcnt = 1; |
1320 |
< |
} else { /* else FVECT determines input format */ |
1321 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1320 |
> |
} else { /* else in sampling mode */ |
1321 |
> |
if (iropt) { |
1322 |
> |
fputs(progname, stderr); |
1323 |
> |
fputs(": -i, -I supported for pass-through only\n", stderr); |
1324 |
> |
return(1); |
1325 |
> |
} |
1326 |
> |
#ifdef SMLFLT |
1327 |
> |
fmtopt[2] = 'f'; |
1328 |
> |
#else |
1329 |
> |
fmtopt[2] = 'd'; |
1330 |
> |
#endif |
1331 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1332 |
|
} |
1333 |
|
sprintf(sampcntbuf, "%d", sampcnt); |
1346 |
|
return(my_exec(rcarg)); /* rcontrib does everything */ |
1347 |
|
} |
1348 |
|
clear_params(&curparams, 0); /* else load sender surface & params */ |
1349 |
+ |
curmod[0] = '\0'; |
1350 |
|
if (load_scene(sendfn, add_send_object) < 0) |
1351 |
|
return(1); |
1352 |
|
if ((nsbins = prepare_sampler()) <= 0) |
1364 |
|
#ifdef getc_unlocked |
1365 |
|
flockfile(rcfp); |
1366 |
|
#endif |
1367 |
< |
if (verbose) { |
1367 |
> |
if (verbose > 0) { |
1368 |
|
fprintf(stderr, "%s: sampling %d directions", progname, nsbins); |
1369 |
|
if (curparams.nsurfs > 1) |
1370 |
|
fprintf(stderr, " (%d elements)\n", curparams.nsurfs); |
1374 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
1375 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
1376 |
|
return(1); |
1377 |
< |
return(pclose(rcfp) == 0); /* all finished! */ |
1377 |
> |
return(pclose(rcfp) < 0); /* all finished! */ |
1378 |
|
userr: |
1379 |
|
if (a < argc-2) |
1380 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |
1381 |
< |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [system.rad ..]\n", |
1381 |
> |
fprintf(stderr, "Usage: %s [-v][rcontrib options] sender.rad receiver.rad [-i system.oct] [system.rad ..]\n", |
1382 |
|
progname); |
1383 |
|
return(1); |
1384 |
|
} |