checkpoint
[anneal.git] / src / edu / berkeley / qfat / Main.java
index 9ba230d..2b36405 100644 (file)
@@ -80,9 +80,9 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
     public Main(StlFile stlf) {
 
         for(int i=0; i<stlf.coordArray.length; i+=3) {
-            Mesh.Vert p0 = goal.register(new Point(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG));
-            Mesh.Vert p1 = goal.register(new Point(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG));
-            Mesh.Vert p2 = goal.register(new Point(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG));
+            Point p0 = new Point(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG);
+            Point p1 = new Point(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG);
+            Point p2 = new Point(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG);
             Vec n  = new Vec(stlf.normArray[i/3].x * MAG, stlf.normArray[i/3].y  * MAG, stlf.normArray[i/3].z * MAG);
             Mesh.T t  = goal.newT(p0, p1, p2, n);
         }
@@ -118,20 +118,20 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
         };
 
 
-        Mesh.Vert ltf = tile.register(new Point(-(width/2),  (height/2),  (depth/2)));
-        Mesh.Vert mtf = tile.register(new Point( 0.0,        (height/2),  (depth/2)));
-        Mesh.Vert rtf = tile.register(new Point( (width/2),  (height/2),  (depth/2)));
-        Mesh.Vert ltn = tile.register(new Point(-(width/2),  (height/2), -(depth/2)));
-        Mesh.Vert mtn = tile.register(new Point( 0.0,        (height/2), -(depth/2)));
-        Mesh.Vert rtn = tile.register(new Point( (width/2),  (height/2), -(depth/2)));
-        Mesh.Vert lbf = tile.register(new Point(-(width/2), -(height/2),  (depth/2)));
-        Mesh.Vert mbf = tile.register(new Point( 0.0,       -(height/2),  (depth/2)));
-        Mesh.Vert rbf = tile.register(new Point( (width/2), -(height/2),  (depth/2)));
-        Mesh.Vert lbn = tile.register(new Point(-(width/2), -(height/2), -(depth/2)));
-        Mesh.Vert mbn = tile.register(new Point( 0.0,       -(height/2), -(depth/2)));
-        Mesh.Vert rbn = tile.register(new Point( (width/2), -(height/2), -(depth/2)));
+        Point ltf = new Point(-(width/2),  (height/2),  (depth/2));
+        Point mtf = new Point( 0.0,        (height/2),  (depth/2));
+        Point rtf = new Point( (width/2),  (height/2),  (depth/2));
+        Point ltn = new Point(-(width/2),  (height/2), -(depth/2));
+        Point mtn = new Point( 0.0,        (height/2), -(depth/2));
+        Point rtn = new Point( (width/2),  (height/2), -(depth/2));
+        Point lbf = new Point(-(width/2), -(height/2),  (depth/2));
+        Point mbf = new Point( 0.0,       -(height/2),  (depth/2));
+        Point rbf = new Point( (width/2), -(height/2),  (depth/2));
+        Point lbn = new Point(-(width/2), -(height/2), -(depth/2));
+        Point mbn = new Point( 0.0,       -(height/2), -(depth/2));
+        Point rbn = new Point( (width/2), -(height/2), -(depth/2));
         
