X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=output.c;h=262991a41d978e0b02200a22ca6de92a3ed16830;hp=e37aa7c21775c3383381b856685fd7ed1be6370b;hb=cf1b738d035a22d539a44ca50925fb23cdb7588c;hpb=fcb05a81ecead2dcd3375c6d4ceb528ca6e181c0 diff --git a/output.c b/output.c index e37aa7c..262991a 100644 --- a/output.c +++ b/output.c @@ -10,6 +10,11 @@ * - scale the coordinates * - translate the coordinates so they're all positive */ +/* + * ./output-64 t.stl + * ./output-125 t.stl 0.1 50 + * meshlab t.stl + */ /* * Re STL, see: * http://www.ennex.com/~fabbers/StL.asp @@ -45,7 +50,7 @@ * / *B2 2\ / /1 *A \ / *A \ / *A \ / * \ / \/:/ 0 \ / \ / \ / * *C ____________|*C ____________ *C ___________ *C ___________ *C __ - * /\ 3 | : 0 /\ /\ /\ + * /\ 3 |/\ 0 /\ /\ /\ * / \ / :\ / \ / \ / \ * \ *A3 4/ \: \5 5*B / \ *B / \ *B / \ * \ / \ \ / \ / \ / @@ -103,14 +108,8 @@ * * The outfacets are: * - * For each non-rim vertex on each side, the six triangles formed by - * its C and the surrounding A's and B's. - * - * For each rim vertex on each side, the two triangles formed by its - * D and the nearest As and Bs (two As and one B or vice versa). - * - * For each rim edge on each side, the triangle formed by that edge's - * ends' Ds and the corresponding A or B. + * For each input vertex on each side, the six (or perhaps only three) + * triangles formed by its C or D and the surrounding Cs and/or Ds. * * For each G, the six triangles formed by that G and the adjacent * four Fs (or two Fs and two Ds) and two Es. @@ -149,6 +148,10 @@ static double scale; static void outfacet(int rev, const OutVertex *a, const OutVertex *b, const OutVertex *c); +typedef int int_map(int); +static int defs_aroundmap_swap(int around) { return NDEF-1-around; } +static int int_identity_function(int i) { return i; } + static void normalise_thick(double a[D3]) { /* multiplies a by a scalar so that its magnitude is thick */ int k; @@ -262,8 +265,10 @@ static void compute_outvertices(void) { normalise_thick(radius_cos); normalise_thick(radius_sin); + int_map *around_map= y ? int_identity_function : defs_aroundmap_swap; + for (around=0; around= 0); - int around; - for (around=0; around=0); gs= ovG [v0 & XMASK][rimy]; defs= ovDEF[v0 & XMASK][rimy]; - defs1= ovDEF[v1 & XMASK][rimy]; + defs1= ovDEF[v1 & XMASK][!!(v1 & ~XMASK)]; defs1aroundmap= vertices_span_join_p(v0,v1) ? defs_aroundmap_swap : int_identity_function; @@ -328,23 +341,16 @@ static void outfacets(void) { } FOR_SIDE { - OutVertex *cd; - if (defs) { - int around= side ? NDEF-1 : 0; - cd= &defs[around]; - OutVertex *ab= &ovAB[v0][!rimy][side]; - OutVertex *cd1= &defs1[defs1aroundmap(around)]; - outfacet(side^rimy,cd,ab,cd1); - } else { - cd= &ovC[v0][side]; + int ab; + for (ab=0; ab<2; ab++) { + int v1= EDGE_END2(v0, ab ? 5 : 0); + int v2= EDGE_END2(v0, ab ? 0 : 1); + if (v1<0 || v2<0) continue; + outfacet(side, + invertex2outvertexcd(v0,side), + invertex2outvertexcd(v1,side^vertices_span_join_p(v0,v1)), + invertex2outvertexcd(v2,side^vertices_span_join_p(v0,v2))); } - OutVertex *ab[6]; - FOR_VPEDGE(e) { - ab[e]= invertex2outvertexab(v0,e,side); - if (ab[e]) - K assert(!isnan(ab[e]->p[k])); - } - outfacets_around(side, cd, 6,ab); } } } @@ -368,8 +374,11 @@ static void blank_outvertices(void) { static void transform_outvertex_array(int n, OutVertex ovX[n]) { int i, k; - for (i=0; i= -1e3 && d <= 1e3); static uint32_t noutfacets; static uint32_t noutfacets_counted; +static long badfacets; static void outfacet(int rev, const OutVertex *a, const OutVertex *b, const OutVertex *c) { @@ -432,8 +442,10 @@ static void outfacet(int rev, const OutVertex *a, triangle_normal(normal, a->p, b->p, c->p); double multby= 1/magnD(normal); - if (multby > 1e6) + if (multby > 1e6) { + badfacets++; return; + } noutfacets++; if (!~noutfacets_counted) return; @@ -466,6 +478,11 @@ static void write_file(void) { assert(noutfacets == noutfacets_counted); if (fflush(stdout)) diee("fflush stdout"); + + if (badfacets) { + fprintf(stderr,"%ld degenerate facets!\n",badfacets); + exit(4); + } }