From 3637de3ab66ba9c7bcd94d3b863bd22c706119e1 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 15 Dec 2007 23:49:45 -0800 Subject: [PATCH] checkpoint darcs-hash:20071216074945-5007d-92d8bb7076a42464190d2074300f4add4645f568.gz --- src/edu/berkeley/qfat/Main.java | 36 ++++++++++++++++------ src/edu/berkeley/qfat/Mesh.java | 54 +++++++++++++++++---------------- src/edu/berkeley/qfat/MeshViewer.java | 4 +-- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index fa69058..d085fd9 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -267,6 +267,7 @@ public class Main extends MeshViewer { } public void breakit() { + /* int oldverts = verts; System.out.println("doubling vertices."); PriorityQueue es = new PriorityQueue(); @@ -286,6 +287,7 @@ public class Main extends MeshViewer { repaint(); } tile.rebindPoints(); + */ } public synchronized void rand(float temp, Mesh.Vertex p) { @@ -303,14 +305,12 @@ public class Main extends MeshViewer { boolean good = p.move(m, false); if (!good) { misses++; return; } - p.reComputeErrorAround(); - double new_tile_error = tile.error(); double new_goal_error = goal.error(); double tile_delta = (new_tile_error - tile_error) / tile_error; double goal_delta = (new_goal_error - goal_error) / goal_error; double delta = tile_delta + goal_delta; - double swapProbability = Math.exp((-1 * delta) / (((double)temp)/100000)); + double swapProbability = Math.exp((-1 * delta) / (((double)temp)/1000000)); boolean doSwap = good && (Math.random() < swapProbability); //boolean doSwap = good && (tile_delta <= 0 && goal_delta <= 0); //boolean doSwap = good && (tile_delta + goal_delta <= 0); @@ -346,20 +346,21 @@ public class Main extends MeshViewer { if (breaks > 0) { while (breaks>0) { breaks--; - breakit(); + //breakit(); } - seek_upward = true; + //seek_upward = true; } else if (acceptance > 0.96) gamma = 0.4f; else if (acceptance > 0.9) gamma = 0.5f; else if (acceptance > 0.8) gamma = 0.65f; else if (acceptance > 0.6) gamma = 0.7f; - else if (acceptance > 0.3) gamma = 0.9f; - else if (acceptance > 0.15) gamma = 0.95f; - else if (acceptance > 0.10) gamma = 0.98f; + else if (acceptance > 0.3) gamma = 0.8f; + else if (acceptance > 0.15) gamma = 0.9f; + else if (acceptance > 0.05) gamma = 0.95f; + else if (acceptance > 0.01) gamma = 0.98f; else breaks++; if (seek_upward) { - if (acceptance > 0.3) seek_upward = false; + if (acceptance > 0.2) seek_upward = false; else gamma = 2-gamma; } @@ -383,6 +384,23 @@ public class Main extends MeshViewer { Thread.yield(); repaint(); } + PriorityQueue es = new PriorityQueue(); + for(Mesh.T t : tile) { + float max = 5; + for(Mesh.E e : new Mesh.E[] { t.e1(), t.e2(), t.e3() }) { + if (e==null) continue; + if (e.stretchRatio() > max) es.add(e); + if (t.aspect() < 0.1) es.add(e); + } + } + + for(int i=0; i<1; i++) { + Mesh.E e = es.poll(); + if (e==null) break; + e.shatter(); + } + tile.rebindPoints(); + System.out.println("temp="+temp + " ratio="+(Math.ceil(acceptance*100)) + " " + "points_per_second=" + (count*1000)/((double)(System.currentTimeMillis()-then))); diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 7083d76..d395d7f 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -137,25 +137,35 @@ public class Mesh implements Iterable { public void computeError() { if (error_against==null) return; float nerror = - quadric_count != 0 - ? (quadric.preAndPostMultiply(p) * 100)/quadric_count - : nearest_in_other_mesh != null - ? nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 - : nearest().fundamentalQuadric().preAndPostMultiply(p) * 100; + nearest_in_other_mesh != null + ? nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) + : nearest().fundamentalQuadric().preAndPostMultiply(p); + if (quadric_count != 0) + nerror = (/*nerror +*/ quadric.preAndPostMultiply(p))/(quadric_count/*+1*/); + /* for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) { - double ang = Math.abs(e.crossAngle()); + double ang = Math.abs(e.dihedralAngle()); if (ang > Math.PI) throw new Error(); float minangle = (float)(Math.PI * 0.8); if (ang > minangle) nerror += (ang - minangle); - /* if (e.t.aspect() < 0.2) { nerror += (0.2-e.t.aspect()) * 300; } - */ } + */ setError(nerror); } + public boolean move(Matrix m, boolean ignoreProblems) { + boolean good = true; + for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) + good &= p.transform(m.times(p.p), ignoreProblems); + for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) + if (good || ignoreProblems) p.reComputeErrorAround(); + else p.transform(p.oldp, true); + return good; + } + /** does NOT update bound pairs! */ private boolean transform(Point newp, boolean ignoreProblems) { this.oldp = this.p; @@ -177,8 +187,8 @@ public class Mesh implements Iterable { public void checkLegality() { /* for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) { - if (Math.abs(e.crossAngle()) > (Math.PI * 0.9) || - Math.abs(e.next.crossAngle()) > (Math.PI * 0.9)) illegal = true; + if (Math.abs(e.dihedralAngle()) > (Math.PI * 0.9) || + Math.abs(e.next.dihedralAngle()) > (Math.PI * 0.9)) illegal = true; if (e.t.aspect() < 0.1) illegal = true; } */ @@ -209,16 +219,6 @@ public class Mesh implements Iterable { return !illegal; } - public boolean move(Matrix m, boolean ignoreProblems) { - boolean good = true; - for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) - good &= p.transform(m.times(p.p), ignoreProblems); - for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) - if (good || ignoreProblems) p.reComputeErrorAround(); - else p.transform(p.oldp, true); - return good; - } - public E getFreeIncident() { E ret = getFreeIncident(e, e); if (ret != null) return ret; @@ -330,17 +330,18 @@ public class Mesh implements Iterable { boolean shattered = false; public boolean intersects(T t) { return t.intersects(p1.p, p2.p); } - public float comparator() { - /* + + public float stretchRatio() { Vertex nearest = error_against.nearest(midpoint()); - //return (float)Math.max(length(), midpoint().distance(nearest.p)); - //return length(); float nearest_distance = midpoint().distance(nearest.p); float other_distance = (p1.p.distance(error_against.nearest(p1.p).p)+ p2.p.distance(error_against.nearest(p2.p).p))/2; return nearest_distance/other_distance; - */ + } + public float comparator() { + + return length(); //return t==null?0:(1/t.aspect()); } @@ -423,7 +424,7 @@ public class Mesh implements Iterable { public T makeT(int colorclass) { return t==null ? (t = new T(this, colorclass)) : t; } - public double crossAngle() { + public double dihedralAngle() { Vec v1 = t.norm().times(-1); Vec v2 = pair.t.norm().times(-1); return Math.acos(v1.norm().dot(v2.norm())); @@ -599,6 +600,7 @@ public class Mesh implements Iterable { /** issue gl.glVertex() for each of the triangle's points */ public void glVertices(GL gl) { + if (!shouldBeDrawn()) return; norm().glNormal(gl); Point p1 = v1().oldp; Point p2 = v2().oldp; diff --git a/src/edu/berkeley/qfat/MeshViewer.java b/src/edu/berkeley/qfat/MeshViewer.java index b0ed97b..29919a4 100644 --- a/src/edu/berkeley/qfat/MeshViewer.java +++ b/src/edu/berkeley/qfat/MeshViewer.java @@ -199,12 +199,12 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi for(Matrix m : translations) { //if (v1.z==0 && v1.y==0) continue; i++; - //if (i != 7 && i!=4) continue; + if (i!=2&&i!=5) continue; Point p = new Point(0, 0, 0).times(m); Vec v = new Vec(p.x, p.y, p.z); v = v.times((float)1.04); gl.glTranslatef(v.x, v.y, v.z); - //draw(gl, false, tile); + //draw(gl, false, safeTriangles); gl.glTranslatef(-v.x, -v.y, -v.z); } //gl.glEnable(GL.GL_DEPTH_TEST); -- 1.7.10.4