checkpoint
authoradam <adam@megacz.com>
Wed, 5 Dec 2007 04:49:14 +0000 (20:49 -0800)
committeradam <adam@megacz.com>
Wed, 5 Dec 2007 04:49:14 +0000 (20:49 -0800)
darcs-hash:20071205044914-5007d-ce494b80fc1e03e2643f35fbb4806268cfd3856d.gz

src/edu/berkeley/qfat/Mesh.java

index 523f6e1..5b98a31 100644 (file)
@@ -20,7 +20,10 @@ public class Mesh implements Iterable<Mesh.T> {
     public  HashSet<E>           es = new HashSet<E>();
     public  ArrayList<T>         ts = new ArrayList<T>();
 
-    public Iterator<T> iterator() { return ts.iterator(); }
+    public Iterator<T> iterator() {
+        if (es.size() == 0) return new FaceIterator();
+        return new FaceIterator(es.iterator().next().p1);
+    }
 
     public Point origin() { return new Point(0, 0, 0); }
 
@@ -51,17 +54,17 @@ public class Mesh implements Iterable<Mesh.T> {
         int num = 0;
         double dist = 0;
         HashSet<Vert> done = new HashSet<Vert>();
-        for(T t : ts)
+        for(T t : this)
             for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() }) {
                 if (done.contains(p)) continue;
                 done.add(p);
                 p.rescore();
             }
-        for(T t : ts)
+        for(T t : this)
             for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() })
                 p.kdremove();
         kd = new KDTree(3);
-        for(T t : ts)
+        for(T t : this)
             for(Vert p : new Vert[] { t.v1(), t.v2(), t.v3() })
                 p.kdinsert();
         return (float)(dist/num);
@@ -113,7 +116,7 @@ public class Mesh implements Iterable<Mesh.T> {
 
     public float volume() {
         double total = 0;
-        for(T t : ts) {
+        for(T t : this) {
             double area = t.area();
             Vec origin_to_centroid = new Vec(new Point(0, 0, 0), t.centroid());
             boolean facingAway = t.norm().dot(origin_to_centroid) > 0;
@@ -599,9 +602,11 @@ public class Mesh implements Iterable<Mesh.T> {
         return ret;
     }
 
+
     public class FaceIterator implements Iterator<T> {
         private HashSet<T> visited = new HashSet<T>();
         private LinkedList<T> next = new LinkedList<T>();
+        public FaceIterator() { }
         public FaceIterator(Vert v) { next.addFirst(v.e.t); }
         public boolean hasNext() { return next.peek()!=null; }
         public void remove() { throw new Error(); }