-        points = new Mesh.Vert[] {
+        Point[] points = new Point[] {
             ltf,
             mtf,
             rtf,
@@ -184,23 +184,23 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
                 for(Mesh.T t2 : tile) {
                     if (t1==t2) continue;
 
-                    if ((t1.p1().p.times(m).minus(t2.p1().p).mag() < Mesh.EPSILON) &&
-                        (t1.p2().p.times(m).minus(t2.p3().p).mag() < Mesh.EPSILON) &&
-                        (t1.p3().p.times(m).minus(t2.p2().p).mag() < Mesh.EPSILON)) {
+                    if ((t1.v1().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) &&
+                        (t1.v2().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) &&
+                        (t1.v3().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) {
                         t1.e1().bind(t2.e3().pair);
                         t1.e2().bind(t2.e2().pair);
                         t1.e3().bind(t2.e1().pair);
                     }
-                    if ((t1.p2().p.times(m).minus(t2.p1().p).mag() < Mesh.EPSILON) &&
-                        (t1.p3().p.times(m).minus(t2.p3().p).mag() < Mesh.EPSILON) &&
-                        (t1.p1().p.times(m).minus(t2.p2().p).mag() < Mesh.EPSILON)) {
+                    if ((t1.v2().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) &&
+                        (t1.v3().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) &&
+                        (t1.v1().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) {
                         t1.e2().bind(t2.e3().pair);
                         t1.e3().bind(t2.e2().pair);
                         t1.e1().bind(t2.e1().pair);
                     }
-                    if ((t1.p3().p.times(m).minus(t2.p1().p).mag() < Mesh.EPSILON) &&
-                        (t1.p1().p.times(m).minus(t2.p3().p).mag() < Mesh.EPSILON) &&
-                        (t1.p2().p.times(m).minus(t2.p2().p).mag() < Mesh.EPSILON)) {
+                    if ((t1.v3().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) &&
+                        (t1.v1().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) &&
+                        (t1.v2().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) {
                         t1.e3().bind(t2.e3().pair);
                         t1.e1().bind(t2.e2().pair);
                         t1.e2().bind(t2.e1().pair);
@@ -239,11 +239,11 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
         Random random = new Random();
 
     public synchronized void breakit() {
-        if (verts > 300) return;
+        if (verts > 50) return;
         //double min = (tile.avgedge/tile.numedges)*(1+(4/(double)verts));
         //if (verts>0 && tile.es.peek().length() < min) return;
         PriorityQueue<Mesh.E> es = new PriorityQueue<Mesh.E>();
-        for(Mesh.E e : tile.es) es.add(e);
+        for(Mesh.E e : tile.edges()) es.add(e);
         for(int i=0; i<10; i++) {
             Mesh.E e = es.poll();
             verts++;
@@ -257,16 +257,28 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
     public synchronized void rand(double temperature, Mesh.Vert p) {
         double tile_score = tile.score();
         double goal_score = goal.score();
-        
         p.rescore();
+
+        /*
         //if (p.watch==null) return;
         float r1 = Math.abs(random.nextFloat());
         r1 = r1 - (float)Math.floor(r1);
         r1 = r1 * (float)0.01;
         r1 = r1 - (float)0.005;
-        Vec v = p.watchback().p.minus(p.p).norm().times(r1);
+        public Vert partner() { return quadric==null ? this : quadric; }
+        public Point quadric() { return quadric_count==0 ? partner().p :
+                new Point(quadric_x/quadric_count, quadric_y/quadric_count, quadric_z/quadric_count); }
 
+        Vec v = p.nearest_vert_in_other_mesh().minus(p.p).norm().times(r1);
+        */
         //v = p.norm().times(v.dot(p.norm()));
+        /*
+        Vec v = new Vec((random.nextFloat() - (float)0.5) / 1000,
+                        (random.nextFloat() - (float)0.5) / 1000,
+                        (random.nextFloat() - (float)0.5) / 1000);
+        */
+        Matrix inv = p.errorQuadric();
+        Vec v = new Vec(inv.d, inv.h, inv.l).norm().times(1/(float)1000);
 
         boolean aspect = false;//(Math.abs(random.nextInt()) % 100) <= 2;
         Matrix old_tile_aspect = null;//goal.aspect;
@@ -290,6 +302,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
         double swapProbability = Math.exp((-1 * delta) / temperature);
         //boolean doSwap = Math.random() < swapProbability;
         boolean doSwap = good && (tile_delta <= 0 && goal_delta <= 0);
+        //System.out.println(doSwap);
         if (doSwap) {
             tile_score = new_tile_score;
             goal_score = new_goal_score;
@@ -408,10 +421,10 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
             */
 
             if (mesh==goal)
-                for(Mesh.Vert p : new Mesh.Vert[] { t.p1(), t.p2(), t.p3() }) {
+                for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) {
                     p.p.glVertex(gl);
                     //p.plus(p.norm().times(p.score()*10)).glVertex(gl);
-                    p.partner().p.glVertex(gl);
+                    //p.partner().p.glVertex(gl);
                     //tile.nearest(p).centroid().glVertex(gl);
                 }
 
@@ -450,7 +463,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
                 glcanvas.repaint();
                 //tile.ts.get(Math.abs(random.nextInt()) % tile.ts.size()).e1().p1
                 for(Mesh.T t : tile)
-                    for(Mesh.Vert p : new Mesh.Vert[] { t.p1(), t.p2(), t.p3() }) {
+                    for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) {
                         rand(10,p);
                     }
                 goal.rescore();