X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2Fgeom%2FRTree.java;h=1e6e39a3e1cc9aea626fe8dcabc813f89d3f21e1;hb=1e2214af081840f74ebef09a7f9973cac3107d13;hp=eaa9f6986f6575e61b3b484cfeffc68f11a0641e;hpb=8eb1f25c21956fea2fdd1fffc3d1f1ace5a2047b;p=anneal.git
diff --git a/src/edu/berkeley/qfat/geom/RTree.java b/src/edu/berkeley/qfat/geom/RTree.java
index eaa9f69..1e6e39a 100644
--- a/src/edu/berkeley/qfat/geom/RTree.java
+++ b/src/edu/berkeley/qfat/geom/RTree.java
@@ -4,21 +4,35 @@ import java.util.*;
import com.infomatiq.jsi.*;
import com.infomatiq.jsi.rtree.*;
+/** wrapper around the com.infomatiq.jsi.rtree.RTree class */
public class RTree implements Iterable {
private com.infomatiq.jsi.rtree.RTree rtree =
new com.infomatiq.jsi.rtree.RTree();
- int lowid = 0;
- HashMap idToV = new HashMap();
- HashMap vToId = new HashMap();
+ private int lowid = 0;
+ private HashMap idToV = new HashMap();
+ private HashMap vToId = new HashMap();
public Iterator iterator() { return vToId.keySet().iterator(); }
- public RTree() {
- Properties props = new Properties();
+ 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 com.infomatiq.jsi.Point point = new com.infomatiq.jsi.Point(0,0,0);
+ private V found = null;
+ private Visitor visitor = null;
+
+ private static final Properties props = new Properties();
+ static {
props.put("MinNodeEntries", "1");
props.put("MaxNodeEntries", "5");
+ }
+
+ public RTree() { clear(); }
+
+ public void clear() {
+ idToV.clear();
+ vToId.clear();
rtree.init(props);
}
@@ -27,9 +41,8 @@ public class RTree implements Iterable {
int id = lowid++;
idToV.put(id, v);
vToId.put(v, id);
- rtree.add(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(),
- v.getMaxX(), v.getMaxY(), v.getMaxZ()),
- id);
+ rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
+ rtree.add(rect, id);
}
public void remove(V v) {
@@ -38,41 +51,42 @@ public class RTree implements Iterable {
int id = idi;
idToV.remove(id);
vToId.remove(v);
- rtree.delete(new com.infomatiq.jsi.Rectangle(v.getMinX(), v.getMinY(), v.getMinZ(),
- v.getMaxX(), v.getMaxY(), v.getMaxZ()),
- id);
+ rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
+ rtree.delete(rect, id);
}
- // gross...
- V found = null;
- private IntProcedure finder = new IntProcedure() {
- public boolean execute(int id) {
- found = idToV.get(id);
- return false;
- }
- };
-
public V nearest(Point p) {
- rtree.nearest(new com.infomatiq.jsi.Point(p.x, p.y, p.z), finder, Float.POSITIVE_INFINITY);
+ point.set(p.x, p.y, p.z);
+ rtree.nearest(point, myIntProcedure, Float.POSITIVE_INFINITY);
V ret = found;
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);
+ rect.set(v.getMinX(), v.getMinY(), v.getMinZ(), v.getMaxX(), v.getMaxY(), v.getMaxZ());
+ rtree.intersects(rect, myIntProcedure);
visitor = null;
}
+ public void range(Point p1, Point p2, Visitor vis) {
+ visitor = vis;
+ rect.set(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
+ rtree.intersects(rect, myIntProcedure);
+ visitor = null;
+ }
+
+ private class MyIntProcedure implements IntProcedure {
+ public boolean execute(int id) {
+ if (visitor != null) {
+ V v = idToV.get(id);
+ visitor.visit(v);
+ return true;
+ } else {
+ found = idToV.get(id);
+ return false;
+ }
+ }
+ }
}