From: Ian Jackson Date: Sun, 17 Feb 2008 19:28:08 +0000 (+0000) Subject: compiles and most output facets are right; needs debugging X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=commitdiff_plain;h=fcb05a81ecead2dcd3375c6d4ceb528ca6e181c0 compiles and most output facets are right; needs debugging --- diff --git a/dumpstl b/dumpstl new file mode 100755 index 0000000..2080b6c --- /dev/null +++ b/dumpstl @@ -0,0 +1,16 @@ +#!/usr/bin/perl +sub rd ($) { my ($l)=@_; my $v; read(STDIN,$v,$l)==$l or die; return $v; } +$hdr= rd(80); +$number= rd(4); $number= unpack "V", $number; +for ($i=0; $i<$number; $i++) { + for ($fi=0; $fi<4; $fi++) { + printf " %5d %d ", $i,$fi; + foreach $coord (qw(x y z)) { + $float= rd(4); $float= unpack "f", $float; + printf " %s=%15g", $coord, $float; + } + print "\n"; + } + rd(2); + +} diff --git a/mgraph.c b/mgraph.c index 7f5f3bd..46c7533 100644 --- a/mgraph.c +++ b/mgraph.c @@ -39,3 +39,10 @@ int edge_reverse(int v1, int e) { // v1,e,eprime, EDGE_END2(v1,e), x2,flip); return eprime; } + +int vertices_span_join_p(int v0, int v1) { + int v0x= v0 & XMASK; + int v1x= v1 & XMASK; + int diff= v0x-v1x; + return diff < -2 || diff > 2; +} diff --git a/mgraph.h b/mgraph.h index 4ab0205..06c53e2 100644 --- a/mgraph.h +++ b/mgraph.h @@ -125,9 +125,7 @@ int edge_reverse(int v1, int e); for ((vy)=0; (vy)p[k]; + K { + assert(!isnan(ovab->p[k])); + adjust[k] += ovab->p[k]; + } } K adjust[k] /= 6; K adjust[k] -= in[v0][k]; normalise_thick(adjust); - K ovC[v0][side].p[k]= in[v0][k] + adjust[k]; + K Ok(ovC[v0][side], in[v0][k] + adjust[k]); } } FOR_RIM_VERTEX(y,x,v0) { @@ -252,10 +264,10 @@ static void compute_outvertices(void) { for (around=0; around= 0); int around; for (around=0; aroundp[k])); + } + outfacets_around(side, cd, 6,ab); } } } -/*---------- transformation (scale and perhaps shift) ----------*/ +/*---------- operations on very output vertex ----------*/ + +#define DO_OUTPUT_ARRAY_OUTVERTEX_ARRAY(fn,ovX) \ + ((fn)(sizeof((ovX))/sizeof(OutVertex), (OutVertex*)(ovX))) -static void scaleshift_outvertex_array(int n, OutVertex ovX[n]) { +static void blank_outvertex_array(int n, OutVertex ovX[n]) { + int i, k; + for (i=0; i= -1e3 && d <= 1e3); + +#if BYTE_ORDER==BIG_ENDIAN 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) +#elif BYTE_ORDER==LITTLE_ENDIAN ieee754single f= d; WR(f); #else @@ -384,20 +413,31 @@ static void wf(double d) { #endif } -static uint32_t nouttriangles; -static uint32_t nouttriangles_counted; +static uint32_t noutfacets; +static uint32_t noutfacets_counted; -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; +static void outfacet(int rev, const OutVertex *a, + const OutVertex *b, const OutVertex *c) { + if (rev) { outfacet(0, c,b,a); return; } double normal[D3]; int k; + K { + assert(!isnan(a->p[k])); + assert(!isnan(b->p[k])); + assert(!isnan(c->p[k])); + } + triangle_normal(normal, a->p, b->p, c->p); double multby= 1/magnD(normal); + + if (multby > 1e6) + return; + + noutfacets++; + if (!~noutfacets_counted) return; + K normal[k] *= multby; K wf(normal[k]); @@ -415,15 +455,15 @@ static void write_file(void) { WR(header); - nouttriangles_counted=~(uint32_t)0; - nouttriangles=0; - outtriangles(); - WR(nouttriangles); + noutfacets_counted=~(uint32_t)0; + noutfacets=0; + outfacets(); + WR(noutfacets); - nouttriangles_counted= nouttriangles; - nouttriangles=0; - outtriangles(); - assert(nouttriangles == nouttriangles_counted); + noutfacets_counted= noutfacets; + noutfacets=0; + outfacets(); + assert(noutfacets == noutfacets_counted); if (fflush(stdout)) diee("fflush stdout"); } @@ -441,8 +481,9 @@ int main(int argc, const char *const *argv) { errno= 0; r= fread(&in,sizeof(in),1,stdin); if (r!=1) diee("fread"); + blank_outvertices(); compute_outvertices(); - scaleshift_outvertices(); + transform_outvertices(); write_file(); if (fclose(stdout)) diee("fclose stdout"); return 0;