checkpoint
authoradam <adam@megacz.com>
Wed, 5 Dec 2007 06:33:35 +0000 (22:33 -0800)
committeradam <adam@megacz.com>
Wed, 5 Dec 2007 06:33:35 +0000 (22:33 -0800)
darcs-hash:20071205063335-5007d-b5fee023de2b08d2dd98ba4483d870cecea0e5fb.gz

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

index 6c663d0..b774066 100644 (file)
@@ -209,11 +209,6 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
             }
         }
 
             }
         }
 
-        for(Mesh.Vert vert : goal.vertices()) {
-            System.out.println("error: " + vert.quadric().preAndPostMultiply(vert.p));
-        }
-
-
         //xMesh.Vert mid = lbf.getE(mbn).shatter();
 
         // rescale to match volume
         //xMesh.Vert mid = lbf.getE(mbn).shatter();
 
         // rescale to match volume
@@ -269,7 +264,8 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener
         r1 = r1 - (float)Math.floor(r1);
         r1 = r1 * (float)0.01;
         r1 = r1 - (float)0.005;
         r1 = r1 - (float)Math.floor(r1);
         r1 = r1 * (float)0.01;
         r1 = r1 - (float)0.005;
-        Vec v = p.watchback().minus(p.p).norm().times(r1);
+
+        Vec v = p.nearest_vert_in_other_mesh().minus(p.p).norm().times(r1);
 
         //v = p.norm().times(v.dot(p.norm()));
 
 
         //v = p.norm().times(v.dot(p.norm()));
 
index 08d89e7..f635754 100644 (file)
@@ -126,11 +126,11 @@ public class Mesh implements Iterable<Mesh.T> {
         E e;                // some edge *leaving* this point
 
         Vert bound_to = this;
         E e;                // some edge *leaving* this point
 
         Vert bound_to = this;
-        int watch_count;
-        float watch_x;
-        float watch_y;
-        float watch_z;
-        Vert watch;
+        int nearest_vert_in_other_mesh_count;
+        float nearest_vert_in_other_mesh_x;
+        float nearest_vert_in_other_mesh_y;
+        float nearest_vert_in_other_mesh_z;
+        Vert nearest_vert_in_other_mesh;
         Matrix binding = new Matrix();
         float oldscore = 0;
         boolean inserted = false;
         Matrix binding = new Matrix();
         float oldscore = 0;
         boolean inserted = false;
@@ -154,47 +154,47 @@ public class Mesh implements Iterable<Mesh.T> {
         }
         public float score() { return oldscore; }
         public void unscore() {
         }
         public float score() { return oldscore; }
         public void unscore() {
-            if (watch == null) return;
-            watch.watch_x -= p.x;
-            watch.watch_y -= p.y;
-            watch.watch_z -= p.z;
-            watch.watch_count--;
-            if (watch.watch_count==0) {
-                watch.watch_x = 0;
-                watch.watch_y = 0;
-                watch.watch_z = 0;
+            if (nearest_vert_in_other_mesh == null) return;
+            nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x -= p.x;
+            nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y -= p.y;
+            nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z -= p.z;
+            nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count--;
+            if (nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count==0) {
+                nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x = 0;
+                nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y = 0;
+                nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z = 0;
             }
             }
-            watch = null;
+            nearest_vert_in_other_mesh = null;
         }
         }
-        public Vert partner() { return watch==null ? this : watch; }
-        public Point watchback() { return watch_count==0 ? partner().p :
-                new Point(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count); }
+        public Vert partner() { return nearest_vert_in_other_mesh==null ? this : nearest_vert_in_other_mesh; }
+        public Point nearest_vert_in_other_mesh() { return nearest_vert_in_other_mesh_count==0 ? partner().p :
+                new Point(nearest_vert_in_other_mesh_x/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_y/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_z/nearest_vert_in_other_mesh_count); }
         public void rescore() {
             if (score_against == null) return;
 
             score -= oldscore;
             oldscore = 0;
 
         public void rescore() {
             if (score_against == null) return;
 
             score -= oldscore;
             oldscore = 0;
 
-            if (watch != null) unscore();
+            if (nearest_vert_in_other_mesh != null) unscore();
             Vert po = this;
             Vert po = this;
-            if (watch == null) {
-                watch = score_against.nearest(po.p);
+            if (nearest_vert_in_other_mesh == null) {
+                nearest_vert_in_other_mesh = score_against.nearest(po.p);
 
                 // don't attract to vertices that face the other way
 
                 // don't attract to vertices that face the other way
-                if (watch.e == null || watch.norm().dot(norm()) < 0) {
-                    watch = null;
+                if (nearest_vert_in_other_mesh.e == null || nearest_vert_in_other_mesh.norm().dot(norm()) < 0) {
+                    nearest_vert_in_other_mesh = null;
                 } else {
                 } else {
-                    watch.watch_x += po.p.x;
-                    watch.watch_y += po.p.y;
-                    watch.watch_z += po.p.z;
-                    watch.watch_count++;
+                    nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x += po.p.x;
+                    nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y += po.p.y;
+                    nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z += po.p.z;
+                    nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count++;
                 }
             }
 
             double s1, s2;
                 }
             }
 
             double s1, s2;
-            if (watch_count==0) s1 = 0;
-            else                s1 = p.distance(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count);
-            s2 = watch==null ? 0 : po.p.distance(watch.p);
+            if (nearest_vert_in_other_mesh_count==0) s1 = 0;
+            else                s1 = p.distance(nearest_vert_in_other_mesh_x/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_y/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_z/nearest_vert_in_other_mesh_count);
+            s2 = nearest_vert_in_other_mesh==null ? 0 : po.p.distance(nearest_vert_in_other_mesh.p);
             oldscore = (float)(s1 + s2);
             score += oldscore;
         }
             oldscore = (float)(s1 + s2);
             score += oldscore;
         }
index 1f25ddc..7d14a71 100644 (file)
@@ -39,6 +39,9 @@ public class Matrix {
     public Matrix plus(Matrix x) {
         return new Matrix(a+x.a, b+x.b, c+x.c, d+x.d, e+x.e, f+x.f, g+x.g, h+x.h, i+x.i, j+x.j, k+x.k, l+x.l, m+x.m, n+x.n, o+x.o, p+x.p);
     }
     public Matrix plus(Matrix x) {
         return new Matrix(a+x.a, b+x.b, c+x.c, d+x.d, e+x.e, f+x.f, g+x.g, h+x.h, i+x.i, j+x.j, k+x.k, l+x.l, m+x.m, n+x.n, o+x.o, p+x.p);
     }
+    public Matrix minus(Matrix x) {
+        return new Matrix(a-x.a, b-x.b, c-x.c, d-x.d, e-x.e, f-x.f, g-x.g, h-x.h, i-x.i, j-x.j, k-x.k, l-x.l, m-x.m, n-x.n, o-x.o, p-x.p);
+    }
     public Matrix times(float x) {
         return new Matrix(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x, m*x, n*x, o*x, p*x);
     }
     public Matrix times(float x) {
         return new Matrix(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x, m*x, n*x, o*x, p*x);
     }