checkpoint
authoradam <adam@megacz.com>
Mon, 7 Jul 2008 00:21:23 +0000 (17:21 -0700)
committeradam <adam@megacz.com>
Mon, 7 Jul 2008 00:21:23 +0000 (17:21 -0700)
darcs-hash:20080707002123-5007d-c4ce1fb25eb174864117db302e1c0445407e4cb4.gz

src/edu/berkeley/qfat/Main.java
src/edu/berkeley/qfat/geom/AffineConstraint.java
src/edu/berkeley/qfat/geom/BindingGroup.java
src/edu/berkeley/qfat/geom/HalfSpace.java
src/edu/berkeley/qfat/geom/HasBindingGroup.java
src/edu/berkeley/qfat/geom/Line.java
src/edu/berkeley/qfat/geom/Matrix.java
src/edu/berkeley/qfat/geom/Plane.java
src/edu/berkeley/qfat/geom/Point.java
src/edu/berkeley/qfat/geom/Polygon.java

index ac40acc..910c35c 100644 (file)
@@ -106,7 +106,7 @@ public class Main extends InteractiveMeshViewer {
                 polygons.add(new Polygon(hs));
         }
         for(Polygon p : polygons) {
                 polygons.add(new Polygon(hs));
         }
         for(Polygon p : polygons) {
-            System.out.println(p.plane.norm + " " + p.plane.dvalue);
+            System.out.println(p.plane.norm() + " " + p.plane.d);
             for(HalfSpace hs : halfSpaces) {
                 if (p.plane==hs) continue;
                 p = p.intersect(hs);
             for(HalfSpace hs : halfSpaces) {
                 if (p.plane==hs) continue;
                 p = p.intersect(hs);
index a6fb01c..0ac6f03 100644 (file)
@@ -6,15 +6,18 @@ public interface AffineConstraint {
 
     public Point getProjection(Point p);
     public AffineConstraint intersect(AffineConstraint c, float epsilon);
 
     public Point getProjection(Point p);
     public AffineConstraint intersect(AffineConstraint c, float epsilon);
+    public AffineConstraint multiply(Matrix m);
 
     public static class All implements AffineConstraint {
         public Point getProjection(Point p) { return p; }
         public AffineConstraint intersect(AffineConstraint c, float epsilon) { return c; }
 
     public static class All implements AffineConstraint {
         public Point getProjection(Point p) { return p; }
         public AffineConstraint intersect(AffineConstraint c, float epsilon) { return c; }
+        public AffineConstraint multiply(Matrix m) { return this; }
     }
 
     public static class Nothing implements AffineConstraint {
         public Point getProjection(Point p) { return null; }
         public AffineConstraint intersect(AffineConstraint c, float epsilon) { return this; }
     }
 
     public static class Nothing implements AffineConstraint {
         public Point getProjection(Point p) { return null; }
         public AffineConstraint intersect(AffineConstraint c, float epsilon) { return this; }
+        public AffineConstraint multiply(Matrix m) { return this; }
     }
 
 }
     }
 
 }
index 4df8cc4..e64cc17 100644 (file)
@@ -5,8 +5,9 @@ import java.util.*;
 /** tracks an equivalence class of geometric objects which are related to each other by transformation matrices */
 public class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
 
 /** tracks an equivalence class of geometric objects which are related to each other by transformation matrices */
 public class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
 
-    private T                  master   = null;
-    private HashMap<T,Matrix>  matrices = new HashMap<T,Matrix>();
+    private T                  master     = null;
+    private AffineConstraint   constraint = new AffineConstraint.All();
+    private HashMap<T,Matrix>  matrices   = new HashMap<T,Matrix>();
 
     public BindingGroup(T master) {
         this.master = master;
 
     public BindingGroup(T master) {
         this.master = master;
@@ -16,13 +17,20 @@ public class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
     public int size() { return matrices.size(); }
 
     public void merge(BindingGroup<T> bg, Matrix m) {
     public int size() { return matrices.size(); }
 
     public void merge(BindingGroup<T> bg, Matrix m) {
-        if (bg==this) throw new Error();
+        if (bg==this) {
+            if (m.equalsModuloEpsilon(Matrix.ONE, 0.001f)) return;
+            System.err.println(m.getAffineConstraint(0.001f));
+            return;
+        }
+
         for(HasBindingGroup hbg : bg.matrices.keySet()) {
             matrices.put((T)hbg, bg.matrices.get(hbg).times(m));
             hbg.bindingGroup = this;
         }
 
         for(HasBindingGroup hbg : bg.matrices.keySet()) {
             matrices.put((T)hbg, bg.matrices.get(hbg).times(m));
             hbg.bindingGroup = this;
         }
 
-        Matrix v = getMatrix(bg.master, master);
+        // FIXME: what if points do not fall on the merged constraint-line?
+        AffineConstraint ac = bg.constraint.multiply(getMatrix(master, bg.master));
+        constraint = constraint.intersect(ac, 0.001f);
 
         HashSet<HasBindingGroup> stuff = new HashSet<HasBindingGroup>();
         for(HasBindingGroup hbg : bg.matrices.keySet())
 
         HashSet<HasBindingGroup> stuff = new HashSet<HasBindingGroup>();
         for(HasBindingGroup hbg : bg.matrices.keySet())
@@ -45,6 +53,10 @@ public class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
         return getMatrix(t1).times(getMatrix(t2).inverse());
     }
 
         return getMatrix(t1).times(getMatrix(t2).inverse());
     }
 
+    public AffineConstraint getConstraint(T t) {
+        return constraint.multiply(matrices.get(t));
+    }
+
     public void unbind(T trem) {
         if (trem != master) {
             matrices.remove(trem);
     public void unbind(T trem) {
         if (trem != master) {
             matrices.remove(trem);
index a48a22c..8667903 100644 (file)
@@ -6,7 +6,7 @@ public final class HalfSpace extends Plane {
     public HalfSpace(Point p, Vec norm) { super(p, norm); }
 
     public boolean contains(Point p, float epsilon) {
     public HalfSpace(Point p, Vec norm) { super(p, norm); }
 
     public boolean contains(Point p, float epsilon) {
-        return p.x*norm.x+p.y*norm.y+p.z*norm.z + dvalue <= epsilon;
+        return p.x*norm().x+p.y*norm().y+p.z*norm().z + d <= epsilon;
     }
 
 }
     }
 
 }
index ecc4f1c..16dee1c 100644 (file)
@@ -16,12 +16,6 @@ public abstract class HasBindingGroup {
         if (bindingGroup == null) bindingGroup = new BindingGroup(this);
         if (other.bindingGroup == null) other.bindingGroup = new BindingGroup(other);
 
         if (bindingGroup == null) bindingGroup = new BindingGroup(this);
         if (other.bindingGroup == null) other.bindingGroup = new BindingGroup(other);
 
-        if (other.bindingGroup == this.bindingGroup) {
-            if (getBindingMatrix(other).equalsModuloEpsilon(bindingMatrix, 0.001f))
-                return;
-            return;
-        }
-
         bindingMatrix =
             getBindingMatrix().inverse()
             .times(bindingMatrix)
         bindingMatrix =
             getBindingMatrix().inverse()
             .times(bindingMatrix)
index 5997130..a4dd2a0 100644 (file)
@@ -66,4 +66,8 @@ public class Line implements AffineConstraint {
         return new Point(x, m*x+c, n*x+d);
     }
 
         return new Point(x, m*x+c, n*x+d);
     }
 
+    public AffineConstraint multiply(Matrix m) {
+        throw new RuntimeException("not yet implemented");
+    }
+
 }
 }
index 372e6c2..3713761 100644 (file)
@@ -367,7 +367,7 @@ public class Matrix {
     }
 
     /** returns the constraint-conjunction "(forall v)Mv=v" */
     }
 
     /** returns the constraint-conjunction "(forall v)Mv=v" */
-    public AffineConstraint getConstraint(float epsilon) {
+    public AffineConstraint getAffineConstraint(float epsilon) {
         AffineConstraint c1 = getConstraint(a-1, b,   c,   d  , epsilon);
         AffineConstraint c2 = getConstraint(e,   f-1, g,   h  , epsilon);
         AffineConstraint c3 = getConstraint(i,   j,   k-1, l  , epsilon);
         AffineConstraint c1 = getConstraint(a-1, b,   c,   d  , epsilon);
         AffineConstraint c2 = getConstraint(e,   f-1, g,   h  , epsilon);
         AffineConstraint c3 = getConstraint(i,   j,   k-1, l  , epsilon);
index 5f5d990..b3aacdd 100644 (file)
@@ -3,29 +3,34 @@ import javax.media.opengl.*;
 
 public class Plane implements AffineConstraint {
 
 
 public class Plane implements AffineConstraint {
 
-    // FIXME: could be given by
     // ax+by+cz=d
     // ax+by+cz=d
+    public final float a, b, c, d;
 
 
-    public final Vec norm;
-    public final float dvalue;
+    public Vec norm() { return new Vec(a, b, c); }
 
     public Plane(Point p, Vec norm) {
 
     public Plane(Point p, Vec norm) {
-        this.norm = norm.norm();
-        this.dvalue = p.x*this.norm.x+p.y*this.norm.y+p.z*this.norm.z;
+        this.a = norm.x;
+        this.b = norm.y;
+        this.c = norm.z;
+        this.d = p.x*norm.x+p.y*norm.y+p.z*norm.z;
     }
 
     /** provided at least one of a,b,c is nonzero, return the Plane representing ax+by+cz=d */
     public Plane(float a, float b, float c, float d) {
     }
 
     /** provided at least one of a,b,c is nonzero, return the Plane representing ax+by+cz=d */
     public Plane(float a, float b, float c, float d) {
-        throw new RuntimeException("not implemented yet");
+        this.a = a;
+        this.b = b;
+        this.c = c;
+        this.d = d;
     }
 
     public Point intersect(Plane p1, Plane p2) {
     }
 
     public Point intersect(Plane p1, Plane p2) {
+        Vec norm = norm();
         Plane p3 = this;
         Plane p3 = this;
-        float z = p1.norm.dot(p2.norm.cross(p3.norm));
+        float z = p1.norm().dot(p2.norm().cross(p3.norm()));
         if (Math.abs(z) < 0.0001) return null;  // planes do not intersect at a point
         if (Math.abs(z) < 0.0001) return null;  // planes do not intersect at a point
-        Vec v1 = p2.norm.cross(p3.norm).times(-1 * p1.dvalue);
-        Vec v2 = p3.norm.cross(p1.norm).times(-1 * p2.dvalue);
-        Vec v3 = p1.norm.cross(p2.norm).times(-1 * p3.dvalue);
+        Vec v1 = p2.norm().cross(p3.norm()).times(-1 * p1.d);
+        Vec v2 = p3.norm().cross(p1.norm()).times(-1 * p2.d);
+        Vec v3 = p1.norm().cross(p2.norm()).times(-1 * p3.d);
         return Point.ZERO.plus(v1.plus(v2).plus(v3).times(1/z));
     }
 
         return Point.ZERO.plus(v1.plus(v2).plus(v3).times(1/z));
     }
 
@@ -36,4 +41,8 @@ public class Plane implements AffineConstraint {
     public AffineConstraint intersect(AffineConstraint c, float epsilon) {
         throw new RuntimeException("not implemented yet");
     }
     public AffineConstraint intersect(AffineConstraint c, float epsilon) {
         throw new RuntimeException("not implemented yet");
     }
+
+    public AffineConstraint multiply(Matrix m) {
+        throw new RuntimeException("not yet implemented");
+    }
 }
 }
index 57c8667..0194ef3 100644 (file)
@@ -39,5 +39,6 @@ public final class Point extends HasPoint implements HasBoundingBox, AffineConst
         if (c.getProjection(this).distance(this) <= epsilon) return this;
         return null;
     }
         if (c.getProjection(this).distance(this) <= epsilon) return this;
         return null;
     }
+    public AffineConstraint multiply(Matrix m) { return m.times(this); }
 }
 
 }
 
index 2afa144..00458b2 100644 (file)
@@ -65,8 +65,8 @@ public final class Polygon {
         //centroid = new Point(round(centroid.x), round(centroid.y), round(centroid.z));
         if (segments.size() >= 3)
         for(Segment s : segments) {
         //centroid = new Point(round(centroid.x), round(centroid.y), round(centroid.z));
         if (segments.size() >= 3)
         for(Segment s : segments) {
-            System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm.times(-1));
-            mesh.newT(s.p1, centroid, s.p2, plane.norm.times(-1), 0);
+            System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm().times(-1));
+            mesh.newT(s.p1, centroid, s.p2, plane.norm().times(-1), 0);
         }
         System.out.println("done");
         return null;
         }
         System.out.println("done");
         return null;