checkpoint
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index eecaad8..774efa3 100644 (file)
@@ -65,7 +65,7 @@ public class Mesh implements Iterable<Mesh.T> {
         }
     }
 
-    public void unscore() {
+    public void unscoreAll() {
         HashSet<Vert> done = new HashSet<Vert>();
         for(T t : this)
             for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() }) {
@@ -74,7 +74,7 @@ public class Mesh implements Iterable<Mesh.T> {
                 p.unscore();
             }
     }
-    public void fundamental() {
+    public void recomputeAllFundamentalQuadrics() {
         HashSet<Vert> done = new HashSet<Vert>();
         for(T t : this)
             for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() }) {
@@ -83,7 +83,7 @@ public class Mesh implements Iterable<Mesh.T> {
                 p.recomputeFundamentalQuadric();
             }
     }
-    public float rescore() {
+    public float rescoreAll() {
         int num = 0;
         double dist = 0;
         HashSet<Vert> done = new HashSet<Vert>();
@@ -186,18 +186,23 @@ public class Mesh implements Iterable<Mesh.T> {
         public void unscore() {
             if (nearest_in_other_mesh == null) return;
             if (fundamentalQuadric == null) return;
+            nearest_in_other_mesh.unsc();
             nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.minus(fundamentalQuadric);
             nearest_in_other_mesh.quadric_count--;
             if (nearest_in_other_mesh.quadric_count==0)
                 nearest_in_other_mesh.quadric = Matrix.ZERO;
+            nearest_in_other_mesh.resc();
             nearest_in_other_mesh = null;
         }
 
+        public void unsc() {
+            score -= oldscore;
+            oldscore = 0;
+        }
         public void rescore() {
             if (score_against == null) return;
 
-            score -= oldscore;
-            oldscore = 0;
+            unsc();
 
             if (nearest_in_other_mesh != null) unscore();
             if (nearest_in_other_mesh == null) {
@@ -207,11 +212,16 @@ public class Mesh implements Iterable<Mesh.T> {
                 if (nearest_in_other_mesh.e == null || nearest_in_other_mesh.norm().dot(norm()) < 0) {
                     nearest_in_other_mesh = null;
                 } else {
+                    nearest_in_other_mesh.unsc();
                     nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.plus(fundamentalQuadric());
                     nearest_in_other_mesh.quadric_count++;
+                    nearest_in_other_mesh.resc();
                 }
             }
 
+            resc();
+        }
+        public void resc() {
             oldscore = quadric_count == 0 ? 0 : (quadric.preAndPostMultiply(p) / quadric_count);
             score += oldscore;
         }