From f9488635746daea6f8ccbb4680ff7f169dc5b2e5 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 13 Dec 2007 18:42:41 -0800 Subject: [PATCH] use rtree for intersection testing darcs-hash:20071214024241-5007d-0ea64e63b500c5d94ac52eb312119b4c6d370f63.gz --- src/edu/berkeley/qfat/Main.java | 47 ++++++++++-------- src/edu/berkeley/qfat/Mesh.java | 77 ++++++++++++++++++++++++------ src/edu/berkeley/qfat/MeshViewer.java | 4 +- src/edu/berkeley/qfat/geom/PointSet.java | 50 ++----------------- src/edu/berkeley/qfat/geom/RTree.java | 25 ++++++++-- 5 files changed, 118 insertions(+), 85 deletions(-) diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 6a02d08..1f625fb 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -45,7 +45,7 @@ home: home view: take current angle, zoom to whole scnee public class Main extends MeshViewer { - public static int verts = 0; + public static int verts = 1; public static final Random random = new Random(); @@ -88,16 +88,16 @@ public class Main extends MeshViewer { float halfup = 0; translations = new Matrix[] { - /* + new Matrix(new Vec(lshift, depth, halfup)), new Matrix(new Vec(rshift, depth, halfup)), new Matrix(new Vec(lshift, -depth, halfup)), new Matrix(new Vec(rshift, -depth, halfup)), - */ + /* new Matrix(new Vec(0, depth, halfup)), new Matrix(new Vec(0, -depth, halfup)), - + */ new Matrix(new Vec(lshift, 0, height)), new Matrix(new Vec(rshift, 0, height)), @@ -269,18 +269,17 @@ public class Main extends MeshViewer { } public synchronized void breakit() { - if (verts > 800) return; - //while(verts < 800) { + int oldverts = verts; + System.out.println("doubling vertices."); PriorityQueue es = new PriorityQueue(); for(Mesh.E e : tile.edges()) es.add(e); - for(int i=0; i<10; i++) { + for(int i=0; i { rtree.init(props); } + public void add(V v) { insert(v); } public void insert(V v) { int id = lowid++; idToV.put(id, v); @@ -30,7 +31,9 @@ public class RTree { } public void remove(V v) { - int id = vToId.get(v); + Integer idi = vToId.get(v); + if (idi==null) return; + int id = idi; idToV.remove(id); vToId.remove(v); rtree.delete(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(), @@ -38,9 +41,8 @@ public class RTree { id); } - + // gross... V found = null; - private IntProcedure finder = new IntProcedure() { public boolean execute(int id) { found = idToV.get(id); @@ -54,4 +56,21 @@ public class RTree { found = null; return ret; } + + Visitor visitor = null; + private IntProcedure searcher = new IntProcedure() { + public boolean execute(int id) { + V v = idToV.get(id); + visitor.visit(v); + return true; + } + }; + public void range(HasBoundingBox v, Visitor vis) { + visitor = vis; + rtree.intersects(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(), + v.getMaxX(), v.getMaxY(), v.getMaxZ()), + searcher); + visitor = null; + } + } -- 1.7.10.4