X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=f63bd1d55a02c20179f21ccd726d54f01a239d3b;hp=1a210cd1dc152dcaa90165d60d52fcb6c37c6226;hb=87e7ecfbdce5f5ecb16cd911f21890ccbaf4679c;hpb=77be9651f3e4d3b99582ffdf2561608c50b6208c diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 1a210cd..f63bd1d 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -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 com.infomatiq.jsi.IntProcedure; public class Mesh implements Iterable { @@ -74,8 +75,7 @@ public class Mesh implements Iterable { // Vertexices ////////////////////////////////////////////////////////////////////////////// /** a vertex in the mesh */ - public final class Vertex extends HasQuadric implements Visitor { - public String toString() { return p.toString(); } + public final class Vertex extends HasQuadric implements Visitor { public Point p; E e; // some edge *leaving* this point @@ -91,84 +91,44 @@ 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() { - unApplyQuadricToNeighbor(); - if (quadricStale || fundamentalQuadric==null) { - 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())); - count++; - } - quadricStale = false; - fundamentalQuadric = m.times(1/(float)count); + 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) { + m = m.plus(e.t.norm().fundamentalQuadric(e.t.centroid())); + count++; } - applyQuadricToNeighbor(); + return m.times(1/(float)count); } - public void applyQuadricToNeighbor() { - if (score_against == null) return; - - Vertex new_nearest = score_against.nearest(p); - 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; - - // 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 { - 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 (score_against==null) return null; + return score_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.nearest(p); } + 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 - ? 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()); 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() { @@ -210,18 +170,35 @@ public class Mesh implements Iterable { if (!ignorecollision && good) triangles.range(oldp, this.p, (Visitor)this); reComputeErrorAround(); + 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 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; + 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; @@ -263,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)