checkpoint
authoradam <adam@megacz.com>
Thu, 6 Dec 2007 04:49:27 +0000 (20:49 -0800)
committeradam <adam@megacz.com>
Thu, 6 Dec 2007 04:49:27 +0000 (20:49 -0800)
darcs-hash:20071206044927-5007d-81ce5d1bb648c5542da926dc8840771bd71474ac.gz

src/edu/berkeley/qfat/Main.java
src/edu/berkeley/qfat/Mesh.java

index 982119b..dac265b 100644 (file)
@@ -35,6 +35,8 @@ public class Main extends MeshViewer {
             Mesh.T t  = goal.newT(p0, p1, p2, n, 0);
         }
 
             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(new Matrix(new Vec(0, 0, 1), (float)(Math.PI/2)));
 
         // rotate to align major axis -- this probably needs to be done by a human.
         goal.transform(new Matrix(new Vec(0, 0, 1), (float)(Math.PI/2)));
 
@@ -47,9 +49,9 @@ public class Main extends MeshViewer {
         float height = (float)0.08;
         float depth  = (float)0.3;
         */
         float height = (float)0.08;
         float depth  = (float)0.3;
         */
-        float width  = (float)0.6;
+        float width  = (float)0.7;
         float depth  = (float)0.08;
         float depth  = (float)0.08;
-        float height = (float)0.3;
+        float height = (float)0.35;
 
         float rshift = width/2;
         float lshift = -(width/2);
 
         float rshift = width/2;
         float lshift = -(width/2);
@@ -234,7 +236,7 @@ public class Main extends MeshViewer {
         //while(verts < 800) {
         PriorityQueue<Mesh.E> es = new PriorityQueue<Mesh.E>();
         for(Mesh.E e : tile.edges()) es.add(e);
         //while(verts < 800) {
         PriorityQueue<Mesh.E> es = new PriorityQueue<Mesh.E>();
         for(Mesh.E e : tile.edges()) es.add(e);
-        for(int i=0; i<8; i++) {
+        for(int i=0; i<10; i++) {
             Mesh.E e = es.poll();
             verts++;
             System.out.println("shatter " + e);
             Mesh.E e = es.poll();
             verts++;
             System.out.println("shatter " + e);
@@ -251,13 +253,16 @@ public class Main extends MeshViewer {
         double tile_score = tile.score();
         double goal_score = goal.score();
 
         double tile_score = tile.score();
         double goal_score = goal.score();
 
-        Vec v = new Vec((random.nextFloat() - (float)0.5) / 200,
-                        (random.nextFloat() - (float)0.5) / 200,
-                        (random.nextFloat() - (float)0.5) / 200);
-        /*
+        Vec v;
         Matrix inv = p.errorQuadric();
         v = new Vec(inv.d, inv.h, inv.l).norm().times(1/(float)1000);
         Matrix inv = p.errorQuadric();
         v = new Vec(inv.d, inv.h, inv.l).norm().times(1/(float)1000);
-        */
+        if (p.quadric_count == 0) {
+            v = goal.nearest(p.p).p.minus(p.p).norm().times(1/(float)1000);
+        }
+        Vec v2 = new Vec((random.nextFloat() - (float)0.5) / 500,
+                        (random.nextFloat() - (float)0.5)  / 500,
+                        (random.nextFloat() - (float)0.5)  / 500);
+        v = v.plus(v2.norm().times(1/(float)1000));
 
         boolean good = p.move(v);
 
 
         boolean good = p.move(v);
 
@@ -269,8 +274,8 @@ public class Main extends MeshViewer {
         double goal_delta = (new_goal_score - goal_score) / goal_score;
         double delta = tile_delta + goal_delta;
         double swapProbability = Math.exp((-1 * delta) / temp);
         double goal_delta = (new_goal_score - goal_score) / goal_score;
         double delta = tile_delta + goal_delta;
         double swapProbability = Math.exp((-1 * delta) / temp);
-        boolean doSwap = good && (Math.random() < swapProbability);
-        //boolean doSwap = good && (tile_delta <= 0 && goal_delta <= 0);
+        //boolean doSwap = good && (Math.random() < swapProbability);
+        boolean doSwap = good && (tile_delta <= 0 && goal_delta <= 0);
         if (doSwap) {
             tile_score = new_tile_score;
             goal_score = new_goal_score;
         if (doSwap) {
             tile_score = new_tile_score;
             goal_score = new_goal_score;
@@ -300,23 +305,24 @@ public class Main extends MeshViewer {
                 breaks = false;
                     breakit();
                     //gamma = 1;
                 breaks = false;
                     breakit();
                     //gamma = 1;
-                    gamma = 2;
+                    gamma = 1;
                     //temp = last * 0.8f;
                     //last = temp;
                     //temp = hightemp;
             } else
                     //temp = last * 0.8f;
                     //last = temp;
                     //temp = hightemp;
             } else
-            if (acceptance > 0.96) gamma = 0.6f;
-            else if (acceptance > 0.9) gamma = 0.7f;
-            else if (acceptance > 0.8) gamma = 0.75f;
-            else if (acceptance > 0.6) gamma = 0.8f;
+            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 {
             else {
                 if (acceptance > 0.3) {
                     gamma = 0.9f;
                 } else if (acceptance > 0.15) {
                     gamma = 0.95f;
                 } else {
-                    breakit();
-                    gamma = 2;
+                    //breakit();
+                    //gamma = 1;
+                    gamma = 0.99f;
                     //gamma = 1;
                     //temp = last * 0.8f;
                     //last = temp;
                     //gamma = 1;
                     //temp = last * 0.8f;
                     //last = temp;
@@ -345,7 +351,8 @@ public class Main extends MeshViewer {
 
     public static void main(String[] s) throws Exception {
         StlFile stlf = new StlFile();
 
     public static void main(String[] s) throws Exception {
         StlFile stlf = new StlFile();
-        stlf.load("simplefish.stl");
+        stlf.load("fish.stl");
+        //stlf.load("monkey.stl");
         Frame f = new Frame();
         Main main = new Main(stlf, f);
         f.pack();
         Frame f = new Frame();
         Main main = new Main(stlf, f);
         f.pack();
index 87cf35d..e3a7cde 100644 (file)
@@ -126,6 +126,7 @@ public class Mesh implements Iterable<Mesh.T> {
     public Vert nearest(Point p) { return pointset.nearest(p); }
 
     public final class Vert extends HasPoint {
     public Vert nearest(Point p) { return pointset.nearest(p); }
 
     public final class Vert extends HasPoint {
+        public String toString() { return p.toString(); }
         public Point p;
         E e;                // some edge *leaving* this point
 
         public Point p;
         E e;                // some edge *leaving* this point
 
@@ -238,15 +239,15 @@ public class Mesh implements Iterable<Mesh.T> {
                 else if (nearest_in_other_mesh == null) {
                     if (score_against != null) {
                         Vert ne = score_against.nearest(p);
                 else if (nearest_in_other_mesh == null) {
                     if (score_against != null) {
                         Vert ne = score_against.nearest(p);
-                        oldscore = ne.fundamentalQuadric().preAndPostMultiply(p) * 100 * 10;
+                        oldscore = ne.fundamentalQuadric().preAndPostMultiply(p) * 100 * 100;
                     } else {
                         oldscore = 0;
                     }
                 } else {
                     } else {
                         oldscore = 0;
                     }
                 } else {
-                    oldscore = nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 * 10;
+                    oldscore = nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 * 100;
                 }
             } else {
                 }
             } else {
-                oldscore = (quadric.preAndPostMultiply(p) * 100) /*/ quadric_count*/;
+                oldscore = (quadric.preAndPostMultiply(p) * 100);
             }
 
             oldscore = oldscore;
             }
 
             oldscore = oldscore;
@@ -255,6 +256,7 @@ public class Mesh implements Iterable<Mesh.T> {
             float aspects = 0;
             E e = this.e;
             do {
             float aspects = 0;
             E e = this.e;
             do {
+                //double ang = Math.abs(e.crossAngle());
                 double ang = Math.abs(e.crossAngle());
                 if (ang > Math.PI) throw new Error();
                 /*
                 double ang = Math.abs(e.crossAngle());
                 if (ang > Math.PI) throw new Error();
                 /*
@@ -263,11 +265,11 @@ public class Mesh implements Iterable<Mesh.T> {
                     aspects += e.t.aspect()*e.t.aspect();
                 }
                 */
                     aspects += e.t.aspect()*e.t.aspect();
                 }
                 */
-                /*
-                float minangle = (float)(Math.PI * 0.8);
+
+                float minangle = (float)(Math.PI * 0.9);
                 if (ang > minangle)
                     oldscore += (ang - minangle);
                 if (ang > minangle)
                     oldscore += (ang - minangle);
-                */
+
                 e = e.pair.next;
             } while (e != this.e);
             if (numaspects > 0) oldscore += (aspects / numaspects);
                 e = e.pair.next;
             } while (e != this.e);
             if (numaspects > 0) oldscore += (aspects / numaspects);
@@ -302,7 +304,8 @@ public class Mesh implements Iterable<Mesh.T> {
 
             // FIXME: intersection test needed?
             boolean good = true;
 
             // FIXME: intersection test needed?
             boolean good = true;
-            /*
+
+            if (!ignorecollision)
             for(T t : Mesh.this) {
                 if (!good) break;
                 e = this.e;
             for(T t : Mesh.this) {
                 if (!good) break;
                 e = this.e;
@@ -316,7 +319,7 @@ public class Mesh implements Iterable<Mesh.T> {
                     e = e.pair.next;
                 } while(e != this.e);
             }
                     e = e.pair.next;
                 } while(e != this.e);
             }
-            */
+
             reComputeErrorAround();
             return good;
         }
             reComputeErrorAround();
             return good;
         }
@@ -336,7 +339,14 @@ public class Mesh implements Iterable<Mesh.T> {
             E ret = getFreeIncident(e, e);
             if (ret != null) return ret;
             ret = getFreeIncident(e.pair.next, e.pair.next);
             E ret = getFreeIncident(e, e);
             if (ret != null) return ret;
             ret = getFreeIncident(e.pair.next, e.pair.next);
-            if (ret == null) throw new Error("unable to find free incident to " + this);
+            if (ret == null) {
+                E ex = e;
+                do {
+                    System.out.println(ex + " " + ex.t);
+                    ex = ex.pair.next;
+                } while (ex != e);
+                throw new Error("unable to find free incident to " + this);
+            }
             return ret;
         }
 
             return ret;
         }
 
@@ -448,10 +458,20 @@ public class Mesh implements Iterable<Mesh.T> {
         boolean shattered = false;
 
         public float comparator() {
         boolean shattered = false;
 
         public float comparator() {
-            if (t==null) return length();
+            Vert nearest = score_against.nearest(midpoint());
+            //if (t==null) return length();
+            /*
+            double ang = Math.abs(crossAngle());
+            float minangle = (float)(Math.PI * 0.9);
+            if (ang > minangle)
+                return 300;
+            */
+            /*
             if ((length() * length()) / t.area() > 10)
                 return (float)(length()*Math.sqrt(t.area()));
             return length()*t.area();
             if ((length() * length()) / t.area() > 10)
                 return (float)(length()*Math.sqrt(t.area()));
             return length()*t.area();
+            */
+            return length() + midpoint().distance(nearest.p);
         }
         public int compareTo(E e) {
             return e.comparator() > comparator() ? 1 : -1;
         }
         public int compareTo(E e) {
             return e.comparator() > comparator() ? 1 : -1;
@@ -798,11 +818,11 @@ public class Mesh implements Iterable<Mesh.T> {
         public boolean has(Vert v) { return v1()==v || v2()==v || v3()==v; }
 
         public void glVertices(GL gl) {
         public boolean has(Vert v) { return v1()==v || v2()==v || v3()==v; }
 
         public void glVertices(GL gl) {
-            /*
+
             if (e1().bind_to.set.size() == 0) return;
             if (e2().bind_to.set.size() == 0) return;
             if (e3().bind_to.set.size() == 0) return;
             if (e1().bind_to.set.size() == 0) return;
             if (e2().bind_to.set.size() == 0) return;
             if (e3().bind_to.set.size() == 0) return;
-            */
+
             norm().glNormal(gl);
             p1().glVertex(gl);
             p2().glVertex(gl);
             norm().glNormal(gl);
             p1().glVertex(gl);
             p2().glVertex(gl);
@@ -810,4 +830,5 @@ public class Mesh implements Iterable<Mesh.T> {
         }
     }
     public boolean tilemesh = false;
         }
     }
     public boolean tilemesh = false;
+    public boolean ignorecollision = false;
 }
 }