From 3685f1880f7505a26574d02102aafcef11b0686e Mon Sep 17 00:00:00 2001 From: adam Date: Wed, 5 Dec 2007 00:24:00 -0800 Subject: [PATCH] checkpoint darcs-hash:20071205082400-5007d-1a2203c7e591ae0e8b7fa4d2f910ae20e9fab19a.gz --- src/edu/berkeley/qfat/Main.java | 5 ++-- src/edu/berkeley/qfat/Mesh.java | 38 ++++++++++++++++++++---------- src/edu/berkeley/qfat/geom/PointSet.java | 8 +++++++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index c4dcf5a..d8896c2 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -178,13 +178,13 @@ public class Main extends MeshViewer { } public synchronized void breakit() { - if (verts > 50) return; + if (verts > 300) return; PriorityQueue es = new PriorityQueue(); for(Mesh.E e : tile.edges()) es.add(e); for(int i=0; i<10; i++) { Mesh.E e = es.poll(); verts++; - System.out.println("shatter " + e); + //System.out.println("shatter " + e); e.shatter(); tile.rebindPoints(); } @@ -231,6 +231,7 @@ public class Main extends MeshViewer { repaint(); for(Mesh.Vert v : hs) rand(10,v); } + tile.rebuildPointSet(); breakit(); repaint(); goal.unApplyQuadricToNeighborAll(); diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 74ccd4b..f4f0837 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -135,6 +135,7 @@ public class Mesh implements Iterable { } } + public void rebuildPointSet() { pointset.rebuild(); } public Vec diagonal() { return pointset.diagonal(); } public Point centroid() { return pointset.centroid(); } public Vert nearest(Point p) { return pointset.nearest(p); } @@ -153,6 +154,7 @@ public class Mesh implements Iterable { Vert bound_to = this; Matrix binding = new Matrix(); float oldscore = 0; + boolean quadricStale = false; public Matrix errorQuadric() { return quadric; } public Point getPoint() { return p; } @@ -171,6 +173,8 @@ public class Mesh implements Iterable { } public void recomputeFundamentalQuadric() { + if (!quadricStale && fundamentalQuadric != null) return; + quadricStale = false; unApplyQuadricToNeighbor(); Matrix m = Matrix.ZERO; E e = this.e; @@ -198,19 +202,22 @@ public class Mesh implements Iterable { public void applyQuadricToNeighbor() { if (score_against == null) return; + Vert 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) { - nearest_in_other_mesh = score_against.nearest(p); - - // don't attract to vertices that face the other way - if (nearest_in_other_mesh.e == null || 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(); - } + 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 (nearest_in_other_mesh.e == null || 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(); } @@ -245,6 +252,13 @@ public class Mesh implements Iterable { applyQuadricToNeighbor(); // should recompute fundamental quadrics of all vertices sharing a face, but we defer... + E e = this.e; + do { + e.p2.quadricStale = true; + e = e.pair.next; + } while(e != this.e); + + // FIXME: intersection test needed? return true; } diff --git a/src/edu/berkeley/qfat/geom/PointSet.java b/src/edu/berkeley/qfat/geom/PointSet.java index 8c6642c..0934336 100644 --- a/src/edu/berkeley/qfat/geom/PointSet.java +++ b/src/edu/berkeley/qfat/geom/PointSet.java @@ -14,12 +14,20 @@ public class PointSet implements Iterable { } public void clear() { kd = new KDTree(3); + exact = new HashMap(); } public V get(Point p) { return exact.get(p); } + public void rebuild() { + HashMap old_exact = exact; + exact = new HashMap(); + kd = new KDTree(3); + for(V v : old_exact.values()) add(v); + } + public void add(V v) { V x = get(v.getPoint()); if (x != null && x.equals(v)) return; -- 1.7.10.4