X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMain.java;h=fa6905892713c92fcdc8f90b368de703987ddc72;hp=58961675069379a9aec66e3b10475f96ec60bd7c;hb=85bf586c55813abe79fab0476e2196700a6d0ea1;hpb=415f5ddcc1c38053f390ec9dc6f55ae3d0101849 diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 5896167..fa69058 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -26,19 +26,19 @@ import edu.berkeley.qfat.geom.Point; // http://www.cs.cmu.edu/afs/cs/project/quake/public/code/predicates.c /* -blender keys -- middle mouse = option+click -- right mouse = command+click + blender keys + - middle mouse = option+click + - right mouse = command+click -3,7,1 = view along axes (control for opp direction) -4, 8, 7, 2 = rotate in discrete increments (+control to translate) -middle trag: rotate space -shift+middle drag: translate space -wheel: zoom -home: home view: take current angle, zoom to whole scnee -5 = ortho vs non-ortho + 3,7,1 = view along axes (control for opp direction) + 4, 8, 7, 2 = rotate in discrete increments (+control to translate) + middle trag: rotate space + shift+middle drag: translate space + wheel: zoom + home: home view: take current angle, zoom to whole scnee + 5 = ortho vs non-ortho - */ +*/ // FIXME: re-orient goal (how?) @@ -63,8 +63,6 @@ public class Main extends MeshViewer { Mesh.T t = goal.newT(p0, p1, p2, n, 0); } - goal.ignorecollision = true; - // rotate to align major axis -- this probably needs to be done by a human. goal.transform(Matrix.rotate(new Vec(0, 0, 1), (float)(Math.PI/2))); @@ -73,9 +71,9 @@ public class Main extends MeshViewer { float goal_depth = goal.diagonal().dot(new Vec(0, 0, 1)); /* - float width = (float)0.6; - float height = (float)0.08; - float depth = (float)0.3; + float width = (float)0.6; + float height = (float)0.08; + float depth = (float)0.3; */ float width = (float)0.7; float depth = (float)0.08; @@ -95,8 +93,8 @@ public class Main extends MeshViewer { Matrix.translate(new Vec(rshift, -depth, halfup)), /* - Matrix.translate(new Vec(0, depth, halfup)), - Matrix.translate(new Vec(0, -depth, halfup)), + Matrix.translate(new Vec(0, depth, halfup)), + Matrix.translate(new Vec(0, -depth, halfup)), */ Matrix.translate(new Vec(lshift, 0, height)), @@ -239,7 +237,7 @@ public class Main extends MeshViewer { } } - //xMesh.Vert mid = lbf.getE(mbn).shatter(); + //xMesh.Vertex mid = lbf.getE(mbn).shatter(); // rescale to match volume float factor = (float)Math.pow(tile.volume() / goal.volume(), 1.0/3.0); @@ -247,6 +245,7 @@ public class Main extends MeshViewer { // translate to match centroid goal.transform(Matrix.translate(tile.centroid().minus(goal.centroid()))); + goal.makeVerticesImmutable(); //tx.e2.shatter(); //tx.e3.shatter(); @@ -263,12 +262,11 @@ public class Main extends MeshViewer { System.out.println("tile volume: " + tile.volume()); System.out.println("goal volume: " + goal.volume()); - tile.score_against = goal; - goal.score_against = tile; - tile.tilemesh = true; + tile.error_against = goal; + goal.error_against = tile; } - public synchronized void breakit() { + public void breakit() { int oldverts = verts; System.out.println("doubling vertices."); PriorityQueue es = new PriorityQueue(); @@ -276,57 +274,53 @@ public class Main extends MeshViewer { es.add(t.e1()); es.add(t.e2()); es.add(t.e3()); + Thread.yield(); + repaint(); } - for(int i=0; i 0) { while (breaks>0) { - breaks--; - breakit(); - //gamma = 1; - gamma = 1; - //temp = last * 0.8f; - //last = temp; - //temp = hightemp; - } } 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 { - breakit(); - //gamma = 1; - gamma = 0.99f; - //gamma = 1; - //temp = last * 0.8f; - //last = temp; - //temp = hightemp; + double ratio = (hits+misses==0) ? 1 : (hits / (hits+misses)); + hits = 0; + misses = 0; + float gamma = 1; + acceptance = (ratio+acceptance)/2; + accepts = (int)(Math.ceil(ratio*100)); + temps = (int)(Math.ceil(temp*1000)); + vertss = tile.size(); + if (breaks > 0) { + while (breaks>0) { + breaks--; + breakit(); + } + 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 breaks++; + + if (seek_upward) { + if (acceptance > 0.3) seek_upward = false; + else gamma = 2-gamma; } - } - temp = temp * gamma; + + temp = temp * gamma; - HashSet hs = new HashSet(); - for(Mesh.Vert p : tile.vertices()) hs.add(p); - Mesh.Vert[] pts = (Mesh.Vert[])hs.toArray(new Mesh.Vert[0]); + HashSet hs = new HashSet(); + for(Mesh.Vertex p : tile.vertices()) hs.add(p); + Mesh.Vertex[] pts = (Mesh.Vertex[])hs.toArray(new Mesh.Vertex[0]); - int count = 0; - long then = System.currentTimeMillis(); - for(int i=0; i<100; i++) { - if (anneal) { - count++; - Mesh.Vert v = pts[Math.abs(random.nextInt()) % pts.length]; - rand(temp,v); + int count = 0; + long then = System.currentTimeMillis(); + for(int i=0; i<40; i++) { + if (anneal) { + count++; + Mesh.Vertex v = pts[Math.abs(random.nextInt()) % pts.length]; + rand(temp,v); + v.recomputeFundamentalQuadricIfStale(); + v.recomputeFundamentalQuadricIfNeighborChanged(); + } + Thread.yield(); + repaint(); } - Thread.yield(); - repaint(); - } - System.out.println("temp="+temp + " ratio="+(Math.ceil(ratio*100)) + " " + - "points_per_second=" + - (count*1000)/((double)(System.currentTimeMillis()-then))); - tile.rebuild(); - repaint(); - //breakit(); - repaint(); - goal.unApplyQuadricToNeighborAll(); - repaint(); - tile.recomputeAllFundamentalQuadrics(); - repaint(); - goal.applyQuadricToNeighborAll(); + 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(); - safeTriangles.clear(); - for(Mesh.T t : tile) safeTriangles.add(t); + synchronized(safeTriangles) { + safeTriangles.clear(); + for(Mesh.T t : tile) if (t.shouldBeDrawn()) safeTriangles.add(t); + } } - } + } }