From 97861fe55db813365768e4ab2d53f2f5908c1486 Mon Sep 17 00:00:00 2001 From: adam Date: Wed, 5 Dec 2007 00:43:21 -0800 Subject: [PATCH] checkpoint darcs-hash:20071205084321-5007d-e8d74ab2a56d55e4c258cbaf93a655d50b53c464.gz --- src/edu/berkeley/qfat/Main.java | 23 +++++++------- src/edu/berkeley/qfat/Mesh.java | 65 +++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index d8896c2..bb5dd11 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -12,6 +12,8 @@ import edu.berkeley.qfat.geom.Point; public class Main extends MeshViewer { + public static int verts = 0; + public static final Random random = new Random(); /** magnification factor */ @@ -127,23 +129,23 @@ public class Main extends MeshViewer { if ((t1.v1().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) && (t1.v2().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) && (t1.v3().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) { - t1.e1().bind(t2.e3().pair); - t1.e2().bind(t2.e2().pair); - t1.e3().bind(t2.e1().pair); + t1.e1().bindEdge(t2.e3()); + t1.e2().bindEdge(t2.e2()); + t1.e3().bindEdge(t2.e1()); } if ((t1.v2().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) && (t1.v3().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) && (t1.v1().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) { - t1.e2().bind(t2.e3().pair); - t1.e3().bind(t2.e2().pair); - t1.e1().bind(t2.e1().pair); + t1.e2().bindEdge(t2.e3()); + t1.e3().bindEdge(t2.e2()); + t1.e1().bindEdge(t2.e1()); } if ((t1.v3().p.times(m).minus(t2.v1().p).mag() < Mesh.EPSILON) && (t1.v1().p.times(m).minus(t2.v3().p).mag() < Mesh.EPSILON) && (t1.v2().p.times(m).minus(t2.v2().p).mag() < Mesh.EPSILON)) { - t1.e3().bind(t2.e3().pair); - t1.e1().bind(t2.e2().pair); - t1.e2().bind(t2.e1().pair); + t1.e3().bindEdge(t2.e3()); + t1.e1().bindEdge(t2.e2()); + t1.e2().bindEdge(t2.e1()); } } } @@ -220,8 +222,6 @@ public class Main extends MeshViewer { } } - public static int verts = 0; - public void anneal() throws Exception { int verts = 0; while(true) { @@ -249,4 +249,5 @@ public class Main extends MeshViewer { Main main = new Main(stlf, f); main.anneal(); } + } \ No newline at end of file diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index f4f0837..3a0d72c 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -116,25 +116,6 @@ public class Mesh implements Iterable { return (float)total; } - public class BindingGroup { - public HashSet es = new HashSet(); - public BindingGroup() { } - public BindingGroup(E e) { - es.add(e); - } - public void add(E e) { - if (e.bg != null) { merge(e.bg); return; } - es.add(e); - e.bg = this; - } - public void merge(BindingGroup bg) { - for(E e : bg.es) { - e.bg = null; - add(e); - } - } - } - public void rebuildPointSet() { pointset.rebuild(); } public Vec diagonal() { return pointset.diagonal(); } public Point centroid() { return pointset.centroid(); } @@ -337,6 +318,37 @@ public class Mesh implements Iterable { } } + public class BindingGroup { + private HashSet ess = new HashSet(); + public BindingGroup() { } + public BindingGroup(E e) { + ess.add(e); + } + public void add(E e) { + if (e.bg != null) { merge(e.bg); return; } + ess.add(e); + e.bg = this; + } + public void merge(BindingGroup bg) { + for(E e : bg.ess) { + e.bg = null; + add(e); + } + } + public void dobind(E e) { + for(E ex : ess) { + if (ex==e) continue; + e.p1.bind(ex.p1); + e.p2.bind(ex.p2); + } + } + public void shatter(BindingGroup bg1, BindingGroup bg2) { + for(E e : ess) { + e.shatter(e.midpoint(), bg1, bg2); + } + } + } + /** [UNIQUE] an edge */ public final class E implements Comparable { @@ -350,17 +362,10 @@ public class Mesh implements Iterable { public int compareTo(E e) { return e.length() > length() ? 1 : -1; } - public void bind(E e) { bind(e, new Matrix()); } - public void bind(E e, Matrix m) { e.bg.add(this); } - - public void dobind() { - if (bg==null) return; - for(E ex : bg.es) { - if (ex==this) continue; - p1.bind(ex.p1); - p2.bind(ex.p2); - } + public void bindEdge(E e) { + e.pair.bg.add(this); } + public void dobind() { if (bg != null) bg.dobind(this); } public Point shatter() { return shatter(midpoint(), null, null); } public Point shatter(Point mid, BindingGroup bg1, BindingGroup bg2) { @@ -373,7 +378,7 @@ public class Mesh implements Iterable { if (bg1==null) bg1 = new BindingGroup(); if (bg2==null) bg2 = new BindingGroup(); - for(E e : bg.es) e.shatter(e.midpoint(), bg1, bg2); + bg.shatter(bg1, bg2); pair.shatter(); destroy(); -- 1.7.10.4