From: adam Date: Sun, 16 Dec 2007 05:34:04 +0000 (-0800) Subject: checkpoint X-Git-Url: http://git.megacz.com/?p=anneal.git;a=commitdiff_plain;h=4e22c754574f3d410e1ddc0bc5cdedd6b3586497 checkpoint darcs-hash:20071216053404-5007d-db3ee237c96cfde3d082358df42c6bc93fbb2901.gz --- diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 28b04e2..f51c772 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -63,8 +63,6 @@ public class Main extends MeshViewer { Mesh.T t = goal.newT(p0, p1, p2, n, 0); } - goal.ignorecollision = true; - // rotate to align major axis -- this probably needs to be done by a human. goal.transform(Matrix.rotate(new Vec(0, 0, 1), (float)(Math.PI/2))); diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index c583106..3208442 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -19,7 +19,6 @@ public class Mesh implements Iterable { private PointSet vertices = new PointSet(); public boolean immutableVertices; - public boolean ignorecollision = false; public Mesh error_against = null; public double error = 0; @@ -92,6 +91,8 @@ public class Mesh implements Iterable { vertices.add(this); } + public void reinsert() { vertices.remove(this); vertices.add(this); } + public float olderror = 0; public void setError(float nerror) { error -= olderror; @@ -135,29 +136,21 @@ public class Mesh implements Iterable { unApplyQuadricToNeighbor(); - if (vertices.get(this.p)==null) throw new Error(); - vertices.remove(this); - 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); + for(E e = this.e; e!=null; e=e.pair.next==this.e?null:e.pair.next) e.t.reinsert(); + reinsert(); applyQuadricToNeighbor(); - good = 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 && !ignoreProblems && good) - triangles.range(oldp, this.p, (Visitor)this); + if (ignoreProblems) return true; + 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 (good) triangles.range(oldp, this.p, (Visitor)this); return good; } @@ -165,10 +158,8 @@ public class Mesh implements Iterable { 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) { @@ -510,18 +501,12 @@ public class Mesh implements Iterable { return ret; } - /** [UNIQUE] a triangle (face) */ public final class T extends Triangle { public final E e1; public final int color; public final int colorclass; - public void removeFromRTree() { triangles.remove(this); } - public void addToRTree() { triangles.insert(this); } - - public void destroy() { triangles.remove(this); } - T(E e1, int colorclass) { this.e1 = e1; E e2 = e1.next; @@ -559,6 +544,11 @@ public class Mesh implements Iterable { public boolean hasE(E e) { return e1==e || e1.next==e || e1.prev==e; } public boolean has(Vertex v) { return v1()==v || v2()==v || v3()==v; } + public void removeFromRTree() { triangles.remove(this); } + public void addToRTree() { triangles.insert(this); } + public void destroy() { triangles.remove(this); } + public void reinsert() { triangles.remove(this); triangles.add(this); } + public boolean shouldBeDrawn() { if (e1().bind_to.set.size() == 0) return false; if (e2().bind_to.set.size() == 0) return false; diff --git a/src/edu/berkeley/qfat/geom/RTree.java b/src/edu/berkeley/qfat/geom/RTree.java index 5a29093..2487cc7 100644 --- a/src/edu/berkeley/qfat/geom/RTree.java +++ b/src/edu/berkeley/qfat/geom/RTree.java @@ -11,13 +11,14 @@ public class RTree implements Iterable { new com.infomatiq.jsi.rtree.RTree(); private int lowid = 0; - private HashMap idToV = new HashMap(); - private HashMap vToId = new HashMap(); + private HashMap idToV = new HashMap(); + private HashMap vToId = new HashMap(); + private HashMap vToRect = new HashMap(); public Iterator iterator() { return vToId.keySet().iterator(); } private final MyIntProcedure myIntProcedure = new MyIntProcedure(); - private final com.infomatiq.jsi.Rectangle rect = new com.infomatiq.jsi.Rectangle(0,0,0,0,0,0); + private final Rectangle rect = new Rectangle(0,0,0,0,0,0); private final com.infomatiq.jsi.Point point = new com.infomatiq.jsi.Point(0,0,0); private V found = null; private Visitor visitor = null; @@ -33,6 +34,7 @@ public class RTree implements Iterable { public void clear() { idToV.clear(); vToId.clear(); + vToRect.clear(); rtree.init(props); } @@ -41,8 +43,9 @@ public class RTree implements Iterable { int id = lowid++; idToV.put(id, v); vToId.put(v, id); - rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ()); + Rectangle rect = new Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ()); rtree.add(rect, id); + vToRect.put(v, rect); } public void remove(V v) { @@ -52,7 +55,8 @@ public class RTree implements Iterable { idToV.remove(id); vToId.remove(v); rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ()); - rtree.delete(rect, id); + rtree.delete(vToRect.get(v), id); + vToRect.remove(v); } public V nearest(Point p) { return nearest(p, null); }