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 |
– |
|
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 */ |
181 |
|
return(popen(cmd, mode)); |
182 |
|
} |
183 |
|
|
184 |
< |
#ifdef _WIN32 |
184 |
> |
#if defined(_WIN32) || defined(_WIN64) |
185 |
|
/* Execute system command (Windows version) */ |
186 |
|
static int |
187 |
|
my_exec(char *av[]) |
602 |
|
sp->priv = (void *)ptp; |
603 |
|
} |
604 |
|
/* pick triangle by partial area */ |
605 |
< |
for (i = 0; i < ptp->ntris && x > ptp->tri[i].afrac; i++) |
605 |
> |
for (i = 0; i < ptp->ntris-1 && x > ptp->tri[i].afrac; i++) |
606 |
|
x -= ptp->tri[i].afrac; |
607 |
|
SDmultiSamp(samp2, 2, x/ptp->tri[i].afrac); |
608 |
|
samp2[0] *= samp2[1] = sqrt(samp2[1]); |
643 |
|
if (p->nsurfs > nall) { /* (re)allocate surface area cache */ |
644 |
|
if (projsa) free(projsa); |
645 |
|
projsa = (double *)malloc(sizeof(double)*p->nsurfs); |
646 |
< |
if (!projsa) return(0); |
646 |
> |
if (projsa == NULL) { |
647 |
> |
fputs(progname, stderr); |
648 |
> |
fputs(": out of memory in sample_origin!\n", stderr); |
649 |
> |
exit(1); |
650 |
> |
} |
651 |
|
nall = p->nsurfs; |
652 |
|
} |
653 |
|
/* compute projected areas */ |
690 |
|
duvw[2]*p->nrm[i] ; |
691 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
692 |
|
return(0); |
693 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
693 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
694 |
|
return(0); |
695 |
|
} |
696 |
|
return(1); |
720 |
|
duvw[2]*p->nrm[i] ; |
721 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
722 |
|
return(0); |
723 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
723 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
724 |
|
return(0); |
725 |
|
} |
726 |
|
return(1); |
768 |
|
duvw[2]*p->nrm[i] ; |
769 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp3[0])) |
770 |
|
return(0); |
771 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
771 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
772 |
|
return(0); |
773 |
|
} |
774 |
|
return(1); |
819 |
|
duvw[2]*p->nrm[i] ; |
820 |
|
if (!sample_origin(p, orig_dir[0], orig_dir[1], samp2[0])) |
821 |
|
return(0); |
822 |
< |
if (fwrite(orig_dir, sizeof(FVECT), 2, fp) != 2) |
822 |
> |
if (putbinary(orig_dir, sizeof(FVECT), 2, fp) != 2) |
823 |
|
return(0); |
824 |
|
} |
825 |
|
return(1); |
946 |
|
snew = (SURF *)malloc(sizeof(SURF) + sizeof(double)*(n-1)); |
947 |
|
if (snew == NULL) { |
948 |
|
fputs(progname, stderr); |
949 |
< |
fputs(": out of memory!\n", stderr); |
949 |
> |
fputs(": out of memory in add_surface!\n", stderr); |
950 |
|
exit(1); |
951 |
|
} |
952 |
|
strncpy(snew->sname, oname, sizeof(snew->sname)-1); |
1305 |
|
fputs(": -i, -I supported for pass-through only\n", stderr); |
1306 |
|
return(1); |
1307 |
|
} |
1308 |
< |
fmtopt[2] = (sizeof(RREAL)==sizeof(double)) ? 'd' : 'f'; |
1308 |
> |
#ifdef SMLFLT |
1309 |
> |
fmtopt[2] = 'f'; |
1310 |
> |
#else |
1311 |
> |
fmtopt[2] = 'd'; |
1312 |
> |
#endif |
1313 |
|
if (sampcnt <= 0) sampcnt = 10000; |
1314 |
|
} |
1315 |
|
sprintf(sampcntbuf, "%d", sampcnt); |