X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=6fd53d3e68d6002dde7ed63cb0a637f73893ec9e;hp=f63bd1d55a02c20179f21ccd726d54f01a239d3b;hb=ba475c8edc2d38444381eeed6545ae36e47b093e;hpb=87e7ecfbdce5f5ecb16cd911f21890ccbaf4679c diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index f63bd1d..6fd53d3 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; } @@ -50,7 +50,7 @@ public class Mesh implements Iterable { public void transform(Matrix m) { ArrayList set = new ArrayList(); for(Vertex v : vertices) set.add(v); - for(Vertex v : set) v.transform(m); + for(Vertex v : set) v.transform(m.times(v.p), true); } public void rebuild() { /*vertices.rebuild();*/ } @@ -76,14 +76,15 @@ public class Mesh implements Iterable { /** a vertex in the mesh */ public final class Vertex extends HasQuadric implements Visitor { - public Point p; + public Point p, oldp; E e; // some edge *leaving* this point Matrix binding = Matrix.ONE; Vertex bound_to = this; + private boolean good; public Point getPoint() { return p; } - public float score() { return oldscore; } + public float error() { return olderror; } private Vertex(Point p) { this.p = p; @@ -91,11 +92,11 @@ public class Mesh implements Iterable { vertices.add(this); } - public float oldscore = 0; - public void setScore(float nscore) { - score -= oldscore; - oldscore = nscore; - score += oldscore; + public float olderror = 0; + public void setError(float nerror) { + error -= olderror; + olderror = nerror; + error += olderror; } public Matrix _recomputeFundamentalQuadric() { @@ -108,68 +109,54 @@ public class Mesh implements Iterable { return m.times(1/(float)count); } - public HasQuadric nearest() { - if (score_against==null) return null; - return score_against.vertices.nearest(p, this); - } - public void unComputeError() { setScore(0); } + public HasQuadric nearest() { return error_against==null ? null : error_against.vertices.nearest(p, this); } public void computeError() { - float nscore = + float nerror = quadric_count != 0 ? (quadric.preAndPostMultiply(p) * 100) / quadric_count : 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) nscore += (ang - minangle); + if (ang > minangle) nerror += (ang - minangle); } - setScore(nscore); - } - - private void removeTrianglesFromRTree() { - for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) - if (e.t != null) e.t.removeFromRTree(); - } - private void addTrianglesToRTree() { - for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) - if (e.t != null) e.t.addToRTree(); + setError(nerror); } /** does NOT update bound pairs! */ - public boolean transform(Matrix m) { + public boolean transform(Point newp, boolean ignoreProblems) { + this.oldp = this.p; if (immutableVertices) throw new Error(); unApplyQuadricToNeighbor(); - Point oldp = this.p; if (vertices.get(this.p)==null) throw new Error(); vertices.remove(this); - removeTrianglesFromRTree(); - float newx = m.a*p.x + m.b*p.y + m.c*p.z + m.d; - float newy = m.e*p.x + m.f*p.y + m.g*p.z + m.h; - float newz = m.i*p.x + m.j*p.y + m.k*p.z + m.l; - this.p = new Point(newx, newy, newz); - addTrianglesToRTree(); + for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) + if (e.t != null) e.t.removeFromRTree(); + this.p = newp; + for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) + if (e.t != null) e.t.addToRTree(); vertices.add(this); applyQuadricToNeighbor(); good = true; - for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) { - if (Math.abs(e.crossAngle()) > (Math.PI * 0.9) || Math.abs(e.next.crossAngle()) > (Math.PI * 0.9)) good = false; - if (e.t.aspect() < 0.1) good = false; - e.p2.quadricStale = true; - } - - if (!ignorecollision && good) triangles.range(oldp, this.p, (Visitor)this); + if (!ignoreProblems) + for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) { + if (Math.abs(e.crossAngle()) > (Math.PI * 0.9) || Math.abs(e.next.crossAngle()) > (Math.PI * 0.9)) good = false; + if (e.t.aspect() < 0.1) good = false; + e.p2.quadricStale = true; + } - reComputeErrorAround(); + if (!ignorecollision && !ignoreProblems && good) + triangles.range(oldp, this.p, (Visitor)this); return good; } @@ -201,16 +188,15 @@ public class Mesh implements Iterable { return true; } } - private boolean good; public boolean move(Vec v) { Matrix m = Matrix.translate(v); - Vertex p = this; boolean good = true; - do { - good &= p.transform(m); - p = p.bound_to; - } while (p != this); + for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) + good &= p.transform(m.times(p.p), false); + for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) + if (good) p.reComputeErrorAround(); + else p.transform(p.oldp, true); return good; } @@ -326,7 +312,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) {