From: adam Date: Wed, 2 Jul 2008 03:50:41 +0000 (-0700) Subject: checkpoint X-Git-Url: http://git.megacz.com/?p=anneal.git;a=commitdiff_plain;h=e05e2bb718f149e746167856fc742eacabccdeab checkpoint darcs-hash:20080702035041-5007d-935e2ae56c1f598c59be9af567bea77efa6fc2ce.gz --- diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 5240413..1998b4b 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,26 +153,29 @@ 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); + + /* + tris.clear(); + for (T t : this) if (t.v1().edge && t.v2().edge && t.v3().edge) tris.add(t); + for (T t : tris) + t.shatter(); + */ + /* - 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(); - } - 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); + v.move(v.recenter().minus(v.getPoint()), false); } */ - /* Queue q = new LinkedList(); OUTER: while(true) { @@ -180,15 +185,34 @@ public class Mesh implements Iterable { break; } */ - /* - for (Vertex v : vertices()) - clearWish(); - for (Vertex v : vertices()) { - + + rebindPoints(); + HashSet verts = new HashSet(); + for(Vertex v : vertices()) verts.add(v); + 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); + } + } + } + } } - for (Vertex v : vertices()) - grantWish(); - */ + for (Vertex v : verts) + v.grantWish(); + } // Vertexices ////////////////////////////////////////////////////////////////////////////// @@ -203,6 +227,28 @@ public class Mesh implements Iterable { 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; + 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(); + } + private boolean illegal = false; public boolean visible = false; @@ -489,7 +535,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 +587,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 +606,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 +765,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() {