X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=c85de26f550f4c50daa8109f87284807030a5fff;hb=94a51f6ee148dbc5dc4fddcd6e3bd13fee12f4fa;hp=a93535799bb82953a400c69e76cd0e97d48d0c20;hpb=4d3990172ccd3eae8c771780a7a0c3bc0d897f36;p=anneal.git diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index a935357..c85de26 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -14,49 +14,22 @@ public class Mesh implements Iterable { public static final float EPSILON = (float)0.0001; public static final Random random = new Random(); + private RTree tris = new RTree(); private PointSet vertices = new PointSet(); - public int size() { return vertices.size(); } - public Iterable vertices() { return vertices; } - - public Iterable edges() { - return - new Iterable() { - public Iterator iterator() { - // HACK - HashSet hse = new HashSet(); - for(T t : Mesh.this) { - hse.add(t.e1()); - hse.add(t.e2()); - hse.add(t.e3()); - hse.add(t.e1().pair); - hse.add(t.e2().pair); - hse.add(t.e3().pair); - } - return hse.iterator(); - } }; - } - - public Iterator iterator() { - /* - for(Vert v : vertices) - if (v.e != null && v.e.t != null) - return new FaceIterator(v); - return new FaceIterator(); - */ - return ts.iterator(); - } - - public HashSet ts = new HashSet(); - public RTree tris = new RTree(); - public Mesh score_against = null; public double score = 0; public float score() { return (float)score; } - public int numedges = 0; public float avgedge = 0; + public int size() { return vertices.size(); } + public Iterable vertices() { return vertices; } + + public Iterator iterator() { + return tris.iterator(); + } + public void rebindPoints() { // unbind all points for(Mesh.T t : this) { @@ -511,6 +484,7 @@ public class Mesh implements Iterable { public BindingGroup bind_to = bind_peers.other(); boolean shattered = false; + public boolean intersects(T t) { return t.intersects(p1.p, p2.p); } public float comparator() { Vert nearest = score_against.nearest(midpoint()); //if (t==null) return length(); @@ -697,75 +671,6 @@ public class Mesh implements Iterable { public float length() { return p1.p.minus(p2.p).mag(); } public String toString() { return p1+"->"+p2; } - public boolean intersects(T t) { - double A0=t.v1().p.x, A1=t.v1().p.y, A2=t.v1().p.z; - double B0=t.v2().p.x, B1=t.v2().p.y, B2=t.v2().p.z; - double C0=t.v3().p.x, C1=t.v3().p.y, C2=t.v3().p.z; - double j0=p1.p.x, j1=p1.p.y, j2=p1.p.z; - double k0=p2.p.x, k1=p2.p.y, k2=p2.p.z; - double J0, J1, J2; - double K0, K1, K2; - double i0, i1, i2; - double a0, a1, a2; - double b0, b1, b2; - double c0, c1, c2; - double in_det; - double R00, R01, R02, R03, - R10, R11, R12, R13, - R20, R21, R22, R23, - R30, R31, R32, R33; - - - /* a = B - A */ - a0 = B0 - A0; - a1 = B1 - A1; - a2 = B2 - A2; - /* b = C - B */ - b0 = C0 - A0; - b1 = C1 - A1; - b2 = C2 - A2; - /* c = a × b */ - c0 = a1 * b2 - a2 * b1; - c1 = a2 * b0 - a0 * b2; - c2 = a0 * b1 - a1 * b0; - - /* M^(-1) = (1/det(M)) * adj(M) */ - in_det = 1 / (c0 * c0 + c1 * c1 + c2 * c2); - R00 = (b1 * c2 - b2 * c1) * in_det; - R01 = (b2 * c0 - b0 * c2) * in_det; - R02 = (b0 * c1 - b1 * c0) * in_det; - R10 = (c1 * a2 - c2 * a1) * in_det; - R11 = (c2 * a0 - c0 * a2) * in_det; - R12 = (c0 * a1 - c1 * a0) * in_det; - R20 = (c0) * in_det; - R21 = (c1) * in_det; - R22 = (c2) * in_det; - - /* O = M^(-1) * A */ - R03 = -(R00 * A0 + R01 * A1 + R02 * A2); - R13 = -(R10 * A0 + R11 * A1 + R12 * A2); - R23 = -(R20 * A0 + R21 * A1 + R22 * A2); - - /* fill in last row of 4x4 matrix */ - R30 = R31 = R32 = 0; - R33 = 1; - - J2 = R20 * j0 + R21 * j1 + R22 * j2 + R23; - K2 = R20 * k0 + R21 * k1 + R22 * k2 + R23; - if (J2 * K2 >= 0) return false; - - J0 = R00 * j0 + R01 * j1 + R02 * j2 + R03; - K0 = R00 * k0 + R01 * k1 + R02 * k2 + R03; - i0 = J0 + J2 * ((K0 - J0) / (J2 - K2)); - if (i0 < 0 || i0 > 1) return false; - - J1 = R10 * j0 + R11 * j1 + R12 * j2 + R13; - K1 = R10 * k0 + R11 * k1 + R12 * k2 + R13; - i1 = J1 + J2 * ((K1 - J1) / (J2 - K2)); - if (i1 < 0 || i1 > 1 || i0 + i1 > 1) return false; - - return true; - } } public E makeE(Point p1, Point p2) { @@ -834,10 +739,7 @@ public class Mesh implements Iterable { public void removeFromRTree() { tris.remove(this); } public void addToRTree() { tris.insert(this); } - public void destroy() { - tris.remove(this); - ts.remove(this); - } + public void destroy() { tris.remove(this); } T(E e1, int colorclass) { this.e1 = e1; @@ -862,7 +764,6 @@ public class Mesh implements Iterable { } this.color = color; this.colorclass = colorclass; - ts.add(this); tris.add(this); } public E e1() { return e1; } @@ -879,9 +780,11 @@ public class Mesh implements Iterable { public void glVertices(GL gl) { + /* if (e1().bind_to.set.size() == 0) return; if (e2().bind_to.set.size() == 0) return; if (e3().bind_to.set.size() == 0) return; + */ norm().glNormal(gl); p1().glVertex(gl);