checkpoint
authoradam <adam@megacz.com>
Sun, 16 Dec 2007 03:21:40 +0000 (19:21 -0800)
committeradam <adam@megacz.com>
Sun, 16 Dec 2007 03:21:40 +0000 (19:21 -0800)
darcs-hash:20071216032140-5007d-40a3f6b766c6184986b80804e95d7b636245ac05.gz

src/edu/berkeley/qfat/Mesh.java
src/edu/berkeley/qfat/geom/PointSet.java
src/edu/berkeley/qfat/geom/RTree.java
src/edu/berkeley/qfat/geom/Visitor.java

index 3a4cba5..f95b33d 100644 (file)
@@ -8,6 +8,7 @@ import javax.media.opengl.glu.*;
 import edu.berkeley.qfat.geom.*;
 import edu.wlu.cs.levy.CG.KDTree;
 import edu.berkeley.qfat.geom.Point;
 import edu.berkeley.qfat.geom.*;
 import edu.wlu.cs.levy.CG.KDTree;
 import edu.berkeley.qfat.geom.Point;
+import com.infomatiq.jsi.IntProcedure;
 
 public class Mesh implements Iterable<Mesh.T> {
 
 
 public class Mesh implements Iterable<Mesh.T> {
 
@@ -74,7 +75,7 @@ public class Mesh implements Iterable<Mesh.T> {
     // Vertexices //////////////////////////////////////////////////////////////////////////////
 
     /** a vertex in the mesh */
     // Vertexices //////////////////////////////////////////////////////////////////////////////
 
     /** a vertex in the mesh */
-    public final class Vertex extends HasQuadric implements Visitor<T> {
+    public final class Vertex extends HasQuadric implements Visitor {
         public String toString() { return p.toString(); }
         public Point p;
         E e;                // some edge *leaving* this point
         public String toString() { return p.toString(); }
         public Point p;
         E e;                // some edge *leaving* this point
@@ -111,7 +112,7 @@ public class Mesh implements Iterable<Mesh.T> {
         public void applyQuadricToNeighbor() {
             if (score_against == null) return;
 
         public void applyQuadricToNeighbor() {
             if (score_against == null) return;
 
-            Vertex new_nearest = score_against.nearest(p);
+            Vertex new_nearest = (Vertex)nearest();
             if (nearest_in_other_mesh != null && new_nearest == nearest_in_other_mesh) return;
 
             if (nearest_in_other_mesh != null) unApplyQuadricToNeighbor();
             if (nearest_in_other_mesh != null && new_nearest == nearest_in_other_mesh) return;
 
             if (nearest_in_other_mesh != null) unApplyQuadricToNeighbor();
@@ -120,16 +121,13 @@ public class Mesh implements Iterable<Mesh.T> {
             nearest_in_other_mesh = new_nearest;
                 
             // don't attract to vertices that face the other way
             nearest_in_other_mesh = new_nearest;
                 
             // don't attract to vertices that face the other way
-
             if (((Vertex)nearest_in_other_mesh).e == null || ((Vertex)nearest_in_other_mesh).norm().dot(norm()) < 0) {
                 nearest_in_other_mesh = null;
             } else {
             if (((Vertex)nearest_in_other_mesh).e == null || ((Vertex)nearest_in_other_mesh).norm().dot(norm()) < 0) {
                 nearest_in_other_mesh = null;
             } else {
-
                 nearest_in_other_mesh.unComputeError();
                 nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.plus(fundamentalQuadric());
                 nearest_in_other_mesh.quadric_count++;
                 nearest_in_other_mesh.computeError();
                 nearest_in_other_mesh.unComputeError();
                 nearest_in_other_mesh.quadric = nearest_in_other_mesh.quadric.plus(fundamentalQuadric());
                 nearest_in_other_mesh.quadric_count++;
                 nearest_in_other_mesh.computeError();
-
             }
 
             reComputeError();
             }
 
             reComputeError();
@@ -149,7 +147,7 @@ public class Mesh implements Iterable<Mesh.T> {
             score -= oldscore;
             oldscore = 0;
         }
             score -= oldscore;
             oldscore = 0;
         }
-        public HasQuadric nearest() { return score_against.nearest(p); }
+        public HasQuadric nearest() { return score_against.vertices.nearest(p, this); }
         public void computeError() {
             oldscore =
                 quadric_count != 0
         public void computeError() {
             oldscore =
                 quadric_count != 0
@@ -159,7 +157,7 @@ public class Mesh implements Iterable<Mesh.T> {
                 : nearest_in_other_mesh != null
                 ? nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 * 10
                 : score_against != null
                 : nearest_in_other_mesh != null
                 ? nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 * 10
                 : score_against != null
-                ? score_against.nearest(p).fundamentalQuadric().preAndPostMultiply(p) * 100 * 10
+                ? nearest().fundamentalQuadric().preAndPostMultiply(p) * 100 * 10
                 : 0;
             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
                 double ang = Math.abs(e.crossAngle());
                 : 0;
             for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) {
                 double ang = Math.abs(e.crossAngle());
@@ -213,15 +211,24 @@ public class Mesh implements Iterable<Mesh.T> {
             return good;
         }
 
             return good;
         }
 
-        public void visit(T t) {
-            if (!good) return;
-            for(E e = Vertex.this.e; e!=null; e=e.pair.next==Vertex.this.e?null:e.pair.next) {
-                if (!t.has(e.p1) && !t.has(e.p2) && e.intersects(t)) { good = false; }
-                if (e.t != null) {
-                    if (!e.t.has(t.e1().p1) && !e.t.has(t.e1().p2) && t.e1().intersects(e.t)) { good = false; }
-                    if (!e.t.has(t.e2().p1) && !e.t.has(t.e2().p2) && t.e2().intersects(e.t)) { good = false; }
-                    if (!e.t.has(t.e3().p1) && !e.t.has(t.e3().p2) && t.e3().intersects(e.t)) { good = false; }
+        public boolean visit(Object o) {
+            if (o instanceof T) {
+                T t = (T)o;
+                if (!good) return false;
+                for(E e = Vertex.this.e; e!=null; e=e.pair.next==Vertex.this.e?null:e.pair.next) {
+                    if (!t.has(e.p1) && !t.has(e.p2) && e.intersects(t)) { good = false; }
+                    if (e.t != null) {
+                        if (!e.t.has(t.e1().p1) && !e.t.has(t.e1().p2) && t.e1().intersects(e.t)) { good = false; }
+                        if (!e.t.has(t.e2().p1) && !e.t.has(t.e2().p2) && t.e2().intersects(e.t)) { good = false; }
+                        if (!e.t.has(t.e3().p1) && !e.t.has(t.e3().p2) && t.e3().intersects(e.t)) { good = false; }
+                    }
                 }
                 }
+                return good;
+            } else {
+                Vertex v = (Vertex)o;
+                if (v.e==null || v.norm().dot(Vertex.this.norm()) < 0)
+                    return false;
+                return true;
             }
         }
         private boolean good;
             }
         }
         private boolean good;
index c1b4cf9..b75038c 100644 (file)
@@ -36,9 +36,10 @@ public class PointSet<V extends HasPoint> implements Iterable<V> {
         exact.remove(p);
     }
 
         exact.remove(p);
     }
 
-    public V nearest(Point p) {
+    public V nearest(Point p) { return nearest(p, null); }
+    public V nearest(Point p, Visitor<V> vis) {
         if (exact.size()==0) return null;
         if (exact.size()==0) return null;
-        return rtree.nearest(p);
+        return rtree.nearest(p, vis);
     }
 
     // FEATURE: compute incrementally?
     }
 
     // FEATURE: compute incrementally?
index 1e6e39a..5a29093 100644 (file)
@@ -55,22 +55,25 @@ public class RTree<V extends HasBoundingBox> implements Iterable<V> {
         rtree.delete(rect, id);
     }
 
         rtree.delete(rect, id);
     }
 
-    public V nearest(Point p) {
+    public V nearest(Point p) { return nearest(p, null); }
+    public V nearest(Point p, Visitor<V> ip) {
         point.set(p.x, p.y, p.z);
         point.set(p.x, p.y, p.z);
+        this.visitor = ip;
         rtree.nearest(point, myIntProcedure, Float.POSITIVE_INFINITY);
         rtree.nearest(point, myIntProcedure, Float.POSITIVE_INFINITY);
+        this.visitor = null;
         V ret = found;
         found = null;
         return ret;
     }
 
         V ret = found;
         found = null;
         return ret;
     }
 
-    public void range(HasBoundingBox v, Visitor vis) {
+    public void range(HasBoundingBox v, Visitor<V> vis) {
         visitor = vis;
         rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
         rtree.intersects(rect, myIntProcedure);
         visitor = null;
     }
 
         visitor = vis;
         rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
         rtree.intersects(rect, myIntProcedure);
         visitor = null;
     }
 
-    public void range(Point p1, Point p2, Visitor vis) {
+    public void range(Point p1, Point p2, Visitor<V> vis) {
         visitor = vis;
         rect.set(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
         rtree.intersects(rect, myIntProcedure);
         visitor = vis;
         rect.set(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
         rtree.intersects(rect, myIntProcedure);
@@ -79,12 +82,10 @@ public class RTree<V extends HasBoundingBox> implements Iterable<V> {
 
     private class MyIntProcedure implements IntProcedure {
         public boolean execute(int id) {
 
     private class MyIntProcedure implements IntProcedure {
         public boolean execute(int id) {
+            found = idToV.get(id);
             if (visitor != null) {
             if (visitor != null) {
-                V v = idToV.get(id);
-                visitor.visit(v);
-                return true;
+                return visitor.visit(found);
             } else {
             } else {
-                found = idToV.get(id);
                 return false;
             }
         }
                 return false;
             }
         }
index 897cdce..d794083 100644 (file)
@@ -1,5 +1,5 @@
 package edu.berkeley.qfat.geom;
 
 public interface Visitor<V> {
 package edu.berkeley.qfat.geom;
 
 public interface Visitor<V> {
-    public void visit(V v);
+    public boolean visit(V v);
 }
 }