X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=8243b184b6ab89f303f144719509d07892c6cbb8;hp=c563563a906c1e87c9706793570fdfac3c1292f5;hb=6b8b94ec2b88321d9f53b759200137657445a08a;hpb=366e1c99a39b4ac6e8a55828678ce0213e1badc2 diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index c563563..8243b18 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -20,13 +20,13 @@ public class Mesh implements Iterable { public boolean immutableVertices; public boolean ignorecollision = false; - public Mesh score_against = null; - public double score = 0; + public Mesh error_against = null; + public double error = 0; public Mesh(boolean immutableVertices) { this.immutableVertices = immutableVertices; } public void makeVerticesImmutable() { this.immutableVertices = true; } - public float score() { return (float)score; } + public float error() { return (float)error; } public int size() { return vertices.size(); } public Iterable vertices() { return vertices; } @@ -76,7 +76,6 @@ public class Mesh implements Iterable { /** a vertex in the mesh */ public final class Vertex extends HasQuadric implements Visitor { - public String toString() { return p.toString(); } public Point p; E e; // some edge *leaving* this point @@ -84,7 +83,7 @@ public class Mesh implements Iterable { Vertex bound_to = this; public Point getPoint() { return p; } - public float score() { return oldscore; } + public float error() { return olderror; } private Vertex(Point p) { this.p = p; @@ -92,76 +91,45 @@ public class Mesh implements Iterable { vertices.add(this); } - private void glNormal(GL gl) { - Vec norm = norm(); - gl.glNormal3f(norm.x, norm.y, norm.z); + public float olderror = 0; + public void setError(float nerror) { + error -= olderror; + olderror = nerror; + error += olderror; } - public void _recomputeFundamentalQuadric() { + public Matrix _recomputeFundamentalQuadric() { Matrix m = Matrix.ZERO; int count = 0; for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) { - T t = e.t; - m = m.plus(t.norm().fundamentalQuadric(t.centroid())); + m = m.plus(e.t.norm().fundamentalQuadric(e.t.centroid())); count++; } - quadricStale = false; - fundamentalQuadric = m.times(1/(float)count); + return m.times(1/(float)count); } - public void applyQuadricToNeighbor() { - if (score_against == null) return; - - 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) throw new Error(); - - nearest_in_other_mesh = new_nearest; - - 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(); + public HasQuadric nearest() { + if (error_against==null) return null; + return error_against.vertices.nearest(p, this); } - public void reComputeErrorAround() { - reComputeError(); - if (nearest_in_other_mesh != null) nearest_in_other_mesh.reComputeError(); - for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) - e.p2.reComputeError(); - } - public void reComputeError() { - unComputeError(); - computeError(); - } - public void unComputeError() { - score -= oldscore; - oldscore = 0; - } - public HasQuadric nearest() { return score_against.vertices.nearest(p, this); } + public void computeError() { - oldscore = + float nerror = quadric_count != 0 ? (quadric.preAndPostMultiply(p) * 100) / quadric_count - : immutableVertices - ? oldscore : nearest_in_other_mesh != null ? nearest_in_other_mesh.fundamentalQuadric().preAndPostMultiply(p) * 100 * 10 - : score_against != null + : error_against != null ? 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()); if (ang > Math.PI) throw new Error(); float minangle = (float)(Math.PI * 0.8); - if (ang > minangle) - oldscore += (ang - minangle); + if (ang > minangle) nerror += (ang - minangle); } - score += oldscore; + setError(nerror); } private void removeTrianglesFromRTree() { @@ -203,9 +171,17 @@ public class Mesh implements Iterable { if (!ignorecollision && good) triangles.range(oldp, this.p, (Visitor)this); reComputeErrorAround(); + return good; } + public void reComputeErrorAround() { + reComputeError(); + if (nearest_in_other_mesh != null) nearest_in_other_mesh.reComputeError(); + for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) + e.p2.reComputeError(); + } + public boolean visit(Object o) { if (o instanceof T) { T t = (T)o; @@ -265,6 +241,10 @@ public class Mesh implements Iterable { return null; } + private void glNormal(GL gl) { + Vec norm = norm(); + gl.glNormal3f(norm.x, norm.y, norm.z); + } public Vec norm() { Vec norm = new Vec(0, 0, 0); for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) @@ -347,7 +327,7 @@ public class Mesh implements Iterable { public boolean intersects(T t) { return t.intersects(p1.p, p2.p); } public float comparator() { - Vertex nearest = score_against.nearest(midpoint()); + Vertex nearest = error_against.nearest(midpoint()); return (float)Math.max(length(), midpoint().distance(nearest.p)); } public int compareTo(E e) {