11 |
|
#include <stdlib.h> |
12 |
|
#include "rtio.h" |
13 |
|
#include "rtmath.h" |
14 |
< |
#include "rtprocess.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 |
23 |
– |
#define getc getc_unlocked |
24 |
– |
#endif |
25 |
– |
|
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 |
– |
|
21 |
|
#define MAXRCARG 512 |
22 |
|
|
23 |
|
char *progname; /* global argv[0] */ |
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 */ |
128 |
|
return(ST_NONE); |
129 |
|
} |
130 |
|
|
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 |
– |
|
131 |
|
/* Add arguments to oconv command */ |
132 |
|
static char * |
133 |
|
oconv_command(int ac, char *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) { |
146 |
|
strcpy(cp, *av++); |
147 |
|
while (*cp) cp++; |
168 |
|
exit(1); |
169 |
|
} |
170 |
|
|
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[]) |
198 |
– |
{ |
199 |
– |
int match; |
200 |
– |
char *cp; |
201 |
– |
|
202 |
– |
for (cp = cmd; *av != NULL; av++) { |
203 |
– |
const int n = strlen(*av); |
204 |
– |
if (cp+n >= cmd+(len-3)) |
205 |
– |
return(NULL); |
206 |
– |
if (matchany(*av, SPECIALS)) { |
207 |
– |
const int quote = |
208 |
– |
#ifdef ALTQUOT |
209 |
– |
strchr(*av, QUOTCHAR) ? ALTQUOT : |
210 |
– |
#endif |
211 |
– |
QUOTCHAR; |
212 |
– |
*cp++ = quote; |
213 |
– |
strcpy(cp, *av); |
214 |
– |
cp += n; |
215 |
– |
*cp++ = quote; |
216 |
– |
} else { |
217 |
– |
strcpy(cp, *av); |
218 |
– |
cp += n; |
219 |
– |
} |
220 |
– |
*cp++ = ' '; |
221 |
– |
} |
222 |
– |
if (cp <= cmd) |
223 |
– |
return(NULL); |
224 |
– |
*--cp = '\0'; |
225 |
– |
return(cmd); |
226 |
– |
} |
227 |
– |
|
171 |
|
/* Open a pipe to/from a command given as an argument list */ |
172 |
|
static FILE * |
173 |
|
popen_arglist(char *av[], char *mode) |
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[]) |
383 |
|
curparams.vup[1] = 1; |
384 |
|
} |
385 |
|
/* determine sample type/bin */ |
386 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
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); |
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]); |
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); |
760 |
|
} |
761 |
|
while (n--) { /* stratified sampling */ |
762 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
763 |
+ |
if (row >= RowMax-1) /* avoid crowding at zenith */ |
764 |
+ |
samp3[1] *= samp3[1]; |
765 |
|
alt = (row+samp3[1])*RAH; |
766 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
767 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
768 |
|
duvw[0] = tsin(azi)*duvw[2]; |
769 |
< |
duvw[1] = tcos(azi)*duvw[2]; |
769 |
> |
duvw[1] = -tcos(azi)*duvw[2]; |
770 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
771 |
|
for (i = 3; i--; ) |
772 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
774 |
|
duvw[2]*p->nrm[i] ; |
775 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
776 |
|
return(0); |
777 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
777 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
778 |
|
return(0); |
779 |
|
} |
780 |
|
return(1); |
825 |
|
duvw[2]*p->nrm[i] ; |
826 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
827 |
|
return(0); |
828 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
828 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
829 |
|
return(0); |
830 |
|
} |
831 |
|
return(1); |
873 |
|
curparams.udir[1] *= -1.; |
874 |
|
curparams.udir[2] *= -1.; |
875 |
|
} |
876 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
876 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
877 |
|
curparams.sample_basis = sample_uniform; |
878 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
879 |
|
tolower(curparams.hemis[1]) == 'c') |
952 |
|
snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1)); |
953 |
|
if (snew == NULL) { |
954 |
|
fputs(progname, stderr); |
955 |
< |
fputs(": out of memory!\n", stderr); |
955 |
> |
fputs(": out of memory in add_surface!\n", stderr); |
956 |
|
exit(1); |
957 |
|
} |
958 |
|
strncpy(snew->sname, oname, sizeof(snew->sname)-1); |
1311 |
|
fputs(": -i, -I supported for pass-through only\n", stderr); |
1312 |
|
return(1); |
1313 |
|
} |
1314 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1314 |
> |
#ifdef SMLFLT |
1315 |
> |
fmtopt[2] = 'f'; |
1316 |
> |
#else |
1317 |
> |
fmtopt[2] = 'd'; |
1318 |
> |
#endif |
1319 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1320 |
|
} |
1321 |
|
sprintf(sampcntbuf, "%d", sampcnt); |