X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=45ddf31e7daa3ef803395907a75cf8c05475cb93;hp=5240413e6c2437c7946464b867787bba64371a82;hb=17972ccdcc4b45ccf91a4281d6dedd6f1d79e003;hpb=20fe91a50615c12bdfdec4a72665ff92a700abd5 diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 5240413..45ddf31 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -47,12 +47,14 @@ public class Mesh implements Iterable { (float)(0.25+(0.05*t.color)), (float)(0.75+(0.05*t.color)), (float)0.3); + /* if (t.red) { gl.glColor4f((float)(0.75+(0.05*t.color)), (float)(0.25+(0.05*t.color)), (float)(0.25+(0.05*t.color)), (float)0.3); } + */ t.glTriangle(gl, m); } if (option_errorNormals) @@ -151,43 +153,62 @@ public class Mesh implements Iterable { } int i=0; + for(E e : flip) { e.flip(); System.out.println("flip!"); i++; - //if (i>2) break; } + System.out.println("count="+count); - /* - for (E e : flip) { - if (e.p1.original && !e.p2.face && !e.p2.original) e.flip(); - else if (e.p2.original && !e.p1.face && !e.p1.original) e.flip(); - } + + rebindPoints(); HashSet verts = new HashSet(); for(Vertex v : vertices()) verts.add(v); - for(Vertex v : verts) { - if (!v.face) continue; - //v.move(v.recenter().minus(v.getPoint()), false); - } - */ - - /* - Queue q = new LinkedList(); - OUTER: while(true) { - for (T t : this) { - if (t.old) { t.shatter(); continue OUTER; } + for (Vertex v : verts) + v.clearWish(); + for (Vertex v : verts) { + if (v.edge) { + for(E e = v.e; e!=null; e=e.pair.next==v.e?null:e.pair.next) { + if (e.p2.original) { + v.wish(e.p2); + v.wish(e.p2); + v.wish(e.p2); + v.wish(e.p2); + } + } + for(E e = v.e; e!=null; e=e.pair.next==v.e?null:e.pair.next) { + for(E e2 = e.p2.e; e2!=null; e2=e2.pair.next==e.p2.e?null:e2.pair.next) { + if (e2.p2.original) { + v.wish(e.p2); + } + } + } } - break; } - */ + for (Vertex v : verts) + v.grantWish(); + System.out.println("-------------------------------------------------------------------"); /* - for (Vertex v : vertices()) - clearWish(); - for (Vertex v : vertices()) { - + for (Vertex v : verts) { + if (v.original) { + int n=0; + for(E e = v.e; e!=null; e=e.pair.next==v.e?null:e.pair.next) { + n++; + v.wish(e.midpoint()); + v.wish(e.midpoint()); + v.wish(e.next.pair.t.centroid()); + } + v.avgWish(); + v.wishes = 3; + for(int j=0; j { public boolean edge = false; public boolean face = false; + private int wishes = 0; + private Point wish = Point.ZERO; + public void clearWish() { wishes = 0; wish = Point.ZERO; } + public void wish(HasPoint hp) { + Point p = hp.getPoint(); + wishes++; + wish = new Point(wish.x+p.x, wish.y+p.y, wish.z+p.z); + } + public void grantWish() { + for(Vertex v : (Iterable)getBoundPeers()) { + if (v==this) continue; + if (v.wishes==0) continue; + Point p = this.getBindingMatrix(v).times(v.wish.minus(Point.ZERO).div(v.wishes).plus(Point.ZERO)); + wish = p.minus(Point.ZERO).times(v.wishes).plus(wish); + wishes += v.wishes; + v.clearWish(); + } + if (wishes==0) return; + Vec d = wish.minus(Point.ZERO).div(wishes).plus(Point.ZERO).minus(getPoint()); + move(d, false); + clearWish(); + } + public void avgWish() { + if (wishes==0) return; + wish = wish.minus(Point.ZERO).div(wishes).plus(Point.ZERO); + wishes = 1; + } + private boolean illegal = false; public boolean visible = false; @@ -360,8 +409,8 @@ public class Mesh implements Iterable { if (bindingGroup != null) { /* for(int i=0; i<20 ; i++) { - Point p2 = getConstraint().times(pp); - pp = pp.midpoint(p2); + Point v2 = getConstraint().times(pp); + pp = pp.midpoint(v2); //System.out.println(m.minus(m2)); } */ @@ -489,7 +538,7 @@ public class Mesh implements Iterable { if (e.p1 == this && e.p2 == p2) return e; i++; e.sanity(); - if (e.destroyed) throw new RuntimeException(); + if (e.destroyed) throw new RuntimeException("fark " + i + " " + e.prev + " " + (e.prev.next==e) + " " + e.prev.destroyed); } return null; } @@ -541,9 +590,17 @@ public class Mesh implements Iterable { Vertex v2 = pair.t.getOtherVertex(pair); destroy(); pair.destroy(); - newT(v1, v2, p2).red = true; - newT(v2, v1, p1).red = true; + T t1 = newT(v1, v2, p2); + T t2 = newT(v2, v1, p1); + t1.e1().sanity(); + t1.e2().sanity(); + t1.e3().sanity(); + t2.e1().sanity(); + t2.e2().sanity(); + t2.e3().sanity(); + for (E e : (Iterable)getBoundPeers()) { + if (e==this) continue; if (e.destroyed) continue; Vertex v1e = e.t.getOtherVertex(e); Vertex v2e = e.pair.t.getOtherVertex(e.pair); @@ -552,12 +609,10 @@ public class Mesh implements Iterable { if (v1e.getE(v2e)!=null) throw new RuntimeException(); newT(v1e, v2e, e.p2).red = true; newT(v2e, v1e, e.p1).red = true; - makeE(v1.getPoint(), - v2.getPoint()).bindTo(this.getBindingMatrix(e), makeE(v1e.getPoint(), v2e.getPoint())); - makeE(v2.getPoint(), - v1.getPoint()).bindTo(pair.getBindingMatrix(e.pair), makeE(v2e.getPoint(), v1e.getPoint())); - + v2e.getE(v1e).bindTo(e.getBindingMatrix(this), v1.getE(v2)); + v1e.getE(v2e).bindTo(e.pair.getBindingMatrix(this.pair), v2.getE(v1)); } + } public void bindingGroupChanged(edu.berkeley.qfat.geom.BindingGroup newBindingGroup_) { @@ -713,22 +768,37 @@ public class Mesh implements Iterable { pair.next.t = null; pair.prev.t = null; - if (next.destroyed) throw new RuntimeException(); - if (prev.destroyed) throw new RuntimeException(); pair.prev.next = next; next.prev = pair.prev; prev.next = pair.next; - pair.next = prev; + pair.next.prev = prev; + + if (p1.e == this) p1.e = pair.next; + if (pair.p1.e == pair) pair.p1.e = next; - if (p1.e == this) p1.e = prev.next; - if (pair.p1.e == pair) pair.p1.e = pair.prev.next; if (p2.e == this) throw new RuntimeException(); if (pair.p2.e == pair) throw new RuntimeException(); + /* + next = pair; + prev = pair; + pair.next = this; + pair.prev = this; + */ + + /* + pair.prev = null; + pair.next = null; + next = null; + prev = null; + */ + + /* sanity(); next.sanity(); prev.sanity(); pair.sanity(); + */ } private void sync() {