static double thick; /* in input units */
static double scale;
+static void outtriangle(int rev, const OutVertex *a,
+ const OutVertex *b, const OutVertex *c);
+
static void normalise_thick(double a[D3]) {
/* multiplies a by a scalar so that its magnitude is thick */
int k;
}
}
FOR_VERTEX(v0) {
- double centroid[D3];
int vw= EDGE_END2(v0,3);
int vnw= EDGE_END2(v0,2);
int vsw= EDGE_END2(v0,4);
continue;
}
FOR_SIDE {
+ double adjust[D3];
+ int e;
K adjust[k]= 0;
FOR_VPEDGE(e) {
OutVertex *ovab= invertex2outvertexab(v0,e,side);
- K adjust[k] += ovab->k[k];
+ K adjust[k] += ovab->p[k];
}
K adjust[k] /= 6;
K adjust[k] -= in[v0][k];
}
}
FOR_RIM_VERTEX(y,x,v0) {
- double rim[D3], inner[D3], radius_cos[D3];, radius_sin[D3];
+ double rim[D3], inner[D3], radius_cos[D3], radius_sin[D3];
int vback, vfwd, around;
/* compute mean rim vector, which is just the vector between
vback= EDGE_END2(v0,3);
vfwd= EDGE_END2(v0,0);
assert(vback>=0 && vfwd>=0);
- K rim[k]= in[fwd][k] - in[vback][k];
+ K rim[k]= in[vfwd][k] - in[vback][k];
/* compute the inner centroid */
vback= EDGE_END2(v0,4);
normalise_thick(radius_sin);
for (around=0; around<NDEF; around++) {
- double angle= around * PI / (NDEF-1);
- double result[D3];
+ double angle= around * M_PI / (NDEF-1);
K ovDEF[x][!!y][around].p[k]=
in[v0][k] +
cos(angle) * radius_cos[k] +
FOR_RIM_VERTEX(y,x,v0) {
int vfwd= EDGE_END2(v0,0);
assert(vfwd >= 0);
+ int around;
for (around=0; around<NG; around++) {
K ovG[x][!!y][around].p[k]=
(ovDEF[ x ][!!y][around*2].p[k] +
}
}
+static int defs_aroundmap_swap(int around) { return NDEF-around; }
+static int int_identity_function(int i) { return i; }
+
static void outtriangles(void) {
- int v0,e0,e1;
+ int v0,e,side,aroung;
FOR_VERTEX(v0) {
OutVertex *defs=0, *defs1=0;
- int (*defs1aroundmap)(int)=0, rimy;
+ int (*defs1aroundmap)(int)=0, rimy=-1;
if (RIM_VERTEX_P(v0)) {
- Outvertex *gs;
+ OutVertex *gs;
rimy= !!(v0 & ~XMASK);
int v1= EDGE_END2(v0,0); assert(v1>=0);
gs= ovG [v0 & XMASK][rimy];
outtriangles_around(rimy, &gs[aroung], 6,surround);
}
}
-
+
FOR_SIDE {
+ OutVertex *cd;
if (defs) {
int around= side ? NDEF-1 : 0;
cd= &defs[around];
- OutVertex *ab= ovAB[v0][!rimy][side];
+ OutVertex *ab= &ovAB[v0][!rimy][side];
OutVertex *cd1= &defs1[defs1aroundmap(around)];
outtriangle(side^rimy,cd,ab,cd1);
} else {
cd= &ovC[v0][side];
}
- OutVertex *abs[6];
+ OutVertex *ab[6];
FOR_VPEDGE(e)
- abs[e0]= invertex2outvertexab(v0,e,side);
- outtriangles_around(side, cd, 6,abs);
+ ab[e]= invertex2outvertexab(v0,e,side);
+ outtriangles_around(side, cd, 6,ab);
}
}
}
/*---------- transformation (scale and perhaps shift) ----------*/
static void scaleshift_outvertex_array(int n, OutVertex ovX[n]) {
+ int i, k;
for (i=0; i<n; i++)
K ovX[i].p[k] *= scale;
/*
#define WR(x) wr((const void*)&(x), sizeof((x)))
static void wf(double d) {
-#if sizeof(float)==4
typedef float ieee754single;
-#endif
+
+ assert(sizeof(ieee754single)==4);
#if defined(BIG_ENDIAN)
- union { Byte b[4]; ieee754single f; } value; value.f= d;
+ union { uint8_t b[4]; ieee754single f; } value; value.f= d;
int i; for (i=3; i>=0; i--) WR(value.b[i]);
#elif defined(LITTLE_ENDIAN)
ieee754single f= d;
static uint32_t nouttriangles;
static uint32_t nouttriangles_counted;
-static void outtriangle(int rev, OutVertex *a, OutVertex *b, OutVertex *c) {
+static void outtriangle(int rev, const OutVertex *a,
+ const OutVertex *b, const OutVertex *c) {
if (rev) { outtriangle(0, c,b,a); return; }
nouttriangles++;
if (!~nouttriangles_counted) return;
- triangle_normal(normal, a.p, b.p, c.p);
+ double normal[D3];
+ int k;
+
+ triangle_normal(normal, a->p, b->p, c->p);
double multby= 1/magnD(normal);
K normal[k] *= multby;
K wf(normal[k]);
- K wf(a.p[k]);
- K wf(b.p[k]);
- K wf(c.p[k]);
- uint16_t attrbc;
+ K wf(a->p[k]);
+ K wf(b->p[k]);
+ K wf(c->p[k]);
+ uint16_t attrbc=0;
WR(attrbc);
}
static void write_file(void) {
static const char header[80]= "#!/usr/bin/meshlab\n" "binary STL file\n";
- if (isatty(stdout)) die("will not write binary stl to tty!");
+ if (isatty(1)) fail("will not write binary stl to tty!\n");
WR(header);