X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=f63bd1d55a02c20179f21ccd726d54f01a239d3b;hp=42f03d24abfe9c3a5cd782e69269593b0a22b0fa;hb=87e7ecfbdce5f5ecb16cd911f21890ccbaf4679c;hpb=0333b4f07d3e3cacb5975fe7ac3c8c3933150e37 diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 42f03d2..f63bd1d 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -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 @@ -92,47 +91,32 @@ 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 oldscore = 0; + public void setScore(float nscore) { + score -= oldscore; + oldscore = nscore; + score += oldscore; } - 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 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() { if (score_against==null) return null; return score_against.vertices.nearest(p, this); } + public void unComputeError() { setScore(0); } public void computeError() { - oldscore = + float nscore = 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 @@ -142,10 +126,9 @@ public class Mesh implements Iterable { 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) nscore += (ang - minangle); } - score += oldscore; + setScore(nscore); } private void removeTrianglesFromRTree() { @@ -187,9 +170,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; @@ -249,6 +240,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)