From: adam Date: Thu, 20 Dec 2007 12:36:04 +0000 (-0800) Subject: checkpoint autogen tile X-Git-Url: http://git.megacz.com/?p=anneal.git;a=commitdiff_plain;h=7c42fc87add9f8304182ccfd9722e22e95a70a96 checkpoint autogen tile darcs-hash:20071220123604-5007d-239350201abec1ee8cacb2a1da407a4df423f239.gz --- diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 8b5b51f..82b6862 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -456,27 +456,27 @@ public class Main extends MeshViewer { translations = new Matrix[] { - /* + Matrix.translate(new Vec(0, 0.2f,0)) - .times(Matrix.rotate(new Vec(0,1,0), (float)( 1*Math.PI/2))), + .times(Matrix.rotate(new Vec(0,1,0), (float)(1*Math.PI/2))), Matrix.translate(new Vec(0,-0.2f,0)) - .times(Matrix.rotate(new Vec(0,1,0), (float)(-1*Math.PI/2))), + .times(Matrix.rotate(new Vec(0,1,0), (float)(1*Math.PI/2))), Matrix.translate(new Vec( 0.2f,0,0)) - .times(Matrix.rotate(new Vec(1,0,0), (float)( 1*Math.PI/2))), + .times(Matrix.rotate(new Vec(1,0,0), (float)(-1*Math.PI/2))), Matrix.translate(new Vec(-0.2f,0,0)) .times(Matrix.rotate(new Vec(1,0,0), (float)(-1*Math.PI/2))), - */ + /* Matrix.rotate(new Vec(0,0,1), (float)(1*Math.PI/2)), Matrix.rotate(new Vec(0,0,1), (float)(2*Math.PI/2)), Matrix.rotate(new Vec(0,0,1), (float)(3*Math.PI/2)), - */ - Matrix.rotate(new Vec(1,0,0), (float)(2*Math.PI/2)), + Matrix.rotate(new Vec(1,0,0), (float)(2*Math.PI/2)), + */ //Matrix.rotate(new Vec(0,0,1), (float)(2*Math.PI/2)), //Matrix.scale(1,-1,1), @@ -511,48 +511,47 @@ public class Main extends MeshViewer { for(Matrix m2 : translations) { for(Mesh.T t1 : tile) { for(Mesh.T t2 : tile) { - if (t1==t2) continue; Matrix m = m1.inverse().times(m2); - if ((t1.v1().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) && - (t1.v2().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON) && - (t1.v3().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON)) { + if ((t1.v1().p.times(m).distance(t2.v1().p) < MATCHING_EPSILON) && + (t1.v2().p.times(m).distance(t2.v3().p) < MATCHING_EPSILON) && + (t1.v3().p.times(m).distance(t2.v2().p) < MATCHING_EPSILON)) { t2.e3().bindEdge(t1.e1(), m); t2.e2().bindEdge(t1.e2(), m); t2.e1().bindEdge(t1.e3(), m); } - if ((t1.v2().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) && - (t1.v3().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON) && - (t1.v1().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON)) { + if ((t1.v2().p.times(m).distance(t2.v1().p) < MATCHING_EPSILON) && + (t1.v3().p.times(m).distance(t2.v3().p) < MATCHING_EPSILON) && + (t1.v1().p.times(m).distance(t2.v2().p) < MATCHING_EPSILON)) { t2.e3().bindEdge(t1.e2(), m); t2.e2().bindEdge(t1.e3(), m); t2.e1().bindEdge(t1.e1(), m); } - if ((t1.v3().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) && - (t1.v1().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON) && - (t1.v2().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON)) { + if ((t1.v3().p.times(m).distance(t2.v1().p) < MATCHING_EPSILON) && + (t1.v1().p.times(m).distance(t2.v3().p) < MATCHING_EPSILON) && + (t1.v2().p.times(m).distance(t2.v2().p) < MATCHING_EPSILON)) { t2.e3().bindEdge(t1.e3(), m); t2.e2().bindEdge(t1.e1(), m); t2.e1().bindEdge(t1.e2(), m); } - if ((t1.v1().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) && - (t1.v2().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON) && - (t1.v3().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON)) { + if ((t1.v1().p.times(m).distance(t2.v1().p) < MATCHING_EPSILON) && + (t1.v2().p.times(m).distance(t2.v2().p) < MATCHING_EPSILON) && + (t1.v3().p.times(m).distance(t2.v3().p) < MATCHING_EPSILON)) { t2.e1().bindEdge(t1.e1().pair, m); t2.e2().bindEdge(t1.e2().pair, m); t2.e3().bindEdge(t1.e3().pair, m); } - if ((t1.v2().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) && - (t1.v3().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON) && - (t1.v1().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON)) { + if ((t1.v2().p.times(m).distance(t2.v1().p) < MATCHING_EPSILON) && + (t1.v3().p.times(m).distance(t2.v2().p) < MATCHING_EPSILON) && + (t1.v1().p.times(m).distance(t2.v3().p) < MATCHING_EPSILON)) { t2.e2().bindEdge(t1.e1().pair, m); t2.e3().bindEdge(t1.e2().pair, m); t2.e1().bindEdge(t1.e3().pair, m); } - if ((t1.v3().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) && - (t1.v1().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON) && - (t1.v2().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON)) { + if ((t1.v3().p.times(m).distance(t2.v1().p) < MATCHING_EPSILON) && + (t1.v1().p.times(m).distance(t2.v2().p) < MATCHING_EPSILON) && + (t1.v2().p.times(m).distance(t2.v3().p) < MATCHING_EPSILON)) { t2.e3().bindEdge(t1.e1().pair, m); t2.e1().bindEdge(t1.e2().pair, m); t2.e2().bindEdge(t1.e3().pair, m); @@ -569,7 +568,7 @@ public class Main extends MeshViewer { float factor = (float)Math.pow(tile.volume() / goal.volume(), 1.0/3.0); - goal.transform(Matrix.scale(factor/2.4f)); + goal.transform(Matrix.scale(factor/2.1f)); goal.transform(Matrix.rotate(new Vec(0, 1, 0), (float)(Math.PI/2))); // translate to match centroid @@ -634,7 +633,7 @@ public class Main extends MeshViewer { //System.out.println(v.mag() + " " + max); boolean good = p.move(m, false); - //if (!good) { /*misses++;*/ return; } + if (!good) { /*misses++;*/ return; } double new_tile_error = tile.error(); double new_goal_error = goal.error(); @@ -659,6 +658,7 @@ public class Main extends MeshViewer { p.move(Matrix.translate(v.times(-1)), true); misses++; } + p.reComputeErrorAround(); } float hits = 0; @@ -748,7 +748,10 @@ public class Main extends MeshViewer { System.out.println("temp="+temp + " ratio="+(Math.ceil(acceptance*100)) + " " + "points_per_second=" + (count*1000)/((double)(System.currentTimeMillis()-then))); - for(Mesh.Vertex p : goal.vertices()) p.recomputeFundamentalQuadricIfNeighborChanged(); + for(Mesh.Vertex p : goal.vertices()) { + p.quadricStale = true; + p.recomputeFundamentalQuadricIfNeighborChanged(); + } synchronized(safeTriangles) { safeTriangles.clear(); diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 0d7a96a..1e83eee 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -192,12 +192,18 @@ public class Mesh implements Iterable { throw new Error(v.p+" "+pt2+"\n"+op+" "+pt+"\n"+v.getBindingMatrix(this)); if (Math.abs( v.p.minus(pt2).mag() / pt.minus(op).mag() ) < 1/5) throw new Error(); */ - good &= v.transform(pt2, - ignoreProblems, v.getBindingMatrix(this)); + good &= v.transform(pt2, ignoreProblems, v.getBindingMatrix(this)); + } + + if (!good) { + for(Vertex v : (Iterable)getBoundPeers()) + v.transform(v.oldp, true, null); } for(Vertex v : (Iterable)getBoundPeers()) v.recomputeFundamentalQuadricIfNeighborChanged(); + for(Vertex v : (Iterable)getBoundPeers()) + v.reComputeErrorAround(); return good; } @@ -411,12 +417,14 @@ public class Mesh implements Iterable { Point mid = e.midpoint(); Vertex r = e.next.p2; Vertex l = e.pair.next.p2; - e.destroy(); - e.pair.destroy(); - newT(r.p, e.p1.p, mid, null, 0); - newT(r.p, mid, e.p2.p, null, 0); - newT(l.p, mid, e.p1.p, null, 0); - newT(l.p, e.p2.p, mid, null, 0); + if (!e.destroyed) { + e.destroy(); + e.pair.destroy(); + newT(r.p, e.p1.p, mid, null, 0); + newT(r.p, mid, e.p2.p, null, 0); + newT(l.p, mid, e.p1.p, null, 0); + newT(l.p, e.p2.p, mid, null, 0); + } } for(E e : (Iterable)getBoundPeers()) { Point mid = e.midpoint(); @@ -431,6 +439,10 @@ public class Mesh implements Iterable { e.p1.getE(mid).pair. bindTo(e.getBindingMatrix(firste), first.pair); e.p2.getE(mid).pair. bindTo(e.getBindingMatrix(firste), firstq); e.p2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair); + first.bindingGroup.setKrank(e.bindingGroup.krank); + firstq.bindingGroup.setKrank(e.bindingGroup.krank); + first.pair.bindingGroup.setKrank(e.bindingGroup.krank); + firstq.pair.bindingGroup.setKrank(e.bindingGroup.krank); } return null; } diff --git a/src/edu/berkeley/qfat/geom/BindingGroup.java b/src/edu/berkeley/qfat/geom/BindingGroup.java index 8c2d9a7..7a64af9 100644 --- a/src/edu/berkeley/qfat/geom/BindingGroup.java +++ b/src/edu/berkeley/qfat/geom/BindingGroup.java @@ -16,12 +16,17 @@ public class BindingGroup implements Iterable { public int size() { return matrices.size(); } + public void setKrank(Matrix k) { krank = krank.times(k); } public void merge(BindingGroup bg, Matrix m) { if (bg==this) throw new Error(); for(HasBindingGroup hbg : bg.matrices.keySet()) { matrices.put((T)hbg, bg.matrices.get(hbg).times(m)); hbg.bindingGroup = this; } + + Matrix v = getMatrix(bg.master, master); + krank = krank.times(v.inverse().times(bg.krank).times(v)); + HashSet stuff = new HashSet(); for(HasBindingGroup hbg : bg.matrices.keySet()) stuff.add(hbg);