18 |
|
#include "triangulate.h" |
19 |
|
#include "platform.h" |
20 |
|
|
21 |
< |
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
22 |
< |
#undef getc |
23 |
< |
#define getc getc_unlocked |
21 |
> |
#ifndef MAXRCARG |
22 |
> |
#define MAXRCARG 10000 |
23 |
|
#endif |
24 |
|
|
26 |
– |
#ifdef _WIN32 |
27 |
– |
#define SPECIALS " \t\"$*?" |
28 |
– |
#define QUOTCHAR '"' |
29 |
– |
#else |
30 |
– |
#define SPECIALS " \t\n'\"()${}*?[];|&" |
31 |
– |
#define QUOTCHAR '\'' |
32 |
– |
#define ALTQUOT '"' |
33 |
– |
#endif |
34 |
– |
|
35 |
– |
#define MAXRCARG 512 |
36 |
– |
|
25 |
|
char *progname; /* global argv[0] */ |
26 |
|
|
27 |
|
int verbose = 0; /* verbose mode (< 0 no warnings) */ |
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 */ |
140 |
|
|
141 |
|
if (ac-- <= 0) |
142 |
|
return(NULL); |
143 |
< |
while (ac-- > 0) { |
144 |
< |
strcpy(cp, *av++); |
145 |
< |
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 |
< |
} |
143 |
> |
if (verbose < 0) { /* turn off warnings */ |
144 |
> |
strcpy(cp, "-w "); |
145 |
> |
cp += 3; |
146 |
|
} |
147 |
< |
strcpy(cp, recv); /* receiver goes last */ |
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) { |
173 |
< |
const char *cp = str2; |
174 |
< |
while (*cp) |
175 |
< |
if (*cp++ == *str1) |
176 |
< |
return(*str1); |
177 |
< |
++str1; |
178 |
< |
} |
179 |
< |
return(0); |
180 |
< |
} |
181 |
< |
|
182 |
< |
|
183 |
< |
/* Convert a set of arguments into a command line for pipe() or system() */ |
184 |
< |
static char * |
185 |
< |
convert_commandline(char *cmd, const int len, char *av[]) |
186 |
< |
{ |
187 |
< |
int match; |
188 |
< |
char *cp; |
189 |
< |
|
190 |
< |
for (cp = cmd; *av != NULL; av++) { |
191 |
< |
const int n = strlen(*av); |
192 |
< |
if (cp+n >= cmd+(len-3)) { |
193 |
< |
fputs(progname, stderr); |
194 |
< |
return(NULL); |
195 |
< |
} |
196 |
< |
if ((match = matchany(*av, SPECIALS))) { |
197 |
< |
const int quote = |
198 |
< |
#ifdef ALTQUOT |
199 |
< |
(match == QUOTCHAR) ? ALTQUOT : |
200 |
< |
#endif |
201 |
< |
QUOTCHAR; |
202 |
< |
*cp++ = quote; |
203 |
< |
strcpy(cp, *av); |
204 |
< |
cp += n; |
205 |
< |
*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 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
182 |
+ |
|
183 |
|
/* Open a pipe to/from a command given as an argument list */ |
184 |
|
static FILE * |
185 |
|
popen_arglist(char *av[], char *mode) |
197 |
|
return(popen(cmd, mode)); |
198 |
|
} |
199 |
|
|
200 |
< |
#ifdef _WIN32 |
200 |
> |
#define pclose_al pclose |
201 |
> |
|
202 |
|
/* Execute system command (Windows version) */ |
203 |
|
static int |
204 |
|
my_exec(char *av[]) |
214 |
|
fprintf(stderr, "%s: running: %s\n", progname, cmd); |
215 |
|
return(system(cmd)); |
216 |
|
} |
217 |
< |
#else |
217 |
> |
|
218 |
> |
#else /* UNIX */ |
219 |
> |
|
220 |
> |
static SUBPROC rt_proc = SP_INACTIVE; /* we only support one of these */ |
221 |
> |
|
222 |
> |
/* Open a pipe to a command using an argument list */ |
223 |
> |
static FILE * |
224 |
> |
popen_arglist(char *av[], char *mode) |
225 |
> |
{ |
226 |
> |
int fd; |
227 |
> |
|
228 |
> |
if (rt_proc.pid > 0) { |
229 |
> |
fprintf(stderr, "%s: only one i/o pipe at a time!\n", progname); |
230 |
> |
return(NULL); |
231 |
> |
} |
232 |
> |
if (verbose > 0) { |
233 |
> |
char cmd[4096]; |
234 |
> |
if (!convert_commandline(cmd, sizeof(cmd), av)) |
235 |
> |
strcpy(cmd, "COMMAND TOO LONG TO SHOW"); |
236 |
> |
fprintf(stderr, "%s: opening pipe %s: %s\n", |
237 |
> |
progname, (*mode=='w') ? "to" : "from", cmd); |
238 |
> |
} |
239 |
> |
if (*mode == 'w') { |
240 |
> |
fd = rt_proc.w = dup(fileno(stdout)); |
241 |
> |
rt_proc.flags |= PF_FILT_OUT; |
242 |
> |
} else if (*mode == 'r') { |
243 |
> |
fd = rt_proc.r = dup(fileno(stdin)); |
244 |
> |
rt_proc.flags |= PF_FILT_INP; |
245 |
> |
} |
246 |
> |
if (fd < 0 || open_process(&rt_proc, av) <= 0) { |
247 |
> |
perror(av[0]); |
248 |
> |
return(NULL); |
249 |
> |
} |
250 |
> |
return(fdopen(fd, mode)); |
251 |
> |
} |
252 |
> |
|
253 |
> |
/* Close command pipe (returns -1 on error to match pclose) */ |
254 |
> |
static int |
255 |
> |
pclose_al(FILE *fp) |
256 |
> |
{ |
257 |
> |
int prob = (fclose(fp) == EOF); |
258 |
> |
|
259 |
> |
if (rt_proc.pid <= 0) |
260 |
> |
return(-1); |
261 |
> |
|
262 |
> |
prob |= (close_process(&rt_proc) != 0); |
263 |
> |
|
264 |
> |
return(-prob); |
265 |
> |
} |
266 |
> |
|
267 |
|
/* Execute system command in our stead (Unix version) */ |
268 |
|
static int |
269 |
|
my_exec(char *av[]) |
284 |
|
perror(compath); |
285 |
|
return(1); |
286 |
|
} |
287 |
+ |
|
288 |
|
#endif |
289 |
|
|
290 |
|
/* Get normalized direction vector from string specification */ |
333 |
|
{ |
334 |
|
char *cp = pargs; |
335 |
|
int nparams = 0; |
336 |
+ |
int quot; |
337 |
|
int i; |
338 |
|
|
339 |
|
for ( ; ; ) { |
341 |
|
case 'h': |
342 |
|
if (*cp++ != '=') |
343 |
|
break; |
344 |
+ |
if ((*cp == '+') | (*cp == '-')) |
345 |
+ |
p->sign = *cp++; |
346 |
+ |
else |
347 |
+ |
p->sign = '+'; |
348 |
|
p->hsiz = 0; |
349 |
|
i = 0; |
350 |
|
while (*cp && !isspace(*cp)) { |
370 |
|
case 'o': |
371 |
|
if (*cp++ != '=') |
372 |
|
break; |
373 |
+ |
quot = 0; |
374 |
+ |
if ((*cp == '"') | (*cp == '\'')) |
375 |
+ |
quot = *cp++; |
376 |
|
i = 0; |
377 |
< |
while (*cp && !isspace(*cp++)) |
378 |
< |
i++; |
377 |
> |
while (*cp && (quot ? (*cp != quot) : !isspace(*cp))) { |
378 |
> |
i++; cp++; |
379 |
> |
} |
380 |
|
if (!i) |
381 |
|
break; |
382 |
< |
*--cp = '\0'; |
382 |
> |
if (!*cp) { |
383 |
> |
if (quot) |
384 |
> |
break; |
385 |
> |
cp[1] = '\0'; |
386 |
> |
} |
387 |
> |
*cp = '\0'; |
388 |
|
p->outfn = savqstr(cp-i); |
389 |
< |
*cp++ = ' '; |
389 |
> |
*cp++ = quot ? quot : ' '; |
390 |
|
++nparams; |
391 |
|
continue; |
392 |
|
case ' ': |
393 |
|
case '\t': |
394 |
|
case '\r': |
365 |
– |
continue; |
395 |
|
case '\n': |
396 |
+ |
continue; |
397 |
|
case '\0': |
398 |
|
return(nparams); |
399 |
|
default: |
446 |
|
curparams.vup[1] = 1; |
447 |
|
} |
448 |
|
/* determine sample type/bin */ |
449 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
450 |
< |
binv = "0"; /* uniform sampling -- one bin */ |
449 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { |
450 |
> |
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
451 |
> |
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
452 |
> |
binv = savqstr(sbuf); |
453 |
> |
nbins = "1"; /* uniform sampling -- one bin */ |
454 |
|
uniform = 1; |
455 |
|
} else if (tolower(curparams.hemis[0]) == 's' && |
456 |
|
tolower(curparams.hemis[1]) == 'c') { |
461 |
|
exit(1); |
462 |
|
} |
463 |
|
calfn = shirchiufn; shirchiufn = NULL; |
464 |
< |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", |
464 |
> |
sprintf(sbuf, "SCdim=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
465 |
|
curparams.hsiz, |
466 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
467 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
467 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
468 |
> |
curparams.sign); |
469 |
|
params = savqstr(sbuf); |
470 |
|
binv = "scbin"; |
471 |
|
nbins = "SCdim*SCdim"; |
472 |
|
} else if ((tolower(curparams.hemis[0]) == 'r') | |
473 |
|
(tolower(curparams.hemis[0]) == 't')) { |
474 |
|
calfn = reinhfn; reinhfn = NULL; |
475 |
< |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g", |
475 |
> |
sprintf(sbuf, "MF=%d,rNx=%g,rNy=%g,rNz=%g,Ux=%g,Uy=%g,Uz=%g,RHS=%c1", |
476 |
|
curparams.hsiz, |
477 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2], |
478 |
< |
curparams.vup[0], curparams.vup[1], curparams.vup[2]); |
478 |
> |
curparams.vup[0], curparams.vup[1], curparams.vup[2], |
479 |
> |
curparams.sign); |
480 |
|
params = savqstr(sbuf); |
481 |
|
binv = "rbin"; |
482 |
|
nbins = "Nrbins"; |
504 |
|
progname, curparams.hemis); |
505 |
|
exit(1); |
506 |
|
} |
507 |
+ |
if (tolower(curparams.hemis[0]) == 'k') { |
508 |
+ |
sprintf(sbuf, "RHS=%c1", curparams.sign); |
509 |
+ |
params = savqstr(sbuf); |
510 |
+ |
} |
511 |
|
if (!uniform & (curparams.slist->styp == ST_SOURCE)) { |
512 |
|
SURF *sp; |
513 |
|
for (sp = curparams.slist; sp != NULL; sp = sp->next) |
555 |
|
{ |
556 |
|
int i; |
557 |
|
|
558 |
< |
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) { |
558 |
> |
if (!getperpendicular(uva[0], nrm, 1)) { |
559 |
|
fputs(progname, stderr); |
560 |
|
fputs(": bad surface normal in make_axes!\n", stderr); |
561 |
|
exit(1); |
562 |
|
} |
563 |
< |
uva[1][i] = 1.0; |
531 |
< |
VCROSS(uva[0], uva[1], nrm); |
532 |
< |
normalize(uva[0]); |
533 |
< |
VCROSS(uva[1], nrm, uva[0]); |
563 |
> |
fcross(uva[1], nrm, uva[0]); |
564 |
|
} |
565 |
|
|
566 |
|
/* Illegal sender surfaces end up here */ |
669 |
|
sp->priv = (void *)ptp; |
670 |
|
} |
671 |
|
/* pick triangle by partial area */ |
672 |
< |
for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) |
672 |
> |
for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) |
673 |
|
x -= ptp->tri[i].afrac; |
674 |
|
SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); |
675 |
|
samp2[0] *= samp2[1] = sqrt(samp2[1]); |
699 |
|
/* special case for lone surface */ |
700 |
|
if (p->nsurfs == 1) { |
701 |
|
sp = p->slist; |
702 |
< |
if (DOT(sp->snrm, rdir) >= -FTINY) { |
702 |
> |
if (DOT(sp->snrm, rdir) >= FTINY) { |
703 |
|
fprintf(stderr, |
704 |
|
"%s: internal - sample behind sender '%s'\n", |
705 |
|
progname, sp->sname); |
710 |
|
if (p->nsurfs > nall) { /* (re)allocate surface area cache */ |
711 |
|
if (projsa) free(projsa); |
712 |
|
projsa = (double *)malloc(sizeof(double)*p->nsurfs); |
713 |
< |
if (!projsa) return(0); |
713 |
> |
if (projsa == NULL) { |
714 |
> |
fputs(progname, stderr); |
715 |
> |
fputs(": out of memory in sample_origin!\n", stderr); |
716 |
> |
exit(1); |
717 |
> |
} |
718 |
|
nall = p->nsurfs; |
719 |
|
} |
720 |
|
/* compute projected areas */ |
721 |
|
for (i = 0, sp = p->slist; sp != NULL; i++, sp = sp->next) { |
722 |
|
projsa[i] = -DOT(sp->snrm, rdir) * sp->area; |
723 |
< |
tarea += projsa[i] *= (double)(projsa[i] > FTINY); |
723 |
> |
tarea += projsa[i] *= (double)(projsa[i] > 0); |
724 |
|
} |
725 |
< |
if (tarea <= FTINY) { /* wrong side of sender? */ |
725 |
> |
if (tarea < FTINY*FTINY) { /* wrong side of sender? */ |
726 |
|
fputs(progname, stderr); |
727 |
|
fputs(": internal - sample behind all sender elements!\n", |
728 |
|
stderr); |
740 |
|
{ |
741 |
|
int n = sampcnt; |
742 |
|
double samp3[3]; |
743 |
< |
double duvw[3]; |
710 |
< |
FVECT orig_dir[2]; |
743 |
> |
FVECT duvw, orig_dir[2]; |
744 |
|
int i; |
745 |
|
|
746 |
|
if (fp == NULL) /* just requesting number of bins? */ |
748 |
|
|
749 |
|
while (n--) { /* stratified hemisphere sampling */ |
750 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
751 |
< |
SDsquare2disk(duvw, samp3[1], samp3[2]); |
751 |
> |
square2disk(duvw, samp3[1], samp3[2]); |
752 |
|
duvw[2] = -sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]); |
753 |
|
for (i = 3; i--; ) |
754 |
|
orig_dir[1][i] = duvw[0]*p->udir[i] + |
756 |
|
duvw[2]*p->nrm[i] ; |
757 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
758 |
|
return(0); |
759 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
759 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
760 |
|
return(0); |
761 |
|
} |
762 |
|
return(1); |
768 |
|
{ |
769 |
|
int n = sampcnt; |
770 |
|
double samp3[3]; |
771 |
< |
double duvw[3]; |
739 |
< |
FVECT orig_dir[2]; |
771 |
> |
FVECT duvw, orig_dir[2]; |
772 |
|
int i; |
773 |
|
|
774 |
|
if (fp == NULL) /* just requesting number of bins? */ |
776 |
|
|
777 |
|
while (n--) { /* stratified sampling */ |
778 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
779 |
< |
SDsquare2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz, |
779 |
> |
square2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz, |
780 |
|
(b%p->hsiz + samp3[2])/curparams.hsiz); |
781 |
|
duvw[2] = sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]); |
782 |
|
for (i = 3; i--; ) |
785 |
|
duvw[2]*p->nrm[i] ; |
786 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
787 |
|
return(0); |
788 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
788 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
789 |
|
return(0); |
790 |
|
} |
791 |
|
return(1); |
821 |
|
} |
822 |
|
while (n--) { /* stratified sampling */ |
823 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
824 |
+ |
if (row >= RowMax-1) /* avoid crowding at zenith */ |
825 |
+ |
samp3[1] *= samp3[1]; |
826 |
|
alt = (row+samp3[1])*RAH; |
827 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
828 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
829 |
|
duvw[0] = tsin(azi)*duvw[2]; |
830 |
< |
duvw[1] = tcos(azi)*duvw[2]; |
830 |
> |
duvw[1] = -tcos(azi)*duvw[2]; |
831 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
832 |
|
for (i = 3; i--; ) |
833 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
835 |
|
duvw[2]*p->nrm[i] ; |
836 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[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); |
878 |
|
|
879 |
|
while (n--) { /* stratified sampling */ |
880 |
|
SDmultiSamp(samp2, 2, (n+frandom())/sampcnt); |
881 |
< |
if (!bi_getvec(duvw, b+samp2[1], kbasis[bi])) |
881 |
> |
if (!fo_getvec(duvw, b+samp2[1], kbasis[bi])) |
882 |
|
return(0); |
883 |
|
for (i = 3; i--; ) |
884 |
< |
orig_dir[1][i] = duvw[0]*p->udir[i] + |
885 |
< |
duvw[1]*p->vdir[i] + |
884 |
> |
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
885 |
> |
duvw[1]*p->vdir[i] - |
886 |
|
duvw[2]*p->nrm[i] ; |
887 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
888 |
|
return(0); |
889 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
889 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
890 |
|
return(0); |
891 |
|
} |
892 |
|
return(1); |
922 |
|
else |
923 |
|
curparams.vup[1] = 1; |
924 |
|
} |
925 |
< |
VCROSS(curparams.udir, curparams.vup, curparams.nrm); |
925 |
> |
fcross(curparams.udir, curparams.vup, curparams.nrm); |
926 |
|
if (normalize(curparams.udir) == 0) { |
927 |
|
fputs(progname, stderr); |
928 |
|
fputs(": up vector coincides with sender normal\n", stderr); |
929 |
|
return(-1); |
930 |
|
} |
931 |
< |
VCROSS(curparams.vdir, curparams.nrm, curparams.udir); |
932 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
931 |
> |
fcross(curparams.vdir, curparams.nrm, curparams.udir); |
932 |
> |
if (curparams.sign == '-') { /* left-handed coordinate system? */ |
933 |
> |
curparams.udir[0] *= -1.; |
934 |
> |
curparams.udir[1] *= -1.; |
935 |
> |
curparams.udir[2] *= -1.; |
936 |
> |
} |
937 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
938 |
|
curparams.sample_basis = sample_uniform; |
939 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
940 |
|
tolower(curparams.hemis[1]) == 'c') |
995 |
|
VCOPY(e1, e2); |
996 |
|
} |
997 |
|
p->area = normalize(p->snrm)*0.5; |
998 |
< |
return(p->area > FTINY); |
998 |
> |
return(p->area > FTINY*FTINY); |
999 |
|
} |
1000 |
|
|
1001 |
|
/* Add a surface to our current parameters */ |
1013 |
|
snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1)); |
1014 |
|
if (snew == NULL) { |
1015 |
|
fputs(progname, stderr); |
1016 |
< |
fputs(": out of memory!\n", stderr); |
1016 |
> |
fputs(": out of memory in add_surface!\n", stderr); |
1017 |
|
exit(1); |
1018 |
|
} |
1019 |
|
strncpy(snew->sname, oname, sizeof(snew->sname)-1); |
1058 |
|
snew->area *= PI*snew->area; |
1059 |
|
break; |
1060 |
|
} |
1061 |
< |
if ((snew->area <= FTINY) & (verbose >= 0)) { |
1061 |
> |
if ((snew->area <= FTINY*FTINY) & (verbose >= 0)) { |
1062 |
|
fprintf(stderr, "%s: warning - zero area for surface '%s'\n", |
1063 |
|
progname, oname); |
1064 |
|
free(snew); |
1128 |
|
add_send_object(FILE *fp) |
1129 |
|
{ |
1130 |
|
int st; |
1131 |
< |
char otype[32], oname[128]; |
1131 |
> |
char thismod[128], otype[32], oname[128]; |
1132 |
|
int n; |
1133 |
|
|
1134 |
< |
if (fscanf(fp, "%*s %s %s", otype, oname) != 2) |
1134 |
> |
if (fscanf(fp, "%s %s %s", thismod, otype, oname) != 3) |
1135 |
|
return(0); /* must have hit EOF! */ |
1136 |
|
if (!strcmp(otype, "alias")) { |
1137 |
|
fscanf(fp, "%*s"); /* skip alias */ |
1144 |
|
fputs(": cannot use source as a sender!\n", stderr); |
1145 |
|
return(-1); |
1146 |
|
} |
1147 |
+ |
if (strcmp(thismod, curmod)) { |
1148 |
+ |
if (curmod[0]) { |
1149 |
+ |
fputs(progname, stderr); |
1150 |
+ |
fputs(": warning - multiple modifiers in sender\n", |
1151 |
+ |
stderr); |
1152 |
+ |
} |
1153 |
+ |
strcpy(curmod, thismod); |
1154 |
+ |
} |
1155 |
|
parse_params(&curparams, newparams); |
1156 |
|
newparams[0] = '\0'; |
1157 |
|
add_surface(st, oname, fp); /* read & store surface */ |
1295 |
|
na = 0; |
1296 |
|
continue; |
1297 |
|
case 'w': /* options without arguments */ |
1298 |
< |
if (argv[a][2] != '+') verbose = -1; |
1298 |
> |
if (!argv[a][2] || strchr("+1tTyY", argv[a][2]) == NULL) |
1299 |
> |
verbose = -1; |
1300 |
> |
break; |
1301 |
|
case 'V': |
1302 |
|
case 'u': |
1303 |
|
case 'h': |
1306 |
|
case 'n': /* options with 1 argument */ |
1307 |
|
case 's': |
1308 |
|
case 'o': |
1309 |
+ |
case 't': |
1310 |
|
na = 2; |
1311 |
|
break; |
1312 |
|
case 'b': /* special case */ |
1324 |
|
if (argv[a][2] != 'v') na = 2; |
1325 |
|
break; |
1326 |
|
case 'a': /* special case */ |
1327 |
< |
na = (argv[a][2] == 'v') ? 4 : 2; |
1327 |
> |
if (argv[a][2] == 'p') { |
1328 |
> |
na = 2; /* photon map [+ bandwidth(s)] */ |
1329 |
> |
if (a < argc-3 && atoi(argv[a+1]) > 0) |
1330 |
> |
na += 1 + (a < argc-4 && atoi(argv[a+2]) > 0); |
1331 |
> |
} else |
1332 |
> |
na = (argv[a][2] == 'v') ? 4 : 2; |
1333 |
|
break; |
1334 |
|
case 'm': /* special case */ |
1335 |
|
if (!argv[a][2]) goto userr; |
1375 |
|
fputs(": -i, -I supported for pass-through only\n", stderr); |
1376 |
|
return(1); |
1377 |
|
} |
1378 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1378 |
> |
#ifdef SMLFLT |
1379 |
> |
fmtopt[2] = 'f'; |
1380 |
> |
#else |
1381 |
> |
fmtopt[2] = 'd'; |
1382 |
> |
#endif |
1383 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1384 |
|
} |
1385 |
|
sprintf(sampcntbuf, "%d", sampcnt); |
1398 |
|
return(my_exec(rcarg)); /* rcontrib does everything */ |
1399 |
|
} |
1400 |
|
clear_params(&curparams, 0); /* else load sender surface & params */ |
1401 |
+ |
curmod[0] = '\0'; |
1402 |
|
if (load_scene(sendfn, add_send_object) < 0) |
1403 |
|
return(1); |
1404 |
|
if ((nsbins = prepare_sampler()) <= 0) |
1416 |
|
#ifdef getc_unlocked |
1417 |
|
flockfile(rcfp); |
1418 |
|
#endif |
1419 |
< |
if (verbose) { |
1419 |
> |
if (verbose > 0) { |
1420 |
|
fprintf(stderr, "%s: sampling %d directions", progname, nsbins); |
1421 |
|
if (curparams.nsurfs > 1) |
1422 |
|
fprintf(stderr, " (%d elements)\n", curparams.nsurfs); |
1426 |
|
for (i = 0; i < nsbins; i++) /* send rcontrib ray samples */ |
1427 |
|
if (!(*curparams.sample_basis)(&curparams, i, rcfp)) |
1428 |
|
return(1); |
1429 |
< |
return(pclose(rcfp) == 0); /* all finished! */ |
1429 |
> |
return(pclose_al(rcfp) < 0); /* all finished! */ |
1430 |
|
userr: |
1431 |
|
if (a < argc-2) |
1432 |
|
fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]); |