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 |
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 */ |
130 |
|
return(ST_NONE); |
131 |
|
} |
132 |
|
|
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 |
– |
|
133 |
|
/* Add arguments to oconv command */ |
134 |
|
static char * |
135 |
|
oconv_command(int ac, char *av[]) |
140 |
|
|
141 |
|
if (ac-- <= 0) |
142 |
|
return(NULL); |
143 |
+ |
if (verbose < 0) { /* turn off warnings */ |
144 |
+ |
strcpy(cp, "-w- "); |
145 |
+ |
cp += 4; |
146 |
+ |
} |
147 |
|
while (ac-- > 0) { |
148 |
|
strcpy(cp, *av++); |
149 |
|
while (*cp) cp++; |
170 |
|
exit(1); |
171 |
|
} |
172 |
|
|
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 |
– |
|
173 |
|
/* Open a pipe to/from a command given as an argument list */ |
174 |
|
static FILE * |
175 |
|
popen_arglist(char *av[], char *mode) |
187 |
|
return(popen(cmd, mode)); |
188 |
|
} |
189 |
|
|
190 |
< |
#ifdef _WIN32 |
190 |
> |
#if defined(_WIN32) || defined(_WIN64) |
191 |
|
/* Execute system command (Windows version) */ |
192 |
|
static int |
193 |
|
my_exec(char *av[]) |
385 |
|
curparams.vup[1] = 1; |
386 |
|
} |
387 |
|
/* determine sample type/bin */ |
388 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') { |
388 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) { |
389 |
|
sprintf(sbuf, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)", |
390 |
|
curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]); |
391 |
|
binv = savqstr(sbuf); |
608 |
|
sp->priv = (void *)ptp; |
609 |
|
} |
610 |
|
/* pick triangle by partial area */ |
611 |
< |
for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) |
611 |
> |
for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) |
612 |
|
x -= ptp->tri[i].afrac; |
613 |
|
SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); |
614 |
|
samp2[0] *= samp2[1] = sqrt(samp2[1]); |
649 |
|
if (p->nsurfs > nall) { /* (re)allocate surface area cache */ |
650 |
|
if (projsa) free(projsa); |
651 |
|
projsa = (double *)malloc(sizeof(double)*p->nsurfs); |
652 |
< |
if (!projsa) return(0); |
652 |
> |
if (projsa == NULL) { |
653 |
> |
fputs(progname, stderr); |
654 |
> |
fputs(": out of memory in sample_origin!\n", stderr); |
655 |
> |
exit(1); |
656 |
> |
} |
657 |
|
nall = p->nsurfs; |
658 |
|
} |
659 |
|
/* compute projected areas */ |
696 |
|
duvw[2]*p->nrm[i] ; |
697 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
698 |
|
return(0); |
699 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
699 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
700 |
|
return(0); |
701 |
|
} |
702 |
|
return(1); |
726 |
|
duvw[2]*p->nrm[i] ; |
727 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
728 |
|
return(0); |
729 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
729 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
730 |
|
return(0); |
731 |
|
} |
732 |
|
return(1); |
762 |
|
} |
763 |
|
while (n--) { /* stratified sampling */ |
764 |
|
SDmultiSamp(samp3, 3, (n+frandom())/sampcnt); |
765 |
+ |
if (row >= RowMax-1) /* avoid crowding at zenith */ |
766 |
+ |
samp3[1] *= samp3[1]; |
767 |
|
alt = (row+samp3[1])*RAH; |
768 |
|
azi = (2.*PI)*(col+samp3[2]-.5)/rnaz(row); |
769 |
|
duvw[2] = cos(alt); /* measured from horizon */ |
770 |
|
duvw[0] = tsin(azi)*duvw[2]; |
771 |
< |
duvw[1] = tcos(azi)*duvw[2]; |
771 |
> |
duvw[1] = -tcos(azi)*duvw[2]; |
772 |
|
duvw[2] = sqrt(1. - duvw[2]*duvw[2]); |
773 |
|
for (i = 3; i--; ) |
774 |
|
orig_dir[1][i] = -duvw[0]*p->udir[i] - |
776 |
|
duvw[2]*p->nrm[i] ; |
777 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
778 |
|
return(0); |
779 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
779 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
780 |
|
return(0); |
781 |
|
} |
782 |
|
return(1); |
827 |
|
duvw[2]*p->nrm[i] ; |
828 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
829 |
|
return(0); |
830 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
830 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
831 |
|
return(0); |
832 |
|
} |
833 |
|
return(1); |
875 |
|
curparams.udir[1] *= -1.; |
876 |
|
curparams.udir[2] *= -1.; |
877 |
|
} |
878 |
< |
if (tolower(curparams.hemis[0]) == 'u' | curparams.hemis[0] == '1') |
878 |
> |
if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) |
879 |
|
curparams.sample_basis = sample_uniform; |
880 |
|
else if (tolower(curparams.hemis[0]) == 's' && |
881 |
|
tolower(curparams.hemis[1]) == 'c') |
954 |
|
snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1)); |
955 |
|
if (snew == NULL) { |
956 |
|
fputs(progname, stderr); |
957 |
< |
fputs(": out of memory!\n", stderr); |
957 |
> |
fputs(": out of memory in add_surface!\n", stderr); |
958 |
|
exit(1); |
959 |
|
} |
960 |
|
strncpy(snew->sname, oname, sizeof(snew->sname)-1); |
1313 |
|
fputs(": -i, -I supported for pass-through only\n", stderr); |
1314 |
|
return(1); |
1315 |
|
} |
1316 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1316 |
> |
#ifdef SMLFLT |
1317 |
> |
fmtopt[2] = 'f'; |
1318 |
> |
#else |
1319 |
> |
fmtopt[2] = 'd'; |
1320 |
> |
#endif |
1321 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1322 |
|
} |
1323 |
|
sprintf(sampcntbuf, "%d", sampcnt); |