X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FMesh.java;h=6fd53d3e68d6002dde7ed63cb0a637f73893ec9e;hp=0e2c1d68416114d28338da36bc115048ebcd2900;hb=ba475c8edc2d38444381eeed6545ae36e47b093e;hpb=d39304bb7e226d94996842f57a4d8d6987695184 diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 0e2c1d6..6fd53d3 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -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,7 +76,7 @@ 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; @@ -109,11 +109,7 @@ public class Mesh implements Iterable { return m.times(1/(float)count); } - public HasQuadric nearest() { - if (error_against==null) return null; - return error_against.vertices.nearest(p, this); - } - + public HasQuadric nearest() { return error_against==null ? null : error_against.vertices.nearest(p, this); } public void computeError() { float nerror = quadric_count != 0 @@ -132,43 +128,35 @@ public class Mesh implements Iterable { setError(nerror); } - 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(); - } - /** 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 (!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; + } - if (!ignorecollision && good) triangles.range(oldp, this.p, (Visitor)this); + if (!ignorecollision && !ignoreProblems && good) + triangles.range(oldp, this.p, (Visitor)this); return good; } @@ -203,18 +191,12 @@ public class Mesh implements Iterable { public boolean move(Vec v) { Matrix m = Matrix.translate(v); - boolean good = true; for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) - good &= p.transform(m); - - if (good) { - for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) - p.reComputeErrorAround(); - } else { - for(Vertex p = this; p != null; p = (p.bound_to==this)?null:p.bound_to) - p.transform(Matrix.translate(v.times(-1))); - } + 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; }