checkpoint
[anneal.git] / src / edu / berkeley / qfat / Mesh.java
index f5ce535..926a5b7 100644 (file)
@@ -6,8 +6,8 @@ import javax.swing.*;
 import javax.media.opengl.*;
 import javax.media.opengl.glu.*;
 import edu.berkeley.qfat.geom.*;
-import edu.berkeley.qfat.geom.HasBindingGroup;
 import edu.wlu.cs.levy.CG.KDTree;
+import edu.berkeley.qfat.bind.*;
 import edu.berkeley.qfat.geom.Point;
 import com.infomatiq.jsi.IntProcedure;
 
@@ -215,8 +215,19 @@ public class Mesh implements Iterable<Mesh.T> {
 
     // Vertexices //////////////////////////////////////////////////////////////////////////////
 
+
     /** a vertex in the mesh */
-    public final class Vertex extends HasQuadric implements Visitor {
+    public final class Vertex extends HasQuadric implements Visitor, HasPoint {
+        public void bindTo(Matrix bindingMatrix, HasBindingGroup other) {
+            bindTo(bindingMatrix, other, EPSILON);
+        }
+        public float getMaxX() { return getPoint().getMaxX(); }
+        public float getMinX() { return getPoint().getMinX(); }
+        public float getMaxY() { return getPoint().getMaxY(); }
+        public float getMinY() { return getPoint().getMinY(); }
+        public float getMaxZ() { return getPoint().getMaxZ(); }
+        public float getMinZ() { return getPoint().getMinZ(); }
+
         public Point p, goodp;
         public Point oldp;
         E e;                // some edge *leaving* this point
@@ -364,7 +375,7 @@ public class Mesh implements Iterable<Mesh.T> {
                 float minangle = (float)(Math.PI * 0.8);
                 //nerror += ((ang / Math.PI)*(ang/Math.PI)) * e.length() * 0.05;
 
-                nerror += (1-e.t.quality())*0.0001;
+                //nerror += (1-e.t.quality())*0.0001;
                 if (ang > minangle) nerror += (ang - minangle);
 
                 //System.out.println(((ang / Math.PI)*(ang/Math.PI)) * 0.000001);
@@ -399,27 +410,21 @@ public class Mesh implements Iterable<Mesh.T> {
             //     t1 =     t1.getMatrix(t2) * t2
             // M * t1 = M * t1.getMatrix(t2) * t2
 
+            /*
             if (bindingGroup!=null && this != bindingGroup.getMaster()) {
                 Matrix m2 = getBindingMatrix(bindingGroup.getMaster());
                 Vec v2 = m2.times(vv.plus(getPoint())).minus(m2.times(getPoint()));
                 return ((Vertex)bindingGroup.getMaster()).move(v2, ignoreProblems);
             }
+            */
 
             Point op = this.p;
-            Point pp = vv.plus(getPoint());
-            if (bindingGroup != null) {
-                /*
-                for(int i=0; i<20 ; i++) {
-                    Point v2 = getConstraint().times(pp);
-                    pp = pp.midpoint(v2);
-                    //System.out.println(m.minus(m2));
-                }
-            */
-                //pp = getConstraint().times(pp);
-            }
-            //pp = pp.minus(op).norm().times(vv.mag()).plus(op);
-            ok = false;
-            Point pt = pp;
+            Point pt = vv.plus(getPoint());
+            Point pp = pt;
+            pt = getBindingConstraint().getProjection(pp);
+            if (pt==null) return false;
+            System.out.println(pt.minus(pp).mag() + " " + getBindingConstraint());
+
             for(Vertex v : (Iterable<Vertex>)getBoundPeers()) {
                 Point pt2 = v.getBindingMatrix(this).times(pt);
                 /*
@@ -563,6 +568,10 @@ public class Mesh implements Iterable<Mesh.T> {
     /** [UNIQUE] an edge */
     public final class E extends HasBindingGroup implements Comparable<E> {
 
+        public void bindTo(Matrix bindingMatrix, HasBindingGroup other) {
+            bindTo(bindingMatrix, other, EPSILON);
+        }
+
         public void sanity() {
             if (destroyed) return;
             if (pair!=null && (pair.v1!=v2 || pair.v2!=v1)) throw new RuntimeException();
@@ -616,14 +625,9 @@ public class Mesh implements Iterable<Mesh.T> {
 
         }
 
-        public void bindingGroupChanged(edu.berkeley.qfat.geom.BindingGroup newBindingGroup_) {
-
-            edu.berkeley.qfat.geom.BindingGroup<E> newBindingGroup =
-                (edu.berkeley.qfat.geom.BindingGroup<E>)newBindingGroup_;
-            if (newBindingGroup==null) return;
-            if (this==newBindingGroup.getMaster()) return;
+        public void bindingGroupChanged() {
             HashSet<E> nbg = new HashSet<E>();
-            for(E eother : (Iterable<E>)newBindingGroup) nbg.add(eother);
+            for(E eother : (Iterable<E>)getBoundPeers()) nbg.add(eother);
             for(E eother : nbg) {
                 if (next==null || prev==null) continue;
                 if (eother.next==null || eother.prev==null) continue;
@@ -697,8 +701,10 @@ public class Mesh implements Iterable<Mesh.T> {
                 if (e==this) continue;
                 v1.bindTo(getBindingMatrix(e), e.v1);
                 v2.bindTo(getBindingMatrix(e), e.v2);
-                e.v1.setConstraint(getConstraint());
-                e.v2.setConstraint(getConstraint());
+                /*
+                e.v1.setConstraint(getAffineConstraint());
+                e.v2.setConstraint(getAffineConstraint());
+                */
             }
         }
 
@@ -741,8 +747,8 @@ public class Mesh implements Iterable<Mesh.T> {
                 e.v2.getE(mid).pair.pair.bindTo(e.getBindingMatrix(firste), firstq.pair);
             }
             /*
-            first.setConstraint(firste.getConstraint());
-            firstq.setConstraint(firste.getConstraint());
+            first.setConstraint(firste.getAffineConstraint());
+            firstq.setConstraint(firste.getAffineConstraint());
             */
             return nearest(midpoint());
         }
@@ -1074,8 +1080,8 @@ public class Mesh implements Iterable<Mesh.T> {
             }
             */
             /*
-            first.setConstraint(firste.getConstraint());
-            firstq.setConstraint(firste.getConstraint());
+            first.setConstraint(firste.getAffineConstraint());
+            firstq.setConstraint(firste.getAffineConstraint());
             */
             return null;
         }